blob: 45865bc5cae4725763d89ab62206ea2a77bd2bf0 [file] [log] [blame]
Martin Rothedb937a2016-01-12 16:17:44 -07001// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are
5// met:
6//
7// * Redistributions of source code must retain the above copyright
8// notice, this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above
10// copyright notice, this list of conditions and the following disclaimer
11// in the documentation and/or other materials provided with the
12// distribution.
13// * Neither the name of Google Inc. nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080028
29/* Host communication command constants for Chrome EC */
30
Duncan Laurieeb316852015-12-01 18:51:18 -080031#ifndef __CROS_EC_EC_COMMANDS_H
32#define __CROS_EC_EC_COMMANDS_H
Stefan Reinauerd6682e82013-02-21 15:39:35 -080033
Patrick Georgi0f6187a2017-07-28 15:57:23 +020034#if !defined(__ACPI__) && !defined(__KERNEL__)
Duncan Laurie67f26cc2017-06-29 23:17:22 -070035#include <stdint.h>
36#endif
37
38/*
39 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
40 * generates more efficient code for accessing request/response structures on
41 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
42 */
43#ifdef CHROMIUM_EC
44#include "common.h"
45#endif
46
Stefan Reinauerd6682e82013-02-21 15:39:35 -080047/*
Duncan Laurie93e24442014-01-06 12:30:52 -080048 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080049 *
Duncan Laurie93e24442014-01-06 12:30:52 -080050 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
51 * determined in other ways. Remove this once the kernel code no longer
52 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080053 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080054#define EC_PROTO_VERSION 0x00000002
55
56/* Command version mask */
57#define EC_VER_MASK(version) (1UL << (version))
58
59/* I/O addresses for ACPI commands */
60#define EC_LPC_ADDR_ACPI_DATA 0x62
61#define EC_LPC_ADDR_ACPI_CMD 0x66
62
63/* I/O addresses for host command */
64#define EC_LPC_ADDR_HOST_DATA 0x200
65#define EC_LPC_ADDR_HOST_CMD 0x204
66
67/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080068/* Protocol version 2 */
69#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
70#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
71 * EC_PROTO2_MAX_PARAM_SIZE */
72/* Protocol version 3 */
73#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
74#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080075
Bill Richardsone221aad2013-06-12 10:50:41 -070076/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
77 * and they tell the kernel that so we have to think of it as two parts. */
78#define EC_HOST_CMD_REGION0 0x800
79#define EC_HOST_CMD_REGION1 0x880
80#define EC_HOST_CMD_REGION_SIZE 0x80
81
Stefan Reinauerd6682e82013-02-21 15:39:35 -080082/* EC command register bit functions */
83#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
84#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
85#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
86#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
87#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
88#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
89#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
90
91#define EC_LPC_ADDR_MEMMAP 0x900
92#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
93#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
94
95/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070096#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
97#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
98#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
99#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800100#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
101#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
102#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
103#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
104#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700105#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
106/* Unused 0x28 - 0x2f */
107#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
108/* Unused 0x31 - 0x33 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600109#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
110/* Battery values are all 32 bits, unless otherwise noted. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800111#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
112#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
113#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600114#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
115#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
116#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
117/* Unused 0x4f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800118#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
119#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
120#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
121#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700122/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800123#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
124#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
125#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
126#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700127#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
128/* Unused 0x84 - 0x8f */
129#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
130/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800131#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
132/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
133/* 0x94 - 0x99: 1st Accelerometer */
134/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700135#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700136/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700137
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700138/*
139 * ACPI is unable to access memory mapped data at or above this offset due to
140 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
141 * which might be needed by ACPI.
142 */
143#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700144
145/* Define the format of the accelerometer mapped memory status byte. */
146#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
147#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
148#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800149
150/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
151#define EC_TEMP_SENSOR_ENTRIES 16
152/*
153 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
154 *
155 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
156 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700157#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800158
159/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700160#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
161#define EC_TEMP_SENSOR_ERROR 0xfe
162#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
163#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800164/*
165 * The offset of temperature value stored in mapped memory. This allows
166 * reporting a temperature range of 200K to 454K = -73C to 181C.
167 */
168#define EC_TEMP_SENSOR_OFFSET 200
169
Duncan Laurie93e24442014-01-06 12:30:52 -0800170/*
171 * Number of ALS readings at EC_MEMMAP_ALS
172 */
173#define EC_ALS_ENTRIES 2
174
175/*
176 * The default value a temperature sensor will return when it is present but
177 * has not been read this boot. This is a reasonable number to avoid
178 * triggering alarms on the host.
179 */
180#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
181
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800182#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
183#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
184#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
185
186/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
187#define EC_BATT_FLAG_AC_PRESENT 0x01
188#define EC_BATT_FLAG_BATT_PRESENT 0x02
189#define EC_BATT_FLAG_DISCHARGING 0x04
190#define EC_BATT_FLAG_CHARGING 0x08
191#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600192/* Set if some of the static/dynamic data is invalid (or outdated). */
193#define EC_BATT_FLAG_INVALID_DATA 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800194
195/* Switch flags at EC_MEMMAP_SWITCHES */
196#define EC_SWITCH_LID_OPEN 0x01
197#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
198#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700199/* Was recovery requested via keyboard; now unused. */
200#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800201/* Recovery requested via dedicated signal (from servo board) */
202#define EC_SWITCH_DEDICATED_RECOVERY 0x10
203/* Was fake developer mode switch; now unused. Remove in next refactor. */
204#define EC_SWITCH_IGNORE0 0x20
205
206/* Host command interface flags */
207/* Host command interface supports LPC args (LPC interface only) */
208#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800209/* Host command interface supports version 3 protocol */
210#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800211
212/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800213#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
214#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
215#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
216#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
217#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800218
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700219/*****************************************************************************/
220/*
221 * ACPI commands
222 *
223 * These are valid ONLY on the ACPI command/data port.
224 */
225
226/*
227 * ACPI Read Embedded Controller
228 *
229 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
230 *
231 * Use the following sequence:
232 *
233 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
234 * - Wait for EC_LPC_CMDR_PENDING bit to clear
235 * - Write address to EC_LPC_ADDR_ACPI_DATA
236 * - Wait for EC_LPC_CMDR_DATA bit to set
237 * - Read value from EC_LPC_ADDR_ACPI_DATA
238 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700239#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700240
241/*
242 * ACPI Write Embedded Controller
243 *
244 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
245 *
246 * Use the following sequence:
247 *
248 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
249 * - Wait for EC_LPC_CMDR_PENDING bit to clear
250 * - Write address to EC_LPC_ADDR_ACPI_DATA
251 * - Wait for EC_LPC_CMDR_PENDING bit to clear
252 * - Write value to EC_LPC_ADDR_ACPI_DATA
253 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700254#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700255
256/*
257 * ACPI Burst Enable Embedded Controller
258 *
259 * This enables burst mode on the EC to allow the host to issue several
260 * commands back-to-back. While in this mode, writes to mapped multi-byte
261 * data are locked out to ensure data consistency.
262 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700263#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700264
265/*
266 * ACPI Burst Disable Embedded Controller
267 *
268 * This disables burst mode on the EC and stops preventing EC writes to mapped
269 * multi-byte data.
270 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700271#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700272
273/*
274 * ACPI Query Embedded Controller
275 *
276 * This clears the lowest-order bit in the currently pending host events, and
277 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
278 * event 0x80000000 = 32), or 0 if no event was pending.
279 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700280#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700281
282/* Valid addresses in ACPI memory space, for read/write commands */
283
284/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
285#define EC_ACPI_MEM_VERSION 0x00
286/*
287 * Test location; writing value here updates test compliment byte to (0xff -
288 * value).
289 */
290#define EC_ACPI_MEM_TEST 0x01
291/* Test compliment; writes here are ignored. */
292#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
293
294/* Keyboard backlight brightness percent (0 - 100) */
295#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
296/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
297#define EC_ACPI_MEM_FAN_DUTY 0x04
298
299/*
300 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
301 * independent thresholds attached to them. The current value of the ID
302 * register determines which sensor is affected by the THRESHOLD and COMMIT
303 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
304 * as the memory-mapped sensors. The COMMIT register applies those settings.
305 *
306 * The spec does not mandate any way to read back the threshold settings
307 * themselves, but when a threshold is crossed the AP needs a way to determine
308 * which sensor(s) are responsible. Each reading of the ID register clears and
309 * returns one sensor ID that has crossed one of its threshold (in either
310 * direction) since the last read. A value of 0xFF means "no new thresholds
311 * have tripped". Setting or enabling the thresholds for a sensor will clear
312 * the unread event count for that sensor.
313 */
314#define EC_ACPI_MEM_TEMP_ID 0x05
315#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
316#define EC_ACPI_MEM_TEMP_COMMIT 0x07
317/*
318 * Here are the bits for the COMMIT register:
319 * bit 0 selects the threshold index for the chosen sensor (0/1)
320 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
321 * Each write to the commit register affects one threshold.
322 */
323#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
324#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
325/*
326 * Example:
327 *
328 * Set the thresholds for sensor 2 to 50 C and 60 C:
329 * write 2 to [0x05] -- select temp sensor 2
330 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
331 * write 0x2 to [0x07] -- enable threshold 0 with this value
332 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
333 * write 0x3 to [0x07] -- enable threshold 1 with this value
334 *
335 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
336 * write 2 to [0x05] -- select temp sensor 2
337 * write 0x1 to [0x07] -- disable threshold 1
338 */
339
340/* DPTF battery charging current limit */
341#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
342
343/* Charging limit is specified in 64 mA steps */
344#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
345/* Value to disable DPTF battery charging limit */
346#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700347
jiazi Yang51fc93f2016-07-28 05:15:01 -0400348/*
349 * Report device orientation
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700350 * bit 0 device is tablet mode
jiazi Yang51fc93f2016-07-28 05:15:01 -0400351 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700352#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
353#define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700354
355/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600356 * Report device features. Uses the same format as the host command, except:
357 *
358 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
359 * of features", which is of limited interest when the system is already
360 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
361 * these are supported, it defaults to 0.
362 * This allows detecting the presence of this field since older versions of
363 * the EC codebase would simply return 0xff to that unknown address. Check
364 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
365 * are valid.
366 */
367#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
368#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
369#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
370#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
371#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
372#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
373#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
374#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
375
376#define EC_ACPI_MEM_BATTERY_INDEX 0x12
377
378/*
379 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
380 * is enabled (1) or disabled (0).
381 * bit 0 USB port ID 0
382 * ...
383 * bit 7 USB port ID 7
384 */
385#define EC_ACPI_MEM_USB_PORT_POWER 0x13
386
387/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700388 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
389 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
390 */
391#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
392#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
393
394/* Current version of ACPI memory address space */
395#define EC_ACPI_MEM_VERSION_CURRENT 2
396
397
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800398/*
399 * This header file is used in coreboot both in C and ACPI code. The ACPI code
400 * is pre-processed to handle constants but the ASL compiler is unable to
401 * handle actual C code so keep it separate.
402 */
403#ifndef __ACPI__
404
405/*
406 * Define __packed if someone hasn't beat us to it. Linux kernel style
407 * checking prefers __packed over __attribute__((packed)).
408 */
409#ifndef __packed
410#define __packed __attribute__((packed))
411#endif
412
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700413#ifndef __aligned
414#define __aligned(x) __attribute__((aligned(x)))
415#endif
416
417/*
418 * Attributes for EC request and response packets. Just defining __packed
419 * results in inefficient assembly code on ARM, if the structure is actually
420 * 32-bit aligned, as it should be for all buffers.
421 *
422 * Be very careful when adding these to existing structures. They will round
423 * up the structure size to the specified boundary.
424 *
425 * Also be very careful to make that if a structure is included in some other
426 * parent structure that the alignment will still be true given the packing of
427 * the parent structure. This is particularly important if the sub-structure
428 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200429 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700430 *
431 * Also be very careful using __packed - particularly when nesting non-packed
432 * structures inside packed ones. In fact, DO NOT use __packed directly;
433 * always use one of these attributes.
434 *
435 * Once everything is annotated properly, the following search strings should
436 * not return ANY matches in this file other than right here:
437 *
438 * "__packed" - generates inefficient code; all sub-structs must also be packed
439 *
440 * "struct [^_]" - all structs should be annotated, except for structs that are
441 * members of other structs/unions (and their original declarations should be
442 * annotated).
443 */
444#ifdef CONFIG_HOSTCMD_ALIGNED
445
446/*
447 * Packed structures where offset and size are always aligned to 1, 2, or 4
448 * byte boundary.
449 */
450#define __ec_align1 __packed
451#define __ec_align2 __packed __aligned(2)
452#define __ec_align4 __packed __aligned(4)
453
454/*
455 * Packed structure which must be under-aligned, because its size is not a
456 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
457 * of all multi-byte fields in it, even though they are themselves aligned.
458 *
459 * In theory, we could duplicate the structure with __aligned(4) for accessing
460 * its members, but use the __packed version for sizeof().
461 */
462#define __ec_align_size1 __packed
463
464/*
465 * Packed structure which must be under-aligned, because its offset inside a
466 * parent structure is not a 4-byte multiple.
467 */
468#define __ec_align_offset1 __packed
469#define __ec_align_offset2 __packed __aligned(2)
470
471/*
472 * Structures which are complicated enough that I'm skipping them on the first
473 * pass. They are effectively unchanged from their previous definitions.
474 *
475 * TODO(rspangler): Figure out what to do with these. It's likely necessary
476 * to work out the size and offset of each member and add explicit padding to
477 * maintain those.
478 */
479#define __ec_todo_packed __packed
480#define __ec_todo_unpacked
481
482#else /* !CONFIG_HOSTCMD_ALIGNED */
483
484/*
485 * Packed structures make no assumption about alignment, so they do inefficient
486 * byte-wise reads.
487 */
488#define __ec_align1 __packed
489#define __ec_align2 __packed
490#define __ec_align4 __packed
491#define __ec_align_size1 __packed
492#define __ec_align_offset1 __packed
493#define __ec_align_offset2 __packed
494#define __ec_todo_packed __packed
495#define __ec_todo_unpacked
496
497#endif /* !CONFIG_HOSTCMD_ALIGNED */
498
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800499/* LPC command status byte masks */
500/* EC has written a byte in the data register and host hasn't read it yet */
501#define EC_LPC_STATUS_TO_HOST 0x01
502/* Host has written a command/data byte and the EC hasn't read it yet */
503#define EC_LPC_STATUS_FROM_HOST 0x02
504/* EC is processing a command */
505#define EC_LPC_STATUS_PROCESSING 0x04
506/* Last write to EC was a command, not data */
507#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700508/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800509#define EC_LPC_STATUS_BURST_MODE 0x10
510/* SCI event is pending (requesting SCI query) */
511#define EC_LPC_STATUS_SCI_PENDING 0x20
512/* SMI event is pending (requesting SMI query) */
513#define EC_LPC_STATUS_SMI_PENDING 0x40
514/* (reserved) */
515#define EC_LPC_STATUS_RESERVED 0x80
516
517/*
518 * EC is busy. This covers both the EC processing a command, and the host has
519 * written a new command but the EC hasn't picked it up yet.
520 */
521#define EC_LPC_STATUS_BUSY_MASK \
522 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
523
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700524/* Host command response codes (16-bit). Note that response codes should be
525 * stored in a uint16_t rather than directly in a value of this type.
526 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800527enum ec_status {
528 EC_RES_SUCCESS = 0,
529 EC_RES_INVALID_COMMAND = 1,
530 EC_RES_ERROR = 2,
531 EC_RES_INVALID_PARAM = 3,
532 EC_RES_ACCESS_DENIED = 4,
533 EC_RES_INVALID_RESPONSE = 5,
534 EC_RES_INVALID_VERSION = 6,
535 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700536 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
537 EC_RES_UNAVAILABLE = 9, /* No response available */
538 EC_RES_TIMEOUT = 10, /* We got a timeout */
539 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800540 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
541 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700542 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700543 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600544 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
545 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
546 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
547 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
548 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800549};
550
551/*
552 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
553 * EC command uses code 0 to mean "no event pending". We explicitly specify
554 * each value in the enum listing so they won't change if we delete/insert an
555 * item or rearrange the list (it needs to be stable across platforms, not
556 * just within a single compiled instance).
557 */
558enum host_event_code {
559 EC_HOST_EVENT_LID_CLOSED = 1,
560 EC_HOST_EVENT_LID_OPEN = 2,
561 EC_HOST_EVENT_POWER_BUTTON = 3,
562 EC_HOST_EVENT_AC_CONNECTED = 4,
563 EC_HOST_EVENT_AC_DISCONNECTED = 5,
564 EC_HOST_EVENT_BATTERY_LOW = 6,
565 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
566 EC_HOST_EVENT_BATTERY = 8,
567 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700568 /* Event generated by a device attached to the EC */
569 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800570 EC_HOST_EVENT_THERMAL = 11,
571 EC_HOST_EVENT_USB_CHARGER = 12,
572 EC_HOST_EVENT_KEY_PRESSED = 13,
573 /*
574 * EC has finished initializing the host interface. The host can check
575 * for this event following sending a EC_CMD_REBOOT_EC command to
576 * determine when the EC is ready to accept subsequent commands.
577 */
578 EC_HOST_EVENT_INTERFACE_READY = 14,
579 /* Keyboard recovery combo has been pressed */
580 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
581
582 /* Shutdown due to thermal overload */
583 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
584 /* Shutdown due to battery level too low */
585 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
586
Duncan Laurie93e24442014-01-06 12:30:52 -0800587 /* Suggest that the AP throttle itself */
588 EC_HOST_EVENT_THROTTLE_START = 18,
589 /* Suggest that the AP resume normal speed */
590 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700591
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800592 /* Hang detect logic detected a hang and host event timeout expired */
593 EC_HOST_EVENT_HANG_DETECT = 20,
594 /* Hang detect logic detected a hang and warm rebooted the AP */
595 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700596
597 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700598 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800599
Duncan Lauried8401182014-09-29 08:32:19 -0700600 /* Battery Status flags have changed */
601 EC_HOST_EVENT_BATTERY_STATUS = 23,
602
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700603 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800604 EC_HOST_EVENT_PANIC = 24,
605
Furquan Shaikh066cc852015-06-20 15:53:03 -0700606 /* Keyboard fastboot combo has been pressed */
607 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
608
Gwendal Grignou880b4582016-06-20 08:49:25 -0700609 /* EC RTC event occurred */
610 EC_HOST_EVENT_RTC = 26,
611
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700612 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700613 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700614
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700615 /* EC desires to change state of host-controlled USB mux */
616 EC_HOST_EVENT_USB_MUX = 28,
617
jiazi Yang51fc93f2016-07-28 05:15:01 -0400618 /* TABLET/LAPTOP mode event*/
619 EC_HOST_EVENT_MODE_CHANGE = 29,
620
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700621 /* Keyboard recovery combo with hardware reinitialization */
622 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
623
624 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800625 * The high bit of the event mask is not used as a host event code. If
626 * it reads back as set, then the entire event mask should be
627 * considered invalid by the host. This can happen when reading the
628 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
629 * not initialized on the EC, or improperly configured on the host.
630 */
631 EC_HOST_EVENT_INVALID = 32
632};
633/* Host event mask */
Furquan Shaikh8788fd62017-11-20 20:28:18 -0800634#define EC_HOST_EVENT_MASK(event_code) (1ULL << ((event_code) - 1))
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800635
636/* Arguments at EC_LPC_ADDR_HOST_ARGS */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700637struct __ec_align4 ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800638 uint8_t flags;
639 uint8_t command_version;
640 uint8_t data_size;
641 /*
642 * Checksum; sum of command + flags + command_version + data_size +
643 * all params/response data bytes.
644 */
645 uint8_t checksum;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700646};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800647
648/* Flags for ec_lpc_host_args.flags */
649/*
650 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
651 * params.
652 *
653 * If EC gets a command and this flag is not set, this is an old-style command.
654 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
655 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700656 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800657 */
658#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
659/*
660 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
661 *
662 * If EC responds to a command and this flag is not set, this is an old-style
663 * response. Command version is 0 and response data from EC is at
664 * EC_LPC_ADDR_OLD_PARAM with unknown length.
665 */
666#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
667
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800668/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800669/*
670 * Byte codes returned by EC over SPI interface.
671 *
672 * These can be used by the AP to debug the EC interface, and to determine
673 * when the EC is not in a state where it will ever get around to responding
674 * to the AP.
675 *
676 * Example of sequence of bytes read from EC for a current good transfer:
677 * 1. - - AP asserts chip select (CS#)
678 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
679 * 3. - - EC starts handling CS# interrupt
680 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
681 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
682 * bytes looking for EC_SPI_FRAME_START
683 * 6. - - EC finishes processing and sets up response
684 * 7. EC_SPI_FRAME_START - AP reads frame byte
685 * 8. (response packet) - AP reads response packet
686 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
687 * 10 - - AP deasserts chip select
688 * 11 - - EC processes CS# interrupt and sets up DMA for
689 * next request
690 *
691 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
692 * the following byte values:
693 * EC_SPI_OLD_READY
694 * EC_SPI_RX_READY
695 * EC_SPI_RECEIVING
696 * EC_SPI_PROCESSING
697 *
698 * Then the EC found an error in the request, or was not ready for the request
699 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
700 * because the EC is unable to tell when the AP is done sending its request.
701 */
702
703/*
704 * Framing byte which precedes a response packet from the EC. After sending a
705 * request, the AP will clock in bytes until it sees the framing byte, then
706 * clock in the response packet.
707 */
708#define EC_SPI_FRAME_START 0xec
709
710/*
711 * Padding bytes which are clocked out after the end of a response packet.
712 */
713#define EC_SPI_PAST_END 0xed
714
715/*
716 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
717 * that the AP will send a valid packet header (starting with
718 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
719 */
720#define EC_SPI_RX_READY 0xf8
721
722/*
723 * EC has started receiving the request from the AP, but hasn't started
724 * processing it yet.
725 */
726#define EC_SPI_RECEIVING 0xf9
727
728/* EC has received the entire request from the AP and is processing it. */
729#define EC_SPI_PROCESSING 0xfa
730
731/*
732 * EC received bad data from the AP, such as a packet header with an invalid
733 * length. EC will ignore all data until chip select deasserts.
734 */
735#define EC_SPI_RX_BAD_DATA 0xfb
736
737/*
738 * EC received data from the AP before it was ready. That is, the AP asserted
739 * chip select and started clocking data before the EC was ready to receive it.
740 * EC will ignore all data until chip select deasserts.
741 */
742#define EC_SPI_NOT_READY 0xfc
743
744/*
745 * EC was ready to receive a request from the AP. EC has treated the byte sent
746 * by the AP as part of a request packet, or (for old-style ECs) is processing
747 * a fully received packet but is not ready to respond yet.
748 */
749#define EC_SPI_OLD_READY 0xfd
750
751/*****************************************************************************/
752
753/*
754 * Protocol version 2 for I2C and SPI send a request this way:
755 *
756 * 0 EC_CMD_VERSION0 + (command version)
757 * 1 Command number
758 * 2 Length of params = N
759 * 3..N+2 Params, if any
760 * N+3 8-bit checksum of bytes 0..N+2
761 *
762 * The corresponding response is:
763 *
764 * 0 Result code (EC_RES_*)
765 * 1 Length of params = M
766 * 2..M+1 Params, if any
767 * M+2 8-bit checksum of bytes 0..M+1
768 */
769#define EC_PROTO2_REQUEST_HEADER_BYTES 3
770#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
771#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
772 EC_PROTO2_REQUEST_TRAILER_BYTES)
773
774#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
775#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
776#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
777 EC_PROTO2_RESPONSE_TRAILER_BYTES)
778
779/* Parameter length was limited by the LPC interface */
780#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
781
782/* Maximum request and response packet sizes for protocol version 2 */
783#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
784 EC_PROTO2_MAX_PARAM_SIZE)
785#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
786 EC_PROTO2_MAX_PARAM_SIZE)
787
788/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800789
790/*
791 * Value written to legacy command port / prefix byte to indicate protocol
792 * 3+ structs are being used. Usage is bus-dependent.
793 */
794#define EC_COMMAND_PROTOCOL_3 0xda
795
796#define EC_HOST_REQUEST_VERSION 3
797
798/* Version 3 request from host */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700799struct __ec_align4 ec_host_request {
800 /* Structure version (=3)
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800801 *
802 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
803 * version it doesn't know how to parse.
804 */
805 uint8_t struct_version;
806
807 /*
808 * Checksum of request and data; sum of all bytes including checksum
809 * should total to 0.
810 */
811 uint8_t checksum;
812
813 /* Command code */
814 uint16_t command;
815
816 /* Command version */
817 uint8_t command_version;
818
819 /* Unused byte in current protocol version; set to 0 */
820 uint8_t reserved;
821
822 /* Length of data which follows this header */
823 uint16_t data_len;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700824};
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800825
826#define EC_HOST_RESPONSE_VERSION 3
827
828/* Version 3 response from EC */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700829struct __ec_align4 ec_host_response {
830 /* Structure version (=3) */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800831 uint8_t struct_version;
832
833 /*
834 * Checksum of response and data; sum of all bytes including checksum
835 * should total to 0.
836 */
837 uint8_t checksum;
838
839 /* Result code (EC_RES_*) */
840 uint16_t result;
841
842 /* Length of data which follows this header */
843 uint16_t data_len;
844
845 /* Unused bytes in current protocol version; set to 0 */
846 uint16_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700847};
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800848
849/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600850
851/*
852 * Host command protocol V4.
853 *
854 * Packets always start with a request or response header. They are followed
855 * by data_len bytes of data. If the data_crc_present flag is set, the data
856 * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1
857 * polynomial.
858 *
859 * Host algorithm when sending a request q:
860 *
861 * 101) tries_left=(some value, e.g. 3);
862 * 102) q.seq_num++
863 * 103) q.seq_dup=0
864 * 104) Calculate q.header_crc.
865 * 105) Send request q to EC.
866 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
867 *
868 * 201) If r.struct_version != 4, go to 301.
869 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
870 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
871 * 204) If r.seq_num != q.seq_num, go to 301.
872 * 205) If r.seq_dup == q.seq_dup, return success.
873 * 207) If r.seq_dup == 1, go to 301.
874 * 208) Return error.
875 *
876 * 301) If --tries_left <= 0, return error.
877 * 302) If q.seq_dup == 1, go to 105.
878 * 303) q.seq_dup = 1
879 * 304) Go to 104.
880 *
881 * EC algorithm when receiving a request q.
882 * EC has response buffer r, error buffer e.
883 *
884 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
885 * and go to 301
886 * 102) If q.header_crc mismatches calculated CRC, set e.result =
887 * EC_RES_INVALID_HEADER_CRC and go to 301
888 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
889 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
890 * and go to 301.
891 * 104) If q.seq_dup == 0, go to 201.
892 * 105) If q.seq_num != r.seq_num, go to 201.
893 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
894 *
895 * 201) Process request q into response r.
896 * 202) r.seq_num = q.seq_num
897 * 203) r.seq_dup = q.seq_dup
898 * 204) Calculate r.header_crc
899 * 205) If r.data_len > 0 and data is no longer available, set e.result =
900 * EC_RES_DUP_UNAVAILABLE and go to 301.
901 * 206) Send response r.
902 *
903 * 301) e.seq_num = q.seq_num
904 * 302) e.seq_dup = q.seq_dup
905 * 303) Calculate e.header_crc.
906 * 304) Send error response e.
907 */
908
909/* Version 4 request from host */
910struct __ec_align4 ec_host_request4 {
911 /*
912 * bits 0-3: struct_version: Structure version (=4)
913 * bit 4: is_response: Is response (=0)
914 * bits 5-6: seq_num: Sequence number
915 * bit 7: seq_dup: Sequence duplicate flag
916 */
917 uint8_t fields0;
918
919 /*
920 * bits 0-4: command_version: Command version
921 * bits 5-6: Reserved (set 0, ignore on read)
922 * bit 7: data_crc_present: Is data CRC present after data
923 */
924 uint8_t fields1;
925
926 /* Command code (EC_CMD_*) */
927 uint16_t command;
928
929 /* Length of data which follows this header (not including data CRC) */
930 uint16_t data_len;
931
932 /* Reserved (set 0, ignore on read) */
933 uint8_t reserved;
934
935 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
936 uint8_t header_crc;
937};
938
939/* Version 4 response from EC */
940struct __ec_align4 ec_host_response4 {
941 /*
942 * bits 0-3: struct_version: Structure version (=4)
943 * bit 4: is_response: Is response (=1)
944 * bits 5-6: seq_num: Sequence number
945 * bit 7: seq_dup: Sequence duplicate flag
946 */
947 uint8_t fields0;
948
949 /*
950 * bits 0-6: Reserved (set 0, ignore on read)
951 * bit 7: data_crc_present: Is data CRC present after data
952 */
953 uint8_t fields1;
954
955 /* Result code (EC_RES_*) */
956 uint16_t result;
957
958 /* Length of data which follows this header (not including data CRC) */
959 uint16_t data_len;
960
961 /* Reserved (set 0, ignore on read) */
962 uint8_t reserved;
963
964 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
965 uint8_t header_crc;
966};
967
968/* Fields in fields0 byte */
969#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
970#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
971#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
972#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
973#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
974
975/* Fields in fields1 byte */
976#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
977#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
978
979/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800980/*
981 * Notes on commands:
982 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700983 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700984 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800985 * specified, the command does not input or output data, respectively.
986 * Parameter/response length is implicit in the structs. Some underlying
987 * communication protocols (I2C, SPI) may add length or checksum headers, but
988 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700989 *
990 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
991 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800992 */
993
994/*****************************************************************************/
995/* General / test commands */
996
997/*
998 * Get protocol version, used to deal with non-backward compatible protocol
999 * changes.
1000 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001001#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001002
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001003struct __ec_align4 ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001004 uint32_t version;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001005};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001006
1007/*
1008 * Hello. This is a simple command to test the EC is responsive to
1009 * commands.
1010 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001011#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001012
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001013struct __ec_align4 ec_params_hello {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001014 uint32_t in_data; /* Pass anything here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001015};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001016
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001017struct __ec_align4 ec_response_hello {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001018 uint32_t out_data; /* Output will be in_data + 0x01020304 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001019};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001020
1021/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001022#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001023
1024enum ec_current_image {
1025 EC_IMAGE_UNKNOWN = 0,
1026 EC_IMAGE_RO,
1027 EC_IMAGE_RW
1028};
1029
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001030struct __ec_align4 ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001031 /* Null-terminated version strings for RO, RW */
1032 char version_string_ro[32];
1033 char version_string_rw[32];
1034 char reserved[32]; /* Was previously RW-B string */
1035 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001036};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001037
1038/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001039#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001040
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001041struct __ec_align4 ec_params_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001042 uint32_t offset; /* Starting value for read buffer */
1043 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001044};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001045
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001046struct __ec_align4 ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001047 uint32_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001048};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001049
1050/*
1051 * Get build information
1052 *
1053 * Response is null-terminated string.
1054 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001055#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001056
1057/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001058#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001059
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001060struct __ec_align4 ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001061 /* Null-terminated strings */
1062 char vendor[32];
1063 char name[32];
1064 char revision[32]; /* Mask version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001065};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001066
1067/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001068#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001069
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001070struct __ec_align2 ec_response_board_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001071 uint16_t board_version; /* A monotonously incrementing number. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001072};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001073
1074/*
1075 * Read memory-mapped data.
1076 *
1077 * This is an alternate interface to memory-mapped data for bus protocols
1078 * which don't support direct-mapped memory - I2C, SPI, etc.
1079 *
1080 * Response is params.size bytes of data.
1081 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001082#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001083
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001084struct __ec_align1 ec_params_read_memmap {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001085 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
1086 uint8_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001087};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001088
1089/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001090#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001091
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001092struct __ec_align1 ec_params_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001093 uint8_t cmd; /* Command to check */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001094};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001095
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001096struct __ec_align2 ec_params_get_cmd_versions_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001097 uint16_t cmd; /* Command to check */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001098};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001099
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001100struct __ec_align4 ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001101 /*
1102 * Mask of supported versions; use EC_VER_MASK() to compare with a
1103 * desired version.
1104 */
1105 uint32_t version_mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001106};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001107
Duncan Laurie433432b2013-06-03 10:38:22 -07001108/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001109 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001110 * on lpc since it has its own out-of-band busy indicator.
1111 *
1112 * lpc must read the status from the command register. Attempting this on
1113 * lpc will overwrite the args/parameter space and corrupt its data.
1114 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001115#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001116
1117/* Avoid using ec_status which is for return values */
1118enum ec_comms_status {
1119 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
1120};
1121
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001122struct __ec_align4 ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001123 uint32_t flags; /* Mask of enum ec_comms_status */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001124};
Duncan Laurie433432b2013-06-03 10:38:22 -07001125
Duncan Laurie93e24442014-01-06 12:30:52 -08001126/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001127#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001128
1129/* Tell the EC what to send back to us. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001130struct __ec_align4 ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001131 uint32_t ec_result;
1132 uint32_t ret_len;
1133 uint8_t buf[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001134};
Duncan Laurie93e24442014-01-06 12:30:52 -08001135
1136/* Here it comes... */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001137struct __ec_align4 ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001138 uint8_t buf[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001139};
Duncan Laurie93e24442014-01-06 12:30:52 -08001140
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001141/* Get protocol information */
1142#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001143
1144/* Flags for ec_response_get_protocol_info.flags */
1145/* EC_RES_IN_PROGRESS may be returned if a command is slow */
1146#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
1147
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001148struct __ec_align4 ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001149 /* Fields which exist if at least protocol version 3 supported */
1150
1151 /* Bitmask of protocol versions supported (1 << n means version n)*/
1152 uint32_t protocol_versions;
1153
1154 /* Maximum request packet size, in bytes */
1155 uint16_t max_request_packet_size;
1156
1157 /* Maximum response packet size, in bytes */
1158 uint16_t max_response_packet_size;
1159
1160 /* Flags; see EC_PROTOCOL_INFO_* */
1161 uint32_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001162};
Duncan Laurie93e24442014-01-06 12:30:52 -08001163
1164
1165/*****************************************************************************/
1166/* Get/Set miscellaneous values */
1167
1168/* The upper byte of .flags tells what to do (nothing means "get") */
1169#define EC_GSV_SET 0x80000000
1170
1171/* The lower three bytes of .flags identifies the parameter, if that has
1172 meaning for an individual command. */
1173#define EC_GSV_PARAM_MASK 0x00ffffff
1174
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001175struct __ec_align4 ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001176 uint32_t flags;
1177 uint32_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001178};
Duncan Laurie93e24442014-01-06 12:30:52 -08001179
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001180struct __ec_align4 ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001181 uint32_t flags;
1182 uint32_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001183};
Duncan Laurie93e24442014-01-06 12:30:52 -08001184
Duncan Laurieeb316852015-12-01 18:51:18 -08001185/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001186#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001187
Duncan Laurieeb316852015-12-01 18:51:18 -08001188/*****************************************************************************/
1189/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001190#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001191
1192/* Supported features */
1193enum ec_feature_code {
1194 /*
1195 * This image contains a limited set of features. Another image
1196 * in RW partition may support more features.
1197 */
1198 EC_FEATURE_LIMITED = 0,
1199 /*
1200 * Commands for probing/reading/writing/erasing the flash in the
1201 * EC are present.
1202 */
1203 EC_FEATURE_FLASH = 1,
1204 /*
1205 * Can control the fan speed directly.
1206 */
1207 EC_FEATURE_PWM_FAN = 2,
1208 /*
1209 * Can control the intensity of the keyboard backlight.
1210 */
1211 EC_FEATURE_PWM_KEYB = 3,
1212 /*
1213 * Support Google lightbar, introduced on Pixel.
1214 */
1215 EC_FEATURE_LIGHTBAR = 4,
1216 /* Control of LEDs */
1217 EC_FEATURE_LED = 5,
1218 /* Exposes an interface to control gyro and sensors.
1219 * The host goes through the EC to access these sensors.
1220 * In addition, the EC may provide composite sensors, like lid angle.
1221 */
1222 EC_FEATURE_MOTION_SENSE = 6,
1223 /* The keyboard is controlled by the EC */
1224 EC_FEATURE_KEYB = 7,
1225 /* The AP can use part of the EC flash as persistent storage. */
1226 EC_FEATURE_PSTORE = 8,
1227 /* The EC monitors BIOS port 80h, and can return POST codes. */
1228 EC_FEATURE_PORT80 = 9,
1229 /*
1230 * Thermal management: include TMP specific commands.
1231 * Higher level than direct fan control.
1232 */
1233 EC_FEATURE_THERMAL = 10,
1234 /* Can switch the screen backlight on/off */
1235 EC_FEATURE_BKLIGHT_SWITCH = 11,
1236 /* Can switch the wifi module on/off */
1237 EC_FEATURE_WIFI_SWITCH = 12,
1238 /* Monitor host events, through for example SMI or SCI */
1239 EC_FEATURE_HOST_EVENTS = 13,
1240 /* The EC exposes GPIO commands to control/monitor connected devices. */
1241 EC_FEATURE_GPIO = 14,
1242 /* The EC can send i2c messages to downstream devices. */
1243 EC_FEATURE_I2C = 15,
1244 /* Command to control charger are included */
1245 EC_FEATURE_CHARGER = 16,
1246 /* Simple battery support. */
1247 EC_FEATURE_BATTERY = 17,
1248 /*
1249 * Support Smart battery protocol
1250 * (Common Smart Battery System Interface Specification)
1251 */
1252 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001253 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001254 EC_FEATURE_HANG_DETECT = 19,
1255 /* Report power information, for pit only */
1256 EC_FEATURE_PMU = 20,
1257 /* Another Cros EC device is present downstream of this one */
1258 EC_FEATURE_SUB_MCU = 21,
1259 /* Support USB Power delivery (PD) commands */
1260 EC_FEATURE_USB_PD = 22,
1261 /* Control USB multiplexer, for audio through USB port for instance. */
1262 EC_FEATURE_USB_MUX = 23,
1263 /* Motion Sensor code has an internal software FIFO */
1264 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1265 /* Support temporary secure vstore */
1266 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001267 /* EC decides on USB-C SS mux state, muxes configured by host */
1268 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1269 /* EC has RTC feature that can be controlled by host commands */
1270 EC_FEATURE_RTC = 27,
1271 /* The MCU exposes a Fingerprint sensor */
1272 EC_FEATURE_FINGERPRINT = 28,
1273 /* The MCU exposes a Touchpad */
1274 EC_FEATURE_TOUCHPAD = 29,
1275 /* The MCU has RWSIG task enabled */
1276 EC_FEATURE_RWSIG = 30,
1277 /* EC has device events support */
1278 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001279 /* EC supports the unified wake masks for LPC/eSPI systems */
1280 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001281 /* EC supports 64-bit host events */
1282 EC_FEATURE_HOST_EVENT64 = 33,
1283 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1284 EC_FEATURE_EXEC_IN_RAM = 34,
1285 /* EC supports CEC commands */
1286 EC_FEATURE_CEC = 35,
1287 /* EC supports tight sensor timestamping. */
1288 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
Duncan Laurieeb316852015-12-01 18:51:18 -08001289};
1290
1291#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
1292#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001293struct __ec_align4 ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001294 uint32_t flags[2];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001295};
Duncan Laurie433432b2013-06-03 10:38:22 -07001296
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001297/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001298/* Get the board's SKU ID from EC */
1299#define EC_CMD_GET_SKU_ID 0x000E
1300
Kevin Chiue2bb0592017-09-12 09:13:41 +08001301/* Set SKU ID from AP */
1302#define EC_CMD_SET_SKU_ID 0x000F
1303
1304struct __ec_align4 ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001305 uint32_t sku_id;
1306};
1307
1308/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001309/* Flash commands */
1310
1311/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001312#define EC_CMD_FLASH_INFO 0x0010
1313#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001314
Duncan Laurie93e24442014-01-06 12:30:52 -08001315/* Version 0 returns these fields */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001316struct __ec_align4 ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001317 /* Usable flash size, in bytes */
1318 uint32_t flash_size;
1319 /*
1320 * Write block size. Write offset and size must be a multiple
1321 * of this.
1322 */
1323 uint32_t write_block_size;
1324 /*
1325 * Erase block size. Erase offset and size must be a multiple
1326 * of this.
1327 */
1328 uint32_t erase_block_size;
1329 /*
1330 * Protection block size. Protection offset and size must be a
1331 * multiple of this.
1332 */
1333 uint32_t protect_block_size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001334};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001335
Duncan Laurie93e24442014-01-06 12:30:52 -08001336/* Flags for version 1+ flash info command */
1337/* EC flash erases bits to 0 instead of 1 */
1338#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1339
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001340/* Flash must be selected for read/write/erase operations to succeed. This may
1341 * be necessary on a chip where write/erase can be corrupted by other board
1342 * activity, or where the chip needs to enable some sort of programming voltage,
1343 * or where the read/write/erase operations require cleanly suspending other
1344 * chip functionality. */
1345#define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1346
Duncan Laurie93e24442014-01-06 12:30:52 -08001347/*
1348 * Version 1 returns the same initial fields as version 0, with additional
1349 * fields following.
1350 *
1351 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001352 * if they did we'd define the version 0 structure as a sub-structure of this
1353 * one.
1354 *
1355 * Version 2 supports flash banks of different sizes:
1356 * The caller specified the number of banks it has preallocated
1357 * (num_banks_desc)
1358 * The EC returns the number of banks describing the flash memory.
1359 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001360 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001361struct __ec_align4 ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001362 /* Version 0 fields; see above for description */
1363 uint32_t flash_size;
1364 uint32_t write_block_size;
1365 uint32_t erase_block_size;
1366 uint32_t protect_block_size;
1367
1368 /* Version 1 adds these fields: */
1369 /*
1370 * Ideal write size in bytes. Writes will be fastest if size is
1371 * exactly this and offset is a multiple of this. For example, an EC
1372 * may have a write buffer which can do half-page operations if data is
1373 * aligned, and a slower word-at-a-time write mode.
1374 */
1375 uint32_t write_ideal_size;
1376
1377 /* Flags; see EC_FLASH_INFO_* */
1378 uint32_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001379};
1380
1381struct __ec_align4 ec_params_flash_info_2 {
1382 /* Number of banks to describe */
1383 uint16_t num_banks_desc;
1384 /* Reserved; set 0; ignore on read */
1385 uint8_t reserved[2];
1386};
1387
1388struct ec_flash_bank {
1389 /* Number of sector is in this bank. */
1390 uint16_t count;
1391 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1392 uint8_t size_exp;
1393 /* Minimal write size for the sectors in this bank */
1394 uint8_t write_size_exp;
1395 /* Erase size for the sectors in this bank */
1396 uint8_t erase_size_exp;
1397 /* Size for write protection, usually identical to erase size. */
1398 uint8_t protect_size_exp;
1399 /* Reserved; set 0; ignore on read */
1400 uint8_t reserved[2];
1401};
1402
1403struct __ec_align4 ec_response_flash_info_2 {
1404 /* Total flash in the EC. */
1405 uint32_t flash_size;
1406 /* Flags; see EC_FLASH_INFO_* */
1407 uint32_t flags;
1408 /* Maximum size to use to send data to write to the EC. */
1409 uint32_t write_ideal_size;
1410 /* Number of banks present in the EC. */
1411 uint16_t num_banks_total;
1412 /* Number of banks described in banks array. */
1413 uint16_t num_banks_desc;
1414 struct ec_flash_bank banks[0];
1415};
Duncan Laurie93e24442014-01-06 12:30:52 -08001416
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001417/*
1418 * Read flash
1419 *
1420 * Response is params.size bytes of data.
1421 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001422#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001423
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001424struct __ec_align4 ec_params_flash_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001425 uint32_t offset; /* Byte offset to read */
1426 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001427};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001428
1429/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001430#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001431#define EC_VER_FLASH_WRITE 1
1432
1433/* Version 0 of the flash command supported only 64 bytes of data */
1434#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001435
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001436struct __ec_align4 ec_params_flash_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001437 uint32_t offset; /* Byte offset to write */
1438 uint32_t size; /* Size to write in bytes */
Duncan Laurie93e24442014-01-06 12:30:52 -08001439 /* Followed by data to write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001440};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001441
1442/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001443#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001444
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001445/* v0 */
1446struct __ec_align4 ec_params_flash_erase {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001447 uint32_t offset; /* Byte offset to erase */
1448 uint32_t size; /* Size to erase in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001449};
1450
1451
1452#define EC_VER_FLASH_WRITE 1
1453/* v1 add async erase:
1454 * subcommands can returns:
1455 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1456 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1457 * EC_RES_ERROR : other errors.
1458 * EC_RES_BUSY : an existing erase operation is in progress.
1459 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1460 *
1461 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1462 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1463 * the proper result.
1464 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1465 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1466 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1467 * permitted while erasing. (For instance, STM32F4).
1468 */
1469enum ec_flash_erase_cmd {
1470 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1471 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1472 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1473};
1474
1475struct __ec_align4 ec_params_flash_erase_v1 {
1476 /* One of ec_flash_erase_cmd. */
1477 uint8_t cmd;
1478 /* Pad byte; currently always contains 0 */
1479 uint8_t reserved;
1480 /* No flags defined yet; set to 0 */
1481 uint16_t flag;
1482 /* Same as v0 parameters. */
1483 struct ec_params_flash_erase params;
1484};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001485
1486/*
1487 * Get/set flash protection.
1488 *
1489 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1490 * firmware write protect GPIO, not all flags will take effect immediately;
1491 * some flags require a subsequent hard reset to take effect. Check the
1492 * returned flags bits to see what actually happened.
1493 *
1494 * If mask=0, simply returns the current flags state.
1495 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001496#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001497#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1498
1499/* Flags for flash protection */
1500/* RO flash code protected when the EC boots */
1501#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1502/*
1503 * RO flash code protected now. If this bit is set, at-boot status cannot
1504 * be changed.
1505 */
1506#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001507/* Entire flash code protected now, until reboot. */
1508#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001509/* Flash write protect GPIO is asserted now */
1510#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1511/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1512#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1513/*
1514 * Error - flash protection is in inconsistent state. At least one bank of
1515 * flash which should be protected is not protected. Usually fixed by
1516 * re-requesting the desired flags, or by a hard reset if that fails.
1517 */
1518#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001519/* Entire flash code protected when the EC boots */
Duncan Laurie433432b2013-06-03 10:38:22 -07001520#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001521/* RW flash code protected when the EC boots */
1522#define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
1523/* RW flash code protected now. */
1524#define EC_FLASH_PROTECT_RW_NOW (1 << 8)
1525/* Rollback information flash region protected when the EC boots */
1526#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
1527/* Rollback information flash region protected now */
1528#define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001529
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001530struct __ec_align4 ec_params_flash_protect {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001531 uint32_t mask; /* Bits in flags to apply */
1532 uint32_t flags; /* New flags to apply */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001533};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001534
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001535struct __ec_align4 ec_response_flash_protect {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001536 /* Current value of flash protect flags */
1537 uint32_t flags;
1538 /*
1539 * Flags which are valid on this platform. This allows the caller
1540 * to distinguish between flags which aren't set vs. flags which can't
1541 * be set on this platform.
1542 */
1543 uint32_t valid_flags;
1544 /* Flags which can be changed given the current protection state */
1545 uint32_t writable_flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001546};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001547
1548/*
1549 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1550 * write protect. These commands may be reused with version > 0.
1551 */
1552
1553/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001554#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001555#define EC_VER_FLASH_REGION_INFO 1
1556
1557enum ec_flash_region {
1558 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001559 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001560 /*
1561 * Region which holds active RW image. 'Active' is different from
1562 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1563 * scheduled to run, active/non-active applies only to RW images (for
1564 * the same reason 'update' applies only to RW images. It's a state of
1565 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1566 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1567 * doesn't enter 'running' state but it's still active on a flash.
1568 */
1569 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001570 /*
1571 * Region which should be write-protected in the factory (a superset of
1572 * EC_FLASH_REGION_RO)
1573 */
1574 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001575 /* Region which holds updatable (non-active) RW image */
1576 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001577 /* Number of regions */
1578 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001579};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001580/* 'RW' is vague if there are multiple RW images; we mean the active one,
1581 * so the old constant is deprecated */
1582#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001583
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001584struct __ec_align4 ec_params_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001585 uint32_t region; /* enum ec_flash_region */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001586};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001587
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001588struct __ec_align4 ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001589 uint32_t offset;
1590 uint32_t size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001591};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001592
Duncan Laurie433432b2013-06-03 10:38:22 -07001593/* Read/write VbNvContext */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001594#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001595#define EC_VER_VBNV_CONTEXT 1
1596#define EC_VBNV_BLOCK_SIZE 16
1597
1598enum ec_vbnvcontext_op {
1599 EC_VBNV_CONTEXT_OP_READ,
1600 EC_VBNV_CONTEXT_OP_WRITE,
1601};
1602
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001603struct __ec_align4 ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001604 uint32_t op;
1605 uint8_t block[EC_VBNV_BLOCK_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001606};
Duncan Laurie433432b2013-06-03 10:38:22 -07001607
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001608struct __ec_align4 ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001609 uint8_t block[EC_VBNV_BLOCK_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001610};
1611
1612
1613/* Get SPI flash information */
1614#define EC_CMD_FLASH_SPI_INFO 0x0018
1615
1616struct __ec_align1 ec_response_flash_spi_info {
1617 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1618 uint8_t jedec[3];
1619
1620 /* Pad byte; currently always contains 0 */
1621 uint8_t reserved0;
1622
1623 /* Manufacturer / device ID from command 0x90 */
1624 uint8_t mfr_dev_id[2];
1625
1626 /* Status registers from command 0x05 and 0x35 */
1627 uint8_t sr1, sr2;
1628};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001629
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001630
1631/* Select flash during flash operations */
1632#define EC_CMD_FLASH_SELECT 0x0019
1633
1634struct __ec_align4 ec_params_flash_select {
1635 /* 1 to select flash, 0 to deselect flash */
1636 uint8_t select;
1637};
1638
1639
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001640/*****************************************************************************/
1641/* PWM commands */
1642
1643/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001644#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001645
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001646struct __ec_align4 ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001647 uint32_t rpm;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001648};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001649
1650/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001651#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001652
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001653/* Version 0 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001654struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001655 uint32_t rpm;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001656};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001657
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001658/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001659struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001660 uint32_t rpm;
1661 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001662};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001663
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001664/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001665/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001666#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001667
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001668struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001669 uint8_t percent;
1670 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001671};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001672
1673/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001674/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001675#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001676
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001677struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001678 uint8_t percent;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001679};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001680
1681/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001682#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001683
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001684/* Version 0 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001685struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001686 uint32_t percent;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001687};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001688
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001689/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001690struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001691 uint32_t percent;
1692 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001693};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001694
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001695#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07001696/* 16 bit duty cycle, 0xffff = 100% */
1697#define EC_PWM_MAX_DUTY 0xffff
1698
1699enum ec_pwm_type {
1700 /* All types, indexed by board-specific enum pwm_channel */
1701 EC_PWM_TYPE_GENERIC = 0,
1702 /* Keyboard backlight */
1703 EC_PWM_TYPE_KB_LIGHT,
1704 /* Display backlight */
1705 EC_PWM_TYPE_DISPLAY_LIGHT,
1706 EC_PWM_TYPE_COUNT,
1707};
1708
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001709struct __ec_align4 ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001710 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1711 uint8_t pwm_type; /* ec_pwm_type */
1712 uint8_t index; /* Type-specific index, or 0 if unique */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001713};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001714
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001715#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07001716
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001717struct __ec_align1 ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001718 uint8_t pwm_type; /* ec_pwm_type */
1719 uint8_t index; /* Type-specific index, or 0 if unique */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001720};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001721
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001722struct __ec_align2 ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001723 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001724};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001725
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001726/*****************************************************************************/
1727/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001728 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001729 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1730 * into a subcommand. We'll make separate structs for subcommands with
1731 * different input args, so that we know how much to expect.
1732 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001733#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001734
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001735struct __ec_todo_unpacked rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07001736 uint8_t r, g, b;
1737};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001738
Duncan Laurie433432b2013-06-03 10:38:22 -07001739#define LB_BATTERY_LEVELS 4
1740/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1741 * host command, but the alignment is the same regardless. Keep it that way.
1742 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001743struct __ec_todo_packed lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001744 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001745 int32_t google_ramp_up;
1746 int32_t google_ramp_down;
1747 int32_t s3s0_ramp_up;
1748 int32_t s0_tick_delay[2]; /* AC=0/1 */
1749 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1750 int32_t s0s3_ramp_down;
1751 int32_t s3_sleep_for;
1752 int32_t s3_ramp_up;
1753 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001754
1755 /* Oscillation */
1756 uint8_t new_s0;
1757 uint8_t osc_min[2]; /* AC=0/1 */
1758 uint8_t osc_max[2]; /* AC=0/1 */
1759 uint8_t w_ofs[2]; /* AC=0/1 */
1760
1761 /* Brightness limits based on the backlight and AC. */
1762 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1763 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1764 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1765
1766 /* Battery level thresholds */
1767 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1768
1769 /* Map [AC][battery_level] to color index */
1770 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1771 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1772
1773 /* Color palette */
1774 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001775};
Duncan Laurie433432b2013-06-03 10:38:22 -07001776
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001777struct __ec_todo_packed lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001778 /* Timing */
1779 int32_t google_ramp_up;
1780 int32_t google_ramp_down;
1781 int32_t s3s0_ramp_up;
1782 int32_t s0_tick_delay[2]; /* AC=0/1 */
1783 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1784 int32_t s0s3_ramp_down;
1785 int32_t s3_sleep_for;
1786 int32_t s3_ramp_up;
1787 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001788 int32_t s5_ramp_up;
1789 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001790 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001791 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001792 int32_t tap_display_time;
1793
1794 /* Tap-for-battery params */
1795 uint8_t tap_pct_red;
1796 uint8_t tap_pct_green;
1797 uint8_t tap_seg_min_on;
1798 uint8_t tap_seg_max_on;
1799 uint8_t tap_seg_osc;
1800 uint8_t tap_idx[3];
1801
1802 /* Oscillation */
1803 uint8_t osc_min[2]; /* AC=0/1 */
1804 uint8_t osc_max[2]; /* AC=0/1 */
1805 uint8_t w_ofs[2]; /* AC=0/1 */
1806
1807 /* Brightness limits based on the backlight and AC. */
1808 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1809 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1810 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1811
1812 /* Battery level thresholds */
1813 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1814
1815 /* Map [AC][battery_level] to color index */
1816 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1817 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1818
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001819 /* s5: single color pulse on inhibited power-up */
1820 uint8_t s5_idx;
1821
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001822 /* Color palette */
1823 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001824};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001825
Duncan Laurieeb316852015-12-01 18:51:18 -08001826/* Lightbar command params v2
1827 * crbug.com/467716
1828 *
1829 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1830 * logical groups to make it more manageable ( < 120 bytes).
1831 *
1832 * NOTE: Each of these groups must be less than 120 bytes.
1833 */
1834
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001835struct __ec_todo_packed lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08001836 /* Timing */
1837 int32_t google_ramp_up;
1838 int32_t google_ramp_down;
1839 int32_t s3s0_ramp_up;
1840 int32_t s0_tick_delay[2]; /* AC=0/1 */
1841 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1842 int32_t s0s3_ramp_down;
1843 int32_t s3_sleep_for;
1844 int32_t s3_ramp_up;
1845 int32_t s3_ramp_down;
1846 int32_t s5_ramp_up;
1847 int32_t s5_ramp_down;
1848 int32_t tap_tick_delay;
1849 int32_t tap_gate_delay;
1850 int32_t tap_display_time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001851};
Duncan Laurieeb316852015-12-01 18:51:18 -08001852
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001853struct __ec_todo_packed lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08001854 /* Tap-for-battery params */
1855 uint8_t tap_pct_red;
1856 uint8_t tap_pct_green;
1857 uint8_t tap_seg_min_on;
1858 uint8_t tap_seg_max_on;
1859 uint8_t tap_seg_osc;
1860 uint8_t tap_idx[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001861};
Duncan Laurieeb316852015-12-01 18:51:18 -08001862
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001863struct __ec_todo_packed lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08001864 /* Oscillation */
1865 uint8_t osc_min[2]; /* AC=0/1 */
1866 uint8_t osc_max[2]; /* AC=0/1 */
1867 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001868};
Duncan Laurieeb316852015-12-01 18:51:18 -08001869
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001870struct __ec_todo_packed lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08001871 /* Brightness limits based on the backlight and AC. */
1872 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1873 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1874 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001875};
Duncan Laurieeb316852015-12-01 18:51:18 -08001876
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001877struct __ec_todo_packed lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08001878 /* Battery level thresholds */
1879 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001880};
Duncan Laurieeb316852015-12-01 18:51:18 -08001881
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001882struct __ec_todo_packed lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08001883 /* Map [AC][battery_level] to color index */
1884 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1885 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1886
1887 /* s5: single color pulse on inhibited power-up */
1888 uint8_t s5_idx;
1889
1890 /* Color palette */
1891 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001892};
Duncan Laurieeb316852015-12-01 18:51:18 -08001893
Duncan Lauried8401182014-09-29 08:32:19 -07001894/* Lightbyte program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001895#define EC_LB_PROG_LEN 192
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001896struct __ec_todo_unpacked lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07001897 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001898 uint8_t data[EC_LB_PROG_LEN];
Duncan Lauried8401182014-09-29 08:32:19 -07001899};
1900
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001901struct __ec_todo_packed ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07001902 uint8_t cmd; /* Command (see enum lightbar_command) */
1903 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001904 /*
1905 * The following commands have no args:
1906 *
1907 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1908 * version, get_brightness, get_demo, suspend, resume,
1909 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
1910 * get_params_v2_bright, get_params_v2_thlds,
1911 * get_params_v2_colors
1912 *
1913 * Don't use an empty struct, because C++ hates that.
1914 */
Duncan Laurie433432b2013-06-03 10:38:22 -07001915
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001916 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001917 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001918 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001919
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001920 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001921 uint8_t ctrl, reg, value;
1922 } reg;
1923
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001924 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001925 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001926 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07001927
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001928 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001929 uint8_t led;
1930 } get_rgb;
1931
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001932 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001933 uint8_t enable;
1934 } manual_suspend_ctrl;
1935
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001936 struct lightbar_params_v0 set_params_v0;
1937 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08001938
1939 struct lightbar_params_v2_timing set_v2par_timing;
1940 struct lightbar_params_v2_tap set_v2par_tap;
1941 struct lightbar_params_v2_oscillation set_v2par_osc;
1942 struct lightbar_params_v2_brightness set_v2par_bright;
1943 struct lightbar_params_v2_thresholds set_v2par_thlds;
1944 struct lightbar_params_v2_colors set_v2par_colors;
1945
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001946 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001947 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001948};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001949
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001950struct __ec_todo_packed ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07001951 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001952 struct __ec_todo_unpacked {
1953 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001954 uint8_t reg;
1955 uint8_t ic0;
1956 uint8_t ic1;
1957 } vals[23];
1958 } dump;
1959
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001960 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001961 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001962 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001963
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001964 struct lightbar_params_v0 get_params_v0;
1965 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07001966
Duncan Laurieeb316852015-12-01 18:51:18 -08001967
1968 struct lightbar_params_v2_timing get_params_v2_timing;
1969 struct lightbar_params_v2_tap get_params_v2_tap;
1970 struct lightbar_params_v2_oscillation get_params_v2_osc;
1971 struct lightbar_params_v2_brightness get_params_v2_bright;
1972 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1973 struct lightbar_params_v2_colors get_params_v2_colors;
1974
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001975 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08001976 uint32_t num;
1977 uint32_t flags;
1978 } version;
1979
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001980 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001981 uint8_t red, green, blue;
1982 } get_rgb;
1983
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001984 /*
1985 * The following commands have no response:
1986 *
1987 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
1988 * set_params_v0, set_params_v1, set_program,
1989 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
1990 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
1991 * set_v2par_thlds, set_v2par_colors
1992 */
Duncan Laurie433432b2013-06-03 10:38:22 -07001993 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001994};
Duncan Laurie433432b2013-06-03 10:38:22 -07001995
1996/* Lightbar commands */
1997enum lightbar_command {
1998 LIGHTBAR_CMD_DUMP = 0,
1999 LIGHTBAR_CMD_OFF = 1,
2000 LIGHTBAR_CMD_ON = 2,
2001 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002002 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002003 LIGHTBAR_CMD_SEQ = 5,
2004 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002005 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002006 LIGHTBAR_CMD_GET_SEQ = 8,
2007 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002008 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2009 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002010 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002011 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2012 LIGHTBAR_CMD_GET_RGB = 14,
2013 LIGHTBAR_CMD_GET_DEMO = 15,
2014 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2015 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002016 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002017 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2018 LIGHTBAR_CMD_SUSPEND = 20,
2019 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002020 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2021 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2022 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2023 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2024 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2025 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2026 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2027 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2028 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2029 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2030 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2031 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002032 LIGHTBAR_NUM_CMDS
2033};
2034
2035/*****************************************************************************/
2036/* LED control commands */
2037
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002038#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002039
Bill Richardsone221aad2013-06-12 10:50:41 -07002040enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002041 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002042 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002043 /*
2044 * LED to indicate system power state (on or in suspend).
2045 * May be on power button or on C-panel.
2046 */
2047 EC_LED_ID_POWER_LED,
2048 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002049 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002050 /* LED to indicate left side */
2051 EC_LED_ID_LEFT_LED,
2052 /* LED to indicate right side */
2053 EC_LED_ID_RIGHT_LED,
2054 /* LED to indicate recovery mode with HW_REINIT */
2055 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2056 /* LED to indicate sysrq debug mode. */
2057 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002058
2059 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002060};
Duncan Laurie433432b2013-06-03 10:38:22 -07002061
Bill Richardsone221aad2013-06-12 10:50:41 -07002062/* LED control flags */
2063#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
2064#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
2065
2066enum ec_led_colors {
2067 EC_LED_COLOR_RED = 0,
2068 EC_LED_COLOR_GREEN,
2069 EC_LED_COLOR_BLUE,
2070 EC_LED_COLOR_YELLOW,
2071 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002072 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002073
2074 EC_LED_COLOR_COUNT
2075};
2076
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002077struct __ec_align1 ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002078 uint8_t led_id; /* Which LED to control */
2079 uint8_t flags; /* Control flags */
2080
2081 uint8_t brightness[EC_LED_COLOR_COUNT];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002082};
Bill Richardsone221aad2013-06-12 10:50:41 -07002083
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002084struct __ec_align1 ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002085 /*
2086 * Available brightness value range.
2087 *
2088 * Range 0 means color channel not present.
2089 * Range 1 means on/off control.
2090 * Other values means the LED is control by PWM.
2091 */
2092 uint8_t brightness_range[EC_LED_COLOR_COUNT];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002093};
Duncan Laurie433432b2013-06-03 10:38:22 -07002094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002095/*****************************************************************************/
2096/* Verified boot commands */
2097
2098/*
2099 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2100 * reused for other purposes with version > 0.
2101 */
2102
2103/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002104#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002105
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002106struct __ec_align4 ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002107 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2108 uint8_t hash_type; /* enum ec_vboot_hash_type */
2109 uint8_t nonce_size; /* Nonce size; may be 0 */
2110 uint8_t reserved0; /* Reserved; set 0 */
2111 uint32_t offset; /* Offset in flash to hash */
2112 uint32_t size; /* Number of bytes to hash */
2113 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002114};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002115
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002116struct __ec_align4 ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002117 uint8_t status; /* enum ec_vboot_hash_status */
2118 uint8_t hash_type; /* enum ec_vboot_hash_type */
2119 uint8_t digest_size; /* Size of hash digest in bytes */
2120 uint8_t reserved0; /* Ignore; will be 0 */
2121 uint32_t offset; /* Offset in flash which was hashed */
2122 uint32_t size; /* Number of bytes hashed */
2123 uint8_t hash_digest[64]; /* Hash digest data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002124};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002125
2126enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002127 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2128 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2129 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2130 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002131};
2132
2133enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002134 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002135};
2136
2137enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002138 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2139 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2140 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002141};
2142
Duncan Laurie433432b2013-06-03 10:38:22 -07002143/*
2144 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2145 * If one of these is specified, the EC will automatically update offset and
2146 * size to the correct values for the specified image (RO or RW).
2147 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002148#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2149#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2150#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2151
2152/* 'RW' is vague if there are multiple RW images; we mean the active one,
2153 * so the old constant is deprecated */
2154#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002155
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002156/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002157/*
2158 * Motion sense commands. We'll make separate structs for sub-commands with
2159 * different input args, so that we know how much to expect.
2160 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002161#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002162
2163/* Motion sense commands */
2164enum motionsense_command {
2165 /*
2166 * Dump command returns all motion sensor data including motion sense
2167 * module flags and individual sensor flags.
2168 */
2169 MOTIONSENSE_CMD_DUMP = 0,
2170
2171 /*
2172 * Info command returns data describing the details of a given sensor,
2173 * including enum motionsensor_type, enum motionsensor_location, and
2174 * enum motionsensor_chip.
2175 */
2176 MOTIONSENSE_CMD_INFO = 1,
2177
2178 /*
2179 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002180 * in milliseconds.
2181 * It is per sensor, the EC run sample task at the minimum of all
2182 * sensors EC_RATE.
2183 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2184 * to collect all the sensor samples.
2185 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2186 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002187 */
2188 MOTIONSENSE_CMD_EC_RATE = 2,
2189
2190 /*
2191 * Sensor ODR command is a setter/getter command for the output data
2192 * rate of a specific motion sensor in millihertz.
2193 */
2194 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2195
2196 /*
2197 * Sensor range command is a setter/getter command for the range of
2198 * a specified motion sensor in +/-G's or +/- deg/s.
2199 */
2200 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2201
2202 /*
2203 * Setter/getter command for the keyboard wake angle. When the lid
2204 * angle is greater than this value, keyboard wake is disabled in S3,
2205 * and when the lid angle goes less than this value, keyboard wake is
2206 * enabled. Note, the lid angle measurement is an approximate,
2207 * un-calibrated value, hence the wake angle isn't exact.
2208 */
2209 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2210
Duncan Laurieeb316852015-12-01 18:51:18 -08002211 /*
2212 * Returns a single sensor data.
2213 */
2214 MOTIONSENSE_CMD_DATA = 6,
2215
2216 /*
2217 * Return sensor fifo info.
2218 */
2219 MOTIONSENSE_CMD_FIFO_INFO = 7,
2220
2221 /*
2222 * Insert a flush element in the fifo and return sensor fifo info.
2223 * The host can use that element to synchronize its operation.
2224 */
2225 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2226
2227 /*
2228 * Return a portion of the fifo.
2229 */
2230 MOTIONSENSE_CMD_FIFO_READ = 9,
2231
2232 /*
2233 * Perform low level calibration.
2234 * On sensors that support it, ask to do offset calibration.
2235 */
2236 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2237
2238 /*
2239 * Sensor Offset command is a setter/getter command for the offset
2240 * used for calibration.
2241 * The offsets can be calculated by the host, or via
2242 * PERFORM_CALIB command.
2243 */
2244 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2245
2246 /*
2247 * List available activities for a MOTION sensor.
2248 * Indicates if they are enabled or disabled.
2249 */
2250 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2251
2252 /*
2253 * Activity management
2254 * Enable/Disable activity recognition.
2255 */
2256 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2257
2258 /*
2259 * Lid Angle
2260 */
2261 MOTIONSENSE_CMD_LID_ANGLE = 14,
2262
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002263 /*
2264 * Allow the FIFO to trigger interrupt via MKBP events.
2265 * By default the FIFO does not send interrupt to process the FIFO
2266 * until the AP is ready or it is coming from a wakeup sensor.
2267 */
2268 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2269
2270 /*
2271 * Spoof the readings of the sensors. The spoofed readings can be set
2272 * to arbitrary values, or will lock to the last read actual values.
2273 */
2274 MOTIONSENSE_CMD_SPOOF = 16,
2275
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002276 /* Number of motionsense sub-commands. */
2277 MOTIONSENSE_NUM_CMDS
2278};
2279
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002280/* List of motion sensor types. */
2281enum motionsensor_type {
2282 MOTIONSENSE_TYPE_ACCEL = 0,
2283 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002284 MOTIONSENSE_TYPE_MAG = 2,
2285 MOTIONSENSE_TYPE_PROX = 3,
2286 MOTIONSENSE_TYPE_LIGHT = 4,
2287 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002288 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002289 MOTIONSENSE_TYPE_SYNC = 7,
Duncan Laurieeb316852015-12-01 18:51:18 -08002290 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002291};
2292
2293/* List of motion sensor locations. */
2294enum motionsensor_location {
2295 MOTIONSENSE_LOC_BASE = 0,
2296 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002297 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002298 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002299};
2300
2301/* List of motion sensor chips. */
2302enum motionsensor_chip {
2303 MOTIONSENSE_CHIP_KXCJ9 = 0,
2304 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002305 MOTIONSENSE_CHIP_BMI160 = 2,
2306 MOTIONSENSE_CHIP_SI1141 = 3,
2307 MOTIONSENSE_CHIP_SI1142 = 4,
2308 MOTIONSENSE_CHIP_SI1143 = 5,
2309 MOTIONSENSE_CHIP_KX022 = 6,
2310 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002311 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002312 MOTIONSENSE_CHIP_BMP280 = 9,
2313 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002314 MOTIONSENSE_CHIP_BH1730 = 11,
2315 MOTIONSENSE_CHIP_GPIO = 12,
2316 MOTIONSENSE_CHIP_LIS2DH = 13,
2317 MOTIONSENSE_CHIP_LSM6DSM = 14,
2318 MOTIONSENSE_CHIP_LIS2DE = 15,
2319 MOTIONSENSE_CHIP_MAX,
2320};
2321
2322/* List of orientation positions */
2323enum motionsensor_orientation {
2324 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2325 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2326 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2327 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2328 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002329};
2330
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002331struct __ec_todo_packed ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002332 /* Flags for each sensor. */
2333 uint8_t flags;
2334 /* sensor number the data comes from */
2335 uint8_t sensor_num;
2336 /* Each sensor is up to 3-axis. */
2337 union {
2338 int16_t data[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002339 struct __ec_todo_packed {
2340 uint16_t reserved;
Duncan Laurieeb316852015-12-01 18:51:18 -08002341 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002342 };
2343 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002344 uint8_t activity; /* motionsensor_activity */
2345 uint8_t state;
2346 int16_t add_info[2];
2347 };
2348 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002349};
Duncan Laurieeb316852015-12-01 18:51:18 -08002350
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002351/* Note: used in ec_response_get_next_data */
2352struct __ec_todo_packed ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002353 /* Size of the fifo */
2354 uint16_t size;
2355 /* Amount of space used in the fifo */
2356 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002357 /* Timestamp recorded in us.
2358 * aka accurate timestamp when host event was triggered.
2359 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002360 uint32_t timestamp;
2361 /* Total amount of vector lost */
2362 uint16_t total_lost;
2363 /* Lost events since the last fifo_info, per sensors */
2364 uint16_t lost[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002365};
Duncan Laurieeb316852015-12-01 18:51:18 -08002366
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002367struct __ec_todo_packed ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002368 uint32_t number_data;
2369 struct ec_response_motion_sensor_data data[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002370};
Duncan Laurieeb316852015-12-01 18:51:18 -08002371
2372/* List supported activity recognition */
2373enum motionsensor_activity {
2374 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2375 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2376 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002377 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Duncan Laurieeb316852015-12-01 18:51:18 -08002378};
2379
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002380struct __ec_todo_unpacked ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002381 uint8_t sensor_num;
2382 uint8_t activity; /* one of enum motionsensor_activity */
2383 uint8_t enable; /* 1: enable, 0: disable */
2384 uint8_t reserved;
2385 uint16_t parameters[3]; /* activity dependent parameters */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002386};
2387
2388/* Module flag masks used for the dump sub-command. */
2389#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2390
2391/* Sensor flag masks used for the dump sub-command. */
2392#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2393
2394/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002395 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002396 * data contains time stamp
2397 */
2398#define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2399#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2400#define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002401#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
Duncan Laurieeb316852015-12-01 18:51:18 -08002402
2403/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002404 * Send this value for the data element to only perform a read. If you
2405 * send any other value, the EC will interpret it as data to set and will
2406 * return the actual value set.
2407 */
2408#define EC_MOTION_SENSE_NO_VALUE -1
2409
Duncan Laurieeb316852015-12-01 18:51:18 -08002410#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2411
2412/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2413/* Set Calibration information */
2414#define MOTION_SENSE_SET_OFFSET 1
2415
2416#define LID_ANGLE_UNRELIABLE 500
2417
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002418enum motionsense_spoof_mode {
2419 /* Disable spoof mode. */
2420 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2421
2422 /* Enable spoof mode, but use provided component values. */
2423 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2424
2425 /* Enable spoof mode, but use the current sensor values. */
2426 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2427
2428 /* Query the current spoof mode status for the sensor. */
2429 MOTIONSENSE_SPOOF_MODE_QUERY,
2430};
2431
2432struct __ec_todo_packed ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002433 uint8_t cmd;
2434 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002435 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002436 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002437 /*
2438 * Maximal number of sensor the host is expecting.
2439 * 0 means the host is only interested in the number
2440 * of sensors controlled by the EC.
2441 */
2442 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002443 } dump;
2444
2445 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002446 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002447 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002448 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002449 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2450 * kb_wake_angle: angle to wakup AP.
2451 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002452 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002453 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002454
Duncan Laurieeb316852015-12-01 18:51:18 -08002455 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2456 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002457 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002458 uint8_t sensor_num;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002459 } info, info_3, data, fifo_flush, perform_calib,
2460 list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002461
2462 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002463 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2464 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002465 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002466 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002467 uint8_t sensor_num;
2468
2469 /* Rounding flag, true for round-up, false for down. */
2470 uint8_t roundup;
2471
2472 uint16_t reserved;
2473
2474 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2475 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002476 } ec_rate, sensor_odr, sensor_range;
2477
2478 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002479 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002480 uint8_t sensor_num;
2481
2482 /*
2483 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2484 * the calibration information in the EC.
2485 * If unset, just retrieve calibration information.
2486 */
2487 uint16_t flags;
2488
2489 /*
2490 * Temperature at calibration, in units of 0.01 C
2491 * 0x8000: invalid / unknown.
2492 * 0x0: 0C
2493 * 0x7fff: +327.67C
2494 */
2495 int16_t temp;
2496
2497 /*
2498 * Offset for calibration.
2499 * Unit:
2500 * Accelerometer: 1/1024 g
2501 * Gyro: 1/1024 deg/s
2502 * Compass: 1/16 uT
2503 */
2504 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002505 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002506
2507 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002508 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002509
2510 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002511 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002512 /*
2513 * Number of expected vector to return.
2514 * EC may return less or 0 if none available.
2515 */
2516 uint32_t max_data_vector;
2517 } fifo_read;
2518
2519 struct ec_motion_sense_activity set_activity;
2520
2521 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002522 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002523
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002524 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2525 struct __ec_todo_unpacked {
2526 /*
2527 * 1: enable, 0 disable fifo,
2528 * EC_MOTION_SENSE_NO_VALUE return value.
2529 */
2530 int8_t enable;
2531 } fifo_int_enable;
2532
2533 /* Used for MOTIONSENSE_CMD_SPOOF */
2534 struct __ec_todo_packed {
2535 uint8_t sensor_id;
2536
2537 /* See enum motionsense_spoof_mode. */
2538 uint8_t spoof_enable;
2539
2540 /* Ignored, used for alignment. */
2541 uint8_t reserved;
2542
2543 /* Individual component values to spoof. */
2544 int16_t components[3];
2545 } spoof;
2546 };
2547};
2548
2549struct __ec_todo_packed ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002550 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002551 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002552 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002553 /* Flags representing the motion sensor module. */
2554 uint8_t module_flags;
2555
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002556 /* Number of sensors managed directly by the EC */
2557 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002558
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002559 /*
2560 * sensor data is truncated if response_max is too small
2561 * for holding all the data.
2562 */
2563 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002564 } dump;
2565
2566 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002567 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002568 /* Should be element of enum motionsensor_type. */
2569 uint8_t type;
2570
2571 /* Should be element of enum motionsensor_location. */
2572 uint8_t location;
2573
2574 /* Should be element of enum motionsensor_chip. */
2575 uint8_t chip;
2576 } info;
2577
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002578 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2579 struct __ec_todo_unpacked {
2580 /* Should be element of enum motionsensor_type. */
2581 uint8_t type;
2582
2583 /* Should be element of enum motionsensor_location. */
2584 uint8_t location;
2585
2586 /* Should be element of enum motionsensor_chip. */
2587 uint8_t chip;
2588
2589 /* Minimum sensor sampling frequency */
2590 uint32_t min_frequency;
2591
2592 /* Maximum sensor sampling frequency */
2593 uint32_t max_frequency;
2594
2595 /* Max number of sensor events that could be in fifo */
2596 uint32_t fifo_max_event_count;
2597 } info_3;
2598
Duncan Laurieeb316852015-12-01 18:51:18 -08002599 /* Used for MOTIONSENSE_CMD_DATA */
2600 struct ec_response_motion_sensor_data data;
2601
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002602 /*
2603 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002604 * MOTIONSENSE_CMD_SENSOR_RANGE,
2605 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2606 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2607 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002608 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002609 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002610 /* Current value of the parameter queried. */
2611 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002612 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2613 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08002614
2615 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002616 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002617 int16_t temp;
2618 int16_t offset[3];
2619 } sensor_offset, perform_calib;
2620
2621 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2622
2623 struct ec_response_motion_sense_fifo_data fifo_read;
2624
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002625 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002626 uint16_t reserved;
2627 uint32_t enabled;
2628 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002629 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08002630
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002631 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08002632
Duncan Laurieeb316852015-12-01 18:51:18 -08002633 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002634 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002635 /*
2636 * Angle between 0 and 360 degree if available,
2637 * LID_ANGLE_UNRELIABLE otherwise.
2638 */
2639 uint16_t value;
2640 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002641 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002642};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002643
2644/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002645/* Force lid open command */
2646
2647/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002648#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002649
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002650struct __ec_align1 ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002651 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002652};
2653
2654/*****************************************************************************/
2655/* Configure the behavior of the power button */
2656#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2657
2658enum ec_config_power_button_flags {
2659 /* Enable/Disable power button pulses for x86 devices */
2660 EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2661};
2662
2663struct __ec_align1 ec_params_config_power_button {
2664 /* See enum ec_config_power_button_flags */
2665 uint8_t flags;
2666};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002667
2668/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002669/* USB charging control commands */
2670
2671/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002672#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002673
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002674struct __ec_align1 ec_params_usb_charge_set_mode {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002675 uint8_t usb_port_id;
2676 uint8_t mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002677};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002678
2679/*****************************************************************************/
2680/* Persistent storage for host */
2681
2682/* Maximum bytes that can be read/written in a single command */
2683#define EC_PSTORE_SIZE_MAX 64
2684
2685/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002686#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002687
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002688struct __ec_align4 ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002689 /* Persistent storage size, in bytes */
2690 uint32_t pstore_size;
2691 /* Access size; read/write offset and size must be a multiple of this */
2692 uint32_t access_size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002693};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002694
2695/*
2696 * Read persistent storage
2697 *
2698 * Response is params.size bytes of data.
2699 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002700#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002701
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002702struct __ec_align4 ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002703 uint32_t offset; /* Byte offset to read */
2704 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002705};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002706
2707/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002708#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002709
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002710struct __ec_align4 ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002711 uint32_t offset; /* Byte offset to write */
2712 uint32_t size; /* Size to write in bytes */
2713 uint8_t data[EC_PSTORE_SIZE_MAX];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002714};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002715
2716/*****************************************************************************/
2717/* Real-time clock */
2718
2719/* RTC params and response structures */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002720struct __ec_align4 ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002721 uint32_t time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002722};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002723
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002724struct __ec_align4 ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002725 uint32_t time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002726};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002727
2728/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002729#define EC_CMD_RTC_GET_VALUE 0x0044
2730#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002731
2732/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002733#define EC_CMD_RTC_SET_VALUE 0x0046
2734#define EC_CMD_RTC_SET_ALARM 0x0047
2735
2736/* Pass as time param to SET_ALARM to clear the current alarm */
2737#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002738
2739/*****************************************************************************/
2740/* Port80 log access */
2741
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002742/* Maximum entries that can be read/written in a single command */
2743#define EC_PORT80_SIZE_MAX 32
2744
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002745/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002746#define EC_CMD_PORT80_LAST_BOOT 0x0048
2747#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002748
2749enum ec_port80_subcmd {
2750 EC_PORT80_GET_INFO = 0,
2751 EC_PORT80_READ_BUFFER,
2752};
2753
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002754struct __ec_todo_packed ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002755 uint16_t subcmd;
2756 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002757 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002758 uint32_t offset;
2759 uint32_t num_entries;
2760 } read_buffer;
2761 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002762};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002763
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002764struct __ec_todo_packed ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002765 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002766 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002767 uint32_t writes;
2768 uint32_t history_size;
2769 uint32_t last_boot;
2770 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002771 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002772 uint16_t codes[EC_PORT80_SIZE_MAX];
2773 } data;
2774 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002775};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002776
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002777struct __ec_align2 ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002778 uint16_t code;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002779};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002780
2781/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08002782/* Temporary secure storage for host verified boot use */
2783
2784/* Number of bytes in a vstore slot */
2785#define EC_VSTORE_SLOT_SIZE 64
2786
2787/* Maximum number of vstore slots */
2788#define EC_VSTORE_SLOT_MAX 32
2789
2790/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002791#define EC_CMD_VSTORE_INFO 0x0049
2792struct __ec_align_size1 ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002793 /* Indicates which slots are locked */
2794 uint32_t slot_locked;
2795 /* Total number of slots available */
2796 uint8_t slot_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002797};
Duncan Laurieeb316852015-12-01 18:51:18 -08002798
2799/*
2800 * Read temporary secure storage
2801 *
2802 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2803 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002804#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08002805
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002806struct __ec_align1 ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08002807 uint8_t slot; /* Slot to read from */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002808};
Duncan Laurieeb316852015-12-01 18:51:18 -08002809
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002810struct __ec_align1 ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08002811 uint8_t data[EC_VSTORE_SLOT_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002812};
Duncan Laurieeb316852015-12-01 18:51:18 -08002813
2814/*
2815 * Write temporary secure storage and lock it.
2816 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002817#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08002818
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002819struct __ec_align1 ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08002820 uint8_t slot; /* Slot to write to */
2821 uint8_t data[EC_VSTORE_SLOT_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002822};
Duncan Laurieeb316852015-12-01 18:51:18 -08002823
2824/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08002825/* Thermal engine commands. Note that there are two implementations. We'll
2826 * reuse the command number, but the data and behavior is incompatible.
2827 * Version 0 is what originally shipped on Link.
2828 * Version 1 separates the CPU thermal limits from the fan control.
2829 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002830
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002831#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2832#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002833
Duncan Laurie93e24442014-01-06 12:30:52 -08002834/* The version 0 structs are opaque. You have to know what they are for
2835 * the get/set commands to make any sense.
2836 */
2837
2838/* Version 0 - set */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002839struct __ec_align2 ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002840 uint8_t sensor_type;
2841 uint8_t threshold_id;
2842 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002843};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002844
Duncan Laurie93e24442014-01-06 12:30:52 -08002845/* Version 0 - get */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002846struct __ec_align1 ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002847 uint8_t sensor_type;
2848 uint8_t threshold_id;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002849};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002850
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002851struct __ec_align2 ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002852 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002853};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002854
Duncan Laurie93e24442014-01-06 12:30:52 -08002855
2856/* The version 1 structs are visible. */
2857enum ec_temp_thresholds {
2858 EC_TEMP_THRESH_WARN = 0,
2859 EC_TEMP_THRESH_HIGH,
2860 EC_TEMP_THRESH_HALT,
2861
2862 EC_TEMP_THRESH_COUNT
2863};
2864
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002865/*
2866 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08002867 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002868 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002869 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
2870 * hysteresis.
2871 * For example,
2872 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
2873 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
2874 * EC will throttle ap when temperature >= 301 K, and release throttling when
2875 * temperature <= 299 K.
2876 *
2877 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
2878 * For example,
2879 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
2880 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
2881 * EC will throttle ap when temperature >= 301 K, and release throttling when
2882 * temperature <= 294 K.
2883 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002884 * Note that this structure is a sub-structure of
2885 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08002886 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002887struct __ec_align4 ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08002888 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002889 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08002890 uint32_t temp_fan_off; /* no active cooling needed */
2891 uint32_t temp_fan_max; /* max active cooling needed */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002892};
Duncan Laurie93e24442014-01-06 12:30:52 -08002893
2894/* Version 1 - get config for one sensor. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002895struct __ec_align4 ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08002896 uint32_t sensor_num;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002897};
Duncan Laurie93e24442014-01-06 12:30:52 -08002898/* This returns a struct ec_thermal_config */
2899
2900/* Version 1 - set config for one sensor.
2901 * Use read-modify-write for best results! */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002902struct __ec_align4 ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08002903 uint32_t sensor_num;
2904 struct ec_thermal_config cfg;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002905};
Duncan Laurie93e24442014-01-06 12:30:52 -08002906/* This returns no data */
2907
2908/****************************************************************************/
2909
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002910/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002911#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002912
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002913/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002914struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002915 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002916};
Duncan Laurie433432b2013-06-03 10:38:22 -07002917
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002918/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002919#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2920#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002921
2922/*
2923 * The original TMP006 calibration only needed four params, but now we need
2924 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2925 * the params opaque. The v1 "get" response will include the algorithm number
2926 * and how many params it requires. That way we can change the EC code without
2927 * needing to update this file. We can also use a different algorithm on each
2928 * sensor.
2929 */
2930
2931/* This is the same struct for both v0 and v1. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002932struct __ec_align1 ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07002933 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002934};
Duncan Laurie433432b2013-06-03 10:38:22 -07002935
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002936/* Version 0 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002937struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002938 float s0;
2939 float b0;
2940 float b1;
2941 float b2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002942};
Duncan Laurie433432b2013-06-03 10:38:22 -07002943
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002944struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002945 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002946 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07002947 float s0;
2948 float b0;
2949 float b1;
2950 float b2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002951};
Duncan Laurie433432b2013-06-03 10:38:22 -07002952
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002953/* Version 1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002954struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002955 uint8_t algorithm;
2956 uint8_t num_params;
2957 uint8_t reserved[2];
2958 float val[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002959};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002960
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002961struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002962 uint8_t index;
2963 uint8_t algorithm;
2964 uint8_t num_params;
2965 uint8_t reserved;
2966 float val[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002967};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002968
2969
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002970/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002971#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002972
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002973struct __ec_align1 ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002974 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002975};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002976
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002977struct __ec_align4 ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002978 int32_t t; /* In 1/100 K */
2979 int32_t v; /* In nV */
2980};
2981
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002982/*****************************************************************************/
2983/* MKBP - Matrix KeyBoard Protocol */
2984
2985/*
2986 * Read key state
2987 *
2988 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2989 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002990 *
2991 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2992 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2993 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002994 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002995#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002996
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002997/*
2998 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2999 */
3000#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003001
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003002struct __ec_align_size1 ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003003 uint32_t rows;
3004 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003005 /* Formerly "switches", which was 0. */
3006 uint8_t reserved;
3007};
3008
3009struct __ec_align1 ec_params_mkbp_info {
3010 uint8_t info_type;
3011 uint8_t event_type;
3012};
3013
3014enum ec_mkbp_info_type {
3015 /*
3016 * Info about the keyboard matrix: number of rows and columns.
3017 *
3018 * Returns struct ec_response_mkbp_info.
3019 */
3020 EC_MKBP_INFO_KBD = 0,
3021
3022 /*
3023 * For buttons and switches, info about which specifically are
3024 * supported. event_type must be set to one of the values in enum
3025 * ec_mkbp_event.
3026 *
3027 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3028 * bitmask indicating which buttons or switches are present. See the
3029 * bit inidices below.
3030 */
3031 EC_MKBP_INFO_SUPPORTED = 1,
3032
3033 /*
3034 * Instantaneous state of buttons and switches.
3035 *
3036 * event_type must be set to one of the values in enum ec_mkbp_event.
3037 *
3038 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3039 * indicating the current state of the keyboard matrix.
3040 *
3041 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3042 * event state.
3043 *
3044 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3045 * state of supported buttons.
3046 *
3047 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3048 * state of supported switches.
3049 */
3050 EC_MKBP_INFO_CURRENT = 2,
3051};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003052
3053/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003054#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003055
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003056struct __ec_align1 ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003057 uint8_t col;
3058 uint8_t row;
3059 uint8_t pressed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003060};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003061
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003062#define EC_CMD_GET_KEYBOARD_ID 0x0063
3063
3064struct __ec_align4 ec_response_keyboard_id {
3065 uint32_t keyboard_id;
3066};
3067
3068enum keyboard_id {
3069 KEYBOARD_ID_UNSUPPORTED = 0,
3070 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3071};
3072
Duncan Laurie433432b2013-06-03 10:38:22 -07003073/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003074#define EC_CMD_MKBP_SET_CONFIG 0x0064
3075#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003076
3077/* flags */
3078enum mkbp_config_flags {
3079 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3080};
3081
3082enum mkbp_config_valid {
3083 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
3084 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
3085 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
3086 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
3087 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
3088 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
3089 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
3090};
3091
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003092/*
3093 * Configuration for our key scanning algorithm.
3094 *
3095 * Note that this is used as a sub-structure of
3096 * ec_{params/response}_mkbp_get_config.
3097 */
3098struct __ec_align_size1 ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003099 uint32_t valid_mask; /* valid fields */
3100 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3101 uint8_t valid_flags; /* which flags are valid */
3102 uint16_t scan_period_us; /* period between start of scans */
3103 /* revert to interrupt mode after no activity for this long */
3104 uint32_t poll_timeout_us;
3105 /*
3106 * minimum post-scan relax time. Once we finish a scan we check
3107 * the time until we are due to start the next one. If this time is
3108 * shorter this field, we use this instead.
3109 */
3110 uint16_t min_post_scan_delay_us;
3111 /* delay between setting up output and waiting for it to settle */
3112 uint16_t output_settle_us;
3113 uint16_t debounce_down_us; /* time for debounce on key down */
3114 uint16_t debounce_up_us; /* time for debounce on key up */
3115 /* maximum depth to allow for fifo (0 = no keyscan output) */
3116 uint8_t fifo_max_depth;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003117};
Duncan Laurie433432b2013-06-03 10:38:22 -07003118
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003119struct __ec_align_size1 ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003120 struct ec_mkbp_config config;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003121};
Duncan Laurie433432b2013-06-03 10:38:22 -07003122
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003123struct __ec_align_size1 ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003124 struct ec_mkbp_config config;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003125};
Duncan Laurie433432b2013-06-03 10:38:22 -07003126
3127/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003128#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003129
3130enum ec_keyscan_seq_cmd {
3131 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3132 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3133 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3134 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3135 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3136};
3137
3138enum ec_collect_flags {
3139 /*
3140 * Indicates this scan was processed by the EC. Due to timing, some
3141 * scans may be skipped.
3142 */
3143 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
3144};
3145
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003146struct __ec_align1 ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003147 uint8_t flags; /* some flags (enum ec_collect_flags) */
3148};
3149
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003150struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003151 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3152 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003153 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003154 uint8_t active; /* still active */
3155 uint8_t num_items; /* number of items */
3156 /* Current item being presented */
3157 uint8_t cur_item;
3158 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003159 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003160 /*
3161 * Absolute time for this scan, measured from the
3162 * start of the sequence.
3163 */
3164 uint32_t time_us;
3165 uint8_t scan[0]; /* keyscan data */
3166 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003167 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003168 uint8_t start_item; /* First item to return */
3169 uint8_t num_items; /* Number of items to return */
3170 } collect;
3171 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003172};
Duncan Laurie433432b2013-06-03 10:38:22 -07003173
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003174struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003175 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003176 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003177 uint8_t num_items; /* Number of items */
3178 /* Data for each item */
3179 struct ec_collect_item item[0];
3180 } collect;
3181 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003182};
Duncan Laurie433432b2013-06-03 10:38:22 -07003183
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003184/*
3185 * Get the next pending MKBP event.
3186 *
3187 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3188 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003189#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003190
3191enum ec_mkbp_event {
3192 /* Keyboard matrix changed. The event data is the new matrix state. */
3193 EC_MKBP_EVENT_KEY_MATRIX = 0,
3194
3195 /* New host event. The event data is 4 bytes of host event flags. */
3196 EC_MKBP_EVENT_HOST_EVENT = 1,
3197
Duncan Laurieeb316852015-12-01 18:51:18 -08003198 /* New Sensor FIFO data. The event data is fifo_info structure. */
3199 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3200
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003201 /* The state of the non-matrixed buttons have changed. */
3202 EC_MKBP_EVENT_BUTTON = 3,
3203
3204 /* The state of the switches have changed. */
3205 EC_MKBP_EVENT_SWITCH = 4,
3206
3207 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3208 EC_MKBP_EVENT_FINGERPRINT = 5,
3209
3210 /*
3211 * Sysrq event: send emulated sysrq. The event data is sysrq,
3212 * corresponding to the key to be pressed.
3213 */
3214 EC_MKBP_EVENT_SYSRQ = 6,
3215
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003216 /*
3217 * New 64-bit host event.
3218 * The event data is 8 bytes of host event flags.
3219 */
3220 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3221
3222 /* Notify the AP that something happened on CEC */
3223 EC_MKBP_EVENT_CEC_EVENT = 8,
3224
3225 /* Send an incoming CEC message to the AP */
3226 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3227
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003228 /* Number of MKBP events */
3229 EC_MKBP_EVENT_COUNT,
3230};
3231
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003232union __ec_align_offset1 ec_response_get_next_data {
3233 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003234
3235 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003236 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003237 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003238
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003239 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003240 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003241 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003242 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003243 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003244
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003245 uint32_t buttons;
3246
3247 uint32_t switches;
3248
3249 uint32_t fp_events;
3250
3251 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003252
3253 /* CEC events from enum mkbp_cec_event */
3254 uint32_t cec_events;
3255};
3256
3257union __ec_align_offset1 ec_response_get_next_data_v1 {
3258 uint8_t key_matrix[16];
3259
3260 /* Unaligned */
3261 uint32_t host_event;
3262 uint64_t host_event64;
3263
3264 struct __ec_todo_unpacked {
3265 /* For aligning the fifo_info */
3266 uint8_t reserved[3];
3267 struct ec_response_motion_sense_fifo_info info;
3268 } sensor_fifo;
3269
3270 uint32_t buttons;
3271
3272 uint32_t switches;
3273
3274 uint32_t fp_events;
3275
3276 uint32_t sysrq;
3277
3278 /* CEC events from enum mkbp_cec_event */
3279 uint32_t cec_events;
3280
3281 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003282};
3283
3284struct __ec_align1 ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003285 uint8_t event_type;
3286 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003287 union ec_response_get_next_data data;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003288};
3289
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003290struct __ec_align1 ec_response_get_next_event_v1 {
3291 uint8_t event_type;
3292 /* Followed by event data if any */
3293 union ec_response_get_next_data_v1 data;
3294};
3295
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003296/* Bit indices for buttons and switches.*/
3297/* Buttons */
3298#define EC_MKBP_POWER_BUTTON 0
3299#define EC_MKBP_VOL_UP 1
3300#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003301#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003302
3303/* Switches */
3304#define EC_MKBP_LID_OPEN 0
3305#define EC_MKBP_TABLET_MODE 1
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003306
Gwendal Grignou880b4582016-06-20 08:49:25 -07003307/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003308#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003309
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003310struct __ec_align2 ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003311 uint16_t shorted; /* Keyboard pins are shorted */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003312};
3313
3314/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3315#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003316#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3317#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3318#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3319 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3320#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3321#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3322#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3323 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
3324#define EC_MKBP_FP_ENROLL (1 << 27)
3325#define EC_MKBP_FP_MATCH (1 << 28)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003326#define EC_MKBP_FP_FINGER_DOWN (1 << 29)
3327#define EC_MKBP_FP_FINGER_UP (1 << 30)
3328#define EC_MKBP_FP_IMAGE_READY (1 << 31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003329/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3330#define EC_MKBP_FP_ERR_ENROLL_OK 0
3331#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3332#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3333#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3334#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3335/* Can be used to detect if image was usable for enrollment or not. */
3336#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3337/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3338#define EC_MKBP_FP_ERR_MATCH_NO 0
3339#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
3340#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3341#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3342#define EC_MKBP_FP_ERR_MATCH_YES 1
3343#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3344#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3345
Gwendal Grignou880b4582016-06-20 08:49:25 -07003346
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003347/*****************************************************************************/
3348/* Temperature sensor commands */
3349
3350/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003351#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003352
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003353struct __ec_align1 ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003354 uint8_t id;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003355};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003356
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003357struct __ec_align1 ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003358 char sensor_name[32];
3359 uint8_t sensor_type;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003360};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003361
3362/*****************************************************************************/
3363
3364/*
3365 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3366 * commands accidentally sent to the wrong interface. See the ACPI section
3367 * below.
3368 */
3369
3370/*****************************************************************************/
3371/* Host event commands */
3372
Jenny TC1dfc2c32017-12-14 14:24:39 +05303373
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003374/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003375/*
3376 * Host event mask params and response structures, shared by all of the host
3377 * event commands below.
3378 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003379struct __ec_align4 ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003380 uint32_t mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003381};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003382
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003383struct __ec_align4 ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003384 uint32_t mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003385};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003386
3387/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003388#define EC_CMD_HOST_EVENT_GET_B 0x0087
3389#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3390#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3391#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003392
3393/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003394#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3395#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3396#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3397#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3398#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003399
Jenny TC1dfc2c32017-12-14 14:24:39 +05303400/*
3401 * Unified host event programming interface - Should be used by newer versions
3402 * of BIOS/OS to program host events and masks
3403 */
3404
3405struct __ec_align4 ec_params_host_event {
3406
3407 /* Action requested by host - one of enum ec_host_event_action. */
3408 uint8_t action;
3409
3410 /*
3411 * Mask type that the host requested the action on - one of
3412 * enum ec_host_event_mask_type.
3413 */
3414 uint8_t mask_type;
3415
3416 /* Set to 0, ignore on read */
3417 uint16_t reserved;
3418
3419 /* Value to be used in case of set operations. */
3420 uint64_t value;
3421};
3422
3423/*
3424 * Response structure returned by EC_CMD_HOST_EVENT.
3425 * Update the value on a GET request. Set to 0 on GET/CLEAR
3426 */
3427
3428struct __ec_align4 ec_response_host_event {
3429
3430 /* Mask value in case of get operation */
3431 uint64_t value;
3432};
3433
3434enum ec_host_event_action {
3435 /*
3436 * params.value is ignored. Value of mask_type populated
3437 * in response.value
3438 */
3439 EC_HOST_EVENT_GET,
3440
3441 /* Bits in params.value are set */
3442 EC_HOST_EVENT_SET,
3443
3444 /* Bits in params.value are cleared */
3445 EC_HOST_EVENT_CLEAR,
3446};
3447
3448enum ec_host_event_mask_type {
3449
3450 /* Main host event copy */
3451 EC_HOST_EVENT_MAIN,
3452
3453 /* Copy B of host events */
3454 EC_HOST_EVENT_B,
3455
3456 /* SCI Mask */
3457 EC_HOST_EVENT_SCI_MASK,
3458
3459 /* SMI Mask */
3460 EC_HOST_EVENT_SMI_MASK,
3461
3462 /* Mask of events that should be always reported in hostevents */
3463 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3464
3465 /* Active wake mask */
3466 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3467
3468 /* Lazy wake mask for S0ix */
3469 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3470
3471 /* Lazy wake mask for S3 */
3472 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3473
3474 /* Lazy wake mask for S5 */
3475 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3476};
3477
3478#define EC_CMD_HOST_EVENT 0x00A4
3479
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003480/*****************************************************************************/
3481/* Switch commands */
3482
3483/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003484#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003485
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003486struct __ec_align1 ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003487 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003488};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003489
3490/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003491#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003492#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003493
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003494/* Version 0 params; no response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003495struct __ec_align1 ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003496 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003497};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003498
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003499/* Version 1 params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003500struct __ec_align1 ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003501 /* Flags to enable now */
3502 uint8_t now_flags;
3503
3504 /* Which flags to copy from now_flags */
3505 uint8_t now_mask;
3506
3507 /*
3508 * Flags to leave enabled in S3, if they're on at the S0->S3
3509 * transition. (Other flags will be disabled by the S0->S3
3510 * transition.)
3511 */
3512 uint8_t suspend_flags;
3513
3514 /* Which flags to copy from suspend_flags */
3515 uint8_t suspend_mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003516};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003517
3518/* Version 1 response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003519struct __ec_align1 ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003520 /* Flags to enable now */
3521 uint8_t now_flags;
3522
3523 /* Flags to leave enabled in S3 */
3524 uint8_t suspend_flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003525};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003526
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003527/*****************************************************************************/
3528/* GPIO commands. Only available on EC if write protect has been disabled. */
3529
3530/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003531#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003532
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003533struct __ec_align1 ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003534 char name[32];
3535 uint8_t val;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003536};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003537
3538/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003539#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003540
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003541/* Version 0 of input params and response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003542struct __ec_align1 ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003543 char name[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003544};
3545
3546struct __ec_align1 ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003547 uint8_t val;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003548};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003549
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003550/* Version 1 of input params and response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003551struct __ec_align1 ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003552 uint8_t subcmd;
3553 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003554 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003555 char name[32];
3556 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003557 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003558 uint8_t index;
3559 } get_info;
3560 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003561};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003562
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003563struct __ec_todo_packed ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003564 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003565 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003566 uint8_t val;
3567 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003568 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003569 uint8_t val;
3570 char name[32];
3571 uint32_t flags;
3572 } get_info;
3573 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003574};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003575
3576enum gpio_get_subcmd {
3577 EC_GPIO_GET_BY_NAME = 0,
3578 EC_GPIO_GET_COUNT = 1,
3579 EC_GPIO_GET_INFO = 2,
3580};
3581
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003582/*****************************************************************************/
3583/* I2C commands. Only available when flash write protect is unlocked. */
3584
Duncan Laurie93e24442014-01-06 12:30:52 -08003585/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003586 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3587 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3588 *
3589 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08003590 */
3591
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003592/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003593#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003594
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003595struct __ec_align_size1 ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07003596 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003597 uint8_t read_size; /* Either 8 or 16. */
3598 uint8_t port;
3599 uint8_t offset;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003600};
3601
3602struct __ec_align2 ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003603 uint16_t data;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003604};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003605
3606/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003607#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003608
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003609struct __ec_align_size1 ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003610 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07003611 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003612 uint8_t write_size; /* Either 8 or 16. */
3613 uint8_t port;
3614 uint8_t offset;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003615};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003616
3617/*****************************************************************************/
3618/* Charge state commands. Only available when flash write protect unlocked. */
3619
Duncan Laurie93e24442014-01-06 12:30:52 -08003620/* Force charge state machine to stop charging the battery or force it to
3621 * discharge the battery.
3622 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003623#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08003624#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003625
Duncan Laurie93e24442014-01-06 12:30:52 -08003626enum ec_charge_control_mode {
3627 CHARGE_CONTROL_NORMAL = 0,
3628 CHARGE_CONTROL_IDLE,
3629 CHARGE_CONTROL_DISCHARGE,
3630};
3631
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003632struct __ec_align4 ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08003633 uint32_t mode; /* enum charge_control_mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003634};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003635
3636/*****************************************************************************/
3637/* Console commands. Only available when flash write protect is unlocked. */
3638
3639/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003640#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003641
3642/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003643 * Read data from the saved snapshot. If the subcmd parameter is
3644 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3645 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3646 * end of the previous snapshot.
3647 *
3648 * The params are only looked at in version >= 1 of this command. Prior
3649 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003650 *
3651 * Response is null-terminated string. Empty string, if there is no more
3652 * remaining output.
3653 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003654#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003655
Duncan Laurieeb316852015-12-01 18:51:18 -08003656enum ec_console_read_subcmd {
3657 CONSOLE_READ_NEXT = 0,
3658 CONSOLE_READ_RECENT
3659};
3660
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003661struct __ec_align1 ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08003662 uint8_t subcmd; /* enum ec_console_read_subcmd */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003663};
Duncan Laurieeb316852015-12-01 18:51:18 -08003664
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003665/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07003666
3667/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003668 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07003669 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003670 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3671 * EC_RES_SUCCESS if the command was successful.
3672 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07003673 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003674#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07003675
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003676#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3677
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003678struct __ec_align1 ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003679 uint8_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003680};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003681
Duncan Laurie433432b2013-06-03 10:38:22 -07003682/*****************************************************************************/
3683/* USB port mux control. */
3684
3685/*
3686 * Switch USB mux or return to automatic switching.
3687 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003688#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07003689
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003690struct __ec_align1 ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07003691 uint8_t mux;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003692};
Duncan Laurie433432b2013-06-03 10:38:22 -07003693
3694/*****************************************************************************/
3695/* LDOs / FETs control. */
3696
3697enum ec_ldo_state {
3698 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3699 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3700};
3701
3702/*
3703 * Switch on/off a LDO.
3704 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003705#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07003706
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003707struct __ec_align1 ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07003708 uint8_t index;
3709 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003710};
Duncan Laurie433432b2013-06-03 10:38:22 -07003711
3712/*
3713 * Get LDO state.
3714 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003715#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07003716
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003717struct __ec_align1 ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07003718 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003719};
Duncan Laurie433432b2013-06-03 10:38:22 -07003720
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003721struct __ec_align1 ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07003722 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003723};
Duncan Laurie433432b2013-06-03 10:38:22 -07003724
3725/*****************************************************************************/
3726/* Power info. */
3727
3728/*
3729 * Get power info.
3730 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003731#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07003732
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003733struct __ec_align4 ec_response_power_info {
Duncan Laurie433432b2013-06-03 10:38:22 -07003734 uint32_t usb_dev_type;
3735 uint16_t voltage_ac;
3736 uint16_t voltage_system;
3737 uint16_t current_system;
3738 uint16_t usb_current_limit;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003739};
Duncan Laurie433432b2013-06-03 10:38:22 -07003740
3741/*****************************************************************************/
3742/* I2C passthru command */
3743
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003744#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07003745
Duncan Laurie433432b2013-06-03 10:38:22 -07003746/* Read data; if not present, message is a write */
3747#define EC_I2C_FLAG_READ (1 << 15)
3748
3749/* Mask for address */
3750#define EC_I2C_ADDR_MASK 0x3ff
3751
3752#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
3753#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3754
3755/* Any error */
3756#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3757
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003758struct __ec_align2 ec_params_i2c_passthru_msg {
Duncan Laurie433432b2013-06-03 10:38:22 -07003759 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3760 uint16_t len; /* Number of bytes to read or write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003761};
Duncan Laurie433432b2013-06-03 10:38:22 -07003762
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003763struct __ec_align2 ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07003764 uint8_t port; /* I2C port number */
3765 uint8_t num_msgs; /* Number of messages */
3766 struct ec_params_i2c_passthru_msg msg[];
3767 /* Data to write for all messages is concatenated here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003768};
Duncan Laurie433432b2013-06-03 10:38:22 -07003769
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003770struct __ec_align1 ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07003771 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3772 uint8_t num_msgs; /* Number of messages processed */
3773 uint8_t data[]; /* Data read by messages concatenated here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003774};
Duncan Laurie433432b2013-06-03 10:38:22 -07003775
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003776/*****************************************************************************/
3777/* Power button hang detect */
3778
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003779#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003780
3781/* Reasons to start hang detection timer */
3782/* Power button pressed */
3783#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3784
3785/* Lid closed */
3786#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3787
3788 /* Lid opened */
3789#define EC_HANG_START_ON_LID_OPEN (1 << 2)
3790
3791/* Start of AP S3->S0 transition (booting or resuming from suspend) */
3792#define EC_HANG_START_ON_RESUME (1 << 3)
3793
3794/* Reasons to cancel hang detection */
3795
3796/* Power button released */
3797#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3798
3799/* Any host command from AP received */
3800#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3801
3802/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3803#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
3804
3805/*
3806 * If this flag is set, all the other fields are ignored, and the hang detect
3807 * timer is started. This provides the AP a way to start the hang timer
3808 * without reconfiguring any of the other hang detect settings. Note that
3809 * you must previously have configured the timeouts.
3810 */
3811#define EC_HANG_START_NOW (1 << 30)
3812
3813/*
3814 * If this flag is set, all the other fields are ignored (including
3815 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3816 * without reconfiguring any of the other hang detect settings.
3817 */
3818#define EC_HANG_STOP_NOW (1 << 31)
3819
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003820struct __ec_align4 ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003821 /* Flags; see EC_HANG_* */
3822 uint32_t flags;
3823
3824 /* Timeout in msec before generating host event, if enabled */
3825 uint16_t host_event_timeout_msec;
3826
3827 /* Timeout in msec before generating warm reboot, if enabled */
3828 uint16_t warm_reboot_timeout_msec;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003829};
Duncan Laurie433432b2013-06-03 10:38:22 -07003830
3831/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003832/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07003833
3834/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003835 * This is the single catch-all host command to exchange data regarding the
3836 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07003837 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003838#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003839
3840/* Subcommands for this host command */
3841enum charge_state_command {
3842 CHARGE_STATE_CMD_GET_STATE,
3843 CHARGE_STATE_CMD_GET_PARAM,
3844 CHARGE_STATE_CMD_SET_PARAM,
3845 CHARGE_STATE_NUM_CMDS
3846};
3847
3848/*
3849 * Known param numbers are defined here. Ranges are reserved for board-specific
3850 * params, which are handled by the particular implementations.
3851 */
3852enum charge_state_params {
3853 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
3854 CS_PARAM_CHG_CURRENT, /* charger current limit */
3855 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3856 CS_PARAM_CHG_STATUS, /* charger-specific status */
3857 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08003858 CS_PARAM_LIMIT_POWER, /*
3859 * Check if power is limited due to
3860 * low battery and / or a weak external
3861 * charger. READ ONLY.
3862 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003863 /* How many so far? */
3864 CS_NUM_BASE_PARAMS,
3865
3866 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3867 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3868 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3869
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003870 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
3871 CS_PARAM_DEBUG_MIN = 0x20000,
3872 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
3873 CS_PARAM_DEBUG_MANUAL_MODE,
3874 CS_PARAM_DEBUG_SEEMS_DEAD,
3875 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
3876 CS_PARAM_DEBUG_BATT_REMOVED,
3877 CS_PARAM_DEBUG_MANUAL_CURRENT,
3878 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
3879 CS_PARAM_DEBUG_MAX = 0x2ffff,
3880
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003881 /* Other custom param ranges go here... */
3882};
3883
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003884struct __ec_todo_packed ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003885 uint8_t cmd; /* enum charge_state_command */
3886 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003887 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003888
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003889 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003890 uint32_t param; /* enum charge_state_param */
3891 } get_param;
3892
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003893 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003894 uint32_t param; /* param to set */
3895 uint32_t value; /* value to set */
3896 } set_param;
3897 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003898};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003899
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003900struct __ec_align4 ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003901 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003902 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003903 int ac;
3904 int chg_voltage;
3905 int chg_current;
3906 int chg_input_current;
3907 int batt_state_of_charge;
3908 } get_state;
3909
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003910 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003911 uint32_t value;
3912 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003913
3914 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003915 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003916};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003917
Duncan Laurie433432b2013-06-03 10:38:22 -07003918
3919/*
3920 * Set maximum battery charging current.
3921 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003922#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07003923
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003924struct __ec_align4 ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07003925 uint32_t limit; /* in mA */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003926};
Duncan Laurie433432b2013-06-03 10:38:22 -07003927
3928/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003929 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07003930 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003931#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07003932
Duncan Laurieeb316852015-12-01 18:51:18 -08003933/* Command v0 is used only on Spring and is obsolete + unsupported */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003934struct __ec_align2 ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08003935 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3936 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003937};
Duncan Laurie433432b2013-06-03 10:38:22 -07003938
Duncan Laurieeb316852015-12-01 18:51:18 -08003939#define EC_POWER_LIMIT_NONE 0xffff
3940
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08003941/*
3942 * Set maximum voltage & current of a dedicated charge port
3943 */
3944#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
3945
3946struct __ec_align2 ec_params_dedicated_charger_limit {
3947 uint16_t current_lim; /* in mA */
3948 uint16_t voltage_lim; /* in mV */
3949};
3950
Duncan Laurieeb316852015-12-01 18:51:18 -08003951/*****************************************************************************/
3952/* Hibernate/Deep Sleep Commands */
3953
3954/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003955#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08003956
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003957struct __ec_align4 ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08003958 /*
3959 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3960 * current settings without changing them.
3961 */
3962 uint32_t seconds;
3963};
3964
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003965struct __ec_align4 ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08003966 /*
3967 * The current time in seconds in which the system has been in the G3
3968 * state. This value is reset if the EC transitions out of G3.
3969 */
3970 uint32_t time_g3;
3971
3972 /*
3973 * The current time remaining in seconds until the EC should hibernate.
3974 * This value is also reset if the EC transitions out of G3.
3975 */
3976 uint32_t time_remaining;
3977
3978 /*
3979 * The current time in seconds that the EC should wait in G3 before
3980 * hibernating.
3981 */
3982 uint32_t hibernate_delay;
3983};
3984
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003985/* Inform the EC when entering a sleep state */
3986#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
3987
3988enum host_sleep_event {
3989 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
3990 HOST_SLEEP_EVENT_S3_RESUME = 2,
3991 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003992 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
3993 /* S3 suspend with additional enabled wake sources */
3994 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003995};
3996
3997struct __ec_align1 ec_params_host_sleep_event {
3998 uint8_t sleep_event;
3999};
4000
4001/*****************************************************************************/
4002/* Device events */
4003#define EC_CMD_DEVICE_EVENT 0x00AA
4004
4005enum ec_device_event {
4006 EC_DEVICE_EVENT_TRACKPAD,
4007 EC_DEVICE_EVENT_DSP,
4008 EC_DEVICE_EVENT_WIFI,
4009};
4010
4011enum ec_device_event_param {
4012 /* Get and clear pending device events */
4013 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4014 /* Get device event mask */
4015 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4016 /* Set device event mask */
4017 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4018};
4019
4020#define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
4021
4022struct __ec_align_size1 ec_params_device_event {
4023 uint32_t event_mask;
4024 uint8_t param;
4025};
4026
4027struct __ec_align4 ec_response_device_event {
4028 uint32_t event_mask;
4029};
Duncan Laurieeb316852015-12-01 18:51:18 -08004030
Duncan Laurie433432b2013-06-03 10:38:22 -07004031/*****************************************************************************/
4032/* Smart battery pass-through */
4033
4034/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004035#define EC_CMD_SB_READ_WORD 0x00B0
4036#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004037
4038/* Get / Set string smart battery parameters
4039 * formatted as SMBUS "block".
4040 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004041#define EC_CMD_SB_READ_BLOCK 0x00B2
4042#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004043
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004044struct __ec_align1 ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004045 uint8_t reg;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004046};
Duncan Laurie433432b2013-06-03 10:38:22 -07004047
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004048struct __ec_align2 ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004049 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004050};
Duncan Laurie433432b2013-06-03 10:38:22 -07004051
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004052struct __ec_align1 ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004053 uint8_t reg;
4054 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004055};
Duncan Laurie433432b2013-06-03 10:38:22 -07004056
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004057struct __ec_align1 ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004058 uint8_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004059};
Duncan Laurie433432b2013-06-03 10:38:22 -07004060
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004061struct __ec_align1 ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004062 uint8_t reg;
4063 uint16_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004064};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004065
4066/*****************************************************************************/
4067/* Battery vendor parameters
4068 *
4069 * Get or set vendor-specific parameters in the battery. Implementations may
4070 * differ between boards or batteries. On a set operation, the response
4071 * contains the actual value set, which may be rounded or clipped from the
4072 * requested value.
4073 */
4074
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004075#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004076
4077enum ec_battery_vendor_param_mode {
4078 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4079 BATTERY_VENDOR_PARAM_MODE_SET,
4080};
4081
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004082struct __ec_align_size1 ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004083 uint32_t param;
4084 uint32_t value;
4085 uint8_t mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004086};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004087
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004088struct __ec_align4 ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004089 uint32_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004090};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004091
4092/*****************************************************************************/
4093/*
4094 * Smart Battery Firmware Update Commands
4095 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004096#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004097
4098enum ec_sb_fw_update_subcmd {
4099 EC_SB_FW_UPDATE_PREPARE = 0x0,
4100 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4101 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4102 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4103 EC_SB_FW_UPDATE_END = 0x4,
4104 EC_SB_FW_UPDATE_STATUS = 0x5,
4105 EC_SB_FW_UPDATE_PROTECT = 0x6,
4106 EC_SB_FW_UPDATE_MAX = 0x7,
4107};
4108
4109#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4110#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4111#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4112
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004113struct __ec_align4 ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004114 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4115 uint16_t fw_id; /* firmware id */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004116};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004117
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004118struct __ec_align4 ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004119 struct ec_sb_fw_update_header hdr;
4120 union {
4121 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4122 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4123 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4124 /* EC_SB_FW_UPDATE_END = 0x4 */
4125 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4126 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004127 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004128
4129 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004130 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004131 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4132 } write;
4133 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004134};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004135
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004136struct __ec_align1 ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004137 union {
4138 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004139 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004140 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4141 } info;
4142
4143 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004144 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004145 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4146 } status;
4147 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004148};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004149
4150/*
4151 * Entering Verified Boot Mode Command
4152 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4153 * Valid Modes are: normal, developer, and recovery.
4154 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004155#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004156
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004157struct __ec_align4 ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004158 int vboot_mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004159};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004160
4161#define VBOOT_MODE_NORMAL 0
4162#define VBOOT_MODE_DEVELOPER 1
4163#define VBOOT_MODE_RECOVERY 2
4164
Duncan Laurie433432b2013-06-03 10:38:22 -07004165/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004166/*
4167 * I2C passthru protection command: Protects I2C tunnels against access on
4168 * certain addresses (board-specific).
4169 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004170#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004171
4172enum ec_i2c_passthru_protect_subcmd {
4173 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
4174 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
4175};
4176
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004177struct __ec_align1 ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004178 uint8_t subcmd;
4179 uint8_t port; /* I2C port number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004180};
Gwendal Grignou880b4582016-06-20 08:49:25 -07004181
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004182struct __ec_align1 ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004183 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004184};
Gwendal Grignou880b4582016-06-20 08:49:25 -07004185
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004186
4187/*****************************************************************************/
4188/*
4189 * HDMI CEC commands
4190 *
4191 * These commands are for sending and receiving message via HDMI CEC
4192 */
4193
4194#define MAX_CEC_MSG_LEN 16
4195
4196/* CEC message from the AP to be written on the CEC bus */
4197#define EC_CMD_CEC_WRITE_MSG 0x00B8
4198
4199/* Message to write to the CEC bus */
4200struct __ec_align1 ec_params_cec_write {
4201 uint8_t msg[MAX_CEC_MSG_LEN];
4202};
4203
4204/* Set various CEC parameters */
4205#define EC_CMD_CEC_SET 0x00BA
4206
4207struct __ec_align1 ec_params_cec_set {
4208 uint8_t cmd; /* enum cec_command */
4209 uint8_t val;
4210};
4211
4212/* Read various CEC parameters */
4213#define EC_CMD_CEC_GET 0x00BB
4214
4215struct __ec_align1 ec_params_cec_get {
4216 uint8_t cmd; /* enum cec_command */
4217};
4218
4219struct __ec_align1 ec_response_cec_get {
4220 uint8_t val;
4221};
4222
4223enum cec_command {
4224 /* CEC reading, writing and events enable */
4225 CEC_CMD_ENABLE,
4226 /* CEC logical address */
4227 CEC_CMD_LOGICAL_ADDRESS,
4228};
4229
4230/* Events from CEC to AP */
4231enum mkbp_cec_event {
4232 /* Outgoing message was acknowledged by a follower */
4233 EC_MKBP_CEC_SEND_OK = 1 << 0,
4234 /* Outgoing message was not acknowledged */
4235 EC_MKBP_CEC_SEND_FAILED = 1 << 1,
4236};
4237
Gwendal Grignou880b4582016-06-20 08:49:25 -07004238/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004239/* System commands */
4240
4241/*
Duncan Laurie93e24442014-01-06 12:30:52 -08004242 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
4243 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004244 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004245#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004246
4247/* Command */
4248enum ec_reboot_cmd {
4249 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07004250 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004251 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004252 /* (command 3 was jump to RW-B) */
4253 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07004254 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08004255 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
4256 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004257};
4258
4259/* Flags for ec_params_reboot_ec.reboot_flags */
4260#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
Duncan Laurie433432b2013-06-03 10:38:22 -07004261#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004262#define EC_REBOOT_FLAG_SWITCH_RW_SLOT (1 << 2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004263
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004264struct __ec_align1 ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004265 uint8_t cmd; /* enum ec_reboot_cmd */
4266 uint8_t flags; /* See EC_REBOOT_FLAG_* */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004267};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004268
Duncan Laurie433432b2013-06-03 10:38:22 -07004269/*
4270 * Get information on last EC panic.
4271 *
4272 * Returns variable-length platform-dependent panic information. See panic.h
4273 * for details.
4274 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004275#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07004276
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004277/*****************************************************************************/
4278/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004279 * Special commands
4280 *
4281 * These do not follow the normal rules for commands. See each command for
4282 * details.
4283 */
4284
4285/*
4286 * Reboot NOW
4287 *
4288 * This command will work even when the EC LPC interface is busy, because the
4289 * reboot command is processed at interrupt level. Note that when the EC
4290 * reboots, the host will reboot too, so there is no response to this command.
4291 *
4292 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
4293 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004294#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004295
4296/*
Duncan Laurie433432b2013-06-03 10:38:22 -07004297 * Resend last response (not supported on LPC).
4298 *
4299 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
4300 * there was no previous command, or the previous command's response was too
4301 * big to save.
4302 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004303#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07004304
4305/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004306 * This header byte on a command indicate version 0. Any header byte less
4307 * than this means that we are talking to an old EC which doesn't support
4308 * versioning. In that case, we assume version 0.
4309 *
4310 * Header bytes greater than this indicate a later version. For example,
4311 * EC_CMD_VERSION0 + 1 means we are using version 1.
4312 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004313 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004314 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004315#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004316
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004317/*****************************************************************************/
4318/*
4319 * PD commands
4320 *
4321 * These commands are for PD MCU communication.
4322 */
4323
4324/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004325#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08004326#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004327
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004328enum pd_charge_state {
4329 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
4330 PD_CHARGE_NONE, /* No charging allowed */
4331 PD_CHARGE_5V, /* 5V charging only */
4332 PD_CHARGE_MAX /* Charge at max voltage */
4333};
4334
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004335/* Status of EC being sent to PD */
Duncan Laurieeb316852015-12-01 18:51:18 -08004336#define EC_STATUS_HIBERNATING (1 << 0)
4337
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004338struct __ec_align1 ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08004339 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004340 int8_t batt_soc; /* battery state of charge */
4341 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004342};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004343
4344/* Status of PD being sent back to EC */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004345#define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
4346#define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
4347#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
Duncan Laurieeb316852015-12-01 18:51:18 -08004348#define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
4349#define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
4350#define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
4351#define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
4352#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
4353 PD_STATUS_TCPC_ALERT_1 | \
4354 PD_STATUS_HOST_EVENT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004355struct __ec_align_size1 ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08004356 uint32_t curr_lim_ma; /* input current limit */
4357 uint16_t status; /* PD MCU status */
4358 int8_t active_charge_port; /* active charging port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004359};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004360
4361/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004362#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004363
4364/* PD MCU host event status bits */
4365#define PD_EVENT_UPDATE_DEVICE (1 << 0)
4366#define PD_EVENT_POWER_CHANGE (1 << 1)
4367#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
Duncan Laurieeb316852015-12-01 18:51:18 -08004368#define PD_EVENT_DATA_SWAP (1 << 3)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004369struct __ec_align4 ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004370 uint32_t status; /* PD MCU host event status */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004371};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004372
4373/* Set USB type-C port role and muxes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004374#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004375
4376enum usb_pd_control_role {
4377 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
4378 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
4379 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
4380 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
4381 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004382 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004383 USB_PD_CTRL_ROLE_COUNT
4384};
4385
4386enum usb_pd_control_mux {
4387 USB_PD_CTRL_MUX_NO_CHANGE = 0,
4388 USB_PD_CTRL_MUX_NONE = 1,
4389 USB_PD_CTRL_MUX_USB = 2,
4390 USB_PD_CTRL_MUX_DP = 3,
4391 USB_PD_CTRL_MUX_DOCK = 4,
4392 USB_PD_CTRL_MUX_AUTO = 5,
4393 USB_PD_CTRL_MUX_COUNT
4394};
4395
Duncan Laurieeb316852015-12-01 18:51:18 -08004396enum usb_pd_control_swap {
4397 USB_PD_CTRL_SWAP_NONE = 0,
4398 USB_PD_CTRL_SWAP_DATA = 1,
4399 USB_PD_CTRL_SWAP_POWER = 2,
4400 USB_PD_CTRL_SWAP_VCONN = 3,
4401 USB_PD_CTRL_SWAP_COUNT
4402};
4403
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004404struct __ec_align1 ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004405 uint8_t port;
4406 uint8_t role;
4407 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08004408 uint8_t swap;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004409};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004410
Duncan Laurieeb316852015-12-01 18:51:18 -08004411#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
4412#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
4413#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
4414
4415#define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
4416#define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
4417#define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
4418#define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
4419#define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
4420#define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
4421#define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
4422
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004423struct __ec_align1 ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004424 uint8_t enabled;
4425 uint8_t role;
4426 uint8_t polarity;
4427 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004428};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004429
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004430struct __ec_align1 ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004431 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08004432 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004433 uint8_t polarity;
4434 char state[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004435};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004436
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004437#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004438
Patrick Georgi0f6187a2017-07-28 15:57:23 +02004439/* Maximum number of PD ports on a device, num_ports will be <= this */
4440#define EC_USB_PD_MAX_PORTS 8
4441
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004442struct __ec_align1 ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004443 uint8_t num_ports;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004444};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004445
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004446#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004447
4448#define PD_POWER_CHARGING_PORT 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004449struct __ec_align1 ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004450 uint8_t port;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004451};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004452
4453enum usb_chg_type {
4454 USB_CHG_TYPE_NONE,
4455 USB_CHG_TYPE_PD,
4456 USB_CHG_TYPE_C,
4457 USB_CHG_TYPE_PROPRIETARY,
4458 USB_CHG_TYPE_BC12_DCP,
4459 USB_CHG_TYPE_BC12_CDP,
4460 USB_CHG_TYPE_BC12_SDP,
4461 USB_CHG_TYPE_OTHER,
4462 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08004463 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004464 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004465};
4466enum usb_power_roles {
4467 USB_PD_PORT_POWER_DISCONNECTED,
4468 USB_PD_PORT_POWER_SOURCE,
4469 USB_PD_PORT_POWER_SINK,
4470 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
4471};
4472
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004473struct __ec_align2 usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004474 uint16_t voltage_max;
4475 uint16_t voltage_now;
4476 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08004477 uint16_t current_lim;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004478};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004479
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004480struct __ec_align4 ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004481 uint8_t role;
4482 uint8_t type;
4483 uint8_t dualrole;
4484 uint8_t reserved1;
4485 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004486 uint32_t max_power;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004487};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004488
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004489
4490/*
4491 * This command will return the number of USB PD charge port + the number
4492 * of dedicated port present.
4493 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
4494 */
4495#define EC_CMD_CHARGE_PORT_COUNT 0x0105
4496struct __ec_align1 ec_response_charge_port_count {
4497 uint8_t port_count;
4498};
4499
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004500/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004501#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004502
4503enum usb_pd_fw_update_cmds {
4504 USB_PD_FW_REBOOT,
4505 USB_PD_FW_FLASH_ERASE,
4506 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004507 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004508};
4509
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004510struct __ec_align4 ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004511 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004512 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004513 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004514 uint32_t size; /* Size to write in bytes */
4515 /* Followed by data to write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004516};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004517
4518/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004519#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004520/* RW hash is first 20 bytes of SHA-256 of RW section */
4521#define PD_RW_HASH_SIZE 20
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004522struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004523 uint16_t dev_id;
4524 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004525 uint8_t reserved; /* For alignment of current_image
4526 * TODO(rspangler) but it's not aligned!
4527 * Should have been reserved[2]. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004528 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004529};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004530
4531/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004532#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004533
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004534struct __ec_align1 ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004535 uint8_t port;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004536};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004537
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004538/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004539#define EC_CMD_USB_PD_DISCOVERY 0x0113
4540struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004541 uint16_t vid; /* USB-IF VID */
4542 uint16_t pid; /* USB-IF PID */
4543 uint8_t ptype; /* product type (hub,periph,cable,ama) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004544};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004545
4546/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004547#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004548
4549/* Negative port parameters have special meaning */
4550enum usb_pd_override_ports {
4551 OVERRIDE_DONT_CHARGE = -2,
4552 OVERRIDE_OFF = -1,
Duncan Laurieeb316852015-12-01 18:51:18 -08004553 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004554};
4555
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004556struct __ec_align2 ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004557 int16_t override_port; /* Override port# */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004558};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004559
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004560/*
4561 * Read (and delete) one entry of PD event log.
4562 * TODO(crbug.com/751742): Make this host command more generic to accommodate
4563 * future non-PD logs that use the same internal EC event_log.
4564 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004565#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004566
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004567struct __ec_align4 ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004568 uint32_t timestamp; /* relative timestamp in milliseconds */
4569 uint8_t type; /* event type : see PD_EVENT_xx below */
4570 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4571 uint16_t data; /* type-defined data payload */
4572 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004573};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004574
4575
4576/* The timestamp is the microsecond counter shifted to get about a ms. */
4577#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4578
Duncan Laurieeb316852015-12-01 18:51:18 -08004579#define PD_LOG_SIZE_MASK 0x1f
4580#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004581#define PD_LOG_PORT_SHIFT 5
4582#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4583 ((size) & PD_LOG_SIZE_MASK))
4584#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4585#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4586
4587/* PD event log : entry types */
4588/* PD MCU events */
4589#define PD_EVENT_MCU_BASE 0x00
4590#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4591#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4592/* Reserved for custom board event */
4593#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4594/* PD generic accessory events */
4595#define PD_EVENT_ACC_BASE 0x20
4596#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4597#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4598/* PD power supply events */
4599#define PD_EVENT_PS_BASE 0x40
4600#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4601/* PD video dongles events */
4602#define PD_EVENT_VIDEO_BASE 0x60
4603#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4604#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4605/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08004606#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004607
4608/*
4609 * PD_EVENT_MCU_CHARGE event definition :
4610 * the payload is "struct usb_chg_measures"
4611 * the data field contains the port state flags as defined below :
4612 */
4613/* Port partner is a dual role device */
4614#define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
4615/* Port is the pending override port */
4616#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
4617/* Port is the override port */
4618#define CHARGE_FLAGS_OVERRIDE (1 << 13)
4619/* Charger type */
4620#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08004621#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004622/* Power delivery role */
4623#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4624
4625/*
4626 * PD_EVENT_PS_FAULT data field flags definition :
4627 */
4628#define PS_FAULT_OCP 1
4629#define PS_FAULT_FAST_OCP 2
4630#define PS_FAULT_OVP 3
4631#define PS_FAULT_DISCH 4
4632
4633/*
4634 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4635 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004636struct __ec_align4 mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004637 uint8_t major;
4638 uint8_t minor;
4639 uint16_t build;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004640};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004641
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004642struct __ec_align4 mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004643 uint8_t family[2];
4644 uint8_t chipid[2];
4645 struct mcdp_version irom;
4646 struct mcdp_version fw;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004647};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004648
4649/* struct mcdp_info field decoding */
4650#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4651#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4652
4653/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004654#define EC_CMD_USB_PD_GET_AMODE 0x0116
4655struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004656 uint16_t svid_idx; /* SVID index to get */
4657 uint8_t port; /* port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004658};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004659
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004660struct __ec_align4 ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004661 uint16_t svid; /* SVID */
4662 uint16_t opos; /* Object Position */
4663 uint32_t vdo[6]; /* Mode VDOs */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004664};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004665
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004666#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004667
4668enum pd_mode_cmd {
4669 PD_EXIT_MODE = 0,
4670 PD_ENTER_MODE = 1,
4671 /* Not a command. Do NOT remove. */
4672 PD_MODE_CMD_COUNT,
4673};
4674
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004675struct __ec_align4 ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004676 uint32_t cmd; /* enum pd_mode_cmd */
4677 uint16_t svid; /* SVID to set */
4678 uint8_t opos; /* Object Position */
4679 uint8_t port; /* port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004680};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004681
4682/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004683#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004684
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004685struct __ec_align1 ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004686 uint8_t type; /* event type : see PD_EVENT_xx above */
4687 uint8_t port; /* port#, or 0 for events unrelated to a given port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004688};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004689
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004690
Gwendal Grignou880b4582016-06-20 08:49:25 -07004691/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004692#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07004693
4694enum ec_pd_control_cmd {
4695 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4696 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4697 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004698 PD_CONTROL_DISABLE, /* Disable further calls to this command */
4699 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07004700};
4701
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004702struct __ec_align1 ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004703 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07004704 uint8_t subcmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004705};
Gwendal Grignou880b4582016-06-20 08:49:25 -07004706
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004707/* Get info about USB-C SS muxes */
4708#define EC_CMD_USB_PD_MUX_INFO 0x011A
4709
4710struct __ec_align1 ec_params_usb_pd_mux_info {
4711 uint8_t port; /* USB-C port number */
4712};
4713
4714/* Flags representing mux state */
4715#define USB_PD_MUX_USB_ENABLED (1 << 0)
4716#define USB_PD_MUX_DP_ENABLED (1 << 1)
4717#define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4718#define USB_PD_MUX_HPD_IRQ (1 << 3)
4719
4720struct __ec_align1 ec_response_usb_pd_mux_info {
4721 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4722};
4723
4724#define EC_CMD_PD_CHIP_INFO 0x011B
4725
4726struct __ec_align1 ec_params_pd_chip_info {
4727 uint8_t port; /* USB-C port number */
4728 uint8_t renew; /* Force renewal */
4729};
4730
4731struct __ec_align2 ec_response_pd_chip_info {
4732 uint16_t vendor_id;
4733 uint16_t product_id;
4734 uint16_t device_id;
4735 union {
4736 uint8_t fw_version_string[8];
4737 uint64_t fw_version_number;
4738 };
4739};
4740
4741/* Run RW signature verification and get status */
4742#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
4743
4744struct __ec_align4 ec_response_rwsig_check_status {
4745 uint32_t status;
4746};
4747
4748/* For controlling RWSIG task */
4749#define EC_CMD_RWSIG_ACTION 0x011D
4750
4751enum rwsig_action {
4752 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
4753 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
4754};
4755
4756struct __ec_align4 ec_params_rwsig_action {
4757 uint32_t action;
4758};
4759
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08004760/* Run verification on a slot */
4761#define EC_CMD_EFS_VERIFY 0x011E
4762
4763struct __ec_align1 ec_params_efs_verify {
4764 uint8_t region; /* enum ec_flash_region */
4765};
4766
4767/*
4768 * Retrieve info from Cros Board Info store. Response is based on the data
4769 * type. Integers return a uint32. Strings return a string, using the response
4770 * size to determine how big it is.
4771 */
4772#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
4773/*
4774 * Write info into Cros Board Info on EEPROM. Write fails if the board has
4775 * hardware write-protect enabled.
4776 */
4777#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
4778
Daisuke Nojirif984a052018-02-15 12:38:15 -08004779enum cbi_data_tag {
4780 CBI_TAG_BOARD_VERSION = 0, /* uint16_t or uint8_t[] = {minor,major} */
4781 CBI_TAG_OEM_ID = 1, /* uint8_t */
4782 CBI_TAG_SKU_ID = 2, /* uint8_t */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06004783 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Daisuke Nojirif984a052018-02-15 12:38:15 -08004784 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08004785};
4786
4787/*
4788 * Flags to control read operation
4789 *
4790 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
4791 * write was successful without reboot.
4792 */
4793#define CBI_GET_RELOAD (1 << 0)
4794
4795struct __ec_align4 ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004796 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08004797 uint32_t flag; /* CBI_GET_* */
4798};
4799
4800/*
4801 * Flags to control write behavior.
4802 *
4803 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
4804 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004805 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08004806 * will be initialized to zero first.
4807 */
4808#define CBI_SET_NO_SYNC (1 << 0)
4809#define CBI_SET_INIT (1 << 1)
4810
4811struct __ec_align1 ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08004812 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08004813 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08004814 uint32_t size; /* Data size */
4815 uint8_t data[]; /* For string and raw data */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08004816};
4817
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004818/*
4819 * Information about resets of the AP by the EC and the EC's own uptime.
4820 */
4821#define EC_CMD_GET_UPTIME_INFO 0x0121
4822
4823struct __ec_align4 ec_response_uptime_info {
4824 /* Number of milliseconds since last EC reset */
4825 uint32_t time_since_ec_boot_ms;
4826
4827 /*
4828 * Number of times the AP was reset by the EC since the last EC boot.
4829 * Note that the AP may be held in reset by the EC during the initial
4830 * boot sequence, such that the very first AP boot may count as more
4831 * than one here.
4832 */
4833 uint32_t ap_resets_since_ec_boot;
4834
4835 /*
4836 * The set of flags which describe the EC's most recent reset. See
4837 * include/system.h RESET_FLAG_* for details.
4838 */
4839 uint32_t ec_reset_flags;
4840
4841 /* Empty log entries have both the cause and timestamp set to zero. */
4842 struct ap_reset_log_entry {
4843 /* See include/chipset.h for details */
4844 uint16_t reset_cause;
4845
4846 /*
4847 * The time of the reset's assertion, in milliseconds since the
4848 * last EC reset. Set to zero if the log entry is empty.
4849 */
4850 uint32_t reset_time_ms;
4851 } recent_ap_reset[4];
4852};
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004853/*****************************************************************************/
4854/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08004855
4856/*****************************************************************************/
4857/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004858 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08004859 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004860#define EC_CMD_CR51_BASE 0x0300
4861#define EC_CMD_CR51_LAST 0x03FF
4862
4863/*****************************************************************************/
4864/* Fingerprint MCU commands: range 0x0400-0x040x */
4865
4866/* Fingerprint SPI sensor passthru command: prototyping ONLY */
4867#define EC_CMD_FP_PASSTHRU 0x0400
4868
4869#define EC_FP_FLAG_NOT_COMPLETE 0x1
4870
4871struct __ec_align2 ec_params_fp_passthru {
4872 uint16_t len; /* Number of bytes to write then read */
4873 uint16_t flags; /* EC_FP_FLAG_xxx */
4874 uint8_t data[]; /* Data to send */
4875};
4876
4877/* Fingerprint sensor configuration command: prototyping ONLY */
4878#define EC_CMD_FP_SENSOR_CONFIG 0x0401
4879
4880#define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4881
4882struct __ec_align2 ec_params_fp_sensor_config {
4883 uint8_t count; /* Number of setup registers */
4884 /*
4885 * the value to send to each of the 'count' setup registers
4886 * is stored in the 'data' array for 'len' bytes just after
4887 * the previous one.
4888 */
4889 uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4890 uint8_t data[];
4891};
4892
4893/* Configure the Fingerprint MCU behavior */
4894#define EC_CMD_FP_MODE 0x0402
4895
4896/* Put the sensor in its lowest power mode */
4897#define FP_MODE_DEEPSLEEP (1<<0)
4898/* Wait to see a finger on the sensor */
4899#define FP_MODE_FINGER_DOWN (1<<1)
4900/* Poll until the finger has left the sensor */
4901#define FP_MODE_FINGER_UP (1<<2)
4902/* Capture the current finger image */
4903#define FP_MODE_CAPTURE (1<<3)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004904/* Capture types defined in bits [30..28] */
4905#define FP_MODE_CAPTURE_TYPE_SHIFT 28
4906#define FP_MODE_CAPTURE_TYPE_MASK 0x7
4907/* Full blown vendor-defined capture (produces 'frame_size' bytes) */
4908#define FP_CAPTURE_VENDOR_FORMAT 0
4909/* Simple raw image capture (produces width x height x bpp bits) */
4910#define FP_CAPTURE_SIMPLE_IMAGE 1
4911/* Self test pattern (e.g. checkerboard) */
4912#define FP_CAPTURE_PATTERN0 2
4913/* Self test pattern (e.g. inverted checkerboard) */
4914#define FP_CAPTURE_PATTERN1 3
4915/* Capture for Quality test with fixed contrast */
4916#define FP_CAPTURE_QUALITY_TEST 4
4917/* Capture for pixel reset value test */
4918#define FP_CAPTURE_RESET_TEST 5
4919/* Extracts the capture type from the sensor 'mode' word */
4920#define FP_CAPTURE_TYPE(mode) (((mode) >> FP_MODE_CAPTURE_TYPE_SHIFT) \
4921 & FP_MODE_CAPTURE_TYPE_MASK)
4922/* Finger enrollment session on-going */
4923#define FP_MODE_ENROLL_SESSION (1<<4)
4924/* Enroll the current finger image */
4925#define FP_MODE_ENROLL_IMAGE (1<<5)
4926/* Try to match the current finger image */
4927#define FP_MODE_MATCH (1<<6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004928/* special value: don't change anything just read back current mode */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004929#define FP_MODE_DONT_CHANGE (1<<31)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004930
4931struct __ec_align4 ec_params_fp_mode {
4932 uint32_t mode; /* as defined by FP_MODE_ constants */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004933};
4934
4935struct __ec_align4 ec_response_fp_mode {
4936 uint32_t mode; /* as defined by FP_MODE_ constants */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004937};
4938
4939/* Retrieve Fingerprint sensor information */
4940#define EC_CMD_FP_INFO 0x0403
4941
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004942/* Number of dead pixels detected on the last maintenance */
4943#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
4944/* No interrupt from the sensor */
4945#define FP_ERROR_NO_IRQ (1 << 12)
4946/* SPI communication error */
4947#define FP_ERROR_SPI_COMM (1 << 13)
4948/* Invalid sensor Hardware ID */
4949#define FP_ERROR_BAD_HWID (1 << 14)
4950/* Sensor initialization failed */
4951#define FP_ERROR_INIT_FAIL (1 << 15)
4952
4953struct __ec_align4 ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004954 /* Sensor identification */
4955 uint32_t vendor_id;
4956 uint32_t product_id;
4957 uint32_t model_id;
4958 uint32_t version;
4959 /* Image frame characteristics */
4960 uint32_t frame_size;
4961 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4962 uint16_t width;
4963 uint16_t height;
4964 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004965 uint16_t errors; /* see FP_ERROR_ flags above */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004966};
4967
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004968struct __ec_align4 ec_response_fp_info {
4969 /* Sensor identification */
4970 uint32_t vendor_id;
4971 uint32_t product_id;
4972 uint32_t model_id;
4973 uint32_t version;
4974 /* Image frame characteristics */
4975 uint32_t frame_size;
4976 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4977 uint16_t width;
4978 uint16_t height;
4979 uint16_t bpp;
4980 uint16_t errors; /* see FP_ERROR_ flags above */
4981 /* Template/finger current information */
4982 uint32_t template_size; /* max template size in bytes */
4983 uint16_t template_max; /* maximum number of fingers/templates */
4984 uint16_t template_valid; /* number of valid fingers/templates */
4985 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
4986};
4987
4988/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004989#define EC_CMD_FP_FRAME 0x0404
4990
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004991/* constants defining the 'offset' field which also contains the frame index */
4992#define FP_FRAME_INDEX_SHIFT 28
4993#define FP_FRAME_INDEX_RAW_IMAGE 0
4994#define FP_FRAME_TEMPLATE_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
4995#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
4996
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004997struct __ec_align4 ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004998 /*
4999 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
5000 * in the high nibble, and the real offset within the frame in
5001 * FP_FRAME_OFFSET_MASK.
5002 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005003 uint32_t offset;
5004 uint32_t size;
5005};
5006
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005007/* Load a template into the MCU */
5008#define EC_CMD_FP_TEMPLATE 0x0405
5009
5010/* Flag in the 'size' field indicating that the full template has been sent */
5011#define FP_TEMPLATE_COMMIT 0x80000000
5012
5013struct __ec_align4 ec_params_fp_template {
5014 uint32_t offset;
5015 uint32_t size;
5016 uint8_t data[];
5017};
5018
5019/* Clear the current fingerprint user context and set a new one */
5020#define EC_CMD_FP_CONTEXT 0x0406
5021
5022#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
5023#define FP_CONTEXT_NONCE_WORDS (32 / sizeof(uint32_t))
5024
5025struct __ec_align4 ec_params_fp_context {
5026 uint32_t userid[FP_CONTEXT_USERID_WORDS];
5027 /* TODO(b/73337313) mostly a placeholder, details to be implemented */
5028 uint32_t nonce[FP_CONTEXT_NONCE_WORDS];
5029};
5030
5031struct __ec_align4 ec_response_fp_context {
5032 uint32_t nonce[FP_CONTEXT_NONCE_WORDS];
5033};
5034
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005035/*****************************************************************************/
5036/* Touchpad MCU commands: range 0x0500-0x05FF */
5037
5038/* Perform touchpad self test */
5039#define EC_CMD_TP_SELF_TEST 0x0500
5040
5041/* Get number of frame types, and the size of each type */
5042#define EC_CMD_TP_FRAME_INFO 0x0501
5043
5044struct __ec_align4 ec_response_tp_frame_info {
5045 uint32_t n_frames;
5046 uint32_t frame_sizes[0];
5047};
5048
5049/* Create a snapshot of current frame readings */
5050#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
5051
5052/* Read the frame */
5053#define EC_CMD_TP_FRAME_GET 0x0503
5054
5055struct __ec_align4 ec_params_tp_frame_get {
5056 uint32_t frame_index;
5057 uint32_t offset;
5058 uint32_t size;
5059};
Duncan Laurieeb316852015-12-01 18:51:18 -08005060
5061/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005062/* EC-EC communication commands: range 0x0600-0x06FF */
5063
5064#define EC_COMM_TEXT_MAX 8
5065
5066/*
5067 * Get battery static information, i.e. information that never changes, or
5068 * very infrequently.
5069 */
5070#define EC_CMD_BATTERY_GET_STATIC 0x0600
5071
5072struct __ec_align_size1 ec_params_battery_static_info {
5073 uint8_t index; /* Battery index. */
5074};
5075
5076struct __ec_align4 ec_response_battery_static_info {
5077 uint16_t design_capacity; /* Battery Design Capacity (mAh) */
5078 uint16_t design_voltage; /* Battery Design Voltage (mV) */
5079 char manufacturer[EC_COMM_TEXT_MAX]; /* Battery Manufacturer String */
5080 char model[EC_COMM_TEXT_MAX]; /* Battery Model Number String */
5081 char serial[EC_COMM_TEXT_MAX]; /* Battery Serial Number String */
5082 char type[EC_COMM_TEXT_MAX]; /* Battery Type String */
5083 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
5084 uint32_t cycle_count; /* Battery Cycle Count */
5085};
5086
5087/*
5088 * Get battery dynamic information, i.e. information that is likely to change
5089 * every time it is read.
5090 */
5091#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
5092
5093struct __ec_align_size1 ec_params_battery_dynamic_info {
5094 uint8_t index; /* Battery index. */
5095};
5096
5097struct __ec_align2 ec_response_battery_dynamic_info {
5098 int16_t actual_voltage; /* Battery voltage (mV) */
5099 int16_t actual_current; /* Battery current (mA); negative=discharging */
5100 int16_t remaining_capacity; /* Remaining capacity (mAh) */
5101 int16_t full_capacity; /* Capacity (mAh, might change occasionally) */
5102 int16_t flags; /* Flags, see EC_BATT_FLAG_* */
5103 int16_t desired_voltage; /* Charging voltage desired by battery (mV) */
5104 int16_t desired_current; /* Charging current desired by battery (mA) */
5105};
5106
5107/*
5108 * Control charger chip. Used to control charger chip on the slave.
5109 */
5110#define EC_CMD_CHARGER_CONTROL 0x0602
5111
5112struct __ec_align_size1 ec_params_charger_control {
5113 /*
5114 * Charger current (mA). Positive to allow base to draw up to
5115 * max_current and (possibly) charge battery, negative to request
5116 * current from base (OTG).
5117 */
5118 int16_t max_current;
5119
5120 /* Voltage (mV) to use in OTG mode, ignored if max_current is >= 0. */
5121 uint16_t otg_voltage;
5122
5123 /* Allow base battery charging (only makes sense if max_current > 0). */
5124 uint8_t allow_charging;
5125};
5126
5127/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08005128/*
5129 * Reserve a range of host commands for board-specific, experimental, or
5130 * special purpose features. These can be (re)used without updating this file.
5131 *
5132 * CAUTION: Don't go nuts with this. Shipping products should document ALL
5133 * their EC commands for easier development, testing, debugging, and support.
5134 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005135 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
5136 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
5137 *
Duncan Laurieeb316852015-12-01 18:51:18 -08005138 * In your experimental code, you may want to do something like this:
5139 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005140 * #define EC_CMD_MAGIC_FOO 0x0000
5141 * #define EC_CMD_MAGIC_BAR 0x0001
5142 * #define EC_CMD_MAGIC_HEY 0x0002
5143 *
5144 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
5145 * EC_VER_MASK(0);
5146 *
5147 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
5148 * EC_VER_MASK(0);
5149 *
5150 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
5151 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08005152 */
5153#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
5154#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
5155
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005156/*
5157 * Given the private host command offset, calculate the true private host
5158 * command value.
5159 */
5160#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
5161 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
5162
Duncan Laurie93e24442014-01-06 12:30:52 -08005163/*****************************************************************************/
5164/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005165 * Passthru commands
5166 *
5167 * Some platforms have sub-processors chained to each other. For example.
5168 *
5169 * AP <--> EC <--> PD MCU
5170 *
5171 * The top 2 bits of the command number are used to indicate which device the
5172 * command is intended for. Device 0 is always the device receiving the
5173 * command; other device mapping is board-specific.
5174 *
5175 * When a device receives a command to be passed to a sub-processor, it passes
5176 * it on with the device number set back to 0. This allows the sub-processor
5177 * to remain blissfully unaware of whether the command originated on the next
5178 * device up the chain, or was passed through from the AP.
5179 *
5180 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
5181 * AP sends command 0x4002 to the EC
5182 * EC sends command 0x0002 to the PD MCU
5183 * EC forwards PD MCU response back to the AP
5184 */
5185
5186/* Offset and max command number for sub-device n */
5187#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
5188#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
5189
5190/*****************************************************************************/
5191/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005192 * Deprecated constants. These constants have been renamed for clarity. The
5193 * meaning and size has not changed. Programs that use the old names should
5194 * switch to the new names soon, as the old names may not be carried forward
5195 * forever.
5196 */
5197#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
5198#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
5199#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
5200
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005201#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005202
Duncan Laurieeb316852015-12-01 18:51:18 -08005203#endif /* __CROS_EC_EC_COMMANDS_H */