blob: 46ab905e8f9f5d7965d12e118fab362badd9fce2 [file] [log] [blame]
Martin Rothedb937a2016-01-12 16:17:44 -07001// Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
2//
3// Redistribution and use in source and binary forms, with or without
4// modification, are permitted provided that the following conditions are
5// met:
6//
7// * Redistributions of source code must retain the above copyright
8// notice, this list of conditions and the following disclaimer.
9// * Redistributions in binary form must reproduce the above
10// copyright notice, this list of conditions and the following disclaimer
11// in the documentation and/or other materials provided with the
12// distribution.
13// * Neither the name of Google Inc. nor the names of its
14// contributors may be used to endorse or promote products derived from
15// this software without specific prior written permission.
16//
17// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080028
29/* Host communication command constants for Chrome EC */
30
Duncan Laurieeb316852015-12-01 18:51:18 -080031#ifndef __CROS_EC_EC_COMMANDS_H
32#define __CROS_EC_EC_COMMANDS_H
Stefan Reinauerd6682e82013-02-21 15:39:35 -080033
Patrick Georgi0f6187a2017-07-28 15:57:23 +020034#if !defined(__ACPI__) && !defined(__KERNEL__)
Duncan Laurie67f26cc2017-06-29 23:17:22 -070035#include <stdint.h>
36#endif
37
38/*
39 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
40 * generates more efficient code for accessing request/response structures on
41 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
42 */
43#ifdef CHROMIUM_EC
44#include "common.h"
45#endif
46
Stefan Reinauerd6682e82013-02-21 15:39:35 -080047/*
Duncan Laurie93e24442014-01-06 12:30:52 -080048 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080049 *
Duncan Laurie93e24442014-01-06 12:30:52 -080050 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
51 * determined in other ways. Remove this once the kernel code no longer
52 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080053 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080054#define EC_PROTO_VERSION 0x00000002
55
56/* Command version mask */
57#define EC_VER_MASK(version) (1UL << (version))
58
59/* I/O addresses for ACPI commands */
60#define EC_LPC_ADDR_ACPI_DATA 0x62
61#define EC_LPC_ADDR_ACPI_CMD 0x66
62
63/* I/O addresses for host command */
64#define EC_LPC_ADDR_HOST_DATA 0x200
65#define EC_LPC_ADDR_HOST_CMD 0x204
66
67/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080068/* Protocol version 2 */
69#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
70#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
71 * EC_PROTO2_MAX_PARAM_SIZE */
72/* Protocol version 3 */
73#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
74#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080075
Bill Richardsone221aad2013-06-12 10:50:41 -070076/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
77 * and they tell the kernel that so we have to think of it as two parts. */
78#define EC_HOST_CMD_REGION0 0x800
79#define EC_HOST_CMD_REGION1 0x880
80#define EC_HOST_CMD_REGION_SIZE 0x80
81
Stefan Reinauerd6682e82013-02-21 15:39:35 -080082/* EC command register bit functions */
83#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
84#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
85#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
86#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
87#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
88#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
89#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
90
91#define EC_LPC_ADDR_MEMMAP 0x900
92#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
93#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
94
95/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070096#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
97#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
98#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
99#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800100#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
101#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
102#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
103#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
104#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700105#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
106/* Unused 0x28 - 0x2f */
107#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
108/* Unused 0x31 - 0x33 */
109#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
110/* Reserve 0x38 - 0x3f for additional host event-related stuff */
111/* Battery values are all 32 bits */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800112#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
113#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
114#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
115#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
116#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
117#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
118#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
119#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700120/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800121#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
122#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
123#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
124#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700125#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
126/* Unused 0x84 - 0x8f */
127#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
128/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800129#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
130/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
131/* 0x94 - 0x99: 1st Accelerometer */
132/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700133#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700134/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700135
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700136/*
137 * ACPI is unable to access memory mapped data at or above this offset due to
138 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
139 * which might be needed by ACPI.
140 */
141#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700142
143/* Define the format of the accelerometer mapped memory status byte. */
144#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
145#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
146#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800147
148/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
149#define EC_TEMP_SENSOR_ENTRIES 16
150/*
151 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
152 *
153 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
154 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700155#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800156
157/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700158#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
159#define EC_TEMP_SENSOR_ERROR 0xfe
160#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
161#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800162/*
163 * The offset of temperature value stored in mapped memory. This allows
164 * reporting a temperature range of 200K to 454K = -73C to 181C.
165 */
166#define EC_TEMP_SENSOR_OFFSET 200
167
Duncan Laurie93e24442014-01-06 12:30:52 -0800168/*
169 * Number of ALS readings at EC_MEMMAP_ALS
170 */
171#define EC_ALS_ENTRIES 2
172
173/*
174 * The default value a temperature sensor will return when it is present but
175 * has not been read this boot. This is a reasonable number to avoid
176 * triggering alarms on the host.
177 */
178#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
179
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800180#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
181#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
182#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
183
184/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
185#define EC_BATT_FLAG_AC_PRESENT 0x01
186#define EC_BATT_FLAG_BATT_PRESENT 0x02
187#define EC_BATT_FLAG_DISCHARGING 0x04
188#define EC_BATT_FLAG_CHARGING 0x08
189#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
190
191/* Switch flags at EC_MEMMAP_SWITCHES */
192#define EC_SWITCH_LID_OPEN 0x01
193#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
194#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700195/* Was recovery requested via keyboard; now unused. */
196#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800197/* Recovery requested via dedicated signal (from servo board) */
198#define EC_SWITCH_DEDICATED_RECOVERY 0x10
199/* Was fake developer mode switch; now unused. Remove in next refactor. */
200#define EC_SWITCH_IGNORE0 0x20
201
202/* Host command interface flags */
203/* Host command interface supports LPC args (LPC interface only) */
204#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800205/* Host command interface supports version 3 protocol */
206#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800207
208/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800209#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
210#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
211#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
212#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
213#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800214
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700215/*****************************************************************************/
216/*
217 * ACPI commands
218 *
219 * These are valid ONLY on the ACPI command/data port.
220 */
221
222/*
223 * ACPI Read Embedded Controller
224 *
225 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
226 *
227 * Use the following sequence:
228 *
229 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
230 * - Wait for EC_LPC_CMDR_PENDING bit to clear
231 * - Write address to EC_LPC_ADDR_ACPI_DATA
232 * - Wait for EC_LPC_CMDR_DATA bit to set
233 * - Read value from EC_LPC_ADDR_ACPI_DATA
234 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700235#define EC_CMD_ACPI_READ 0x0080
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700236
237/*
238 * ACPI Write Embedded Controller
239 *
240 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
241 *
242 * Use the following sequence:
243 *
244 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
245 * - Wait for EC_LPC_CMDR_PENDING bit to clear
246 * - Write address to EC_LPC_ADDR_ACPI_DATA
247 * - Wait for EC_LPC_CMDR_PENDING bit to clear
248 * - Write value to EC_LPC_ADDR_ACPI_DATA
249 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700250#define EC_CMD_ACPI_WRITE 0x0081
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700251
252/*
253 * ACPI Burst Enable Embedded Controller
254 *
255 * This enables burst mode on the EC to allow the host to issue several
256 * commands back-to-back. While in this mode, writes to mapped multi-byte
257 * data are locked out to ensure data consistency.
258 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700259#define EC_CMD_ACPI_BURST_ENABLE 0x0082
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700260
261/*
262 * ACPI Burst Disable Embedded Controller
263 *
264 * This disables burst mode on the EC and stops preventing EC writes to mapped
265 * multi-byte data.
266 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700267#define EC_CMD_ACPI_BURST_DISABLE 0x0083
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700268
269/*
270 * ACPI Query Embedded Controller
271 *
272 * This clears the lowest-order bit in the currently pending host events, and
273 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
274 * event 0x80000000 = 32), or 0 if no event was pending.
275 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700276#define EC_CMD_ACPI_QUERY_EVENT 0x0084
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700277
278/* Valid addresses in ACPI memory space, for read/write commands */
279
280/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
281#define EC_ACPI_MEM_VERSION 0x00
282/*
283 * Test location; writing value here updates test compliment byte to (0xff -
284 * value).
285 */
286#define EC_ACPI_MEM_TEST 0x01
287/* Test compliment; writes here are ignored. */
288#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
289
290/* Keyboard backlight brightness percent (0 - 100) */
291#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
292/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
293#define EC_ACPI_MEM_FAN_DUTY 0x04
294
295/*
296 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
297 * independent thresholds attached to them. The current value of the ID
298 * register determines which sensor is affected by the THRESHOLD and COMMIT
299 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
300 * as the memory-mapped sensors. The COMMIT register applies those settings.
301 *
302 * The spec does not mandate any way to read back the threshold settings
303 * themselves, but when a threshold is crossed the AP needs a way to determine
304 * which sensor(s) are responsible. Each reading of the ID register clears and
305 * returns one sensor ID that has crossed one of its threshold (in either
306 * direction) since the last read. A value of 0xFF means "no new thresholds
307 * have tripped". Setting or enabling the thresholds for a sensor will clear
308 * the unread event count for that sensor.
309 */
310#define EC_ACPI_MEM_TEMP_ID 0x05
311#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
312#define EC_ACPI_MEM_TEMP_COMMIT 0x07
313/*
314 * Here are the bits for the COMMIT register:
315 * bit 0 selects the threshold index for the chosen sensor (0/1)
316 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
317 * Each write to the commit register affects one threshold.
318 */
319#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
320#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
321/*
322 * Example:
323 *
324 * Set the thresholds for sensor 2 to 50 C and 60 C:
325 * write 2 to [0x05] -- select temp sensor 2
326 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
327 * write 0x2 to [0x07] -- enable threshold 0 with this value
328 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
329 * write 0x3 to [0x07] -- enable threshold 1 with this value
330 *
331 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
332 * write 2 to [0x05] -- select temp sensor 2
333 * write 0x1 to [0x07] -- disable threshold 1
334 */
335
336/* DPTF battery charging current limit */
337#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
338
339/* Charging limit is specified in 64 mA steps */
340#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
341/* Value to disable DPTF battery charging limit */
342#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700343
jiazi Yang51fc93f2016-07-28 05:15:01 -0400344/*
345 * Report device orientation
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700346 * bit 0 device is tablet mode
jiazi Yang51fc93f2016-07-28 05:15:01 -0400347 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700348#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
349#define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700350
351/*
352 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
353 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
354 */
355#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
356#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
357
358/* Current version of ACPI memory address space */
359#define EC_ACPI_MEM_VERSION_CURRENT 2
360
361
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800362/*
363 * This header file is used in coreboot both in C and ACPI code. The ACPI code
364 * is pre-processed to handle constants but the ASL compiler is unable to
365 * handle actual C code so keep it separate.
366 */
367#ifndef __ACPI__
368
369/*
370 * Define __packed if someone hasn't beat us to it. Linux kernel style
371 * checking prefers __packed over __attribute__((packed)).
372 */
373#ifndef __packed
374#define __packed __attribute__((packed))
375#endif
376
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700377#ifndef __aligned
378#define __aligned(x) __attribute__((aligned(x)))
379#endif
380
381/*
382 * Attributes for EC request and response packets. Just defining __packed
383 * results in inefficient assembly code on ARM, if the structure is actually
384 * 32-bit aligned, as it should be for all buffers.
385 *
386 * Be very careful when adding these to existing structures. They will round
387 * up the structure size to the specified boundary.
388 *
389 * Also be very careful to make that if a structure is included in some other
390 * parent structure that the alignment will still be true given the packing of
391 * the parent structure. This is particularly important if the sub-structure
392 * will be passed as a pointer to another function, since that function will
393 * not know about the misaligment caused by the parent structure's packing.
394 *
395 * Also be very careful using __packed - particularly when nesting non-packed
396 * structures inside packed ones. In fact, DO NOT use __packed directly;
397 * always use one of these attributes.
398 *
399 * Once everything is annotated properly, the following search strings should
400 * not return ANY matches in this file other than right here:
401 *
402 * "__packed" - generates inefficient code; all sub-structs must also be packed
403 *
404 * "struct [^_]" - all structs should be annotated, except for structs that are
405 * members of other structs/unions (and their original declarations should be
406 * annotated).
407 */
408#ifdef CONFIG_HOSTCMD_ALIGNED
409
410/*
411 * Packed structures where offset and size are always aligned to 1, 2, or 4
412 * byte boundary.
413 */
414#define __ec_align1 __packed
415#define __ec_align2 __packed __aligned(2)
416#define __ec_align4 __packed __aligned(4)
417
418/*
419 * Packed structure which must be under-aligned, because its size is not a
420 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
421 * of all multi-byte fields in it, even though they are themselves aligned.
422 *
423 * In theory, we could duplicate the structure with __aligned(4) for accessing
424 * its members, but use the __packed version for sizeof().
425 */
426#define __ec_align_size1 __packed
427
428/*
429 * Packed structure which must be under-aligned, because its offset inside a
430 * parent structure is not a 4-byte multiple.
431 */
432#define __ec_align_offset1 __packed
433#define __ec_align_offset2 __packed __aligned(2)
434
435/*
436 * Structures which are complicated enough that I'm skipping them on the first
437 * pass. They are effectively unchanged from their previous definitions.
438 *
439 * TODO(rspangler): Figure out what to do with these. It's likely necessary
440 * to work out the size and offset of each member and add explicit padding to
441 * maintain those.
442 */
443#define __ec_todo_packed __packed
444#define __ec_todo_unpacked
445
446#else /* !CONFIG_HOSTCMD_ALIGNED */
447
448/*
449 * Packed structures make no assumption about alignment, so they do inefficient
450 * byte-wise reads.
451 */
452#define __ec_align1 __packed
453#define __ec_align2 __packed
454#define __ec_align4 __packed
455#define __ec_align_size1 __packed
456#define __ec_align_offset1 __packed
457#define __ec_align_offset2 __packed
458#define __ec_todo_packed __packed
459#define __ec_todo_unpacked
460
461#endif /* !CONFIG_HOSTCMD_ALIGNED */
462
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800463/* LPC command status byte masks */
464/* EC has written a byte in the data register and host hasn't read it yet */
465#define EC_LPC_STATUS_TO_HOST 0x01
466/* Host has written a command/data byte and the EC hasn't read it yet */
467#define EC_LPC_STATUS_FROM_HOST 0x02
468/* EC is processing a command */
469#define EC_LPC_STATUS_PROCESSING 0x04
470/* Last write to EC was a command, not data */
471#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700472/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800473#define EC_LPC_STATUS_BURST_MODE 0x10
474/* SCI event is pending (requesting SCI query) */
475#define EC_LPC_STATUS_SCI_PENDING 0x20
476/* SMI event is pending (requesting SMI query) */
477#define EC_LPC_STATUS_SMI_PENDING 0x40
478/* (reserved) */
479#define EC_LPC_STATUS_RESERVED 0x80
480
481/*
482 * EC is busy. This covers both the EC processing a command, and the host has
483 * written a new command but the EC hasn't picked it up yet.
484 */
485#define EC_LPC_STATUS_BUSY_MASK \
486 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
487
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700488/* Host command response codes (16-bit). Note that response codes should be
489 * stored in a uint16_t rather than directly in a value of this type.
490 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800491enum ec_status {
492 EC_RES_SUCCESS = 0,
493 EC_RES_INVALID_COMMAND = 1,
494 EC_RES_ERROR = 2,
495 EC_RES_INVALID_PARAM = 3,
496 EC_RES_ACCESS_DENIED = 4,
497 EC_RES_INVALID_RESPONSE = 5,
498 EC_RES_INVALID_VERSION = 6,
499 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700500 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
501 EC_RES_UNAVAILABLE = 9, /* No response available */
502 EC_RES_TIMEOUT = 10, /* We got a timeout */
503 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800504 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
505 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700506 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700507 EC_RES_BUS_ERROR = 15, /* Communications bus error */
508 EC_RES_BUSY = 16 /* Up but too busy. Should retry */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800509};
510
511/*
512 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
513 * EC command uses code 0 to mean "no event pending". We explicitly specify
514 * each value in the enum listing so they won't change if we delete/insert an
515 * item or rearrange the list (it needs to be stable across platforms, not
516 * just within a single compiled instance).
517 */
518enum host_event_code {
519 EC_HOST_EVENT_LID_CLOSED = 1,
520 EC_HOST_EVENT_LID_OPEN = 2,
521 EC_HOST_EVENT_POWER_BUTTON = 3,
522 EC_HOST_EVENT_AC_CONNECTED = 4,
523 EC_HOST_EVENT_AC_DISCONNECTED = 5,
524 EC_HOST_EVENT_BATTERY_LOW = 6,
525 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
526 EC_HOST_EVENT_BATTERY = 8,
527 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700528 /* Event generated by a device attached to the EC */
529 EC_HOST_EVENT_DEVICE = 10,
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800530 EC_HOST_EVENT_THERMAL = 11,
531 EC_HOST_EVENT_USB_CHARGER = 12,
532 EC_HOST_EVENT_KEY_PRESSED = 13,
533 /*
534 * EC has finished initializing the host interface. The host can check
535 * for this event following sending a EC_CMD_REBOOT_EC command to
536 * determine when the EC is ready to accept subsequent commands.
537 */
538 EC_HOST_EVENT_INTERFACE_READY = 14,
539 /* Keyboard recovery combo has been pressed */
540 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
541
542 /* Shutdown due to thermal overload */
543 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
544 /* Shutdown due to battery level too low */
545 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
546
Duncan Laurie93e24442014-01-06 12:30:52 -0800547 /* Suggest that the AP throttle itself */
548 EC_HOST_EVENT_THROTTLE_START = 18,
549 /* Suggest that the AP resume normal speed */
550 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700551
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800552 /* Hang detect logic detected a hang and host event timeout expired */
553 EC_HOST_EVENT_HANG_DETECT = 20,
554 /* Hang detect logic detected a hang and warm rebooted the AP */
555 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700556
557 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700558 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800559
Duncan Lauried8401182014-09-29 08:32:19 -0700560 /* Battery Status flags have changed */
561 EC_HOST_EVENT_BATTERY_STATUS = 23,
562
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700563 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800564 EC_HOST_EVENT_PANIC = 24,
565
Furquan Shaikh066cc852015-06-20 15:53:03 -0700566 /* Keyboard fastboot combo has been pressed */
567 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
568
Gwendal Grignou880b4582016-06-20 08:49:25 -0700569 /* EC RTC event occurred */
570 EC_HOST_EVENT_RTC = 26,
571
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700572 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700573 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700574
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700575 /* EC desires to change state of host-controlled USB mux */
576 EC_HOST_EVENT_USB_MUX = 28,
577
jiazi Yang51fc93f2016-07-28 05:15:01 -0400578 /* TABLET/LAPTOP mode event*/
579 EC_HOST_EVENT_MODE_CHANGE = 29,
580
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700581 /* Keyboard recovery combo with hardware reinitialization */
582 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
583
584 /*
585 * Reserve this last bit to indicate that at least one bit in a
586 * secondary host event word is set. See crbug.com/633646.
587 */
588 EC_HOST_EVENT_EXTENDED = 31,
589
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800590 /*
591 * The high bit of the event mask is not used as a host event code. If
592 * it reads back as set, then the entire event mask should be
593 * considered invalid by the host. This can happen when reading the
594 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
595 * not initialized on the EC, or improperly configured on the host.
596 */
597 EC_HOST_EVENT_INVALID = 32
598};
599/* Host event mask */
600#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
601
602/* Arguments at EC_LPC_ADDR_HOST_ARGS */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700603struct __ec_align4 ec_lpc_host_args {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800604 uint8_t flags;
605 uint8_t command_version;
606 uint8_t data_size;
607 /*
608 * Checksum; sum of command + flags + command_version + data_size +
609 * all params/response data bytes.
610 */
611 uint8_t checksum;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700612};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800613
614/* Flags for ec_lpc_host_args.flags */
615/*
616 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
617 * params.
618 *
619 * If EC gets a command and this flag is not set, this is an old-style command.
620 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
621 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700622 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800623 */
624#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
625/*
626 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
627 *
628 * If EC responds to a command and this flag is not set, this is an old-style
629 * response. Command version is 0 and response data from EC is at
630 * EC_LPC_ADDR_OLD_PARAM with unknown length.
631 */
632#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
633
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800634/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800635/*
636 * Byte codes returned by EC over SPI interface.
637 *
638 * These can be used by the AP to debug the EC interface, and to determine
639 * when the EC is not in a state where it will ever get around to responding
640 * to the AP.
641 *
642 * Example of sequence of bytes read from EC for a current good transfer:
643 * 1. - - AP asserts chip select (CS#)
644 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
645 * 3. - - EC starts handling CS# interrupt
646 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
647 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
648 * bytes looking for EC_SPI_FRAME_START
649 * 6. - - EC finishes processing and sets up response
650 * 7. EC_SPI_FRAME_START - AP reads frame byte
651 * 8. (response packet) - AP reads response packet
652 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
653 * 10 - - AP deasserts chip select
654 * 11 - - EC processes CS# interrupt and sets up DMA for
655 * next request
656 *
657 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
658 * the following byte values:
659 * EC_SPI_OLD_READY
660 * EC_SPI_RX_READY
661 * EC_SPI_RECEIVING
662 * EC_SPI_PROCESSING
663 *
664 * Then the EC found an error in the request, or was not ready for the request
665 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
666 * because the EC is unable to tell when the AP is done sending its request.
667 */
668
669/*
670 * Framing byte which precedes a response packet from the EC. After sending a
671 * request, the AP will clock in bytes until it sees the framing byte, then
672 * clock in the response packet.
673 */
674#define EC_SPI_FRAME_START 0xec
675
676/*
677 * Padding bytes which are clocked out after the end of a response packet.
678 */
679#define EC_SPI_PAST_END 0xed
680
681/*
682 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
683 * that the AP will send a valid packet header (starting with
684 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
685 */
686#define EC_SPI_RX_READY 0xf8
687
688/*
689 * EC has started receiving the request from the AP, but hasn't started
690 * processing it yet.
691 */
692#define EC_SPI_RECEIVING 0xf9
693
694/* EC has received the entire request from the AP and is processing it. */
695#define EC_SPI_PROCESSING 0xfa
696
697/*
698 * EC received bad data from the AP, such as a packet header with an invalid
699 * length. EC will ignore all data until chip select deasserts.
700 */
701#define EC_SPI_RX_BAD_DATA 0xfb
702
703/*
704 * EC received data from the AP before it was ready. That is, the AP asserted
705 * chip select and started clocking data before the EC was ready to receive it.
706 * EC will ignore all data until chip select deasserts.
707 */
708#define EC_SPI_NOT_READY 0xfc
709
710/*
711 * EC was ready to receive a request from the AP. EC has treated the byte sent
712 * by the AP as part of a request packet, or (for old-style ECs) is processing
713 * a fully received packet but is not ready to respond yet.
714 */
715#define EC_SPI_OLD_READY 0xfd
716
717/*****************************************************************************/
718
719/*
720 * Protocol version 2 for I2C and SPI send a request this way:
721 *
722 * 0 EC_CMD_VERSION0 + (command version)
723 * 1 Command number
724 * 2 Length of params = N
725 * 3..N+2 Params, if any
726 * N+3 8-bit checksum of bytes 0..N+2
727 *
728 * The corresponding response is:
729 *
730 * 0 Result code (EC_RES_*)
731 * 1 Length of params = M
732 * 2..M+1 Params, if any
733 * M+2 8-bit checksum of bytes 0..M+1
734 */
735#define EC_PROTO2_REQUEST_HEADER_BYTES 3
736#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
737#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
738 EC_PROTO2_REQUEST_TRAILER_BYTES)
739
740#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
741#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
742#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
743 EC_PROTO2_RESPONSE_TRAILER_BYTES)
744
745/* Parameter length was limited by the LPC interface */
746#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
747
748/* Maximum request and response packet sizes for protocol version 2 */
749#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
750 EC_PROTO2_MAX_PARAM_SIZE)
751#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
752 EC_PROTO2_MAX_PARAM_SIZE)
753
754/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800755
756/*
757 * Value written to legacy command port / prefix byte to indicate protocol
758 * 3+ structs are being used. Usage is bus-dependent.
759 */
760#define EC_COMMAND_PROTOCOL_3 0xda
761
762#define EC_HOST_REQUEST_VERSION 3
763
764/* Version 3 request from host */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700765struct __ec_align4 ec_host_request {
766 /* Structure version (=3)
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800767 *
768 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
769 * version it doesn't know how to parse.
770 */
771 uint8_t struct_version;
772
773 /*
774 * Checksum of request and data; sum of all bytes including checksum
775 * should total to 0.
776 */
777 uint8_t checksum;
778
779 /* Command code */
780 uint16_t command;
781
782 /* Command version */
783 uint8_t command_version;
784
785 /* Unused byte in current protocol version; set to 0 */
786 uint8_t reserved;
787
788 /* Length of data which follows this header */
789 uint16_t data_len;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700790};
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800791
792#define EC_HOST_RESPONSE_VERSION 3
793
794/* Version 3 response from EC */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700795struct __ec_align4 ec_host_response {
796 /* Structure version (=3) */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800797 uint8_t struct_version;
798
799 /*
800 * Checksum of response and data; sum of all bytes including checksum
801 * should total to 0.
802 */
803 uint8_t checksum;
804
805 /* Result code (EC_RES_*) */
806 uint16_t result;
807
808 /* Length of data which follows this header */
809 uint16_t data_len;
810
811 /* Unused bytes in current protocol version; set to 0 */
812 uint16_t reserved;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700813};
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800814
815/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800816/*
817 * Notes on commands:
818 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700819 * Each command is an 16-bit command value. Commands which take params or
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700820 * return response data specify structures for that data. If no structure is
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800821 * specified, the command does not input or output data, respectively.
822 * Parameter/response length is implicit in the structs. Some underlying
823 * communication protocols (I2C, SPI) may add length or checksum headers, but
824 * those are implementation-dependent and not defined here.
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700825 *
826 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
827 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800828 */
829
830/*****************************************************************************/
831/* General / test commands */
832
833/*
834 * Get protocol version, used to deal with non-backward compatible protocol
835 * changes.
836 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700837#define EC_CMD_PROTO_VERSION 0x0000
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800838
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700839struct __ec_align4 ec_response_proto_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800840 uint32_t version;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700841};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800842
843/*
844 * Hello. This is a simple command to test the EC is responsive to
845 * commands.
846 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700847#define EC_CMD_HELLO 0x0001
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800848
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700849struct __ec_align4 ec_params_hello {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800850 uint32_t in_data; /* Pass anything here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700851};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800852
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700853struct __ec_align4 ec_response_hello {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800854 uint32_t out_data; /* Output will be in_data + 0x01020304 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700855};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800856
857/* Get version number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700858#define EC_CMD_GET_VERSION 0x0002
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800859
860enum ec_current_image {
861 EC_IMAGE_UNKNOWN = 0,
862 EC_IMAGE_RO,
863 EC_IMAGE_RW
864};
865
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700866struct __ec_align4 ec_response_get_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800867 /* Null-terminated version strings for RO, RW */
868 char version_string_ro[32];
869 char version_string_rw[32];
870 char reserved[32]; /* Was previously RW-B string */
871 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700872};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800873
874/* Read test */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700875#define EC_CMD_READ_TEST 0x0003
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800876
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700877struct __ec_align4 ec_params_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800878 uint32_t offset; /* Starting value for read buffer */
879 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700880};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800881
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700882struct __ec_align4 ec_response_read_test {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800883 uint32_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700884};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800885
886/*
887 * Get build information
888 *
889 * Response is null-terminated string.
890 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700891#define EC_CMD_GET_BUILD_INFO 0x0004
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800892
893/* Get chip info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700894#define EC_CMD_GET_CHIP_INFO 0x0005
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800895
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700896struct __ec_align4 ec_response_get_chip_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800897 /* Null-terminated strings */
898 char vendor[32];
899 char name[32];
900 char revision[32]; /* Mask version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700901};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800902
903/* Get board HW version */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700904#define EC_CMD_GET_BOARD_VERSION 0x0006
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800905
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700906struct __ec_align2 ec_response_board_version {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800907 uint16_t board_version; /* A monotonously incrementing number. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700908};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800909
910/*
911 * Read memory-mapped data.
912 *
913 * This is an alternate interface to memory-mapped data for bus protocols
914 * which don't support direct-mapped memory - I2C, SPI, etc.
915 *
916 * Response is params.size bytes of data.
917 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700918#define EC_CMD_READ_MEMMAP 0x0007
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800919
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700920struct __ec_align1 ec_params_read_memmap {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800921 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
922 uint8_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700923};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800924
925/* Read versions supported for a command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700926#define EC_CMD_GET_CMD_VERSIONS 0x0008
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800927
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700928struct __ec_align1 ec_params_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800929 uint8_t cmd; /* Command to check */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700930};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800931
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700932struct __ec_align2 ec_params_get_cmd_versions_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700933 uint16_t cmd; /* Command to check */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700934};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700935
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700936struct __ec_align4 ec_response_get_cmd_versions {
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800937 /*
938 * Mask of supported versions; use EC_VER_MASK() to compare with a
939 * desired version.
940 */
941 uint32_t version_mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700942};
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800943
Duncan Laurie433432b2013-06-03 10:38:22 -0700944/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700945 * Check EC communications status (busy). This is needed on i2c/spi but not
Duncan Laurie433432b2013-06-03 10:38:22 -0700946 * on lpc since it has its own out-of-band busy indicator.
947 *
948 * lpc must read the status from the command register. Attempting this on
949 * lpc will overwrite the args/parameter space and corrupt its data.
950 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700951#define EC_CMD_GET_COMMS_STATUS 0x0009
Duncan Laurie433432b2013-06-03 10:38:22 -0700952
953/* Avoid using ec_status which is for return values */
954enum ec_comms_status {
955 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
956};
957
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700958struct __ec_align4 ec_response_get_comms_status {
Duncan Laurie433432b2013-06-03 10:38:22 -0700959 uint32_t flags; /* Mask of enum ec_comms_status */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700960};
Duncan Laurie433432b2013-06-03 10:38:22 -0700961
Duncan Laurie93e24442014-01-06 12:30:52 -0800962/* Fake a variety of responses, purely for testing purposes. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700963#define EC_CMD_TEST_PROTOCOL 0x000A
Duncan Laurie93e24442014-01-06 12:30:52 -0800964
965/* Tell the EC what to send back to us. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700966struct __ec_align4 ec_params_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -0800967 uint32_t ec_result;
968 uint32_t ret_len;
969 uint8_t buf[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700970};
Duncan Laurie93e24442014-01-06 12:30:52 -0800971
972/* Here it comes... */
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700973struct __ec_align4 ec_response_test_protocol {
Duncan Laurie93e24442014-01-06 12:30:52 -0800974 uint8_t buf[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700975};
Duncan Laurie93e24442014-01-06 12:30:52 -0800976
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700977/* Get protocol information */
978#define EC_CMD_GET_PROTOCOL_INFO 0x000B
Duncan Laurie93e24442014-01-06 12:30:52 -0800979
980/* Flags for ec_response_get_protocol_info.flags */
981/* EC_RES_IN_PROGRESS may be returned if a command is slow */
982#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
983
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700984struct __ec_align4 ec_response_get_protocol_info {
Duncan Laurie93e24442014-01-06 12:30:52 -0800985 /* Fields which exist if at least protocol version 3 supported */
986
987 /* Bitmask of protocol versions supported (1 << n means version n)*/
988 uint32_t protocol_versions;
989
990 /* Maximum request packet size, in bytes */
991 uint16_t max_request_packet_size;
992
993 /* Maximum response packet size, in bytes */
994 uint16_t max_response_packet_size;
995
996 /* Flags; see EC_PROTOCOL_INFO_* */
997 uint32_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -0700998};
Duncan Laurie93e24442014-01-06 12:30:52 -0800999
1000
1001/*****************************************************************************/
1002/* Get/Set miscellaneous values */
1003
1004/* The upper byte of .flags tells what to do (nothing means "get") */
1005#define EC_GSV_SET 0x80000000
1006
1007/* The lower three bytes of .flags identifies the parameter, if that has
1008 meaning for an individual command. */
1009#define EC_GSV_PARAM_MASK 0x00ffffff
1010
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001011struct __ec_align4 ec_params_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001012 uint32_t flags;
1013 uint32_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001014};
Duncan Laurie93e24442014-01-06 12:30:52 -08001015
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001016struct __ec_align4 ec_response_get_set_value {
Duncan Laurie93e24442014-01-06 12:30:52 -08001017 uint32_t flags;
1018 uint32_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001019};
Duncan Laurie93e24442014-01-06 12:30:52 -08001020
Duncan Laurieeb316852015-12-01 18:51:18 -08001021/* More than one command can use these structs to get/set parameters. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001022#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
Duncan Laurie93e24442014-01-06 12:30:52 -08001023
Duncan Laurieeb316852015-12-01 18:51:18 -08001024/*****************************************************************************/
1025/* List the features supported by the firmware */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001026#define EC_CMD_GET_FEATURES 0x000D
Duncan Laurieeb316852015-12-01 18:51:18 -08001027
1028/* Supported features */
1029enum ec_feature_code {
1030 /*
1031 * This image contains a limited set of features. Another image
1032 * in RW partition may support more features.
1033 */
1034 EC_FEATURE_LIMITED = 0,
1035 /*
1036 * Commands for probing/reading/writing/erasing the flash in the
1037 * EC are present.
1038 */
1039 EC_FEATURE_FLASH = 1,
1040 /*
1041 * Can control the fan speed directly.
1042 */
1043 EC_FEATURE_PWM_FAN = 2,
1044 /*
1045 * Can control the intensity of the keyboard backlight.
1046 */
1047 EC_FEATURE_PWM_KEYB = 3,
1048 /*
1049 * Support Google lightbar, introduced on Pixel.
1050 */
1051 EC_FEATURE_LIGHTBAR = 4,
1052 /* Control of LEDs */
1053 EC_FEATURE_LED = 5,
1054 /* Exposes an interface to control gyro and sensors.
1055 * The host goes through the EC to access these sensors.
1056 * In addition, the EC may provide composite sensors, like lid angle.
1057 */
1058 EC_FEATURE_MOTION_SENSE = 6,
1059 /* The keyboard is controlled by the EC */
1060 EC_FEATURE_KEYB = 7,
1061 /* The AP can use part of the EC flash as persistent storage. */
1062 EC_FEATURE_PSTORE = 8,
1063 /* The EC monitors BIOS port 80h, and can return POST codes. */
1064 EC_FEATURE_PORT80 = 9,
1065 /*
1066 * Thermal management: include TMP specific commands.
1067 * Higher level than direct fan control.
1068 */
1069 EC_FEATURE_THERMAL = 10,
1070 /* Can switch the screen backlight on/off */
1071 EC_FEATURE_BKLIGHT_SWITCH = 11,
1072 /* Can switch the wifi module on/off */
1073 EC_FEATURE_WIFI_SWITCH = 12,
1074 /* Monitor host events, through for example SMI or SCI */
1075 EC_FEATURE_HOST_EVENTS = 13,
1076 /* The EC exposes GPIO commands to control/monitor connected devices. */
1077 EC_FEATURE_GPIO = 14,
1078 /* The EC can send i2c messages to downstream devices. */
1079 EC_FEATURE_I2C = 15,
1080 /* Command to control charger are included */
1081 EC_FEATURE_CHARGER = 16,
1082 /* Simple battery support. */
1083 EC_FEATURE_BATTERY = 17,
1084 /*
1085 * Support Smart battery protocol
1086 * (Common Smart Battery System Interface Specification)
1087 */
1088 EC_FEATURE_SMART_BATTERY = 18,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001089 /* EC can detect when the host hangs. */
Duncan Laurieeb316852015-12-01 18:51:18 -08001090 EC_FEATURE_HANG_DETECT = 19,
1091 /* Report power information, for pit only */
1092 EC_FEATURE_PMU = 20,
1093 /* Another Cros EC device is present downstream of this one */
1094 EC_FEATURE_SUB_MCU = 21,
1095 /* Support USB Power delivery (PD) commands */
1096 EC_FEATURE_USB_PD = 22,
1097 /* Control USB multiplexer, for audio through USB port for instance. */
1098 EC_FEATURE_USB_MUX = 23,
1099 /* Motion Sensor code has an internal software FIFO */
1100 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1101 /* Support temporary secure vstore */
1102 EC_FEATURE_VSTORE = 25,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001103 /* EC decides on USB-C SS mux state, muxes configured by host */
1104 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1105 /* EC has RTC feature that can be controlled by host commands */
1106 EC_FEATURE_RTC = 27,
1107 /* The MCU exposes a Fingerprint sensor */
1108 EC_FEATURE_FINGERPRINT = 28,
1109 /* The MCU exposes a Touchpad */
1110 EC_FEATURE_TOUCHPAD = 29,
1111 /* The MCU has RWSIG task enabled */
1112 EC_FEATURE_RWSIG = 30,
1113 /* EC has device events support */
1114 EC_FEATURE_DEVICE_EVENT = 31,
Duncan Laurieeb316852015-12-01 18:51:18 -08001115};
1116
1117#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
1118#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001119struct __ec_align4 ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001120 uint32_t flags[2];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001121};
Duncan Laurie433432b2013-06-03 10:38:22 -07001122
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001123/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001124/* Get the board's SKU ID from EC */
1125#define EC_CMD_GET_SKU_ID 0x000E
1126
1127struct __ec_align4 ec_response_sku_id {
1128 uint32_t sku_id;
1129};
1130
1131/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001132/* Flash commands */
1133
1134/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001135#define EC_CMD_FLASH_INFO 0x0010
1136#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001137
Duncan Laurie93e24442014-01-06 12:30:52 -08001138/* Version 0 returns these fields */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001139struct __ec_align4 ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001140 /* Usable flash size, in bytes */
1141 uint32_t flash_size;
1142 /*
1143 * Write block size. Write offset and size must be a multiple
1144 * of this.
1145 */
1146 uint32_t write_block_size;
1147 /*
1148 * Erase block size. Erase offset and size must be a multiple
1149 * of this.
1150 */
1151 uint32_t erase_block_size;
1152 /*
1153 * Protection block size. Protection offset and size must be a
1154 * multiple of this.
1155 */
1156 uint32_t protect_block_size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001157};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001158
Duncan Laurie93e24442014-01-06 12:30:52 -08001159/* Flags for version 1+ flash info command */
1160/* EC flash erases bits to 0 instead of 1 */
1161#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1162
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001163/* Flash must be selected for read/write/erase operations to succeed. This may
1164 * be necessary on a chip where write/erase can be corrupted by other board
1165 * activity, or where the chip needs to enable some sort of programming voltage,
1166 * or where the read/write/erase operations require cleanly suspending other
1167 * chip functionality. */
1168#define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1169
Duncan Laurie93e24442014-01-06 12:30:52 -08001170/*
1171 * Version 1 returns the same initial fields as version 0, with additional
1172 * fields following.
1173 *
1174 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001175 * if they did we'd define the version 0 structure as a sub-structure of this
1176 * one.
1177 *
1178 * Version 2 supports flash banks of different sizes:
1179 * The caller specified the number of banks it has preallocated
1180 * (num_banks_desc)
1181 * The EC returns the number of banks describing the flash memory.
1182 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001183 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001184struct __ec_align4 ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001185 /* Version 0 fields; see above for description */
1186 uint32_t flash_size;
1187 uint32_t write_block_size;
1188 uint32_t erase_block_size;
1189 uint32_t protect_block_size;
1190
1191 /* Version 1 adds these fields: */
1192 /*
1193 * Ideal write size in bytes. Writes will be fastest if size is
1194 * exactly this and offset is a multiple of this. For example, an EC
1195 * may have a write buffer which can do half-page operations if data is
1196 * aligned, and a slower word-at-a-time write mode.
1197 */
1198 uint32_t write_ideal_size;
1199
1200 /* Flags; see EC_FLASH_INFO_* */
1201 uint32_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001202};
1203
1204struct __ec_align4 ec_params_flash_info_2 {
1205 /* Number of banks to describe */
1206 uint16_t num_banks_desc;
1207 /* Reserved; set 0; ignore on read */
1208 uint8_t reserved[2];
1209};
1210
1211struct ec_flash_bank {
1212 /* Number of sector is in this bank. */
1213 uint16_t count;
1214 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1215 uint8_t size_exp;
1216 /* Minimal write size for the sectors in this bank */
1217 uint8_t write_size_exp;
1218 /* Erase size for the sectors in this bank */
1219 uint8_t erase_size_exp;
1220 /* Size for write protection, usually identical to erase size. */
1221 uint8_t protect_size_exp;
1222 /* Reserved; set 0; ignore on read */
1223 uint8_t reserved[2];
1224};
1225
1226struct __ec_align4 ec_response_flash_info_2 {
1227 /* Total flash in the EC. */
1228 uint32_t flash_size;
1229 /* Flags; see EC_FLASH_INFO_* */
1230 uint32_t flags;
1231 /* Maximum size to use to send data to write to the EC. */
1232 uint32_t write_ideal_size;
1233 /* Number of banks present in the EC. */
1234 uint16_t num_banks_total;
1235 /* Number of banks described in banks array. */
1236 uint16_t num_banks_desc;
1237 struct ec_flash_bank banks[0];
1238};
Duncan Laurie93e24442014-01-06 12:30:52 -08001239
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001240/*
1241 * Read flash
1242 *
1243 * Response is params.size bytes of data.
1244 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001245#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001246
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001247struct __ec_align4 ec_params_flash_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001248 uint32_t offset; /* Byte offset to read */
1249 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001250};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001251
1252/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001253#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001254#define EC_VER_FLASH_WRITE 1
1255
1256/* Version 0 of the flash command supported only 64 bytes of data */
1257#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001258
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001259struct __ec_align4 ec_params_flash_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001260 uint32_t offset; /* Byte offset to write */
1261 uint32_t size; /* Size to write in bytes */
Duncan Laurie93e24442014-01-06 12:30:52 -08001262 /* Followed by data to write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001263};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001264
1265/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001266#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001267
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001268/* v0 */
1269struct __ec_align4 ec_params_flash_erase {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001270 uint32_t offset; /* Byte offset to erase */
1271 uint32_t size; /* Size to erase in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001272};
1273
1274
1275#define EC_VER_FLASH_WRITE 1
1276/* v1 add async erase:
1277 * subcommands can returns:
1278 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1279 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1280 * EC_RES_ERROR : other errors.
1281 * EC_RES_BUSY : an existing erase operation is in progress.
1282 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1283 *
1284 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1285 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1286 * the proper result.
1287 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1288 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1289 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1290 * permitted while erasing. (For instance, STM32F4).
1291 */
1292enum ec_flash_erase_cmd {
1293 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1294 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1295 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1296};
1297
1298struct __ec_align4 ec_params_flash_erase_v1 {
1299 /* One of ec_flash_erase_cmd. */
1300 uint8_t cmd;
1301 /* Pad byte; currently always contains 0 */
1302 uint8_t reserved;
1303 /* No flags defined yet; set to 0 */
1304 uint16_t flag;
1305 /* Same as v0 parameters. */
1306 struct ec_params_flash_erase params;
1307};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001308
1309/*
1310 * Get/set flash protection.
1311 *
1312 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1313 * firmware write protect GPIO, not all flags will take effect immediately;
1314 * some flags require a subsequent hard reset to take effect. Check the
1315 * returned flags bits to see what actually happened.
1316 *
1317 * If mask=0, simply returns the current flags state.
1318 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001319#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001320#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1321
1322/* Flags for flash protection */
1323/* RO flash code protected when the EC boots */
1324#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1325/*
1326 * RO flash code protected now. If this bit is set, at-boot status cannot
1327 * be changed.
1328 */
1329#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001330/* Entire flash code protected now, until reboot. */
1331#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001332/* Flash write protect GPIO is asserted now */
1333#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1334/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1335#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1336/*
1337 * Error - flash protection is in inconsistent state. At least one bank of
1338 * flash which should be protected is not protected. Usually fixed by
1339 * re-requesting the desired flags, or by a hard reset if that fails.
1340 */
1341#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001342/* Entire flash code protected when the EC boots */
Duncan Laurie433432b2013-06-03 10:38:22 -07001343#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001344/* RW flash code protected when the EC boots */
1345#define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
1346/* RW flash code protected now. */
1347#define EC_FLASH_PROTECT_RW_NOW (1 << 8)
1348/* Rollback information flash region protected when the EC boots */
1349#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
1350/* Rollback information flash region protected now */
1351#define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001352
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001353struct __ec_align4 ec_params_flash_protect {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001354 uint32_t mask; /* Bits in flags to apply */
1355 uint32_t flags; /* New flags to apply */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001356};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001357
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001358struct __ec_align4 ec_response_flash_protect {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001359 /* Current value of flash protect flags */
1360 uint32_t flags;
1361 /*
1362 * Flags which are valid on this platform. This allows the caller
1363 * to distinguish between flags which aren't set vs. flags which can't
1364 * be set on this platform.
1365 */
1366 uint32_t valid_flags;
1367 /* Flags which can be changed given the current protection state */
1368 uint32_t writable_flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001369};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001370
1371/*
1372 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1373 * write protect. These commands may be reused with version > 0.
1374 */
1375
1376/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001377#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001378#define EC_VER_FLASH_REGION_INFO 1
1379
1380enum ec_flash_region {
1381 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001382 EC_FLASH_REGION_RO = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001383 /* Region which holds rewritable EC image */
1384 EC_FLASH_REGION_RW,
1385 /*
1386 * Region which should be write-protected in the factory (a superset of
1387 * EC_FLASH_REGION_RO)
1388 */
1389 EC_FLASH_REGION_WP_RO,
Duncan Laurie93e24442014-01-06 12:30:52 -08001390 /* Number of regions */
1391 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001392};
1393
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001394struct __ec_align4 ec_params_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001395 uint32_t region; /* enum ec_flash_region */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001396};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001397
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001398struct __ec_align4 ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001399 uint32_t offset;
1400 uint32_t size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001401};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001402
Duncan Laurie433432b2013-06-03 10:38:22 -07001403/* Read/write VbNvContext */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001404#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001405#define EC_VER_VBNV_CONTEXT 1
1406#define EC_VBNV_BLOCK_SIZE 16
1407
1408enum ec_vbnvcontext_op {
1409 EC_VBNV_CONTEXT_OP_READ,
1410 EC_VBNV_CONTEXT_OP_WRITE,
1411};
1412
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001413struct __ec_align4 ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001414 uint32_t op;
1415 uint8_t block[EC_VBNV_BLOCK_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001416};
Duncan Laurie433432b2013-06-03 10:38:22 -07001417
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001418struct __ec_align4 ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001419 uint8_t block[EC_VBNV_BLOCK_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001420};
1421
1422
1423/* Get SPI flash information */
1424#define EC_CMD_FLASH_SPI_INFO 0x0018
1425
1426struct __ec_align1 ec_response_flash_spi_info {
1427 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1428 uint8_t jedec[3];
1429
1430 /* Pad byte; currently always contains 0 */
1431 uint8_t reserved0;
1432
1433 /* Manufacturer / device ID from command 0x90 */
1434 uint8_t mfr_dev_id[2];
1435
1436 /* Status registers from command 0x05 and 0x35 */
1437 uint8_t sr1, sr2;
1438};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001439
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001440
1441/* Select flash during flash operations */
1442#define EC_CMD_FLASH_SELECT 0x0019
1443
1444struct __ec_align4 ec_params_flash_select {
1445 /* 1 to select flash, 0 to deselect flash */
1446 uint8_t select;
1447};
1448
1449
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001450/*****************************************************************************/
1451/* PWM commands */
1452
1453/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001454#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001455
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001456struct __ec_align4 ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001457 uint32_t rpm;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001458};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001459
1460/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001461#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001462
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001463/* Version 0 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001464struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001465 uint32_t rpm;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001466};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001467
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001468/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001469struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001470 uint32_t rpm;
1471 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001472};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001473
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001474/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001475/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001476#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001477
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001478struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001479 uint8_t percent;
1480 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001481};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001482
1483/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001484/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001485#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001486
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001487struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001488 uint8_t percent;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001489};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001490
1491/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001492#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001493
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001494/* Version 0 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001495struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001496 uint32_t percent;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001497};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001498
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001499/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001500struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001501 uint32_t percent;
1502 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001503};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001504
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001505#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07001506/* 16 bit duty cycle, 0xffff = 100% */
1507#define EC_PWM_MAX_DUTY 0xffff
1508
1509enum ec_pwm_type {
1510 /* All types, indexed by board-specific enum pwm_channel */
1511 EC_PWM_TYPE_GENERIC = 0,
1512 /* Keyboard backlight */
1513 EC_PWM_TYPE_KB_LIGHT,
1514 /* Display backlight */
1515 EC_PWM_TYPE_DISPLAY_LIGHT,
1516 EC_PWM_TYPE_COUNT,
1517};
1518
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001519struct __ec_align4 ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001520 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1521 uint8_t pwm_type; /* ec_pwm_type */
1522 uint8_t index; /* Type-specific index, or 0 if unique */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001523};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001524
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001525#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07001526
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001527struct __ec_align1 ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001528 uint8_t pwm_type; /* ec_pwm_type */
1529 uint8_t index; /* Type-specific index, or 0 if unique */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001530};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001531
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001532struct __ec_align2 ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001533 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001534};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001535
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001536/*****************************************************************************/
1537/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001538 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001539 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1540 * into a subcommand. We'll make separate structs for subcommands with
1541 * different input args, so that we know how much to expect.
1542 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001543#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001544
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001545struct __ec_todo_unpacked rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07001546 uint8_t r, g, b;
1547};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001548
Duncan Laurie433432b2013-06-03 10:38:22 -07001549#define LB_BATTERY_LEVELS 4
1550/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1551 * host command, but the alignment is the same regardless. Keep it that way.
1552 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001553struct __ec_todo_packed lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001554 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001555 int32_t google_ramp_up;
1556 int32_t google_ramp_down;
1557 int32_t s3s0_ramp_up;
1558 int32_t s0_tick_delay[2]; /* AC=0/1 */
1559 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1560 int32_t s0s3_ramp_down;
1561 int32_t s3_sleep_for;
1562 int32_t s3_ramp_up;
1563 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001564
1565 /* Oscillation */
1566 uint8_t new_s0;
1567 uint8_t osc_min[2]; /* AC=0/1 */
1568 uint8_t osc_max[2]; /* AC=0/1 */
1569 uint8_t w_ofs[2]; /* AC=0/1 */
1570
1571 /* Brightness limits based on the backlight and AC. */
1572 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1573 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1574 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1575
1576 /* Battery level thresholds */
1577 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1578
1579 /* Map [AC][battery_level] to color index */
1580 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1581 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1582
1583 /* Color palette */
1584 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001585};
Duncan Laurie433432b2013-06-03 10:38:22 -07001586
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001587struct __ec_todo_packed lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001588 /* Timing */
1589 int32_t google_ramp_up;
1590 int32_t google_ramp_down;
1591 int32_t s3s0_ramp_up;
1592 int32_t s0_tick_delay[2]; /* AC=0/1 */
1593 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1594 int32_t s0s3_ramp_down;
1595 int32_t s3_sleep_for;
1596 int32_t s3_ramp_up;
1597 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001598 int32_t s5_ramp_up;
1599 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001600 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001601 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001602 int32_t tap_display_time;
1603
1604 /* Tap-for-battery params */
1605 uint8_t tap_pct_red;
1606 uint8_t tap_pct_green;
1607 uint8_t tap_seg_min_on;
1608 uint8_t tap_seg_max_on;
1609 uint8_t tap_seg_osc;
1610 uint8_t tap_idx[3];
1611
1612 /* Oscillation */
1613 uint8_t osc_min[2]; /* AC=0/1 */
1614 uint8_t osc_max[2]; /* AC=0/1 */
1615 uint8_t w_ofs[2]; /* AC=0/1 */
1616
1617 /* Brightness limits based on the backlight and AC. */
1618 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1619 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1620 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1621
1622 /* Battery level thresholds */
1623 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1624
1625 /* Map [AC][battery_level] to color index */
1626 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1627 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1628
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001629 /* s5: single color pulse on inhibited power-up */
1630 uint8_t s5_idx;
1631
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001632 /* Color palette */
1633 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001634};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001635
Duncan Laurieeb316852015-12-01 18:51:18 -08001636/* Lightbar command params v2
1637 * crbug.com/467716
1638 *
1639 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1640 * logical groups to make it more manageable ( < 120 bytes).
1641 *
1642 * NOTE: Each of these groups must be less than 120 bytes.
1643 */
1644
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001645struct __ec_todo_packed lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08001646 /* Timing */
1647 int32_t google_ramp_up;
1648 int32_t google_ramp_down;
1649 int32_t s3s0_ramp_up;
1650 int32_t s0_tick_delay[2]; /* AC=0/1 */
1651 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1652 int32_t s0s3_ramp_down;
1653 int32_t s3_sleep_for;
1654 int32_t s3_ramp_up;
1655 int32_t s3_ramp_down;
1656 int32_t s5_ramp_up;
1657 int32_t s5_ramp_down;
1658 int32_t tap_tick_delay;
1659 int32_t tap_gate_delay;
1660 int32_t tap_display_time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001661};
Duncan Laurieeb316852015-12-01 18:51:18 -08001662
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001663struct __ec_todo_packed lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08001664 /* Tap-for-battery params */
1665 uint8_t tap_pct_red;
1666 uint8_t tap_pct_green;
1667 uint8_t tap_seg_min_on;
1668 uint8_t tap_seg_max_on;
1669 uint8_t tap_seg_osc;
1670 uint8_t tap_idx[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001671};
Duncan Laurieeb316852015-12-01 18:51:18 -08001672
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001673struct __ec_todo_packed lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08001674 /* Oscillation */
1675 uint8_t osc_min[2]; /* AC=0/1 */
1676 uint8_t osc_max[2]; /* AC=0/1 */
1677 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001678};
Duncan Laurieeb316852015-12-01 18:51:18 -08001679
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001680struct __ec_todo_packed lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08001681 /* Brightness limits based on the backlight and AC. */
1682 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1683 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1684 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001685};
Duncan Laurieeb316852015-12-01 18:51:18 -08001686
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001687struct __ec_todo_packed lightbar_params_v2_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08001688 /* Battery level thresholds */
1689 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001690};
Duncan Laurieeb316852015-12-01 18:51:18 -08001691
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001692struct __ec_todo_packed lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08001693 /* Map [AC][battery_level] to color index */
1694 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1695 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1696
1697 /* s5: single color pulse on inhibited power-up */
1698 uint8_t s5_idx;
1699
1700 /* Color palette */
1701 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001702};
Duncan Laurieeb316852015-12-01 18:51:18 -08001703
Duncan Lauried8401182014-09-29 08:32:19 -07001704/* Lightbyte program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001705#define EC_LB_PROG_LEN 192
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001706struct __ec_todo_unpacked lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07001707 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001708 uint8_t data[EC_LB_PROG_LEN];
Duncan Lauried8401182014-09-29 08:32:19 -07001709};
1710
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001711struct __ec_todo_packed ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07001712 uint8_t cmd; /* Command (see enum lightbar_command) */
1713 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001714 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001715 /* no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001716 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001717 version, get_brightness, get_demo, suspend, resume,
1718 get_params_v2_timing, get_params_v2_tap,
1719 get_params_v2_osc, get_params_v2_bright,
1720 get_params_v2_thlds, get_params_v2_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001721
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001722 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001723 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001724 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001725
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001726 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001727 uint8_t ctrl, reg, value;
1728 } reg;
1729
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001730 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001731 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001732 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07001733
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001734 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001735 uint8_t led;
1736 } get_rgb;
1737
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001738 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001739 uint8_t enable;
1740 } manual_suspend_ctrl;
1741
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001742 struct lightbar_params_v0 set_params_v0;
1743 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08001744
1745 struct lightbar_params_v2_timing set_v2par_timing;
1746 struct lightbar_params_v2_tap set_v2par_tap;
1747 struct lightbar_params_v2_oscillation set_v2par_osc;
1748 struct lightbar_params_v2_brightness set_v2par_bright;
1749 struct lightbar_params_v2_thresholds set_v2par_thlds;
1750 struct lightbar_params_v2_colors set_v2par_colors;
1751
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001752 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001753 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001754};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001755
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001756struct __ec_todo_packed ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07001757 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001758 struct __ec_todo_unpacked {
1759 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001760 uint8_t reg;
1761 uint8_t ic0;
1762 uint8_t ic1;
1763 } vals[23];
1764 } dump;
1765
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001766 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001767 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001768 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001769
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001770 struct lightbar_params_v0 get_params_v0;
1771 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07001772
Duncan Laurieeb316852015-12-01 18:51:18 -08001773
1774 struct lightbar_params_v2_timing get_params_v2_timing;
1775 struct lightbar_params_v2_tap get_params_v2_tap;
1776 struct lightbar_params_v2_oscillation get_params_v2_osc;
1777 struct lightbar_params_v2_brightness get_params_v2_bright;
1778 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1779 struct lightbar_params_v2_colors get_params_v2_colors;
1780
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001781 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08001782 uint32_t num;
1783 uint32_t flags;
1784 } version;
1785
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001786 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001787 uint8_t red, green, blue;
1788 } get_rgb;
1789
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001790 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001791 /* no return params */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001792 } off, on, init, set_brightness, seq, reg, set_rgb,
Duncan Lauried8401182014-09-29 08:32:19 -07001793 demo, set_params_v0, set_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001794 set_program, manual_suspend_ctrl, suspend, resume,
1795 set_v2par_timing, set_v2par_tap,
1796 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1797 set_v2par_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001798 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001799};
Duncan Laurie433432b2013-06-03 10:38:22 -07001800
1801/* Lightbar commands */
1802enum lightbar_command {
1803 LIGHTBAR_CMD_DUMP = 0,
1804 LIGHTBAR_CMD_OFF = 1,
1805 LIGHTBAR_CMD_ON = 2,
1806 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001807 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07001808 LIGHTBAR_CMD_SEQ = 5,
1809 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001810 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07001811 LIGHTBAR_CMD_GET_SEQ = 8,
1812 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001813 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1814 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08001815 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001816 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1817 LIGHTBAR_CMD_GET_RGB = 14,
1818 LIGHTBAR_CMD_GET_DEMO = 15,
1819 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1820 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07001821 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001822 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1823 LIGHTBAR_CMD_SUSPEND = 20,
1824 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08001825 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1826 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1827 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1828 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1829 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1830 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1831 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1832 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1833 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1834 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1835 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1836 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07001837 LIGHTBAR_NUM_CMDS
1838};
1839
1840/*****************************************************************************/
1841/* LED control commands */
1842
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001843#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07001844
Bill Richardsone221aad2013-06-12 10:50:41 -07001845enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08001846 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07001847 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08001848 /*
1849 * LED to indicate system power state (on or in suspend).
1850 * May be on power button or on C-panel.
1851 */
1852 EC_LED_ID_POWER_LED,
1853 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07001854 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001855 /* LED to indicate left side */
1856 EC_LED_ID_LEFT_LED,
1857 /* LED to indicate right side */
1858 EC_LED_ID_RIGHT_LED,
1859 /* LED to indicate recovery mode with HW_REINIT */
1860 EC_LED_ID_RECOVERY_HW_REINIT_LED,
1861 /* LED to indicate sysrq debug mode. */
1862 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08001863
1864 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07001865};
Duncan Laurie433432b2013-06-03 10:38:22 -07001866
Bill Richardsone221aad2013-06-12 10:50:41 -07001867/* LED control flags */
1868#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1869#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1870
1871enum ec_led_colors {
1872 EC_LED_COLOR_RED = 0,
1873 EC_LED_COLOR_GREEN,
1874 EC_LED_COLOR_BLUE,
1875 EC_LED_COLOR_YELLOW,
1876 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08001877 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07001878
1879 EC_LED_COLOR_COUNT
1880};
1881
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001882struct __ec_align1 ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07001883 uint8_t led_id; /* Which LED to control */
1884 uint8_t flags; /* Control flags */
1885
1886 uint8_t brightness[EC_LED_COLOR_COUNT];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001887};
Bill Richardsone221aad2013-06-12 10:50:41 -07001888
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001889struct __ec_align1 ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07001890 /*
1891 * Available brightness value range.
1892 *
1893 * Range 0 means color channel not present.
1894 * Range 1 means on/off control.
1895 * Other values means the LED is control by PWM.
1896 */
1897 uint8_t brightness_range[EC_LED_COLOR_COUNT];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001898};
Duncan Laurie433432b2013-06-03 10:38:22 -07001899
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001900/*****************************************************************************/
1901/* Verified boot commands */
1902
1903/*
1904 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1905 * reused for other purposes with version > 0.
1906 */
1907
1908/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001909#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001910
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001911struct __ec_align4 ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001912 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1913 uint8_t hash_type; /* enum ec_vboot_hash_type */
1914 uint8_t nonce_size; /* Nonce size; may be 0 */
1915 uint8_t reserved0; /* Reserved; set 0 */
1916 uint32_t offset; /* Offset in flash to hash */
1917 uint32_t size; /* Number of bytes to hash */
1918 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001919};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001920
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001921struct __ec_align4 ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001922 uint8_t status; /* enum ec_vboot_hash_status */
1923 uint8_t hash_type; /* enum ec_vboot_hash_type */
1924 uint8_t digest_size; /* Size of hash digest in bytes */
1925 uint8_t reserved0; /* Ignore; will be 0 */
1926 uint32_t offset; /* Offset in flash which was hashed */
1927 uint32_t size; /* Number of bytes hashed */
1928 uint8_t hash_digest[64]; /* Hash digest data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001929};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001930
1931enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07001932 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1933 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1934 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1935 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001936};
1937
1938enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07001939 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001940};
1941
1942enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001943 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1944 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1945 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001946};
1947
Duncan Laurie433432b2013-06-03 10:38:22 -07001948/*
1949 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1950 * If one of these is specified, the EC will automatically update offset and
1951 * size to the correct values for the specified image (RO or RW).
1952 */
1953#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1954#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1955
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001956/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001957/*
1958 * Motion sense commands. We'll make separate structs for sub-commands with
1959 * different input args, so that we know how much to expect.
1960 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001961#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001962
1963/* Motion sense commands */
1964enum motionsense_command {
1965 /*
1966 * Dump command returns all motion sensor data including motion sense
1967 * module flags and individual sensor flags.
1968 */
1969 MOTIONSENSE_CMD_DUMP = 0,
1970
1971 /*
1972 * Info command returns data describing the details of a given sensor,
1973 * including enum motionsensor_type, enum motionsensor_location, and
1974 * enum motionsensor_chip.
1975 */
1976 MOTIONSENSE_CMD_INFO = 1,
1977
1978 /*
1979 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08001980 * in milliseconds.
1981 * It is per sensor, the EC run sample task at the minimum of all
1982 * sensors EC_RATE.
1983 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
1984 * to collect all the sensor samples.
1985 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
1986 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001987 */
1988 MOTIONSENSE_CMD_EC_RATE = 2,
1989
1990 /*
1991 * Sensor ODR command is a setter/getter command for the output data
1992 * rate of a specific motion sensor in millihertz.
1993 */
1994 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1995
1996 /*
1997 * Sensor range command is a setter/getter command for the range of
1998 * a specified motion sensor in +/-G's or +/- deg/s.
1999 */
2000 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2001
2002 /*
2003 * Setter/getter command for the keyboard wake angle. When the lid
2004 * angle is greater than this value, keyboard wake is disabled in S3,
2005 * and when the lid angle goes less than this value, keyboard wake is
2006 * enabled. Note, the lid angle measurement is an approximate,
2007 * un-calibrated value, hence the wake angle isn't exact.
2008 */
2009 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2010
Duncan Laurieeb316852015-12-01 18:51:18 -08002011 /*
2012 * Returns a single sensor data.
2013 */
2014 MOTIONSENSE_CMD_DATA = 6,
2015
2016 /*
2017 * Return sensor fifo info.
2018 */
2019 MOTIONSENSE_CMD_FIFO_INFO = 7,
2020
2021 /*
2022 * Insert a flush element in the fifo and return sensor fifo info.
2023 * The host can use that element to synchronize its operation.
2024 */
2025 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2026
2027 /*
2028 * Return a portion of the fifo.
2029 */
2030 MOTIONSENSE_CMD_FIFO_READ = 9,
2031
2032 /*
2033 * Perform low level calibration.
2034 * On sensors that support it, ask to do offset calibration.
2035 */
2036 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2037
2038 /*
2039 * Sensor Offset command is a setter/getter command for the offset
2040 * used for calibration.
2041 * The offsets can be calculated by the host, or via
2042 * PERFORM_CALIB command.
2043 */
2044 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2045
2046 /*
2047 * List available activities for a MOTION sensor.
2048 * Indicates if they are enabled or disabled.
2049 */
2050 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2051
2052 /*
2053 * Activity management
2054 * Enable/Disable activity recognition.
2055 */
2056 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2057
2058 /*
2059 * Lid Angle
2060 */
2061 MOTIONSENSE_CMD_LID_ANGLE = 14,
2062
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002063 /*
2064 * Allow the FIFO to trigger interrupt via MKBP events.
2065 * By default the FIFO does not send interrupt to process the FIFO
2066 * until the AP is ready or it is coming from a wakeup sensor.
2067 */
2068 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2069
2070 /*
2071 * Spoof the readings of the sensors. The spoofed readings can be set
2072 * to arbitrary values, or will lock to the last read actual values.
2073 */
2074 MOTIONSENSE_CMD_SPOOF = 16,
2075
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002076 /* Number of motionsense sub-commands. */
2077 MOTIONSENSE_NUM_CMDS
2078};
2079
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002080/* List of motion sensor types. */
2081enum motionsensor_type {
2082 MOTIONSENSE_TYPE_ACCEL = 0,
2083 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002084 MOTIONSENSE_TYPE_MAG = 2,
2085 MOTIONSENSE_TYPE_PROX = 3,
2086 MOTIONSENSE_TYPE_LIGHT = 4,
2087 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002088 MOTIONSENSE_TYPE_BARO = 6,
Duncan Laurieeb316852015-12-01 18:51:18 -08002089 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002090};
2091
2092/* List of motion sensor locations. */
2093enum motionsensor_location {
2094 MOTIONSENSE_LOC_BASE = 0,
2095 MOTIONSENSE_LOC_LID = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002096 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002097};
2098
2099/* List of motion sensor chips. */
2100enum motionsensor_chip {
2101 MOTIONSENSE_CHIP_KXCJ9 = 0,
2102 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002103 MOTIONSENSE_CHIP_BMI160 = 2,
2104 MOTIONSENSE_CHIP_SI1141 = 3,
2105 MOTIONSENSE_CHIP_SI1142 = 4,
2106 MOTIONSENSE_CHIP_SI1143 = 5,
2107 MOTIONSENSE_CHIP_KX022 = 6,
2108 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002109 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002110 MOTIONSENSE_CHIP_BMP280 = 9,
2111 MOTIONSENSE_CHIP_OPT3001 = 10,
Duncan Laurieeb316852015-12-01 18:51:18 -08002112};
2113
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002114struct __ec_todo_packed ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002115 /* Flags for each sensor. */
2116 uint8_t flags;
2117 /* sensor number the data comes from */
2118 uint8_t sensor_num;
2119 /* Each sensor is up to 3-axis. */
2120 union {
2121 int16_t data[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002122 struct __ec_todo_packed {
2123 uint16_t reserved;
Duncan Laurieeb316852015-12-01 18:51:18 -08002124 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002125 };
2126 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002127 uint8_t activity; /* motionsensor_activity */
2128 uint8_t state;
2129 int16_t add_info[2];
2130 };
2131 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002132};
Duncan Laurieeb316852015-12-01 18:51:18 -08002133
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002134/* Note: used in ec_response_get_next_data */
2135struct __ec_todo_packed ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002136 /* Size of the fifo */
2137 uint16_t size;
2138 /* Amount of space used in the fifo */
2139 uint16_t count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002140 /* Timestamp recorded in us */
Duncan Laurieeb316852015-12-01 18:51:18 -08002141 uint32_t timestamp;
2142 /* Total amount of vector lost */
2143 uint16_t total_lost;
2144 /* Lost events since the last fifo_info, per sensors */
2145 uint16_t lost[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002146};
Duncan Laurieeb316852015-12-01 18:51:18 -08002147
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002148struct __ec_todo_packed ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002149 uint32_t number_data;
2150 struct ec_response_motion_sensor_data data[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002151};
Duncan Laurieeb316852015-12-01 18:51:18 -08002152
2153/* List supported activity recognition */
2154enum motionsensor_activity {
2155 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2156 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2157 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2158};
2159
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002160struct __ec_todo_unpacked ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002161 uint8_t sensor_num;
2162 uint8_t activity; /* one of enum motionsensor_activity */
2163 uint8_t enable; /* 1: enable, 0: disable */
2164 uint8_t reserved;
2165 uint16_t parameters[3]; /* activity dependent parameters */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002166};
2167
2168/* Module flag masks used for the dump sub-command. */
2169#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2170
2171/* Sensor flag masks used for the dump sub-command. */
2172#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2173
2174/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002175 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002176 * data contains time stamp
2177 */
2178#define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2179#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2180#define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002181#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
Duncan Laurieeb316852015-12-01 18:51:18 -08002182
2183/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002184 * Send this value for the data element to only perform a read. If you
2185 * send any other value, the EC will interpret it as data to set and will
2186 * return the actual value set.
2187 */
2188#define EC_MOTION_SENSE_NO_VALUE -1
2189
Duncan Laurieeb316852015-12-01 18:51:18 -08002190#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2191
2192/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2193/* Set Calibration information */
2194#define MOTION_SENSE_SET_OFFSET 1
2195
2196#define LID_ANGLE_UNRELIABLE 500
2197
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002198enum motionsense_spoof_mode {
2199 /* Disable spoof mode. */
2200 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2201
2202 /* Enable spoof mode, but use provided component values. */
2203 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2204
2205 /* Enable spoof mode, but use the current sensor values. */
2206 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2207
2208 /* Query the current spoof mode status for the sensor. */
2209 MOTIONSENSE_SPOOF_MODE_QUERY,
2210};
2211
2212struct __ec_todo_packed ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002213 uint8_t cmd;
2214 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002215 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002216 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002217 /*
2218 * Maximal number of sensor the host is expecting.
2219 * 0 means the host is only interested in the number
2220 * of sensors controlled by the EC.
2221 */
2222 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002223 } dump;
2224
2225 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002226 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002227 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002228 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002229 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2230 * kb_wake_angle: angle to wakup AP.
2231 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002232 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002233 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002234
Duncan Laurieeb316852015-12-01 18:51:18 -08002235 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2236 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002237 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002238 uint8_t sensor_num;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002239 } info, info_3, data, fifo_flush, perform_calib,
2240 list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002241
2242 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002243 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2244 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002245 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002246 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002247 uint8_t sensor_num;
2248
2249 /* Rounding flag, true for round-up, false for down. */
2250 uint8_t roundup;
2251
2252 uint16_t reserved;
2253
2254 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2255 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002256 } ec_rate, sensor_odr, sensor_range;
2257
2258 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002259 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002260 uint8_t sensor_num;
2261
2262 /*
2263 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2264 * the calibration information in the EC.
2265 * If unset, just retrieve calibration information.
2266 */
2267 uint16_t flags;
2268
2269 /*
2270 * Temperature at calibration, in units of 0.01 C
2271 * 0x8000: invalid / unknown.
2272 * 0x0: 0C
2273 * 0x7fff: +327.67C
2274 */
2275 int16_t temp;
2276
2277 /*
2278 * Offset for calibration.
2279 * Unit:
2280 * Accelerometer: 1/1024 g
2281 * Gyro: 1/1024 deg/s
2282 * Compass: 1/16 uT
2283 */
2284 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002285 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002286
2287 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002288 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002289 } fifo_info;
2290
2291 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002292 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002293 /*
2294 * Number of expected vector to return.
2295 * EC may return less or 0 if none available.
2296 */
2297 uint32_t max_data_vector;
2298 } fifo_read;
2299
2300 struct ec_motion_sense_activity set_activity;
2301
2302 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002303 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002304 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002305
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002306 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2307 struct __ec_todo_unpacked {
2308 /*
2309 * 1: enable, 0 disable fifo,
2310 * EC_MOTION_SENSE_NO_VALUE return value.
2311 */
2312 int8_t enable;
2313 } fifo_int_enable;
2314
2315 /* Used for MOTIONSENSE_CMD_SPOOF */
2316 struct __ec_todo_packed {
2317 uint8_t sensor_id;
2318
2319 /* See enum motionsense_spoof_mode. */
2320 uint8_t spoof_enable;
2321
2322 /* Ignored, used for alignment. */
2323 uint8_t reserved;
2324
2325 /* Individual component values to spoof. */
2326 int16_t components[3];
2327 } spoof;
2328 };
2329};
2330
2331struct __ec_todo_packed ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002332 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002333 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002334 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002335 /* Flags representing the motion sensor module. */
2336 uint8_t module_flags;
2337
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002338 /* Number of sensors managed directly by the EC */
2339 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002340
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002341 /*
2342 * sensor data is truncated if response_max is too small
2343 * for holding all the data.
2344 */
2345 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002346 } dump;
2347
2348 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002349 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002350 /* Should be element of enum motionsensor_type. */
2351 uint8_t type;
2352
2353 /* Should be element of enum motionsensor_location. */
2354 uint8_t location;
2355
2356 /* Should be element of enum motionsensor_chip. */
2357 uint8_t chip;
2358 } info;
2359
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002360 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2361 struct __ec_todo_unpacked {
2362 /* Should be element of enum motionsensor_type. */
2363 uint8_t type;
2364
2365 /* Should be element of enum motionsensor_location. */
2366 uint8_t location;
2367
2368 /* Should be element of enum motionsensor_chip. */
2369 uint8_t chip;
2370
2371 /* Minimum sensor sampling frequency */
2372 uint32_t min_frequency;
2373
2374 /* Maximum sensor sampling frequency */
2375 uint32_t max_frequency;
2376
2377 /* Max number of sensor events that could be in fifo */
2378 uint32_t fifo_max_event_count;
2379 } info_3;
2380
Duncan Laurieeb316852015-12-01 18:51:18 -08002381 /* Used for MOTIONSENSE_CMD_DATA */
2382 struct ec_response_motion_sensor_data data;
2383
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002384 /*
2385 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002386 * MOTIONSENSE_CMD_SENSOR_RANGE,
2387 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2388 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2389 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002390 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002391 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002392 /* Current value of the parameter queried. */
2393 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002394 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2395 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08002396
2397 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002398 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002399 int16_t temp;
2400 int16_t offset[3];
2401 } sensor_offset, perform_calib;
2402
2403 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2404
2405 struct ec_response_motion_sense_fifo_data fifo_read;
2406
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002407 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002408 uint16_t reserved;
2409 uint32_t enabled;
2410 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002411 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08002412
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002413 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002414 } set_activity;
2415
Duncan Laurieeb316852015-12-01 18:51:18 -08002416 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002417 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002418 /*
2419 * Angle between 0 and 360 degree if available,
2420 * LID_ANGLE_UNRELIABLE otherwise.
2421 */
2422 uint16_t value;
2423 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002424 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002425};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002426
2427/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002428/* Force lid open command */
2429
2430/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002431#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002432
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002433struct __ec_align1 ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002434 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002435};
2436
2437/*****************************************************************************/
2438/* Configure the behavior of the power button */
2439#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2440
2441enum ec_config_power_button_flags {
2442 /* Enable/Disable power button pulses for x86 devices */
2443 EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2444};
2445
2446struct __ec_align1 ec_params_config_power_button {
2447 /* See enum ec_config_power_button_flags */
2448 uint8_t flags;
2449};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002450
2451/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002452/* USB charging control commands */
2453
2454/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002455#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002456
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002457struct __ec_align1 ec_params_usb_charge_set_mode {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002458 uint8_t usb_port_id;
2459 uint8_t mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002460};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002461
2462/*****************************************************************************/
2463/* Persistent storage for host */
2464
2465/* Maximum bytes that can be read/written in a single command */
2466#define EC_PSTORE_SIZE_MAX 64
2467
2468/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002469#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002470
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002471struct __ec_align4 ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002472 /* Persistent storage size, in bytes */
2473 uint32_t pstore_size;
2474 /* Access size; read/write offset and size must be a multiple of this */
2475 uint32_t access_size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002476};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002477
2478/*
2479 * Read persistent storage
2480 *
2481 * Response is params.size bytes of data.
2482 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002483#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002484
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002485struct __ec_align4 ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002486 uint32_t offset; /* Byte offset to read */
2487 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002488};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002489
2490/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002491#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002492
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002493struct __ec_align4 ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002494 uint32_t offset; /* Byte offset to write */
2495 uint32_t size; /* Size to write in bytes */
2496 uint8_t data[EC_PSTORE_SIZE_MAX];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002497};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002498
2499/*****************************************************************************/
2500/* Real-time clock */
2501
2502/* RTC params and response structures */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002503struct __ec_align4 ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002504 uint32_t time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002505};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002506
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002507struct __ec_align4 ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002508 uint32_t time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002509};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002510
2511/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002512#define EC_CMD_RTC_GET_VALUE 0x0044
2513#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002514
2515/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002516#define EC_CMD_RTC_SET_VALUE 0x0046
2517#define EC_CMD_RTC_SET_ALARM 0x0047
2518
2519/* Pass as time param to SET_ALARM to clear the current alarm */
2520#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002521
2522/*****************************************************************************/
2523/* Port80 log access */
2524
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002525/* Maximum entries that can be read/written in a single command */
2526#define EC_PORT80_SIZE_MAX 32
2527
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002528/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002529#define EC_CMD_PORT80_LAST_BOOT 0x0048
2530#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002531
2532enum ec_port80_subcmd {
2533 EC_PORT80_GET_INFO = 0,
2534 EC_PORT80_READ_BUFFER,
2535};
2536
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002537struct __ec_todo_packed ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002538 uint16_t subcmd;
2539 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002540 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002541 uint32_t offset;
2542 uint32_t num_entries;
2543 } read_buffer;
2544 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002545};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002546
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002547struct __ec_todo_packed ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002548 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002549 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002550 uint32_t writes;
2551 uint32_t history_size;
2552 uint32_t last_boot;
2553 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002554 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002555 uint16_t codes[EC_PORT80_SIZE_MAX];
2556 } data;
2557 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002558};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002559
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002560struct __ec_align2 ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002561 uint16_t code;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002562};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002563
2564/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08002565/* Temporary secure storage for host verified boot use */
2566
2567/* Number of bytes in a vstore slot */
2568#define EC_VSTORE_SLOT_SIZE 64
2569
2570/* Maximum number of vstore slots */
2571#define EC_VSTORE_SLOT_MAX 32
2572
2573/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002574#define EC_CMD_VSTORE_INFO 0x0049
2575struct __ec_align_size1 ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002576 /* Indicates which slots are locked */
2577 uint32_t slot_locked;
2578 /* Total number of slots available */
2579 uint8_t slot_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002580};
Duncan Laurieeb316852015-12-01 18:51:18 -08002581
2582/*
2583 * Read temporary secure storage
2584 *
2585 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2586 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002587#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08002588
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002589struct __ec_align1 ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08002590 uint8_t slot; /* Slot to read from */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002591};
Duncan Laurieeb316852015-12-01 18:51:18 -08002592
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002593struct __ec_align1 ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08002594 uint8_t data[EC_VSTORE_SLOT_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002595};
Duncan Laurieeb316852015-12-01 18:51:18 -08002596
2597/*
2598 * Write temporary secure storage and lock it.
2599 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002600#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08002601
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002602struct __ec_align1 ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08002603 uint8_t slot; /* Slot to write to */
2604 uint8_t data[EC_VSTORE_SLOT_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002605};
Duncan Laurieeb316852015-12-01 18:51:18 -08002606
2607/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08002608/* Thermal engine commands. Note that there are two implementations. We'll
2609 * reuse the command number, but the data and behavior is incompatible.
2610 * Version 0 is what originally shipped on Link.
2611 * Version 1 separates the CPU thermal limits from the fan control.
2612 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002613
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002614#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2615#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002616
Duncan Laurie93e24442014-01-06 12:30:52 -08002617/* The version 0 structs are opaque. You have to know what they are for
2618 * the get/set commands to make any sense.
2619 */
2620
2621/* Version 0 - set */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002622struct __ec_align2 ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002623 uint8_t sensor_type;
2624 uint8_t threshold_id;
2625 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002626};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002627
Duncan Laurie93e24442014-01-06 12:30:52 -08002628/* Version 0 - get */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002629struct __ec_align1 ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002630 uint8_t sensor_type;
2631 uint8_t threshold_id;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002632};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002633
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002634struct __ec_align2 ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002635 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002636};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002637
Duncan Laurie93e24442014-01-06 12:30:52 -08002638
2639/* The version 1 structs are visible. */
2640enum ec_temp_thresholds {
2641 EC_TEMP_THRESH_WARN = 0,
2642 EC_TEMP_THRESH_HIGH,
2643 EC_TEMP_THRESH_HALT,
2644
2645 EC_TEMP_THRESH_COUNT
2646};
2647
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002648/*
2649 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08002650 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002651 *
2652 * Note that this structure is a sub-structure of
2653 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08002654 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002655struct __ec_align4 ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08002656 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2657 uint32_t temp_fan_off; /* no active cooling needed */
2658 uint32_t temp_fan_max; /* max active cooling needed */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002659};
Duncan Laurie93e24442014-01-06 12:30:52 -08002660
2661/* Version 1 - get config for one sensor. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002662struct __ec_align4 ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08002663 uint32_t sensor_num;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002664};
Duncan Laurie93e24442014-01-06 12:30:52 -08002665/* This returns a struct ec_thermal_config */
2666
2667/* Version 1 - set config for one sensor.
2668 * Use read-modify-write for best results! */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002669struct __ec_align4 ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08002670 uint32_t sensor_num;
2671 struct ec_thermal_config cfg;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002672};
Duncan Laurie93e24442014-01-06 12:30:52 -08002673/* This returns no data */
2674
2675/****************************************************************************/
2676
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002677/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002678#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002679
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002680/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002681struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002682 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002683};
Duncan Laurie433432b2013-06-03 10:38:22 -07002684
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002685/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002686#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2687#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002688
2689/*
2690 * The original TMP006 calibration only needed four params, but now we need
2691 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2692 * the params opaque. The v1 "get" response will include the algorithm number
2693 * and how many params it requires. That way we can change the EC code without
2694 * needing to update this file. We can also use a different algorithm on each
2695 * sensor.
2696 */
2697
2698/* This is the same struct for both v0 and v1. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002699struct __ec_align1 ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07002700 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002701};
Duncan Laurie433432b2013-06-03 10:38:22 -07002702
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002703/* Version 0 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002704struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002705 float s0;
2706 float b0;
2707 float b1;
2708 float b2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002709};
Duncan Laurie433432b2013-06-03 10:38:22 -07002710
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002711struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002712 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002713 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07002714 float s0;
2715 float b0;
2716 float b1;
2717 float b2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002718};
Duncan Laurie433432b2013-06-03 10:38:22 -07002719
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002720/* Version 1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002721struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002722 uint8_t algorithm;
2723 uint8_t num_params;
2724 uint8_t reserved[2];
2725 float val[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002726};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002727
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002728struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002729 uint8_t index;
2730 uint8_t algorithm;
2731 uint8_t num_params;
2732 uint8_t reserved;
2733 float val[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002734};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002735
2736
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002737/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002738#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002739
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002740struct __ec_align1 ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002741 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002742};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002743
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002744struct __ec_align4 ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002745 int32_t t; /* In 1/100 K */
2746 int32_t v; /* In nV */
2747};
2748
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002749/*****************************************************************************/
2750/* MKBP - Matrix KeyBoard Protocol */
2751
2752/*
2753 * Read key state
2754 *
2755 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2756 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002757 *
2758 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2759 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2760 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002761 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002762#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002763
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002764/*
2765 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2766 */
2767#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002768
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002769struct __ec_align_size1 ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002770 uint32_t rows;
2771 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002772 /* Formerly "switches", which was 0. */
2773 uint8_t reserved;
2774};
2775
2776struct __ec_align1 ec_params_mkbp_info {
2777 uint8_t info_type;
2778 uint8_t event_type;
2779};
2780
2781enum ec_mkbp_info_type {
2782 /*
2783 * Info about the keyboard matrix: number of rows and columns.
2784 *
2785 * Returns struct ec_response_mkbp_info.
2786 */
2787 EC_MKBP_INFO_KBD = 0,
2788
2789 /*
2790 * For buttons and switches, info about which specifically are
2791 * supported. event_type must be set to one of the values in enum
2792 * ec_mkbp_event.
2793 *
2794 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2795 * bitmask indicating which buttons or switches are present. See the
2796 * bit inidices below.
2797 */
2798 EC_MKBP_INFO_SUPPORTED = 1,
2799
2800 /*
2801 * Instantaneous state of buttons and switches.
2802 *
2803 * event_type must be set to one of the values in enum ec_mkbp_event.
2804 *
2805 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2806 * indicating the current state of the keyboard matrix.
2807 *
2808 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2809 * event state.
2810 *
2811 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2812 * state of supported buttons.
2813 *
2814 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2815 * state of supported switches.
2816 */
2817 EC_MKBP_INFO_CURRENT = 2,
2818};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002819
2820/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002821#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002822
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002823struct __ec_align1 ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002824 uint8_t col;
2825 uint8_t row;
2826 uint8_t pressed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002827};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002828
Duncan Laurie433432b2013-06-03 10:38:22 -07002829/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002830#define EC_CMD_MKBP_SET_CONFIG 0x0064
2831#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07002832
2833/* flags */
2834enum mkbp_config_flags {
2835 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2836};
2837
2838enum mkbp_config_valid {
2839 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2840 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2841 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2842 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2843 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2844 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2845 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2846};
2847
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002848/*
2849 * Configuration for our key scanning algorithm.
2850 *
2851 * Note that this is used as a sub-structure of
2852 * ec_{params/response}_mkbp_get_config.
2853 */
2854struct __ec_align_size1 ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07002855 uint32_t valid_mask; /* valid fields */
2856 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2857 uint8_t valid_flags; /* which flags are valid */
2858 uint16_t scan_period_us; /* period between start of scans */
2859 /* revert to interrupt mode after no activity for this long */
2860 uint32_t poll_timeout_us;
2861 /*
2862 * minimum post-scan relax time. Once we finish a scan we check
2863 * the time until we are due to start the next one. If this time is
2864 * shorter this field, we use this instead.
2865 */
2866 uint16_t min_post_scan_delay_us;
2867 /* delay between setting up output and waiting for it to settle */
2868 uint16_t output_settle_us;
2869 uint16_t debounce_down_us; /* time for debounce on key down */
2870 uint16_t debounce_up_us; /* time for debounce on key up */
2871 /* maximum depth to allow for fifo (0 = no keyscan output) */
2872 uint8_t fifo_max_depth;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002873};
Duncan Laurie433432b2013-06-03 10:38:22 -07002874
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002875struct __ec_align_size1 ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07002876 struct ec_mkbp_config config;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002877};
Duncan Laurie433432b2013-06-03 10:38:22 -07002878
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002879struct __ec_align_size1 ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07002880 struct ec_mkbp_config config;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002881};
Duncan Laurie433432b2013-06-03 10:38:22 -07002882
2883/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002884#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07002885
2886enum ec_keyscan_seq_cmd {
2887 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2888 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2889 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2890 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2891 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2892};
2893
2894enum ec_collect_flags {
2895 /*
2896 * Indicates this scan was processed by the EC. Due to timing, some
2897 * scans may be skipped.
2898 */
2899 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2900};
2901
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002902struct __ec_align1 ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07002903 uint8_t flags; /* some flags (enum ec_collect_flags) */
2904};
2905
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002906struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07002907 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2908 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002909 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002910 uint8_t active; /* still active */
2911 uint8_t num_items; /* number of items */
2912 /* Current item being presented */
2913 uint8_t cur_item;
2914 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002915 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002916 /*
2917 * Absolute time for this scan, measured from the
2918 * start of the sequence.
2919 */
2920 uint32_t time_us;
2921 uint8_t scan[0]; /* keyscan data */
2922 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002923 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002924 uint8_t start_item; /* First item to return */
2925 uint8_t num_items; /* Number of items to return */
2926 } collect;
2927 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002928};
Duncan Laurie433432b2013-06-03 10:38:22 -07002929
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002930struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07002931 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002932 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002933 uint8_t num_items; /* Number of items */
2934 /* Data for each item */
2935 struct ec_collect_item item[0];
2936 } collect;
2937 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002938};
Duncan Laurie433432b2013-06-03 10:38:22 -07002939
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002940/*
2941 * Get the next pending MKBP event.
2942 *
2943 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2944 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002945#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002946
2947enum ec_mkbp_event {
2948 /* Keyboard matrix changed. The event data is the new matrix state. */
2949 EC_MKBP_EVENT_KEY_MATRIX = 0,
2950
2951 /* New host event. The event data is 4 bytes of host event flags. */
2952 EC_MKBP_EVENT_HOST_EVENT = 1,
2953
Duncan Laurieeb316852015-12-01 18:51:18 -08002954 /* New Sensor FIFO data. The event data is fifo_info structure. */
2955 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2956
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002957 /* The state of the non-matrixed buttons have changed. */
2958 EC_MKBP_EVENT_BUTTON = 3,
2959
2960 /* The state of the switches have changed. */
2961 EC_MKBP_EVENT_SWITCH = 4,
2962
2963 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
2964 EC_MKBP_EVENT_FINGERPRINT = 5,
2965
2966 /*
2967 * Sysrq event: send emulated sysrq. The event data is sysrq,
2968 * corresponding to the key to be pressed.
2969 */
2970 EC_MKBP_EVENT_SYSRQ = 6,
2971
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002972 /* Number of MKBP events */
2973 EC_MKBP_EVENT_COUNT,
2974};
2975
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002976union __ec_align_offset1 ec_response_get_next_data {
2977 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08002978
2979 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002980 uint32_t host_event;
Duncan Laurieeb316852015-12-01 18:51:18 -08002981
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002982 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002983 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002984 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08002985 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002986 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08002987
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002988 uint32_t buttons;
2989
2990 uint32_t switches;
2991
2992 uint32_t fp_events;
2993
2994 uint32_t sysrq;
2995};
2996
2997struct __ec_align1 ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002998 uint8_t event_type;
2999 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003000 union ec_response_get_next_data data;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003001};
3002
3003/* Bit indices for buttons and switches.*/
3004/* Buttons */
3005#define EC_MKBP_POWER_BUTTON 0
3006#define EC_MKBP_VOL_UP 1
3007#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003008#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003009
3010/* Switches */
3011#define EC_MKBP_LID_OPEN 0
3012#define EC_MKBP_TABLET_MODE 1
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003013
Gwendal Grignou880b4582016-06-20 08:49:25 -07003014/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003015#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003016
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003017struct __ec_align2 ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003018 uint16_t shorted; /* Keyboard pins are shorted */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003019};
3020
3021/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3022#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3023#define EC_MKBP_FP_FINGER_DOWN (1 << 29)
3024#define EC_MKBP_FP_FINGER_UP (1 << 30)
3025#define EC_MKBP_FP_IMAGE_READY (1 << 31)
Gwendal Grignou880b4582016-06-20 08:49:25 -07003026
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003027/*****************************************************************************/
3028/* Temperature sensor commands */
3029
3030/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003031#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003032
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003033struct __ec_align1 ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003034 uint8_t id;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003035};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003036
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003037struct __ec_align1 ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003038 char sensor_name[32];
3039 uint8_t sensor_type;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003040};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003041
3042/*****************************************************************************/
3043
3044/*
3045 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3046 * commands accidentally sent to the wrong interface. See the ACPI section
3047 * below.
3048 */
3049
3050/*****************************************************************************/
3051/* Host event commands */
3052
3053/*
3054 * Host event mask params and response structures, shared by all of the host
3055 * event commands below.
3056 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003057struct __ec_align4 ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003058 uint32_t mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003059};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003060
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003061struct __ec_align4 ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003062 uint32_t mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003063};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003064
3065/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003066#define EC_CMD_HOST_EVENT_GET_B 0x0087
3067#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3068#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3069#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003070
3071/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003072#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3073#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3074#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3075#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3076#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003077
3078/*****************************************************************************/
3079/* Switch commands */
3080
3081/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003082#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003083
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003084struct __ec_align1 ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003085 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003086};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003087
3088/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003089#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003090#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003092/* Version 0 params; no response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003093struct __ec_align1 ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003094 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003095};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003096
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003097/* Version 1 params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003098struct __ec_align1 ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003099 /* Flags to enable now */
3100 uint8_t now_flags;
3101
3102 /* Which flags to copy from now_flags */
3103 uint8_t now_mask;
3104
3105 /*
3106 * Flags to leave enabled in S3, if they're on at the S0->S3
3107 * transition. (Other flags will be disabled by the S0->S3
3108 * transition.)
3109 */
3110 uint8_t suspend_flags;
3111
3112 /* Which flags to copy from suspend_flags */
3113 uint8_t suspend_mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003114};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003115
3116/* Version 1 response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003117struct __ec_align1 ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003118 /* Flags to enable now */
3119 uint8_t now_flags;
3120
3121 /* Flags to leave enabled in S3 */
3122 uint8_t suspend_flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003123};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003124
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003125/*****************************************************************************/
3126/* GPIO commands. Only available on EC if write protect has been disabled. */
3127
3128/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003129#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003130
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003131struct __ec_align1 ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003132 char name[32];
3133 uint8_t val;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003134};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003135
3136/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003137#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003138
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003139/* Version 0 of input params and response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003140struct __ec_align1 ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003141 char name[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003142};
3143
3144struct __ec_align1 ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003145 uint8_t val;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003146};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003147
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003148/* Version 1 of input params and response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003149struct __ec_align1 ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003150 uint8_t subcmd;
3151 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003152 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003153 char name[32];
3154 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003155 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003156 uint8_t index;
3157 } get_info;
3158 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003159};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003160
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003161struct __ec_todo_packed ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003162 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003163 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003164 uint8_t val;
3165 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003166 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003167 uint8_t val;
3168 char name[32];
3169 uint32_t flags;
3170 } get_info;
3171 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003172};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003173
3174enum gpio_get_subcmd {
3175 EC_GPIO_GET_BY_NAME = 0,
3176 EC_GPIO_GET_COUNT = 1,
3177 EC_GPIO_GET_INFO = 2,
3178};
3179
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003180/*****************************************************************************/
3181/* I2C commands. Only available when flash write protect is unlocked. */
3182
Duncan Laurie93e24442014-01-06 12:30:52 -08003183/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003184 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3185 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3186 *
3187 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08003188 */
3189
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003190/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003191#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003192
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003193struct __ec_align_size1 ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07003194 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003195 uint8_t read_size; /* Either 8 or 16. */
3196 uint8_t port;
3197 uint8_t offset;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003198};
3199
3200struct __ec_align2 ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003201 uint16_t data;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003202};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003203
3204/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003205#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003206
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003207struct __ec_align_size1 ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003208 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07003209 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003210 uint8_t write_size; /* Either 8 or 16. */
3211 uint8_t port;
3212 uint8_t offset;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003213};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003214
3215/*****************************************************************************/
3216/* Charge state commands. Only available when flash write protect unlocked. */
3217
Duncan Laurie93e24442014-01-06 12:30:52 -08003218/* Force charge state machine to stop charging the battery or force it to
3219 * discharge the battery.
3220 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003221#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08003222#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003223
Duncan Laurie93e24442014-01-06 12:30:52 -08003224enum ec_charge_control_mode {
3225 CHARGE_CONTROL_NORMAL = 0,
3226 CHARGE_CONTROL_IDLE,
3227 CHARGE_CONTROL_DISCHARGE,
3228};
3229
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003230struct __ec_align4 ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08003231 uint32_t mode; /* enum charge_control_mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003232};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003233
3234/*****************************************************************************/
3235/* Console commands. Only available when flash write protect is unlocked. */
3236
3237/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003238#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003239
3240/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003241 * Read data from the saved snapshot. If the subcmd parameter is
3242 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3243 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3244 * end of the previous snapshot.
3245 *
3246 * The params are only looked at in version >= 1 of this command. Prior
3247 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003248 *
3249 * Response is null-terminated string. Empty string, if there is no more
3250 * remaining output.
3251 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003252#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003253
Duncan Laurieeb316852015-12-01 18:51:18 -08003254enum ec_console_read_subcmd {
3255 CONSOLE_READ_NEXT = 0,
3256 CONSOLE_READ_RECENT
3257};
3258
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003259struct __ec_align1 ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08003260 uint8_t subcmd; /* enum ec_console_read_subcmd */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003261};
Duncan Laurieeb316852015-12-01 18:51:18 -08003262
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003263/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07003264
3265/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003266 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07003267 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003268 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3269 * EC_RES_SUCCESS if the command was successful.
3270 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07003271 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003272#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07003273
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003274#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3275
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003276struct __ec_align1 ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003277 uint8_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003278};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003279
Duncan Laurie433432b2013-06-03 10:38:22 -07003280/*****************************************************************************/
3281/* USB port mux control. */
3282
3283/*
3284 * Switch USB mux or return to automatic switching.
3285 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003286#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07003287
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003288struct __ec_align1 ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07003289 uint8_t mux;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003290};
Duncan Laurie433432b2013-06-03 10:38:22 -07003291
3292/*****************************************************************************/
3293/* LDOs / FETs control. */
3294
3295enum ec_ldo_state {
3296 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3297 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3298};
3299
3300/*
3301 * Switch on/off a LDO.
3302 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003303#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07003304
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003305struct __ec_align1 ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07003306 uint8_t index;
3307 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003308};
Duncan Laurie433432b2013-06-03 10:38:22 -07003309
3310/*
3311 * Get LDO state.
3312 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003313#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07003314
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003315struct __ec_align1 ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07003316 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003317};
Duncan Laurie433432b2013-06-03 10:38:22 -07003318
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003319struct __ec_align1 ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07003320 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003321};
Duncan Laurie433432b2013-06-03 10:38:22 -07003322
3323/*****************************************************************************/
3324/* Power info. */
3325
3326/*
3327 * Get power info.
3328 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003329#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07003330
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003331struct __ec_align4 ec_response_power_info {
Duncan Laurie433432b2013-06-03 10:38:22 -07003332 uint32_t usb_dev_type;
3333 uint16_t voltage_ac;
3334 uint16_t voltage_system;
3335 uint16_t current_system;
3336 uint16_t usb_current_limit;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003337};
Duncan Laurie433432b2013-06-03 10:38:22 -07003338
3339/*****************************************************************************/
3340/* I2C passthru command */
3341
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003342#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07003343
Duncan Laurie433432b2013-06-03 10:38:22 -07003344/* Read data; if not present, message is a write */
3345#define EC_I2C_FLAG_READ (1 << 15)
3346
3347/* Mask for address */
3348#define EC_I2C_ADDR_MASK 0x3ff
3349
3350#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
3351#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3352
3353/* Any error */
3354#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3355
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003356struct __ec_align2 ec_params_i2c_passthru_msg {
Duncan Laurie433432b2013-06-03 10:38:22 -07003357 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3358 uint16_t len; /* Number of bytes to read or write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003359};
Duncan Laurie433432b2013-06-03 10:38:22 -07003360
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003361struct __ec_align2 ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07003362 uint8_t port; /* I2C port number */
3363 uint8_t num_msgs; /* Number of messages */
3364 struct ec_params_i2c_passthru_msg msg[];
3365 /* Data to write for all messages is concatenated here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003366};
Duncan Laurie433432b2013-06-03 10:38:22 -07003367
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003368struct __ec_align1 ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07003369 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3370 uint8_t num_msgs; /* Number of messages processed */
3371 uint8_t data[]; /* Data read by messages concatenated here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003372};
Duncan Laurie433432b2013-06-03 10:38:22 -07003373
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003374/*****************************************************************************/
3375/* Power button hang detect */
3376
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003377#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003378
3379/* Reasons to start hang detection timer */
3380/* Power button pressed */
3381#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3382
3383/* Lid closed */
3384#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3385
3386 /* Lid opened */
3387#define EC_HANG_START_ON_LID_OPEN (1 << 2)
3388
3389/* Start of AP S3->S0 transition (booting or resuming from suspend) */
3390#define EC_HANG_START_ON_RESUME (1 << 3)
3391
3392/* Reasons to cancel hang detection */
3393
3394/* Power button released */
3395#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3396
3397/* Any host command from AP received */
3398#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3399
3400/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3401#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
3402
3403/*
3404 * If this flag is set, all the other fields are ignored, and the hang detect
3405 * timer is started. This provides the AP a way to start the hang timer
3406 * without reconfiguring any of the other hang detect settings. Note that
3407 * you must previously have configured the timeouts.
3408 */
3409#define EC_HANG_START_NOW (1 << 30)
3410
3411/*
3412 * If this flag is set, all the other fields are ignored (including
3413 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3414 * without reconfiguring any of the other hang detect settings.
3415 */
3416#define EC_HANG_STOP_NOW (1 << 31)
3417
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003418struct __ec_align4 ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003419 /* Flags; see EC_HANG_* */
3420 uint32_t flags;
3421
3422 /* Timeout in msec before generating host event, if enabled */
3423 uint16_t host_event_timeout_msec;
3424
3425 /* Timeout in msec before generating warm reboot, if enabled */
3426 uint16_t warm_reboot_timeout_msec;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003427};
Duncan Laurie433432b2013-06-03 10:38:22 -07003428
3429/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003430/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07003431
3432/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003433 * This is the single catch-all host command to exchange data regarding the
3434 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07003435 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003436#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003437
3438/* Subcommands for this host command */
3439enum charge_state_command {
3440 CHARGE_STATE_CMD_GET_STATE,
3441 CHARGE_STATE_CMD_GET_PARAM,
3442 CHARGE_STATE_CMD_SET_PARAM,
3443 CHARGE_STATE_NUM_CMDS
3444};
3445
3446/*
3447 * Known param numbers are defined here. Ranges are reserved for board-specific
3448 * params, which are handled by the particular implementations.
3449 */
3450enum charge_state_params {
3451 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
3452 CS_PARAM_CHG_CURRENT, /* charger current limit */
3453 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3454 CS_PARAM_CHG_STATUS, /* charger-specific status */
3455 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08003456 CS_PARAM_LIMIT_POWER, /*
3457 * Check if power is limited due to
3458 * low battery and / or a weak external
3459 * charger. READ ONLY.
3460 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003461 /* How many so far? */
3462 CS_NUM_BASE_PARAMS,
3463
3464 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3465 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3466 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3467
3468 /* Other custom param ranges go here... */
3469};
3470
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003471struct __ec_todo_packed ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003472 uint8_t cmd; /* enum charge_state_command */
3473 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003474 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003475 /* no args */
3476 } get_state;
3477
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003478 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003479 uint32_t param; /* enum charge_state_param */
3480 } get_param;
3481
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003482 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003483 uint32_t param; /* param to set */
3484 uint32_t value; /* value to set */
3485 } set_param;
3486 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003487};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003488
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003489struct __ec_align4 ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003490 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003491 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003492 int ac;
3493 int chg_voltage;
3494 int chg_current;
3495 int chg_input_current;
3496 int batt_state_of_charge;
3497 } get_state;
3498
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003499 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003500 uint32_t value;
3501 } get_param;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003502 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003503 /* no return values */
3504 } set_param;
3505 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003506};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003507
Duncan Laurie433432b2013-06-03 10:38:22 -07003508
3509/*
3510 * Set maximum battery charging current.
3511 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003512#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07003513
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003514struct __ec_align4 ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07003515 uint32_t limit; /* in mA */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003516};
Duncan Laurie433432b2013-06-03 10:38:22 -07003517
3518/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003519 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07003520 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003521#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07003522
Duncan Laurieeb316852015-12-01 18:51:18 -08003523/* Command v0 is used only on Spring and is obsolete + unsupported */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003524struct __ec_align2 ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08003525 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3526 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003527};
Duncan Laurie433432b2013-06-03 10:38:22 -07003528
Duncan Laurieeb316852015-12-01 18:51:18 -08003529#define EC_POWER_LIMIT_NONE 0xffff
3530
3531/*****************************************************************************/
3532/* Hibernate/Deep Sleep Commands */
3533
3534/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003535#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08003536
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003537struct __ec_align4 ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08003538 /*
3539 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3540 * current settings without changing them.
3541 */
3542 uint32_t seconds;
3543};
3544
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003545struct __ec_align4 ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08003546 /*
3547 * The current time in seconds in which the system has been in the G3
3548 * state. This value is reset if the EC transitions out of G3.
3549 */
3550 uint32_t time_g3;
3551
3552 /*
3553 * The current time remaining in seconds until the EC should hibernate.
3554 * This value is also reset if the EC transitions out of G3.
3555 */
3556 uint32_t time_remaining;
3557
3558 /*
3559 * The current time in seconds that the EC should wait in G3 before
3560 * hibernating.
3561 */
3562 uint32_t hibernate_delay;
3563};
3564
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003565/* Inform the EC when entering a sleep state */
3566#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
3567
3568enum host_sleep_event {
3569 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
3570 HOST_SLEEP_EVENT_S3_RESUME = 2,
3571 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
3572 HOST_SLEEP_EVENT_S0IX_RESUME = 4
3573};
3574
3575struct __ec_align1 ec_params_host_sleep_event {
3576 uint8_t sleep_event;
3577};
3578
3579/*****************************************************************************/
3580/* Device events */
3581#define EC_CMD_DEVICE_EVENT 0x00AA
3582
3583enum ec_device_event {
3584 EC_DEVICE_EVENT_TRACKPAD,
3585 EC_DEVICE_EVENT_DSP,
3586 EC_DEVICE_EVENT_WIFI,
3587};
3588
3589enum ec_device_event_param {
3590 /* Get and clear pending device events */
3591 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
3592 /* Get device event mask */
3593 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
3594 /* Set device event mask */
3595 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
3596};
3597
3598#define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
3599
3600struct __ec_align_size1 ec_params_device_event {
3601 uint32_t event_mask;
3602 uint8_t param;
3603};
3604
3605struct __ec_align4 ec_response_device_event {
3606 uint32_t event_mask;
3607};
Duncan Laurieeb316852015-12-01 18:51:18 -08003608
Duncan Laurie433432b2013-06-03 10:38:22 -07003609/*****************************************************************************/
3610/* Smart battery pass-through */
3611
3612/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003613#define EC_CMD_SB_READ_WORD 0x00B0
3614#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07003615
3616/* Get / Set string smart battery parameters
3617 * formatted as SMBUS "block".
3618 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003619#define EC_CMD_SB_READ_BLOCK 0x00B2
3620#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07003621
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003622struct __ec_align1 ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07003623 uint8_t reg;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003624};
Duncan Laurie433432b2013-06-03 10:38:22 -07003625
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003626struct __ec_align2 ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07003627 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003628};
Duncan Laurie433432b2013-06-03 10:38:22 -07003629
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003630struct __ec_align1 ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07003631 uint8_t reg;
3632 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003633};
Duncan Laurie433432b2013-06-03 10:38:22 -07003634
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003635struct __ec_align1 ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07003636 uint8_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003637};
Duncan Laurie433432b2013-06-03 10:38:22 -07003638
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003639struct __ec_align1 ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07003640 uint8_t reg;
3641 uint16_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003642};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003643
3644/*****************************************************************************/
3645/* Battery vendor parameters
3646 *
3647 * Get or set vendor-specific parameters in the battery. Implementations may
3648 * differ between boards or batteries. On a set operation, the response
3649 * contains the actual value set, which may be rounded or clipped from the
3650 * requested value.
3651 */
3652
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003653#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003654
3655enum ec_battery_vendor_param_mode {
3656 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3657 BATTERY_VENDOR_PARAM_MODE_SET,
3658};
3659
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003660struct __ec_align_size1 ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003661 uint32_t param;
3662 uint32_t value;
3663 uint8_t mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003664};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003665
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003666struct __ec_align4 ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003667 uint32_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003668};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003669
3670/*****************************************************************************/
3671/*
3672 * Smart Battery Firmware Update Commands
3673 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003674#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003675
3676enum ec_sb_fw_update_subcmd {
3677 EC_SB_FW_UPDATE_PREPARE = 0x0,
3678 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3679 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3680 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3681 EC_SB_FW_UPDATE_END = 0x4,
3682 EC_SB_FW_UPDATE_STATUS = 0x5,
3683 EC_SB_FW_UPDATE_PROTECT = 0x6,
3684 EC_SB_FW_UPDATE_MAX = 0x7,
3685};
3686
3687#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3688#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3689#define SB_FW_UPDATE_CMD_INFO_SIZE 8
3690
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003691struct __ec_align4 ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003692 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3693 uint16_t fw_id; /* firmware id */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003694};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003695
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003696struct __ec_align4 ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003697 struct ec_sb_fw_update_header hdr;
3698 union {
3699 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3700 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3701 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3702 /* EC_SB_FW_UPDATE_END = 0x4 */
3703 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3704 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003705 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003706 /* no args */
3707 } dummy;
3708
3709 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003710 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003711 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3712 } write;
3713 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003714};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003715
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003716struct __ec_align1 ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003717 union {
3718 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003719 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003720 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3721 } info;
3722
3723 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003724 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003725 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3726 } status;
3727 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003728};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003729
3730/*
3731 * Entering Verified Boot Mode Command
3732 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3733 * Valid Modes are: normal, developer, and recovery.
3734 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003735#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003736
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003737struct __ec_align4 ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003738 int vboot_mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003739};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003740
3741#define VBOOT_MODE_NORMAL 0
3742#define VBOOT_MODE_DEVELOPER 1
3743#define VBOOT_MODE_RECOVERY 2
3744
Duncan Laurie433432b2013-06-03 10:38:22 -07003745/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07003746/*
3747 * I2C passthru protection command: Protects I2C tunnels against access on
3748 * certain addresses (board-specific).
3749 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003750#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07003751
3752enum ec_i2c_passthru_protect_subcmd {
3753 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3754 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3755};
3756
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003757struct __ec_align1 ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003758 uint8_t subcmd;
3759 uint8_t port; /* I2C port number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003760};
Gwendal Grignou880b4582016-06-20 08:49:25 -07003761
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003762struct __ec_align1 ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003763 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003764};
Gwendal Grignou880b4582016-06-20 08:49:25 -07003765
3766/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003767/* System commands */
3768
3769/*
Duncan Laurie93e24442014-01-06 12:30:52 -08003770 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3771 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003772 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003773#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003774
3775/* Command */
3776enum ec_reboot_cmd {
3777 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003778 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3779 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003780 /* (command 3 was jump to RW-B) */
3781 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003782 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3783 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003784};
3785
3786/* Flags for ec_params_reboot_ec.reboot_flags */
3787#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
Duncan Laurie433432b2013-06-03 10:38:22 -07003788#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003789
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003790struct __ec_align1 ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003791 uint8_t cmd; /* enum ec_reboot_cmd */
3792 uint8_t flags; /* See EC_REBOOT_FLAG_* */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003793};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003794
Duncan Laurie433432b2013-06-03 10:38:22 -07003795/*
3796 * Get information on last EC panic.
3797 *
3798 * Returns variable-length platform-dependent panic information. See panic.h
3799 * for details.
3800 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003801#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07003802
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003803/*****************************************************************************/
3804/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003805 * Special commands
3806 *
3807 * These do not follow the normal rules for commands. See each command for
3808 * details.
3809 */
3810
3811/*
3812 * Reboot NOW
3813 *
3814 * This command will work even when the EC LPC interface is busy, because the
3815 * reboot command is processed at interrupt level. Note that when the EC
3816 * reboots, the host will reboot too, so there is no response to this command.
3817 *
3818 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3819 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003820#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003821
3822/*
Duncan Laurie433432b2013-06-03 10:38:22 -07003823 * Resend last response (not supported on LPC).
3824 *
3825 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3826 * there was no previous command, or the previous command's response was too
3827 * big to save.
3828 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003829#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07003830
3831/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003832 * This header byte on a command indicate version 0. Any header byte less
3833 * than this means that we are talking to an old EC which doesn't support
3834 * versioning. In that case, we assume version 0.
3835 *
3836 * Header bytes greater than this indicate a later version. For example,
3837 * EC_CMD_VERSION0 + 1 means we are using version 1.
3838 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003839 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003840 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003841#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003842
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003843/*****************************************************************************/
3844/*
3845 * PD commands
3846 *
3847 * These commands are for PD MCU communication.
3848 */
3849
3850/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003851#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08003852#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003853
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003854enum pd_charge_state {
3855 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3856 PD_CHARGE_NONE, /* No charging allowed */
3857 PD_CHARGE_5V, /* 5V charging only */
3858 PD_CHARGE_MAX /* Charge at max voltage */
3859};
3860
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003861/* Status of EC being sent to PD */
Duncan Laurieeb316852015-12-01 18:51:18 -08003862#define EC_STATUS_HIBERNATING (1 << 0)
3863
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003864struct __ec_align1 ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003865 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003866 int8_t batt_soc; /* battery state of charge */
3867 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003868};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003869
3870/* Status of PD being sent back to EC */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003871#define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3872#define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3873#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
Duncan Laurieeb316852015-12-01 18:51:18 -08003874#define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
3875#define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
3876#define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
3877#define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
3878#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
3879 PD_STATUS_TCPC_ALERT_1 | \
3880 PD_STATUS_HOST_EVENT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003881struct __ec_align_size1 ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003882 uint32_t curr_lim_ma; /* input current limit */
3883 uint16_t status; /* PD MCU status */
3884 int8_t active_charge_port; /* active charging port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003885};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003886
3887/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003888#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003889
3890/* PD MCU host event status bits */
3891#define PD_EVENT_UPDATE_DEVICE (1 << 0)
3892#define PD_EVENT_POWER_CHANGE (1 << 1)
3893#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
Duncan Laurieeb316852015-12-01 18:51:18 -08003894#define PD_EVENT_DATA_SWAP (1 << 3)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003895struct __ec_align4 ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003896 uint32_t status; /* PD MCU host event status */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003897};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003898
3899/* Set USB type-C port role and muxes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003900#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003901
3902enum usb_pd_control_role {
3903 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3904 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3905 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3906 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3907 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3908 USB_PD_CTRL_ROLE_COUNT
3909};
3910
3911enum usb_pd_control_mux {
3912 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3913 USB_PD_CTRL_MUX_NONE = 1,
3914 USB_PD_CTRL_MUX_USB = 2,
3915 USB_PD_CTRL_MUX_DP = 3,
3916 USB_PD_CTRL_MUX_DOCK = 4,
3917 USB_PD_CTRL_MUX_AUTO = 5,
3918 USB_PD_CTRL_MUX_COUNT
3919};
3920
Duncan Laurieeb316852015-12-01 18:51:18 -08003921enum usb_pd_control_swap {
3922 USB_PD_CTRL_SWAP_NONE = 0,
3923 USB_PD_CTRL_SWAP_DATA = 1,
3924 USB_PD_CTRL_SWAP_POWER = 2,
3925 USB_PD_CTRL_SWAP_VCONN = 3,
3926 USB_PD_CTRL_SWAP_COUNT
3927};
3928
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003929struct __ec_align1 ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003930 uint8_t port;
3931 uint8_t role;
3932 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08003933 uint8_t swap;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003934};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003935
Duncan Laurieeb316852015-12-01 18:51:18 -08003936#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3937#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3938#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3939
3940#define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
3941#define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
3942#define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
3943#define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
3944#define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
3945#define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
3946#define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
3947
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003948struct __ec_align1 ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003949 uint8_t enabled;
3950 uint8_t role;
3951 uint8_t polarity;
3952 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003953};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003954
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003955struct __ec_align1 ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003956 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08003957 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003958 uint8_t polarity;
3959 char state[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003960};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003961
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003962#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003963
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003964/* Maximum number of PD ports on a device, num_ports will be <= this */
3965#define EC_USB_PD_MAX_PORTS 8
3966
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003967struct __ec_align1 ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003968 uint8_t num_ports;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003969};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003970
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003971#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003972
3973#define PD_POWER_CHARGING_PORT 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003974struct __ec_align1 ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003975 uint8_t port;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003976};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003977
3978enum usb_chg_type {
3979 USB_CHG_TYPE_NONE,
3980 USB_CHG_TYPE_PD,
3981 USB_CHG_TYPE_C,
3982 USB_CHG_TYPE_PROPRIETARY,
3983 USB_CHG_TYPE_BC12_DCP,
3984 USB_CHG_TYPE_BC12_CDP,
3985 USB_CHG_TYPE_BC12_SDP,
3986 USB_CHG_TYPE_OTHER,
3987 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08003988 USB_CHG_TYPE_UNKNOWN,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003989};
3990enum usb_power_roles {
3991 USB_PD_PORT_POWER_DISCONNECTED,
3992 USB_PD_PORT_POWER_SOURCE,
3993 USB_PD_PORT_POWER_SINK,
3994 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3995};
3996
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003997struct __ec_align2 usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003998 uint16_t voltage_max;
3999 uint16_t voltage_now;
4000 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08004001 uint16_t current_lim;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004002};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004003
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004004struct __ec_align4 ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004005 uint8_t role;
4006 uint8_t type;
4007 uint8_t dualrole;
4008 uint8_t reserved1;
4009 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004010 uint32_t max_power;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004011};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004012
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004013/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004014#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004015
4016enum usb_pd_fw_update_cmds {
4017 USB_PD_FW_REBOOT,
4018 USB_PD_FW_FLASH_ERASE,
4019 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004020 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004021};
4022
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004023struct __ec_align4 ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004024 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004025 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004026 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004027 uint32_t size; /* Size to write in bytes */
4028 /* Followed by data to write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004029};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004030
4031/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004032#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004033/* RW hash is first 20 bytes of SHA-256 of RW section */
4034#define PD_RW_HASH_SIZE 20
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004035struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004036 uint16_t dev_id;
4037 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004038 uint8_t reserved; /* For alignment of current_image
4039 * TODO(rspangler) but it's not aligned!
4040 * Should have been reserved[2]. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004041 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004042};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004043
4044/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004045#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004046
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004047struct __ec_align1 ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004048 uint8_t port;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004049};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004050
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004051/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004052#define EC_CMD_USB_PD_DISCOVERY 0x0113
4053struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004054 uint16_t vid; /* USB-IF VID */
4055 uint16_t pid; /* USB-IF PID */
4056 uint8_t ptype; /* product type (hub,periph,cable,ama) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004057};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004058
4059/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004060#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004061
4062/* Negative port parameters have special meaning */
4063enum usb_pd_override_ports {
4064 OVERRIDE_DONT_CHARGE = -2,
4065 OVERRIDE_OFF = -1,
Duncan Laurieeb316852015-12-01 18:51:18 -08004066 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004067};
4068
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004069struct __ec_align2 ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004070 int16_t override_port; /* Override port# */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004071};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004072
4073/* Read (and delete) one entry of PD event log */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004074#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004075
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004076struct __ec_align4 ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004077 uint32_t timestamp; /* relative timestamp in milliseconds */
4078 uint8_t type; /* event type : see PD_EVENT_xx below */
4079 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4080 uint16_t data; /* type-defined data payload */
4081 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004082};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004083
4084
4085/* The timestamp is the microsecond counter shifted to get about a ms. */
4086#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4087
Duncan Laurieeb316852015-12-01 18:51:18 -08004088#define PD_LOG_SIZE_MASK 0x1f
4089#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004090#define PD_LOG_PORT_SHIFT 5
4091#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4092 ((size) & PD_LOG_SIZE_MASK))
4093#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4094#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4095
4096/* PD event log : entry types */
4097/* PD MCU events */
4098#define PD_EVENT_MCU_BASE 0x00
4099#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4100#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4101/* Reserved for custom board event */
4102#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4103/* PD generic accessory events */
4104#define PD_EVENT_ACC_BASE 0x20
4105#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4106#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4107/* PD power supply events */
4108#define PD_EVENT_PS_BASE 0x40
4109#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4110/* PD video dongles events */
4111#define PD_EVENT_VIDEO_BASE 0x60
4112#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4113#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4114/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08004115#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004116
4117/*
4118 * PD_EVENT_MCU_CHARGE event definition :
4119 * the payload is "struct usb_chg_measures"
4120 * the data field contains the port state flags as defined below :
4121 */
4122/* Port partner is a dual role device */
4123#define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
4124/* Port is the pending override port */
4125#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
4126/* Port is the override port */
4127#define CHARGE_FLAGS_OVERRIDE (1 << 13)
4128/* Charger type */
4129#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08004130#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004131/* Power delivery role */
4132#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4133
4134/*
4135 * PD_EVENT_PS_FAULT data field flags definition :
4136 */
4137#define PS_FAULT_OCP 1
4138#define PS_FAULT_FAST_OCP 2
4139#define PS_FAULT_OVP 3
4140#define PS_FAULT_DISCH 4
4141
4142/*
4143 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4144 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004145struct __ec_align4 mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004146 uint8_t major;
4147 uint8_t minor;
4148 uint16_t build;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004149};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004150
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004151struct __ec_align4 mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004152 uint8_t family[2];
4153 uint8_t chipid[2];
4154 struct mcdp_version irom;
4155 struct mcdp_version fw;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004156};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004157
4158/* struct mcdp_info field decoding */
4159#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4160#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4161
4162/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004163#define EC_CMD_USB_PD_GET_AMODE 0x0116
4164struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004165 uint16_t svid_idx; /* SVID index to get */
4166 uint8_t port; /* port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004167};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004168
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004169struct __ec_align4 ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004170 uint16_t svid; /* SVID */
4171 uint16_t opos; /* Object Position */
4172 uint32_t vdo[6]; /* Mode VDOs */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004173};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004174
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004175#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004176
4177enum pd_mode_cmd {
4178 PD_EXIT_MODE = 0,
4179 PD_ENTER_MODE = 1,
4180 /* Not a command. Do NOT remove. */
4181 PD_MODE_CMD_COUNT,
4182};
4183
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004184struct __ec_align4 ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004185 uint32_t cmd; /* enum pd_mode_cmd */
4186 uint16_t svid; /* SVID to set */
4187 uint8_t opos; /* Object Position */
4188 uint8_t port; /* port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004189};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004190
4191/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004192#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004193
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004194struct __ec_align1 ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004195 uint8_t type; /* event type : see PD_EVENT_xx above */
4196 uint8_t port; /* port#, or 0 for events unrelated to a given port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004197};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004198
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004199
Gwendal Grignou880b4582016-06-20 08:49:25 -07004200/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004201#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07004202
4203enum ec_pd_control_cmd {
4204 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4205 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4206 PD_RESET, /* Force reset the PD chip */
4207 PD_CONTROL_DISABLE /* Disable further calls to this command */
4208};
4209
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004210struct __ec_align1 ec_params_pd_control {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004211 uint8_t chip; /* chip id (should be 0) */
4212 uint8_t subcmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004213};
Gwendal Grignou880b4582016-06-20 08:49:25 -07004214
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004215/* Get info about USB-C SS muxes */
4216#define EC_CMD_USB_PD_MUX_INFO 0x011A
4217
4218struct __ec_align1 ec_params_usb_pd_mux_info {
4219 uint8_t port; /* USB-C port number */
4220};
4221
4222/* Flags representing mux state */
4223#define USB_PD_MUX_USB_ENABLED (1 << 0)
4224#define USB_PD_MUX_DP_ENABLED (1 << 1)
4225#define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4226#define USB_PD_MUX_HPD_IRQ (1 << 3)
4227
4228struct __ec_align1 ec_response_usb_pd_mux_info {
4229 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4230};
4231
4232#define EC_CMD_PD_CHIP_INFO 0x011B
4233
4234struct __ec_align1 ec_params_pd_chip_info {
4235 uint8_t port; /* USB-C port number */
4236 uint8_t renew; /* Force renewal */
4237};
4238
4239struct __ec_align2 ec_response_pd_chip_info {
4240 uint16_t vendor_id;
4241 uint16_t product_id;
4242 uint16_t device_id;
4243 union {
4244 uint8_t fw_version_string[8];
4245 uint64_t fw_version_number;
4246 };
4247};
4248
4249/* Run RW signature verification and get status */
4250#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
4251
4252struct __ec_align4 ec_response_rwsig_check_status {
4253 uint32_t status;
4254};
4255
4256/* For controlling RWSIG task */
4257#define EC_CMD_RWSIG_ACTION 0x011D
4258
4259enum rwsig_action {
4260 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
4261 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
4262};
4263
4264struct __ec_align4 ec_params_rwsig_action {
4265 uint32_t action;
4266};
4267
4268/*****************************************************************************/
4269/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08004270
4271/*****************************************************************************/
4272/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004273 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08004274 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004275#define EC_CMD_CR51_BASE 0x0300
4276#define EC_CMD_CR51_LAST 0x03FF
4277
4278/*****************************************************************************/
4279/* Fingerprint MCU commands: range 0x0400-0x040x */
4280
4281/* Fingerprint SPI sensor passthru command: prototyping ONLY */
4282#define EC_CMD_FP_PASSTHRU 0x0400
4283
4284#define EC_FP_FLAG_NOT_COMPLETE 0x1
4285
4286struct __ec_align2 ec_params_fp_passthru {
4287 uint16_t len; /* Number of bytes to write then read */
4288 uint16_t flags; /* EC_FP_FLAG_xxx */
4289 uint8_t data[]; /* Data to send */
4290};
4291
4292/* Fingerprint sensor configuration command: prototyping ONLY */
4293#define EC_CMD_FP_SENSOR_CONFIG 0x0401
4294
4295#define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4296
4297struct __ec_align2 ec_params_fp_sensor_config {
4298 uint8_t count; /* Number of setup registers */
4299 /*
4300 * the value to send to each of the 'count' setup registers
4301 * is stored in the 'data' array for 'len' bytes just after
4302 * the previous one.
4303 */
4304 uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4305 uint8_t data[];
4306};
4307
4308/* Configure the Fingerprint MCU behavior */
4309#define EC_CMD_FP_MODE 0x0402
4310
4311/* Put the sensor in its lowest power mode */
4312#define FP_MODE_DEEPSLEEP (1<<0)
4313/* Wait to see a finger on the sensor */
4314#define FP_MODE_FINGER_DOWN (1<<1)
4315/* Poll until the finger has left the sensor */
4316#define FP_MODE_FINGER_UP (1<<2)
4317/* Capture the current finger image */
4318#define FP_MODE_CAPTURE (1<<3)
4319/* special value: don't change anything just read back current mode */
4320#define FP_MODE_DONT_CHANGE (1<<31)
4321
4322struct __ec_align4 ec_params_fp_mode {
4323 uint32_t mode; /* as defined by FP_MODE_ constants */
4324 /* TBD */
4325};
4326
4327struct __ec_align4 ec_response_fp_mode {
4328 uint32_t mode; /* as defined by FP_MODE_ constants */
4329 /* TBD */
4330};
4331
4332/* Retrieve Fingerprint sensor information */
4333#define EC_CMD_FP_INFO 0x0403
4334
4335struct __ec_align2 ec_response_fp_info {
4336 /* Sensor identification */
4337 uint32_t vendor_id;
4338 uint32_t product_id;
4339 uint32_t model_id;
4340 uint32_t version;
4341 /* Image frame characteristics */
4342 uint32_t frame_size;
4343 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4344 uint16_t width;
4345 uint16_t height;
4346 uint16_t bpp;
4347};
4348
4349/* Get the last captured finger frame: TODO: will be AES-encrypted */
4350#define EC_CMD_FP_FRAME 0x0404
4351
4352struct __ec_align4 ec_params_fp_frame {
4353 uint32_t offset;
4354 uint32_t size;
4355};
4356
4357/*****************************************************************************/
4358/* Touchpad MCU commands: range 0x0500-0x05FF */
4359
4360/* Perform touchpad self test */
4361#define EC_CMD_TP_SELF_TEST 0x0500
4362
4363/* Get number of frame types, and the size of each type */
4364#define EC_CMD_TP_FRAME_INFO 0x0501
4365
4366struct __ec_align4 ec_response_tp_frame_info {
4367 uint32_t n_frames;
4368 uint32_t frame_sizes[0];
4369};
4370
4371/* Create a snapshot of current frame readings */
4372#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
4373
4374/* Read the frame */
4375#define EC_CMD_TP_FRAME_GET 0x0503
4376
4377struct __ec_align4 ec_params_tp_frame_get {
4378 uint32_t frame_index;
4379 uint32_t offset;
4380 uint32_t size;
4381};
Duncan Laurieeb316852015-12-01 18:51:18 -08004382
4383/*****************************************************************************/
4384/*
4385 * Reserve a range of host commands for board-specific, experimental, or
4386 * special purpose features. These can be (re)used without updating this file.
4387 *
4388 * CAUTION: Don't go nuts with this. Shipping products should document ALL
4389 * their EC commands for easier development, testing, debugging, and support.
4390 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004391 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
4392 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
4393 *
Duncan Laurieeb316852015-12-01 18:51:18 -08004394 * In your experimental code, you may want to do something like this:
4395 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004396 * #define EC_CMD_MAGIC_FOO 0x0000
4397 * #define EC_CMD_MAGIC_BAR 0x0001
4398 * #define EC_CMD_MAGIC_HEY 0x0002
4399 *
4400 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
4401 * EC_VER_MASK(0);
4402 *
4403 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
4404 * EC_VER_MASK(0);
4405 *
4406 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
4407 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08004408 */
4409#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
4410#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
4411
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004412/*
4413 * Given the private host command offset, calculate the true private host
4414 * command value.
4415 */
4416#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
4417 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
4418
Duncan Laurie93e24442014-01-06 12:30:52 -08004419/*****************************************************************************/
4420/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004421 * Passthru commands
4422 *
4423 * Some platforms have sub-processors chained to each other. For example.
4424 *
4425 * AP <--> EC <--> PD MCU
4426 *
4427 * The top 2 bits of the command number are used to indicate which device the
4428 * command is intended for. Device 0 is always the device receiving the
4429 * command; other device mapping is board-specific.
4430 *
4431 * When a device receives a command to be passed to a sub-processor, it passes
4432 * it on with the device number set back to 0. This allows the sub-processor
4433 * to remain blissfully unaware of whether the command originated on the next
4434 * device up the chain, or was passed through from the AP.
4435 *
4436 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
4437 * AP sends command 0x4002 to the EC
4438 * EC sends command 0x0002 to the PD MCU
4439 * EC forwards PD MCU response back to the AP
4440 */
4441
4442/* Offset and max command number for sub-device n */
4443#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
4444#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
4445
4446/*****************************************************************************/
4447/*
Duncan Laurie93e24442014-01-06 12:30:52 -08004448 * Deprecated constants. These constants have been renamed for clarity. The
4449 * meaning and size has not changed. Programs that use the old names should
4450 * switch to the new names soon, as the old names may not be carried forward
4451 * forever.
4452 */
4453#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
4454#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
4455#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
4456
Patrick Georgi0f6187a2017-07-28 15:57:23 +02004457#endif /* !__ACPI__ && !__KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004458
Duncan Laurieeb316852015-12-01 18:51:18 -08004459#endif /* __CROS_EC_EC_COMMANDS_H */