blob: ec404f091ebdfed4ea0d51d9aaca47d928d1adb4 [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
34/*
Duncan Laurie93e24442014-01-06 12:30:52 -080035 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080036 *
Duncan Laurie93e24442014-01-06 12:30:52 -080037 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
38 * determined in other ways. Remove this once the kernel code no longer
39 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080040 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080041#define EC_PROTO_VERSION 0x00000002
42
43/* Command version mask */
44#define EC_VER_MASK(version) (1UL << (version))
45
46/* I/O addresses for ACPI commands */
47#define EC_LPC_ADDR_ACPI_DATA 0x62
48#define EC_LPC_ADDR_ACPI_CMD 0x66
49
50/* I/O addresses for host command */
51#define EC_LPC_ADDR_HOST_DATA 0x200
52#define EC_LPC_ADDR_HOST_CMD 0x204
53
54/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080055/* Protocol version 2 */
56#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
57#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
58 * EC_PROTO2_MAX_PARAM_SIZE */
59/* Protocol version 3 */
60#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
61#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080062
Bill Richardsone221aad2013-06-12 10:50:41 -070063/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
64 * and they tell the kernel that so we have to think of it as two parts. */
65#define EC_HOST_CMD_REGION0 0x800
66#define EC_HOST_CMD_REGION1 0x880
67#define EC_HOST_CMD_REGION_SIZE 0x80
68
Stefan Reinauerd6682e82013-02-21 15:39:35 -080069/* EC command register bit functions */
70#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
71#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
72#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
73#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
74#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
75#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
76#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
77
78#define EC_LPC_ADDR_MEMMAP 0x900
79#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
80#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
81
82/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070083#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
84#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
85#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
86#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080087#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
88#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
89#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
90#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
91#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070092#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
93/* Unused 0x28 - 0x2f */
94#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
95/* Unused 0x31 - 0x33 */
96#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
97/* Reserve 0x38 - 0x3f for additional host event-related stuff */
98/* Battery values are all 32 bits */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080099#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
100#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
101#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
102#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
103#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
104#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
105#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
106#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700107/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800108#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
109#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
110#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
111#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700112#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
113/* Unused 0x84 - 0x8f */
114#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
115/* Unused 0x91 */
Duncan Laurieeb316852015-12-01 18:51:18 -0800116#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
117/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
118/* 0x94 - 0x99: 1st Accelerometer */
119/* 0x9a - 0x9f: 2nd Accelerometer */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700120#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700121/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700122
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700123/*
124 * ACPI is unable to access memory mapped data at or above this offset due to
125 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
126 * which might be needed by ACPI.
127 */
128#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700129
130/* Define the format of the accelerometer mapped memory status byte. */
131#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
132#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
133#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800134
135/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
136#define EC_TEMP_SENSOR_ENTRIES 16
137/*
138 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
139 *
140 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
141 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700142#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800143
144/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700145#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
146#define EC_TEMP_SENSOR_ERROR 0xfe
147#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
148#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800149/*
150 * The offset of temperature value stored in mapped memory. This allows
151 * reporting a temperature range of 200K to 454K = -73C to 181C.
152 */
153#define EC_TEMP_SENSOR_OFFSET 200
154
Duncan Laurie93e24442014-01-06 12:30:52 -0800155/*
156 * Number of ALS readings at EC_MEMMAP_ALS
157 */
158#define EC_ALS_ENTRIES 2
159
160/*
161 * The default value a temperature sensor will return when it is present but
162 * has not been read this boot. This is a reasonable number to avoid
163 * triggering alarms on the host.
164 */
165#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
166
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800167#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
168#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
169#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
170
171/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
172#define EC_BATT_FLAG_AC_PRESENT 0x01
173#define EC_BATT_FLAG_BATT_PRESENT 0x02
174#define EC_BATT_FLAG_DISCHARGING 0x04
175#define EC_BATT_FLAG_CHARGING 0x08
176#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
177
178/* Switch flags at EC_MEMMAP_SWITCHES */
179#define EC_SWITCH_LID_OPEN 0x01
180#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
181#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700182/* Was recovery requested via keyboard; now unused. */
183#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800184/* Recovery requested via dedicated signal (from servo board) */
185#define EC_SWITCH_DEDICATED_RECOVERY 0x10
186/* Was fake developer mode switch; now unused. Remove in next refactor. */
187#define EC_SWITCH_IGNORE0 0x20
188
189/* Host command interface flags */
190/* Host command interface supports LPC args (LPC interface only) */
191#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800192/* Host command interface supports version 3 protocol */
193#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800194
195/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800196#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
197#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
198#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
199#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
200#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800201
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700202/*****************************************************************************/
203/*
204 * ACPI commands
205 *
206 * These are valid ONLY on the ACPI command/data port.
207 */
208
209/*
210 * ACPI Read Embedded Controller
211 *
212 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
213 *
214 * Use the following sequence:
215 *
216 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
217 * - Wait for EC_LPC_CMDR_PENDING bit to clear
218 * - Write address to EC_LPC_ADDR_ACPI_DATA
219 * - Wait for EC_LPC_CMDR_DATA bit to set
220 * - Read value from EC_LPC_ADDR_ACPI_DATA
221 */
222#define EC_CMD_ACPI_READ 0x80
223
224/*
225 * ACPI Write Embedded Controller
226 *
227 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
228 *
229 * Use the following sequence:
230 *
231 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
232 * - Wait for EC_LPC_CMDR_PENDING bit to clear
233 * - Write address to EC_LPC_ADDR_ACPI_DATA
234 * - Wait for EC_LPC_CMDR_PENDING bit to clear
235 * - Write value to EC_LPC_ADDR_ACPI_DATA
236 */
237#define EC_CMD_ACPI_WRITE 0x81
238
239/*
240 * ACPI Burst Enable Embedded Controller
241 *
242 * This enables burst mode on the EC to allow the host to issue several
243 * commands back-to-back. While in this mode, writes to mapped multi-byte
244 * data are locked out to ensure data consistency.
245 */
246#define EC_CMD_ACPI_BURST_ENABLE 0x82
247
248/*
249 * ACPI Burst Disable Embedded Controller
250 *
251 * This disables burst mode on the EC and stops preventing EC writes to mapped
252 * multi-byte data.
253 */
254#define EC_CMD_ACPI_BURST_DISABLE 0x83
255
256/*
257 * ACPI Query Embedded Controller
258 *
259 * This clears the lowest-order bit in the currently pending host events, and
260 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
261 * event 0x80000000 = 32), or 0 if no event was pending.
262 */
263#define EC_CMD_ACPI_QUERY_EVENT 0x84
264
265/* Valid addresses in ACPI memory space, for read/write commands */
266
267/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
268#define EC_ACPI_MEM_VERSION 0x00
269/*
270 * Test location; writing value here updates test compliment byte to (0xff -
271 * value).
272 */
273#define EC_ACPI_MEM_TEST 0x01
274/* Test compliment; writes here are ignored. */
275#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
276
277/* Keyboard backlight brightness percent (0 - 100) */
278#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
279/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
280#define EC_ACPI_MEM_FAN_DUTY 0x04
281
282/*
283 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
284 * independent thresholds attached to them. The current value of the ID
285 * register determines which sensor is affected by the THRESHOLD and COMMIT
286 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
287 * as the memory-mapped sensors. The COMMIT register applies those settings.
288 *
289 * The spec does not mandate any way to read back the threshold settings
290 * themselves, but when a threshold is crossed the AP needs a way to determine
291 * which sensor(s) are responsible. Each reading of the ID register clears and
292 * returns one sensor ID that has crossed one of its threshold (in either
293 * direction) since the last read. A value of 0xFF means "no new thresholds
294 * have tripped". Setting or enabling the thresholds for a sensor will clear
295 * the unread event count for that sensor.
296 */
297#define EC_ACPI_MEM_TEMP_ID 0x05
298#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
299#define EC_ACPI_MEM_TEMP_COMMIT 0x07
300/*
301 * Here are the bits for the COMMIT register:
302 * bit 0 selects the threshold index for the chosen sensor (0/1)
303 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
304 * Each write to the commit register affects one threshold.
305 */
306#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
307#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
308/*
309 * Example:
310 *
311 * Set the thresholds for sensor 2 to 50 C and 60 C:
312 * write 2 to [0x05] -- select temp sensor 2
313 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
314 * write 0x2 to [0x07] -- enable threshold 0 with this value
315 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
316 * write 0x3 to [0x07] -- enable threshold 1 with this value
317 *
318 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
319 * write 2 to [0x05] -- select temp sensor 2
320 * write 0x1 to [0x07] -- disable threshold 1
321 */
322
323/* DPTF battery charging current limit */
324#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
325
326/* Charging limit is specified in 64 mA steps */
327#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
328/* Value to disable DPTF battery charging limit */
329#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
jiazi Yang51fc93f2016-07-28 05:15:01 -0400330/*
331 * Report device orientation
332 * bit 0 device is tablet mode
333 */
334#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
335#define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700336
337/*
338 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
339 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
340 */
341#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
342#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
343
344/* Current version of ACPI memory address space */
345#define EC_ACPI_MEM_VERSION_CURRENT 2
346
347
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800348/*
349 * This header file is used in coreboot both in C and ACPI code. The ACPI code
350 * is pre-processed to handle constants but the ASL compiler is unable to
351 * handle actual C code so keep it separate.
352 */
353#ifndef __ACPI__
354
Alexandru Gagniuc0d3a5122016-04-26 14:53:46 -0700355#include <stdint.h>
356
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800357/*
358 * Define __packed if someone hasn't beat us to it. Linux kernel style
359 * checking prefers __packed over __attribute__((packed)).
360 */
361#ifndef __packed
362#define __packed __attribute__((packed))
363#endif
364
365/* LPC command status byte masks */
366/* EC has written a byte in the data register and host hasn't read it yet */
367#define EC_LPC_STATUS_TO_HOST 0x01
368/* Host has written a command/data byte and the EC hasn't read it yet */
369#define EC_LPC_STATUS_FROM_HOST 0x02
370/* EC is processing a command */
371#define EC_LPC_STATUS_PROCESSING 0x04
372/* Last write to EC was a command, not data */
373#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700374/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800375#define EC_LPC_STATUS_BURST_MODE 0x10
376/* SCI event is pending (requesting SCI query) */
377#define EC_LPC_STATUS_SCI_PENDING 0x20
378/* SMI event is pending (requesting SMI query) */
379#define EC_LPC_STATUS_SMI_PENDING 0x40
380/* (reserved) */
381#define EC_LPC_STATUS_RESERVED 0x80
382
383/*
384 * EC is busy. This covers both the EC processing a command, and the host has
385 * written a new command but the EC hasn't picked it up yet.
386 */
387#define EC_LPC_STATUS_BUSY_MASK \
388 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
389
390/* Host command response codes */
391enum ec_status {
392 EC_RES_SUCCESS = 0,
393 EC_RES_INVALID_COMMAND = 1,
394 EC_RES_ERROR = 2,
395 EC_RES_INVALID_PARAM = 3,
396 EC_RES_ACCESS_DENIED = 4,
397 EC_RES_INVALID_RESPONSE = 5,
398 EC_RES_INVALID_VERSION = 6,
399 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700400 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
401 EC_RES_UNAVAILABLE = 9, /* No response available */
402 EC_RES_TIMEOUT = 10, /* We got a timeout */
403 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800404 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
405 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700406 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700407 EC_RES_BUS_ERROR = 15, /* Communications bus error */
408 EC_RES_BUSY = 16 /* Up but too busy. Should retry */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800409};
410
411/*
412 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
413 * EC command uses code 0 to mean "no event pending". We explicitly specify
414 * each value in the enum listing so they won't change if we delete/insert an
415 * item or rearrange the list (it needs to be stable across platforms, not
416 * just within a single compiled instance).
417 */
418enum host_event_code {
419 EC_HOST_EVENT_LID_CLOSED = 1,
420 EC_HOST_EVENT_LID_OPEN = 2,
421 EC_HOST_EVENT_POWER_BUTTON = 3,
422 EC_HOST_EVENT_AC_CONNECTED = 4,
423 EC_HOST_EVENT_AC_DISCONNECTED = 5,
424 EC_HOST_EVENT_BATTERY_LOW = 6,
425 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
426 EC_HOST_EVENT_BATTERY = 8,
427 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
428 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
429 EC_HOST_EVENT_THERMAL = 11,
430 EC_HOST_EVENT_USB_CHARGER = 12,
431 EC_HOST_EVENT_KEY_PRESSED = 13,
432 /*
433 * EC has finished initializing the host interface. The host can check
434 * for this event following sending a EC_CMD_REBOOT_EC command to
435 * determine when the EC is ready to accept subsequent commands.
436 */
437 EC_HOST_EVENT_INTERFACE_READY = 14,
438 /* Keyboard recovery combo has been pressed */
439 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
440
441 /* Shutdown due to thermal overload */
442 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
443 /* Shutdown due to battery level too low */
444 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
445
Duncan Laurie93e24442014-01-06 12:30:52 -0800446 /* Suggest that the AP throttle itself */
447 EC_HOST_EVENT_THROTTLE_START = 18,
448 /* Suggest that the AP resume normal speed */
449 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700450
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800451 /* Hang detect logic detected a hang and host event timeout expired */
452 EC_HOST_EVENT_HANG_DETECT = 20,
453 /* Hang detect logic detected a hang and warm rebooted the AP */
454 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700455
456 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700457 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800458
Duncan Lauried8401182014-09-29 08:32:19 -0700459 /* Battery Status flags have changed */
460 EC_HOST_EVENT_BATTERY_STATUS = 23,
461
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700462 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800463 EC_HOST_EVENT_PANIC = 24,
464
Furquan Shaikh066cc852015-06-20 15:53:03 -0700465 /* Keyboard fastboot combo has been pressed */
466 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
467
Gwendal Grignou880b4582016-06-20 08:49:25 -0700468 /* EC RTC event occurred */
469 EC_HOST_EVENT_RTC = 26,
470
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700471 /* Emulate MKBP event */
Gwendal Grignou880b4582016-06-20 08:49:25 -0700472 EC_HOST_EVENT_MKBP = 27,
Gwendal Grignou95b7a6c2016-05-03 23:53:23 -0700473
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700474 /* EC desires to change state of host-controlled USB mux */
475 EC_HOST_EVENT_USB_MUX = 28,
476
jiazi Yang51fc93f2016-07-28 05:15:01 -0400477 /* TABLET/LAPTOP mode event*/
478 EC_HOST_EVENT_MODE_CHANGE = 29,
479
Furquan Shaikh2afc4e72016-11-06 00:12:23 -0700480 /* Keyboard recovery combo with hardware reinitialization */
481 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
482
483 /*
484 * Reserve this last bit to indicate that at least one bit in a
485 * secondary host event word is set. See crbug.com/633646.
486 */
487 EC_HOST_EVENT_EXTENDED = 31,
488
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800489 /*
490 * The high bit of the event mask is not used as a host event code. If
491 * it reads back as set, then the entire event mask should be
492 * considered invalid by the host. This can happen when reading the
493 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
494 * not initialized on the EC, or improperly configured on the host.
495 */
496 EC_HOST_EVENT_INVALID = 32
497};
498/* Host event mask */
499#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
500
501/* Arguments at EC_LPC_ADDR_HOST_ARGS */
502struct ec_lpc_host_args {
503 uint8_t flags;
504 uint8_t command_version;
505 uint8_t data_size;
506 /*
507 * Checksum; sum of command + flags + command_version + data_size +
508 * all params/response data bytes.
509 */
510 uint8_t checksum;
511} __packed;
512
513/* Flags for ec_lpc_host_args.flags */
514/*
515 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
516 * params.
517 *
518 * If EC gets a command and this flag is not set, this is an old-style command.
519 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
520 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurieeb316852015-12-01 18:51:18 -0800521 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800522 */
523#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
524/*
525 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
526 *
527 * If EC responds to a command and this flag is not set, this is an old-style
528 * response. Command version is 0 and response data from EC is at
529 * EC_LPC_ADDR_OLD_PARAM with unknown length.
530 */
531#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
532
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800533/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800534/*
535 * Byte codes returned by EC over SPI interface.
536 *
537 * These can be used by the AP to debug the EC interface, and to determine
538 * when the EC is not in a state where it will ever get around to responding
539 * to the AP.
540 *
541 * Example of sequence of bytes read from EC for a current good transfer:
542 * 1. - - AP asserts chip select (CS#)
543 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
544 * 3. - - EC starts handling CS# interrupt
545 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
546 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
547 * bytes looking for EC_SPI_FRAME_START
548 * 6. - - EC finishes processing and sets up response
549 * 7. EC_SPI_FRAME_START - AP reads frame byte
550 * 8. (response packet) - AP reads response packet
551 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
552 * 10 - - AP deasserts chip select
553 * 11 - - EC processes CS# interrupt and sets up DMA for
554 * next request
555 *
556 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
557 * the following byte values:
558 * EC_SPI_OLD_READY
559 * EC_SPI_RX_READY
560 * EC_SPI_RECEIVING
561 * EC_SPI_PROCESSING
562 *
563 * Then the EC found an error in the request, or was not ready for the request
564 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
565 * because the EC is unable to tell when the AP is done sending its request.
566 */
567
568/*
569 * Framing byte which precedes a response packet from the EC. After sending a
570 * request, the AP will clock in bytes until it sees the framing byte, then
571 * clock in the response packet.
572 */
573#define EC_SPI_FRAME_START 0xec
574
575/*
576 * Padding bytes which are clocked out after the end of a response packet.
577 */
578#define EC_SPI_PAST_END 0xed
579
580/*
581 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
582 * that the AP will send a valid packet header (starting with
583 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
584 */
585#define EC_SPI_RX_READY 0xf8
586
587/*
588 * EC has started receiving the request from the AP, but hasn't started
589 * processing it yet.
590 */
591#define EC_SPI_RECEIVING 0xf9
592
593/* EC has received the entire request from the AP and is processing it. */
594#define EC_SPI_PROCESSING 0xfa
595
596/*
597 * EC received bad data from the AP, such as a packet header with an invalid
598 * length. EC will ignore all data until chip select deasserts.
599 */
600#define EC_SPI_RX_BAD_DATA 0xfb
601
602/*
603 * EC received data from the AP before it was ready. That is, the AP asserted
604 * chip select and started clocking data before the EC was ready to receive it.
605 * EC will ignore all data until chip select deasserts.
606 */
607#define EC_SPI_NOT_READY 0xfc
608
609/*
610 * EC was ready to receive a request from the AP. EC has treated the byte sent
611 * by the AP as part of a request packet, or (for old-style ECs) is processing
612 * a fully received packet but is not ready to respond yet.
613 */
614#define EC_SPI_OLD_READY 0xfd
615
616/*****************************************************************************/
617
618/*
619 * Protocol version 2 for I2C and SPI send a request this way:
620 *
621 * 0 EC_CMD_VERSION0 + (command version)
622 * 1 Command number
623 * 2 Length of params = N
624 * 3..N+2 Params, if any
625 * N+3 8-bit checksum of bytes 0..N+2
626 *
627 * The corresponding response is:
628 *
629 * 0 Result code (EC_RES_*)
630 * 1 Length of params = M
631 * 2..M+1 Params, if any
632 * M+2 8-bit checksum of bytes 0..M+1
633 */
634#define EC_PROTO2_REQUEST_HEADER_BYTES 3
635#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
636#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
637 EC_PROTO2_REQUEST_TRAILER_BYTES)
638
639#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
640#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
641#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
642 EC_PROTO2_RESPONSE_TRAILER_BYTES)
643
644/* Parameter length was limited by the LPC interface */
645#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
646
647/* Maximum request and response packet sizes for protocol version 2 */
648#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
649 EC_PROTO2_MAX_PARAM_SIZE)
650#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
651 EC_PROTO2_MAX_PARAM_SIZE)
652
653/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800654
655/*
656 * Value written to legacy command port / prefix byte to indicate protocol
657 * 3+ structs are being used. Usage is bus-dependent.
658 */
659#define EC_COMMAND_PROTOCOL_3 0xda
660
661#define EC_HOST_REQUEST_VERSION 3
662
663/* Version 3 request from host */
664struct ec_host_request {
665 /* Struct version (=3)
666 *
667 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
668 * version it doesn't know how to parse.
669 */
670 uint8_t struct_version;
671
672 /*
673 * Checksum of request and data; sum of all bytes including checksum
674 * should total to 0.
675 */
676 uint8_t checksum;
677
678 /* Command code */
679 uint16_t command;
680
681 /* Command version */
682 uint8_t command_version;
683
684 /* Unused byte in current protocol version; set to 0 */
685 uint8_t reserved;
686
687 /* Length of data which follows this header */
688 uint16_t data_len;
689} __packed;
690
691#define EC_HOST_RESPONSE_VERSION 3
692
693/* Version 3 response from EC */
694struct ec_host_response {
695 /* Struct version (=3) */
696 uint8_t struct_version;
697
698 /*
699 * Checksum of response and data; sum of all bytes including checksum
700 * should total to 0.
701 */
702 uint8_t checksum;
703
704 /* Result code (EC_RES_*) */
705 uint16_t result;
706
707 /* Length of data which follows this header */
708 uint16_t data_len;
709
710 /* Unused bytes in current protocol version; set to 0 */
711 uint16_t reserved;
712} __packed;
713
714/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800715/*
716 * Notes on commands:
717 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700718 * Each command is an 16-bit command value. Commands which take params or
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800719 * return response data specify structs for that data. If no struct is
720 * specified, the command does not input or output data, respectively.
721 * Parameter/response length is implicit in the structs. Some underlying
722 * communication protocols (I2C, SPI) may add length or checksum headers, but
723 * those are implementation-dependent and not defined here.
724 */
725
726/*****************************************************************************/
727/* General / test commands */
728
729/*
730 * Get protocol version, used to deal with non-backward compatible protocol
731 * changes.
732 */
733#define EC_CMD_PROTO_VERSION 0x00
734
735struct ec_response_proto_version {
736 uint32_t version;
737} __packed;
738
739/*
740 * Hello. This is a simple command to test the EC is responsive to
741 * commands.
742 */
743#define EC_CMD_HELLO 0x01
744
745struct ec_params_hello {
746 uint32_t in_data; /* Pass anything here */
747} __packed;
748
749struct ec_response_hello {
750 uint32_t out_data; /* Output will be in_data + 0x01020304 */
751} __packed;
752
753/* Get version number */
754#define EC_CMD_GET_VERSION 0x02
755
756enum ec_current_image {
757 EC_IMAGE_UNKNOWN = 0,
758 EC_IMAGE_RO,
759 EC_IMAGE_RW
760};
761
762struct ec_response_get_version {
763 /* Null-terminated version strings for RO, RW */
764 char version_string_ro[32];
765 char version_string_rw[32];
766 char reserved[32]; /* Was previously RW-B string */
767 uint32_t current_image; /* One of ec_current_image */
768} __packed;
769
770/* Read test */
771#define EC_CMD_READ_TEST 0x03
772
773struct ec_params_read_test {
774 uint32_t offset; /* Starting value for read buffer */
775 uint32_t size; /* Size to read in bytes */
776} __packed;
777
778struct ec_response_read_test {
779 uint32_t data[32];
780} __packed;
781
782/*
783 * Get build information
784 *
785 * Response is null-terminated string.
786 */
787#define EC_CMD_GET_BUILD_INFO 0x04
788
789/* Get chip info */
790#define EC_CMD_GET_CHIP_INFO 0x05
791
792struct ec_response_get_chip_info {
793 /* Null-terminated strings */
794 char vendor[32];
795 char name[32];
796 char revision[32]; /* Mask version */
797} __packed;
798
799/* Get board HW version */
800#define EC_CMD_GET_BOARD_VERSION 0x06
801
802struct ec_response_board_version {
803 uint16_t board_version; /* A monotonously incrementing number. */
804} __packed;
805
806/*
807 * Read memory-mapped data.
808 *
809 * This is an alternate interface to memory-mapped data for bus protocols
810 * which don't support direct-mapped memory - I2C, SPI, etc.
811 *
812 * Response is params.size bytes of data.
813 */
814#define EC_CMD_READ_MEMMAP 0x07
815
816struct ec_params_read_memmap {
817 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
818 uint8_t size; /* Size to read in bytes */
819} __packed;
820
821/* Read versions supported for a command */
822#define EC_CMD_GET_CMD_VERSIONS 0x08
823
824struct ec_params_get_cmd_versions {
825 uint8_t cmd; /* Command to check */
826} __packed;
827
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700828struct ec_params_get_cmd_versions_v1 {
829 uint16_t cmd; /* Command to check */
830} __packed;
831
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800832struct ec_response_get_cmd_versions {
833 /*
834 * Mask of supported versions; use EC_VER_MASK() to compare with a
835 * desired version.
836 */
837 uint32_t version_mask;
838} __packed;
839
Duncan Laurie433432b2013-06-03 10:38:22 -0700840/*
841 * Check EC communcations status (busy). This is needed on i2c/spi but not
842 * on lpc since it has its own out-of-band busy indicator.
843 *
844 * lpc must read the status from the command register. Attempting this on
845 * lpc will overwrite the args/parameter space and corrupt its data.
846 */
847#define EC_CMD_GET_COMMS_STATUS 0x09
848
849/* Avoid using ec_status which is for return values */
850enum ec_comms_status {
851 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
852};
853
854struct ec_response_get_comms_status {
855 uint32_t flags; /* Mask of enum ec_comms_status */
856} __packed;
857
Duncan Laurie93e24442014-01-06 12:30:52 -0800858/* Fake a variety of responses, purely for testing purposes. */
859#define EC_CMD_TEST_PROTOCOL 0x0a
860
861/* Tell the EC what to send back to us. */
862struct ec_params_test_protocol {
863 uint32_t ec_result;
864 uint32_t ret_len;
865 uint8_t buf[32];
866} __packed;
867
868/* Here it comes... */
869struct ec_response_test_protocol {
870 uint8_t buf[32];
871} __packed;
872
873/* Get prococol information */
874#define EC_CMD_GET_PROTOCOL_INFO 0x0b
875
876/* Flags for ec_response_get_protocol_info.flags */
877/* EC_RES_IN_PROGRESS may be returned if a command is slow */
878#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
879
880struct ec_response_get_protocol_info {
881 /* Fields which exist if at least protocol version 3 supported */
882
883 /* Bitmask of protocol versions supported (1 << n means version n)*/
884 uint32_t protocol_versions;
885
886 /* Maximum request packet size, in bytes */
887 uint16_t max_request_packet_size;
888
889 /* Maximum response packet size, in bytes */
890 uint16_t max_response_packet_size;
891
892 /* Flags; see EC_PROTOCOL_INFO_* */
893 uint32_t flags;
894} __packed;
895
896
897/*****************************************************************************/
898/* Get/Set miscellaneous values */
899
900/* The upper byte of .flags tells what to do (nothing means "get") */
901#define EC_GSV_SET 0x80000000
902
903/* The lower three bytes of .flags identifies the parameter, if that has
904 meaning for an individual command. */
905#define EC_GSV_PARAM_MASK 0x00ffffff
906
907struct ec_params_get_set_value {
908 uint32_t flags;
909 uint32_t value;
910} __packed;
911
912struct ec_response_get_set_value {
913 uint32_t flags;
914 uint32_t value;
915} __packed;
916
Duncan Laurieeb316852015-12-01 18:51:18 -0800917/* More than one command can use these structs to get/set parameters. */
Duncan Laurie93e24442014-01-06 12:30:52 -0800918#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
919
Duncan Laurieeb316852015-12-01 18:51:18 -0800920/*****************************************************************************/
921/* List the features supported by the firmware */
922#define EC_CMD_GET_FEATURES 0x0d
923
924/* Supported features */
925enum ec_feature_code {
926 /*
927 * This image contains a limited set of features. Another image
928 * in RW partition may support more features.
929 */
930 EC_FEATURE_LIMITED = 0,
931 /*
932 * Commands for probing/reading/writing/erasing the flash in the
933 * EC are present.
934 */
935 EC_FEATURE_FLASH = 1,
936 /*
937 * Can control the fan speed directly.
938 */
939 EC_FEATURE_PWM_FAN = 2,
940 /*
941 * Can control the intensity of the keyboard backlight.
942 */
943 EC_FEATURE_PWM_KEYB = 3,
944 /*
945 * Support Google lightbar, introduced on Pixel.
946 */
947 EC_FEATURE_LIGHTBAR = 4,
948 /* Control of LEDs */
949 EC_FEATURE_LED = 5,
950 /* Exposes an interface to control gyro and sensors.
951 * The host goes through the EC to access these sensors.
952 * In addition, the EC may provide composite sensors, like lid angle.
953 */
954 EC_FEATURE_MOTION_SENSE = 6,
955 /* The keyboard is controlled by the EC */
956 EC_FEATURE_KEYB = 7,
957 /* The AP can use part of the EC flash as persistent storage. */
958 EC_FEATURE_PSTORE = 8,
959 /* The EC monitors BIOS port 80h, and can return POST codes. */
960 EC_FEATURE_PORT80 = 9,
961 /*
962 * Thermal management: include TMP specific commands.
963 * Higher level than direct fan control.
964 */
965 EC_FEATURE_THERMAL = 10,
966 /* Can switch the screen backlight on/off */
967 EC_FEATURE_BKLIGHT_SWITCH = 11,
968 /* Can switch the wifi module on/off */
969 EC_FEATURE_WIFI_SWITCH = 12,
970 /* Monitor host events, through for example SMI or SCI */
971 EC_FEATURE_HOST_EVENTS = 13,
972 /* The EC exposes GPIO commands to control/monitor connected devices. */
973 EC_FEATURE_GPIO = 14,
974 /* The EC can send i2c messages to downstream devices. */
975 EC_FEATURE_I2C = 15,
976 /* Command to control charger are included */
977 EC_FEATURE_CHARGER = 16,
978 /* Simple battery support. */
979 EC_FEATURE_BATTERY = 17,
980 /*
981 * Support Smart battery protocol
982 * (Common Smart Battery System Interface Specification)
983 */
984 EC_FEATURE_SMART_BATTERY = 18,
985 /* EC can dectect when the host hangs. */
986 EC_FEATURE_HANG_DETECT = 19,
987 /* Report power information, for pit only */
988 EC_FEATURE_PMU = 20,
989 /* Another Cros EC device is present downstream of this one */
990 EC_FEATURE_SUB_MCU = 21,
991 /* Support USB Power delivery (PD) commands */
992 EC_FEATURE_USB_PD = 22,
993 /* Control USB multiplexer, for audio through USB port for instance. */
994 EC_FEATURE_USB_MUX = 23,
995 /* Motion Sensor code has an internal software FIFO */
996 EC_FEATURE_MOTION_SENSE_FIFO = 24,
997 /* Support temporary secure vstore */
998 EC_FEATURE_VSTORE = 25,
999};
1000
1001#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
1002#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
1003struct ec_response_get_features {
1004 uint32_t flags[2];
1005} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07001006
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001007/*****************************************************************************/
1008/* Flash commands */
1009
1010/* Get flash info */
1011#define EC_CMD_FLASH_INFO 0x10
1012
Duncan Laurie93e24442014-01-06 12:30:52 -08001013/* Version 0 returns these fields */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001014struct ec_response_flash_info {
1015 /* Usable flash size, in bytes */
1016 uint32_t flash_size;
1017 /*
1018 * Write block size. Write offset and size must be a multiple
1019 * of this.
1020 */
1021 uint32_t write_block_size;
1022 /*
1023 * Erase block size. Erase offset and size must be a multiple
1024 * of this.
1025 */
1026 uint32_t erase_block_size;
1027 /*
1028 * Protection block size. Protection offset and size must be a
1029 * multiple of this.
1030 */
1031 uint32_t protect_block_size;
1032} __packed;
1033
Duncan Laurie93e24442014-01-06 12:30:52 -08001034/* Flags for version 1+ flash info command */
1035/* EC flash erases bits to 0 instead of 1 */
1036#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1037
1038/*
1039 * Version 1 returns the same initial fields as version 0, with additional
1040 * fields following.
1041 *
1042 * gcc anonymous structs don't seem to get along with the __packed directive;
1043 * if they did we'd define the version 0 struct as a sub-struct of this one.
1044 */
1045struct ec_response_flash_info_1 {
1046 /* Version 0 fields; see above for description */
1047 uint32_t flash_size;
1048 uint32_t write_block_size;
1049 uint32_t erase_block_size;
1050 uint32_t protect_block_size;
1051
1052 /* Version 1 adds these fields: */
1053 /*
1054 * Ideal write size in bytes. Writes will be fastest if size is
1055 * exactly this and offset is a multiple of this. For example, an EC
1056 * may have a write buffer which can do half-page operations if data is
1057 * aligned, and a slower word-at-a-time write mode.
1058 */
1059 uint32_t write_ideal_size;
1060
1061 /* Flags; see EC_FLASH_INFO_* */
1062 uint32_t flags;
1063} __packed;
1064
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001065/*
1066 * Read flash
1067 *
1068 * Response is params.size bytes of data.
1069 */
1070#define EC_CMD_FLASH_READ 0x11
1071
1072struct ec_params_flash_read {
1073 uint32_t offset; /* Byte offset to read */
1074 uint32_t size; /* Size to read in bytes */
1075} __packed;
1076
1077/* Write flash */
1078#define EC_CMD_FLASH_WRITE 0x12
Duncan Laurie93e24442014-01-06 12:30:52 -08001079#define EC_VER_FLASH_WRITE 1
1080
1081/* Version 0 of the flash command supported only 64 bytes of data */
1082#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001083
1084struct ec_params_flash_write {
1085 uint32_t offset; /* Byte offset to write */
1086 uint32_t size; /* Size to write in bytes */
Duncan Laurie93e24442014-01-06 12:30:52 -08001087 /* Followed by data to write */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001088} __packed;
1089
1090/* Erase flash */
1091#define EC_CMD_FLASH_ERASE 0x13
1092
1093struct ec_params_flash_erase {
1094 uint32_t offset; /* Byte offset to erase */
1095 uint32_t size; /* Size to erase in bytes */
1096} __packed;
1097
1098/*
1099 * Get/set flash protection.
1100 *
1101 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1102 * firmware write protect GPIO, not all flags will take effect immediately;
1103 * some flags require a subsequent hard reset to take effect. Check the
1104 * returned flags bits to see what actually happened.
1105 *
1106 * If mask=0, simply returns the current flags state.
1107 */
1108#define EC_CMD_FLASH_PROTECT 0x15
1109#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1110
1111/* Flags for flash protection */
1112/* RO flash code protected when the EC boots */
1113#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1114/*
1115 * RO flash code protected now. If this bit is set, at-boot status cannot
1116 * be changed.
1117 */
1118#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001119/* Entire flash code protected now, until reboot. */
1120#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001121/* Flash write protect GPIO is asserted now */
1122#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1123/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1124#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1125/*
1126 * Error - flash protection is in inconsistent state. At least one bank of
1127 * flash which should be protected is not protected. Usually fixed by
1128 * re-requesting the desired flags, or by a hard reset if that fails.
1129 */
1130#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001131/* Entire flash code protected when the EC boots */
Duncan Laurie433432b2013-06-03 10:38:22 -07001132#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001133
1134struct ec_params_flash_protect {
1135 uint32_t mask; /* Bits in flags to apply */
1136 uint32_t flags; /* New flags to apply */
1137} __packed;
1138
1139struct ec_response_flash_protect {
1140 /* Current value of flash protect flags */
1141 uint32_t flags;
1142 /*
1143 * Flags which are valid on this platform. This allows the caller
1144 * to distinguish between flags which aren't set vs. flags which can't
1145 * be set on this platform.
1146 */
1147 uint32_t valid_flags;
1148 /* Flags which can be changed given the current protection state */
1149 uint32_t writable_flags;
1150} __packed;
1151
1152/*
1153 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1154 * write protect. These commands may be reused with version > 0.
1155 */
1156
1157/* Get the region offset/size */
1158#define EC_CMD_FLASH_REGION_INFO 0x16
1159#define EC_VER_FLASH_REGION_INFO 1
1160
1161enum ec_flash_region {
1162 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001163 EC_FLASH_REGION_RO = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001164 /* Region which holds rewritable EC image */
1165 EC_FLASH_REGION_RW,
1166 /*
1167 * Region which should be write-protected in the factory (a superset of
1168 * EC_FLASH_REGION_RO)
1169 */
1170 EC_FLASH_REGION_WP_RO,
Duncan Laurie93e24442014-01-06 12:30:52 -08001171 /* Number of regions */
1172 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001173};
1174
1175struct ec_params_flash_region_info {
1176 uint32_t region; /* enum ec_flash_region */
1177} __packed;
1178
1179struct ec_response_flash_region_info {
1180 uint32_t offset;
1181 uint32_t size;
1182} __packed;
1183
Duncan Laurie433432b2013-06-03 10:38:22 -07001184/* Read/write VbNvContext */
1185#define EC_CMD_VBNV_CONTEXT 0x17
1186#define EC_VER_VBNV_CONTEXT 1
1187#define EC_VBNV_BLOCK_SIZE 16
1188
1189enum ec_vbnvcontext_op {
1190 EC_VBNV_CONTEXT_OP_READ,
1191 EC_VBNV_CONTEXT_OP_WRITE,
1192};
1193
1194struct ec_params_vbnvcontext {
1195 uint32_t op;
1196 uint8_t block[EC_VBNV_BLOCK_SIZE];
1197} __packed;
1198
1199struct ec_response_vbnvcontext {
1200 uint8_t block[EC_VBNV_BLOCK_SIZE];
1201} __packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001202
1203/*****************************************************************************/
1204/* PWM commands */
1205
1206/* Get fan target RPM */
1207#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1208
1209struct ec_response_pwm_get_fan_rpm {
1210 uint32_t rpm;
1211} __packed;
1212
1213/* Set target fan RPM */
1214#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1215
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001216/* Version 0 of input params */
1217struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001218 uint32_t rpm;
1219} __packed;
1220
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001221/* Version 1 of input params */
1222struct ec_params_pwm_set_fan_target_rpm_v1 {
1223 uint32_t rpm;
1224 uint8_t fan_idx;
1225} __packed;
1226
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001227/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001228/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001229#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1230
1231struct ec_response_pwm_get_keyboard_backlight {
1232 uint8_t percent;
1233 uint8_t enabled;
1234} __packed;
1235
1236/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001237/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001238#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1239
1240struct ec_params_pwm_set_keyboard_backlight {
1241 uint8_t percent;
1242} __packed;
1243
1244/* Set target fan PWM duty cycle */
1245#define EC_CMD_PWM_SET_FAN_DUTY 0x24
1246
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001247/* Version 0 of input params */
1248struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001249 uint32_t percent;
1250} __packed;
1251
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001252/* Version 1 of input params */
1253struct ec_params_pwm_set_fan_duty_v1 {
1254 uint32_t percent;
1255 uint8_t fan_idx;
1256} __packed;
1257
Gwendal Grignou880b4582016-06-20 08:49:25 -07001258#define EC_CMD_PWM_SET_DUTY 0x25
1259/* 16 bit duty cycle, 0xffff = 100% */
1260#define EC_PWM_MAX_DUTY 0xffff
1261
1262enum ec_pwm_type {
1263 /* All types, indexed by board-specific enum pwm_channel */
1264 EC_PWM_TYPE_GENERIC = 0,
1265 /* Keyboard backlight */
1266 EC_PWM_TYPE_KB_LIGHT,
1267 /* Display backlight */
1268 EC_PWM_TYPE_DISPLAY_LIGHT,
1269 EC_PWM_TYPE_COUNT,
1270};
1271
1272struct ec_params_pwm_set_duty {
1273 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1274 uint8_t pwm_type; /* ec_pwm_type */
1275 uint8_t index; /* Type-specific index, or 0 if unique */
1276} __packed;
1277
1278#define EC_CMD_PWM_GET_DUTY 0x26
1279
1280struct ec_params_pwm_get_duty {
1281 uint8_t pwm_type; /* ec_pwm_type */
1282 uint8_t index; /* Type-specific index, or 0 if unique */
1283} __packed;
1284
1285struct ec_response_pwm_get_duty {
1286 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1287} __packed;
1288
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001289/*****************************************************************************/
1290/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001291 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001292 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1293 * into a subcommand. We'll make separate structs for subcommands with
1294 * different input args, so that we know how much to expect.
1295 */
1296#define EC_CMD_LIGHTBAR_CMD 0x28
1297
Duncan Laurie433432b2013-06-03 10:38:22 -07001298struct rgb_s {
1299 uint8_t r, g, b;
1300};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001301
Duncan Laurie433432b2013-06-03 10:38:22 -07001302#define LB_BATTERY_LEVELS 4
1303/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1304 * host command, but the alignment is the same regardless. Keep it that way.
1305 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001306struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001307 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001308 int32_t google_ramp_up;
1309 int32_t google_ramp_down;
1310 int32_t s3s0_ramp_up;
1311 int32_t s0_tick_delay[2]; /* AC=0/1 */
1312 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1313 int32_t s0s3_ramp_down;
1314 int32_t s3_sleep_for;
1315 int32_t s3_ramp_up;
1316 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001317
1318 /* Oscillation */
1319 uint8_t new_s0;
1320 uint8_t osc_min[2]; /* AC=0/1 */
1321 uint8_t osc_max[2]; /* AC=0/1 */
1322 uint8_t w_ofs[2]; /* AC=0/1 */
1323
1324 /* Brightness limits based on the backlight and AC. */
1325 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1326 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1327 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1328
1329 /* Battery level thresholds */
1330 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1331
1332 /* Map [AC][battery_level] to color index */
1333 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1334 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1335
1336 /* Color palette */
1337 struct rgb_s color[8]; /* 0-3 are Google colors */
1338} __packed;
1339
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001340struct lightbar_params_v1 {
1341 /* Timing */
1342 int32_t google_ramp_up;
1343 int32_t google_ramp_down;
1344 int32_t s3s0_ramp_up;
1345 int32_t s0_tick_delay[2]; /* AC=0/1 */
1346 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1347 int32_t s0s3_ramp_down;
1348 int32_t s3_sleep_for;
1349 int32_t s3_ramp_up;
1350 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001351 int32_t s5_ramp_up;
1352 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001353 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001354 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001355 int32_t tap_display_time;
1356
1357 /* Tap-for-battery params */
1358 uint8_t tap_pct_red;
1359 uint8_t tap_pct_green;
1360 uint8_t tap_seg_min_on;
1361 uint8_t tap_seg_max_on;
1362 uint8_t tap_seg_osc;
1363 uint8_t tap_idx[3];
1364
1365 /* Oscillation */
1366 uint8_t osc_min[2]; /* AC=0/1 */
1367 uint8_t osc_max[2]; /* AC=0/1 */
1368 uint8_t w_ofs[2]; /* AC=0/1 */
1369
1370 /* Brightness limits based on the backlight and AC. */
1371 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1372 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1373 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1374
1375 /* Battery level thresholds */
1376 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1377
1378 /* Map [AC][battery_level] to color index */
1379 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1380 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1381
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001382 /* s5: single color pulse on inhibited power-up */
1383 uint8_t s5_idx;
1384
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001385 /* Color palette */
1386 struct rgb_s color[8]; /* 0-3 are Google colors */
1387} __packed;
1388
Duncan Laurieeb316852015-12-01 18:51:18 -08001389/* Lightbar command params v2
1390 * crbug.com/467716
1391 *
1392 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1393 * logical groups to make it more manageable ( < 120 bytes).
1394 *
1395 * NOTE: Each of these groups must be less than 120 bytes.
1396 */
1397
1398struct lightbar_params_v2_timing {
1399 /* Timing */
1400 int32_t google_ramp_up;
1401 int32_t google_ramp_down;
1402 int32_t s3s0_ramp_up;
1403 int32_t s0_tick_delay[2]; /* AC=0/1 */
1404 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1405 int32_t s0s3_ramp_down;
1406 int32_t s3_sleep_for;
1407 int32_t s3_ramp_up;
1408 int32_t s3_ramp_down;
1409 int32_t s5_ramp_up;
1410 int32_t s5_ramp_down;
1411 int32_t tap_tick_delay;
1412 int32_t tap_gate_delay;
1413 int32_t tap_display_time;
1414} __packed;
1415
1416struct lightbar_params_v2_tap {
1417 /* Tap-for-battery params */
1418 uint8_t tap_pct_red;
1419 uint8_t tap_pct_green;
1420 uint8_t tap_seg_min_on;
1421 uint8_t tap_seg_max_on;
1422 uint8_t tap_seg_osc;
1423 uint8_t tap_idx[3];
1424} __packed;
1425
1426struct lightbar_params_v2_oscillation {
1427 /* Oscillation */
1428 uint8_t osc_min[2]; /* AC=0/1 */
1429 uint8_t osc_max[2]; /* AC=0/1 */
1430 uint8_t w_ofs[2]; /* AC=0/1 */
1431} __packed;
1432
1433struct lightbar_params_v2_brightness {
1434 /* Brightness limits based on the backlight and AC. */
1435 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1436 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1437 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1438} __packed;
1439
1440struct lightbar_params_v2_thresholds {
1441 /* Battery level thresholds */
1442 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1443} __packed;
1444
1445struct lightbar_params_v2_colors {
1446 /* Map [AC][battery_level] to color index */
1447 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1448 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1449
1450 /* s5: single color pulse on inhibited power-up */
1451 uint8_t s5_idx;
1452
1453 /* Color palette */
1454 struct rgb_s color[8]; /* 0-3 are Google colors */
1455} __packed;
1456
Duncan Lauried8401182014-09-29 08:32:19 -07001457/* Lightbyte program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001458#define EC_LB_PROG_LEN 192
1459struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07001460 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001461 uint8_t data[EC_LB_PROG_LEN];
Duncan Lauried8401182014-09-29 08:32:19 -07001462};
1463
Duncan Laurie433432b2013-06-03 10:38:22 -07001464struct ec_params_lightbar {
1465 uint8_t cmd; /* Command (see enum lightbar_command) */
1466 union {
1467 struct {
1468 /* no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001469 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001470 version, get_brightness, get_demo, suspend, resume,
1471 get_params_v2_timing, get_params_v2_tap,
1472 get_params_v2_osc, get_params_v2_bright,
1473 get_params_v2_thlds, get_params_v2_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001474
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001475 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001476 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001477 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001478
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001479 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001480 uint8_t ctrl, reg, value;
1481 } reg;
1482
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001483 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001484 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001485 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07001486
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001487 struct {
1488 uint8_t led;
1489 } get_rgb;
1490
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001491 struct {
1492 uint8_t enable;
1493 } manual_suspend_ctrl;
1494
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001495 struct lightbar_params_v0 set_params_v0;
1496 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08001497
1498 struct lightbar_params_v2_timing set_v2par_timing;
1499 struct lightbar_params_v2_tap set_v2par_tap;
1500 struct lightbar_params_v2_oscillation set_v2par_osc;
1501 struct lightbar_params_v2_brightness set_v2par_bright;
1502 struct lightbar_params_v2_thresholds set_v2par_thlds;
1503 struct lightbar_params_v2_colors set_v2par_colors;
1504
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001505 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001506 };
1507} __packed;
1508
Duncan Laurie433432b2013-06-03 10:38:22 -07001509struct ec_response_lightbar {
1510 union {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001511 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001512 struct {
1513 uint8_t reg;
1514 uint8_t ic0;
1515 uint8_t ic1;
1516 } vals[23];
1517 } dump;
1518
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001519 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001520 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001521 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001522
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001523 struct lightbar_params_v0 get_params_v0;
1524 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07001525
Duncan Laurieeb316852015-12-01 18:51:18 -08001526
1527 struct lightbar_params_v2_timing get_params_v2_timing;
1528 struct lightbar_params_v2_tap get_params_v2_tap;
1529 struct lightbar_params_v2_oscillation get_params_v2_osc;
1530 struct lightbar_params_v2_brightness get_params_v2_bright;
1531 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1532 struct lightbar_params_v2_colors get_params_v2_colors;
1533
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001534 struct {
Duncan Laurie93e24442014-01-06 12:30:52 -08001535 uint32_t num;
1536 uint32_t flags;
1537 } version;
1538
Duncan Laurie433432b2013-06-03 10:38:22 -07001539 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001540 uint8_t red, green, blue;
1541 } get_rgb;
1542
1543 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001544 /* no return params */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001545 } off, on, init, set_brightness, seq, reg, set_rgb,
Duncan Lauried8401182014-09-29 08:32:19 -07001546 demo, set_params_v0, set_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001547 set_program, manual_suspend_ctrl, suspend, resume,
1548 set_v2par_timing, set_v2par_tap,
1549 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1550 set_v2par_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001551 };
1552} __packed;
1553
1554/* Lightbar commands */
1555enum lightbar_command {
1556 LIGHTBAR_CMD_DUMP = 0,
1557 LIGHTBAR_CMD_OFF = 1,
1558 LIGHTBAR_CMD_ON = 2,
1559 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001560 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07001561 LIGHTBAR_CMD_SEQ = 5,
1562 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001563 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07001564 LIGHTBAR_CMD_GET_SEQ = 8,
1565 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001566 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1567 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08001568 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001569 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1570 LIGHTBAR_CMD_GET_RGB = 14,
1571 LIGHTBAR_CMD_GET_DEMO = 15,
1572 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1573 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07001574 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001575 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1576 LIGHTBAR_CMD_SUSPEND = 20,
1577 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08001578 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1579 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1580 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1581 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1582 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1583 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1584 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1585 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1586 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1587 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1588 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1589 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07001590 LIGHTBAR_NUM_CMDS
1591};
1592
1593/*****************************************************************************/
1594/* LED control commands */
1595
Bill Richardsone221aad2013-06-12 10:50:41 -07001596#define EC_CMD_LED_CONTROL 0x29
Duncan Laurie433432b2013-06-03 10:38:22 -07001597
Bill Richardsone221aad2013-06-12 10:50:41 -07001598enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08001599 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07001600 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08001601 /*
1602 * LED to indicate system power state (on or in suspend).
1603 * May be on power button or on C-panel.
1604 */
1605 EC_LED_ID_POWER_LED,
1606 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07001607 EC_LED_ID_ADAPTER_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08001608
1609 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07001610};
Duncan Laurie433432b2013-06-03 10:38:22 -07001611
Bill Richardsone221aad2013-06-12 10:50:41 -07001612/* LED control flags */
1613#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1614#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1615
1616enum ec_led_colors {
1617 EC_LED_COLOR_RED = 0,
1618 EC_LED_COLOR_GREEN,
1619 EC_LED_COLOR_BLUE,
1620 EC_LED_COLOR_YELLOW,
1621 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08001622 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07001623
1624 EC_LED_COLOR_COUNT
1625};
1626
1627struct ec_params_led_control {
1628 uint8_t led_id; /* Which LED to control */
1629 uint8_t flags; /* Control flags */
1630
1631 uint8_t brightness[EC_LED_COLOR_COUNT];
1632} __packed;
1633
1634struct ec_response_led_control {
1635 /*
1636 * Available brightness value range.
1637 *
1638 * Range 0 means color channel not present.
1639 * Range 1 means on/off control.
1640 * Other values means the LED is control by PWM.
1641 */
1642 uint8_t brightness_range[EC_LED_COLOR_COUNT];
Duncan Laurie433432b2013-06-03 10:38:22 -07001643} __packed;
1644
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001645/*****************************************************************************/
1646/* Verified boot commands */
1647
1648/*
1649 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1650 * reused for other purposes with version > 0.
1651 */
1652
1653/* Verified boot hash command */
Duncan Laurieeb316852015-12-01 18:51:18 -08001654#define EC_CMD_VBOOT_HASH 0x2a
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001655
1656struct ec_params_vboot_hash {
1657 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1658 uint8_t hash_type; /* enum ec_vboot_hash_type */
1659 uint8_t nonce_size; /* Nonce size; may be 0 */
1660 uint8_t reserved0; /* Reserved; set 0 */
1661 uint32_t offset; /* Offset in flash to hash */
1662 uint32_t size; /* Number of bytes to hash */
1663 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1664} __packed;
1665
1666struct ec_response_vboot_hash {
1667 uint8_t status; /* enum ec_vboot_hash_status */
1668 uint8_t hash_type; /* enum ec_vboot_hash_type */
1669 uint8_t digest_size; /* Size of hash digest in bytes */
1670 uint8_t reserved0; /* Ignore; will be 0 */
1671 uint32_t offset; /* Offset in flash which was hashed */
1672 uint32_t size; /* Number of bytes hashed */
1673 uint8_t hash_digest[64]; /* Hash digest data */
1674} __packed;
1675
1676enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07001677 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1678 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1679 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1680 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001681};
1682
1683enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07001684 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001685};
1686
1687enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001688 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1689 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1690 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001691};
1692
Duncan Laurie433432b2013-06-03 10:38:22 -07001693/*
1694 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1695 * If one of these is specified, the EC will automatically update offset and
1696 * size to the correct values for the specified image (RO or RW).
1697 */
1698#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1699#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1700
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001701/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001702/*
1703 * Motion sense commands. We'll make separate structs for sub-commands with
1704 * different input args, so that we know how much to expect.
1705 */
Duncan Laurieeb316852015-12-01 18:51:18 -08001706#define EC_CMD_MOTION_SENSE_CMD 0x2b
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001707
1708/* Motion sense commands */
1709enum motionsense_command {
1710 /*
1711 * Dump command returns all motion sensor data including motion sense
1712 * module flags and individual sensor flags.
1713 */
1714 MOTIONSENSE_CMD_DUMP = 0,
1715
1716 /*
1717 * Info command returns data describing the details of a given sensor,
1718 * including enum motionsensor_type, enum motionsensor_location, and
1719 * enum motionsensor_chip.
1720 */
1721 MOTIONSENSE_CMD_INFO = 1,
1722
1723 /*
1724 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08001725 * in milliseconds.
1726 * It is per sensor, the EC run sample task at the minimum of all
1727 * sensors EC_RATE.
1728 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
1729 * to collect all the sensor samples.
1730 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
1731 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001732 */
1733 MOTIONSENSE_CMD_EC_RATE = 2,
1734
1735 /*
1736 * Sensor ODR command is a setter/getter command for the output data
1737 * rate of a specific motion sensor in millihertz.
1738 */
1739 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1740
1741 /*
1742 * Sensor range command is a setter/getter command for the range of
1743 * a specified motion sensor in +/-G's or +/- deg/s.
1744 */
1745 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1746
1747 /*
1748 * Setter/getter command for the keyboard wake angle. When the lid
1749 * angle is greater than this value, keyboard wake is disabled in S3,
1750 * and when the lid angle goes less than this value, keyboard wake is
1751 * enabled. Note, the lid angle measurement is an approximate,
1752 * un-calibrated value, hence the wake angle isn't exact.
1753 */
1754 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1755
Duncan Laurieeb316852015-12-01 18:51:18 -08001756 /*
1757 * Returns a single sensor data.
1758 */
1759 MOTIONSENSE_CMD_DATA = 6,
1760
1761 /*
1762 * Return sensor fifo info.
1763 */
1764 MOTIONSENSE_CMD_FIFO_INFO = 7,
1765
1766 /*
1767 * Insert a flush element in the fifo and return sensor fifo info.
1768 * The host can use that element to synchronize its operation.
1769 */
1770 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
1771
1772 /*
1773 * Return a portion of the fifo.
1774 */
1775 MOTIONSENSE_CMD_FIFO_READ = 9,
1776
1777 /*
1778 * Perform low level calibration.
1779 * On sensors that support it, ask to do offset calibration.
1780 */
1781 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1782
1783 /*
1784 * Sensor Offset command is a setter/getter command for the offset
1785 * used for calibration.
1786 * The offsets can be calculated by the host, or via
1787 * PERFORM_CALIB command.
1788 */
1789 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1790
1791 /*
1792 * List available activities for a MOTION sensor.
1793 * Indicates if they are enabled or disabled.
1794 */
1795 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
1796
1797 /*
1798 * Activity management
1799 * Enable/Disable activity recognition.
1800 */
1801 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
1802
1803 /*
1804 * Lid Angle
1805 */
1806 MOTIONSENSE_CMD_LID_ANGLE = 14,
1807
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001808 /* Number of motionsense sub-commands. */
1809 MOTIONSENSE_NUM_CMDS
1810};
1811
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001812/* List of motion sensor types. */
1813enum motionsensor_type {
1814 MOTIONSENSE_TYPE_ACCEL = 0,
1815 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001816 MOTIONSENSE_TYPE_MAG = 2,
1817 MOTIONSENSE_TYPE_PROX = 3,
1818 MOTIONSENSE_TYPE_LIGHT = 4,
1819 MOTIONSENSE_TYPE_ACTIVITY = 5,
1820 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001821};
1822
1823/* List of motion sensor locations. */
1824enum motionsensor_location {
1825 MOTIONSENSE_LOC_BASE = 0,
1826 MOTIONSENSE_LOC_LID = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001827 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001828};
1829
1830/* List of motion sensor chips. */
1831enum motionsensor_chip {
1832 MOTIONSENSE_CHIP_KXCJ9 = 0,
1833 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001834 MOTIONSENSE_CHIP_BMI160 = 2,
1835 MOTIONSENSE_CHIP_SI1141 = 3,
1836 MOTIONSENSE_CHIP_SI1142 = 4,
1837 MOTIONSENSE_CHIP_SI1143 = 5,
1838 MOTIONSENSE_CHIP_KX022 = 6,
1839 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07001840 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08001841};
1842
1843struct ec_response_motion_sensor_data {
1844 /* Flags for each sensor. */
1845 uint8_t flags;
1846 /* sensor number the data comes from */
1847 uint8_t sensor_num;
1848 /* Each sensor is up to 3-axis. */
1849 union {
1850 int16_t data[3];
1851 struct {
1852 uint16_t rsvd;
1853 uint32_t timestamp;
1854 } __packed;
1855 struct {
1856 uint8_t activity; /* motionsensor_activity */
1857 uint8_t state;
1858 int16_t add_info[2];
1859 };
1860 };
1861} __packed;
1862
1863struct ec_response_motion_sense_fifo_info {
1864 /* Size of the fifo */
1865 uint16_t size;
1866 /* Amount of space used in the fifo */
1867 uint16_t count;
1868 /* TImestamp recorded in us */
1869 uint32_t timestamp;
1870 /* Total amount of vector lost */
1871 uint16_t total_lost;
1872 /* Lost events since the last fifo_info, per sensors */
1873 uint16_t lost[0];
1874} __packed;
1875
1876struct ec_response_motion_sense_fifo_data {
1877 uint32_t number_data;
1878 struct ec_response_motion_sensor_data data[0];
1879} __packed;
1880
1881/* List supported activity recognition */
1882enum motionsensor_activity {
1883 MOTIONSENSE_ACTIVITY_RESERVED = 0,
1884 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
1885 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
1886};
1887
1888struct ec_motion_sense_activity {
1889 uint8_t sensor_num;
1890 uint8_t activity; /* one of enum motionsensor_activity */
1891 uint8_t enable; /* 1: enable, 0: disable */
1892 uint8_t reserved;
1893 uint16_t parameters[3]; /* activity dependent parameters */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001894};
1895
1896/* Module flag masks used for the dump sub-command. */
1897#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1898
1899/* Sensor flag masks used for the dump sub-command. */
1900#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1901
1902/*
Duncan Laurieeb316852015-12-01 18:51:18 -08001903 * Flush entry for synchronisation.
1904 * data contains time stamp
1905 */
1906#define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
1907#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
1908#define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
1909
1910/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001911 * Send this value for the data element to only perform a read. If you
1912 * send any other value, the EC will interpret it as data to set and will
1913 * return the actual value set.
1914 */
1915#define EC_MOTION_SENSE_NO_VALUE -1
1916
Duncan Laurieeb316852015-12-01 18:51:18 -08001917#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1918
1919/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
1920/* Set Calibration information */
1921#define MOTION_SENSE_SET_OFFSET 1
1922
1923#define LID_ANGLE_UNRELIABLE 500
1924
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001925struct ec_params_motion_sense {
1926 uint8_t cmd;
1927 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001928 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001929 struct {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001930 /*
1931 * Maximal number of sensor the host is expecting.
1932 * 0 means the host is only interested in the number
1933 * of sensors controlled by the EC.
1934 */
1935 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001936 } dump;
1937
1938 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08001939 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001940 */
1941 struct {
Duncan Laurieeb316852015-12-01 18:51:18 -08001942 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
1943 * kb_wake_angle: angle to wakup AP.
1944 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001945 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08001946 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001947
Duncan Laurieeb316852015-12-01 18:51:18 -08001948 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
1949 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001950 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001951 uint8_t sensor_num;
Duncan Laurieeb316852015-12-01 18:51:18 -08001952 } info, data, fifo_flush, perform_calib, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001953
1954 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08001955 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
1956 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001957 */
1958 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001959 uint8_t sensor_num;
1960
1961 /* Rounding flag, true for round-up, false for down. */
1962 uint8_t roundup;
1963
1964 uint16_t reserved;
1965
1966 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1967 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08001968 } ec_rate, sensor_odr, sensor_range;
1969
1970 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1971 struct {
1972 uint8_t sensor_num;
1973
1974 /*
1975 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1976 * the calibration information in the EC.
1977 * If unset, just retrieve calibration information.
1978 */
1979 uint16_t flags;
1980
1981 /*
1982 * Temperature at calibration, in units of 0.01 C
1983 * 0x8000: invalid / unknown.
1984 * 0x0: 0C
1985 * 0x7fff: +327.67C
1986 */
1987 int16_t temp;
1988
1989 /*
1990 * Offset for calibration.
1991 * Unit:
1992 * Accelerometer: 1/1024 g
1993 * Gyro: 1/1024 deg/s
1994 * Compass: 1/16 uT
1995 */
1996 int16_t offset[3];
1997 } __packed sensor_offset;
1998
1999 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
2000 struct {
2001 } fifo_info;
2002
2003 /* Used for MOTIONSENSE_CMD_FIFO_READ */
2004 struct {
2005 /*
2006 * Number of expected vector to return.
2007 * EC may return less or 0 if none available.
2008 */
2009 uint32_t max_data_vector;
2010 } fifo_read;
2011
2012 struct ec_motion_sense_activity set_activity;
2013
2014 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2015 struct {
2016 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002017 };
2018} __packed;
2019
2020struct ec_response_motion_sense {
2021 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002022 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002023 struct {
2024 /* Flags representing the motion sensor module. */
2025 uint8_t module_flags;
2026
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002027 /* Number of sensors managed directly by the EC */
2028 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002029
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002030 /*
2031 * sensor data is truncated if response_max is too small
2032 * for holding all the data.
2033 */
2034 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002035 } dump;
2036
2037 /* Used for MOTIONSENSE_CMD_INFO. */
2038 struct {
2039 /* Should be element of enum motionsensor_type. */
2040 uint8_t type;
2041
2042 /* Should be element of enum motionsensor_location. */
2043 uint8_t location;
2044
2045 /* Should be element of enum motionsensor_chip. */
2046 uint8_t chip;
2047 } info;
2048
Duncan Laurieeb316852015-12-01 18:51:18 -08002049 /* Used for MOTIONSENSE_CMD_DATA */
2050 struct ec_response_motion_sensor_data data;
2051
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002052 /*
2053 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
2054 * MOTIONSENSE_CMD_SENSOR_RANGE, and
2055 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2056 */
2057 struct {
2058 /* Current value of the parameter queried. */
2059 int32_t ret;
2060 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
Duncan Laurieeb316852015-12-01 18:51:18 -08002061
2062 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2063 struct {
2064 int16_t temp;
2065 int16_t offset[3];
2066 } sensor_offset, perform_calib;
2067
2068 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2069
2070 struct ec_response_motion_sense_fifo_data fifo_read;
2071
2072 struct {
2073 uint16_t reserved;
2074 uint32_t enabled;
2075 uint32_t disabled;
2076 } __packed list_activities;
2077
2078 struct {
2079 } set_activity;
2080
2081
2082 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2083 struct {
2084 /*
2085 * Angle between 0 and 360 degree if available,
2086 * LID_ANGLE_UNRELIABLE otherwise.
2087 */
2088 uint16_t value;
2089 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002090 };
2091} __packed;
2092
2093/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002094/* Force lid open command */
2095
2096/* Make lid event always open */
2097#define EC_CMD_FORCE_LID_OPEN 0x2c
2098
2099struct ec_params_force_lid_open {
2100 uint8_t enabled;
2101} __packed;
2102
2103/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002104/* USB charging control commands */
2105
2106/* Set USB port charging mode */
2107#define EC_CMD_USB_CHARGE_SET_MODE 0x30
2108
2109struct ec_params_usb_charge_set_mode {
2110 uint8_t usb_port_id;
2111 uint8_t mode;
2112} __packed;
2113
2114/*****************************************************************************/
2115/* Persistent storage for host */
2116
2117/* Maximum bytes that can be read/written in a single command */
2118#define EC_PSTORE_SIZE_MAX 64
2119
2120/* Get persistent storage info */
2121#define EC_CMD_PSTORE_INFO 0x40
2122
2123struct ec_response_pstore_info {
2124 /* Persistent storage size, in bytes */
2125 uint32_t pstore_size;
2126 /* Access size; read/write offset and size must be a multiple of this */
2127 uint32_t access_size;
2128} __packed;
2129
2130/*
2131 * Read persistent storage
2132 *
2133 * Response is params.size bytes of data.
2134 */
2135#define EC_CMD_PSTORE_READ 0x41
2136
2137struct ec_params_pstore_read {
2138 uint32_t offset; /* Byte offset to read */
2139 uint32_t size; /* Size to read in bytes */
2140} __packed;
2141
2142/* Write persistent storage */
2143#define EC_CMD_PSTORE_WRITE 0x42
2144
2145struct ec_params_pstore_write {
2146 uint32_t offset; /* Byte offset to write */
2147 uint32_t size; /* Size to write in bytes */
2148 uint8_t data[EC_PSTORE_SIZE_MAX];
2149} __packed;
2150
2151/*****************************************************************************/
2152/* Real-time clock */
2153
2154/* RTC params and response structures */
2155struct ec_params_rtc {
2156 uint32_t time;
2157} __packed;
2158
2159struct ec_response_rtc {
2160 uint32_t time;
2161} __packed;
2162
2163/* These use ec_response_rtc */
2164#define EC_CMD_RTC_GET_VALUE 0x44
2165#define EC_CMD_RTC_GET_ALARM 0x45
2166
2167/* These all use ec_params_rtc */
2168#define EC_CMD_RTC_SET_VALUE 0x46
2169#define EC_CMD_RTC_SET_ALARM 0x47
2170
2171/*****************************************************************************/
2172/* Port80 log access */
2173
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002174/* Maximum entries that can be read/written in a single command */
2175#define EC_PORT80_SIZE_MAX 32
2176
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002177/* Get last port80 code from previous boot */
2178#define EC_CMD_PORT80_LAST_BOOT 0x48
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002179#define EC_CMD_PORT80_READ 0x48
2180
2181enum ec_port80_subcmd {
2182 EC_PORT80_GET_INFO = 0,
2183 EC_PORT80_READ_BUFFER,
2184};
2185
2186struct ec_params_port80_read {
2187 uint16_t subcmd;
2188 union {
2189 struct {
2190 uint32_t offset;
2191 uint32_t num_entries;
2192 } read_buffer;
2193 };
2194} __packed;
2195
2196struct ec_response_port80_read {
2197 union {
2198 struct {
2199 uint32_t writes;
2200 uint32_t history_size;
2201 uint32_t last_boot;
2202 } get_info;
2203 struct {
2204 uint16_t codes[EC_PORT80_SIZE_MAX];
2205 } data;
2206 };
2207} __packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002208
2209struct ec_response_port80_last_boot {
2210 uint16_t code;
2211} __packed;
2212
2213/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08002214/* Temporary secure storage for host verified boot use */
2215
2216/* Number of bytes in a vstore slot */
2217#define EC_VSTORE_SLOT_SIZE 64
2218
2219/* Maximum number of vstore slots */
2220#define EC_VSTORE_SLOT_MAX 32
2221
2222/* Get persistent storage info */
2223#define EC_CMD_VSTORE_INFO 0x49
2224
2225struct ec_response_vstore_info {
2226 /* Indicates which slots are locked */
2227 uint32_t slot_locked;
2228 /* Total number of slots available */
2229 uint8_t slot_count;
2230} __packed;
2231
2232/*
2233 * Read temporary secure storage
2234 *
2235 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2236 */
2237#define EC_CMD_VSTORE_READ 0x4a
2238
2239struct ec_params_vstore_read {
2240 uint8_t slot; /* Slot to read from */
2241} __packed;
2242
2243struct ec_response_vstore_read {
2244 uint8_t data[EC_VSTORE_SLOT_SIZE];
2245} __packed;
2246
2247/*
2248 * Write temporary secure storage and lock it.
2249 */
2250#define EC_CMD_VSTORE_WRITE 0x4b
2251
2252struct ec_params_vstore_write {
2253 uint8_t slot; /* Slot to write to */
2254 uint8_t data[EC_VSTORE_SLOT_SIZE];
2255} __packed;
2256
2257/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08002258/* Thermal engine commands. Note that there are two implementations. We'll
2259 * reuse the command number, but the data and behavior is incompatible.
2260 * Version 0 is what originally shipped on Link.
2261 * Version 1 separates the CPU thermal limits from the fan control.
2262 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002263
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002264#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
Duncan Laurie93e24442014-01-06 12:30:52 -08002265#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002266
Duncan Laurie93e24442014-01-06 12:30:52 -08002267/* The version 0 structs are opaque. You have to know what they are for
2268 * the get/set commands to make any sense.
2269 */
2270
2271/* Version 0 - set */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002272struct ec_params_thermal_set_threshold {
2273 uint8_t sensor_type;
2274 uint8_t threshold_id;
2275 uint16_t value;
2276} __packed;
2277
Duncan Laurie93e24442014-01-06 12:30:52 -08002278/* Version 0 - get */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002279struct ec_params_thermal_get_threshold {
2280 uint8_t sensor_type;
2281 uint8_t threshold_id;
2282} __packed;
2283
2284struct ec_response_thermal_get_threshold {
2285 uint16_t value;
2286} __packed;
2287
Duncan Laurie93e24442014-01-06 12:30:52 -08002288
2289/* The version 1 structs are visible. */
2290enum ec_temp_thresholds {
2291 EC_TEMP_THRESH_WARN = 0,
2292 EC_TEMP_THRESH_HIGH,
2293 EC_TEMP_THRESH_HALT,
2294
2295 EC_TEMP_THRESH_COUNT
2296};
2297
2298/* Thermal configuration for one temperature sensor. Temps are in degrees K.
2299 * Zero values will be silently ignored by the thermal task.
2300 */
2301struct ec_thermal_config {
2302 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2303 uint32_t temp_fan_off; /* no active cooling needed */
2304 uint32_t temp_fan_max; /* max active cooling needed */
2305} __packed;
2306
2307/* Version 1 - get config for one sensor. */
2308struct ec_params_thermal_get_threshold_v1 {
2309 uint32_t sensor_num;
2310} __packed;
2311/* This returns a struct ec_thermal_config */
2312
2313/* Version 1 - set config for one sensor.
2314 * Use read-modify-write for best results! */
2315struct ec_params_thermal_set_threshold_v1 {
2316 uint32_t sensor_num;
2317 struct ec_thermal_config cfg;
2318} __packed;
2319/* This returns no data */
2320
2321/****************************************************************************/
2322
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002323/* Toggle automatic fan control */
2324#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
2325
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002326/* Version 1 of input params */
2327struct ec_params_auto_fan_ctrl_v1 {
2328 uint8_t fan_idx;
2329} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002330
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002331/* Get/Set TMP006 calibration data */
2332#define EC_CMD_TMP006_GET_CALIBRATION 0x53
2333#define EC_CMD_TMP006_SET_CALIBRATION 0x54
2334
2335/*
2336 * The original TMP006 calibration only needed four params, but now we need
2337 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2338 * the params opaque. The v1 "get" response will include the algorithm number
2339 * and how many params it requires. That way we can change the EC code without
2340 * needing to update this file. We can also use a different algorithm on each
2341 * sensor.
2342 */
2343
2344/* This is the same struct for both v0 and v1. */
Duncan Laurie433432b2013-06-03 10:38:22 -07002345struct ec_params_tmp006_get_calibration {
2346 uint8_t index;
2347} __packed;
2348
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002349/* Version 0 */
2350struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002351 float s0;
2352 float b0;
2353 float b1;
2354 float b2;
2355} __packed;
2356
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002357struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002358 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002359 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07002360 float s0;
2361 float b0;
2362 float b1;
2363 float b2;
2364} __packed;
2365
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002366/* Version 1 */
2367struct ec_response_tmp006_get_calibration_v1 {
2368 uint8_t algorithm;
2369 uint8_t num_params;
2370 uint8_t reserved[2];
2371 float val[0];
2372} __packed;
2373
2374struct ec_params_tmp006_set_calibration_v1 {
2375 uint8_t index;
2376 uint8_t algorithm;
2377 uint8_t num_params;
2378 uint8_t reserved;
2379 float val[0];
2380} __packed;
2381
2382
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002383/* Read raw TMP006 data */
2384#define EC_CMD_TMP006_GET_RAW 0x55
2385
2386struct ec_params_tmp006_get_raw {
2387 uint8_t index;
2388} __packed;
2389
2390struct ec_response_tmp006_get_raw {
2391 int32_t t; /* In 1/100 K */
2392 int32_t v; /* In nV */
2393};
2394
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002395/*****************************************************************************/
2396/* MKBP - Matrix KeyBoard Protocol */
2397
2398/*
2399 * Read key state
2400 *
2401 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2402 * expected response size.
2403 */
2404#define EC_CMD_MKBP_STATE 0x60
2405
2406/* Provide information about the matrix : number of rows and columns */
2407#define EC_CMD_MKBP_INFO 0x61
2408
2409struct ec_response_mkbp_info {
2410 uint32_t rows;
2411 uint32_t cols;
2412 uint8_t switches;
2413} __packed;
2414
2415/* Simulate key press */
2416#define EC_CMD_MKBP_SIMULATE_KEY 0x62
2417
2418struct ec_params_mkbp_simulate_key {
2419 uint8_t col;
2420 uint8_t row;
2421 uint8_t pressed;
2422} __packed;
2423
Duncan Laurie433432b2013-06-03 10:38:22 -07002424/* Configure keyboard scanning */
2425#define EC_CMD_MKBP_SET_CONFIG 0x64
2426#define EC_CMD_MKBP_GET_CONFIG 0x65
2427
2428/* flags */
2429enum mkbp_config_flags {
2430 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2431};
2432
2433enum mkbp_config_valid {
2434 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2435 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2436 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2437 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2438 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2439 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2440 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2441};
2442
2443/* Configuration for our key scanning algorithm */
2444struct ec_mkbp_config {
2445 uint32_t valid_mask; /* valid fields */
2446 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2447 uint8_t valid_flags; /* which flags are valid */
2448 uint16_t scan_period_us; /* period between start of scans */
2449 /* revert to interrupt mode after no activity for this long */
2450 uint32_t poll_timeout_us;
2451 /*
2452 * minimum post-scan relax time. Once we finish a scan we check
2453 * the time until we are due to start the next one. If this time is
2454 * shorter this field, we use this instead.
2455 */
2456 uint16_t min_post_scan_delay_us;
2457 /* delay between setting up output and waiting for it to settle */
2458 uint16_t output_settle_us;
2459 uint16_t debounce_down_us; /* time for debounce on key down */
2460 uint16_t debounce_up_us; /* time for debounce on key up */
2461 /* maximum depth to allow for fifo (0 = no keyscan output) */
2462 uint8_t fifo_max_depth;
2463} __packed;
2464
2465struct ec_params_mkbp_set_config {
2466 struct ec_mkbp_config config;
2467} __packed;
2468
2469struct ec_response_mkbp_get_config {
2470 struct ec_mkbp_config config;
2471} __packed;
2472
2473/* Run the key scan emulation */
2474#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
2475
2476enum ec_keyscan_seq_cmd {
2477 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2478 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2479 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2480 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2481 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2482};
2483
2484enum ec_collect_flags {
2485 /*
2486 * Indicates this scan was processed by the EC. Due to timing, some
2487 * scans may be skipped.
2488 */
2489 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2490};
2491
2492struct ec_collect_item {
2493 uint8_t flags; /* some flags (enum ec_collect_flags) */
2494};
2495
2496struct ec_params_keyscan_seq_ctrl {
2497 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2498 union {
2499 struct {
2500 uint8_t active; /* still active */
2501 uint8_t num_items; /* number of items */
2502 /* Current item being presented */
2503 uint8_t cur_item;
2504 } status;
2505 struct {
2506 /*
2507 * Absolute time for this scan, measured from the
2508 * start of the sequence.
2509 */
2510 uint32_t time_us;
2511 uint8_t scan[0]; /* keyscan data */
2512 } add;
2513 struct {
2514 uint8_t start_item; /* First item to return */
2515 uint8_t num_items; /* Number of items to return */
2516 } collect;
2517 };
2518} __packed;
2519
2520struct ec_result_keyscan_seq_ctrl {
2521 union {
2522 struct {
2523 uint8_t num_items; /* Number of items */
2524 /* Data for each item */
2525 struct ec_collect_item item[0];
2526 } collect;
2527 };
2528} __packed;
2529
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002530/*
2531 * Get the next pending MKBP event.
2532 *
2533 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2534 */
2535#define EC_CMD_GET_NEXT_EVENT 0x67
2536
2537enum ec_mkbp_event {
2538 /* Keyboard matrix changed. The event data is the new matrix state. */
2539 EC_MKBP_EVENT_KEY_MATRIX = 0,
2540
2541 /* New host event. The event data is 4 bytes of host event flags. */
2542 EC_MKBP_EVENT_HOST_EVENT = 1,
2543
Duncan Laurieeb316852015-12-01 18:51:18 -08002544 /* New Sensor FIFO data. The event data is fifo_info structure. */
2545 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2546
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002547 /* Number of MKBP events */
2548 EC_MKBP_EVENT_COUNT,
2549};
2550
Duncan Laurieeb316852015-12-01 18:51:18 -08002551union ec_response_get_next_data {
2552 uint8_t key_matrix[13];
2553
2554 /* Unaligned */
2555 uint32_t host_event;
2556
2557 struct {
2558 /* For aligning the fifo_info */
2559 uint8_t rsvd[3];
2560 struct ec_response_motion_sense_fifo_info info;
2561 } sensor_fifo;
2562} __packed;
2563
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002564struct ec_response_get_next_event {
2565 uint8_t event_type;
2566 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08002567 union ec_response_get_next_data data;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002568} __packed;
2569
Gwendal Grignou880b4582016-06-20 08:49:25 -07002570/* Run keyboard factory test scanning */
2571#define EC_CMD_KEYBOARD_FACTORY_TEST 0x68
2572
2573struct ec_response_keyboard_factory_test {
2574 uint16_t shorted; /* Keyboard pins are shorted */
2575} __packed;
2576
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002577/*****************************************************************************/
2578/* Temperature sensor commands */
2579
2580/* Read temperature sensor info */
2581#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2582
2583struct ec_params_temp_sensor_get_info {
2584 uint8_t id;
2585} __packed;
2586
2587struct ec_response_temp_sensor_get_info {
2588 char sensor_name[32];
2589 uint8_t sensor_type;
2590} __packed;
2591
2592/*****************************************************************************/
2593
2594/*
2595 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2596 * commands accidentally sent to the wrong interface. See the ACPI section
2597 * below.
2598 */
2599
2600/*****************************************************************************/
2601/* Host event commands */
2602
2603/*
2604 * Host event mask params and response structures, shared by all of the host
2605 * event commands below.
2606 */
2607struct ec_params_host_event_mask {
2608 uint32_t mask;
2609} __packed;
2610
2611struct ec_response_host_event_mask {
2612 uint32_t mask;
2613} __packed;
2614
2615/* These all use ec_response_host_event_mask */
2616#define EC_CMD_HOST_EVENT_GET_B 0x87
2617#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2618#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2619#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2620
2621/* These all use ec_params_host_event_mask */
2622#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2623#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2624#define EC_CMD_HOST_EVENT_CLEAR 0x8c
2625#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2626#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2627
2628/*****************************************************************************/
2629/* Switch commands */
2630
2631/* Enable/disable LCD backlight */
2632#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2633
2634struct ec_params_switch_enable_backlight {
2635 uint8_t enabled;
2636} __packed;
2637
2638/* Enable/disable WLAN/Bluetooth */
2639#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002640#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002641
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002642/* Version 0 params; no response */
2643struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002644 uint8_t enabled;
2645} __packed;
2646
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002647/* Version 1 params */
2648struct ec_params_switch_enable_wireless_v1 {
2649 /* Flags to enable now */
2650 uint8_t now_flags;
2651
2652 /* Which flags to copy from now_flags */
2653 uint8_t now_mask;
2654
2655 /*
2656 * Flags to leave enabled in S3, if they're on at the S0->S3
2657 * transition. (Other flags will be disabled by the S0->S3
2658 * transition.)
2659 */
2660 uint8_t suspend_flags;
2661
2662 /* Which flags to copy from suspend_flags */
2663 uint8_t suspend_mask;
2664} __packed;
2665
2666/* Version 1 response */
2667struct ec_response_switch_enable_wireless_v1 {
2668 /* Flags to enable now */
2669 uint8_t now_flags;
2670
2671 /* Flags to leave enabled in S3 */
2672 uint8_t suspend_flags;
2673} __packed;
2674
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002675/*****************************************************************************/
2676/* GPIO commands. Only available on EC if write protect has been disabled. */
2677
2678/* Set GPIO output value */
2679#define EC_CMD_GPIO_SET 0x92
2680
2681struct ec_params_gpio_set {
2682 char name[32];
2683 uint8_t val;
2684} __packed;
2685
2686/* Get GPIO value */
2687#define EC_CMD_GPIO_GET 0x93
2688
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002689/* Version 0 of input params and response */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002690struct ec_params_gpio_get {
2691 char name[32];
2692} __packed;
2693struct ec_response_gpio_get {
2694 uint8_t val;
2695} __packed;
2696
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002697/* Version 1 of input params and response */
2698struct ec_params_gpio_get_v1 {
2699 uint8_t subcmd;
2700 union {
2701 struct {
2702 char name[32];
2703 } get_value_by_name;
2704 struct {
2705 uint8_t index;
2706 } get_info;
2707 };
2708} __packed;
2709
2710struct ec_response_gpio_get_v1 {
2711 union {
2712 struct {
2713 uint8_t val;
2714 } get_value_by_name, get_count;
2715 struct {
2716 uint8_t val;
2717 char name[32];
2718 uint32_t flags;
2719 } get_info;
2720 };
2721} __packed;
2722
2723enum gpio_get_subcmd {
2724 EC_GPIO_GET_BY_NAME = 0,
2725 EC_GPIO_GET_COUNT = 1,
2726 EC_GPIO_GET_INFO = 2,
2727};
2728
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002729/*****************************************************************************/
2730/* I2C commands. Only available when flash write protect is unlocked. */
2731
Duncan Laurie93e24442014-01-06 12:30:52 -08002732/*
2733 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
Duncan Laurieeb316852015-12-01 18:51:18 -08002734 * removed soon. Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08002735 */
2736
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002737/* Read I2C bus */
2738#define EC_CMD_I2C_READ 0x94
2739
2740struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07002741 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002742 uint8_t read_size; /* Either 8 or 16. */
2743 uint8_t port;
2744 uint8_t offset;
2745} __packed;
2746struct ec_response_i2c_read {
2747 uint16_t data;
2748} __packed;
2749
2750/* Write I2C bus */
2751#define EC_CMD_I2C_WRITE 0x95
2752
2753struct ec_params_i2c_write {
2754 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07002755 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002756 uint8_t write_size; /* Either 8 or 16. */
2757 uint8_t port;
2758 uint8_t offset;
2759} __packed;
2760
2761/*****************************************************************************/
2762/* Charge state commands. Only available when flash write protect unlocked. */
2763
Duncan Laurie93e24442014-01-06 12:30:52 -08002764/* Force charge state machine to stop charging the battery or force it to
2765 * discharge the battery.
2766 */
2767#define EC_CMD_CHARGE_CONTROL 0x96
2768#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002769
Duncan Laurie93e24442014-01-06 12:30:52 -08002770enum ec_charge_control_mode {
2771 CHARGE_CONTROL_NORMAL = 0,
2772 CHARGE_CONTROL_IDLE,
2773 CHARGE_CONTROL_DISCHARGE,
2774};
2775
2776struct ec_params_charge_control {
2777 uint32_t mode; /* enum charge_control_mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002778} __packed;
2779
2780/*****************************************************************************/
2781/* Console commands. Only available when flash write protect is unlocked. */
2782
2783/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2784#define EC_CMD_CONSOLE_SNAPSHOT 0x97
2785
2786/*
Duncan Laurieeb316852015-12-01 18:51:18 -08002787 * Read data from the saved snapshot. If the subcmd parameter is
2788 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2789 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2790 * end of the previous snapshot.
2791 *
2792 * The params are only looked at in version >= 1 of this command. Prior
2793 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002794 *
2795 * Response is null-terminated string. Empty string, if there is no more
2796 * remaining output.
2797 */
2798#define EC_CMD_CONSOLE_READ 0x98
2799
Duncan Laurieeb316852015-12-01 18:51:18 -08002800enum ec_console_read_subcmd {
2801 CONSOLE_READ_NEXT = 0,
2802 CONSOLE_READ_RECENT
2803};
2804
2805struct ec_params_console_read_v1 {
2806 uint8_t subcmd; /* enum ec_console_read_subcmd */
2807} __packed;
2808
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002809/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07002810
2811/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002812 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07002813 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002814 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2815 * EC_RES_SUCCESS if the command was successful.
2816 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07002817 */
2818#define EC_CMD_BATTERY_CUT_OFF 0x99
2819
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002820#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2821
2822struct ec_params_battery_cutoff {
2823 uint8_t flags;
2824} __packed;
2825
Duncan Laurie433432b2013-06-03 10:38:22 -07002826/*****************************************************************************/
2827/* USB port mux control. */
2828
2829/*
2830 * Switch USB mux or return to automatic switching.
2831 */
2832#define EC_CMD_USB_MUX 0x9a
2833
2834struct ec_params_usb_mux {
2835 uint8_t mux;
2836} __packed;
2837
2838/*****************************************************************************/
2839/* LDOs / FETs control. */
2840
2841enum ec_ldo_state {
2842 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2843 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2844};
2845
2846/*
2847 * Switch on/off a LDO.
2848 */
2849#define EC_CMD_LDO_SET 0x9b
2850
2851struct ec_params_ldo_set {
2852 uint8_t index;
2853 uint8_t state;
2854} __packed;
2855
2856/*
2857 * Get LDO state.
2858 */
2859#define EC_CMD_LDO_GET 0x9c
2860
2861struct ec_params_ldo_get {
2862 uint8_t index;
2863} __packed;
2864
2865struct ec_response_ldo_get {
2866 uint8_t state;
2867} __packed;
2868
2869/*****************************************************************************/
2870/* Power info. */
2871
2872/*
2873 * Get power info.
2874 */
2875#define EC_CMD_POWER_INFO 0x9d
2876
2877struct ec_response_power_info {
2878 uint32_t usb_dev_type;
2879 uint16_t voltage_ac;
2880 uint16_t voltage_system;
2881 uint16_t current_system;
2882 uint16_t usb_current_limit;
2883} __packed;
2884
2885/*****************************************************************************/
2886/* I2C passthru command */
2887
2888#define EC_CMD_I2C_PASSTHRU 0x9e
2889
Duncan Laurie433432b2013-06-03 10:38:22 -07002890/* Read data; if not present, message is a write */
2891#define EC_I2C_FLAG_READ (1 << 15)
2892
2893/* Mask for address */
2894#define EC_I2C_ADDR_MASK 0x3ff
2895
2896#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2897#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2898
2899/* Any error */
2900#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2901
2902struct ec_params_i2c_passthru_msg {
2903 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2904 uint16_t len; /* Number of bytes to read or write */
2905} __packed;
2906
2907struct ec_params_i2c_passthru {
2908 uint8_t port; /* I2C port number */
2909 uint8_t num_msgs; /* Number of messages */
2910 struct ec_params_i2c_passthru_msg msg[];
2911 /* Data to write for all messages is concatenated here */
2912} __packed;
2913
2914struct ec_response_i2c_passthru {
2915 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2916 uint8_t num_msgs; /* Number of messages processed */
2917 uint8_t data[]; /* Data read by messages concatenated here */
2918} __packed;
2919
Duncan Lauriee6b280e2014-02-10 16:21:05 -08002920/*****************************************************************************/
2921/* Power button hang detect */
2922
2923#define EC_CMD_HANG_DETECT 0x9f
2924
2925/* Reasons to start hang detection timer */
2926/* Power button pressed */
2927#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2928
2929/* Lid closed */
2930#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2931
2932 /* Lid opened */
2933#define EC_HANG_START_ON_LID_OPEN (1 << 2)
2934
2935/* Start of AP S3->S0 transition (booting or resuming from suspend) */
2936#define EC_HANG_START_ON_RESUME (1 << 3)
2937
2938/* Reasons to cancel hang detection */
2939
2940/* Power button released */
2941#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2942
2943/* Any host command from AP received */
2944#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2945
2946/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2947#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2948
2949/*
2950 * If this flag is set, all the other fields are ignored, and the hang detect
2951 * timer is started. This provides the AP a way to start the hang timer
2952 * without reconfiguring any of the other hang detect settings. Note that
2953 * you must previously have configured the timeouts.
2954 */
2955#define EC_HANG_START_NOW (1 << 30)
2956
2957/*
2958 * If this flag is set, all the other fields are ignored (including
2959 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2960 * without reconfiguring any of the other hang detect settings.
2961 */
2962#define EC_HANG_STOP_NOW (1 << 31)
2963
2964struct ec_params_hang_detect {
2965 /* Flags; see EC_HANG_* */
2966 uint32_t flags;
2967
2968 /* Timeout in msec before generating host event, if enabled */
2969 uint16_t host_event_timeout_msec;
2970
2971 /* Timeout in msec before generating warm reboot, if enabled */
2972 uint16_t warm_reboot_timeout_msec;
2973} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002974
2975/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002976/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07002977
2978/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002979 * This is the single catch-all host command to exchange data regarding the
2980 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07002981 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002982#define EC_CMD_CHARGE_STATE 0xa0
2983
2984/* Subcommands for this host command */
2985enum charge_state_command {
2986 CHARGE_STATE_CMD_GET_STATE,
2987 CHARGE_STATE_CMD_GET_PARAM,
2988 CHARGE_STATE_CMD_SET_PARAM,
2989 CHARGE_STATE_NUM_CMDS
2990};
2991
2992/*
2993 * Known param numbers are defined here. Ranges are reserved for board-specific
2994 * params, which are handled by the particular implementations.
2995 */
2996enum charge_state_params {
2997 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2998 CS_PARAM_CHG_CURRENT, /* charger current limit */
2999 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3000 CS_PARAM_CHG_STATUS, /* charger-specific status */
3001 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08003002 CS_PARAM_LIMIT_POWER, /*
3003 * Check if power is limited due to
3004 * low battery and / or a weak external
3005 * charger. READ ONLY.
3006 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003007 /* How many so far? */
3008 CS_NUM_BASE_PARAMS,
3009
3010 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3011 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3012 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3013
3014 /* Other custom param ranges go here... */
3015};
3016
3017struct ec_params_charge_state {
3018 uint8_t cmd; /* enum charge_state_command */
3019 union {
3020 struct {
3021 /* no args */
3022 } get_state;
3023
3024 struct {
3025 uint32_t param; /* enum charge_state_param */
3026 } get_param;
3027
3028 struct {
3029 uint32_t param; /* param to set */
3030 uint32_t value; /* value to set */
3031 } set_param;
3032 };
3033} __packed;
3034
3035struct ec_response_charge_state {
3036 union {
3037 struct {
3038 int ac;
3039 int chg_voltage;
3040 int chg_current;
3041 int chg_input_current;
3042 int batt_state_of_charge;
3043 } get_state;
3044
3045 struct {
3046 uint32_t value;
3047 } get_param;
3048 struct {
3049 /* no return values */
3050 } set_param;
3051 };
3052} __packed;
3053
Duncan Laurie433432b2013-06-03 10:38:22 -07003054
3055/*
3056 * Set maximum battery charging current.
3057 */
3058#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
3059
3060struct ec_params_current_limit {
3061 uint32_t limit; /* in mA */
3062} __packed;
3063
3064/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003065 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07003066 */
Duncan Laurieeb316852015-12-01 18:51:18 -08003067#define EC_CMD_EXTERNAL_POWER_LIMIT 0xa2
Duncan Laurie433432b2013-06-03 10:38:22 -07003068
Duncan Laurieeb316852015-12-01 18:51:18 -08003069/* Command v0 is used only on Spring and is obsolete + unsupported */
3070struct ec_params_external_power_limit_v1 {
3071 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3072 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
Duncan Laurie433432b2013-06-03 10:38:22 -07003073} __packed;
3074
Duncan Laurieeb316852015-12-01 18:51:18 -08003075#define EC_POWER_LIMIT_NONE 0xffff
3076
3077/*****************************************************************************/
3078/* Hibernate/Deep Sleep Commands */
3079
3080/* Set the delay before going into hibernation. */
3081#define EC_CMD_HIBERNATION_DELAY 0xa8
3082
3083struct ec_params_hibernation_delay {
3084 /*
3085 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3086 * current settings without changing them.
3087 */
3088 uint32_t seconds;
3089};
3090
3091struct ec_response_hibernation_delay {
3092 /*
3093 * The current time in seconds in which the system has been in the G3
3094 * state. This value is reset if the EC transitions out of G3.
3095 */
3096 uint32_t time_g3;
3097
3098 /*
3099 * The current time remaining in seconds until the EC should hibernate.
3100 * This value is also reset if the EC transitions out of G3.
3101 */
3102 uint32_t time_remaining;
3103
3104 /*
3105 * The current time in seconds that the EC should wait in G3 before
3106 * hibernating.
3107 */
3108 uint32_t hibernate_delay;
3109};
3110
3111
Duncan Laurie433432b2013-06-03 10:38:22 -07003112/*****************************************************************************/
3113/* Smart battery pass-through */
3114
3115/* Get / Set 16-bit smart battery registers */
3116#define EC_CMD_SB_READ_WORD 0xb0
3117#define EC_CMD_SB_WRITE_WORD 0xb1
3118
3119/* Get / Set string smart battery parameters
3120 * formatted as SMBUS "block".
3121 */
3122#define EC_CMD_SB_READ_BLOCK 0xb2
3123#define EC_CMD_SB_WRITE_BLOCK 0xb3
3124
3125struct ec_params_sb_rd {
3126 uint8_t reg;
3127} __packed;
3128
3129struct ec_response_sb_rd_word {
3130 uint16_t value;
3131} __packed;
3132
3133struct ec_params_sb_wr_word {
3134 uint8_t reg;
3135 uint16_t value;
3136} __packed;
3137
3138struct ec_response_sb_rd_block {
3139 uint8_t data[32];
3140} __packed;
3141
3142struct ec_params_sb_wr_block {
3143 uint8_t reg;
3144 uint16_t data[32];
3145} __packed;
3146
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003147
3148/*****************************************************************************/
3149/* Battery vendor parameters
3150 *
3151 * Get or set vendor-specific parameters in the battery. Implementations may
3152 * differ between boards or batteries. On a set operation, the response
3153 * contains the actual value set, which may be rounded or clipped from the
3154 * requested value.
3155 */
3156
3157#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
3158
3159enum ec_battery_vendor_param_mode {
3160 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3161 BATTERY_VENDOR_PARAM_MODE_SET,
3162};
3163
3164struct ec_params_battery_vendor_param {
3165 uint32_t param;
3166 uint32_t value;
3167 uint8_t mode;
3168} __packed;
3169
3170struct ec_response_battery_vendor_param {
3171 uint32_t value;
3172} __packed;
3173
3174/*****************************************************************************/
3175/*
3176 * Smart Battery Firmware Update Commands
3177 */
3178#define EC_CMD_SB_FW_UPDATE 0xb5
3179
3180enum ec_sb_fw_update_subcmd {
3181 EC_SB_FW_UPDATE_PREPARE = 0x0,
3182 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3183 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3184 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3185 EC_SB_FW_UPDATE_END = 0x4,
3186 EC_SB_FW_UPDATE_STATUS = 0x5,
3187 EC_SB_FW_UPDATE_PROTECT = 0x6,
3188 EC_SB_FW_UPDATE_MAX = 0x7,
3189};
3190
3191#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3192#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3193#define SB_FW_UPDATE_CMD_INFO_SIZE 8
3194
3195struct ec_sb_fw_update_header {
3196 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3197 uint16_t fw_id; /* firmware id */
3198} __packed;
3199
3200struct ec_params_sb_fw_update {
3201 struct ec_sb_fw_update_header hdr;
3202 union {
3203 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3204 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3205 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3206 /* EC_SB_FW_UPDATE_END = 0x4 */
3207 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3208 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
3209 struct {
3210 /* no args */
3211 } dummy;
3212
3213 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
3214 struct {
3215 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3216 } write;
3217 };
3218} __packed;
3219
3220struct ec_response_sb_fw_update {
3221 union {
3222 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3223 struct {
3224 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3225 } info;
3226
3227 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3228 struct {
3229 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3230 } status;
3231 };
3232} __packed;
3233
3234/*
3235 * Entering Verified Boot Mode Command
3236 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3237 * Valid Modes are: normal, developer, and recovery.
3238 */
3239#define EC_CMD_ENTERING_MODE 0xb6
3240
3241struct ec_params_entering_mode {
3242 int vboot_mode;
3243} __packed;
3244
3245#define VBOOT_MODE_NORMAL 0
3246#define VBOOT_MODE_DEVELOPER 1
3247#define VBOOT_MODE_RECOVERY 2
3248
Duncan Laurie433432b2013-06-03 10:38:22 -07003249/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07003250/*
3251 * I2C passthru protection command: Protects I2C tunnels against access on
3252 * certain addresses (board-specific).
3253 */
3254#define EC_CMD_I2C_PASSTHRU_PROTECT 0xb7
3255
3256enum ec_i2c_passthru_protect_subcmd {
3257 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3258 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3259};
3260
3261struct ec_params_i2c_passthru_protect {
3262 uint8_t subcmd;
3263 uint8_t port; /* I2C port number */
3264} __packed;
3265
3266struct ec_response_i2c_passthru_protect {
3267 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
3268} __packed;
3269
3270/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003271/* System commands */
3272
3273/*
Duncan Laurie93e24442014-01-06 12:30:52 -08003274 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3275 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003276 */
3277#define EC_CMD_REBOOT_EC 0xd2
3278
3279/* Command */
3280enum ec_reboot_cmd {
3281 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003282 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3283 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003284 /* (command 3 was jump to RW-B) */
3285 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003286 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3287 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003288};
3289
3290/* Flags for ec_params_reboot_ec.reboot_flags */
3291#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
Duncan Laurie433432b2013-06-03 10:38:22 -07003292#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003293
3294struct ec_params_reboot_ec {
3295 uint8_t cmd; /* enum ec_reboot_cmd */
3296 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3297} __packed;
3298
Duncan Laurie433432b2013-06-03 10:38:22 -07003299/*
3300 * Get information on last EC panic.
3301 *
3302 * Returns variable-length platform-dependent panic information. See panic.h
3303 * for details.
3304 */
3305#define EC_CMD_GET_PANIC_INFO 0xd3
3306
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003307/*****************************************************************************/
3308/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003309 * Special commands
3310 *
3311 * These do not follow the normal rules for commands. See each command for
3312 * details.
3313 */
3314
3315/*
3316 * Reboot NOW
3317 *
3318 * This command will work even when the EC LPC interface is busy, because the
3319 * reboot command is processed at interrupt level. Note that when the EC
3320 * reboots, the host will reboot too, so there is no response to this command.
3321 *
3322 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3323 */
3324#define EC_CMD_REBOOT 0xd1 /* Think "die" */
3325
3326/*
Duncan Laurie433432b2013-06-03 10:38:22 -07003327 * Resend last response (not supported on LPC).
3328 *
3329 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3330 * there was no previous command, or the previous command's response was too
3331 * big to save.
3332 */
3333#define EC_CMD_RESEND_RESPONSE 0xdb
3334
3335/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003336 * This header byte on a command indicate version 0. Any header byte less
3337 * than this means that we are talking to an old EC which doesn't support
3338 * versioning. In that case, we assume version 0.
3339 *
3340 * Header bytes greater than this indicate a later version. For example,
3341 * EC_CMD_VERSION0 + 1 means we are using version 1.
3342 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003343 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003344 */
3345#define EC_CMD_VERSION0 0xdc
3346
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003347/*****************************************************************************/
3348/*
3349 * PD commands
3350 *
3351 * These commands are for PD MCU communication.
3352 */
3353
3354/* EC to PD MCU exchange status command */
3355#define EC_CMD_PD_EXCHANGE_STATUS 0x100
Duncan Laurieeb316852015-12-01 18:51:18 -08003356#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003357
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003358enum pd_charge_state {
3359 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3360 PD_CHARGE_NONE, /* No charging allowed */
3361 PD_CHARGE_5V, /* 5V charging only */
3362 PD_CHARGE_MAX /* Charge at max voltage */
3363};
3364
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003365/* Status of EC being sent to PD */
Duncan Laurieeb316852015-12-01 18:51:18 -08003366#define EC_STATUS_HIBERNATING (1 << 0)
3367
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003368struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003369 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003370 int8_t batt_soc; /* battery state of charge */
3371 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003372} __packed;
3373
3374/* Status of PD being sent back to EC */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003375#define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3376#define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3377#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
Duncan Laurieeb316852015-12-01 18:51:18 -08003378#define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
3379#define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
3380#define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
3381#define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
3382#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
3383 PD_STATUS_TCPC_ALERT_1 | \
3384 PD_STATUS_HOST_EVENT)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003385struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003386 uint32_t curr_lim_ma; /* input current limit */
3387 uint16_t status; /* PD MCU status */
3388 int8_t active_charge_port; /* active charging port */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003389} __packed;
3390
3391/* AP to PD MCU host event status command, cleared on read */
3392#define EC_CMD_PD_HOST_EVENT_STATUS 0x104
3393
3394/* PD MCU host event status bits */
3395#define PD_EVENT_UPDATE_DEVICE (1 << 0)
3396#define PD_EVENT_POWER_CHANGE (1 << 1)
3397#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
Duncan Laurieeb316852015-12-01 18:51:18 -08003398#define PD_EVENT_DATA_SWAP (1 << 3)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003399struct ec_response_host_event_status {
3400 uint32_t status; /* PD MCU host event status */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003401} __packed;
3402
3403/* Set USB type-C port role and muxes */
3404#define EC_CMD_USB_PD_CONTROL 0x101
3405
3406enum usb_pd_control_role {
3407 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3408 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3409 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3410 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3411 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3412 USB_PD_CTRL_ROLE_COUNT
3413};
3414
3415enum usb_pd_control_mux {
3416 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3417 USB_PD_CTRL_MUX_NONE = 1,
3418 USB_PD_CTRL_MUX_USB = 2,
3419 USB_PD_CTRL_MUX_DP = 3,
3420 USB_PD_CTRL_MUX_DOCK = 4,
3421 USB_PD_CTRL_MUX_AUTO = 5,
3422 USB_PD_CTRL_MUX_COUNT
3423};
3424
Duncan Laurieeb316852015-12-01 18:51:18 -08003425enum usb_pd_control_swap {
3426 USB_PD_CTRL_SWAP_NONE = 0,
3427 USB_PD_CTRL_SWAP_DATA = 1,
3428 USB_PD_CTRL_SWAP_POWER = 2,
3429 USB_PD_CTRL_SWAP_VCONN = 3,
3430 USB_PD_CTRL_SWAP_COUNT
3431};
3432
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003433struct ec_params_usb_pd_control {
3434 uint8_t port;
3435 uint8_t role;
3436 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08003437 uint8_t swap;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003438} __packed;
3439
Duncan Laurieeb316852015-12-01 18:51:18 -08003440#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3441#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3442#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3443
3444#define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
3445#define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
3446#define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
3447#define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
3448#define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
3449#define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
3450#define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
3451
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003452struct ec_response_usb_pd_control {
3453 uint8_t enabled;
3454 uint8_t role;
3455 uint8_t polarity;
3456 uint8_t state;
3457} __packed;
3458
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003459struct ec_response_usb_pd_control_v1 {
3460 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08003461 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003462 uint8_t polarity;
3463 char state[32];
3464} __packed;
3465
3466#define EC_CMD_USB_PD_PORTS 0x102
3467
3468struct ec_response_usb_pd_ports {
3469 uint8_t num_ports;
3470} __packed;
3471
3472#define EC_CMD_USB_PD_POWER_INFO 0x103
3473
3474#define PD_POWER_CHARGING_PORT 0xff
3475struct ec_params_usb_pd_power_info {
3476 uint8_t port;
3477} __packed;
3478
3479enum usb_chg_type {
3480 USB_CHG_TYPE_NONE,
3481 USB_CHG_TYPE_PD,
3482 USB_CHG_TYPE_C,
3483 USB_CHG_TYPE_PROPRIETARY,
3484 USB_CHG_TYPE_BC12_DCP,
3485 USB_CHG_TYPE_BC12_CDP,
3486 USB_CHG_TYPE_BC12_SDP,
3487 USB_CHG_TYPE_OTHER,
3488 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08003489 USB_CHG_TYPE_UNKNOWN,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003490};
3491enum usb_power_roles {
3492 USB_PD_PORT_POWER_DISCONNECTED,
3493 USB_PD_PORT_POWER_SOURCE,
3494 USB_PD_PORT_POWER_SINK,
3495 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3496};
3497
3498struct usb_chg_measures {
3499 uint16_t voltage_max;
3500 uint16_t voltage_now;
3501 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08003502 uint16_t current_lim;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003503} __packed;
3504
3505struct ec_response_usb_pd_power_info {
3506 uint8_t role;
3507 uint8_t type;
3508 uint8_t dualrole;
3509 uint8_t reserved1;
3510 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003511 uint32_t max_power;
3512} __packed;
3513
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003514/* Write USB-PD device FW */
3515#define EC_CMD_USB_PD_FW_UPDATE 0x110
3516
3517enum usb_pd_fw_update_cmds {
3518 USB_PD_FW_REBOOT,
3519 USB_PD_FW_FLASH_ERASE,
3520 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003521 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003522};
3523
3524struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003525 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003526 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003527 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003528 uint32_t size; /* Size to write in bytes */
3529 /* Followed by data to write */
3530} __packed;
3531
3532/* Write USB-PD Accessory RW_HASH table entry */
3533#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003534/* RW hash is first 20 bytes of SHA-256 of RW section */
3535#define PD_RW_HASH_SIZE 20
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003536struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003537 uint16_t dev_id;
3538 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
3539 uint8_t reserved; /* For alignment of current_image */
3540 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003541} __packed;
3542
3543/* Read USB-PD Accessory info */
3544#define EC_CMD_USB_PD_DEV_INFO 0x112
3545
3546struct ec_params_usb_pd_info_request {
3547 uint8_t port;
3548} __packed;
3549
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003550/* Read USB-PD Device discovery info */
3551#define EC_CMD_USB_PD_DISCOVERY 0x113
3552struct ec_params_usb_pd_discovery_entry {
3553 uint16_t vid; /* USB-IF VID */
3554 uint16_t pid; /* USB-IF PID */
3555 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3556} __packed;
3557
3558/* Override default charge behavior */
3559#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x114
3560
3561/* Negative port parameters have special meaning */
3562enum usb_pd_override_ports {
3563 OVERRIDE_DONT_CHARGE = -2,
3564 OVERRIDE_OFF = -1,
Duncan Laurieeb316852015-12-01 18:51:18 -08003565 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003566};
3567
3568struct ec_params_charge_port_override {
3569 int16_t override_port; /* Override port# */
3570} __packed;
3571
3572/* Read (and delete) one entry of PD event log */
3573#define EC_CMD_PD_GET_LOG_ENTRY 0x115
3574
3575struct ec_response_pd_log {
3576 uint32_t timestamp; /* relative timestamp in milliseconds */
3577 uint8_t type; /* event type : see PD_EVENT_xx below */
3578 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3579 uint16_t data; /* type-defined data payload */
3580 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3581} __packed;
3582
3583
3584/* The timestamp is the microsecond counter shifted to get about a ms. */
3585#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
3586
Duncan Laurieeb316852015-12-01 18:51:18 -08003587#define PD_LOG_SIZE_MASK 0x1f
3588#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003589#define PD_LOG_PORT_SHIFT 5
3590#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
3591 ((size) & PD_LOG_SIZE_MASK))
3592#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
3593#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
3594
3595/* PD event log : entry types */
3596/* PD MCU events */
3597#define PD_EVENT_MCU_BASE 0x00
3598#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
3599#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
3600/* Reserved for custom board event */
3601#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
3602/* PD generic accessory events */
3603#define PD_EVENT_ACC_BASE 0x20
3604#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
3605#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
3606/* PD power supply events */
3607#define PD_EVENT_PS_BASE 0x40
3608#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
3609/* PD video dongles events */
3610#define PD_EVENT_VIDEO_BASE 0x60
3611#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
3612#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
3613/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08003614#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003615
3616/*
3617 * PD_EVENT_MCU_CHARGE event definition :
3618 * the payload is "struct usb_chg_measures"
3619 * the data field contains the port state flags as defined below :
3620 */
3621/* Port partner is a dual role device */
3622#define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
3623/* Port is the pending override port */
3624#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
3625/* Port is the override port */
3626#define CHARGE_FLAGS_OVERRIDE (1 << 13)
3627/* Charger type */
3628#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08003629#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003630/* Power delivery role */
3631#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
3632
3633/*
3634 * PD_EVENT_PS_FAULT data field flags definition :
3635 */
3636#define PS_FAULT_OCP 1
3637#define PS_FAULT_FAST_OCP 2
3638#define PS_FAULT_OVP 3
3639#define PS_FAULT_DISCH 4
3640
3641/*
3642 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
3643 */
3644struct mcdp_version {
3645 uint8_t major;
3646 uint8_t minor;
3647 uint16_t build;
3648} __packed;
3649
3650struct mcdp_info {
3651 uint8_t family[2];
3652 uint8_t chipid[2];
3653 struct mcdp_version irom;
3654 struct mcdp_version fw;
3655} __packed;
3656
3657/* struct mcdp_info field decoding */
3658#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3659#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3660
3661/* Get/Set USB-PD Alternate mode info */
3662#define EC_CMD_USB_PD_GET_AMODE 0x116
3663struct ec_params_usb_pd_get_mode_request {
3664 uint16_t svid_idx; /* SVID index to get */
3665 uint8_t port; /* port */
3666} __packed;
3667
3668struct ec_params_usb_pd_get_mode_response {
3669 uint16_t svid; /* SVID */
3670 uint16_t opos; /* Object Position */
3671 uint32_t vdo[6]; /* Mode VDOs */
3672} __packed;
3673
3674#define EC_CMD_USB_PD_SET_AMODE 0x117
3675
3676enum pd_mode_cmd {
3677 PD_EXIT_MODE = 0,
3678 PD_ENTER_MODE = 1,
3679 /* Not a command. Do NOT remove. */
3680 PD_MODE_CMD_COUNT,
3681};
3682
3683struct ec_params_usb_pd_set_mode_request {
3684 uint32_t cmd; /* enum pd_mode_cmd */
3685 uint16_t svid; /* SVID to set */
3686 uint8_t opos; /* Object Position */
3687 uint8_t port; /* port */
3688} __packed;
3689
3690/* Ask the PD MCU to record a log of a requested type */
3691#define EC_CMD_PD_WRITE_LOG_ENTRY 0x118
3692
3693struct ec_params_pd_write_log_entry {
3694 uint8_t type; /* event type : see PD_EVENT_xx above */
3695 uint8_t port; /* port#, or 0 for events unrelated to a given port */
3696} __packed;
3697
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003698
Gwendal Grignou880b4582016-06-20 08:49:25 -07003699/* Control USB-PD chip */
3700#define EC_CMD_PD_CONTROL 0x119
3701
3702enum ec_pd_control_cmd {
3703 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
3704 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
3705 PD_RESET, /* Force reset the PD chip */
3706 PD_CONTROL_DISABLE /* Disable further calls to this command */
3707};
3708
3709struct ec_params_pd_control {
3710 uint8_t chip; /* chip id (should be 0) */
3711 uint8_t subcmd;
3712} __packed;
3713
3714#endif /* !__ACPI__ */
Duncan Laurieeb316852015-12-01 18:51:18 -08003715
3716/*****************************************************************************/
3717/*
3718 * Blob commands are just opaque chunks of data, sent with proto v3.
3719 * params is struct ec_host_request, response is struct ec_host_response.
3720 */
3721#define EC_CMD_BLOB 0x200
3722
3723/*****************************************************************************/
3724/*
3725 * Reserve a range of host commands for board-specific, experimental, or
3726 * special purpose features. These can be (re)used without updating this file.
3727 *
3728 * CAUTION: Don't go nuts with this. Shipping products should document ALL
3729 * their EC commands for easier development, testing, debugging, and support.
3730 *
3731 * In your experimental code, you may want to do something like this:
3732 *
3733 * #define EC_CMD_MAGIC_FOO (EC_CMD_BOARD_SPECIFIC_BASE + 0x000)
3734 * #define EC_CMD_MAGIC_BAR (EC_CMD_BOARD_SPECIFIC_BASE + 0x001)
3735 * #define EC_CMD_MAGIC_HEY (EC_CMD_BOARD_SPECIFIC_BASE + 0x002)
3736 */
3737#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
3738#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
3739
Duncan Laurie93e24442014-01-06 12:30:52 -08003740/*****************************************************************************/
3741/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003742 * Passthru commands
3743 *
3744 * Some platforms have sub-processors chained to each other. For example.
3745 *
3746 * AP <--> EC <--> PD MCU
3747 *
3748 * The top 2 bits of the command number are used to indicate which device the
3749 * command is intended for. Device 0 is always the device receiving the
3750 * command; other device mapping is board-specific.
3751 *
3752 * When a device receives a command to be passed to a sub-processor, it passes
3753 * it on with the device number set back to 0. This allows the sub-processor
3754 * to remain blissfully unaware of whether the command originated on the next
3755 * device up the chain, or was passed through from the AP.
3756 *
3757 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3758 * AP sends command 0x4002 to the EC
3759 * EC sends command 0x0002 to the PD MCU
3760 * EC forwards PD MCU response back to the AP
3761 */
3762
3763/* Offset and max command number for sub-device n */
3764#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3765#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3766
3767/*****************************************************************************/
3768/*
Duncan Laurie93e24442014-01-06 12:30:52 -08003769 * Deprecated constants. These constants have been renamed for clarity. The
3770 * meaning and size has not changed. Programs that use the old names should
3771 * switch to the new names soon, as the old names may not be carried forward
3772 * forever.
3773 */
3774#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3775#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3776#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3777
Duncan Laurieeb316852015-12-01 18:51:18 -08003778#endif /* __CROS_EC_EC_COMMANDS_H */