History

Merge tag 'ib-mfd-cros-v5.3' into chrome-platform/for-next

Immutable branch between MFD and chrome-platform for driver changes to allow picking patches that depends on the cros_ec_commands.h file update.

Enric Balletbo i Serra committed 7 years ago

Commit 74e80d82 parents 81bc8c0 3aa6be32 files · +2915 −751Browse files

Showing the changes to include/linux (1 of 2 files). Show all

Unified · Split

include/linux/mfd/cros_ec_commands.h+2911−747
@@ -1,28 +1,23 @@
1+/* SPDX-License-Identifier: GPL-2.0 */
12 /*
23 * Host communication command constants for ChromeOS EC
34 *
45 * Copyright (C) 2012 Google, Inc
56 *
6− * This software is licensed under the terms of the GNU General Public
7− * License version 2, as published by the Free Software Foundation, and
8− * may be copied, distributed, and modified under those terms.
9− *
10− * This program is distributed in the hope that it will be useful,
11− * but WITHOUT ANY WARRANTY; without even the implied warranty of
12− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13− * GNU General Public License for more details.
14− *
15− * The ChromeOS EC multi function device is used to mux all the requests
16− * to the EC device for its multiple features: keyboard controller,
17− * battery charging and regulator control, firmware update.
18− *
19− * NOTE: This file is copied verbatim from the ChromeOS EC Open Source
20− * project in an attempt to make future updates easy to make.
7+ * NOTE: This file is auto-generated from ChromeOS EC Open Source code from
8+ * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h
219 */
2210
11+/* Host communication command constants for Chrome EC */
12+
2313 #ifndef __CROS_EC_COMMANDS_H
2414 #define __CROS_EC_COMMANDS_H
2515
16+
17+
18+
19+#define BUILD_ASSERT(_cond)
20+
2621 /*
2722 * Current version of this protocol
2823 *
@@ -33,7 +28,7 @@ · 4 unmodified lines
3328 #define EC_PROTO_VERSION 0x00000002
3429
3530 /* Command version mask */
36−#define EC_VER_MASK(version) (1UL << (version))
31+#define EC_VER_MASK(version) BIT(version)
3732
3833 /* I/O addresses for ACPI commands */
3934 #define EC_LPC_ADDR_ACPI_DATA 0x62
@@ -47,25 +42,28 @@ · 7 unmodified lines
4742 /* Protocol version 2 */
4843 #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
4944 #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
50− * EC_PROTO2_MAX_PARAM_SIZE */
45+ * EC_PROTO2_MAX_PARAM_SIZE
46+ */
5147 /* Protocol version 3 */
5248 #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
5349 #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
5450
55−/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
56− * and they tell the kernel that so we have to think of it as two parts. */
51+/*
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+ */
5755 #define EC_HOST_CMD_REGION0 0x800
5856 #define EC_HOST_CMD_REGION1 0x880
5957 #define EC_HOST_CMD_REGION_SIZE 0x80
6058
6159 /* EC command register bit functions */
62−#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
63−#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
64−#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
65−#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
66−#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
67−#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
68−#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
60+#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
61+#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
62+#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
63+#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
64+#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
65+#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
66+#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
6967
7068 #define EC_LPC_ADDR_MEMMAP 0x900
7169 #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
@@ -85,13 +83,15 @@ · 13 unmodified lines
8583 /* Unused 0x28 - 0x2f */
8684 #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
8785 /* Unused 0x31 - 0x33 */
88−#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
89−/* Reserve 0x38 - 0x3f for additional host event-related stuff */
90−/* Battery values are all 32 bits */
86+#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
87+/* Battery values are all 32 bits, unless otherwise noted. */
9188 #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
9289 #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
9390 #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
94−#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 */
9595 #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
9696 #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
9797 #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
@@ -105,15 +105,24 @@ · 7 unmodified lines
105105 /* Unused 0x84 - 0x8f */
106106 #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
107107 /* Unused 0x91 */
108−#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 */
109112 #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
110−/* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
113+/* Unused 0xa6 - 0xdf */
111114
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
112121
113122 /* Define the format of the accelerometer mapped memory status byte. */
114123 #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
115−#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
116−#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
124+#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
125+#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
117126
118127 /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
119128 #define EC_TEMP_SENSOR_ENTRIES 16
@@ -157,6 +166,8 @@ · 37 unmodified lines
157166 #define EC_BATT_FLAG_DISCHARGING 0x04
158167 #define EC_BATT_FLAG_CHARGING 0x08
159168 #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
160171
161172 /* Switch flags at EC_MEMMAP_SWITCHES */
162173 #define EC_SWITCH_LID_OPEN 0x01
@@ -182,20 +193,242 @@ · 19 unmodified lines
182193 #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
183194 #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
184195
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+
185384 /*
186385 * This header file is used in coreboot both in C and ACPI code. The ACPI code
187386 * is pre-processed to handle constants but the ASL compiler is unable to
188387 * handle actual C code so keep it separate.
189388 */
190−#ifndef __ACPI__
389+
390+
391+/*
392+ * Attributes for EC request and response packets. Just defining __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+ */
191418
192419 /*
193− * Define __packed if someone hasn't beat us to it. Linux kernel style
194− * checking prefers __packed over __attribute__((packed)).
420+ * Packed structures make no assumption about alignment, so they do inefficient
421+ * byte-wise reads.
195422 */
196−#ifndef __packed
197−#define __packed __attribute__((packed))
198−#endif
423+#define __ec_align1 __packed
424+#define __ec_align2 __packed
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+
199432
200433 /* LPC command status byte masks */
201434 /* EC has written a byte in the data register and host hasn't read it yet */
@@ -206,7 +439,7 @@ · 4 unmodified lines
206439 #define EC_LPC_STATUS_PROCESSING 0x04
207440 /* Last write to EC was a command, not data */
208441 #define EC_LPC_STATUS_LAST_CMD 0x08
209−/* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
442+/* EC is in burst mode */
210443 #define EC_LPC_STATUS_BURST_MODE 0x10
211444 /* SCI event is pending (requesting SCI query) */
212445 #define EC_LPC_STATUS_SCI_PENDING 0x20
@@ -222,7 +455,10 @@ · 9 unmodified lines
222455 #define EC_LPC_STATUS_BUSY_MASK \
223456 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
224457
225−/* 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+ */
226462 enum ec_status {
227463 EC_RES_SUCCESS = 0,
228464 EC_RES_INVALID_COMMAND = 1,
@@ -238,7 +474,13 @@ enum ec_status { · 9 unmodified lines
238474 EC_RES_OVERFLOW = 11, /* Table / data overflow */
239475 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
240476 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
241− 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 */
242484 };
243485
244486 /*
@@ -258,7 +500,8 @@ enum host_event_code { · 13 unmodified lines
258500 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
259501 EC_HOST_EVENT_BATTERY = 8,
260502 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
261− EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
503+ /* Event generated by a device attached to the EC */
504+ EC_HOST_EVENT_DEVICE = 10,
262505 EC_HOST_EVENT_THERMAL = 11,
263506 EC_HOST_EVENT_USB_CHARGER = 12,
264507 EC_HOST_EVENT_KEY_PRESSED = 13,
@@ -285,15 +528,34 @@ enum host_event_code { · 20 unmodified lines
285528 EC_HOST_EVENT_HANG_DETECT = 20,
286529 /* Hang detect logic detected a hang and warm rebooted the AP */
287530 EC_HOST_EVENT_HANG_REBOOT = 21,
531+
288532 /* PD MCU triggering host event */
289533 EC_HOST_EVENT_PD_MCU = 22,
290534
291− /* EC desires to change state of host-controlled USB mux */
292− EC_HOST_EVENT_USB_MUX = 28,
535+ /* Battery Status flags have changed */
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,
293543
294544 /* EC RTC event occurred */
295545 EC_HOST_EVENT_RTC = 26,
296546
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+
297559 /*
298560 * The high bit of the event mask is not used as a host event code. If
299561 * it reads back as set, then the entire event mask should be
@@ -304,7 +566,7 @@ enum host_event_code { · 4 unmodified lines
304566 EC_HOST_EVENT_INVALID = 32
305567 };
306568 /* Host event mask */
307−#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
569+#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
308570
309571 /**
310572 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
@@ -319,7 +581,7 @@ struct ec_lpc_host_args { · 8 unmodified lines
319581 uint8_t command_version;
320582 uint8_t data_size;
321583 uint8_t checksum;
322−} __packed;
584+} __ec_align4;
323585
324586 /* Flags for ec_lpc_host_args.flags */
325587 /*
@@ -329,7 +591,7 @@ struct ec_lpc_host_args { · 3 unmodified lines
329591 * If EC gets a command and this flag is not set, this is an old-style command.
330592 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
331593 * unknown length. EC must respond with an old-style response (that is,
332− * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
594+ * without setting EC_HOST_ARGS_FLAG_TO_HOST).
333595 */
334596 #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
335597 /*
@@ -490,7 +752,7 @@ struct ec_host_request { · 154 unmodified lines
490752 uint8_t command_version;
491753 uint8_t reserved;
492754 uint16_t data_len;
493−} __packed;
755+} __ec_align4;
494756
495757 #define EC_HOST_RESPONSE_VERSION 3
496758
@@ -509,18 +771,151 @@ struct ec_host_response { · 12 unmodified lines
509771 uint16_t result;
510772 uint16_t data_len;
511773 uint16_t reserved;
512−} __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 */
837+struct 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 */
867+struct 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
513905
514906 /*****************************************************************************/
515907 /*
516908 * Notes on commands:
517909 *
518910 * Each command is an 16-bit command value. Commands which take params or
519− * 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
520912 * specified, the command does not input or output data, respectively.
521913 * Parameter/response length is implicit in the structs. Some underlying
522914 * communication protocols (I2C, SPI) may add length or checksum headers, but
523915 * 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.
524919 */
525920
526921 /*****************************************************************************/
@@ -530,7 +925,7 @@ struct ec_host_response { · 3 unmodified lines
530925 * Get protocol version, used to deal with non-backward compatible protocol
531926 * changes.
532927 */
533−#define EC_CMD_PROTO_VERSION 0x00
928+#define EC_CMD_PROTO_VERSION 0x0000
534929
535930 /**
536931 * struct ec_response_proto_version - Response to the proto version command.
@@ -538,13 +933,13 @@ struct ec_host_response { · 1 unmodified line
538933 */
539934 struct ec_response_proto_version {
540935 uint32_t version;
541−} __packed;
936+} __ec_align4;
542937
543938 /*
544939 * Hello. This is a simple command to test the EC is responsive to
545940 * commands.
546941 */
547−#define EC_CMD_HELLO 0x01
942+#define EC_CMD_HELLO 0x0001
548943
549944 /**
550945 * struct ec_params_hello - Parameters to the hello command.
@@ -552,7 +947,7 @@ struct ec_response_proto_version { · 1 unmodified line
552947 */
553948 struct ec_params_hello {
554949 uint32_t in_data;
555−} __packed;
950+} __ec_align4;
556951
557952 /**
558953 * struct ec_response_hello - Response to the hello command.
@@ -560,10 +955,10 @@ struct ec_params_hello { · 1 unmodified line
560955 */
561956 struct ec_response_hello {
562957 uint32_t out_data;
563−} __packed;
958+} __ec_align4;
564959
565960 /* Get version number */
566−#define EC_CMD_GET_VERSION 0x02
961+#define EC_CMD_GET_VERSION 0x0002
567962
568963 enum ec_current_image {
569964 EC_IMAGE_UNKNOWN = 0,
@@ -583,10 +978,10 @@ struct ec_response_get_version { · 13 unmodified lines
583978 char version_string_rw[32];
584979 char reserved[32];
585980 uint32_t current_image;
586−} __packed;
981+} __ec_align4;
587982
588983 /* Read test */
589−#define EC_CMD_READ_TEST 0x03
984+#define EC_CMD_READ_TEST 0x0003
590985
591986 /**
592987 * struct ec_params_read_test - Parameters for the read test command.
@@ -596,7 +991,7 @@ struct ec_response_get_version { · 3 unmodified lines
596991 struct ec_params_read_test {
597992 uint32_t offset;
598993 uint32_t size;
599−} __packed;
994+} __ec_align4;
600995
601996 /**
602997 * struct ec_response_read_test - Response to the read test command.
@@ -604,17 +999,17 @@ struct ec_params_read_test { · 1 unmodified line
604999 */
6051000 struct ec_response_read_test {
6061001 uint32_t data[32];
607−} __packed;
1002+} __ec_align4;
6081003
6091004 /*
6101005 * Get build information
6111006 *
6121007 * Response is null-terminated string.
6131008 */
614−#define EC_CMD_GET_BUILD_INFO 0x04
1009+#define EC_CMD_GET_BUILD_INFO 0x0004
6151010
6161011 /* Get chip info */
617−#define EC_CMD_GET_CHIP_INFO 0x05
1012+#define EC_CMD_GET_CHIP_INFO 0x0005
6181013
6191014 /**
6201015 * struct ec_response_get_chip_info - Response to the get chip info command.
@@ -626,10 +1021,10 @@ struct ec_response_get_chip_info { · 5 unmodified lines
6261021 char vendor[32];
6271022 char name[32];
6281023 char revision[32];
629−} __packed;
1024+} __ec_align4;
6301025
6311026 /* Get board HW version */
632−#define EC_CMD_GET_BOARD_VERSION 0x06
1027+#define EC_CMD_GET_BOARD_VERSION 0x0006
6331028
6341029 /**
6351030 * struct ec_response_board_version - Response to the board version command.
@@ -637,7 +1032,7 @@ struct ec_response_get_chip_info { · 1 unmodified line
6371032 */
6381033 struct ec_response_board_version {
6391034 uint16_t board_version;
640−} __packed;
1035+} __ec_align2;
6411036
6421037 /*
6431038 * Read memory-mapped data.
@@ -647,7 +1042,7 @@ struct ec_response_board_version { · 3 unmodified lines
6471042 *
6481043 * Response is params.size bytes of data.
6491044 */
650−#define EC_CMD_READ_MEMMAP 0x07
1045+#define EC_CMD_READ_MEMMAP 0x0007
6511046
6521047 /**
6531048 * struct ec_params_read_memmap - Parameters for the read memory map command.
@@ -657,10 +1052,10 @@ struct ec_response_board_version { · 3 unmodified lines
6571052 struct ec_params_read_memmap {
6581053 uint8_t offset;
6591054 uint8_t size;
660−} __packed;
1055+} __ec_align1;
6611056
6621057 /* Read versions supported for a command */
663−#define EC_CMD_GET_CMD_VERSIONS 0x08
1058+#define EC_CMD_GET_CMD_VERSIONS 0x0008
6641059
6651060 /**
6661061 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
@@ -668,7 +1063,7 @@ struct ec_params_read_memmap { · 1 unmodified line
6681063 */
6691064 struct ec_params_get_cmd_versions {
6701065 uint8_t cmd;
671−} __packed;
1066+} __ec_align1;
6721067
6731068 /**
6741069 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
@@ -677,7 +1072,7 @@ struct ec_params_get_cmd_versions { · 2 unmodified lines
6771072 */
6781073 struct ec_params_get_cmd_versions_v1 {
6791074 uint16_t cmd;
680−} __packed;
1075+} __ec_align2;
6811076
6821077 /**
6831078 * struct ec_response_get_cmd_version - Response to the get command versions.
@@ -686,20 +1081,20 @@ struct ec_params_get_cmd_versions_v1 { · 2 unmodified lines
6861081 */
6871082 struct ec_response_get_cmd_versions {
6881083 uint32_t version_mask;
689−} __packed;
1084+} __ec_align4;
6901085
6911086 /*
692− * 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
6931088 * on lpc since it has its own out-of-band busy indicator.
6941089 *
6951090 * lpc must read the status from the command register. Attempting this on
6961091 * lpc will overwrite the args/parameter space and corrupt its data.
6971092 */
698−#define EC_CMD_GET_COMMS_STATUS 0x09
1093+#define EC_CMD_GET_COMMS_STATUS 0x0009
6991094
7001095 /* Avoid using ec_status which is for return values */
7011096 enum ec_comms_status {
702− EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
1097+ EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
7031098 };
7041099
7051100 /**
@@ -709,29 +1104,29 @@ enum ec_comms_status { · 3 unmodified lines
7091104 */
7101105 struct ec_response_get_comms_status {
7111106 uint32_t flags; /* Mask of enum ec_comms_status */
712−} __packed;
1107+} __ec_align4;
7131108
7141109 /* Fake a variety of responses, purely for testing purposes. */
715−#define EC_CMD_TEST_PROTOCOL 0x0a
1110+#define EC_CMD_TEST_PROTOCOL 0x000A
7161111
7171112 /* Tell the EC what to send back to us. */
7181113 struct ec_params_test_protocol {
7191114 uint32_t ec_result;
7201115 uint32_t ret_len;
7211116 uint8_t buf[32];
722−} __packed;
1117+} __ec_align4;
7231118
7241119 /* Here it comes... */
7251120 struct ec_response_test_protocol {
7261121 uint8_t buf[32];
727−} __packed;
1122+} __ec_align4;
7281123
729−/* Get prococol information */
730−#define EC_CMD_GET_PROTOCOL_INFO 0x0b
1124+/* Get protocol information */
1125+#define EC_CMD_GET_PROTOCOL_INFO 0x000B
7311126
7321127 /* Flags for ec_response_get_protocol_info.flags */
7331128 /* EC_RES_IN_PROGRESS may be returned if a command is slow */
734−#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
1129+#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
7351130
7361131 /**
7371132 * struct ec_response_get_protocol_info - Response to the get protocol info.
@@ -747,7 +1142,7 @@ struct ec_response_get_protocol_info { · 9 unmodified lines
7471142 uint16_t max_request_packet_size;
7481143 uint16_t max_response_packet_size;
7491144 uint32_t flags;
750−} __packed;
1145+} __ec_align4;
7511146
7521147
7531148 /*****************************************************************************/
@@ -765,19 +1160,19 @@ struct ec_response_get_protocol_info { · 11 unmodified lines
7651160 struct ec_params_get_set_value {
7661161 uint32_t flags;
7671162 uint32_t value;
768−} __packed;
1163+} __ec_align4;
7691164
7701165 struct ec_response_get_set_value {
7711166 uint32_t flags;
7721167 uint32_t value;
773−} __packed;
1168+} __ec_align4;
7741169
775−/* More than one command can use these structs to get/set paramters. */
776−#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
1170+/* More than one command can use these structs to get/set parameters. */
1171+#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
7771172
7781173 /*****************************************************************************/
7791174 /* List the features supported by the firmware */
780−#define EC_CMD_GET_FEATURES 0x0d
1175+#define EC_CMD_GET_FEATURES 0x000D
7811176
7821177 /* Supported features */
7831178 enum ec_feature_code {
@@ -884,24 +1279,36 @@ enum ec_feature_code { · 100 unmodified lines
8841279 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
8851280 /* EC supports audio codec. */
8861281 EC_FEATURE_AUDIO_CODEC = 38,
887− /* EC Supports SCP. */
1282+ /* The MCU is a System Companion Processor (SCP). */
8881283 EC_FEATURE_SCP = 39,
8891284 /* The MCU is an Integrated Sensor Hub */
8901285 EC_FEATURE_ISH = 40,
8911286 };
8921287
893−#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
894−#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
1288+#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1289+#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
8951290
8961291 struct ec_response_get_features {
8971292 uint32_t flags[2];
898−} __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+
1302+struct ec_sku_id_info {
1303+ uint32_t sku_id;
1304+} __ec_align4;
8991305
9001306 /*****************************************************************************/
9011307 /* Flash commands */
9021308
9031309 /* Get flash info */
904−#define EC_CMD_FLASH_INFO 0x10
1310+#define EC_CMD_FLASH_INFO 0x0010
1311+#define EC_VER_FLASH_INFO 2
9051312
9061313 /**
9071314 * struct ec_response_flash_info - Response to the flash info command.
@@ -920,11 +1327,22 @@ struct ec_response_flash_info { · 12 unmodified lines
9201327 uint32_t write_block_size;
9211328 uint32_t erase_block_size;
9221329 uint32_t protect_block_size;
923−} __packed;
1330+} __ec_align4;
1331+
1332+/*
1333+ * Flags for version 1+ flash info command
1334+ * EC flash erases bits to 0 instead of 1.
1335+ */
1336+#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
9241337
925−/* Flags for version 1+ flash info command */
926−/* EC flash erases bits to 0 instead of 1 */
927−#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
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)
9281346
9291347 /**
9301348 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
@@ -946,7 +1364,14 @@ struct ec_response_flash_info { · 15 unmodified lines
9461364 * fields following.
9471365 *
9481366 * gcc anonymous structs don't seem to get along with the __packed directive;
949− * 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.
9501375 */
9511376 struct ec_response_flash_info_1 {
9521377 /* Version 0 fields; see above for description */
@@ -958,14 +1383,50 @@ struct ec_response_flash_info_1 { · 5 unmodified lines
9581383 /* Version 1 adds these fields: */
9591384 uint32_t write_ideal_size;
9601385 uint32_t flags;
961−} __packed;
1386+} __ec_align4;
1387+
1388+struct 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+
1395+struct 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+
1410+struct 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;
9621423
9631424 /*
9641425 * Read flash
9651426 *
9661427 * Response is params.size bytes of data.
9671428 */
968−#define EC_CMD_FLASH_READ 0x11
1429+#define EC_CMD_FLASH_READ 0x0011
9691430
9701431 /**
9711432 * struct ec_params_flash_read - Parameters for the flash read command.
@@ -975,10 +1436,10 @@ struct ec_response_flash_info_1 { · 3 unmodified lines
9751436 struct ec_params_flash_read {
9761437 uint32_t offset;
9771438 uint32_t size;
978−} __packed;
1439+} __ec_align4;
9791440
9801441 /* Write flash */
981−#define EC_CMD_FLASH_WRITE 0x12
1442+#define EC_CMD_FLASH_WRITE 0x0012
9821443 #define EC_VER_FLASH_WRITE 1
9831444
9841445 /* Version 0 of the flash command supported only 64 bytes of data */
@@ -993,20 +1454,57 @@ struct ec_params_flash_write { · 8 unmodified lines
9931454 uint32_t offset;
9941455 uint32_t size;
9951456 /* Followed by data to write */
996−} __packed;
1457+} __ec_align4;
9971458
9981459 /* Erase flash */
999−#define EC_CMD_FLASH_ERASE 0x13
1460+#define EC_CMD_FLASH_ERASE 0x0013
10001461
10011462 /**
1002− * struct ec_params_flash_erase - Parameters for the flash erase command.
1463+ * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
10031464 * @offset: Byte offset to erase.
10041465 * @size: Size to erase in bytes.
10051466 */
10061467 struct ec_params_flash_erase {
10071468 uint32_t offset;
10081469 uint32_t size;
1009−} __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+ */
1489+enum 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+ */
1502+struct 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;
10101508
10111509 /*
10121510 * Get/set flash protection.
@@ -1018,31 +1516,40 @@ struct ec_params_flash_erase { · 5 unmodified lines
10181516 *
10191517 * If mask=0, simply returns the current flags state.
10201518 */
1021−#define EC_CMD_FLASH_PROTECT 0x15
1519+#define EC_CMD_FLASH_PROTECT 0x0015
10221520 #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
10231521
10241522 /* Flags for flash protection */
10251523 /* RO flash code protected when the EC boots */
1026−#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1524+#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
10271525 /*
10281526 * RO flash code protected now. If this bit is set, at-boot status cannot
10291527 * be changed.
10301528 */
1031−#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1529+#define EC_FLASH_PROTECT_RO_NOW BIT(1)
10321530 /* Entire flash code protected now, until reboot. */
1033−#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1531+#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
10341532 /* Flash write protect GPIO is asserted now */
1035−#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1533+#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
10361534 /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1037−#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1535+#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
10381536 /*
10391537 * Error - flash protection is in inconsistent state. At least one bank of
10401538 * flash which should be protected is not protected. Usually fixed by
10411539 * re-requesting the desired flags, or by a hard reset if that fails.
10421540 */
1043−#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1044−/* Entile flash code protected when the EC boots */
1045−#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1541+#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
1542+/* Entire flash code protected when the EC boots */
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+
10461553
10471554 /**
10481555 * struct ec_params_flash_protect - Parameters for the flash protect command.
@@ -1052,7 +1559,7 @@ struct ec_params_flash_erase { · 3 unmodified lines
10521559 struct ec_params_flash_protect {
10531560 uint32_t mask;
10541561 uint32_t flags;
1055−} __packed;
1562+} __ec_align4;
10561563
10571564 /**
10581565 * struct ec_response_flash_protect - Response to the flash protect command.
@@ -1067,7 +1574,7 @@ struct ec_response_flash_protect { · 8 unmodified lines
10671574 uint32_t flags;
10681575 uint32_t valid_flags;
10691576 uint32_t writable_flags;
1070−} __packed;
1577+} __ec_align4;
10711578
10721579 /*
10731580 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
@@ -1075,22 +1582,37 @@ struct ec_response_flash_protect { · 1 unmodified line
10751582 */
10761583
10771584 /* Get the region offset/size */
1078−#define EC_CMD_FLASH_REGION_INFO 0x16
1585+#define EC_CMD_FLASH_REGION_INFO 0x0016
10791586 #define EC_VER_FLASH_REGION_INFO 1
10801587
10811588 enum ec_flash_region {
10821589 /* Region which holds read-only EC image */
10831590 EC_FLASH_REGION_RO = 0,
1084− /* Region which holds rewritable EC image */
1085− EC_FLASH_REGION_RW,
1591+ /*
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,
10861601 /*
10871602 * Region which should be write-protected in the factory (a superset of
10881603 * EC_FLASH_REGION_RO)
10891604 */
10901605 EC_FLASH_REGION_WP_RO,
1606+ /* Region which holds updatable (non-active) RW image */
1607+ EC_FLASH_REGION_UPDATE,
10911608 /* Number of regions */
10921609 EC_FLASH_REGION_COUNT,
10931610 };
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
10941616
10951617 /**
10961618 * struct ec_params_flash_region_info - Parameters for the flash region info
@@ -1099,15 +1621,15 @@ enum ec_flash_region { · 2 unmodified lines
10991621 */
11001622 struct ec_params_flash_region_info {
11011623 uint32_t region;
1102−} __packed;
1624+} __ec_align4;
11031625
11041626 struct ec_response_flash_region_info {
11051627 uint32_t offset;
11061628 uint32_t size;
1107−} __packed;
1629+} __ec_align4;
11081630
11091631 /* Read/write VbNvContext */
1110−#define EC_CMD_VBNV_CONTEXT 0x17
1632+#define EC_CMD_VBNV_CONTEXT 0x0017
11111633 #define EC_VER_VBNV_CONTEXT 1
11121634 #define EC_VBNV_BLOCK_SIZE 16
11131635
@@ -1119,52 +1641,99 @@ enum ec_vbnvcontext_op { · 5 unmodified lines
11191641 struct ec_params_vbnvcontext {
11201642 uint32_t op;
11211643 uint8_t block[EC_VBNV_BLOCK_SIZE];
1122−} __packed;
1644+} __ec_align4;
11231645
11241646 struct ec_response_vbnvcontext {
11251647 uint8_t block[EC_VBNV_BLOCK_SIZE];
1126−} __packed;
1648+} __ec_align4;
1649+
1650+
1651+/* Get SPI flash information */
1652+#define EC_CMD_FLASH_SPI_INFO 0x0018
1653+
1654+struct 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+ */
1676+struct ec_params_flash_select {
1677+ uint8_t select;
1678+} __ec_align4;
1679+
11271680
11281681 /*****************************************************************************/
11291682 /* PWM commands */
11301683
11311684 /* Get fan target RPM */
1132−#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1685+#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
11331686
11341687 struct ec_response_pwm_get_fan_rpm {
11351688 uint32_t rpm;
1136−} __packed;
1689+} __ec_align4;
11371690
11381691 /* Set target fan RPM */
1139−#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 */
1695+struct ec_params_pwm_set_fan_target_rpm_v0 {
1696+ uint32_t rpm;
1697+} __ec_align4;
11401698
1141−struct ec_params_pwm_set_fan_target_rpm {
1699+/* Version 1 of input params */
1700+struct ec_params_pwm_set_fan_target_rpm_v1 {
11421701 uint32_t rpm;
1143−} __packed;
1702+ uint8_t fan_idx;
1703+} __ec_align_size1;
11441704
11451705 /* Get keyboard backlight */
1146−#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
11471708
11481709 struct ec_response_pwm_get_keyboard_backlight {
11491710 uint8_t percent;
11501711 uint8_t enabled;
1151−} __packed;
1712+} __ec_align1;
11521713
11531714 /* Set keyboard backlight */
1154−#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
11551717
11561718 struct ec_params_pwm_set_keyboard_backlight {
11571719 uint8_t percent;
1158−} __packed;
1720+} __ec_align1;
11591721
11601722 /* Set target fan PWM duty cycle */
1161−#define EC_CMD_PWM_SET_FAN_DUTY 0x24
1723+#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1724+
1725+/* Version 0 of input params */
1726+struct ec_params_pwm_set_fan_duty_v0 {
1727+ uint32_t percent;
1728+} __ec_align4;
11621729
1163−struct ec_params_pwm_set_fan_duty {
1730+/* Version 1 of input params */
1731+struct ec_params_pwm_set_fan_duty_v1 {
11641732 uint32_t percent;
1165−} __packed;
1733+ uint8_t fan_idx;
1734+} __ec_align_size1;
11661735
1167−#define EC_CMD_PWM_SET_DUTY 0x25
1736+#define EC_CMD_PWM_SET_DUTY 0x0025
11681737 /* 16 bit duty cycle, 0xffff = 100% */
11691738 #define EC_PWM_MAX_DUTY 0xffff
11701739
@@ -1182,18 +1751,18 @@ struct ec_params_pwm_set_duty { · 11 unmodified lines
11821751 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
11831752 uint8_t pwm_type; /* ec_pwm_type */
11841753 uint8_t index; /* Type-specific index, or 0 if unique */
1185−} __packed;
1754+} __ec_align4;
11861755
1187−#define EC_CMD_PWM_GET_DUTY 0x26
1756+#define EC_CMD_PWM_GET_DUTY 0x0026
11881757
11891758 struct ec_params_pwm_get_duty {
11901759 uint8_t pwm_type; /* ec_pwm_type */
11911760 uint8_t index; /* Type-specific index, or 0 if unique */
1192−} __packed;
1761+} __ec_align1;
11931762
11941763 struct ec_response_pwm_get_duty {
11951764 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1196−} __packed;
1765+} __ec_align2;
11971766
11981767 /*****************************************************************************/
11991768 /*
@@ -1202,11 +1771,11 @@ struct ec_response_pwm_get_duty { · 2 unmodified lines
12021771 * into a subcommand. We'll make separate structs for subcommands with
12031772 * different input args, so that we know how much to expect.
12041773 */
1205−#define EC_CMD_LIGHTBAR_CMD 0x28
1774+#define EC_CMD_LIGHTBAR_CMD 0x0028
12061775
12071776 struct rgb_s {
12081777 uint8_t r, g, b;
1209−};
1778+} __ec_todo_unpacked;
12101779
12111780 #define LB_BATTERY_LEVELS 4
12121781
@@ -1246,7 +1815,7 @@ struct lightbar_params_v0 { · 33 unmodified lines
12461815
12471816 /* Color palette */
12481817 struct rgb_s color[8]; /* 0-3 are Google colors */
1249−} __packed;
1818+} __ec_todo_packed;
12501819
12511820 struct lightbar_params_v1 {
12521821 /* Timing */
@@ -1259,7 +1828,10 @@ struct lightbar_params_v1 { · 6 unmodified lines
12591828 int32_t s3_sleep_for;
12601829 int32_t s3_ramp_up;
12611830 int32_t s3_ramp_down;
1831+ int32_t s5_ramp_up;
1832+ int32_t s5_ramp_down;
12621833 int32_t tap_tick_delay;
1834+ int32_t tap_gate_delay;
12631835 int32_t tap_display_time;
12641836
12651837 /* Tap-for-battery params */
@@ -1287,84 +1859,182 @@ struct lightbar_params_v1 { · 21 unmodified lines
12871859 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
12881860 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
12891861
1862+ /* s5: single color pulse on inhibited power-up */
1863+ uint8_t s5_idx;
1864+
1865+ /* Color palette */
1866+ struct rgb_s color[8]; /* 0-3 are Google colors */
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+
1878+struct 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+
1896+struct 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+
1906+struct 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+
1913+struct 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+
1920+struct lightbar_params_v2_thresholds {
1921+ /* Battery level thresholds */
1922+ uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1923+} __ec_todo_packed;
1924+
1925+struct 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+
12901933 /* Color palette */
12911934 struct rgb_s color[8]; /* 0-3 are Google colors */
1292−} __packed;
1935+} __ec_todo_packed;
12931936
1294−/* Lightbar program */
1937+/* Lightbar program. */
12951938 #define EC_LB_PROG_LEN 192
12961939 struct lightbar_program {
12971940 uint8_t size;
12981941 uint8_t data[EC_LB_PROG_LEN];
1299−};
1942+} __ec_todo_unpacked;
13001943
13011944 struct ec_params_lightbar {
13021945 uint8_t cmd; /* Command (see enum lightbar_command) */
13031946 union {
1304− struct {
1305− /* no args */
1306− } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1307− version, get_brightness, get_demo, suspend, resume;
1947+ /*
1948+ * The following commands have no args:
1949+ *
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+ */
13081958
1309− struct {
1959+ struct __ec_todo_unpacked {
13101960 uint8_t num;
13111961 } set_brightness, seq, demo;
13121962
1313− struct {
1963+ struct __ec_todo_unpacked {
13141964 uint8_t ctrl, reg, value;
13151965 } reg;
13161966
1317− struct {
1967+ struct __ec_todo_unpacked {
13181968 uint8_t led, red, green, blue;
13191969 } set_rgb;
13201970
1321− struct {
1971+ struct __ec_todo_unpacked {
13221972 uint8_t led;
13231973 } get_rgb;
13241974
1325− struct {
1975+ struct __ec_todo_unpacked {
13261976 uint8_t enable;
13271977 } manual_suspend_ctrl;
13281978
13291979 struct lightbar_params_v0 set_params_v0;
13301980 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+
13311989 struct lightbar_program set_program;
13321990 };
1333−} __packed;
1991+} __ec_todo_packed;
13341992
13351993 struct ec_response_lightbar {
13361994 union {
1337− struct {
1338− struct {
1995+ struct __ec_todo_unpacked {
1996+ struct __ec_todo_unpacked {
13391997 uint8_t reg;
13401998 uint8_t ic0;
13411999 uint8_t ic1;
13422000 } vals[23];
13432001 } dump;
13442002
1345− struct {
2003+ struct __ec_todo_unpacked {
13462004 uint8_t num;
13472005 } get_seq, get_brightness, get_demo;
13482006
13492007 struct lightbar_params_v0 get_params_v0;
13502008 struct lightbar_params_v1 get_params_v1;
13512009
1352− 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 {
13532019 uint32_t num;
13542020 uint32_t flags;
13552021 } version;
13562022
1357− struct {
2023+ struct __ec_todo_unpacked {
13582024 uint8_t red, green, blue;
13592025 } get_rgb;
13602026
1361− struct {
1362− /* no return params */
1363− } off, on, init, set_brightness, seq, reg, set_rgb,
1364− demo, set_params_v0, set_params_v1,
1365− set_program, manual_suspend_ctrl, suspend, resume;
2027+ /*
2028+ * The following commands have no response:
2029+ *
2030+ * off, on, init, set_brightness, seq, reg, set_rgb, demo,
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+ */
13662036 };
1367−} __packed;
2037+} __ec_todo_packed;
13682038
13692039 /* Lightbar commands */
13702040 enum lightbar_command {
@@ -1390,13 +2060,25 @@ enum lightbar_command { · 19 unmodified lines
13902060 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
13912061 LIGHTBAR_CMD_SUSPEND = 20,
13922062 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,
13932075 LIGHTBAR_NUM_CMDS
13942076 };
13952077
13962078 /*****************************************************************************/
13972079 /* LED control commands */
13982080
1399−#define EC_CMD_LED_CONTROL 0x29
2081+#define EC_CMD_LED_CONTROL 0x0029
14002082
14012083 enum ec_led_id {
14022084 /* LED to indicate battery state of charge */
@@ -1408,13 +2090,21 @@ enum ec_led_id { · 5 unmodified lines
14082090 EC_LED_ID_POWER_LED,
14092091 /* LED on power adapter or its plug */
14102092 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,
14112101
14122102 EC_LED_ID_COUNT
14132103 };
14142104
14152105 /* LED control flags */
1416−#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1417−#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
2106+#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2107+#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
14182108
14192109 enum ec_led_colors {
14202110 EC_LED_COLOR_RED = 0,
@@ -1422,6 +2112,7 @@ enum ec_led_colors { · 1 unmodified line
14222112 EC_LED_COLOR_BLUE,
14232113 EC_LED_COLOR_YELLOW,
14242114 EC_LED_COLOR_WHITE,
2115+ EC_LED_COLOR_AMBER,
14252116
14262117 EC_LED_COLOR_COUNT
14272118 };
@@ -1431,7 +2122,7 @@ struct ec_params_led_control { · 3 unmodified lines
14312122 uint8_t flags; /* Control flags */
14322123
14332124 uint8_t brightness[EC_LED_COLOR_COUNT];
1434−} __packed;
2125+} __ec_align1;
14352126
14362127 struct ec_response_led_control {
14372128 /*
@@ -1442,7 +2133,7 @@ struct ec_response_led_control { · 4 unmodified lines
14422133 * Other values means the LED is control by PWM.
14432134 */
14442135 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1445−} __packed;
2136+} __ec_align1;
14462137
14472138 /*****************************************************************************/
14482139 /* Verified boot commands */
@@ -1453,7 +2144,7 @@ struct ec_response_led_control { · 4 unmodified lines
14532144 */
14542145
14552146 /* Verified boot hash command */
1456−#define EC_CMD_VBOOT_HASH 0x2A
2147+#define EC_CMD_VBOOT_HASH 0x002A
14572148
14582149 struct ec_params_vboot_hash {
14592150 uint8_t cmd; /* enum ec_vboot_hash_cmd */
@@ -1463,7 +2154,7 @@ struct ec_params_vboot_hash { · 3 unmodified lines
14632154 uint32_t offset; /* Offset in flash to hash */
14642155 uint32_t size; /* Number of bytes to hash */
14652156 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1466−} __packed;
2157+} __ec_align4;
14672158
14682159 struct ec_response_vboot_hash {
14692160 uint8_t status; /* enum ec_vboot_hash_status */
@@ -1473,7 +2164,7 @@ struct ec_response_vboot_hash { · 3 unmodified lines
14732164 uint32_t offset; /* Offset in flash which was hashed */
14742165 uint32_t size; /* Number of bytes hashed */
14752166 uint8_t hash_digest[64]; /* Hash digest data */
1476−} __packed;
2167+} __ec_align4;
14772168
14782169 enum ec_vboot_hash_cmd {
14792170 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
@@ -1497,15 +2188,22 @@ enum ec_vboot_hash_status { · 17 unmodified lines
14972188 * If one of these is specified, the EC will automatically update offset and
14982189 * size to the correct values for the specified image (RO or RW).
14992190 */
1500−#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1501−#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
2191+#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
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
15022200
15032201 /*****************************************************************************/
15042202 /*
15052203 * Motion sense commands. We'll make separate structs for sub-commands with
15062204 * different input args, so that we know how much to expect.
15072205 */
1508−#define EC_CMD_MOTION_SENSE_CMD 0x2B
2206+#define EC_CMD_MOTION_SENSE_CMD 0x002B
15092207
15102208 /* Motion sense commands */
15112209 enum motionsense_command {
@@ -1524,7 +2222,13 @@ enum motionsense_command { · 12 unmodified lines
15242222
15252223 /*
15262224 * EC Rate command is a setter/getter command for the EC sampling rate
1527− * 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.
15282232 */
15292233 MOTIONSENSE_CMD_EC_RATE = 2,
15302234
@@ -1555,32 +2259,76 @@ enum motionsense_command { · 24 unmodified lines
15552259 MOTIONSENSE_CMD_DATA = 6,
15562260
15572261 /*
1558− * Perform low level calibration.. On sensors that support it, ask to
1559− * do offset calibration.
2262+ * Return sensor fifo info.
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.
15602280 */
15612281 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
15622282
15632283 /*
1564− * Sensor Offset command is a setter/getter command for the offset used
1565− * for calibration. The offsets can be calculated by the host, or via
2284+ * Sensor Offset command is a setter/getter command for the offset
2285+ * used for calibration.
2286+ * The offsets can be calculated by the host, or via
15662287 * PERFORM_CALIB command.
15672288 */
15682289 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
15692290
1570− /* Number of motionsense sub-commands. */
1571− MOTIONSENSE_NUM_CMDS
1572−};
2291+ /*
2292+ * List available activities for a MOTION sensor.
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,
15732314
1574−enum motionsensor_id {
1575− EC_MOTION_SENSOR_ACCEL_BASE = 0,
1576− EC_MOTION_SENSOR_ACCEL_LID = 1,
1577− EC_MOTION_SENSOR_GYRO = 2,
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,
2320+
2321+ /* Set lid angle for tablet mode detection. */
2322+ MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
15782323
15792324 /*
1580− * Note, if more sensors are added and this count changes, the padding
1581− * in ec_response_motion_sense dump command must be modified.
2325+ * Sensor Scale command is a setter/getter command for the calibration
2326+ * scale.
15822327 */
1583− EC_MOTION_SENSOR_COUNT = 3
2328+ MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2329+
2330+ /* Number of motionsense sub-commands. */
2331+ MOTIONSENSE_NUM_CMDS
15842332 };
15852333
15862334 /* List of motion sensor types. */
@@ -1592,6 +2340,7 @@ enum motionsensor_type { · 5 unmodified lines
15922340 MOTIONSENSE_TYPE_LIGHT = 4,
15932341 MOTIONSENSE_TYPE_ACTIVITY = 5,
15942342 MOTIONSENSE_TYPE_BARO = 6,
2343+ MOTIONSENSE_TYPE_SYNC = 7,
15952344 MOTIONSENSE_TYPE_MAX,
15962345 };
15972346
@@ -1599,19 +2348,116 @@ enum motionsensor_type { · 1 unmodified line
15992348 enum motionsensor_location {
16002349 MOTIONSENSE_LOC_BASE = 0,
16012350 MOTIONSENSE_LOC_LID = 1,
2351+ MOTIONSENSE_LOC_CAMERA = 2,
16022352 MOTIONSENSE_LOC_MAX,
16032353 };
16042354
16052355 /* List of motion sensor chips. */
16062356 enum motionsensor_chip {
16072357 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 */
2381+enum 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+
2389+struct 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 */
2410+struct 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+
2425+struct 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 */
2431+enum motionsensor_activity {
2432+ MOTIONSENSE_ACTIVITY_RESERVED = 0,
2433+ MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2434+ MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2435+ MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
16082436 };
16092437
2438+struct 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+
16102446 /* Module flag masks used for the dump sub-command. */
1611−#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2447+#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
16122448
16132449 /* Sensor flag masks used for the dump sub-command. */
1614−#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)
16152461
16162462 /*
16172463 * Send this value for the data element to only perform a read. If you
@@ -1622,48 +2468,79 @@ enum motionsensor_chip { · 4 unmodified lines
16222468
16232469 #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
16242470
2471+/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
16252472 /* Set Calibration information */
1626−#define MOTION_SENSE_SET_OFFSET 1
2473+#define MOTION_SENSE_SET_OFFSET BIT(0)
16272474
1628−struct ec_response_motion_sensor_data {
1629− /* Flags for each sensor. */
1630− uint8_t flags;
1631− /* Sensor number the data comes from */
1632− uint8_t sensor_num;
1633− /* Each sensor is up to 3-axis. */
1634− union {
1635− int16_t data[3];
1636− struct {
1637− uint16_t rsvd;
1638− uint32_t timestamp;
1639− } __packed;
1640− struct {
1641− uint8_t activity; /* motionsensor_activity */
1642− uint8_t state;
1643− int16_t add_info[2];
1644− };
1645− };
1646−} __packed;
2475+/* Default Scale value, factor 1. */
2476+#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
2477+
2478+#define LID_ANGLE_UNRELIABLE 500
2479+
2480+enum motionsense_spoof_mode {
2481+ /* Disable spoof mode. */
2482+ MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2483+
2484+ /* Enable spoof mode, but use provided component values. */
2485+ MOTIONSENSE_SPOOF_MODE_CUSTOM,
2486+
2487+ /* Enable spoof mode, but use the current sensor values. */
2488+ MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2489+
2490+ /* Query the current spoof mode status for the sensor. */
2491+ MOTIONSENSE_SPOOF_MODE_QUERY,
2492+};
16472493
16482494 struct ec_params_motion_sense {
16492495 uint8_t cmd;
16502496 union {
16512497 /* Used for MOTIONSENSE_CMD_DUMP. */
1652− struct {
1653− /* no args */
2498+ struct __ec_todo_unpacked {
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;
16542505 } dump;
16552506
16562507 /*
1657− * Used for MOTIONSENSE_CMD_EC_RATE and
1658− * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2508+ * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
16592509 */
1660− struct {
1661− /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2510+ struct __ec_todo_unpacked {
2511+ /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2512+ * kb_wake_angle: angle to wakup AP.
2513+ */
16622514 int16_t data;
1663− } 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;
16642541
16652542 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1666− struct {
2543+ struct __ec_todo_packed {
16672544 uint8_t sensor_num;
16682545
16692546 /*
@@ -1689,36 +2566,102 @@ struct ec_params_motion_sense { · 19 unmodified lines
16892566 * Compass: 1/16 uT
16902567 */
16912568 int16_t offset[3];
1692− } __packed sensor_offset;
2569+ } sensor_offset;
16932570
1694− /* Used for MOTIONSENSE_CMD_INFO. */
1695− struct {
2571+ /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2572+ struct __ec_todo_packed {
16962573 uint8_t sensor_num;
1697− } info;
16982574
1699− /*
1700− * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1701− * MOTIONSENSE_CMD_SENSOR_RANGE.
1702− */
1703− struct {
1704− /* Should be element of enum motionsensor_id. */
1705− uint8_t sensor_num;
2575+ /*
2576+ * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2577+ * the calibration information in the EC.
2578+ * If unset, just retrieve calibration information.
2579+ */
2580+ uint16_t flags;
17062581
1707− /* Rounding flag, true for round-up, false for down. */
1708− uint8_t roundup;
2582+ /*
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;
17092589
1710− 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;
17112599
1712− /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1713− int32_t data;
1714− } sensor_odr, sensor_range;
2600+
2601+ /* Used for MOTIONSENSE_CMD_FIFO_INFO */
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;
17152658 };
1716−} __packed;
2659+} __ec_todo_packed;
17172660
17182661 struct ec_response_motion_sense {
17192662 union {
1720− /* Used for MOTIONSENSE_CMD_DUMP. */
1721− struct {
2663+ /* Used for MOTIONSENSE_CMD_DUMP */
2664+ struct __ec_todo_unpacked {
17222665 /* Flags representing the motion sensor module. */
17232666 uint8_t module_flags;
17242667
@@ -1733,7 +2676,7 @@ struct ec_response_motion_sense { · 8 unmodified lines
17332676 } dump;
17342677
17352678 /* Used for MOTIONSENSE_CMD_INFO. */
1736− struct {
2679+ struct __ec_todo_unpacked {
17372680 /* Should be element of enum motionsensor_type. */
17382681 uint8_t type;
17392682
@@ -1744,74 +2687,166 @@ struct ec_response_motion_sense { · 4 unmodified lines
17442687 uint8_t chip;
17452688 } info;
17462689
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+
17472711 /* Used for MOTIONSENSE_CMD_DATA */
17482712 struct ec_response_motion_sensor_data data;
17492713
17502714 /*
17512715 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1752− * MOTIONSENSE_CMD_SENSOR_RANGE, and
1753− * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2716+ * MOTIONSENSE_CMD_SENSOR_RANGE,
2717+ * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2718+ * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2719+ * MOTIONSENSE_CMD_SPOOF.
17542720 */
1755− struct {
2721+ struct __ec_todo_unpacked {
17562722 /* Current value of the parameter queried. */
17572723 int32_t ret;
1758− } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
2724+ } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2725+ fifo_int_enable, spoof;
17592726
1760− /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1761− struct {
2727+ /*
2728+ * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
2729+ * PERFORM_CALIB.
2730+ */
2731+ struct __ec_todo_unpacked {
17622732 int16_t temp;
17632733 int16_t offset[3];
17642734 } sensor_offset, perform_calib;
1765− };
1766−} __packed;
17672735
1768−/*****************************************************************************/
1769−/* USB charging control commands */
2736+ /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2737+ struct __ec_todo_unpacked {
2738+ int16_t temp;
2739+ uint16_t scale[3];
2740+ } sensor_scale;
17702741
1771−/* Set USB port charging mode */
1772−#define EC_CMD_USB_CHARGE_SET_MODE 0x30
2742+ struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
17732743
1774−struct ec_params_usb_charge_set_mode {
1775− uint8_t usb_port_id;
1776− uint8_t mode;
1777−} __packed;
2744+ struct ec_response_motion_sense_fifo_data fifo_read;
17782745
1779−/*****************************************************************************/
1780−/* Persistent storage for host */
2746+ struct __ec_todo_packed {
2747+ uint16_t reserved;
2748+ uint32_t enabled;
2749+ uint32_t disabled;
2750+ } list_activities;
17812751
1782−/* Maximum bytes that can be read/written in a single command */
1783−#define EC_PSTORE_SIZE_MAX 64
2752+ /* No params for set activity */
17842753
1785−/* Get persistent storage info */
1786−#define EC_CMD_PSTORE_INFO 0x40
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;
17872762
1788−struct ec_response_pstore_info {
1789− /* Persistent storage size, in bytes */
1790− uint32_t pstore_size;
1791− /* Access size; read/write offset and size must be a multiple of this */
1792− uint32_t access_size;
1793−} __packed;
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+
2775+ };
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+
2784+struct 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+
2792+enum ec_config_power_button_flags {
2793+ /* Enable/Disable power button pulses for x86 devices */
2794+ EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
2795+};
2796+
2797+struct ec_params_config_power_button {
2798+ /* See enum ec_config_power_button_flags */
2799+ uint8_t flags;
2800+} __ec_align1;
2801+
2802+/*****************************************************************************/
2803+/* USB charging control commands */
2804+
2805+/* Set USB port charging mode */
2806+#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
2807+
2808+struct ec_params_usb_charge_set_mode {
2809+ uint8_t usb_port_id;
2810+ uint8_t mode:7;
2811+ uint8_t inhibit_charge:1;
2812+} __ec_align1;
2813+
2814+/*****************************************************************************/
2815+/* Persistent storage for host */
2816+
2817+/* Maximum bytes that can be read/written in a single command */
2818+#define EC_PSTORE_SIZE_MAX 64
2819+
2820+/* Get persistent storage info */
2821+#define EC_CMD_PSTORE_INFO 0x0040
2822+
2823+struct ec_response_pstore_info {
2824+ /* Persistent storage size, in bytes */
2825+ uint32_t pstore_size;
2826+ /* Access size; read/write offset and size must be a multiple of this */
2827+ uint32_t access_size;
2828+} __ec_align4;
17942829
17952830 /*
17962831 * Read persistent storage
17972832 *
17982833 * Response is params.size bytes of data.
17992834 */
1800−#define EC_CMD_PSTORE_READ 0x41
2835+#define EC_CMD_PSTORE_READ 0x0041
18012836
18022837 struct ec_params_pstore_read {
18032838 uint32_t offset; /* Byte offset to read */
18042839 uint32_t size; /* Size to read in bytes */
1805−} __packed;
2840+} __ec_align4;
18062841
18072842 /* Write persistent storage */
1808−#define EC_CMD_PSTORE_WRITE 0x42
2843+#define EC_CMD_PSTORE_WRITE 0x0042
18092844
18102845 struct ec_params_pstore_write {
18112846 uint32_t offset; /* Byte offset to write */
18122847 uint32_t size; /* Size to write in bytes */
18132848 uint8_t data[EC_PSTORE_SIZE_MAX];
1814−} __packed;
2849+} __ec_align4;
18152850
18162851 /*****************************************************************************/
18172852 /* Real-time clock */
@@ -1819,21 +2854,21 @@ struct ec_params_pstore_write { · 1 unmodified line
18192854 /* RTC params and response structures */
18202855 struct ec_params_rtc {
18212856 uint32_t time;
1822−} __packed;
2857+} __ec_align4;
18232858
18242859 struct ec_response_rtc {
18252860 uint32_t time;
1826−} __packed;
2861+} __ec_align4;
18272862
18282863 /* These use ec_response_rtc */
1829−#define EC_CMD_RTC_GET_VALUE 0x44
1830−#define EC_CMD_RTC_GET_ALARM 0x45
2864+#define EC_CMD_RTC_GET_VALUE 0x0044
2865+#define EC_CMD_RTC_GET_ALARM 0x0045
18312866
18322867 /* These all use ec_params_rtc */
1833−#define EC_CMD_RTC_SET_VALUE 0x46
1834−#define EC_CMD_RTC_SET_ALARM 0x47
2868+#define EC_CMD_RTC_SET_VALUE 0x0046
2869+#define EC_CMD_RTC_SET_ALARM 0x0047
18352870
1836−/* Pass as param to SET_ALARM to clear the current alarm */
2871+/* Pass as time param to SET_ALARM to clear the current alarm */
18372872 #define EC_RTC_ALARM_CLEAR 0
18382873
18392874 /*****************************************************************************/
@@ -1843,8 +2878,8 @@ struct ec_response_rtc { · 3 unmodified lines
18432878 #define EC_PORT80_SIZE_MAX 32
18442879
18452880 /* Get last port80 code from previous boot */
1846−#define EC_CMD_PORT80_LAST_BOOT 0x48
1847−#define EC_CMD_PORT80_READ 0x48
2881+#define EC_CMD_PORT80_LAST_BOOT 0x0048
2882+#define EC_CMD_PORT80_READ 0x0048
18482883
18492884 enum ec_port80_subcmd {
18502885 EC_PORT80_GET_INFO = 0,
@@ -1854,29 +2889,72 @@ enum ec_port80_subcmd { · 3 unmodified lines
18542889 struct ec_params_port80_read {
18552890 uint16_t subcmd;
18562891 union {
1857− struct {
2892+ struct __ec_todo_unpacked {
18582893 uint32_t offset;
18592894 uint32_t num_entries;
18602895 } read_buffer;
18612896 };
1862−} __packed;
2897+} __ec_todo_packed;
18632898
18642899 struct ec_response_port80_read {
18652900 union {
1866− struct {
2901+ struct __ec_todo_unpacked {
18672902 uint32_t writes;
18682903 uint32_t history_size;
18692904 uint32_t last_boot;
18702905 } get_info;
1871− struct {
2906+ struct __ec_todo_unpacked {
18722907 uint16_t codes[EC_PORT80_SIZE_MAX];
18732908 } data;
18742909 };
1875−} __packed;
2910+} __ec_todo_packed;
18762911
18772912 struct ec_response_port80_last_boot {
18782913 uint16_t code;
1879−} __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
2927+struct 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+
2941+struct ec_params_vstore_read {
2942+ uint8_t slot; /* Slot to read from */
2943+} __ec_align1;
2944+
2945+struct 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+
2954+struct ec_params_vstore_write {
2955+ uint8_t slot; /* Slot to write to */
2956+ uint8_t data[EC_VSTORE_SLOT_SIZE];
2957+} __ec_align1;
18802958
18812959 /*****************************************************************************/
18822960 /* Thermal engine commands. Note that there are two implementations. We'll
@@ -1885,8 +2963,8 @@ struct ec_response_port80_last_boot { · 2 unmodified lines
18852963 * Version 1 separates the CPU thermal limits from the fan control.
18862964 */
18872965
1888−#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
1889−#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
2966+#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2967+#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
18902968
18912969 /* The version 0 structs are opaque. You have to know what they are for
18922970 * the get/set commands to make any sense.
@@ -1897,17 +2975,17 @@ struct ec_params_thermal_set_threshold { · 4 unmodified lines
18972975 uint8_t sensor_type;
18982976 uint8_t threshold_id;
18992977 uint16_t value;
1900−} __packed;
2978+} __ec_align2;
19012979
19022980 /* Version 0 - get */
19032981 struct ec_params_thermal_get_threshold {
19042982 uint8_t sensor_type;
19052983 uint8_t threshold_id;
1906−} __packed;
2984+} __ec_align1;
19072985
19082986 struct ec_response_thermal_get_threshold {
19092987 uint16_t value;
1910−} __packed;
2988+} __ec_align2;
19112989
19122990
19132991 /* The version 1 structs are visible. */
@@ -1919,71 +2997,124 @@ enum ec_temp_thresholds { · 5 unmodified lines
19192997 EC_TEMP_THRESH_COUNT
19202998 };
19212999
1922−/* Thermal configuration for one temperature sensor. Temps are in degrees K.
3000+/*
3001+ * Thermal configuration for one temperature sensor. Temps are in degrees K.
19233002 * 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.
19243021 */
19253022 struct ec_thermal_config {
19263023 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
3024+ uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
19273025 uint32_t temp_fan_off; /* no active cooling needed */
19283026 uint32_t temp_fan_max; /* max active cooling needed */
1929−} __packed;
3027+} __ec_align4;
19303028
19313029 /* Version 1 - get config for one sensor. */
19323030 struct ec_params_thermal_get_threshold_v1 {
19333031 uint32_t sensor_num;
1934−} __packed;
3032+} __ec_align4;
19353033 /* This returns a struct ec_thermal_config */
19363034
1937−/* Version 1 - set config for one sensor.
1938− * Use read-modify-write for best results! */
3035+/*
3036+ * Version 1 - set config for one sensor.
3037+ * Use read-modify-write for best results!
3038+ */
19393039 struct ec_params_thermal_set_threshold_v1 {
19403040 uint32_t sensor_num;
19413041 struct ec_thermal_config cfg;
1942−} __packed;
3042+} __ec_align4;
19433043 /* This returns no data */
19443044
19453045 /****************************************************************************/
19463046
19473047 /* Toggle automatic fan control */
1948−#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
3048+#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
3049+
3050+/* Version 1 of input params */
3051+struct ec_params_auto_fan_ctrl_v1 {
3052+ uint8_t fan_idx;
3053+} __ec_align1;
19493054
1950−/* Get TMP006 calibration data */
1951−#define EC_CMD_TMP006_GET_CALIBRATION 0x53
3055+/* Get/Set TMP006 calibration data */
3056+#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3057+#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
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+ */
19523067
3068+/* This is the same struct for both v0 and v1. */
19533069 struct ec_params_tmp006_get_calibration {
19543070 uint8_t index;
1955−} __packed;
3071+} __ec_align1;
19563072
1957−struct ec_response_tmp006_get_calibration {
3073+/* Version 0 */
3074+struct ec_response_tmp006_get_calibration_v0 {
19583075 float s0;
19593076 float b0;
19603077 float b1;
19613078 float b2;
1962−} __packed;
1963−
1964−/* Set TMP006 calibration data */
1965−#define EC_CMD_TMP006_SET_CALIBRATION 0x54
3079+} __ec_align4;
19663080
1967−struct ec_params_tmp006_set_calibration {
3081+struct ec_params_tmp006_set_calibration_v0 {
19683082 uint8_t index;
1969− uint8_t reserved[3]; /* Reserved; set 0 */
3083+ uint8_t reserved[3];
19703084 float s0;
19713085 float b0;
19723086 float b1;
19733087 float b2;
1974−} __packed;
3088+} __ec_align4;
3089+
3090+/* Version 1 */
3091+struct 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+
3098+struct 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+
19753106
19763107 /* Read raw TMP006 data */
1977−#define EC_CMD_TMP006_GET_RAW 0x55
3108+#define EC_CMD_TMP006_GET_RAW 0x0055
19783109
19793110 struct ec_params_tmp006_get_raw {
19803111 uint8_t index;
1981−} __packed;
3112+} __ec_align1;
19823113
19833114 struct ec_response_tmp006_get_raw {
19843115 int32_t t; /* In 1/100 K */
19853116 int32_t v; /* In nV */
1986−};
3117+} __ec_align4;
19873118
19883119 /*****************************************************************************/
19893120 /* MKBP - Matrix KeyBoard Protocol */
@@ -1998,24 +3129,24 @@ struct ec_response_tmp006_get_raw { · 8 unmodified lines
19983129 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
19993130 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
20003131 */
2001−#define EC_CMD_MKBP_STATE 0x60
3132+#define EC_CMD_MKBP_STATE 0x0060
20023133
20033134 /*
20043135 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
20053136 */
2006−#define EC_CMD_MKBP_INFO 0x61
3137+#define EC_CMD_MKBP_INFO 0x0061
20073138
20083139 struct ec_response_mkbp_info {
20093140 uint32_t rows;
20103141 uint32_t cols;
20113142 /* Formerly "switches", which was 0. */
20123143 uint8_t reserved;
2013−} __packed;
3144+} __ec_align_size1;
20143145
20153146 struct ec_params_mkbp_info {
20163147 uint8_t info_type;
20173148 uint8_t event_type;
2018−} __packed;
3149+} __ec_align1;
20193150
20203151 enum ec_mkbp_info_type {
20213152 /*
@@ -2057,17 +3188,28 @@ enum ec_mkbp_info_type { · 35 unmodified lines
20573188 };
20583189
20593190 /* Simulate key press */
2060−#define EC_CMD_MKBP_SIMULATE_KEY 0x62
3191+#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
20613192
20623193 struct ec_params_mkbp_simulate_key {
20633194 uint8_t col;
20643195 uint8_t row;
20653196 uint8_t pressed;
2066−} __packed;
3197+} __ec_align1;
3198+
3199+#define EC_CMD_GET_KEYBOARD_ID 0x0063
3200+
3201+struct ec_response_keyboard_id {
3202+ uint32_t keyboard_id;
3203+} __ec_align4;
3204+
3205+enum keyboard_id {
3206+ KEYBOARD_ID_UNSUPPORTED = 0,
3207+ KEYBOARD_ID_UNREADABLE = 0xffffffff,
3208+};
20673209
20683210 /* Configure keyboard scanning */
2069−#define EC_CMD_MKBP_SET_CONFIG 0x64
2070−#define EC_CMD_MKBP_GET_CONFIG 0x65
3211+#define EC_CMD_MKBP_SET_CONFIG 0x0064
3212+#define EC_CMD_MKBP_GET_CONFIG 0x0065
20713213
20723214 /* flags */
20733215 enum mkbp_config_flags {
@@ -2075,16 +3217,21 @@ enum mkbp_config_flags { · 1 unmodified line
20753217 };
20763218
20773219 enum mkbp_config_valid {
2078− EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2079− EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2080− EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2081− EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2082− EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2083− EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2084− EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
3220+ EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3221+ EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3222+ EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3223+ EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3224+ EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3225+ EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3226+ EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
20853227 };
20863228
2087−/* 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+ */
20883235 struct ec_mkbp_config {
20893236 uint32_t valid_mask; /* valid fields */
20903237 uint8_t flags; /* some flags (enum mkbp_config_flags) */
@@ -2104,18 +3251,18 @@ struct ec_mkbp_config { · 13 unmodified lines
21043251 uint16_t debounce_up_us; /* time for debounce on key up */
21053252 /* maximum depth to allow for fifo (0 = no keyscan output) */
21063253 uint8_t fifo_max_depth;
2107−} __packed;
3254+} __ec_align_size1;
21083255
21093256 struct ec_params_mkbp_set_config {
21103257 struct ec_mkbp_config config;
2111−} __packed;
3258+} __ec_align_size1;
21123259
21133260 struct ec_response_mkbp_get_config {
21143261 struct ec_mkbp_config config;
2115−} __packed;
3262+} __ec_align_size1;
21163263
21173264 /* Run the key scan emulation */
2118−#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
3265+#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
21193266
21203267 enum ec_keyscan_seq_cmd {
21213268 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
@@ -2130,23 +3277,23 @@ enum ec_collect_flags { · 8 unmodified lines
21303277 * Indicates this scan was processed by the EC. Due to timing, some
21313278 * scans may be skipped.
21323279 */
2133− EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
3280+ EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
21343281 };
21353282
21363283 struct ec_collect_item {
21373284 uint8_t flags; /* some flags (enum ec_collect_flags) */
2138−};
3285+} __ec_align1;
21393286
21403287 struct ec_params_keyscan_seq_ctrl {
21413288 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
21423289 union {
2143− struct {
3290+ struct __ec_align1 {
21443291 uint8_t active; /* still active */
21453292 uint8_t num_items; /* number of items */
21463293 /* Current item being presented */
21473294 uint8_t cur_item;
21483295 } status;
2149− struct {
3296+ struct __ec_todo_unpacked {
21503297 /*
21513298 * Absolute time for this scan, measured from the
21523299 * start of the sequence.
@@ -2154,29 +3301,40 @@ struct ec_params_keyscan_seq_ctrl { · 1 unmodified line
21543301 uint32_t time_us;
21553302 uint8_t scan[0]; /* keyscan data */
21563303 } add;
2157− struct {
3304+ struct __ec_align1 {
21583305 uint8_t start_item; /* First item to return */
21593306 uint8_t num_items; /* Number of items to return */
21603307 } collect;
21613308 };
2162−} __packed;
3309+} __ec_todo_packed;
21633310
21643311 struct ec_result_keyscan_seq_ctrl {
21653312 union {
2166− struct {
3313+ struct __ec_todo_unpacked {
21673314 uint8_t num_items; /* Number of items */
21683315 /* Data for each item */
21693316 struct ec_collect_item item[0];
21703317 } collect;
21713318 };
2172−} __packed;
3319+} __ec_todo_packed;
21733320
21743321 /*
2175− * Command for retrieving the next pending MKBP event from the EC device
3322+ * Get the next pending MKBP event.
21763323 *
2177− * The device replies with UNAVAILABLE if there aren't any pending events.
3324+ * Returns EC_RES_UNAVAILABLE if there is no event pending.
3325+ */
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.
21783333 */
2179−#define EC_CMD_GET_NEXT_EVENT 0x67
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)
21803338
21813339 enum ec_mkbp_event {
21823340 /* Keyboard matrix changed. The event data is the new matrix state. */
@@ -2194,9 +3352,21 @@ enum ec_mkbp_event { · 11 unmodified lines
21943352 /* The state of the switches have changed. */
21953353 EC_MKBP_EVENT_SWITCH = 4,
21963354
2197− /* 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+ */
21983362 EC_MKBP_EVENT_SYSRQ = 6,
21993363
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+
22003370 /* Notify the AP that something happened on CEC */
22013371 EC_MKBP_EVENT_CEC_EVENT = 8,
22023372
@@ -2206,65 +3376,140 @@ enum ec_mkbp_event { · 3 unmodified lines
22063376 /* Number of MKBP events */
22073377 EC_MKBP_EVENT_COUNT,
22083378 };
3379+BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
22093380
2210−union ec_response_get_next_data {
2211− uint8_t key_matrix[13];
3381+union __ec_align_offset1 ec_response_get_next_data {
3382+ uint8_t key_matrix[13];
22123383
22133384 /* Unaligned */
2214− uint32_t host_event;
3385+ uint32_t host_event;
3386+ uint64_t host_event64;
22153387
2216− uint32_t buttons;
2217− uint32_t switches;
2218− uint32_t sysrq;
2219−} __packed;
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;
22203393
2221−union ec_response_get_next_data_v1 {
3394+ uint32_t buttons;
3395+
3396+ uint32_t switches;
3397+
3398+ uint32_t fp_events;
3399+
3400+ uint32_t sysrq;
3401+
3402+ /* CEC events from enum mkbp_cec_event */
3403+ uint32_t cec_events;
3404+};
3405+
3406+union __ec_align_offset1 ec_response_get_next_data_v1 {
22223407 uint8_t key_matrix[16];
3408+
3409+ /* Unaligned */
22233410 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+
22243419 uint32_t buttons;
3420+
22253421 uint32_t switches;
3422+
3423+ uint32_t fp_events;
3424+
22263425 uint32_t sysrq;
3426+
3427+ /* CEC events from enum mkbp_cec_event */
22273428 uint32_t cec_events;
3429+
22283430 uint8_t cec_message[16];
2229−} __packed;
3431+};
3432+BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
22303433
22313434 struct ec_response_get_next_event {
22323435 uint8_t event_type;
22333436 /* Followed by event data if any */
22343437 union ec_response_get_next_data data;
2235−} __packed;
3438+} __ec_align1;
22363439
22373440 struct ec_response_get_next_event_v1 {
22383441 uint8_t event_type;
22393442 /* Followed by event data if any */
22403443 union ec_response_get_next_data_v1 data;
2241−} __packed;
3444+} __ec_align1;
22423445
22433446 /* Bit indices for buttons and switches.*/
22443447 /* Buttons */
22453448 #define EC_MKBP_POWER_BUTTON 0
22463449 #define EC_MKBP_VOL_UP 1
22473450 #define EC_MKBP_VOL_DOWN 2
3451+#define EC_MKBP_RECOVERY 3
22483452
22493453 /* Switches */
22503454 #define EC_MKBP_LID_OPEN 0
22513455 #define EC_MKBP_TABLET_MODE 1
22523456 #define EC_MKBP_BASE_ATTACHED 2
22533457
3458+/* Run keyboard factory test scanning */
3459+#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3460+
3461+struct 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+
22543499 /*****************************************************************************/
22553500 /* Temperature sensor commands */
22563501
22573502 /* Read temperature sensor info */
2258−#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
3503+#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
22593504
22603505 struct ec_params_temp_sensor_get_info {
22613506 uint8_t id;
2262−} __packed;
3507+} __ec_align1;
22633508
22643509 struct ec_response_temp_sensor_get_info {
22653510 char sensor_name[32];
22663511 uint8_t sensor_type;
2267−} __packed;
3512+} __ec_align1;
22683513
22693514 /*****************************************************************************/
22703515
@@ -2277,49 +3522,131 @@ struct ec_response_temp_sensor_get_info { · 6 unmodified lines
22773522 /*****************************************************************************/
22783523 /* Host event commands */
22793524
3525+
3526+/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
22803527 /*
22813528 * Host event mask params and response structures, shared by all of the host
22823529 * event commands below.
22833530 */
22843531 struct ec_params_host_event_mask {
22853532 uint32_t mask;
2286−} __packed;
3533+} __ec_align4;
22873534
22883535 struct ec_response_host_event_mask {
22893536 uint32_t mask;
2290−} __packed;
3537+} __ec_align4;
22913538
22923539 /* These all use ec_response_host_event_mask */
2293−#define EC_CMD_HOST_EVENT_GET_B 0x87
2294−#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2295−#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2296−#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
3540+#define EC_CMD_HOST_EVENT_GET_B 0x0087
3541+#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3542+#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3543+#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
22973544
22983545 /* These all use ec_params_host_event_mask */
2299−#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2300−#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2301−#define EC_CMD_HOST_EVENT_CLEAR 0x8c
2302−#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2303−#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
3546+#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3547+#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3548+#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3549+#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
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+
3557+struct 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+
3580+struct ec_response_host_event {
3581+
3582+ /* Mask value in case of get operation */
3583+ uint64_t value;
3584+} __ec_align4;
3585+
3586+enum 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+
3600+enum 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
23043631
23053632 /*****************************************************************************/
23063633 /* Switch commands */
23073634
23083635 /* Enable/disable LCD backlight */
2309−#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
3636+#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
23103637
23113638 struct ec_params_switch_enable_backlight {
23123639 uint8_t enabled;
2313−} __packed;
3640+} __ec_align1;
23143641
23153642 /* Enable/disable WLAN/Bluetooth */
2316−#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
3643+#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
23173644 #define EC_VER_SWITCH_ENABLE_WIRELESS 1
23183645
23193646 /* Version 0 params; no response */
23203647 struct ec_params_switch_enable_wireless_v0 {
23213648 uint8_t enabled;
2322−} __packed;
3649+} __ec_align1;
23233650
23243651 /* Version 1 params */
23253652 struct ec_params_switch_enable_wireless_v1 {
@@ -2338,7 +3665,7 @@ struct ec_params_switch_enable_wireless_v1 { · 12 unmodified lines
23383665
23393666 /* Which flags to copy from suspend_flags */
23403667 uint8_t suspend_mask;
2341−} __packed;
3668+} __ec_align1;
23423669
23433670 /* Version 1 response */
23443671 struct ec_response_switch_enable_wireless_v1 {
@@ -2347,55 +3674,56 @@ struct ec_response_switch_enable_wireless_v1 { · 2 unmodified lines
23473674
23483675 /* Flags to leave enabled in S3 */
23493676 uint8_t suspend_flags;
2350−} __packed;
3677+} __ec_align1;
23513678
23523679 /*****************************************************************************/
23533680 /* GPIO commands. Only available on EC if write protect has been disabled. */
23543681
23553682 /* Set GPIO output value */
2356−#define EC_CMD_GPIO_SET 0x92
3683+#define EC_CMD_GPIO_SET 0x0092
23573684
23583685 struct ec_params_gpio_set {
23593686 char name[32];
23603687 uint8_t val;
2361−} __packed;
3688+} __ec_align1;
23623689
23633690 /* Get GPIO value */
2364−#define EC_CMD_GPIO_GET 0x93
3691+#define EC_CMD_GPIO_GET 0x0093
23653692
23663693 /* Version 0 of input params and response */
23673694 struct ec_params_gpio_get {
23683695 char name[32];
2369−} __packed;
3696+} __ec_align1;
3697+
23703698 struct ec_response_gpio_get {
23713699 uint8_t val;
2372−} __packed;
3700+} __ec_align1;
23733701
23743702 /* Version 1 of input params and response */
23753703 struct ec_params_gpio_get_v1 {
23763704 uint8_t subcmd;
23773705 union {
2378− struct {
3706+ struct __ec_align1 {
23793707 char name[32];
23803708 } get_value_by_name;
2381− struct {
3709+ struct __ec_align1 {
23823710 uint8_t index;
23833711 } get_info;
23843712 };
2385−} __packed;
3713+} __ec_align1;
23863714
23873715 struct ec_response_gpio_get_v1 {
23883716 union {
2389− struct {
3717+ struct __ec_align1 {
23903718 uint8_t val;
23913719 } get_value_by_name, get_count;
2392− struct {
3720+ struct __ec_todo_unpacked {
23933721 uint8_t val;
23943722 char name[32];
23953723 uint32_t flags;
23963724 } get_info;
23973725 };
2398−} __packed;
3726+} __ec_todo_packed;
23993727
24003728 enum gpio_get_subcmd {
24013729 EC_GPIO_GET_BY_NAME = 0,
@@ -2407,25 +3735,28 @@ enum gpio_get_subcmd { · 5 unmodified lines
24073735 /* I2C commands. Only available when flash write protect is unlocked. */
24083736
24093737 /*
2410− * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2411− * removed soon. Use EC_CMD_I2C_XFER instead.
3738+ * CAUTION: These commands are deprecated, and are not supported anymore in EC
3739+ * builds >= 8398.0.0 (see crosbug.com/p/23570).
3740+ *
3741+ * Use EC_CMD_I2C_PASSTHRU instead.
24123742 */
24133743
24143744 /* Read I2C bus */
2415−#define EC_CMD_I2C_READ 0x94
3745+#define EC_CMD_I2C_READ 0x0094
24163746
24173747 struct ec_params_i2c_read {
24183748 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
24193749 uint8_t read_size; /* Either 8 or 16. */
24203750 uint8_t port;
24213751 uint8_t offset;
2422−} __packed;
3752+} __ec_align_size1;
3753+
24233754 struct ec_response_i2c_read {
24243755 uint16_t data;
2425−} __packed;
3756+} __ec_align2;
24263757
24273758 /* Write I2C bus */
2428−#define EC_CMD_I2C_WRITE 0x95
3759+#define EC_CMD_I2C_WRITE 0x0095
24293760
24303761 struct ec_params_i2c_write {
24313762 uint16_t data;
@@ -2433,7 +3764,7 @@ struct ec_params_i2c_write { · 1 unmodified line
24333764 uint8_t write_size; /* Either 8 or 16. */
24343765 uint8_t port;
24353766 uint8_t offset;
2436−} __packed;
3767+} __ec_align_size1;
24373768
24383769 /*****************************************************************************/
24393770 /* Charge state commands. Only available when flash write protect unlocked. */
@@ -2441,7 +3772,7 @@ struct ec_params_i2c_write { · 1 unmodified line
24413772 /* Force charge state machine to stop charging the battery or force it to
24423773 * discharge the battery.
24433774 */
2444−#define EC_CMD_CHARGE_CONTROL 0x96
3775+#define EC_CMD_CHARGE_CONTROL 0x0096
24453776 #define EC_VER_CHARGE_CONTROL 1
24463777
24473778 enum ec_charge_control_mode {
@@ -2452,13 +3783,12 @@ enum ec_charge_control_mode { · 4 unmodified lines
24523783
24533784 struct ec_params_charge_control {
24543785 uint32_t mode; /* enum charge_control_mode */
2455−} __packed;
3786+} __ec_align4;
24563787
24573788 /*****************************************************************************/
2458−/* Console commands. Only available when flash write protect is unlocked. */
24593789
24603790 /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2461−#define EC_CMD_CONSOLE_SNAPSHOT 0x97
3791+#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
24623792
24633793 /*
24643794 * Read data from the saved snapshot. If the subcmd parameter is
@@ -2472,7 +3802,7 @@ struct ec_params_charge_control { · 7 unmodified lines
24723802 * Response is null-terminated string. Empty string, if there is no more
24733803 * remaining output.
24743804 */
2475−#define EC_CMD_CONSOLE_READ 0x98
3805+#define EC_CMD_CONSOLE_READ 0x0098
24763806
24773807 enum ec_console_read_subcmd {
24783808 CONSOLE_READ_NEXT = 0,
@@ -2481,7 +3811,7 @@ enum ec_console_read_subcmd { · 2 unmodified lines
24813811
24823812 struct ec_params_console_read_v1 {
24833813 uint8_t subcmd; /* enum ec_console_read_subcmd */
2484−} __packed;
3814+} __ec_align1;
24853815
24863816 /*****************************************************************************/
24873817
@@ -2492,14 +3822,13 @@ struct ec_params_console_read_v1 { · 4 unmodified lines
24923822 * EC_RES_SUCCESS if the command was successful.
24933823 * EC_RES_ERROR if the cut off command failed.
24943824 */
3825+#define EC_CMD_BATTERY_CUT_OFF 0x0099
24953826
2496−#define EC_CMD_BATTERY_CUT_OFF 0x99
2497−
2498−#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3827+#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
24993828
25003829 struct ec_params_battery_cutoff {
25013830 uint8_t flags;
2502−} __packed;
3831+} __ec_align1;
25033832
25043833 /*****************************************************************************/
25053834 /* USB port mux control. */
@@ -2507,11 +3836,11 @@ struct ec_params_battery_cutoff { · 1 unmodified line
25073836 /*
25083837 * Switch USB mux or return to automatic switching.
25093838 */
2510−#define EC_CMD_USB_MUX 0x9a
3839+#define EC_CMD_USB_MUX 0x009A
25113840
25123841 struct ec_params_usb_mux {
25133842 uint8_t mux;
2514−} __packed;
3843+} __ec_align1;
25153844
25163845 /*****************************************************************************/
25173846 /* LDOs / FETs control. */
@@ -2524,25 +3853,25 @@ enum ec_ldo_state { · 6 unmodified lines
25243853 /*
25253854 * Switch on/off a LDO.
25263855 */
2527−#define EC_CMD_LDO_SET 0x9b
3856+#define EC_CMD_LDO_SET 0x009B
25283857
25293858 struct ec_params_ldo_set {
25303859 uint8_t index;
25313860 uint8_t state;
2532−} __packed;
3861+} __ec_align1;
25333862
25343863 /*
25353864 * Get LDO state.
25363865 */
2537−#define EC_CMD_LDO_GET 0x9c
3866+#define EC_CMD_LDO_GET 0x009C
25383867
25393868 struct ec_params_ldo_get {
25403869 uint8_t index;
2541−} __packed;
3870+} __ec_align1;
25423871
25433872 struct ec_response_ldo_get {
25443873 uint8_t state;
2545−} __packed;
3874+} __ec_align1;
25463875
25473876 /*****************************************************************************/
25483877 /* Power info. */
@@ -2550,7 +3879,7 @@ struct ec_response_ldo_get { · 1 unmodified line
25503879 /*
25513880 * Get power info.
25523881 */
2553−#define EC_CMD_POWER_INFO 0x9d
3882+#define EC_CMD_POWER_INFO 0x009D
25543883
25553884 struct ec_response_power_info {
25563885 uint32_t usb_dev_type;
@@ -2558,21 +3887,21 @@ struct ec_response_power_info { · 1 unmodified line
25583887 uint16_t voltage_system;
25593888 uint16_t current_system;
25603889 uint16_t usb_current_limit;
2561−} __packed;
3890+} __ec_align4;
25623891
25633892 /*****************************************************************************/
25643893 /* I2C passthru command */
25653894
2566−#define EC_CMD_I2C_PASSTHRU 0x9e
3895+#define EC_CMD_I2C_PASSTHRU 0x009E
25673896
25683897 /* Read data; if not present, message is a write */
2569−#define EC_I2C_FLAG_READ (1 << 15)
3898+#define EC_I2C_FLAG_READ BIT(15)
25703899
25713900 /* Mask for address */
25723901 #define EC_I2C_ADDR_MASK 0x3ff
25733902
2574−#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2575−#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3903+#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
3904+#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
25763905
25773906 /* Any error */
25783907 #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
@@ -2580,49 +3909,49 @@ struct ec_response_power_info { · 1 unmodified line
25803909 struct ec_params_i2c_passthru_msg {
25813910 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
25823911 uint16_t len; /* Number of bytes to read or write */
2583−} __packed;
3912+} __ec_align2;
25843913
25853914 struct ec_params_i2c_passthru {
25863915 uint8_t port; /* I2C port number */
25873916 uint8_t num_msgs; /* Number of messages */
25883917 struct ec_params_i2c_passthru_msg msg[];
25893918 /* Data to write for all messages is concatenated here */
2590−} __packed;
3919+} __ec_align2;
25913920
25923921 struct ec_response_i2c_passthru {
25933922 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
25943923 uint8_t num_msgs; /* Number of messages processed */
25953924 uint8_t data[]; /* Data read by messages concatenated here */
2596−} __packed;
3925+} __ec_align1;
25973926
25983927 /*****************************************************************************/
25993928 /* Power button hang detect */
26003929
2601−#define EC_CMD_HANG_DETECT 0x9f
3930+#define EC_CMD_HANG_DETECT 0x009F
26023931
26033932 /* Reasons to start hang detection timer */
26043933 /* Power button pressed */
2605−#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3934+#define EC_HANG_START_ON_POWER_PRESS BIT(0)
26063935
26073936 /* Lid closed */
2608−#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3937+#define EC_HANG_START_ON_LID_CLOSE BIT(1)
26093938
26103939 /* Lid opened */
2611−#define EC_HANG_START_ON_LID_OPEN (1 << 2)
3940+#define EC_HANG_START_ON_LID_OPEN BIT(2)
26123941
26133942 /* Start of AP S3->S0 transition (booting or resuming from suspend) */
2614−#define EC_HANG_START_ON_RESUME (1 << 3)
3943+#define EC_HANG_START_ON_RESUME BIT(3)
26153944
26163945 /* Reasons to cancel hang detection */
26173946
26183947 /* Power button released */
2619−#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3948+#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
26203949
26213950 /* Any host command from AP received */
2622−#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3951+#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
26233952
26243953 /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2625−#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
3954+#define EC_HANG_STOP_ON_SUSPEND BIT(10)
26263955
26273956 /*
26283957 * If this flag is set, all the other fields are ignored, and the hang detect
@@ -2630,14 +3959,14 @@ struct ec_response_i2c_passthru { · 1 unmodified line
26303959 * without reconfiguring any of the other hang detect settings. Note that
26313960 * you must previously have configured the timeouts.
26323961 */
2633−#define EC_HANG_START_NOW (1 << 30)
3962+#define EC_HANG_START_NOW BIT(30)
26343963
26353964 /*
26363965 * If this flag is set, all the other fields are ignored (including
26373966 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
26383967 * without reconfiguring any of the other hang detect settings.
26393968 */
2640−#define EC_HANG_STOP_NOW (1 << 31)
3969+#define EC_HANG_STOP_NOW BIT(31)
26413970
26423971 struct ec_params_hang_detect {
26433972 /* Flags; see EC_HANG_* */
@@ -2648,7 +3977,7 @@ struct ec_params_hang_detect { · 4 unmodified lines
26483977
26493978 /* Timeout in msec before generating warm reboot, if enabled */
26503979 uint16_t warm_reboot_timeout_msec;
2651−} __packed;
3980+} __ec_align4;
26523981
26533982 /*****************************************************************************/
26543983 /* Commands for battery charging */
@@ -2657,7 +3986,7 @@ struct ec_params_hang_detect { · 2 unmodified lines
26573986 * This is the single catch-all host command to exchange data regarding the
26583987 * charge state machine (v2 and up).
26593988 */
2660−#define EC_CMD_CHARGE_STATE 0xa0
3989+#define EC_CMD_CHARGE_STATE 0x00A0
26613990
26623991 /* Subcommands for this host command */
26633992 enum charge_state_command {
@@ -2677,6 +4006,11 @@ enum charge_state_params { · 13 unmodified lines
26774006 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
26784007 CS_PARAM_CHG_STATUS, /* charger-specific status */
26794008 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+ */
26804014 /* How many so far? */
26814015 CS_NUM_BASE_PARAMS,
26824016
@@ -2684,30 +4018,39 @@ enum charge_state_params { · 1 unmodified line
26844018 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
26854019 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
26864020
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+
26874032 /* Other custom param ranges go here... */
26884033 };
26894034
26904035 struct ec_params_charge_state {
26914036 uint8_t cmd; /* enum charge_state_command */
26924037 union {
2693− struct {
2694− /* no args */
2695− } get_state;
4038+ /* get_state has no args */
26964039
2697− struct {
4040+ struct __ec_todo_unpacked {
26984041 uint32_t param; /* enum charge_state_param */
26994042 } get_param;
27004043
2701− struct {
4044+ struct __ec_todo_unpacked {
27024045 uint32_t param; /* param to set */
27034046 uint32_t value; /* value to set */
27044047 } set_param;
27054048 };
2706−} __packed;
4049+} __ec_todo_packed;
27074050
27084051 struct ec_response_charge_state {
27094052 union {
2710− struct {
4053+ struct __ec_align4 {
27114054 int ac;
27124055 int chg_voltage;
27134056 int chg_current;
@@ -2715,24 +4058,23 @@ struct ec_response_charge_state { · 1 unmodified line
27154058 int batt_state_of_charge;
27164059 } get_state;
27174060
2718− struct {
4061+ struct __ec_align4 {
27194062 uint32_t value;
27204063 } get_param;
2721− struct {
2722− /* no return values */
2723− } set_param;
4064+
4065+ /* set_param returns no args */
27244066 };
2725−} __packed;
4067+} __ec_align4;
27264068
27274069
27284070 /*
27294071 * Set maximum battery charging current.
27304072 */
2731−#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
4073+#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
27324074
27334075 struct ec_params_current_limit {
27344076 uint32_t limit; /* in mA */
2735−} __packed;
4077+} __ec_align4;
27364078
27374079 /*
27384080 * Set maximum external voltage / current.
@@ -2743,23 +4085,69 @@ struct ec_params_current_limit { · 4 unmodified lines
27434085 struct ec_params_external_power_limit_v1 {
27444086 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
27454087 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
2746−} __packed;
4088+} __ec_align2;
27474089
27484090 #define EC_POWER_LIMIT_NONE 0xffff
27494091
4092+/*
4093+ * Set maximum voltage & current of a dedicated charge port
4094+ */
4095+#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4096+
4097+struct 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+
4108+struct 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+
4116+struct 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+
27504136 /* Inform the EC when entering a sleep state */
2751−#define EC_CMD_HOST_SLEEP_EVENT 0xa9
4137+#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
27524138
27534139 enum host_sleep_event {
27544140 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
27554141 HOST_SLEEP_EVENT_S3_RESUME = 2,
27564142 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2757− 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,
27584146 };
27594147
27604148 struct ec_params_host_sleep_event {
27614149 uint8_t sleep_event;
2762−} __packed;
4150+} __ec_align1;
27634151
27644152 /*
27654153 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
@@ -2790,7 +4178,7 @@ struct ec_params_host_sleep_event_v1 { · 24 unmodified lines
27904178
27914179 /* No parameters for non-suspend messages. */
27924180 };
2793−} __packed;
4181+} __ec_align2;
27944182
27954183 /* A timeout occurred when this bit is set */
27964184 #define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
@@ -2816,42 +4204,72 @@ struct ec_response_host_sleep_event_v1 { · 19 unmodified lines
28164204
28174205 /* No response fields for non-resume messages. */
28184206 };
2819−} __packed;
4207+} __ec_align4;
4208+
4209+/*****************************************************************************/
4210+/* Device events */
4211+#define EC_CMD_DEVICE_EVENT 0x00AA
4212+
4213+enum ec_device_event {
4214+ EC_DEVICE_EVENT_TRACKPAD,
4215+ EC_DEVICE_EVENT_DSP,
4216+ EC_DEVICE_EVENT_WIFI,
4217+};
4218+
4219+enum 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+
4230+struct ec_params_device_event {
4231+ uint32_t event_mask;
4232+ uint8_t param;
4233+} __ec_align_size1;
4234+
4235+struct ec_response_device_event {
4236+ uint32_t event_mask;
4237+} __ec_align4;
28204238
28214239 /*****************************************************************************/
28224240 /* Smart battery pass-through */
28234241
28244242 /* Get / Set 16-bit smart battery registers */
2825−#define EC_CMD_SB_READ_WORD 0xb0
2826−#define EC_CMD_SB_WRITE_WORD 0xb1
4243+#define EC_CMD_SB_READ_WORD 0x00B0
4244+#define EC_CMD_SB_WRITE_WORD 0x00B1
28274245
28284246 /* Get / Set string smart battery parameters
28294247 * formatted as SMBUS "block".
28304248 */
2831−#define EC_CMD_SB_READ_BLOCK 0xb2
2832−#define EC_CMD_SB_WRITE_BLOCK 0xb3
4249+#define EC_CMD_SB_READ_BLOCK 0x00B2
4250+#define EC_CMD_SB_WRITE_BLOCK 0x00B3
28334251
28344252 struct ec_params_sb_rd {
28354253 uint8_t reg;
2836−} __packed;
4254+} __ec_align1;
28374255
28384256 struct ec_response_sb_rd_word {
28394257 uint16_t value;
2840−} __packed;
4258+} __ec_align2;
28414259
28424260 struct ec_params_sb_wr_word {
28434261 uint8_t reg;
28444262 uint16_t value;
2845−} __packed;
4263+} __ec_align1;
28464264
28474265 struct ec_response_sb_rd_block {
28484266 uint8_t data[32];
2849−} __packed;
4267+} __ec_align1;
28504268
28514269 struct ec_params_sb_wr_block {
28524270 uint8_t reg;
28534271 uint16_t data[32];
2854−} __packed;
4272+} __ec_align1;
28554273
28564274 /*****************************************************************************/
28574275 /* Battery vendor parameters
@@ -2862,7 +4280,7 @@ struct ec_params_sb_wr_block { · 4 unmodified lines
28624280 * requested value.
28634281 */
28644282
2865−#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
4283+#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
28664284
28674285 enum ec_battery_vendor_param_mode {
28684286 BATTERY_VENDOR_PARAM_MODE_GET = 0,
@@ -2873,257 +4291,105 @@ struct ec_params_battery_vendor_param { · 4 unmodified lines
28734291 uint32_t param;
28744292 uint32_t value;
28754293 uint8_t mode;
2876−} __packed;
4294+} __ec_align_size1;
28774295
28784296 struct ec_response_battery_vendor_param {
28794297 uint32_t value;
2880−} __packed;
4298+} __ec_align4;
28814299
28824300 /*****************************************************************************/
2883−/* Commands for I2S recording on audio codec. */
2884−
2885−#define EC_CMD_CODEC_I2S 0x00BC
2886−
2887−enum ec_codec_i2s_subcmd {
2888− EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
2889− EC_CODEC_SET_GAIN = 0x1,
2890− EC_CODEC_GET_GAIN = 0x2,
2891− EC_CODEC_I2S_ENABLE = 0x3,
2892− EC_CODEC_I2S_SET_CONFIG = 0x4,
2893− EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
2894− EC_CODEC_I2S_SET_BCLK = 0x6,
4301+/*
4302+ * Smart Battery Firmware Update Commands
4303+ */
4304+#define EC_CMD_SB_FW_UPDATE 0x00B5
4305+
4306+enum 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,
28954315 };
28964316
2897−enum ec_sample_depth_value {
2898− EC_CODEC_SAMPLE_DEPTH_16 = 0,
2899− EC_CODEC_SAMPLE_DEPTH_24 = 1,
2900−};
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
29014320
2902−enum ec_i2s_config {
2903− EC_DAI_FMT_I2S = 0,
2904− EC_DAI_FMT_RIGHT_J = 1,
2905− EC_DAI_FMT_LEFT_J = 2,
2906− EC_DAI_FMT_PCM_A = 3,
2907− EC_DAI_FMT_PCM_B = 4,
2908− EC_DAI_FMT_PCM_TDM = 5,
2909−};
4321+struct 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;
29104325
2911−struct ec_param_codec_i2s {
2912− /*
2913− * enum ec_codec_i2s_subcmd
2914− */
2915− uint8_t cmd;
4326+struct ec_params_sb_fw_update {
4327+ struct ec_sb_fw_update_header hdr;
29164328 union {
2917− /*
2918− * EC_CODEC_SET_SAMPLE_DEPTH
2919− * Value should be one of ec_sample_depth_value.
2920− */
2921− uint8_t depth;
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;
29224343
2923− /*
2924− * EC_CODEC_SET_GAIN
2925− * Value should be 0~43 for both channels.
2926− */
2927− struct ec_param_codec_i2s_set_gain {
2928− uint8_t left;
2929− uint8_t right;
2930− } __packed gain;
4344+struct 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;
29314350
2932− /*
2933− * EC_CODEC_I2S_ENABLE
2934− * 1 to enable, 0 to disable.
2935− */
2936− uint8_t i2s_enable;
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;
29374357
2938− /*
2939− * EC_CODEC_I2S_SET_COFNIG
2940− * Value should be one of ec_i2s_config.
2941− */
2942− uint8_t i2s_config;
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
29434364
2944− /*
2945− * EC_CODEC_I2S_SET_TDM_CONFIG
2946− * Value should be one of ec_i2s_config.
2947− */
2948− struct ec_param_codec_i2s_tdm {
2949− /*
2950− * 0 to 496
2951− */
2952− int16_t ch0_delay;
2953− /*
2954− * -1 to 496
2955− */
2956− int16_t ch1_delay;
2957− uint8_t adjacent_to_ch0;
2958− uint8_t adjacent_to_ch1;
2959− } __packed tdm_param;
4365+struct ec_params_entering_mode {
4366+ int vboot_mode;
4367+} __ec_align4;
29604368
2961− /*
2962− * EC_CODEC_I2S_SET_BCLK
2963− */
2964− uint32_t bclk;
2965− };
2966−} __packed;
2967−
2968−/*
2969− * For subcommand EC_CODEC_GET_GAIN.
2970− */
2971−struct ec_response_codec_gain {
2972− uint8_t left;
2973− uint8_t right;
2974−} __packed;
4369+#define VBOOT_MODE_NORMAL 0
4370+#define VBOOT_MODE_DEVELOPER 1
4371+#define VBOOT_MODE_RECOVERY 2
29754372
29764373 /*****************************************************************************/
2977−/* System commands */
2978−
29794374 /*
2980− * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2981− * necessarily reboot the EC. Rename to "image" or something similar?
4375+ * I2C passthru protection command: Protects I2C tunnels against access on
4376+ * certain addresses (board-specific).
29824377 */
2983−#define EC_CMD_REBOOT_EC 0xd2
4378+#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
29844379
2985−/* Command */
2986−enum ec_reboot_cmd {
2987− EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2988− EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2989− EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2990− /* (command 3 was jump to RW-B) */
2991− EC_REBOOT_COLD = 4, /* Cold-reboot */
2992− EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2993− EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
4380+enum ec_i2c_passthru_protect_subcmd {
4381+ EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
4382+ EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
29944383 };
29954384
2996−/* Flags for ec_params_reboot_ec.reboot_flags */
2997−#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2998−#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2999−
3000−struct ec_params_reboot_ec {
3001− uint8_t cmd; /* enum ec_reboot_cmd */
3002− uint8_t flags; /* See EC_REBOOT_FLAG_* */
3003−} __packed;
3004−
3005−/*
3006− * Get information on last EC panic.
3007− *
3008− * Returns variable-length platform-dependent panic information. See panic.h
3009− * for details.
3010− */
3011−#define EC_CMD_GET_PANIC_INFO 0xd3
3012−
3013−/*****************************************************************************/
3014−/*
3015− * ACPI commands
3016− *
3017− * These are valid ONLY on the ACPI command/data port.
3018− */
3019−
3020−/*
3021− * ACPI Read Embedded Controller
3022− *
3023− * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3024− *
3025− * Use the following sequence:
3026− *
3027− * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
3028− * - Wait for EC_LPC_CMDR_PENDING bit to clear
3029− * - Write address to EC_LPC_ADDR_ACPI_DATA
3030− * - Wait for EC_LPC_CMDR_DATA bit to set
3031− * - Read value from EC_LPC_ADDR_ACPI_DATA
3032− */
3033−#define EC_CMD_ACPI_READ 0x80
3034−
3035−/*
3036− * ACPI Write Embedded Controller
3037− *
3038− * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3039− *
3040− * Use the following sequence:
3041− *
3042− * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
3043− * - Wait for EC_LPC_CMDR_PENDING bit to clear
3044− * - Write address to EC_LPC_ADDR_ACPI_DATA
3045− * - Wait for EC_LPC_CMDR_PENDING bit to clear
3046− * - Write value to EC_LPC_ADDR_ACPI_DATA
3047− */
3048−#define EC_CMD_ACPI_WRITE 0x81
3049−
3050−/*
3051− * ACPI Query Embedded Controller
3052− *
3053− * This clears the lowest-order bit in the currently pending host events, and
3054− * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
3055− * event 0x80000000 = 32), or 0 if no event was pending.
3056− */
3057−#define EC_CMD_ACPI_QUERY_EVENT 0x84
3058−
3059−/* Valid addresses in ACPI memory space, for read/write commands */
3060−
3061−/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
3062−#define EC_ACPI_MEM_VERSION 0x00
3063−/*
3064− * Test location; writing value here updates test compliment byte to (0xff -
3065− * value).
3066− */
3067−#define EC_ACPI_MEM_TEST 0x01
3068−/* Test compliment; writes here are ignored. */
3069−#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
3070−
3071−/* Keyboard backlight brightness percent (0 - 100) */
3072−#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
3073−/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
3074−#define EC_ACPI_MEM_FAN_DUTY 0x04
3075−
3076−/*
3077− * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
3078− * independent thresholds attached to them. The current value of the ID
3079− * register determines which sensor is affected by the THRESHOLD and COMMIT
3080− * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
3081− * as the memory-mapped sensors. The COMMIT register applies those settings.
3082− *
3083− * The spec does not mandate any way to read back the threshold settings
3084− * themselves, but when a threshold is crossed the AP needs a way to determine
3085− * which sensor(s) are responsible. Each reading of the ID register clears and
3086− * returns one sensor ID that has crossed one of its threshold (in either
3087− * direction) since the last read. A value of 0xFF means "no new thresholds
3088− * have tripped". Setting or enabling the thresholds for a sensor will clear
3089− * the unread event count for that sensor.
3090− */
3091−#define EC_ACPI_MEM_TEMP_ID 0x05
3092−#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
3093−#define EC_ACPI_MEM_TEMP_COMMIT 0x07
3094−/*
3095− * Here are the bits for the COMMIT register:
3096− * bit 0 selects the threshold index for the chosen sensor (0/1)
3097− * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
3098− * Each write to the commit register affects one threshold.
3099− */
3100−#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
3101−#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
3102−/*
3103− * Example:
3104− *
3105− * Set the thresholds for sensor 2 to 50 C and 60 C:
3106− * write 2 to [0x05] -- select temp sensor 2
3107− * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
3108− * write 0x2 to [0x07] -- enable threshold 0 with this value
3109− * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
3110− * write 0x3 to [0x07] -- enable threshold 1 with this value
3111− *
3112− * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
3113− * write 2 to [0x05] -- select temp sensor 2
3114− * write 0x1 to [0x07] -- disable threshold 1
3115− */
3116−
3117−/* DPTF battery charging current limit */
3118−#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
3119−
3120−/* Charging limit is specified in 64 mA steps */
3121−#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
3122−/* Value to disable DPTF battery charging limit */
3123−#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
4385+struct ec_params_i2c_passthru_protect {
4386+ uint8_t subcmd;
4387+ uint8_t port; /* I2C port number */
4388+} __ec_align1;
31244389
3125−/* Current version of ACPI memory address space */
3126−#define EC_ACPI_MEM_VERSION_CURRENT 1
4390+struct ec_response_i2c_passthru_protect {
4391+ uint8_t status; /* Status flags (0: unlocked, 1: locked) */
4392+} __ec_align1;
31274393
31284394
31294395 /*****************************************************************************/
@@ -3132,7 +4398,8 @@ struct ec_params_reboot_ec { · 2 unmodified lines
31324398 *
31334399 * These commands are for sending and receiving message via HDMI CEC
31344400 */
3135−#define EC_MAX_CEC_MSG_LEN 16
4401+
4402+#define MAX_CEC_MSG_LEN 16
31364403
31374404 /* CEC message from the AP to be written on the CEC bus */
31384405 #define EC_CMD_CEC_WRITE_MSG 0x00B8
@@ -3142,8 +4409,8 @@ struct ec_params_reboot_ec { · 3 unmodified lines
31424409 * @msg: message content to write to the CEC bus
31434410 */
31444411 struct ec_params_cec_write {
3145− uint8_t msg[EC_MAX_CEC_MSG_LEN];
3146−} __packed;
4412+ uint8_t msg[MAX_CEC_MSG_LEN];
4413+} __ec_align1;
31474414
31484415 /* Set various CEC parameters */
31494416 #define EC_CMD_CEC_SET 0x00BA
@@ -3152,14 +4419,14 @@ struct ec_params_cec_write { · 2 unmodified lines
31524419 * struct ec_params_cec_set - CEC parameters set
31534420 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
31544421 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
3155− * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS,
3156− * this field encodes the requested logical address between 0 and 15
3157− * or 0xff to unregister
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
31584425 */
31594426 struct ec_params_cec_set {
31604427 uint8_t cmd; /* enum cec_command */
31614428 uint8_t val;
3162−} __packed;
4429+} __ec_align1;
31634430
31644431 /* Read various CEC parameters */
31654432 #define EC_CMD_CEC_GET 0x00BB
@@ -3170,7 +4437,7 @@ struct ec_params_cec_set { · 4 unmodified lines
31704437 */
31714438 struct ec_params_cec_get {
31724439 uint8_t cmd; /* enum cec_command */
3173−} __packed;
4440+} __ec_align1;
31744441
31754442 /**
31764443 * struct ec_response_cec_get - CEC parameters get response
@@ -3181,10 +4448,10 @@ struct ec_params_cec_get { · 4 unmodified lines
31814448 */
31824449 struct ec_response_cec_get {
31834450 uint8_t val;
3184−} __packed;
4451+} __ec_align1;
31854452
31864453 /* CEC parameters command */
3187−enum ec_cec_command {
4454+enum cec_command {
31884455 /* CEC reading, writing and events enable */
31894456 CEC_CMD_ENABLE,
31904457 /* CEC logical address */
@@ -3199,6 +4466,134 @@ enum mkbp_cec_event { · 8 unmodified lines
31994466 EC_MKBP_CEC_SEND_FAILED = BIT(1),
32004467 };
32014468
4469+/*****************************************************************************/
4470+
4471+/* Commands for I2S recording on audio codec. */
4472+
4473+#define EC_CMD_CODEC_I2S 0x00BC
4474+#define EC_WOV_I2S_SAMPLE_RATE 48000
4475+
4476+enum ec_codec_i2s_subcmd {
4477+ EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
4478+ EC_CODEC_SET_GAIN = 0x1,
4479+ EC_CODEC_GET_GAIN = 0x2,
4480+ EC_CODEC_I2S_ENABLE = 0x3,
4481+ EC_CODEC_I2S_SET_CONFIG = 0x4,
4482+ EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
4483+ EC_CODEC_I2S_SET_BCLK = 0x6,
4484+ EC_CODEC_I2S_SUBCMD_COUNT = 0x7,
4485+};
4486+
4487+enum ec_sample_depth_value {
4488+ EC_CODEC_SAMPLE_DEPTH_16 = 0,
4489+ EC_CODEC_SAMPLE_DEPTH_24 = 1,
4490+};
4491+
4492+enum ec_i2s_config {
4493+ EC_DAI_FMT_I2S = 0,
4494+ EC_DAI_FMT_RIGHT_J = 1,
4495+ EC_DAI_FMT_LEFT_J = 2,
4496+ EC_DAI_FMT_PCM_A = 3,
4497+ EC_DAI_FMT_PCM_B = 4,
4498+ EC_DAI_FMT_PCM_TDM = 5,
4499+};
4500+
4501+/*
4502+ * For subcommand EC_CODEC_GET_GAIN.
4503+ */
4504+struct __ec_align1 ec_codec_i2s_gain {
4505+ uint8_t left;
4506+ uint8_t right;
4507+};
4508+
4509+struct __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+
4516+struct __ec_todo_packed ec_param_codec_i2s {
4517+ /* enum ec_codec_i2s_subcmd */
4518+ uint8_t cmd;
4519+ union {
4520+ /*
4521+ * EC_CODEC_SET_SAMPLE_DEPTH
4522+ * Value should be one of ec_sample_depth_value.
4523+ */
4524+ uint8_t depth;
4525+
4526+ /*
4527+ * EC_CODEC_SET_GAIN
4528+ * Value should be 0~43 for both channels.
4529+ */
4530+ struct ec_codec_i2s_gain gain;
4531+
4532+ /*
4533+ * EC_CODEC_I2S_ENABLE
4534+ * 1 to enable, 0 to disable.
4535+ */
4536+ uint8_t i2s_enable;
4537+
4538+ /*
4539+ * EC_CODEC_I2S_SET_CONFIG
4540+ * Value should be one of ec_i2s_config.
4541+ */
4542+ uint8_t i2s_config;
4543+
4544+ /*
4545+ * EC_CODEC_I2S_SET_TDM_CONFIG
4546+ * Value should be one of ec_i2s_config.
4547+ */
4548+ struct ec_param_codec_i2s_tdm tdm_param;
4549+
4550+ /*
4551+ * EC_CODEC_I2S_SET_BCLK
4552+ */
4553+ uint32_t bclk;
4554+ };
4555+};
4556+
4557+
4558+/*****************************************************************************/
4559+/* System commands */
4560+
4561+/*
4562+ * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
4563+ * necessarily reboot the EC. Rename to "image" or something similar?
4564+ */
4565+#define EC_CMD_REBOOT_EC 0x00D2
4566+
4567+/* Command */
4568+enum ec_reboot_cmd {
4569+ EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
4570+ EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
4571+ EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
4572+ /* (command 3 was jump to RW-B) */
4573+ EC_REBOOT_COLD = 4, /* Cold-reboot */
4574+ EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
4575+ EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
4576+ EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
4577+};
4578+
4579+/* Flags for ec_params_reboot_ec.reboot_flags */
4580+#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
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 */
4583+
4584+struct ec_params_reboot_ec {
4585+ uint8_t cmd; /* enum ec_reboot_cmd */
4586+ uint8_t flags; /* See EC_REBOOT_FLAG_* */
4587+} __ec_align1;
4588+
4589+/*
4590+ * Get information on last EC panic.
4591+ *
4592+ * Returns variable-length platform-dependent panic information. See panic.h
4593+ * for details.
4594+ */
4595+#define EC_CMD_GET_PANIC_INFO 0x00D3
4596+
32024597 /*****************************************************************************/
32034598 /*
32044599 * Special commands
@@ -3216,7 +4611,7 @@ enum mkbp_cec_event { · 11 unmodified lines
32164611 *
32174612 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
32184613 */
3219−#define EC_CMD_REBOOT 0xd1 /* Think "die" */
4614+#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
32204615
32214616 /*
32224617 * Resend last response (not supported on LPC).
@@ -3225,7 +4620,7 @@ enum mkbp_cec_event { · 2 unmodified lines
32254620 * there was no previous command, or the previous command's response was too
32264621 * big to save.
32274622 */
3228−#define EC_CMD_RESEND_RESPONSE 0xdb
4623+#define EC_CMD_RESEND_RESPONSE 0x00DB
32294624
32304625 /*
32314626 * This header byte on a command indicate version 0. Any header byte less
@@ -3237,9 +4632,7 @@ enum mkbp_cec_event { · 5 unmodified lines
32374632 *
32384633 * The old EC interface must not use commands 0xdc or higher.
32394634 */
3240−#define EC_CMD_VERSION0 0xdc
3241−
3242−#endif /* !__ACPI__ */
4635+#define EC_CMD_VERSION0 0x00DC
32434636
32444637 /*****************************************************************************/
32454638 /*
@@ -3249,21 +4642,56 @@ enum mkbp_cec_event { · 3 unmodified lines
32494642 */
32504643
32514644 /* EC to PD MCU exchange status command */
3252−#define EC_CMD_PD_EXCHANGE_STATUS 0x100
4645+#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
4646+#define EC_VER_PD_EXCHANGE_STATUS 2
4647+
4648+enum 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+};
32534654
32544655 /* Status of EC being sent to PD */
4656+#define EC_STATUS_HIBERNATING BIT(0)
4657+
32554658 struct ec_params_pd_status {
3256− int8_t batt_soc; /* battery state of charge */
3257−} __packed;
4659+ uint8_t status; /* EC status */
4660+ int8_t batt_soc; /* battery state of charge */
4661+ uint8_t charge_state; /* charging state (from enum pd_charge_state) */
4662+} __ec_align1;
32584663
32594664 /* 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)
32604675 struct ec_response_pd_status {
3261− int8_t status; /* PD MCU status */
3262− uint32_t curr_lim_ma; /* input current limit */
3263−} __packed;
4676+ uint32_t curr_lim_ma; /* input current limit */
4677+ uint16_t status; /* PD MCU status */
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)
4689+struct ec_response_host_event_status {
4690+ uint32_t status; /* PD MCU host event status */
4691+} __ec_align4;
32644692
32654693 /* Set USB type-C port role and muxes */
3266−#define EC_CMD_USB_PD_CONTROL 0x101
4694+#define EC_CMD_USB_PD_CONTROL 0x0101
32674695
32684696 enum usb_pd_control_role {
32694697 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
@@ -3271,6 +4699,8 @@ enum usb_pd_control_role { · 1 unmodified line
32714699 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
32724700 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
32734701 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
4702+ USB_PD_CTRL_ROLE_FREEZE = 5,
4703+ USB_PD_CTRL_ROLE_COUNT
32744704 };
32754705
32764706 enum usb_pd_control_mux {
@@ -3280,6 +4710,7 @@ enum usb_pd_control_mux { · 3 unmodified lines
32804710 USB_PD_CTRL_MUX_DP = 3,
32814711 USB_PD_CTRL_MUX_DOCK = 4,
32824712 USB_PD_CTRL_MUX_AUTO = 5,
4713+ USB_PD_CTRL_MUX_COUNT
32834714 };
32844715
32854716 enum usb_pd_control_swap {
@@ -3295,11 +4726,11 @@ struct ec_params_usb_pd_control { · 9 unmodified lines
32954726 uint8_t role;
32964727 uint8_t mux;
32974728 uint8_t swap;
3298−} __packed;
4729+} __ec_align1;
32994730
3300−#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3301−#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3302−#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
4731+#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
4732+#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
4733+#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
33034734
33044735 #define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
33054736 #define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
@@ -3309,28 +4740,54 @@ struct ec_params_usb_pd_control { · 3 unmodified lines
33094740 #define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
33104741 #define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
33114742
4743+struct 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+
33124750 struct ec_response_usb_pd_control_v1 {
33134751 uint8_t enabled;
33144752 uint8_t role;
33154753 uint8_t polarity;
33164754 char state[32];
3317−} __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+
4765+struct 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;
33184775
3319−#define EC_CMD_USB_PD_PORTS 0x102
4776+#define EC_CMD_USB_PD_PORTS 0x0102
33204777
33214778 /* Maximum number of PD ports on a device, num_ports will be <= this */
33224779 #define EC_USB_PD_MAX_PORTS 8
33234780
33244781 struct ec_response_usb_pd_ports {
33254782 uint8_t num_ports;
3326−} __packed;
4783+} __ec_align1;
33274784
3328−#define EC_CMD_USB_PD_POWER_INFO 0x103
4785+#define EC_CMD_USB_PD_POWER_INFO 0x0103
33294786
33304787 #define PD_POWER_CHARGING_PORT 0xff
33314788 struct ec_params_usb_pd_power_info {
33324789 uint8_t port;
3333−} __packed;
4790+} __ec_align1;
33344791
33354792 enum usb_chg_type {
33364793 USB_CHG_TYPE_NONE,
@@ -3343,6 +4800,7 @@ enum usb_chg_type { · 6 unmodified lines
33434800 USB_CHG_TYPE_OTHER,
33444801 USB_CHG_TYPE_VBUS,
33454802 USB_CHG_TYPE_UNKNOWN,
4803+ USB_CHG_TYPE_DEDICATED,
33464804 };
33474805 enum usb_power_roles {
33484806 USB_PD_PORT_POWER_DISCONNECTED,
@@ -3356,7 +4814,7 @@ struct usb_chg_measures { · 7 unmodified lines
33564814 uint16_t voltage_now;
33574815 uint16_t current_max;
33584816 uint16_t current_lim;
3359−} __packed;
4817+} __ec_align2;
33604818
33614819 struct ec_response_usb_pd_power_info {
33624820 uint8_t role;
@@ -3365,11 +4823,8 @@ struct ec_response_usb_pd_power_info { · 2 unmodified lines
33654823 uint8_t reserved1;
33664824 struct usb_chg_measures meas;
33674825 uint32_t max_power;
3368−} __packed;
4826+} __ec_align4;
33694827
3370−struct ec_params_usb_pd_info_request {
3371− uint8_t port;
3372−} __packed;
33734828
33744829 /*
33754830 * This command will return the number of USB PD charge port + the number
@@ -3379,7 +4834,47 @@ struct ec_params_usb_pd_info_request { · 3 unmodified lines
33794834 #define EC_CMD_CHARGE_PORT_COUNT 0x0105
33804835 struct ec_response_charge_port_count {
33814836 uint8_t port_count;
3382−} __packed;
4837+} __ec_align1;
4838+
4839+/* Write USB-PD device FW */
4840+#define EC_CMD_USB_PD_FW_UPDATE 0x0110
4841+
4842+enum 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+
4849+struct 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
4861+struct 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+
4875+struct ec_params_usb_pd_info_request {
4876+ uint8_t port;
4877+} __ec_align1;
33834878
33844879 /* Read USB-PD Device discovery info */
33854880 #define EC_CMD_USB_PD_DISCOVERY 0x0113
@@ -3387,7 +4882,7 @@ struct ec_params_usb_pd_discovery_entry { · 1 unmodified line
33874882 uint16_t vid; /* USB-IF VID */
33884883 uint16_t pid; /* USB-IF PID */
33894884 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3390−} __packed;
4885+} __ec_align_size1;
33914886
33924887 /* Override default charge behavior */
33934888 #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
@@ -3401,9 +4896,13 @@ enum usb_pd_override_ports { · 7 unmodified lines
34014896
34024897 struct ec_params_charge_port_override {
34034898 int16_t override_port; /* Override port# */
3404−} __packed;
4899+} __ec_align2;
34054900
3406−/* 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+ */
34074906 #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
34084907
34094908 struct ec_response_pd_log {
@@ -3412,7 +4911,7 @@ struct ec_response_pd_log { · 2 unmodified lines
34124911 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
34134912 uint16_t data; /* type-defined data payload */
34144913 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3415−} __packed;
4914+} __ec_align4;
34164915
34174916 /* The timestamp is the microsecond counter shifted to get about a ms. */
34184917 #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
@@ -3478,35 +4977,698 @@ struct mcdp_version { · 59 unmodified lines
34784977 uint8_t major;
34794978 uint8_t minor;
34804979 uint16_t build;
3481−} __packed;
4980+} __ec_align4;
34824981
34834982 struct mcdp_info {
34844983 uint8_t family[2];
34854984 uint8_t chipid[2];
34864985 struct mcdp_version irom;
34874986 struct mcdp_version fw;
3488−} __packed;
4987+} __ec_align4;
34894988
34904989 /* struct mcdp_info field decoding */
34914990 #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
34924991 #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
34934992
4993+/* Get/Set USB-PD Alternate mode info */
4994+#define EC_CMD_USB_PD_GET_AMODE 0x0116
4995+struct 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+
5000+struct 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+
5008+enum 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+
5015+struct 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+
5025+struct 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+
5034+enum 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+
5042+struct ec_params_pd_control {
5043+ uint8_t chip; /* chip id */
5044+ uint8_t subcmd;
5045+} __ec_align1;
5046+
34945047 /* Get info about USB-C SS muxes */
3495−#define EC_CMD_USB_PD_MUX_INFO 0x11a
5048+#define EC_CMD_USB_PD_MUX_INFO 0x011A
34965049
34975050 struct ec_params_usb_pd_mux_info {
34985051 uint8_t port; /* USB-C port number */
3499−} __packed;
5052+} __ec_align1;
35005053
35015054 /* Flags representing mux state */
3502−#define USB_PD_MUX_USB_ENABLED (1 << 0)
3503−#define USB_PD_MUX_DP_ENABLED (1 << 1)
3504−#define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
3505−#define USB_PD_MUX_HPD_IRQ (1 << 3)
5055+#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5056+#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5057+#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
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 */
35065060
35075061 struct ec_response_usb_pd_mux_info {
35085062 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3509−} __packed;
5063+} __ec_align1;
5064+
5065+#define EC_CMD_PD_CHIP_INFO 0x011B
5066+
5067+struct ec_params_pd_chip_info {
5068+ uint8_t port; /* USB-C port number */
5069+ uint8_t renew; /* Force renewal */
5070+} __ec_align1;
5071+
5072+struct 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+
5082+struct 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+
5099+struct 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+
5106+enum rwsig_action {
5107+ RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5108+ RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5109+};
5110+
5111+struct 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+
5118+struct 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+
5134+enum 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+
5152+struct 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+
5168+struct 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+
5180+struct 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+
5233+enum 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+
5246+struct 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+
5255+struct ec_params_adc_read {
5256+ uint8_t adc_channel;
5257+} __ec_align1;
5258+
5259+struct ec_response_adc_read {
5260+ int32_t adc_value;
5261+} __ec_align4;

420 more lines aren’t shown here.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t