blob: 0fbb1a6b8cf3410c634660181fb52e4dddced526 [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 */
Furquan Shaikh8788fd62017-11-20 20:28:18 -0800600#define EC_HOST_EVENT_MASK(event_code) (1ULL << ((event_code) - 1))
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800601
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,
Furquan Shaikh1432cbc2017-10-13 11:31:35 -07001115 /* EC supports the unified wake masks for LPC/eSPI systems */
1116 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
Duncan Laurieeb316852015-12-01 18:51:18 -08001117};
1118
1119#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
1120#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001121struct __ec_align4 ec_response_get_features {
Duncan Laurieeb316852015-12-01 18:51:18 -08001122 uint32_t flags[2];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001123};
Duncan Laurie433432b2013-06-03 10:38:22 -07001124
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001125/*****************************************************************************/
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001126/* Get the board's SKU ID from EC */
1127#define EC_CMD_GET_SKU_ID 0x000E
1128
Kevin Chiue2bb0592017-09-12 09:13:41 +08001129/* Set SKU ID from AP */
1130#define EC_CMD_SET_SKU_ID 0x000F
1131
1132struct __ec_align4 ec_sku_id_info {
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001133 uint32_t sku_id;
1134};
1135
1136/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001137/* Flash commands */
1138
1139/* Get flash info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001140#define EC_CMD_FLASH_INFO 0x0010
1141#define EC_VER_FLASH_INFO 2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001142
Duncan Laurie93e24442014-01-06 12:30:52 -08001143/* Version 0 returns these fields */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001144struct __ec_align4 ec_response_flash_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001145 /* Usable flash size, in bytes */
1146 uint32_t flash_size;
1147 /*
1148 * Write block size. Write offset and size must be a multiple
1149 * of this.
1150 */
1151 uint32_t write_block_size;
1152 /*
1153 * Erase block size. Erase offset and size must be a multiple
1154 * of this.
1155 */
1156 uint32_t erase_block_size;
1157 /*
1158 * Protection block size. Protection offset and size must be a
1159 * multiple of this.
1160 */
1161 uint32_t protect_block_size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001162};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001163
Duncan Laurie93e24442014-01-06 12:30:52 -08001164/* Flags for version 1+ flash info command */
1165/* EC flash erases bits to 0 instead of 1 */
1166#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1167
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001168/* Flash must be selected for read/write/erase operations to succeed. This may
1169 * be necessary on a chip where write/erase can be corrupted by other board
1170 * activity, or where the chip needs to enable some sort of programming voltage,
1171 * or where the read/write/erase operations require cleanly suspending other
1172 * chip functionality. */
1173#define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1174
Duncan Laurie93e24442014-01-06 12:30:52 -08001175/*
1176 * Version 1 returns the same initial fields as version 0, with additional
1177 * fields following.
1178 *
1179 * gcc anonymous structs don't seem to get along with the __packed directive;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001180 * if they did we'd define the version 0 structure as a sub-structure of this
1181 * one.
1182 *
1183 * Version 2 supports flash banks of different sizes:
1184 * The caller specified the number of banks it has preallocated
1185 * (num_banks_desc)
1186 * The EC returns the number of banks describing the flash memory.
1187 * It adds banks descriptions up to num_banks_desc.
Duncan Laurie93e24442014-01-06 12:30:52 -08001188 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001189struct __ec_align4 ec_response_flash_info_1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08001190 /* Version 0 fields; see above for description */
1191 uint32_t flash_size;
1192 uint32_t write_block_size;
1193 uint32_t erase_block_size;
1194 uint32_t protect_block_size;
1195
1196 /* Version 1 adds these fields: */
1197 /*
1198 * Ideal write size in bytes. Writes will be fastest if size is
1199 * exactly this and offset is a multiple of this. For example, an EC
1200 * may have a write buffer which can do half-page operations if data is
1201 * aligned, and a slower word-at-a-time write mode.
1202 */
1203 uint32_t write_ideal_size;
1204
1205 /* Flags; see EC_FLASH_INFO_* */
1206 uint32_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001207};
1208
1209struct __ec_align4 ec_params_flash_info_2 {
1210 /* Number of banks to describe */
1211 uint16_t num_banks_desc;
1212 /* Reserved; set 0; ignore on read */
1213 uint8_t reserved[2];
1214};
1215
1216struct ec_flash_bank {
1217 /* Number of sector is in this bank. */
1218 uint16_t count;
1219 /* Size in power of 2 of each sector (8 --> 256 bytes) */
1220 uint8_t size_exp;
1221 /* Minimal write size for the sectors in this bank */
1222 uint8_t write_size_exp;
1223 /* Erase size for the sectors in this bank */
1224 uint8_t erase_size_exp;
1225 /* Size for write protection, usually identical to erase size. */
1226 uint8_t protect_size_exp;
1227 /* Reserved; set 0; ignore on read */
1228 uint8_t reserved[2];
1229};
1230
1231struct __ec_align4 ec_response_flash_info_2 {
1232 /* Total flash in the EC. */
1233 uint32_t flash_size;
1234 /* Flags; see EC_FLASH_INFO_* */
1235 uint32_t flags;
1236 /* Maximum size to use to send data to write to the EC. */
1237 uint32_t write_ideal_size;
1238 /* Number of banks present in the EC. */
1239 uint16_t num_banks_total;
1240 /* Number of banks described in banks array. */
1241 uint16_t num_banks_desc;
1242 struct ec_flash_bank banks[0];
1243};
Duncan Laurie93e24442014-01-06 12:30:52 -08001244
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001245/*
1246 * Read flash
1247 *
1248 * Response is params.size bytes of data.
1249 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001250#define EC_CMD_FLASH_READ 0x0011
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001251
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001252struct __ec_align4 ec_params_flash_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001253 uint32_t offset; /* Byte offset to read */
1254 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001255};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001256
1257/* Write flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001258#define EC_CMD_FLASH_WRITE 0x0012
Duncan Laurie93e24442014-01-06 12:30:52 -08001259#define EC_VER_FLASH_WRITE 1
1260
1261/* Version 0 of the flash command supported only 64 bytes of data */
1262#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001263
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001264struct __ec_align4 ec_params_flash_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001265 uint32_t offset; /* Byte offset to write */
1266 uint32_t size; /* Size to write in bytes */
Duncan Laurie93e24442014-01-06 12:30:52 -08001267 /* Followed by data to write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001268};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001269
1270/* Erase flash */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001271#define EC_CMD_FLASH_ERASE 0x0013
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001272
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001273/* v0 */
1274struct __ec_align4 ec_params_flash_erase {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001275 uint32_t offset; /* Byte offset to erase */
1276 uint32_t size; /* Size to erase in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001277};
1278
1279
1280#define EC_VER_FLASH_WRITE 1
1281/* v1 add async erase:
1282 * subcommands can returns:
1283 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1284 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1285 * EC_RES_ERROR : other errors.
1286 * EC_RES_BUSY : an existing erase operation is in progress.
1287 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1288 *
1289 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
1290 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1291 * the proper result.
1292 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1293 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1294 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1295 * permitted while erasing. (For instance, STM32F4).
1296 */
1297enum ec_flash_erase_cmd {
1298 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1299 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1300 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1301};
1302
1303struct __ec_align4 ec_params_flash_erase_v1 {
1304 /* One of ec_flash_erase_cmd. */
1305 uint8_t cmd;
1306 /* Pad byte; currently always contains 0 */
1307 uint8_t reserved;
1308 /* No flags defined yet; set to 0 */
1309 uint16_t flag;
1310 /* Same as v0 parameters. */
1311 struct ec_params_flash_erase params;
1312};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001313
1314/*
1315 * Get/set flash protection.
1316 *
1317 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1318 * firmware write protect GPIO, not all flags will take effect immediately;
1319 * some flags require a subsequent hard reset to take effect. Check the
1320 * returned flags bits to see what actually happened.
1321 *
1322 * If mask=0, simply returns the current flags state.
1323 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001324#define EC_CMD_FLASH_PROTECT 0x0015
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001325#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1326
1327/* Flags for flash protection */
1328/* RO flash code protected when the EC boots */
1329#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1330/*
1331 * RO flash code protected now. If this bit is set, at-boot status cannot
1332 * be changed.
1333 */
1334#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001335/* Entire flash code protected now, until reboot. */
1336#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001337/* Flash write protect GPIO is asserted now */
1338#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1339/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1340#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1341/*
1342 * Error - flash protection is in inconsistent state. At least one bank of
1343 * flash which should be protected is not protected. Usually fixed by
1344 * re-requesting the desired flags, or by a hard reset if that fails.
1345 */
1346#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001347/* Entire flash code protected when the EC boots */
Duncan Laurie433432b2013-06-03 10:38:22 -07001348#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001349/* RW flash code protected when the EC boots */
1350#define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
1351/* RW flash code protected now. */
1352#define EC_FLASH_PROTECT_RW_NOW (1 << 8)
1353/* Rollback information flash region protected when the EC boots */
1354#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
1355/* Rollback information flash region protected now */
1356#define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001357
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001358struct __ec_align4 ec_params_flash_protect {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001359 uint32_t mask; /* Bits in flags to apply */
1360 uint32_t flags; /* New flags to apply */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001361};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001362
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001363struct __ec_align4 ec_response_flash_protect {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001364 /* Current value of flash protect flags */
1365 uint32_t flags;
1366 /*
1367 * Flags which are valid on this platform. This allows the caller
1368 * to distinguish between flags which aren't set vs. flags which can't
1369 * be set on this platform.
1370 */
1371 uint32_t valid_flags;
1372 /* Flags which can be changed given the current protection state */
1373 uint32_t writable_flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001374};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001375
1376/*
1377 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1378 * write protect. These commands may be reused with version > 0.
1379 */
1380
1381/* Get the region offset/size */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001382#define EC_CMD_FLASH_REGION_INFO 0x0016
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001383#define EC_VER_FLASH_REGION_INFO 1
1384
1385enum ec_flash_region {
1386 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001387 EC_FLASH_REGION_RO = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001388 /* Region which holds rewritable EC image */
1389 EC_FLASH_REGION_RW,
1390 /*
1391 * Region which should be write-protected in the factory (a superset of
1392 * EC_FLASH_REGION_RO)
1393 */
1394 EC_FLASH_REGION_WP_RO,
Duncan Laurie93e24442014-01-06 12:30:52 -08001395 /* Number of regions */
1396 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001397};
1398
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001399struct __ec_align4 ec_params_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001400 uint32_t region; /* enum ec_flash_region */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001401};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001402
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001403struct __ec_align4 ec_response_flash_region_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001404 uint32_t offset;
1405 uint32_t size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001406};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001407
Duncan Laurie433432b2013-06-03 10:38:22 -07001408/* Read/write VbNvContext */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001409#define EC_CMD_VBNV_CONTEXT 0x0017
Duncan Laurie433432b2013-06-03 10:38:22 -07001410#define EC_VER_VBNV_CONTEXT 1
1411#define EC_VBNV_BLOCK_SIZE 16
1412
1413enum ec_vbnvcontext_op {
1414 EC_VBNV_CONTEXT_OP_READ,
1415 EC_VBNV_CONTEXT_OP_WRITE,
1416};
1417
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001418struct __ec_align4 ec_params_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001419 uint32_t op;
1420 uint8_t block[EC_VBNV_BLOCK_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001421};
Duncan Laurie433432b2013-06-03 10:38:22 -07001422
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001423struct __ec_align4 ec_response_vbnvcontext {
Duncan Laurie433432b2013-06-03 10:38:22 -07001424 uint8_t block[EC_VBNV_BLOCK_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001425};
1426
1427
1428/* Get SPI flash information */
1429#define EC_CMD_FLASH_SPI_INFO 0x0018
1430
1431struct __ec_align1 ec_response_flash_spi_info {
1432 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1433 uint8_t jedec[3];
1434
1435 /* Pad byte; currently always contains 0 */
1436 uint8_t reserved0;
1437
1438 /* Manufacturer / device ID from command 0x90 */
1439 uint8_t mfr_dev_id[2];
1440
1441 /* Status registers from command 0x05 and 0x35 */
1442 uint8_t sr1, sr2;
1443};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001444
Patrick Georgi0f6187a2017-07-28 15:57:23 +02001445
1446/* Select flash during flash operations */
1447#define EC_CMD_FLASH_SELECT 0x0019
1448
1449struct __ec_align4 ec_params_flash_select {
1450 /* 1 to select flash, 0 to deselect flash */
1451 uint8_t select;
1452};
1453
1454
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001455/*****************************************************************************/
1456/* PWM commands */
1457
1458/* Get fan target RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001459#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001460
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001461struct __ec_align4 ec_response_pwm_get_fan_rpm {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001462 uint32_t rpm;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001463};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001464
1465/* Set target fan RPM */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001466#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001467
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001468/* Version 0 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001469struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001470 uint32_t rpm;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001471};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001472
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001473/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001474struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001475 uint32_t rpm;
1476 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001477};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001478
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001479/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001480/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001481#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001482
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001483struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001484 uint8_t percent;
1485 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001486};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001487
1488/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001489/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001490#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001491
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001492struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001493 uint8_t percent;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001494};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001495
1496/* Set target fan PWM duty cycle */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001497#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001498
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001499/* Version 0 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001500struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001501 uint32_t percent;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001502};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001503
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001504/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001505struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001506 uint32_t percent;
1507 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001508};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001509
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001510#define EC_CMD_PWM_SET_DUTY 0x0025
Gwendal Grignou880b4582016-06-20 08:49:25 -07001511/* 16 bit duty cycle, 0xffff = 100% */
1512#define EC_PWM_MAX_DUTY 0xffff
1513
1514enum ec_pwm_type {
1515 /* All types, indexed by board-specific enum pwm_channel */
1516 EC_PWM_TYPE_GENERIC = 0,
1517 /* Keyboard backlight */
1518 EC_PWM_TYPE_KB_LIGHT,
1519 /* Display backlight */
1520 EC_PWM_TYPE_DISPLAY_LIGHT,
1521 EC_PWM_TYPE_COUNT,
1522};
1523
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001524struct __ec_align4 ec_params_pwm_set_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001525 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1526 uint8_t pwm_type; /* ec_pwm_type */
1527 uint8_t index; /* Type-specific index, or 0 if unique */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001528};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001529
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001530#define EC_CMD_PWM_GET_DUTY 0x0026
Gwendal Grignou880b4582016-06-20 08:49:25 -07001531
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001532struct __ec_align1 ec_params_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001533 uint8_t pwm_type; /* ec_pwm_type */
1534 uint8_t index; /* Type-specific index, or 0 if unique */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001535};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001536
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001537struct __ec_align2 ec_response_pwm_get_duty {
Gwendal Grignou880b4582016-06-20 08:49:25 -07001538 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001539};
Gwendal Grignou880b4582016-06-20 08:49:25 -07001540
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001541/*****************************************************************************/
1542/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001543 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001544 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1545 * into a subcommand. We'll make separate structs for subcommands with
1546 * different input args, so that we know how much to expect.
1547 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001548#define EC_CMD_LIGHTBAR_CMD 0x0028
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001549
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001550struct __ec_todo_unpacked rgb_s {
Duncan Laurie433432b2013-06-03 10:38:22 -07001551 uint8_t r, g, b;
1552};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001553
Duncan Laurie433432b2013-06-03 10:38:22 -07001554#define LB_BATTERY_LEVELS 4
1555/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1556 * host command, but the alignment is the same regardless. Keep it that way.
1557 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001558struct __ec_todo_packed lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001559 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001560 int32_t google_ramp_up;
1561 int32_t google_ramp_down;
1562 int32_t s3s0_ramp_up;
1563 int32_t s0_tick_delay[2]; /* AC=0/1 */
1564 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1565 int32_t s0s3_ramp_down;
1566 int32_t s3_sleep_for;
1567 int32_t s3_ramp_up;
1568 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001569
1570 /* Oscillation */
1571 uint8_t new_s0;
1572 uint8_t osc_min[2]; /* AC=0/1 */
1573 uint8_t osc_max[2]; /* AC=0/1 */
1574 uint8_t w_ofs[2]; /* AC=0/1 */
1575
1576 /* Brightness limits based on the backlight and AC. */
1577 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1578 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1579 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1580
1581 /* Battery level thresholds */
1582 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1583
1584 /* Map [AC][battery_level] to color index */
1585 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1586 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1587
1588 /* Color palette */
1589 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001590};
Duncan Laurie433432b2013-06-03 10:38:22 -07001591
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001592struct __ec_todo_packed lightbar_params_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001593 /* Timing */
1594 int32_t google_ramp_up;
1595 int32_t google_ramp_down;
1596 int32_t s3s0_ramp_up;
1597 int32_t s0_tick_delay[2]; /* AC=0/1 */
1598 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1599 int32_t s0s3_ramp_down;
1600 int32_t s3_sleep_for;
1601 int32_t s3_ramp_up;
1602 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001603 int32_t s5_ramp_up;
1604 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001605 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001606 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001607 int32_t tap_display_time;
1608
1609 /* Tap-for-battery params */
1610 uint8_t tap_pct_red;
1611 uint8_t tap_pct_green;
1612 uint8_t tap_seg_min_on;
1613 uint8_t tap_seg_max_on;
1614 uint8_t tap_seg_osc;
1615 uint8_t tap_idx[3];
1616
1617 /* Oscillation */
1618 uint8_t osc_min[2]; /* AC=0/1 */
1619 uint8_t osc_max[2]; /* AC=0/1 */
1620 uint8_t w_ofs[2]; /* AC=0/1 */
1621
1622 /* Brightness limits based on the backlight and AC. */
1623 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1624 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1625 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1626
1627 /* Battery level thresholds */
1628 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1629
1630 /* Map [AC][battery_level] to color index */
1631 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1632 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1633
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001634 /* s5: single color pulse on inhibited power-up */
1635 uint8_t s5_idx;
1636
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001637 /* Color palette */
1638 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001639};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001640
Duncan Laurieeb316852015-12-01 18:51:18 -08001641/* Lightbar command params v2
1642 * crbug.com/467716
1643 *
1644 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1645 * logical groups to make it more manageable ( < 120 bytes).
1646 *
1647 * NOTE: Each of these groups must be less than 120 bytes.
1648 */
1649
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001650struct __ec_todo_packed lightbar_params_v2_timing {
Duncan Laurieeb316852015-12-01 18:51:18 -08001651 /* Timing */
1652 int32_t google_ramp_up;
1653 int32_t google_ramp_down;
1654 int32_t s3s0_ramp_up;
1655 int32_t s0_tick_delay[2]; /* AC=0/1 */
1656 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1657 int32_t s0s3_ramp_down;
1658 int32_t s3_sleep_for;
1659 int32_t s3_ramp_up;
1660 int32_t s3_ramp_down;
1661 int32_t s5_ramp_up;
1662 int32_t s5_ramp_down;
1663 int32_t tap_tick_delay;
1664 int32_t tap_gate_delay;
1665 int32_t tap_display_time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001666};
Duncan Laurieeb316852015-12-01 18:51:18 -08001667
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001668struct __ec_todo_packed lightbar_params_v2_tap {
Duncan Laurieeb316852015-12-01 18:51:18 -08001669 /* Tap-for-battery params */
1670 uint8_t tap_pct_red;
1671 uint8_t tap_pct_green;
1672 uint8_t tap_seg_min_on;
1673 uint8_t tap_seg_max_on;
1674 uint8_t tap_seg_osc;
1675 uint8_t tap_idx[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001676};
Duncan Laurieeb316852015-12-01 18:51:18 -08001677
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001678struct __ec_todo_packed lightbar_params_v2_oscillation {
Duncan Laurieeb316852015-12-01 18:51:18 -08001679 /* Oscillation */
1680 uint8_t osc_min[2]; /* AC=0/1 */
1681 uint8_t osc_max[2]; /* AC=0/1 */
1682 uint8_t w_ofs[2]; /* AC=0/1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001683};
Duncan Laurieeb316852015-12-01 18:51:18 -08001684
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001685struct __ec_todo_packed lightbar_params_v2_brightness {
Duncan Laurieeb316852015-12-01 18:51:18 -08001686 /* Brightness limits based on the backlight and AC. */
1687 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1688 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1689 uint8_t bright_bl_on_max[2]; /* AC=0/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_thresholds {
Duncan Laurieeb316852015-12-01 18:51:18 -08001693 /* Battery level thresholds */
1694 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001695};
Duncan Laurieeb316852015-12-01 18:51:18 -08001696
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001697struct __ec_todo_packed lightbar_params_v2_colors {
Duncan Laurieeb316852015-12-01 18:51:18 -08001698 /* Map [AC][battery_level] to color index */
1699 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1700 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1701
1702 /* s5: single color pulse on inhibited power-up */
1703 uint8_t s5_idx;
1704
1705 /* Color palette */
1706 struct rgb_s color[8]; /* 0-3 are Google colors */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001707};
Duncan Laurieeb316852015-12-01 18:51:18 -08001708
Duncan Lauried8401182014-09-29 08:32:19 -07001709/* Lightbyte program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001710#define EC_LB_PROG_LEN 192
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001711struct __ec_todo_unpacked lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07001712 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001713 uint8_t data[EC_LB_PROG_LEN];
Duncan Lauried8401182014-09-29 08:32:19 -07001714};
1715
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001716struct __ec_todo_packed ec_params_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07001717 uint8_t cmd; /* Command (see enum lightbar_command) */
1718 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001719 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001720 /* no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001721 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001722 version, get_brightness, get_demo, suspend, resume,
1723 get_params_v2_timing, get_params_v2_tap,
1724 get_params_v2_osc, get_params_v2_bright,
1725 get_params_v2_thlds, get_params_v2_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001726
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001727 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001728 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001729 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001730
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001731 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001732 uint8_t ctrl, reg, value;
1733 } reg;
1734
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001735 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001736 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001737 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07001738
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001739 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001740 uint8_t led;
1741 } get_rgb;
1742
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001743 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001744 uint8_t enable;
1745 } manual_suspend_ctrl;
1746
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001747 struct lightbar_params_v0 set_params_v0;
1748 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08001749
1750 struct lightbar_params_v2_timing set_v2par_timing;
1751 struct lightbar_params_v2_tap set_v2par_tap;
1752 struct lightbar_params_v2_oscillation set_v2par_osc;
1753 struct lightbar_params_v2_brightness set_v2par_bright;
1754 struct lightbar_params_v2_thresholds set_v2par_thlds;
1755 struct lightbar_params_v2_colors set_v2par_colors;
1756
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001757 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001758 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001759};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001760
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001761struct __ec_todo_packed ec_response_lightbar {
Duncan Laurie433432b2013-06-03 10:38:22 -07001762 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001763 struct __ec_todo_unpacked {
1764 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001765 uint8_t reg;
1766 uint8_t ic0;
1767 uint8_t ic1;
1768 } vals[23];
1769 } dump;
1770
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001771 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001772 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001773 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001774
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001775 struct lightbar_params_v0 get_params_v0;
1776 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07001777
Duncan Laurieeb316852015-12-01 18:51:18 -08001778
1779 struct lightbar_params_v2_timing get_params_v2_timing;
1780 struct lightbar_params_v2_tap get_params_v2_tap;
1781 struct lightbar_params_v2_oscillation get_params_v2_osc;
1782 struct lightbar_params_v2_brightness get_params_v2_bright;
1783 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1784 struct lightbar_params_v2_colors get_params_v2_colors;
1785
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001786 struct __ec_todo_unpacked {
Duncan Laurie93e24442014-01-06 12:30:52 -08001787 uint32_t num;
1788 uint32_t flags;
1789 } version;
1790
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001791 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001792 uint8_t red, green, blue;
1793 } get_rgb;
1794
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001795 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07001796 /* no return params */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001797 } off, on, init, set_brightness, seq, reg, set_rgb,
Duncan Lauried8401182014-09-29 08:32:19 -07001798 demo, set_params_v0, set_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001799 set_program, manual_suspend_ctrl, suspend, resume,
1800 set_v2par_timing, set_v2par_tap,
1801 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1802 set_v2par_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001803 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001804};
Duncan Laurie433432b2013-06-03 10:38:22 -07001805
1806/* Lightbar commands */
1807enum lightbar_command {
1808 LIGHTBAR_CMD_DUMP = 0,
1809 LIGHTBAR_CMD_OFF = 1,
1810 LIGHTBAR_CMD_ON = 2,
1811 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001812 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07001813 LIGHTBAR_CMD_SEQ = 5,
1814 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001815 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07001816 LIGHTBAR_CMD_GET_SEQ = 8,
1817 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001818 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1819 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08001820 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001821 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1822 LIGHTBAR_CMD_GET_RGB = 14,
1823 LIGHTBAR_CMD_GET_DEMO = 15,
1824 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1825 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07001826 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001827 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1828 LIGHTBAR_CMD_SUSPEND = 20,
1829 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08001830 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1831 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1832 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1833 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1834 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1835 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1836 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1837 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1838 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1839 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1840 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1841 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07001842 LIGHTBAR_NUM_CMDS
1843};
1844
1845/*****************************************************************************/
1846/* LED control commands */
1847
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001848#define EC_CMD_LED_CONTROL 0x0029
Duncan Laurie433432b2013-06-03 10:38:22 -07001849
Bill Richardsone221aad2013-06-12 10:50:41 -07001850enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08001851 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07001852 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08001853 /*
1854 * LED to indicate system power state (on or in suspend).
1855 * May be on power button or on C-panel.
1856 */
1857 EC_LED_ID_POWER_LED,
1858 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07001859 EC_LED_ID_ADAPTER_LED,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001860 /* LED to indicate left side */
1861 EC_LED_ID_LEFT_LED,
1862 /* LED to indicate right side */
1863 EC_LED_ID_RIGHT_LED,
1864 /* LED to indicate recovery mode with HW_REINIT */
1865 EC_LED_ID_RECOVERY_HW_REINIT_LED,
1866 /* LED to indicate sysrq debug mode. */
1867 EC_LED_ID_SYSRQ_DEBUG_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08001868
1869 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07001870};
Duncan Laurie433432b2013-06-03 10:38:22 -07001871
Bill Richardsone221aad2013-06-12 10:50:41 -07001872/* LED control flags */
1873#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1874#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1875
1876enum ec_led_colors {
1877 EC_LED_COLOR_RED = 0,
1878 EC_LED_COLOR_GREEN,
1879 EC_LED_COLOR_BLUE,
1880 EC_LED_COLOR_YELLOW,
1881 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08001882 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07001883
1884 EC_LED_COLOR_COUNT
1885};
1886
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001887struct __ec_align1 ec_params_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07001888 uint8_t led_id; /* Which LED to control */
1889 uint8_t flags; /* Control flags */
1890
1891 uint8_t brightness[EC_LED_COLOR_COUNT];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001892};
Bill Richardsone221aad2013-06-12 10:50:41 -07001893
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001894struct __ec_align1 ec_response_led_control {
Bill Richardsone221aad2013-06-12 10:50:41 -07001895 /*
1896 * Available brightness value range.
1897 *
1898 * Range 0 means color channel not present.
1899 * Range 1 means on/off control.
1900 * Other values means the LED is control by PWM.
1901 */
1902 uint8_t brightness_range[EC_LED_COLOR_COUNT];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001903};
Duncan Laurie433432b2013-06-03 10:38:22 -07001904
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001905/*****************************************************************************/
1906/* Verified boot commands */
1907
1908/*
1909 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1910 * reused for other purposes with version > 0.
1911 */
1912
1913/* Verified boot hash command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001914#define EC_CMD_VBOOT_HASH 0x002A
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001915
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001916struct __ec_align4 ec_params_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001917 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1918 uint8_t hash_type; /* enum ec_vboot_hash_type */
1919 uint8_t nonce_size; /* Nonce size; may be 0 */
1920 uint8_t reserved0; /* Reserved; set 0 */
1921 uint32_t offset; /* Offset in flash to hash */
1922 uint32_t size; /* Number of bytes to hash */
1923 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001924};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001925
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001926struct __ec_align4 ec_response_vboot_hash {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001927 uint8_t status; /* enum ec_vboot_hash_status */
1928 uint8_t hash_type; /* enum ec_vboot_hash_type */
1929 uint8_t digest_size; /* Size of hash digest in bytes */
1930 uint8_t reserved0; /* Ignore; will be 0 */
1931 uint32_t offset; /* Offset in flash which was hashed */
1932 uint32_t size; /* Number of bytes hashed */
1933 uint8_t hash_digest[64]; /* Hash digest data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001934};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001935
1936enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07001937 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1938 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1939 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1940 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001941};
1942
1943enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07001944 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001945};
1946
1947enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001948 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1949 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1950 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001951};
1952
Duncan Laurie433432b2013-06-03 10:38:22 -07001953/*
1954 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1955 * If one of these is specified, the EC will automatically update offset and
1956 * size to the correct values for the specified image (RO or RW).
1957 */
1958#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1959#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1960
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001961/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001962/*
1963 * Motion sense commands. We'll make separate structs for sub-commands with
1964 * different input args, so that we know how much to expect.
1965 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07001966#define EC_CMD_MOTION_SENSE_CMD 0x002B
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001967
1968/* Motion sense commands */
1969enum motionsense_command {
1970 /*
1971 * Dump command returns all motion sensor data including motion sense
1972 * module flags and individual sensor flags.
1973 */
1974 MOTIONSENSE_CMD_DUMP = 0,
1975
1976 /*
1977 * Info command returns data describing the details of a given sensor,
1978 * including enum motionsensor_type, enum motionsensor_location, and
1979 * enum motionsensor_chip.
1980 */
1981 MOTIONSENSE_CMD_INFO = 1,
1982
1983 /*
1984 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08001985 * in milliseconds.
1986 * It is per sensor, the EC run sample task at the minimum of all
1987 * sensors EC_RATE.
1988 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
1989 * to collect all the sensor samples.
1990 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
1991 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001992 */
1993 MOTIONSENSE_CMD_EC_RATE = 2,
1994
1995 /*
1996 * Sensor ODR command is a setter/getter command for the output data
1997 * rate of a specific motion sensor in millihertz.
1998 */
1999 MOTIONSENSE_CMD_SENSOR_ODR = 3,
2000
2001 /*
2002 * Sensor range command is a setter/getter command for the range of
2003 * a specified motion sensor in +/-G's or +/- deg/s.
2004 */
2005 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
2006
2007 /*
2008 * Setter/getter command for the keyboard wake angle. When the lid
2009 * angle is greater than this value, keyboard wake is disabled in S3,
2010 * and when the lid angle goes less than this value, keyboard wake is
2011 * enabled. Note, the lid angle measurement is an approximate,
2012 * un-calibrated value, hence the wake angle isn't exact.
2013 */
2014 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
2015
Duncan Laurieeb316852015-12-01 18:51:18 -08002016 /*
2017 * Returns a single sensor data.
2018 */
2019 MOTIONSENSE_CMD_DATA = 6,
2020
2021 /*
2022 * Return sensor fifo info.
2023 */
2024 MOTIONSENSE_CMD_FIFO_INFO = 7,
2025
2026 /*
2027 * Insert a flush element in the fifo and return sensor fifo info.
2028 * The host can use that element to synchronize its operation.
2029 */
2030 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2031
2032 /*
2033 * Return a portion of the fifo.
2034 */
2035 MOTIONSENSE_CMD_FIFO_READ = 9,
2036
2037 /*
2038 * Perform low level calibration.
2039 * On sensors that support it, ask to do offset calibration.
2040 */
2041 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2042
2043 /*
2044 * Sensor Offset command is a setter/getter command for the offset
2045 * used for calibration.
2046 * The offsets can be calculated by the host, or via
2047 * PERFORM_CALIB command.
2048 */
2049 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2050
2051 /*
2052 * List available activities for a MOTION sensor.
2053 * Indicates if they are enabled or disabled.
2054 */
2055 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2056
2057 /*
2058 * Activity management
2059 * Enable/Disable activity recognition.
2060 */
2061 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2062
2063 /*
2064 * Lid Angle
2065 */
2066 MOTIONSENSE_CMD_LID_ANGLE = 14,
2067
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002068 /*
2069 * Allow the FIFO to trigger interrupt via MKBP events.
2070 * By default the FIFO does not send interrupt to process the FIFO
2071 * until the AP is ready or it is coming from a wakeup sensor.
2072 */
2073 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2074
2075 /*
2076 * Spoof the readings of the sensors. The spoofed readings can be set
2077 * to arbitrary values, or will lock to the last read actual values.
2078 */
2079 MOTIONSENSE_CMD_SPOOF = 16,
2080
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002081 /* Number of motionsense sub-commands. */
2082 MOTIONSENSE_NUM_CMDS
2083};
2084
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002085/* List of motion sensor types. */
2086enum motionsensor_type {
2087 MOTIONSENSE_TYPE_ACCEL = 0,
2088 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002089 MOTIONSENSE_TYPE_MAG = 2,
2090 MOTIONSENSE_TYPE_PROX = 3,
2091 MOTIONSENSE_TYPE_LIGHT = 4,
2092 MOTIONSENSE_TYPE_ACTIVITY = 5,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002093 MOTIONSENSE_TYPE_BARO = 6,
Duncan Laurieeb316852015-12-01 18:51:18 -08002094 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002095};
2096
2097/* List of motion sensor locations. */
2098enum motionsensor_location {
2099 MOTIONSENSE_LOC_BASE = 0,
2100 MOTIONSENSE_LOC_LID = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002101 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002102};
2103
2104/* List of motion sensor chips. */
2105enum motionsensor_chip {
2106 MOTIONSENSE_CHIP_KXCJ9 = 0,
2107 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08002108 MOTIONSENSE_CHIP_BMI160 = 2,
2109 MOTIONSENSE_CHIP_SI1141 = 3,
2110 MOTIONSENSE_CHIP_SI1142 = 4,
2111 MOTIONSENSE_CHIP_SI1143 = 5,
2112 MOTIONSENSE_CHIP_KX022 = 6,
2113 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07002114 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002115 MOTIONSENSE_CHIP_BMP280 = 9,
2116 MOTIONSENSE_CHIP_OPT3001 = 10,
Duncan Laurieeb316852015-12-01 18:51:18 -08002117};
2118
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002119struct __ec_todo_packed ec_response_motion_sensor_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002120 /* Flags for each sensor. */
2121 uint8_t flags;
2122 /* sensor number the data comes from */
2123 uint8_t sensor_num;
2124 /* Each sensor is up to 3-axis. */
2125 union {
2126 int16_t data[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002127 struct __ec_todo_packed {
2128 uint16_t reserved;
Duncan Laurieeb316852015-12-01 18:51:18 -08002129 uint32_t timestamp;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002130 };
2131 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002132 uint8_t activity; /* motionsensor_activity */
2133 uint8_t state;
2134 int16_t add_info[2];
2135 };
2136 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002137};
Duncan Laurieeb316852015-12-01 18:51:18 -08002138
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002139/* Note: used in ec_response_get_next_data */
2140struct __ec_todo_packed ec_response_motion_sense_fifo_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002141 /* Size of the fifo */
2142 uint16_t size;
2143 /* Amount of space used in the fifo */
2144 uint16_t count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002145 /* Timestamp recorded in us */
Duncan Laurieeb316852015-12-01 18:51:18 -08002146 uint32_t timestamp;
2147 /* Total amount of vector lost */
2148 uint16_t total_lost;
2149 /* Lost events since the last fifo_info, per sensors */
2150 uint16_t lost[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002151};
Duncan Laurieeb316852015-12-01 18:51:18 -08002152
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002153struct __ec_todo_packed ec_response_motion_sense_fifo_data {
Duncan Laurieeb316852015-12-01 18:51:18 -08002154 uint32_t number_data;
2155 struct ec_response_motion_sensor_data data[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002156};
Duncan Laurieeb316852015-12-01 18:51:18 -08002157
2158/* List supported activity recognition */
2159enum motionsensor_activity {
2160 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2161 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2162 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2163};
2164
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002165struct __ec_todo_unpacked ec_motion_sense_activity {
Duncan Laurieeb316852015-12-01 18:51:18 -08002166 uint8_t sensor_num;
2167 uint8_t activity; /* one of enum motionsensor_activity */
2168 uint8_t enable; /* 1: enable, 0: disable */
2169 uint8_t reserved;
2170 uint16_t parameters[3]; /* activity dependent parameters */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002171};
2172
2173/* Module flag masks used for the dump sub-command. */
2174#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2175
2176/* Sensor flag masks used for the dump sub-command. */
2177#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2178
2179/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002180 * Flush entry for synchronization.
Duncan Laurieeb316852015-12-01 18:51:18 -08002181 * data contains time stamp
2182 */
2183#define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2184#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2185#define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002186#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
Duncan Laurieeb316852015-12-01 18:51:18 -08002187
2188/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002189 * Send this value for the data element to only perform a read. If you
2190 * send any other value, the EC will interpret it as data to set and will
2191 * return the actual value set.
2192 */
2193#define EC_MOTION_SENSE_NO_VALUE -1
2194
Duncan Laurieeb316852015-12-01 18:51:18 -08002195#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2196
2197/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2198/* Set Calibration information */
2199#define MOTION_SENSE_SET_OFFSET 1
2200
2201#define LID_ANGLE_UNRELIABLE 500
2202
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002203enum motionsense_spoof_mode {
2204 /* Disable spoof mode. */
2205 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2206
2207 /* Enable spoof mode, but use provided component values. */
2208 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2209
2210 /* Enable spoof mode, but use the current sensor values. */
2211 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2212
2213 /* Query the current spoof mode status for the sensor. */
2214 MOTIONSENSE_SPOOF_MODE_QUERY,
2215};
2216
2217struct __ec_todo_packed ec_params_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002218 uint8_t cmd;
2219 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002220 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002221 struct __ec_todo_unpacked {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002222 /*
2223 * Maximal number of sensor the host is expecting.
2224 * 0 means the host is only interested in the number
2225 * of sensors controlled by the EC.
2226 */
2227 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002228 } dump;
2229
2230 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002231 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002232 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002233 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002234 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2235 * kb_wake_angle: angle to wakup AP.
2236 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002237 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002238 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002239
Duncan Laurieeb316852015-12-01 18:51:18 -08002240 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2241 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002242 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002243 uint8_t sensor_num;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002244 } info, info_3, data, fifo_flush, perform_calib,
2245 list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002246
2247 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08002248 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2249 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002250 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002251 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002252 uint8_t sensor_num;
2253
2254 /* Rounding flag, true for round-up, false for down. */
2255 uint8_t roundup;
2256
2257 uint16_t reserved;
2258
2259 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2260 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08002261 } ec_rate, sensor_odr, sensor_range;
2262
2263 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002264 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002265 uint8_t sensor_num;
2266
2267 /*
2268 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2269 * the calibration information in the EC.
2270 * If unset, just retrieve calibration information.
2271 */
2272 uint16_t flags;
2273
2274 /*
2275 * Temperature at calibration, in units of 0.01 C
2276 * 0x8000: invalid / unknown.
2277 * 0x0: 0C
2278 * 0x7fff: +327.67C
2279 */
2280 int16_t temp;
2281
2282 /*
2283 * Offset for calibration.
2284 * Unit:
2285 * Accelerometer: 1/1024 g
2286 * Gyro: 1/1024 deg/s
2287 * Compass: 1/16 uT
2288 */
2289 int16_t offset[3];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002290 } sensor_offset;
Duncan Laurieeb316852015-12-01 18:51:18 -08002291
2292 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002293 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002294 } fifo_info;
2295
2296 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002297 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002298 /*
2299 * Number of expected vector to return.
2300 * EC may return less or 0 if none available.
2301 */
2302 uint32_t max_data_vector;
2303 } fifo_read;
2304
2305 struct ec_motion_sense_activity set_activity;
2306
2307 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002308 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002309 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002310
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002311 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
2312 struct __ec_todo_unpacked {
2313 /*
2314 * 1: enable, 0 disable fifo,
2315 * EC_MOTION_SENSE_NO_VALUE return value.
2316 */
2317 int8_t enable;
2318 } fifo_int_enable;
2319
2320 /* Used for MOTIONSENSE_CMD_SPOOF */
2321 struct __ec_todo_packed {
2322 uint8_t sensor_id;
2323
2324 /* See enum motionsense_spoof_mode. */
2325 uint8_t spoof_enable;
2326
2327 /* Ignored, used for alignment. */
2328 uint8_t reserved;
2329
2330 /* Individual component values to spoof. */
2331 int16_t components[3];
2332 } spoof;
2333 };
2334};
2335
2336struct __ec_todo_packed ec_response_motion_sense {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002337 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002338 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002339 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002340 /* Flags representing the motion sensor module. */
2341 uint8_t module_flags;
2342
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002343 /* Number of sensors managed directly by the EC */
2344 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002345
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002346 /*
2347 * sensor data is truncated if response_max is too small
2348 * for holding all the data.
2349 */
2350 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002351 } dump;
2352
2353 /* Used for MOTIONSENSE_CMD_INFO. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002354 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002355 /* Should be element of enum motionsensor_type. */
2356 uint8_t type;
2357
2358 /* Should be element of enum motionsensor_location. */
2359 uint8_t location;
2360
2361 /* Should be element of enum motionsensor_chip. */
2362 uint8_t chip;
2363 } info;
2364
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002365 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2366 struct __ec_todo_unpacked {
2367 /* Should be element of enum motionsensor_type. */
2368 uint8_t type;
2369
2370 /* Should be element of enum motionsensor_location. */
2371 uint8_t location;
2372
2373 /* Should be element of enum motionsensor_chip. */
2374 uint8_t chip;
2375
2376 /* Minimum sensor sampling frequency */
2377 uint32_t min_frequency;
2378
2379 /* Maximum sensor sampling frequency */
2380 uint32_t max_frequency;
2381
2382 /* Max number of sensor events that could be in fifo */
2383 uint32_t fifo_max_event_count;
2384 } info_3;
2385
Duncan Laurieeb316852015-12-01 18:51:18 -08002386 /* Used for MOTIONSENSE_CMD_DATA */
2387 struct ec_response_motion_sensor_data data;
2388
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002389 /*
2390 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002391 * MOTIONSENSE_CMD_SENSOR_RANGE,
2392 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2393 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2394 * MOTIONSENSE_CMD_SPOOF.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002395 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002396 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002397 /* Current value of the parameter queried. */
2398 int32_t ret;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002399 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
2400 fifo_int_enable, spoof;
Duncan Laurieeb316852015-12-01 18:51:18 -08002401
2402 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002403 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002404 int16_t temp;
2405 int16_t offset[3];
2406 } sensor_offset, perform_calib;
2407
2408 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2409
2410 struct ec_response_motion_sense_fifo_data fifo_read;
2411
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002412 struct __ec_todo_packed {
Duncan Laurieeb316852015-12-01 18:51:18 -08002413 uint16_t reserved;
2414 uint32_t enabled;
2415 uint32_t disabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002416 } list_activities;
Duncan Laurieeb316852015-12-01 18:51:18 -08002417
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002418 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002419 } set_activity;
2420
Duncan Laurieeb316852015-12-01 18:51:18 -08002421 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002422 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002423 /*
2424 * Angle between 0 and 360 degree if available,
2425 * LID_ANGLE_UNRELIABLE otherwise.
2426 */
2427 uint16_t value;
2428 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002429 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002430};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002431
2432/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002433/* Force lid open command */
2434
2435/* Make lid event always open */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002436#define EC_CMD_FORCE_LID_OPEN 0x002C
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002437
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002438struct __ec_align1 ec_params_force_lid_open {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002439 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002440};
2441
2442/*****************************************************************************/
2443/* Configure the behavior of the power button */
2444#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2445
2446enum ec_config_power_button_flags {
2447 /* Enable/Disable power button pulses for x86 devices */
2448 EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2449};
2450
2451struct __ec_align1 ec_params_config_power_button {
2452 /* See enum ec_config_power_button_flags */
2453 uint8_t flags;
2454};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002455
2456/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002457/* USB charging control commands */
2458
2459/* Set USB port charging mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002460#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002461
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002462struct __ec_align1 ec_params_usb_charge_set_mode {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002463 uint8_t usb_port_id;
2464 uint8_t mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002465};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002466
2467/*****************************************************************************/
2468/* Persistent storage for host */
2469
2470/* Maximum bytes that can be read/written in a single command */
2471#define EC_PSTORE_SIZE_MAX 64
2472
2473/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002474#define EC_CMD_PSTORE_INFO 0x0040
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002475
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002476struct __ec_align4 ec_response_pstore_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002477 /* Persistent storage size, in bytes */
2478 uint32_t pstore_size;
2479 /* Access size; read/write offset and size must be a multiple of this */
2480 uint32_t access_size;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002481};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002482
2483/*
2484 * Read persistent storage
2485 *
2486 * Response is params.size bytes of data.
2487 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002488#define EC_CMD_PSTORE_READ 0x0041
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002489
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002490struct __ec_align4 ec_params_pstore_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002491 uint32_t offset; /* Byte offset to read */
2492 uint32_t size; /* Size to read in bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002493};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002494
2495/* Write persistent storage */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002496#define EC_CMD_PSTORE_WRITE 0x0042
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002497
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002498struct __ec_align4 ec_params_pstore_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002499 uint32_t offset; /* Byte offset to write */
2500 uint32_t size; /* Size to write in bytes */
2501 uint8_t data[EC_PSTORE_SIZE_MAX];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002502};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002503
2504/*****************************************************************************/
2505/* Real-time clock */
2506
2507/* RTC params and response structures */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002508struct __ec_align4 ec_params_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002509 uint32_t time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002510};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002511
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002512struct __ec_align4 ec_response_rtc {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002513 uint32_t time;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002514};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002515
2516/* These use ec_response_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002517#define EC_CMD_RTC_GET_VALUE 0x0044
2518#define EC_CMD_RTC_GET_ALARM 0x0045
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002519
2520/* These all use ec_params_rtc */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002521#define EC_CMD_RTC_SET_VALUE 0x0046
2522#define EC_CMD_RTC_SET_ALARM 0x0047
2523
2524/* Pass as time param to SET_ALARM to clear the current alarm */
2525#define EC_RTC_ALARM_CLEAR 0
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002526
2527/*****************************************************************************/
2528/* Port80 log access */
2529
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002530/* Maximum entries that can be read/written in a single command */
2531#define EC_PORT80_SIZE_MAX 32
2532
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002533/* Get last port80 code from previous boot */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002534#define EC_CMD_PORT80_LAST_BOOT 0x0048
2535#define EC_CMD_PORT80_READ 0x0048
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002536
2537enum ec_port80_subcmd {
2538 EC_PORT80_GET_INFO = 0,
2539 EC_PORT80_READ_BUFFER,
2540};
2541
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002542struct __ec_todo_packed ec_params_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002543 uint16_t subcmd;
2544 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002545 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002546 uint32_t offset;
2547 uint32_t num_entries;
2548 } read_buffer;
2549 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002550};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002551
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002552struct __ec_todo_packed ec_response_port80_read {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002553 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002554 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002555 uint32_t writes;
2556 uint32_t history_size;
2557 uint32_t last_boot;
2558 } get_info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002559 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002560 uint16_t codes[EC_PORT80_SIZE_MAX];
2561 } data;
2562 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002563};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002564
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002565struct __ec_align2 ec_response_port80_last_boot {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002566 uint16_t code;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002567};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002568
2569/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08002570/* Temporary secure storage for host verified boot use */
2571
2572/* Number of bytes in a vstore slot */
2573#define EC_VSTORE_SLOT_SIZE 64
2574
2575/* Maximum number of vstore slots */
2576#define EC_VSTORE_SLOT_MAX 32
2577
2578/* Get persistent storage info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002579#define EC_CMD_VSTORE_INFO 0x0049
2580struct __ec_align_size1 ec_response_vstore_info {
Duncan Laurieeb316852015-12-01 18:51:18 -08002581 /* Indicates which slots are locked */
2582 uint32_t slot_locked;
2583 /* Total number of slots available */
2584 uint8_t slot_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002585};
Duncan Laurieeb316852015-12-01 18:51:18 -08002586
2587/*
2588 * Read temporary secure storage
2589 *
2590 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2591 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002592#define EC_CMD_VSTORE_READ 0x004A
Duncan Laurieeb316852015-12-01 18:51:18 -08002593
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002594struct __ec_align1 ec_params_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08002595 uint8_t slot; /* Slot to read from */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002596};
Duncan Laurieeb316852015-12-01 18:51:18 -08002597
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002598struct __ec_align1 ec_response_vstore_read {
Duncan Laurieeb316852015-12-01 18:51:18 -08002599 uint8_t data[EC_VSTORE_SLOT_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002600};
Duncan Laurieeb316852015-12-01 18:51:18 -08002601
2602/*
2603 * Write temporary secure storage and lock it.
2604 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002605#define EC_CMD_VSTORE_WRITE 0x004B
Duncan Laurieeb316852015-12-01 18:51:18 -08002606
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002607struct __ec_align1 ec_params_vstore_write {
Duncan Laurieeb316852015-12-01 18:51:18 -08002608 uint8_t slot; /* Slot to write to */
2609 uint8_t data[EC_VSTORE_SLOT_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002610};
Duncan Laurieeb316852015-12-01 18:51:18 -08002611
2612/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08002613/* Thermal engine commands. Note that there are two implementations. We'll
2614 * reuse the command number, but the data and behavior is incompatible.
2615 * Version 0 is what originally shipped on Link.
2616 * Version 1 separates the CPU thermal limits from the fan control.
2617 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002618
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002619#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2620#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002621
Duncan Laurie93e24442014-01-06 12:30:52 -08002622/* The version 0 structs are opaque. You have to know what they are for
2623 * the get/set commands to make any sense.
2624 */
2625
2626/* Version 0 - set */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002627struct __ec_align2 ec_params_thermal_set_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002628 uint8_t sensor_type;
2629 uint8_t threshold_id;
2630 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002631};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002632
Duncan Laurie93e24442014-01-06 12:30:52 -08002633/* Version 0 - get */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002634struct __ec_align1 ec_params_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002635 uint8_t sensor_type;
2636 uint8_t threshold_id;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002637};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002638
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002639struct __ec_align2 ec_response_thermal_get_threshold {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002640 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002641};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002642
Duncan Laurie93e24442014-01-06 12:30:52 -08002643
2644/* The version 1 structs are visible. */
2645enum ec_temp_thresholds {
2646 EC_TEMP_THRESH_WARN = 0,
2647 EC_TEMP_THRESH_HIGH,
2648 EC_TEMP_THRESH_HALT,
2649
2650 EC_TEMP_THRESH_COUNT
2651};
2652
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002653/*
2654 * Thermal configuration for one temperature sensor. Temps are in degrees K.
Duncan Laurie93e24442014-01-06 12:30:52 -08002655 * Zero values will be silently ignored by the thermal task.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002656 *
2657 * Note that this structure is a sub-structure of
2658 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
Duncan Laurie93e24442014-01-06 12:30:52 -08002659 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002660struct __ec_align4 ec_thermal_config {
Duncan Laurie93e24442014-01-06 12:30:52 -08002661 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2662 uint32_t temp_fan_off; /* no active cooling needed */
2663 uint32_t temp_fan_max; /* max active cooling needed */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002664};
Duncan Laurie93e24442014-01-06 12:30:52 -08002665
2666/* Version 1 - get config for one sensor. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002667struct __ec_align4 ec_params_thermal_get_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08002668 uint32_t sensor_num;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002669};
Duncan Laurie93e24442014-01-06 12:30:52 -08002670/* This returns a struct ec_thermal_config */
2671
2672/* Version 1 - set config for one sensor.
2673 * Use read-modify-write for best results! */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002674struct __ec_align4 ec_params_thermal_set_threshold_v1 {
Duncan Laurie93e24442014-01-06 12:30:52 -08002675 uint32_t sensor_num;
2676 struct ec_thermal_config cfg;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002677};
Duncan Laurie93e24442014-01-06 12:30:52 -08002678/* This returns no data */
2679
2680/****************************************************************************/
2681
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002682/* Toggle automatic fan control */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002683#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002684
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002685/* Version 1 of input params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002686struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002687 uint8_t fan_idx;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002688};
Duncan Laurie433432b2013-06-03 10:38:22 -07002689
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002690/* Get/Set TMP006 calibration data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002691#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2692#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002693
2694/*
2695 * The original TMP006 calibration only needed four params, but now we need
2696 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2697 * the params opaque. The v1 "get" response will include the algorithm number
2698 * and how many params it requires. That way we can change the EC code without
2699 * needing to update this file. We can also use a different algorithm on each
2700 * sensor.
2701 */
2702
2703/* This is the same struct for both v0 and v1. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002704struct __ec_align1 ec_params_tmp006_get_calibration {
Duncan Laurie433432b2013-06-03 10:38:22 -07002705 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002706};
Duncan Laurie433432b2013-06-03 10:38:22 -07002707
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002708/* Version 0 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002709struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002710 float s0;
2711 float b0;
2712 float b1;
2713 float b2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002714};
Duncan Laurie433432b2013-06-03 10:38:22 -07002715
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002716struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002717 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002718 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07002719 float s0;
2720 float b0;
2721 float b1;
2722 float b2;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002723};
Duncan Laurie433432b2013-06-03 10:38:22 -07002724
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002725/* Version 1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002726struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002727 uint8_t algorithm;
2728 uint8_t num_params;
2729 uint8_t reserved[2];
2730 float val[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002731};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002732
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002733struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002734 uint8_t index;
2735 uint8_t algorithm;
2736 uint8_t num_params;
2737 uint8_t reserved;
2738 float val[0];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002739};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002740
2741
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002742/* Read raw TMP006 data */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002743#define EC_CMD_TMP006_GET_RAW 0x0055
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002744
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002745struct __ec_align1 ec_params_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002746 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002747};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002748
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002749struct __ec_align4 ec_response_tmp006_get_raw {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002750 int32_t t; /* In 1/100 K */
2751 int32_t v; /* In nV */
2752};
2753
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002754/*****************************************************************************/
2755/* MKBP - Matrix KeyBoard Protocol */
2756
2757/*
2758 * Read key state
2759 *
2760 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2761 * expected response size.
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002762 *
2763 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2764 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2765 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002766 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002767#define EC_CMD_MKBP_STATE 0x0060
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002768
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002769/*
2770 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2771 */
2772#define EC_CMD_MKBP_INFO 0x0061
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002773
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002774struct __ec_align_size1 ec_response_mkbp_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002775 uint32_t rows;
2776 uint32_t cols;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002777 /* Formerly "switches", which was 0. */
2778 uint8_t reserved;
2779};
2780
2781struct __ec_align1 ec_params_mkbp_info {
2782 uint8_t info_type;
2783 uint8_t event_type;
2784};
2785
2786enum ec_mkbp_info_type {
2787 /*
2788 * Info about the keyboard matrix: number of rows and columns.
2789 *
2790 * Returns struct ec_response_mkbp_info.
2791 */
2792 EC_MKBP_INFO_KBD = 0,
2793
2794 /*
2795 * For buttons and switches, info about which specifically are
2796 * supported. event_type must be set to one of the values in enum
2797 * ec_mkbp_event.
2798 *
2799 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2800 * bitmask indicating which buttons or switches are present. See the
2801 * bit inidices below.
2802 */
2803 EC_MKBP_INFO_SUPPORTED = 1,
2804
2805 /*
2806 * Instantaneous state of buttons and switches.
2807 *
2808 * event_type must be set to one of the values in enum ec_mkbp_event.
2809 *
2810 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2811 * indicating the current state of the keyboard matrix.
2812 *
2813 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2814 * event state.
2815 *
2816 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2817 * state of supported buttons.
2818 *
2819 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2820 * state of supported switches.
2821 */
2822 EC_MKBP_INFO_CURRENT = 2,
2823};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002824
2825/* Simulate key press */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002826#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002827
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002828struct __ec_align1 ec_params_mkbp_simulate_key {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002829 uint8_t col;
2830 uint8_t row;
2831 uint8_t pressed;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002832};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002833
Duncan Laurie433432b2013-06-03 10:38:22 -07002834/* Configure keyboard scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002835#define EC_CMD_MKBP_SET_CONFIG 0x0064
2836#define EC_CMD_MKBP_GET_CONFIG 0x0065
Duncan Laurie433432b2013-06-03 10:38:22 -07002837
2838/* flags */
2839enum mkbp_config_flags {
2840 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2841};
2842
2843enum mkbp_config_valid {
2844 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2845 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2846 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2847 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2848 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2849 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2850 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2851};
2852
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002853/*
2854 * Configuration for our key scanning algorithm.
2855 *
2856 * Note that this is used as a sub-structure of
2857 * ec_{params/response}_mkbp_get_config.
2858 */
2859struct __ec_align_size1 ec_mkbp_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07002860 uint32_t valid_mask; /* valid fields */
2861 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2862 uint8_t valid_flags; /* which flags are valid */
2863 uint16_t scan_period_us; /* period between start of scans */
2864 /* revert to interrupt mode after no activity for this long */
2865 uint32_t poll_timeout_us;
2866 /*
2867 * minimum post-scan relax time. Once we finish a scan we check
2868 * the time until we are due to start the next one. If this time is
2869 * shorter this field, we use this instead.
2870 */
2871 uint16_t min_post_scan_delay_us;
2872 /* delay between setting up output and waiting for it to settle */
2873 uint16_t output_settle_us;
2874 uint16_t debounce_down_us; /* time for debounce on key down */
2875 uint16_t debounce_up_us; /* time for debounce on key up */
2876 /* maximum depth to allow for fifo (0 = no keyscan output) */
2877 uint8_t fifo_max_depth;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002878};
Duncan Laurie433432b2013-06-03 10:38:22 -07002879
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002880struct __ec_align_size1 ec_params_mkbp_set_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07002881 struct ec_mkbp_config config;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002882};
Duncan Laurie433432b2013-06-03 10:38:22 -07002883
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002884struct __ec_align_size1 ec_response_mkbp_get_config {
Duncan Laurie433432b2013-06-03 10:38:22 -07002885 struct ec_mkbp_config config;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002886};
Duncan Laurie433432b2013-06-03 10:38:22 -07002887
2888/* Run the key scan emulation */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002889#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
Duncan Laurie433432b2013-06-03 10:38:22 -07002890
2891enum ec_keyscan_seq_cmd {
2892 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2893 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2894 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2895 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2896 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2897};
2898
2899enum ec_collect_flags {
2900 /*
2901 * Indicates this scan was processed by the EC. Due to timing, some
2902 * scans may be skipped.
2903 */
2904 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2905};
2906
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002907struct __ec_align1 ec_collect_item {
Duncan Laurie433432b2013-06-03 10:38:22 -07002908 uint8_t flags; /* some flags (enum ec_collect_flags) */
2909};
2910
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002911struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07002912 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2913 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002914 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002915 uint8_t active; /* still active */
2916 uint8_t num_items; /* number of items */
2917 /* Current item being presented */
2918 uint8_t cur_item;
2919 } status;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002920 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002921 /*
2922 * Absolute time for this scan, measured from the
2923 * start of the sequence.
2924 */
2925 uint32_t time_us;
2926 uint8_t scan[0]; /* keyscan data */
2927 } add;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002928 struct __ec_align1 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002929 uint8_t start_item; /* First item to return */
2930 uint8_t num_items; /* Number of items to return */
2931 } collect;
2932 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002933};
Duncan Laurie433432b2013-06-03 10:38:22 -07002934
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002935struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
Duncan Laurie433432b2013-06-03 10:38:22 -07002936 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002937 struct __ec_todo_unpacked {
Duncan Laurie433432b2013-06-03 10:38:22 -07002938 uint8_t num_items; /* Number of items */
2939 /* Data for each item */
2940 struct ec_collect_item item[0];
2941 } collect;
2942 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002943};
Duncan Laurie433432b2013-06-03 10:38:22 -07002944
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002945/*
2946 * Get the next pending MKBP event.
2947 *
2948 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2949 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002950#define EC_CMD_GET_NEXT_EVENT 0x0067
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002951
2952enum ec_mkbp_event {
2953 /* Keyboard matrix changed. The event data is the new matrix state. */
2954 EC_MKBP_EVENT_KEY_MATRIX = 0,
2955
2956 /* New host event. The event data is 4 bytes of host event flags. */
2957 EC_MKBP_EVENT_HOST_EVENT = 1,
2958
Duncan Laurieeb316852015-12-01 18:51:18 -08002959 /* New Sensor FIFO data. The event data is fifo_info structure. */
2960 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2961
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002962 /* The state of the non-matrixed buttons have changed. */
2963 EC_MKBP_EVENT_BUTTON = 3,
2964
2965 /* The state of the switches have changed. */
2966 EC_MKBP_EVENT_SWITCH = 4,
2967
2968 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
2969 EC_MKBP_EVENT_FINGERPRINT = 5,
2970
2971 /*
2972 * Sysrq event: send emulated sysrq. The event data is sysrq,
2973 * corresponding to the key to be pressed.
2974 */
2975 EC_MKBP_EVENT_SYSRQ = 6,
2976
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002977 /* Number of MKBP events */
2978 EC_MKBP_EVENT_COUNT,
2979};
2980
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002981union __ec_align_offset1 ec_response_get_next_data {
2982 uint8_t key_matrix[13];
Duncan Laurieeb316852015-12-01 18:51:18 -08002983
2984 /* Unaligned */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002985 uint32_t host_event;
Duncan Laurieeb316852015-12-01 18:51:18 -08002986
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002987 struct __ec_todo_unpacked {
Duncan Laurieeb316852015-12-01 18:51:18 -08002988 /* For aligning the fifo_info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002989 uint8_t reserved[3];
Duncan Laurieeb316852015-12-01 18:51:18 -08002990 struct ec_response_motion_sense_fifo_info info;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002991 } sensor_fifo;
Duncan Laurieeb316852015-12-01 18:51:18 -08002992
Duncan Laurie67f26cc2017-06-29 23:17:22 -07002993 uint32_t buttons;
2994
2995 uint32_t switches;
2996
2997 uint32_t fp_events;
2998
2999 uint32_t sysrq;
3000};
3001
3002struct __ec_align1 ec_response_get_next_event {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003003 uint8_t event_type;
3004 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08003005 union ec_response_get_next_data data;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003006};
3007
3008/* Bit indices for buttons and switches.*/
3009/* Buttons */
3010#define EC_MKBP_POWER_BUTTON 0
3011#define EC_MKBP_VOL_UP 1
3012#define EC_MKBP_VOL_DOWN 2
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003013#define EC_MKBP_RECOVERY 3
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003014
3015/* Switches */
3016#define EC_MKBP_LID_OPEN 0
3017#define EC_MKBP_TABLET_MODE 1
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003018
Gwendal Grignou880b4582016-06-20 08:49:25 -07003019/* Run keyboard factory test scanning */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003020#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
Gwendal Grignou880b4582016-06-20 08:49:25 -07003021
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003022struct __ec_align2 ec_response_keyboard_factory_test {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003023 uint16_t shorted; /* Keyboard pins are shorted */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003024};
3025
3026/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
3027#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
3028#define EC_MKBP_FP_FINGER_DOWN (1 << 29)
3029#define EC_MKBP_FP_FINGER_UP (1 << 30)
3030#define EC_MKBP_FP_IMAGE_READY (1 << 31)
Gwendal Grignou880b4582016-06-20 08:49:25 -07003031
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003032/*****************************************************************************/
3033/* Temperature sensor commands */
3034
3035/* Read temperature sensor info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003036#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003037
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003038struct __ec_align1 ec_params_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003039 uint8_t id;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003040};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003041
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003042struct __ec_align1 ec_response_temp_sensor_get_info {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003043 char sensor_name[32];
3044 uint8_t sensor_type;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003045};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003046
3047/*****************************************************************************/
3048
3049/*
3050 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3051 * commands accidentally sent to the wrong interface. See the ACPI section
3052 * below.
3053 */
3054
3055/*****************************************************************************/
3056/* Host event commands */
3057
3058/*
3059 * Host event mask params and response structures, shared by all of the host
3060 * event commands below.
3061 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003062struct __ec_align4 ec_params_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003063 uint32_t mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003064};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003065
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003066struct __ec_align4 ec_response_host_event_mask {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003067 uint32_t mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003068};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003069
3070/* These all use ec_response_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003071#define EC_CMD_HOST_EVENT_GET_B 0x0087
3072#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3073#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3074#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003075
3076/* These all use ec_params_host_event_mask */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003077#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3078#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3079#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3080#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3081#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003082
3083/*****************************************************************************/
3084/* Switch commands */
3085
3086/* Enable/disable LCD backlight */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003087#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003088
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003089struct __ec_align1 ec_params_switch_enable_backlight {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003090 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003091};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003092
3093/* Enable/disable WLAN/Bluetooth */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003094#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003095#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003096
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003097/* Version 0 params; no response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003098struct __ec_align1 ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003099 uint8_t enabled;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003100};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003102/* Version 1 params */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003103struct __ec_align1 ec_params_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003104 /* Flags to enable now */
3105 uint8_t now_flags;
3106
3107 /* Which flags to copy from now_flags */
3108 uint8_t now_mask;
3109
3110 /*
3111 * Flags to leave enabled in S3, if they're on at the S0->S3
3112 * transition. (Other flags will be disabled by the S0->S3
3113 * transition.)
3114 */
3115 uint8_t suspend_flags;
3116
3117 /* Which flags to copy from suspend_flags */
3118 uint8_t suspend_mask;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003119};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003120
3121/* Version 1 response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003122struct __ec_align1 ec_response_switch_enable_wireless_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003123 /* Flags to enable now */
3124 uint8_t now_flags;
3125
3126 /* Flags to leave enabled in S3 */
3127 uint8_t suspend_flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003128};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003129
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003130/*****************************************************************************/
3131/* GPIO commands. Only available on EC if write protect has been disabled. */
3132
3133/* Set GPIO output value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003134#define EC_CMD_GPIO_SET 0x0092
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003135
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003136struct __ec_align1 ec_params_gpio_set {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003137 char name[32];
3138 uint8_t val;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003139};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003140
3141/* Get GPIO value */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003142#define EC_CMD_GPIO_GET 0x0093
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003143
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003144/* Version 0 of input params and response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003145struct __ec_align1 ec_params_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003146 char name[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003147};
3148
3149struct __ec_align1 ec_response_gpio_get {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003150 uint8_t val;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003151};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003152
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003153/* Version 1 of input params and response */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003154struct __ec_align1 ec_params_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003155 uint8_t subcmd;
3156 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003157 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003158 char name[32];
3159 } get_value_by_name;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003160 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003161 uint8_t index;
3162 } get_info;
3163 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003164};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003165
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003166struct __ec_todo_packed ec_response_gpio_get_v1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003167 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003168 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003169 uint8_t val;
3170 } get_value_by_name, get_count;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003171 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003172 uint8_t val;
3173 char name[32];
3174 uint32_t flags;
3175 } get_info;
3176 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003177};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003178
3179enum gpio_get_subcmd {
3180 EC_GPIO_GET_BY_NAME = 0,
3181 EC_GPIO_GET_COUNT = 1,
3182 EC_GPIO_GET_INFO = 2,
3183};
3184
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003185/*****************************************************************************/
3186/* I2C commands. Only available when flash write protect is unlocked. */
3187
Duncan Laurie93e24442014-01-06 12:30:52 -08003188/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003189 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3190 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3191 *
3192 * Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08003193 */
3194
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003195/* Read I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003196#define EC_CMD_I2C_READ 0x0094
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003197
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003198struct __ec_align_size1 ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07003199 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003200 uint8_t read_size; /* Either 8 or 16. */
3201 uint8_t port;
3202 uint8_t offset;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003203};
3204
3205struct __ec_align2 ec_response_i2c_read {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003206 uint16_t data;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003207};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003208
3209/* Write I2C bus */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003210#define EC_CMD_I2C_WRITE 0x0095
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003211
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003212struct __ec_align_size1 ec_params_i2c_write {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003213 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07003214 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003215 uint8_t write_size; /* Either 8 or 16. */
3216 uint8_t port;
3217 uint8_t offset;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003218};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003219
3220/*****************************************************************************/
3221/* Charge state commands. Only available when flash write protect unlocked. */
3222
Duncan Laurie93e24442014-01-06 12:30:52 -08003223/* Force charge state machine to stop charging the battery or force it to
3224 * discharge the battery.
3225 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003226#define EC_CMD_CHARGE_CONTROL 0x0096
Duncan Laurie93e24442014-01-06 12:30:52 -08003227#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003228
Duncan Laurie93e24442014-01-06 12:30:52 -08003229enum ec_charge_control_mode {
3230 CHARGE_CONTROL_NORMAL = 0,
3231 CHARGE_CONTROL_IDLE,
3232 CHARGE_CONTROL_DISCHARGE,
3233};
3234
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003235struct __ec_align4 ec_params_charge_control {
Duncan Laurie93e24442014-01-06 12:30:52 -08003236 uint32_t mode; /* enum charge_control_mode */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003237};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003238
3239/*****************************************************************************/
3240/* Console commands. Only available when flash write protect is unlocked. */
3241
3242/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003243#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003244
3245/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003246 * Read data from the saved snapshot. If the subcmd parameter is
3247 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3248 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3249 * end of the previous snapshot.
3250 *
3251 * The params are only looked at in version >= 1 of this command. Prior
3252 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003253 *
3254 * Response is null-terminated string. Empty string, if there is no more
3255 * remaining output.
3256 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003257#define EC_CMD_CONSOLE_READ 0x0098
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003258
Duncan Laurieeb316852015-12-01 18:51:18 -08003259enum ec_console_read_subcmd {
3260 CONSOLE_READ_NEXT = 0,
3261 CONSOLE_READ_RECENT
3262};
3263
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003264struct __ec_align1 ec_params_console_read_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08003265 uint8_t subcmd; /* enum ec_console_read_subcmd */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003266};
Duncan Laurieeb316852015-12-01 18:51:18 -08003267
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003268/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07003269
3270/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003271 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07003272 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003273 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3274 * EC_RES_SUCCESS if the command was successful.
3275 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07003276 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003277#define EC_CMD_BATTERY_CUT_OFF 0x0099
Duncan Laurie433432b2013-06-03 10:38:22 -07003278
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003279#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3280
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003281struct __ec_align1 ec_params_battery_cutoff {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003282 uint8_t flags;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003283};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003284
Duncan Laurie433432b2013-06-03 10:38:22 -07003285/*****************************************************************************/
3286/* USB port mux control. */
3287
3288/*
3289 * Switch USB mux or return to automatic switching.
3290 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003291#define EC_CMD_USB_MUX 0x009A
Duncan Laurie433432b2013-06-03 10:38:22 -07003292
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003293struct __ec_align1 ec_params_usb_mux {
Duncan Laurie433432b2013-06-03 10:38:22 -07003294 uint8_t mux;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003295};
Duncan Laurie433432b2013-06-03 10:38:22 -07003296
3297/*****************************************************************************/
3298/* LDOs / FETs control. */
3299
3300enum ec_ldo_state {
3301 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3302 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3303};
3304
3305/*
3306 * Switch on/off a LDO.
3307 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003308#define EC_CMD_LDO_SET 0x009B
Duncan Laurie433432b2013-06-03 10:38:22 -07003309
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003310struct __ec_align1 ec_params_ldo_set {
Duncan Laurie433432b2013-06-03 10:38:22 -07003311 uint8_t index;
3312 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003313};
Duncan Laurie433432b2013-06-03 10:38:22 -07003314
3315/*
3316 * Get LDO state.
3317 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003318#define EC_CMD_LDO_GET 0x009C
Duncan Laurie433432b2013-06-03 10:38:22 -07003319
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003320struct __ec_align1 ec_params_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07003321 uint8_t index;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003322};
Duncan Laurie433432b2013-06-03 10:38:22 -07003323
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003324struct __ec_align1 ec_response_ldo_get {
Duncan Laurie433432b2013-06-03 10:38:22 -07003325 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003326};
Duncan Laurie433432b2013-06-03 10:38:22 -07003327
3328/*****************************************************************************/
3329/* Power info. */
3330
3331/*
3332 * Get power info.
3333 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003334#define EC_CMD_POWER_INFO 0x009D
Duncan Laurie433432b2013-06-03 10:38:22 -07003335
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003336struct __ec_align4 ec_response_power_info {
Duncan Laurie433432b2013-06-03 10:38:22 -07003337 uint32_t usb_dev_type;
3338 uint16_t voltage_ac;
3339 uint16_t voltage_system;
3340 uint16_t current_system;
3341 uint16_t usb_current_limit;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003342};
Duncan Laurie433432b2013-06-03 10:38:22 -07003343
3344/*****************************************************************************/
3345/* I2C passthru command */
3346
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003347#define EC_CMD_I2C_PASSTHRU 0x009E
Duncan Laurie433432b2013-06-03 10:38:22 -07003348
Duncan Laurie433432b2013-06-03 10:38:22 -07003349/* Read data; if not present, message is a write */
3350#define EC_I2C_FLAG_READ (1 << 15)
3351
3352/* Mask for address */
3353#define EC_I2C_ADDR_MASK 0x3ff
3354
3355#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
3356#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3357
3358/* Any error */
3359#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3360
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003361struct __ec_align2 ec_params_i2c_passthru_msg {
Duncan Laurie433432b2013-06-03 10:38:22 -07003362 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3363 uint16_t len; /* Number of bytes to read or write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003364};
Duncan Laurie433432b2013-06-03 10:38:22 -07003365
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003366struct __ec_align2 ec_params_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07003367 uint8_t port; /* I2C port number */
3368 uint8_t num_msgs; /* Number of messages */
3369 struct ec_params_i2c_passthru_msg msg[];
3370 /* Data to write for all messages is concatenated here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003371};
Duncan Laurie433432b2013-06-03 10:38:22 -07003372
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003373struct __ec_align1 ec_response_i2c_passthru {
Duncan Laurie433432b2013-06-03 10:38:22 -07003374 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3375 uint8_t num_msgs; /* Number of messages processed */
3376 uint8_t data[]; /* Data read by messages concatenated here */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003377};
Duncan Laurie433432b2013-06-03 10:38:22 -07003378
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003379/*****************************************************************************/
3380/* Power button hang detect */
3381
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003382#define EC_CMD_HANG_DETECT 0x009F
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003383
3384/* Reasons to start hang detection timer */
3385/* Power button pressed */
3386#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3387
3388/* Lid closed */
3389#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3390
3391 /* Lid opened */
3392#define EC_HANG_START_ON_LID_OPEN (1 << 2)
3393
3394/* Start of AP S3->S0 transition (booting or resuming from suspend) */
3395#define EC_HANG_START_ON_RESUME (1 << 3)
3396
3397/* Reasons to cancel hang detection */
3398
3399/* Power button released */
3400#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3401
3402/* Any host command from AP received */
3403#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3404
3405/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3406#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
3407
3408/*
3409 * If this flag is set, all the other fields are ignored, and the hang detect
3410 * timer is started. This provides the AP a way to start the hang timer
3411 * without reconfiguring any of the other hang detect settings. Note that
3412 * you must previously have configured the timeouts.
3413 */
3414#define EC_HANG_START_NOW (1 << 30)
3415
3416/*
3417 * If this flag is set, all the other fields are ignored (including
3418 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3419 * without reconfiguring any of the other hang detect settings.
3420 */
3421#define EC_HANG_STOP_NOW (1 << 31)
3422
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003423struct __ec_align4 ec_params_hang_detect {
Duncan Lauriee6b280e2014-02-10 16:21:05 -08003424 /* Flags; see EC_HANG_* */
3425 uint32_t flags;
3426
3427 /* Timeout in msec before generating host event, if enabled */
3428 uint16_t host_event_timeout_msec;
3429
3430 /* Timeout in msec before generating warm reboot, if enabled */
3431 uint16_t warm_reboot_timeout_msec;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003432};
Duncan Laurie433432b2013-06-03 10:38:22 -07003433
3434/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003435/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07003436
3437/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003438 * This is the single catch-all host command to exchange data regarding the
3439 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07003440 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003441#define EC_CMD_CHARGE_STATE 0x00A0
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003442
3443/* Subcommands for this host command */
3444enum charge_state_command {
3445 CHARGE_STATE_CMD_GET_STATE,
3446 CHARGE_STATE_CMD_GET_PARAM,
3447 CHARGE_STATE_CMD_SET_PARAM,
3448 CHARGE_STATE_NUM_CMDS
3449};
3450
3451/*
3452 * Known param numbers are defined here. Ranges are reserved for board-specific
3453 * params, which are handled by the particular implementations.
3454 */
3455enum charge_state_params {
3456 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
3457 CS_PARAM_CHG_CURRENT, /* charger current limit */
3458 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3459 CS_PARAM_CHG_STATUS, /* charger-specific status */
3460 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08003461 CS_PARAM_LIMIT_POWER, /*
3462 * Check if power is limited due to
3463 * low battery and / or a weak external
3464 * charger. READ ONLY.
3465 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003466 /* How many so far? */
3467 CS_NUM_BASE_PARAMS,
3468
3469 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3470 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3471 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3472
3473 /* Other custom param ranges go here... */
3474};
3475
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003476struct __ec_todo_packed ec_params_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003477 uint8_t cmd; /* enum charge_state_command */
3478 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003479 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003480 /* no args */
3481 } get_state;
3482
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003483 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003484 uint32_t param; /* enum charge_state_param */
3485 } get_param;
3486
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003487 struct __ec_todo_unpacked {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003488 uint32_t param; /* param to set */
3489 uint32_t value; /* value to set */
3490 } set_param;
3491 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003492};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003493
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003494struct __ec_align4 ec_response_charge_state {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003495 union {
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003496 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003497 int ac;
3498 int chg_voltage;
3499 int chg_current;
3500 int chg_input_current;
3501 int batt_state_of_charge;
3502 } get_state;
3503
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003504 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003505 uint32_t value;
3506 } get_param;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003507 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003508 /* no return values */
3509 } set_param;
3510 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003511};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003512
Duncan Laurie433432b2013-06-03 10:38:22 -07003513
3514/*
3515 * Set maximum battery charging current.
3516 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003517#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
Duncan Laurie433432b2013-06-03 10:38:22 -07003518
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003519struct __ec_align4 ec_params_current_limit {
Duncan Laurie433432b2013-06-03 10:38:22 -07003520 uint32_t limit; /* in mA */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003521};
Duncan Laurie433432b2013-06-03 10:38:22 -07003522
3523/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003524 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07003525 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003526#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Duncan Laurie433432b2013-06-03 10:38:22 -07003527
Duncan Laurieeb316852015-12-01 18:51:18 -08003528/* Command v0 is used only on Spring and is obsolete + unsupported */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003529struct __ec_align2 ec_params_external_power_limit_v1 {
Duncan Laurieeb316852015-12-01 18:51:18 -08003530 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3531 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003532};
Duncan Laurie433432b2013-06-03 10:38:22 -07003533
Duncan Laurieeb316852015-12-01 18:51:18 -08003534#define EC_POWER_LIMIT_NONE 0xffff
3535
Daisuke Nojiri93fd8fa2017-11-28 14:11:30 -08003536/*
3537 * Set maximum voltage & current of a dedicated charge port
3538 */
3539#define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
3540
3541struct __ec_align2 ec_params_dedicated_charger_limit {
3542 uint16_t current_lim; /* in mA */
3543 uint16_t voltage_lim; /* in mV */
3544};
3545
Duncan Laurieeb316852015-12-01 18:51:18 -08003546/*****************************************************************************/
3547/* Hibernate/Deep Sleep Commands */
3548
3549/* Set the delay before going into hibernation. */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003550#define EC_CMD_HIBERNATION_DELAY 0x00A8
Duncan Laurieeb316852015-12-01 18:51:18 -08003551
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003552struct __ec_align4 ec_params_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08003553 /*
3554 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3555 * current settings without changing them.
3556 */
3557 uint32_t seconds;
3558};
3559
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003560struct __ec_align4 ec_response_hibernation_delay {
Duncan Laurieeb316852015-12-01 18:51:18 -08003561 /*
3562 * The current time in seconds in which the system has been in the G3
3563 * state. This value is reset if the EC transitions out of G3.
3564 */
3565 uint32_t time_g3;
3566
3567 /*
3568 * The current time remaining in seconds until the EC should hibernate.
3569 * This value is also reset if the EC transitions out of G3.
3570 */
3571 uint32_t time_remaining;
3572
3573 /*
3574 * The current time in seconds that the EC should wait in G3 before
3575 * hibernating.
3576 */
3577 uint32_t hibernate_delay;
3578};
3579
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003580/* Inform the EC when entering a sleep state */
3581#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
3582
3583enum host_sleep_event {
3584 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
3585 HOST_SLEEP_EVENT_S3_RESUME = 2,
3586 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
3587 HOST_SLEEP_EVENT_S0IX_RESUME = 4
3588};
3589
3590struct __ec_align1 ec_params_host_sleep_event {
3591 uint8_t sleep_event;
3592};
3593
3594/*****************************************************************************/
3595/* Device events */
3596#define EC_CMD_DEVICE_EVENT 0x00AA
3597
3598enum ec_device_event {
3599 EC_DEVICE_EVENT_TRACKPAD,
3600 EC_DEVICE_EVENT_DSP,
3601 EC_DEVICE_EVENT_WIFI,
3602};
3603
3604enum ec_device_event_param {
3605 /* Get and clear pending device events */
3606 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
3607 /* Get device event mask */
3608 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
3609 /* Set device event mask */
3610 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
3611};
3612
3613#define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
3614
3615struct __ec_align_size1 ec_params_device_event {
3616 uint32_t event_mask;
3617 uint8_t param;
3618};
3619
3620struct __ec_align4 ec_response_device_event {
3621 uint32_t event_mask;
3622};
Duncan Laurieeb316852015-12-01 18:51:18 -08003623
Duncan Laurie433432b2013-06-03 10:38:22 -07003624/*****************************************************************************/
3625/* Smart battery pass-through */
3626
3627/* Get / Set 16-bit smart battery registers */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003628#define EC_CMD_SB_READ_WORD 0x00B0
3629#define EC_CMD_SB_WRITE_WORD 0x00B1
Duncan Laurie433432b2013-06-03 10:38:22 -07003630
3631/* Get / Set string smart battery parameters
3632 * formatted as SMBUS "block".
3633 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003634#define EC_CMD_SB_READ_BLOCK 0x00B2
3635#define EC_CMD_SB_WRITE_BLOCK 0x00B3
Duncan Laurie433432b2013-06-03 10:38:22 -07003636
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003637struct __ec_align1 ec_params_sb_rd {
Duncan Laurie433432b2013-06-03 10:38:22 -07003638 uint8_t reg;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003639};
Duncan Laurie433432b2013-06-03 10:38:22 -07003640
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003641struct __ec_align2 ec_response_sb_rd_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07003642 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003643};
Duncan Laurie433432b2013-06-03 10:38:22 -07003644
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003645struct __ec_align1 ec_params_sb_wr_word {
Duncan Laurie433432b2013-06-03 10:38:22 -07003646 uint8_t reg;
3647 uint16_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003648};
Duncan Laurie433432b2013-06-03 10:38:22 -07003649
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003650struct __ec_align1 ec_response_sb_rd_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07003651 uint8_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003652};
Duncan Laurie433432b2013-06-03 10:38:22 -07003653
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003654struct __ec_align1 ec_params_sb_wr_block {
Duncan Laurie433432b2013-06-03 10:38:22 -07003655 uint8_t reg;
3656 uint16_t data[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003657};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003658
3659/*****************************************************************************/
3660/* Battery vendor parameters
3661 *
3662 * Get or set vendor-specific parameters in the battery. Implementations may
3663 * differ between boards or batteries. On a set operation, the response
3664 * contains the actual value set, which may be rounded or clipped from the
3665 * requested value.
3666 */
3667
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003668#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003669
3670enum ec_battery_vendor_param_mode {
3671 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3672 BATTERY_VENDOR_PARAM_MODE_SET,
3673};
3674
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003675struct __ec_align_size1 ec_params_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003676 uint32_t param;
3677 uint32_t value;
3678 uint8_t mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003679};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003680
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003681struct __ec_align4 ec_response_battery_vendor_param {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003682 uint32_t value;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003683};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003684
3685/*****************************************************************************/
3686/*
3687 * Smart Battery Firmware Update Commands
3688 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003689#define EC_CMD_SB_FW_UPDATE 0x00B5
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003690
3691enum ec_sb_fw_update_subcmd {
3692 EC_SB_FW_UPDATE_PREPARE = 0x0,
3693 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3694 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3695 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3696 EC_SB_FW_UPDATE_END = 0x4,
3697 EC_SB_FW_UPDATE_STATUS = 0x5,
3698 EC_SB_FW_UPDATE_PROTECT = 0x6,
3699 EC_SB_FW_UPDATE_MAX = 0x7,
3700};
3701
3702#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3703#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3704#define SB_FW_UPDATE_CMD_INFO_SIZE 8
3705
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003706struct __ec_align4 ec_sb_fw_update_header {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003707 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3708 uint16_t fw_id; /* firmware id */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003709};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003710
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003711struct __ec_align4 ec_params_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003712 struct ec_sb_fw_update_header hdr;
3713 union {
3714 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3715 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3716 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3717 /* EC_SB_FW_UPDATE_END = 0x4 */
3718 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3719 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003720 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003721 /* no args */
3722 } dummy;
3723
3724 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003725 struct __ec_align4 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003726 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3727 } write;
3728 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003729};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003730
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003731struct __ec_align1 ec_response_sb_fw_update {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003732 union {
3733 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003734 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003735 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3736 } info;
3737
3738 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003739 struct __ec_align1 {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003740 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3741 } status;
3742 };
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003743};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003744
3745/*
3746 * Entering Verified Boot Mode Command
3747 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3748 * Valid Modes are: normal, developer, and recovery.
3749 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003750#define EC_CMD_ENTERING_MODE 0x00B6
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003751
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003752struct __ec_align4 ec_params_entering_mode {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003753 int vboot_mode;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003754};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003755
3756#define VBOOT_MODE_NORMAL 0
3757#define VBOOT_MODE_DEVELOPER 1
3758#define VBOOT_MODE_RECOVERY 2
3759
Duncan Laurie433432b2013-06-03 10:38:22 -07003760/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07003761/*
3762 * I2C passthru protection command: Protects I2C tunnels against access on
3763 * certain addresses (board-specific).
3764 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003765#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
Gwendal Grignou880b4582016-06-20 08:49:25 -07003766
3767enum ec_i2c_passthru_protect_subcmd {
3768 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3769 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3770};
3771
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003772struct __ec_align1 ec_params_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003773 uint8_t subcmd;
3774 uint8_t port; /* I2C port number */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003775};
Gwendal Grignou880b4582016-06-20 08:49:25 -07003776
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003777struct __ec_align1 ec_response_i2c_passthru_protect {
Gwendal Grignou880b4582016-06-20 08:49:25 -07003778 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003779};
Gwendal Grignou880b4582016-06-20 08:49:25 -07003780
3781/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003782/* System commands */
3783
3784/*
Duncan Laurie93e24442014-01-06 12:30:52 -08003785 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3786 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003787 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003788#define EC_CMD_REBOOT_EC 0x00D2
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003789
3790/* Command */
3791enum ec_reboot_cmd {
3792 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003793 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3794 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003795 /* (command 3 was jump to RW-B) */
3796 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003797 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
Daisuke Nojiri40d0bfa2017-11-30 17:41:09 -08003798 EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
3799 EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003800};
3801
3802/* Flags for ec_params_reboot_ec.reboot_flags */
3803#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
Duncan Laurie433432b2013-06-03 10:38:22 -07003804#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003805
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003806struct __ec_align1 ec_params_reboot_ec {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003807 uint8_t cmd; /* enum ec_reboot_cmd */
3808 uint8_t flags; /* See EC_REBOOT_FLAG_* */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003809};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003810
Duncan Laurie433432b2013-06-03 10:38:22 -07003811/*
3812 * Get information on last EC panic.
3813 *
3814 * Returns variable-length platform-dependent panic information. See panic.h
3815 * for details.
3816 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003817#define EC_CMD_GET_PANIC_INFO 0x00D3
Duncan Laurie433432b2013-06-03 10:38:22 -07003818
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003819/*****************************************************************************/
3820/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003821 * Special commands
3822 *
3823 * These do not follow the normal rules for commands. See each command for
3824 * details.
3825 */
3826
3827/*
3828 * Reboot NOW
3829 *
3830 * This command will work even when the EC LPC interface is busy, because the
3831 * reboot command is processed at interrupt level. Note that when the EC
3832 * reboots, the host will reboot too, so there is no response to this command.
3833 *
3834 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3835 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003836#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003837
3838/*
Duncan Laurie433432b2013-06-03 10:38:22 -07003839 * Resend last response (not supported on LPC).
3840 *
3841 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3842 * there was no previous command, or the previous command's response was too
3843 * big to save.
3844 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003845#define EC_CMD_RESEND_RESPONSE 0x00DB
Duncan Laurie433432b2013-06-03 10:38:22 -07003846
3847/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003848 * This header byte on a command indicate version 0. Any header byte less
3849 * than this means that we are talking to an old EC which doesn't support
3850 * versioning. In that case, we assume version 0.
3851 *
3852 * Header bytes greater than this indicate a later version. For example,
3853 * EC_CMD_VERSION0 + 1 means we are using version 1.
3854 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003855 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003856 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003857#define EC_CMD_VERSION0 0x00DC
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003858
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003859/*****************************************************************************/
3860/*
3861 * PD commands
3862 *
3863 * These commands are for PD MCU communication.
3864 */
3865
3866/* EC to PD MCU exchange status command */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003867#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
Duncan Laurieeb316852015-12-01 18:51:18 -08003868#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003869
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003870enum pd_charge_state {
3871 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3872 PD_CHARGE_NONE, /* No charging allowed */
3873 PD_CHARGE_5V, /* 5V charging only */
3874 PD_CHARGE_MAX /* Charge at max voltage */
3875};
3876
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003877/* Status of EC being sent to PD */
Duncan Laurieeb316852015-12-01 18:51:18 -08003878#define EC_STATUS_HIBERNATING (1 << 0)
3879
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003880struct __ec_align1 ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003881 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003882 int8_t batt_soc; /* battery state of charge */
3883 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003884};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003885
3886/* Status of PD being sent back to EC */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003887#define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3888#define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3889#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
Duncan Laurieeb316852015-12-01 18:51:18 -08003890#define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
3891#define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
3892#define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
3893#define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
3894#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
3895 PD_STATUS_TCPC_ALERT_1 | \
3896 PD_STATUS_HOST_EVENT)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003897struct __ec_align_size1 ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003898 uint32_t curr_lim_ma; /* input current limit */
3899 uint16_t status; /* PD MCU status */
3900 int8_t active_charge_port; /* active charging port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003901};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003902
3903/* AP to PD MCU host event status command, cleared on read */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003904#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003905
3906/* PD MCU host event status bits */
3907#define PD_EVENT_UPDATE_DEVICE (1 << 0)
3908#define PD_EVENT_POWER_CHANGE (1 << 1)
3909#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
Duncan Laurieeb316852015-12-01 18:51:18 -08003910#define PD_EVENT_DATA_SWAP (1 << 3)
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003911struct __ec_align4 ec_response_host_event_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003912 uint32_t status; /* PD MCU host event status */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003913};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003914
3915/* Set USB type-C port role and muxes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003916#define EC_CMD_USB_PD_CONTROL 0x0101
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003917
3918enum usb_pd_control_role {
3919 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3920 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3921 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3922 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3923 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3924 USB_PD_CTRL_ROLE_COUNT
3925};
3926
3927enum usb_pd_control_mux {
3928 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3929 USB_PD_CTRL_MUX_NONE = 1,
3930 USB_PD_CTRL_MUX_USB = 2,
3931 USB_PD_CTRL_MUX_DP = 3,
3932 USB_PD_CTRL_MUX_DOCK = 4,
3933 USB_PD_CTRL_MUX_AUTO = 5,
3934 USB_PD_CTRL_MUX_COUNT
3935};
3936
Duncan Laurieeb316852015-12-01 18:51:18 -08003937enum usb_pd_control_swap {
3938 USB_PD_CTRL_SWAP_NONE = 0,
3939 USB_PD_CTRL_SWAP_DATA = 1,
3940 USB_PD_CTRL_SWAP_POWER = 2,
3941 USB_PD_CTRL_SWAP_VCONN = 3,
3942 USB_PD_CTRL_SWAP_COUNT
3943};
3944
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003945struct __ec_align1 ec_params_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003946 uint8_t port;
3947 uint8_t role;
3948 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08003949 uint8_t swap;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003950};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003951
Duncan Laurieeb316852015-12-01 18:51:18 -08003952#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3953#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3954#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3955
3956#define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
3957#define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
3958#define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
3959#define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
3960#define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
3961#define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
3962#define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
3963
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003964struct __ec_align1 ec_response_usb_pd_control {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003965 uint8_t enabled;
3966 uint8_t role;
3967 uint8_t polarity;
3968 uint8_t state;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003969};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003970
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003971struct __ec_align1 ec_response_usb_pd_control_v1 {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003972 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08003973 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003974 uint8_t polarity;
3975 char state[32];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003976};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003977
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003978#define EC_CMD_USB_PD_PORTS 0x0102
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003979
Patrick Georgi0f6187a2017-07-28 15:57:23 +02003980/* Maximum number of PD ports on a device, num_ports will be <= this */
3981#define EC_USB_PD_MAX_PORTS 8
3982
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003983struct __ec_align1 ec_response_usb_pd_ports {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003984 uint8_t num_ports;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003985};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003986
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003987#define EC_CMD_USB_PD_POWER_INFO 0x0103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003988
3989#define PD_POWER_CHARGING_PORT 0xff
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003990struct __ec_align1 ec_params_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003991 uint8_t port;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07003992};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003993
3994enum usb_chg_type {
3995 USB_CHG_TYPE_NONE,
3996 USB_CHG_TYPE_PD,
3997 USB_CHG_TYPE_C,
3998 USB_CHG_TYPE_PROPRIETARY,
3999 USB_CHG_TYPE_BC12_DCP,
4000 USB_CHG_TYPE_BC12_CDP,
4001 USB_CHG_TYPE_BC12_SDP,
4002 USB_CHG_TYPE_OTHER,
4003 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08004004 USB_CHG_TYPE_UNKNOWN,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004005};
4006enum usb_power_roles {
4007 USB_PD_PORT_POWER_DISCONNECTED,
4008 USB_PD_PORT_POWER_SOURCE,
4009 USB_PD_PORT_POWER_SINK,
4010 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
4011};
4012
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004013struct __ec_align2 usb_chg_measures {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004014 uint16_t voltage_max;
4015 uint16_t voltage_now;
4016 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08004017 uint16_t current_lim;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004018};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004019
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004020struct __ec_align4 ec_response_usb_pd_power_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004021 uint8_t role;
4022 uint8_t type;
4023 uint8_t dualrole;
4024 uint8_t reserved1;
4025 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004026 uint32_t max_power;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004027};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004028
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004029/* Write USB-PD device FW */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004030#define EC_CMD_USB_PD_FW_UPDATE 0x0110
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004031
4032enum usb_pd_fw_update_cmds {
4033 USB_PD_FW_REBOOT,
4034 USB_PD_FW_FLASH_ERASE,
4035 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004036 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004037};
4038
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004039struct __ec_align4 ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004040 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004041 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004042 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004043 uint32_t size; /* Size to write in bytes */
4044 /* Followed by data to write */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004045};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004046
4047/* Write USB-PD Accessory RW_HASH table entry */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004048#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004049/* RW hash is first 20 bytes of SHA-256 of RW section */
4050#define PD_RW_HASH_SIZE 20
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004051struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004052 uint16_t dev_id;
4053 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004054 uint8_t reserved; /* For alignment of current_image
4055 * TODO(rspangler) but it's not aligned!
4056 * Should have been reserved[2]. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004057 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004058};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004059
4060/* Read USB-PD Accessory info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004061#define EC_CMD_USB_PD_DEV_INFO 0x0112
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004062
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004063struct __ec_align1 ec_params_usb_pd_info_request {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004064 uint8_t port;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004065};
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004066
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004067/* Read USB-PD Device discovery info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004068#define EC_CMD_USB_PD_DISCOVERY 0x0113
4069struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004070 uint16_t vid; /* USB-IF VID */
4071 uint16_t pid; /* USB-IF PID */
4072 uint8_t ptype; /* product type (hub,periph,cable,ama) */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004073};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004074
4075/* Override default charge behavior */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004076#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004077
4078/* Negative port parameters have special meaning */
4079enum usb_pd_override_ports {
4080 OVERRIDE_DONT_CHARGE = -2,
4081 OVERRIDE_OFF = -1,
Duncan Laurieeb316852015-12-01 18:51:18 -08004082 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004083};
4084
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004085struct __ec_align2 ec_params_charge_port_override {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004086 int16_t override_port; /* Override port# */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004087};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004088
4089/* Read (and delete) one entry of PD event log */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004090#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004091
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004092struct __ec_align4 ec_response_pd_log {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004093 uint32_t timestamp; /* relative timestamp in milliseconds */
4094 uint8_t type; /* event type : see PD_EVENT_xx below */
4095 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4096 uint16_t data; /* type-defined data payload */
4097 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004098};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004099
4100
4101/* The timestamp is the microsecond counter shifted to get about a ms. */
4102#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4103
Duncan Laurieeb316852015-12-01 18:51:18 -08004104#define PD_LOG_SIZE_MASK 0x1f
4105#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004106#define PD_LOG_PORT_SHIFT 5
4107#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4108 ((size) & PD_LOG_SIZE_MASK))
4109#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4110#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4111
4112/* PD event log : entry types */
4113/* PD MCU events */
4114#define PD_EVENT_MCU_BASE 0x00
4115#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4116#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4117/* Reserved for custom board event */
4118#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4119/* PD generic accessory events */
4120#define PD_EVENT_ACC_BASE 0x20
4121#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4122#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4123/* PD power supply events */
4124#define PD_EVENT_PS_BASE 0x40
4125#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4126/* PD video dongles events */
4127#define PD_EVENT_VIDEO_BASE 0x60
4128#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4129#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4130/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08004131#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004132
4133/*
4134 * PD_EVENT_MCU_CHARGE event definition :
4135 * the payload is "struct usb_chg_measures"
4136 * the data field contains the port state flags as defined below :
4137 */
4138/* Port partner is a dual role device */
4139#define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
4140/* Port is the pending override port */
4141#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
4142/* Port is the override port */
4143#define CHARGE_FLAGS_OVERRIDE (1 << 13)
4144/* Charger type */
4145#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08004146#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004147/* Power delivery role */
4148#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4149
4150/*
4151 * PD_EVENT_PS_FAULT data field flags definition :
4152 */
4153#define PS_FAULT_OCP 1
4154#define PS_FAULT_FAST_OCP 2
4155#define PS_FAULT_OVP 3
4156#define PS_FAULT_DISCH 4
4157
4158/*
4159 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4160 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004161struct __ec_align4 mcdp_version {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004162 uint8_t major;
4163 uint8_t minor;
4164 uint16_t build;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004165};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004166
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004167struct __ec_align4 mcdp_info {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004168 uint8_t family[2];
4169 uint8_t chipid[2];
4170 struct mcdp_version irom;
4171 struct mcdp_version fw;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004172};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004173
4174/* struct mcdp_info field decoding */
4175#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4176#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4177
4178/* Get/Set USB-PD Alternate mode info */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004179#define EC_CMD_USB_PD_GET_AMODE 0x0116
4180struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004181 uint16_t svid_idx; /* SVID index to get */
4182 uint8_t port; /* port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004183};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004184
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004185struct __ec_align4 ec_params_usb_pd_get_mode_response {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004186 uint16_t svid; /* SVID */
4187 uint16_t opos; /* Object Position */
4188 uint32_t vdo[6]; /* Mode VDOs */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004189};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004190
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004191#define EC_CMD_USB_PD_SET_AMODE 0x0117
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004192
4193enum pd_mode_cmd {
4194 PD_EXIT_MODE = 0,
4195 PD_ENTER_MODE = 1,
4196 /* Not a command. Do NOT remove. */
4197 PD_MODE_CMD_COUNT,
4198};
4199
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004200struct __ec_align4 ec_params_usb_pd_set_mode_request {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004201 uint32_t cmd; /* enum pd_mode_cmd */
4202 uint16_t svid; /* SVID to set */
4203 uint8_t opos; /* Object Position */
4204 uint8_t port; /* port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004205};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004206
4207/* Ask the PD MCU to record a log of a requested type */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004208#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004209
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004210struct __ec_align1 ec_params_pd_write_log_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004211 uint8_t type; /* event type : see PD_EVENT_xx above */
4212 uint8_t port; /* port#, or 0 for events unrelated to a given port */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004213};
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07004214
Stefan Reinauerd6682e82013-02-21 15:39:35 -08004215
Gwendal Grignou880b4582016-06-20 08:49:25 -07004216/* Control USB-PD chip */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004217#define EC_CMD_PD_CONTROL 0x0119
Gwendal Grignou880b4582016-06-20 08:49:25 -07004218
4219enum ec_pd_control_cmd {
4220 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4221 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4222 PD_RESET, /* Force reset the PD chip */
4223 PD_CONTROL_DISABLE /* Disable further calls to this command */
4224};
4225
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004226struct __ec_align1 ec_params_pd_control {
Gwendal Grignou880b4582016-06-20 08:49:25 -07004227 uint8_t chip; /* chip id (should be 0) */
4228 uint8_t subcmd;
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004229};
Gwendal Grignou880b4582016-06-20 08:49:25 -07004230
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004231/* Get info about USB-C SS muxes */
4232#define EC_CMD_USB_PD_MUX_INFO 0x011A
4233
4234struct __ec_align1 ec_params_usb_pd_mux_info {
4235 uint8_t port; /* USB-C port number */
4236};
4237
4238/* Flags representing mux state */
4239#define USB_PD_MUX_USB_ENABLED (1 << 0)
4240#define USB_PD_MUX_DP_ENABLED (1 << 1)
4241#define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4242#define USB_PD_MUX_HPD_IRQ (1 << 3)
4243
4244struct __ec_align1 ec_response_usb_pd_mux_info {
4245 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
4246};
4247
4248#define EC_CMD_PD_CHIP_INFO 0x011B
4249
4250struct __ec_align1 ec_params_pd_chip_info {
4251 uint8_t port; /* USB-C port number */
4252 uint8_t renew; /* Force renewal */
4253};
4254
4255struct __ec_align2 ec_response_pd_chip_info {
4256 uint16_t vendor_id;
4257 uint16_t product_id;
4258 uint16_t device_id;
4259 union {
4260 uint8_t fw_version_string[8];
4261 uint64_t fw_version_number;
4262 };
4263};
4264
4265/* Run RW signature verification and get status */
4266#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
4267
4268struct __ec_align4 ec_response_rwsig_check_status {
4269 uint32_t status;
4270};
4271
4272/* For controlling RWSIG task */
4273#define EC_CMD_RWSIG_ACTION 0x011D
4274
4275enum rwsig_action {
4276 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
4277 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
4278};
4279
4280struct __ec_align4 ec_params_rwsig_action {
4281 uint32_t action;
4282};
4283
4284/*****************************************************************************/
4285/* The command range 0x200-0x2FF is reserved for Rotor. */
Duncan Laurieeb316852015-12-01 18:51:18 -08004286
4287/*****************************************************************************/
4288/*
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004289 * Reserve a range of host commands for the CR51 firmware.
Duncan Laurieeb316852015-12-01 18:51:18 -08004290 */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004291#define EC_CMD_CR51_BASE 0x0300
4292#define EC_CMD_CR51_LAST 0x03FF
4293
4294/*****************************************************************************/
4295/* Fingerprint MCU commands: range 0x0400-0x040x */
4296
4297/* Fingerprint SPI sensor passthru command: prototyping ONLY */
4298#define EC_CMD_FP_PASSTHRU 0x0400
4299
4300#define EC_FP_FLAG_NOT_COMPLETE 0x1
4301
4302struct __ec_align2 ec_params_fp_passthru {
4303 uint16_t len; /* Number of bytes to write then read */
4304 uint16_t flags; /* EC_FP_FLAG_xxx */
4305 uint8_t data[]; /* Data to send */
4306};
4307
4308/* Fingerprint sensor configuration command: prototyping ONLY */
4309#define EC_CMD_FP_SENSOR_CONFIG 0x0401
4310
4311#define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4312
4313struct __ec_align2 ec_params_fp_sensor_config {
4314 uint8_t count; /* Number of setup registers */
4315 /*
4316 * the value to send to each of the 'count' setup registers
4317 * is stored in the 'data' array for 'len' bytes just after
4318 * the previous one.
4319 */
4320 uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4321 uint8_t data[];
4322};
4323
4324/* Configure the Fingerprint MCU behavior */
4325#define EC_CMD_FP_MODE 0x0402
4326
4327/* Put the sensor in its lowest power mode */
4328#define FP_MODE_DEEPSLEEP (1<<0)
4329/* Wait to see a finger on the sensor */
4330#define FP_MODE_FINGER_DOWN (1<<1)
4331/* Poll until the finger has left the sensor */
4332#define FP_MODE_FINGER_UP (1<<2)
4333/* Capture the current finger image */
4334#define FP_MODE_CAPTURE (1<<3)
4335/* special value: don't change anything just read back current mode */
4336#define FP_MODE_DONT_CHANGE (1<<31)
4337
4338struct __ec_align4 ec_params_fp_mode {
4339 uint32_t mode; /* as defined by FP_MODE_ constants */
4340 /* TBD */
4341};
4342
4343struct __ec_align4 ec_response_fp_mode {
4344 uint32_t mode; /* as defined by FP_MODE_ constants */
4345 /* TBD */
4346};
4347
4348/* Retrieve Fingerprint sensor information */
4349#define EC_CMD_FP_INFO 0x0403
4350
4351struct __ec_align2 ec_response_fp_info {
4352 /* Sensor identification */
4353 uint32_t vendor_id;
4354 uint32_t product_id;
4355 uint32_t model_id;
4356 uint32_t version;
4357 /* Image frame characteristics */
4358 uint32_t frame_size;
4359 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4360 uint16_t width;
4361 uint16_t height;
4362 uint16_t bpp;
4363};
4364
4365/* Get the last captured finger frame: TODO: will be AES-encrypted */
4366#define EC_CMD_FP_FRAME 0x0404
4367
4368struct __ec_align4 ec_params_fp_frame {
4369 uint32_t offset;
4370 uint32_t size;
4371};
4372
4373/*****************************************************************************/
4374/* Touchpad MCU commands: range 0x0500-0x05FF */
4375
4376/* Perform touchpad self test */
4377#define EC_CMD_TP_SELF_TEST 0x0500
4378
4379/* Get number of frame types, and the size of each type */
4380#define EC_CMD_TP_FRAME_INFO 0x0501
4381
4382struct __ec_align4 ec_response_tp_frame_info {
4383 uint32_t n_frames;
4384 uint32_t frame_sizes[0];
4385};
4386
4387/* Create a snapshot of current frame readings */
4388#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
4389
4390/* Read the frame */
4391#define EC_CMD_TP_FRAME_GET 0x0503
4392
4393struct __ec_align4 ec_params_tp_frame_get {
4394 uint32_t frame_index;
4395 uint32_t offset;
4396 uint32_t size;
4397};
Duncan Laurieeb316852015-12-01 18:51:18 -08004398
4399/*****************************************************************************/
4400/*
4401 * Reserve a range of host commands for board-specific, experimental, or
4402 * special purpose features. These can be (re)used without updating this file.
4403 *
4404 * CAUTION: Don't go nuts with this. Shipping products should document ALL
4405 * their EC commands for easier development, testing, debugging, and support.
4406 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004407 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
4408 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
4409 *
Duncan Laurieeb316852015-12-01 18:51:18 -08004410 * In your experimental code, you may want to do something like this:
4411 *
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004412 * #define EC_CMD_MAGIC_FOO 0x0000
4413 * #define EC_CMD_MAGIC_BAR 0x0001
4414 * #define EC_CMD_MAGIC_HEY 0x0002
4415 *
4416 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
4417 * EC_VER_MASK(0);
4418 *
4419 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
4420 * EC_VER_MASK(0);
4421 *
4422 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
4423 * EC_VER_MASK(0);
Duncan Laurieeb316852015-12-01 18:51:18 -08004424 */
4425#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
4426#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
4427
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004428/*
4429 * Given the private host command offset, calculate the true private host
4430 * command value.
4431 */
4432#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
4433 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
4434
Duncan Laurie93e24442014-01-06 12:30:52 -08004435/*****************************************************************************/
4436/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07004437 * Passthru commands
4438 *
4439 * Some platforms have sub-processors chained to each other. For example.
4440 *
4441 * AP <--> EC <--> PD MCU
4442 *
4443 * The top 2 bits of the command number are used to indicate which device the
4444 * command is intended for. Device 0 is always the device receiving the
4445 * command; other device mapping is board-specific.
4446 *
4447 * When a device receives a command to be passed to a sub-processor, it passes
4448 * it on with the device number set back to 0. This allows the sub-processor
4449 * to remain blissfully unaware of whether the command originated on the next
4450 * device up the chain, or was passed through from the AP.
4451 *
4452 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
4453 * AP sends command 0x4002 to the EC
4454 * EC sends command 0x0002 to the PD MCU
4455 * EC forwards PD MCU response back to the AP
4456 */
4457
4458/* Offset and max command number for sub-device n */
4459#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
4460#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
4461
4462/*****************************************************************************/
4463/*
Duncan Laurie93e24442014-01-06 12:30:52 -08004464 * Deprecated constants. These constants have been renamed for clarity. The
4465 * meaning and size has not changed. Programs that use the old names should
4466 * switch to the new names soon, as the old names may not be carried forward
4467 * forever.
4468 */
4469#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
4470#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
4471#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
4472
Patrick Georgi0f6187a2017-07-28 15:57:23 +02004473#endif /* !__ACPI__ && !__KERNEL__ */
Duncan Laurie67f26cc2017-06-29 23:17:22 -07004474
Duncan Laurieeb316852015-12-01 18:51:18 -08004475#endif /* __CROS_EC_EC_COMMANDS_H */