blob: d642d9eb64fae686b076d8a5e8480522891d4ffa [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
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080038#ifdef __cplusplus
39extern "C" {
40#endif
41
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070042#ifdef CHROMIUM_EC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080043/*
44 * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository.
45 * It is used to not include macros that may cause conflicts in foreign
46 * projects (refer to crbug.com/984623).
47 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070048
Duncan Laurie67f26cc2017-06-29 23:17:22 -070049/*
50 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
51 * generates more efficient code for accessing request/response structures on
52 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
53 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -070054#include "common.h"
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080055#include "compile_time_macros.h"
56
57#else
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080058#define BUILD_ASSERT(_cond)
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070059#endif /* CHROMIUM_EC */
60
61#ifdef __KERNEL__
62#include <linux/limits.h>
63#else
64/*
65 * Defines macros that may be needed but are for sure defined by the linux
66 * kernel. This section is removed when cros_ec_commands.h is generated (by
67 * util/make_linux_ec_commands_h.sh).
68 * cros_ec_commands.h looks more integrated to the kernel.
69 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080070
71#ifndef BIT
72#define BIT(nr) (1UL << (nr))
Duncan Laurie67f26cc2017-06-29 23:17:22 -070073#endif
74
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080075#ifndef BIT_ULL
76#define BIT_ULL(nr) (1ULL << (nr))
77#endif
78
Furquan Shaikhe6c04b92020-04-07 22:01:59 -070079#endif /* __KERNEL__ */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080080
Stefan Reinauerd6682e82013-02-21 15:39:35 -080081/*
Duncan Laurie93e24442014-01-06 12:30:52 -080082 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080083 *
Duncan Laurie93e24442014-01-06 12:30:52 -080084 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
85 * determined in other ways. Remove this once the kernel code no longer
86 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080087 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080088#define EC_PROTO_VERSION 0x00000002
89
90/* Command version mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080091#define EC_VER_MASK(version) BIT(version)
Stefan Reinauerd6682e82013-02-21 15:39:35 -080092
93/* I/O addresses for ACPI commands */
94#define EC_LPC_ADDR_ACPI_DATA 0x62
95#define EC_LPC_ADDR_ACPI_CMD 0x66
96
97/* I/O addresses for host command */
98#define EC_LPC_ADDR_HOST_DATA 0x200
99#define EC_LPC_ADDR_HOST_CMD 0x204
100
101/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -0800102/* Protocol version 2 */
103#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
104#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800105 * EC_PROTO2_MAX_PARAM_SIZE
106 */
Duncan Laurie93e24442014-01-06 12:30:52 -0800107/* Protocol version 3 */
108#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
109#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800110
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800111/*
112 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
113 * and they tell the kernel that so we have to think of it as two parts.
114 */
Bill Richardsone221aad2013-06-12 10:50:41 -0700115#define EC_HOST_CMD_REGION0 0x800
116#define EC_HOST_CMD_REGION1 0x880
117#define EC_HOST_CMD_REGION_SIZE 0x80
118
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800119/* EC command register bit functions */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800120#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
121#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
122#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
123#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
124#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
125#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
126#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800127
128#define EC_LPC_ADDR_MEMMAP 0x900
129#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
130#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
131
132/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700133#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
134#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
135#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
136#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800137#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
138#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
139#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
140#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
141#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700142#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
143/* Unused 0x28 - 0x2f */
144#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
145/* Unused 0x31 - 0x33 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600146#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
147/* Battery values are all 32 bits, unless otherwise noted. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800148#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
149#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
150#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600151#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
152#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
153#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
154/* Unused 0x4f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800155#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
156#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
157#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
158#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700159/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800160#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
161#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
162#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
163#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700164#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
165/* Unused 0x84 - 0x8f */
166#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
167/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800168#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
169/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
170/* 0x94 - 0x99: 1st Accelerometer */
171/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700172#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700173/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700174
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700175/*
176 * ACPI is unable to access memory mapped data at or above this offset due to
177 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
178 * which might be needed by ACPI.
179 */
180#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700181
182/* Define the format of the accelerometer mapped memory status byte. */
183#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800184#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
185#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800186
187/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
188#define EC_TEMP_SENSOR_ENTRIES 16
189/*
190 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
191 *
192 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
193 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700194#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800195
196/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700197#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
198#define EC_TEMP_SENSOR_ERROR 0xfe
199#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
200#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800201/*
202 * The offset of temperature value stored in mapped memory. This allows
203 * reporting a temperature range of 200K to 454K = -73C to 181C.
204 */
205#define EC_TEMP_SENSOR_OFFSET 200
206
Duncan Laurie93e24442014-01-06 12:30:52 -0800207/*
208 * Number of ALS readings at EC_MEMMAP_ALS
209 */
210#define EC_ALS_ENTRIES 2
211
212/*
213 * The default value a temperature sensor will return when it is present but
214 * has not been read this boot. This is a reasonable number to avoid
215 * triggering alarms on the host.
216 */
217#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
218
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800219#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
220#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
221#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
222
223/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
224#define EC_BATT_FLAG_AC_PRESENT 0x01
225#define EC_BATT_FLAG_BATT_PRESENT 0x02
226#define EC_BATT_FLAG_DISCHARGING 0x04
227#define EC_BATT_FLAG_CHARGING 0x08
228#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600229/* Set if some of the static/dynamic data is invalid (or outdated). */
230#define EC_BATT_FLAG_INVALID_DATA 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800231
232/* Switch flags at EC_MEMMAP_SWITCHES */
233#define EC_SWITCH_LID_OPEN 0x01
234#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
235#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700236/* Was recovery requested via keyboard; now unused. */
237#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800238/* Recovery requested via dedicated signal (from servo board) */
239#define EC_SWITCH_DEDICATED_RECOVERY 0x10
240/* Was fake developer mode switch; now unused. Remove in next refactor. */
241#define EC_SWITCH_IGNORE0 0x20
242
243/* Host command interface flags */
244/* Host command interface supports LPC args (LPC interface only) */
245#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800246/* Host command interface supports version 3 protocol */
247#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800248
249/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800250#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
251#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
252#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
253#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
254#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800255
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700256/*****************************************************************************/
257/*
258 * ACPI commands
259 *
260 * These are valid ONLY on the ACPI command/data port.
261 */
262
263/*
264 * ACPI Read Embedded Controller
265 *
266 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
267 *
268 * Use the following sequence:
269 *
270 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
271 * - Wait for EC_LPC_CMDR_PENDING bit to clear
272 * - Write address to EC_LPC_ADDR_ACPI_DATA
273 * - Wait for EC_LPC_CMDR_DATA bit to set
274 * - Read value from EC_LPC_ADDR_ACPI_DATA
275 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700276#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700277
278/*
279 * ACPI Write Embedded Controller
280 *
281 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
282 *
283 * Use the following sequence:
284 *
285 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
286 * - Wait for EC_LPC_CMDR_PENDING bit to clear
287 * - Write address to EC_LPC_ADDR_ACPI_DATA
288 * - Wait for EC_LPC_CMDR_PENDING bit to clear
289 * - Write value to EC_LPC_ADDR_ACPI_DATA
290 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700291#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700292
293/*
294 * ACPI Burst Enable Embedded Controller
295 *
296 * This enables burst mode on the EC to allow the host to issue several
297 * commands back-to-back. While in this mode, writes to mapped multi-byte
298 * data are locked out to ensure data consistency.
299 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700300#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700301
302/*
303 * ACPI Burst Disable Embedded Controller
304 *
305 * This disables burst mode on the EC and stops preventing EC writes to mapped
306 * multi-byte data.
307 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700308#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700309
310/*
311 * ACPI Query Embedded Controller
312 *
313 * This clears the lowest-order bit in the currently pending host events, and
314 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
315 * event 0x80000000 = 32), or 0 if no event was pending.
316 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700317#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700318
319/* Valid addresses in ACPI memory space, for read/write commands */
320
321/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
322#define EC_ACPI_MEM_VERSION 0x00
323/*
324 * Test location; writing value here updates test compliment byte to (0xff -
325 * value).
326 */
327#define EC_ACPI_MEM_TEST 0x01
328/* Test compliment; writes here are ignored. */
329#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
330
331/* Keyboard backlight brightness percent (0 - 100) */
332#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
333/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
334#define EC_ACPI_MEM_FAN_DUTY 0x04
335
336/*
337 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
338 * independent thresholds attached to them. The current value of the ID
339 * register determines which sensor is affected by the THRESHOLD and COMMIT
340 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
341 * as the memory-mapped sensors. The COMMIT register applies those settings.
342 *
343 * The spec does not mandate any way to read back the threshold settings
344 * themselves, but when a threshold is crossed the AP needs a way to determine
345 * which sensor(s) are responsible. Each reading of the ID register clears and
346 * returns one sensor ID that has crossed one of its threshold (in either
347 * direction) since the last read. A value of 0xFF means "no new thresholds
348 * have tripped". Setting or enabling the thresholds for a sensor will clear
349 * the unread event count for that sensor.
350 */
351#define EC_ACPI_MEM_TEMP_ID 0x05
352#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
353#define EC_ACPI_MEM_TEMP_COMMIT 0x07
354/*
355 * Here are the bits for the COMMIT register:
356 * bit 0 selects the threshold index for the chosen sensor (0/1)
357 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
358 * Each write to the commit register affects one threshold.
359 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800360#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
361#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700362/*
363 * Example:
364 *
365 * Set the thresholds for sensor 2 to 50 C and 60 C:
366 * write 2 to [0x05] -- select temp sensor 2
367 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
368 * write 0x2 to [0x07] -- enable threshold 0 with this value
369 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
370 * write 0x3 to [0x07] -- enable threshold 1 with this value
371 *
372 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
373 * write 2 to [0x05] -- select temp sensor 2
374 * write 0x1 to [0x07] -- disable threshold 1
375 */
376
377/* DPTF battery charging current limit */
378#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
379
380/* Charging limit is specified in 64 mA steps */
381#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
382/* Value to disable DPTF battery charging limit */
383#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700384
jiazi Yang51fc93f2016-07-28 05:15:01 -0400385/*
386 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800387 * Bits Definition
388 * 3:1 Device DPTF Profile Number (DDPN)
389 * 0 = Reserved for backward compatibility (indicates no valid
390 * profile number. Host should fall back to using TBMD).
391 * 1..7 = DPTF Profile number to indicate to host which table needs
392 * to be loaded.
393 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400394 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700395#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800396#define EC_ACPI_MEM_TBMD_SHIFT 0
397#define EC_ACPI_MEM_TBMD_MASK 0x1
398#define EC_ACPI_MEM_DDPN_SHIFT 1
399#define EC_ACPI_MEM_DDPN_MASK 0x7
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700400
401/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600402 * Report device features. Uses the same format as the host command, except:
403 *
404 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
405 * of features", which is of limited interest when the system is already
406 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
407 * these are supported, it defaults to 0.
408 * This allows detecting the presence of this field since older versions of
409 * the EC codebase would simply return 0xff to that unknown address. Check
410 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
411 * are valid.
412 */
413#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
414#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
415#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
416#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
417#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
418#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
419#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
420#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
421
422#define EC_ACPI_MEM_BATTERY_INDEX 0x12
423
424/*
425 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
426 * is enabled (1) or disabled (0).
427 * bit 0 USB port ID 0
428 * ...
429 * bit 7 USB port ID 7
430 */
431#define EC_ACPI_MEM_USB_PORT_POWER 0x13
432
433/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700434 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
435 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
436 */
437#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
438#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
439
440/* Current version of ACPI memory address space */
441#define EC_ACPI_MEM_VERSION_CURRENT 2
442
443
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800444/*
445 * This header file is used in coreboot both in C and ACPI code. The ACPI code
446 * is pre-processed to handle constants but the ASL compiler is unable to
447 * handle actual C code so keep it separate.
448 */
449#ifndef __ACPI__
450
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800451#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800452/*
453 * Define __packed if someone hasn't beat us to it. Linux kernel style
454 * checking prefers __packed over __attribute__((packed)).
455 */
456#ifndef __packed
457#define __packed __attribute__((packed))
458#endif
459
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700460#ifndef __aligned
461#define __aligned(x) __attribute__((aligned(x)))
462#endif
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800463#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700464
465/*
466 * Attributes for EC request and response packets. Just defining __packed
467 * results in inefficient assembly code on ARM, if the structure is actually
468 * 32-bit aligned, as it should be for all buffers.
469 *
470 * Be very careful when adding these to existing structures. They will round
471 * up the structure size to the specified boundary.
472 *
473 * Also be very careful to make that if a structure is included in some other
474 * parent structure that the alignment will still be true given the packing of
475 * the parent structure. This is particularly important if the sub-structure
476 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200477 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700478 *
479 * Also be very careful using __packed - particularly when nesting non-packed
480 * structures inside packed ones. In fact, DO NOT use __packed directly;
481 * always use one of these attributes.
482 *
483 * Once everything is annotated properly, the following search strings should
484 * not return ANY matches in this file other than right here:
485 *
486 * "__packed" - generates inefficient code; all sub-structs must also be packed
487 *
488 * "struct [^_]" - all structs should be annotated, except for structs that are
489 * members of other structs/unions (and their original declarations should be
490 * annotated).
491 */
492#ifdef CONFIG_HOSTCMD_ALIGNED
493
494/*
495 * Packed structures where offset and size are always aligned to 1, 2, or 4
496 * byte boundary.
497 */
498#define __ec_align1 __packed
499#define __ec_align2 __packed __aligned(2)
500#define __ec_align4 __packed __aligned(4)
501
502/*
503 * Packed structure which must be under-aligned, because its size is not a
504 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
505 * of all multi-byte fields in it, even though they are themselves aligned.
506 *
507 * In theory, we could duplicate the structure with __aligned(4) for accessing
508 * its members, but use the __packed version for sizeof().
509 */
510#define __ec_align_size1 __packed
511
512/*
513 * Packed structure which must be under-aligned, because its offset inside a
514 * parent structure is not a 4-byte multiple.
515 */
516#define __ec_align_offset1 __packed
517#define __ec_align_offset2 __packed __aligned(2)
518
519/*
520 * Structures which are complicated enough that I'm skipping them on the first
521 * pass. They are effectively unchanged from their previous definitions.
522 *
523 * TODO(rspangler): Figure out what to do with these. It's likely necessary
524 * to work out the size and offset of each member and add explicit padding to
525 * maintain those.
526 */
527#define __ec_todo_packed __packed
528#define __ec_todo_unpacked
529
530#else /* !CONFIG_HOSTCMD_ALIGNED */
531
532/*
533 * Packed structures make no assumption about alignment, so they do inefficient
534 * byte-wise reads.
535 */
536#define __ec_align1 __packed
537#define __ec_align2 __packed
538#define __ec_align4 __packed
539#define __ec_align_size1 __packed
540#define __ec_align_offset1 __packed
541#define __ec_align_offset2 __packed
542#define __ec_todo_packed __packed
543#define __ec_todo_unpacked
544
545#endif /* !CONFIG_HOSTCMD_ALIGNED */
546
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800547/* LPC command status byte masks */
548/* EC has written a byte in the data register and host hasn't read it yet */
549#define EC_LPC_STATUS_TO_HOST 0x01
550/* Host has written a command/data byte and the EC hasn't read it yet */
551#define EC_LPC_STATUS_FROM_HOST 0x02
552/* EC is processing a command */
553#define EC_LPC_STATUS_PROCESSING 0x04
554/* Last write to EC was a command, not data */
555#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700556/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800557#define EC_LPC_STATUS_BURST_MODE 0x10
558/* SCI event is pending (requesting SCI query) */
559#define EC_LPC_STATUS_SCI_PENDING 0x20
560/* SMI event is pending (requesting SMI query) */
561#define EC_LPC_STATUS_SMI_PENDING 0x40
562/* (reserved) */
563#define EC_LPC_STATUS_RESERVED 0x80
564
565/*
566 * EC is busy. This covers both the EC processing a command, and the host has
567 * written a new command but the EC hasn't picked it up yet.
568 */
569#define EC_LPC_STATUS_BUSY_MASK \
570 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
571
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800572/*
Jett Rinkba2edaf2020-01-14 11:49:06 -0700573 * Host command response codes (16-bit).
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700574 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800575enum ec_status {
576 EC_RES_SUCCESS = 0,
577 EC_RES_INVALID_COMMAND = 1,
578 EC_RES_ERROR = 2,
579 EC_RES_INVALID_PARAM = 3,
580 EC_RES_ACCESS_DENIED = 4,
581 EC_RES_INVALID_RESPONSE = 5,
582 EC_RES_INVALID_VERSION = 6,
583 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700584 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
585 EC_RES_UNAVAILABLE = 9, /* No response available */
586 EC_RES_TIMEOUT = 10, /* We got a timeout */
587 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800588 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
589 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700590 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700591 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600592 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
593 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
594 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
595 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
596 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Jett Rinkba2edaf2020-01-14 11:49:06 -0700597
598 EC_RES_MAX = UINT16_MAX /**< Force enum to be 16 bits */
599} __packed;
600BUILD_ASSERT(sizeof(enum ec_status) == sizeof(uint16_t));
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800601
602/*
603 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
604 * EC command uses code 0 to mean "no event pending". We explicitly specify
605 * each value in the enum listing so they won't change if we delete/insert an
606 * item or rearrange the list (it needs to be stable across platforms, not
607 * just within a single compiled instance).
608 */
609enum host_event_code {
610 EC_HOST_EVENT_LID_CLOSED = 1,
611 EC_HOST_EVENT_LID_OPEN = 2,
612 EC_HOST_EVENT_POWER_BUTTON = 3,
613 EC_HOST_EVENT_AC_CONNECTED = 4,
614 EC_HOST_EVENT_AC_DISCONNECTED = 5,
615 EC_HOST_EVENT_BATTERY_LOW = 6,
616 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
617 EC_HOST_EVENT_BATTERY = 8,
618 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700619 /* Event generated by a device attached to the EC */
620 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800621 EC_HOST_EVENT_THERMAL = 11,
622 EC_HOST_EVENT_USB_CHARGER = 12,
623 EC_HOST_EVENT_KEY_PRESSED = 13,
624 /*
625 * EC has finished initializing the host interface. The host can check
626 * for this event following sending a EC_CMD_REBOOT_EC command to
627 * determine when the EC is ready to accept subsequent commands.
628 */
629 EC_HOST_EVENT_INTERFACE_READY = 14,
630 /* Keyboard recovery combo has been pressed */
631 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
632
633 /* Shutdown due to thermal overload */
634 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
635 /* Shutdown due to battery level too low */
636 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
637
Duncan Laurie93e24442014-01-06 12:30:52 -0800638 /* Suggest that the AP throttle itself */
639 EC_HOST_EVENT_THROTTLE_START = 18,
640 /* Suggest that the AP resume normal speed */
641 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700642
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800643 /* Hang detect logic detected a hang and host event timeout expired */
644 EC_HOST_EVENT_HANG_DETECT = 20,
645 /* Hang detect logic detected a hang and warm rebooted the AP */
646 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700647
648 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700649 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800650
Duncan Lauried8401182014-09-29 08:32:19 -0700651 /* Battery Status flags have changed */
652 EC_HOST_EVENT_BATTERY_STATUS = 23,
653
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700654 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800655 EC_HOST_EVENT_PANIC = 24,
656
Furquan Shaikh066cc852015-06-20 15:53:03 -0700657 /* Keyboard fastboot combo has been pressed */
658 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
659
Gwendal Grignou880b4582016-06-20 08:49:25 -0700660 /* EC RTC event occurred */
661 EC_HOST_EVENT_RTC = 26,
662
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700663 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700664 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700665
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700666 /* EC desires to change state of host-controlled USB mux */
667 EC_HOST_EVENT_USB_MUX = 28,
668
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800669 /*
670 * The device has changed "modes". This can be one of the following:
671 *
672 * - TABLET/LAPTOP mode
673 * - detachable base attach/detach event
674 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400675 EC_HOST_EVENT_MODE_CHANGE = 29,
676
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700677 /* Keyboard recovery combo with hardware reinitialization */
678 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
679
Jett Rinkba2edaf2020-01-14 11:49:06 -0700680 /* WoV */
681 EC_HOST_EVENT_WOV = 31,
682
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700683 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800684 * The high bit of the event mask is not used as a host event code. If
685 * it reads back as set, then the entire event mask should be
686 * considered invalid by the host. This can happen when reading the
687 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
688 * not initialized on the EC, or improperly configured on the host.
689 */
690 EC_HOST_EVENT_INVALID = 32
691};
692/* Host event mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800693#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800694
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800695/**
696 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
697 * @flags: The host argument flags.
698 * @command_version: Command version.
699 * @data_size: The length of data.
700 * @checksum: Checksum; sum of command + flags + command_version + data_size +
701 * all params/response data bytes.
702 */
703struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800704 uint8_t flags;
705 uint8_t command_version;
706 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800707 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800708} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800709
710/* Flags for ec_lpc_host_args.flags */
711/*
712 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
713 * params.
714 *
715 * If EC gets a command and this flag is not set, this is an old-style command.
716 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
717 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700718 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800719 */
720#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
721/*
722 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
723 *
724 * If EC responds to a command and this flag is not set, this is an old-style
725 * response. Command version is 0 and response data from EC is at
726 * EC_LPC_ADDR_OLD_PARAM with unknown length.
727 */
728#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
729
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800730/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800731/*
732 * Byte codes returned by EC over SPI interface.
733 *
734 * These can be used by the AP to debug the EC interface, and to determine
735 * when the EC is not in a state where it will ever get around to responding
736 * to the AP.
737 *
738 * Example of sequence of bytes read from EC for a current good transfer:
739 * 1. - - AP asserts chip select (CS#)
740 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
741 * 3. - - EC starts handling CS# interrupt
742 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
743 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
744 * bytes looking for EC_SPI_FRAME_START
745 * 6. - - EC finishes processing and sets up response
746 * 7. EC_SPI_FRAME_START - AP reads frame byte
747 * 8. (response packet) - AP reads response packet
748 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
749 * 10 - - AP deasserts chip select
750 * 11 - - EC processes CS# interrupt and sets up DMA for
751 * next request
752 *
753 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
754 * the following byte values:
755 * EC_SPI_OLD_READY
756 * EC_SPI_RX_READY
757 * EC_SPI_RECEIVING
758 * EC_SPI_PROCESSING
759 *
760 * Then the EC found an error in the request, or was not ready for the request
761 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
762 * because the EC is unable to tell when the AP is done sending its request.
763 */
764
765/*
766 * Framing byte which precedes a response packet from the EC. After sending a
767 * request, the AP will clock in bytes until it sees the framing byte, then
768 * clock in the response packet.
769 */
770#define EC_SPI_FRAME_START 0xec
771
772/*
773 * Padding bytes which are clocked out after the end of a response packet.
774 */
775#define EC_SPI_PAST_END 0xed
776
777/*
778 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
779 * that the AP will send a valid packet header (starting with
780 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
781 */
782#define EC_SPI_RX_READY 0xf8
783
784/*
785 * EC has started receiving the request from the AP, but hasn't started
786 * processing it yet.
787 */
788#define EC_SPI_RECEIVING 0xf9
789
790/* EC has received the entire request from the AP and is processing it. */
791#define EC_SPI_PROCESSING 0xfa
792
793/*
794 * EC received bad data from the AP, such as a packet header with an invalid
795 * length. EC will ignore all data until chip select deasserts.
796 */
797#define EC_SPI_RX_BAD_DATA 0xfb
798
799/*
800 * EC received data from the AP before it was ready. That is, the AP asserted
801 * chip select and started clocking data before the EC was ready to receive it.
802 * EC will ignore all data until chip select deasserts.
803 */
804#define EC_SPI_NOT_READY 0xfc
805
806/*
807 * EC was ready to receive a request from the AP. EC has treated the byte sent
808 * by the AP as part of a request packet, or (for old-style ECs) is processing
809 * a fully received packet but is not ready to respond yet.
810 */
811#define EC_SPI_OLD_READY 0xfd
812
813/*****************************************************************************/
814
815/*
816 * Protocol version 2 for I2C and SPI send a request this way:
817 *
818 * 0 EC_CMD_VERSION0 + (command version)
819 * 1 Command number
820 * 2 Length of params = N
821 * 3..N+2 Params, if any
822 * N+3 8-bit checksum of bytes 0..N+2
823 *
824 * The corresponding response is:
825 *
826 * 0 Result code (EC_RES_*)
827 * 1 Length of params = M
828 * 2..M+1 Params, if any
829 * M+2 8-bit checksum of bytes 0..M+1
830 */
831#define EC_PROTO2_REQUEST_HEADER_BYTES 3
832#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
833#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
834 EC_PROTO2_REQUEST_TRAILER_BYTES)
835
836#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
837#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
838#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
839 EC_PROTO2_RESPONSE_TRAILER_BYTES)
840
841/* Parameter length was limited by the LPC interface */
842#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
843
844/* Maximum request and response packet sizes for protocol version 2 */
845#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
846 EC_PROTO2_MAX_PARAM_SIZE)
847#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
848 EC_PROTO2_MAX_PARAM_SIZE)
849
850/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800851
852/*
853 * Value written to legacy command port / prefix byte to indicate protocol
854 * 3+ structs are being used. Usage is bus-dependent.
855 */
856#define EC_COMMAND_PROTOCOL_3 0xda
857
858#define EC_HOST_REQUEST_VERSION 3
859
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800860/**
861 * struct ec_host_request - Version 3 request from host.
862 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
863 * receives a header with a version it doesn't know how to
864 * parse.
865 * @checksum: Checksum of request and data; sum of all bytes including checksum
866 * should total to 0.
867 * @command: Command to send (EC_CMD_...)
868 * @command_version: Command version.
869 * @reserved: Unused byte in current protocol version; set to 0.
870 * @data_len: Length of data which follows this header.
871 */
872struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800873 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800874 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800875 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800876 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800877 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800878 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800879} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800880
881#define EC_HOST_RESPONSE_VERSION 3
882
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800883/**
884 * struct ec_host_response - Version 3 response from EC.
885 * @struct_version: Struct version (=3).
886 * @checksum: Checksum of response and data; sum of all bytes including
887 * checksum should total to 0.
888 * @result: EC's response to the command (separate from communication failure)
889 * @data_len: Length of data which follows this header.
890 * @reserved: Unused bytes in current protocol version; set to 0.
891 */
892struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800893 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800894 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800895 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800896 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800897 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800898} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800899
900/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600901
902/*
903 * Host command protocol V4.
904 *
905 * Packets always start with a request or response header. They are followed
906 * by data_len bytes of data. If the data_crc_present flag is set, the data
907 * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1
908 * polynomial.
909 *
910 * Host algorithm when sending a request q:
911 *
912 * 101) tries_left=(some value, e.g. 3);
913 * 102) q.seq_num++
914 * 103) q.seq_dup=0
915 * 104) Calculate q.header_crc.
916 * 105) Send request q to EC.
917 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
918 *
919 * 201) If r.struct_version != 4, go to 301.
920 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
921 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
922 * 204) If r.seq_num != q.seq_num, go to 301.
923 * 205) If r.seq_dup == q.seq_dup, return success.
924 * 207) If r.seq_dup == 1, go to 301.
925 * 208) Return error.
926 *
927 * 301) If --tries_left <= 0, return error.
928 * 302) If q.seq_dup == 1, go to 105.
929 * 303) q.seq_dup = 1
930 * 304) Go to 104.
931 *
932 * EC algorithm when receiving a request q.
933 * EC has response buffer r, error buffer e.
934 *
935 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
936 * and go to 301
937 * 102) If q.header_crc mismatches calculated CRC, set e.result =
938 * EC_RES_INVALID_HEADER_CRC and go to 301
939 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
940 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
941 * and go to 301.
942 * 104) If q.seq_dup == 0, go to 201.
943 * 105) If q.seq_num != r.seq_num, go to 201.
944 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
945 *
946 * 201) Process request q into response r.
947 * 202) r.seq_num = q.seq_num
948 * 203) r.seq_dup = q.seq_dup
949 * 204) Calculate r.header_crc
950 * 205) If r.data_len > 0 and data is no longer available, set e.result =
951 * EC_RES_DUP_UNAVAILABLE and go to 301.
952 * 206) Send response r.
953 *
954 * 301) e.seq_num = q.seq_num
955 * 302) e.seq_dup = q.seq_dup
956 * 303) Calculate e.header_crc.
957 * 304) Send error response e.
958 */
959
960/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800961struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600962 /*
963 * bits 0-3: struct_version: Structure version (=4)
964 * bit 4: is_response: Is response (=0)
965 * bits 5-6: seq_num: Sequence number
966 * bit 7: seq_dup: Sequence duplicate flag
967 */
968 uint8_t fields0;
969
970 /*
971 * bits 0-4: command_version: Command version
972 * bits 5-6: Reserved (set 0, ignore on read)
973 * bit 7: data_crc_present: Is data CRC present after data
974 */
975 uint8_t fields1;
976
977 /* Command code (EC_CMD_*) */
978 uint16_t command;
979
980 /* Length of data which follows this header (not including data CRC) */
981 uint16_t data_len;
982
983 /* Reserved (set 0, ignore on read) */
984 uint8_t reserved;
985
986 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
987 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800988} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600989
990/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800991struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600992 /*
993 * bits 0-3: struct_version: Structure version (=4)
994 * bit 4: is_response: Is response (=1)
995 * bits 5-6: seq_num: Sequence number
996 * bit 7: seq_dup: Sequence duplicate flag
997 */
998 uint8_t fields0;
999
1000 /*
1001 * bits 0-6: Reserved (set 0, ignore on read)
1002 * bit 7: data_crc_present: Is data CRC present after data
1003 */
1004 uint8_t fields1;
1005
1006 /* Result code (EC_RES_*) */
1007 uint16_t result;
1008
1009 /* Length of data which follows this header (not including data CRC) */
1010 uint16_t data_len;
1011
1012 /* Reserved (set 0, ignore on read) */
1013 uint8_t reserved;
1014
1015 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1016 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001017} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001018
1019/* Fields in fields0 byte */
1020#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1021#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1022#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1023#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1024#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
1025
1026/* Fields in fields1 byte */
1027#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1028#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1029
1030/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001031/*
1032 * Notes on commands:
1033 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001034 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001035 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001036 * specified, the command does not input or output data, respectively.
1037 * Parameter/response length is implicit in the structs. Some underlying
1038 * communication protocols (I2C, SPI) may add length or checksum headers, but
1039 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001040 *
1041 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1042 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001043 */
1044
1045/*****************************************************************************/
1046/* General / test commands */
1047
1048/*
1049 * Get protocol version, used to deal with non-backward compatible protocol
1050 * changes.
1051 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001052#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001053
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001054/**
1055 * struct ec_response_proto_version - Response to the proto version command.
1056 * @version: The protocol version.
1057 */
1058struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001059 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001060} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001061
1062/*
1063 * Hello. This is a simple command to test the EC is responsive to
1064 * commands.
1065 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001066#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001067
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001068/**
1069 * struct ec_params_hello - Parameters to the hello command.
1070 * @in_data: Pass anything here.
1071 */
1072struct ec_params_hello {
1073 uint32_t in_data;
1074} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001075
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001076/**
1077 * struct ec_response_hello - Response to the hello command.
1078 * @out_data: Output will be in_data + 0x01020304.
1079 */
1080struct ec_response_hello {
1081 uint32_t out_data;
1082} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001083
1084/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001085#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001086
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001087#if !defined(CHROMIUM_EC) && !defined(__KERNEL__)
1088/*
1089 * enum ec_current_image is deprecated and replaced by enum ec_image. This
1090 * macro exists for backwards compatibility of external projects until they
1091 * have been updated: b/149987779.
1092 */
1093#define ec_current_image ec_image
1094#endif
1095
1096enum ec_image {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001097 EC_IMAGE_UNKNOWN = 0,
1098 EC_IMAGE_RO,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001099 EC_IMAGE_RW,
1100 EC_IMAGE_RW_A = EC_IMAGE_RW,
1101 EC_IMAGE_RO_B,
1102 EC_IMAGE_RW_B
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001103};
1104
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001105/**
1106 * struct ec_response_get_version - Response to the get version command.
1107 * @version_string_ro: Null-terminated RO firmware version string.
1108 * @version_string_rw: Null-terminated RW firmware version string.
1109 * @reserved: Unused bytes; was previously RW-B firmware version string.
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001110 * @current_image: One of ec_image.
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001111 */
1112struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001113 char version_string_ro[32];
1114 char version_string_rw[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001115 char reserved[32];
1116 uint32_t current_image;
1117} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001118
1119/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001120#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001121
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001122/**
1123 * struct ec_params_read_test - Parameters for the read test command.
1124 * @offset: Starting value for read buffer.
1125 * @size: Size to read in bytes.
1126 */
1127struct ec_params_read_test {
1128 uint32_t offset;
1129 uint32_t size;
1130} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001131
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001132/**
1133 * struct ec_response_read_test - Response to the read test command.
1134 * @data: Data returned by the read test command.
1135 */
1136struct ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001137 uint32_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001138} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001139
1140/*
1141 * Get build information
1142 *
1143 * Response is null-terminated string.
1144 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001145#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001146
1147/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001148#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001149
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001150/**
1151 * struct ec_response_get_chip_info - Response to the get chip info command.
1152 * @vendor: Null-terminated string for chip vendor.
1153 * @name: Null-terminated string for chip name.
1154 * @revision: Null-terminated string for chip mask version.
1155 */
1156struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001157 char vendor[32];
1158 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001159 char revision[32];
1160} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001161
1162/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001163#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001164
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001165/**
1166 * struct ec_response_board_version - Response to the board version command.
1167 * @board_version: A monotonously incrementing number.
1168 */
1169struct ec_response_board_version {
1170 uint16_t board_version;
1171} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001172
1173/*
1174 * Read memory-mapped data.
1175 *
1176 * This is an alternate interface to memory-mapped data for bus protocols
1177 * which don't support direct-mapped memory - I2C, SPI, etc.
1178 *
1179 * Response is params.size bytes of data.
1180 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001181#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001182
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001183/**
1184 * struct ec_params_read_memmap - Parameters for the read memory map command.
1185 * @offset: Offset in memmap (EC_MEMMAP_*).
1186 * @size: Size to read in bytes.
1187 */
1188struct ec_params_read_memmap {
1189 uint8_t offset;
1190 uint8_t size;
1191} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001192
1193/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001194#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001195
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001196/**
1197 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1198 * @cmd: Command to check.
1199 */
1200struct ec_params_get_cmd_versions {
1201 uint8_t cmd;
1202} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001203
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001204/**
1205 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1206 * versions (v1)
1207 * @cmd: Command to check.
1208 */
1209struct ec_params_get_cmd_versions_v1 {
1210 uint16_t cmd;
1211} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001212
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001213/**
1214 * struct ec_response_get_cmd_version - Response to the get command versions.
1215 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1216 * a desired version.
1217 */
1218struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001219 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001220} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001221
Duncan Laurie433432b2013-06-03 10:38:22 -07001222/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001223 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001224 * on lpc since it has its own out-of-band busy indicator.
1225 *
1226 * lpc must read the status from the command register. Attempting this on
1227 * lpc will overwrite the args/parameter space and corrupt its data.
1228 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001229#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001230
1231/* Avoid using ec_status which is for return values */
1232enum ec_comms_status {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001233 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001234};
1235
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001236/**
1237 * struct ec_response_get_comms_status - Response to the get comms status
1238 * command.
1239 * @flags: Mask of enum ec_comms_status.
1240 */
1241struct ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001242 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001243} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001244
Duncan Laurie93e24442014-01-06 12:30:52 -08001245/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001246#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001247
1248/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001249struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001250 uint32_t ec_result;
1251 uint32_t ret_len;
1252 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001253} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001254
1255/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001256struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001257 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001258} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001259
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001260/* Get protocol information */
1261#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001262
1263/* Flags for ec_response_get_protocol_info.flags */
1264/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001265#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001266
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001267/**
1268 * struct ec_response_get_protocol_info - Response to the get protocol info.
1269 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1270 * version n).
1271 * @max_request_packet_size: Maximum request packet size in bytes.
1272 * @max_response_packet_size: Maximum response packet size in bytes.
1273 * @flags: see EC_PROTOCOL_INFO_*
1274 */
1275struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001276 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001277 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001278 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001279 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001280 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001281} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001282
1283
1284/*****************************************************************************/
1285/* Get/Set miscellaneous values */
1286
1287/* The upper byte of .flags tells what to do (nothing means "get") */
1288#define EC_GSV_SET 0x80000000
1289
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001290/*
1291 * The lower three bytes of .flags identifies the parameter, if that has
1292 * meaning for an individual command.
1293 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001294#define EC_GSV_PARAM_MASK 0x00ffffff
1295
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001296struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001297 uint32_t flags;
1298 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001299} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001300
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001301struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001302 uint32_t flags;
1303 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001304} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001305
Duncan Laurieeb316852015-12-01 18:51:18 -08001306/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001307#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001308
Duncan Laurieeb316852015-12-01 18:51:18 -08001309/*****************************************************************************/
1310/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001311#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001312
1313/* Supported features */
1314enum ec_feature_code {
1315 /*
1316 * This image contains a limited set of features. Another image
1317 * in RW partition may support more features.
1318 */
1319 EC_FEATURE_LIMITED = 0,
1320 /*
1321 * Commands for probing/reading/writing/erasing the flash in the
1322 * EC are present.
1323 */
1324 EC_FEATURE_FLASH = 1,
1325 /*
1326 * Can control the fan speed directly.
1327 */
1328 EC_FEATURE_PWM_FAN = 2,
1329 /*
1330 * Can control the intensity of the keyboard backlight.
1331 */
1332 EC_FEATURE_PWM_KEYB = 3,
1333 /*
1334 * Support Google lightbar, introduced on Pixel.
1335 */
1336 EC_FEATURE_LIGHTBAR = 4,
1337 /* Control of LEDs */
1338 EC_FEATURE_LED = 5,
1339 /* Exposes an interface to control gyro and sensors.
1340 * The host goes through the EC to access these sensors.
1341 * In addition, the EC may provide composite sensors, like lid angle.
1342 */
1343 EC_FEATURE_MOTION_SENSE = 6,
1344 /* The keyboard is controlled by the EC */
1345 EC_FEATURE_KEYB = 7,
1346 /* The AP can use part of the EC flash as persistent storage. */
1347 EC_FEATURE_PSTORE = 8,
1348 /* The EC monitors BIOS port 80h, and can return POST codes. */
1349 EC_FEATURE_PORT80 = 9,
1350 /*
1351 * Thermal management: include TMP specific commands.
1352 * Higher level than direct fan control.
1353 */
1354 EC_FEATURE_THERMAL = 10,
1355 /* Can switch the screen backlight on/off */
1356 EC_FEATURE_BKLIGHT_SWITCH = 11,
1357 /* Can switch the wifi module on/off */
1358 EC_FEATURE_WIFI_SWITCH = 12,
1359 /* Monitor host events, through for example SMI or SCI */
1360 EC_FEATURE_HOST_EVENTS = 13,
1361 /* The EC exposes GPIO commands to control/monitor connected devices. */
1362 EC_FEATURE_GPIO = 14,
1363 /* The EC can send i2c messages to downstream devices. */
1364 EC_FEATURE_I2C = 15,
1365 /* Command to control charger are included */
1366 EC_FEATURE_CHARGER = 16,
1367 /* Simple battery support. */
1368 EC_FEATURE_BATTERY = 17,
1369 /*
1370 * Support Smart battery protocol
1371 * (Common Smart Battery System Interface Specification)
1372 */
1373 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001374 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001375 EC_FEATURE_HANG_DETECT = 19,
1376 /* Report power information, for pit only */
1377 EC_FEATURE_PMU = 20,
1378 /* Another Cros EC device is present downstream of this one */
1379 EC_FEATURE_SUB_MCU = 21,
1380 /* Support USB Power delivery (PD) commands */
1381 EC_FEATURE_USB_PD = 22,
1382 /* Control USB multiplexer, for audio through USB port for instance. */
1383 EC_FEATURE_USB_MUX = 23,
1384 /* Motion Sensor code has an internal software FIFO */
1385 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1386 /* Support temporary secure vstore */
1387 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001388 /* EC decides on USB-C SS mux state, muxes configured by host */
1389 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1390 /* EC has RTC feature that can be controlled by host commands */
1391 EC_FEATURE_RTC = 27,
1392 /* The MCU exposes a Fingerprint sensor */
1393 EC_FEATURE_FINGERPRINT = 28,
1394 /* The MCU exposes a Touchpad */
1395 EC_FEATURE_TOUCHPAD = 29,
1396 /* The MCU has RWSIG task enabled */
1397 EC_FEATURE_RWSIG = 30,
1398 /* EC has device events support */
1399 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001400 /* EC supports the unified wake masks for LPC/eSPI systems */
1401 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001402 /* EC supports 64-bit host events */
1403 EC_FEATURE_HOST_EVENT64 = 33,
1404 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1405 EC_FEATURE_EXEC_IN_RAM = 34,
1406 /* EC supports CEC commands */
1407 EC_FEATURE_CEC = 35,
1408 /* EC supports tight sensor timestamping. */
1409 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001410 /*
1411 * EC supports tablet mode detection aligned to Chrome and allows
1412 * setting of threshold by host command using
1413 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1414 */
1415 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001416 /*
1417 * Early Firmware Selection ver.2. Enabled by CONFIG_VBOOT_EFS2.
1418 * Note this is a RO feature. So, a query (EC_CMD_GET_FEATURES) should
1419 * be sent to RO to be precise.
1420 */
1421 EC_FEATURE_EFS2 = 38,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001422 /* The MCU is a System Companion Processor (SCP). */
1423 EC_FEATURE_SCP = 39,
1424 /* The MCU is an Integrated Sensor Hub */
1425 EC_FEATURE_ISH = 40,
Duncan Laurieeb316852015-12-01 18:51:18 -08001426};
1427
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001428#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1429#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1430
1431struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001432 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001433} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001434
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001435/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001436/* Get the board's SKU ID from EC */
1437#define EC_CMD_GET_SKU_ID 0x000E
1438
Kevin Chiue2bb0592017-09-12 09:13:41 +08001439/* Set SKU ID from AP */
1440#define EC_CMD_SET_SKU_ID 0x000F
1441
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001442struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001443 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001444} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001445
1446/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001447/* Flash commands */
1448
1449/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001450#define EC_CMD_FLASH_INFO 0x0010
1451#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001452
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001453/**
1454 * struct ec_response_flash_info - Response to the flash info command.
1455 * @flash_size: Usable flash size in bytes.
1456 * @write_block_size: Write block size. Write offset and size must be a
1457 * multiple of this.
1458 * @erase_block_size: Erase block size. Erase offset and size must be a
1459 * multiple of this.
1460 * @protect_block_size: Protection block size. Protection offset and size
1461 * must be a multiple of this.
1462 *
1463 * Version 0 returns these fields.
1464 */
1465struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001466 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001467 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001468 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001469 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001470} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001471
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001472/*
1473 * Flags for version 1+ flash info command
1474 * EC flash erases bits to 0 instead of 1.
1475 */
1476#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001477
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001478/*
1479 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001480 * be necessary on a chip where write/erase can be corrupted by other board
1481 * activity, or where the chip needs to enable some sort of programming voltage,
1482 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001483 * chip functionality.
1484 */
1485#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001486
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001487/**
1488 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1489 * @flash_size: Usable flash size in bytes.
1490 * @write_block_size: Write block size. Write offset and size must be a
1491 * multiple of this.
1492 * @erase_block_size: Erase block size. Erase offset and size must be a
1493 * multiple of this.
1494 * @protect_block_size: Protection block size. Protection offset and size
1495 * must be a multiple of this.
1496 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1497 * size is exactly this and offset is a multiple of this.
1498 * For example, an EC may have a write buffer which can do
1499 * half-page operations if data is aligned, and a slower
1500 * word-at-a-time write mode.
1501 * @flags: Flags; see EC_FLASH_INFO_*
1502 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001503 * Version 1 returns the same initial fields as version 0, with additional
1504 * fields following.
1505 *
1506 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001507 * if they did we'd define the version 0 structure as a sub-structure of this
1508 * one.
1509 *
1510 * Version 2 supports flash banks of different sizes:
1511 * The caller specified the number of banks it has preallocated
1512 * (num_banks_desc)
1513 * The EC returns the number of banks describing the flash memory.
1514 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001515 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001516struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001517 /* Version 0 fields; see above for description */
1518 uint32_t flash_size;
1519 uint32_t write_block_size;
1520 uint32_t erase_block_size;
1521 uint32_t protect_block_size;
1522
1523 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001524 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001525 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001526} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001527
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001528struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001529 /* Number of banks to describe */
1530 uint16_t num_banks_desc;
1531 /* Reserved; set 0; ignore on read */
1532 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001533} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001534
1535struct ec_flash_bank {
1536 /* Number of sector is in this bank. */
1537 uint16_t count;
1538 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1539 uint8_t size_exp;
1540 /* Minimal write size for the sectors in this bank */
1541 uint8_t write_size_exp;
1542 /* Erase size for the sectors in this bank */
1543 uint8_t erase_size_exp;
1544 /* Size for write protection, usually identical to erase size. */
1545 uint8_t protect_size_exp;
1546 /* Reserved; set 0; ignore on read */
1547 uint8_t reserved[2];
1548};
1549
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001550struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001551 /* Total flash in the EC. */
1552 uint32_t flash_size;
1553 /* Flags; see EC_FLASH_INFO_* */
1554 uint32_t flags;
1555 /* Maximum size to use to send data to write to the EC. */
1556 uint32_t write_ideal_size;
1557 /* Number of banks present in the EC. */
1558 uint16_t num_banks_total;
1559 /* Number of banks described in banks array. */
1560 uint16_t num_banks_desc;
1561 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001562} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001563
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001564/*
1565 * Read flash
1566 *
1567 * Response is params.size bytes of data.
1568 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001569#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001570
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001571/**
1572 * struct ec_params_flash_read - Parameters for the flash read command.
1573 * @offset: Byte offset to read.
1574 * @size: Size to read in bytes.
1575 */
1576struct ec_params_flash_read {
1577 uint32_t offset;
1578 uint32_t size;
1579} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001580
1581/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001582#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001583#define EC_VER_FLASH_WRITE 1
1584
1585/* Version 0 of the flash command supported only 64 bytes of data */
1586#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001587
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001588/**
1589 * struct ec_params_flash_write - Parameters for the flash write command.
1590 * @offset: Byte offset to write.
1591 * @size: Size to write in bytes.
1592 */
1593struct ec_params_flash_write {
1594 uint32_t offset;
1595 uint32_t size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001596 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001597} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001598
1599/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001600#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001601
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001602/**
1603 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1604 * @offset: Byte offset to erase.
1605 * @size: Size to erase in bytes.
1606 */
1607struct ec_params_flash_erase {
1608 uint32_t offset;
1609 uint32_t size;
1610} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001611
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001612/*
1613 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001614 * subcommands can returns:
1615 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1616 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1617 * EC_RES_ERROR : other errors.
1618 * EC_RES_BUSY : an existing erase operation is in progress.
1619 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1620 *
1621 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1622 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1623 * the proper result.
1624 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1625 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1626 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1627 * permitted while erasing. (For instance, STM32F4).
1628 */
1629enum ec_flash_erase_cmd {
1630 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1631 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1632 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1633};
1634
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001635/**
1636 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1637 * @cmd: One of ec_flash_erase_cmd.
1638 * @reserved: Pad byte; currently always contains 0.
1639 * @flag: No flags defined yet; set to 0.
1640 * @params: Same as v0 parameters.
1641 */
1642struct ec_params_flash_erase_v1 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001643 uint8_t cmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001644 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001645 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001646 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001647} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001648
1649/*
1650 * Get/set flash protection.
1651 *
1652 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1653 * firmware write protect GPIO, not all flags will take effect immediately;
1654 * some flags require a subsequent hard reset to take effect. Check the
1655 * returned flags bits to see what actually happened.
1656 *
1657 * If mask=0, simply returns the current flags state.
1658 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001659#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001660#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1661
1662/* Flags for flash protection */
1663/* RO flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001664#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001665/*
1666 * RO flash code protected now. If this bit is set, at-boot status cannot
1667 * be changed.
1668 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001669#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001670/* Entire flash code protected now, until reboot. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001671#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001672/* Flash write protect GPIO is asserted now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001673#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001674/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001675#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001676/*
1677 * Error - flash protection is in inconsistent state. At least one bank of
1678 * flash which should be protected is not protected. Usually fixed by
1679 * re-requesting the desired flags, or by a hard reset if that fails.
1680 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001681#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001682/* Entire flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001683#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001684/* RW flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001685#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001686/* RW flash code protected now. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001687#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001688/* Rollback information flash region protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001689#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001690/* Rollback information flash region protected now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001691#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001692
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001693
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001694/**
1695 * struct ec_params_flash_protect - Parameters for the flash protect command.
1696 * @mask: Bits in flags to apply.
1697 * @flags: New flags to apply.
1698 */
1699struct ec_params_flash_protect {
1700 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001701 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001702} __ec_align4;
1703
1704/**
1705 * struct ec_response_flash_protect - Response to the flash protect command.
1706 * @flags: Current value of flash protect flags.
1707 * @valid_flags: Flags which are valid on this platform. This allows the
1708 * caller to distinguish between flags which aren't set vs. flags
1709 * which can't be set on this platform.
1710 * @writable_flags: Flags which can be changed given the current protection
1711 * state.
1712 */
1713struct ec_response_flash_protect {
1714 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001715 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001716 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001717} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001718
1719/*
1720 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1721 * write protect. These commands may be reused with version > 0.
1722 */
1723
1724/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001725#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001726#define EC_VER_FLASH_REGION_INFO 1
1727
1728enum ec_flash_region {
1729 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001730 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001731 /*
1732 * Region which holds active RW image. 'Active' is different from
1733 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1734 * scheduled to run, active/non-active applies only to RW images (for
1735 * the same reason 'update' applies only to RW images. It's a state of
1736 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1737 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1738 * doesn't enter 'running' state but it's still active on a flash.
1739 */
1740 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001741 /*
1742 * Region which should be write-protected in the factory (a superset of
1743 * EC_FLASH_REGION_RO)
1744 */
1745 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001746 /* Region which holds updatable (non-active) RW image */
1747 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001748 /* Number of regions */
1749 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001750};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001751/*
1752 * 'RW' is vague if there are multiple RW images; we mean the active one,
1753 * so the old constant is deprecated.
1754 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001755#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001756
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001757/**
1758 * struct ec_params_flash_region_info - Parameters for the flash region info
1759 * command.
1760 * @region: Flash region; see EC_FLASH_REGION_*
1761 */
1762struct ec_params_flash_region_info {
1763 uint32_t region;
1764} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001765
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001766struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001767 uint32_t offset;
1768 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001769} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001770
Duncan Laurie433432b2013-06-03 10:38:22 -07001771/* Read/write VbNvContext */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001772#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001773#define EC_VER_VBNV_CONTEXT 1
1774#define EC_VBNV_BLOCK_SIZE 16
1775
1776enum ec_vbnvcontext_op {
1777 EC_VBNV_CONTEXT_OP_READ,
1778 EC_VBNV_CONTEXT_OP_WRITE,
1779};
1780
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001781struct ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001782 uint32_t op;
1783 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001784} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001785
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001786struct ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001787 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001788} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001789
1790
1791/* Get SPI flash information */
1792#define EC_CMD_FLASH_SPI_INFO 0x0018
1793
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001794struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001795 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1796 uint8_t jedec[3];
1797
1798 /* Pad byte; currently always contains 0 */
1799 uint8_t reserved0;
1800
1801 /* Manufacturer / device ID from command 0x90 */
1802 uint8_t mfr_dev_id[2];
1803
1804 /* Status registers from command 0x05 and 0x35 */
1805 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001806} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001807
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001808
1809/* Select flash during flash operations */
1810#define EC_CMD_FLASH_SELECT 0x0019
1811
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001812/**
1813 * struct ec_params_flash_select - Parameters for the flash select command.
1814 * @select: 1 to select flash, 0 to deselect flash
1815 */
1816struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001817 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001818} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001819
1820
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001821/**
1822 * Request random numbers to be generated and returned.
1823 * Can be used to test the random number generator is truly random.
1824 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1825 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1826 */
1827#define EC_CMD_RAND_NUM 0x001A
1828#define EC_VER_RAND_NUM 0
1829
1830struct ec_params_rand_num {
1831 uint16_t num_rand_bytes; /**< num random bytes to generate */
1832} __ec_align4;
1833
1834struct ec_response_rand_num {
1835 uint8_t rand[0]; /**< generated random numbers */
1836} __ec_align4;
1837
1838BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1839
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07001840/**
1841 * Get information about the key used to sign the RW firmware.
1842 * For more details on the fields, see "struct vb21_packed_key".
1843 */
1844#define EC_CMD_RWSIG_INFO 0x001B
1845#define EC_VER_RWSIG_INFO 0
1846
1847#define VBOOT2_KEY_ID_BYTES 20
1848
1849#ifdef CHROMIUM_EC
1850/* Don't force external projects to depend on the vboot headers. */
1851#include "vb21_struct.h"
1852BUILD_ASSERT(sizeof(struct vb2_id) == VBOOT2_KEY_ID_BYTES);
1853#endif
1854
1855struct ec_response_rwsig_info {
1856 /**
1857 * Signature algorithm used by the key
1858 * (enum vb2_signature_algorithm).
1859 */
1860 uint16_t sig_alg;
1861
1862 /**
1863 * Hash digest algorithm used with the key
1864 * (enum vb2_hash_algorithm).
1865 */
1866 uint16_t hash_alg;
1867
1868 /** Key version. */
1869 uint32_t key_version;
1870
1871 /** Key ID (struct vb2_id). */
1872 uint8_t key_id[VBOOT2_KEY_ID_BYTES];
1873
1874 uint8_t key_is_valid;
1875
1876 /** Alignment padding. */
1877 uint8_t reserved[3];
1878} __ec_align4;
1879
1880BUILD_ASSERT(sizeof(struct ec_response_rwsig_info) == 32);
1881
1882/**
1883 * Get information about the system, such as reset flags, locked state, etc.
1884 */
1885#define EC_CMD_SYSINFO 0x001C
1886#define EC_VER_SYSINFO 0
1887
1888enum sysinfo_flags {
1889 SYSTEM_IS_LOCKED = BIT(0),
1890 SYSTEM_IS_FORCE_LOCKED = BIT(1),
1891 SYSTEM_JUMP_ENABLED = BIT(2),
1892 SYSTEM_JUMPED_TO_CURRENT_IMAGE = BIT(3),
1893 SYSTEM_REBOOT_AT_SHUTDOWN = BIT(4)
1894};
1895
1896struct ec_response_sysinfo {
1897 uint32_t reset_flags; /**< EC_RESET_FLAG_* flags */
1898 uint32_t current_image; /**< enum ec_current_image */
1899 uint32_t flags; /**< enum sysinfo_flags */
1900} __ec_align4;
1901
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001902/*****************************************************************************/
1903/* PWM commands */
1904
1905/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001906#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001907
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001908struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001909 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001910} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001911
1912/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001913#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001914
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001915/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001916struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001917 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001918} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001919
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001920/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001921struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001922 uint32_t rpm;
1923 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001924} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001925
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001926/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001927/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001928#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001929
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001930struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001931 uint8_t percent;
1932 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001933} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001934
1935/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001936/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001937#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001938
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001939struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001940 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001941} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001942
1943/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001944#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001945
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001946/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001947struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001948 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001949} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001950
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001951/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001952struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001953 uint32_t percent;
1954 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001955} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001956
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001957#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07001958/* 16 bit duty cycle, 0xffff = 100% */
1959#define EC_PWM_MAX_DUTY 0xffff
1960
1961enum ec_pwm_type {
1962 /* All types, indexed by board-specific enum pwm_channel */
1963 EC_PWM_TYPE_GENERIC = 0,
1964 /* Keyboard backlight */
1965 EC_PWM_TYPE_KB_LIGHT,
1966 /* Display backlight */
1967 EC_PWM_TYPE_DISPLAY_LIGHT,
1968 EC_PWM_TYPE_COUNT,
1969};
1970
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001971struct ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001972 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1973 uint8_t pwm_type; /* ec_pwm_type */
1974 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001975} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001976
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001977#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07001978
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001979struct ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001980 uint8_t pwm_type; /* ec_pwm_type */
1981 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001982} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001983
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001984struct ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001985 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001986} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001987
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001988/*****************************************************************************/
1989/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001990 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001991 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1992 * into a subcommand. We'll make separate structs for subcommands with
1993 * different input args, so that we know how much to expect.
1994 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001995#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001996
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001997struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07001998 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001999} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002000
Duncan Laurie433432b2013-06-03 10:38:22 -07002001#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002002
2003/*
2004 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07002005 * host command, but the alignment is the same regardless. Keep it that way.
2006 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002007struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002008 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08002009 int32_t google_ramp_up;
2010 int32_t google_ramp_down;
2011 int32_t s3s0_ramp_up;
2012 int32_t s0_tick_delay[2]; /* AC=0/1 */
2013 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2014 int32_t s0s3_ramp_down;
2015 int32_t s3_sleep_for;
2016 int32_t s3_ramp_up;
2017 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07002018
2019 /* Oscillation */
2020 uint8_t new_s0;
2021 uint8_t osc_min[2]; /* AC=0/1 */
2022 uint8_t osc_max[2]; /* AC=0/1 */
2023 uint8_t w_ofs[2]; /* AC=0/1 */
2024
2025 /* Brightness limits based on the backlight and AC. */
2026 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2027 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2028 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2029
2030 /* Battery level thresholds */
2031 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2032
2033 /* Map [AC][battery_level] to color index */
2034 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2035 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2036
2037 /* Color palette */
2038 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002039} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002040
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002041struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002042 /* Timing */
2043 int32_t google_ramp_up;
2044 int32_t google_ramp_down;
2045 int32_t s3s0_ramp_up;
2046 int32_t s0_tick_delay[2]; /* AC=0/1 */
2047 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2048 int32_t s0s3_ramp_down;
2049 int32_t s3_sleep_for;
2050 int32_t s3_ramp_up;
2051 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002052 int32_t s5_ramp_up;
2053 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002054 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002055 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002056 int32_t tap_display_time;
2057
2058 /* Tap-for-battery params */
2059 uint8_t tap_pct_red;
2060 uint8_t tap_pct_green;
2061 uint8_t tap_seg_min_on;
2062 uint8_t tap_seg_max_on;
2063 uint8_t tap_seg_osc;
2064 uint8_t tap_idx[3];
2065
2066 /* Oscillation */
2067 uint8_t osc_min[2]; /* AC=0/1 */
2068 uint8_t osc_max[2]; /* AC=0/1 */
2069 uint8_t w_ofs[2]; /* AC=0/1 */
2070
2071 /* Brightness limits based on the backlight and AC. */
2072 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2073 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2074 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
2075
2076 /* Battery level thresholds */
2077 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
2078
2079 /* Map [AC][battery_level] to color index */
2080 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2081 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002083 /* s5: single color pulse on inhibited power-up */
2084 uint8_t s5_idx;
2085
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002086 /* Color palette */
2087 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002088} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002089
Duncan Laurieeb316852015-12-01 18:51:18 -08002090/* Lightbar command params v2
2091 * crbug.com/467716
2092 *
2093 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2094 * logical groups to make it more manageable ( < 120 bytes).
2095 *
2096 * NOTE: Each of these groups must be less than 120 bytes.
2097 */
2098
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002099struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002100 /* Timing */
2101 int32_t google_ramp_up;
2102 int32_t google_ramp_down;
2103 int32_t s3s0_ramp_up;
2104 int32_t s0_tick_delay[2]; /* AC=0/1 */
2105 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2106 int32_t s0s3_ramp_down;
2107 int32_t s3_sleep_for;
2108 int32_t s3_ramp_up;
2109 int32_t s3_ramp_down;
2110 int32_t s5_ramp_up;
2111 int32_t s5_ramp_down;
2112 int32_t tap_tick_delay;
2113 int32_t tap_gate_delay;
2114 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002115} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002117struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002118 /* Tap-for-battery params */
2119 uint8_t tap_pct_red;
2120 uint8_t tap_pct_green;
2121 uint8_t tap_seg_min_on;
2122 uint8_t tap_seg_max_on;
2123 uint8_t tap_seg_osc;
2124 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002125} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002126
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002127struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002128 /* Oscillation */
2129 uint8_t osc_min[2]; /* AC=0/1 */
2130 uint8_t osc_max[2]; /* AC=0/1 */
2131 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002132} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002133
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002134struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002135 /* Brightness limits based on the backlight and AC. */
2136 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2137 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2138 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002139} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002140
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002141struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002142 /* Battery level thresholds */
2143 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002144} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002145
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002146struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002147 /* Map [AC][battery_level] to color index */
2148 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2149 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2150
2151 /* s5: single color pulse on inhibited power-up */
2152 uint8_t s5_idx;
2153
2154 /* Color palette */
2155 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002156} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002157
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002158/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002159#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002160struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002161 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002162 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002163} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002164
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002165struct ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002166 uint8_t cmd; /* Command (see enum lightbar_command) */
2167 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002168 /*
2169 * The following commands have no args:
2170 *
2171 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2172 * version, get_brightness, get_demo, suspend, resume,
2173 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2174 * get_params_v2_bright, get_params_v2_thlds,
2175 * get_params_v2_colors
2176 *
2177 * Don't use an empty struct, because C++ hates that.
2178 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002179
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002180 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002181 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002182 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002183
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002184 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002185 uint8_t ctrl, reg, value;
2186 } reg;
2187
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002188 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002189 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002190 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002191
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002192 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002193 uint8_t led;
2194 } get_rgb;
2195
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002196 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002197 uint8_t enable;
2198 } manual_suspend_ctrl;
2199
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002200 struct lightbar_params_v0 set_params_v0;
2201 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002202
2203 struct lightbar_params_v2_timing set_v2par_timing;
2204 struct lightbar_params_v2_tap set_v2par_tap;
2205 struct lightbar_params_v2_oscillation set_v2par_osc;
2206 struct lightbar_params_v2_brightness set_v2par_bright;
2207 struct lightbar_params_v2_thresholds set_v2par_thlds;
2208 struct lightbar_params_v2_colors set_v2par_colors;
2209
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002210 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002211 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002212} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002213
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002214struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002215 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002216 struct __ec_todo_unpacked {
2217 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002218 uint8_t reg;
2219 uint8_t ic0;
2220 uint8_t ic1;
2221 } vals[23];
2222 } dump;
2223
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002224 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002225 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002226 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002227
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002228 struct lightbar_params_v0 get_params_v0;
2229 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002230
Duncan Laurieeb316852015-12-01 18:51:18 -08002231
2232 struct lightbar_params_v2_timing get_params_v2_timing;
2233 struct lightbar_params_v2_tap get_params_v2_tap;
2234 struct lightbar_params_v2_oscillation get_params_v2_osc;
2235 struct lightbar_params_v2_brightness get_params_v2_bright;
2236 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2237 struct lightbar_params_v2_colors get_params_v2_colors;
2238
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002239 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002240 uint32_t num;
2241 uint32_t flags;
2242 } version;
2243
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002244 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002245 uint8_t red, green, blue;
2246 } get_rgb;
2247
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002248 /*
2249 * The following commands have no response:
2250 *
2251 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2252 * set_params_v0, set_params_v1, set_program,
2253 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2254 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2255 * set_v2par_thlds, set_v2par_colors
2256 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002257 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002258} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002259
2260/* Lightbar commands */
2261enum lightbar_command {
2262 LIGHTBAR_CMD_DUMP = 0,
2263 LIGHTBAR_CMD_OFF = 1,
2264 LIGHTBAR_CMD_ON = 2,
2265 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002266 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002267 LIGHTBAR_CMD_SEQ = 5,
2268 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002269 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002270 LIGHTBAR_CMD_GET_SEQ = 8,
2271 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002272 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2273 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002274 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002275 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2276 LIGHTBAR_CMD_GET_RGB = 14,
2277 LIGHTBAR_CMD_GET_DEMO = 15,
2278 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2279 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002280 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002281 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2282 LIGHTBAR_CMD_SUSPEND = 20,
2283 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002284 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2285 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2286 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2287 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2288 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2289 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2290 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2291 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2292 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2293 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2294 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2295 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002296 LIGHTBAR_NUM_CMDS
2297};
2298
2299/*****************************************************************************/
2300/* LED control commands */
2301
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002302#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002303
Bill Richardsone221aad2013-06-12 10:50:41 -07002304enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002305 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002306 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002307 /*
2308 * LED to indicate system power state (on or in suspend).
2309 * May be on power button or on C-panel.
2310 */
2311 EC_LED_ID_POWER_LED,
2312 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002313 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002314 /* LED to indicate left side */
2315 EC_LED_ID_LEFT_LED,
2316 /* LED to indicate right side */
2317 EC_LED_ID_RIGHT_LED,
2318 /* LED to indicate recovery mode with HW_REINIT */
2319 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2320 /* LED to indicate sysrq debug mode. */
2321 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002322
2323 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002324};
Duncan Laurie433432b2013-06-03 10:38:22 -07002325
Bill Richardsone221aad2013-06-12 10:50:41 -07002326/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002327#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2328#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002329
2330enum ec_led_colors {
2331 EC_LED_COLOR_RED = 0,
2332 EC_LED_COLOR_GREEN,
2333 EC_LED_COLOR_BLUE,
2334 EC_LED_COLOR_YELLOW,
2335 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002336 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002337
2338 EC_LED_COLOR_COUNT
2339};
2340
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002341struct ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002342 uint8_t led_id; /* Which LED to control */
2343 uint8_t flags; /* Control flags */
2344
2345 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002346} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002347
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002348struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002349 /*
2350 * Available brightness value range.
2351 *
2352 * Range 0 means color channel not present.
2353 * Range 1 means on/off control.
2354 * Other values means the LED is control by PWM.
2355 */
2356 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002357} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002358
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002359/*****************************************************************************/
2360/* Verified boot commands */
2361
2362/*
2363 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2364 * reused for other purposes with version > 0.
2365 */
2366
2367/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002368#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002369
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002370struct ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002371 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2372 uint8_t hash_type; /* enum ec_vboot_hash_type */
2373 uint8_t nonce_size; /* Nonce size; may be 0 */
2374 uint8_t reserved0; /* Reserved; set 0 */
2375 uint32_t offset; /* Offset in flash to hash */
2376 uint32_t size; /* Number of bytes to hash */
2377 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002378} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002379
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002380struct ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002381 uint8_t status; /* enum ec_vboot_hash_status */
2382 uint8_t hash_type; /* enum ec_vboot_hash_type */
2383 uint8_t digest_size; /* Size of hash digest in bytes */
2384 uint8_t reserved0; /* Ignore; will be 0 */
2385 uint32_t offset; /* Offset in flash which was hashed */
2386 uint32_t size; /* Number of bytes hashed */
2387 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002388} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002389
2390enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002391 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2392 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2393 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2394 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002395};
2396
2397enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002398 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002399};
2400
2401enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002402 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2403 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2404 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002405};
2406
Duncan Laurie433432b2013-06-03 10:38:22 -07002407/*
2408 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2409 * If one of these is specified, the EC will automatically update offset and
2410 * size to the correct values for the specified image (RO or RW).
2411 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002412#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2413#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2414#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2415
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002416/*
2417 * 'RW' is vague if there are multiple RW images; we mean the active one,
2418 * so the old constant is deprecated.
2419 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002420#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002421
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002422/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002423/*
2424 * Motion sense commands. We'll make separate structs for sub-commands with
2425 * different input args, so that we know how much to expect.
2426 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002427#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002428
2429/* Motion sense commands */
2430enum motionsense_command {
2431 /*
2432 * Dump command returns all motion sensor data including motion sense
2433 * module flags and individual sensor flags.
2434 */
2435 MOTIONSENSE_CMD_DUMP = 0,
2436
2437 /*
2438 * Info command returns data describing the details of a given sensor,
2439 * including enum motionsensor_type, enum motionsensor_location, and
2440 * enum motionsensor_chip.
2441 */
2442 MOTIONSENSE_CMD_INFO = 1,
2443
2444 /*
2445 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002446 * in milliseconds.
2447 * It is per sensor, the EC run sample task at the minimum of all
2448 * sensors EC_RATE.
2449 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2450 * to collect all the sensor samples.
2451 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2452 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002453 */
2454 MOTIONSENSE_CMD_EC_RATE = 2,
2455
2456 /*
2457 * Sensor ODR command is a setter/getter command for the output data
2458 * rate of a specific motion sensor in millihertz.
2459 */
2460 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2461
2462 /*
2463 * Sensor range command is a setter/getter command for the range of
2464 * a specified motion sensor in +/-G's or +/- deg/s.
2465 */
2466 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2467
2468 /*
2469 * Setter/getter command for the keyboard wake angle. When the lid
2470 * angle is greater than this value, keyboard wake is disabled in S3,
2471 * and when the lid angle goes less than this value, keyboard wake is
2472 * enabled. Note, the lid angle measurement is an approximate,
2473 * un-calibrated value, hence the wake angle isn't exact.
2474 */
2475 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2476
Duncan Laurieeb316852015-12-01 18:51:18 -08002477 /*
2478 * Returns a single sensor data.
2479 */
2480 MOTIONSENSE_CMD_DATA = 6,
2481
2482 /*
2483 * Return sensor fifo info.
2484 */
2485 MOTIONSENSE_CMD_FIFO_INFO = 7,
2486
2487 /*
2488 * Insert a flush element in the fifo and return sensor fifo info.
2489 * The host can use that element to synchronize its operation.
2490 */
2491 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2492
2493 /*
2494 * Return a portion of the fifo.
2495 */
2496 MOTIONSENSE_CMD_FIFO_READ = 9,
2497
2498 /*
2499 * Perform low level calibration.
2500 * On sensors that support it, ask to do offset calibration.
2501 */
2502 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2503
2504 /*
2505 * Sensor Offset command is a setter/getter command for the offset
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002506 * used for factory calibration.
Duncan Laurieeb316852015-12-01 18:51:18 -08002507 * The offsets can be calculated by the host, or via
2508 * PERFORM_CALIB command.
2509 */
2510 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2511
2512 /*
2513 * List available activities for a MOTION sensor.
2514 * Indicates if they are enabled or disabled.
2515 */
2516 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2517
2518 /*
2519 * Activity management
2520 * Enable/Disable activity recognition.
2521 */
2522 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2523
2524 /*
2525 * Lid Angle
2526 */
2527 MOTIONSENSE_CMD_LID_ANGLE = 14,
2528
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002529 /*
2530 * Allow the FIFO to trigger interrupt via MKBP events.
2531 * By default the FIFO does not send interrupt to process the FIFO
2532 * until the AP is ready or it is coming from a wakeup sensor.
2533 */
2534 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2535
2536 /*
2537 * Spoof the readings of the sensors. The spoofed readings can be set
2538 * to arbitrary values, or will lock to the last read actual values.
2539 */
2540 MOTIONSENSE_CMD_SPOOF = 16,
2541
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002542 /* Set lid angle for tablet mode detection. */
2543 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2544
2545 /*
2546 * Sensor Scale command is a setter/getter command for the calibration
2547 * scale.
2548 */
2549 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2550
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002551 /*
2552 * Read the current online calibration values (if available).
2553 */
2554 MOTIONSENSE_CMD_ONLINE_CALIB_READ = 19,
2555
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002556 /* Number of motionsense sub-commands. */
2557 MOTIONSENSE_NUM_CMDS
2558};
2559
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002560/* List of motion sensor types. */
2561enum motionsensor_type {
2562 MOTIONSENSE_TYPE_ACCEL = 0,
2563 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002564 MOTIONSENSE_TYPE_MAG = 2,
2565 MOTIONSENSE_TYPE_PROX = 3,
2566 MOTIONSENSE_TYPE_LIGHT = 4,
2567 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002568 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002569 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002570 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002571 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002572};
2573
2574/* List of motion sensor locations. */
2575enum motionsensor_location {
2576 MOTIONSENSE_LOC_BASE = 0,
2577 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002578 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002579 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002580};
2581
2582/* List of motion sensor chips. */
2583enum motionsensor_chip {
2584 MOTIONSENSE_CHIP_KXCJ9 = 0,
2585 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002586 MOTIONSENSE_CHIP_BMI160 = 2,
2587 MOTIONSENSE_CHIP_SI1141 = 3,
2588 MOTIONSENSE_CHIP_SI1142 = 4,
2589 MOTIONSENSE_CHIP_SI1143 = 5,
2590 MOTIONSENSE_CHIP_KX022 = 6,
2591 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002592 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002593 MOTIONSENSE_CHIP_BMP280 = 9,
2594 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002595 MOTIONSENSE_CHIP_BH1730 = 11,
2596 MOTIONSENSE_CHIP_GPIO = 12,
2597 MOTIONSENSE_CHIP_LIS2DH = 13,
2598 MOTIONSENSE_CHIP_LSM6DSM = 14,
2599 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002600 MOTIONSENSE_CHIP_LIS2MDL = 16,
2601 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2602 MOTIONSENSE_CHIP_LSM6DSO = 18,
2603 MOTIONSENSE_CHIP_LNG2DM = 19,
2604 MOTIONSENSE_CHIP_TCS3400 = 20,
2605 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2606 MOTIONSENSE_CHIP_LIS2DWL = 22,
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002607 MOTIONSENSE_CHIP_LIS2DS = 23,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002608 MOTIONSENSE_CHIP_MAX,
2609};
2610
2611/* List of orientation positions */
2612enum motionsensor_orientation {
2613 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2614 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2615 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2616 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2617 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002618};
2619
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002620struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002621 /* Flags for each sensor. */
2622 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002623 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002624 uint8_t sensor_num;
2625 /* Each sensor is up to 3-axis. */
2626 union {
2627 int16_t data[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002628 struct __ec_todo_packed {
2629 uint16_t reserved;
Duncan Laurieeb316852015-12-01 18:51:18 -08002630 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002631 };
2632 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002633 uint8_t activity; /* motionsensor_activity */
2634 uint8_t state;
2635 int16_t add_info[2];
2636 };
2637 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002638} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002639
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002640/* Response to AP reporting calibration data for a given sensor. */
2641struct ec_response_online_calibration_data {
2642 /** The calibration values. */
2643 int16_t data[3];
2644};
2645
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002646/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002647struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002648 /* Size of the fifo */
2649 uint16_t size;
2650 /* Amount of space used in the fifo */
2651 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002652 /* Timestamp recorded in us.
2653 * aka accurate timestamp when host event was triggered.
2654 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002655 uint32_t timestamp;
2656 /* Total amount of vector lost */
2657 uint16_t total_lost;
2658 /* Lost events since the last fifo_info, per sensors */
2659 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002660} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002661
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002662struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002663 uint32_t number_data;
2664 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002665} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002666
2667/* List supported activity recognition */
2668enum motionsensor_activity {
2669 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2670 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2671 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002672 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Duncan Laurieeb316852015-12-01 18:51:18 -08002673};
2674
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002675struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002676 uint8_t sensor_num;
2677 uint8_t activity; /* one of enum motionsensor_activity */
2678 uint8_t enable; /* 1: enable, 0: disable */
2679 uint8_t reserved;
2680 uint16_t parameters[3]; /* activity dependent parameters */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002681} __ec_todo_unpacked;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002682
2683/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002684#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002685
2686/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002687#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002688
2689/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002690 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002691 * data contains time stamp
2692 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002693#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2694#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2695#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2696#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2697#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002698
2699/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002700 * Send this value for the data element to only perform a read. If you
2701 * send any other value, the EC will interpret it as data to set and will
2702 * return the actual value set.
2703 */
2704#define EC_MOTION_SENSE_NO_VALUE -1
2705
Duncan Laurieeb316852015-12-01 18:51:18 -08002706#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2707
2708/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2709/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002710#define MOTION_SENSE_SET_OFFSET BIT(0)
2711
2712/* Default Scale value, factor 1. */
2713#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002714
2715#define LID_ANGLE_UNRELIABLE 500
2716
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002717enum motionsense_spoof_mode {
2718 /* Disable spoof mode. */
2719 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2720
2721 /* Enable spoof mode, but use provided component values. */
2722 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2723
2724 /* Enable spoof mode, but use the current sensor values. */
2725 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2726
2727 /* Query the current spoof mode status for the sensor. */
2728 MOTIONSENSE_SPOOF_MODE_QUERY,
2729};
2730
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002731struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002732 uint8_t cmd;
2733 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002734 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002735 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002736 /*
2737 * Maximal number of sensor the host is expecting.
2738 * 0 means the host is only interested in the number
2739 * of sensors controlled by the EC.
2740 */
2741 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002742 } dump;
2743
2744 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002745 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002746 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002747 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002748 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2749 * kb_wake_angle: angle to wakup AP.
2750 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002751 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002752 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002753
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002754 /*
2755 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2756 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002757 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002758 uint8_t sensor_num;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002759 } info, info_3, info_4, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002760
2761 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002762 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2763 * Allow entering/exiting the calibration mode.
2764 */
2765 struct __ec_todo_unpacked {
2766 uint8_t sensor_num;
2767 uint8_t enable;
2768 } perform_calib;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002769
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002770 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002771 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2772 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002773 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002774 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002775 uint8_t sensor_num;
2776
2777 /* Rounding flag, true for round-up, false for down. */
2778 uint8_t roundup;
2779
2780 uint16_t reserved;
2781
2782 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2783 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002784 } ec_rate, sensor_odr, sensor_range;
2785
2786 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002787 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002788 uint8_t sensor_num;
2789
2790 /*
2791 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2792 * the calibration information in the EC.
2793 * If unset, just retrieve calibration information.
2794 */
2795 uint16_t flags;
2796
2797 /*
2798 * Temperature at calibration, in units of 0.01 C
2799 * 0x8000: invalid / unknown.
2800 * 0x0: 0C
2801 * 0x7fff: +327.67C
2802 */
2803 int16_t temp;
2804
2805 /*
2806 * Offset for calibration.
2807 * Unit:
2808 * Accelerometer: 1/1024 g
2809 * Gyro: 1/1024 deg/s
2810 * Compass: 1/16 uT
2811 */
2812 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002813 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002814
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002815 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2816 struct __ec_todo_packed {
2817 uint8_t sensor_num;
2818
2819 /*
2820 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2821 * the calibration information in the EC.
2822 * If unset, just retrieve calibration information.
2823 */
2824 uint16_t flags;
2825
2826 /*
2827 * Temperature at calibration, in units of 0.01 C
2828 * 0x8000: invalid / unknown.
2829 * 0x0: 0C
2830 * 0x7fff: +327.67C
2831 */
2832 int16_t temp;
2833
2834 /*
2835 * Scale for calibration:
2836 * By default scale is 1, it is encoded on 16bits:
2837 * 1 = BIT(15)
2838 * ~2 = 0xFFFF
2839 * ~0 = 0.
2840 */
2841 uint16_t scale[3];
2842 } sensor_scale;
2843
2844
Duncan Laurieeb316852015-12-01 18:51:18 -08002845 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002846 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002847
2848 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002849 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002850 /*
2851 * Number of expected vector to return.
2852 * EC may return less or 0 if none available.
2853 */
2854 uint32_t max_data_vector;
2855 } fifo_read;
2856
2857 struct ec_motion_sense_activity set_activity;
2858
2859 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002860 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002861
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002862 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2863 struct __ec_todo_unpacked {
2864 /*
2865 * 1: enable, 0 disable fifo,
2866 * EC_MOTION_SENSE_NO_VALUE return value.
2867 */
2868 int8_t enable;
2869 } fifo_int_enable;
2870
2871 /* Used for MOTIONSENSE_CMD_SPOOF */
2872 struct __ec_todo_packed {
2873 uint8_t sensor_id;
2874
2875 /* See enum motionsense_spoof_mode. */
2876 uint8_t spoof_enable;
2877
2878 /* Ignored, used for alignment. */
2879 uint8_t reserved;
2880
2881 /* Individual component values to spoof. */
2882 int16_t components[3];
2883 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002884
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002885 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2886 struct __ec_todo_unpacked {
2887 /*
2888 * Lid angle threshold for switching between tablet and
2889 * clamshell mode.
2890 */
2891 int16_t lid_angle;
2892
2893 /*
2894 * Hysteresis degree to prevent fluctuations between
2895 * clamshell and tablet mode if lid angle keeps
2896 * changing around the threshold. Lid motion driver will
2897 * use lid_angle + hys_degree to trigger tablet mode and
2898 * lid_angle - hys_degree to trigger clamshell mode.
2899 */
2900 int16_t hys_degree;
2901 } tablet_mode_threshold;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07002902
2903 /*
2904 * Used for MOTIONSENSE_CMD_ONLINE_CALIB_READ:
2905 * Allow reading a single sensor's online calibration value.
2906 */
2907 struct __ec_todo_unpacked {
2908 uint8_t sensor_num;
2909 } online_calib_read;
2910
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002911 };
2912} __ec_todo_packed;
2913
Jett Rinkba2edaf2020-01-14 11:49:06 -07002914enum motion_sense_cmd_info_flags {
2915 /* The sensor supports online calibration */
2916 MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB = BIT(0),
2917};
2918
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002919struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002920 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002921 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002922 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002923 /* Flags representing the motion sensor module. */
2924 uint8_t module_flags;
2925
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002926 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002927 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002928
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002929 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002930 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002931 * for holding all the data.
2932 */
2933 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002934 } dump;
2935
2936 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002937 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002938 /* Should be element of enum motionsensor_type. */
2939 uint8_t type;
2940
2941 /* Should be element of enum motionsensor_location. */
2942 uint8_t location;
2943
2944 /* Should be element of enum motionsensor_chip. */
2945 uint8_t chip;
2946 } info;
2947
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002948 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2949 struct __ec_todo_unpacked {
2950 /* Should be element of enum motionsensor_type. */
2951 uint8_t type;
2952
2953 /* Should be element of enum motionsensor_location. */
2954 uint8_t location;
2955
2956 /* Should be element of enum motionsensor_chip. */
2957 uint8_t chip;
2958
2959 /* Minimum sensor sampling frequency */
2960 uint32_t min_frequency;
2961
2962 /* Maximum sensor sampling frequency */
2963 uint32_t max_frequency;
2964
2965 /* Max number of sensor events that could be in fifo */
2966 uint32_t fifo_max_event_count;
2967 } info_3;
2968
Jett Rinkba2edaf2020-01-14 11:49:06 -07002969 /* Used for MOTIONSENSE_CMD_INFO version 4 */
2970 struct __ec_align4 {
2971 /* Should be element of enum motionsensor_type. */
2972 uint8_t type;
2973
2974 /* Should be element of enum motionsensor_location. */
2975 uint8_t location;
2976
2977 /* Should be element of enum motionsensor_chip. */
2978 uint8_t chip;
2979
2980 /* Minimum sensor sampling frequency */
2981 uint32_t min_frequency;
2982
2983 /* Maximum sensor sampling frequency */
2984 uint32_t max_frequency;
2985
2986 /* Max number of sensor events that could be in fifo */
2987 uint32_t fifo_max_event_count;
2988
2989 /*
2990 * Should be elements of
2991 * enum motion_sense_cmd_info_flags
2992 */
2993 uint32_t flags;
2994 } info_4;
2995
Duncan Laurieeb316852015-12-01 18:51:18 -08002996 /* Used for MOTIONSENSE_CMD_DATA */
2997 struct ec_response_motion_sensor_data data;
2998
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002999 /*
3000 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003001 * MOTIONSENSE_CMD_SENSOR_RANGE,
3002 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
3003 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
3004 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003005 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003006 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003007 /* Current value of the parameter queried. */
3008 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003009 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
3010 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08003011
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003012 /*
3013 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
3014 * PERFORM_CALIB.
3015 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003016 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003017 int16_t temp;
3018 int16_t offset[3];
3019 } sensor_offset, perform_calib;
3020
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003021 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
3022 struct __ec_todo_unpacked {
3023 int16_t temp;
3024 uint16_t scale[3];
3025 } sensor_scale;
3026
Duncan Laurieeb316852015-12-01 18:51:18 -08003027 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
3028
3029 struct ec_response_motion_sense_fifo_data fifo_read;
3030
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003031 struct ec_response_online_calibration_data online_calib_read;
3032
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003033 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08003034 uint16_t reserved;
3035 uint32_t enabled;
3036 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003037 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08003038
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003039 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08003040
Duncan Laurieeb316852015-12-01 18:51:18 -08003041 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003042 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003043 /*
3044 * Angle between 0 and 360 degree if available,
3045 * LID_ANGLE_UNRELIABLE otherwise.
3046 */
3047 uint16_t value;
3048 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003049
3050 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
3051 struct __ec_todo_unpacked {
3052 /*
3053 * Lid angle threshold for switching between tablet and
3054 * clamshell mode.
3055 */
3056 uint16_t lid_angle;
3057
3058 /* Hysteresis degree. */
3059 uint16_t hys_degree;
3060 } tablet_mode_threshold;
3061
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003062 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003063} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003064
3065/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003066/* Force lid open command */
3067
3068/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003069#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003070
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003071struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003072 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003073} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003074
3075/*****************************************************************************/
3076/* Configure the behavior of the power button */
3077#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
3078
3079enum ec_config_power_button_flags {
3080 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003081 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003082};
3083
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003084struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003085 /* See enum ec_config_power_button_flags */
3086 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003087} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003088
3089/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003090/* USB charging control commands */
3091
3092/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003093#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003094
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003095enum usb_charge_mode {
3096 /* Disable USB port. */
3097 USB_CHARGE_MODE_DISABLED,
3098 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
3099 USB_CHARGE_MODE_SDP2,
3100 /* Set USB port to Charging Downstream Port, BC 1.2. */
3101 USB_CHARGE_MODE_CDP,
3102 /* Set USB port to Dedicated Charging Port, BC 1.2. */
3103 USB_CHARGE_MODE_DCP_SHORT,
3104 /* Enable USB port (for dumb ports). */
3105 USB_CHARGE_MODE_ENABLED,
3106 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
3107 USB_CHARGE_MODE_DEFAULT,
3108
3109 USB_CHARGE_MODE_COUNT
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003110};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003111
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003112enum usb_suspend_charge {
3113 /* Enable charging in suspend */
3114 USB_ALLOW_SUSPEND_CHARGE,
3115 /* Disable charging in suspend */
3116 USB_DISALLOW_SUSPEND_CHARGE
3117};
3118
3119struct ec_params_usb_charge_set_mode {
3120 uint8_t usb_port_id;
3121 uint8_t mode:7; /* enum usb_charge_mode */
3122 uint8_t inhibit_charge:1; /* enum usb_suspend_charge */
3123} __ec_align1;
3124
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003125/*****************************************************************************/
3126/* Persistent storage for host */
3127
3128/* Maximum bytes that can be read/written in a single command */
3129#define EC_PSTORE_SIZE_MAX 64
3130
3131/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003132#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003133
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003134struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003135 /* Persistent storage size, in bytes */
3136 uint32_t pstore_size;
3137 /* Access size; read/write offset and size must be a multiple of this */
3138 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003139} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003140
3141/*
3142 * Read persistent storage
3143 *
3144 * Response is params.size bytes of data.
3145 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003146#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003147
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003148struct ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003149 uint32_t offset; /* Byte offset to read */
3150 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003151} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003152
3153/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003154#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003155
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003156struct ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003157 uint32_t offset; /* Byte offset to write */
3158 uint32_t size; /* Size to write in bytes */
3159 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003160} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003161
3162/*****************************************************************************/
3163/* Real-time clock */
3164
3165/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003166struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003167 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003168} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003169
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003170struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003171 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003172} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003173
3174/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003175#define EC_CMD_RTC_GET_VALUE 0x0044
3176#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003177
3178/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003179#define EC_CMD_RTC_SET_VALUE 0x0046
3180#define EC_CMD_RTC_SET_ALARM 0x0047
3181
3182/* Pass as time param to SET_ALARM to clear the current alarm */
3183#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003184
3185/*****************************************************************************/
3186/* Port80 log access */
3187
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003188/* Maximum entries that can be read/written in a single command */
3189#define EC_PORT80_SIZE_MAX 32
3190
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003191/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003192#define EC_CMD_PORT80_LAST_BOOT 0x0048
3193#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003194
3195enum ec_port80_subcmd {
3196 EC_PORT80_GET_INFO = 0,
3197 EC_PORT80_READ_BUFFER,
3198};
3199
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003200struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003201 uint16_t subcmd;
3202 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003203 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003204 uint32_t offset;
3205 uint32_t num_entries;
3206 } read_buffer;
3207 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003208} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003209
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003210struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003211 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003212 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003213 uint32_t writes;
3214 uint32_t history_size;
3215 uint32_t last_boot;
3216 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003217 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003218 uint16_t codes[EC_PORT80_SIZE_MAX];
3219 } data;
3220 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003221} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003222
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003223struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003224 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003225} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003226
3227/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003228/* Temporary secure storage for host verified boot use */
3229
3230/* Number of bytes in a vstore slot */
3231#define EC_VSTORE_SLOT_SIZE 64
3232
3233/* Maximum number of vstore slots */
3234#define EC_VSTORE_SLOT_MAX 32
3235
3236/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003237#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003238struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003239 /* Indicates which slots are locked */
3240 uint32_t slot_locked;
3241 /* Total number of slots available */
3242 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003243} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003244
3245/*
3246 * Read temporary secure storage
3247 *
3248 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3249 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003250#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003251
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003252struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003253 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003254} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003255
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003256struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003257 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003258} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003259
3260/*
3261 * Write temporary secure storage and lock it.
3262 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003263#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003264
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003265struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003266 uint8_t slot; /* Slot to write to */
3267 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003268} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003269
3270/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003271/* Thermal engine commands. Note that there are two implementations. We'll
3272 * reuse the command number, but the data and behavior is incompatible.
3273 * Version 0 is what originally shipped on Link.
3274 * Version 1 separates the CPU thermal limits from the fan control.
3275 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003276
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003277#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3278#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003279
Duncan Laurie93e24442014-01-06 12:30:52 -08003280/* The version 0 structs are opaque. You have to know what they are for
3281 * the get/set commands to make any sense.
3282 */
3283
3284/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003285struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003286 uint8_t sensor_type;
3287 uint8_t threshold_id;
3288 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003289} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003290
Duncan Laurie93e24442014-01-06 12:30:52 -08003291/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003292struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003293 uint8_t sensor_type;
3294 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003295} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003296
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003297struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003298 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003299} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003300
Duncan Laurie93e24442014-01-06 12:30:52 -08003301
3302/* The version 1 structs are visible. */
3303enum ec_temp_thresholds {
3304 EC_TEMP_THRESH_WARN = 0,
3305 EC_TEMP_THRESH_HIGH,
3306 EC_TEMP_THRESH_HALT,
3307
3308 EC_TEMP_THRESH_COUNT
3309};
3310
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003311/*
3312 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003313 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003314 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003315 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3316 * hysteresis.
3317 * For example,
3318 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3319 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3320 * EC will throttle ap when temperature >= 301 K, and release throttling when
3321 * temperature <= 299 K.
3322 *
3323 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3324 * For example,
3325 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3326 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3327 * EC will throttle ap when temperature >= 301 K, and release throttling when
3328 * temperature <= 294 K.
3329 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003330 * Note that this structure is a sub-structure of
3331 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003332 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003333struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003334 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003335 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08003336 uint32_t temp_fan_off; /* no active cooling needed */
3337 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003338} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003339
3340/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003341struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003342 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003343} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003344/* This returns a struct ec_thermal_config */
3345
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003346/*
3347 * Version 1 - set config for one sensor.
3348 * Use read-modify-write for best results!
3349 */
3350struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003351 uint32_t sensor_num;
3352 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003353} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003354/* This returns no data */
3355
3356/****************************************************************************/
3357
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003358/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003359#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003360
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003361/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003362struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003363 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003364} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003365
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003366/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003367#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3368#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003369
3370/*
3371 * The original TMP006 calibration only needed four params, but now we need
3372 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3373 * the params opaque. The v1 "get" response will include the algorithm number
3374 * and how many params it requires. That way we can change the EC code without
3375 * needing to update this file. We can also use a different algorithm on each
3376 * sensor.
3377 */
3378
3379/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003380struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003381 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003382} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003383
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003384/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003385struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003386 float s0;
3387 float b0;
3388 float b1;
3389 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003390} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003391
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003392struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003393 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003394 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003395 float s0;
3396 float b0;
3397 float b1;
3398 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003399} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003400
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003401/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003402struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003403 uint8_t algorithm;
3404 uint8_t num_params;
3405 uint8_t reserved[2];
3406 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003407} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003408
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003409struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003410 uint8_t index;
3411 uint8_t algorithm;
3412 uint8_t num_params;
3413 uint8_t reserved;
3414 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003415} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003416
3417
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003418/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003419#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003420
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003421struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003422 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003423} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003424
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003425struct ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003426 int32_t t; /* In 1/100 K */
3427 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003428} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003429
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003430/*****************************************************************************/
3431/* MKBP - Matrix KeyBoard Protocol */
3432
3433/*
3434 * Read key state
3435 *
3436 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3437 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003438 *
3439 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3440 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3441 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003442 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003443#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003444
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003445/*
3446 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3447 */
3448#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003449
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003450struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003451 uint32_t rows;
3452 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003453 /* Formerly "switches", which was 0. */
3454 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003455} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003456
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003457struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003458 uint8_t info_type;
3459 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003460} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003461
3462enum ec_mkbp_info_type {
3463 /*
3464 * Info about the keyboard matrix: number of rows and columns.
3465 *
3466 * Returns struct ec_response_mkbp_info.
3467 */
3468 EC_MKBP_INFO_KBD = 0,
3469
3470 /*
3471 * For buttons and switches, info about which specifically are
3472 * supported. event_type must be set to one of the values in enum
3473 * ec_mkbp_event.
3474 *
3475 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3476 * bitmask indicating which buttons or switches are present. See the
3477 * bit inidices below.
3478 */
3479 EC_MKBP_INFO_SUPPORTED = 1,
3480
3481 /*
3482 * Instantaneous state of buttons and switches.
3483 *
3484 * event_type must be set to one of the values in enum ec_mkbp_event.
3485 *
3486 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3487 * indicating the current state of the keyboard matrix.
3488 *
3489 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3490 * event state.
3491 *
3492 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3493 * state of supported buttons.
3494 *
3495 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3496 * state of supported switches.
3497 */
3498 EC_MKBP_INFO_CURRENT = 2,
3499};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003500
3501/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003502#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003503
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003504struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003505 uint8_t col;
3506 uint8_t row;
3507 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003508} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003509
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003510#define EC_CMD_GET_KEYBOARD_ID 0x0063
3511
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003512struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003513 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003514} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003515
3516enum keyboard_id {
3517 KEYBOARD_ID_UNSUPPORTED = 0,
3518 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3519};
3520
Duncan Laurie433432b2013-06-03 10:38:22 -07003521/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003522#define EC_CMD_MKBP_SET_CONFIG 0x0064
3523#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003524
3525/* flags */
3526enum mkbp_config_flags {
3527 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3528};
3529
3530enum mkbp_config_valid {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003531 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3532 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3533 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3534 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3535 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3536 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3537 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003538};
3539
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003540/*
3541 * Configuration for our key scanning algorithm.
3542 *
3543 * Note that this is used as a sub-structure of
3544 * ec_{params/response}_mkbp_get_config.
3545 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003546struct ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003547 uint32_t valid_mask; /* valid fields */
3548 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3549 uint8_t valid_flags; /* which flags are valid */
3550 uint16_t scan_period_us; /* period between start of scans */
3551 /* revert to interrupt mode after no activity for this long */
3552 uint32_t poll_timeout_us;
3553 /*
3554 * minimum post-scan relax time. Once we finish a scan we check
3555 * the time until we are due to start the next one. If this time is
3556 * shorter this field, we use this instead.
3557 */
3558 uint16_t min_post_scan_delay_us;
3559 /* delay between setting up output and waiting for it to settle */
3560 uint16_t output_settle_us;
3561 uint16_t debounce_down_us; /* time for debounce on key down */
3562 uint16_t debounce_up_us; /* time for debounce on key up */
3563 /* maximum depth to allow for fifo (0 = no keyscan output) */
3564 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003565} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003566
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003567struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003568 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003569} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003570
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003571struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003572 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003573} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003574
3575/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003576#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003577
3578enum ec_keyscan_seq_cmd {
3579 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3580 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3581 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3582 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3583 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3584};
3585
3586enum ec_collect_flags {
3587 /*
3588 * Indicates this scan was processed by the EC. Due to timing, some
3589 * scans may be skipped.
3590 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003591 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003592};
3593
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003594struct ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003595 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003596} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003597
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003598struct ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003599 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3600 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003601 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003602 uint8_t active; /* still active */
3603 uint8_t num_items; /* number of items */
3604 /* Current item being presented */
3605 uint8_t cur_item;
3606 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003607 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003608 /*
3609 * Absolute time for this scan, measured from the
3610 * start of the sequence.
3611 */
3612 uint32_t time_us;
3613 uint8_t scan[0]; /* keyscan data */
3614 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003615 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003616 uint8_t start_item; /* First item to return */
3617 uint8_t num_items; /* Number of items to return */
3618 } collect;
3619 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003620} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003621
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003622struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003623 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003624 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003625 uint8_t num_items; /* Number of items */
3626 /* Data for each item */
3627 struct ec_collect_item item[0];
3628 } collect;
3629 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003630} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003631
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003632/*
3633 * Get the next pending MKBP event.
3634 *
3635 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3636 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003637#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003638
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003639#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3640
3641/*
3642 * We use the most significant bit of the event type to indicate to the host
3643 * that the EC has more MKBP events available to provide.
3644 */
3645#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3646
3647/* The mask to apply to get the raw event type */
3648#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3649
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003650enum ec_mkbp_event {
3651 /* Keyboard matrix changed. The event data is the new matrix state. */
3652 EC_MKBP_EVENT_KEY_MATRIX = 0,
3653
3654 /* New host event. The event data is 4 bytes of host event flags. */
3655 EC_MKBP_EVENT_HOST_EVENT = 1,
3656
Duncan Laurieeb316852015-12-01 18:51:18 -08003657 /* New Sensor FIFO data. The event data is fifo_info structure. */
3658 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3659
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003660 /* The state of the non-matrixed buttons have changed. */
3661 EC_MKBP_EVENT_BUTTON = 3,
3662
3663 /* The state of the switches have changed. */
3664 EC_MKBP_EVENT_SWITCH = 4,
3665
3666 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3667 EC_MKBP_EVENT_FINGERPRINT = 5,
3668
3669 /*
3670 * Sysrq event: send emulated sysrq. The event data is sysrq,
3671 * corresponding to the key to be pressed.
3672 */
3673 EC_MKBP_EVENT_SYSRQ = 6,
3674
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003675 /*
3676 * New 64-bit host event.
3677 * The event data is 8 bytes of host event flags.
3678 */
3679 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3680
3681 /* Notify the AP that something happened on CEC */
3682 EC_MKBP_EVENT_CEC_EVENT = 8,
3683
3684 /* Send an incoming CEC message to the AP */
3685 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3686
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003687 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3688 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3689
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07003690 /* New online calibration values are available. */
3691 EC_MKBP_EVENT_ONLINE_CALIBRATION = 11,
3692
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003693 /* Number of MKBP events */
3694 EC_MKBP_EVENT_COUNT,
3695};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003696BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003697
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003698union __ec_align_offset1 ec_response_get_next_data {
3699 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003700
3701 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003702 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003703 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003704
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003705 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003706 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003707 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003708 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003709 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003710
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003711 uint32_t buttons;
3712
3713 uint32_t switches;
3714
3715 uint32_t fp_events;
3716
3717 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003718
3719 /* CEC events from enum mkbp_cec_event */
3720 uint32_t cec_events;
3721};
3722
3723union __ec_align_offset1 ec_response_get_next_data_v1 {
3724 uint8_t key_matrix[16];
3725
3726 /* Unaligned */
3727 uint32_t host_event;
3728 uint64_t host_event64;
3729
3730 struct __ec_todo_unpacked {
3731 /* For aligning the fifo_info */
3732 uint8_t reserved[3];
3733 struct ec_response_motion_sense_fifo_info info;
3734 } sensor_fifo;
3735
3736 uint32_t buttons;
3737
3738 uint32_t switches;
3739
3740 uint32_t fp_events;
3741
3742 uint32_t sysrq;
3743
3744 /* CEC events from enum mkbp_cec_event */
3745 uint32_t cec_events;
3746
3747 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003748};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003749BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003750
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003751struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003752 uint8_t event_type;
3753 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003754 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003755} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003756
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003757struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003758 uint8_t event_type;
3759 /* Followed by event data if any */
3760 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003761} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003762
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003763/* Bit indices for buttons and switches.*/
3764/* Buttons */
3765#define EC_MKBP_POWER_BUTTON 0
3766#define EC_MKBP_VOL_UP 1
3767#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003768#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003769
3770/* Switches */
3771#define EC_MKBP_LID_OPEN 0
3772#define EC_MKBP_TABLET_MODE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003773#define EC_MKBP_BASE_ATTACHED 2
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003774
Gwendal Grignou880b4582016-06-20 08:49:25 -07003775/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003776#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003777
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003778struct ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003779 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003780} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003781
3782/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3783#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003784#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3785#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3786#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3787 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3788#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3789#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3790#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3791 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003792#define EC_MKBP_FP_ENROLL BIT(27)
3793#define EC_MKBP_FP_MATCH BIT(28)
3794#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3795#define EC_MKBP_FP_FINGER_UP BIT(30)
3796#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003797/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3798#define EC_MKBP_FP_ERR_ENROLL_OK 0
3799#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3800#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3801#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3802#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3803/* Can be used to detect if image was usable for enrollment or not. */
3804#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3805/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3806#define EC_MKBP_FP_ERR_MATCH_NO 0
3807#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003808#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003809#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3810#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3811#define EC_MKBP_FP_ERR_MATCH_YES 1
3812#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3813#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3814
Gwendal Grignou880b4582016-06-20 08:49:25 -07003815
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003816#define EC_CMD_MKBP_WAKE_MASK 0x0069
3817enum ec_mkbp_event_mask_action {
3818 /* Retrieve the value of a wake mask. */
3819 GET_WAKE_MASK = 0,
3820
3821 /* Set the value of a wake mask. */
3822 SET_WAKE_MASK,
3823};
3824
3825enum ec_mkbp_mask_type {
3826 /*
3827 * These are host events sent via MKBP.
3828 *
3829 * Some examples are:
3830 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
3831 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
3832 *
3833 * The only things that should be in this mask are:
3834 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
3835 */
3836 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
3837
3838 /*
3839 * These are MKBP events. Some examples are:
3840 *
3841 * EC_MKBP_EVENT_KEY_MATRIX
3842 * EC_MKBP_EVENT_SWITCH
3843 *
3844 * The only things that should be in this mask are EC_MKBP_EVENT_*.
3845 */
3846 EC_MKBP_EVENT_WAKE_MASK,
3847};
3848
3849struct ec_params_mkbp_event_wake_mask {
3850 /* One of enum ec_mkbp_event_mask_action */
3851 uint8_t action;
3852
3853 /*
3854 * Which MKBP mask are you interested in acting upon? This is one of
3855 * ec_mkbp_mask_type.
3856 */
3857 uint8_t mask_type;
3858
3859 /* If setting a new wake mask, this contains the mask to set. */
3860 uint32_t new_wake_mask;
3861};
3862
3863struct ec_response_mkbp_event_wake_mask {
3864 uint32_t wake_mask;
3865};
3866
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003867/*****************************************************************************/
3868/* Temperature sensor commands */
3869
3870/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003871#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003872
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003873struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003874 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003875} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003876
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003877struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003878 char sensor_name[32];
3879 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003880} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003881
3882/*****************************************************************************/
3883
3884/*
3885 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3886 * commands accidentally sent to the wrong interface. See the ACPI section
3887 * below.
3888 */
3889
3890/*****************************************************************************/
3891/* Host event commands */
3892
Jenny TC1dfc2c32017-12-14 14:24:39 +05303893
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003894/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003895/*
3896 * Host event mask params and response structures, shared by all of the host
3897 * event commands below.
3898 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003899struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003900 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003901} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003902
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003903struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003904 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003905} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003906
3907/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003908#define EC_CMD_HOST_EVENT_GET_B 0x0087
3909#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3910#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3911#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003912
3913/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003914#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3915#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3916#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3917#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3918#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003919
Jenny TC1dfc2c32017-12-14 14:24:39 +05303920/*
3921 * Unified host event programming interface - Should be used by newer versions
3922 * of BIOS/OS to program host events and masks
3923 */
3924
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003925struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303926
3927 /* Action requested by host - one of enum ec_host_event_action. */
3928 uint8_t action;
3929
3930 /*
3931 * Mask type that the host requested the action on - one of
3932 * enum ec_host_event_mask_type.
3933 */
3934 uint8_t mask_type;
3935
3936 /* Set to 0, ignore on read */
3937 uint16_t reserved;
3938
3939 /* Value to be used in case of set operations. */
3940 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003941} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05303942
3943/*
3944 * Response structure returned by EC_CMD_HOST_EVENT.
3945 * Update the value on a GET request. Set to 0 on GET/CLEAR
3946 */
3947
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003948struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303949
3950 /* Mask value in case of get operation */
3951 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003952} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05303953
3954enum ec_host_event_action {
3955 /*
3956 * params.value is ignored. Value of mask_type populated
3957 * in response.value
3958 */
3959 EC_HOST_EVENT_GET,
3960
3961 /* Bits in params.value are set */
3962 EC_HOST_EVENT_SET,
3963
3964 /* Bits in params.value are cleared */
3965 EC_HOST_EVENT_CLEAR,
3966};
3967
3968enum ec_host_event_mask_type {
3969
3970 /* Main host event copy */
3971 EC_HOST_EVENT_MAIN,
3972
3973 /* Copy B of host events */
3974 EC_HOST_EVENT_B,
3975
3976 /* SCI Mask */
3977 EC_HOST_EVENT_SCI_MASK,
3978
3979 /* SMI Mask */
3980 EC_HOST_EVENT_SMI_MASK,
3981
3982 /* Mask of events that should be always reported in hostevents */
3983 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3984
3985 /* Active wake mask */
3986 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3987
3988 /* Lazy wake mask for S0ix */
3989 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3990
3991 /* Lazy wake mask for S3 */
3992 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3993
3994 /* Lazy wake mask for S5 */
3995 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3996};
3997
3998#define EC_CMD_HOST_EVENT 0x00A4
3999
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004000/*****************************************************************************/
4001/* Switch commands */
4002
4003/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004004#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004005
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004006struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004007 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004008} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004009
4010/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004011#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004012#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004013
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004014/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004015struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004016 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004017} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004018
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004019/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004020struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004021 /* Flags to enable now */
4022 uint8_t now_flags;
4023
4024 /* Which flags to copy from now_flags */
4025 uint8_t now_mask;
4026
4027 /*
4028 * Flags to leave enabled in S3, if they're on at the S0->S3
4029 * transition. (Other flags will be disabled by the S0->S3
4030 * transition.)
4031 */
4032 uint8_t suspend_flags;
4033
4034 /* Which flags to copy from suspend_flags */
4035 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004036} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004037
4038/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004039struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004040 /* Flags to enable now */
4041 uint8_t now_flags;
4042
4043 /* Flags to leave enabled in S3 */
4044 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004045} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004046
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004047/*****************************************************************************/
4048/* GPIO commands. Only available on EC if write protect has been disabled. */
4049
4050/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004051#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004052
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004053struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004054 char name[32];
4055 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004056} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004057
4058/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004059#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004060
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004061/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004062struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004063 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004064} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004065
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004066struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004067 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004068} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004069
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004070/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004071struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004072 uint8_t subcmd;
4073 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004074 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004075 char name[32];
4076 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004077 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004078 uint8_t index;
4079 } get_info;
4080 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004081} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004082
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004083struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004084 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004085 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004086 uint8_t val;
4087 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004088 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004089 uint8_t val;
4090 char name[32];
4091 uint32_t flags;
4092 } get_info;
4093 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004094} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004095
4096enum gpio_get_subcmd {
4097 EC_GPIO_GET_BY_NAME = 0,
4098 EC_GPIO_GET_COUNT = 1,
4099 EC_GPIO_GET_INFO = 2,
4100};
4101
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004102/*****************************************************************************/
4103/* I2C commands. Only available when flash write protect is unlocked. */
4104
Duncan Laurie93e24442014-01-06 12:30:52 -08004105/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004106 * CAUTION: These commands are deprecated, and are not supported anymore in EC
4107 * builds >= 8398.0.0 (see crosbug.com/p/23570).
4108 *
4109 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08004110 */
4111
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004112/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004113#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004114
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004115struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07004116 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004117 uint8_t read_size; /* Either 8 or 16. */
4118 uint8_t port;
4119 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004120} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004121
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004122struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004123 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004124} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004125
4126/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004127#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004128
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004129struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004130 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07004131 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004132 uint8_t write_size; /* Either 8 or 16. */
4133 uint8_t port;
4134 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004135} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004136
4137/*****************************************************************************/
4138/* Charge state commands. Only available when flash write protect unlocked. */
4139
Duncan Laurie93e24442014-01-06 12:30:52 -08004140/* Force charge state machine to stop charging the battery or force it to
4141 * discharge the battery.
4142 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004143#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08004144#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004145
Duncan Laurie93e24442014-01-06 12:30:52 -08004146enum ec_charge_control_mode {
4147 CHARGE_CONTROL_NORMAL = 0,
4148 CHARGE_CONTROL_IDLE,
4149 CHARGE_CONTROL_DISCHARGE,
4150};
4151
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004152struct ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08004153 uint32_t mode; /* enum charge_control_mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004154} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004155
4156/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004157
4158/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004159#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004160
4161/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004162 * Read data from the saved snapshot. If the subcmd parameter is
4163 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4164 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4165 * end of the previous snapshot.
4166 *
4167 * The params are only looked at in version >= 1 of this command. Prior
4168 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004169 *
4170 * Response is null-terminated string. Empty string, if there is no more
4171 * remaining output.
4172 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004173#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004174
Duncan Laurieeb316852015-12-01 18:51:18 -08004175enum ec_console_read_subcmd {
4176 CONSOLE_READ_NEXT = 0,
4177 CONSOLE_READ_RECENT
4178};
4179
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004180struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004181 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004182} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004183
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004184/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004185
4186/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004187 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004188 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004189 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4190 * EC_RES_SUCCESS if the command was successful.
4191 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004192 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004193#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004194
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004195#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004196
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004197struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004198 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004199} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004200
Duncan Laurie433432b2013-06-03 10:38:22 -07004201/*****************************************************************************/
4202/* USB port mux control. */
4203
4204/*
4205 * Switch USB mux or return to automatic switching.
4206 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004207#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004208
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004209struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004210 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004211} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004212
4213/*****************************************************************************/
4214/* LDOs / FETs control. */
4215
4216enum ec_ldo_state {
4217 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4218 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4219};
4220
4221/*
4222 * Switch on/off a LDO.
4223 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004224#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004225
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004226struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004227 uint8_t index;
4228 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004229} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004230
4231/*
4232 * Get LDO state.
4233 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004234#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004235
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004236struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004237 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004238} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004239
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004240struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004241 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004242} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004243
4244/*****************************************************************************/
4245/* Power info. */
4246
4247/*
4248 * Get power info.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004249 *
4250 * Note: v0 of this command is deprecated
Duncan Laurie433432b2013-06-03 10:38:22 -07004251 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004252#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004253
Jett Rinkba2edaf2020-01-14 11:49:06 -07004254/*
4255 * v1 of EC_CMD_POWER_INFO
4256 */
4257enum system_power_source {
4258 /*
4259 * Haven't established which power source is used yet,
4260 * or no presence signals are available
4261 */
4262 POWER_SOURCE_UNKNOWN = 0,
4263 /* System is running on battery alone */
4264 POWER_SOURCE_BATTERY = 1,
4265 /* System is running on A/C alone */
4266 POWER_SOURCE_AC = 2,
4267 /* System is running on A/C and battery */
4268 POWER_SOURCE_AC_BATTERY = 3,
4269};
4270
4271struct ec_response_power_info_v1 {
4272 /* enum system_power_source */
4273 uint8_t system_power_source;
4274 /* Battery state-of-charge, 0-100, 0 if not present */
4275 uint8_t battery_soc;
4276 /* AC Adapter 100% rating, Watts */
4277 uint8_t ac_adapter_100pct;
4278 /* AC Adapter 10ms rating, Watts */
4279 uint8_t ac_adapter_10ms;
4280 /* Battery 1C rating, derated */
4281 uint8_t battery_1cd;
4282 /* Rest of Platform average, Watts */
4283 uint8_t rop_avg;
4284 /* Rest of Platform peak, Watts */
4285 uint8_t rop_peak;
4286 /* Nominal charger efficiency, % */
4287 uint8_t nominal_charger_eff;
4288 /* Rest of Platform VR Average Efficiency, % */
4289 uint8_t rop_avg_eff;
4290 /* Rest of Platform VR Peak Efficiency, % */
4291 uint8_t rop_peak_eff;
4292 /* SoC VR Efficiency at Average level, % */
4293 uint8_t soc_avg_eff;
4294 /* SoC VR Efficiency at Peak level, % */
4295 uint8_t soc_peak_eff;
4296 /* Intel-specific items */
4297 struct {
4298 /* Battery's level of DBPT support: 0, 2 */
4299 uint8_t batt_dbpt_support_level;
4300 /*
4301 * Maximum peak power from battery (10ms), Watts
4302 * If DBPT is not supported, this is 0
4303 */
4304 uint8_t batt_dbpt_max_peak_power;
4305 /*
4306 * Sustained peak power from battery, Watts
4307 * If DBPT is not supported, this is 0
4308 */
4309 uint8_t batt_dbpt_sus_peak_power;
4310 } intel;
4311} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004312
4313/*****************************************************************************/
4314/* I2C passthru command */
4315
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004316#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004317
Duncan Laurie433432b2013-06-03 10:38:22 -07004318/* Read data; if not present, message is a write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004319#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004320
4321/* Mask for address */
4322#define EC_I2C_ADDR_MASK 0x3ff
4323
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004324#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4325#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004326
4327/* Any error */
4328#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4329
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004330struct ec_params_i2c_passthru_msg {
4331 uint16_t addr_flags; /* I2C slave address and flags */
Duncan Laurie433432b2013-06-03 10:38:22 -07004332 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004333} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004334
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004335struct ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004336 uint8_t port; /* I2C port number */
4337 uint8_t num_msgs; /* Number of messages */
4338 struct ec_params_i2c_passthru_msg msg[];
4339 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004340} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004341
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004342struct ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004343 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4344 uint8_t num_msgs; /* Number of messages processed */
4345 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004346} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004347
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004348/*****************************************************************************/
4349/* Power button hang detect */
4350
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004351#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004352
4353/* Reasons to start hang detection timer */
4354/* Power button pressed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004355#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004356
4357/* Lid closed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004358#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004359
4360 /* Lid opened */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004361#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004362
4363/* Start of AP S3->S0 transition (booting or resuming from suspend) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004364#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004365
4366/* Reasons to cancel hang detection */
4367
4368/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004369#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004370
4371/* Any host command from AP received */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004372#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004373
4374/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004375#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004376
4377/*
4378 * If this flag is set, all the other fields are ignored, and the hang detect
4379 * timer is started. This provides the AP a way to start the hang timer
4380 * without reconfiguring any of the other hang detect settings. Note that
4381 * you must previously have configured the timeouts.
4382 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004383#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004384
4385/*
4386 * If this flag is set, all the other fields are ignored (including
4387 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4388 * without reconfiguring any of the other hang detect settings.
4389 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004390#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004391
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004392struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004393 /* Flags; see EC_HANG_* */
4394 uint32_t flags;
4395
4396 /* Timeout in msec before generating host event, if enabled */
4397 uint16_t host_event_timeout_msec;
4398
4399 /* Timeout in msec before generating warm reboot, if enabled */
4400 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004401} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004402
4403/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004404/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004405
4406/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004407 * This is the single catch-all host command to exchange data regarding the
4408 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004409 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004410#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004411
4412/* Subcommands for this host command */
4413enum charge_state_command {
4414 CHARGE_STATE_CMD_GET_STATE,
4415 CHARGE_STATE_CMD_GET_PARAM,
4416 CHARGE_STATE_CMD_SET_PARAM,
4417 CHARGE_STATE_NUM_CMDS
4418};
4419
4420/*
4421 * Known param numbers are defined here. Ranges are reserved for board-specific
4422 * params, which are handled by the particular implementations.
4423 */
4424enum charge_state_params {
4425 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4426 CS_PARAM_CHG_CURRENT, /* charger current limit */
4427 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4428 CS_PARAM_CHG_STATUS, /* charger-specific status */
4429 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08004430 CS_PARAM_LIMIT_POWER, /*
4431 * Check if power is limited due to
4432 * low battery and / or a weak external
4433 * charger. READ ONLY.
4434 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004435 /* How many so far? */
4436 CS_NUM_BASE_PARAMS,
4437
4438 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4439 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4440 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4441
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004442 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4443 CS_PARAM_DEBUG_MIN = 0x20000,
4444 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4445 CS_PARAM_DEBUG_MANUAL_MODE,
4446 CS_PARAM_DEBUG_SEEMS_DEAD,
4447 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4448 CS_PARAM_DEBUG_BATT_REMOVED,
4449 CS_PARAM_DEBUG_MANUAL_CURRENT,
4450 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4451 CS_PARAM_DEBUG_MAX = 0x2ffff,
4452
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004453 /* Other custom param ranges go here... */
4454};
4455
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004456struct ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004457 uint8_t cmd; /* enum charge_state_command */
4458 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004459 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004460
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004461 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004462 uint32_t param; /* enum charge_state_param */
4463 } get_param;
4464
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004465 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004466 uint32_t param; /* param to set */
4467 uint32_t value; /* value to set */
4468 } set_param;
4469 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004470} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004471
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004472struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004473 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004474 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004475 int ac;
4476 int chg_voltage;
4477 int chg_current;
4478 int chg_input_current;
4479 int batt_state_of_charge;
4480 } get_state;
4481
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004482 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004483 uint32_t value;
4484 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004485
4486 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004487 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004488} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004489
Duncan Laurie433432b2013-06-03 10:38:22 -07004490
4491/*
4492 * Set maximum battery charging current.
4493 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004494#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004495
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004496struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004497 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004498} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004499
4500/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004501 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004502 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004503#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004504
Duncan Laurieeb316852015-12-01 18:51:18 -08004505/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004506struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004507 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4508 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004509} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004510
Duncan Laurieeb316852015-12-01 18:51:18 -08004511#define EC_POWER_LIMIT_NONE 0xffff
4512
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004513/*
4514 * Set maximum voltage & current of a dedicated charge port
4515 */
4516#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4517
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004518struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004519 uint16_t current_lim; /* in mA */
4520 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004521} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004522
Duncan Laurieeb316852015-12-01 18:51:18 -08004523/*****************************************************************************/
4524/* Hibernate/Deep Sleep Commands */
4525
4526/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004527#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004528
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004529struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004530 /*
4531 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4532 * current settings without changing them.
4533 */
4534 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004535} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004536
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004537struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004538 /*
4539 * The current time in seconds in which the system has been in the G3
4540 * state. This value is reset if the EC transitions out of G3.
4541 */
4542 uint32_t time_g3;
4543
4544 /*
4545 * The current time remaining in seconds until the EC should hibernate.
4546 * This value is also reset if the EC transitions out of G3.
4547 */
4548 uint32_t time_remaining;
4549
4550 /*
4551 * The current time in seconds that the EC should wait in G3 before
4552 * hibernating.
4553 */
4554 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004555} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004556
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004557/* Inform the EC when entering a sleep state */
4558#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4559
4560enum host_sleep_event {
4561 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4562 HOST_SLEEP_EVENT_S3_RESUME = 2,
4563 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004564 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4565 /* S3 suspend with additional enabled wake sources */
4566 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004567};
4568
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004569struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004570 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004571} __ec_align1;
4572
4573/*
4574 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4575 * transition failures
4576 */
4577#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4578
4579/* Disable timeout detection for this sleep transition */
4580#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4581
4582struct ec_params_host_sleep_event_v1 {
4583 /* The type of sleep being entered or exited. */
4584 uint8_t sleep_event;
4585
4586 /* Padding */
4587 uint8_t reserved;
4588 union {
4589 /* Parameters that apply for suspend messages. */
4590 struct {
4591 /*
4592 * The timeout in milliseconds between when this message
4593 * is received and when the EC will declare sleep
4594 * transition failure if the sleep signal is not
4595 * asserted.
4596 */
4597 uint16_t sleep_timeout_ms;
4598 } suspend_params;
4599
4600 /* No parameters for non-suspend messages. */
4601 };
4602} __ec_align2;
4603
4604/* A timeout occurred when this bit is set */
4605#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4606
4607/*
4608 * The mask defining which bits correspond to the number of sleep transitions,
4609 * as well as the maximum number of suspend line transitions that will be
4610 * reported back to the host.
4611 */
4612#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4613
4614struct ec_response_host_sleep_event_v1 {
4615 union {
4616 /* Response fields that apply for resume messages. */
4617 struct {
4618 /*
4619 * The number of sleep power signal transitions that
4620 * occurred since the suspend message. The high bit
4621 * indicates a timeout occurred.
4622 */
4623 uint32_t sleep_transitions;
4624 } resume_response;
4625
4626 /* No response fields for non-resume messages. */
4627 };
4628} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004629
4630/*****************************************************************************/
4631/* Device events */
4632#define EC_CMD_DEVICE_EVENT 0x00AA
4633
4634enum ec_device_event {
4635 EC_DEVICE_EVENT_TRACKPAD,
4636 EC_DEVICE_EVENT_DSP,
4637 EC_DEVICE_EVENT_WIFI,
4638};
4639
4640enum ec_device_event_param {
4641 /* Get and clear pending device events */
4642 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4643 /* Get device event mask */
4644 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4645 /* Set device event mask */
4646 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4647};
4648
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004649#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004650
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004651struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004652 uint32_t event_mask;
4653 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004654} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004655
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004656struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004657 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004658} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004659
Duncan Laurie433432b2013-06-03 10:38:22 -07004660/*****************************************************************************/
4661/* Smart battery pass-through */
4662
4663/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004664#define EC_CMD_SB_READ_WORD 0x00B0
4665#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004666
4667/* Get / Set string smart battery parameters
4668 * formatted as SMBUS "block".
4669 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004670#define EC_CMD_SB_READ_BLOCK 0x00B2
4671#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004672
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004673struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004674 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004675} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004676
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004677struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004678 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004679} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004680
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004681struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004682 uint8_t reg;
4683 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004684} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004685
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004686struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004687 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004688} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004689
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004690struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004691 uint8_t reg;
4692 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004693} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004694
4695/*****************************************************************************/
4696/* Battery vendor parameters
4697 *
4698 * Get or set vendor-specific parameters in the battery. Implementations may
4699 * differ between boards or batteries. On a set operation, the response
4700 * contains the actual value set, which may be rounded or clipped from the
4701 * requested value.
4702 */
4703
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004704#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004705
4706enum ec_battery_vendor_param_mode {
4707 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4708 BATTERY_VENDOR_PARAM_MODE_SET,
4709};
4710
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004711struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004712 uint32_t param;
4713 uint32_t value;
4714 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004715} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004716
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004717struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004718 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004719} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004720
4721/*****************************************************************************/
4722/*
4723 * Smart Battery Firmware Update Commands
4724 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004725#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004726
4727enum ec_sb_fw_update_subcmd {
4728 EC_SB_FW_UPDATE_PREPARE = 0x0,
4729 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4730 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4731 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4732 EC_SB_FW_UPDATE_END = 0x4,
4733 EC_SB_FW_UPDATE_STATUS = 0x5,
4734 EC_SB_FW_UPDATE_PROTECT = 0x6,
4735 EC_SB_FW_UPDATE_MAX = 0x7,
4736};
4737
4738#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4739#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4740#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4741
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004742struct ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004743 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4744 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004745} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004746
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004747struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004748 struct ec_sb_fw_update_header hdr;
4749 union {
4750 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4751 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4752 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4753 /* EC_SB_FW_UPDATE_END = 0x4 */
4754 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4755 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004756 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004757
4758 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004759 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004760 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4761 } write;
4762 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004763} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004764
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004765struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004766 union {
4767 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004768 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004769 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4770 } info;
4771
4772 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004773 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004774 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4775 } status;
4776 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004777} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004778
4779/*
4780 * Entering Verified Boot Mode Command
4781 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4782 * Valid Modes are: normal, developer, and recovery.
Jett Rinkba2edaf2020-01-14 11:49:06 -07004783 *
4784 * EC no longer needs to know what mode vboot has entered,
4785 * so this command is deprecated. (See chromium:1014379.)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004786 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004787#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004788
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004789struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004790 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004791} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004792
4793#define VBOOT_MODE_NORMAL 0
4794#define VBOOT_MODE_DEVELOPER 1
4795#define VBOOT_MODE_RECOVERY 2
4796
Duncan Laurie433432b2013-06-03 10:38:22 -07004797/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004798/*
4799 * I2C passthru protection command: Protects I2C tunnels against access on
4800 * certain addresses (board-specific).
4801 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004802#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004803
4804enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004805 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
4806 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
4807 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07004808};
4809
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004810struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004811 uint8_t subcmd;
4812 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004813} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004814
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004815struct ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004816 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004817} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004818
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004819
4820/*****************************************************************************/
4821/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004822 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004823 *
4824 * These commands are for sending and receiving message via HDMI CEC
4825 */
4826
4827#define MAX_CEC_MSG_LEN 16
4828
4829/* CEC message from the AP to be written on the CEC bus */
4830#define EC_CMD_CEC_WRITE_MSG 0x00B8
4831
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004832/**
4833 * struct ec_params_cec_write - Message to write to the CEC bus
4834 * @msg: message content to write to the CEC bus
4835 */
4836struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004837 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004838} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004839
4840/* Set various CEC parameters */
4841#define EC_CMD_CEC_SET 0x00BA
4842
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004843/**
4844 * struct ec_params_cec_set - CEC parameters set
4845 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4846 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
4847 * or 1 to enable CEC functionality, in case cmd is
4848 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
4849 * address between 0 and 15 or 0xff to unregister
4850 */
4851struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004852 uint8_t cmd; /* enum cec_command */
4853 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004854} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004855
4856/* Read various CEC parameters */
4857#define EC_CMD_CEC_GET 0x00BB
4858
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004859/**
4860 * struct ec_params_cec_get - CEC parameters get
4861 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4862 */
4863struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004864 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004865} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004866
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004867/**
4868 * struct ec_response_cec_get - CEC parameters get response
4869 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
4870 * disabled or 1 if CEC functionality is enabled,
4871 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
4872 * configured logical address between 0 and 15 or 0xff if unregistered
4873 */
4874struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004875 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004876} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004877
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004878/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004879enum cec_command {
4880 /* CEC reading, writing and events enable */
4881 CEC_CMD_ENABLE,
4882 /* CEC logical address */
4883 CEC_CMD_LOGICAL_ADDRESS,
4884};
4885
4886/* Events from CEC to AP */
4887enum mkbp_cec_event {
4888 /* Outgoing message was acknowledged by a follower */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004889 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004890 /* Outgoing message was not acknowledged */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004891 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004892};
4893
Gwendal Grignou880b4582016-06-20 08:49:25 -07004894/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004895
Jett Rinkba2edaf2020-01-14 11:49:06 -07004896/* Commands for audio codec. */
4897#define EC_CMD_EC_CODEC 0x00BC
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004898
Jett Rinkba2edaf2020-01-14 11:49:06 -07004899enum ec_codec_subcmd {
4900 EC_CODEC_GET_CAPABILITIES = 0x0,
4901 EC_CODEC_GET_SHM_ADDR = 0x1,
4902 EC_CODEC_SET_SHM_ADDR = 0x2,
4903 EC_CODEC_SUBCMD_COUNT,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004904};
4905
Jett Rinkba2edaf2020-01-14 11:49:06 -07004906enum ec_codec_cap {
4907 EC_CODEC_CAP_WOV_AUDIO_SHM = 0,
4908 EC_CODEC_CAP_WOV_LANG_SHM = 1,
4909 EC_CODEC_CAP_LAST = 32,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004910};
4911
Jett Rinkba2edaf2020-01-14 11:49:06 -07004912enum ec_codec_shm_id {
4913 EC_CODEC_SHM_ID_WOV_AUDIO = 0x0,
4914 EC_CODEC_SHM_ID_WOV_LANG = 0x1,
4915 EC_CODEC_SHM_ID_LAST,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004916};
4917
Jett Rinkba2edaf2020-01-14 11:49:06 -07004918enum ec_codec_shm_type {
4919 EC_CODEC_SHM_TYPE_EC_RAM = 0x0,
4920 EC_CODEC_SHM_TYPE_SYSTEM_RAM = 0x1,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004921};
4922
Jett Rinkba2edaf2020-01-14 11:49:06 -07004923struct __ec_align1 ec_param_ec_codec_get_shm_addr {
4924 uint8_t shm_id;
4925 uint8_t reserved[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004926};
4927
Jett Rinkba2edaf2020-01-14 11:49:06 -07004928struct __ec_align4 ec_param_ec_codec_set_shm_addr {
4929 uint64_t phys_addr;
4930 uint32_t len;
4931 uint8_t shm_id;
4932 uint8_t reserved[3];
4933};
4934
4935struct __ec_align4 ec_param_ec_codec {
4936 uint8_t cmd; /* enum ec_codec_subcmd */
4937 uint8_t reserved[3];
4938
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004939 union {
Jett Rinkba2edaf2020-01-14 11:49:06 -07004940 struct ec_param_ec_codec_get_shm_addr
4941 get_shm_addr_param;
4942 struct ec_param_ec_codec_set_shm_addr
4943 set_shm_addr_param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004944 };
4945};
4946
Jett Rinkba2edaf2020-01-14 11:49:06 -07004947struct __ec_align4 ec_response_ec_codec_get_capabilities {
4948 uint32_t capabilities;
4949};
4950
4951struct __ec_align4 ec_response_ec_codec_get_shm_addr {
4952 uint64_t phys_addr;
4953 uint32_t len;
4954 uint8_t type;
4955 uint8_t reserved[3];
4956};
4957
4958/*****************************************************************************/
4959
4960/* Commands for DMIC on audio codec. */
4961#define EC_CMD_EC_CODEC_DMIC 0x00BD
4962
4963enum ec_codec_dmic_subcmd {
4964 EC_CODEC_DMIC_GET_MAX_GAIN = 0x0,
4965 EC_CODEC_DMIC_SET_GAIN_IDX = 0x1,
4966 EC_CODEC_DMIC_GET_GAIN_IDX = 0x2,
4967 EC_CODEC_DMIC_SUBCMD_COUNT,
4968};
4969
4970enum ec_codec_dmic_channel {
4971 EC_CODEC_DMIC_CHANNEL_0 = 0x0,
4972 EC_CODEC_DMIC_CHANNEL_1 = 0x1,
4973 EC_CODEC_DMIC_CHANNEL_2 = 0x2,
4974 EC_CODEC_DMIC_CHANNEL_3 = 0x3,
4975 EC_CODEC_DMIC_CHANNEL_4 = 0x4,
4976 EC_CODEC_DMIC_CHANNEL_5 = 0x5,
4977 EC_CODEC_DMIC_CHANNEL_6 = 0x6,
4978 EC_CODEC_DMIC_CHANNEL_7 = 0x7,
4979 EC_CODEC_DMIC_CHANNEL_COUNT,
4980};
4981
4982struct __ec_align1 ec_param_ec_codec_dmic_set_gain_idx {
4983 uint8_t channel; /* enum ec_codec_dmic_channel */
4984 uint8_t gain;
4985 uint8_t reserved[2];
4986};
4987
4988struct __ec_align1 ec_param_ec_codec_dmic_get_gain_idx {
4989 uint8_t channel; /* enum ec_codec_dmic_channel */
4990 uint8_t reserved[3];
4991};
4992
4993struct __ec_align4 ec_param_ec_codec_dmic {
4994 uint8_t cmd; /* enum ec_codec_dmic_subcmd */
4995 uint8_t reserved[3];
4996
4997 union {
4998 struct ec_param_ec_codec_dmic_set_gain_idx
4999 set_gain_idx_param;
5000 struct ec_param_ec_codec_dmic_get_gain_idx
5001 get_gain_idx_param;
5002 };
5003};
5004
5005struct __ec_align1 ec_response_ec_codec_dmic_get_max_gain {
5006 uint8_t max_gain;
5007};
5008
5009struct __ec_align1 ec_response_ec_codec_dmic_get_gain_idx {
5010 uint8_t gain;
5011};
5012
5013/*****************************************************************************/
5014
5015/* Commands for I2S RX on audio codec. */
5016
5017#define EC_CMD_EC_CODEC_I2S_RX 0x00BE
5018
5019enum ec_codec_i2s_rx_subcmd {
5020 EC_CODEC_I2S_RX_ENABLE = 0x0,
5021 EC_CODEC_I2S_RX_DISABLE = 0x1,
5022 EC_CODEC_I2S_RX_SET_SAMPLE_DEPTH = 0x2,
5023 EC_CODEC_I2S_RX_SET_DAIFMT = 0x3,
5024 EC_CODEC_I2S_RX_SET_BCLK = 0x4,
5025 EC_CODEC_I2S_RX_SUBCMD_COUNT,
5026};
5027
5028enum ec_codec_i2s_rx_sample_depth {
5029 EC_CODEC_I2S_RX_SAMPLE_DEPTH_16 = 0x0,
5030 EC_CODEC_I2S_RX_SAMPLE_DEPTH_24 = 0x1,
5031 EC_CODEC_I2S_RX_SAMPLE_DEPTH_COUNT,
5032};
5033
5034enum ec_codec_i2s_rx_daifmt {
5035 EC_CODEC_I2S_RX_DAIFMT_I2S = 0x0,
5036 EC_CODEC_I2S_RX_DAIFMT_RIGHT_J = 0x1,
5037 EC_CODEC_I2S_RX_DAIFMT_LEFT_J = 0x2,
5038 EC_CODEC_I2S_RX_DAIFMT_COUNT,
5039};
5040
5041struct __ec_align1 ec_param_ec_codec_i2s_rx_set_sample_depth {
5042 uint8_t depth;
5043 uint8_t reserved[3];
5044};
5045
5046struct __ec_align1 ec_param_ec_codec_i2s_rx_set_gain {
5047 uint8_t left;
5048 uint8_t right;
5049 uint8_t reserved[2];
5050};
5051
5052struct __ec_align1 ec_param_ec_codec_i2s_rx_set_daifmt {
5053 uint8_t daifmt;
5054 uint8_t reserved[3];
5055};
5056
5057struct __ec_align4 ec_param_ec_codec_i2s_rx_set_bclk {
5058 uint32_t bclk;
5059};
5060
5061struct __ec_align4 ec_param_ec_codec_i2s_rx {
5062 uint8_t cmd; /* enum ec_codec_i2s_rx_subcmd */
5063 uint8_t reserved[3];
5064
5065 union {
5066 struct ec_param_ec_codec_i2s_rx_set_sample_depth
5067 set_sample_depth_param;
5068 struct ec_param_ec_codec_i2s_rx_set_daifmt
5069 set_daifmt_param;
5070 struct ec_param_ec_codec_i2s_rx_set_bclk
5071 set_bclk_param;
5072 };
5073};
5074
5075/*****************************************************************************/
5076/* Commands for WoV on audio codec. */
5077
5078#define EC_CMD_EC_CODEC_WOV 0x00BF
5079
5080enum ec_codec_wov_subcmd {
5081 EC_CODEC_WOV_SET_LANG = 0x0,
5082 EC_CODEC_WOV_SET_LANG_SHM = 0x1,
5083 EC_CODEC_WOV_GET_LANG = 0x2,
5084 EC_CODEC_WOV_ENABLE = 0x3,
5085 EC_CODEC_WOV_DISABLE = 0x4,
5086 EC_CODEC_WOV_READ_AUDIO = 0x5,
5087 EC_CODEC_WOV_READ_AUDIO_SHM = 0x6,
5088 EC_CODEC_WOV_SUBCMD_COUNT,
5089};
5090
5091/*
5092 * @hash is SHA256 of the whole language model.
5093 * @total_len indicates the length of whole language model.
5094 * @offset is the cursor from the beginning of the model.
5095 * @buf is the packet buffer.
5096 * @len denotes how many bytes in the buf.
5097 */
5098struct __ec_align4 ec_param_ec_codec_wov_set_lang {
5099 uint8_t hash[32];
5100 uint32_t total_len;
5101 uint32_t offset;
5102 uint8_t buf[128];
5103 uint32_t len;
5104};
5105
5106struct __ec_align4 ec_param_ec_codec_wov_set_lang_shm {
5107 uint8_t hash[32];
5108 uint32_t total_len;
5109};
5110
5111struct __ec_align4 ec_param_ec_codec_wov {
5112 uint8_t cmd; /* enum ec_codec_wov_subcmd */
5113 uint8_t reserved[3];
5114
5115 union {
5116 struct ec_param_ec_codec_wov_set_lang
5117 set_lang_param;
5118 struct ec_param_ec_codec_wov_set_lang_shm
5119 set_lang_shm_param;
5120 };
5121};
5122
5123struct __ec_align4 ec_response_ec_codec_wov_get_lang {
5124 uint8_t hash[32];
5125};
5126
5127struct __ec_align4 ec_response_ec_codec_wov_read_audio {
5128 uint8_t buf[128];
5129 uint32_t len;
5130};
5131
5132struct __ec_align4 ec_response_ec_codec_wov_read_audio_shm {
5133 uint32_t offset;
5134 uint32_t len;
5135};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005136
5137/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005138/* System commands */
5139
5140/*
Duncan Laurie93e24442014-01-06 12:30:52 -08005141 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
5142 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005143 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005144#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005145
5146/* Command */
5147enum ec_reboot_cmd {
5148 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005149 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005150 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005151 /* (command 3 was jump to RW-B) */
5152 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07005153 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08005154 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
5155 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005156};
5157
5158/* Flags for ec_params_reboot_ec.reboot_flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005159#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
5160#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
5161#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005162
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005163struct ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005164 uint8_t cmd; /* enum ec_reboot_cmd */
5165 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005166} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005167
Duncan Laurie433432b2013-06-03 10:38:22 -07005168/*
5169 * Get information on last EC panic.
5170 *
5171 * Returns variable-length platform-dependent panic information. See panic.h
5172 * for details.
5173 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005174#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07005175
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005176/*****************************************************************************/
5177/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005178 * Special commands
5179 *
5180 * These do not follow the normal rules for commands. See each command for
5181 * details.
5182 */
5183
5184/*
5185 * Reboot NOW
5186 *
5187 * This command will work even when the EC LPC interface is busy, because the
5188 * reboot command is processed at interrupt level. Note that when the EC
5189 * reboots, the host will reboot too, so there is no response to this command.
5190 *
5191 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
5192 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005193#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005194
5195/*
Duncan Laurie433432b2013-06-03 10:38:22 -07005196 * Resend last response (not supported on LPC).
5197 *
5198 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
5199 * there was no previous command, or the previous command's response was too
5200 * big to save.
5201 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005202#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07005203
5204/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005205 * This header byte on a command indicate version 0. Any header byte less
5206 * than this means that we are talking to an old EC which doesn't support
5207 * versioning. In that case, we assume version 0.
5208 *
5209 * Header bytes greater than this indicate a later version. For example,
5210 * EC_CMD_VERSION0 + 1 means we are using version 1.
5211 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005212 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005213 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005214#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005215
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005216/*****************************************************************************/
5217/*
5218 * PD commands
5219 *
5220 * These commands are for PD MCU communication.
5221 */
5222
5223/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005224#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08005225#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005226
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005227enum pd_charge_state {
5228 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
5229 PD_CHARGE_NONE, /* No charging allowed */
5230 PD_CHARGE_5V, /* 5V charging only */
5231 PD_CHARGE_MAX /* Charge at max voltage */
5232};
5233
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005234/* Status of EC being sent to PD */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005235#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08005236
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005237struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005238 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005239 int8_t batt_soc; /* battery state of charge */
5240 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005241} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005242
5243/* Status of PD being sent back to EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005244#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
5245#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
5246#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
5247#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
5248#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
5249#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
5250#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
Duncan Laurieeb316852015-12-01 18:51:18 -08005251#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
5252 PD_STATUS_TCPC_ALERT_1 | \
5253 PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005254struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08005255 uint32_t curr_lim_ma; /* input current limit */
5256 uint16_t status; /* PD MCU status */
5257 int8_t active_charge_port; /* active charging port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005258} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005259
5260/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005261#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005262
5263/* PD MCU host event status bits */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005264#define PD_EVENT_UPDATE_DEVICE BIT(0)
5265#define PD_EVENT_POWER_CHANGE BIT(1)
5266#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
5267#define PD_EVENT_DATA_SWAP BIT(3)
5268struct ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005269 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005270} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005271
5272/* Set USB type-C port role and muxes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005273#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005274
5275enum usb_pd_control_role {
5276 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
5277 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
5278 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
5279 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
5280 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005281 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005282 USB_PD_CTRL_ROLE_COUNT
5283};
5284
5285enum usb_pd_control_mux {
5286 USB_PD_CTRL_MUX_NO_CHANGE = 0,
5287 USB_PD_CTRL_MUX_NONE = 1,
5288 USB_PD_CTRL_MUX_USB = 2,
5289 USB_PD_CTRL_MUX_DP = 3,
5290 USB_PD_CTRL_MUX_DOCK = 4,
5291 USB_PD_CTRL_MUX_AUTO = 5,
5292 USB_PD_CTRL_MUX_COUNT
5293};
5294
Duncan Laurieeb316852015-12-01 18:51:18 -08005295enum usb_pd_control_swap {
5296 USB_PD_CTRL_SWAP_NONE = 0,
5297 USB_PD_CTRL_SWAP_DATA = 1,
5298 USB_PD_CTRL_SWAP_POWER = 2,
5299 USB_PD_CTRL_SWAP_VCONN = 3,
5300 USB_PD_CTRL_SWAP_COUNT
5301};
5302
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005303struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005304 uint8_t port;
5305 uint8_t role;
5306 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08005307 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005308} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005309
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005310#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
5311#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
5312#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08005313
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005314#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
5315#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
5316#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
5317#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
5318#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
5319#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005320#define PD_CTRL_RESP_ROLE_UNCONSTRAINED BIT(6) /* Partner unconstrained power */
Duncan Laurieeb316852015-12-01 18:51:18 -08005321
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005322struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005323 uint8_t enabled;
5324 uint8_t role;
5325 uint8_t polarity;
5326 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005327} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005328
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005329struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005330 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08005331 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005332 uint8_t polarity;
5333 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005334} __ec_align1;
5335
Jett Rinkba2edaf2020-01-14 11:49:06 -07005336/* Possible port partner connections based on CC line states */
5337enum pd_cc_states {
5338 PD_CC_NONE = 0, /* No port partner attached */
5339
5340 /* From DFP perspective */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005341 PD_CC_UFP_NONE = 1, /* No UFP accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005342 PD_CC_UFP_AUDIO_ACC = 2, /* UFP Audio accessory connected */
5343 PD_CC_UFP_DEBUG_ACC = 3, /* UFP Debug accessory connected */
5344 PD_CC_UFP_ATTACHED = 4, /* Plain UFP attached */
5345
5346 /* From UFP perspective */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005347 PD_CC_DFP_ATTACHED = 5, /* Plain DFP attached */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005348 PD_CC_DFP_DEBUG_ACC = 6, /* DFP debug accessory connected */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005349};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005350
Jett Rinkba2edaf2020-01-14 11:49:06 -07005351/* Active/Passive Cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005352#define USB_PD_CTRL_ACTIVE_CABLE BIT(0)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005353/* Optical/Non-optical cable */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005354#define USB_PD_CTRL_OPTICAL_CABLE BIT(1)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005355/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005356#define USB_PD_CTRL_TBT_LEGACY_ADAPTER BIT(2)
5357/* Active Link Uni-Direction */
5358#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR BIT(3)
Jett Rinkba2edaf2020-01-14 11:49:06 -07005359
5360/*
5361 * Underdevelopement :
5362 * Please remove this tag if using _v2 outside platform/ec
5363 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005364struct ec_response_usb_pd_control_v2 {
5365 uint8_t enabled;
5366 uint8_t role;
5367 uint8_t polarity;
5368 char state[32];
Jett Rinkba2edaf2020-01-14 11:49:06 -07005369 uint8_t cc_state; /* enum pd_cc_states representing cc state */
5370 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005371 uint8_t reserved; /* Reserved for future use */
5372 uint8_t control_flags; /* USB_PD_CTRL_*flags */
5373 uint8_t cable_speed; /* TBT_SS_* cable speed */
5374 uint8_t cable_gen; /* TBT_GEN3_* cable rounded support */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005375} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005376
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005377#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005378
Patrick Georgi0f6187a2017-07-28 15:57:23 +02005379/* Maximum number of PD ports on a device, num_ports will be <= this */
5380#define EC_USB_PD_MAX_PORTS 8
5381
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005382struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005383 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005384} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005385
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005386#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005387
5388#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005389struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005390 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005391} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005392
5393enum usb_chg_type {
5394 USB_CHG_TYPE_NONE,
5395 USB_CHG_TYPE_PD,
5396 USB_CHG_TYPE_C,
5397 USB_CHG_TYPE_PROPRIETARY,
5398 USB_CHG_TYPE_BC12_DCP,
5399 USB_CHG_TYPE_BC12_CDP,
5400 USB_CHG_TYPE_BC12_SDP,
5401 USB_CHG_TYPE_OTHER,
5402 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005403 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005404 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005405};
5406enum usb_power_roles {
5407 USB_PD_PORT_POWER_DISCONNECTED,
5408 USB_PD_PORT_POWER_SOURCE,
5409 USB_PD_PORT_POWER_SINK,
5410 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5411};
5412
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005413struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005414 uint16_t voltage_max;
5415 uint16_t voltage_now;
5416 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005417 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005418} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005419
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005420struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005421 uint8_t role;
5422 uint8_t type;
5423 uint8_t dualrole;
5424 uint8_t reserved1;
5425 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005426 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005427} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005428
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005429
5430/*
5431 * This command will return the number of USB PD charge port + the number
5432 * of dedicated port present.
5433 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5434 */
5435#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005436struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005437 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005438} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005439
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005440/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005441#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005442
5443enum usb_pd_fw_update_cmds {
5444 USB_PD_FW_REBOOT,
5445 USB_PD_FW_FLASH_ERASE,
5446 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005447 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005448};
5449
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005450struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005451 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005452 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005453 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005454 uint32_t size; /* Size to write in bytes */
5455 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005456} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005457
5458/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005459#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005460/* RW hash is first 20 bytes of SHA-256 of RW section */
5461#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005462struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005463 uint16_t dev_id;
5464 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005465 uint8_t reserved; /*
5466 * For alignment of current_image
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005467 * TODO(rspangler) but it's not aligned!
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005468 * Should have been reserved[2].
5469 */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005470 uint32_t current_image; /* One of ec_image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005471} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005472
5473/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005474#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005475
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005476struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005477 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005478} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005479
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005480/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005481#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005482struct ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005483 uint16_t vid; /* USB-IF VID */
5484 uint16_t pid; /* USB-IF PID */
5485 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005486} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005487
5488/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005489#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005490
5491/* Negative port parameters have special meaning */
5492enum usb_pd_override_ports {
5493 OVERRIDE_DONT_CHARGE = -2,
5494 OVERRIDE_OFF = -1,
Jett Rinkba2edaf2020-01-14 11:49:06 -07005495 /* [0, CONFIG_USB_PD_PORT_MAX_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005496};
5497
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005498struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005499 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005500} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005501
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005502/*
5503 * Read (and delete) one entry of PD event log.
5504 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5505 * future non-PD logs that use the same internal EC event_log.
5506 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005507#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005508
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005509struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005510 uint32_t timestamp; /* relative timestamp in milliseconds */
5511 uint8_t type; /* event type : see PD_EVENT_xx below */
5512 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5513 uint16_t data; /* type-defined data payload */
5514 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005515} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005516
5517/* The timestamp is the microsecond counter shifted to get about a ms. */
5518#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5519
Duncan Laurieeb316852015-12-01 18:51:18 -08005520#define PD_LOG_SIZE_MASK 0x1f
5521#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005522#define PD_LOG_PORT_SHIFT 5
5523#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
5524 ((size) & PD_LOG_SIZE_MASK))
5525#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
5526#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
5527
5528/* PD event log : entry types */
5529/* PD MCU events */
5530#define PD_EVENT_MCU_BASE 0x00
5531#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
5532#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
5533/* Reserved for custom board event */
5534#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
5535/* PD generic accessory events */
5536#define PD_EVENT_ACC_BASE 0x20
5537#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
5538#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
5539/* PD power supply events */
5540#define PD_EVENT_PS_BASE 0x40
5541#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
5542/* PD video dongles events */
5543#define PD_EVENT_VIDEO_BASE 0x60
5544#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
5545#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
5546/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08005547#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005548
5549/*
5550 * PD_EVENT_MCU_CHARGE event definition :
5551 * the payload is "struct usb_chg_measures"
5552 * the data field contains the port state flags as defined below :
5553 */
5554/* Port partner is a dual role device */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005555#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005556/* Port is the pending override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005557#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005558/* Port is the override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005559#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005560/* Charger type */
5561#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08005562#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005563/* Power delivery role */
5564#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
5565
5566/*
5567 * PD_EVENT_PS_FAULT data field flags definition :
5568 */
5569#define PS_FAULT_OCP 1
5570#define PS_FAULT_FAST_OCP 2
5571#define PS_FAULT_OVP 3
5572#define PS_FAULT_DISCH 4
5573
5574/*
5575 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5576 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005577struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005578 uint8_t major;
5579 uint8_t minor;
5580 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005581} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005582
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005583struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005584 uint8_t family[2];
5585 uint8_t chipid[2];
5586 struct mcdp_version irom;
5587 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005588} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005589
5590/* struct mcdp_info field decoding */
5591#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5592#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5593
5594/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005595#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005596struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005597 uint16_t svid_idx; /* SVID index to get */
5598 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005599} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005600
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005601struct ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005602 uint16_t svid; /* SVID */
5603 uint16_t opos; /* Object Position */
5604 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005605} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005606
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005607#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005608
5609enum pd_mode_cmd {
5610 PD_EXIT_MODE = 0,
5611 PD_ENTER_MODE = 1,
5612 /* Not a command. Do NOT remove. */
5613 PD_MODE_CMD_COUNT,
5614};
5615
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005616struct ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005617 uint32_t cmd; /* enum pd_mode_cmd */
5618 uint16_t svid; /* SVID to set */
5619 uint8_t opos; /* Object Position */
5620 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005621} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005622
5623/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005624#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005625
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005626struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005627 uint8_t type; /* event type : see PD_EVENT_xx above */
5628 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005629} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005630
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005631
Gwendal Grignou880b4582016-06-20 08:49:25 -07005632/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005633#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07005634
5635enum ec_pd_control_cmd {
5636 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5637 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5638 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005639 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5640 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005641};
5642
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005643struct ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005644 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005645 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005646} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005647
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005648/* Get info about USB-C SS muxes */
5649#define EC_CMD_USB_PD_MUX_INFO 0x011A
5650
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005651struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005652 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005653} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005654
5655/* Flags representing mux state */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005656#define USB_PD_MUX_NONE 0 /* Open switch */
5657#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5658#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5659#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5660#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5661#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
5662#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
5663#define USB_PD_MUX_TBT_COMPAT_ENABLED BIT(6) /* TBT compat enabled */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005664#define USB_PD_MUX_USB4_ENABLED BIT(7) /* USB4 enabled */
5665
5666/* USB-C Dock connected */
5667#define USB_PD_MUX_DOCK (USB_PD_MUX_USB_ENABLED | USB_PD_MUX_DP_ENABLED)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005668
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005669struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005670 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005671} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005672
5673#define EC_CMD_PD_CHIP_INFO 0x011B
5674
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005675struct ec_params_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005676 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005677 /*
5678 * Fetch the live chip info or hard-coded + cached chip info
5679 * 0: hardcoded value for VID/PID, cached value for FW version
5680 * 1: live chip value for VID/PID/FW Version
5681 */
5682 uint8_t live;
5683} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005684
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005685struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005686 uint16_t vendor_id;
5687 uint16_t product_id;
5688 uint16_t device_id;
5689 union {
5690 uint8_t fw_version_string[8];
5691 uint64_t fw_version_number;
5692 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005693} __ec_align2;
5694
5695struct ec_response_pd_chip_info_v1 {
5696 uint16_t vendor_id;
5697 uint16_t product_id;
5698 uint16_t device_id;
5699 union {
5700 uint8_t fw_version_string[8];
5701 uint64_t fw_version_number;
5702 };
5703 union {
5704 uint8_t min_req_fw_version_string[8];
5705 uint64_t min_req_fw_version_number;
5706 };
5707} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005708
5709/* Run RW signature verification and get status */
5710#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5711
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005712struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005713 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005714} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005715
5716/* For controlling RWSIG task */
5717#define EC_CMD_RWSIG_ACTION 0x011D
5718
5719enum rwsig_action {
5720 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5721 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5722};
5723
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005724struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005725 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005726} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005727
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005728/* Run verification on a slot */
5729#define EC_CMD_EFS_VERIFY 0x011E
5730
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005731struct ec_params_efs_verify {
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005732 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005733} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005734
5735/*
5736 * Retrieve info from Cros Board Info store. Response is based on the data
5737 * type. Integers return a uint32. Strings return a string, using the response
5738 * size to determine how big it is.
5739 */
5740#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5741/*
5742 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5743 * hardware write-protect enabled.
5744 */
5745#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5746
Daisuke Nojirif984a052018-02-15 12:38:15 -08005747enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005748 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5749 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5750 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06005751 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Wisley Chenc1efec72018-11-06 09:28:23 +08005752 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005753 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
Jett Rinkba2edaf2020-01-14 11:49:06 -07005754 CBI_TAG_FW_CONFIG = 6, /* uint32_t bit field */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005755 CBI_TAG_PCB_SUPPLIER = 7, /* uint32_t or smaller */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005756 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005757};
5758
5759/*
5760 * Flags to control read operation
5761 *
5762 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5763 * write was successful without reboot.
5764 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005765#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005766
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005767struct ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005768 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005769 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005770} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005771
5772/*
5773 * Flags to control write behavior.
5774 *
5775 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5776 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005777 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005778 * will be initialized to zero first.
5779 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005780#define CBI_SET_NO_SYNC BIT(0)
5781#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005782
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005783struct ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08005784 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005785 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005786 uint32_t size; /* Data size */
5787 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005788} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005789
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005790/*
5791 * Information about resets of the AP by the EC and the EC's own uptime.
5792 */
5793#define EC_CMD_GET_UPTIME_INFO 0x0121
5794
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005795/* Reset causes */
5796#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
5797#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
5798#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
5799#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
5800#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
5801#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
5802#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
5803#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
5804#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
5805#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
5806#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
5807#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
5808#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
5809#define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from
5810 * previous boot
5811 */
5812#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
5813#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
5814#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
5815#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
5816#define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07005817#define EC_RESET_FLAG_STAY_IN_RO BIT(19) /* Do not select RW in EFS. This
5818 * enables PD in RO for Chromebox.
5819 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005820
5821struct ec_response_uptime_info {
5822 /*
5823 * Number of milliseconds since the last EC boot. Sysjump resets
5824 * typically do not restart the EC's time_since_boot epoch.
5825 *
5826 * WARNING: The EC's sense of time is much less accurate than the AP's
5827 * sense of time, in both phase and frequency. This timebase is similar
5828 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
5829 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005830 uint32_t time_since_ec_boot_ms;
5831
5832 /*
5833 * Number of times the AP was reset by the EC since the last EC boot.
5834 * Note that the AP may be held in reset by the EC during the initial
5835 * boot sequence, such that the very first AP boot may count as more
5836 * than one here.
5837 */
5838 uint32_t ap_resets_since_ec_boot;
5839
5840 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005841 * The set of flags which describe the EC's most recent reset.
5842 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005843 */
5844 uint32_t ec_reset_flags;
5845
5846 /* Empty log entries have both the cause and timestamp set to zero. */
5847 struct ap_reset_log_entry {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005848 /*
5849 * See include/chipset.h: enum chipset_{reset,shutdown}_reason
5850 * for details.
5851 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005852 uint16_t reset_cause;
5853
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005854 /* Reserved for protocol growth. */
5855 uint16_t reserved;
5856
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005857 /*
5858 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005859 * last EC boot, in the same epoch as time_since_ec_boot_ms.
5860 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005861 */
5862 uint32_t reset_time_ms;
5863 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005864} __ec_align4;
5865
5866/*
5867 * Add entropy to the device secret (stored in the rollback region).
5868 *
5869 * Depending on the chip, the operation may take a long time (e.g. to erase
5870 * flash), so the commands are asynchronous.
5871 */
5872#define EC_CMD_ADD_ENTROPY 0x0122
5873
5874enum add_entropy_action {
5875 /* Add entropy to the current secret. */
5876 ADD_ENTROPY_ASYNC = 0,
5877 /*
5878 * Add entropy, and also make sure that the previous secret is erased.
5879 * (this can be implemented by adding entropy multiple times until
5880 * all rolback blocks have been overwritten).
5881 */
5882 ADD_ENTROPY_RESET_ASYNC = 1,
5883 /* Read back result from the previous operation. */
5884 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005885};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005886
5887struct ec_params_rollback_add_entropy {
5888 uint8_t action;
5889} __ec_align1;
5890
5891/*
5892 * Perform a single read of a given ADC channel.
5893 */
5894#define EC_CMD_ADC_READ 0x0123
5895
5896struct ec_params_adc_read {
5897 uint8_t adc_channel;
5898} __ec_align1;
5899
5900struct ec_response_adc_read {
5901 int32_t adc_value;
5902} __ec_align4;
5903
5904/*
5905 * Read back rollback info
5906 */
5907#define EC_CMD_ROLLBACK_INFO 0x0124
5908
5909struct ec_response_rollback_info {
5910 int32_t id; /* Incrementing number to indicate which region to use. */
5911 int32_t rollback_min_version;
5912 int32_t rw_rollback_version;
5913} __ec_align4;
5914
5915
5916/* Issue AP reset */
5917#define EC_CMD_AP_RESET 0x0125
5918
5919/*****************************************************************************/
5920/* Locate peripheral chips
5921 *
5922 * Return values:
5923 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
5924 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
5925 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
5926 */
5927#define EC_CMD_LOCATE_CHIP 0x0126
5928
5929enum ec_chip_type {
5930 EC_CHIP_TYPE_CBI_EEPROM = 0,
5931 EC_CHIP_TYPE_TCPC = 1,
5932 EC_CHIP_TYPE_COUNT,
5933 EC_CHIP_TYPE_MAX = 0xFF,
5934};
5935
5936enum ec_bus_type {
5937 EC_BUS_TYPE_I2C = 0,
5938 EC_BUS_TYPE_EMBEDDED = 1,
5939 EC_BUS_TYPE_COUNT,
5940 EC_BUS_TYPE_MAX = 0xFF,
5941};
5942
5943struct ec_i2c_info {
5944 uint16_t port; /* Physical port for device */
5945 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
5946};
5947
5948struct ec_params_locate_chip {
5949 uint8_t type; /* enum ec_chip_type */
5950 uint8_t index; /* Specifies one instance of chip type */
5951 /* Used for type specific parameters in future */
5952 union {
5953 uint16_t reserved;
5954 };
5955} __ec_align2;
5956
5957
5958struct ec_response_locate_chip {
5959 uint8_t bus_type; /* enum ec_bus_type */
5960 uint8_t reserved; /* Aligning the following union to 2 bytes */
5961 union {
5962 struct ec_i2c_info i2c_info;
5963 };
5964} __ec_align2;
5965
Jett Rinkba2edaf2020-01-14 11:49:06 -07005966/*
5967 * Reboot AP on G3
5968 *
5969 * This command is used for validation purpose, where the AP needs to be
5970 * returned back to S0 state from G3 state without using the servo to trigger
5971 * wake events.For this,there is no request or response struct.
5972 *
5973 * Order of command usage:
5974 * ectool reboot_ap_on_g3 && shutdown -h now
5975 */
5976#define EC_CMD_REBOOT_AP_ON_G3 0x0127
5977
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005978/*****************************************************************************/
Tim Wawrzynczak87afa902020-01-22 15:02:48 -07005979/* Get PD port capabilities
5980 *
5981 * Returns the following static *capabilities* of the given port:
5982 * 1) Power role: source, sink, or dual. It is not anticipated that
5983 * future CrOS devices would ever be only a source, so the options are
5984 * sink or dual.
5985 * 2) Try-power role: source, sink, or none (practically speaking, I don't
5986 * believe any CrOS device would support Try.SNK, so this would be source
5987 * or none).
5988 * 3) Data role: dfp, ufp, or dual. This will probably only be DFP or dual
5989 * for CrOS devices.
5990 */
5991#define EC_CMD_GET_PD_PORT_CAPS 0x0128
5992
5993enum ec_pd_power_role_caps {
5994 EC_PD_POWER_ROLE_SOURCE = 0,
5995 EC_PD_POWER_ROLE_SINK = 1,
5996 EC_PD_POWER_ROLE_DUAL = 2,
5997};
5998
5999enum ec_pd_try_power_role_caps {
6000 EC_PD_TRY_POWER_ROLE_NONE = 0,
6001 EC_PD_TRY_POWER_ROLE_SINK = 1,
6002 EC_PD_TRY_POWER_ROLE_SOURCE = 2,
6003};
6004
6005enum ec_pd_data_role_caps {
6006 EC_PD_DATA_ROLE_DFP = 0,
6007 EC_PD_DATA_ROLE_UFP = 1,
6008 EC_PD_DATA_ROLE_DUAL = 2,
6009};
6010
6011/* From: power_manager/power_supply_properties.proto */
6012enum ec_pd_port_location {
6013 /* The location of the port is unknown, or there's only one port. */
6014 EC_PD_PORT_LOCATION_UNKNOWN = 0,
6015
6016 /*
6017 * Various positions on the device. The first word describes the side of
6018 * the device where the port is located while the second clarifies the
6019 * position. For example, LEFT_BACK means the farthest-back port on the
6020 * left side, while BACK_LEFT means the leftmost port on the back of the
6021 * device.
6022 */
6023 EC_PD_PORT_LOCATION_LEFT = 1,
6024 EC_PD_PORT_LOCATION_RIGHT = 2,
6025 EC_PD_PORT_LOCATION_BACK = 3,
6026 EC_PD_PORT_LOCATION_FRONT = 4,
6027 EC_PD_PORT_LOCATION_LEFT_FRONT = 5,
6028 EC_PD_PORT_LOCATION_LEFT_BACK = 6,
6029 EC_PD_PORT_LOCATION_RIGHT_FRONT = 7,
6030 EC_PD_PORT_LOCATION_RIGHT_BACK = 8,
6031 EC_PD_PORT_LOCATION_BACK_LEFT = 9,
6032 EC_PD_PORT_LOCATION_BACK_RIGHT = 10,
6033};
6034
6035struct ec_params_get_pd_port_caps {
6036 uint8_t port; /* Which port to interrogate */
6037} __ec_align1;
6038
6039struct ec_response_get_pd_port_caps {
6040 uint8_t pd_power_role_cap; /* enum ec_pd_power_role_caps */
6041 uint8_t pd_try_power_role_cap; /* enum ec_pd_try_power_role_caps */
6042 uint8_t pd_data_role_cap; /* enum ec_pd_data_role_caps */
6043 uint8_t pd_port_location; /* enum ec_pd_port_location */
6044} __ec_align1;
6045
6046/*****************************************************************************/
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006047/*
6048 * Button press simulation
6049 *
6050 * This command is used to simulate a button press.
6051 * Supported commands are vup(volume up) vdown(volume down) & rec(recovery)
6052 * Time duration for which button needs to be pressed is an optional parameter.
6053 *
6054 * NOTE: This is only available on unlocked devices for testing purposes only.
6055 */
6056#define EC_CMD_BUTTON 0x0129
6057
6058struct ec_params_button {
6059 /* Button mask aligned to enum keyboard_button_type */
6060 uint32_t btn_mask;
6061
6062 /* Duration in milliseconds button needs to be pressed */
6063 uint32_t press_ms;
6064} __ec_align1;
6065
6066enum keyboard_button_type {
6067 KEYBOARD_BUTTON_POWER = 0,
6068 KEYBOARD_BUTTON_VOLUME_DOWN = 1,
6069 KEYBOARD_BUTTON_VOLUME_UP = 2,
6070 KEYBOARD_BUTTON_RECOVERY = 3,
6071 KEYBOARD_BUTTON_CAPSENSE_1 = 4,
6072 KEYBOARD_BUTTON_CAPSENSE_2 = 5,
6073 KEYBOARD_BUTTON_CAPSENSE_3 = 6,
6074 KEYBOARD_BUTTON_CAPSENSE_4 = 7,
6075 KEYBOARD_BUTTON_CAPSENSE_5 = 8,
6076 KEYBOARD_BUTTON_CAPSENSE_6 = 9,
6077 KEYBOARD_BUTTON_CAPSENSE_7 = 10,
6078 KEYBOARD_BUTTON_CAPSENSE_8 = 11,
6079
6080 KEYBOARD_BUTTON_COUNT
6081};
Rajat Jainc0495722020-04-02 23:58:35 -07006082/*****************************************************************************/
6083/*
6084 * "Get the Keyboard Config". An EC implementing this command is expected to be
6085 * vivaldi capable, i.e. can send action codes for the top row keys.
6086 * Additionally, capability to send function codes for the same keys is
6087 * optional and acceptable.
6088 *
6089 * Note: If the top row can generate both function and action codes by
6090 * using a dedicated Fn key, it does not matter whether the key sends
6091 * "function" or "action" codes by default. In both cases, the response
6092 * for this command will look the same.
6093 */
6094#define EC_CMD_GET_KEYBD_CONFIG 0x012A
6095
6096/* Possible values for the top row keys */
6097enum action_key {
6098 TK_ABSENT = 0,
6099 TK_BACK = 1,
6100 TK_FORWARD = 2,
6101 TK_REFRESH = 3,
6102 TK_FULLSCREEN = 4,
6103 TK_OVERVIEW = 5,
6104 TK_BRIGHTNESS_DOWN = 6,
6105 TK_BRIGHTNESS_UP = 7,
6106 TK_VOL_MUTE = 8,
6107 TK_VOL_DOWN = 9,
6108 TK_VOL_UP = 10,
6109 TK_SNAPSHOT = 11,
6110 TK_PRIVACY_SCRN_TOGGLE = 12,
6111 TK_KBD_BKLIGHT_DOWN = 13,
6112 TK_KBD_BKLIGHT_UP = 14,
6113 TK_PLAY_PAUSE = 15,
6114 TK_NEXT_TRACK = 16,
6115 TK_PREV_TRACK = 17,
6116};
6117
6118/*
6119 * Max & Min number of top row keys, excluding Esc and Screenlock keys.
6120 * If this needs to change, please create a new version of the command.
6121 */
6122#define MAX_TOP_ROW_KEYS 15
6123#define MIN_TOP_ROW_KEYS 10
6124
6125/*
6126 * Is the keyboard capable of sending function keys *in addition to*
6127 * action keys. This is possible for e.g. if the keyboard has a
6128 * dedicated Fn key.
6129 */
6130#define KEYBD_CAP_FUNCTION_KEYS BIT(0)
6131/*
6132 * Whether the keyboard has a dedicated numeric keyboard.
6133 */
6134#define KEYBD_CAP_NUMERIC_KEYPAD BIT(1)
6135/*
6136 * Whether the keyboard has a screenlock key.
6137 */
6138#define KEYBD_CAP_SCRNLOCK_KEY BIT(2)
6139
6140struct ec_response_keybd_config {
6141 /*
6142 * Number of top row keys, excluding Esc and Screenlock.
6143 * If this is 0, all Vivaldi keyboard code is disabled.
6144 * (i.e. does not expose any tables to the kernel).
6145 */
6146 uint8_t num_top_row_keys;
6147
6148 /*
6149 * The action keys in the top row, in order from left to right.
6150 * The values are filled from enum action_key. Esc and Screenlock
6151 * keys are not considered part of top row keys.
6152 */
6153 uint8_t action_keys[MAX_TOP_ROW_KEYS];
6154
6155 /* Capability flags */
6156 uint8_t capabilities;
6157
6158} __ec_align1;
Furquan Shaikhe6c04b92020-04-07 22:01:59 -07006159
6160/*****************************************************************************/
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006161/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08006162
6163/*****************************************************************************/
6164/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006165 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08006166 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006167#define EC_CMD_CR51_BASE 0x0300
6168#define EC_CMD_CR51_LAST 0x03FF
6169
6170/*****************************************************************************/
6171/* Fingerprint MCU commands: range 0x0400-0x040x */
6172
6173/* Fingerprint SPI sensor passthru command: prototyping ONLY */
6174#define EC_CMD_FP_PASSTHRU 0x0400
6175
6176#define EC_FP_FLAG_NOT_COMPLETE 0x1
6177
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006178struct ec_params_fp_passthru {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006179 uint16_t len; /* Number of bytes to write then read */
6180 uint16_t flags; /* EC_FP_FLAG_xxx */
6181 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006182} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006183
6184/* Configure the Fingerprint MCU behavior */
6185#define EC_CMD_FP_MODE 0x0402
6186
6187/* Put the sensor in its lowest power mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006188#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006189/* Wait to see a finger on the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006190#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006191/* Poll until the finger has left the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006192#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006193/* Capture the current finger image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006194#define FP_MODE_CAPTURE BIT(3)
6195/* Finger enrollment session on-going */
6196#define FP_MODE_ENROLL_SESSION BIT(4)
6197/* Enroll the current finger image */
6198#define FP_MODE_ENROLL_IMAGE BIT(5)
6199/* Try to match the current finger image */
6200#define FP_MODE_MATCH BIT(6)
6201/* Reset and re-initialize the sensor. */
6202#define FP_MODE_RESET_SENSOR BIT(7)
6203/* special value: don't change anything just read back current mode */
6204#define FP_MODE_DONT_CHANGE BIT(31)
6205
6206#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
6207 FP_MODE_FINGER_DOWN | \
6208 FP_MODE_FINGER_UP | \
6209 FP_MODE_CAPTURE | \
6210 FP_MODE_ENROLL_SESSION | \
6211 FP_MODE_ENROLL_IMAGE | \
6212 FP_MODE_MATCH | \
6213 FP_MODE_RESET_SENSOR | \
6214 FP_MODE_DONT_CHANGE)
6215
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006216/* Capture types defined in bits [30..28] */
6217#define FP_MODE_CAPTURE_TYPE_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006218#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
6219/*
6220 * This enum must remain ordered, if you add new values you must ensure that
6221 * FP_CAPTURE_TYPE_MAX is still the last one.
6222 */
6223enum fp_capture_type {
6224 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
6225 FP_CAPTURE_VENDOR_FORMAT = 0,
6226 /* Simple raw image capture (produces width x height x bpp bits) */
6227 FP_CAPTURE_SIMPLE_IMAGE = 1,
6228 /* Self test pattern (e.g. checkerboard) */
6229 FP_CAPTURE_PATTERN0 = 2,
6230 /* Self test pattern (e.g. inverted checkerboard) */
6231 FP_CAPTURE_PATTERN1 = 3,
6232 /* Capture for Quality test with fixed contrast */
6233 FP_CAPTURE_QUALITY_TEST = 4,
6234 /* Capture for pixel reset value test */
6235 FP_CAPTURE_RESET_TEST = 5,
6236 FP_CAPTURE_TYPE_MAX,
6237};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006238/* Extracts the capture type from the sensor 'mode' word */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006239#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
6240 >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006241
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006242struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006243 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006244} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006245
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006246struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006247 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006248} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006249
6250/* Retrieve Fingerprint sensor information */
6251#define EC_CMD_FP_INFO 0x0403
6252
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006253/* Number of dead pixels detected on the last maintenance */
6254#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006255/* Unknown number of dead pixels detected on the last maintenance */
6256#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006257/* No interrupt from the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006258#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006259/* SPI communication error */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006260#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006261/* Invalid sensor Hardware ID */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006262#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006263/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006264#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006265
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006266struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006267 /* Sensor identification */
6268 uint32_t vendor_id;
6269 uint32_t product_id;
6270 uint32_t model_id;
6271 uint32_t version;
6272 /* Image frame characteristics */
6273 uint32_t frame_size;
6274 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
6275 uint16_t width;
6276 uint16_t height;
6277 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006278 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006279} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006280
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006281struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006282 /* Sensor identification */
6283 uint32_t vendor_id;
6284 uint32_t product_id;
6285 uint32_t model_id;
6286 uint32_t version;
6287 /* Image frame characteristics */
6288 uint32_t frame_size;
6289 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
6290 uint16_t width;
6291 uint16_t height;
6292 uint16_t bpp;
6293 uint16_t errors; /* see FP_ERROR_ flags above */
6294 /* Template/finger current information */
6295 uint32_t template_size; /* max template size in bytes */
6296 uint16_t template_max; /* maximum number of fingers/templates */
6297 uint16_t template_valid; /* number of valid fingers/templates */
6298 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006299 uint32_t template_version; /* version of the template format */
6300} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006301
6302/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006303#define EC_CMD_FP_FRAME 0x0404
6304
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006305/* constants defining the 'offset' field which also contains the frame index */
6306#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006307/* Frame buffer where the captured image is stored */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006308#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006309/* First frame buffer holding a template */
6310#define FP_FRAME_INDEX_TEMPLATE 1
6311#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006312#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
6313
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006314/* Version of the format of the encrypted templates. */
Jett Rinkba2edaf2020-01-14 11:49:06 -07006315#define FP_TEMPLATE_FORMAT_VERSION 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006316
6317/* Constants for encryption parameters */
6318#define FP_CONTEXT_NONCE_BYTES 12
6319#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
6320#define FP_CONTEXT_TAG_BYTES 16
Jett Rinkba2edaf2020-01-14 11:49:06 -07006321#define FP_CONTEXT_ENCRYPTION_SALT_BYTES 16
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006322#define FP_CONTEXT_TPM_BYTES 32
6323
Jett Rinkba2edaf2020-01-14 11:49:06 -07006324/* Constants for positive match parameters. */
6325#define FP_POSITIVE_MATCH_SALT_BYTES 16
6326
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006327struct ec_fp_template_encryption_metadata {
6328 /*
6329 * Version of the structure format (N=3).
6330 */
6331 uint16_t struct_version;
6332 /* Reserved bytes, set to 0. */
6333 uint16_t reserved;
6334 /*
6335 * The salt is *only* ever used for key derivation. The nonce is unique,
6336 * a different one is used for every message.
6337 */
6338 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
Jett Rinkba2edaf2020-01-14 11:49:06 -07006339 uint8_t encryption_salt[FP_CONTEXT_ENCRYPTION_SALT_BYTES];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006340 uint8_t tag[FP_CONTEXT_TAG_BYTES];
6341};
6342
6343struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006344 /*
6345 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
6346 * in the high nibble, and the real offset within the frame in
6347 * FP_FRAME_OFFSET_MASK.
6348 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006349 uint32_t offset;
6350 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006351} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006352
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006353/* Load a template into the MCU */
6354#define EC_CMD_FP_TEMPLATE 0x0405
6355
6356/* Flag in the 'size' field indicating that the full template has been sent */
6357#define FP_TEMPLATE_COMMIT 0x80000000
6358
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006359struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006360 uint32_t offset;
6361 uint32_t size;
6362 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006363} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006364
6365/* Clear the current fingerprint user context and set a new one */
6366#define EC_CMD_FP_CONTEXT 0x0406
6367
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006368struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006369 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006370} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006371
Jett Rinkba2edaf2020-01-14 11:49:06 -07006372enum fp_context_action {
6373 FP_CONTEXT_ASYNC = 0,
6374 FP_CONTEXT_GET_RESULT = 1,
6375};
6376
6377/* Version 1 of the command is "asynchronous". */
6378struct ec_params_fp_context_v1 {
6379 uint8_t action; /**< enum fp_context_action */
6380 uint8_t reserved[3]; /**< padding for alignment */
6381 uint32_t userid[FP_CONTEXT_USERID_WORDS];
6382} __ec_align4;
6383
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006384#define EC_CMD_FP_STATS 0x0407
6385
6386#define FPSTATS_CAPTURE_INV BIT(0)
6387#define FPSTATS_MATCHING_INV BIT(1)
6388
6389struct ec_response_fp_stats {
6390 uint32_t capture_time_us;
6391 uint32_t matching_time_us;
6392 uint32_t overall_time_us;
6393 struct {
6394 uint32_t lo;
6395 uint32_t hi;
6396 } overall_t0;
6397 uint8_t timestamps_invalid;
6398 int8_t template_matched;
6399} __ec_align2;
6400
6401#define EC_CMD_FP_SEED 0x0408
6402struct ec_params_fp_seed {
6403 /*
6404 * Version of the structure format (N=3).
6405 */
6406 uint16_t struct_version;
6407 /* Reserved bytes, set to 0. */
6408 uint16_t reserved;
6409 /* Seed from the TPM. */
6410 uint8_t seed[FP_CONTEXT_TPM_BYTES];
6411} __ec_align4;
6412
6413#define EC_CMD_FP_ENC_STATUS 0x0409
6414
6415/* FP TPM seed has been set or not */
6416#define FP_ENC_STATUS_SEED_SET BIT(0)
6417
6418struct ec_response_fp_encryption_status {
6419 /* Used bits in encryption engine status */
6420 uint32_t valid_flags;
6421 /* Encryption engine status */
6422 uint32_t status;
6423} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006424
Jett Rinkba2edaf2020-01-14 11:49:06 -07006425#define EC_CMD_FP_READ_MATCH_SECRET 0x040A
6426struct ec_params_fp_read_match_secret {
6427 uint16_t fgr;
6428} __ec_align4;
6429
6430/* The positive match secret has the length of the SHA256 digest. */
6431#define FP_POSITIVE_MATCH_SECRET_BYTES 32
6432struct ec_response_fp_read_match_secret {
6433 uint8_t positive_match_secret[FP_POSITIVE_MATCH_SECRET_BYTES];
6434} __ec_align4;
6435
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006436/*****************************************************************************/
6437/* Touchpad MCU commands: range 0x0500-0x05FF */
6438
6439/* Perform touchpad self test */
6440#define EC_CMD_TP_SELF_TEST 0x0500
6441
6442/* Get number of frame types, and the size of each type */
6443#define EC_CMD_TP_FRAME_INFO 0x0501
6444
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006445struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006446 uint32_t n_frames;
6447 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006448} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006449
6450/* Create a snapshot of current frame readings */
6451#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
6452
6453/* Read the frame */
6454#define EC_CMD_TP_FRAME_GET 0x0503
6455
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006456struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006457 uint32_t frame_index;
6458 uint32_t offset;
6459 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006460} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08006461
6462/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006463/* EC-EC communication commands: range 0x0600-0x06FF */
6464
6465#define EC_COMM_TEXT_MAX 8
6466
6467/*
6468 * Get battery static information, i.e. information that never changes, or
6469 * very infrequently.
6470 */
6471#define EC_CMD_BATTERY_GET_STATIC 0x0600
6472
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006473/**
6474 * struct ec_params_battery_static_info - Battery static info parameters
6475 * @index: Battery index.
6476 */
6477struct ec_params_battery_static_info {
6478 uint8_t index;
6479} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006480
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006481/**
6482 * struct ec_response_battery_static_info - Battery static info response
6483 * @design_capacity: Battery Design Capacity (mAh)
6484 * @design_voltage: Battery Design Voltage (mV)
6485 * @manufacturer: Battery Manufacturer String
6486 * @model: Battery Model Number String
6487 * @serial: Battery Serial Number String
6488 * @type: Battery Type String
6489 * @cycle_count: Battery Cycle Count
6490 */
6491struct ec_response_battery_static_info {
6492 uint16_t design_capacity;
6493 uint16_t design_voltage;
6494 char manufacturer[EC_COMM_TEXT_MAX];
6495 char model[EC_COMM_TEXT_MAX];
6496 char serial[EC_COMM_TEXT_MAX];
6497 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006498 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006499 uint32_t cycle_count;
6500} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006501
6502/*
6503 * Get battery dynamic information, i.e. information that is likely to change
6504 * every time it is read.
6505 */
6506#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
6507
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006508/**
6509 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
6510 * @index: Battery index.
6511 */
6512struct ec_params_battery_dynamic_info {
6513 uint8_t index;
6514} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006515
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006516/**
6517 * struct ec_response_battery_dynamic_info - Battery dynamic info response
6518 * @actual_voltage: Battery voltage (mV)
6519 * @actual_current: Battery current (mA); negative=discharging
6520 * @remaining_capacity: Remaining capacity (mAh)
6521 * @full_capacity: Capacity (mAh, might change occasionally)
6522 * @flags: Flags, see EC_BATT_FLAG_*
6523 * @desired_voltage: Charging voltage desired by battery (mV)
6524 * @desired_current: Charging current desired by battery (mA)
6525 */
6526struct ec_response_battery_dynamic_info {
6527 int16_t actual_voltage;
6528 int16_t actual_current;
6529 int16_t remaining_capacity;
6530 int16_t full_capacity;
6531 int16_t flags;
6532 int16_t desired_voltage;
6533 int16_t desired_current;
6534} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006535
6536/*
6537 * Control charger chip. Used to control charger chip on the slave.
6538 */
6539#define EC_CMD_CHARGER_CONTROL 0x0602
6540
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006541/**
6542 * struct ec_params_charger_control - Charger control parameters
6543 * @max_current: Charger current (mA). Positive to allow base to draw up to
6544 * max_current and (possibly) charge battery, negative to request current
6545 * from base (OTG).
6546 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
6547 * >= 0.
6548 * @allow_charging: Allow base battery charging (only makes sense if
6549 * max_current > 0).
6550 */
6551struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006552 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006553 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006554 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006555} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006556
6557/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08006558/*
6559 * Reserve a range of host commands for board-specific, experimental, or
6560 * special purpose features. These can be (re)used without updating this file.
6561 *
6562 * CAUTION: Don't go nuts with this. Shipping products should document ALL
6563 * their EC commands for easier development, testing, debugging, and support.
6564 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006565 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
6566 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
6567 *
Duncan Laurieeb316852015-12-01 18:51:18 -08006568 * In your experimental code, you may want to do something like this:
6569 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006570 * #define EC_CMD_MAGIC_FOO 0x0000
6571 * #define EC_CMD_MAGIC_BAR 0x0001
6572 * #define EC_CMD_MAGIC_HEY 0x0002
6573 *
6574 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
6575 * EC_VER_MASK(0);
6576 *
6577 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
6578 * EC_VER_MASK(0);
6579 *
6580 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
6581 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08006582 */
6583#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
6584#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
6585
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006586/*
6587 * Given the private host command offset, calculate the true private host
6588 * command value.
6589 */
6590#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
6591 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
6592
Duncan Laurie93e24442014-01-06 12:30:52 -08006593/*****************************************************************************/
6594/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07006595 * Passthru commands
6596 *
6597 * Some platforms have sub-processors chained to each other. For example.
6598 *
6599 * AP <--> EC <--> PD MCU
6600 *
6601 * The top 2 bits of the command number are used to indicate which device the
6602 * command is intended for. Device 0 is always the device receiving the
6603 * command; other device mapping is board-specific.
6604 *
6605 * When a device receives a command to be passed to a sub-processor, it passes
6606 * it on with the device number set back to 0. This allows the sub-processor
6607 * to remain blissfully unaware of whether the command originated on the next
6608 * device up the chain, or was passed through from the AP.
6609 *
6610 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
6611 * AP sends command 0x4002 to the EC
6612 * EC sends command 0x0002 to the PD MCU
6613 * EC forwards PD MCU response back to the AP
6614 */
6615
6616/* Offset and max command number for sub-device n */
6617#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
6618#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
6619
6620/*****************************************************************************/
6621/*
Duncan Laurie93e24442014-01-06 12:30:52 -08006622 * Deprecated constants. These constants have been renamed for clarity. The
6623 * meaning and size has not changed. Programs that use the old names should
6624 * switch to the new names soon, as the old names may not be carried forward
6625 * forever.
6626 */
6627#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
6628#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
6629#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
6630
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006631#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006632
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006633#ifdef __cplusplus
6634}
6635#endif
6636
Duncan Laurieeb316852015-12-01 18:51:18 -08006637#endif /* __CROS_EC_EC_COMMANDS_H */