blob: 4f46fab6a8e1785e16949309ffde30148729aa51 [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. */