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 */
1/*2/*
2 * Host communication command constants for ChromeOS EC3 * Host communication command constants for ChromeOS EC
3 *4 *
4 * Copyright (C) 2012 Google, Inc5 * Copyright (C) 2012 Google, Inc
5 *6 *
6 * This software is licensed under the terms of the GNU General Public7 * NOTE: This file is auto-generated from ChromeOS EC Open Source code from
7 * License version 2, as published by the Free Software Foundation, and8 * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h
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.
21 */9 */
22 10
11/* Host communication command constants for Chrome EC */
12
23#ifndef __CROS_EC_COMMANDS_H13#ifndef __CROS_EC_COMMANDS_H
24#define __CROS_EC_COMMANDS_H14#define __CROS_EC_COMMANDS_H
25 15
16
17
18
19#define BUILD_ASSERT(_cond)
20
26/*21/*
27 * Current version of this protocol22 * Current version of this protocol
28 *23 *
@@ -33,7 +28,7 @@ · 4 unmodified lines
33#define EC_PROTO_VERSION 0x0000000228#define EC_PROTO_VERSION 0x00000002
34 29
35/* Command version mask */30/* Command version mask */
36#define EC_VER_MASK(version) (1UL << (version))31#define EC_VER_MASK(version) BIT(version)
37 32
38/* I/O addresses for ACPI commands */33/* I/O addresses for ACPI commands */
39#define EC_LPC_ADDR_ACPI_DATA 0x6234#define EC_LPC_ADDR_ACPI_DATA 0x62
@@ -47,25 +42,28 @@ · 7 unmodified lines
47/* Protocol version 2 */42/* Protocol version 2 */
48#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */43#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
49#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is44#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 */
51/* Protocol version 3 */47/* Protocol version 3 */
52#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */48#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
53#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */49#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
54 50
55/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff51/*
56 * and they tell the kernel that so we have to think of it as two parts. */52 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
53 * and they tell the kernel that so we have to think of it as two parts.
54 */
57#define EC_HOST_CMD_REGION0 0x80055#define EC_HOST_CMD_REGION0 0x800
58#define EC_HOST_CMD_REGION1 0x88056#define EC_HOST_CMD_REGION1 0x880
59#define EC_HOST_CMD_REGION_SIZE 0x8057#define EC_HOST_CMD_REGION_SIZE 0x80
60 58
61/* EC command register bit functions */59/* EC command register bit functions */
62#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */60#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
63#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */61#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
64#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */62#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
65#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */63#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
66#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */64#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
67#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */65#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
68#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */66#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
69 67
70#define EC_LPC_ADDR_MEMMAP 0x90068#define EC_LPC_ADDR_MEMMAP 0x900
71#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */69#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
@@ -85,13 +83,15 @@ · 13 unmodified lines
85/* Unused 0x28 - 0x2f */83/* Unused 0x28 - 0x2f */
86#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */84#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
87/* Unused 0x31 - 0x33 */85/* Unused 0x31 - 0x33 */
88#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */86#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
89/* Reserve 0x38 - 0x3f for additional host event-related stuff */87/* Battery values are all 32 bits, unless otherwise noted. */
90/* Battery values are all 32 bits */
91#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */88#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
92#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */89#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
93#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */90#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 */
95#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */95#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
96#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */96#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
97#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */97#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
@@ -105,15 +105,24 @@ · 7 unmodified lines
105/* Unused 0x84 - 0x8f */105/* Unused 0x84 - 0x8f */
106#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/106#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
107/* Unused 0x91 */107/* 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 */
109#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */112#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 */
111 114
115/*
116 * ACPI is unable to access memory mapped data at or above this offset due to
117 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
118 * which might be needed by ACPI.
119 */
120#define EC_MEMMAP_NO_ACPI 0xe0
112 121
113/* Define the format of the accelerometer mapped memory status byte. */122/* Define the format of the accelerometer mapped memory status byte. */
114#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f123#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
115#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)124#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
116#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)125#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
117 126
118/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */127/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
119#define EC_TEMP_SENSOR_ENTRIES 16128#define EC_TEMP_SENSOR_ENTRIES 16
@@ -157,6 +166,8 @@ · 37 unmodified lines
157#define EC_BATT_FLAG_DISCHARGING 0x04166#define EC_BATT_FLAG_DISCHARGING 0x04
158#define EC_BATT_FLAG_CHARGING 0x08167#define EC_BATT_FLAG_CHARGING 0x08
159#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10168#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
160 171
161/* Switch flags at EC_MEMMAP_SWITCHES */172/* Switch flags at EC_MEMMAP_SWITCHES */
162#define EC_SWITCH_LID_OPEN 0x01173#define EC_SWITCH_LID_OPEN 0x01
@@ -182,20 +193,242 @@ · 19 unmodified lines
182#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */193#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
183#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */194#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
184 195
196/*****************************************************************************/
197/*
198 * ACPI commands
199 *
200 * These are valid ONLY on the ACPI command/data port.
201 */
202
203/*
204 * ACPI Read Embedded Controller
205 *
206 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
207 *
208 * Use the following sequence:
209 *
210 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
211 * - Wait for EC_LPC_CMDR_PENDING bit to clear
212 * - Write address to EC_LPC_ADDR_ACPI_DATA
213 * - Wait for EC_LPC_CMDR_DATA bit to set
214 * - Read value from EC_LPC_ADDR_ACPI_DATA
215 */
216#define EC_CMD_ACPI_READ 0x0080
217
218/*
219 * ACPI Write Embedded Controller
220 *
221 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
222 *
223 * Use the following sequence:
224 *
225 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
226 * - Wait for EC_LPC_CMDR_PENDING bit to clear
227 * - Write address to EC_LPC_ADDR_ACPI_DATA
228 * - Wait for EC_LPC_CMDR_PENDING bit to clear
229 * - Write value to EC_LPC_ADDR_ACPI_DATA
230 */
231#define EC_CMD_ACPI_WRITE 0x0081
232
233/*
234 * ACPI Burst Enable Embedded Controller
235 *
236 * This enables burst mode on the EC to allow the host to issue several
237 * commands back-to-back. While in this mode, writes to mapped multi-byte
238 * data are locked out to ensure data consistency.
239 */
240#define EC_CMD_ACPI_BURST_ENABLE 0x0082
241
242/*
243 * ACPI Burst Disable Embedded Controller
244 *
245 * This disables burst mode on the EC and stops preventing EC writes to mapped
246 * multi-byte data.
247 */
248#define EC_CMD_ACPI_BURST_DISABLE 0x0083
249
250/*
251 * ACPI Query Embedded Controller
252 *
253 * This clears the lowest-order bit in the currently pending host events, and
254 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
255 * event 0x80000000 = 32), or 0 if no event was pending.
256 */
257#define EC_CMD_ACPI_QUERY_EVENT 0x0084
258
259/* Valid addresses in ACPI memory space, for read/write commands */
260
261/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
262#define EC_ACPI_MEM_VERSION 0x00
263/*
264 * Test location; writing value here updates test compliment byte to (0xff -
265 * value).
266 */
267#define EC_ACPI_MEM_TEST 0x01
268/* Test compliment; writes here are ignored. */
269#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
270
271/* Keyboard backlight brightness percent (0 - 100) */
272#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
273/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
274#define EC_ACPI_MEM_FAN_DUTY 0x04
275
276/*
277 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
278 * independent thresholds attached to them. The current value of the ID
279 * register determines which sensor is affected by the THRESHOLD and COMMIT
280 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
281 * as the memory-mapped sensors. The COMMIT register applies those settings.
282 *
283 * The spec does not mandate any way to read back the threshold settings
284 * themselves, but when a threshold is crossed the AP needs a way to determine
285 * which sensor(s) are responsible. Each reading of the ID register clears and
286 * returns one sensor ID that has crossed one of its threshold (in either
287 * direction) since the last read. A value of 0xFF means "no new thresholds
288 * have tripped". Setting or enabling the thresholds for a sensor will clear
289 * the unread event count for that sensor.
290 */
291#define EC_ACPI_MEM_TEMP_ID 0x05
292#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
293#define EC_ACPI_MEM_TEMP_COMMIT 0x07
294/*
295 * Here are the bits for the COMMIT register:
296 * bit 0 selects the threshold index for the chosen sensor (0/1)
297 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
298 * Each write to the commit register affects one threshold.
299 */
300#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
301#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
302/*
303 * Example:
304 *
305 * Set the thresholds for sensor 2 to 50 C and 60 C:
306 * write 2 to [0x05] -- select temp sensor 2
307 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
308 * write 0x2 to [0x07] -- enable threshold 0 with this value
309 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
310 * write 0x3 to [0x07] -- enable threshold 1 with this value
311 *
312 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
313 * write 2 to [0x05] -- select temp sensor 2
314 * write 0x1 to [0x07] -- disable threshold 1
315 */
316
317/* DPTF battery charging current limit */
318#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
319
320/* Charging limit is specified in 64 mA steps */
321#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
322/* Value to disable DPTF battery charging limit */
323#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
324
325/*
326 * Report device orientation
327 * Bits Definition
328 * 3:1 Device DPTF Profile Number (DDPN)
329 * 0 = Reserved for backward compatibility (indicates no valid
330 * profile number. Host should fall back to using TBMD).
331 * 1..7 = DPTF Profile number to indicate to host which table needs
332 * to be loaded.
333 * 0 Tablet Mode Device Indicator (TBMD)
334 */
335#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
336#define EC_ACPI_MEM_TBMD_SHIFT 0
337#define EC_ACPI_MEM_TBMD_MASK 0x1
338#define EC_ACPI_MEM_DDPN_SHIFT 1
339#define EC_ACPI_MEM_DDPN_MASK 0x7
340
341/*
342 * Report device features. Uses the same format as the host command, except:
343 *
344 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
345 * of features", which is of limited interest when the system is already
346 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
347 * these are supported, it defaults to 0.
348 * This allows detecting the presence of this field since older versions of
349 * the EC codebase would simply return 0xff to that unknown address. Check
350 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
351 * are valid.
352 */
353#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
354#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
355#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
356#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
357#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
358#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
359#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
360#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
361
362#define EC_ACPI_MEM_BATTERY_INDEX 0x12
363
364/*
365 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
366 * is enabled (1) or disabled (0).
367 * bit 0 USB port ID 0
368 * ...
369 * bit 7 USB port ID 7
370 */
371#define EC_ACPI_MEM_USB_PORT_POWER 0x13
372
373/*
374 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
375 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
376 */
377#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
378#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
379
380/* Current version of ACPI memory address space */
381#define EC_ACPI_MEM_VERSION_CURRENT 2
382
383
185/*384/*
186 * This header file is used in coreboot both in C and ACPI code. The ACPI code385 * This header file is used in coreboot both in C and ACPI code. The ACPI code
187 * is pre-processed to handle constants but the ASL compiler is unable to386 * is pre-processed to handle constants but the ASL compiler is unable to
188 * handle actual C code so keep it separate.387 * handle actual C code so keep it separate.
189 */388 */
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 */
191 418
192/*419/*
193 * Define __packed if someone hasn't beat us to it. Linux kernel style420 * Packed structures make no assumption about alignment, so they do inefficient
194 * checking prefers __packed over __attribute__((packed)).421 * byte-wise reads.
195 */422 */
196#ifndef __packed423#define __ec_align1 __packed
197#define __packed __attribute__((packed))424#define __ec_align2 __packed
198#endif425#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
199 432
200/* LPC command status byte masks */433/* LPC command status byte masks */
201/* EC has written a byte in the data register and host hasn't read it yet */434/* EC has written a byte in the data register and host hasn't read it yet */
@@ -206,7 +439,7 @@ · 4 unmodified lines
206#define EC_LPC_STATUS_PROCESSING 0x04439#define EC_LPC_STATUS_PROCESSING 0x04
207/* Last write to EC was a command, not data */440/* Last write to EC was a command, not data */
208#define EC_LPC_STATUS_LAST_CMD 0x08441#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 */
210#define EC_LPC_STATUS_BURST_MODE 0x10443#define EC_LPC_STATUS_BURST_MODE 0x10
211/* SCI event is pending (requesting SCI query) */444/* SCI event is pending (requesting SCI query) */
212#define EC_LPC_STATUS_SCI_PENDING 0x20445#define EC_LPC_STATUS_SCI_PENDING 0x20
@@ -222,7 +455,10 @@ · 9 unmodified lines
222#define EC_LPC_STATUS_BUSY_MASK \455#define EC_LPC_STATUS_BUSY_MASK \
223 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)456 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
224 457
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 */
226enum ec_status {462enum ec_status {
227 EC_RES_SUCCESS = 0,463 EC_RES_SUCCESS = 0,
228 EC_RES_INVALID_COMMAND = 1,464 EC_RES_INVALID_COMMAND = 1,
@@ -238,7 +474,13 @@ enum ec_status { · 9 unmodified lines
238 EC_RES_OVERFLOW = 11, /* Table / data overflow */474 EC_RES_OVERFLOW = 11, /* Table / data overflow */
239 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */475 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
240 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */476 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 */
242};484};
243 485
244/*486/*
@@ -258,7 +500,8 @@ enum host_event_code { · 13 unmodified lines
258 EC_HOST_EVENT_BATTERY_CRITICAL = 7,500 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
259 EC_HOST_EVENT_BATTERY = 8,501 EC_HOST_EVENT_BATTERY = 8,
260 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,502 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,
262 EC_HOST_EVENT_THERMAL = 11,505 EC_HOST_EVENT_THERMAL = 11,
263 EC_HOST_EVENT_USB_CHARGER = 12,506 EC_HOST_EVENT_USB_CHARGER = 12,
264 EC_HOST_EVENT_KEY_PRESSED = 13,507 EC_HOST_EVENT_KEY_PRESSED = 13,
@@ -285,15 +528,34 @@ enum host_event_code { · 20 unmodified lines
285 EC_HOST_EVENT_HANG_DETECT = 20,528 EC_HOST_EVENT_HANG_DETECT = 20,
286 /* Hang detect logic detected a hang and warm rebooted the AP */529 /* Hang detect logic detected a hang and warm rebooted the AP */
287 EC_HOST_EVENT_HANG_REBOOT = 21,530 EC_HOST_EVENT_HANG_REBOOT = 21,
531
288 /* PD MCU triggering host event */532 /* PD MCU triggering host event */
289 EC_HOST_EVENT_PD_MCU = 22,533 EC_HOST_EVENT_PD_MCU = 22,
290 534
291 /* EC desires to change state of host-controlled USB mux */535 /* Battery Status flags have changed */
292 EC_HOST_EVENT_USB_MUX = 28,536 EC_HOST_EVENT_BATTERY_STATUS = 23,
537
538 /* EC encountered a panic, triggering a reset */
539 EC_HOST_EVENT_PANIC = 24,
540
541 /* Keyboard fastboot combo has been pressed */
542 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
293 543
294 /* EC RTC event occurred */544 /* EC RTC event occurred */
295 EC_HOST_EVENT_RTC = 26,545 EC_HOST_EVENT_RTC = 26,
296 546
547 /* Emulate MKBP event */
548 EC_HOST_EVENT_MKBP = 27,
549
550 /* EC desires to change state of host-controlled USB mux */
551 EC_HOST_EVENT_USB_MUX = 28,
552
553 /* TABLET/LAPTOP mode or detachable base attach/detach event */
554 EC_HOST_EVENT_MODE_CHANGE = 29,
555
556 /* Keyboard recovery combo with hardware reinitialization */
557 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
558
297 /*559 /*
298 * The high bit of the event mask is not used as a host event code. If560 * The high bit of the event mask is not used as a host event code. If
299 * it reads back as set, then the entire event mask should be561 * it reads back as set, then the entire event mask should be
@@ -304,7 +566,7 @@ enum host_event_code { · 4 unmodified lines
304 EC_HOST_EVENT_INVALID = 32566 EC_HOST_EVENT_INVALID = 32
305};567};
306/* Host event mask */568/* 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)
308 570
309/**571/**
310 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS572 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
@@ -319,7 +581,7 @@ struct ec_lpc_host_args { · 8 unmodified lines
319 uint8_t command_version;581 uint8_t command_version;
320 uint8_t data_size;582 uint8_t data_size;
321 uint8_t checksum;583 uint8_t checksum;
322} __packed;584} __ec_align4;
323 585
324/* Flags for ec_lpc_host_args.flags */586/* Flags for ec_lpc_host_args.flags */
325/*587/*
@@ -329,7 +591,7 @@ struct ec_lpc_host_args { · 3 unmodified lines
329 * If EC gets a command and this flag is not set, this is an old-style command.591 * If EC gets a command and this flag is not set, this is an old-style command.
330 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with592 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
331 * unknown length. EC must respond with an old-style response (that is,593 * unknown length. EC must respond with an old-style response (that is,
332 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).594 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
333 */595 */
334#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01596#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
335/*597/*
@@ -490,7 +752,7 @@ struct ec_host_request { · 154 unmodified lines
490 uint8_t command_version;752 uint8_t command_version;
491 uint8_t reserved;753 uint8_t reserved;
492 uint16_t data_len;754 uint16_t data_len;
493} __packed;755} __ec_align4;
494 756
495#define EC_HOST_RESPONSE_VERSION 3757#define EC_HOST_RESPONSE_VERSION 3
496 758
@@ -509,18 +771,151 @@ struct ec_host_response { · 12 unmodified lines
509 uint16_t result;771 uint16_t result;
510 uint16_t data_len;772 uint16_t data_len;
511 uint16_t reserved;773 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 */
837struct ec_host_request4 {
838 /*
839 * bits 0-3: struct_version: Structure version (=4)
840 * bit 4: is_response: Is response (=0)
841 * bits 5-6: seq_num: Sequence number
842 * bit 7: seq_dup: Sequence duplicate flag
843 */
844 uint8_t fields0;
845
846 /*
847 * bits 0-4: command_version: Command version
848 * bits 5-6: Reserved (set 0, ignore on read)
849 * bit 7: data_crc_present: Is data CRC present after data
850 */
851 uint8_t fields1;
852
853 /* Command code (EC_CMD_*) */
854 uint16_t command;
855
856 /* Length of data which follows this header (not including data CRC) */
857 uint16_t data_len;
858
859 /* Reserved (set 0, ignore on read) */
860 uint8_t reserved;
861
862 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
863 uint8_t header_crc;
864} __ec_align4;
865
866/* Version 4 response from EC */
867struct ec_host_response4 {
868 /*
869 * bits 0-3: struct_version: Structure version (=4)
870 * bit 4: is_response: Is response (=1)
871 * bits 5-6: seq_num: Sequence number
872 * bit 7: seq_dup: Sequence duplicate flag
873 */
874 uint8_t fields0;
875
876 /*
877 * bits 0-6: Reserved (set 0, ignore on read)
878 * bit 7: data_crc_present: Is data CRC present after data
879 */
880 uint8_t fields1;
881
882 /* Result code (EC_RES_*) */
883 uint16_t result;
884
885 /* Length of data which follows this header (not including data CRC) */
886 uint16_t data_len;
887
888 /* Reserved (set 0, ignore on read) */
889 uint8_t reserved;
890
891 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
892 uint8_t header_crc;
893} __ec_align4;
894
895/* Fields in fields0 byte */
896#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
897#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
898#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
899#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
900#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
901
902/* Fields in fields1 byte */
903#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
904#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
513 905
514/*****************************************************************************/906/*****************************************************************************/
515/*907/*
516 * Notes on commands:908 * Notes on commands:
517 *909 *
518 * Each command is an 16-bit command value. Commands which take params or910 * 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 is911 * return response data specify structures for that data. If no structure is
520 * specified, the command does not input or output data, respectively.912 * specified, the command does not input or output data, respectively.
521 * Parameter/response length is implicit in the structs. Some underlying913 * Parameter/response length is implicit in the structs. Some underlying
522 * communication protocols (I2C, SPI) may add length or checksum headers, but914 * communication protocols (I2C, SPI) may add length or checksum headers, but
523 * those are implementation-dependent and not defined here.915 * those are implementation-dependent and not defined here.
916 *
917 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
918 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
524 */919 */
525 920
526/*****************************************************************************/921/*****************************************************************************/
@@ -530,7 +925,7 @@ struct ec_host_response { · 3 unmodified lines
530 * Get protocol version, used to deal with non-backward compatible protocol925 * Get protocol version, used to deal with non-backward compatible protocol
531 * changes.926 * changes.
532 */927 */
533#define EC_CMD_PROTO_VERSION 0x00928#define EC_CMD_PROTO_VERSION 0x0000
534 929
535/**930/**
536 * struct ec_response_proto_version - Response to the proto version command.931 * struct ec_response_proto_version - Response to the proto version command.
@@ -538,13 +933,13 @@ struct ec_host_response { · 1 unmodified line
538 */933 */
539struct ec_response_proto_version {934struct ec_response_proto_version {
540 uint32_t version;935 uint32_t version;
541} __packed;936} __ec_align4;
542 937
543/*938/*
544 * Hello. This is a simple command to test the EC is responsive to939 * Hello. This is a simple command to test the EC is responsive to
545 * commands.940 * commands.
546 */941 */
547#define EC_CMD_HELLO 0x01942#define EC_CMD_HELLO 0x0001
548 943
549/**944/**
550 * struct ec_params_hello - Parameters to the hello command.945 * struct ec_params_hello - Parameters to the hello command.
@@ -552,7 +947,7 @@ struct ec_response_proto_version { · 1 unmodified line
552 */947 */
553struct ec_params_hello {948struct ec_params_hello {
554 uint32_t in_data;949 uint32_t in_data;
555} __packed;950} __ec_align4;
556 951
557/**952/**
558 * struct ec_response_hello - Response to the hello command.953 * struct ec_response_hello - Response to the hello command.
@@ -560,10 +955,10 @@ struct ec_params_hello { · 1 unmodified line
560 */955 */
561struct ec_response_hello {956struct ec_response_hello {
562 uint32_t out_data;957 uint32_t out_data;
563} __packed;958} __ec_align4;
564 959
565/* Get version number */960/* Get version number */
566#define EC_CMD_GET_VERSION 0x02961#define EC_CMD_GET_VERSION 0x0002
567 962
568enum ec_current_image {963enum ec_current_image {
569 EC_IMAGE_UNKNOWN = 0,964 EC_IMAGE_UNKNOWN = 0,
@@ -583,10 +978,10 @@ struct ec_response_get_version { · 13 unmodified lines
583 char version_string_rw[32];978 char version_string_rw[32];
584 char reserved[32];979 char reserved[32];
585 uint32_t current_image;980 uint32_t current_image;
586} __packed;981} __ec_align4;
587 982
588/* Read test */983/* Read test */
589#define EC_CMD_READ_TEST 0x03984#define EC_CMD_READ_TEST 0x0003
590 985
591/**986/**
592 * struct ec_params_read_test - Parameters for the read test command.987 * struct ec_params_read_test - Parameters for the read test command.
@@ -596,7 +991,7 @@ struct ec_response_get_version { · 3 unmodified lines
596struct ec_params_read_test {991struct ec_params_read_test {
597 uint32_t offset;992 uint32_t offset;
598 uint32_t size;993 uint32_t size;
599} __packed;994} __ec_align4;
600 995
601/**996/**
602 * struct ec_response_read_test - Response to the read test command.997 * struct ec_response_read_test - Response to the read test command.
@@ -604,17 +999,17 @@ struct ec_params_read_test { · 1 unmodified line
604 */999 */
605struct ec_response_read_test {1000struct ec_response_read_test {
606 uint32_t data[32];1001 uint32_t data[32];
607} __packed;1002} __ec_align4;
608 1003
609/*1004/*
610 * Get build information1005 * Get build information
611 *1006 *
612 * Response is null-terminated string.1007 * Response is null-terminated string.
613 */1008 */
614#define EC_CMD_GET_BUILD_INFO 0x041009#define EC_CMD_GET_BUILD_INFO 0x0004
615 1010
616/* Get chip info */1011/* Get chip info */
617#define EC_CMD_GET_CHIP_INFO 0x051012#define EC_CMD_GET_CHIP_INFO 0x0005
618 1013
619/**1014/**
620 * struct ec_response_get_chip_info - Response to the get chip info command.1015 * struct ec_response_get_chip_info - Response to the get chip info command.
@@ -626,10 +1021,10 @@ struct ec_response_get_chip_info { · 5 unmodified lines
626 char vendor[32];1021 char vendor[32];
627 char name[32];1022 char name[32];
628 char revision[32];1023 char revision[32];
629} __packed;1024} __ec_align4;
630 1025
631/* Get board HW version */1026/* Get board HW version */
632#define EC_CMD_GET_BOARD_VERSION 0x061027#define EC_CMD_GET_BOARD_VERSION 0x0006
633 1028
634/**1029/**
635 * struct ec_response_board_version - Response to the board version command.1030 * struct ec_response_board_version - Response to the board version command.
@@ -637,7 +1032,7 @@ struct ec_response_get_chip_info { · 1 unmodified line
637 */1032 */
638struct ec_response_board_version {1033struct ec_response_board_version {
639 uint16_t board_version;1034 uint16_t board_version;
640} __packed;1035} __ec_align2;
641 1036
642/*1037/*
643 * Read memory-mapped data.1038 * Read memory-mapped data.
@@ -647,7 +1042,7 @@ struct ec_response_board_version { · 3 unmodified lines
647 *1042 *
648 * Response is params.size bytes of data.1043 * Response is params.size bytes of data.
649 */1044 */
650#define EC_CMD_READ_MEMMAP 0x071045#define EC_CMD_READ_MEMMAP 0x0007
651 1046
652/**1047/**
653 * struct ec_params_read_memmap - Parameters for the read memory map command.1048 * struct ec_params_read_memmap - Parameters for the read memory map command.
@@ -657,10 +1052,10 @@ struct ec_response_board_version { · 3 unmodified lines
657struct ec_params_read_memmap {1052struct ec_params_read_memmap {
658 uint8_t offset;1053 uint8_t offset;
659 uint8_t size;1054 uint8_t size;
660} __packed;1055} __ec_align1;
661 1056
662/* Read versions supported for a command */1057/* Read versions supported for a command */
663#define EC_CMD_GET_CMD_VERSIONS 0x081058#define EC_CMD_GET_CMD_VERSIONS 0x0008
664 1059
665/**1060/**
666 * struct ec_params_get_cmd_versions - Parameters for the get command versions.1061 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
@@ -668,7 +1063,7 @@ struct ec_params_read_memmap { · 1 unmodified line
668 */1063 */
669struct ec_params_get_cmd_versions {1064struct ec_params_get_cmd_versions {
670 uint8_t cmd;1065 uint8_t cmd;
671} __packed;1066} __ec_align1;
672 1067
673/**1068/**
674 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command1069 * 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
677 */1072 */
678struct ec_params_get_cmd_versions_v1 {1073struct ec_params_get_cmd_versions_v1 {
679 uint16_t cmd;1074 uint16_t cmd;
680} __packed;1075} __ec_align2;
681 1076
682/**1077/**
683 * struct ec_response_get_cmd_version - Response to the get command versions.1078 * struct ec_response_get_cmd_version - Response to the get command versions.
@@ -686,20 +1081,20 @@ struct ec_params_get_cmd_versions_v1 { · 2 unmodified lines
686 */1081 */
687struct ec_response_get_cmd_versions {1082struct ec_response_get_cmd_versions {
688 uint32_t version_mask;1083 uint32_t version_mask;
689} __packed;1084} __ec_align4;
690 1085
691/*1086/*
692 * Check EC communcations status (busy). This is needed on i2c/spi but not1087 * Check EC communications status (busy). This is needed on i2c/spi but not
693 * on lpc since it has its own out-of-band busy indicator.1088 * on lpc since it has its own out-of-band busy indicator.
694 *1089 *
695 * lpc must read the status from the command register. Attempting this on1090 * lpc must read the status from the command register. Attempting this on
696 * lpc will overwrite the args/parameter space and corrupt its data.1091 * lpc will overwrite the args/parameter space and corrupt its data.
697 */1092 */
698#define EC_CMD_GET_COMMS_STATUS 0x091093#define EC_CMD_GET_COMMS_STATUS 0x0009
699 1094
700/* Avoid using ec_status which is for return values */1095/* Avoid using ec_status which is for return values */
701enum ec_comms_status {1096enum ec_comms_status {
702 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */1097 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
703};1098};
704 1099
705/**1100/**
@@ -709,29 +1104,29 @@ enum ec_comms_status { · 3 unmodified lines
709 */1104 */
710struct ec_response_get_comms_status {1105struct ec_response_get_comms_status {
711 uint32_t flags; /* Mask of enum ec_comms_status */1106 uint32_t flags; /* Mask of enum ec_comms_status */
712} __packed;1107} __ec_align4;
713 1108
714/* Fake a variety of responses, purely for testing purposes. */1109/* Fake a variety of responses, purely for testing purposes. */
715#define EC_CMD_TEST_PROTOCOL 0x0a1110#define EC_CMD_TEST_PROTOCOL 0x000A
716 1111
717/* Tell the EC what to send back to us. */1112/* Tell the EC what to send back to us. */
718struct ec_params_test_protocol {1113struct ec_params_test_protocol {
719 uint32_t ec_result;1114 uint32_t ec_result;
720 uint32_t ret_len;1115 uint32_t ret_len;
721 uint8_t buf[32];1116 uint8_t buf[32];
722} __packed;1117} __ec_align4;
723 1118
724/* Here it comes... */1119/* Here it comes... */
725struct ec_response_test_protocol {1120struct ec_response_test_protocol {
726 uint8_t buf[32];1121 uint8_t buf[32];
727} __packed;1122} __ec_align4;
728 1123
729/* Get prococol information */1124/* Get protocol information */
730#define EC_CMD_GET_PROTOCOL_INFO 0x0b1125#define EC_CMD_GET_PROTOCOL_INFO 0x000B
731 1126
732/* Flags for ec_response_get_protocol_info.flags */1127/* Flags for ec_response_get_protocol_info.flags */
733/* EC_RES_IN_PROGRESS may be returned if a command is slow */1128/* EC_RES_IN_PROGRESS may be returned if a command is slow */
734#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)1129#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
735 1130
736/**1131/**
737 * struct ec_response_get_protocol_info - Response to the get protocol info.1132 * struct ec_response_get_protocol_info - Response to the get protocol info.
@@ -747,7 +1142,7 @@ struct ec_response_get_protocol_info { · 9 unmodified lines
747 uint16_t max_request_packet_size;1142 uint16_t max_request_packet_size;
748 uint16_t max_response_packet_size;1143 uint16_t max_response_packet_size;
749 uint32_t flags;1144 uint32_t flags;
750} __packed;1145} __ec_align4;
751 1146
752 1147
753/*****************************************************************************/1148/*****************************************************************************/
@@ -765,19 +1160,19 @@ struct ec_response_get_protocol_info { · 11 unmodified lines
765struct ec_params_get_set_value {1160struct ec_params_get_set_value {
766 uint32_t flags;1161 uint32_t flags;
767 uint32_t value;1162 uint32_t value;
768} __packed;1163} __ec_align4;
769 1164
770struct ec_response_get_set_value {1165struct ec_response_get_set_value {
771 uint32_t flags;1166 uint32_t flags;
772 uint32_t value;1167 uint32_t value;
773} __packed;1168} __ec_align4;
774 1169
775/* More than one command can use these structs to get/set paramters. */1170/* More than one command can use these structs to get/set parameters. */
776#define EC_CMD_GSV_PAUSE_IN_S5 0x0c1171#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
777 1172
778/*****************************************************************************/1173/*****************************************************************************/
779/* List the features supported by the firmware */1174/* List the features supported by the firmware */
780#define EC_CMD_GET_FEATURES 0x0d1175#define EC_CMD_GET_FEATURES 0x000D
781 1176
782/* Supported features */1177/* Supported features */
783enum ec_feature_code {1178enum ec_feature_code {
@@ -884,24 +1279,36 @@ enum ec_feature_code { · 100 unmodified lines
884 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,1279 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
885 /* EC supports audio codec. */1280 /* EC supports audio codec. */
886 EC_FEATURE_AUDIO_CODEC = 38,1281 EC_FEATURE_AUDIO_CODEC = 38,
887 /* EC Supports SCP. */1282 /* The MCU is a System Companion Processor (SCP). */
888 EC_FEATURE_SCP = 39,1283 EC_FEATURE_SCP = 39,
889 /* The MCU is an Integrated Sensor Hub */1284 /* The MCU is an Integrated Sensor Hub */
890 EC_FEATURE_ISH = 40,1285 EC_FEATURE_ISH = 40,
891};1286};
892 1287
893#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))1288#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
894#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))1289#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
895 1290
896struct ec_response_get_features {1291struct ec_response_get_features {
897 uint32_t flags[2];1292 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
1302struct ec_sku_id_info {
1303 uint32_t sku_id;
1304} __ec_align4;
899 1305
900/*****************************************************************************/1306/*****************************************************************************/
901/* Flash commands */1307/* Flash commands */
902 1308
903/* Get flash info */1309/* Get flash info */
904#define EC_CMD_FLASH_INFO 0x101310#define EC_CMD_FLASH_INFO 0x0010
1311#define EC_VER_FLASH_INFO 2
905 1312
906/**1313/**
907 * struct ec_response_flash_info - Response to the flash info command.1314 * struct ec_response_flash_info - Response to the flash info command.
@@ -920,11 +1327,22 @@ struct ec_response_flash_info { · 12 unmodified lines
920 uint32_t write_block_size;1327 uint32_t write_block_size;
921 uint32_t erase_block_size;1328 uint32_t erase_block_size;
922 uint32_t protect_block_size;1329 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)
924 1337
925/* Flags for version 1+ flash info command */1338/*
926/* EC flash erases bits to 0 instead of 1 */1339 * Flash must be selected for read/write/erase operations to succeed. This may
927#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)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)
928 1346
929/**1347/**
930 * struct ec_response_flash_info_1 - Response to the flash info v1 command.1348 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
@@ -946,7 +1364,14 @@ struct ec_response_flash_info { · 15 unmodified lines
946 * fields following.1364 * fields following.
947 *1365 *
948 * gcc anonymous structs don't seem to get along with the __packed directive;1366 * gcc anonymous structs don't seem to get along with the __packed directive;
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.
950 */1375 */
951struct ec_response_flash_info_1 {1376struct ec_response_flash_info_1 {
952 /* Version 0 fields; see above for description */1377 /* Version 0 fields; see above for description */
@@ -958,14 +1383,50 @@ struct ec_response_flash_info_1 { · 5 unmodified lines
958 /* Version 1 adds these fields: */1383 /* Version 1 adds these fields: */
959 uint32_t write_ideal_size;1384 uint32_t write_ideal_size;
960 uint32_t flags;1385 uint32_t flags;
961} __packed;1386} __ec_align4;
1387
1388struct ec_params_flash_info_2 {
1389 /* Number of banks to describe */
1390 uint16_t num_banks_desc;
1391 /* Reserved; set 0; ignore on read */
1392 uint8_t reserved[2];
1393} __ec_align4;
1394
1395struct ec_flash_bank {
1396 /* Number of sector is in this bank. */
1397 uint16_t count;
1398 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1399 uint8_t size_exp;
1400 /* Minimal write size for the sectors in this bank */
1401 uint8_t write_size_exp;
1402 /* Erase size for the sectors in this bank */
1403 uint8_t erase_size_exp;
1404 /* Size for write protection, usually identical to erase size. */
1405 uint8_t protect_size_exp;
1406 /* Reserved; set 0; ignore on read */
1407 uint8_t reserved[2];
1408};
1409
1410struct ec_response_flash_info_2 {
1411 /* Total flash in the EC. */
1412 uint32_t flash_size;
1413 /* Flags; see EC_FLASH_INFO_* */
1414 uint32_t flags;
1415 /* Maximum size to use to send data to write to the EC. */
1416 uint32_t write_ideal_size;
1417 /* Number of banks present in the EC. */
1418 uint16_t num_banks_total;
1419 /* Number of banks described in banks array. */
1420 uint16_t num_banks_desc;
1421 struct ec_flash_bank banks[0];
1422} __ec_align4;
962 1423
963/*1424/*
964 * Read flash1425 * Read flash
965 *1426 *
966 * Response is params.size bytes of data.1427 * Response is params.size bytes of data.
967 */1428 */
968#define EC_CMD_FLASH_READ 0x111429#define EC_CMD_FLASH_READ 0x0011
969 1430
970/**1431/**
971 * struct ec_params_flash_read - Parameters for the flash read command.1432 * struct ec_params_flash_read - Parameters for the flash read command.
@@ -975,10 +1436,10 @@ struct ec_response_flash_info_1 { · 3 unmodified lines
975struct ec_params_flash_read {1436struct ec_params_flash_read {
976 uint32_t offset;1437 uint32_t offset;
977 uint32_t size;1438 uint32_t size;
978} __packed;1439} __ec_align4;
979 1440
980/* Write flash */1441/* Write flash */
981#define EC_CMD_FLASH_WRITE 0x121442#define EC_CMD_FLASH_WRITE 0x0012
982#define EC_VER_FLASH_WRITE 11443#define EC_VER_FLASH_WRITE 1
983 1444
984/* Version 0 of the flash command supported only 64 bytes of data */1445/* Version 0 of the flash command supported only 64 bytes of data */
@@ -993,20 +1454,57 @@ struct ec_params_flash_write { · 8 unmodified lines
993 uint32_t offset;1454 uint32_t offset;
994 uint32_t size;1455 uint32_t size;
995 /* Followed by data to write */1456 /* Followed by data to write */
996} __packed;1457} __ec_align4;
997 1458
998/* Erase flash */1459/* Erase flash */
999#define EC_CMD_FLASH_ERASE 0x131460#define EC_CMD_FLASH_ERASE 0x0013
1000 1461
1001/**1462/**
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.
1003 * @offset: Byte offset to erase.1464 * @offset: Byte offset to erase.
1004 * @size: Size to erase in bytes.1465 * @size: Size to erase in bytes.
1005 */1466 */
1006struct ec_params_flash_erase {1467struct ec_params_flash_erase {
1007 uint32_t offset;1468 uint32_t offset;
1008 uint32_t size;1469 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 */
1489enum ec_flash_erase_cmd {
1490 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1491 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1492 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1493};
1494
1495/**
1496 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1497 * @cmd: One of ec_flash_erase_cmd.
1498 * @reserved: Pad byte; currently always contains 0.
1499 * @flag: No flags defined yet; set to 0.
1500 * @params: Same as v0 parameters.
1501 */
1502struct ec_params_flash_erase_v1 {
1503 uint8_t cmd;
1504 uint8_t reserved;
1505 uint16_t flag;
1506 struct ec_params_flash_erase params;
1507} __ec_align4;
1010 1508
1011/*1509/*
1012 * Get/set flash protection.1510 * Get/set flash protection.
@@ -1018,31 +1516,40 @@ struct ec_params_flash_erase { · 5 unmodified lines
1018 *1516 *
1019 * If mask=0, simply returns the current flags state.1517 * If mask=0, simply returns the current flags state.
1020 */1518 */
1021#define EC_CMD_FLASH_PROTECT 0x151519#define EC_CMD_FLASH_PROTECT 0x0015
1022#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */1520#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1023 1521
1024/* Flags for flash protection */1522/* Flags for flash protection */
1025/* RO flash code protected when the EC boots */1523/* 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)
1027/*1525/*
1028 * RO flash code protected now. If this bit is set, at-boot status cannot1526 * RO flash code protected now. If this bit is set, at-boot status cannot
1029 * be changed.1527 * be changed.
1030 */1528 */
1031#define EC_FLASH_PROTECT_RO_NOW (1 << 1)1529#define EC_FLASH_PROTECT_RO_NOW BIT(1)
1032/* Entire flash code protected now, until reboot. */1530/* 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)
1034/* Flash write protect GPIO is asserted now */1532/* 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)
1036/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */1534/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1037#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)1535#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
1038/*1536/*
1039 * Error - flash protection is in inconsistent state. At least one bank of1537 * Error - flash protection is in inconsistent state. At least one bank of
1040 * flash which should be protected is not protected. Usually fixed by1538 * flash which should be protected is not protected. Usually fixed by
1041 * re-requesting the desired flags, or by a hard reset if that fails.1539 * re-requesting the desired flags, or by a hard reset if that fails.
1042 */1540 */
1043#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)1541#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
1044/* Entile flash code protected when the EC boots */1542/* Entire flash code protected when the EC boots */
1045#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)1543#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
1544/* RW flash code protected when the EC boots */
1545#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
1546/* RW flash code protected now. */
1547#define EC_FLASH_PROTECT_RW_NOW BIT(8)
1548/* Rollback information flash region protected when the EC boots */
1549#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
1550/* Rollback information flash region protected now */
1551#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
1552
1046 1553
1047/**1554/**
1048 * struct ec_params_flash_protect - Parameters for the flash protect command.1555 * struct ec_params_flash_protect - Parameters for the flash protect command.
@@ -1052,7 +1559,7 @@ struct ec_params_flash_erase { · 3 unmodified lines
1052struct ec_params_flash_protect {1559struct ec_params_flash_protect {
1053 uint32_t mask;1560 uint32_t mask;
1054 uint32_t flags;1561 uint32_t flags;
1055} __packed;1562} __ec_align4;
1056 1563
1057/**1564/**
1058 * struct ec_response_flash_protect - Response to the flash protect command.1565 * struct ec_response_flash_protect - Response to the flash protect command.
@@ -1067,7 +1574,7 @@ struct ec_response_flash_protect { · 8 unmodified lines
1067 uint32_t flags;1574 uint32_t flags;
1068 uint32_t valid_flags;1575 uint32_t valid_flags;
1069 uint32_t writable_flags;1576 uint32_t writable_flags;
1070} __packed;1577} __ec_align4;
1071 1578
1072/*1579/*
1073 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash1580 * 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
1075 */1582 */
1076 1583
1077/* Get the region offset/size */1584/* Get the region offset/size */
1078#define EC_CMD_FLASH_REGION_INFO 0x161585#define EC_CMD_FLASH_REGION_INFO 0x0016
1079#define EC_VER_FLASH_REGION_INFO 11586#define EC_VER_FLASH_REGION_INFO 1
1080 1587
1081enum ec_flash_region {1588enum ec_flash_region {
1082 /* Region which holds read-only EC image */1589 /* Region which holds read-only EC image */
1083 EC_FLASH_REGION_RO = 0,1590 EC_FLASH_REGION_RO = 0,
1084 /* Region which holds rewritable EC image */1591 /*
1085 EC_FLASH_REGION_RW,1592 * Region which holds active RW image. 'Active' is different from
1593 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1594 * scheduled to run, active/non-active applies only to RW images (for
1595 * the same reason 'update' applies only to RW images. It's a state of
1596 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1597 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1598 * doesn't enter 'running' state but it's still active on a flash.
1599 */
1600 EC_FLASH_REGION_ACTIVE,
1086 /*1601 /*
1087 * Region which should be write-protected in the factory (a superset of1602 * Region which should be write-protected in the factory (a superset of
1088 * EC_FLASH_REGION_RO)1603 * EC_FLASH_REGION_RO)
1089 */1604 */
1090 EC_FLASH_REGION_WP_RO,1605 EC_FLASH_REGION_WP_RO,
1606 /* Region which holds updatable (non-active) RW image */
1607 EC_FLASH_REGION_UPDATE,
1091 /* Number of regions */1608 /* Number of regions */
1092 EC_FLASH_REGION_COUNT,1609 EC_FLASH_REGION_COUNT,
1093};1610};
1611/*
1612 * 'RW' is vague if there are multiple RW images; we mean the active one,
1613 * so the old constant is deprecated.
1614 */
1615#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
1094 1616
1095/**1617/**
1096 * struct ec_params_flash_region_info - Parameters for the flash region info1618 * struct ec_params_flash_region_info - Parameters for the flash region info
@@ -1099,15 +1621,15 @@ enum ec_flash_region { · 2 unmodified lines
1099 */1621 */
1100struct ec_params_flash_region_info {1622struct ec_params_flash_region_info {
1101 uint32_t region;1623 uint32_t region;
1102} __packed;1624} __ec_align4;
1103 1625
1104struct ec_response_flash_region_info {1626struct ec_response_flash_region_info {
1105 uint32_t offset;1627 uint32_t offset;
1106 uint32_t size;1628 uint32_t size;
1107} __packed;1629} __ec_align4;
1108 1630
1109/* Read/write VbNvContext */1631/* Read/write VbNvContext */
1110#define EC_CMD_VBNV_CONTEXT 0x171632#define EC_CMD_VBNV_CONTEXT 0x0017
1111#define EC_VER_VBNV_CONTEXT 11633#define EC_VER_VBNV_CONTEXT 1
1112#define EC_VBNV_BLOCK_SIZE 161634#define EC_VBNV_BLOCK_SIZE 16
1113 1635
@@ -1119,52 +1641,99 @@ enum ec_vbnvcontext_op { · 5 unmodified lines
1119struct ec_params_vbnvcontext {1641struct ec_params_vbnvcontext {
1120 uint32_t op;1642 uint32_t op;
1121 uint8_t block[EC_VBNV_BLOCK_SIZE];1643 uint8_t block[EC_VBNV_BLOCK_SIZE];
1122} __packed;1644} __ec_align4;
1123 1645
1124struct ec_response_vbnvcontext {1646struct ec_response_vbnvcontext {
1125 uint8_t block[EC_VBNV_BLOCK_SIZE];1647 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
1654struct ec_response_flash_spi_info {
1655 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1656 uint8_t jedec[3];
1657
1658 /* Pad byte; currently always contains 0 */
1659 uint8_t reserved0;
1660
1661 /* Manufacturer / device ID from command 0x90 */
1662 uint8_t mfr_dev_id[2];
1663
1664 /* Status registers from command 0x05 and 0x35 */
1665 uint8_t sr1, sr2;
1666} __ec_align1;
1667
1668
1669/* Select flash during flash operations */
1670#define EC_CMD_FLASH_SELECT 0x0019
1671
1672/**
1673 * struct ec_params_flash_select - Parameters for the flash select command.
1674 * @select: 1 to select flash, 0 to deselect flash
1675 */
1676struct ec_params_flash_select {
1677 uint8_t select;
1678} __ec_align4;
1679
1127 1680
1128/*****************************************************************************/1681/*****************************************************************************/
1129/* PWM commands */1682/* PWM commands */
1130 1683
1131/* Get fan target RPM */1684/* Get fan target RPM */
1132#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x201685#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
1133 1686
1134struct ec_response_pwm_get_fan_rpm {1687struct ec_response_pwm_get_fan_rpm {
1135 uint32_t rpm;1688 uint32_t rpm;
1136} __packed;1689} __ec_align4;
1137 1690
1138/* Set target fan RPM */1691/* Set target fan RPM */
1139#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x211692#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
1693
1694/* Version 0 of input params */
1695struct ec_params_pwm_set_fan_target_rpm_v0 {
1696 uint32_t rpm;
1697} __ec_align4;
1140 1698
1141struct ec_params_pwm_set_fan_target_rpm {1699/* Version 1 of input params */
1700struct ec_params_pwm_set_fan_target_rpm_v1 {
1142 uint32_t rpm;1701 uint32_t rpm;
1143} __packed;1702 uint8_t fan_idx;
1703} __ec_align_size1;
1144 1704
1145/* Get keyboard backlight */1705/* Get keyboard backlight */
1146#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x221706/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1707#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
1147 1708
1148struct ec_response_pwm_get_keyboard_backlight {1709struct ec_response_pwm_get_keyboard_backlight {
1149 uint8_t percent;1710 uint8_t percent;
1150 uint8_t enabled;1711 uint8_t enabled;
1151} __packed;1712} __ec_align1;
1152 1713
1153/* Set keyboard backlight */1714/* Set keyboard backlight */
1154#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x231715/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
1716#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
1155 1717
1156struct ec_params_pwm_set_keyboard_backlight {1718struct ec_params_pwm_set_keyboard_backlight {
1157 uint8_t percent;1719 uint8_t percent;
1158} __packed;1720} __ec_align1;
1159 1721
1160/* Set target fan PWM duty cycle */1722/* Set target fan PWM duty cycle */
1161#define EC_CMD_PWM_SET_FAN_DUTY 0x241723#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
1724
1725/* Version 0 of input params */
1726struct ec_params_pwm_set_fan_duty_v0 {
1727 uint32_t percent;
1728} __ec_align4;
1162 1729
1163struct ec_params_pwm_set_fan_duty {1730/* Version 1 of input params */
1731struct ec_params_pwm_set_fan_duty_v1 {
1164 uint32_t percent;1732 uint32_t percent;
1165} __packed;1733 uint8_t fan_idx;
1734} __ec_align_size1;
1166 1735
1167#define EC_CMD_PWM_SET_DUTY 0x251736#define EC_CMD_PWM_SET_DUTY 0x0025
1168/* 16 bit duty cycle, 0xffff = 100% */1737/* 16 bit duty cycle, 0xffff = 100% */
1169#define EC_PWM_MAX_DUTY 0xffff1738#define EC_PWM_MAX_DUTY 0xffff
1170 1739
@@ -1182,18 +1751,18 @@ struct ec_params_pwm_set_duty { · 11 unmodified lines
1182 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */1751 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1183 uint8_t pwm_type; /* ec_pwm_type */1752 uint8_t pwm_type; /* ec_pwm_type */
1184 uint8_t index; /* Type-specific index, or 0 if unique */1753 uint8_t index; /* Type-specific index, or 0 if unique */
1185} __packed;1754} __ec_align4;
1186 1755
1187#define EC_CMD_PWM_GET_DUTY 0x261756#define EC_CMD_PWM_GET_DUTY 0x0026
1188 1757
1189struct ec_params_pwm_get_duty {1758struct ec_params_pwm_get_duty {
1190 uint8_t pwm_type; /* ec_pwm_type */1759 uint8_t pwm_type; /* ec_pwm_type */
1191 uint8_t index; /* Type-specific index, or 0 if unique */1760 uint8_t index; /* Type-specific index, or 0 if unique */
1192} __packed;1761} __ec_align1;
1193 1762
1194struct ec_response_pwm_get_duty {1763struct ec_response_pwm_get_duty {
1195 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */1764 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1196} __packed;1765} __ec_align2;
1197 1766
1198/*****************************************************************************/1767/*****************************************************************************/
1199/*1768/*
@@ -1202,11 +1771,11 @@ struct ec_response_pwm_get_duty { · 2 unmodified lines
1202 * into a subcommand. We'll make separate structs for subcommands with1771 * into a subcommand. We'll make separate structs for subcommands with
1203 * different input args, so that we know how much to expect.1772 * different input args, so that we know how much to expect.
1204 */1773 */
1205#define EC_CMD_LIGHTBAR_CMD 0x281774#define EC_CMD_LIGHTBAR_CMD 0x0028
1206 1775
1207struct rgb_s {1776struct rgb_s {
1208 uint8_t r, g, b;1777 uint8_t r, g, b;
1209};1778} __ec_todo_unpacked;
1210 1779
1211#define LB_BATTERY_LEVELS 41780#define LB_BATTERY_LEVELS 4
1212 1781
@@ -1246,7 +1815,7 @@ struct lightbar_params_v0 { · 33 unmodified lines
1246 1815
1247 /* Color palette */1816 /* Color palette */
1248 struct rgb_s color[8]; /* 0-3 are Google colors */1817 struct rgb_s color[8]; /* 0-3 are Google colors */
1249} __packed;1818} __ec_todo_packed;
1250 1819
1251struct lightbar_params_v1 {1820struct lightbar_params_v1 {
1252 /* Timing */1821 /* Timing */
@@ -1259,7 +1828,10 @@ struct lightbar_params_v1 { · 6 unmodified lines
1259 int32_t s3_sleep_for;1828 int32_t s3_sleep_for;
1260 int32_t s3_ramp_up;1829 int32_t s3_ramp_up;
1261 int32_t s3_ramp_down;1830 int32_t s3_ramp_down;
1831 int32_t s5_ramp_up;
1832 int32_t s5_ramp_down;
1262 int32_t tap_tick_delay;1833 int32_t tap_tick_delay;
1834 int32_t tap_gate_delay;
1263 int32_t tap_display_time;1835 int32_t tap_display_time;
1264 1836
1265 /* Tap-for-battery params */1837 /* Tap-for-battery params */
@@ -1287,84 +1859,182 @@ struct lightbar_params_v1 { · 21 unmodified lines
1287 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */1859 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1288 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */1860 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1289 1861
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
1878struct lightbar_params_v2_timing {
1879 /* Timing */
1880 int32_t google_ramp_up;
1881 int32_t google_ramp_down;
1882 int32_t s3s0_ramp_up;
1883 int32_t s0_tick_delay[2]; /* AC=0/1 */
1884 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1885 int32_t s0s3_ramp_down;
1886 int32_t s3_sleep_for;
1887 int32_t s3_ramp_up;
1888 int32_t s3_ramp_down;
1889 int32_t s5_ramp_up;
1890 int32_t s5_ramp_down;
1891 int32_t tap_tick_delay;
1892 int32_t tap_gate_delay;
1893 int32_t tap_display_time;
1894} __ec_todo_packed;
1895
1896struct lightbar_params_v2_tap {
1897 /* Tap-for-battery params */
1898 uint8_t tap_pct_red;
1899 uint8_t tap_pct_green;
1900 uint8_t tap_seg_min_on;
1901 uint8_t tap_seg_max_on;
1902 uint8_t tap_seg_osc;
1903 uint8_t tap_idx[3];
1904} __ec_todo_packed;
1905
1906struct lightbar_params_v2_oscillation {
1907 /* Oscillation */
1908 uint8_t osc_min[2]; /* AC=0/1 */
1909 uint8_t osc_max[2]; /* AC=0/1 */
1910 uint8_t w_ofs[2]; /* AC=0/1 */
1911} __ec_todo_packed;
1912
1913struct lightbar_params_v2_brightness {
1914 /* Brightness limits based on the backlight and AC. */
1915 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1916 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1917 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1918} __ec_todo_packed;
1919
1920struct lightbar_params_v2_thresholds {
1921 /* Battery level thresholds */
1922 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1923} __ec_todo_packed;
1924
1925struct lightbar_params_v2_colors {
1926 /* Map [AC][battery_level] to color index */
1927 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1928 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1929
1930 /* s5: single color pulse on inhibited power-up */
1931 uint8_t s5_idx;
1932
1290 /* Color palette */1933 /* Color palette */
1291 struct rgb_s color[8]; /* 0-3 are Google colors */1934 struct rgb_s color[8]; /* 0-3 are Google colors */
1292} __packed;1935} __ec_todo_packed;
1293 1936
1294/* Lightbar program */1937/* Lightbar program. */
1295#define EC_LB_PROG_LEN 1921938#define EC_LB_PROG_LEN 192
1296struct lightbar_program {1939struct lightbar_program {
1297 uint8_t size;1940 uint8_t size;
1298 uint8_t data[EC_LB_PROG_LEN];1941 uint8_t data[EC_LB_PROG_LEN];
1299};1942} __ec_todo_unpacked;
1300 1943
1301struct ec_params_lightbar {1944struct ec_params_lightbar {
1302 uint8_t cmd; /* Command (see enum lightbar_command) */1945 uint8_t cmd; /* Command (see enum lightbar_command) */
1303 union {1946 union {
1304 struct {1947 /*
1305 /* no args */1948 * The following commands have no args:
1306 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,1949 *
1307 version, get_brightness, get_demo, suspend, resume;1950 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1951 * version, get_brightness, get_demo, suspend, resume,
1952 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
1953 * get_params_v2_bright, get_params_v2_thlds,
1954 * get_params_v2_colors
1955 *
1956 * Don't use an empty struct, because C++ hates that.
1957 */
1308 1958
1309 struct {1959 struct __ec_todo_unpacked {
1310 uint8_t num;1960 uint8_t num;
1311 } set_brightness, seq, demo;1961 } set_brightness, seq, demo;
1312 1962
1313 struct {1963 struct __ec_todo_unpacked {
1314 uint8_t ctrl, reg, value;1964 uint8_t ctrl, reg, value;
1315 } reg;1965 } reg;
1316 1966
1317 struct {1967 struct __ec_todo_unpacked {
1318 uint8_t led, red, green, blue;1968 uint8_t led, red, green, blue;
1319 } set_rgb;1969 } set_rgb;
1320 1970
1321 struct {1971 struct __ec_todo_unpacked {
1322 uint8_t led;1972 uint8_t led;
1323 } get_rgb;1973 } get_rgb;
1324 1974
1325 struct {1975 struct __ec_todo_unpacked {
1326 uint8_t enable;1976 uint8_t enable;
1327 } manual_suspend_ctrl;1977 } manual_suspend_ctrl;
1328 1978
1329 struct lightbar_params_v0 set_params_v0;1979 struct lightbar_params_v0 set_params_v0;
1330 struct lightbar_params_v1 set_params_v1;1980 struct lightbar_params_v1 set_params_v1;
1981
1982 struct lightbar_params_v2_timing set_v2par_timing;
1983 struct lightbar_params_v2_tap set_v2par_tap;
1984 struct lightbar_params_v2_oscillation set_v2par_osc;
1985 struct lightbar_params_v2_brightness set_v2par_bright;
1986 struct lightbar_params_v2_thresholds set_v2par_thlds;
1987 struct lightbar_params_v2_colors set_v2par_colors;
1988
1331 struct lightbar_program set_program;1989 struct lightbar_program set_program;
1332 };1990 };
1333} __packed;1991} __ec_todo_packed;
1334 1992
1335struct ec_response_lightbar {1993struct ec_response_lightbar {
1336 union {1994 union {
1337 struct {1995 struct __ec_todo_unpacked {
1338 struct {1996 struct __ec_todo_unpacked {
1339 uint8_t reg;1997 uint8_t reg;
1340 uint8_t ic0;1998 uint8_t ic0;
1341 uint8_t ic1;1999 uint8_t ic1;
1342 } vals[23];2000 } vals[23];
1343 } dump;2001 } dump;
1344 2002
1345 struct {2003 struct __ec_todo_unpacked {
1346 uint8_t num;2004 uint8_t num;
1347 } get_seq, get_brightness, get_demo;2005 } get_seq, get_brightness, get_demo;
1348 2006
1349 struct lightbar_params_v0 get_params_v0;2007 struct lightbar_params_v0 get_params_v0;
1350 struct lightbar_params_v1 get_params_v1;2008 struct lightbar_params_v1 get_params_v1;
1351 2009
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 {
1353 uint32_t num;2019 uint32_t num;
1354 uint32_t flags;2020 uint32_t flags;
1355 } version;2021 } version;
1356 2022
1357 struct {2023 struct __ec_todo_unpacked {
1358 uint8_t red, green, blue;2024 uint8_t red, green, blue;
1359 } get_rgb;2025 } get_rgb;
1360 2026
1361 struct {2027 /*
1362 /* no return params */2028 * The following commands have no response:
1363 } off, on, init, set_brightness, seq, reg, set_rgb,2029 *
1364 demo, set_params_v0, set_params_v1,2030 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
1365 set_program, manual_suspend_ctrl, suspend, resume;2031 * set_params_v0, set_params_v1, set_program,
2032 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2033 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2034 * set_v2par_thlds, set_v2par_colors
2035 */
1366 };2036 };
1367} __packed;2037} __ec_todo_packed;
1368 2038
1369/* Lightbar commands */2039/* Lightbar commands */
1370enum lightbar_command {2040enum lightbar_command {
@@ -1390,13 +2060,25 @@ enum lightbar_command { · 19 unmodified lines
1390 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,2060 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1391 LIGHTBAR_CMD_SUSPEND = 20,2061 LIGHTBAR_CMD_SUSPEND = 20,
1392 LIGHTBAR_CMD_RESUME = 21,2062 LIGHTBAR_CMD_RESUME = 21,
2063 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2064 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2065 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2066 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2067 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2068 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2069 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2070 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2071 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2072 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2073 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2074 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
1393 LIGHTBAR_NUM_CMDS2075 LIGHTBAR_NUM_CMDS
1394};2076};
1395 2077
1396/*****************************************************************************/2078/*****************************************************************************/
1397/* LED control commands */2079/* LED control commands */
1398 2080
1399#define EC_CMD_LED_CONTROL 0x292081#define EC_CMD_LED_CONTROL 0x0029
1400 2082
1401enum ec_led_id {2083enum ec_led_id {
1402 /* LED to indicate battery state of charge */2084 /* LED to indicate battery state of charge */
@@ -1408,13 +2090,21 @@ enum ec_led_id { · 5 unmodified lines
1408 EC_LED_ID_POWER_LED,2090 EC_LED_ID_POWER_LED,
1409 /* LED on power adapter or its plug */2091 /* LED on power adapter or its plug */
1410 EC_LED_ID_ADAPTER_LED,2092 EC_LED_ID_ADAPTER_LED,
2093 /* LED to indicate left side */
2094 EC_LED_ID_LEFT_LED,
2095 /* LED to indicate right side */
2096 EC_LED_ID_RIGHT_LED,
2097 /* LED to indicate recovery mode with HW_REINIT */
2098 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2099 /* LED to indicate sysrq debug mode. */
2100 EC_LED_ID_SYSRQ_DEBUG_LED,
1411 2101
1412 EC_LED_ID_COUNT2102 EC_LED_ID_COUNT
1413};2103};
1414 2104
1415/* LED control flags */2105/* LED control flags */
1416#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */2106#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
1417#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */2107#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
1418 2108
1419enum ec_led_colors {2109enum ec_led_colors {
1420 EC_LED_COLOR_RED = 0,2110 EC_LED_COLOR_RED = 0,
@@ -1422,6 +2112,7 @@ enum ec_led_colors { · 1 unmodified line
1422 EC_LED_COLOR_BLUE,2112 EC_LED_COLOR_BLUE,
1423 EC_LED_COLOR_YELLOW,2113 EC_LED_COLOR_YELLOW,
1424 EC_LED_COLOR_WHITE,2114 EC_LED_COLOR_WHITE,
2115 EC_LED_COLOR_AMBER,
1425 2116
1426 EC_LED_COLOR_COUNT2117 EC_LED_COLOR_COUNT
1427};2118};
@@ -1431,7 +2122,7 @@ struct ec_params_led_control { · 3 unmodified lines
1431 uint8_t flags; /* Control flags */2122 uint8_t flags; /* Control flags */
1432 2123
1433 uint8_t brightness[EC_LED_COLOR_COUNT];2124 uint8_t brightness[EC_LED_COLOR_COUNT];
1434} __packed;2125} __ec_align1;
1435 2126
1436struct ec_response_led_control {2127struct ec_response_led_control {
1437 /*2128 /*
@@ -1442,7 +2133,7 @@ struct ec_response_led_control { · 4 unmodified lines
1442 * Other values means the LED is control by PWM.2133 * Other values means the LED is control by PWM.
1443 */2134 */
1444 uint8_t brightness_range[EC_LED_COLOR_COUNT];2135 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1445} __packed;2136} __ec_align1;
1446 2137
1447/*****************************************************************************/2138/*****************************************************************************/
1448/* Verified boot commands */2139/* Verified boot commands */
@@ -1453,7 +2144,7 @@ struct ec_response_led_control { · 4 unmodified lines
1453 */2144 */
1454 2145
1455/* Verified boot hash command */2146/* Verified boot hash command */
1456#define EC_CMD_VBOOT_HASH 0x2A2147#define EC_CMD_VBOOT_HASH 0x002A
1457 2148
1458struct ec_params_vboot_hash {2149struct ec_params_vboot_hash {
1459 uint8_t cmd; /* enum ec_vboot_hash_cmd */2150 uint8_t cmd; /* enum ec_vboot_hash_cmd */
@@ -1463,7 +2154,7 @@ struct ec_params_vboot_hash { · 3 unmodified lines
1463 uint32_t offset; /* Offset in flash to hash */2154 uint32_t offset; /* Offset in flash to hash */
1464 uint32_t size; /* Number of bytes to hash */2155 uint32_t size; /* Number of bytes to hash */
1465 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */2156 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1466} __packed;2157} __ec_align4;
1467 2158
1468struct ec_response_vboot_hash {2159struct ec_response_vboot_hash {
1469 uint8_t status; /* enum ec_vboot_hash_status */2160 uint8_t status; /* enum ec_vboot_hash_status */
@@ -1473,7 +2164,7 @@ struct ec_response_vboot_hash { · 3 unmodified lines
1473 uint32_t offset; /* Offset in flash which was hashed */2164 uint32_t offset; /* Offset in flash which was hashed */
1474 uint32_t size; /* Number of bytes hashed */2165 uint32_t size; /* Number of bytes hashed */
1475 uint8_t hash_digest[64]; /* Hash digest data */2166 uint8_t hash_digest[64]; /* Hash digest data */
1476} __packed;2167} __ec_align4;
1477 2168
1478enum ec_vboot_hash_cmd {2169enum ec_vboot_hash_cmd {
1479 EC_VBOOT_HASH_GET = 0, /* Get current hash status */2170 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
@@ -1497,15 +2188,22 @@ enum ec_vboot_hash_status { · 17 unmodified lines
1497 * If one of these is specified, the EC will automatically update offset and2188 * If one of these is specified, the EC will automatically update offset and
1498 * size to the correct values for the specified image (RO or RW).2189 * size to the correct values for the specified image (RO or RW).
1499 */2190 */
1500#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe2191#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1501#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd2192#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
1502 2200
1503/*****************************************************************************/2201/*****************************************************************************/
1504/*2202/*
1505 * Motion sense commands. We'll make separate structs for sub-commands with2203 * Motion sense commands. We'll make separate structs for sub-commands with
1506 * different input args, so that we know how much to expect.2204 * different input args, so that we know how much to expect.
1507 */2205 */
1508#define EC_CMD_MOTION_SENSE_CMD 0x2B2206#define EC_CMD_MOTION_SENSE_CMD 0x002B
1509 2207
1510/* Motion sense commands */2208/* Motion sense commands */
1511enum motionsense_command {2209enum motionsense_command {
@@ -1524,7 +2222,13 @@ enum motionsense_command { · 12 unmodified lines
1524 2222
1525 /*2223 /*
1526 * EC Rate command is a setter/getter command for the EC sampling rate2224 * 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.
1528 */2232 */
1529 MOTIONSENSE_CMD_EC_RATE = 2,2233 MOTIONSENSE_CMD_EC_RATE = 2,
1530 2234
@@ -1555,32 +2259,76 @@ enum motionsense_command { · 24 unmodified lines
1555 MOTIONSENSE_CMD_DATA = 6,2259 MOTIONSENSE_CMD_DATA = 6,
1556 2260
1557 /*2261 /*
1558 * Perform low level calibration.. On sensors that support it, ask to2262 * Return sensor fifo info.
1559 * do offset calibration.2263 */
2264 MOTIONSENSE_CMD_FIFO_INFO = 7,
2265
2266 /*
2267 * Insert a flush element in the fifo and return sensor fifo info.
2268 * The host can use that element to synchronize its operation.
2269 */
2270 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2271
2272 /*
2273 * Return a portion of the fifo.
2274 */
2275 MOTIONSENSE_CMD_FIFO_READ = 9,
2276
2277 /*
2278 * Perform low level calibration.
2279 * On sensors that support it, ask to do offset calibration.
1560 */2280 */
1561 MOTIONSENSE_CMD_PERFORM_CALIB = 10,2281 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1562 2282
1563 /*2283 /*
1564 * Sensor Offset command is a setter/getter command for the offset used2284 * Sensor Offset command is a setter/getter command for the offset
1565 * for calibration. The offsets can be calculated by the host, or via2285 * used for calibration.
2286 * The offsets can be calculated by the host, or via
1566 * PERFORM_CALIB command.2287 * PERFORM_CALIB command.
1567 */2288 */
1568 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,2289 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1569 2290
1570 /* Number of motionsense sub-commands. */2291 /*
1571 MOTIONSENSE_NUM_CMDS2292 * List available activities for a MOTION sensor.
1572};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,
1573 2314
1574enum motionsensor_id {2315 /*
1575 EC_MOTION_SENSOR_ACCEL_BASE = 0,2316 * Spoof the readings of the sensors. The spoofed readings can be set
1576 EC_MOTION_SENSOR_ACCEL_LID = 1,2317 * to arbitrary values, or will lock to the last read actual values.
1577 EC_MOTION_SENSOR_GYRO = 2,2318 */
2319 MOTIONSENSE_CMD_SPOOF = 16,
2320
2321 /* Set lid angle for tablet mode detection. */
2322 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
1578 2323
1579 /*2324 /*
1580 * Note, if more sensors are added and this count changes, the padding2325 * Sensor Scale command is a setter/getter command for the calibration
1581 * in ec_response_motion_sense dump command must be modified.2326 * scale.
1582 */2327 */
1583 EC_MOTION_SENSOR_COUNT = 32328 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2329
2330 /* Number of motionsense sub-commands. */
2331 MOTIONSENSE_NUM_CMDS
1584};2332};
1585 2333
1586/* List of motion sensor types. */2334/* List of motion sensor types. */
@@ -1592,6 +2340,7 @@ enum motionsensor_type { · 5 unmodified lines
1592 MOTIONSENSE_TYPE_LIGHT = 4,2340 MOTIONSENSE_TYPE_LIGHT = 4,
1593 MOTIONSENSE_TYPE_ACTIVITY = 5,2341 MOTIONSENSE_TYPE_ACTIVITY = 5,
1594 MOTIONSENSE_TYPE_BARO = 6,2342 MOTIONSENSE_TYPE_BARO = 6,
2343 MOTIONSENSE_TYPE_SYNC = 7,
1595 MOTIONSENSE_TYPE_MAX,2344 MOTIONSENSE_TYPE_MAX,
1596};2345};
1597 2346
@@ -1599,19 +2348,116 @@ enum motionsensor_type { · 1 unmodified line
1599enum motionsensor_location {2348enum motionsensor_location {
1600 MOTIONSENSE_LOC_BASE = 0,2349 MOTIONSENSE_LOC_BASE = 0,
1601 MOTIONSENSE_LOC_LID = 1,2350 MOTIONSENSE_LOC_LID = 1,
2351 MOTIONSENSE_LOC_CAMERA = 2,
1602 MOTIONSENSE_LOC_MAX,2352 MOTIONSENSE_LOC_MAX,
1603};2353};
1604 2354
1605/* List of motion sensor chips. */2355/* List of motion sensor chips. */
1606enum motionsensor_chip {2356enum motionsensor_chip {
1607 MOTIONSENSE_CHIP_KXCJ9 = 0,2357 MOTIONSENSE_CHIP_KXCJ9 = 0,
2358 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2359 MOTIONSENSE_CHIP_BMI160 = 2,
2360 MOTIONSENSE_CHIP_SI1141 = 3,
2361 MOTIONSENSE_CHIP_SI1142 = 4,
2362 MOTIONSENSE_CHIP_SI1143 = 5,
2363 MOTIONSENSE_CHIP_KX022 = 6,
2364 MOTIONSENSE_CHIP_L3GD20H = 7,
2365 MOTIONSENSE_CHIP_BMA255 = 8,
2366 MOTIONSENSE_CHIP_BMP280 = 9,
2367 MOTIONSENSE_CHIP_OPT3001 = 10,
2368 MOTIONSENSE_CHIP_BH1730 = 11,
2369 MOTIONSENSE_CHIP_GPIO = 12,
2370 MOTIONSENSE_CHIP_LIS2DH = 13,
2371 MOTIONSENSE_CHIP_LSM6DSM = 14,
2372 MOTIONSENSE_CHIP_LIS2DE = 15,
2373 MOTIONSENSE_CHIP_LIS2MDL = 16,
2374 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2375 MOTIONSENSE_CHIP_LSM6DSO = 18,
2376 MOTIONSENSE_CHIP_LNG2DM = 19,
2377 MOTIONSENSE_CHIP_MAX,
2378};
2379
2380/* List of orientation positions */
2381enum motionsensor_orientation {
2382 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2383 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2384 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2385 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2386 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
2387};
2388
2389struct ec_response_motion_sensor_data {
2390 /* Flags for each sensor. */
2391 uint8_t flags;
2392 /* Sensor number the data comes from. */
2393 uint8_t sensor_num;
2394 /* Each sensor is up to 3-axis. */
2395 union {
2396 int16_t data[3];
2397 struct __ec_todo_packed {
2398 uint16_t reserved;
2399 uint32_t timestamp;
2400 };
2401 struct __ec_todo_unpacked {
2402 uint8_t activity; /* motionsensor_activity */
2403 uint8_t state;
2404 int16_t add_info[2];
2405 };
2406 };
2407} __ec_todo_packed;
2408
2409/* Note: used in ec_response_get_next_data */
2410struct ec_response_motion_sense_fifo_info {
2411 /* Size of the fifo */
2412 uint16_t size;
2413 /* Amount of space used in the fifo */
2414 uint16_t count;
2415 /* Timestamp recorded in us.
2416 * aka accurate timestamp when host event was triggered.
2417 */
2418 uint32_t timestamp;
2419 /* Total amount of vector lost */
2420 uint16_t total_lost;
2421 /* Lost events since the last fifo_info, per sensors */
2422 uint16_t lost[0];
2423} __ec_todo_packed;
2424
2425struct ec_response_motion_sense_fifo_data {
2426 uint32_t number_data;
2427 struct ec_response_motion_sensor_data data[0];
2428} __ec_todo_packed;
2429
2430/* List supported activity recognition */
2431enum motionsensor_activity {
2432 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2433 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2434 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2435 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
1608};2436};
1609 2437
2438struct ec_motion_sense_activity {
2439 uint8_t sensor_num;
2440 uint8_t activity; /* one of enum motionsensor_activity */
2441 uint8_t enable; /* 1: enable, 0: disable */
2442 uint8_t reserved;
2443 uint16_t parameters[3]; /* activity dependent parameters */
2444} __ec_todo_unpacked;
2445
1610/* Module flag masks used for the dump sub-command. */2446/* 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)
1612 2448
1613/* Sensor flag masks used for the dump sub-command. */2449/* 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)
1615 2461
1616/*2462/*
1617 * Send this value for the data element to only perform a read. If you2463 * Send this value for the data element to only perform a read. If you
@@ -1622,48 +2468,79 @@ enum motionsensor_chip { · 4 unmodified lines
1622 2468
1623#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x80002469#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1624 2470
2471/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
1625/* Set Calibration information */2472/* Set Calibration information */
1626#define MOTION_SENSE_SET_OFFSET 12473#define MOTION_SENSE_SET_OFFSET BIT(0)
1627 2474
1628struct ec_response_motion_sensor_data {2475/* Default Scale value, factor 1. */
1629 /* Flags for each sensor. */2476#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
1630 uint8_t flags;2477
1631 /* Sensor number the data comes from */2478#define LID_ANGLE_UNRELIABLE 500
1632 uint8_t sensor_num;2479
1633 /* Each sensor is up to 3-axis. */2480enum motionsense_spoof_mode {
1634 union {2481 /* Disable spoof mode. */
1635 int16_t data[3];2482 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
1636 struct {2483
1637 uint16_t rsvd;2484 /* Enable spoof mode, but use provided component values. */
1638 uint32_t timestamp;2485 MOTIONSENSE_SPOOF_MODE_CUSTOM,
1639 } __packed;2486
1640 struct {2487 /* Enable spoof mode, but use the current sensor values. */
1641 uint8_t activity; /* motionsensor_activity */2488 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
1642 uint8_t state;2489
1643 int16_t add_info[2];2490 /* Query the current spoof mode status for the sensor. */
1644 };2491 MOTIONSENSE_SPOOF_MODE_QUERY,
1645 };2492};
1646} __packed;
1647 2493
1648struct ec_params_motion_sense {2494struct ec_params_motion_sense {
1649 uint8_t cmd;2495 uint8_t cmd;
1650 union {2496 union {
1651 /* Used for MOTIONSENSE_CMD_DUMP. */2497 /* Used for MOTIONSENSE_CMD_DUMP. */
1652 struct {2498 struct __ec_todo_unpacked {
1653 /* no args */2499 /*
2500 * Maximal number of sensor the host is expecting.
2501 * 0 means the host is only interested in the number
2502 * of sensors controlled by the EC.
2503 */
2504 uint8_t max_sensor_count;
1654 } dump;2505 } dump;
1655 2506
1656 /*2507 /*
1657 * Used for MOTIONSENSE_CMD_EC_RATE and2508 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1658 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1659 */2509 */
1660 struct {2510 struct __ec_todo_unpacked {
1661 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */2511 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2512 * kb_wake_angle: angle to wakup AP.
2513 */
1662 int16_t data;2514 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;
1664 2541
1665 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */2542 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1666 struct {2543 struct __ec_todo_packed {
1667 uint8_t sensor_num;2544 uint8_t sensor_num;
1668 2545
1669 /*2546 /*
@@ -1689,36 +2566,102 @@ struct ec_params_motion_sense { · 19 unmodified lines
1689 * Compass: 1/16 uT2566 * Compass: 1/16 uT
1690 */2567 */
1691 int16_t offset[3];2568 int16_t offset[3];
1692 } __packed sensor_offset;2569 } sensor_offset;
1693 2570
1694 /* Used for MOTIONSENSE_CMD_INFO. */2571 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
1695 struct {2572 struct __ec_todo_packed {
1696 uint8_t sensor_num;2573 uint8_t sensor_num;
1697 } info;
1698 2574
1699 /*2575 /*
1700 * Used for MOTIONSENSE_CMD_SENSOR_ODR and2576 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1701 * MOTIONSENSE_CMD_SENSOR_RANGE.2577 * the calibration information in the EC.
1702 */2578 * If unset, just retrieve calibration information.
1703 struct {2579 */
1704 /* Should be element of enum motionsensor_id. */2580 uint16_t flags;
1705 uint8_t sensor_num;
1706 2581
1707 /* Rounding flag, true for round-up, false for down. */2582 /*
1708 uint8_t roundup;2583 * Temperature at calibration, in units of 0.01 C
2584 * 0x8000: invalid / unknown.
2585 * 0x0: 0C
2586 * 0x7fff: +327.67C
2587 */
2588 int16_t temp;
1709 2589
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;
1711 2599
1712 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */2600
1713 int32_t data;2601 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
1714 } sensor_odr, sensor_range;2602 /* (no params) */
2603
2604 /* Used for MOTIONSENSE_CMD_FIFO_READ */
2605 struct __ec_todo_unpacked {
2606 /*
2607 * Number of expected vector to return.
2608 * EC may return less or 0 if none available.
2609 */
2610 uint32_t max_data_vector;
2611 } fifo_read;
2612
2613 struct ec_motion_sense_activity set_activity;
2614
2615 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2616 /* (no params) */
2617
2618 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2619 struct __ec_todo_unpacked {
2620 /*
2621 * 1: enable, 0 disable fifo,
2622 * EC_MOTION_SENSE_NO_VALUE return value.
2623 */
2624 int8_t enable;
2625 } fifo_int_enable;
2626
2627 /* Used for MOTIONSENSE_CMD_SPOOF */
2628 struct __ec_todo_packed {
2629 uint8_t sensor_id;
2630
2631 /* See enum motionsense_spoof_mode. */
2632 uint8_t spoof_enable;
2633
2634 /* Ignored, used for alignment. */
2635 uint8_t reserved;
2636
2637 /* Individual component values to spoof. */
2638 int16_t components[3];
2639 } spoof;
2640
2641 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2642 struct __ec_todo_unpacked {
2643 /*
2644 * Lid angle threshold for switching between tablet and
2645 * clamshell mode.
2646 */
2647 int16_t lid_angle;
2648
2649 /*
2650 * Hysteresis degree to prevent fluctuations between
2651 * clamshell and tablet mode if lid angle keeps
2652 * changing around the threshold. Lid motion driver will
2653 * use lid_angle + hys_degree to trigger tablet mode and
2654 * lid_angle - hys_degree to trigger clamshell mode.
2655 */
2656 int16_t hys_degree;
2657 } tablet_mode_threshold;
1715 };2658 };
1716} __packed;2659} __ec_todo_packed;
1717 2660
1718struct ec_response_motion_sense {2661struct ec_response_motion_sense {
1719 union {2662 union {
1720 /* Used for MOTIONSENSE_CMD_DUMP. */2663 /* Used for MOTIONSENSE_CMD_DUMP */
1721 struct {2664 struct __ec_todo_unpacked {
1722 /* Flags representing the motion sensor module. */2665 /* Flags representing the motion sensor module. */
1723 uint8_t module_flags;2666 uint8_t module_flags;
1724 2667
@@ -1733,7 +2676,7 @@ struct ec_response_motion_sense { · 8 unmodified lines
1733 } dump;2676 } dump;
1734 2677
1735 /* Used for MOTIONSENSE_CMD_INFO. */2678 /* Used for MOTIONSENSE_CMD_INFO. */
1736 struct {2679 struct __ec_todo_unpacked {
1737 /* Should be element of enum motionsensor_type. */2680 /* Should be element of enum motionsensor_type. */
1738 uint8_t type;2681 uint8_t type;
1739 2682
@@ -1744,74 +2687,166 @@ struct ec_response_motion_sense { · 4 unmodified lines
1744 uint8_t chip;2687 uint8_t chip;
1745 } info;2688 } info;
1746 2689
2690 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2691 struct __ec_todo_unpacked {
2692 /* Should be element of enum motionsensor_type. */
2693 uint8_t type;
2694
2695 /* Should be element of enum motionsensor_location. */
2696 uint8_t location;
2697
2698 /* Should be element of enum motionsensor_chip. */
2699 uint8_t chip;
2700
2701 /* Minimum sensor sampling frequency */
2702 uint32_t min_frequency;
2703
2704 /* Maximum sensor sampling frequency */
2705 uint32_t max_frequency;
2706
2707 /* Max number of sensor events that could be in fifo */
2708 uint32_t fifo_max_event_count;
2709 } info_3;
2710
1747 /* Used for MOTIONSENSE_CMD_DATA */2711 /* Used for MOTIONSENSE_CMD_DATA */
1748 struct ec_response_motion_sensor_data data;2712 struct ec_response_motion_sensor_data data;
1749 2713
1750 /*2714 /*
1751 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,2715 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1752 * MOTIONSENSE_CMD_SENSOR_RANGE, and2716 * MOTIONSENSE_CMD_SENSOR_RANGE,
1753 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.2717 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2718 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2719 * MOTIONSENSE_CMD_SPOOF.
1754 */2720 */
1755 struct {2721 struct __ec_todo_unpacked {
1756 /* Current value of the parameter queried. */2722 /* Current value of the parameter queried. */
1757 int32_t ret;2723 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;
1759 2726
1760 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */2727 /*
1761 struct {2728 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
2729 * PERFORM_CALIB.
2730 */
2731 struct __ec_todo_unpacked {
1762 int16_t temp;2732 int16_t temp;
1763 int16_t offset[3];2733 int16_t offset[3];
1764 } sensor_offset, perform_calib;2734 } sensor_offset, perform_calib;
1765 };
1766} __packed;
1767 2735
1768/*****************************************************************************/2736 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
1769/* USB charging control commands */2737 struct __ec_todo_unpacked {
2738 int16_t temp;
2739 uint16_t scale[3];
2740 } sensor_scale;
1770 2741
1771/* Set USB port charging mode */2742 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
1772#define EC_CMD_USB_CHARGE_SET_MODE 0x30
1773 2743
1774struct ec_params_usb_charge_set_mode {2744 struct ec_response_motion_sense_fifo_data fifo_read;
1775 uint8_t usb_port_id;
1776 uint8_t mode;
1777} __packed;
1778 2745
1779/*****************************************************************************/2746 struct __ec_todo_packed {
1780/* Persistent storage for host */2747 uint16_t reserved;
2748 uint32_t enabled;
2749 uint32_t disabled;
2750 } list_activities;
1781 2751
1782/* Maximum bytes that can be read/written in a single command */2752 /* No params for set activity */
1783#define EC_PSTORE_SIZE_MAX 64
1784 2753
1785/* Get persistent storage info */2754 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
1786#define EC_CMD_PSTORE_INFO 0x402755 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;
1787 2762
1788struct ec_response_pstore_info {2763 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
1789 /* Persistent storage size, in bytes */2764 struct __ec_todo_unpacked {
1790 uint32_t pstore_size;2765 /*
1791 /* Access size; read/write offset and size must be a multiple of this */2766 * Lid angle threshold for switching between tablet and
1792 uint32_t access_size;2767 * clamshell mode.
1793} __packed;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
2784struct ec_params_force_lid_open {
2785 uint8_t enabled;
2786} __ec_align1;
2787
2788/*****************************************************************************/
2789/* Configure the behavior of the power button */
2790#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2791
2792enum ec_config_power_button_flags {
2793 /* Enable/Disable power button pulses for x86 devices */
2794 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
2795};
2796
2797struct ec_params_config_power_button {
2798 /* See enum ec_config_power_button_flags */
2799 uint8_t flags;
2800} __ec_align1;
2801
2802/*****************************************************************************/
2803/* USB charging control commands */
2804
2805/* Set USB port charging mode */
2806#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
2807
2808struct 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
2823struct 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;
1794 2829
1795/*2830/*
1796 * Read persistent storage2831 * Read persistent storage
1797 *2832 *
1798 * Response is params.size bytes of data.2833 * Response is params.size bytes of data.
1799 */2834 */
1800#define EC_CMD_PSTORE_READ 0x412835#define EC_CMD_PSTORE_READ 0x0041
1801 2836
1802struct ec_params_pstore_read {2837struct ec_params_pstore_read {
1803 uint32_t offset; /* Byte offset to read */2838 uint32_t offset; /* Byte offset to read */
1804 uint32_t size; /* Size to read in bytes */2839 uint32_t size; /* Size to read in bytes */
1805} __packed;2840} __ec_align4;
1806 2841
1807/* Write persistent storage */2842/* Write persistent storage */
1808#define EC_CMD_PSTORE_WRITE 0x422843#define EC_CMD_PSTORE_WRITE 0x0042
1809 2844
1810struct ec_params_pstore_write {2845struct ec_params_pstore_write {
1811 uint32_t offset; /* Byte offset to write */2846 uint32_t offset; /* Byte offset to write */
1812 uint32_t size; /* Size to write in bytes */2847 uint32_t size; /* Size to write in bytes */
1813 uint8_t data[EC_PSTORE_SIZE_MAX];2848 uint8_t data[EC_PSTORE_SIZE_MAX];
1814} __packed;2849} __ec_align4;
1815 2850
1816/*****************************************************************************/2851/*****************************************************************************/
1817/* Real-time clock */2852/* Real-time clock */
@@ -1819,21 +2854,21 @@ struct ec_params_pstore_write { · 1 unmodified line
1819/* RTC params and response structures */2854/* RTC params and response structures */
1820struct ec_params_rtc {2855struct ec_params_rtc {
1821 uint32_t time;2856 uint32_t time;
1822} __packed;2857} __ec_align4;
1823 2858
1824struct ec_response_rtc {2859struct ec_response_rtc {
1825 uint32_t time;2860 uint32_t time;
1826} __packed;2861} __ec_align4;
1827 2862
1828/* These use ec_response_rtc */2863/* These use ec_response_rtc */
1829#define EC_CMD_RTC_GET_VALUE 0x442864#define EC_CMD_RTC_GET_VALUE 0x0044
1830#define EC_CMD_RTC_GET_ALARM 0x452865#define EC_CMD_RTC_GET_ALARM 0x0045
1831 2866
1832/* These all use ec_params_rtc */2867/* These all use ec_params_rtc */
1833#define EC_CMD_RTC_SET_VALUE 0x462868#define EC_CMD_RTC_SET_VALUE 0x0046
1834#define EC_CMD_RTC_SET_ALARM 0x472869#define EC_CMD_RTC_SET_ALARM 0x0047
1835 2870
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 */
1837#define EC_RTC_ALARM_CLEAR 02872#define EC_RTC_ALARM_CLEAR 0
1838 2873
1839/*****************************************************************************/2874/*****************************************************************************/
@@ -1843,8 +2878,8 @@ struct ec_response_rtc { · 3 unmodified lines
1843#define EC_PORT80_SIZE_MAX 322878#define EC_PORT80_SIZE_MAX 32
1844 2879
1845/* Get last port80 code from previous boot */2880/* Get last port80 code from previous boot */
1846#define EC_CMD_PORT80_LAST_BOOT 0x482881#define EC_CMD_PORT80_LAST_BOOT 0x0048
1847#define EC_CMD_PORT80_READ 0x482882#define EC_CMD_PORT80_READ 0x0048
1848 2883
1849enum ec_port80_subcmd {2884enum ec_port80_subcmd {
1850 EC_PORT80_GET_INFO = 0,2885 EC_PORT80_GET_INFO = 0,
@@ -1854,29 +2889,72 @@ enum ec_port80_subcmd { · 3 unmodified lines
1854struct ec_params_port80_read {2889struct ec_params_port80_read {
1855 uint16_t subcmd;2890 uint16_t subcmd;
1856 union {2891 union {
1857 struct {2892 struct __ec_todo_unpacked {
1858 uint32_t offset;2893 uint32_t offset;
1859 uint32_t num_entries;2894 uint32_t num_entries;
1860 } read_buffer;2895 } read_buffer;
1861 };2896 };
1862} __packed;2897} __ec_todo_packed;
1863 2898
1864struct ec_response_port80_read {2899struct ec_response_port80_read {
1865 union {2900 union {
1866 struct {2901 struct __ec_todo_unpacked {
1867 uint32_t writes;2902 uint32_t writes;
1868 uint32_t history_size;2903 uint32_t history_size;
1869 uint32_t last_boot;2904 uint32_t last_boot;
1870 } get_info;2905 } get_info;
1871 struct {2906 struct __ec_todo_unpacked {
1872 uint16_t codes[EC_PORT80_SIZE_MAX];2907 uint16_t codes[EC_PORT80_SIZE_MAX];
1873 } data;2908 } data;
1874 };2909 };
1875} __packed;2910} __ec_todo_packed;
1876 2911
1877struct ec_response_port80_last_boot {2912struct ec_response_port80_last_boot {
1878 uint16_t code;2913 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
2927struct ec_response_vstore_info {
2928 /* Indicates which slots are locked */
2929 uint32_t slot_locked;
2930 /* Total number of slots available */
2931 uint8_t slot_count;
2932} __ec_align_size1;
2933
2934/*
2935 * Read temporary secure storage
2936 *
2937 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2938 */
2939#define EC_CMD_VSTORE_READ 0x004A
2940
2941struct ec_params_vstore_read {
2942 uint8_t slot; /* Slot to read from */
2943} __ec_align1;
2944
2945struct ec_response_vstore_read {
2946 uint8_t data[EC_VSTORE_SLOT_SIZE];
2947} __ec_align1;
2948
2949/*
2950 * Write temporary secure storage and lock it.
2951 */
2952#define EC_CMD_VSTORE_WRITE 0x004B
2953
2954struct ec_params_vstore_write {
2955 uint8_t slot; /* Slot to write to */
2956 uint8_t data[EC_VSTORE_SLOT_SIZE];
2957} __ec_align1;
1880 2958
1881/*****************************************************************************/2959/*****************************************************************************/
1882/* Thermal engine commands. Note that there are two implementations. We'll2960/* Thermal engine commands. Note that there are two implementations. We'll
@@ -1885,8 +2963,8 @@ struct ec_response_port80_last_boot { · 2 unmodified lines
1885 * Version 1 separates the CPU thermal limits from the fan control.2963 * Version 1 separates the CPU thermal limits from the fan control.
1886 */2964 */
1887 2965
1888#define EC_CMD_THERMAL_SET_THRESHOLD 0x502966#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
1889#define EC_CMD_THERMAL_GET_THRESHOLD 0x512967#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
1890 2968
1891/* The version 0 structs are opaque. You have to know what they are for2969/* The version 0 structs are opaque. You have to know what they are for
1892 * the get/set commands to make any sense.2970 * the get/set commands to make any sense.
@@ -1897,17 +2975,17 @@ struct ec_params_thermal_set_threshold { · 4 unmodified lines
1897 uint8_t sensor_type;2975 uint8_t sensor_type;
1898 uint8_t threshold_id;2976 uint8_t threshold_id;
1899 uint16_t value;2977 uint16_t value;
1900} __packed;2978} __ec_align2;
1901 2979
1902/* Version 0 - get */2980/* Version 0 - get */
1903struct ec_params_thermal_get_threshold {2981struct ec_params_thermal_get_threshold {
1904 uint8_t sensor_type;2982 uint8_t sensor_type;
1905 uint8_t threshold_id;2983 uint8_t threshold_id;
1906} __packed;2984} __ec_align1;
1907 2985
1908struct ec_response_thermal_get_threshold {2986struct ec_response_thermal_get_threshold {
1909 uint16_t value;2987 uint16_t value;
1910} __packed;2988} __ec_align2;
1911 2989
1912 2990
1913/* The version 1 structs are visible. */2991/* The version 1 structs are visible. */
@@ -1919,71 +2997,124 @@ enum ec_temp_thresholds { · 5 unmodified lines
1919 EC_TEMP_THRESH_COUNT2997 EC_TEMP_THRESH_COUNT
1920};2998};
1921 2999
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.
1923 * Zero values will be silently ignored by the thermal task.3002 * Zero values will be silently ignored by the thermal task.
3003 *
3004 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3005 * hysteresis.
3006 * For example,
3007 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3008 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3009 * EC will throttle ap when temperature >= 301 K, and release throttling when
3010 * temperature <= 299 K.
3011 *
3012 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3013 * For example,
3014 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3015 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3016 * EC will throttle ap when temperature >= 301 K, and release throttling when
3017 * temperature <= 294 K.
3018 *
3019 * Note that this structure is a sub-structure of
3020 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
1924 */3021 */
1925struct ec_thermal_config {3022struct ec_thermal_config {
1926 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */3023 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
3024 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
1927 uint32_t temp_fan_off; /* no active cooling needed */3025 uint32_t temp_fan_off; /* no active cooling needed */
1928 uint32_t temp_fan_max; /* max active cooling needed */3026 uint32_t temp_fan_max; /* max active cooling needed */
1929} __packed;3027} __ec_align4;
1930 3028
1931/* Version 1 - get config for one sensor. */3029/* Version 1 - get config for one sensor. */
1932struct ec_params_thermal_get_threshold_v1 {3030struct ec_params_thermal_get_threshold_v1 {
1933 uint32_t sensor_num;3031 uint32_t sensor_num;
1934} __packed;3032} __ec_align4;
1935/* This returns a struct ec_thermal_config */3033/* This returns a struct ec_thermal_config */
1936 3034
1937/* Version 1 - set config for one sensor.3035/*
1938 * Use read-modify-write for best results! */3036 * Version 1 - set config for one sensor.
3037 * Use read-modify-write for best results!
3038 */
1939struct ec_params_thermal_set_threshold_v1 {3039struct ec_params_thermal_set_threshold_v1 {
1940 uint32_t sensor_num;3040 uint32_t sensor_num;
1941 struct ec_thermal_config cfg;3041 struct ec_thermal_config cfg;
1942} __packed;3042} __ec_align4;
1943/* This returns no data */3043/* This returns no data */
1944 3044
1945/****************************************************************************/3045/****************************************************************************/
1946 3046
1947/* Toggle automatic fan control */3047/* Toggle automatic fan control */
1948#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x523048#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
3049
3050/* Version 1 of input params */
3051struct ec_params_auto_fan_ctrl_v1 {
3052 uint8_t fan_idx;
3053} __ec_align1;
1949 3054
1950/* Get TMP006 calibration data */3055/* Get/Set TMP006 calibration data */
1951#define EC_CMD_TMP006_GET_CALIBRATION 0x533056#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 */
1952 3067
3068/* This is the same struct for both v0 and v1. */
1953struct ec_params_tmp006_get_calibration {3069struct ec_params_tmp006_get_calibration {
1954 uint8_t index;3070 uint8_t index;
1955} __packed;3071} __ec_align1;
1956 3072
1957struct ec_response_tmp006_get_calibration {3073/* Version 0 */
3074struct ec_response_tmp006_get_calibration_v0 {
1958 float s0;3075 float s0;
1959 float b0;3076 float b0;
1960 float b1;3077 float b1;
1961 float b2;3078 float b2;
1962} __packed;3079} __ec_align4;
1963
1964/* Set TMP006 calibration data */
1965#define EC_CMD_TMP006_SET_CALIBRATION 0x54
1966 3080
1967struct ec_params_tmp006_set_calibration {3081struct ec_params_tmp006_set_calibration_v0 {
1968 uint8_t index;3082 uint8_t index;
1969 uint8_t reserved[3]; /* Reserved; set 0 */3083 uint8_t reserved[3];
1970 float s0;3084 float s0;
1971 float b0;3085 float b0;
1972 float b1;3086 float b1;
1973 float b2;3087 float b2;
1974} __packed;3088} __ec_align4;
3089
3090/* Version 1 */
3091struct ec_response_tmp006_get_calibration_v1 {
3092 uint8_t algorithm;
3093 uint8_t num_params;
3094 uint8_t reserved[2];
3095 float val[0];
3096} __ec_align4;
3097
3098struct ec_params_tmp006_set_calibration_v1 {
3099 uint8_t index;
3100 uint8_t algorithm;
3101 uint8_t num_params;
3102 uint8_t reserved;
3103 float val[0];
3104} __ec_align4;
3105
1975 3106
1976/* Read raw TMP006 data */3107/* Read raw TMP006 data */
1977#define EC_CMD_TMP006_GET_RAW 0x553108#define EC_CMD_TMP006_GET_RAW 0x0055
1978 3109
1979struct ec_params_tmp006_get_raw {3110struct ec_params_tmp006_get_raw {
1980 uint8_t index;3111 uint8_t index;
1981} __packed;3112} __ec_align1;
1982 3113
1983struct ec_response_tmp006_get_raw {3114struct ec_response_tmp006_get_raw {
1984 int32_t t; /* In 1/100 K */3115 int32_t t; /* In 1/100 K */
1985 int32_t v; /* In nV */3116 int32_t v; /* In nV */
1986};3117} __ec_align4;
1987 3118
1988/*****************************************************************************/3119/*****************************************************************************/
1989/* MKBP - Matrix KeyBoard Protocol */3120/* MKBP - Matrix KeyBoard Protocol */
@@ -1998,24 +3129,24 @@ struct ec_response_tmp006_get_raw { · 8 unmodified lines
1998 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type3129 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1999 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.3130 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
2000 */3131 */
2001#define EC_CMD_MKBP_STATE 0x603132#define EC_CMD_MKBP_STATE 0x0060
2002 3133
2003/*3134/*
2004 * Provide information about various MKBP things. See enum ec_mkbp_info_type.3135 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2005 */3136 */
2006#define EC_CMD_MKBP_INFO 0x613137#define EC_CMD_MKBP_INFO 0x0061
2007 3138
2008struct ec_response_mkbp_info {3139struct ec_response_mkbp_info {
2009 uint32_t rows;3140 uint32_t rows;
2010 uint32_t cols;3141 uint32_t cols;
2011 /* Formerly "switches", which was 0. */3142 /* Formerly "switches", which was 0. */
2012 uint8_t reserved;3143 uint8_t reserved;
2013} __packed;3144} __ec_align_size1;
2014 3145
2015struct ec_params_mkbp_info {3146struct ec_params_mkbp_info {
2016 uint8_t info_type;3147 uint8_t info_type;
2017 uint8_t event_type;3148 uint8_t event_type;
2018} __packed;3149} __ec_align1;
2019 3150
2020enum ec_mkbp_info_type {3151enum ec_mkbp_info_type {
2021 /*3152 /*
@@ -2057,17 +3188,28 @@ enum ec_mkbp_info_type { · 35 unmodified lines
2057};3188};
2058 3189
2059/* Simulate key press */3190/* Simulate key press */
2060#define EC_CMD_MKBP_SIMULATE_KEY 0x623191#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
2061 3192
2062struct ec_params_mkbp_simulate_key {3193struct ec_params_mkbp_simulate_key {
2063 uint8_t col;3194 uint8_t col;
2064 uint8_t row;3195 uint8_t row;
2065 uint8_t pressed;3196 uint8_t pressed;
2066} __packed;3197} __ec_align1;
3198
3199#define EC_CMD_GET_KEYBOARD_ID 0x0063
3200
3201struct ec_response_keyboard_id {
3202 uint32_t keyboard_id;
3203} __ec_align4;
3204
3205enum keyboard_id {
3206 KEYBOARD_ID_UNSUPPORTED = 0,
3207 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3208};
2067 3209
2068/* Configure keyboard scanning */3210/* Configure keyboard scanning */
2069#define EC_CMD_MKBP_SET_CONFIG 0x643211#define EC_CMD_MKBP_SET_CONFIG 0x0064
2070#define EC_CMD_MKBP_GET_CONFIG 0x653212#define EC_CMD_MKBP_GET_CONFIG 0x0065
2071 3213
2072/* flags */3214/* flags */
2073enum mkbp_config_flags {3215enum mkbp_config_flags {
@@ -2075,16 +3217,21 @@ enum mkbp_config_flags { · 1 unmodified line
2075};3217};
2076 3218
2077enum mkbp_config_valid {3219enum mkbp_config_valid {
2078 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,3220 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
2079 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,3221 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
2080 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,3222 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
2081 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,3223 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
2082 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,3224 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
2083 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,3225 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
2084 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,3226 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
2085};3227};
2086 3228
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 */
2088struct ec_mkbp_config {3235struct ec_mkbp_config {
2089 uint32_t valid_mask; /* valid fields */3236 uint32_t valid_mask; /* valid fields */
2090 uint8_t flags; /* some flags (enum mkbp_config_flags) */3237 uint8_t flags; /* some flags (enum mkbp_config_flags) */
@@ -2104,18 +3251,18 @@ struct ec_mkbp_config { · 13 unmodified lines
2104 uint16_t debounce_up_us; /* time for debounce on key up */3251 uint16_t debounce_up_us; /* time for debounce on key up */
2105 /* maximum depth to allow for fifo (0 = no keyscan output) */3252 /* maximum depth to allow for fifo (0 = no keyscan output) */
2106 uint8_t fifo_max_depth;3253 uint8_t fifo_max_depth;
2107} __packed;3254} __ec_align_size1;
2108 3255
2109struct ec_params_mkbp_set_config {3256struct ec_params_mkbp_set_config {
2110 struct ec_mkbp_config config;3257 struct ec_mkbp_config config;
2111} __packed;3258} __ec_align_size1;
2112 3259
2113struct ec_response_mkbp_get_config {3260struct ec_response_mkbp_get_config {
2114 struct ec_mkbp_config config;3261 struct ec_mkbp_config config;
2115} __packed;3262} __ec_align_size1;
2116 3263
2117/* Run the key scan emulation */3264/* Run the key scan emulation */
2118#define EC_CMD_KEYSCAN_SEQ_CTRL 0x663265#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
2119 3266
2120enum ec_keyscan_seq_cmd {3267enum ec_keyscan_seq_cmd {
2121 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */3268 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
@@ -2130,23 +3277,23 @@ enum ec_collect_flags { · 8 unmodified lines
2130 * Indicates this scan was processed by the EC. Due to timing, some3277 * Indicates this scan was processed by the EC. Due to timing, some
2131 * scans may be skipped.3278 * scans may be skipped.
2132 */3279 */
2133 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,3280 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
2134};3281};
2135 3282
2136struct ec_collect_item {3283struct ec_collect_item {
2137 uint8_t flags; /* some flags (enum ec_collect_flags) */3284 uint8_t flags; /* some flags (enum ec_collect_flags) */
2138};3285} __ec_align1;
2139 3286
2140struct ec_params_keyscan_seq_ctrl {3287struct ec_params_keyscan_seq_ctrl {
2141 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */3288 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2142 union {3289 union {
2143 struct {3290 struct __ec_align1 {
2144 uint8_t active; /* still active */3291 uint8_t active; /* still active */
2145 uint8_t num_items; /* number of items */3292 uint8_t num_items; /* number of items */
2146 /* Current item being presented */3293 /* Current item being presented */
2147 uint8_t cur_item;3294 uint8_t cur_item;
2148 } status;3295 } status;
2149 struct {3296 struct __ec_todo_unpacked {
2150 /*3297 /*
2151 * Absolute time for this scan, measured from the3298 * Absolute time for this scan, measured from the
2152 * start of the sequence.3299 * start of the sequence.
@@ -2154,29 +3301,40 @@ struct ec_params_keyscan_seq_ctrl { · 1 unmodified line
2154 uint32_t time_us;3301 uint32_t time_us;
2155 uint8_t scan[0]; /* keyscan data */3302 uint8_t scan[0]; /* keyscan data */
2156 } add;3303 } add;
2157 struct {3304 struct __ec_align1 {
2158 uint8_t start_item; /* First item to return */3305 uint8_t start_item; /* First item to return */
2159 uint8_t num_items; /* Number of items to return */3306 uint8_t num_items; /* Number of items to return */
2160 } collect;3307 } collect;
2161 };3308 };
2162} __packed;3309} __ec_todo_packed;
2163 3310
2164struct ec_result_keyscan_seq_ctrl {3311struct ec_result_keyscan_seq_ctrl {
2165 union {3312 union {
2166 struct {3313 struct __ec_todo_unpacked {
2167 uint8_t num_items; /* Number of items */3314 uint8_t num_items; /* Number of items */
2168 /* Data for each item */3315 /* Data for each item */
2169 struct ec_collect_item item[0];3316 struct ec_collect_item item[0];
2170 } collect;3317 } collect;
2171 };3318 };
2172} __packed;3319} __ec_todo_packed;
2173 3320
2174/*3321/*
2175 * Command for retrieving the next pending MKBP event from the EC device3322 * Get the next pending MKBP event.
2176 *3323 *
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.
2178 */3333 */
2179#define EC_CMD_GET_NEXT_EVENT 0x673334#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)
2180 3338
2181enum ec_mkbp_event {3339enum ec_mkbp_event {
2182 /* Keyboard matrix changed. The event data is the new matrix state. */3340 /* Keyboard matrix changed. The event data is the new matrix state. */
@@ -2194,9 +3352,21 @@ enum ec_mkbp_event { · 11 unmodified lines
2194 /* The state of the switches have changed. */3352 /* The state of the switches have changed. */
2195 EC_MKBP_EVENT_SWITCH = 4,3353 EC_MKBP_EVENT_SWITCH = 4,
2196 3354
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 */
2198 EC_MKBP_EVENT_SYSRQ = 6,3362 EC_MKBP_EVENT_SYSRQ = 6,
2199 3363
3364 /*
3365 * New 64-bit host event.
3366 * The event data is 8 bytes of host event flags.
3367 */
3368 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3369
2200 /* Notify the AP that something happened on CEC */3370 /* Notify the AP that something happened on CEC */
2201 EC_MKBP_EVENT_CEC_EVENT = 8,3371 EC_MKBP_EVENT_CEC_EVENT = 8,
2202 3372
@@ -2206,65 +3376,140 @@ enum ec_mkbp_event { · 3 unmodified lines
2206 /* Number of MKBP events */3376 /* Number of MKBP events */
2207 EC_MKBP_EVENT_COUNT,3377 EC_MKBP_EVENT_COUNT,
2208};3378};
3379BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
2209 3380
2210union ec_response_get_next_data {3381union __ec_align_offset1 ec_response_get_next_data {
2211 uint8_t key_matrix[13];3382 uint8_t key_matrix[13];
2212 3383
2213 /* Unaligned */3384 /* Unaligned */
2214 uint32_t host_event;3385 uint32_t host_event;
3386 uint64_t host_event64;
2215 3387
2216 uint32_t buttons;3388 struct __ec_todo_unpacked {
2217 uint32_t switches;3389 /* For aligning the fifo_info */
2218 uint32_t sysrq;3390 uint8_t reserved[3];
2219} __packed;3391 struct ec_response_motion_sense_fifo_info info;
3392 } sensor_fifo;
2220 3393
2221union 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
3406union __ec_align_offset1 ec_response_get_next_data_v1 {
2222 uint8_t key_matrix[16];3407 uint8_t key_matrix[16];
3408
3409 /* Unaligned */
2223 uint32_t host_event;3410 uint32_t host_event;
3411 uint64_t host_event64;
3412
3413 struct __ec_todo_unpacked {
3414 /* For aligning the fifo_info */
3415 uint8_t reserved[3];
3416 struct ec_response_motion_sense_fifo_info info;
3417 } sensor_fifo;
3418
2224 uint32_t buttons;3419 uint32_t buttons;
3420
2225 uint32_t switches;3421 uint32_t switches;
3422
3423 uint32_t fp_events;
3424
2226 uint32_t sysrq;3425 uint32_t sysrq;
3426
3427 /* CEC events from enum mkbp_cec_event */
2227 uint32_t cec_events;3428 uint32_t cec_events;
3429
2228 uint8_t cec_message[16];3430 uint8_t cec_message[16];
2229} __packed;3431};
3432BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
2230 3433
2231struct ec_response_get_next_event {3434struct ec_response_get_next_event {
2232 uint8_t event_type;3435 uint8_t event_type;
2233 /* Followed by event data if any */3436 /* Followed by event data if any */
2234 union ec_response_get_next_data data;3437 union ec_response_get_next_data data;
2235} __packed;3438} __ec_align1;
2236 3439
2237struct ec_response_get_next_event_v1 {3440struct ec_response_get_next_event_v1 {
2238 uint8_t event_type;3441 uint8_t event_type;
2239 /* Followed by event data if any */3442 /* Followed by event data if any */
2240 union ec_response_get_next_data_v1 data;3443 union ec_response_get_next_data_v1 data;
2241} __packed;3444} __ec_align1;
2242 3445
2243/* Bit indices for buttons and switches.*/3446/* Bit indices for buttons and switches.*/
2244/* Buttons */3447/* Buttons */
2245#define EC_MKBP_POWER_BUTTON 03448#define EC_MKBP_POWER_BUTTON 0
2246#define EC_MKBP_VOL_UP 13449#define EC_MKBP_VOL_UP 1
2247#define EC_MKBP_VOL_DOWN 23450#define EC_MKBP_VOL_DOWN 2
3451#define EC_MKBP_RECOVERY 3
2248 3452
2249/* Switches */3453/* Switches */
2250#define EC_MKBP_LID_OPEN 03454#define EC_MKBP_LID_OPEN 0
2251#define EC_MKBP_TABLET_MODE 13455#define EC_MKBP_TABLET_MODE 1
2252#define EC_MKBP_BASE_ATTACHED 23456#define EC_MKBP_BASE_ATTACHED 2
2253 3457
3458/* Run keyboard factory test scanning */
3459#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
3460
3461struct ec_response_keyboard_factory_test {
3462 uint16_t shorted; /* Keyboard pins are shorted */
3463} __ec_align2;
3464
3465/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3466#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3467#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3468#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3469#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3470 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3471#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3472#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3473#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3474 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
3475#define EC_MKBP_FP_ENROLL BIT(27)
3476#define EC_MKBP_FP_MATCH BIT(28)
3477#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3478#define EC_MKBP_FP_FINGER_UP BIT(30)
3479#define EC_MKBP_FP_IMAGE_READY BIT(31)
3480/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3481#define EC_MKBP_FP_ERR_ENROLL_OK 0
3482#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3483#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3484#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3485#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3486/* Can be used to detect if image was usable for enrollment or not. */
3487#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3488/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3489#define EC_MKBP_FP_ERR_MATCH_NO 0
3490#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
3491#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
3492#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3493#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3494#define EC_MKBP_FP_ERR_MATCH_YES 1
3495#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3496#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3497
3498
2254/*****************************************************************************/3499/*****************************************************************************/
2255/* Temperature sensor commands */3500/* Temperature sensor commands */
2256 3501
2257/* Read temperature sensor info */3502/* Read temperature sensor info */
2258#define EC_CMD_TEMP_SENSOR_GET_INFO 0x703503#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
2259 3504
2260struct ec_params_temp_sensor_get_info {3505struct ec_params_temp_sensor_get_info {
2261 uint8_t id;3506 uint8_t id;
2262} __packed;3507} __ec_align1;
2263 3508
2264struct ec_response_temp_sensor_get_info {3509struct ec_response_temp_sensor_get_info {
2265 char sensor_name[32];3510 char sensor_name[32];
2266 uint8_t sensor_type;3511 uint8_t sensor_type;
2267} __packed;3512} __ec_align1;
2268 3513
2269/*****************************************************************************/3514/*****************************************************************************/
2270 3515
@@ -2277,49 +3522,131 @@ struct ec_response_temp_sensor_get_info { · 6 unmodified lines
2277/*****************************************************************************/3522/*****************************************************************************/
2278/* Host event commands */3523/* Host event commands */
2279 3524
3525
3526/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
2280/*3527/*
2281 * Host event mask params and response structures, shared by all of the host3528 * Host event mask params and response structures, shared by all of the host
2282 * event commands below.3529 * event commands below.
2283 */3530 */
2284struct ec_params_host_event_mask {3531struct ec_params_host_event_mask {
2285 uint32_t mask;3532 uint32_t mask;
2286} __packed;3533} __ec_align4;
2287 3534
2288struct ec_response_host_event_mask {3535struct ec_response_host_event_mask {
2289 uint32_t mask;3536 uint32_t mask;
2290} __packed;3537} __ec_align4;
2291 3538
2292/* These all use ec_response_host_event_mask */3539/* These all use ec_response_host_event_mask */
2293#define EC_CMD_HOST_EVENT_GET_B 0x873540#define EC_CMD_HOST_EVENT_GET_B 0x0087
2294#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x883541#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
2295#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x893542#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
2296#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d3543#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
2297 3544
2298/* These all use ec_params_host_event_mask */3545/* These all use ec_params_host_event_mask */
2299#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a3546#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
2300#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b3547#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
2301#define EC_CMD_HOST_EVENT_CLEAR 0x8c3548#define EC_CMD_HOST_EVENT_CLEAR 0x008C
2302#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e3549#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
2303#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f3550#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
3551
3552/*
3553 * Unified host event programming interface - Should be used by newer versions
3554 * of BIOS/OS to program host events and masks
3555 */
3556
3557struct ec_params_host_event {
3558
3559 /* Action requested by host - one of enum ec_host_event_action. */
3560 uint8_t action;
3561
3562 /*
3563 * Mask type that the host requested the action on - one of
3564 * enum ec_host_event_mask_type.
3565 */
3566 uint8_t mask_type;
3567
3568 /* Set to 0, ignore on read */
3569 uint16_t reserved;
3570
3571 /* Value to be used in case of set operations. */
3572 uint64_t value;
3573} __ec_align4;
3574
3575/*
3576 * Response structure returned by EC_CMD_HOST_EVENT.
3577 * Update the value on a GET request. Set to 0 on GET/CLEAR
3578 */
3579
3580struct ec_response_host_event {
3581
3582 /* Mask value in case of get operation */
3583 uint64_t value;
3584} __ec_align4;
3585
3586enum ec_host_event_action {
3587 /*
3588 * params.value is ignored. Value of mask_type populated
3589 * in response.value
3590 */
3591 EC_HOST_EVENT_GET,
3592
3593 /* Bits in params.value are set */
3594 EC_HOST_EVENT_SET,
3595
3596 /* Bits in params.value are cleared */
3597 EC_HOST_EVENT_CLEAR,
3598};
3599
3600enum ec_host_event_mask_type {
3601
3602 /* Main host event copy */
3603 EC_HOST_EVENT_MAIN,
3604
3605 /* Copy B of host events */
3606 EC_HOST_EVENT_B,
3607
3608 /* SCI Mask */
3609 EC_HOST_EVENT_SCI_MASK,
3610
3611 /* SMI Mask */
3612 EC_HOST_EVENT_SMI_MASK,
3613
3614 /* Mask of events that should be always reported in hostevents */
3615 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3616
3617 /* Active wake mask */
3618 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3619
3620 /* Lazy wake mask for S0ix */
3621 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3622
3623 /* Lazy wake mask for S3 */
3624 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3625
3626 /* Lazy wake mask for S5 */
3627 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3628};
3629
3630#define EC_CMD_HOST_EVENT 0x00A4
2304 3631
2305/*****************************************************************************/3632/*****************************************************************************/
2306/* Switch commands */3633/* Switch commands */
2307 3634
2308/* Enable/disable LCD backlight */3635/* Enable/disable LCD backlight */
2309#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x903636#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
2310 3637
2311struct ec_params_switch_enable_backlight {3638struct ec_params_switch_enable_backlight {
2312 uint8_t enabled;3639 uint8_t enabled;
2313} __packed;3640} __ec_align1;
2314 3641
2315/* Enable/disable WLAN/Bluetooth */3642/* Enable/disable WLAN/Bluetooth */
2316#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x913643#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
2317#define EC_VER_SWITCH_ENABLE_WIRELESS 13644#define EC_VER_SWITCH_ENABLE_WIRELESS 1
2318 3645
2319/* Version 0 params; no response */3646/* Version 0 params; no response */
2320struct ec_params_switch_enable_wireless_v0 {3647struct ec_params_switch_enable_wireless_v0 {
2321 uint8_t enabled;3648 uint8_t enabled;
2322} __packed;3649} __ec_align1;
2323 3650
2324/* Version 1 params */3651/* Version 1 params */
2325struct ec_params_switch_enable_wireless_v1 {3652struct ec_params_switch_enable_wireless_v1 {
@@ -2338,7 +3665,7 @@ struct ec_params_switch_enable_wireless_v1 { · 12 unmodified lines
2338 3665
2339 /* Which flags to copy from suspend_flags */3666 /* Which flags to copy from suspend_flags */
2340 uint8_t suspend_mask;3667 uint8_t suspend_mask;
2341} __packed;3668} __ec_align1;
2342 3669
2343/* Version 1 response */3670/* Version 1 response */
2344struct ec_response_switch_enable_wireless_v1 {3671struct ec_response_switch_enable_wireless_v1 {
@@ -2347,55 +3674,56 @@ struct ec_response_switch_enable_wireless_v1 { · 2 unmodified lines
2347 3674
2348 /* Flags to leave enabled in S3 */3675 /* Flags to leave enabled in S3 */
2349 uint8_t suspend_flags;3676 uint8_t suspend_flags;
2350} __packed;3677} __ec_align1;
2351 3678
2352/*****************************************************************************/3679/*****************************************************************************/
2353/* GPIO commands. Only available on EC if write protect has been disabled. */3680/* GPIO commands. Only available on EC if write protect has been disabled. */
2354 3681
2355/* Set GPIO output value */3682/* Set GPIO output value */
2356#define EC_CMD_GPIO_SET 0x923683#define EC_CMD_GPIO_SET 0x0092
2357 3684
2358struct ec_params_gpio_set {3685struct ec_params_gpio_set {
2359 char name[32];3686 char name[32];
2360 uint8_t val;3687 uint8_t val;
2361} __packed;3688} __ec_align1;
2362 3689
2363/* Get GPIO value */3690/* Get GPIO value */
2364#define EC_CMD_GPIO_GET 0x933691#define EC_CMD_GPIO_GET 0x0093
2365 3692
2366/* Version 0 of input params and response */3693/* Version 0 of input params and response */
2367struct ec_params_gpio_get {3694struct ec_params_gpio_get {
2368 char name[32];3695 char name[32];
2369} __packed;3696} __ec_align1;
3697
2370struct ec_response_gpio_get {3698struct ec_response_gpio_get {
2371 uint8_t val;3699 uint8_t val;
2372} __packed;3700} __ec_align1;
2373 3701
2374/* Version 1 of input params and response */3702/* Version 1 of input params and response */
2375struct ec_params_gpio_get_v1 {3703struct ec_params_gpio_get_v1 {
2376 uint8_t subcmd;3704 uint8_t subcmd;
2377 union {3705 union {
2378 struct {3706 struct __ec_align1 {
2379 char name[32];3707 char name[32];
2380 } get_value_by_name;3708 } get_value_by_name;
2381 struct {3709 struct __ec_align1 {
2382 uint8_t index;3710 uint8_t index;
2383 } get_info;3711 } get_info;
2384 };3712 };
2385} __packed;3713} __ec_align1;
2386 3714
2387struct ec_response_gpio_get_v1 {3715struct ec_response_gpio_get_v1 {
2388 union {3716 union {
2389 struct {3717 struct __ec_align1 {
2390 uint8_t val;3718 uint8_t val;
2391 } get_value_by_name, get_count;3719 } get_value_by_name, get_count;
2392 struct {3720 struct __ec_todo_unpacked {
2393 uint8_t val;3721 uint8_t val;
2394 char name[32];3722 char name[32];
2395 uint32_t flags;3723 uint32_t flags;
2396 } get_info;3724 } get_info;
2397 };3725 };
2398} __packed;3726} __ec_todo_packed;
2399 3727
2400enum gpio_get_subcmd {3728enum gpio_get_subcmd {
2401 EC_GPIO_GET_BY_NAME = 0,3729 EC_GPIO_GET_BY_NAME = 0,
@@ -2407,25 +3735,28 @@ enum gpio_get_subcmd { · 5 unmodified lines
2407/* I2C commands. Only available when flash write protect is unlocked. */3735/* I2C commands. Only available when flash write protect is unlocked. */
2408 3736
2409/*3737/*
2410 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be3738 * CAUTION: These commands are deprecated, and are not supported anymore in EC
2411 * removed soon. Use EC_CMD_I2C_XFER instead.3739 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3740 *
3741 * Use EC_CMD_I2C_PASSTHRU instead.
2412 */3742 */
2413 3743
2414/* Read I2C bus */3744/* Read I2C bus */
2415#define EC_CMD_I2C_READ 0x943745#define EC_CMD_I2C_READ 0x0094
2416 3746
2417struct ec_params_i2c_read {3747struct ec_params_i2c_read {
2418 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */3748 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
2419 uint8_t read_size; /* Either 8 or 16. */3749 uint8_t read_size; /* Either 8 or 16. */
2420 uint8_t port;3750 uint8_t port;
2421 uint8_t offset;3751 uint8_t offset;
2422} __packed;3752} __ec_align_size1;
3753
2423struct ec_response_i2c_read {3754struct ec_response_i2c_read {
2424 uint16_t data;3755 uint16_t data;
2425} __packed;3756} __ec_align2;
2426 3757
2427/* Write I2C bus */3758/* Write I2C bus */
2428#define EC_CMD_I2C_WRITE 0x953759#define EC_CMD_I2C_WRITE 0x0095
2429 3760
2430struct ec_params_i2c_write {3761struct ec_params_i2c_write {
2431 uint16_t data;3762 uint16_t data;
@@ -2433,7 +3764,7 @@ struct ec_params_i2c_write { · 1 unmodified line
2433 uint8_t write_size; /* Either 8 or 16. */3764 uint8_t write_size; /* Either 8 or 16. */
2434 uint8_t port;3765 uint8_t port;
2435 uint8_t offset;3766 uint8_t offset;
2436} __packed;3767} __ec_align_size1;
2437 3768
2438/*****************************************************************************/3769/*****************************************************************************/
2439/* Charge state commands. Only available when flash write protect unlocked. */3770/* Charge state commands. Only available when flash write protect unlocked. */
@@ -2441,7 +3772,7 @@ struct ec_params_i2c_write { · 1 unmodified line
2441/* Force charge state machine to stop charging the battery or force it to3772/* Force charge state machine to stop charging the battery or force it to
2442 * discharge the battery.3773 * discharge the battery.
2443 */3774 */
2444#define EC_CMD_CHARGE_CONTROL 0x963775#define EC_CMD_CHARGE_CONTROL 0x0096
2445#define EC_VER_CHARGE_CONTROL 13776#define EC_VER_CHARGE_CONTROL 1
2446 3777
2447enum ec_charge_control_mode {3778enum ec_charge_control_mode {
@@ -2452,13 +3783,12 @@ enum ec_charge_control_mode { · 4 unmodified lines
2452 3783
2453struct ec_params_charge_control {3784struct ec_params_charge_control {
2454 uint32_t mode; /* enum charge_control_mode */3785 uint32_t mode; /* enum charge_control_mode */
2455} __packed;3786} __ec_align4;
2456 3787
2457/*****************************************************************************/3788/*****************************************************************************/
2458/* Console commands. Only available when flash write protect is unlocked. */
2459 3789
2460/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */3790/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2461#define EC_CMD_CONSOLE_SNAPSHOT 0x973791#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
2462 3792
2463/*3793/*
2464 * Read data from the saved snapshot. If the subcmd parameter is3794 * Read data from the saved snapshot. If the subcmd parameter is
@@ -2472,7 +3802,7 @@ struct ec_params_charge_control { · 7 unmodified lines
2472 * Response is null-terminated string. Empty string, if there is no more3802 * Response is null-terminated string. Empty string, if there is no more
2473 * remaining output.3803 * remaining output.
2474 */3804 */
2475#define EC_CMD_CONSOLE_READ 0x983805#define EC_CMD_CONSOLE_READ 0x0098
2476 3806
2477enum ec_console_read_subcmd {3807enum ec_console_read_subcmd {
2478 CONSOLE_READ_NEXT = 0,3808 CONSOLE_READ_NEXT = 0,
@@ -2481,7 +3811,7 @@ enum ec_console_read_subcmd { · 2 unmodified lines
2481 3811
2482struct ec_params_console_read_v1 {3812struct ec_params_console_read_v1 {
2483 uint8_t subcmd; /* enum ec_console_read_subcmd */3813 uint8_t subcmd; /* enum ec_console_read_subcmd */
2484} __packed;3814} __ec_align1;
2485 3815
2486/*****************************************************************************/3816/*****************************************************************************/
2487 3817
@@ -2492,14 +3822,13 @@ struct ec_params_console_read_v1 { · 4 unmodified lines
2492 * EC_RES_SUCCESS if the command was successful.3822 * EC_RES_SUCCESS if the command was successful.
2493 * EC_RES_ERROR if the cut off command failed.3823 * EC_RES_ERROR if the cut off command failed.
2494 */3824 */
3825#define EC_CMD_BATTERY_CUT_OFF 0x0099
2495 3826
2496#define EC_CMD_BATTERY_CUT_OFF 0x993827#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
2497
2498#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2499 3828
2500struct ec_params_battery_cutoff {3829struct ec_params_battery_cutoff {
2501 uint8_t flags;3830 uint8_t flags;
2502} __packed;3831} __ec_align1;
2503 3832
2504/*****************************************************************************/3833/*****************************************************************************/
2505/* USB port mux control. */3834/* USB port mux control. */
@@ -2507,11 +3836,11 @@ struct ec_params_battery_cutoff { · 1 unmodified line
2507/*3836/*
2508 * Switch USB mux or return to automatic switching.3837 * Switch USB mux or return to automatic switching.
2509 */3838 */
2510#define EC_CMD_USB_MUX 0x9a3839#define EC_CMD_USB_MUX 0x009A
2511 3840
2512struct ec_params_usb_mux {3841struct ec_params_usb_mux {
2513 uint8_t mux;3842 uint8_t mux;
2514} __packed;3843} __ec_align1;
2515 3844
2516/*****************************************************************************/3845/*****************************************************************************/
2517/* LDOs / FETs control. */3846/* LDOs / FETs control. */
@@ -2524,25 +3853,25 @@ enum ec_ldo_state { · 6 unmodified lines
2524/*3853/*
2525 * Switch on/off a LDO.3854 * Switch on/off a LDO.
2526 */3855 */
2527#define EC_CMD_LDO_SET 0x9b3856#define EC_CMD_LDO_SET 0x009B
2528 3857
2529struct ec_params_ldo_set {3858struct ec_params_ldo_set {
2530 uint8_t index;3859 uint8_t index;
2531 uint8_t state;3860 uint8_t state;
2532} __packed;3861} __ec_align1;
2533 3862
2534/*3863/*
2535 * Get LDO state.3864 * Get LDO state.
2536 */3865 */
2537#define EC_CMD_LDO_GET 0x9c3866#define EC_CMD_LDO_GET 0x009C
2538 3867
2539struct ec_params_ldo_get {3868struct ec_params_ldo_get {
2540 uint8_t index;3869 uint8_t index;
2541} __packed;3870} __ec_align1;
2542 3871
2543struct ec_response_ldo_get {3872struct ec_response_ldo_get {
2544 uint8_t state;3873 uint8_t state;
2545} __packed;3874} __ec_align1;
2546 3875
2547/*****************************************************************************/3876/*****************************************************************************/
2548/* Power info. */3877/* Power info. */
@@ -2550,7 +3879,7 @@ struct ec_response_ldo_get { · 1 unmodified line
2550/*3879/*
2551 * Get power info.3880 * Get power info.
2552 */3881 */
2553#define EC_CMD_POWER_INFO 0x9d3882#define EC_CMD_POWER_INFO 0x009D
2554 3883
2555struct ec_response_power_info {3884struct ec_response_power_info {
2556 uint32_t usb_dev_type;3885 uint32_t usb_dev_type;
@@ -2558,21 +3887,21 @@ struct ec_response_power_info { · 1 unmodified line
2558 uint16_t voltage_system;3887 uint16_t voltage_system;
2559 uint16_t current_system;3888 uint16_t current_system;
2560 uint16_t usb_current_limit;3889 uint16_t usb_current_limit;
2561} __packed;3890} __ec_align4;
2562 3891
2563/*****************************************************************************/3892/*****************************************************************************/
2564/* I2C passthru command */3893/* I2C passthru command */
2565 3894
2566#define EC_CMD_I2C_PASSTHRU 0x9e3895#define EC_CMD_I2C_PASSTHRU 0x009E
2567 3896
2568/* Read data; if not present, message is a write */3897/* 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)
2570 3899
2571/* Mask for address */3900/* Mask for address */
2572#define EC_I2C_ADDR_MASK 0x3ff3901#define EC_I2C_ADDR_MASK 0x3ff
2573 3902
2574#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */3903#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
2575#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */3904#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
2576 3905
2577/* Any error */3906/* Any error */
2578#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)3907#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
@@ -2580,49 +3909,49 @@ struct ec_response_power_info { · 1 unmodified line
2580struct ec_params_i2c_passthru_msg {3909struct ec_params_i2c_passthru_msg {
2581 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */3910 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2582 uint16_t len; /* Number of bytes to read or write */3911 uint16_t len; /* Number of bytes to read or write */
2583} __packed;3912} __ec_align2;
2584 3913
2585struct ec_params_i2c_passthru {3914struct ec_params_i2c_passthru {
2586 uint8_t port; /* I2C port number */3915 uint8_t port; /* I2C port number */
2587 uint8_t num_msgs; /* Number of messages */3916 uint8_t num_msgs; /* Number of messages */
2588 struct ec_params_i2c_passthru_msg msg[];3917 struct ec_params_i2c_passthru_msg msg[];
2589 /* Data to write for all messages is concatenated here */3918 /* Data to write for all messages is concatenated here */
2590} __packed;3919} __ec_align2;
2591 3920
2592struct ec_response_i2c_passthru {3921struct ec_response_i2c_passthru {
2593 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */3922 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2594 uint8_t num_msgs; /* Number of messages processed */3923 uint8_t num_msgs; /* Number of messages processed */
2595 uint8_t data[]; /* Data read by messages concatenated here */3924 uint8_t data[]; /* Data read by messages concatenated here */
2596} __packed;3925} __ec_align1;
2597 3926
2598/*****************************************************************************/3927/*****************************************************************************/
2599/* Power button hang detect */3928/* Power button hang detect */
2600 3929
2601#define EC_CMD_HANG_DETECT 0x9f3930#define EC_CMD_HANG_DETECT 0x009F
2602 3931
2603/* Reasons to start hang detection timer */3932/* Reasons to start hang detection timer */
2604/* Power button pressed */3933/* Power button pressed */
2605#define EC_HANG_START_ON_POWER_PRESS (1 << 0)3934#define EC_HANG_START_ON_POWER_PRESS BIT(0)
2606 3935
2607/* Lid closed */3936/* Lid closed */
2608#define EC_HANG_START_ON_LID_CLOSE (1 << 1)3937#define EC_HANG_START_ON_LID_CLOSE BIT(1)
2609 3938
2610 /* Lid opened */3939 /* Lid opened */
2611#define EC_HANG_START_ON_LID_OPEN (1 << 2)3940#define EC_HANG_START_ON_LID_OPEN BIT(2)
2612 3941
2613/* Start of AP S3->S0 transition (booting or resuming from suspend) */3942/* 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)
2615 3944
2616/* Reasons to cancel hang detection */3945/* Reasons to cancel hang detection */
2617 3946
2618/* Power button released */3947/* Power button released */
2619#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)3948#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
2620 3949
2621/* Any host command from AP received */3950/* 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)
2623 3952
2624/* Stop on end of AP S0->S3 transition (suspending or shutting down) */3953/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2625#define EC_HANG_STOP_ON_SUSPEND (1 << 10)3954#define EC_HANG_STOP_ON_SUSPEND BIT(10)
2626 3955
2627/*3956/*
2628 * If this flag is set, all the other fields are ignored, and the hang detect3957 * 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
2630 * without reconfiguring any of the other hang detect settings. Note that3959 * without reconfiguring any of the other hang detect settings. Note that
2631 * you must previously have configured the timeouts.3960 * you must previously have configured the timeouts.
2632 */3961 */
2633#define EC_HANG_START_NOW (1 << 30)3962#define EC_HANG_START_NOW BIT(30)
2634 3963
2635/*3964/*
2636 * If this flag is set, all the other fields are ignored (including3965 * If this flag is set, all the other fields are ignored (including
2637 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer3966 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2638 * without reconfiguring any of the other hang detect settings.3967 * without reconfiguring any of the other hang detect settings.
2639 */3968 */
2640#define EC_HANG_STOP_NOW (1 << 31)3969#define EC_HANG_STOP_NOW BIT(31)
2641 3970
2642struct ec_params_hang_detect {3971struct ec_params_hang_detect {
2643 /* Flags; see EC_HANG_* */3972 /* Flags; see EC_HANG_* */
@@ -2648,7 +3977,7 @@ struct ec_params_hang_detect { · 4 unmodified lines
2648 3977
2649 /* Timeout in msec before generating warm reboot, if enabled */3978 /* Timeout in msec before generating warm reboot, if enabled */
2650 uint16_t warm_reboot_timeout_msec;3979 uint16_t warm_reboot_timeout_msec;
2651} __packed;3980} __ec_align4;
2652 3981
2653/*****************************************************************************/3982/*****************************************************************************/
2654/* Commands for battery charging */3983/* Commands for battery charging */
@@ -2657,7 +3986,7 @@ struct ec_params_hang_detect { · 2 unmodified lines
2657 * This is the single catch-all host command to exchange data regarding the3986 * This is the single catch-all host command to exchange data regarding the
2658 * charge state machine (v2 and up).3987 * charge state machine (v2 and up).
2659 */3988 */
2660#define EC_CMD_CHARGE_STATE 0xa03989#define EC_CMD_CHARGE_STATE 0x00A0
2661 3990
2662/* Subcommands for this host command */3991/* Subcommands for this host command */
2663enum charge_state_command {3992enum charge_state_command {
@@ -2677,6 +4006,11 @@ enum charge_state_params { · 13 unmodified lines
2677 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */4006 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2678 CS_PARAM_CHG_STATUS, /* charger-specific status */4007 CS_PARAM_CHG_STATUS, /* charger-specific status */
2679 CS_PARAM_CHG_OPTION, /* charger-specific options */4008 CS_PARAM_CHG_OPTION, /* charger-specific options */
4009 CS_PARAM_LIMIT_POWER, /*
4010 * Check if power is limited due to
4011 * low battery and / or a weak external
4012 * charger. READ ONLY.
4013 */
2680 /* How many so far? */4014 /* How many so far? */
2681 CS_NUM_BASE_PARAMS,4015 CS_NUM_BASE_PARAMS,
2682 4016
@@ -2684,30 +4018,39 @@ enum charge_state_params { · 1 unmodified line
2684 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,4018 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2685 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,4019 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2686 4020
4021 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4022 CS_PARAM_DEBUG_MIN = 0x20000,
4023 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4024 CS_PARAM_DEBUG_MANUAL_MODE,
4025 CS_PARAM_DEBUG_SEEMS_DEAD,
4026 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4027 CS_PARAM_DEBUG_BATT_REMOVED,
4028 CS_PARAM_DEBUG_MANUAL_CURRENT,
4029 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4030 CS_PARAM_DEBUG_MAX = 0x2ffff,
4031
2687 /* Other custom param ranges go here... */4032 /* Other custom param ranges go here... */
2688};4033};
2689 4034
2690struct ec_params_charge_state {4035struct ec_params_charge_state {
2691 uint8_t cmd; /* enum charge_state_command */4036 uint8_t cmd; /* enum charge_state_command */
2692 union {4037 union {
2693 struct {4038 /* get_state has no args */
2694 /* no args */
2695 } get_state;
2696 4039
2697 struct {4040 struct __ec_todo_unpacked {
2698 uint32_t param; /* enum charge_state_param */4041 uint32_t param; /* enum charge_state_param */
2699 } get_param;4042 } get_param;
2700 4043
2701 struct {4044 struct __ec_todo_unpacked {
2702 uint32_t param; /* param to set */4045 uint32_t param; /* param to set */
2703 uint32_t value; /* value to set */4046 uint32_t value; /* value to set */
2704 } set_param;4047 } set_param;
2705 };4048 };
2706} __packed;4049} __ec_todo_packed;
2707 4050
2708struct ec_response_charge_state {4051struct ec_response_charge_state {
2709 union {4052 union {
2710 struct {4053 struct __ec_align4 {
2711 int ac;4054 int ac;
2712 int chg_voltage;4055 int chg_voltage;
2713 int chg_current;4056 int chg_current;
@@ -2715,24 +4058,23 @@ struct ec_response_charge_state { · 1 unmodified line
2715 int batt_state_of_charge;4058 int batt_state_of_charge;
2716 } get_state;4059 } get_state;
2717 4060
2718 struct {4061 struct __ec_align4 {
2719 uint32_t value;4062 uint32_t value;
2720 } get_param;4063 } get_param;
2721 struct {4064
2722 /* no return values */4065 /* set_param returns no args */
2723 } set_param;
2724 };4066 };
2725} __packed;4067} __ec_align4;
2726 4068
2727 4069
2728/*4070/*
2729 * Set maximum battery charging current.4071 * Set maximum battery charging current.
2730 */4072 */
2731#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa14073#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
2732 4074
2733struct ec_params_current_limit {4075struct ec_params_current_limit {
2734 uint32_t limit; /* in mA */4076 uint32_t limit; /* in mA */
2735} __packed;4077} __ec_align4;
2736 4078
2737/*4079/*
2738 * Set maximum external voltage / current.4080 * Set maximum external voltage / current.
@@ -2743,23 +4085,69 @@ struct ec_params_current_limit { · 4 unmodified lines
2743struct ec_params_external_power_limit_v1 {4085struct ec_params_external_power_limit_v1 {
2744 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */4086 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
2745 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */4087 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
2746} __packed;4088} __ec_align2;
2747 4089
2748#define EC_POWER_LIMIT_NONE 0xffff4090#define EC_POWER_LIMIT_NONE 0xffff
2749 4091
4092/*
4093 * Set maximum voltage & current of a dedicated charge port
4094 */
4095#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4096
4097struct ec_params_dedicated_charger_limit {
4098 uint16_t current_lim; /* in mA */
4099 uint16_t voltage_lim; /* in mV */
4100} __ec_align2;
4101
4102/*****************************************************************************/
4103/* Hibernate/Deep Sleep Commands */
4104
4105/* Set the delay before going into hibernation. */
4106#define EC_CMD_HIBERNATION_DELAY 0x00A8
4107
4108struct ec_params_hibernation_delay {
4109 /*
4110 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4111 * current settings without changing them.
4112 */
4113 uint32_t seconds;
4114} __ec_align4;
4115
4116struct ec_response_hibernation_delay {
4117 /*
4118 * The current time in seconds in which the system has been in the G3
4119 * state. This value is reset if the EC transitions out of G3.
4120 */
4121 uint32_t time_g3;
4122
4123 /*
4124 * The current time remaining in seconds until the EC should hibernate.
4125 * This value is also reset if the EC transitions out of G3.
4126 */
4127 uint32_t time_remaining;
4128
4129 /*
4130 * The current time in seconds that the EC should wait in G3 before
4131 * hibernating.
4132 */
4133 uint32_t hibernate_delay;
4134} __ec_align4;
4135
2750/* Inform the EC when entering a sleep state */4136/* Inform the EC when entering a sleep state */
2751#define EC_CMD_HOST_SLEEP_EVENT 0xa94137#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
2752 4138
2753enum host_sleep_event {4139enum host_sleep_event {
2754 HOST_SLEEP_EVENT_S3_SUSPEND = 1,4140 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2755 HOST_SLEEP_EVENT_S3_RESUME = 2,4141 HOST_SLEEP_EVENT_S3_RESUME = 2,
2756 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,4142 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2757 HOST_SLEEP_EVENT_S0IX_RESUME = 44143 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4144 /* S3 suspend with additional enabled wake sources */
4145 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
2758};4146};
2759 4147
2760struct ec_params_host_sleep_event {4148struct ec_params_host_sleep_event {
2761 uint8_t sleep_event;4149 uint8_t sleep_event;
2762} __packed;4150} __ec_align1;
2763 4151
2764/*4152/*
2765 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep4153 * 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
2790 4178
2791 /* No parameters for non-suspend messages. */4179 /* No parameters for non-suspend messages. */
2792 };4180 };
2793} __packed;4181} __ec_align2;
2794 4182
2795/* A timeout occurred when this bit is set */4183/* A timeout occurred when this bit is set */
2796#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x800000004184#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
@@ -2816,42 +4204,72 @@ struct ec_response_host_sleep_event_v1 { · 19 unmodified lines
2816 4204
2817 /* No response fields for non-resume messages. */4205 /* No response fields for non-resume messages. */
2818 };4206 };
2819} __packed;4207} __ec_align4;
4208
4209/*****************************************************************************/
4210/* Device events */
4211#define EC_CMD_DEVICE_EVENT 0x00AA
4212
4213enum ec_device_event {
4214 EC_DEVICE_EVENT_TRACKPAD,
4215 EC_DEVICE_EVENT_DSP,
4216 EC_DEVICE_EVENT_WIFI,
4217};
4218
4219enum ec_device_event_param {
4220 /* Get and clear pending device events */
4221 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4222 /* Get device event mask */
4223 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4224 /* Set device event mask */
4225 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4226};
4227
4228#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
4229
4230struct ec_params_device_event {
4231 uint32_t event_mask;
4232 uint8_t param;
4233} __ec_align_size1;
4234
4235struct ec_response_device_event {
4236 uint32_t event_mask;
4237} __ec_align4;
2820 4238
2821/*****************************************************************************/4239/*****************************************************************************/
2822/* Smart battery pass-through */4240/* Smart battery pass-through */
2823 4241
2824/* Get / Set 16-bit smart battery registers */4242/* Get / Set 16-bit smart battery registers */
2825#define EC_CMD_SB_READ_WORD 0xb04243#define EC_CMD_SB_READ_WORD 0x00B0
2826#define EC_CMD_SB_WRITE_WORD 0xb14244#define EC_CMD_SB_WRITE_WORD 0x00B1
2827 4245
2828/* Get / Set string smart battery parameters4246/* Get / Set string smart battery parameters
2829 * formatted as SMBUS "block".4247 * formatted as SMBUS "block".
2830 */4248 */
2831#define EC_CMD_SB_READ_BLOCK 0xb24249#define EC_CMD_SB_READ_BLOCK 0x00B2
2832#define EC_CMD_SB_WRITE_BLOCK 0xb34250#define EC_CMD_SB_WRITE_BLOCK 0x00B3
2833 4251
2834struct ec_params_sb_rd {4252struct ec_params_sb_rd {
2835 uint8_t reg;4253 uint8_t reg;
2836} __packed;4254} __ec_align1;
2837 4255
2838struct ec_response_sb_rd_word {4256struct ec_response_sb_rd_word {
2839 uint16_t value;4257 uint16_t value;
2840} __packed;4258} __ec_align2;
2841 4259
2842struct ec_params_sb_wr_word {4260struct ec_params_sb_wr_word {
2843 uint8_t reg;4261 uint8_t reg;
2844 uint16_t value;4262 uint16_t value;
2845} __packed;4263} __ec_align1;
2846 4264
2847struct ec_response_sb_rd_block {4265struct ec_response_sb_rd_block {
2848 uint8_t data[32];4266 uint8_t data[32];
2849} __packed;4267} __ec_align1;
2850 4268
2851struct ec_params_sb_wr_block {4269struct ec_params_sb_wr_block {
2852 uint8_t reg;4270 uint8_t reg;
2853 uint16_t data[32];4271 uint16_t data[32];
2854} __packed;4272} __ec_align1;
2855 4273
2856/*****************************************************************************/4274/*****************************************************************************/
2857/* Battery vendor parameters4275/* Battery vendor parameters
@@ -2862,7 +4280,7 @@ struct ec_params_sb_wr_block { · 4 unmodified lines
2862 * requested value.4280 * requested value.
2863 */4281 */
2864 4282
2865#define EC_CMD_BATTERY_VENDOR_PARAM 0xb44283#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
2866 4284
2867enum ec_battery_vendor_param_mode {4285enum ec_battery_vendor_param_mode {
2868 BATTERY_VENDOR_PARAM_MODE_GET = 0,4286 BATTERY_VENDOR_PARAM_MODE_GET = 0,
@@ -2873,257 +4291,105 @@ struct ec_params_battery_vendor_param { · 4 unmodified lines
2873 uint32_t param;4291 uint32_t param;
2874 uint32_t value;4292 uint32_t value;
2875 uint8_t mode;4293 uint8_t mode;
2876} __packed;4294} __ec_align_size1;
2877 4295
2878struct ec_response_battery_vendor_param {4296struct ec_response_battery_vendor_param {
2879 uint32_t value;4297 uint32_t value;
2880} __packed;4298} __ec_align4;
2881 4299
2882/*****************************************************************************/4300/*****************************************************************************/
2883/* Commands for I2S recording on audio codec. */4301/*
2884 4302 * Smart Battery Firmware Update Commands
2885#define EC_CMD_CODEC_I2S 0x00BC4303 */
2886 4304#define EC_CMD_SB_FW_UPDATE 0x00B5
2887enum ec_codec_i2s_subcmd {4305
2888 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,4306enum ec_sb_fw_update_subcmd {
2889 EC_CODEC_SET_GAIN = 0x1,4307 EC_SB_FW_UPDATE_PREPARE = 0x0,
2890 EC_CODEC_GET_GAIN = 0x2,4308 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
2891 EC_CODEC_I2S_ENABLE = 0x3,4309 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
2892 EC_CODEC_I2S_SET_CONFIG = 0x4,4310 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
2893 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,4311 EC_SB_FW_UPDATE_END = 0x4,
2894 EC_CODEC_I2S_SET_BCLK = 0x6,4312 EC_SB_FW_UPDATE_STATUS = 0x5,
4313 EC_SB_FW_UPDATE_PROTECT = 0x6,
4314 EC_SB_FW_UPDATE_MAX = 0x7,
2895};4315};
2896 4316
2897enum ec_sample_depth_value {4317#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
2898 EC_CODEC_SAMPLE_DEPTH_16 = 0,4318#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
2899 EC_CODEC_SAMPLE_DEPTH_24 = 1,4319#define SB_FW_UPDATE_CMD_INFO_SIZE 8
2900};
2901 4320
2902enum ec_i2s_config {4321struct ec_sb_fw_update_header {
2903 EC_DAI_FMT_I2S = 0,4322 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
2904 EC_DAI_FMT_RIGHT_J = 1,4323 uint16_t fw_id; /* firmware id */
2905 EC_DAI_FMT_LEFT_J = 2,4324} __ec_align4;
2906 EC_DAI_FMT_PCM_A = 3,
2907 EC_DAI_FMT_PCM_B = 4,
2908 EC_DAI_FMT_PCM_TDM = 5,
2909};
2910 4325
2911struct ec_param_codec_i2s {4326struct ec_params_sb_fw_update {
2912 /*4327 struct ec_sb_fw_update_header hdr;
2913 * enum ec_codec_i2s_subcmd
2914 */
2915 uint8_t cmd;
2916 union {4328 union {
2917 /*4329 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
2918 * EC_CODEC_SET_SAMPLE_DEPTH4330 /* EC_SB_FW_UPDATE_INFO = 0x1 */
2919 * Value should be one of ec_sample_depth_value.4331 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
2920 */4332 /* EC_SB_FW_UPDATE_END = 0x4 */
2921 uint8_t depth;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;
2922 4343
2923 /*4344struct ec_response_sb_fw_update {
2924 * EC_CODEC_SET_GAIN4345 union {
2925 * Value should be 0~43 for both channels.4346 /* EC_SB_FW_UPDATE_INFO = 0x1 */
2926 */4347 struct __ec_align1 {
2927 struct ec_param_codec_i2s_set_gain {4348 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
2928 uint8_t left;4349 } info;
2929 uint8_t right;
2930 } __packed gain;
2931 4350
2932 /*4351 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
2933 * EC_CODEC_I2S_ENABLE4352 struct __ec_align1 {
2934 * 1 to enable, 0 to disable.4353 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
2935 */4354 } status;
2936 uint8_t i2s_enable;4355 };
4356} __ec_align1;
2937 4357
2938 /*4358/*
2939 * EC_CODEC_I2S_SET_COFNIG4359 * Entering Verified Boot Mode Command
2940 * Value should be one of ec_i2s_config.4360 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
2941 */4361 * Valid Modes are: normal, developer, and recovery.
2942 uint8_t i2s_config;4362 */
4363#define EC_CMD_ENTERING_MODE 0x00B6
2943 4364
2944 /*4365struct ec_params_entering_mode {
2945 * EC_CODEC_I2S_SET_TDM_CONFIG4366 int vboot_mode;
2946 * Value should be one of ec_i2s_config.4367} __ec_align4;
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;
2960 4368
2961 /*4369#define VBOOT_MODE_NORMAL 0
2962 * EC_CODEC_I2S_SET_BCLK4370#define VBOOT_MODE_DEVELOPER 1
2963 */4371#define VBOOT_MODE_RECOVERY 2
2964 uint32_t bclk;
2965 };
2966} __packed;
2967
2968/*
2969 * For subcommand EC_CODEC_GET_GAIN.
2970 */
2971struct ec_response_codec_gain {
2972 uint8_t left;
2973 uint8_t right;
2974} __packed;
2975 4372
2976/*****************************************************************************/4373/*****************************************************************************/
2977/* System commands */
2978
2979/*4374/*
2980 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't4375 * I2C passthru protection command: Protects I2C tunnels against access on
2981 * necessarily reboot the EC. Rename to "image" or something similar?4376 * certain addresses (board-specific).
2982 */4377 */
2983#define EC_CMD_REBOOT_EC 0xd24378#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
2984 4379
2985/* Command */4380enum ec_i2c_passthru_protect_subcmd {
2986enum ec_reboot_cmd {4381 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
2987 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */4382 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
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 */
2994};4383};
2995 4384
2996/* Flags for ec_params_reboot_ec.reboot_flags */4385struct ec_params_i2c_passthru_protect {
2997#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */4386 uint8_t subcmd;
2998#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */4387 uint8_t port; /* I2C port number */
2999 4388} __ec_align1;
3000struct 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
3124 4389
3125/* Current version of ACPI memory address space */4390struct ec_response_i2c_passthru_protect {
3126#define EC_ACPI_MEM_VERSION_CURRENT 14391 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
4392} __ec_align1;
3127 4393
3128 4394
3129/*****************************************************************************/4395/*****************************************************************************/
@@ -3132,7 +4398,8 @@ struct ec_params_reboot_ec { · 2 unmodified lines
3132 *4398 *
3133 * These commands are for sending and receiving message via HDMI CEC4399 * These commands are for sending and receiving message via HDMI CEC
3134 */4400 */
3135#define EC_MAX_CEC_MSG_LEN 164401
4402#define MAX_CEC_MSG_LEN 16
3136 4403
3137/* CEC message from the AP to be written on the CEC bus */4404/* CEC message from the AP to be written on the CEC bus */
3138#define EC_CMD_CEC_WRITE_MSG 0x00B84405#define EC_CMD_CEC_WRITE_MSG 0x00B8
@@ -3142,8 +4409,8 @@ struct ec_params_reboot_ec { · 3 unmodified lines
3142 * @msg: message content to write to the CEC bus4409 * @msg: message content to write to the CEC bus
3143 */4410 */
3144struct ec_params_cec_write {4411struct ec_params_cec_write {
3145 uint8_t msg[EC_MAX_CEC_MSG_LEN];4412 uint8_t msg[MAX_CEC_MSG_LEN];
3146} __packed;4413} __ec_align1;
3147 4414
3148/* Set various CEC parameters */4415/* Set various CEC parameters */
3149#define EC_CMD_CEC_SET 0x00BA4416#define EC_CMD_CEC_SET 0x00BA
@@ -3152,14 +4419,14 @@ struct ec_params_cec_write { · 2 unmodified lines
3152 * struct ec_params_cec_set - CEC parameters set4419 * struct ec_params_cec_set - CEC parameters set
3153 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS4420 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3154 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC4421 * @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,4422 * or 1 to enable CEC functionality, in case cmd is
3156 * this field encodes the requested logical address between 0 and 154423 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
3157 * or 0xff to unregister4424 * address between 0 and 15 or 0xff to unregister
3158 */4425 */
3159struct ec_params_cec_set {4426struct ec_params_cec_set {
3160 uint8_t cmd; /* enum cec_command */4427 uint8_t cmd; /* enum cec_command */
3161 uint8_t val;4428 uint8_t val;
3162} __packed;4429} __ec_align1;
3163 4430
3164/* Read various CEC parameters */4431/* Read various CEC parameters */
3165#define EC_CMD_CEC_GET 0x00BB4432#define EC_CMD_CEC_GET 0x00BB
@@ -3170,7 +4437,7 @@ struct ec_params_cec_set { · 4 unmodified lines
3170 */4437 */
3171struct ec_params_cec_get {4438struct ec_params_cec_get {
3172 uint8_t cmd; /* enum cec_command */4439 uint8_t cmd; /* enum cec_command */
3173} __packed;4440} __ec_align1;
3174 4441
3175/**4442/**
3176 * struct ec_response_cec_get - CEC parameters get response4443 * struct ec_response_cec_get - CEC parameters get response
@@ -3181,10 +4448,10 @@ struct ec_params_cec_get { · 4 unmodified lines
3181 */4448 */
3182struct ec_response_cec_get {4449struct ec_response_cec_get {
3183 uint8_t val;4450 uint8_t val;
3184} __packed;4451} __ec_align1;
3185 4452
3186/* CEC parameters command */4453/* CEC parameters command */
3187enum ec_cec_command {4454enum cec_command {
3188 /* CEC reading, writing and events enable */4455 /* CEC reading, writing and events enable */
3189 CEC_CMD_ENABLE,4456 CEC_CMD_ENABLE,
3190 /* CEC logical address */4457 /* CEC logical address */
@@ -3199,6 +4466,134 @@ enum mkbp_cec_event { · 8 unmodified lines
3199 EC_MKBP_CEC_SEND_FAILED = BIT(1),4466 EC_MKBP_CEC_SEND_FAILED = BIT(1),
3200};4467};
3201 4468
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
4476enum 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
4487enum ec_sample_depth_value {
4488 EC_CODEC_SAMPLE_DEPTH_16 = 0,
4489 EC_CODEC_SAMPLE_DEPTH_24 = 1,
4490};
4491
4492enum 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 */
4504struct __ec_align1 ec_codec_i2s_gain {
4505 uint8_t left;
4506 uint8_t right;
4507};
4508
4509struct __ec_todo_unpacked ec_param_codec_i2s_tdm {
4510 int16_t ch0_delay; /* 0 to 496 */
4511 int16_t ch1_delay; /* -1 to 496 */
4512 uint8_t adjacent_to_ch0;
4513 uint8_t adjacent_to_ch1;
4514};
4515
4516struct __ec_todo_packed ec_param_codec_i2s {
4517 /* enum ec_codec_i2s_subcmd */
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 */
4568enum 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
4584struct 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
3202/*****************************************************************************/4597/*****************************************************************************/
3203/*4598/*
3204 * Special commands4599 * Special commands
@@ -3216,7 +4611,7 @@ enum mkbp_cec_event { · 11 unmodified lines
3216 *4611 *
3217 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.4612 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3218 */4613 */
3219#define EC_CMD_REBOOT 0xd1 /* Think "die" */4614#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
3220 4615
3221/*4616/*
3222 * Resend last response (not supported on LPC).4617 * Resend last response (not supported on LPC).
@@ -3225,7 +4620,7 @@ enum mkbp_cec_event { · 2 unmodified lines
3225 * there was no previous command, or the previous command's response was too4620 * there was no previous command, or the previous command's response was too
3226 * big to save.4621 * big to save.
3227 */4622 */
3228#define EC_CMD_RESEND_RESPONSE 0xdb4623#define EC_CMD_RESEND_RESPONSE 0x00DB
3229 4624
3230/*4625/*
3231 * This header byte on a command indicate version 0. Any header byte less4626 * This header byte on a command indicate version 0. Any header byte less
@@ -3237,9 +4632,7 @@ enum mkbp_cec_event { · 5 unmodified lines
3237 *4632 *
3238 * The old EC interface must not use commands 0xdc or higher.4633 * The old EC interface must not use commands 0xdc or higher.
3239 */4634 */
3240#define EC_CMD_VERSION0 0xdc4635#define EC_CMD_VERSION0 0x00DC
3241
3242#endif /* !__ACPI__ */
3243 4636
3244/*****************************************************************************/4637/*****************************************************************************/
3245/*4638/*
@@ -3249,21 +4642,56 @@ enum mkbp_cec_event { · 3 unmodified lines
3249 */4642 */
3250 4643
3251/* EC to PD MCU exchange status command */4644/* EC to PD MCU exchange status command */
3252#define EC_CMD_PD_EXCHANGE_STATUS 0x1004645#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
4646#define EC_VER_PD_EXCHANGE_STATUS 2
4647
4648enum pd_charge_state {
4649 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
4650 PD_CHARGE_NONE, /* No charging allowed */
4651 PD_CHARGE_5V, /* 5V charging only */
4652 PD_CHARGE_MAX /* Charge at max voltage */
4653};
3253 4654
3254/* Status of EC being sent to PD */4655/* Status of EC being sent to PD */
4656#define EC_STATUS_HIBERNATING BIT(0)
4657
3255struct ec_params_pd_status {4658struct ec_params_pd_status {
3256 int8_t batt_soc; /* battery state of charge */4659 uint8_t status; /* EC status */
3257} __packed;4660 int8_t batt_soc; /* battery state of charge */
4661 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
4662} __ec_align1;
3258 4663
3259/* Status of PD being sent back to EC */4664/* Status of PD being sent back to EC */
4665#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
4666#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
4667#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
4668#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
4669#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
4670#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
4671#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
4672#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
4673 PD_STATUS_TCPC_ALERT_1 | \
4674 PD_STATUS_HOST_EVENT)
3260struct ec_response_pd_status {4675struct ec_response_pd_status {
3261 int8_t status; /* PD MCU status */4676 uint32_t curr_lim_ma; /* input current limit */
3262 uint32_t curr_lim_ma; /* input current limit */4677 uint16_t status; /* PD MCU status */
3263} __packed;4678 int8_t active_charge_port; /* active charging port */
4679} __ec_align_size1;
4680
4681/* AP to PD MCU host event status command, cleared on read */
4682#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
4683
4684/* PD MCU host event status bits */
4685#define PD_EVENT_UPDATE_DEVICE BIT(0)
4686#define PD_EVENT_POWER_CHANGE BIT(1)
4687#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
4688#define PD_EVENT_DATA_SWAP BIT(3)
4689struct ec_response_host_event_status {
4690 uint32_t status; /* PD MCU host event status */
4691} __ec_align4;
3264 4692
3265/* Set USB type-C port role and muxes */4693/* Set USB type-C port role and muxes */
3266#define EC_CMD_USB_PD_CONTROL 0x1014694#define EC_CMD_USB_PD_CONTROL 0x0101
3267 4695
3268enum usb_pd_control_role {4696enum usb_pd_control_role {
3269 USB_PD_CTRL_ROLE_NO_CHANGE = 0,4697 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
@@ -3271,6 +4699,8 @@ enum usb_pd_control_role { · 1 unmodified line
3271 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,4699 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3272 USB_PD_CTRL_ROLE_FORCE_SINK = 3,4700 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3273 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,4701 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
4702 USB_PD_CTRL_ROLE_FREEZE = 5,
4703 USB_PD_CTRL_ROLE_COUNT
3274};4704};
3275 4705
3276enum usb_pd_control_mux {4706enum usb_pd_control_mux {
@@ -3280,6 +4710,7 @@ enum usb_pd_control_mux { · 3 unmodified lines
3280 USB_PD_CTRL_MUX_DP = 3,4710 USB_PD_CTRL_MUX_DP = 3,
3281 USB_PD_CTRL_MUX_DOCK = 4,4711 USB_PD_CTRL_MUX_DOCK = 4,
3282 USB_PD_CTRL_MUX_AUTO = 5,4712 USB_PD_CTRL_MUX_AUTO = 5,
4713 USB_PD_CTRL_MUX_COUNT
3283};4714};
3284 4715
3285enum usb_pd_control_swap {4716enum usb_pd_control_swap {
@@ -3295,11 +4726,11 @@ struct ec_params_usb_pd_control { · 9 unmodified lines
3295 uint8_t role;4726 uint8_t role;
3296 uint8_t mux;4727 uint8_t mux;
3297 uint8_t swap;4728 uint8_t swap;
3298} __packed;4729} __ec_align1;
3299 4730
3300#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */4731#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
3301#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */4732#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
3302#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */4733#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
3303 4734
3304#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */4735#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
3305#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */4736#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
@@ -3309,28 +4740,54 @@ struct ec_params_usb_pd_control { · 3 unmodified lines
3309#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */4740#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
3310#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */4741#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
3311 4742
4743struct ec_response_usb_pd_control {
4744 uint8_t enabled;
4745 uint8_t role;
4746 uint8_t polarity;
4747 uint8_t state;
4748} __ec_align1;
4749
3312struct ec_response_usb_pd_control_v1 {4750struct ec_response_usb_pd_control_v1 {
3313 uint8_t enabled;4751 uint8_t enabled;
3314 uint8_t role;4752 uint8_t role;
3315 uint8_t polarity;4753 uint8_t polarity;
3316 char state[32];4754 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
4765struct ec_response_usb_pd_control_v2 {
4766 uint8_t enabled;
4767 uint8_t role;
4768 uint8_t polarity;
4769 char state[32];
4770 uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
4771 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
4772 /* CL:1500994 Current cable type */
4773 uint8_t reserved_cable_type;
4774} __ec_align1;
3318 4775
3319#define EC_CMD_USB_PD_PORTS 0x1024776#define EC_CMD_USB_PD_PORTS 0x0102
3320 4777
3321/* Maximum number of PD ports on a device, num_ports will be <= this */4778/* Maximum number of PD ports on a device, num_ports will be <= this */
3322#define EC_USB_PD_MAX_PORTS 84779#define EC_USB_PD_MAX_PORTS 8
3323 4780
3324struct ec_response_usb_pd_ports {4781struct ec_response_usb_pd_ports {
3325 uint8_t num_ports;4782 uint8_t num_ports;
3326} __packed;4783} __ec_align1;
3327 4784
3328#define EC_CMD_USB_PD_POWER_INFO 0x1034785#define EC_CMD_USB_PD_POWER_INFO 0x0103
3329 4786
3330#define PD_POWER_CHARGING_PORT 0xff4787#define PD_POWER_CHARGING_PORT 0xff
3331struct ec_params_usb_pd_power_info {4788struct ec_params_usb_pd_power_info {
3332 uint8_t port;4789 uint8_t port;
3333} __packed;4790} __ec_align1;
3334 4791
3335enum usb_chg_type {4792enum usb_chg_type {
3336 USB_CHG_TYPE_NONE,4793 USB_CHG_TYPE_NONE,
@@ -3343,6 +4800,7 @@ enum usb_chg_type { · 6 unmodified lines
3343 USB_CHG_TYPE_OTHER,4800 USB_CHG_TYPE_OTHER,
3344 USB_CHG_TYPE_VBUS,4801 USB_CHG_TYPE_VBUS,
3345 USB_CHG_TYPE_UNKNOWN,4802 USB_CHG_TYPE_UNKNOWN,
4803 USB_CHG_TYPE_DEDICATED,
3346};4804};
3347enum usb_power_roles {4805enum usb_power_roles {
3348 USB_PD_PORT_POWER_DISCONNECTED,4806 USB_PD_PORT_POWER_DISCONNECTED,
@@ -3356,7 +4814,7 @@ struct usb_chg_measures { · 7 unmodified lines
3356 uint16_t voltage_now;4814 uint16_t voltage_now;
3357 uint16_t current_max;4815 uint16_t current_max;
3358 uint16_t current_lim;4816 uint16_t current_lim;
3359} __packed;4817} __ec_align2;
3360 4818
3361struct ec_response_usb_pd_power_info {4819struct ec_response_usb_pd_power_info {
3362 uint8_t role;4820 uint8_t role;
@@ -3365,11 +4823,8 @@ struct ec_response_usb_pd_power_info { · 2 unmodified lines
3365 uint8_t reserved1;4823 uint8_t reserved1;
3366 struct usb_chg_measures meas;4824 struct usb_chg_measures meas;
3367 uint32_t max_power;4825 uint32_t max_power;
3368} __packed;4826} __ec_align4;
3369 4827
3370struct ec_params_usb_pd_info_request {
3371 uint8_t port;
3372} __packed;
3373 4828
3374/*4829/*
3375 * This command will return the number of USB PD charge port + the number4830 * 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
3379#define EC_CMD_CHARGE_PORT_COUNT 0x01054834#define EC_CMD_CHARGE_PORT_COUNT 0x0105
3380struct ec_response_charge_port_count {4835struct ec_response_charge_port_count {
3381 uint8_t port_count;4836 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
4842enum usb_pd_fw_update_cmds {
4843 USB_PD_FW_REBOOT,
4844 USB_PD_FW_FLASH_ERASE,
4845 USB_PD_FW_FLASH_WRITE,
4846 USB_PD_FW_ERASE_SIG,
4847};
4848
4849struct ec_params_usb_pd_fw_update {
4850 uint16_t dev_id;
4851 uint8_t cmd;
4852 uint8_t port;
4853 uint32_t size; /* Size to write in bytes */
4854 /* Followed by data to write */
4855} __ec_align4;
4856
4857/* Write USB-PD Accessory RW_HASH table entry */
4858#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
4859/* RW hash is first 20 bytes of SHA-256 of RW section */
4860#define PD_RW_HASH_SIZE 20
4861struct ec_params_usb_pd_rw_hash_entry {
4862 uint16_t dev_id;
4863 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
4864 uint8_t reserved; /*
4865 * For alignment of current_image
4866 * TODO(rspangler) but it's not aligned!
4867 * Should have been reserved[2].
4868 */
4869 uint32_t current_image; /* One of ec_current_image */
4870} __ec_align1;
4871
4872/* Read USB-PD Accessory info */
4873#define EC_CMD_USB_PD_DEV_INFO 0x0112
4874
4875struct ec_params_usb_pd_info_request {
4876 uint8_t port;
4877} __ec_align1;
3383 4878
3384/* Read USB-PD Device discovery info */4879/* Read USB-PD Device discovery info */
3385#define EC_CMD_USB_PD_DISCOVERY 0x01134880#define EC_CMD_USB_PD_DISCOVERY 0x0113
@@ -3387,7 +4882,7 @@ struct ec_params_usb_pd_discovery_entry { · 1 unmodified line
3387 uint16_t vid; /* USB-IF VID */4882 uint16_t vid; /* USB-IF VID */
3388 uint16_t pid; /* USB-IF PID */4883 uint16_t pid; /* USB-IF PID */
3389 uint8_t ptype; /* product type (hub,periph,cable,ama) */4884 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3390} __packed;4885} __ec_align_size1;
3391 4886
3392/* Override default charge behavior */4887/* Override default charge behavior */
3393#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x01144888#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
@@ -3401,9 +4896,13 @@ enum usb_pd_override_ports { · 7 unmodified lines
3401 4896
3402struct ec_params_charge_port_override {4897struct ec_params_charge_port_override {
3403 int16_t override_port; /* Override port# */4898 int16_t override_port; /* Override port# */
3404} __packed;4899} __ec_align2;
3405 4900
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 */
3407#define EC_CMD_PD_GET_LOG_ENTRY 0x01154906#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
3408 4907
3409struct ec_response_pd_log {4908struct ec_response_pd_log {
@@ -3412,7 +4911,7 @@ struct ec_response_pd_log { · 2 unmodified lines
3412 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */4911 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3413 uint16_t data; /* type-defined data payload */4912 uint16_t data; /* type-defined data payload */
3414 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */4913 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3415} __packed;4914} __ec_align4;
3416 4915
3417/* The timestamp is the microsecond counter shifted to get about a ms. */4916/* The timestamp is the microsecond counter shifted to get about a ms. */
3418#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */4917#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
@@ -3478,35 +4977,698 @@ struct mcdp_version { · 59 unmodified lines
3478 uint8_t major;4977 uint8_t major;
3479 uint8_t minor;4978 uint8_t minor;
3480 uint16_t build;4979 uint16_t build;
3481} __packed;4980} __ec_align4;
3482 4981
3483struct mcdp_info {4982struct mcdp_info {
3484 uint8_t family[2];4983 uint8_t family[2];
3485 uint8_t chipid[2];4984 uint8_t chipid[2];
3486 struct mcdp_version irom;4985 struct mcdp_version irom;
3487 struct mcdp_version fw;4986 struct mcdp_version fw;
3488} __packed;4987} __ec_align4;
3489 4988
3490/* struct mcdp_info field decoding */4989/* struct mcdp_info field decoding */
3491#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])4990#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3492#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])4991#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3493 4992
4993/* Get/Set USB-PD Alternate mode info */
4994#define EC_CMD_USB_PD_GET_AMODE 0x0116
4995struct ec_params_usb_pd_get_mode_request {
4996 uint16_t svid_idx; /* SVID index to get */
4997 uint8_t port; /* port */
4998} __ec_align_size1;
4999
5000struct ec_params_usb_pd_get_mode_response {
5001 uint16_t svid; /* SVID */
5002 uint16_t opos; /* Object Position */
5003 uint32_t vdo[6]; /* Mode VDOs */
5004} __ec_align4;
5005
5006#define EC_CMD_USB_PD_SET_AMODE 0x0117
5007
5008enum pd_mode_cmd {
5009 PD_EXIT_MODE = 0,
5010 PD_ENTER_MODE = 1,
5011 /* Not a command. Do NOT remove. */
5012 PD_MODE_CMD_COUNT,
5013};
5014
5015struct ec_params_usb_pd_set_mode_request {
5016 uint32_t cmd; /* enum pd_mode_cmd */
5017 uint16_t svid; /* SVID to set */
5018 uint8_t opos; /* Object Position */
5019 uint8_t port; /* port */
5020} __ec_align4;
5021
5022/* Ask the PD MCU to record a log of a requested type */
5023#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
5024
5025struct ec_params_pd_write_log_entry {
5026 uint8_t type; /* event type : see PD_EVENT_xx above */
5027 uint8_t port; /* port#, or 0 for events unrelated to a given port */
5028} __ec_align1;
5029
5030
5031/* Control USB-PD chip */
5032#define EC_CMD_PD_CONTROL 0x0119
5033
5034enum ec_pd_control_cmd {
5035 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5036 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5037 PD_RESET, /* Force reset the PD chip */
5038 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5039 PD_CHIP_ON, /* Power on the PD chip */
5040};
5041
5042struct ec_params_pd_control {
5043 uint8_t chip; /* chip id */
5044 uint8_t subcmd;
5045} __ec_align1;
5046
3494/* Get info about USB-C SS muxes */5047/* Get info about USB-C SS muxes */
3495#define EC_CMD_USB_PD_MUX_INFO 0x11a5048#define EC_CMD_USB_PD_MUX_INFO 0x011A
3496 5049
3497struct ec_params_usb_pd_mux_info {5050struct ec_params_usb_pd_mux_info {
3498 uint8_t port; /* USB-C port number */5051 uint8_t port; /* USB-C port number */
3499} __packed;5052} __ec_align1;
3500 5053
3501/* Flags representing mux state */5054/* Flags representing mux state */
3502#define USB_PD_MUX_USB_ENABLED (1 << 0)5055#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
3503#define USB_PD_MUX_DP_ENABLED (1 << 1)5056#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
3504#define USB_PD_MUX_POLARITY_INVERTED (1 << 2)5057#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
3505#define USB_PD_MUX_HPD_IRQ (1 << 3)5058#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5059#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
3506 5060
3507struct ec_response_usb_pd_mux_info {5061struct ec_response_usb_pd_mux_info {
3508 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */5062 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
5067struct ec_params_pd_chip_info {
5068 uint8_t port; /* USB-C port number */
5069 uint8_t renew; /* Force renewal */
5070} __ec_align1;
5071
5072struct ec_response_pd_chip_info {
5073 uint16_t vendor_id;
5074 uint16_t product_id;
5075 uint16_t device_id;
5076 union {
5077 uint8_t fw_version_string[8];
5078 uint64_t fw_version_number;
5079 };
5080} __ec_align2;
5081
5082struct ec_response_pd_chip_info_v1 {
5083 uint16_t vendor_id;
5084 uint16_t product_id;
5085 uint16_t device_id;
5086 union {
5087 uint8_t fw_version_string[8];
5088 uint64_t fw_version_number;
5089 };
5090 union {
5091 uint8_t min_req_fw_version_string[8];
5092 uint64_t min_req_fw_version_number;
5093 };
5094} __ec_align2;
5095
5096/* Run RW signature verification and get status */
5097#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5098
5099struct ec_response_rwsig_check_status {
5100 uint32_t status;
5101} __ec_align4;
5102
5103/* For controlling RWSIG task */
5104#define EC_CMD_RWSIG_ACTION 0x011D
5105
5106enum rwsig_action {
5107 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5108 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5109};
5110
5111struct ec_params_rwsig_action {
5112 uint32_t action;
5113} __ec_align4;
5114
5115/* Run verification on a slot */
5116#define EC_CMD_EFS_VERIFY 0x011E
5117
5118struct ec_params_efs_verify {
5119 uint8_t region; /* enum ec_flash_region */
5120} __ec_align1;
5121
5122/*
5123 * Retrieve info from Cros Board Info store. Response is based on the data
5124 * type. Integers return a uint32. Strings return a string, using the response
5125 * size to determine how big it is.
5126 */
5127#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5128/*
5129 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5130 * hardware write-protect enabled.
5131 */
5132#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5133
5134enum cbi_data_tag {
5135 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5136 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5137 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
5138 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
5139 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
5140 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
5141 CBI_TAG_COUNT,
5142};
5143
5144/*
5145 * Flags to control read operation
5146 *
5147 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5148 * write was successful without reboot.
5149 */
5150#define CBI_GET_RELOAD BIT(0)
5151
5152struct ec_params_get_cbi {
5153 uint32_t tag; /* enum cbi_data_tag */
5154 uint32_t flag; /* CBI_GET_* */
5155} __ec_align4;
5156
5157/*
5158 * Flags to control write behavior.
5159 *
5160 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5161 * useful when writing multiple fields in a row.
5162 * INIT: Need to be set when creating a new CBI from scratch. All fields
5163 * will be initialized to zero first.
5164 */
5165#define CBI_SET_NO_SYNC BIT(0)
5166#define CBI_SET_INIT BIT(1)
5167
5168struct ec_params_set_cbi {
5169 uint32_t tag; /* enum cbi_data_tag */
5170 uint32_t flag; /* CBI_SET_* */
5171 uint32_t size; /* Data size */
5172 uint8_t data[]; /* For string and raw data */
5173} __ec_align1;
5174
5175/*
5176 * Information about resets of the AP by the EC and the EC's own uptime.
5177 */
5178#define EC_CMD_GET_UPTIME_INFO 0x0121
5179
5180struct ec_response_uptime_info {
5181 /*
5182 * Number of milliseconds since the last EC boot. Sysjump resets
5183 * typically do not restart the EC's time_since_boot epoch.
5184 *
5185 * WARNING: The EC's sense of time is much less accurate than the AP's
5186 * sense of time, in both phase and frequency. This timebase is similar
5187 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
5188 */
5189 uint32_t time_since_ec_boot_ms;
5190
5191 /*
5192 * Number of times the AP was reset by the EC since the last EC boot.
5193 * Note that the AP may be held in reset by the EC during the initial
5194 * boot sequence, such that the very first AP boot may count as more
5195 * than one here.
5196 */
5197 uint32_t ap_resets_since_ec_boot;
5198
5199 /*
5200 * The set of flags which describe the EC's most recent reset. See
5201 * include/system.h RESET_FLAG_* for details.
5202 */
5203 uint32_t ec_reset_flags;
5204
5205 /* Empty log entries have both the cause and timestamp set to zero. */
5206 struct ap_reset_log_entry {
5207 /*
5208 * See include/chipset.h: enum chipset_{reset,shutdown}_reason
5209 * for details.
5210 */
5211 uint16_t reset_cause;
5212
5213 /* Reserved for protocol growth. */
5214 uint16_t reserved;
5215
5216 /*
5217 * The time of the reset's assertion, in milliseconds since the
5218 * last EC boot, in the same epoch as time_since_ec_boot_ms.
5219 * Set to zero if the log entry is empty.
5220 */
5221 uint32_t reset_time_ms;
5222 } recent_ap_reset[4];
5223} __ec_align4;
5224
5225/*
5226 * Add entropy to the device secret (stored in the rollback region).
5227 *
5228 * Depending on the chip, the operation may take a long time (e.g. to erase
5229 * flash), so the commands are asynchronous.
5230 */
5231#define EC_CMD_ADD_ENTROPY 0x0122
5232
5233enum add_entropy_action {
5234 /* Add entropy to the current secret. */
5235 ADD_ENTROPY_ASYNC = 0,
5236 /*
5237 * Add entropy, and also make sure that the previous secret is erased.
5238 * (this can be implemented by adding entropy multiple times until
5239 * all rolback blocks have been overwritten).
5240 */
5241 ADD_ENTROPY_RESET_ASYNC = 1,
5242 /* Read back result from the previous operation. */
5243 ADD_ENTROPY_GET_RESULT = 2,
5244};
5245
5246struct ec_params_rollback_add_entropy {
5247 uint8_t action;
5248} __ec_align1;
5249
5250/*
5251 * Perform a single read of a given ADC channel.
5252 */
5253#define EC_CMD_ADC_READ 0x0123
5254
5255struct ec_params_adc_read {
5256 uint8_t adc_channel;
5257} __ec_align1;
5258
5259struct ec_response_adc_read {
5260 int32_t adc_value;
5261} __ec_align4;

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