blob: acee2f58e6c92a90a2660bfdb84837097c9904c5 [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
42/*
43 * CHROMIUM_EC is defined by the Makefile system of Chromium EC repository.
44 * It is used to not include macros that may cause conflicts in foreign
45 * projects (refer to crbug.com/984623).
46 */
47#ifdef CHROMIUM_EC
Duncan Laurie67f26cc2017-06-29 23:17:22 -070048/*
49 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
50 * generates more efficient code for accessing request/response structures on
51 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
52 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -070053#include "common.h"
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080054#include "compile_time_macros.h"
55
56#else
57
58#define BUILD_ASSERT(_cond)
59
60#ifndef BIT
61#define BIT(nr) (1UL << (nr))
Duncan Laurie67f26cc2017-06-29 23:17:22 -070062#endif
63
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080064#ifndef BIT_ULL
65#define BIT_ULL(nr) (1ULL << (nr))
66#endif
67
68#endif /* CHROMIUM_EC */
69
Stefan Reinauerd6682e82013-02-21 15:39:35 -080070/*
Duncan Laurie93e24442014-01-06 12:30:52 -080071 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080072 *
Duncan Laurie93e24442014-01-06 12:30:52 -080073 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
74 * determined in other ways. Remove this once the kernel code no longer
75 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080076 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080077#define EC_PROTO_VERSION 0x00000002
78
79/* Command version mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080080#define EC_VER_MASK(version) BIT(version)
Stefan Reinauerd6682e82013-02-21 15:39:35 -080081
82/* I/O addresses for ACPI commands */
83#define EC_LPC_ADDR_ACPI_DATA 0x62
84#define EC_LPC_ADDR_ACPI_CMD 0x66
85
86/* I/O addresses for host command */
87#define EC_LPC_ADDR_HOST_DATA 0x200
88#define EC_LPC_ADDR_HOST_CMD 0x204
89
90/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080091/* Protocol version 2 */
92#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
93#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +080094 * EC_PROTO2_MAX_PARAM_SIZE
95 */
Duncan Laurie93e24442014-01-06 12:30:52 -080096/* Protocol version 3 */
97#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
98#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080099
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800100/*
101 * The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
102 * and they tell the kernel that so we have to think of it as two parts.
103 */
Bill Richardsone221aad2013-06-12 10:50:41 -0700104#define EC_HOST_CMD_REGION0 0x800
105#define EC_HOST_CMD_REGION1 0x880
106#define EC_HOST_CMD_REGION_SIZE 0x80
107
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800108/* EC command register bit functions */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800109#define EC_LPC_CMDR_DATA BIT(0) /* Data ready for host to read */
110#define EC_LPC_CMDR_PENDING BIT(1) /* Write pending to EC */
111#define EC_LPC_CMDR_BUSY BIT(2) /* EC is busy processing a command */
112#define EC_LPC_CMDR_CMD BIT(3) /* Last host write was a command */
113#define EC_LPC_CMDR_ACPI_BRST BIT(4) /* Burst mode (not used) */
114#define EC_LPC_CMDR_SCI BIT(5) /* SCI event is pending */
115#define EC_LPC_CMDR_SMI BIT(6) /* SMI event is pending */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800116
117#define EC_LPC_ADDR_MEMMAP 0x900
118#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
119#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
120
121/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700122#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
123#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
124#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
125#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800126#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
127#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
128#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
129#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
130#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700131#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
132/* Unused 0x28 - 0x2f */
133#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
134/* Unused 0x31 - 0x33 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600135#define EC_MEMMAP_HOST_EVENTS 0x34 /* 64 bits */
136/* Battery values are all 32 bits, unless otherwise noted. */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800137#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
138#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
139#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600140#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, see below (8-bit) */
141#define EC_MEMMAP_BATT_COUNT 0x4d /* Battery Count (8-bit) */
142#define EC_MEMMAP_BATT_INDEX 0x4e /* Current Battery Data Index (8-bit) */
143/* Unused 0x4f */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800144#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
145#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
146#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
147#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700148/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800149#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
150#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
151#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
152#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700153#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
154/* Unused 0x84 - 0x8f */
155#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
156/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800157#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
158/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
159/* 0x94 - 0x99: 1st Accelerometer */
160/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700161#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700162/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700163
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700164/*
165 * ACPI is unable to access memory mapped data at or above this offset due to
166 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
167 * which might be needed by ACPI.
168 */
169#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700170
171/* Define the format of the accelerometer mapped memory status byte. */
172#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800173#define EC_MEMMAP_ACC_STATUS_BUSY_BIT BIT(4)
174#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT BIT(7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800175
176/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
177#define EC_TEMP_SENSOR_ENTRIES 16
178/*
179 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
180 *
181 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
182 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700183#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800184
185/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700186#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
187#define EC_TEMP_SENSOR_ERROR 0xfe
188#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
189#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800190/*
191 * The offset of temperature value stored in mapped memory. This allows
192 * reporting a temperature range of 200K to 454K = -73C to 181C.
193 */
194#define EC_TEMP_SENSOR_OFFSET 200
195
Duncan Laurie93e24442014-01-06 12:30:52 -0800196/*
197 * Number of ALS readings at EC_MEMMAP_ALS
198 */
199#define EC_ALS_ENTRIES 2
200
201/*
202 * The default value a temperature sensor will return when it is present but
203 * has not been read this boot. This is a reasonable number to avoid
204 * triggering alarms on the host.
205 */
206#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
207
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800208#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
209#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
210#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
211
212/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
213#define EC_BATT_FLAG_AC_PRESENT 0x01
214#define EC_BATT_FLAG_BATT_PRESENT 0x02
215#define EC_BATT_FLAG_DISCHARGING 0x04
216#define EC_BATT_FLAG_CHARGING 0x08
217#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600218/* Set if some of the static/dynamic data is invalid (or outdated). */
219#define EC_BATT_FLAG_INVALID_DATA 0x20
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800220
221/* Switch flags at EC_MEMMAP_SWITCHES */
222#define EC_SWITCH_LID_OPEN 0x01
223#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
224#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700225/* Was recovery requested via keyboard; now unused. */
226#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800227/* Recovery requested via dedicated signal (from servo board) */
228#define EC_SWITCH_DEDICATED_RECOVERY 0x10
229/* Was fake developer mode switch; now unused. Remove in next refactor. */
230#define EC_SWITCH_IGNORE0 0x20
231
232/* Host command interface flags */
233/* Host command interface supports LPC args (LPC interface only) */
234#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800235/* Host command interface supports version 3 protocol */
236#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800237
238/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800239#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
240#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
241#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
242#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
243#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800244
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700245/*****************************************************************************/
246/*
247 * ACPI commands
248 *
249 * These are valid ONLY on the ACPI command/data port.
250 */
251
252/*
253 * ACPI Read Embedded Controller
254 *
255 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
256 *
257 * Use the following sequence:
258 *
259 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
260 * - Wait for EC_LPC_CMDR_PENDING bit to clear
261 * - Write address to EC_LPC_ADDR_ACPI_DATA
262 * - Wait for EC_LPC_CMDR_DATA bit to set
263 * - Read value from EC_LPC_ADDR_ACPI_DATA
264 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700265#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700266
267/*
268 * ACPI Write Embedded Controller
269 *
270 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
271 *
272 * Use the following sequence:
273 *
274 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
275 * - Wait for EC_LPC_CMDR_PENDING bit to clear
276 * - Write address to EC_LPC_ADDR_ACPI_DATA
277 * - Wait for EC_LPC_CMDR_PENDING bit to clear
278 * - Write value to EC_LPC_ADDR_ACPI_DATA
279 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700280#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700281
282/*
283 * ACPI Burst Enable Embedded Controller
284 *
285 * This enables burst mode on the EC to allow the host to issue several
286 * commands back-to-back. While in this mode, writes to mapped multi-byte
287 * data are locked out to ensure data consistency.
288 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700289#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700290
291/*
292 * ACPI Burst Disable Embedded Controller
293 *
294 * This disables burst mode on the EC and stops preventing EC writes to mapped
295 * multi-byte data.
296 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700297#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700298
299/*
300 * ACPI Query Embedded Controller
301 *
302 * This clears the lowest-order bit in the currently pending host events, and
303 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
304 * event 0x80000000 = 32), or 0 if no event was pending.
305 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700306#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700307
308/* Valid addresses in ACPI memory space, for read/write commands */
309
310/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
311#define EC_ACPI_MEM_VERSION 0x00
312/*
313 * Test location; writing value here updates test compliment byte to (0xff -
314 * value).
315 */
316#define EC_ACPI_MEM_TEST 0x01
317/* Test compliment; writes here are ignored. */
318#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
319
320/* Keyboard backlight brightness percent (0 - 100) */
321#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
322/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
323#define EC_ACPI_MEM_FAN_DUTY 0x04
324
325/*
326 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
327 * independent thresholds attached to them. The current value of the ID
328 * register determines which sensor is affected by the THRESHOLD and COMMIT
329 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
330 * as the memory-mapped sensors. The COMMIT register applies those settings.
331 *
332 * The spec does not mandate any way to read back the threshold settings
333 * themselves, but when a threshold is crossed the AP needs a way to determine
334 * which sensor(s) are responsible. Each reading of the ID register clears and
335 * returns one sensor ID that has crossed one of its threshold (in either
336 * direction) since the last read. A value of 0xFF means "no new thresholds
337 * have tripped". Setting or enabling the thresholds for a sensor will clear
338 * the unread event count for that sensor.
339 */
340#define EC_ACPI_MEM_TEMP_ID 0x05
341#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
342#define EC_ACPI_MEM_TEMP_COMMIT 0x07
343/*
344 * Here are the bits for the COMMIT register:
345 * bit 0 selects the threshold index for the chosen sensor (0/1)
346 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
347 * Each write to the commit register affects one threshold.
348 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800349#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK BIT(0)
350#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK BIT(1)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700351/*
352 * Example:
353 *
354 * Set the thresholds for sensor 2 to 50 C and 60 C:
355 * write 2 to [0x05] -- select temp sensor 2
356 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
357 * write 0x2 to [0x07] -- enable threshold 0 with this value
358 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
359 * write 0x3 to [0x07] -- enable threshold 1 with this value
360 *
361 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
362 * write 2 to [0x05] -- select temp sensor 2
363 * write 0x1 to [0x07] -- disable threshold 1
364 */
365
366/* DPTF battery charging current limit */
367#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
368
369/* Charging limit is specified in 64 mA steps */
370#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
371/* Value to disable DPTF battery charging limit */
372#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700373
jiazi Yang51fc93f2016-07-28 05:15:01 -0400374/*
375 * Report device orientation
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800376 * Bits Definition
377 * 3:1 Device DPTF Profile Number (DDPN)
378 * 0 = Reserved for backward compatibility (indicates no valid
379 * profile number. Host should fall back to using TBMD).
380 * 1..7 = DPTF Profile number to indicate to host which table needs
381 * to be loaded.
382 * 0 Tablet Mode Device Indicator (TBMD)
jiazi Yang51fc93f2016-07-28 05:15:01 -0400383 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700384#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800385#define EC_ACPI_MEM_TBMD_SHIFT 0
386#define EC_ACPI_MEM_TBMD_MASK 0x1
387#define EC_ACPI_MEM_DDPN_SHIFT 1
388#define EC_ACPI_MEM_DDPN_MASK 0x7
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700389
390/*
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600391 * Report device features. Uses the same format as the host command, except:
392 *
393 * bit 0 (EC_FEATURE_LIMITED) changes meaning from "EC code has a limited set
394 * of features", which is of limited interest when the system is already
395 * interpreting ACPI bytecode, to "EC_FEATURES[0-7] is not supported". Since
396 * these are supported, it defaults to 0.
397 * This allows detecting the presence of this field since older versions of
398 * the EC codebase would simply return 0xff to that unknown address. Check
399 * FEATURES0 != 0xff (or FEATURES0[0] == 0) to make sure that the other bits
400 * are valid.
401 */
402#define EC_ACPI_MEM_DEVICE_FEATURES0 0x0a
403#define EC_ACPI_MEM_DEVICE_FEATURES1 0x0b
404#define EC_ACPI_MEM_DEVICE_FEATURES2 0x0c
405#define EC_ACPI_MEM_DEVICE_FEATURES3 0x0d
406#define EC_ACPI_MEM_DEVICE_FEATURES4 0x0e
407#define EC_ACPI_MEM_DEVICE_FEATURES5 0x0f
408#define EC_ACPI_MEM_DEVICE_FEATURES6 0x10
409#define EC_ACPI_MEM_DEVICE_FEATURES7 0x11
410
411#define EC_ACPI_MEM_BATTERY_INDEX 0x12
412
413/*
414 * USB Port Power. Each bit indicates whether the corresponding USB ports' power
415 * is enabled (1) or disabled (0).
416 * bit 0 USB port ID 0
417 * ...
418 * bit 7 USB port ID 7
419 */
420#define EC_ACPI_MEM_USB_PORT_POWER 0x13
421
422/*
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700423 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
424 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
425 */
426#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
427#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
428
429/* Current version of ACPI memory address space */
430#define EC_ACPI_MEM_VERSION_CURRENT 2
431
432
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800433/*
434 * This header file is used in coreboot both in C and ACPI code. The ACPI code
435 * is pre-processed to handle constants but the ASL compiler is unable to
436 * handle actual C code so keep it separate.
437 */
438#ifndef __ACPI__
439
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800440#ifndef __KERNEL__
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800441/*
442 * Define __packed if someone hasn't beat us to it. Linux kernel style
443 * checking prefers __packed over __attribute__((packed)).
444 */
445#ifndef __packed
446#define __packed __attribute__((packed))
447#endif
448
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700449#ifndef __aligned
450#define __aligned(x) __attribute__((aligned(x)))
451#endif
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800452#endif /* __KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700453
454/*
455 * Attributes for EC request and response packets. Just defining __packed
456 * results in inefficient assembly code on ARM, if the structure is actually
457 * 32-bit aligned, as it should be for all buffers.
458 *
459 * Be very careful when adding these to existing structures. They will round
460 * up the structure size to the specified boundary.
461 *
462 * Also be very careful to make that if a structure is included in some other
463 * parent structure that the alignment will still be true given the packing of
464 * the parent structure. This is particularly important if the sub-structure
465 * will be passed as a pointer to another function, since that function will
Elyes HAOUAS58d5df72018-08-07 12:22:50 +0200466 * not know about the misalignment caused by the parent structure's packing.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700467 *
468 * Also be very careful using __packed - particularly when nesting non-packed
469 * structures inside packed ones. In fact, DO NOT use __packed directly;
470 * always use one of these attributes.
471 *
472 * Once everything is annotated properly, the following search strings should
473 * not return ANY matches in this file other than right here:
474 *
475 * "__packed" - generates inefficient code; all sub-structs must also be packed
476 *
477 * "struct [^_]" - all structs should be annotated, except for structs that are
478 * members of other structs/unions (and their original declarations should be
479 * annotated).
480 */
481#ifdef CONFIG_HOSTCMD_ALIGNED
482
483/*
484 * Packed structures where offset and size are always aligned to 1, 2, or 4
485 * byte boundary.
486 */
487#define __ec_align1 __packed
488#define __ec_align2 __packed __aligned(2)
489#define __ec_align4 __packed __aligned(4)
490
491/*
492 * Packed structure which must be under-aligned, because its size is not a
493 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
494 * of all multi-byte fields in it, even though they are themselves aligned.
495 *
496 * In theory, we could duplicate the structure with __aligned(4) for accessing
497 * its members, but use the __packed version for sizeof().
498 */
499#define __ec_align_size1 __packed
500
501/*
502 * Packed structure which must be under-aligned, because its offset inside a
503 * parent structure is not a 4-byte multiple.
504 */
505#define __ec_align_offset1 __packed
506#define __ec_align_offset2 __packed __aligned(2)
507
508/*
509 * Structures which are complicated enough that I'm skipping them on the first
510 * pass. They are effectively unchanged from their previous definitions.
511 *
512 * TODO(rspangler): Figure out what to do with these. It's likely necessary
513 * to work out the size and offset of each member and add explicit padding to
514 * maintain those.
515 */
516#define __ec_todo_packed __packed
517#define __ec_todo_unpacked
518
519#else /* !CONFIG_HOSTCMD_ALIGNED */
520
521/*
522 * Packed structures make no assumption about alignment, so they do inefficient
523 * byte-wise reads.
524 */
525#define __ec_align1 __packed
526#define __ec_align2 __packed
527#define __ec_align4 __packed
528#define __ec_align_size1 __packed
529#define __ec_align_offset1 __packed
530#define __ec_align_offset2 __packed
531#define __ec_todo_packed __packed
532#define __ec_todo_unpacked
533
534#endif /* !CONFIG_HOSTCMD_ALIGNED */
535
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800536/* LPC command status byte masks */
537/* EC has written a byte in the data register and host hasn't read it yet */
538#define EC_LPC_STATUS_TO_HOST 0x01
539/* Host has written a command/data byte and the EC hasn't read it yet */
540#define EC_LPC_STATUS_FROM_HOST 0x02
541/* EC is processing a command */
542#define EC_LPC_STATUS_PROCESSING 0x04
543/* Last write to EC was a command, not data */
544#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700545/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800546#define EC_LPC_STATUS_BURST_MODE 0x10
547/* SCI event is pending (requesting SCI query) */
548#define EC_LPC_STATUS_SCI_PENDING 0x20
549/* SMI event is pending (requesting SMI query) */
550#define EC_LPC_STATUS_SMI_PENDING 0x40
551/* (reserved) */
552#define EC_LPC_STATUS_RESERVED 0x80
553
554/*
555 * EC is busy. This covers both the EC processing a command, and the host has
556 * written a new command but the EC hasn't picked it up yet.
557 */
558#define EC_LPC_STATUS_BUSY_MASK \
559 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
560
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800561/*
562 * Host command response codes (16-bit). Note that response codes should be
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700563 * stored in a uint16_t rather than directly in a value of this type.
564 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800565enum ec_status {
566 EC_RES_SUCCESS = 0,
567 EC_RES_INVALID_COMMAND = 1,
568 EC_RES_ERROR = 2,
569 EC_RES_INVALID_PARAM = 3,
570 EC_RES_ACCESS_DENIED = 4,
571 EC_RES_INVALID_RESPONSE = 5,
572 EC_RES_INVALID_VERSION = 6,
573 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700574 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
575 EC_RES_UNAVAILABLE = 9, /* No response available */
576 EC_RES_TIMEOUT = 10, /* We got a timeout */
577 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800578 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
579 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700580 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700581 EC_RES_BUS_ERROR = 15, /* Communications bus error */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600582 EC_RES_BUSY = 16, /* Up but too busy. Should retry */
583 EC_RES_INVALID_HEADER_VERSION = 17, /* Header version invalid */
584 EC_RES_INVALID_HEADER_CRC = 18, /* Header CRC invalid */
585 EC_RES_INVALID_DATA_CRC = 19, /* Data CRC invalid */
586 EC_RES_DUP_UNAVAILABLE = 20, /* Can't resend response */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800587};
588
589/*
590 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
591 * EC command uses code 0 to mean "no event pending". We explicitly specify
592 * each value in the enum listing so they won't change if we delete/insert an
593 * item or rearrange the list (it needs to be stable across platforms, not
594 * just within a single compiled instance).
595 */
596enum host_event_code {
597 EC_HOST_EVENT_LID_CLOSED = 1,
598 EC_HOST_EVENT_LID_OPEN = 2,
599 EC_HOST_EVENT_POWER_BUTTON = 3,
600 EC_HOST_EVENT_AC_CONNECTED = 4,
601 EC_HOST_EVENT_AC_DISCONNECTED = 5,
602 EC_HOST_EVENT_BATTERY_LOW = 6,
603 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
604 EC_HOST_EVENT_BATTERY = 8,
605 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700606 /* Event generated by a device attached to the EC */
607 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800608 EC_HOST_EVENT_THERMAL = 11,
609 EC_HOST_EVENT_USB_CHARGER = 12,
610 EC_HOST_EVENT_KEY_PRESSED = 13,
611 /*
612 * EC has finished initializing the host interface. The host can check
613 * for this event following sending a EC_CMD_REBOOT_EC command to
614 * determine when the EC is ready to accept subsequent commands.
615 */
616 EC_HOST_EVENT_INTERFACE_READY = 14,
617 /* Keyboard recovery combo has been pressed */
618 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
619
620 /* Shutdown due to thermal overload */
621 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
622 /* Shutdown due to battery level too low */
623 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
624
Duncan Laurie93e24442014-01-06 12:30:52 -0800625 /* Suggest that the AP throttle itself */
626 EC_HOST_EVENT_THROTTLE_START = 18,
627 /* Suggest that the AP resume normal speed */
628 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700629
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800630 /* Hang detect logic detected a hang and host event timeout expired */
631 EC_HOST_EVENT_HANG_DETECT = 20,
632 /* Hang detect logic detected a hang and warm rebooted the AP */
633 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700634
635 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700636 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800637
Duncan Lauried8401182014-09-29 08:32:19 -0700638 /* Battery Status flags have changed */
639 EC_HOST_EVENT_BATTERY_STATUS = 23,
640
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700641 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800642 EC_HOST_EVENT_PANIC = 24,
643
Furquan Shaikh066cc852015-06-20 15:53:03 -0700644 /* Keyboard fastboot combo has been pressed */
645 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
646
Gwendal Grignou880b4582016-06-20 08:49:25 -0700647 /* EC RTC event occurred */
648 EC_HOST_EVENT_RTC = 26,
649
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700650 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700651 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700652
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700653 /* EC desires to change state of host-controlled USB mux */
654 EC_HOST_EVENT_USB_MUX = 28,
655
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800656 /*
657 * The device has changed "modes". This can be one of the following:
658 *
659 * - TABLET/LAPTOP mode
660 * - detachable base attach/detach event
661 */
jiazi Yang51fc93f2016-07-28 05:15:01 -0400662 EC_HOST_EVENT_MODE_CHANGE = 29,
663
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700664 /* Keyboard recovery combo with hardware reinitialization */
665 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
666
667 /*
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800668 * The high bit of the event mask is not used as a host event code. If
669 * it reads back as set, then the entire event mask should be
670 * considered invalid by the host. This can happen when reading the
671 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
672 * not initialized on the EC, or improperly configured on the host.
673 */
674 EC_HOST_EVENT_INVALID = 32
675};
676/* Host event mask */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800677#define EC_HOST_EVENT_MASK(event_code) BIT_ULL((event_code) - 1)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800678
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800679/**
680 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
681 * @flags: The host argument flags.
682 * @command_version: Command version.
683 * @data_size: The length of data.
684 * @checksum: Checksum; sum of command + flags + command_version + data_size +
685 * all params/response data bytes.
686 */
687struct ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800688 uint8_t flags;
689 uint8_t command_version;
690 uint8_t data_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800691 uint8_t checksum;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800692} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800693
694/* Flags for ec_lpc_host_args.flags */
695/*
696 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
697 * params.
698 *
699 * If EC gets a command and this flag is not set, this is an old-style command.
700 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
701 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700702 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800703 */
704#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
705/*
706 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
707 *
708 * If EC responds to a command and this flag is not set, this is an old-style
709 * response. Command version is 0 and response data from EC is at
710 * EC_LPC_ADDR_OLD_PARAM with unknown length.
711 */
712#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
713
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800714/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800715/*
716 * Byte codes returned by EC over SPI interface.
717 *
718 * These can be used by the AP to debug the EC interface, and to determine
719 * when the EC is not in a state where it will ever get around to responding
720 * to the AP.
721 *
722 * Example of sequence of bytes read from EC for a current good transfer:
723 * 1. - - AP asserts chip select (CS#)
724 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
725 * 3. - - EC starts handling CS# interrupt
726 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
727 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
728 * bytes looking for EC_SPI_FRAME_START
729 * 6. - - EC finishes processing and sets up response
730 * 7. EC_SPI_FRAME_START - AP reads frame byte
731 * 8. (response packet) - AP reads response packet
732 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
733 * 10 - - AP deasserts chip select
734 * 11 - - EC processes CS# interrupt and sets up DMA for
735 * next request
736 *
737 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
738 * the following byte values:
739 * EC_SPI_OLD_READY
740 * EC_SPI_RX_READY
741 * EC_SPI_RECEIVING
742 * EC_SPI_PROCESSING
743 *
744 * Then the EC found an error in the request, or was not ready for the request
745 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
746 * because the EC is unable to tell when the AP is done sending its request.
747 */
748
749/*
750 * Framing byte which precedes a response packet from the EC. After sending a
751 * request, the AP will clock in bytes until it sees the framing byte, then
752 * clock in the response packet.
753 */
754#define EC_SPI_FRAME_START 0xec
755
756/*
757 * Padding bytes which are clocked out after the end of a response packet.
758 */
759#define EC_SPI_PAST_END 0xed
760
761/*
762 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
763 * that the AP will send a valid packet header (starting with
764 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
765 */
766#define EC_SPI_RX_READY 0xf8
767
768/*
769 * EC has started receiving the request from the AP, but hasn't started
770 * processing it yet.
771 */
772#define EC_SPI_RECEIVING 0xf9
773
774/* EC has received the entire request from the AP and is processing it. */
775#define EC_SPI_PROCESSING 0xfa
776
777/*
778 * EC received bad data from the AP, such as a packet header with an invalid
779 * length. EC will ignore all data until chip select deasserts.
780 */
781#define EC_SPI_RX_BAD_DATA 0xfb
782
783/*
784 * EC received data from the AP before it was ready. That is, the AP asserted
785 * chip select and started clocking data before the EC was ready to receive it.
786 * EC will ignore all data until chip select deasserts.
787 */
788#define EC_SPI_NOT_READY 0xfc
789
790/*
791 * EC was ready to receive a request from the AP. EC has treated the byte sent
792 * by the AP as part of a request packet, or (for old-style ECs) is processing
793 * a fully received packet but is not ready to respond yet.
794 */
795#define EC_SPI_OLD_READY 0xfd
796
797/*****************************************************************************/
798
799/*
800 * Protocol version 2 for I2C and SPI send a request this way:
801 *
802 * 0 EC_CMD_VERSION0 + (command version)
803 * 1 Command number
804 * 2 Length of params = N
805 * 3..N+2 Params, if any
806 * N+3 8-bit checksum of bytes 0..N+2
807 *
808 * The corresponding response is:
809 *
810 * 0 Result code (EC_RES_*)
811 * 1 Length of params = M
812 * 2..M+1 Params, if any
813 * M+2 8-bit checksum of bytes 0..M+1
814 */
815#define EC_PROTO2_REQUEST_HEADER_BYTES 3
816#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
817#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
818 EC_PROTO2_REQUEST_TRAILER_BYTES)
819
820#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
821#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
822#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
823 EC_PROTO2_RESPONSE_TRAILER_BYTES)
824
825/* Parameter length was limited by the LPC interface */
826#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
827
828/* Maximum request and response packet sizes for protocol version 2 */
829#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
830 EC_PROTO2_MAX_PARAM_SIZE)
831#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
832 EC_PROTO2_MAX_PARAM_SIZE)
833
834/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800835
836/*
837 * Value written to legacy command port / prefix byte to indicate protocol
838 * 3+ structs are being used. Usage is bus-dependent.
839 */
840#define EC_COMMAND_PROTOCOL_3 0xda
841
842#define EC_HOST_REQUEST_VERSION 3
843
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800844/**
845 * struct ec_host_request - Version 3 request from host.
846 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
847 * receives a header with a version it doesn't know how to
848 * parse.
849 * @checksum: Checksum of request and data; sum of all bytes including checksum
850 * should total to 0.
851 * @command: Command to send (EC_CMD_...)
852 * @command_version: Command version.
853 * @reserved: Unused byte in current protocol version; set to 0.
854 * @data_len: Length of data which follows this header.
855 */
856struct ec_host_request {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800857 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800858 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800859 uint16_t command;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800860 uint8_t command_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800861 uint8_t reserved;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800862 uint16_t data_len;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800863} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800864
865#define EC_HOST_RESPONSE_VERSION 3
866
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800867/**
868 * struct ec_host_response - Version 3 response from EC.
869 * @struct_version: Struct version (=3).
870 * @checksum: Checksum of response and data; sum of all bytes including
871 * checksum should total to 0.
872 * @result: EC's response to the command (separate from communication failure)
873 * @data_len: Length of data which follows this header.
874 * @reserved: Unused bytes in current protocol version; set to 0.
875 */
876struct ec_host_response {
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800877 uint8_t struct_version;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800878 uint8_t checksum;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800879 uint16_t result;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800880 uint16_t data_len;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800881 uint16_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800882} __ec_align4;
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800883
884/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600885
886/*
887 * Host command protocol V4.
888 *
889 * Packets always start with a request or response header. They are followed
890 * by data_len bytes of data. If the data_crc_present flag is set, the data
891 * bytes are followed by a CRC-8 of that data, using using x^8 + x^2 + x + 1
892 * polynomial.
893 *
894 * Host algorithm when sending a request q:
895 *
896 * 101) tries_left=(some value, e.g. 3);
897 * 102) q.seq_num++
898 * 103) q.seq_dup=0
899 * 104) Calculate q.header_crc.
900 * 105) Send request q to EC.
901 * 106) Wait for response r. Go to 201 if received or 301 if timeout.
902 *
903 * 201) If r.struct_version != 4, go to 301.
904 * 202) If r.header_crc mismatches calculated CRC for r header, go to 301.
905 * 203) If r.data_crc_present and r.data_crc mismatches, go to 301.
906 * 204) If r.seq_num != q.seq_num, go to 301.
907 * 205) If r.seq_dup == q.seq_dup, return success.
908 * 207) If r.seq_dup == 1, go to 301.
909 * 208) Return error.
910 *
911 * 301) If --tries_left <= 0, return error.
912 * 302) If q.seq_dup == 1, go to 105.
913 * 303) q.seq_dup = 1
914 * 304) Go to 104.
915 *
916 * EC algorithm when receiving a request q.
917 * EC has response buffer r, error buffer e.
918 *
919 * 101) If q.struct_version != 4, set e.result = EC_RES_INVALID_HEADER_VERSION
920 * and go to 301
921 * 102) If q.header_crc mismatches calculated CRC, set e.result =
922 * EC_RES_INVALID_HEADER_CRC and go to 301
923 * 103) If q.data_crc_present, calculate data CRC. If that mismatches the CRC
924 * byte at the end of the packet, set e.result = EC_RES_INVALID_DATA_CRC
925 * and go to 301.
926 * 104) If q.seq_dup == 0, go to 201.
927 * 105) If q.seq_num != r.seq_num, go to 201.
928 * 106) If q.seq_dup == r.seq_dup, go to 205, else go to 203.
929 *
930 * 201) Process request q into response r.
931 * 202) r.seq_num = q.seq_num
932 * 203) r.seq_dup = q.seq_dup
933 * 204) Calculate r.header_crc
934 * 205) If r.data_len > 0 and data is no longer available, set e.result =
935 * EC_RES_DUP_UNAVAILABLE and go to 301.
936 * 206) Send response r.
937 *
938 * 301) e.seq_num = q.seq_num
939 * 302) e.seq_dup = q.seq_dup
940 * 303) Calculate e.header_crc.
941 * 304) Send error response e.
942 */
943
944/* Version 4 request from host */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800945struct ec_host_request4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600946 /*
947 * bits 0-3: struct_version: Structure version (=4)
948 * bit 4: is_response: Is response (=0)
949 * bits 5-6: seq_num: Sequence number
950 * bit 7: seq_dup: Sequence duplicate flag
951 */
952 uint8_t fields0;
953
954 /*
955 * bits 0-4: command_version: Command version
956 * bits 5-6: Reserved (set 0, ignore on read)
957 * bit 7: data_crc_present: Is data CRC present after data
958 */
959 uint8_t fields1;
960
961 /* Command code (EC_CMD_*) */
962 uint16_t command;
963
964 /* Length of data which follows this header (not including data CRC) */
965 uint16_t data_len;
966
967 /* Reserved (set 0, ignore on read) */
968 uint8_t reserved;
969
970 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
971 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800972} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600973
974/* Version 4 response from EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +0800975struct ec_host_response4 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -0600976 /*
977 * bits 0-3: struct_version: Structure version (=4)
978 * bit 4: is_response: Is response (=1)
979 * bits 5-6: seq_num: Sequence number
980 * bit 7: seq_dup: Sequence duplicate flag
981 */
982 uint8_t fields0;
983
984 /*
985 * bits 0-6: Reserved (set 0, ignore on read)
986 * bit 7: data_crc_present: Is data CRC present after data
987 */
988 uint8_t fields1;
989
990 /* Result code (EC_RES_*) */
991 uint16_t result;
992
993 /* Length of data which follows this header (not including data CRC) */
994 uint16_t data_len;
995
996 /* Reserved (set 0, ignore on read) */
997 uint8_t reserved;
998
999 /* CRC-8 of above fields, using x^8 + x^2 + x + 1 polynomial */
1000 uint8_t header_crc;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001001} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001002
1003/* Fields in fields0 byte */
1004#define EC_PACKET4_0_STRUCT_VERSION_MASK 0x0f
1005#define EC_PACKET4_0_IS_RESPONSE_MASK 0x10
1006#define EC_PACKET4_0_SEQ_NUM_SHIFT 5
1007#define EC_PACKET4_0_SEQ_NUM_MASK 0x60
1008#define EC_PACKET4_0_SEQ_DUP_MASK 0x80
1009
1010/* Fields in fields1 byte */
1011#define EC_PACKET4_1_COMMAND_VERSION_MASK 0x1f /* (request only) */
1012#define EC_PACKET4_1_DATA_CRC_PRESENT_MASK 0x80
1013
1014/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001015/*
1016 * Notes on commands:
1017 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001018 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001019 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001020 * specified, the command does not input or output data, respectively.
1021 * Parameter/response length is implicit in the structs. Some underlying
1022 * communication protocols (I2C, SPI) may add length or checksum headers, but
1023 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001024 *
1025 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
1026 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001027 */
1028
1029/*****************************************************************************/
1030/* General / test commands */
1031
1032/*
1033 * Get protocol version, used to deal with non-backward compatible protocol
1034 * changes.
1035 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001036#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001037
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001038/**
1039 * struct ec_response_proto_version - Response to the proto version command.
1040 * @version: The protocol version.
1041 */
1042struct ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001043 uint32_t version;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001044} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001045
1046/*
1047 * Hello. This is a simple command to test the EC is responsive to
1048 * commands.
1049 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001050#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001051
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001052/**
1053 * struct ec_params_hello - Parameters to the hello command.
1054 * @in_data: Pass anything here.
1055 */
1056struct ec_params_hello {
1057 uint32_t in_data;
1058} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001059
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001060/**
1061 * struct ec_response_hello - Response to the hello command.
1062 * @out_data: Output will be in_data + 0x01020304.
1063 */
1064struct ec_response_hello {
1065 uint32_t out_data;
1066} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001067
1068/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001069#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001070
1071enum ec_current_image {
1072 EC_IMAGE_UNKNOWN = 0,
1073 EC_IMAGE_RO,
1074 EC_IMAGE_RW
1075};
1076
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001077/**
1078 * struct ec_response_get_version - Response to the get version command.
1079 * @version_string_ro: Null-terminated RO firmware version string.
1080 * @version_string_rw: Null-terminated RW firmware version string.
1081 * @reserved: Unused bytes; was previously RW-B firmware version string.
1082 * @current_image: One of ec_current_image.
1083 */
1084struct ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001085 char version_string_ro[32];
1086 char version_string_rw[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001087 char reserved[32];
1088 uint32_t current_image;
1089} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001090
1091/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001092#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001093
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001094/**
1095 * struct ec_params_read_test - Parameters for the read test command.
1096 * @offset: Starting value for read buffer.
1097 * @size: Size to read in bytes.
1098 */
1099struct ec_params_read_test {
1100 uint32_t offset;
1101 uint32_t size;
1102} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001103
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001104/**
1105 * struct ec_response_read_test - Response to the read test command.
1106 * @data: Data returned by the read test command.
1107 */
1108struct ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001109 uint32_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001110} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001111
1112/*
1113 * Get build information
1114 *
1115 * Response is null-terminated string.
1116 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001117#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001118
1119/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001120#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001121
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001122/**
1123 * struct ec_response_get_chip_info - Response to the get chip info command.
1124 * @vendor: Null-terminated string for chip vendor.
1125 * @name: Null-terminated string for chip name.
1126 * @revision: Null-terminated string for chip mask version.
1127 */
1128struct ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001129 char vendor[32];
1130 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001131 char revision[32];
1132} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001133
1134/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001135#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001136
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001137/**
1138 * struct ec_response_board_version - Response to the board version command.
1139 * @board_version: A monotonously incrementing number.
1140 */
1141struct ec_response_board_version {
1142 uint16_t board_version;
1143} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001144
1145/*
1146 * Read memory-mapped data.
1147 *
1148 * This is an alternate interface to memory-mapped data for bus protocols
1149 * which don't support direct-mapped memory - I2C, SPI, etc.
1150 *
1151 * Response is params.size bytes of data.
1152 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001153#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001154
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001155/**
1156 * struct ec_params_read_memmap - Parameters for the read memory map command.
1157 * @offset: Offset in memmap (EC_MEMMAP_*).
1158 * @size: Size to read in bytes.
1159 */
1160struct ec_params_read_memmap {
1161 uint8_t offset;
1162 uint8_t size;
1163} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001164
1165/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001166#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001167
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001168/**
1169 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
1170 * @cmd: Command to check.
1171 */
1172struct ec_params_get_cmd_versions {
1173 uint8_t cmd;
1174} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001175
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001176/**
1177 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
1178 * versions (v1)
1179 * @cmd: Command to check.
1180 */
1181struct ec_params_get_cmd_versions_v1 {
1182 uint16_t cmd;
1183} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001184
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001185/**
1186 * struct ec_response_get_cmd_version - Response to the get command versions.
1187 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
1188 * a desired version.
1189 */
1190struct ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001191 uint32_t version_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001192} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001193
Duncan Laurie433432b2013-06-03 10:38:22 -07001194/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001195 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -07001196 * on lpc since it has its own out-of-band busy indicator.
1197 *
1198 * lpc must read the status from the command register. Attempting this on
1199 * lpc will overwrite the args/parameter space and corrupt its data.
1200 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001201#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -07001202
1203/* Avoid using ec_status which is for return values */
1204enum ec_comms_status {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001205 EC_COMMS_STATUS_PROCESSING = BIT(0), /* Processing cmd */
Duncan Laurie433432b2013-06-03 10:38:22 -07001206};
1207
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001208/**
1209 * struct ec_response_get_comms_status - Response to the get comms status
1210 * command.
1211 * @flags: Mask of enum ec_comms_status.
1212 */
1213struct ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001214 uint32_t flags; /* Mask of enum ec_comms_status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001215} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001216
Duncan Laurie93e24442014-01-06 12:30:52 -08001217/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001218#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -08001219
1220/* Tell the EC what to send back to us. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001221struct ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001222 uint32_t ec_result;
1223 uint32_t ret_len;
1224 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001225} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001226
1227/* Here it comes... */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001228struct ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -08001229 uint8_t buf[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001230} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001231
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001232/* Get protocol information */
1233#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -08001234
1235/* Flags for ec_response_get_protocol_info.flags */
1236/* EC_RES_IN_PROGRESS may be returned if a command is slow */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001237#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001238
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001239/**
1240 * struct ec_response_get_protocol_info - Response to the get protocol info.
1241 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
1242 * version n).
1243 * @max_request_packet_size: Maximum request packet size in bytes.
1244 * @max_response_packet_size: Maximum response packet size in bytes.
1245 * @flags: see EC_PROTOCOL_INFO_*
1246 */
1247struct ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -08001248 /* Fields which exist if at least protocol version 3 supported */
Duncan Laurie93e24442014-01-06 12:30:52 -08001249 uint32_t protocol_versions;
Duncan Laurie93e24442014-01-06 12:30:52 -08001250 uint16_t max_request_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001251 uint16_t max_response_packet_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001252 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001253} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001254
1255
1256/*****************************************************************************/
1257/* Get/Set miscellaneous values */
1258
1259/* The upper byte of .flags tells what to do (nothing means "get") */
1260#define EC_GSV_SET 0x80000000
1261
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001262/*
1263 * The lower three bytes of .flags identifies the parameter, if that has
1264 * meaning for an individual command.
1265 */
Duncan Laurie93e24442014-01-06 12:30:52 -08001266#define EC_GSV_PARAM_MASK 0x00ffffff
1267
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001268struct ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001269 uint32_t flags;
1270 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001271} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001272
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001273struct ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001274 uint32_t flags;
1275 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001276} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001277
Duncan Laurieeb316852015-12-01 18:51:18 -08001278/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001279#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001280
Duncan Laurieeb316852015-12-01 18:51:18 -08001281/*****************************************************************************/
1282/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001283#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001284
1285/* Supported features */
1286enum ec_feature_code {
1287 /*
1288 * This image contains a limited set of features. Another image
1289 * in RW partition may support more features.
1290 */
1291 EC_FEATURE_LIMITED = 0,
1292 /*
1293 * Commands for probing/reading/writing/erasing the flash in the
1294 * EC are present.
1295 */
1296 EC_FEATURE_FLASH = 1,
1297 /*
1298 * Can control the fan speed directly.
1299 */
1300 EC_FEATURE_PWM_FAN = 2,
1301 /*
1302 * Can control the intensity of the keyboard backlight.
1303 */
1304 EC_FEATURE_PWM_KEYB = 3,
1305 /*
1306 * Support Google lightbar, introduced on Pixel.
1307 */
1308 EC_FEATURE_LIGHTBAR = 4,
1309 /* Control of LEDs */
1310 EC_FEATURE_LED = 5,
1311 /* Exposes an interface to control gyro and sensors.
1312 * The host goes through the EC to access these sensors.
1313 * In addition, the EC may provide composite sensors, like lid angle.
1314 */
1315 EC_FEATURE_MOTION_SENSE = 6,
1316 /* The keyboard is controlled by the EC */
1317 EC_FEATURE_KEYB = 7,
1318 /* The AP can use part of the EC flash as persistent storage. */
1319 EC_FEATURE_PSTORE = 8,
1320 /* The EC monitors BIOS port 80h, and can return POST codes. */
1321 EC_FEATURE_PORT80 = 9,
1322 /*
1323 * Thermal management: include TMP specific commands.
1324 * Higher level than direct fan control.
1325 */
1326 EC_FEATURE_THERMAL = 10,
1327 /* Can switch the screen backlight on/off */
1328 EC_FEATURE_BKLIGHT_SWITCH = 11,
1329 /* Can switch the wifi module on/off */
1330 EC_FEATURE_WIFI_SWITCH = 12,
1331 /* Monitor host events, through for example SMI or SCI */
1332 EC_FEATURE_HOST_EVENTS = 13,
1333 /* The EC exposes GPIO commands to control/monitor connected devices. */
1334 EC_FEATURE_GPIO = 14,
1335 /* The EC can send i2c messages to downstream devices. */
1336 EC_FEATURE_I2C = 15,
1337 /* Command to control charger are included */
1338 EC_FEATURE_CHARGER = 16,
1339 /* Simple battery support. */
1340 EC_FEATURE_BATTERY = 17,
1341 /*
1342 * Support Smart battery protocol
1343 * (Common Smart Battery System Interface Specification)
1344 */
1345 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001346 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001347 EC_FEATURE_HANG_DETECT = 19,
1348 /* Report power information, for pit only */
1349 EC_FEATURE_PMU = 20,
1350 /* Another Cros EC device is present downstream of this one */
1351 EC_FEATURE_SUB_MCU = 21,
1352 /* Support USB Power delivery (PD) commands */
1353 EC_FEATURE_USB_PD = 22,
1354 /* Control USB multiplexer, for audio through USB port for instance. */
1355 EC_FEATURE_USB_MUX = 23,
1356 /* Motion Sensor code has an internal software FIFO */
1357 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1358 /* Support temporary secure vstore */
1359 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001360 /* EC decides on USB-C SS mux state, muxes configured by host */
1361 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1362 /* EC has RTC feature that can be controlled by host commands */
1363 EC_FEATURE_RTC = 27,
1364 /* The MCU exposes a Fingerprint sensor */
1365 EC_FEATURE_FINGERPRINT = 28,
1366 /* The MCU exposes a Touchpad */
1367 EC_FEATURE_TOUCHPAD = 29,
1368 /* The MCU has RWSIG task enabled */
1369 EC_FEATURE_RWSIG = 30,
1370 /* EC has device events support */
1371 EC_FEATURE_DEVICE_EVENT = 31,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001372 /* EC supports the unified wake masks for LPC/eSPI systems */
1373 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001374 /* EC supports 64-bit host events */
1375 EC_FEATURE_HOST_EVENT64 = 33,
1376 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1377 EC_FEATURE_EXEC_IN_RAM = 34,
1378 /* EC supports CEC commands */
1379 EC_FEATURE_CEC = 35,
1380 /* EC supports tight sensor timestamping. */
1381 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001382 /*
1383 * EC supports tablet mode detection aligned to Chrome and allows
1384 * setting of threshold by host command using
1385 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
1386 */
1387 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
1388 /* EC supports audio codec. */
1389 EC_FEATURE_AUDIO_CODEC = 38,
1390 /* The MCU is a System Companion Processor (SCP). */
1391 EC_FEATURE_SCP = 39,
1392 /* The MCU is an Integrated Sensor Hub */
1393 EC_FEATURE_ISH = 40,
Duncan Laurieeb316852015-12-01 18:51:18 -08001394};
1395
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001396#define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32)
1397#define EC_FEATURE_MASK_1(event_code) BIT(event_code - 32)
1398
1399struct ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001400 uint32_t flags[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001401} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001402
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001403/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001404/* Get the board's SKU ID from EC */
1405#define EC_CMD_GET_SKU_ID 0x000E
1406
Kevin Chiue2bb0592017-09-12 09:13:41 +08001407/* Set SKU ID from AP */
1408#define EC_CMD_SET_SKU_ID 0x000F
1409
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001410struct ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001411 uint32_t sku_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001412} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001413
1414/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001415/* Flash commands */
1416
1417/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001418#define EC_CMD_FLASH_INFO 0x0010
1419#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001420
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001421/**
1422 * struct ec_response_flash_info - Response to the flash info command.
1423 * @flash_size: Usable flash size in bytes.
1424 * @write_block_size: Write block size. Write offset and size must be a
1425 * multiple of this.
1426 * @erase_block_size: Erase block size. Erase offset and size must be a
1427 * multiple of this.
1428 * @protect_block_size: Protection block size. Protection offset and size
1429 * must be a multiple of this.
1430 *
1431 * Version 0 returns these fields.
1432 */
1433struct ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001434 uint32_t flash_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001435 uint32_t write_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001436 uint32_t erase_block_size;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001437 uint32_t protect_block_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001438} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001439
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001440/*
1441 * Flags for version 1+ flash info command
1442 * EC flash erases bits to 0 instead of 1.
1443 */
1444#define EC_FLASH_INFO_ERASE_TO_0 BIT(0)
Duncan Laurie93e24442014-01-06 12:30:52 -08001445
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001446/*
1447 * Flash must be selected for read/write/erase operations to succeed. This may
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001448 * be necessary on a chip where write/erase can be corrupted by other board
1449 * activity, or where the chip needs to enable some sort of programming voltage,
1450 * or where the read/write/erase operations require cleanly suspending other
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001451 * chip functionality.
1452 */
1453#define EC_FLASH_INFO_SELECT_REQUIRED BIT(1)
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001454
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001455/**
1456 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
1457 * @flash_size: Usable flash size in bytes.
1458 * @write_block_size: Write block size. Write offset and size must be a
1459 * multiple of this.
1460 * @erase_block_size: Erase block size. Erase offset and size must be a
1461 * multiple of this.
1462 * @protect_block_size: Protection block size. Protection offset and size
1463 * must be a multiple of this.
1464 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
1465 * size is exactly this and offset is a multiple of this.
1466 * For example, an EC may have a write buffer which can do
1467 * half-page operations if data is aligned, and a slower
1468 * word-at-a-time write mode.
1469 * @flags: Flags; see EC_FLASH_INFO_*
1470 *
Duncan Laurie93e24442014-01-06 12:30:52 -08001471 * Version 1 returns the same initial fields as version 0, with additional
1472 * fields following.
1473 *
1474 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001475 * if they did we'd define the version 0 structure as a sub-structure of this
1476 * one.
1477 *
1478 * Version 2 supports flash banks of different sizes:
1479 * The caller specified the number of banks it has preallocated
1480 * (num_banks_desc)
1481 * The EC returns the number of banks describing the flash memory.
1482 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001483 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001484struct ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001485 /* Version 0 fields; see above for description */
1486 uint32_t flash_size;
1487 uint32_t write_block_size;
1488 uint32_t erase_block_size;
1489 uint32_t protect_block_size;
1490
1491 /* Version 1 adds these fields: */
Duncan Laurie93e24442014-01-06 12:30:52 -08001492 uint32_t write_ideal_size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001493 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001494} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001495
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001496struct ec_params_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001497 /* Number of banks to describe */
1498 uint16_t num_banks_desc;
1499 /* Reserved; set 0; ignore on read */
1500 uint8_t reserved[2];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001501} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001502
1503struct ec_flash_bank {
1504 /* Number of sector is in this bank. */
1505 uint16_t count;
1506 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1507 uint8_t size_exp;
1508 /* Minimal write size for the sectors in this bank */
1509 uint8_t write_size_exp;
1510 /* Erase size for the sectors in this bank */
1511 uint8_t erase_size_exp;
1512 /* Size for write protection, usually identical to erase size. */
1513 uint8_t protect_size_exp;
1514 /* Reserved; set 0; ignore on read */
1515 uint8_t reserved[2];
1516};
1517
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001518struct ec_response_flash_info_2 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001519 /* Total flash in the EC. */
1520 uint32_t flash_size;
1521 /* Flags; see EC_FLASH_INFO_* */
1522 uint32_t flags;
1523 /* Maximum size to use to send data to write to the EC. */
1524 uint32_t write_ideal_size;
1525 /* Number of banks present in the EC. */
1526 uint16_t num_banks_total;
1527 /* Number of banks described in banks array. */
1528 uint16_t num_banks_desc;
1529 struct ec_flash_bank banks[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001530} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08001531
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001532/*
1533 * Read flash
1534 *
1535 * Response is params.size bytes of data.
1536 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001537#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001538
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001539/**
1540 * struct ec_params_flash_read - Parameters for the flash read command.
1541 * @offset: Byte offset to read.
1542 * @size: Size to read in bytes.
1543 */
1544struct ec_params_flash_read {
1545 uint32_t offset;
1546 uint32_t size;
1547} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001548
1549/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001550#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001551#define EC_VER_FLASH_WRITE 1
1552
1553/* Version 0 of the flash command supported only 64 bytes of data */
1554#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001555
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001556/**
1557 * struct ec_params_flash_write - Parameters for the flash write command.
1558 * @offset: Byte offset to write.
1559 * @size: Size to write in bytes.
1560 */
1561struct ec_params_flash_write {
1562 uint32_t offset;
1563 uint32_t size;
Duncan Laurie93e24442014-01-06 12:30:52 -08001564 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001565} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001566
1567/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001568#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001569
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001570/**
1571 * struct ec_params_flash_erase - Parameters for the flash erase command, v0.
1572 * @offset: Byte offset to erase.
1573 * @size: Size to erase in bytes.
1574 */
1575struct ec_params_flash_erase {
1576 uint32_t offset;
1577 uint32_t size;
1578} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001579
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001580/*
1581 * v1 add async erase:
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001582 * subcommands can returns:
1583 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1584 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1585 * EC_RES_ERROR : other errors.
1586 * EC_RES_BUSY : an existing erase operation is in progress.
1587 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1588 *
1589 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1590 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1591 * the proper result.
1592 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1593 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1594 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1595 * permitted while erasing. (For instance, STM32F4).
1596 */
1597enum ec_flash_erase_cmd {
1598 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1599 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1600 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1601};
1602
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001603/**
1604 * struct ec_params_flash_erase_v1 - Parameters for the flash erase command, v1.
1605 * @cmd: One of ec_flash_erase_cmd.
1606 * @reserved: Pad byte; currently always contains 0.
1607 * @flag: No flags defined yet; set to 0.
1608 * @params: Same as v0 parameters.
1609 */
1610struct ec_params_flash_erase_v1 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001611 uint8_t cmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001612 uint8_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001613 uint16_t flag;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001614 struct ec_params_flash_erase params;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001615} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001616
1617/*
1618 * Get/set flash protection.
1619 *
1620 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1621 * firmware write protect GPIO, not all flags will take effect immediately;
1622 * some flags require a subsequent hard reset to take effect. Check the
1623 * returned flags bits to see what actually happened.
1624 *
1625 * If mask=0, simply returns the current flags state.
1626 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001627#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001628#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1629
1630/* Flags for flash protection */
1631/* RO flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001632#define EC_FLASH_PROTECT_RO_AT_BOOT BIT(0)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001633/*
1634 * RO flash code protected now. If this bit is set, at-boot status cannot
1635 * be changed.
1636 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001637#define EC_FLASH_PROTECT_RO_NOW BIT(1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001638/* Entire flash code protected now, until reboot. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001639#define EC_FLASH_PROTECT_ALL_NOW BIT(2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001640/* Flash write protect GPIO is asserted now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001641#define EC_FLASH_PROTECT_GPIO_ASSERTED BIT(3)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001642/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001643#define EC_FLASH_PROTECT_ERROR_STUCK BIT(4)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001644/*
1645 * Error - flash protection is in inconsistent state. At least one bank of
1646 * flash which should be protected is not protected. Usually fixed by
1647 * re-requesting the desired flags, or by a hard reset if that fails.
1648 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001649#define EC_FLASH_PROTECT_ERROR_INCONSISTENT BIT(5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001650/* Entire flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001651#define EC_FLASH_PROTECT_ALL_AT_BOOT BIT(6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001652/* RW flash code protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001653#define EC_FLASH_PROTECT_RW_AT_BOOT BIT(7)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001654/* RW flash code protected now. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001655#define EC_FLASH_PROTECT_RW_NOW BIT(8)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001656/* Rollback information flash region protected when the EC boots */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001657#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT BIT(9)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001658/* Rollback information flash region protected now */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001659#define EC_FLASH_PROTECT_ROLLBACK_NOW BIT(10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001660
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001661
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001662/**
1663 * struct ec_params_flash_protect - Parameters for the flash protect command.
1664 * @mask: Bits in flags to apply.
1665 * @flags: New flags to apply.
1666 */
1667struct ec_params_flash_protect {
1668 uint32_t mask;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001669 uint32_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001670} __ec_align4;
1671
1672/**
1673 * struct ec_response_flash_protect - Response to the flash protect command.
1674 * @flags: Current value of flash protect flags.
1675 * @valid_flags: Flags which are valid on this platform. This allows the
1676 * caller to distinguish between flags which aren't set vs. flags
1677 * which can't be set on this platform.
1678 * @writable_flags: Flags which can be changed given the current protection
1679 * state.
1680 */
1681struct ec_response_flash_protect {
1682 uint32_t flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001683 uint32_t valid_flags;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001684 uint32_t writable_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001685} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001686
1687/*
1688 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1689 * write protect. These commands may be reused with version > 0.
1690 */
1691
1692/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001693#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001694#define EC_VER_FLASH_REGION_INFO 1
1695
1696enum ec_flash_region {
1697 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001698 EC_FLASH_REGION_RO = 0,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001699 /*
1700 * Region which holds active RW image. 'Active' is different from
1701 * 'running'. Active means 'scheduled-to-run'. Since RO image always
1702 * scheduled to run, active/non-active applies only to RW images (for
1703 * the same reason 'update' applies only to RW images. It's a state of
1704 * an image on a flash. Running image can be RO, RW_A, RW_B but active
1705 * image can only be RW_A or RW_B. In recovery mode, an active RW image
1706 * doesn't enter 'running' state but it's still active on a flash.
1707 */
1708 EC_FLASH_REGION_ACTIVE,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001709 /*
1710 * Region which should be write-protected in the factory (a superset of
1711 * EC_FLASH_REGION_RO)
1712 */
1713 EC_FLASH_REGION_WP_RO,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001714 /* Region which holds updatable (non-active) RW image */
1715 EC_FLASH_REGION_UPDATE,
Duncan Laurie93e24442014-01-06 12:30:52 -08001716 /* Number of regions */
1717 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001718};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001719/*
1720 * 'RW' is vague if there are multiple RW images; we mean the active one,
1721 * so the old constant is deprecated.
1722 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06001723#define EC_FLASH_REGION_RW EC_FLASH_REGION_ACTIVE
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001724
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001725/**
1726 * struct ec_params_flash_region_info - Parameters for the flash region info
1727 * command.
1728 * @region: Flash region; see EC_FLASH_REGION_*
1729 */
1730struct ec_params_flash_region_info {
1731 uint32_t region;
1732} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001733
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001734struct ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001735 uint32_t offset;
1736 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001737} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001738
Duncan Laurie433432b2013-06-03 10:38:22 -07001739/* Read/write VbNvContext */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001740#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001741#define EC_VER_VBNV_CONTEXT 1
1742#define EC_VBNV_BLOCK_SIZE 16
1743
1744enum ec_vbnvcontext_op {
1745 EC_VBNV_CONTEXT_OP_READ,
1746 EC_VBNV_CONTEXT_OP_WRITE,
1747};
1748
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001749struct ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001750 uint32_t op;
1751 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001752} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07001753
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001754struct ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001755 uint8_t block[EC_VBNV_BLOCK_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001756} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001757
1758
1759/* Get SPI flash information */
1760#define EC_CMD_FLASH_SPI_INFO 0x0018
1761
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001762struct ec_response_flash_spi_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001763 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1764 uint8_t jedec[3];
1765
1766 /* Pad byte; currently always contains 0 */
1767 uint8_t reserved0;
1768
1769 /* Manufacturer / device ID from command 0x90 */
1770 uint8_t mfr_dev_id[2];
1771
1772 /* Status registers from command 0x05 and 0x35 */
1773 uint8_t sr1, sr2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001774} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001775
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001776
1777/* Select flash during flash operations */
1778#define EC_CMD_FLASH_SELECT 0x0019
1779
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001780/**
1781 * struct ec_params_flash_select - Parameters for the flash select command.
1782 * @select: 1 to select flash, 0 to deselect flash
1783 */
1784struct ec_params_flash_select {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001785 uint8_t select;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001786} __ec_align4;
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001787
1788
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001789/**
1790 * Request random numbers to be generated and returned.
1791 * Can be used to test the random number generator is truly random.
1792 * See https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final and
1793 * https://webhome.phy.duke.edu/~rgb/General/dieharder.php.
1794 */
1795#define EC_CMD_RAND_NUM 0x001A
1796#define EC_VER_RAND_NUM 0
1797
1798struct ec_params_rand_num {
1799 uint16_t num_rand_bytes; /**< num random bytes to generate */
1800} __ec_align4;
1801
1802struct ec_response_rand_num {
1803 uint8_t rand[0]; /**< generated random numbers */
1804} __ec_align4;
1805
1806BUILD_ASSERT(sizeof(struct ec_response_rand_num) == 0);
1807
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001808/*****************************************************************************/
1809/* PWM commands */
1810
1811/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001812#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001813
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001814struct ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001815 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001816} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001817
1818/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001819#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001820
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001821/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001822struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001823 uint32_t rpm;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001824} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001825
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001826/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001827struct ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001828 uint32_t rpm;
1829 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001830} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001831
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001832/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001833/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001834#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001835
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001836struct ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001837 uint8_t percent;
1838 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001839} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001840
1841/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001842/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001843#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001844
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001845struct ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001846 uint8_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001847} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001848
1849/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001850#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001851
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001852/* Version 0 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001853struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001854 uint32_t percent;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001855} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001856
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001857/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001858struct ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001859 uint32_t percent;
1860 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001861} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001862
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001863#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07001864/* 16 bit duty cycle, 0xffff = 100% */
1865#define EC_PWM_MAX_DUTY 0xffff
1866
1867enum ec_pwm_type {
1868 /* All types, indexed by board-specific enum pwm_channel */
1869 EC_PWM_TYPE_GENERIC = 0,
1870 /* Keyboard backlight */
1871 EC_PWM_TYPE_KB_LIGHT,
1872 /* Display backlight */
1873 EC_PWM_TYPE_DISPLAY_LIGHT,
1874 EC_PWM_TYPE_COUNT,
1875};
1876
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001877struct ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001878 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1879 uint8_t pwm_type; /* ec_pwm_type */
1880 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001881} __ec_align4;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001882
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001883#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07001884
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001885struct ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001886 uint8_t pwm_type; /* ec_pwm_type */
1887 uint8_t index; /* Type-specific index, or 0 if unique */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001888} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001889
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001890struct ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001891 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001892} __ec_align2;
Gwendal Grignou880b4582016-06-20 08:49:25 -07001893
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001894/*****************************************************************************/
1895/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001896 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001897 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1898 * into a subcommand. We'll make separate structs for subcommands with
1899 * different input args, so that we know how much to expect.
1900 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001901#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001902
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001903struct rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07001904 uint8_t r, g, b;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001905} __ec_todo_unpacked;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001906
Duncan Laurie433432b2013-06-03 10:38:22 -07001907#define LB_BATTERY_LEVELS 4
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001908
1909/*
1910 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Duncan Laurie433432b2013-06-03 10:38:22 -07001911 * host command, but the alignment is the same regardless. Keep it that way.
1912 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001913struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001914 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001915 int32_t google_ramp_up;
1916 int32_t google_ramp_down;
1917 int32_t s3s0_ramp_up;
1918 int32_t s0_tick_delay[2]; /* AC=0/1 */
1919 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1920 int32_t s0s3_ramp_down;
1921 int32_t s3_sleep_for;
1922 int32_t s3_ramp_up;
1923 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001924
1925 /* Oscillation */
1926 uint8_t new_s0;
1927 uint8_t osc_min[2]; /* AC=0/1 */
1928 uint8_t osc_max[2]; /* AC=0/1 */
1929 uint8_t w_ofs[2]; /* AC=0/1 */
1930
1931 /* Brightness limits based on the backlight and AC. */
1932 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1933 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1934 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1935
1936 /* Battery level thresholds */
1937 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1938
1939 /* Map [AC][battery_level] to color index */
1940 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1941 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1942
1943 /* Color palette */
1944 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001945} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07001946
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001947struct lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001948 /* Timing */
1949 int32_t google_ramp_up;
1950 int32_t google_ramp_down;
1951 int32_t s3s0_ramp_up;
1952 int32_t s0_tick_delay[2]; /* AC=0/1 */
1953 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1954 int32_t s0s3_ramp_down;
1955 int32_t s3_sleep_for;
1956 int32_t s3_ramp_up;
1957 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001958 int32_t s5_ramp_up;
1959 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001960 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001961 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001962 int32_t tap_display_time;
1963
1964 /* Tap-for-battery params */
1965 uint8_t tap_pct_red;
1966 uint8_t tap_pct_green;
1967 uint8_t tap_seg_min_on;
1968 uint8_t tap_seg_max_on;
1969 uint8_t tap_seg_osc;
1970 uint8_t tap_idx[3];
1971
1972 /* Oscillation */
1973 uint8_t osc_min[2]; /* AC=0/1 */
1974 uint8_t osc_max[2]; /* AC=0/1 */
1975 uint8_t w_ofs[2]; /* AC=0/1 */
1976
1977 /* Brightness limits based on the backlight and AC. */
1978 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1979 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1980 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1981
1982 /* Battery level thresholds */
1983 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1984
1985 /* Map [AC][battery_level] to color index */
1986 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1987 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1988
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001989 /* s5: single color pulse on inhibited power-up */
1990 uint8_t s5_idx;
1991
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001992 /* Color palette */
1993 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08001994} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001995
Duncan Laurieeb316852015-12-01 18:51:18 -08001996/* Lightbar command params v2
1997 * crbug.com/467716
1998 *
1999 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
2000 * logical groups to make it more manageable ( < 120 bytes).
2001 *
2002 * NOTE: Each of these groups must be less than 120 bytes.
2003 */
2004
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002005struct lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08002006 /* Timing */
2007 int32_t google_ramp_up;
2008 int32_t google_ramp_down;
2009 int32_t s3s0_ramp_up;
2010 int32_t s0_tick_delay[2]; /* AC=0/1 */
2011 int32_t s0a_tick_delay[2]; /* AC=0/1 */
2012 int32_t s0s3_ramp_down;
2013 int32_t s3_sleep_for;
2014 int32_t s3_ramp_up;
2015 int32_t s3_ramp_down;
2016 int32_t s5_ramp_up;
2017 int32_t s5_ramp_down;
2018 int32_t tap_tick_delay;
2019 int32_t tap_gate_delay;
2020 int32_t tap_display_time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002021} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002022
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002023struct lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08002024 /* Tap-for-battery params */
2025 uint8_t tap_pct_red;
2026 uint8_t tap_pct_green;
2027 uint8_t tap_seg_min_on;
2028 uint8_t tap_seg_max_on;
2029 uint8_t tap_seg_osc;
2030 uint8_t tap_idx[3];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002031} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002032
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002033struct lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08002034 /* Oscillation */
2035 uint8_t osc_min[2]; /* AC=0/1 */
2036 uint8_t osc_max[2]; /* AC=0/1 */
2037 uint8_t w_ofs[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002038} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002039
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002040struct lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08002041 /* Brightness limits based on the backlight and AC. */
2042 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
2043 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
2044 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002045} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002046
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002047struct lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08002048 /* Battery level thresholds */
2049 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002050} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002051
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002052struct lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08002053 /* Map [AC][battery_level] to color index */
2054 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
2055 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
2056
2057 /* s5: single color pulse on inhibited power-up */
2058 uint8_t s5_idx;
2059
2060 /* Color palette */
2061 struct rgb_s color[8]; /* 0-3 are Google colors */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002062} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002063
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002064/* Lightbar program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002065#define EC_LB_PROG_LEN 192
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002066struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07002067 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002068 uint8_t data[EC_LB_PROG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002069} __ec_todo_unpacked;
Duncan Lauried8401182014-09-29 08:32:19 -07002070
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002071struct ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002072 uint8_t cmd; /* Command (see enum lightbar_command) */
2073 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002074 /*
2075 * The following commands have no args:
2076 *
2077 * dump, off, on, init, get_seq, get_params_v0, get_params_v1,
2078 * version, get_brightness, get_demo, suspend, resume,
2079 * get_params_v2_timing, get_params_v2_tap, get_params_v2_osc,
2080 * get_params_v2_bright, get_params_v2_thlds,
2081 * get_params_v2_colors
2082 *
2083 * Don't use an empty struct, because C++ hates that.
2084 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002085
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002086 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002087 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002088 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002089
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002090 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002091 uint8_t ctrl, reg, value;
2092 } reg;
2093
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002094 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002095 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002096 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07002097
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002098 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002099 uint8_t led;
2100 } get_rgb;
2101
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002102 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002103 uint8_t enable;
2104 } manual_suspend_ctrl;
2105
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002106 struct lightbar_params_v0 set_params_v0;
2107 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08002108
2109 struct lightbar_params_v2_timing set_v2par_timing;
2110 struct lightbar_params_v2_tap set_v2par_tap;
2111 struct lightbar_params_v2_oscillation set_v2par_osc;
2112 struct lightbar_params_v2_brightness set_v2par_bright;
2113 struct lightbar_params_v2_thresholds set_v2par_thlds;
2114 struct lightbar_params_v2_colors set_v2par_colors;
2115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002116 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002117 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002118} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002119
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002120struct ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07002121 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002122 struct __ec_todo_unpacked {
2123 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002124 uint8_t reg;
2125 uint8_t ic0;
2126 uint8_t ic1;
2127 } vals[23];
2128 } dump;
2129
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002130 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002131 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002132 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07002133
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002134 struct lightbar_params_v0 get_params_v0;
2135 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002136
Duncan Laurieeb316852015-12-01 18:51:18 -08002137
2138 struct lightbar_params_v2_timing get_params_v2_timing;
2139 struct lightbar_params_v2_tap get_params_v2_tap;
2140 struct lightbar_params_v2_oscillation get_params_v2_osc;
2141 struct lightbar_params_v2_brightness get_params_v2_bright;
2142 struct lightbar_params_v2_thresholds get_params_v2_thlds;
2143 struct lightbar_params_v2_colors get_params_v2_colors;
2144
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002145 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08002146 uint32_t num;
2147 uint32_t flags;
2148 } version;
2149
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002150 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002151 uint8_t red, green, blue;
2152 } get_rgb;
2153
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002154 /*
2155 * The following commands have no response:
2156 *
2157 * off, on, init, set_brightness, seq, reg, set_rgb, demo,
2158 * set_params_v0, set_params_v1, set_program,
2159 * manual_suspend_ctrl, suspend, resume, set_v2par_timing,
2160 * set_v2par_tap, set_v2par_osc, set_v2par_bright,
2161 * set_v2par_thlds, set_v2par_colors
2162 */
Duncan Laurie433432b2013-06-03 10:38:22 -07002163 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002164} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002165
2166/* Lightbar commands */
2167enum lightbar_command {
2168 LIGHTBAR_CMD_DUMP = 0,
2169 LIGHTBAR_CMD_OFF = 1,
2170 LIGHTBAR_CMD_ON = 2,
2171 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002172 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07002173 LIGHTBAR_CMD_SEQ = 5,
2174 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002175 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07002176 LIGHTBAR_CMD_GET_SEQ = 8,
2177 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002178 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
2179 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08002180 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002181 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
2182 LIGHTBAR_CMD_GET_RGB = 14,
2183 LIGHTBAR_CMD_GET_DEMO = 15,
2184 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
2185 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07002186 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002187 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
2188 LIGHTBAR_CMD_SUSPEND = 20,
2189 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08002190 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
2191 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
2192 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
2193 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
2194 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
2195 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
2196 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
2197 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
2198 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
2199 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
2200 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
2201 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07002202 LIGHTBAR_NUM_CMDS
2203};
2204
2205/*****************************************************************************/
2206/* LED control commands */
2207
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002208#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07002209
Bill Richardsone221aad2013-06-12 10:50:41 -07002210enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08002211 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07002212 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08002213 /*
2214 * LED to indicate system power state (on or in suspend).
2215 * May be on power button or on C-panel.
2216 */
2217 EC_LED_ID_POWER_LED,
2218 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07002219 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002220 /* LED to indicate left side */
2221 EC_LED_ID_LEFT_LED,
2222 /* LED to indicate right side */
2223 EC_LED_ID_RIGHT_LED,
2224 /* LED to indicate recovery mode with HW_REINIT */
2225 EC_LED_ID_RECOVERY_HW_REINIT_LED,
2226 /* LED to indicate sysrq debug mode. */
2227 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08002228
2229 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07002230};
Duncan Laurie433432b2013-06-03 10:38:22 -07002231
Bill Richardsone221aad2013-06-12 10:50:41 -07002232/* LED control flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002233#define EC_LED_FLAGS_QUERY BIT(0) /* Query LED capability only */
2234#define EC_LED_FLAGS_AUTO BIT(1) /* Switch LED back to automatic control */
Bill Richardsone221aad2013-06-12 10:50:41 -07002235
2236enum ec_led_colors {
2237 EC_LED_COLOR_RED = 0,
2238 EC_LED_COLOR_GREEN,
2239 EC_LED_COLOR_BLUE,
2240 EC_LED_COLOR_YELLOW,
2241 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08002242 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07002243
2244 EC_LED_COLOR_COUNT
2245};
2246
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002247struct ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002248 uint8_t led_id; /* Which LED to control */
2249 uint8_t flags; /* Control flags */
2250
2251 uint8_t brightness[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002252} __ec_align1;
Bill Richardsone221aad2013-06-12 10:50:41 -07002253
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002254struct ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07002255 /*
2256 * Available brightness value range.
2257 *
2258 * Range 0 means color channel not present.
2259 * Range 1 means on/off control.
2260 * Other values means the LED is control by PWM.
2261 */
2262 uint8_t brightness_range[EC_LED_COLOR_COUNT];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002263} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07002264
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002265/*****************************************************************************/
2266/* Verified boot commands */
2267
2268/*
2269 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
2270 * reused for other purposes with version > 0.
2271 */
2272
2273/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002274#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002275
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002276struct ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002277 uint8_t cmd; /* enum ec_vboot_hash_cmd */
2278 uint8_t hash_type; /* enum ec_vboot_hash_type */
2279 uint8_t nonce_size; /* Nonce size; may be 0 */
2280 uint8_t reserved0; /* Reserved; set 0 */
2281 uint32_t offset; /* Offset in flash to hash */
2282 uint32_t size; /* Number of bytes to hash */
2283 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002284} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002285
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002286struct ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002287 uint8_t status; /* enum ec_vboot_hash_status */
2288 uint8_t hash_type; /* enum ec_vboot_hash_type */
2289 uint8_t digest_size; /* Size of hash digest in bytes */
2290 uint8_t reserved0; /* Ignore; will be 0 */
2291 uint32_t offset; /* Offset in flash which was hashed */
2292 uint32_t size; /* Number of bytes hashed */
2293 uint8_t hash_digest[64]; /* Hash digest data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002294} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002295
2296enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07002297 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
2298 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
2299 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
2300 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002301};
2302
2303enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07002304 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002305};
2306
2307enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07002308 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
2309 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
2310 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002311};
2312
Duncan Laurie433432b2013-06-03 10:38:22 -07002313/*
2314 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
2315 * If one of these is specified, the EC will automatically update offset and
2316 * size to the correct values for the specified image (RO or RW).
2317 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002318#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
2319#define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
2320#define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
2321
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002322/*
2323 * 'RW' is vague if there are multiple RW images; we mean the active one,
2324 * so the old constant is deprecated.
2325 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002326#define EC_VBOOT_HASH_OFFSET_RW EC_VBOOT_HASH_OFFSET_ACTIVE
Duncan Laurie433432b2013-06-03 10:38:22 -07002327
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002328/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002329/*
2330 * Motion sense commands. We'll make separate structs for sub-commands with
2331 * different input args, so that we know how much to expect.
2332 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002333#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002334
2335/* Motion sense commands */
2336enum motionsense_command {
2337 /*
2338 * Dump command returns all motion sensor data including motion sense
2339 * module flags and individual sensor flags.
2340 */
2341 MOTIONSENSE_CMD_DUMP = 0,
2342
2343 /*
2344 * Info command returns data describing the details of a given sensor,
2345 * including enum motionsensor_type, enum motionsensor_location, and
2346 * enum motionsensor_chip.
2347 */
2348 MOTIONSENSE_CMD_INFO = 1,
2349
2350 /*
2351 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08002352 * in milliseconds.
2353 * It is per sensor, the EC run sample task at the minimum of all
2354 * sensors EC_RATE.
2355 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
2356 * to collect all the sensor samples.
2357 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
2358 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002359 */
2360 MOTIONSENSE_CMD_EC_RATE = 2,
2361
2362 /*
2363 * Sensor ODR command is a setter/getter command for the output data
2364 * rate of a specific motion sensor in millihertz.
2365 */
2366 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2367
2368 /*
2369 * Sensor range command is a setter/getter command for the range of
2370 * a specified motion sensor in +/-G's or +/- deg/s.
2371 */
2372 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2373
2374 /*
2375 * Setter/getter command for the keyboard wake angle. When the lid
2376 * angle is greater than this value, keyboard wake is disabled in S3,
2377 * and when the lid angle goes less than this value, keyboard wake is
2378 * enabled. Note, the lid angle measurement is an approximate,
2379 * un-calibrated value, hence the wake angle isn't exact.
2380 */
2381 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2382
Duncan Laurieeb316852015-12-01 18:51:18 -08002383 /*
2384 * Returns a single sensor data.
2385 */
2386 MOTIONSENSE_CMD_DATA = 6,
2387
2388 /*
2389 * Return sensor fifo info.
2390 */
2391 MOTIONSENSE_CMD_FIFO_INFO = 7,
2392
2393 /*
2394 * Insert a flush element in the fifo and return sensor fifo info.
2395 * The host can use that element to synchronize its operation.
2396 */
2397 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2398
2399 /*
2400 * Return a portion of the fifo.
2401 */
2402 MOTIONSENSE_CMD_FIFO_READ = 9,
2403
2404 /*
2405 * Perform low level calibration.
2406 * On sensors that support it, ask to do offset calibration.
2407 */
2408 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2409
2410 /*
2411 * Sensor Offset command is a setter/getter command for the offset
2412 * used for calibration.
2413 * The offsets can be calculated by the host, or via
2414 * PERFORM_CALIB command.
2415 */
2416 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2417
2418 /*
2419 * List available activities for a MOTION sensor.
2420 * Indicates if they are enabled or disabled.
2421 */
2422 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2423
2424 /*
2425 * Activity management
2426 * Enable/Disable activity recognition.
2427 */
2428 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2429
2430 /*
2431 * Lid Angle
2432 */
2433 MOTIONSENSE_CMD_LID_ANGLE = 14,
2434
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002435 /*
2436 * Allow the FIFO to trigger interrupt via MKBP events.
2437 * By default the FIFO does not send interrupt to process the FIFO
2438 * until the AP is ready or it is coming from a wakeup sensor.
2439 */
2440 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2441
2442 /*
2443 * Spoof the readings of the sensors. The spoofed readings can be set
2444 * to arbitrary values, or will lock to the last read actual values.
2445 */
2446 MOTIONSENSE_CMD_SPOOF = 16,
2447
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002448 /* Set lid angle for tablet mode detection. */
2449 MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE = 17,
2450
2451 /*
2452 * Sensor Scale command is a setter/getter command for the calibration
2453 * scale.
2454 */
2455 MOTIONSENSE_CMD_SENSOR_SCALE = 18,
2456
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002457 /* Number of motionsense sub-commands. */
2458 MOTIONSENSE_NUM_CMDS
2459};
2460
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002461/* List of motion sensor types. */
2462enum motionsensor_type {
2463 MOTIONSENSE_TYPE_ACCEL = 0,
2464 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002465 MOTIONSENSE_TYPE_MAG = 2,
2466 MOTIONSENSE_TYPE_PROX = 3,
2467 MOTIONSENSE_TYPE_LIGHT = 4,
2468 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002469 MOTIONSENSE_TYPE_BARO = 6,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002470 MOTIONSENSE_TYPE_SYNC = 7,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002471 MOTIONSENSE_TYPE_LIGHT_RGB = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08002472 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002473};
2474
2475/* List of motion sensor locations. */
2476enum motionsensor_location {
2477 MOTIONSENSE_LOC_BASE = 0,
2478 MOTIONSENSE_LOC_LID = 1,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002479 MOTIONSENSE_LOC_CAMERA = 2,
Duncan Laurieeb316852015-12-01 18:51:18 -08002480 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002481};
2482
2483/* List of motion sensor chips. */
2484enum motionsensor_chip {
2485 MOTIONSENSE_CHIP_KXCJ9 = 0,
2486 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002487 MOTIONSENSE_CHIP_BMI160 = 2,
2488 MOTIONSENSE_CHIP_SI1141 = 3,
2489 MOTIONSENSE_CHIP_SI1142 = 4,
2490 MOTIONSENSE_CHIP_SI1143 = 5,
2491 MOTIONSENSE_CHIP_KX022 = 6,
2492 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002493 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002494 MOTIONSENSE_CHIP_BMP280 = 9,
2495 MOTIONSENSE_CHIP_OPT3001 = 10,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002496 MOTIONSENSE_CHIP_BH1730 = 11,
2497 MOTIONSENSE_CHIP_GPIO = 12,
2498 MOTIONSENSE_CHIP_LIS2DH = 13,
2499 MOTIONSENSE_CHIP_LSM6DSM = 14,
2500 MOTIONSENSE_CHIP_LIS2DE = 15,
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002501 MOTIONSENSE_CHIP_LIS2MDL = 16,
2502 MOTIONSENSE_CHIP_LSM6DS3 = 17,
2503 MOTIONSENSE_CHIP_LSM6DSO = 18,
2504 MOTIONSENSE_CHIP_LNG2DM = 19,
2505 MOTIONSENSE_CHIP_TCS3400 = 20,
2506 MOTIONSENSE_CHIP_LIS2DW12 = 21,
2507 MOTIONSENSE_CHIP_LIS2DWL = 22,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002508 MOTIONSENSE_CHIP_MAX,
2509};
2510
2511/* List of orientation positions */
2512enum motionsensor_orientation {
2513 MOTIONSENSE_ORIENTATION_LANDSCAPE = 0,
2514 MOTIONSENSE_ORIENTATION_PORTRAIT = 1,
2515 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_PORTRAIT = 2,
2516 MOTIONSENSE_ORIENTATION_UPSIDE_DOWN_LANDSCAPE = 3,
2517 MOTIONSENSE_ORIENTATION_UNKNOWN = 4,
Duncan Laurieeb316852015-12-01 18:51:18 -08002518};
2519
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002520struct ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002521 /* Flags for each sensor. */
2522 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002523 /* Sensor number the data comes from. */
Duncan Laurieeb316852015-12-01 18:51:18 -08002524 uint8_t sensor_num;
2525 /* Each sensor is up to 3-axis. */
2526 union {
2527 int16_t data[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002528 struct __ec_todo_packed {
2529 uint16_t reserved;
Duncan Laurieeb316852015-12-01 18:51:18 -08002530 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002531 };
2532 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002533 uint8_t activity; /* motionsensor_activity */
2534 uint8_t state;
2535 int16_t add_info[2];
2536 };
2537 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002538} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002539
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002540/* Note: used in ec_response_get_next_data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002541struct ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002542 /* Size of the fifo */
2543 uint16_t size;
2544 /* Amount of space used in the fifo */
2545 uint16_t count;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002546 /* Timestamp recorded in us.
2547 * aka accurate timestamp when host event was triggered.
2548 */
Duncan Laurieeb316852015-12-01 18:51:18 -08002549 uint32_t timestamp;
2550 /* Total amount of vector lost */
2551 uint16_t total_lost;
2552 /* Lost events since the last fifo_info, per sensors */
2553 uint16_t lost[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002554} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002555
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002556struct ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002557 uint32_t number_data;
2558 struct ec_response_motion_sensor_data data[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002559} __ec_todo_packed;
Duncan Laurieeb316852015-12-01 18:51:18 -08002560
2561/* List supported activity recognition */
2562enum motionsensor_activity {
2563 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2564 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2565 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002566 MOTIONSENSE_ACTIVITY_ORIENTATION = 3,
Duncan Laurieeb316852015-12-01 18:51:18 -08002567};
2568
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002569struct ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002570 uint8_t sensor_num;
2571 uint8_t activity; /* one of enum motionsensor_activity */
2572 uint8_t enable; /* 1: enable, 0: disable */
2573 uint8_t reserved;
2574 uint16_t parameters[3]; /* activity dependent parameters */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002575} __ec_todo_unpacked;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002576
2577/* Module flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002578#define MOTIONSENSE_MODULE_FLAG_ACTIVE BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002579
2580/* Sensor flag masks used for the dump sub-command. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002581#define MOTIONSENSE_SENSOR_FLAG_PRESENT BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002582
2583/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002584 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002585 * data contains time stamp
2586 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002587#define MOTIONSENSE_SENSOR_FLAG_FLUSH BIT(0)
2588#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP BIT(1)
2589#define MOTIONSENSE_SENSOR_FLAG_WAKEUP BIT(2)
2590#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE BIT(3)
2591#define MOTIONSENSE_SENSOR_FLAG_ODR BIT(4)
Duncan Laurieeb316852015-12-01 18:51:18 -08002592
2593/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002594 * Send this value for the data element to only perform a read. If you
2595 * send any other value, the EC will interpret it as data to set and will
2596 * return the actual value set.
2597 */
2598#define EC_MOTION_SENSE_NO_VALUE -1
2599
Duncan Laurieeb316852015-12-01 18:51:18 -08002600#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2601
2602/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2603/* Set Calibration information */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002604#define MOTION_SENSE_SET_OFFSET BIT(0)
2605
2606/* Default Scale value, factor 1. */
2607#define MOTION_SENSE_DEFAULT_SCALE BIT(15)
Duncan Laurieeb316852015-12-01 18:51:18 -08002608
2609#define LID_ANGLE_UNRELIABLE 500
2610
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002611enum motionsense_spoof_mode {
2612 /* Disable spoof mode. */
2613 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2614
2615 /* Enable spoof mode, but use provided component values. */
2616 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2617
2618 /* Enable spoof mode, but use the current sensor values. */
2619 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2620
2621 /* Query the current spoof mode status for the sensor. */
2622 MOTIONSENSE_SPOOF_MODE_QUERY,
2623};
2624
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002625struct ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002626 uint8_t cmd;
2627 union {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002628 /* Used for MOTIONSENSE_CMD_DUMP. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002629 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002630 /*
2631 * Maximal number of sensor the host is expecting.
2632 * 0 means the host is only interested in the number
2633 * of sensors controlled by the EC.
2634 */
2635 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002636 } dump;
2637
2638 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002639 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002640 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002641 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002642 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2643 * kb_wake_angle: angle to wakup AP.
2644 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002645 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002646 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002647
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002648 /*
2649 * Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2650 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002651 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002652 uint8_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002653 } info, info_3, data, fifo_flush, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002654
2655 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002656 * Used for MOTIONSENSE_CMD_PERFORM_CALIB:
2657 * Allow entering/exiting the calibration mode.
2658 */
2659 struct __ec_todo_unpacked {
2660 uint8_t sensor_num;
2661 uint8_t enable;
2662 } perform_calib;
2663 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002664 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2665 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002666 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002667 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002668 uint8_t sensor_num;
2669
2670 /* Rounding flag, true for round-up, false for down. */
2671 uint8_t roundup;
2672
2673 uint16_t reserved;
2674
2675 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2676 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002677 } ec_rate, sensor_odr, sensor_range;
2678
2679 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002680 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002681 uint8_t sensor_num;
2682
2683 /*
2684 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2685 * the calibration information in the EC.
2686 * If unset, just retrieve calibration information.
2687 */
2688 uint16_t flags;
2689
2690 /*
2691 * Temperature at calibration, in units of 0.01 C
2692 * 0x8000: invalid / unknown.
2693 * 0x0: 0C
2694 * 0x7fff: +327.67C
2695 */
2696 int16_t temp;
2697
2698 /*
2699 * Offset for calibration.
2700 * Unit:
2701 * Accelerometer: 1/1024 g
2702 * Gyro: 1/1024 deg/s
2703 * Compass: 1/16 uT
2704 */
2705 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002706 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002707
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002708 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2709 struct __ec_todo_packed {
2710 uint8_t sensor_num;
2711
2712 /*
2713 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2714 * the calibration information in the EC.
2715 * If unset, just retrieve calibration information.
2716 */
2717 uint16_t flags;
2718
2719 /*
2720 * Temperature at calibration, in units of 0.01 C
2721 * 0x8000: invalid / unknown.
2722 * 0x0: 0C
2723 * 0x7fff: +327.67C
2724 */
2725 int16_t temp;
2726
2727 /*
2728 * Scale for calibration:
2729 * By default scale is 1, it is encoded on 16bits:
2730 * 1 = BIT(15)
2731 * ~2 = 0xFFFF
2732 * ~0 = 0.
2733 */
2734 uint16_t scale[3];
2735 } sensor_scale;
2736
2737
Duncan Laurieeb316852015-12-01 18:51:18 -08002738 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002739 /* (no params) */
Duncan Laurieeb316852015-12-01 18:51:18 -08002740
2741 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002742 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002743 /*
2744 * Number of expected vector to return.
2745 * EC may return less or 0 if none available.
2746 */
2747 uint32_t max_data_vector;
2748 } fifo_read;
2749
2750 struct ec_motion_sense_activity set_activity;
2751
2752 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002753 /* (no params) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002754
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002755 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2756 struct __ec_todo_unpacked {
2757 /*
2758 * 1: enable, 0 disable fifo,
2759 * EC_MOTION_SENSE_NO_VALUE return value.
2760 */
2761 int8_t enable;
2762 } fifo_int_enable;
2763
2764 /* Used for MOTIONSENSE_CMD_SPOOF */
2765 struct __ec_todo_packed {
2766 uint8_t sensor_id;
2767
2768 /* See enum motionsense_spoof_mode. */
2769 uint8_t spoof_enable;
2770
2771 /* Ignored, used for alignment. */
2772 uint8_t reserved;
2773
2774 /* Individual component values to spoof. */
2775 int16_t components[3];
2776 } spoof;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002777
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002778 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2779 struct __ec_todo_unpacked {
2780 /*
2781 * Lid angle threshold for switching between tablet and
2782 * clamshell mode.
2783 */
2784 int16_t lid_angle;
2785
2786 /*
2787 * Hysteresis degree to prevent fluctuations between
2788 * clamshell and tablet mode if lid angle keeps
2789 * changing around the threshold. Lid motion driver will
2790 * use lid_angle + hys_degree to trigger tablet mode and
2791 * lid_angle - hys_degree to trigger clamshell mode.
2792 */
2793 int16_t hys_degree;
2794 } tablet_mode_threshold;
2795 };
2796} __ec_todo_packed;
2797
2798struct ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002799 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002800 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002801 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002802 /* Flags representing the motion sensor module. */
2803 uint8_t module_flags;
2804
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002805 /* Number of sensors managed directly by the EC. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002806 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002807
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002808 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002809 * Sensor data is truncated if response_max is too small
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002810 * for holding all the data.
2811 */
2812 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002813 } dump;
2814
2815 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002816 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002817 /* Should be element of enum motionsensor_type. */
2818 uint8_t type;
2819
2820 /* Should be element of enum motionsensor_location. */
2821 uint8_t location;
2822
2823 /* Should be element of enum motionsensor_chip. */
2824 uint8_t chip;
2825 } info;
2826
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002827 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2828 struct __ec_todo_unpacked {
2829 /* Should be element of enum motionsensor_type. */
2830 uint8_t type;
2831
2832 /* Should be element of enum motionsensor_location. */
2833 uint8_t location;
2834
2835 /* Should be element of enum motionsensor_chip. */
2836 uint8_t chip;
2837
2838 /* Minimum sensor sampling frequency */
2839 uint32_t min_frequency;
2840
2841 /* Maximum sensor sampling frequency */
2842 uint32_t max_frequency;
2843
2844 /* Max number of sensor events that could be in fifo */
2845 uint32_t fifo_max_event_count;
2846 } info_3;
2847
Duncan Laurieeb316852015-12-01 18:51:18 -08002848 /* Used for MOTIONSENSE_CMD_DATA */
2849 struct ec_response_motion_sensor_data data;
2850
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002851 /*
2852 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002853 * MOTIONSENSE_CMD_SENSOR_RANGE,
2854 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2855 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2856 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002857 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002858 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002859 /* Current value of the parameter queried. */
2860 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002861 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2862 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08002863
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002864 /*
2865 * Used for MOTIONSENSE_CMD_SENSOR_OFFSET,
2866 * PERFORM_CALIB.
2867 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002868 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002869 int16_t temp;
2870 int16_t offset[3];
2871 } sensor_offset, perform_calib;
2872
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002873 /* Used for MOTIONSENSE_CMD_SENSOR_SCALE */
2874 struct __ec_todo_unpacked {
2875 int16_t temp;
2876 uint16_t scale[3];
2877 } sensor_scale;
2878
Duncan Laurieeb316852015-12-01 18:51:18 -08002879 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2880
2881 struct ec_response_motion_sense_fifo_data fifo_read;
2882
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002883 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002884 uint16_t reserved;
2885 uint32_t enabled;
2886 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002887 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08002888
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06002889 /* No params for set activity */
Duncan Laurieeb316852015-12-01 18:51:18 -08002890
Duncan Laurieeb316852015-12-01 18:51:18 -08002891 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002892 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002893 /*
2894 * Angle between 0 and 360 degree if available,
2895 * LID_ANGLE_UNRELIABLE otherwise.
2896 */
2897 uint16_t value;
2898 } lid_angle;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002899
2900 /* Used for MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE. */
2901 struct __ec_todo_unpacked {
2902 /*
2903 * Lid angle threshold for switching between tablet and
2904 * clamshell mode.
2905 */
2906 uint16_t lid_angle;
2907
2908 /* Hysteresis degree. */
2909 uint16_t hys_degree;
2910 } tablet_mode_threshold;
2911
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002912 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002913} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002914
2915/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002916/* Force lid open command */
2917
2918/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002919#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002920
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002921struct ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002922 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002923} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002924
2925/*****************************************************************************/
2926/* Configure the behavior of the power button */
2927#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2928
2929enum ec_config_power_button_flags {
2930 /* Enable/Disable power button pulses for x86 devices */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002931 EC_POWER_BUTTON_ENABLE_PULSE = BIT(0),
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002932};
2933
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002934struct ec_params_config_power_button {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002935 /* See enum ec_config_power_button_flags */
2936 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002937} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002938
2939/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002940/* USB charging control commands */
2941
2942/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002943#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002944
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002945enum usb_charge_mode {
2946 /* Disable USB port. */
2947 USB_CHARGE_MODE_DISABLED,
2948 /* Set USB port to Standard Downstream Port, USB 2.0 mode. */
2949 USB_CHARGE_MODE_SDP2,
2950 /* Set USB port to Charging Downstream Port, BC 1.2. */
2951 USB_CHARGE_MODE_CDP,
2952 /* Set USB port to Dedicated Charging Port, BC 1.2. */
2953 USB_CHARGE_MODE_DCP_SHORT,
2954 /* Enable USB port (for dumb ports). */
2955 USB_CHARGE_MODE_ENABLED,
2956 /* Set USB port to CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE. */
2957 USB_CHARGE_MODE_DEFAULT,
2958
2959 USB_CHARGE_MODE_COUNT
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002960};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002961
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002962enum usb_suspend_charge {
2963 /* Enable charging in suspend */
2964 USB_ALLOW_SUSPEND_CHARGE,
2965 /* Disable charging in suspend */
2966 USB_DISALLOW_SUSPEND_CHARGE
2967};
2968
2969struct ec_params_usb_charge_set_mode {
2970 uint8_t usb_port_id;
2971 uint8_t mode:7; /* enum usb_charge_mode */
2972 uint8_t inhibit_charge:1; /* enum usb_suspend_charge */
2973} __ec_align1;
2974
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002975/*****************************************************************************/
2976/* Persistent storage for host */
2977
2978/* Maximum bytes that can be read/written in a single command */
2979#define EC_PSTORE_SIZE_MAX 64
2980
2981/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002982#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002983
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002984struct ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002985 /* Persistent storage size, in bytes */
2986 uint32_t pstore_size;
2987 /* Access size; read/write offset and size must be a multiple of this */
2988 uint32_t access_size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002989} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002990
2991/*
2992 * Read persistent storage
2993 *
2994 * Response is params.size bytes of data.
2995 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002996#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002997
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08002998struct ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002999 uint32_t offset; /* Byte offset to read */
3000 uint32_t size; /* Size to read in bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003001} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003002
3003/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003004#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003005
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003006struct ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003007 uint32_t offset; /* Byte offset to write */
3008 uint32_t size; /* Size to write in bytes */
3009 uint8_t data[EC_PSTORE_SIZE_MAX];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003010} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003011
3012/*****************************************************************************/
3013/* Real-time clock */
3014
3015/* RTC params and response structures */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003016struct ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003017 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003018} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003019
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003020struct ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003021 uint32_t time;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003022} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003023
3024/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003025#define EC_CMD_RTC_GET_VALUE 0x0044
3026#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003027
3028/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003029#define EC_CMD_RTC_SET_VALUE 0x0046
3030#define EC_CMD_RTC_SET_ALARM 0x0047
3031
3032/* Pass as time param to SET_ALARM to clear the current alarm */
3033#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003034
3035/*****************************************************************************/
3036/* Port80 log access */
3037
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003038/* Maximum entries that can be read/written in a single command */
3039#define EC_PORT80_SIZE_MAX 32
3040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003041/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003042#define EC_CMD_PORT80_LAST_BOOT 0x0048
3043#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003044
3045enum ec_port80_subcmd {
3046 EC_PORT80_GET_INFO = 0,
3047 EC_PORT80_READ_BUFFER,
3048};
3049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003050struct ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003051 uint16_t subcmd;
3052 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003053 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003054 uint32_t offset;
3055 uint32_t num_entries;
3056 } read_buffer;
3057 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003058} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003059
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003060struct ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003061 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003062 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003063 uint32_t writes;
3064 uint32_t history_size;
3065 uint32_t last_boot;
3066 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003067 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003068 uint16_t codes[EC_PORT80_SIZE_MAX];
3069 } data;
3070 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003071} __ec_todo_packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003072
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003073struct ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003074 uint16_t code;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003075} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003076
3077/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08003078/* Temporary secure storage for host verified boot use */
3079
3080/* Number of bytes in a vstore slot */
3081#define EC_VSTORE_SLOT_SIZE 64
3082
3083/* Maximum number of vstore slots */
3084#define EC_VSTORE_SLOT_MAX 32
3085
3086/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003087#define EC_CMD_VSTORE_INFO 0x0049
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003088struct ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08003089 /* Indicates which slots are locked */
3090 uint32_t slot_locked;
3091 /* Total number of slots available */
3092 uint8_t slot_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003093} __ec_align_size1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003094
3095/*
3096 * Read temporary secure storage
3097 *
3098 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
3099 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003100#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08003101
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003102struct ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003103 uint8_t slot; /* Slot to read from */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003104} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003106struct ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08003107 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003108} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003109
3110/*
3111 * Write temporary secure storage and lock it.
3112 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003113#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08003114
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003115struct ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08003116 uint8_t slot; /* Slot to write to */
3117 uint8_t data[EC_VSTORE_SLOT_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003118} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08003119
3120/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08003121/* Thermal engine commands. Note that there are two implementations. We'll
3122 * reuse the command number, but the data and behavior is incompatible.
3123 * Version 0 is what originally shipped on Link.
3124 * Version 1 separates the CPU thermal limits from the fan control.
3125 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003126
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003127#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
3128#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003129
Duncan Laurie93e24442014-01-06 12:30:52 -08003130/* The version 0 structs are opaque. You have to know what they are for
3131 * the get/set commands to make any sense.
3132 */
3133
3134/* Version 0 - set */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003135struct ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003136 uint8_t sensor_type;
3137 uint8_t threshold_id;
3138 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003139} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003140
Duncan Laurie93e24442014-01-06 12:30:52 -08003141/* Version 0 - get */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003142struct ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003143 uint8_t sensor_type;
3144 uint8_t threshold_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003145} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003146
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003147struct ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003148 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003149} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003150
Duncan Laurie93e24442014-01-06 12:30:52 -08003151
3152/* The version 1 structs are visible. */
3153enum ec_temp_thresholds {
3154 EC_TEMP_THRESH_WARN = 0,
3155 EC_TEMP_THRESH_HIGH,
3156 EC_TEMP_THRESH_HALT,
3157
3158 EC_TEMP_THRESH_COUNT
3159};
3160
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003161/*
3162 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08003163 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003164 *
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003165 * Set 'temp_host' value allows thermal task to trigger some event with 1 degree
3166 * hysteresis.
3167 * For example,
3168 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3169 * temp_host_release[EC_TEMP_THRESH_HIGH] = 0 K
3170 * EC will throttle ap when temperature >= 301 K, and release throttling when
3171 * temperature <= 299 K.
3172 *
3173 * Set 'temp_host_release' value allows thermal task has a custom hysteresis.
3174 * For example,
3175 * temp_host[EC_TEMP_THRESH_HIGH] = 300 K
3176 * temp_host_release[EC_TEMP_THRESH_HIGH] = 295 K
3177 * EC will throttle ap when temperature >= 301 K, and release throttling when
3178 * temperature <= 294 K.
3179 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003180 * Note that this structure is a sub-structure of
3181 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08003182 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003183struct ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08003184 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003185 uint32_t temp_host_release[EC_TEMP_THRESH_COUNT]; /* release levels */
Duncan Laurie93e24442014-01-06 12:30:52 -08003186 uint32_t temp_fan_off; /* no active cooling needed */
3187 uint32_t temp_fan_max; /* max active cooling needed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003188} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003189
3190/* Version 1 - get config for one sensor. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003191struct ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003192 uint32_t sensor_num;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003193} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003194/* This returns a struct ec_thermal_config */
3195
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003196/*
3197 * Version 1 - set config for one sensor.
3198 * Use read-modify-write for best results!
3199 */
3200struct ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08003201 uint32_t sensor_num;
3202 struct ec_thermal_config cfg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003203} __ec_align4;
Duncan Laurie93e24442014-01-06 12:30:52 -08003204/* This returns no data */
3205
3206/****************************************************************************/
3207
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003208/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003209#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003210
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003211/* Version 1 of input params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003212struct ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003213 uint8_t fan_idx;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003214} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003215
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003216/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003217#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
3218#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003219
3220/*
3221 * The original TMP006 calibration only needed four params, but now we need
3222 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
3223 * the params opaque. The v1 "get" response will include the algorithm number
3224 * and how many params it requires. That way we can change the EC code without
3225 * needing to update this file. We can also use a different algorithm on each
3226 * sensor.
3227 */
3228
3229/* This is the same struct for both v0 and v1. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003230struct ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07003231 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003232} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003233
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003234/* Version 0 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003235struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003236 float s0;
3237 float b0;
3238 float b1;
3239 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003240} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003241
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003242struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003243 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003244 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07003245 float s0;
3246 float b0;
3247 float b1;
3248 float b2;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003249} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07003250
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003251/* Version 1 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003252struct ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003253 uint8_t algorithm;
3254 uint8_t num_params;
3255 uint8_t reserved[2];
3256 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003257} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003258
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003259struct ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003260 uint8_t index;
3261 uint8_t algorithm;
3262 uint8_t num_params;
3263 uint8_t reserved;
3264 float val[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003265} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003266
3267
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003268/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003269#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003270
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003271struct ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003272 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003273} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003274
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003275struct ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003276 int32_t t; /* In 1/100 K */
3277 int32_t v; /* In nV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003278} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003279
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003280/*****************************************************************************/
3281/* MKBP - Matrix KeyBoard Protocol */
3282
3283/*
3284 * Read key state
3285 *
3286 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
3287 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003288 *
3289 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
3290 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
3291 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003292 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003293#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003294
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003295/*
3296 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
3297 */
3298#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003299
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003300struct ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003301 uint32_t rows;
3302 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003303 /* Formerly "switches", which was 0. */
3304 uint8_t reserved;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003305} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003306
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003307struct ec_params_mkbp_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003308 uint8_t info_type;
3309 uint8_t event_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003310} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003311
3312enum ec_mkbp_info_type {
3313 /*
3314 * Info about the keyboard matrix: number of rows and columns.
3315 *
3316 * Returns struct ec_response_mkbp_info.
3317 */
3318 EC_MKBP_INFO_KBD = 0,
3319
3320 /*
3321 * For buttons and switches, info about which specifically are
3322 * supported. event_type must be set to one of the values in enum
3323 * ec_mkbp_event.
3324 *
3325 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
3326 * bitmask indicating which buttons or switches are present. See the
3327 * bit inidices below.
3328 */
3329 EC_MKBP_INFO_SUPPORTED = 1,
3330
3331 /*
3332 * Instantaneous state of buttons and switches.
3333 *
3334 * event_type must be set to one of the values in enum ec_mkbp_event.
3335 *
3336 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
3337 * indicating the current state of the keyboard matrix.
3338 *
3339 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
3340 * event state.
3341 *
3342 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
3343 * state of supported buttons.
3344 *
3345 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
3346 * state of supported switches.
3347 */
3348 EC_MKBP_INFO_CURRENT = 2,
3349};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003350
3351/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003352#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003353
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003354struct ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003355 uint8_t col;
3356 uint8_t row;
3357 uint8_t pressed;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003358} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003359
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003360#define EC_CMD_GET_KEYBOARD_ID 0x0063
3361
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003362struct ec_response_keyboard_id {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003363 uint32_t keyboard_id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003364} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003365
3366enum keyboard_id {
3367 KEYBOARD_ID_UNSUPPORTED = 0,
3368 KEYBOARD_ID_UNREADABLE = 0xffffffff,
3369};
3370
Duncan Laurie433432b2013-06-03 10:38:22 -07003371/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003372#define EC_CMD_MKBP_SET_CONFIG 0x0064
3373#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07003374
3375/* flags */
3376enum mkbp_config_flags {
3377 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
3378};
3379
3380enum mkbp_config_valid {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003381 EC_MKBP_VALID_SCAN_PERIOD = BIT(0),
3382 EC_MKBP_VALID_POLL_TIMEOUT = BIT(1),
3383 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = BIT(3),
3384 EC_MKBP_VALID_OUTPUT_SETTLE = BIT(4),
3385 EC_MKBP_VALID_DEBOUNCE_DOWN = BIT(5),
3386 EC_MKBP_VALID_DEBOUNCE_UP = BIT(6),
3387 EC_MKBP_VALID_FIFO_MAX_DEPTH = BIT(7),
Duncan Laurie433432b2013-06-03 10:38:22 -07003388};
3389
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003390/*
3391 * Configuration for our key scanning algorithm.
3392 *
3393 * Note that this is used as a sub-structure of
3394 * ec_{params/response}_mkbp_get_config.
3395 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003396struct ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003397 uint32_t valid_mask; /* valid fields */
3398 uint8_t flags; /* some flags (enum mkbp_config_flags) */
3399 uint8_t valid_flags; /* which flags are valid */
3400 uint16_t scan_period_us; /* period between start of scans */
3401 /* revert to interrupt mode after no activity for this long */
3402 uint32_t poll_timeout_us;
3403 /*
3404 * minimum post-scan relax time. Once we finish a scan we check
3405 * the time until we are due to start the next one. If this time is
3406 * shorter this field, we use this instead.
3407 */
3408 uint16_t min_post_scan_delay_us;
3409 /* delay between setting up output and waiting for it to settle */
3410 uint16_t output_settle_us;
3411 uint16_t debounce_down_us; /* time for debounce on key down */
3412 uint16_t debounce_up_us; /* time for debounce on key up */
3413 /* maximum depth to allow for fifo (0 = no keyscan output) */
3414 uint8_t fifo_max_depth;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003415} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003416
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003417struct ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003418 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003419} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003420
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003421struct ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07003422 struct ec_mkbp_config config;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003423} __ec_align_size1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003424
3425/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003426#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07003427
3428enum ec_keyscan_seq_cmd {
3429 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
3430 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
3431 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
3432 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
3433 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
3434};
3435
3436enum ec_collect_flags {
3437 /*
3438 * Indicates this scan was processed by the EC. Due to timing, some
3439 * scans may be skipped.
3440 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003441 EC_KEYSCAN_SEQ_FLAG_DONE = BIT(0),
Duncan Laurie433432b2013-06-03 10:38:22 -07003442};
3443
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003444struct ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07003445 uint8_t flags; /* some flags (enum ec_collect_flags) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003446} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07003447
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003448struct ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003449 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
3450 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003451 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003452 uint8_t active; /* still active */
3453 uint8_t num_items; /* number of items */
3454 /* Current item being presented */
3455 uint8_t cur_item;
3456 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003457 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003458 /*
3459 * Absolute time for this scan, measured from the
3460 * start of the sequence.
3461 */
3462 uint32_t time_us;
3463 uint8_t scan[0]; /* keyscan data */
3464 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003465 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07003466 uint8_t start_item; /* First item to return */
3467 uint8_t num_items; /* Number of items to return */
3468 } collect;
3469 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003470} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003471
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003472struct ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07003473 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003474 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07003475 uint8_t num_items; /* Number of items */
3476 /* Data for each item */
3477 struct ec_collect_item item[0];
3478 } collect;
3479 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003480} __ec_todo_packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07003481
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003482/*
3483 * Get the next pending MKBP event.
3484 *
3485 * Returns EC_RES_UNAVAILABLE if there is no event pending.
3486 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003487#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003488
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003489#define EC_MKBP_HAS_MORE_EVENTS_SHIFT 7
3490
3491/*
3492 * We use the most significant bit of the event type to indicate to the host
3493 * that the EC has more MKBP events available to provide.
3494 */
3495#define EC_MKBP_HAS_MORE_EVENTS BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT)
3496
3497/* The mask to apply to get the raw event type */
3498#define EC_MKBP_EVENT_TYPE_MASK (BIT(EC_MKBP_HAS_MORE_EVENTS_SHIFT) - 1)
3499
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003500enum ec_mkbp_event {
3501 /* Keyboard matrix changed. The event data is the new matrix state. */
3502 EC_MKBP_EVENT_KEY_MATRIX = 0,
3503
3504 /* New host event. The event data is 4 bytes of host event flags. */
3505 EC_MKBP_EVENT_HOST_EVENT = 1,
3506
Duncan Laurieeb316852015-12-01 18:51:18 -08003507 /* New Sensor FIFO data. The event data is fifo_info structure. */
3508 EC_MKBP_EVENT_SENSOR_FIFO = 2,
3509
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003510 /* The state of the non-matrixed buttons have changed. */
3511 EC_MKBP_EVENT_BUTTON = 3,
3512
3513 /* The state of the switches have changed. */
3514 EC_MKBP_EVENT_SWITCH = 4,
3515
3516 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
3517 EC_MKBP_EVENT_FINGERPRINT = 5,
3518
3519 /*
3520 * Sysrq event: send emulated sysrq. The event data is sysrq,
3521 * corresponding to the key to be pressed.
3522 */
3523 EC_MKBP_EVENT_SYSRQ = 6,
3524
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003525 /*
3526 * New 64-bit host event.
3527 * The event data is 8 bytes of host event flags.
3528 */
3529 EC_MKBP_EVENT_HOST_EVENT64 = 7,
3530
3531 /* Notify the AP that something happened on CEC */
3532 EC_MKBP_EVENT_CEC_EVENT = 8,
3533
3534 /* Send an incoming CEC message to the AP */
3535 EC_MKBP_EVENT_CEC_MESSAGE = 9,
3536
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003537 /* We have entered DisplayPort Alternate Mode on a Type-C port. */
3538 EC_MKBP_EVENT_DP_ALT_MODE_ENTERED = 10,
3539
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003540 /* Number of MKBP events */
3541 EC_MKBP_EVENT_COUNT,
3542};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003543BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003544
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003545union __ec_align_offset1 ec_response_get_next_data {
3546 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08003547
3548 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003549 uint32_t host_event;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003550 uint64_t host_event64;
Duncan Laurieeb316852015-12-01 18:51:18 -08003551
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003552 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08003553 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003554 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08003555 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003556 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08003557
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003558 uint32_t buttons;
3559
3560 uint32_t switches;
3561
3562 uint32_t fp_events;
3563
3564 uint32_t sysrq;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003565
3566 /* CEC events from enum mkbp_cec_event */
3567 uint32_t cec_events;
3568};
3569
3570union __ec_align_offset1 ec_response_get_next_data_v1 {
3571 uint8_t key_matrix[16];
3572
3573 /* Unaligned */
3574 uint32_t host_event;
3575 uint64_t host_event64;
3576
3577 struct __ec_todo_unpacked {
3578 /* For aligning the fifo_info */
3579 uint8_t reserved[3];
3580 struct ec_response_motion_sense_fifo_info info;
3581 } sensor_fifo;
3582
3583 uint32_t buttons;
3584
3585 uint32_t switches;
3586
3587 uint32_t fp_events;
3588
3589 uint32_t sysrq;
3590
3591 /* CEC events from enum mkbp_cec_event */
3592 uint32_t cec_events;
3593
3594 uint8_t cec_message[16];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003595};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003596BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003597
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003598struct ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003599 uint8_t event_type;
3600 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003601 union ec_response_get_next_data data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003602} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003603
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003604struct ec_response_get_next_event_v1 {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003605 uint8_t event_type;
3606 /* Followed by event data if any */
3607 union ec_response_get_next_data_v1 data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003608} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003609
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003610/* Bit indices for buttons and switches.*/
3611/* Buttons */
3612#define EC_MKBP_POWER_BUTTON 0
3613#define EC_MKBP_VOL_UP 1
3614#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003615#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003616
3617/* Switches */
3618#define EC_MKBP_LID_OPEN 0
3619#define EC_MKBP_TABLET_MODE 1
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003620#define EC_MKBP_BASE_ATTACHED 2
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003621
Gwendal Grignou880b4582016-06-20 08:49:25 -07003622/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003623#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003624
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003625struct ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003626 uint16_t shorted; /* Keyboard pins are shorted */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003627} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003628
3629/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3630#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003631#define EC_MKBP_FP_ERRCODE(fp_events) ((fp_events) & 0x0000000F)
3632#define EC_MKBP_FP_ENROLL_PROGRESS_OFFSET 4
3633#define EC_MKBP_FP_ENROLL_PROGRESS(fpe) (((fpe) & 0x00000FF0) \
3634 >> EC_MKBP_FP_ENROLL_PROGRESS_OFFSET)
3635#define EC_MKBP_FP_MATCH_IDX_OFFSET 12
3636#define EC_MKBP_FP_MATCH_IDX_MASK 0x0000F000
3637#define EC_MKBP_FP_MATCH_IDX(fpe) (((fpe) & EC_MKBP_FP_MATCH_IDX_MASK) \
3638 >> EC_MKBP_FP_MATCH_IDX_OFFSET)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003639#define EC_MKBP_FP_ENROLL BIT(27)
3640#define EC_MKBP_FP_MATCH BIT(28)
3641#define EC_MKBP_FP_FINGER_DOWN BIT(29)
3642#define EC_MKBP_FP_FINGER_UP BIT(30)
3643#define EC_MKBP_FP_IMAGE_READY BIT(31)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003644/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_ENROLL is set */
3645#define EC_MKBP_FP_ERR_ENROLL_OK 0
3646#define EC_MKBP_FP_ERR_ENROLL_LOW_QUALITY 1
3647#define EC_MKBP_FP_ERR_ENROLL_IMMOBILE 2
3648#define EC_MKBP_FP_ERR_ENROLL_LOW_COVERAGE 3
3649#define EC_MKBP_FP_ERR_ENROLL_INTERNAL 5
3650/* Can be used to detect if image was usable for enrollment or not. */
3651#define EC_MKBP_FP_ERR_ENROLL_PROBLEM_MASK 1
3652/* code given by EC_MKBP_FP_ERRCODE() when EC_MKBP_FP_MATCH is set */
3653#define EC_MKBP_FP_ERR_MATCH_NO 0
3654#define EC_MKBP_FP_ERR_MATCH_NO_INTERNAL 6
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003655#define EC_MKBP_FP_ERR_MATCH_NO_TEMPLATES 7
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003656#define EC_MKBP_FP_ERR_MATCH_NO_LOW_QUALITY 2
3657#define EC_MKBP_FP_ERR_MATCH_NO_LOW_COVERAGE 4
3658#define EC_MKBP_FP_ERR_MATCH_YES 1
3659#define EC_MKBP_FP_ERR_MATCH_YES_UPDATED 3
3660#define EC_MKBP_FP_ERR_MATCH_YES_UPDATE_FAILED 5
3661
Gwendal Grignou880b4582016-06-20 08:49:25 -07003662
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003663#define EC_CMD_MKBP_WAKE_MASK 0x0069
3664enum ec_mkbp_event_mask_action {
3665 /* Retrieve the value of a wake mask. */
3666 GET_WAKE_MASK = 0,
3667
3668 /* Set the value of a wake mask. */
3669 SET_WAKE_MASK,
3670};
3671
3672enum ec_mkbp_mask_type {
3673 /*
3674 * These are host events sent via MKBP.
3675 *
3676 * Some examples are:
3677 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)
3678 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_KEY_PRESSED)
3679 *
3680 * The only things that should be in this mask are:
3681 * EC_HOST_EVENT_MASK(EC_HOST_EVENT_*)
3682 */
3683 EC_MKBP_HOST_EVENT_WAKE_MASK = 0,
3684
3685 /*
3686 * These are MKBP events. Some examples are:
3687 *
3688 * EC_MKBP_EVENT_KEY_MATRIX
3689 * EC_MKBP_EVENT_SWITCH
3690 *
3691 * The only things that should be in this mask are EC_MKBP_EVENT_*.
3692 */
3693 EC_MKBP_EVENT_WAKE_MASK,
3694};
3695
3696struct ec_params_mkbp_event_wake_mask {
3697 /* One of enum ec_mkbp_event_mask_action */
3698 uint8_t action;
3699
3700 /*
3701 * Which MKBP mask are you interested in acting upon? This is one of
3702 * ec_mkbp_mask_type.
3703 */
3704 uint8_t mask_type;
3705
3706 /* If setting a new wake mask, this contains the mask to set. */
3707 uint32_t new_wake_mask;
3708};
3709
3710struct ec_response_mkbp_event_wake_mask {
3711 uint32_t wake_mask;
3712};
3713
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003714/*****************************************************************************/
3715/* Temperature sensor commands */
3716
3717/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003718#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003719
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003720struct ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003721 uint8_t id;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003722} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003723
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003724struct ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003725 char sensor_name[32];
3726 uint8_t sensor_type;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003727} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003728
3729/*****************************************************************************/
3730
3731/*
3732 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3733 * commands accidentally sent to the wrong interface. See the ACPI section
3734 * below.
3735 */
3736
3737/*****************************************************************************/
3738/* Host event commands */
3739
Jenny TC1dfc2c32017-12-14 14:24:39 +05303740
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06003741/* Obsolete. New implementation should use EC_CMD_HOST_EVENT instead */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003742/*
3743 * Host event mask params and response structures, shared by all of the host
3744 * event commands below.
3745 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003746struct ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003747 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003748} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003749
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003750struct ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003751 uint32_t mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003752} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003753
3754/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003755#define EC_CMD_HOST_EVENT_GET_B 0x0087
3756#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3757#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3758#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003759
3760/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003761#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3762#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3763#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3764#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3765#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003766
Jenny TC1dfc2c32017-12-14 14:24:39 +05303767/*
3768 * Unified host event programming interface - Should be used by newer versions
3769 * of BIOS/OS to program host events and masks
3770 */
3771
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003772struct ec_params_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303773
3774 /* Action requested by host - one of enum ec_host_event_action. */
3775 uint8_t action;
3776
3777 /*
3778 * Mask type that the host requested the action on - one of
3779 * enum ec_host_event_mask_type.
3780 */
3781 uint8_t mask_type;
3782
3783 /* Set to 0, ignore on read */
3784 uint16_t reserved;
3785
3786 /* Value to be used in case of set operations. */
3787 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003788} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05303789
3790/*
3791 * Response structure returned by EC_CMD_HOST_EVENT.
3792 * Update the value on a GET request. Set to 0 on GET/CLEAR
3793 */
3794
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003795struct ec_response_host_event {
Jenny TC1dfc2c32017-12-14 14:24:39 +05303796
3797 /* Mask value in case of get operation */
3798 uint64_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003799} __ec_align4;
Jenny TC1dfc2c32017-12-14 14:24:39 +05303800
3801enum ec_host_event_action {
3802 /*
3803 * params.value is ignored. Value of mask_type populated
3804 * in response.value
3805 */
3806 EC_HOST_EVENT_GET,
3807
3808 /* Bits in params.value are set */
3809 EC_HOST_EVENT_SET,
3810
3811 /* Bits in params.value are cleared */
3812 EC_HOST_EVENT_CLEAR,
3813};
3814
3815enum ec_host_event_mask_type {
3816
3817 /* Main host event copy */
3818 EC_HOST_EVENT_MAIN,
3819
3820 /* Copy B of host events */
3821 EC_HOST_EVENT_B,
3822
3823 /* SCI Mask */
3824 EC_HOST_EVENT_SCI_MASK,
3825
3826 /* SMI Mask */
3827 EC_HOST_EVENT_SMI_MASK,
3828
3829 /* Mask of events that should be always reported in hostevents */
3830 EC_HOST_EVENT_ALWAYS_REPORT_MASK,
3831
3832 /* Active wake mask */
3833 EC_HOST_EVENT_ACTIVE_WAKE_MASK,
3834
3835 /* Lazy wake mask for S0ix */
3836 EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
3837
3838 /* Lazy wake mask for S3 */
3839 EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
3840
3841 /* Lazy wake mask for S5 */
3842 EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
3843};
3844
3845#define EC_CMD_HOST_EVENT 0x00A4
3846
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003847/*****************************************************************************/
3848/* Switch commands */
3849
3850/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003851#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003852
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003853struct ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003854 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003855} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003856
3857/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003858#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003859#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003860
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003861/* Version 0 params; no response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003862struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003863 uint8_t enabled;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003864} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003865
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003866/* Version 1 params */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003867struct ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003868 /* Flags to enable now */
3869 uint8_t now_flags;
3870
3871 /* Which flags to copy from now_flags */
3872 uint8_t now_mask;
3873
3874 /*
3875 * Flags to leave enabled in S3, if they're on at the S0->S3
3876 * transition. (Other flags will be disabled by the S0->S3
3877 * transition.)
3878 */
3879 uint8_t suspend_flags;
3880
3881 /* Which flags to copy from suspend_flags */
3882 uint8_t suspend_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003883} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003884
3885/* Version 1 response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003886struct ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003887 /* Flags to enable now */
3888 uint8_t now_flags;
3889
3890 /* Flags to leave enabled in S3 */
3891 uint8_t suspend_flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003892} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003893
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003894/*****************************************************************************/
3895/* GPIO commands. Only available on EC if write protect has been disabled. */
3896
3897/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003898#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003899
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003900struct ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003901 char name[32];
3902 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003903} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003904
3905/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003906#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003907
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003908/* Version 0 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003909struct ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003910 char name[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003911} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003912
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003913struct ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003914 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003915} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003916
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003917/* Version 1 of input params and response */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003918struct ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003919 uint8_t subcmd;
3920 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003921 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003922 char name[32];
3923 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003924 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003925 uint8_t index;
3926 } get_info;
3927 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003928} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003929
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003930struct ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003931 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003932 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003933 uint8_t val;
3934 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003935 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003936 uint8_t val;
3937 char name[32];
3938 uint32_t flags;
3939 } get_info;
3940 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003941} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003942
3943enum gpio_get_subcmd {
3944 EC_GPIO_GET_BY_NAME = 0,
3945 EC_GPIO_GET_COUNT = 1,
3946 EC_GPIO_GET_INFO = 2,
3947};
3948
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003949/*****************************************************************************/
3950/* I2C commands. Only available when flash write protect is unlocked. */
3951
Duncan Laurie93e24442014-01-06 12:30:52 -08003952/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003953 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3954 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3955 *
3956 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08003957 */
3958
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003959/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003960#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003961
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003962struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07003963 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003964 uint8_t read_size; /* Either 8 or 16. */
3965 uint8_t port;
3966 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003967} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003968
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003969struct ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003970 uint16_t data;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003971} __ec_align2;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003972
3973/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003974#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003975
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003976struct ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003977 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07003978 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003979 uint8_t write_size; /* Either 8 or 16. */
3980 uint8_t port;
3981 uint8_t offset;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003982} __ec_align_size1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003983
3984/*****************************************************************************/
3985/* Charge state commands. Only available when flash write protect unlocked. */
3986
Duncan Laurie93e24442014-01-06 12:30:52 -08003987/* Force charge state machine to stop charging the battery or force it to
3988 * discharge the battery.
3989 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003990#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08003991#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003992
Duncan Laurie93e24442014-01-06 12:30:52 -08003993enum ec_charge_control_mode {
3994 CHARGE_CONTROL_NORMAL = 0,
3995 CHARGE_CONTROL_IDLE,
3996 CHARGE_CONTROL_DISCHARGE,
3997};
3998
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08003999struct ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08004000 uint32_t mode; /* enum charge_control_mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004001} __ec_align4;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004002
4003/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004004
4005/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004006#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004007
4008/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004009 * Read data from the saved snapshot. If the subcmd parameter is
4010 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
4011 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
4012 * end of the previous snapshot.
4013 *
4014 * The params are only looked at in version >= 1 of this command. Prior
4015 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004016 *
4017 * Response is null-terminated string. Empty string, if there is no more
4018 * remaining output.
4019 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004020#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004021
Duncan Laurieeb316852015-12-01 18:51:18 -08004022enum ec_console_read_subcmd {
4023 CONSOLE_READ_NEXT = 0,
4024 CONSOLE_READ_RECENT
4025};
4026
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004027struct ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004028 uint8_t subcmd; /* enum ec_console_read_subcmd */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004029} __ec_align1;
Duncan Laurieeb316852015-12-01 18:51:18 -08004030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004031/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07004032
4033/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004034 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07004035 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004036 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
4037 * EC_RES_SUCCESS if the command was successful.
4038 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07004039 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004040#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07004041
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004042#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN BIT(0)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004043
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004044struct ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004045 uint8_t flags;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004046} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004047
Duncan Laurie433432b2013-06-03 10:38:22 -07004048/*****************************************************************************/
4049/* USB port mux control. */
4050
4051/*
4052 * Switch USB mux or return to automatic switching.
4053 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004054#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07004055
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004056struct ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07004057 uint8_t mux;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004058} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004059
4060/*****************************************************************************/
4061/* LDOs / FETs control. */
4062
4063enum ec_ldo_state {
4064 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
4065 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
4066};
4067
4068/*
4069 * Switch on/off a LDO.
4070 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004071#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07004072
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004073struct ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07004074 uint8_t index;
4075 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004076} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004077
4078/*
4079 * Get LDO state.
4080 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004081#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07004082
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004083struct ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004084 uint8_t index;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004085} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004086
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004087struct ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07004088 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004089} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004090
4091/*****************************************************************************/
4092/* Power info. */
4093
4094/*
4095 * Get power info.
4096 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004097#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07004098
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004099struct ec_response_power_info {
Duncan Laurie433432b2013-06-03 10:38:22 -07004100 uint32_t usb_dev_type;
4101 uint16_t voltage_ac;
4102 uint16_t voltage_system;
4103 uint16_t current_system;
4104 uint16_t usb_current_limit;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004105} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004106
4107/*****************************************************************************/
4108/* I2C passthru command */
4109
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004110#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07004111
Duncan Laurie433432b2013-06-03 10:38:22 -07004112/* Read data; if not present, message is a write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004113#define EC_I2C_FLAG_READ BIT(15)
Duncan Laurie433432b2013-06-03 10:38:22 -07004114
4115/* Mask for address */
4116#define EC_I2C_ADDR_MASK 0x3ff
4117
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004118#define EC_I2C_STATUS_NAK BIT(0) /* Transfer was not acknowledged */
4119#define EC_I2C_STATUS_TIMEOUT BIT(1) /* Timeout during transfer */
Duncan Laurie433432b2013-06-03 10:38:22 -07004120
4121/* Any error */
4122#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
4123
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004124struct ec_params_i2c_passthru_msg {
4125 uint16_t addr_flags; /* I2C slave address and flags */
Duncan Laurie433432b2013-06-03 10:38:22 -07004126 uint16_t len; /* Number of bytes to read or write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004127} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004128
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004129struct ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004130 uint8_t port; /* I2C port number */
4131 uint8_t num_msgs; /* Number of messages */
4132 struct ec_params_i2c_passthru_msg msg[];
4133 /* Data to write for all messages is concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004134} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004135
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004136struct ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07004137 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
4138 uint8_t num_msgs; /* Number of messages processed */
4139 uint8_t data[]; /* Data read by messages concatenated here */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004140} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004141
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004142/*****************************************************************************/
4143/* Power button hang detect */
4144
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004145#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004146
4147/* Reasons to start hang detection timer */
4148/* Power button pressed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004149#define EC_HANG_START_ON_POWER_PRESS BIT(0)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004150
4151/* Lid closed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004152#define EC_HANG_START_ON_LID_CLOSE BIT(1)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004153
4154 /* Lid opened */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004155#define EC_HANG_START_ON_LID_OPEN BIT(2)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004156
4157/* Start of AP S3->S0 transition (booting or resuming from suspend) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004158#define EC_HANG_START_ON_RESUME BIT(3)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004159
4160/* Reasons to cancel hang detection */
4161
4162/* Power button released */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004163#define EC_HANG_STOP_ON_POWER_RELEASE BIT(8)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004164
4165/* Any host command from AP received */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004166#define EC_HANG_STOP_ON_HOST_COMMAND BIT(9)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004167
4168/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004169#define EC_HANG_STOP_ON_SUSPEND BIT(10)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004170
4171/*
4172 * If this flag is set, all the other fields are ignored, and the hang detect
4173 * timer is started. This provides the AP a way to start the hang timer
4174 * without reconfiguring any of the other hang detect settings. Note that
4175 * you must previously have configured the timeouts.
4176 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004177#define EC_HANG_START_NOW BIT(30)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004178
4179/*
4180 * If this flag is set, all the other fields are ignored (including
4181 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
4182 * without reconfiguring any of the other hang detect settings.
4183 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004184#define EC_HANG_STOP_NOW BIT(31)
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004185
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004186struct ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08004187 /* Flags; see EC_HANG_* */
4188 uint32_t flags;
4189
4190 /* Timeout in msec before generating host event, if enabled */
4191 uint16_t host_event_timeout_msec;
4192
4193 /* Timeout in msec before generating warm reboot, if enabled */
4194 uint16_t warm_reboot_timeout_msec;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004195} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004196
4197/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004198/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07004199
4200/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004201 * This is the single catch-all host command to exchange data regarding the
4202 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07004203 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004204#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004205
4206/* Subcommands for this host command */
4207enum charge_state_command {
4208 CHARGE_STATE_CMD_GET_STATE,
4209 CHARGE_STATE_CMD_GET_PARAM,
4210 CHARGE_STATE_CMD_SET_PARAM,
4211 CHARGE_STATE_NUM_CMDS
4212};
4213
4214/*
4215 * Known param numbers are defined here. Ranges are reserved for board-specific
4216 * params, which are handled by the particular implementations.
4217 */
4218enum charge_state_params {
4219 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
4220 CS_PARAM_CHG_CURRENT, /* charger current limit */
4221 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
4222 CS_PARAM_CHG_STATUS, /* charger-specific status */
4223 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08004224 CS_PARAM_LIMIT_POWER, /*
4225 * Check if power is limited due to
4226 * low battery and / or a weak external
4227 * charger. READ ONLY.
4228 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004229 /* How many so far? */
4230 CS_NUM_BASE_PARAMS,
4231
4232 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
4233 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
4234 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
4235
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004236 /* Range for CONFIG_CHARGE_STATE_DEBUG params */
4237 CS_PARAM_DEBUG_MIN = 0x20000,
4238 CS_PARAM_DEBUG_CTL_MODE = 0x20000,
4239 CS_PARAM_DEBUG_MANUAL_MODE,
4240 CS_PARAM_DEBUG_SEEMS_DEAD,
4241 CS_PARAM_DEBUG_SEEMS_DISCONNECTED,
4242 CS_PARAM_DEBUG_BATT_REMOVED,
4243 CS_PARAM_DEBUG_MANUAL_CURRENT,
4244 CS_PARAM_DEBUG_MANUAL_VOLTAGE,
4245 CS_PARAM_DEBUG_MAX = 0x2ffff,
4246
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004247 /* Other custom param ranges go here... */
4248};
4249
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004250struct ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004251 uint8_t cmd; /* enum charge_state_command */
4252 union {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004253 /* get_state has no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004254
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004255 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004256 uint32_t param; /* enum charge_state_param */
4257 } get_param;
4258
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004259 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004260 uint32_t param; /* param to set */
4261 uint32_t value; /* value to set */
4262 } set_param;
4263 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004264} __ec_todo_packed;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004265
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004266struct ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004267 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004268 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004269 int ac;
4270 int chg_voltage;
4271 int chg_current;
4272 int chg_input_current;
4273 int batt_state_of_charge;
4274 } get_state;
4275
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004276 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004277 uint32_t value;
4278 } get_param;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004279
4280 /* set_param returns no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004281 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004282} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004283
Duncan Laurie433432b2013-06-03 10:38:22 -07004284
4285/*
4286 * Set maximum battery charging current.
4287 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004288#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07004289
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004290struct ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07004291 uint32_t limit; /* in mA */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004292} __ec_align4;
Duncan Laurie433432b2013-06-03 10:38:22 -07004293
4294/*
Duncan Laurieeb316852015-12-01 18:51:18 -08004295 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07004296 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004297#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07004298
Duncan Laurieeb316852015-12-01 18:51:18 -08004299/* Command v0 is used only on Spring and is obsolete + unsupported */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004300struct ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08004301 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
4302 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004303} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004304
Duncan Laurieeb316852015-12-01 18:51:18 -08004305#define EC_POWER_LIMIT_NONE 0xffff
4306
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004307/*
4308 * Set maximum voltage & current of a dedicated charge port
4309 */
4310#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
4311
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004312struct ec_params_dedicated_charger_limit {
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004313 uint16_t current_lim; /* in mA */
4314 uint16_t voltage_lim; /* in mV */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004315} __ec_align2;
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08004316
Duncan Laurieeb316852015-12-01 18:51:18 -08004317/*****************************************************************************/
4318/* Hibernate/Deep Sleep Commands */
4319
4320/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004321#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08004322
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004323struct ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004324 /*
4325 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
4326 * current settings without changing them.
4327 */
4328 uint32_t seconds;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004329} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004330
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004331struct ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08004332 /*
4333 * The current time in seconds in which the system has been in the G3
4334 * state. This value is reset if the EC transitions out of G3.
4335 */
4336 uint32_t time_g3;
4337
4338 /*
4339 * The current time remaining in seconds until the EC should hibernate.
4340 * This value is also reset if the EC transitions out of G3.
4341 */
4342 uint32_t time_remaining;
4343
4344 /*
4345 * The current time in seconds that the EC should wait in G3 before
4346 * hibernating.
4347 */
4348 uint32_t hibernate_delay;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004349} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004350
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004351/* Inform the EC when entering a sleep state */
4352#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
4353
4354enum host_sleep_event {
4355 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
4356 HOST_SLEEP_EVENT_S3_RESUME = 2,
4357 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004358 HOST_SLEEP_EVENT_S0IX_RESUME = 4,
4359 /* S3 suspend with additional enabled wake sources */
4360 HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004361};
4362
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004363struct ec_params_host_sleep_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004364 uint8_t sleep_event;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004365} __ec_align1;
4366
4367/*
4368 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
4369 * transition failures
4370 */
4371#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
4372
4373/* Disable timeout detection for this sleep transition */
4374#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
4375
4376struct ec_params_host_sleep_event_v1 {
4377 /* The type of sleep being entered or exited. */
4378 uint8_t sleep_event;
4379
4380 /* Padding */
4381 uint8_t reserved;
4382 union {
4383 /* Parameters that apply for suspend messages. */
4384 struct {
4385 /*
4386 * The timeout in milliseconds between when this message
4387 * is received and when the EC will declare sleep
4388 * transition failure if the sleep signal is not
4389 * asserted.
4390 */
4391 uint16_t sleep_timeout_ms;
4392 } suspend_params;
4393
4394 /* No parameters for non-suspend messages. */
4395 };
4396} __ec_align2;
4397
4398/* A timeout occurred when this bit is set */
4399#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
4400
4401/*
4402 * The mask defining which bits correspond to the number of sleep transitions,
4403 * as well as the maximum number of suspend line transitions that will be
4404 * reported back to the host.
4405 */
4406#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
4407
4408struct ec_response_host_sleep_event_v1 {
4409 union {
4410 /* Response fields that apply for resume messages. */
4411 struct {
4412 /*
4413 * The number of sleep power signal transitions that
4414 * occurred since the suspend message. The high bit
4415 * indicates a timeout occurred.
4416 */
4417 uint32_t sleep_transitions;
4418 } resume_response;
4419
4420 /* No response fields for non-resume messages. */
4421 };
4422} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004423
4424/*****************************************************************************/
4425/* Device events */
4426#define EC_CMD_DEVICE_EVENT 0x00AA
4427
4428enum ec_device_event {
4429 EC_DEVICE_EVENT_TRACKPAD,
4430 EC_DEVICE_EVENT_DSP,
4431 EC_DEVICE_EVENT_WIFI,
4432};
4433
4434enum ec_device_event_param {
4435 /* Get and clear pending device events */
4436 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
4437 /* Get device event mask */
4438 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
4439 /* Set device event mask */
4440 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
4441};
4442
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004443#define EC_DEVICE_EVENT_MASK(event_code) BIT(event_code % 32)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004444
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004445struct ec_params_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004446 uint32_t event_mask;
4447 uint8_t param;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004448} __ec_align_size1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004449
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004450struct ec_response_device_event {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004451 uint32_t event_mask;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004452} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08004453
Duncan Laurie433432b2013-06-03 10:38:22 -07004454/*****************************************************************************/
4455/* Smart battery pass-through */
4456
4457/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004458#define EC_CMD_SB_READ_WORD 0x00B0
4459#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07004460
4461/* Get / Set string smart battery parameters
4462 * formatted as SMBUS "block".
4463 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004464#define EC_CMD_SB_READ_BLOCK 0x00B2
4465#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07004466
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004467struct ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07004468 uint8_t reg;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004469} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004470
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004471struct ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004472 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004473} __ec_align2;
Duncan Laurie433432b2013-06-03 10:38:22 -07004474
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004475struct ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07004476 uint8_t reg;
4477 uint16_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004478} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004479
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004480struct ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004481 uint8_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004482} __ec_align1;
Duncan Laurie433432b2013-06-03 10:38:22 -07004483
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004484struct ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07004485 uint8_t reg;
4486 uint16_t data[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004487} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004488
4489/*****************************************************************************/
4490/* Battery vendor parameters
4491 *
4492 * Get or set vendor-specific parameters in the battery. Implementations may
4493 * differ between boards or batteries. On a set operation, the response
4494 * contains the actual value set, which may be rounded or clipped from the
4495 * requested value.
4496 */
4497
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004498#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004499
4500enum ec_battery_vendor_param_mode {
4501 BATTERY_VENDOR_PARAM_MODE_GET = 0,
4502 BATTERY_VENDOR_PARAM_MODE_SET,
4503};
4504
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004505struct ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004506 uint32_t param;
4507 uint32_t value;
4508 uint8_t mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004509} __ec_align_size1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004510
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004511struct ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004512 uint32_t value;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004513} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004514
4515/*****************************************************************************/
4516/*
4517 * Smart Battery Firmware Update Commands
4518 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004519#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004520
4521enum ec_sb_fw_update_subcmd {
4522 EC_SB_FW_UPDATE_PREPARE = 0x0,
4523 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
4524 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
4525 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
4526 EC_SB_FW_UPDATE_END = 0x4,
4527 EC_SB_FW_UPDATE_STATUS = 0x5,
4528 EC_SB_FW_UPDATE_PROTECT = 0x6,
4529 EC_SB_FW_UPDATE_MAX = 0x7,
4530};
4531
4532#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
4533#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
4534#define SB_FW_UPDATE_CMD_INFO_SIZE 8
4535
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004536struct ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004537 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
4538 uint16_t fw_id; /* firmware id */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004539} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004540
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004541struct ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004542 struct ec_sb_fw_update_header hdr;
4543 union {
4544 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
4545 /* EC_SB_FW_UPDATE_INFO = 0x1 */
4546 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
4547 /* EC_SB_FW_UPDATE_END = 0x4 */
4548 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
4549 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004550 /* Those have no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004551
4552 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004553 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004554 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
4555 } write;
4556 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004557} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004558
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004559struct ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004560 union {
4561 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004562 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004563 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
4564 } info;
4565
4566 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004567 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004568 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
4569 } status;
4570 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004571} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004572
4573/*
4574 * Entering Verified Boot Mode Command
4575 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
4576 * Valid Modes are: normal, developer, and recovery.
4577 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004578#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004579
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004580struct ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004581 int vboot_mode;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004582} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004583
4584#define VBOOT_MODE_NORMAL 0
4585#define VBOOT_MODE_DEVELOPER 1
4586#define VBOOT_MODE_RECOVERY 2
4587
Duncan Laurie433432b2013-06-03 10:38:22 -07004588/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07004589/*
4590 * I2C passthru protection command: Protects I2C tunnels against access on
4591 * certain addresses (board-specific).
4592 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004593#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07004594
4595enum ec_i2c_passthru_protect_subcmd {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004596 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0,
4597 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 1,
4598 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS = 2,
Gwendal Grignou880b4582016-06-20 08:49:25 -07004599};
4600
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004601struct ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004602 uint8_t subcmd;
4603 uint8_t port; /* I2C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004604} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004605
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004606struct ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004607 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004608} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07004609
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004610
4611/*****************************************************************************/
4612/*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004613 * HDMI CEC commands
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004614 *
4615 * These commands are for sending and receiving message via HDMI CEC
4616 */
4617
4618#define MAX_CEC_MSG_LEN 16
4619
4620/* CEC message from the AP to be written on the CEC bus */
4621#define EC_CMD_CEC_WRITE_MSG 0x00B8
4622
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004623/**
4624 * struct ec_params_cec_write - Message to write to the CEC bus
4625 * @msg: message content to write to the CEC bus
4626 */
4627struct ec_params_cec_write {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004628 uint8_t msg[MAX_CEC_MSG_LEN];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004629} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004630
4631/* Set various CEC parameters */
4632#define EC_CMD_CEC_SET 0x00BA
4633
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004634/**
4635 * struct ec_params_cec_set - CEC parameters set
4636 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4637 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
4638 * or 1 to enable CEC functionality, in case cmd is
4639 * CEC_CMD_LOGICAL_ADDRESS, this field encodes the requested logical
4640 * address between 0 and 15 or 0xff to unregister
4641 */
4642struct ec_params_cec_set {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004643 uint8_t cmd; /* enum cec_command */
4644 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004645} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004646
4647/* Read various CEC parameters */
4648#define EC_CMD_CEC_GET 0x00BB
4649
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004650/**
4651 * struct ec_params_cec_get - CEC parameters get
4652 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
4653 */
4654struct ec_params_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004655 uint8_t cmd; /* enum cec_command */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004656} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004657
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004658/**
4659 * struct ec_response_cec_get - CEC parameters get response
4660 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
4661 * disabled or 1 if CEC functionality is enabled,
4662 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
4663 * configured logical address between 0 and 15 or 0xff if unregistered
4664 */
4665struct ec_response_cec_get {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004666 uint8_t val;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004667} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004668
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004669/* CEC parameters command */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004670enum cec_command {
4671 /* CEC reading, writing and events enable */
4672 CEC_CMD_ENABLE,
4673 /* CEC logical address */
4674 CEC_CMD_LOGICAL_ADDRESS,
4675};
4676
4677/* Events from CEC to AP */
4678enum mkbp_cec_event {
4679 /* Outgoing message was acknowledged by a follower */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004680 EC_MKBP_CEC_SEND_OK = BIT(0),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004681 /* Outgoing message was not acknowledged */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004682 EC_MKBP_CEC_SEND_FAILED = BIT(1),
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004683};
4684
Gwendal Grignou880b4582016-06-20 08:49:25 -07004685/*****************************************************************************/
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004686
4687/* Commands for I2S recording on audio codec. */
4688
4689#define EC_CMD_CODEC_I2S 0x00BC
4690#define EC_WOV_I2S_SAMPLE_RATE 48000
4691
4692enum ec_codec_i2s_subcmd {
4693 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
4694 EC_CODEC_SET_GAIN = 0x1,
4695 EC_CODEC_GET_GAIN = 0x2,
4696 EC_CODEC_I2S_ENABLE = 0x3,
4697 EC_CODEC_I2S_SET_CONFIG = 0x4,
4698 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
4699 EC_CODEC_I2S_SET_BCLK = 0x6,
4700 EC_CODEC_I2S_SUBCMD_COUNT = 0x7,
4701};
4702
4703enum ec_sample_depth_value {
4704 EC_CODEC_SAMPLE_DEPTH_16 = 0,
4705 EC_CODEC_SAMPLE_DEPTH_24 = 1,
4706};
4707
4708enum ec_i2s_config {
4709 EC_DAI_FMT_I2S = 0,
4710 EC_DAI_FMT_RIGHT_J = 1,
4711 EC_DAI_FMT_LEFT_J = 2,
4712 EC_DAI_FMT_PCM_A = 3,
4713 EC_DAI_FMT_PCM_B = 4,
4714 EC_DAI_FMT_PCM_TDM = 5,
4715};
4716
4717/*
4718 * For subcommand EC_CODEC_GET_GAIN.
4719 */
4720struct __ec_align1 ec_codec_i2s_gain {
4721 uint8_t left;
4722 uint8_t right;
4723};
4724
4725struct __ec_todo_unpacked ec_param_codec_i2s_tdm {
4726 int16_t ch0_delay; /* 0 to 496 */
4727 int16_t ch1_delay; /* -1 to 496 */
4728 uint8_t adjacent_to_ch0;
4729 uint8_t adjacent_to_ch1;
4730};
4731
4732struct __ec_todo_packed ec_param_codec_i2s {
4733 /* enum ec_codec_i2s_subcmd */
4734 uint8_t cmd;
4735 union {
4736 /*
4737 * EC_CODEC_SET_SAMPLE_DEPTH
4738 * Value should be one of ec_sample_depth_value.
4739 */
4740 uint8_t depth;
4741
4742 /*
4743 * EC_CODEC_SET_GAIN
4744 * Value should be 0~43 for both channels.
4745 */
4746 struct ec_codec_i2s_gain gain;
4747
4748 /*
4749 * EC_CODEC_I2S_ENABLE
4750 * 1 to enable, 0 to disable.
4751 */
4752 uint8_t i2s_enable;
4753
4754 /*
4755 * EC_CODEC_I2S_SET_CONFIG
4756 * Value should be one of ec_i2s_config.
4757 */
4758 uint8_t i2s_config;
4759
4760 /*
4761 * EC_CODEC_I2S_SET_TDM_CONFIG
4762 * Value should be one of ec_i2s_config.
4763 */
4764 struct ec_param_codec_i2s_tdm tdm_param;
4765
4766 /*
4767 * EC_CODEC_I2S_SET_BCLK
4768 */
4769 uint32_t bclk;
4770 };
4771};
4772
4773
4774/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004775/* System commands */
4776
4777/*
Duncan Laurie93e24442014-01-06 12:30:52 -08004778 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
4779 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004780 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004781#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004782
4783/* Command */
4784enum ec_reboot_cmd {
4785 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07004786 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004787 EC_REBOOT_JUMP_RW = 2, /* Jump to active RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004788 /* (command 3 was jump to RW-B) */
4789 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07004790 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08004791 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
4792 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004793};
4794
4795/* Flags for ec_params_reboot_ec.reboot_flags */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004796#define EC_REBOOT_FLAG_RESERVED0 BIT(0) /* Was recovery request */
4797#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN BIT(1) /* Reboot after AP shutdown */
4798#define EC_REBOOT_FLAG_SWITCH_RW_SLOT BIT(2) /* Switch RW slot */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004799
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004800struct ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004801 uint8_t cmd; /* enum ec_reboot_cmd */
4802 uint8_t flags; /* See EC_REBOOT_FLAG_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004803} __ec_align1;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004804
Duncan Laurie433432b2013-06-03 10:38:22 -07004805/*
4806 * Get information on last EC panic.
4807 *
4808 * Returns variable-length platform-dependent panic information. See panic.h
4809 * for details.
4810 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004811#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07004812
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004813/*****************************************************************************/
4814/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004815 * Special commands
4816 *
4817 * These do not follow the normal rules for commands. See each command for
4818 * details.
4819 */
4820
4821/*
4822 * Reboot NOW
4823 *
4824 * This command will work even when the EC LPC interface is busy, because the
4825 * reboot command is processed at interrupt level. Note that when the EC
4826 * reboots, the host will reboot too, so there is no response to this command.
4827 *
4828 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
4829 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004830#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004831
4832/*
Duncan Laurie433432b2013-06-03 10:38:22 -07004833 * Resend last response (not supported on LPC).
4834 *
4835 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
4836 * there was no previous command, or the previous command's response was too
4837 * big to save.
4838 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004839#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07004840
4841/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004842 * This header byte on a command indicate version 0. Any header byte less
4843 * than this means that we are talking to an old EC which doesn't support
4844 * versioning. In that case, we assume version 0.
4845 *
4846 * Header bytes greater than this indicate a later version. For example,
4847 * EC_CMD_VERSION0 + 1 means we are using version 1.
4848 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004849 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004850 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004851#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004852
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004853/*****************************************************************************/
4854/*
4855 * PD commands
4856 *
4857 * These commands are for PD MCU communication.
4858 */
4859
4860/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004861#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08004862#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004863
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004864enum pd_charge_state {
4865 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
4866 PD_CHARGE_NONE, /* No charging allowed */
4867 PD_CHARGE_5V, /* 5V charging only */
4868 PD_CHARGE_MAX /* Charge at max voltage */
4869};
4870
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004871/* Status of EC being sent to PD */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004872#define EC_STATUS_HIBERNATING BIT(0)
Duncan Laurieeb316852015-12-01 18:51:18 -08004873
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004874struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08004875 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004876 int8_t batt_soc; /* battery state of charge */
4877 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004878} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004879
4880/* Status of PD being sent back to EC */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004881#define PD_STATUS_HOST_EVENT BIT(0) /* Forward host event to AP */
4882#define PD_STATUS_IN_RW BIT(1) /* Running RW image */
4883#define PD_STATUS_JUMPED_TO_IMAGE BIT(2) /* Current image was jumped to */
4884#define PD_STATUS_TCPC_ALERT_0 BIT(3) /* Alert active in port 0 TCPC */
4885#define PD_STATUS_TCPC_ALERT_1 BIT(4) /* Alert active in port 1 TCPC */
4886#define PD_STATUS_TCPC_ALERT_2 BIT(5) /* Alert active in port 2 TCPC */
4887#define PD_STATUS_TCPC_ALERT_3 BIT(6) /* Alert active in port 3 TCPC */
Duncan Laurieeb316852015-12-01 18:51:18 -08004888#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
4889 PD_STATUS_TCPC_ALERT_1 | \
4890 PD_STATUS_HOST_EVENT)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004891struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08004892 uint32_t curr_lim_ma; /* input current limit */
4893 uint16_t status; /* PD MCU status */
4894 int8_t active_charge_port; /* active charging port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004895} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004896
4897/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004898#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004899
4900/* PD MCU host event status bits */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004901#define PD_EVENT_UPDATE_DEVICE BIT(0)
4902#define PD_EVENT_POWER_CHANGE BIT(1)
4903#define PD_EVENT_IDENTITY_RECEIVED BIT(2)
4904#define PD_EVENT_DATA_SWAP BIT(3)
4905struct ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004906 uint32_t status; /* PD MCU host event status */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004907} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004908
4909/* Set USB type-C port role and muxes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004910#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004911
4912enum usb_pd_control_role {
4913 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
4914 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
4915 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
4916 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
4917 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06004918 USB_PD_CTRL_ROLE_FREEZE = 5,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004919 USB_PD_CTRL_ROLE_COUNT
4920};
4921
4922enum usb_pd_control_mux {
4923 USB_PD_CTRL_MUX_NO_CHANGE = 0,
4924 USB_PD_CTRL_MUX_NONE = 1,
4925 USB_PD_CTRL_MUX_USB = 2,
4926 USB_PD_CTRL_MUX_DP = 3,
4927 USB_PD_CTRL_MUX_DOCK = 4,
4928 USB_PD_CTRL_MUX_AUTO = 5,
4929 USB_PD_CTRL_MUX_COUNT
4930};
4931
Duncan Laurieeb316852015-12-01 18:51:18 -08004932enum usb_pd_control_swap {
4933 USB_PD_CTRL_SWAP_NONE = 0,
4934 USB_PD_CTRL_SWAP_DATA = 1,
4935 USB_PD_CTRL_SWAP_POWER = 2,
4936 USB_PD_CTRL_SWAP_VCONN = 3,
4937 USB_PD_CTRL_SWAP_COUNT
4938};
4939
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004940struct ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004941 uint8_t port;
4942 uint8_t role;
4943 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08004944 uint8_t swap;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004945} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004946
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004947#define PD_CTRL_RESP_ENABLED_COMMS BIT(0) /* Communication enabled */
4948#define PD_CTRL_RESP_ENABLED_CONNECTED BIT(1) /* Device connected */
4949#define PD_CTRL_RESP_ENABLED_PD_CAPABLE BIT(2) /* Partner is PD capable */
Duncan Laurieeb316852015-12-01 18:51:18 -08004950
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004951#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
4952#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
4953#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
4954#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
4955#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
4956#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
4957#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
Duncan Laurieeb316852015-12-01 18:51:18 -08004958
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004959struct ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004960 uint8_t enabled;
4961 uint8_t role;
4962 uint8_t polarity;
4963 uint8_t state;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004964} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004965
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004966struct ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004967 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08004968 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004969 uint8_t polarity;
4970 char state[32];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08004971} __ec_align1;
4972
4973/* Values representing usbc PD CC state */
4974#define USBC_PD_CC_NONE 0 /* No accessory connected */
4975#define USBC_PD_CC_NO_UFP 1 /* No UFP accessory connected */
4976#define USBC_PD_CC_AUDIO_ACC 2 /* Audio accessory connected */
4977#define USBC_PD_CC_DEBUG_ACC 3 /* Debug accessory connected */
4978#define USBC_PD_CC_UFP_ATTACHED 4 /* UFP attached to usbc */
4979#define USBC_PD_CC_DFP_ATTACHED 5 /* DPF attached to usbc */
4980
4981#define USBC_CABLE_TYPE_UNDEF 0 /* Undefined */
4982#define USBC_CABLE_TYPE_PASSIVE 3 /* Passive cable attached */
4983#define USBC_CABLE_TYPE_ACTIVE 4 /* Active cable attached */
4984
4985struct ec_response_usb_pd_control_v2 {
4986 uint8_t enabled;
4987 uint8_t role;
4988 uint8_t polarity;
4989 char state[32];
4990 uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
4991 uint8_t dp_mode; /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
4992 uint8_t cable_type; /* USBC_CABLE_TYPE_*cable_type */
4993} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004994
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004995#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004996
Patrick Georgi0f6187a2017-07-28 15:57:23 +02004997/* Maximum number of PD ports on a device, num_ports will be <= this */
4998#define EC_USB_PD_MAX_PORTS 8
4999
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005000struct ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005001 uint8_t num_ports;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005002} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005003
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005004#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005005
5006#define PD_POWER_CHARGING_PORT 0xff
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005007struct ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005008 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005009} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005010
5011enum usb_chg_type {
5012 USB_CHG_TYPE_NONE,
5013 USB_CHG_TYPE_PD,
5014 USB_CHG_TYPE_C,
5015 USB_CHG_TYPE_PROPRIETARY,
5016 USB_CHG_TYPE_BC12_DCP,
5017 USB_CHG_TYPE_BC12_CDP,
5018 USB_CHG_TYPE_BC12_SDP,
5019 USB_CHG_TYPE_OTHER,
5020 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08005021 USB_CHG_TYPE_UNKNOWN,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005022 USB_CHG_TYPE_DEDICATED,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005023};
5024enum usb_power_roles {
5025 USB_PD_PORT_POWER_DISCONNECTED,
5026 USB_PD_PORT_POWER_SOURCE,
5027 USB_PD_PORT_POWER_SINK,
5028 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
5029};
5030
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005031struct usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005032 uint16_t voltage_max;
5033 uint16_t voltage_now;
5034 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08005035 uint16_t current_lim;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005036} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005037
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005038struct ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005039 uint8_t role;
5040 uint8_t type;
5041 uint8_t dualrole;
5042 uint8_t reserved1;
5043 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005044 uint32_t max_power;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005045} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005046
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005047
5048/*
5049 * This command will return the number of USB PD charge port + the number
5050 * of dedicated port present.
5051 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
5052 */
5053#define EC_CMD_CHARGE_PORT_COUNT 0x0105
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005054struct ec_response_charge_port_count {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005055 uint8_t port_count;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005056} __ec_align1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005057
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005058/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005059#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005060
5061enum usb_pd_fw_update_cmds {
5062 USB_PD_FW_REBOOT,
5063 USB_PD_FW_FLASH_ERASE,
5064 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005065 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005066};
5067
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005068struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005069 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005070 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005071 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005072 uint32_t size; /* Size to write in bytes */
5073 /* Followed by data to write */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005074} __ec_align4;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005075
5076/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005077#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005078/* RW hash is first 20 bytes of SHA-256 of RW section */
5079#define PD_RW_HASH_SIZE 20
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005080struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005081 uint16_t dev_id;
5082 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005083 uint8_t reserved; /*
5084 * For alignment of current_image
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005085 * TODO(rspangler) but it's not aligned!
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005086 * Should have been reserved[2].
5087 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005088 uint32_t current_image; /* One of ec_current_image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005089} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005090
5091/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005092#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005093
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005094struct ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005095 uint8_t port;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005096} __ec_align1;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005097
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005098/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005099#define EC_CMD_USB_PD_DISCOVERY 0x0113
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005100struct ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005101 uint16_t vid; /* USB-IF VID */
5102 uint16_t pid; /* USB-IF PID */
5103 uint8_t ptype; /* product type (hub,periph,cable,ama) */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005104} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005105
5106/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005107#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005108
5109/* Negative port parameters have special meaning */
5110enum usb_pd_override_ports {
5111 OVERRIDE_DONT_CHARGE = -2,
5112 OVERRIDE_OFF = -1,
Duncan Laurieeb316852015-12-01 18:51:18 -08005113 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005114};
5115
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005116struct ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005117 int16_t override_port; /* Override port# */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005118} __ec_align2;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005119
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005120/*
5121 * Read (and delete) one entry of PD event log.
5122 * TODO(crbug.com/751742): Make this host command more generic to accommodate
5123 * future non-PD logs that use the same internal EC event_log.
5124 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005125#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005126
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005127struct ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005128 uint32_t timestamp; /* relative timestamp in milliseconds */
5129 uint8_t type; /* event type : see PD_EVENT_xx below */
5130 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
5131 uint16_t data; /* type-defined data payload */
5132 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005133} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005134
5135/* The timestamp is the microsecond counter shifted to get about a ms. */
5136#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
5137
Duncan Laurieeb316852015-12-01 18:51:18 -08005138#define PD_LOG_SIZE_MASK 0x1f
5139#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005140#define PD_LOG_PORT_SHIFT 5
5141#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
5142 ((size) & PD_LOG_SIZE_MASK))
5143#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
5144#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
5145
5146/* PD event log : entry types */
5147/* PD MCU events */
5148#define PD_EVENT_MCU_BASE 0x00
5149#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
5150#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
5151/* Reserved for custom board event */
5152#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
5153/* PD generic accessory events */
5154#define PD_EVENT_ACC_BASE 0x20
5155#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
5156#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
5157/* PD power supply events */
5158#define PD_EVENT_PS_BASE 0x40
5159#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
5160/* PD video dongles events */
5161#define PD_EVENT_VIDEO_BASE 0x60
5162#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
5163#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
5164/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08005165#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005166
5167/*
5168 * PD_EVENT_MCU_CHARGE event definition :
5169 * the payload is "struct usb_chg_measures"
5170 * the data field contains the port state flags as defined below :
5171 */
5172/* Port partner is a dual role device */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005173#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005174/* Port is the pending override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005175#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005176/* Port is the override port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005177#define CHARGE_FLAGS_OVERRIDE BIT(13)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005178/* Charger type */
5179#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08005180#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005181/* Power delivery role */
5182#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
5183
5184/*
5185 * PD_EVENT_PS_FAULT data field flags definition :
5186 */
5187#define PS_FAULT_OCP 1
5188#define PS_FAULT_FAST_OCP 2
5189#define PS_FAULT_OVP 3
5190#define PS_FAULT_DISCH 4
5191
5192/*
5193 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
5194 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005195struct mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005196 uint8_t major;
5197 uint8_t minor;
5198 uint16_t build;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005199} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005200
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005201struct mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005202 uint8_t family[2];
5203 uint8_t chipid[2];
5204 struct mcdp_version irom;
5205 struct mcdp_version fw;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005206} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005207
5208/* struct mcdp_info field decoding */
5209#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
5210#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
5211
5212/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005213#define EC_CMD_USB_PD_GET_AMODE 0x0116
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005214struct ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005215 uint16_t svid_idx; /* SVID index to get */
5216 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005217} __ec_align_size1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005218
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005219struct ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005220 uint16_t svid; /* SVID */
5221 uint16_t opos; /* Object Position */
5222 uint32_t vdo[6]; /* Mode VDOs */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005223} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005224
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005225#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005226
5227enum pd_mode_cmd {
5228 PD_EXIT_MODE = 0,
5229 PD_ENTER_MODE = 1,
5230 /* Not a command. Do NOT remove. */
5231 PD_MODE_CMD_COUNT,
5232};
5233
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005234struct ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005235 uint32_t cmd; /* enum pd_mode_cmd */
5236 uint16_t svid; /* SVID to set */
5237 uint8_t opos; /* Object Position */
5238 uint8_t port; /* port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005239} __ec_align4;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005240
5241/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005242#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005243
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005244struct ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005245 uint8_t type; /* event type : see PD_EVENT_xx above */
5246 uint8_t port; /* port#, or 0 for events unrelated to a given port */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005247} __ec_align1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07005248
Stefan Reinauerd6682e82013-02-21 15:39:35 -08005249
Gwendal Grignou880b4582016-06-20 08:49:25 -07005250/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005251#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07005252
5253enum ec_pd_control_cmd {
5254 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
5255 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
5256 PD_RESET, /* Force reset the PD chip */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005257 PD_CONTROL_DISABLE, /* Disable further calls to this command */
5258 PD_CHIP_ON, /* Power on the PD chip */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005259};
5260
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005261struct ec_params_pd_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005262 uint8_t chip; /* chip id */
Gwendal Grignou880b4582016-06-20 08:49:25 -07005263 uint8_t subcmd;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005264} __ec_align1;
Gwendal Grignou880b4582016-06-20 08:49:25 -07005265
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005266/* Get info about USB-C SS muxes */
5267#define EC_CMD_USB_PD_MUX_INFO 0x011A
5268
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005269struct ec_params_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005270 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005271} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005272
5273/* Flags representing mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005274#define USB_PD_MUX_USB_ENABLED BIT(0) /* USB connected */
5275#define USB_PD_MUX_DP_ENABLED BIT(1) /* DP connected */
5276#define USB_PD_MUX_POLARITY_INVERTED BIT(2) /* CC line Polarity inverted */
5277#define USB_PD_MUX_HPD_IRQ BIT(3) /* HPD IRQ is asserted */
5278#define USB_PD_MUX_HPD_LVL BIT(4) /* HPD level is asserted */
5279#define USB_PD_MUX_SAFE_MODE BIT(5) /* DP is in safe mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005280
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005281struct ec_response_usb_pd_mux_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005282 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005283} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005284
5285#define EC_CMD_PD_CHIP_INFO 0x011B
5286
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005287struct ec_params_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005288 uint8_t port; /* USB-C port number */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005289 /*
5290 * Fetch the live chip info or hard-coded + cached chip info
5291 * 0: hardcoded value for VID/PID, cached value for FW version
5292 * 1: live chip value for VID/PID/FW Version
5293 */
5294 uint8_t live;
5295} __ec_align1;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005296
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005297struct ec_response_pd_chip_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005298 uint16_t vendor_id;
5299 uint16_t product_id;
5300 uint16_t device_id;
5301 union {
5302 uint8_t fw_version_string[8];
5303 uint64_t fw_version_number;
5304 };
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005305} __ec_align2;
5306
5307struct ec_response_pd_chip_info_v1 {
5308 uint16_t vendor_id;
5309 uint16_t product_id;
5310 uint16_t device_id;
5311 union {
5312 uint8_t fw_version_string[8];
5313 uint64_t fw_version_number;
5314 };
5315 union {
5316 uint8_t min_req_fw_version_string[8];
5317 uint64_t min_req_fw_version_number;
5318 };
5319} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005320
5321/* Run RW signature verification and get status */
5322#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
5323
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005324struct ec_response_rwsig_check_status {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005325 uint32_t status;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005326} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005327
5328/* For controlling RWSIG task */
5329#define EC_CMD_RWSIG_ACTION 0x011D
5330
5331enum rwsig_action {
5332 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
5333 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
5334};
5335
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005336struct ec_params_rwsig_action {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005337 uint32_t action;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005338} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005339
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005340/* Run verification on a slot */
5341#define EC_CMD_EFS_VERIFY 0x011E
5342
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005343struct ec_params_efs_verify {
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005344 uint8_t region; /* enum ec_flash_region */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005345} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005346
5347/*
5348 * Retrieve info from Cros Board Info store. Response is based on the data
5349 * type. Integers return a uint32. Strings return a string, using the response
5350 * size to determine how big it is.
5351 */
5352#define EC_CMD_GET_CROS_BOARD_INFO 0x011F
5353/*
5354 * Write info into Cros Board Info on EEPROM. Write fails if the board has
5355 * hardware write-protect enabled.
5356 */
5357#define EC_CMD_SET_CROS_BOARD_INFO 0x0120
5358
Daisuke Nojirif984a052018-02-15 12:38:15 -08005359enum cbi_data_tag {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005360 CBI_TAG_BOARD_VERSION = 0, /* uint32_t or smaller */
5361 CBI_TAG_OEM_ID = 1, /* uint32_t or smaller */
5362 CBI_TAG_SKU_ID = 2, /* uint32_t or smaller */
Aaron Durbinb388c0e2018-08-07 12:24:21 -06005363 CBI_TAG_DRAM_PART_NUM = 3, /* variable length ascii, nul terminated. */
Wisley Chenc1efec72018-11-06 09:28:23 +08005364 CBI_TAG_OEM_NAME = 4, /* variable length ascii, nul terminated. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005365 CBI_TAG_MODEL_ID = 5, /* uint32_t or smaller */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005366 CBI_TAG_COUNT,
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005367};
5368
5369/*
5370 * Flags to control read operation
5371 *
5372 * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
5373 * write was successful without reboot.
5374 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005375#define CBI_GET_RELOAD BIT(0)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005376
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005377struct ec_params_get_cbi {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005378 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005379 uint32_t flag; /* CBI_GET_* */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005380} __ec_align4;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005381
5382/*
5383 * Flags to control write behavior.
5384 *
5385 * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
5386 * useful when writing multiple fields in a row.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005387 * INIT: Need to be set when creating a new CBI from scratch. All fields
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005388 * will be initialized to zero first.
5389 */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005390#define CBI_SET_NO_SYNC BIT(0)
5391#define CBI_SET_INIT BIT(1)
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005392
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005393struct ec_params_set_cbi {
Daisuke Nojirif984a052018-02-15 12:38:15 -08005394 uint32_t tag; /* enum cbi_data_tag */
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005395 uint32_t flag; /* CBI_SET_* */
Daisuke Nojirif984a052018-02-15 12:38:15 -08005396 uint32_t size; /* Data size */
5397 uint8_t data[]; /* For string and raw data */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005398} __ec_align1;
Daisuke Nojiri07f9748f2018-02-01 07:46:02 -08005399
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005400/*
5401 * Information about resets of the AP by the EC and the EC's own uptime.
5402 */
5403#define EC_CMD_GET_UPTIME_INFO 0x0121
5404
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005405/* Reset causes */
5406#define EC_RESET_FLAG_OTHER BIT(0) /* Other known reason */
5407#define EC_RESET_FLAG_RESET_PIN BIT(1) /* Reset pin asserted */
5408#define EC_RESET_FLAG_BROWNOUT BIT(2) /* Brownout */
5409#define EC_RESET_FLAG_POWER_ON BIT(3) /* Power-on reset */
5410#define EC_RESET_FLAG_WATCHDOG BIT(4) /* Watchdog timer reset */
5411#define EC_RESET_FLAG_SOFT BIT(5) /* Soft reset trigger by core */
5412#define EC_RESET_FLAG_HIBERNATE BIT(6) /* Wake from hibernate */
5413#define EC_RESET_FLAG_RTC_ALARM BIT(7) /* RTC alarm wake */
5414#define EC_RESET_FLAG_WAKE_PIN BIT(8) /* Wake pin triggered wake */
5415#define EC_RESET_FLAG_LOW_BATTERY BIT(9) /* Low battery triggered wake */
5416#define EC_RESET_FLAG_SYSJUMP BIT(10) /* Jumped directly to this image */
5417#define EC_RESET_FLAG_HARD BIT(11) /* Hard reset from software */
5418#define EC_RESET_FLAG_AP_OFF BIT(12) /* Do not power on AP */
5419#define EC_RESET_FLAG_PRESERVED BIT(13) /* Some reset flags preserved from
5420 * previous boot
5421 */
5422#define EC_RESET_FLAG_USB_RESUME BIT(14) /* USB resume triggered wake */
5423#define EC_RESET_FLAG_RDD BIT(15) /* USB Type-C debug cable */
5424#define EC_RESET_FLAG_RBOX BIT(16) /* Fixed Reset Functionality */
5425#define EC_RESET_FLAG_SECURITY BIT(17) /* Security threat */
5426#define EC_RESET_FLAG_AP_WATCHDOG BIT(18) /* AP experienced a watchdog reset */
5427
5428struct ec_response_uptime_info {
5429 /*
5430 * Number of milliseconds since the last EC boot. Sysjump resets
5431 * typically do not restart the EC's time_since_boot epoch.
5432 *
5433 * WARNING: The EC's sense of time is much less accurate than the AP's
5434 * sense of time, in both phase and frequency. This timebase is similar
5435 * to CLOCK_MONOTONIC_RAW, but with 1% or more frequency error.
5436 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005437 uint32_t time_since_ec_boot_ms;
5438
5439 /*
5440 * Number of times the AP was reset by the EC since the last EC boot.
5441 * Note that the AP may be held in reset by the EC during the initial
5442 * boot sequence, such that the very first AP boot may count as more
5443 * than one here.
5444 */
5445 uint32_t ap_resets_since_ec_boot;
5446
5447 /*
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005448 * The set of flags which describe the EC's most recent reset.
5449 * See EC_RESET_FLAG_* for details.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005450 */
5451 uint32_t ec_reset_flags;
5452
5453 /* Empty log entries have both the cause and timestamp set to zero. */
5454 struct ap_reset_log_entry {
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005455 /*
5456 * See include/chipset.h: enum chipset_{reset,shutdown}_reason
5457 * for details.
5458 */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005459 uint16_t reset_cause;
5460
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005461 /* Reserved for protocol growth. */
5462 uint16_t reserved;
5463
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005464 /*
5465 * The time of the reset's assertion, in milliseconds since the
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005466 * last EC boot, in the same epoch as time_since_ec_boot_ms.
5467 * Set to zero if the log entry is empty.
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005468 */
5469 uint32_t reset_time_ms;
5470 } recent_ap_reset[4];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005471} __ec_align4;
5472
5473/*
5474 * Add entropy to the device secret (stored in the rollback region).
5475 *
5476 * Depending on the chip, the operation may take a long time (e.g. to erase
5477 * flash), so the commands are asynchronous.
5478 */
5479#define EC_CMD_ADD_ENTROPY 0x0122
5480
5481enum add_entropy_action {
5482 /* Add entropy to the current secret. */
5483 ADD_ENTROPY_ASYNC = 0,
5484 /*
5485 * Add entropy, and also make sure that the previous secret is erased.
5486 * (this can be implemented by adding entropy multiple times until
5487 * all rolback blocks have been overwritten).
5488 */
5489 ADD_ENTROPY_RESET_ASYNC = 1,
5490 /* Read back result from the previous operation. */
5491 ADD_ENTROPY_GET_RESULT = 2,
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005492};
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005493
5494struct ec_params_rollback_add_entropy {
5495 uint8_t action;
5496} __ec_align1;
5497
5498/*
5499 * Perform a single read of a given ADC channel.
5500 */
5501#define EC_CMD_ADC_READ 0x0123
5502
5503struct ec_params_adc_read {
5504 uint8_t adc_channel;
5505} __ec_align1;
5506
5507struct ec_response_adc_read {
5508 int32_t adc_value;
5509} __ec_align4;
5510
5511/*
5512 * Read back rollback info
5513 */
5514#define EC_CMD_ROLLBACK_INFO 0x0124
5515
5516struct ec_response_rollback_info {
5517 int32_t id; /* Incrementing number to indicate which region to use. */
5518 int32_t rollback_min_version;
5519 int32_t rw_rollback_version;
5520} __ec_align4;
5521
5522
5523/* Issue AP reset */
5524#define EC_CMD_AP_RESET 0x0125
5525
5526/*****************************************************************************/
5527/* Locate peripheral chips
5528 *
5529 * Return values:
5530 * EC_RES_UNAVAILABLE: The chip type is supported but not found on system.
5531 * EC_RES_INVALID_PARAM: The chip type was unrecognized.
5532 * EC_RES_OVERFLOW: The index number exceeded the number of chip instances.
5533 */
5534#define EC_CMD_LOCATE_CHIP 0x0126
5535
5536enum ec_chip_type {
5537 EC_CHIP_TYPE_CBI_EEPROM = 0,
5538 EC_CHIP_TYPE_TCPC = 1,
5539 EC_CHIP_TYPE_COUNT,
5540 EC_CHIP_TYPE_MAX = 0xFF,
5541};
5542
5543enum ec_bus_type {
5544 EC_BUS_TYPE_I2C = 0,
5545 EC_BUS_TYPE_EMBEDDED = 1,
5546 EC_BUS_TYPE_COUNT,
5547 EC_BUS_TYPE_MAX = 0xFF,
5548};
5549
5550struct ec_i2c_info {
5551 uint16_t port; /* Physical port for device */
5552 uint16_t addr_flags; /* 7-bit (or 10-bit) address */
5553};
5554
5555struct ec_params_locate_chip {
5556 uint8_t type; /* enum ec_chip_type */
5557 uint8_t index; /* Specifies one instance of chip type */
5558 /* Used for type specific parameters in future */
5559 union {
5560 uint16_t reserved;
5561 };
5562} __ec_align2;
5563
5564
5565struct ec_response_locate_chip {
5566 uint8_t bus_type; /* enum ec_bus_type */
5567 uint8_t reserved; /* Aligning the following union to 2 bytes */
5568 union {
5569 struct ec_i2c_info i2c_info;
5570 };
5571} __ec_align2;
5572
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005573/*****************************************************************************/
5574/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08005575
5576/*****************************************************************************/
5577/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005578 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08005579 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005580#define EC_CMD_CR51_BASE 0x0300
5581#define EC_CMD_CR51_LAST 0x03FF
5582
5583/*****************************************************************************/
5584/* Fingerprint MCU commands: range 0x0400-0x040x */
5585
5586/* Fingerprint SPI sensor passthru command: prototyping ONLY */
5587#define EC_CMD_FP_PASSTHRU 0x0400
5588
5589#define EC_FP_FLAG_NOT_COMPLETE 0x1
5590
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005591struct ec_params_fp_passthru {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005592 uint16_t len; /* Number of bytes to write then read */
5593 uint16_t flags; /* EC_FP_FLAG_xxx */
5594 uint8_t data[]; /* Data to send */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005595} __ec_align2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005596
5597/* Configure the Fingerprint MCU behavior */
5598#define EC_CMD_FP_MODE 0x0402
5599
5600/* Put the sensor in its lowest power mode */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005601#define FP_MODE_DEEPSLEEP BIT(0)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005602/* Wait to see a finger on the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005603#define FP_MODE_FINGER_DOWN BIT(1)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005604/* Poll until the finger has left the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005605#define FP_MODE_FINGER_UP BIT(2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005606/* Capture the current finger image */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005607#define FP_MODE_CAPTURE BIT(3)
5608/* Finger enrollment session on-going */
5609#define FP_MODE_ENROLL_SESSION BIT(4)
5610/* Enroll the current finger image */
5611#define FP_MODE_ENROLL_IMAGE BIT(5)
5612/* Try to match the current finger image */
5613#define FP_MODE_MATCH BIT(6)
5614/* Reset and re-initialize the sensor. */
5615#define FP_MODE_RESET_SENSOR BIT(7)
5616/* special value: don't change anything just read back current mode */
5617#define FP_MODE_DONT_CHANGE BIT(31)
5618
5619#define FP_VALID_MODES (FP_MODE_DEEPSLEEP | \
5620 FP_MODE_FINGER_DOWN | \
5621 FP_MODE_FINGER_UP | \
5622 FP_MODE_CAPTURE | \
5623 FP_MODE_ENROLL_SESSION | \
5624 FP_MODE_ENROLL_IMAGE | \
5625 FP_MODE_MATCH | \
5626 FP_MODE_RESET_SENSOR | \
5627 FP_MODE_DONT_CHANGE)
5628
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005629/* Capture types defined in bits [30..28] */
5630#define FP_MODE_CAPTURE_TYPE_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005631#define FP_MODE_CAPTURE_TYPE_MASK (0x7 << FP_MODE_CAPTURE_TYPE_SHIFT)
5632/*
5633 * This enum must remain ordered, if you add new values you must ensure that
5634 * FP_CAPTURE_TYPE_MAX is still the last one.
5635 */
5636enum fp_capture_type {
5637 /* Full blown vendor-defined capture (produces 'frame_size' bytes) */
5638 FP_CAPTURE_VENDOR_FORMAT = 0,
5639 /* Simple raw image capture (produces width x height x bpp bits) */
5640 FP_CAPTURE_SIMPLE_IMAGE = 1,
5641 /* Self test pattern (e.g. checkerboard) */
5642 FP_CAPTURE_PATTERN0 = 2,
5643 /* Self test pattern (e.g. inverted checkerboard) */
5644 FP_CAPTURE_PATTERN1 = 3,
5645 /* Capture for Quality test with fixed contrast */
5646 FP_CAPTURE_QUALITY_TEST = 4,
5647 /* Capture for pixel reset value test */
5648 FP_CAPTURE_RESET_TEST = 5,
5649 FP_CAPTURE_TYPE_MAX,
5650};
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005651/* Extracts the capture type from the sensor 'mode' word */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005652#define FP_CAPTURE_TYPE(mode) (((mode) & FP_MODE_CAPTURE_TYPE_MASK) \
5653 >> FP_MODE_CAPTURE_TYPE_SHIFT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005654
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005655struct ec_params_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005656 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005657} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005658
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005659struct ec_response_fp_mode {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005660 uint32_t mode; /* as defined by FP_MODE_ constants */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005661} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005662
5663/* Retrieve Fingerprint sensor information */
5664#define EC_CMD_FP_INFO 0x0403
5665
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005666/* Number of dead pixels detected on the last maintenance */
5667#define FP_ERROR_DEAD_PIXELS(errors) ((errors) & 0x3FF)
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005668/* Unknown number of dead pixels detected on the last maintenance */
5669#define FP_ERROR_DEAD_PIXELS_UNKNOWN (0x3FF)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005670/* No interrupt from the sensor */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005671#define FP_ERROR_NO_IRQ BIT(12)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005672/* SPI communication error */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005673#define FP_ERROR_SPI_COMM BIT(13)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005674/* Invalid sensor Hardware ID */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005675#define FP_ERROR_BAD_HWID BIT(14)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005676/* Sensor initialization failed */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005677#define FP_ERROR_INIT_FAIL BIT(15)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005678
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005679struct ec_response_fp_info_v0 {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005680 /* Sensor identification */
5681 uint32_t vendor_id;
5682 uint32_t product_id;
5683 uint32_t model_id;
5684 uint32_t version;
5685 /* Image frame characteristics */
5686 uint32_t frame_size;
5687 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
5688 uint16_t width;
5689 uint16_t height;
5690 uint16_t bpp;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005691 uint16_t errors; /* see FP_ERROR_ flags above */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005692} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005693
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005694struct ec_response_fp_info {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005695 /* Sensor identification */
5696 uint32_t vendor_id;
5697 uint32_t product_id;
5698 uint32_t model_id;
5699 uint32_t version;
5700 /* Image frame characteristics */
5701 uint32_t frame_size;
5702 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
5703 uint16_t width;
5704 uint16_t height;
5705 uint16_t bpp;
5706 uint16_t errors; /* see FP_ERROR_ flags above */
5707 /* Template/finger current information */
5708 uint32_t template_size; /* max template size in bytes */
5709 uint16_t template_max; /* maximum number of fingers/templates */
5710 uint16_t template_valid; /* number of valid fingers/templates */
5711 uint32_t template_dirty; /* bitmap of templates with MCU side changes */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005712 uint32_t template_version; /* version of the template format */
5713} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005714
5715/* Get the last captured finger frame or a template content */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005716#define EC_CMD_FP_FRAME 0x0404
5717
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005718/* constants defining the 'offset' field which also contains the frame index */
5719#define FP_FRAME_INDEX_SHIFT 28
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005720/* Frame buffer where the captured image is stored */
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005721#define FP_FRAME_INDEX_RAW_IMAGE 0
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005722/* First frame buffer holding a template */
5723#define FP_FRAME_INDEX_TEMPLATE 1
5724#define FP_FRAME_GET_BUFFER_INDEX(offset) ((offset) >> FP_FRAME_INDEX_SHIFT)
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005725#define FP_FRAME_OFFSET_MASK 0x0FFFFFFF
5726
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005727/* Version of the format of the encrypted templates. */
5728#define FP_TEMPLATE_FORMAT_VERSION 3
5729
5730/* Constants for encryption parameters */
5731#define FP_CONTEXT_NONCE_BYTES 12
5732#define FP_CONTEXT_USERID_WORDS (32 / sizeof(uint32_t))
5733#define FP_CONTEXT_TAG_BYTES 16
5734#define FP_CONTEXT_SALT_BYTES 16
5735#define FP_CONTEXT_TPM_BYTES 32
5736
5737struct ec_fp_template_encryption_metadata {
5738 /*
5739 * Version of the structure format (N=3).
5740 */
5741 uint16_t struct_version;
5742 /* Reserved bytes, set to 0. */
5743 uint16_t reserved;
5744 /*
5745 * The salt is *only* ever used for key derivation. The nonce is unique,
5746 * a different one is used for every message.
5747 */
5748 uint8_t nonce[FP_CONTEXT_NONCE_BYTES];
5749 uint8_t salt[FP_CONTEXT_SALT_BYTES];
5750 uint8_t tag[FP_CONTEXT_TAG_BYTES];
5751};
5752
5753struct ec_params_fp_frame {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005754 /*
5755 * The offset contains the template index or FP_FRAME_INDEX_RAW_IMAGE
5756 * in the high nibble, and the real offset within the frame in
5757 * FP_FRAME_OFFSET_MASK.
5758 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005759 uint32_t offset;
5760 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005761} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005762
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005763/* Load a template into the MCU */
5764#define EC_CMD_FP_TEMPLATE 0x0405
5765
5766/* Flag in the 'size' field indicating that the full template has been sent */
5767#define FP_TEMPLATE_COMMIT 0x80000000
5768
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005769struct ec_params_fp_template {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005770 uint32_t offset;
5771 uint32_t size;
5772 uint8_t data[];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005773} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005774
5775/* Clear the current fingerprint user context and set a new one */
5776#define EC_CMD_FP_CONTEXT 0x0406
5777
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005778struct ec_params_fp_context {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005779 uint32_t userid[FP_CONTEXT_USERID_WORDS];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005780} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005781
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005782#define EC_CMD_FP_STATS 0x0407
5783
5784#define FPSTATS_CAPTURE_INV BIT(0)
5785#define FPSTATS_MATCHING_INV BIT(1)
5786
5787struct ec_response_fp_stats {
5788 uint32_t capture_time_us;
5789 uint32_t matching_time_us;
5790 uint32_t overall_time_us;
5791 struct {
5792 uint32_t lo;
5793 uint32_t hi;
5794 } overall_t0;
5795 uint8_t timestamps_invalid;
5796 int8_t template_matched;
5797} __ec_align2;
5798
5799#define EC_CMD_FP_SEED 0x0408
5800struct ec_params_fp_seed {
5801 /*
5802 * Version of the structure format (N=3).
5803 */
5804 uint16_t struct_version;
5805 /* Reserved bytes, set to 0. */
5806 uint16_t reserved;
5807 /* Seed from the TPM. */
5808 uint8_t seed[FP_CONTEXT_TPM_BYTES];
5809} __ec_align4;
5810
5811#define EC_CMD_FP_ENC_STATUS 0x0409
5812
5813/* FP TPM seed has been set or not */
5814#define FP_ENC_STATUS_SEED_SET BIT(0)
5815
5816struct ec_response_fp_encryption_status {
5817 /* Used bits in encryption engine status */
5818 uint32_t valid_flags;
5819 /* Encryption engine status */
5820 uint32_t status;
5821} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005822
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005823/*****************************************************************************/
5824/* Touchpad MCU commands: range 0x0500-0x05FF */
5825
5826/* Perform touchpad self test */
5827#define EC_CMD_TP_SELF_TEST 0x0500
5828
5829/* Get number of frame types, and the size of each type */
5830#define EC_CMD_TP_FRAME_INFO 0x0501
5831
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005832struct ec_response_tp_frame_info {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005833 uint32_t n_frames;
5834 uint32_t frame_sizes[0];
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005835} __ec_align4;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005836
5837/* Create a snapshot of current frame readings */
5838#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
5839
5840/* Read the frame */
5841#define EC_CMD_TP_FRAME_GET 0x0503
5842
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005843struct ec_params_tp_frame_get {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005844 uint32_t frame_index;
5845 uint32_t offset;
5846 uint32_t size;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005847} __ec_align4;
Duncan Laurieeb316852015-12-01 18:51:18 -08005848
5849/*****************************************************************************/
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005850/* EC-EC communication commands: range 0x0600-0x06FF */
5851
5852#define EC_COMM_TEXT_MAX 8
5853
5854/*
5855 * Get battery static information, i.e. information that never changes, or
5856 * very infrequently.
5857 */
5858#define EC_CMD_BATTERY_GET_STATIC 0x0600
5859
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005860/**
5861 * struct ec_params_battery_static_info - Battery static info parameters
5862 * @index: Battery index.
5863 */
5864struct ec_params_battery_static_info {
5865 uint8_t index;
5866} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005867
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005868/**
5869 * struct ec_response_battery_static_info - Battery static info response
5870 * @design_capacity: Battery Design Capacity (mAh)
5871 * @design_voltage: Battery Design Voltage (mV)
5872 * @manufacturer: Battery Manufacturer String
5873 * @model: Battery Model Number String
5874 * @serial: Battery Serial Number String
5875 * @type: Battery Type String
5876 * @cycle_count: Battery Cycle Count
5877 */
5878struct ec_response_battery_static_info {
5879 uint16_t design_capacity;
5880 uint16_t design_voltage;
5881 char manufacturer[EC_COMM_TEXT_MAX];
5882 char model[EC_COMM_TEXT_MAX];
5883 char serial[EC_COMM_TEXT_MAX];
5884 char type[EC_COMM_TEXT_MAX];
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005885 /* TODO(crbug.com/795991): Consider moving to dynamic structure. */
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005886 uint32_t cycle_count;
5887} __ec_align4;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005888
5889/*
5890 * Get battery dynamic information, i.e. information that is likely to change
5891 * every time it is read.
5892 */
5893#define EC_CMD_BATTERY_GET_DYNAMIC 0x0601
5894
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005895/**
5896 * struct ec_params_battery_dynamic_info - Battery dynamic info parameters
5897 * @index: Battery index.
5898 */
5899struct ec_params_battery_dynamic_info {
5900 uint8_t index;
5901} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005902
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005903/**
5904 * struct ec_response_battery_dynamic_info - Battery dynamic info response
5905 * @actual_voltage: Battery voltage (mV)
5906 * @actual_current: Battery current (mA); negative=discharging
5907 * @remaining_capacity: Remaining capacity (mAh)
5908 * @full_capacity: Capacity (mAh, might change occasionally)
5909 * @flags: Flags, see EC_BATT_FLAG_*
5910 * @desired_voltage: Charging voltage desired by battery (mV)
5911 * @desired_current: Charging current desired by battery (mA)
5912 */
5913struct ec_response_battery_dynamic_info {
5914 int16_t actual_voltage;
5915 int16_t actual_current;
5916 int16_t remaining_capacity;
5917 int16_t full_capacity;
5918 int16_t flags;
5919 int16_t desired_voltage;
5920 int16_t desired_current;
5921} __ec_align2;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005922
5923/*
5924 * Control charger chip. Used to control charger chip on the slave.
5925 */
5926#define EC_CMD_CHARGER_CONTROL 0x0602
5927
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005928/**
5929 * struct ec_params_charger_control - Charger control parameters
5930 * @max_current: Charger current (mA). Positive to allow base to draw up to
5931 * max_current and (possibly) charge battery, negative to request current
5932 * from base (OTG).
5933 * @otg_voltage: Voltage (mV) to use in OTG mode, ignored if max_current is
5934 * >= 0.
5935 * @allow_charging: Allow base battery charging (only makes sense if
5936 * max_current > 0).
5937 */
5938struct ec_params_charger_control {
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005939 int16_t max_current;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005940 uint16_t otg_voltage;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005941 uint8_t allow_charging;
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08005942} __ec_align_size1;
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06005943
5944/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08005945/*
5946 * Reserve a range of host commands for board-specific, experimental, or
5947 * special purpose features. These can be (re)used without updating this file.
5948 *
5949 * CAUTION: Don't go nuts with this. Shipping products should document ALL
5950 * their EC commands for easier development, testing, debugging, and support.
5951 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005952 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
5953 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
5954 *
Duncan Laurieeb316852015-12-01 18:51:18 -08005955 * In your experimental code, you may want to do something like this:
5956 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005957 * #define EC_CMD_MAGIC_FOO 0x0000
5958 * #define EC_CMD_MAGIC_BAR 0x0001
5959 * #define EC_CMD_MAGIC_HEY 0x0002
5960 *
5961 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
5962 * EC_VER_MASK(0);
5963 *
5964 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
5965 * EC_VER_MASK(0);
5966 *
5967 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
5968 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08005969 */
5970#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
5971#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
5972
Duncan Laurie67f26cc2017-06-29 23:17:22 -07005973/*
5974 * Given the private host command offset, calculate the true private host
5975 * command value.
5976 */
5977#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
5978 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
5979
Duncan Laurie93e24442014-01-06 12:30:52 -08005980/*****************************************************************************/
5981/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07005982 * Passthru commands
5983 *
5984 * Some platforms have sub-processors chained to each other. For example.
5985 *
5986 * AP <--> EC <--> PD MCU
5987 *
5988 * The top 2 bits of the command number are used to indicate which device the
5989 * command is intended for. Device 0 is always the device receiving the
5990 * command; other device mapping is board-specific.
5991 *
5992 * When a device receives a command to be passed to a sub-processor, it passes
5993 * it on with the device number set back to 0. This allows the sub-processor
5994 * to remain blissfully unaware of whether the command originated on the next
5995 * device up the chain, or was passed through from the AP.
5996 *
5997 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
5998 * AP sends command 0x4002 to the EC
5999 * EC sends command 0x0002 to the PD MCU
6000 * EC forwards PD MCU response back to the AP
6001 */
6002
6003/* Offset and max command number for sub-device n */
6004#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
6005#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
6006
6007/*****************************************************************************/
6008/*
Duncan Laurie93e24442014-01-06 12:30:52 -08006009 * Deprecated constants. These constants have been renamed for clarity. The
6010 * meaning and size has not changed. Programs that use the old names should
6011 * switch to the new names soon, as the old names may not be carried forward
6012 * forever.
6013 */
6014#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
6015#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
6016#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
6017
Jonathan Brandmeyer6bffc5c2018-07-23 16:30:44 -06006018#endif /* !__ACPI__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07006019
You-Cheng Syu8d6ea6a2019-03-13 21:37:23 +08006020#ifdef __cplusplus
6021}
6022#endif
6023
Duncan Laurieeb316852015-12-01 18:51:18 -08006024#endif /* __CROS_EC_EC_COMMANDS_H */