blob: 4a551c2e65cfd50328ee6f77d375e24e14fbb328 [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
jiazi Yang51fc93f2016-07-28 05:15:01 -0400474 /* TABLET/LAPTOP mode event*/
475 EC_HOST_EVENT_MODE_CHANGE = 29,
476
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800477 /*
478 * The high bit of the event mask is not used as a host event code. If
479 * it reads back as set, then the entire event mask should be
480 * considered invalid by the host. This can happen when reading the
481 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
482 * not initialized on the EC, or improperly configured on the host.
483 */
484 EC_HOST_EVENT_INVALID = 32
485};
486/* Host event mask */
487#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
488
489/* Arguments at EC_LPC_ADDR_HOST_ARGS */
490struct ec_lpc_host_args {
491 uint8_t flags;
492 uint8_t command_version;
493 uint8_t data_size;
494 /*
495 * Checksum; sum of command + flags + command_version + data_size +
496 * all params/response data bytes.
497 */
498 uint8_t checksum;
499} __packed;
500
501/* Flags for ec_lpc_host_args.flags */
502/*
503 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
504 * params.
505 *
506 * If EC gets a command and this flag is not set, this is an old-style command.
507 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
508 * unknown length. EC must respond with an old-style response (that is,
Duncan Laurieeb316852015-12-01 18:51:18 -0800509 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800510 */
511#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
512/*
513 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
514 *
515 * If EC responds to a command and this flag is not set, this is an old-style
516 * response. Command version is 0 and response data from EC is at
517 * EC_LPC_ADDR_OLD_PARAM with unknown length.
518 */
519#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
520
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800521/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800522/*
523 * Byte codes returned by EC over SPI interface.
524 *
525 * These can be used by the AP to debug the EC interface, and to determine
526 * when the EC is not in a state where it will ever get around to responding
527 * to the AP.
528 *
529 * Example of sequence of bytes read from EC for a current good transfer:
530 * 1. - - AP asserts chip select (CS#)
531 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
532 * 3. - - EC starts handling CS# interrupt
533 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
534 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
535 * bytes looking for EC_SPI_FRAME_START
536 * 6. - - EC finishes processing and sets up response
537 * 7. EC_SPI_FRAME_START - AP reads frame byte
538 * 8. (response packet) - AP reads response packet
539 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
540 * 10 - - AP deasserts chip select
541 * 11 - - EC processes CS# interrupt and sets up DMA for
542 * next request
543 *
544 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
545 * the following byte values:
546 * EC_SPI_OLD_READY
547 * EC_SPI_RX_READY
548 * EC_SPI_RECEIVING
549 * EC_SPI_PROCESSING
550 *
551 * Then the EC found an error in the request, or was not ready for the request
552 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
553 * because the EC is unable to tell when the AP is done sending its request.
554 */
555
556/*
557 * Framing byte which precedes a response packet from the EC. After sending a
558 * request, the AP will clock in bytes until it sees the framing byte, then
559 * clock in the response packet.
560 */
561#define EC_SPI_FRAME_START 0xec
562
563/*
564 * Padding bytes which are clocked out after the end of a response packet.
565 */
566#define EC_SPI_PAST_END 0xed
567
568/*
569 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
570 * that the AP will send a valid packet header (starting with
571 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
572 */
573#define EC_SPI_RX_READY 0xf8
574
575/*
576 * EC has started receiving the request from the AP, but hasn't started
577 * processing it yet.
578 */
579#define EC_SPI_RECEIVING 0xf9
580
581/* EC has received the entire request from the AP and is processing it. */
582#define EC_SPI_PROCESSING 0xfa
583
584/*
585 * EC received bad data from the AP, such as a packet header with an invalid
586 * length. EC will ignore all data until chip select deasserts.
587 */
588#define EC_SPI_RX_BAD_DATA 0xfb
589
590/*
591 * EC received data from the AP before it was ready. That is, the AP asserted
592 * chip select and started clocking data before the EC was ready to receive it.
593 * EC will ignore all data until chip select deasserts.
594 */
595#define EC_SPI_NOT_READY 0xfc
596
597/*
598 * EC was ready to receive a request from the AP. EC has treated the byte sent
599 * by the AP as part of a request packet, or (for old-style ECs) is processing
600 * a fully received packet but is not ready to respond yet.
601 */
602#define EC_SPI_OLD_READY 0xfd
603
604/*****************************************************************************/
605
606/*
607 * Protocol version 2 for I2C and SPI send a request this way:
608 *
609 * 0 EC_CMD_VERSION0 + (command version)
610 * 1 Command number
611 * 2 Length of params = N
612 * 3..N+2 Params, if any
613 * N+3 8-bit checksum of bytes 0..N+2
614 *
615 * The corresponding response is:
616 *
617 * 0 Result code (EC_RES_*)
618 * 1 Length of params = M
619 * 2..M+1 Params, if any
620 * M+2 8-bit checksum of bytes 0..M+1
621 */
622#define EC_PROTO2_REQUEST_HEADER_BYTES 3
623#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
624#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
625 EC_PROTO2_REQUEST_TRAILER_BYTES)
626
627#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
628#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
629#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
630 EC_PROTO2_RESPONSE_TRAILER_BYTES)
631
632/* Parameter length was limited by the LPC interface */
633#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
634
635/* Maximum request and response packet sizes for protocol version 2 */
636#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
637 EC_PROTO2_MAX_PARAM_SIZE)
638#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
639 EC_PROTO2_MAX_PARAM_SIZE)
640
641/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800642
643/*
644 * Value written to legacy command port / prefix byte to indicate protocol
645 * 3+ structs are being used. Usage is bus-dependent.
646 */
647#define EC_COMMAND_PROTOCOL_3 0xda
648
649#define EC_HOST_REQUEST_VERSION 3
650
651/* Version 3 request from host */
652struct ec_host_request {
653 /* Struct version (=3)
654 *
655 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
656 * version it doesn't know how to parse.
657 */
658 uint8_t struct_version;
659
660 /*
661 * Checksum of request and data; sum of all bytes including checksum
662 * should total to 0.
663 */
664 uint8_t checksum;
665
666 /* Command code */
667 uint16_t command;
668
669 /* Command version */
670 uint8_t command_version;
671
672 /* Unused byte in current protocol version; set to 0 */
673 uint8_t reserved;
674
675 /* Length of data which follows this header */
676 uint16_t data_len;
677} __packed;
678
679#define EC_HOST_RESPONSE_VERSION 3
680
681/* Version 3 response from EC */
682struct ec_host_response {
683 /* Struct version (=3) */
684 uint8_t struct_version;
685
686 /*
687 * Checksum of response and data; sum of all bytes including checksum
688 * should total to 0.
689 */
690 uint8_t checksum;
691
692 /* Result code (EC_RES_*) */
693 uint16_t result;
694
695 /* Length of data which follows this header */
696 uint16_t data_len;
697
698 /* Unused bytes in current protocol version; set to 0 */
699 uint16_t reserved;
700} __packed;
701
702/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800703/*
704 * Notes on commands:
705 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700706 * Each command is an 16-bit command value. Commands which take params or
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800707 * return response data specify structs for that data. If no struct is
708 * specified, the command does not input or output data, respectively.
709 * Parameter/response length is implicit in the structs. Some underlying
710 * communication protocols (I2C, SPI) may add length or checksum headers, but
711 * those are implementation-dependent and not defined here.
712 */
713
714/*****************************************************************************/
715/* General / test commands */
716
717/*
718 * Get protocol version, used to deal with non-backward compatible protocol
719 * changes.
720 */
721#define EC_CMD_PROTO_VERSION 0x00
722
723struct ec_response_proto_version {
724 uint32_t version;
725} __packed;
726
727/*
728 * Hello. This is a simple command to test the EC is responsive to
729 * commands.
730 */
731#define EC_CMD_HELLO 0x01
732
733struct ec_params_hello {
734 uint32_t in_data; /* Pass anything here */
735} __packed;
736
737struct ec_response_hello {
738 uint32_t out_data; /* Output will be in_data + 0x01020304 */
739} __packed;
740
741/* Get version number */
742#define EC_CMD_GET_VERSION 0x02
743
744enum ec_current_image {
745 EC_IMAGE_UNKNOWN = 0,
746 EC_IMAGE_RO,
747 EC_IMAGE_RW
748};
749
750struct ec_response_get_version {
751 /* Null-terminated version strings for RO, RW */
752 char version_string_ro[32];
753 char version_string_rw[32];
754 char reserved[32]; /* Was previously RW-B string */
755 uint32_t current_image; /* One of ec_current_image */
756} __packed;
757
758/* Read test */
759#define EC_CMD_READ_TEST 0x03
760
761struct ec_params_read_test {
762 uint32_t offset; /* Starting value for read buffer */
763 uint32_t size; /* Size to read in bytes */
764} __packed;
765
766struct ec_response_read_test {
767 uint32_t data[32];
768} __packed;
769
770/*
771 * Get build information
772 *
773 * Response is null-terminated string.
774 */
775#define EC_CMD_GET_BUILD_INFO 0x04
776
777/* Get chip info */
778#define EC_CMD_GET_CHIP_INFO 0x05
779
780struct ec_response_get_chip_info {
781 /* Null-terminated strings */
782 char vendor[32];
783 char name[32];
784 char revision[32]; /* Mask version */
785} __packed;
786
787/* Get board HW version */
788#define EC_CMD_GET_BOARD_VERSION 0x06
789
790struct ec_response_board_version {
791 uint16_t board_version; /* A monotonously incrementing number. */
792} __packed;
793
794/*
795 * Read memory-mapped data.
796 *
797 * This is an alternate interface to memory-mapped data for bus protocols
798 * which don't support direct-mapped memory - I2C, SPI, etc.
799 *
800 * Response is params.size bytes of data.
801 */
802#define EC_CMD_READ_MEMMAP 0x07
803
804struct ec_params_read_memmap {
805 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
806 uint8_t size; /* Size to read in bytes */
807} __packed;
808
809/* Read versions supported for a command */
810#define EC_CMD_GET_CMD_VERSIONS 0x08
811
812struct ec_params_get_cmd_versions {
813 uint8_t cmd; /* Command to check */
814} __packed;
815
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700816struct ec_params_get_cmd_versions_v1 {
817 uint16_t cmd; /* Command to check */
818} __packed;
819
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800820struct ec_response_get_cmd_versions {
821 /*
822 * Mask of supported versions; use EC_VER_MASK() to compare with a
823 * desired version.
824 */
825 uint32_t version_mask;
826} __packed;
827
Duncan Laurie433432b2013-06-03 10:38:22 -0700828/*
829 * Check EC communcations status (busy). This is needed on i2c/spi but not
830 * on lpc since it has its own out-of-band busy indicator.
831 *
832 * lpc must read the status from the command register. Attempting this on
833 * lpc will overwrite the args/parameter space and corrupt its data.
834 */
835#define EC_CMD_GET_COMMS_STATUS 0x09
836
837/* Avoid using ec_status which is for return values */
838enum ec_comms_status {
839 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
840};
841
842struct ec_response_get_comms_status {
843 uint32_t flags; /* Mask of enum ec_comms_status */
844} __packed;
845
Duncan Laurie93e24442014-01-06 12:30:52 -0800846/* Fake a variety of responses, purely for testing purposes. */
847#define EC_CMD_TEST_PROTOCOL 0x0a
848
849/* Tell the EC what to send back to us. */
850struct ec_params_test_protocol {
851 uint32_t ec_result;
852 uint32_t ret_len;
853 uint8_t buf[32];
854} __packed;
855
856/* Here it comes... */
857struct ec_response_test_protocol {
858 uint8_t buf[32];
859} __packed;
860
861/* Get prococol information */
862#define EC_CMD_GET_PROTOCOL_INFO 0x0b
863
864/* Flags for ec_response_get_protocol_info.flags */
865/* EC_RES_IN_PROGRESS may be returned if a command is slow */
866#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
867
868struct ec_response_get_protocol_info {
869 /* Fields which exist if at least protocol version 3 supported */
870
871 /* Bitmask of protocol versions supported (1 << n means version n)*/
872 uint32_t protocol_versions;
873
874 /* Maximum request packet size, in bytes */
875 uint16_t max_request_packet_size;
876
877 /* Maximum response packet size, in bytes */
878 uint16_t max_response_packet_size;
879
880 /* Flags; see EC_PROTOCOL_INFO_* */
881 uint32_t flags;
882} __packed;
883
884
885/*****************************************************************************/
886/* Get/Set miscellaneous values */
887
888/* The upper byte of .flags tells what to do (nothing means "get") */
889#define EC_GSV_SET 0x80000000
890
891/* The lower three bytes of .flags identifies the parameter, if that has
892 meaning for an individual command. */
893#define EC_GSV_PARAM_MASK 0x00ffffff
894
895struct ec_params_get_set_value {
896 uint32_t flags;
897 uint32_t value;
898} __packed;
899
900struct ec_response_get_set_value {
901 uint32_t flags;
902 uint32_t value;
903} __packed;
904
Duncan Laurieeb316852015-12-01 18:51:18 -0800905/* More than one command can use these structs to get/set parameters. */
Duncan Laurie93e24442014-01-06 12:30:52 -0800906#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
907
Duncan Laurieeb316852015-12-01 18:51:18 -0800908/*****************************************************************************/
909/* List the features supported by the firmware */
910#define EC_CMD_GET_FEATURES 0x0d
911
912/* Supported features */
913enum ec_feature_code {
914 /*
915 * This image contains a limited set of features. Another image
916 * in RW partition may support more features.
917 */
918 EC_FEATURE_LIMITED = 0,
919 /*
920 * Commands for probing/reading/writing/erasing the flash in the
921 * EC are present.
922 */
923 EC_FEATURE_FLASH = 1,
924 /*
925 * Can control the fan speed directly.
926 */
927 EC_FEATURE_PWM_FAN = 2,
928 /*
929 * Can control the intensity of the keyboard backlight.
930 */
931 EC_FEATURE_PWM_KEYB = 3,
932 /*
933 * Support Google lightbar, introduced on Pixel.
934 */
935 EC_FEATURE_LIGHTBAR = 4,
936 /* Control of LEDs */
937 EC_FEATURE_LED = 5,
938 /* Exposes an interface to control gyro and sensors.
939 * The host goes through the EC to access these sensors.
940 * In addition, the EC may provide composite sensors, like lid angle.
941 */
942 EC_FEATURE_MOTION_SENSE = 6,
943 /* The keyboard is controlled by the EC */
944 EC_FEATURE_KEYB = 7,
945 /* The AP can use part of the EC flash as persistent storage. */
946 EC_FEATURE_PSTORE = 8,
947 /* The EC monitors BIOS port 80h, and can return POST codes. */
948 EC_FEATURE_PORT80 = 9,
949 /*
950 * Thermal management: include TMP specific commands.
951 * Higher level than direct fan control.
952 */
953 EC_FEATURE_THERMAL = 10,
954 /* Can switch the screen backlight on/off */
955 EC_FEATURE_BKLIGHT_SWITCH = 11,
956 /* Can switch the wifi module on/off */
957 EC_FEATURE_WIFI_SWITCH = 12,
958 /* Monitor host events, through for example SMI or SCI */
959 EC_FEATURE_HOST_EVENTS = 13,
960 /* The EC exposes GPIO commands to control/monitor connected devices. */
961 EC_FEATURE_GPIO = 14,
962 /* The EC can send i2c messages to downstream devices. */
963 EC_FEATURE_I2C = 15,
964 /* Command to control charger are included */
965 EC_FEATURE_CHARGER = 16,
966 /* Simple battery support. */
967 EC_FEATURE_BATTERY = 17,
968 /*
969 * Support Smart battery protocol
970 * (Common Smart Battery System Interface Specification)
971 */
972 EC_FEATURE_SMART_BATTERY = 18,
973 /* EC can dectect when the host hangs. */
974 EC_FEATURE_HANG_DETECT = 19,
975 /* Report power information, for pit only */
976 EC_FEATURE_PMU = 20,
977 /* Another Cros EC device is present downstream of this one */
978 EC_FEATURE_SUB_MCU = 21,
979 /* Support USB Power delivery (PD) commands */
980 EC_FEATURE_USB_PD = 22,
981 /* Control USB multiplexer, for audio through USB port for instance. */
982 EC_FEATURE_USB_MUX = 23,
983 /* Motion Sensor code has an internal software FIFO */
984 EC_FEATURE_MOTION_SENSE_FIFO = 24,
985 /* Support temporary secure vstore */
986 EC_FEATURE_VSTORE = 25,
987};
988
989#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
990#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
991struct ec_response_get_features {
992 uint32_t flags[2];
993} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -0700994
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800995/*****************************************************************************/
996/* Flash commands */
997
998/* Get flash info */
999#define EC_CMD_FLASH_INFO 0x10
1000
Duncan Laurie93e24442014-01-06 12:30:52 -08001001/* Version 0 returns these fields */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001002struct ec_response_flash_info {
1003 /* Usable flash size, in bytes */
1004 uint32_t flash_size;
1005 /*
1006 * Write block size. Write offset and size must be a multiple
1007 * of this.
1008 */
1009 uint32_t write_block_size;
1010 /*
1011 * Erase block size. Erase offset and size must be a multiple
1012 * of this.
1013 */
1014 uint32_t erase_block_size;
1015 /*
1016 * Protection block size. Protection offset and size must be a
1017 * multiple of this.
1018 */
1019 uint32_t protect_block_size;
1020} __packed;
1021
Duncan Laurie93e24442014-01-06 12:30:52 -08001022/* Flags for version 1+ flash info command */
1023/* EC flash erases bits to 0 instead of 1 */
1024#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1025
1026/*
1027 * Version 1 returns the same initial fields as version 0, with additional
1028 * fields following.
1029 *
1030 * gcc anonymous structs don't seem to get along with the __packed directive;
1031 * if they did we'd define the version 0 struct as a sub-struct of this one.
1032 */
1033struct ec_response_flash_info_1 {
1034 /* Version 0 fields; see above for description */
1035 uint32_t flash_size;
1036 uint32_t write_block_size;
1037 uint32_t erase_block_size;
1038 uint32_t protect_block_size;
1039
1040 /* Version 1 adds these fields: */
1041 /*
1042 * Ideal write size in bytes. Writes will be fastest if size is
1043 * exactly this and offset is a multiple of this. For example, an EC
1044 * may have a write buffer which can do half-page operations if data is
1045 * aligned, and a slower word-at-a-time write mode.
1046 */
1047 uint32_t write_ideal_size;
1048
1049 /* Flags; see EC_FLASH_INFO_* */
1050 uint32_t flags;
1051} __packed;
1052
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001053/*
1054 * Read flash
1055 *
1056 * Response is params.size bytes of data.
1057 */
1058#define EC_CMD_FLASH_READ 0x11
1059
1060struct ec_params_flash_read {
1061 uint32_t offset; /* Byte offset to read */
1062 uint32_t size; /* Size to read in bytes */
1063} __packed;
1064
1065/* Write flash */
1066#define EC_CMD_FLASH_WRITE 0x12
Duncan Laurie93e24442014-01-06 12:30:52 -08001067#define EC_VER_FLASH_WRITE 1
1068
1069/* Version 0 of the flash command supported only 64 bytes of data */
1070#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001071
1072struct ec_params_flash_write {
1073 uint32_t offset; /* Byte offset to write */
1074 uint32_t size; /* Size to write in bytes */
Duncan Laurie93e24442014-01-06 12:30:52 -08001075 /* Followed by data to write */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001076} __packed;
1077
1078/* Erase flash */
1079#define EC_CMD_FLASH_ERASE 0x13
1080
1081struct ec_params_flash_erase {
1082 uint32_t offset; /* Byte offset to erase */
1083 uint32_t size; /* Size to erase in bytes */
1084} __packed;
1085
1086/*
1087 * Get/set flash protection.
1088 *
1089 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1090 * firmware write protect GPIO, not all flags will take effect immediately;
1091 * some flags require a subsequent hard reset to take effect. Check the
1092 * returned flags bits to see what actually happened.
1093 *
1094 * If mask=0, simply returns the current flags state.
1095 */
1096#define EC_CMD_FLASH_PROTECT 0x15
1097#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1098
1099/* Flags for flash protection */
1100/* RO flash code protected when the EC boots */
1101#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1102/*
1103 * RO flash code protected now. If this bit is set, at-boot status cannot
1104 * be changed.
1105 */
1106#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
Duncan Laurie433432b2013-06-03 10:38:22 -07001107/* Entire flash code protected now, until reboot. */
1108#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001109/* Flash write protect GPIO is asserted now */
1110#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1111/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1112#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1113/*
1114 * Error - flash protection is in inconsistent state. At least one bank of
1115 * flash which should be protected is not protected. Usually fixed by
1116 * re-requesting the desired flags, or by a hard reset if that fails.
1117 */
1118#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001119/* Entire flash code protected when the EC boots */
Duncan Laurie433432b2013-06-03 10:38:22 -07001120#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001121
1122struct ec_params_flash_protect {
1123 uint32_t mask; /* Bits in flags to apply */
1124 uint32_t flags; /* New flags to apply */
1125} __packed;
1126
1127struct ec_response_flash_protect {
1128 /* Current value of flash protect flags */
1129 uint32_t flags;
1130 /*
1131 * Flags which are valid on this platform. This allows the caller
1132 * to distinguish between flags which aren't set vs. flags which can't
1133 * be set on this platform.
1134 */
1135 uint32_t valid_flags;
1136 /* Flags which can be changed given the current protection state */
1137 uint32_t writable_flags;
1138} __packed;
1139
1140/*
1141 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1142 * write protect. These commands may be reused with version > 0.
1143 */
1144
1145/* Get the region offset/size */
1146#define EC_CMD_FLASH_REGION_INFO 0x16
1147#define EC_VER_FLASH_REGION_INFO 1
1148
1149enum ec_flash_region {
1150 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001151 EC_FLASH_REGION_RO = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001152 /* Region which holds rewritable EC image */
1153 EC_FLASH_REGION_RW,
1154 /*
1155 * Region which should be write-protected in the factory (a superset of
1156 * EC_FLASH_REGION_RO)
1157 */
1158 EC_FLASH_REGION_WP_RO,
Duncan Laurie93e24442014-01-06 12:30:52 -08001159 /* Number of regions */
1160 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001161};
1162
1163struct ec_params_flash_region_info {
1164 uint32_t region; /* enum ec_flash_region */
1165} __packed;
1166
1167struct ec_response_flash_region_info {
1168 uint32_t offset;
1169 uint32_t size;
1170} __packed;
1171
Duncan Laurie433432b2013-06-03 10:38:22 -07001172/* Read/write VbNvContext */
1173#define EC_CMD_VBNV_CONTEXT 0x17
1174#define EC_VER_VBNV_CONTEXT 1
1175#define EC_VBNV_BLOCK_SIZE 16
1176
1177enum ec_vbnvcontext_op {
1178 EC_VBNV_CONTEXT_OP_READ,
1179 EC_VBNV_CONTEXT_OP_WRITE,
1180};
1181
1182struct ec_params_vbnvcontext {
1183 uint32_t op;
1184 uint8_t block[EC_VBNV_BLOCK_SIZE];
1185} __packed;
1186
1187struct ec_response_vbnvcontext {
1188 uint8_t block[EC_VBNV_BLOCK_SIZE];
1189} __packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001190
1191/*****************************************************************************/
1192/* PWM commands */
1193
1194/* Get fan target RPM */
1195#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1196
1197struct ec_response_pwm_get_fan_rpm {
1198 uint32_t rpm;
1199} __packed;
1200
1201/* Set target fan RPM */
1202#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1203
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001204/* Version 0 of input params */
1205struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001206 uint32_t rpm;
1207} __packed;
1208
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001209/* Version 1 of input params */
1210struct ec_params_pwm_set_fan_target_rpm_v1 {
1211 uint32_t rpm;
1212 uint8_t fan_idx;
1213} __packed;
1214
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001215/* Get keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001216/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001217#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1218
1219struct ec_response_pwm_get_keyboard_backlight {
1220 uint8_t percent;
1221 uint8_t enabled;
1222} __packed;
1223
1224/* Set keyboard backlight */
Gwendal Grignou880b4582016-06-20 08:49:25 -07001225/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001226#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1227
1228struct ec_params_pwm_set_keyboard_backlight {
1229 uint8_t percent;
1230} __packed;
1231
1232/* Set target fan PWM duty cycle */
1233#define EC_CMD_PWM_SET_FAN_DUTY 0x24
1234
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001235/* Version 0 of input params */
1236struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001237 uint32_t percent;
1238} __packed;
1239
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001240/* Version 1 of input params */
1241struct ec_params_pwm_set_fan_duty_v1 {
1242 uint32_t percent;
1243 uint8_t fan_idx;
1244} __packed;
1245
Gwendal Grignou880b4582016-06-20 08:49:25 -07001246#define EC_CMD_PWM_SET_DUTY 0x25
1247/* 16 bit duty cycle, 0xffff = 100% */
1248#define EC_PWM_MAX_DUTY 0xffff
1249
1250enum ec_pwm_type {
1251 /* All types, indexed by board-specific enum pwm_channel */
1252 EC_PWM_TYPE_GENERIC = 0,
1253 /* Keyboard backlight */
1254 EC_PWM_TYPE_KB_LIGHT,
1255 /* Display backlight */
1256 EC_PWM_TYPE_DISPLAY_LIGHT,
1257 EC_PWM_TYPE_COUNT,
1258};
1259
1260struct ec_params_pwm_set_duty {
1261 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1262 uint8_t pwm_type; /* ec_pwm_type */
1263 uint8_t index; /* Type-specific index, or 0 if unique */
1264} __packed;
1265
1266#define EC_CMD_PWM_GET_DUTY 0x26
1267
1268struct ec_params_pwm_get_duty {
1269 uint8_t pwm_type; /* ec_pwm_type */
1270 uint8_t index; /* Type-specific index, or 0 if unique */
1271} __packed;
1272
1273struct ec_response_pwm_get_duty {
1274 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1275} __packed;
1276
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001277/*****************************************************************************/
1278/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001279 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001280 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1281 * into a subcommand. We'll make separate structs for subcommands with
1282 * different input args, so that we know how much to expect.
1283 */
1284#define EC_CMD_LIGHTBAR_CMD 0x28
1285
Duncan Laurie433432b2013-06-03 10:38:22 -07001286struct rgb_s {
1287 uint8_t r, g, b;
1288};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001289
Duncan Laurie433432b2013-06-03 10:38:22 -07001290#define LB_BATTERY_LEVELS 4
1291/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1292 * host command, but the alignment is the same regardless. Keep it that way.
1293 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001294struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001295 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001296 int32_t google_ramp_up;
1297 int32_t google_ramp_down;
1298 int32_t s3s0_ramp_up;
1299 int32_t s0_tick_delay[2]; /* AC=0/1 */
1300 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1301 int32_t s0s3_ramp_down;
1302 int32_t s3_sleep_for;
1303 int32_t s3_ramp_up;
1304 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001305
1306 /* Oscillation */
1307 uint8_t new_s0;
1308 uint8_t osc_min[2]; /* AC=0/1 */
1309 uint8_t osc_max[2]; /* AC=0/1 */
1310 uint8_t w_ofs[2]; /* AC=0/1 */
1311
1312 /* Brightness limits based on the backlight and AC. */
1313 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1314 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1315 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1316
1317 /* Battery level thresholds */
1318 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1319
1320 /* Map [AC][battery_level] to color index */
1321 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1322 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1323
1324 /* Color palette */
1325 struct rgb_s color[8]; /* 0-3 are Google colors */
1326} __packed;
1327
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001328struct lightbar_params_v1 {
1329 /* Timing */
1330 int32_t google_ramp_up;
1331 int32_t google_ramp_down;
1332 int32_t s3s0_ramp_up;
1333 int32_t s0_tick_delay[2]; /* AC=0/1 */
1334 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1335 int32_t s0s3_ramp_down;
1336 int32_t s3_sleep_for;
1337 int32_t s3_ramp_up;
1338 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001339 int32_t s5_ramp_up;
1340 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001341 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001342 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001343 int32_t tap_display_time;
1344
1345 /* Tap-for-battery params */
1346 uint8_t tap_pct_red;
1347 uint8_t tap_pct_green;
1348 uint8_t tap_seg_min_on;
1349 uint8_t tap_seg_max_on;
1350 uint8_t tap_seg_osc;
1351 uint8_t tap_idx[3];
1352
1353 /* Oscillation */
1354 uint8_t osc_min[2]; /* AC=0/1 */
1355 uint8_t osc_max[2]; /* AC=0/1 */
1356 uint8_t w_ofs[2]; /* AC=0/1 */
1357
1358 /* Brightness limits based on the backlight and AC. */
1359 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1360 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1361 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1362
1363 /* Battery level thresholds */
1364 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1365
1366 /* Map [AC][battery_level] to color index */
1367 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1368 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1369
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001370 /* s5: single color pulse on inhibited power-up */
1371 uint8_t s5_idx;
1372
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001373 /* Color palette */
1374 struct rgb_s color[8]; /* 0-3 are Google colors */
1375} __packed;
1376
Duncan Laurieeb316852015-12-01 18:51:18 -08001377/* Lightbar command params v2
1378 * crbug.com/467716
1379 *
1380 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1381 * logical groups to make it more manageable ( < 120 bytes).
1382 *
1383 * NOTE: Each of these groups must be less than 120 bytes.
1384 */
1385
1386struct lightbar_params_v2_timing {
1387 /* Timing */
1388 int32_t google_ramp_up;
1389 int32_t google_ramp_down;
1390 int32_t s3s0_ramp_up;
1391 int32_t s0_tick_delay[2]; /* AC=0/1 */
1392 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1393 int32_t s0s3_ramp_down;
1394 int32_t s3_sleep_for;
1395 int32_t s3_ramp_up;
1396 int32_t s3_ramp_down;
1397 int32_t s5_ramp_up;
1398 int32_t s5_ramp_down;
1399 int32_t tap_tick_delay;
1400 int32_t tap_gate_delay;
1401 int32_t tap_display_time;
1402} __packed;
1403
1404struct lightbar_params_v2_tap {
1405 /* Tap-for-battery params */
1406 uint8_t tap_pct_red;
1407 uint8_t tap_pct_green;
1408 uint8_t tap_seg_min_on;
1409 uint8_t tap_seg_max_on;
1410 uint8_t tap_seg_osc;
1411 uint8_t tap_idx[3];
1412} __packed;
1413
1414struct lightbar_params_v2_oscillation {
1415 /* Oscillation */
1416 uint8_t osc_min[2]; /* AC=0/1 */
1417 uint8_t osc_max[2]; /* AC=0/1 */
1418 uint8_t w_ofs[2]; /* AC=0/1 */
1419} __packed;
1420
1421struct lightbar_params_v2_brightness {
1422 /* Brightness limits based on the backlight and AC. */
1423 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1424 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1425 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1426} __packed;
1427
1428struct lightbar_params_v2_thresholds {
1429 /* Battery level thresholds */
1430 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1431} __packed;
1432
1433struct lightbar_params_v2_colors {
1434 /* Map [AC][battery_level] to color index */
1435 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1436 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1437
1438 /* s5: single color pulse on inhibited power-up */
1439 uint8_t s5_idx;
1440
1441 /* Color palette */
1442 struct rgb_s color[8]; /* 0-3 are Google colors */
1443} __packed;
1444
Duncan Lauried8401182014-09-29 08:32:19 -07001445/* Lightbyte program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001446#define EC_LB_PROG_LEN 192
1447struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07001448 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001449 uint8_t data[EC_LB_PROG_LEN];
Duncan Lauried8401182014-09-29 08:32:19 -07001450};
1451
Duncan Laurie433432b2013-06-03 10:38:22 -07001452struct ec_params_lightbar {
1453 uint8_t cmd; /* Command (see enum lightbar_command) */
1454 union {
1455 struct {
1456 /* no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001457 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001458 version, get_brightness, get_demo, suspend, resume,
1459 get_params_v2_timing, get_params_v2_tap,
1460 get_params_v2_osc, get_params_v2_bright,
1461 get_params_v2_thlds, get_params_v2_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001462
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001463 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001464 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001465 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001466
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001467 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001468 uint8_t ctrl, reg, value;
1469 } reg;
1470
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001471 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001472 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001473 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07001474
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001475 struct {
1476 uint8_t led;
1477 } get_rgb;
1478
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001479 struct {
1480 uint8_t enable;
1481 } manual_suspend_ctrl;
1482
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001483 struct lightbar_params_v0 set_params_v0;
1484 struct lightbar_params_v1 set_params_v1;
Duncan Laurieeb316852015-12-01 18:51:18 -08001485
1486 struct lightbar_params_v2_timing set_v2par_timing;
1487 struct lightbar_params_v2_tap set_v2par_tap;
1488 struct lightbar_params_v2_oscillation set_v2par_osc;
1489 struct lightbar_params_v2_brightness set_v2par_bright;
1490 struct lightbar_params_v2_thresholds set_v2par_thlds;
1491 struct lightbar_params_v2_colors set_v2par_colors;
1492
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001493 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001494 };
1495} __packed;
1496
Duncan Laurie433432b2013-06-03 10:38:22 -07001497struct ec_response_lightbar {
1498 union {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001499 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001500 struct {
1501 uint8_t reg;
1502 uint8_t ic0;
1503 uint8_t ic1;
1504 } vals[23];
1505 } dump;
1506
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001507 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001508 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001509 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001510
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001511 struct lightbar_params_v0 get_params_v0;
1512 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07001513
Duncan Laurieeb316852015-12-01 18:51:18 -08001514
1515 struct lightbar_params_v2_timing get_params_v2_timing;
1516 struct lightbar_params_v2_tap get_params_v2_tap;
1517 struct lightbar_params_v2_oscillation get_params_v2_osc;
1518 struct lightbar_params_v2_brightness get_params_v2_bright;
1519 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1520 struct lightbar_params_v2_colors get_params_v2_colors;
1521
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001522 struct {
Duncan Laurie93e24442014-01-06 12:30:52 -08001523 uint32_t num;
1524 uint32_t flags;
1525 } version;
1526
Duncan Laurie433432b2013-06-03 10:38:22 -07001527 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001528 uint8_t red, green, blue;
1529 } get_rgb;
1530
1531 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001532 /* no return params */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001533 } off, on, init, set_brightness, seq, reg, set_rgb,
Duncan Lauried8401182014-09-29 08:32:19 -07001534 demo, set_params_v0, set_params_v1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001535 set_program, manual_suspend_ctrl, suspend, resume,
1536 set_v2par_timing, set_v2par_tap,
1537 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1538 set_v2par_colors;
Duncan Laurie433432b2013-06-03 10:38:22 -07001539 };
1540} __packed;
1541
1542/* Lightbar commands */
1543enum lightbar_command {
1544 LIGHTBAR_CMD_DUMP = 0,
1545 LIGHTBAR_CMD_OFF = 1,
1546 LIGHTBAR_CMD_ON = 2,
1547 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001548 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07001549 LIGHTBAR_CMD_SEQ = 5,
1550 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001551 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07001552 LIGHTBAR_CMD_GET_SEQ = 8,
1553 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001554 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1555 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08001556 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001557 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1558 LIGHTBAR_CMD_GET_RGB = 14,
1559 LIGHTBAR_CMD_GET_DEMO = 15,
1560 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1561 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07001562 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001563 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1564 LIGHTBAR_CMD_SUSPEND = 20,
1565 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurieeb316852015-12-01 18:51:18 -08001566 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1567 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1568 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1569 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1570 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1571 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1572 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1573 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1574 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1575 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1576 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1577 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
Duncan Laurie433432b2013-06-03 10:38:22 -07001578 LIGHTBAR_NUM_CMDS
1579};
1580
1581/*****************************************************************************/
1582/* LED control commands */
1583
Bill Richardsone221aad2013-06-12 10:50:41 -07001584#define EC_CMD_LED_CONTROL 0x29
Duncan Laurie433432b2013-06-03 10:38:22 -07001585
Bill Richardsone221aad2013-06-12 10:50:41 -07001586enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08001587 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07001588 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08001589 /*
1590 * LED to indicate system power state (on or in suspend).
1591 * May be on power button or on C-panel.
1592 */
1593 EC_LED_ID_POWER_LED,
1594 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07001595 EC_LED_ID_ADAPTER_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08001596
1597 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07001598};
Duncan Laurie433432b2013-06-03 10:38:22 -07001599
Bill Richardsone221aad2013-06-12 10:50:41 -07001600/* LED control flags */
1601#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1602#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1603
1604enum ec_led_colors {
1605 EC_LED_COLOR_RED = 0,
1606 EC_LED_COLOR_GREEN,
1607 EC_LED_COLOR_BLUE,
1608 EC_LED_COLOR_YELLOW,
1609 EC_LED_COLOR_WHITE,
Duncan Laurieeb316852015-12-01 18:51:18 -08001610 EC_LED_COLOR_AMBER,
Bill Richardsone221aad2013-06-12 10:50:41 -07001611
1612 EC_LED_COLOR_COUNT
1613};
1614
1615struct ec_params_led_control {
1616 uint8_t led_id; /* Which LED to control */
1617 uint8_t flags; /* Control flags */
1618
1619 uint8_t brightness[EC_LED_COLOR_COUNT];
1620} __packed;
1621
1622struct ec_response_led_control {
1623 /*
1624 * Available brightness value range.
1625 *
1626 * Range 0 means color channel not present.
1627 * Range 1 means on/off control.
1628 * Other values means the LED is control by PWM.
1629 */
1630 uint8_t brightness_range[EC_LED_COLOR_COUNT];
Duncan Laurie433432b2013-06-03 10:38:22 -07001631} __packed;
1632
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001633/*****************************************************************************/
1634/* Verified boot commands */
1635
1636/*
1637 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1638 * reused for other purposes with version > 0.
1639 */
1640
1641/* Verified boot hash command */
Duncan Laurieeb316852015-12-01 18:51:18 -08001642#define EC_CMD_VBOOT_HASH 0x2a
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001643
1644struct ec_params_vboot_hash {
1645 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1646 uint8_t hash_type; /* enum ec_vboot_hash_type */
1647 uint8_t nonce_size; /* Nonce size; may be 0 */
1648 uint8_t reserved0; /* Reserved; set 0 */
1649 uint32_t offset; /* Offset in flash to hash */
1650 uint32_t size; /* Number of bytes to hash */
1651 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1652} __packed;
1653
1654struct ec_response_vboot_hash {
1655 uint8_t status; /* enum ec_vboot_hash_status */
1656 uint8_t hash_type; /* enum ec_vboot_hash_type */
1657 uint8_t digest_size; /* Size of hash digest in bytes */
1658 uint8_t reserved0; /* Ignore; will be 0 */
1659 uint32_t offset; /* Offset in flash which was hashed */
1660 uint32_t size; /* Number of bytes hashed */
1661 uint8_t hash_digest[64]; /* Hash digest data */
1662} __packed;
1663
1664enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07001665 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1666 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1667 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1668 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001669};
1670
1671enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07001672 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001673};
1674
1675enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001676 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1677 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1678 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001679};
1680
Duncan Laurie433432b2013-06-03 10:38:22 -07001681/*
1682 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1683 * If one of these is specified, the EC will automatically update offset and
1684 * size to the correct values for the specified image (RO or RW).
1685 */
1686#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1687#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1688
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001689/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001690/*
1691 * Motion sense commands. We'll make separate structs for sub-commands with
1692 * different input args, so that we know how much to expect.
1693 */
Duncan Laurieeb316852015-12-01 18:51:18 -08001694#define EC_CMD_MOTION_SENSE_CMD 0x2b
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001695
1696/* Motion sense commands */
1697enum motionsense_command {
1698 /*
1699 * Dump command returns all motion sensor data including motion sense
1700 * module flags and individual sensor flags.
1701 */
1702 MOTIONSENSE_CMD_DUMP = 0,
1703
1704 /*
1705 * Info command returns data describing the details of a given sensor,
1706 * including enum motionsensor_type, enum motionsensor_location, and
1707 * enum motionsensor_chip.
1708 */
1709 MOTIONSENSE_CMD_INFO = 1,
1710
1711 /*
1712 * EC Rate command is a setter/getter command for the EC sampling rate
Duncan Laurieeb316852015-12-01 18:51:18 -08001713 * in milliseconds.
1714 * It is per sensor, the EC run sample task at the minimum of all
1715 * sensors EC_RATE.
1716 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
1717 * to collect all the sensor samples.
1718 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
1719 * to process of all motion sensors in milliseconds.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001720 */
1721 MOTIONSENSE_CMD_EC_RATE = 2,
1722
1723 /*
1724 * Sensor ODR command is a setter/getter command for the output data
1725 * rate of a specific motion sensor in millihertz.
1726 */
1727 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1728
1729 /*
1730 * Sensor range command is a setter/getter command for the range of
1731 * a specified motion sensor in +/-G's or +/- deg/s.
1732 */
1733 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1734
1735 /*
1736 * Setter/getter command for the keyboard wake angle. When the lid
1737 * angle is greater than this value, keyboard wake is disabled in S3,
1738 * and when the lid angle goes less than this value, keyboard wake is
1739 * enabled. Note, the lid angle measurement is an approximate,
1740 * un-calibrated value, hence the wake angle isn't exact.
1741 */
1742 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1743
Duncan Laurieeb316852015-12-01 18:51:18 -08001744 /*
1745 * Returns a single sensor data.
1746 */
1747 MOTIONSENSE_CMD_DATA = 6,
1748
1749 /*
1750 * Return sensor fifo info.
1751 */
1752 MOTIONSENSE_CMD_FIFO_INFO = 7,
1753
1754 /*
1755 * Insert a flush element in the fifo and return sensor fifo info.
1756 * The host can use that element to synchronize its operation.
1757 */
1758 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
1759
1760 /*
1761 * Return a portion of the fifo.
1762 */
1763 MOTIONSENSE_CMD_FIFO_READ = 9,
1764
1765 /*
1766 * Perform low level calibration.
1767 * On sensors that support it, ask to do offset calibration.
1768 */
1769 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1770
1771 /*
1772 * Sensor Offset command is a setter/getter command for the offset
1773 * used for calibration.
1774 * The offsets can be calculated by the host, or via
1775 * PERFORM_CALIB command.
1776 */
1777 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1778
1779 /*
1780 * List available activities for a MOTION sensor.
1781 * Indicates if they are enabled or disabled.
1782 */
1783 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
1784
1785 /*
1786 * Activity management
1787 * Enable/Disable activity recognition.
1788 */
1789 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
1790
1791 /*
1792 * Lid Angle
1793 */
1794 MOTIONSENSE_CMD_LID_ANGLE = 14,
1795
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001796 /* Number of motionsense sub-commands. */
1797 MOTIONSENSE_NUM_CMDS
1798};
1799
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001800/* List of motion sensor types. */
1801enum motionsensor_type {
1802 MOTIONSENSE_TYPE_ACCEL = 0,
1803 MOTIONSENSE_TYPE_GYRO = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001804 MOTIONSENSE_TYPE_MAG = 2,
1805 MOTIONSENSE_TYPE_PROX = 3,
1806 MOTIONSENSE_TYPE_LIGHT = 4,
1807 MOTIONSENSE_TYPE_ACTIVITY = 5,
1808 MOTIONSENSE_TYPE_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001809};
1810
1811/* List of motion sensor locations. */
1812enum motionsensor_location {
1813 MOTIONSENSE_LOC_BASE = 0,
1814 MOTIONSENSE_LOC_LID = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001815 MOTIONSENSE_LOC_MAX,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001816};
1817
1818/* List of motion sensor chips. */
1819enum motionsensor_chip {
1820 MOTIONSENSE_CHIP_KXCJ9 = 0,
1821 MOTIONSENSE_CHIP_LSM6DS0 = 1,
Duncan Laurieeb316852015-12-01 18:51:18 -08001822 MOTIONSENSE_CHIP_BMI160 = 2,
1823 MOTIONSENSE_CHIP_SI1141 = 3,
1824 MOTIONSENSE_CHIP_SI1142 = 4,
1825 MOTIONSENSE_CHIP_SI1143 = 5,
1826 MOTIONSENSE_CHIP_KX022 = 6,
1827 MOTIONSENSE_CHIP_L3GD20H = 7,
Gwendal Grignou880b4582016-06-20 08:49:25 -07001828 MOTIONSENSE_CHIP_BMA255 = 8,
Duncan Laurieeb316852015-12-01 18:51:18 -08001829};
1830
1831struct ec_response_motion_sensor_data {
1832 /* Flags for each sensor. */
1833 uint8_t flags;
1834 /* sensor number the data comes from */
1835 uint8_t sensor_num;
1836 /* Each sensor is up to 3-axis. */
1837 union {
1838 int16_t data[3];
1839 struct {
1840 uint16_t rsvd;
1841 uint32_t timestamp;
1842 } __packed;
1843 struct {
1844 uint8_t activity; /* motionsensor_activity */
1845 uint8_t state;
1846 int16_t add_info[2];
1847 };
1848 };
1849} __packed;
1850
1851struct ec_response_motion_sense_fifo_info {
1852 /* Size of the fifo */
1853 uint16_t size;
1854 /* Amount of space used in the fifo */
1855 uint16_t count;
1856 /* TImestamp recorded in us */
1857 uint32_t timestamp;
1858 /* Total amount of vector lost */
1859 uint16_t total_lost;
1860 /* Lost events since the last fifo_info, per sensors */
1861 uint16_t lost[0];
1862} __packed;
1863
1864struct ec_response_motion_sense_fifo_data {
1865 uint32_t number_data;
1866 struct ec_response_motion_sensor_data data[0];
1867} __packed;
1868
1869/* List supported activity recognition */
1870enum motionsensor_activity {
1871 MOTIONSENSE_ACTIVITY_RESERVED = 0,
1872 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
1873 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
1874};
1875
1876struct ec_motion_sense_activity {
1877 uint8_t sensor_num;
1878 uint8_t activity; /* one of enum motionsensor_activity */
1879 uint8_t enable; /* 1: enable, 0: disable */
1880 uint8_t reserved;
1881 uint16_t parameters[3]; /* activity dependent parameters */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001882};
1883
1884/* Module flag masks used for the dump sub-command. */
1885#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1886
1887/* Sensor flag masks used for the dump sub-command. */
1888#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1889
1890/*
Duncan Laurieeb316852015-12-01 18:51:18 -08001891 * Flush entry for synchronisation.
1892 * data contains time stamp
1893 */
1894#define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
1895#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
1896#define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
1897
1898/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001899 * Send this value for the data element to only perform a read. If you
1900 * send any other value, the EC will interpret it as data to set and will
1901 * return the actual value set.
1902 */
1903#define EC_MOTION_SENSE_NO_VALUE -1
1904
Duncan Laurieeb316852015-12-01 18:51:18 -08001905#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1906
1907/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
1908/* Set Calibration information */
1909#define MOTION_SENSE_SET_OFFSET 1
1910
1911#define LID_ANGLE_UNRELIABLE 500
1912
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001913struct ec_params_motion_sense {
1914 uint8_t cmd;
1915 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001916 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001917 struct {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001918 /*
1919 * Maximal number of sensor the host is expecting.
1920 * 0 means the host is only interested in the number
1921 * of sensors controlled by the EC.
1922 */
1923 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001924 } dump;
1925
1926 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08001927 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001928 */
1929 struct {
Duncan Laurieeb316852015-12-01 18:51:18 -08001930 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
1931 * kb_wake_angle: angle to wakup AP.
1932 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001933 int16_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08001934 } kb_wake_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001935
Duncan Laurieeb316852015-12-01 18:51:18 -08001936 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
1937 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001938 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001939 uint8_t sensor_num;
Duncan Laurieeb316852015-12-01 18:51:18 -08001940 } info, data, fifo_flush, perform_calib, list_activities;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001941
1942 /*
Duncan Laurieeb316852015-12-01 18:51:18 -08001943 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
1944 * and MOTIONSENSE_CMD_SENSOR_RANGE.
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001945 */
1946 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001947 uint8_t sensor_num;
1948
1949 /* Rounding flag, true for round-up, false for down. */
1950 uint8_t roundup;
1951
1952 uint16_t reserved;
1953
1954 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1955 int32_t data;
Duncan Laurieeb316852015-12-01 18:51:18 -08001956 } ec_rate, sensor_odr, sensor_range;
1957
1958 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1959 struct {
1960 uint8_t sensor_num;
1961
1962 /*
1963 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1964 * the calibration information in the EC.
1965 * If unset, just retrieve calibration information.
1966 */
1967 uint16_t flags;
1968
1969 /*
1970 * Temperature at calibration, in units of 0.01 C
1971 * 0x8000: invalid / unknown.
1972 * 0x0: 0C
1973 * 0x7fff: +327.67C
1974 */
1975 int16_t temp;
1976
1977 /*
1978 * Offset for calibration.
1979 * Unit:
1980 * Accelerometer: 1/1024 g
1981 * Gyro: 1/1024 deg/s
1982 * Compass: 1/16 uT
1983 */
1984 int16_t offset[3];
1985 } __packed sensor_offset;
1986
1987 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
1988 struct {
1989 } fifo_info;
1990
1991 /* Used for MOTIONSENSE_CMD_FIFO_READ */
1992 struct {
1993 /*
1994 * Number of expected vector to return.
1995 * EC may return less or 0 if none available.
1996 */
1997 uint32_t max_data_vector;
1998 } fifo_read;
1999
2000 struct ec_motion_sense_activity set_activity;
2001
2002 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2003 struct {
2004 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002005 };
2006} __packed;
2007
2008struct ec_response_motion_sense {
2009 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002010 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002011 struct {
2012 /* Flags representing the motion sensor module. */
2013 uint8_t module_flags;
2014
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002015 /* Number of sensors managed directly by the EC */
2016 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002017
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002018 /*
2019 * sensor data is truncated if response_max is too small
2020 * for holding all the data.
2021 */
2022 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002023 } dump;
2024
2025 /* Used for MOTIONSENSE_CMD_INFO. */
2026 struct {
2027 /* Should be element of enum motionsensor_type. */
2028 uint8_t type;
2029
2030 /* Should be element of enum motionsensor_location. */
2031 uint8_t location;
2032
2033 /* Should be element of enum motionsensor_chip. */
2034 uint8_t chip;
2035 } info;
2036
Duncan Laurieeb316852015-12-01 18:51:18 -08002037 /* Used for MOTIONSENSE_CMD_DATA */
2038 struct ec_response_motion_sensor_data data;
2039
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002040 /*
2041 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
2042 * MOTIONSENSE_CMD_SENSOR_RANGE, and
2043 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
2044 */
2045 struct {
2046 /* Current value of the parameter queried. */
2047 int32_t ret;
2048 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
Duncan Laurieeb316852015-12-01 18:51:18 -08002049
2050 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
2051 struct {
2052 int16_t temp;
2053 int16_t offset[3];
2054 } sensor_offset, perform_calib;
2055
2056 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2057
2058 struct ec_response_motion_sense_fifo_data fifo_read;
2059
2060 struct {
2061 uint16_t reserved;
2062 uint32_t enabled;
2063 uint32_t disabled;
2064 } __packed list_activities;
2065
2066 struct {
2067 } set_activity;
2068
2069
2070 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
2071 struct {
2072 /*
2073 * Angle between 0 and 360 degree if available,
2074 * LID_ANGLE_UNRELIABLE otherwise.
2075 */
2076 uint16_t value;
2077 } lid_angle;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002078 };
2079} __packed;
2080
2081/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002082/* Force lid open command */
2083
2084/* Make lid event always open */
2085#define EC_CMD_FORCE_LID_OPEN 0x2c
2086
2087struct ec_params_force_lid_open {
2088 uint8_t enabled;
2089} __packed;
2090
2091/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002092/* USB charging control commands */
2093
2094/* Set USB port charging mode */
2095#define EC_CMD_USB_CHARGE_SET_MODE 0x30
2096
2097struct ec_params_usb_charge_set_mode {
2098 uint8_t usb_port_id;
2099 uint8_t mode;
2100} __packed;
2101
2102/*****************************************************************************/
2103/* Persistent storage for host */
2104
2105/* Maximum bytes that can be read/written in a single command */
2106#define EC_PSTORE_SIZE_MAX 64
2107
2108/* Get persistent storage info */
2109#define EC_CMD_PSTORE_INFO 0x40
2110
2111struct ec_response_pstore_info {
2112 /* Persistent storage size, in bytes */
2113 uint32_t pstore_size;
2114 /* Access size; read/write offset and size must be a multiple of this */
2115 uint32_t access_size;
2116} __packed;
2117
2118/*
2119 * Read persistent storage
2120 *
2121 * Response is params.size bytes of data.
2122 */
2123#define EC_CMD_PSTORE_READ 0x41
2124
2125struct ec_params_pstore_read {
2126 uint32_t offset; /* Byte offset to read */
2127 uint32_t size; /* Size to read in bytes */
2128} __packed;
2129
2130/* Write persistent storage */
2131#define EC_CMD_PSTORE_WRITE 0x42
2132
2133struct ec_params_pstore_write {
2134 uint32_t offset; /* Byte offset to write */
2135 uint32_t size; /* Size to write in bytes */
2136 uint8_t data[EC_PSTORE_SIZE_MAX];
2137} __packed;
2138
2139/*****************************************************************************/
2140/* Real-time clock */
2141
2142/* RTC params and response structures */
2143struct ec_params_rtc {
2144 uint32_t time;
2145} __packed;
2146
2147struct ec_response_rtc {
2148 uint32_t time;
2149} __packed;
2150
2151/* These use ec_response_rtc */
2152#define EC_CMD_RTC_GET_VALUE 0x44
2153#define EC_CMD_RTC_GET_ALARM 0x45
2154
2155/* These all use ec_params_rtc */
2156#define EC_CMD_RTC_SET_VALUE 0x46
2157#define EC_CMD_RTC_SET_ALARM 0x47
2158
2159/*****************************************************************************/
2160/* Port80 log access */
2161
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002162/* Maximum entries that can be read/written in a single command */
2163#define EC_PORT80_SIZE_MAX 32
2164
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002165/* Get last port80 code from previous boot */
2166#define EC_CMD_PORT80_LAST_BOOT 0x48
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002167#define EC_CMD_PORT80_READ 0x48
2168
2169enum ec_port80_subcmd {
2170 EC_PORT80_GET_INFO = 0,
2171 EC_PORT80_READ_BUFFER,
2172};
2173
2174struct ec_params_port80_read {
2175 uint16_t subcmd;
2176 union {
2177 struct {
2178 uint32_t offset;
2179 uint32_t num_entries;
2180 } read_buffer;
2181 };
2182} __packed;
2183
2184struct ec_response_port80_read {
2185 union {
2186 struct {
2187 uint32_t writes;
2188 uint32_t history_size;
2189 uint32_t last_boot;
2190 } get_info;
2191 struct {
2192 uint16_t codes[EC_PORT80_SIZE_MAX];
2193 } data;
2194 };
2195} __packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002196
2197struct ec_response_port80_last_boot {
2198 uint16_t code;
2199} __packed;
2200
2201/*****************************************************************************/
Duncan Laurieeb316852015-12-01 18:51:18 -08002202/* Temporary secure storage for host verified boot use */
2203
2204/* Number of bytes in a vstore slot */
2205#define EC_VSTORE_SLOT_SIZE 64
2206
2207/* Maximum number of vstore slots */
2208#define EC_VSTORE_SLOT_MAX 32
2209
2210/* Get persistent storage info */
2211#define EC_CMD_VSTORE_INFO 0x49
2212
2213struct ec_response_vstore_info {
2214 /* Indicates which slots are locked */
2215 uint32_t slot_locked;
2216 /* Total number of slots available */
2217 uint8_t slot_count;
2218} __packed;
2219
2220/*
2221 * Read temporary secure storage
2222 *
2223 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2224 */
2225#define EC_CMD_VSTORE_READ 0x4a
2226
2227struct ec_params_vstore_read {
2228 uint8_t slot; /* Slot to read from */
2229} __packed;
2230
2231struct ec_response_vstore_read {
2232 uint8_t data[EC_VSTORE_SLOT_SIZE];
2233} __packed;
2234
2235/*
2236 * Write temporary secure storage and lock it.
2237 */
2238#define EC_CMD_VSTORE_WRITE 0x4b
2239
2240struct ec_params_vstore_write {
2241 uint8_t slot; /* Slot to write to */
2242 uint8_t data[EC_VSTORE_SLOT_SIZE];
2243} __packed;
2244
2245/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08002246/* Thermal engine commands. Note that there are two implementations. We'll
2247 * reuse the command number, but the data and behavior is incompatible.
2248 * Version 0 is what originally shipped on Link.
2249 * Version 1 separates the CPU thermal limits from the fan control.
2250 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002251
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002252#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
Duncan Laurie93e24442014-01-06 12:30:52 -08002253#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002254
Duncan Laurie93e24442014-01-06 12:30:52 -08002255/* The version 0 structs are opaque. You have to know what they are for
2256 * the get/set commands to make any sense.
2257 */
2258
2259/* Version 0 - set */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002260struct ec_params_thermal_set_threshold {
2261 uint8_t sensor_type;
2262 uint8_t threshold_id;
2263 uint16_t value;
2264} __packed;
2265
Duncan Laurie93e24442014-01-06 12:30:52 -08002266/* Version 0 - get */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002267struct ec_params_thermal_get_threshold {
2268 uint8_t sensor_type;
2269 uint8_t threshold_id;
2270} __packed;
2271
2272struct ec_response_thermal_get_threshold {
2273 uint16_t value;
2274} __packed;
2275
Duncan Laurie93e24442014-01-06 12:30:52 -08002276
2277/* The version 1 structs are visible. */
2278enum ec_temp_thresholds {
2279 EC_TEMP_THRESH_WARN = 0,
2280 EC_TEMP_THRESH_HIGH,
2281 EC_TEMP_THRESH_HALT,
2282
2283 EC_TEMP_THRESH_COUNT
2284};
2285
2286/* Thermal configuration for one temperature sensor. Temps are in degrees K.
2287 * Zero values will be silently ignored by the thermal task.
2288 */
2289struct ec_thermal_config {
2290 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2291 uint32_t temp_fan_off; /* no active cooling needed */
2292 uint32_t temp_fan_max; /* max active cooling needed */
2293} __packed;
2294
2295/* Version 1 - get config for one sensor. */
2296struct ec_params_thermal_get_threshold_v1 {
2297 uint32_t sensor_num;
2298} __packed;
2299/* This returns a struct ec_thermal_config */
2300
2301/* Version 1 - set config for one sensor.
2302 * Use read-modify-write for best results! */
2303struct ec_params_thermal_set_threshold_v1 {
2304 uint32_t sensor_num;
2305 struct ec_thermal_config cfg;
2306} __packed;
2307/* This returns no data */
2308
2309/****************************************************************************/
2310
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002311/* Toggle automatic fan control */
2312#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
2313
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002314/* Version 1 of input params */
2315struct ec_params_auto_fan_ctrl_v1 {
2316 uint8_t fan_idx;
2317} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002318
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002319/* Get/Set TMP006 calibration data */
2320#define EC_CMD_TMP006_GET_CALIBRATION 0x53
2321#define EC_CMD_TMP006_SET_CALIBRATION 0x54
2322
2323/*
2324 * The original TMP006 calibration only needed four params, but now we need
2325 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2326 * the params opaque. The v1 "get" response will include the algorithm number
2327 * and how many params it requires. That way we can change the EC code without
2328 * needing to update this file. We can also use a different algorithm on each
2329 * sensor.
2330 */
2331
2332/* This is the same struct for both v0 and v1. */
Duncan Laurie433432b2013-06-03 10:38:22 -07002333struct ec_params_tmp006_get_calibration {
2334 uint8_t index;
2335} __packed;
2336
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002337/* Version 0 */
2338struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002339 float s0;
2340 float b0;
2341 float b1;
2342 float b2;
2343} __packed;
2344
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002345struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07002346 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002347 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07002348 float s0;
2349 float b0;
2350 float b1;
2351 float b2;
2352} __packed;
2353
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002354/* Version 1 */
2355struct ec_response_tmp006_get_calibration_v1 {
2356 uint8_t algorithm;
2357 uint8_t num_params;
2358 uint8_t reserved[2];
2359 float val[0];
2360} __packed;
2361
2362struct ec_params_tmp006_set_calibration_v1 {
2363 uint8_t index;
2364 uint8_t algorithm;
2365 uint8_t num_params;
2366 uint8_t reserved;
2367 float val[0];
2368} __packed;
2369
2370
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002371/* Read raw TMP006 data */
2372#define EC_CMD_TMP006_GET_RAW 0x55
2373
2374struct ec_params_tmp006_get_raw {
2375 uint8_t index;
2376} __packed;
2377
2378struct ec_response_tmp006_get_raw {
2379 int32_t t; /* In 1/100 K */
2380 int32_t v; /* In nV */
2381};
2382
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002383/*****************************************************************************/
2384/* MKBP - Matrix KeyBoard Protocol */
2385
2386/*
2387 * Read key state
2388 *
2389 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2390 * expected response size.
2391 */
2392#define EC_CMD_MKBP_STATE 0x60
2393
2394/* Provide information about the matrix : number of rows and columns */
2395#define EC_CMD_MKBP_INFO 0x61
2396
2397struct ec_response_mkbp_info {
2398 uint32_t rows;
2399 uint32_t cols;
2400 uint8_t switches;
2401} __packed;
2402
2403/* Simulate key press */
2404#define EC_CMD_MKBP_SIMULATE_KEY 0x62
2405
2406struct ec_params_mkbp_simulate_key {
2407 uint8_t col;
2408 uint8_t row;
2409 uint8_t pressed;
2410} __packed;
2411
Duncan Laurie433432b2013-06-03 10:38:22 -07002412/* Configure keyboard scanning */
2413#define EC_CMD_MKBP_SET_CONFIG 0x64
2414#define EC_CMD_MKBP_GET_CONFIG 0x65
2415
2416/* flags */
2417enum mkbp_config_flags {
2418 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2419};
2420
2421enum mkbp_config_valid {
2422 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2423 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2424 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2425 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2426 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2427 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2428 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2429};
2430
2431/* Configuration for our key scanning algorithm */
2432struct ec_mkbp_config {
2433 uint32_t valid_mask; /* valid fields */
2434 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2435 uint8_t valid_flags; /* which flags are valid */
2436 uint16_t scan_period_us; /* period between start of scans */
2437 /* revert to interrupt mode after no activity for this long */
2438 uint32_t poll_timeout_us;
2439 /*
2440 * minimum post-scan relax time. Once we finish a scan we check
2441 * the time until we are due to start the next one. If this time is
2442 * shorter this field, we use this instead.
2443 */
2444 uint16_t min_post_scan_delay_us;
2445 /* delay between setting up output and waiting for it to settle */
2446 uint16_t output_settle_us;
2447 uint16_t debounce_down_us; /* time for debounce on key down */
2448 uint16_t debounce_up_us; /* time for debounce on key up */
2449 /* maximum depth to allow for fifo (0 = no keyscan output) */
2450 uint8_t fifo_max_depth;
2451} __packed;
2452
2453struct ec_params_mkbp_set_config {
2454 struct ec_mkbp_config config;
2455} __packed;
2456
2457struct ec_response_mkbp_get_config {
2458 struct ec_mkbp_config config;
2459} __packed;
2460
2461/* Run the key scan emulation */
2462#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
2463
2464enum ec_keyscan_seq_cmd {
2465 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2466 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2467 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2468 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2469 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2470};
2471
2472enum ec_collect_flags {
2473 /*
2474 * Indicates this scan was processed by the EC. Due to timing, some
2475 * scans may be skipped.
2476 */
2477 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2478};
2479
2480struct ec_collect_item {
2481 uint8_t flags; /* some flags (enum ec_collect_flags) */
2482};
2483
2484struct ec_params_keyscan_seq_ctrl {
2485 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2486 union {
2487 struct {
2488 uint8_t active; /* still active */
2489 uint8_t num_items; /* number of items */
2490 /* Current item being presented */
2491 uint8_t cur_item;
2492 } status;
2493 struct {
2494 /*
2495 * Absolute time for this scan, measured from the
2496 * start of the sequence.
2497 */
2498 uint32_t time_us;
2499 uint8_t scan[0]; /* keyscan data */
2500 } add;
2501 struct {
2502 uint8_t start_item; /* First item to return */
2503 uint8_t num_items; /* Number of items to return */
2504 } collect;
2505 };
2506} __packed;
2507
2508struct ec_result_keyscan_seq_ctrl {
2509 union {
2510 struct {
2511 uint8_t num_items; /* Number of items */
2512 /* Data for each item */
2513 struct ec_collect_item item[0];
2514 } collect;
2515 };
2516} __packed;
2517
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002518/*
2519 * Get the next pending MKBP event.
2520 *
2521 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2522 */
2523#define EC_CMD_GET_NEXT_EVENT 0x67
2524
2525enum ec_mkbp_event {
2526 /* Keyboard matrix changed. The event data is the new matrix state. */
2527 EC_MKBP_EVENT_KEY_MATRIX = 0,
2528
2529 /* New host event. The event data is 4 bytes of host event flags. */
2530 EC_MKBP_EVENT_HOST_EVENT = 1,
2531
Duncan Laurieeb316852015-12-01 18:51:18 -08002532 /* New Sensor FIFO data. The event data is fifo_info structure. */
2533 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2534
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002535 /* Number of MKBP events */
2536 EC_MKBP_EVENT_COUNT,
2537};
2538
Duncan Laurieeb316852015-12-01 18:51:18 -08002539union ec_response_get_next_data {
2540 uint8_t key_matrix[13];
2541
2542 /* Unaligned */
2543 uint32_t host_event;
2544
2545 struct {
2546 /* For aligning the fifo_info */
2547 uint8_t rsvd[3];
2548 struct ec_response_motion_sense_fifo_info info;
2549 } sensor_fifo;
2550} __packed;
2551
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002552struct ec_response_get_next_event {
2553 uint8_t event_type;
2554 /* Followed by event data if any */
Duncan Laurieeb316852015-12-01 18:51:18 -08002555 union ec_response_get_next_data data;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002556} __packed;
2557
Gwendal Grignou880b4582016-06-20 08:49:25 -07002558/* Run keyboard factory test scanning */
2559#define EC_CMD_KEYBOARD_FACTORY_TEST 0x68
2560
2561struct ec_response_keyboard_factory_test {
2562 uint16_t shorted; /* Keyboard pins are shorted */
2563} __packed;
2564
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002565/*****************************************************************************/
2566/* Temperature sensor commands */
2567
2568/* Read temperature sensor info */
2569#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2570
2571struct ec_params_temp_sensor_get_info {
2572 uint8_t id;
2573} __packed;
2574
2575struct ec_response_temp_sensor_get_info {
2576 char sensor_name[32];
2577 uint8_t sensor_type;
2578} __packed;
2579
2580/*****************************************************************************/
2581
2582/*
2583 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2584 * commands accidentally sent to the wrong interface. See the ACPI section
2585 * below.
2586 */
2587
2588/*****************************************************************************/
2589/* Host event commands */
2590
2591/*
2592 * Host event mask params and response structures, shared by all of the host
2593 * event commands below.
2594 */
2595struct ec_params_host_event_mask {
2596 uint32_t mask;
2597} __packed;
2598
2599struct ec_response_host_event_mask {
2600 uint32_t mask;
2601} __packed;
2602
2603/* These all use ec_response_host_event_mask */
2604#define EC_CMD_HOST_EVENT_GET_B 0x87
2605#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2606#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2607#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2608
2609/* These all use ec_params_host_event_mask */
2610#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2611#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2612#define EC_CMD_HOST_EVENT_CLEAR 0x8c
2613#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2614#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2615
2616/*****************************************************************************/
2617/* Switch commands */
2618
2619/* Enable/disable LCD backlight */
2620#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2621
2622struct ec_params_switch_enable_backlight {
2623 uint8_t enabled;
2624} __packed;
2625
2626/* Enable/disable WLAN/Bluetooth */
2627#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002628#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002629
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002630/* Version 0 params; no response */
2631struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002632 uint8_t enabled;
2633} __packed;
2634
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002635/* Version 1 params */
2636struct ec_params_switch_enable_wireless_v1 {
2637 /* Flags to enable now */
2638 uint8_t now_flags;
2639
2640 /* Which flags to copy from now_flags */
2641 uint8_t now_mask;
2642
2643 /*
2644 * Flags to leave enabled in S3, if they're on at the S0->S3
2645 * transition. (Other flags will be disabled by the S0->S3
2646 * transition.)
2647 */
2648 uint8_t suspend_flags;
2649
2650 /* Which flags to copy from suspend_flags */
2651 uint8_t suspend_mask;
2652} __packed;
2653
2654/* Version 1 response */
2655struct ec_response_switch_enable_wireless_v1 {
2656 /* Flags to enable now */
2657 uint8_t now_flags;
2658
2659 /* Flags to leave enabled in S3 */
2660 uint8_t suspend_flags;
2661} __packed;
2662
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002663/*****************************************************************************/
2664/* GPIO commands. Only available on EC if write protect has been disabled. */
2665
2666/* Set GPIO output value */
2667#define EC_CMD_GPIO_SET 0x92
2668
2669struct ec_params_gpio_set {
2670 char name[32];
2671 uint8_t val;
2672} __packed;
2673
2674/* Get GPIO value */
2675#define EC_CMD_GPIO_GET 0x93
2676
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002677/* Version 0 of input params and response */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002678struct ec_params_gpio_get {
2679 char name[32];
2680} __packed;
2681struct ec_response_gpio_get {
2682 uint8_t val;
2683} __packed;
2684
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002685/* Version 1 of input params and response */
2686struct ec_params_gpio_get_v1 {
2687 uint8_t subcmd;
2688 union {
2689 struct {
2690 char name[32];
2691 } get_value_by_name;
2692 struct {
2693 uint8_t index;
2694 } get_info;
2695 };
2696} __packed;
2697
2698struct ec_response_gpio_get_v1 {
2699 union {
2700 struct {
2701 uint8_t val;
2702 } get_value_by_name, get_count;
2703 struct {
2704 uint8_t val;
2705 char name[32];
2706 uint32_t flags;
2707 } get_info;
2708 };
2709} __packed;
2710
2711enum gpio_get_subcmd {
2712 EC_GPIO_GET_BY_NAME = 0,
2713 EC_GPIO_GET_COUNT = 1,
2714 EC_GPIO_GET_INFO = 2,
2715};
2716
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002717/*****************************************************************************/
2718/* I2C commands. Only available when flash write protect is unlocked. */
2719
Duncan Laurie93e24442014-01-06 12:30:52 -08002720/*
2721 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
Duncan Laurieeb316852015-12-01 18:51:18 -08002722 * removed soon. Use EC_CMD_I2C_PASSTHRU instead.
Duncan Laurie93e24442014-01-06 12:30:52 -08002723 */
2724
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002725/* Read I2C bus */
2726#define EC_CMD_I2C_READ 0x94
2727
2728struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07002729 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002730 uint8_t read_size; /* Either 8 or 16. */
2731 uint8_t port;
2732 uint8_t offset;
2733} __packed;
2734struct ec_response_i2c_read {
2735 uint16_t data;
2736} __packed;
2737
2738/* Write I2C bus */
2739#define EC_CMD_I2C_WRITE 0x95
2740
2741struct ec_params_i2c_write {
2742 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07002743 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002744 uint8_t write_size; /* Either 8 or 16. */
2745 uint8_t port;
2746 uint8_t offset;
2747} __packed;
2748
2749/*****************************************************************************/
2750/* Charge state commands. Only available when flash write protect unlocked. */
2751
Duncan Laurie93e24442014-01-06 12:30:52 -08002752/* Force charge state machine to stop charging the battery or force it to
2753 * discharge the battery.
2754 */
2755#define EC_CMD_CHARGE_CONTROL 0x96
2756#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002757
Duncan Laurie93e24442014-01-06 12:30:52 -08002758enum ec_charge_control_mode {
2759 CHARGE_CONTROL_NORMAL = 0,
2760 CHARGE_CONTROL_IDLE,
2761 CHARGE_CONTROL_DISCHARGE,
2762};
2763
2764struct ec_params_charge_control {
2765 uint32_t mode; /* enum charge_control_mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002766} __packed;
2767
2768/*****************************************************************************/
2769/* Console commands. Only available when flash write protect is unlocked. */
2770
2771/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2772#define EC_CMD_CONSOLE_SNAPSHOT 0x97
2773
2774/*
Duncan Laurieeb316852015-12-01 18:51:18 -08002775 * Read data from the saved snapshot. If the subcmd parameter is
2776 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2777 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2778 * end of the previous snapshot.
2779 *
2780 * The params are only looked at in version >= 1 of this command. Prior
2781 * versions will just default to CONSOLE_READ_NEXT behavior.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002782 *
2783 * Response is null-terminated string. Empty string, if there is no more
2784 * remaining output.
2785 */
2786#define EC_CMD_CONSOLE_READ 0x98
2787
Duncan Laurieeb316852015-12-01 18:51:18 -08002788enum ec_console_read_subcmd {
2789 CONSOLE_READ_NEXT = 0,
2790 CONSOLE_READ_RECENT
2791};
2792
2793struct ec_params_console_read_v1 {
2794 uint8_t subcmd; /* enum ec_console_read_subcmd */
2795} __packed;
2796
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002797/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07002798
2799/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002800 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07002801 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002802 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2803 * EC_RES_SUCCESS if the command was successful.
2804 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07002805 */
2806#define EC_CMD_BATTERY_CUT_OFF 0x99
2807
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002808#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2809
2810struct ec_params_battery_cutoff {
2811 uint8_t flags;
2812} __packed;
2813
Duncan Laurie433432b2013-06-03 10:38:22 -07002814/*****************************************************************************/
2815/* USB port mux control. */
2816
2817/*
2818 * Switch USB mux or return to automatic switching.
2819 */
2820#define EC_CMD_USB_MUX 0x9a
2821
2822struct ec_params_usb_mux {
2823 uint8_t mux;
2824} __packed;
2825
2826/*****************************************************************************/
2827/* LDOs / FETs control. */
2828
2829enum ec_ldo_state {
2830 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2831 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2832};
2833
2834/*
2835 * Switch on/off a LDO.
2836 */
2837#define EC_CMD_LDO_SET 0x9b
2838
2839struct ec_params_ldo_set {
2840 uint8_t index;
2841 uint8_t state;
2842} __packed;
2843
2844/*
2845 * Get LDO state.
2846 */
2847#define EC_CMD_LDO_GET 0x9c
2848
2849struct ec_params_ldo_get {
2850 uint8_t index;
2851} __packed;
2852
2853struct ec_response_ldo_get {
2854 uint8_t state;
2855} __packed;
2856
2857/*****************************************************************************/
2858/* Power info. */
2859
2860/*
2861 * Get power info.
2862 */
2863#define EC_CMD_POWER_INFO 0x9d
2864
2865struct ec_response_power_info {
2866 uint32_t usb_dev_type;
2867 uint16_t voltage_ac;
2868 uint16_t voltage_system;
2869 uint16_t current_system;
2870 uint16_t usb_current_limit;
2871} __packed;
2872
2873/*****************************************************************************/
2874/* I2C passthru command */
2875
2876#define EC_CMD_I2C_PASSTHRU 0x9e
2877
Duncan Laurie433432b2013-06-03 10:38:22 -07002878/* Read data; if not present, message is a write */
2879#define EC_I2C_FLAG_READ (1 << 15)
2880
2881/* Mask for address */
2882#define EC_I2C_ADDR_MASK 0x3ff
2883
2884#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2885#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2886
2887/* Any error */
2888#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2889
2890struct ec_params_i2c_passthru_msg {
2891 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2892 uint16_t len; /* Number of bytes to read or write */
2893} __packed;
2894
2895struct ec_params_i2c_passthru {
2896 uint8_t port; /* I2C port number */
2897 uint8_t num_msgs; /* Number of messages */
2898 struct ec_params_i2c_passthru_msg msg[];
2899 /* Data to write for all messages is concatenated here */
2900} __packed;
2901
2902struct ec_response_i2c_passthru {
2903 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2904 uint8_t num_msgs; /* Number of messages processed */
2905 uint8_t data[]; /* Data read by messages concatenated here */
2906} __packed;
2907
Duncan Lauriee6b280e2014-02-10 16:21:05 -08002908/*****************************************************************************/
2909/* Power button hang detect */
2910
2911#define EC_CMD_HANG_DETECT 0x9f
2912
2913/* Reasons to start hang detection timer */
2914/* Power button pressed */
2915#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2916
2917/* Lid closed */
2918#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2919
2920 /* Lid opened */
2921#define EC_HANG_START_ON_LID_OPEN (1 << 2)
2922
2923/* Start of AP S3->S0 transition (booting or resuming from suspend) */
2924#define EC_HANG_START_ON_RESUME (1 << 3)
2925
2926/* Reasons to cancel hang detection */
2927
2928/* Power button released */
2929#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2930
2931/* Any host command from AP received */
2932#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2933
2934/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2935#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2936
2937/*
2938 * If this flag is set, all the other fields are ignored, and the hang detect
2939 * timer is started. This provides the AP a way to start the hang timer
2940 * without reconfiguring any of the other hang detect settings. Note that
2941 * you must previously have configured the timeouts.
2942 */
2943#define EC_HANG_START_NOW (1 << 30)
2944
2945/*
2946 * If this flag is set, all the other fields are ignored (including
2947 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2948 * without reconfiguring any of the other hang detect settings.
2949 */
2950#define EC_HANG_STOP_NOW (1 << 31)
2951
2952struct ec_params_hang_detect {
2953 /* Flags; see EC_HANG_* */
2954 uint32_t flags;
2955
2956 /* Timeout in msec before generating host event, if enabled */
2957 uint16_t host_event_timeout_msec;
2958
2959 /* Timeout in msec before generating warm reboot, if enabled */
2960 uint16_t warm_reboot_timeout_msec;
2961} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002962
2963/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002964/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07002965
2966/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002967 * This is the single catch-all host command to exchange data regarding the
2968 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07002969 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002970#define EC_CMD_CHARGE_STATE 0xa0
2971
2972/* Subcommands for this host command */
2973enum charge_state_command {
2974 CHARGE_STATE_CMD_GET_STATE,
2975 CHARGE_STATE_CMD_GET_PARAM,
2976 CHARGE_STATE_CMD_SET_PARAM,
2977 CHARGE_STATE_NUM_CMDS
2978};
2979
2980/*
2981 * Known param numbers are defined here. Ranges are reserved for board-specific
2982 * params, which are handled by the particular implementations.
2983 */
2984enum charge_state_params {
2985 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2986 CS_PARAM_CHG_CURRENT, /* charger current limit */
2987 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2988 CS_PARAM_CHG_STATUS, /* charger-specific status */
2989 CS_PARAM_CHG_OPTION, /* charger-specific options */
Duncan Laurieeb316852015-12-01 18:51:18 -08002990 CS_PARAM_LIMIT_POWER, /*
2991 * Check if power is limited due to
2992 * low battery and / or a weak external
2993 * charger. READ ONLY.
2994 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002995 /* How many so far? */
2996 CS_NUM_BASE_PARAMS,
2997
2998 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2999 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3000 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3001
3002 /* Other custom param ranges go here... */
3003};
3004
3005struct ec_params_charge_state {
3006 uint8_t cmd; /* enum charge_state_command */
3007 union {
3008 struct {
3009 /* no args */
3010 } get_state;
3011
3012 struct {
3013 uint32_t param; /* enum charge_state_param */
3014 } get_param;
3015
3016 struct {
3017 uint32_t param; /* param to set */
3018 uint32_t value; /* value to set */
3019 } set_param;
3020 };
3021} __packed;
3022
3023struct ec_response_charge_state {
3024 union {
3025 struct {
3026 int ac;
3027 int chg_voltage;
3028 int chg_current;
3029 int chg_input_current;
3030 int batt_state_of_charge;
3031 } get_state;
3032
3033 struct {
3034 uint32_t value;
3035 } get_param;
3036 struct {
3037 /* no return values */
3038 } set_param;
3039 };
3040} __packed;
3041
Duncan Laurie433432b2013-06-03 10:38:22 -07003042
3043/*
3044 * Set maximum battery charging current.
3045 */
3046#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
3047
3048struct ec_params_current_limit {
3049 uint32_t limit; /* in mA */
3050} __packed;
3051
3052/*
Duncan Laurieeb316852015-12-01 18:51:18 -08003053 * Set maximum external voltage / current.
Duncan Laurie433432b2013-06-03 10:38:22 -07003054 */
Duncan Laurieeb316852015-12-01 18:51:18 -08003055#define EC_CMD_EXTERNAL_POWER_LIMIT 0xa2
Duncan Laurie433432b2013-06-03 10:38:22 -07003056
Duncan Laurieeb316852015-12-01 18:51:18 -08003057/* Command v0 is used only on Spring and is obsolete + unsupported */
3058struct ec_params_external_power_limit_v1 {
3059 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3060 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
Duncan Laurie433432b2013-06-03 10:38:22 -07003061} __packed;
3062
Duncan Laurieeb316852015-12-01 18:51:18 -08003063#define EC_POWER_LIMIT_NONE 0xffff
3064
3065/*****************************************************************************/
3066/* Hibernate/Deep Sleep Commands */
3067
3068/* Set the delay before going into hibernation. */
3069#define EC_CMD_HIBERNATION_DELAY 0xa8
3070
3071struct ec_params_hibernation_delay {
3072 /*
3073 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3074 * current settings without changing them.
3075 */
3076 uint32_t seconds;
3077};
3078
3079struct ec_response_hibernation_delay {
3080 /*
3081 * The current time in seconds in which the system has been in the G3
3082 * state. This value is reset if the EC transitions out of G3.
3083 */
3084 uint32_t time_g3;
3085
3086 /*
3087 * The current time remaining in seconds until the EC should hibernate.
3088 * This value is also reset if the EC transitions out of G3.
3089 */
3090 uint32_t time_remaining;
3091
3092 /*
3093 * The current time in seconds that the EC should wait in G3 before
3094 * hibernating.
3095 */
3096 uint32_t hibernate_delay;
3097};
3098
3099
Duncan Laurie433432b2013-06-03 10:38:22 -07003100/*****************************************************************************/
3101/* Smart battery pass-through */
3102
3103/* Get / Set 16-bit smart battery registers */
3104#define EC_CMD_SB_READ_WORD 0xb0
3105#define EC_CMD_SB_WRITE_WORD 0xb1
3106
3107/* Get / Set string smart battery parameters
3108 * formatted as SMBUS "block".
3109 */
3110#define EC_CMD_SB_READ_BLOCK 0xb2
3111#define EC_CMD_SB_WRITE_BLOCK 0xb3
3112
3113struct ec_params_sb_rd {
3114 uint8_t reg;
3115} __packed;
3116
3117struct ec_response_sb_rd_word {
3118 uint16_t value;
3119} __packed;
3120
3121struct ec_params_sb_wr_word {
3122 uint8_t reg;
3123 uint16_t value;
3124} __packed;
3125
3126struct ec_response_sb_rd_block {
3127 uint8_t data[32];
3128} __packed;
3129
3130struct ec_params_sb_wr_block {
3131 uint8_t reg;
3132 uint16_t data[32];
3133} __packed;
3134
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003135
3136/*****************************************************************************/
3137/* Battery vendor parameters
3138 *
3139 * Get or set vendor-specific parameters in the battery. Implementations may
3140 * differ between boards or batteries. On a set operation, the response
3141 * contains the actual value set, which may be rounded or clipped from the
3142 * requested value.
3143 */
3144
3145#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
3146
3147enum ec_battery_vendor_param_mode {
3148 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3149 BATTERY_VENDOR_PARAM_MODE_SET,
3150};
3151
3152struct ec_params_battery_vendor_param {
3153 uint32_t param;
3154 uint32_t value;
3155 uint8_t mode;
3156} __packed;
3157
3158struct ec_response_battery_vendor_param {
3159 uint32_t value;
3160} __packed;
3161
3162/*****************************************************************************/
3163/*
3164 * Smart Battery Firmware Update Commands
3165 */
3166#define EC_CMD_SB_FW_UPDATE 0xb5
3167
3168enum ec_sb_fw_update_subcmd {
3169 EC_SB_FW_UPDATE_PREPARE = 0x0,
3170 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3171 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3172 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3173 EC_SB_FW_UPDATE_END = 0x4,
3174 EC_SB_FW_UPDATE_STATUS = 0x5,
3175 EC_SB_FW_UPDATE_PROTECT = 0x6,
3176 EC_SB_FW_UPDATE_MAX = 0x7,
3177};
3178
3179#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3180#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3181#define SB_FW_UPDATE_CMD_INFO_SIZE 8
3182
3183struct ec_sb_fw_update_header {
3184 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3185 uint16_t fw_id; /* firmware id */
3186} __packed;
3187
3188struct ec_params_sb_fw_update {
3189 struct ec_sb_fw_update_header hdr;
3190 union {
3191 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3192 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3193 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3194 /* EC_SB_FW_UPDATE_END = 0x4 */
3195 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3196 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
3197 struct {
3198 /* no args */
3199 } dummy;
3200
3201 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
3202 struct {
3203 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3204 } write;
3205 };
3206} __packed;
3207
3208struct ec_response_sb_fw_update {
3209 union {
3210 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3211 struct {
3212 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3213 } info;
3214
3215 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3216 struct {
3217 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3218 } status;
3219 };
3220} __packed;
3221
3222/*
3223 * Entering Verified Boot Mode Command
3224 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3225 * Valid Modes are: normal, developer, and recovery.
3226 */
3227#define EC_CMD_ENTERING_MODE 0xb6
3228
3229struct ec_params_entering_mode {
3230 int vboot_mode;
3231} __packed;
3232
3233#define VBOOT_MODE_NORMAL 0
3234#define VBOOT_MODE_DEVELOPER 1
3235#define VBOOT_MODE_RECOVERY 2
3236
Duncan Laurie433432b2013-06-03 10:38:22 -07003237/*****************************************************************************/
Gwendal Grignou880b4582016-06-20 08:49:25 -07003238/*
3239 * I2C passthru protection command: Protects I2C tunnels against access on
3240 * certain addresses (board-specific).
3241 */
3242#define EC_CMD_I2C_PASSTHRU_PROTECT 0xb7
3243
3244enum ec_i2c_passthru_protect_subcmd {
3245 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3246 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3247};
3248
3249struct ec_params_i2c_passthru_protect {
3250 uint8_t subcmd;
3251 uint8_t port; /* I2C port number */
3252} __packed;
3253
3254struct ec_response_i2c_passthru_protect {
3255 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
3256} __packed;
3257
3258/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003259/* System commands */
3260
3261/*
Duncan Laurie93e24442014-01-06 12:30:52 -08003262 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3263 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003264 */
3265#define EC_CMD_REBOOT_EC 0xd2
3266
3267/* Command */
3268enum ec_reboot_cmd {
3269 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003270 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3271 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003272 /* (command 3 was jump to RW-B) */
3273 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07003274 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3275 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003276};
3277
3278/* Flags for ec_params_reboot_ec.reboot_flags */
3279#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
Duncan Laurie433432b2013-06-03 10:38:22 -07003280#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003281
3282struct ec_params_reboot_ec {
3283 uint8_t cmd; /* enum ec_reboot_cmd */
3284 uint8_t flags; /* See EC_REBOOT_FLAG_* */
3285} __packed;
3286
Duncan Laurie433432b2013-06-03 10:38:22 -07003287/*
3288 * Get information on last EC panic.
3289 *
3290 * Returns variable-length platform-dependent panic information. See panic.h
3291 * for details.
3292 */
3293#define EC_CMD_GET_PANIC_INFO 0xd3
3294
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003295/*****************************************************************************/
3296/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003297 * Special commands
3298 *
3299 * These do not follow the normal rules for commands. See each command for
3300 * details.
3301 */
3302
3303/*
3304 * Reboot NOW
3305 *
3306 * This command will work even when the EC LPC interface is busy, because the
3307 * reboot command is processed at interrupt level. Note that when the EC
3308 * reboots, the host will reboot too, so there is no response to this command.
3309 *
3310 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3311 */
3312#define EC_CMD_REBOOT 0xd1 /* Think "die" */
3313
3314/*
Duncan Laurie433432b2013-06-03 10:38:22 -07003315 * Resend last response (not supported on LPC).
3316 *
3317 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3318 * there was no previous command, or the previous command's response was too
3319 * big to save.
3320 */
3321#define EC_CMD_RESEND_RESPONSE 0xdb
3322
3323/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003324 * This header byte on a command indicate version 0. Any header byte less
3325 * than this means that we are talking to an old EC which doesn't support
3326 * versioning. In that case, we assume version 0.
3327 *
3328 * Header bytes greater than this indicate a later version. For example,
3329 * EC_CMD_VERSION0 + 1 means we are using version 1.
3330 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003331 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003332 */
3333#define EC_CMD_VERSION0 0xdc
3334
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003335/*****************************************************************************/
3336/*
3337 * PD commands
3338 *
3339 * These commands are for PD MCU communication.
3340 */
3341
3342/* EC to PD MCU exchange status command */
3343#define EC_CMD_PD_EXCHANGE_STATUS 0x100
Duncan Laurieeb316852015-12-01 18:51:18 -08003344#define EC_VER_PD_EXCHANGE_STATUS 2
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003345
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003346enum pd_charge_state {
3347 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3348 PD_CHARGE_NONE, /* No charging allowed */
3349 PD_CHARGE_5V, /* 5V charging only */
3350 PD_CHARGE_MAX /* Charge at max voltage */
3351};
3352
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003353/* Status of EC being sent to PD */
Duncan Laurieeb316852015-12-01 18:51:18 -08003354#define EC_STATUS_HIBERNATING (1 << 0)
3355
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003356struct ec_params_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003357 uint8_t status; /* EC status */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003358 int8_t batt_soc; /* battery state of charge */
3359 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003360} __packed;
3361
3362/* Status of PD being sent back to EC */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003363#define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3364#define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3365#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
Duncan Laurieeb316852015-12-01 18:51:18 -08003366#define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
3367#define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
3368#define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
3369#define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
3370#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
3371 PD_STATUS_TCPC_ALERT_1 | \
3372 PD_STATUS_HOST_EVENT)
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003373struct ec_response_pd_status {
Duncan Laurieeb316852015-12-01 18:51:18 -08003374 uint32_t curr_lim_ma; /* input current limit */
3375 uint16_t status; /* PD MCU status */
3376 int8_t active_charge_port; /* active charging port */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003377} __packed;
3378
3379/* AP to PD MCU host event status command, cleared on read */
3380#define EC_CMD_PD_HOST_EVENT_STATUS 0x104
3381
3382/* PD MCU host event status bits */
3383#define PD_EVENT_UPDATE_DEVICE (1 << 0)
3384#define PD_EVENT_POWER_CHANGE (1 << 1)
3385#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
Duncan Laurieeb316852015-12-01 18:51:18 -08003386#define PD_EVENT_DATA_SWAP (1 << 3)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003387struct ec_response_host_event_status {
3388 uint32_t status; /* PD MCU host event status */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003389} __packed;
3390
3391/* Set USB type-C port role and muxes */
3392#define EC_CMD_USB_PD_CONTROL 0x101
3393
3394enum usb_pd_control_role {
3395 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3396 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3397 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3398 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3399 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3400 USB_PD_CTRL_ROLE_COUNT
3401};
3402
3403enum usb_pd_control_mux {
3404 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3405 USB_PD_CTRL_MUX_NONE = 1,
3406 USB_PD_CTRL_MUX_USB = 2,
3407 USB_PD_CTRL_MUX_DP = 3,
3408 USB_PD_CTRL_MUX_DOCK = 4,
3409 USB_PD_CTRL_MUX_AUTO = 5,
3410 USB_PD_CTRL_MUX_COUNT
3411};
3412
Duncan Laurieeb316852015-12-01 18:51:18 -08003413enum usb_pd_control_swap {
3414 USB_PD_CTRL_SWAP_NONE = 0,
3415 USB_PD_CTRL_SWAP_DATA = 1,
3416 USB_PD_CTRL_SWAP_POWER = 2,
3417 USB_PD_CTRL_SWAP_VCONN = 3,
3418 USB_PD_CTRL_SWAP_COUNT
3419};
3420
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003421struct ec_params_usb_pd_control {
3422 uint8_t port;
3423 uint8_t role;
3424 uint8_t mux;
Duncan Laurieeb316852015-12-01 18:51:18 -08003425 uint8_t swap;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003426} __packed;
3427
Duncan Laurieeb316852015-12-01 18:51:18 -08003428#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3429#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3430#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3431
3432#define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
3433#define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
3434#define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
3435#define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
3436#define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
3437#define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
3438#define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
3439
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003440struct ec_response_usb_pd_control {
3441 uint8_t enabled;
3442 uint8_t role;
3443 uint8_t polarity;
3444 uint8_t state;
3445} __packed;
3446
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003447struct ec_response_usb_pd_control_v1 {
3448 uint8_t enabled;
Duncan Laurieeb316852015-12-01 18:51:18 -08003449 uint8_t role;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003450 uint8_t polarity;
3451 char state[32];
3452} __packed;
3453
3454#define EC_CMD_USB_PD_PORTS 0x102
3455
3456struct ec_response_usb_pd_ports {
3457 uint8_t num_ports;
3458} __packed;
3459
3460#define EC_CMD_USB_PD_POWER_INFO 0x103
3461
3462#define PD_POWER_CHARGING_PORT 0xff
3463struct ec_params_usb_pd_power_info {
3464 uint8_t port;
3465} __packed;
3466
3467enum usb_chg_type {
3468 USB_CHG_TYPE_NONE,
3469 USB_CHG_TYPE_PD,
3470 USB_CHG_TYPE_C,
3471 USB_CHG_TYPE_PROPRIETARY,
3472 USB_CHG_TYPE_BC12_DCP,
3473 USB_CHG_TYPE_BC12_CDP,
3474 USB_CHG_TYPE_BC12_SDP,
3475 USB_CHG_TYPE_OTHER,
3476 USB_CHG_TYPE_VBUS,
Duncan Laurieeb316852015-12-01 18:51:18 -08003477 USB_CHG_TYPE_UNKNOWN,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003478};
3479enum usb_power_roles {
3480 USB_PD_PORT_POWER_DISCONNECTED,
3481 USB_PD_PORT_POWER_SOURCE,
3482 USB_PD_PORT_POWER_SINK,
3483 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3484};
3485
3486struct usb_chg_measures {
3487 uint16_t voltage_max;
3488 uint16_t voltage_now;
3489 uint16_t current_max;
Duncan Laurieeb316852015-12-01 18:51:18 -08003490 uint16_t current_lim;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003491} __packed;
3492
3493struct ec_response_usb_pd_power_info {
3494 uint8_t role;
3495 uint8_t type;
3496 uint8_t dualrole;
3497 uint8_t reserved1;
3498 struct usb_chg_measures meas;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003499 uint32_t max_power;
3500} __packed;
3501
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003502/* Write USB-PD device FW */
3503#define EC_CMD_USB_PD_FW_UPDATE 0x110
3504
3505enum usb_pd_fw_update_cmds {
3506 USB_PD_FW_REBOOT,
3507 USB_PD_FW_FLASH_ERASE,
3508 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003509 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003510};
3511
3512struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003513 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003514 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003515 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003516 uint32_t size; /* Size to write in bytes */
3517 /* Followed by data to write */
3518} __packed;
3519
3520/* Write USB-PD Accessory RW_HASH table entry */
3521#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003522/* RW hash is first 20 bytes of SHA-256 of RW section */
3523#define PD_RW_HASH_SIZE 20
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003524struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003525 uint16_t dev_id;
3526 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
3527 uint8_t reserved; /* For alignment of current_image */
3528 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003529} __packed;
3530
3531/* Read USB-PD Accessory info */
3532#define EC_CMD_USB_PD_DEV_INFO 0x112
3533
3534struct ec_params_usb_pd_info_request {
3535 uint8_t port;
3536} __packed;
3537
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003538/* Read USB-PD Device discovery info */
3539#define EC_CMD_USB_PD_DISCOVERY 0x113
3540struct ec_params_usb_pd_discovery_entry {
3541 uint16_t vid; /* USB-IF VID */
3542 uint16_t pid; /* USB-IF PID */
3543 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3544} __packed;
3545
3546/* Override default charge behavior */
3547#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x114
3548
3549/* Negative port parameters have special meaning */
3550enum usb_pd_override_ports {
3551 OVERRIDE_DONT_CHARGE = -2,
3552 OVERRIDE_OFF = -1,
Duncan Laurieeb316852015-12-01 18:51:18 -08003553 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003554};
3555
3556struct ec_params_charge_port_override {
3557 int16_t override_port; /* Override port# */
3558} __packed;
3559
3560/* Read (and delete) one entry of PD event log */
3561#define EC_CMD_PD_GET_LOG_ENTRY 0x115
3562
3563struct ec_response_pd_log {
3564 uint32_t timestamp; /* relative timestamp in milliseconds */
3565 uint8_t type; /* event type : see PD_EVENT_xx below */
3566 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3567 uint16_t data; /* type-defined data payload */
3568 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3569} __packed;
3570
3571
3572/* The timestamp is the microsecond counter shifted to get about a ms. */
3573#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
3574
Duncan Laurieeb316852015-12-01 18:51:18 -08003575#define PD_LOG_SIZE_MASK 0x1f
3576#define PD_LOG_PORT_MASK 0xe0
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003577#define PD_LOG_PORT_SHIFT 5
3578#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
3579 ((size) & PD_LOG_SIZE_MASK))
3580#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
3581#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
3582
3583/* PD event log : entry types */
3584/* PD MCU events */
3585#define PD_EVENT_MCU_BASE 0x00
3586#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
3587#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
3588/* Reserved for custom board event */
3589#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
3590/* PD generic accessory events */
3591#define PD_EVENT_ACC_BASE 0x20
3592#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
3593#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
3594/* PD power supply events */
3595#define PD_EVENT_PS_BASE 0x40
3596#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
3597/* PD video dongles events */
3598#define PD_EVENT_VIDEO_BASE 0x60
3599#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
3600#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
3601/* Returned in the "type" field, when there is no entry available */
Duncan Laurieeb316852015-12-01 18:51:18 -08003602#define PD_EVENT_NO_ENTRY 0xff
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003603
3604/*
3605 * PD_EVENT_MCU_CHARGE event definition :
3606 * the payload is "struct usb_chg_measures"
3607 * the data field contains the port state flags as defined below :
3608 */
3609/* Port partner is a dual role device */
3610#define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
3611/* Port is the pending override port */
3612#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
3613/* Port is the override port */
3614#define CHARGE_FLAGS_OVERRIDE (1 << 13)
3615/* Charger type */
3616#define CHARGE_FLAGS_TYPE_SHIFT 3
Duncan Laurieeb316852015-12-01 18:51:18 -08003617#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07003618/* Power delivery role */
3619#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
3620
3621/*
3622 * PD_EVENT_PS_FAULT data field flags definition :
3623 */
3624#define PS_FAULT_OCP 1
3625#define PS_FAULT_FAST_OCP 2
3626#define PS_FAULT_OVP 3
3627#define PS_FAULT_DISCH 4
3628
3629/*
3630 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
3631 */
3632struct mcdp_version {
3633 uint8_t major;
3634 uint8_t minor;
3635 uint16_t build;
3636} __packed;
3637
3638struct mcdp_info {
3639 uint8_t family[2];
3640 uint8_t chipid[2];
3641 struct mcdp_version irom;
3642 struct mcdp_version fw;
3643} __packed;
3644
3645/* struct mcdp_info field decoding */
3646#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3647#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3648
3649/* Get/Set USB-PD Alternate mode info */
3650#define EC_CMD_USB_PD_GET_AMODE 0x116
3651struct ec_params_usb_pd_get_mode_request {
3652 uint16_t svid_idx; /* SVID index to get */
3653 uint8_t port; /* port */
3654} __packed;
3655
3656struct ec_params_usb_pd_get_mode_response {
3657 uint16_t svid; /* SVID */
3658 uint16_t opos; /* Object Position */
3659 uint32_t vdo[6]; /* Mode VDOs */
3660} __packed;
3661
3662#define EC_CMD_USB_PD_SET_AMODE 0x117
3663
3664enum pd_mode_cmd {
3665 PD_EXIT_MODE = 0,
3666 PD_ENTER_MODE = 1,
3667 /* Not a command. Do NOT remove. */
3668 PD_MODE_CMD_COUNT,
3669};
3670
3671struct ec_params_usb_pd_set_mode_request {
3672 uint32_t cmd; /* enum pd_mode_cmd */
3673 uint16_t svid; /* SVID to set */
3674 uint8_t opos; /* Object Position */
3675 uint8_t port; /* port */
3676} __packed;
3677
3678/* Ask the PD MCU to record a log of a requested type */
3679#define EC_CMD_PD_WRITE_LOG_ENTRY 0x118
3680
3681struct ec_params_pd_write_log_entry {
3682 uint8_t type; /* event type : see PD_EVENT_xx above */
3683 uint8_t port; /* port#, or 0 for events unrelated to a given port */
3684} __packed;
3685
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003686
Gwendal Grignou880b4582016-06-20 08:49:25 -07003687/* Control USB-PD chip */
3688#define EC_CMD_PD_CONTROL 0x119
3689
3690enum ec_pd_control_cmd {
3691 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
3692 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
3693 PD_RESET, /* Force reset the PD chip */
3694 PD_CONTROL_DISABLE /* Disable further calls to this command */
3695};
3696
3697struct ec_params_pd_control {
3698 uint8_t chip; /* chip id (should be 0) */
3699 uint8_t subcmd;
3700} __packed;
3701
3702#endif /* !__ACPI__ */
Duncan Laurieeb316852015-12-01 18:51:18 -08003703
3704/*****************************************************************************/
3705/*
3706 * Blob commands are just opaque chunks of data, sent with proto v3.
3707 * params is struct ec_host_request, response is struct ec_host_response.
3708 */
3709#define EC_CMD_BLOB 0x200
3710
3711/*****************************************************************************/
3712/*
3713 * Reserve a range of host commands for board-specific, experimental, or
3714 * special purpose features. These can be (re)used without updating this file.
3715 *
3716 * CAUTION: Don't go nuts with this. Shipping products should document ALL
3717 * their EC commands for easier development, testing, debugging, and support.
3718 *
3719 * In your experimental code, you may want to do something like this:
3720 *
3721 * #define EC_CMD_MAGIC_FOO (EC_CMD_BOARD_SPECIFIC_BASE + 0x000)
3722 * #define EC_CMD_MAGIC_BAR (EC_CMD_BOARD_SPECIFIC_BASE + 0x001)
3723 * #define EC_CMD_MAGIC_HEY (EC_CMD_BOARD_SPECIFIC_BASE + 0x002)
3724 */
3725#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
3726#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
3727
Duncan Laurie93e24442014-01-06 12:30:52 -08003728/*****************************************************************************/
3729/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003730 * Passthru commands
3731 *
3732 * Some platforms have sub-processors chained to each other. For example.
3733 *
3734 * AP <--> EC <--> PD MCU
3735 *
3736 * The top 2 bits of the command number are used to indicate which device the
3737 * command is intended for. Device 0 is always the device receiving the
3738 * command; other device mapping is board-specific.
3739 *
3740 * When a device receives a command to be passed to a sub-processor, it passes
3741 * it on with the device number set back to 0. This allows the sub-processor
3742 * to remain blissfully unaware of whether the command originated on the next
3743 * device up the chain, or was passed through from the AP.
3744 *
3745 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3746 * AP sends command 0x4002 to the EC
3747 * EC sends command 0x0002 to the PD MCU
3748 * EC forwards PD MCU response back to the AP
3749 */
3750
3751/* Offset and max command number for sub-device n */
3752#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3753#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3754
3755/*****************************************************************************/
3756/*
Duncan Laurie93e24442014-01-06 12:30:52 -08003757 * Deprecated constants. These constants have been renamed for clarity. The
3758 * meaning and size has not changed. Programs that use the old names should
3759 * switch to the new names soon, as the old names may not be carried forward
3760 * forever.
3761 */
3762#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3763#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3764#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3765
Duncan Laurieeb316852015-12-01 18:51:18 -08003766#endif /* __CROS_EC_EC_COMMANDS_H */