blob: ac6c09029b8c931ec00f3d916f867cfd9be7a518 [file] [log] [blame]
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6/* Host communication command constants for Chrome EC */
7
8#ifndef __CROS_EC_COMMANDS_H
9#define __CROS_EC_COMMANDS_H
10
11/*
Duncan Laurie93e24442014-01-06 12:30:52 -080012 * Current version of this protocol
Stefan Reinauerd6682e82013-02-21 15:39:35 -080013 *
Duncan Laurie93e24442014-01-06 12:30:52 -080014 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
15 * determined in other ways. Remove this once the kernel code no longer
16 * depends on it.
Stefan Reinauerd6682e82013-02-21 15:39:35 -080017 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080018#define EC_PROTO_VERSION 0x00000002
19
20/* Command version mask */
21#define EC_VER_MASK(version) (1UL << (version))
22
23/* I/O addresses for ACPI commands */
24#define EC_LPC_ADDR_ACPI_DATA 0x62
25#define EC_LPC_ADDR_ACPI_CMD 0x66
26
27/* I/O addresses for host command */
28#define EC_LPC_ADDR_HOST_DATA 0x200
29#define EC_LPC_ADDR_HOST_CMD 0x204
30
31/* I/O addresses for host command args and params */
Duncan Laurie93e24442014-01-06 12:30:52 -080032/* Protocol version 2 */
33#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
34#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
35 * EC_PROTO2_MAX_PARAM_SIZE */
36/* Protocol version 3 */
37#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
38#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080039
Bill Richardsone221aad2013-06-12 10:50:41 -070040/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
41 * and they tell the kernel that so we have to think of it as two parts. */
42#define EC_HOST_CMD_REGION0 0x800
43#define EC_HOST_CMD_REGION1 0x880
44#define EC_HOST_CMD_REGION_SIZE 0x80
45
Stefan Reinauerd6682e82013-02-21 15:39:35 -080046/* EC command register bit functions */
47#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
48#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
49#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
50#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
51#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
52#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
53#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
54
55#define EC_LPC_ADDR_MEMMAP 0x900
56#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
57#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
58
59/* The offset address of each type of data in mapped memory. */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070060#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
61#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
62#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
63#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080064#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
65#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
66#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
67#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
68#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070069#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
70/* Unused 0x28 - 0x2f */
71#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
72/* Unused 0x31 - 0x33 */
73#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
74/* Reserve 0x38 - 0x3f for additional host event-related stuff */
75/* Battery values are all 32 bits */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080076#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
77#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
78#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
79#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
80#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
81#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
82#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
83#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070084/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -080085#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
86#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
87#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
88#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070089#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
90/* Unused 0x84 - 0x8f */
91#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
92/* Unused 0x91 */
93#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
94#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -070095/* Unused 0xa6 - 0xdf */
Duncan Laurie8caa80b2014-09-18 12:48:06 -070096
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -070097/*
98 * ACPI is unable to access memory mapped data at or above this offset due to
99 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
100 * which might be needed by ACPI.
101 */
102#define EC_MEMMAP_NO_ACPI 0xe0
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700103
104/* Define the format of the accelerometer mapped memory status byte. */
105#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
106#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
107#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800108
109/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
110#define EC_TEMP_SENSOR_ENTRIES 16
111/*
112 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
113 *
114 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
115 */
Duncan Laurie433432b2013-06-03 10:38:22 -0700116#define EC_TEMP_SENSOR_B_ENTRIES 8
Duncan Laurie93e24442014-01-06 12:30:52 -0800117
118/* Special values for mapped temperature sensors */
Duncan Laurie433432b2013-06-03 10:38:22 -0700119#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
120#define EC_TEMP_SENSOR_ERROR 0xfe
121#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
122#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800123/*
124 * The offset of temperature value stored in mapped memory. This allows
125 * reporting a temperature range of 200K to 454K = -73C to 181C.
126 */
127#define EC_TEMP_SENSOR_OFFSET 200
128
Duncan Laurie93e24442014-01-06 12:30:52 -0800129/*
130 * Number of ALS readings at EC_MEMMAP_ALS
131 */
132#define EC_ALS_ENTRIES 2
133
134/*
135 * The default value a temperature sensor will return when it is present but
136 * has not been read this boot. This is a reasonable number to avoid
137 * triggering alarms on the host.
138 */
139#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
140
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800141#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
142#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
143#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
144
145/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
146#define EC_BATT_FLAG_AC_PRESENT 0x01
147#define EC_BATT_FLAG_BATT_PRESENT 0x02
148#define EC_BATT_FLAG_DISCHARGING 0x04
149#define EC_BATT_FLAG_CHARGING 0x08
150#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
151
152/* Switch flags at EC_MEMMAP_SWITCHES */
153#define EC_SWITCH_LID_OPEN 0x01
154#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
155#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Duncan Laurie433432b2013-06-03 10:38:22 -0700156/* Was recovery requested via keyboard; now unused. */
157#define EC_SWITCH_IGNORE1 0x08
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800158/* Recovery requested via dedicated signal (from servo board) */
159#define EC_SWITCH_DEDICATED_RECOVERY 0x10
160/* Was fake developer mode switch; now unused. Remove in next refactor. */
161#define EC_SWITCH_IGNORE0 0x20
162
163/* Host command interface flags */
164/* Host command interface supports LPC args (LPC interface only) */
165#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800166/* Host command interface supports version 3 protocol */
167#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800168
169/* Wireless switch flags */
Duncan Laurie93e24442014-01-06 12:30:52 -0800170#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
171#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
172#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
173#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
174#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800175
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700176/*****************************************************************************/
177/*
178 * ACPI commands
179 *
180 * These are valid ONLY on the ACPI command/data port.
181 */
182
183/*
184 * ACPI Read Embedded Controller
185 *
186 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
187 *
188 * Use the following sequence:
189 *
190 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
191 * - Wait for EC_LPC_CMDR_PENDING bit to clear
192 * - Write address to EC_LPC_ADDR_ACPI_DATA
193 * - Wait for EC_LPC_CMDR_DATA bit to set
194 * - Read value from EC_LPC_ADDR_ACPI_DATA
195 */
196#define EC_CMD_ACPI_READ 0x80
197
198/*
199 * ACPI Write Embedded Controller
200 *
201 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
202 *
203 * Use the following sequence:
204 *
205 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
206 * - Wait for EC_LPC_CMDR_PENDING bit to clear
207 * - Write address to EC_LPC_ADDR_ACPI_DATA
208 * - Wait for EC_LPC_CMDR_PENDING bit to clear
209 * - Write value to EC_LPC_ADDR_ACPI_DATA
210 */
211#define EC_CMD_ACPI_WRITE 0x81
212
213/*
214 * ACPI Burst Enable Embedded Controller
215 *
216 * This enables burst mode on the EC to allow the host to issue several
217 * commands back-to-back. While in this mode, writes to mapped multi-byte
218 * data are locked out to ensure data consistency.
219 */
220#define EC_CMD_ACPI_BURST_ENABLE 0x82
221
222/*
223 * ACPI Burst Disable Embedded Controller
224 *
225 * This disables burst mode on the EC and stops preventing EC writes to mapped
226 * multi-byte data.
227 */
228#define EC_CMD_ACPI_BURST_DISABLE 0x83
229
230/*
231 * ACPI Query Embedded Controller
232 *
233 * This clears the lowest-order bit in the currently pending host events, and
234 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
235 * event 0x80000000 = 32), or 0 if no event was pending.
236 */
237#define EC_CMD_ACPI_QUERY_EVENT 0x84
238
239/* Valid addresses in ACPI memory space, for read/write commands */
240
241/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
242#define EC_ACPI_MEM_VERSION 0x00
243/*
244 * Test location; writing value here updates test compliment byte to (0xff -
245 * value).
246 */
247#define EC_ACPI_MEM_TEST 0x01
248/* Test compliment; writes here are ignored. */
249#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
250
251/* Keyboard backlight brightness percent (0 - 100) */
252#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
253/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
254#define EC_ACPI_MEM_FAN_DUTY 0x04
255
256/*
257 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
258 * independent thresholds attached to them. The current value of the ID
259 * register determines which sensor is affected by the THRESHOLD and COMMIT
260 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
261 * as the memory-mapped sensors. The COMMIT register applies those settings.
262 *
263 * The spec does not mandate any way to read back the threshold settings
264 * themselves, but when a threshold is crossed the AP needs a way to determine
265 * which sensor(s) are responsible. Each reading of the ID register clears and
266 * returns one sensor ID that has crossed one of its threshold (in either
267 * direction) since the last read. A value of 0xFF means "no new thresholds
268 * have tripped". Setting or enabling the thresholds for a sensor will clear
269 * the unread event count for that sensor.
270 */
271#define EC_ACPI_MEM_TEMP_ID 0x05
272#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
273#define EC_ACPI_MEM_TEMP_COMMIT 0x07
274/*
275 * Here are the bits for the COMMIT register:
276 * bit 0 selects the threshold index for the chosen sensor (0/1)
277 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
278 * Each write to the commit register affects one threshold.
279 */
280#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
281#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
282/*
283 * Example:
284 *
285 * Set the thresholds for sensor 2 to 50 C and 60 C:
286 * write 2 to [0x05] -- select temp sensor 2
287 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
288 * write 0x2 to [0x07] -- enable threshold 0 with this value
289 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
290 * write 0x3 to [0x07] -- enable threshold 1 with this value
291 *
292 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
293 * write 2 to [0x05] -- select temp sensor 2
294 * write 0x1 to [0x07] -- disable threshold 1
295 */
296
297/* DPTF battery charging current limit */
298#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
299
300/* Charging limit is specified in 64 mA steps */
301#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
302/* Value to disable DPTF battery charging limit */
303#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
304
305/*
306 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
307 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
308 */
309#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
310#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
311
312/* Current version of ACPI memory address space */
313#define EC_ACPI_MEM_VERSION_CURRENT 2
314
315
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800316/*
317 * This header file is used in coreboot both in C and ACPI code. The ACPI code
318 * is pre-processed to handle constants but the ASL compiler is unable to
319 * handle actual C code so keep it separate.
320 */
321#ifndef __ACPI__
322
323/*
324 * Define __packed if someone hasn't beat us to it. Linux kernel style
325 * checking prefers __packed over __attribute__((packed)).
326 */
327#ifndef __packed
328#define __packed __attribute__((packed))
329#endif
330
331/* LPC command status byte masks */
332/* EC has written a byte in the data register and host hasn't read it yet */
333#define EC_LPC_STATUS_TO_HOST 0x01
334/* Host has written a command/data byte and the EC hasn't read it yet */
335#define EC_LPC_STATUS_FROM_HOST 0x02
336/* EC is processing a command */
337#define EC_LPC_STATUS_PROCESSING 0x04
338/* Last write to EC was a command, not data */
339#define EC_LPC_STATUS_LAST_CMD 0x08
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700340/* EC is in burst mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800341#define EC_LPC_STATUS_BURST_MODE 0x10
342/* SCI event is pending (requesting SCI query) */
343#define EC_LPC_STATUS_SCI_PENDING 0x20
344/* SMI event is pending (requesting SMI query) */
345#define EC_LPC_STATUS_SMI_PENDING 0x40
346/* (reserved) */
347#define EC_LPC_STATUS_RESERVED 0x80
348
349/*
350 * EC is busy. This covers both the EC processing a command, and the host has
351 * written a new command but the EC hasn't picked it up yet.
352 */
353#define EC_LPC_STATUS_BUSY_MASK \
354 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
355
356/* Host command response codes */
357enum ec_status {
358 EC_RES_SUCCESS = 0,
359 EC_RES_INVALID_COMMAND = 1,
360 EC_RES_ERROR = 2,
361 EC_RES_INVALID_PARAM = 3,
362 EC_RES_ACCESS_DENIED = 4,
363 EC_RES_INVALID_RESPONSE = 5,
364 EC_RES_INVALID_VERSION = 6,
365 EC_RES_INVALID_CHECKSUM = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -0700366 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
367 EC_RES_UNAVAILABLE = 9, /* No response available */
368 EC_RES_TIMEOUT = 10, /* We got a timeout */
369 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800370 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
371 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700372 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700373 EC_RES_BUS_ERROR = 15, /* Communications bus error */
374 EC_RES_BUSY = 16 /* Up but too busy. Should retry */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800375};
376
377/*
378 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
379 * EC command uses code 0 to mean "no event pending". We explicitly specify
380 * each value in the enum listing so they won't change if we delete/insert an
381 * item or rearrange the list (it needs to be stable across platforms, not
382 * just within a single compiled instance).
383 */
384enum host_event_code {
385 EC_HOST_EVENT_LID_CLOSED = 1,
386 EC_HOST_EVENT_LID_OPEN = 2,
387 EC_HOST_EVENT_POWER_BUTTON = 3,
388 EC_HOST_EVENT_AC_CONNECTED = 4,
389 EC_HOST_EVENT_AC_DISCONNECTED = 5,
390 EC_HOST_EVENT_BATTERY_LOW = 6,
391 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
392 EC_HOST_EVENT_BATTERY = 8,
393 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
394 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
395 EC_HOST_EVENT_THERMAL = 11,
396 EC_HOST_EVENT_USB_CHARGER = 12,
397 EC_HOST_EVENT_KEY_PRESSED = 13,
398 /*
399 * EC has finished initializing the host interface. The host can check
400 * for this event following sending a EC_CMD_REBOOT_EC command to
401 * determine when the EC is ready to accept subsequent commands.
402 */
403 EC_HOST_EVENT_INTERFACE_READY = 14,
404 /* Keyboard recovery combo has been pressed */
405 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
406
407 /* Shutdown due to thermal overload */
408 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
409 /* Shutdown due to battery level too low */
410 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
411
Duncan Laurie93e24442014-01-06 12:30:52 -0800412 /* Suggest that the AP throttle itself */
413 EC_HOST_EVENT_THROTTLE_START = 18,
414 /* Suggest that the AP resume normal speed */
415 EC_HOST_EVENT_THROTTLE_STOP = 19,
Duncan Lauried338b462013-07-31 15:30:41 -0700416
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800417 /* Hang detect logic detected a hang and host event timeout expired */
418 EC_HOST_EVENT_HANG_DETECT = 20,
419 /* Hang detect logic detected a hang and warm rebooted the AP */
420 EC_HOST_EVENT_HANG_REBOOT = 21,
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700421
422 /* PD MCU triggering host event */
Shawn Nematbakhsh98cc94c2014-08-28 11:33:41 -0700423 EC_HOST_EVENT_PD_MCU = 22,
Duncan Lauriee6b280e2014-02-10 16:21:05 -0800424
Duncan Lauried8401182014-09-29 08:32:19 -0700425 /* Battery Status flags have changed */
426 EC_HOST_EVENT_BATTERY_STATUS = 23,
427
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700428 /* EC encountered a panic, triggering a reset */
Shawn Nematbakhsh555f7112015-02-23 15:14:54 -0800429 EC_HOST_EVENT_PANIC = 24,
430
Furquan Shaikh066cc852015-06-20 15:53:03 -0700431 /* Keyboard fastboot combo has been pressed */
432 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
433
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800434 /*
435 * The high bit of the event mask is not used as a host event code. If
436 * it reads back as set, then the entire event mask should be
437 * considered invalid by the host. This can happen when reading the
438 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
439 * not initialized on the EC, or improperly configured on the host.
440 */
441 EC_HOST_EVENT_INVALID = 32
442};
443/* Host event mask */
444#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
445
446/* Arguments at EC_LPC_ADDR_HOST_ARGS */
447struct ec_lpc_host_args {
448 uint8_t flags;
449 uint8_t command_version;
450 uint8_t data_size;
451 /*
452 * Checksum; sum of command + flags + command_version + data_size +
453 * all params/response data bytes.
454 */
455 uint8_t checksum;
456} __packed;
457
458/* Flags for ec_lpc_host_args.flags */
459/*
460 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
461 * params.
462 *
463 * If EC gets a command and this flag is not set, this is an old-style command.
464 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
465 * unknown length. EC must respond with an old-style response (that is,
Martin Roth8940d3e2013-07-09 21:52:41 -0600466 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800467 */
468#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
469/*
470 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
471 *
472 * If EC responds to a command and this flag is not set, this is an old-style
473 * response. Command version is 0 and response data from EC is at
474 * EC_LPC_ADDR_OLD_PARAM with unknown length.
475 */
476#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
477
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800478/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -0800479/*
480 * Byte codes returned by EC over SPI interface.
481 *
482 * These can be used by the AP to debug the EC interface, and to determine
483 * when the EC is not in a state where it will ever get around to responding
484 * to the AP.
485 *
486 * Example of sequence of bytes read from EC for a current good transfer:
487 * 1. - - AP asserts chip select (CS#)
488 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
489 * 3. - - EC starts handling CS# interrupt
490 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
491 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
492 * bytes looking for EC_SPI_FRAME_START
493 * 6. - - EC finishes processing and sets up response
494 * 7. EC_SPI_FRAME_START - AP reads frame byte
495 * 8. (response packet) - AP reads response packet
496 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
497 * 10 - - AP deasserts chip select
498 * 11 - - EC processes CS# interrupt and sets up DMA for
499 * next request
500 *
501 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
502 * the following byte values:
503 * EC_SPI_OLD_READY
504 * EC_SPI_RX_READY
505 * EC_SPI_RECEIVING
506 * EC_SPI_PROCESSING
507 *
508 * Then the EC found an error in the request, or was not ready for the request
509 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
510 * because the EC is unable to tell when the AP is done sending its request.
511 */
512
513/*
514 * Framing byte which precedes a response packet from the EC. After sending a
515 * request, the AP will clock in bytes until it sees the framing byte, then
516 * clock in the response packet.
517 */
518#define EC_SPI_FRAME_START 0xec
519
520/*
521 * Padding bytes which are clocked out after the end of a response packet.
522 */
523#define EC_SPI_PAST_END 0xed
524
525/*
526 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
527 * that the AP will send a valid packet header (starting with
528 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
529 */
530#define EC_SPI_RX_READY 0xf8
531
532/*
533 * EC has started receiving the request from the AP, but hasn't started
534 * processing it yet.
535 */
536#define EC_SPI_RECEIVING 0xf9
537
538/* EC has received the entire request from the AP and is processing it. */
539#define EC_SPI_PROCESSING 0xfa
540
541/*
542 * EC received bad data from the AP, such as a packet header with an invalid
543 * length. EC will ignore all data until chip select deasserts.
544 */
545#define EC_SPI_RX_BAD_DATA 0xfb
546
547/*
548 * EC received data from the AP before it was ready. That is, the AP asserted
549 * chip select and started clocking data before the EC was ready to receive it.
550 * EC will ignore all data until chip select deasserts.
551 */
552#define EC_SPI_NOT_READY 0xfc
553
554/*
555 * EC was ready to receive a request from the AP. EC has treated the byte sent
556 * by the AP as part of a request packet, or (for old-style ECs) is processing
557 * a fully received packet but is not ready to respond yet.
558 */
559#define EC_SPI_OLD_READY 0xfd
560
561/*****************************************************************************/
562
563/*
564 * Protocol version 2 for I2C and SPI send a request this way:
565 *
566 * 0 EC_CMD_VERSION0 + (command version)
567 * 1 Command number
568 * 2 Length of params = N
569 * 3..N+2 Params, if any
570 * N+3 8-bit checksum of bytes 0..N+2
571 *
572 * The corresponding response is:
573 *
574 * 0 Result code (EC_RES_*)
575 * 1 Length of params = M
576 * 2..M+1 Params, if any
577 * M+2 8-bit checksum of bytes 0..M+1
578 */
579#define EC_PROTO2_REQUEST_HEADER_BYTES 3
580#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
581#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
582 EC_PROTO2_REQUEST_TRAILER_BYTES)
583
584#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
585#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
586#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
587 EC_PROTO2_RESPONSE_TRAILER_BYTES)
588
589/* Parameter length was limited by the LPC interface */
590#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
591
592/* Maximum request and response packet sizes for protocol version 2 */
593#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
594 EC_PROTO2_MAX_PARAM_SIZE)
595#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
596 EC_PROTO2_MAX_PARAM_SIZE)
597
598/*****************************************************************************/
Hung-Te Lince7a5a72013-06-20 18:57:04 +0800599
600/*
601 * Value written to legacy command port / prefix byte to indicate protocol
602 * 3+ structs are being used. Usage is bus-dependent.
603 */
604#define EC_COMMAND_PROTOCOL_3 0xda
605
606#define EC_HOST_REQUEST_VERSION 3
607
608/* Version 3 request from host */
609struct ec_host_request {
610 /* Struct version (=3)
611 *
612 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
613 * version it doesn't know how to parse.
614 */
615 uint8_t struct_version;
616
617 /*
618 * Checksum of request and data; sum of all bytes including checksum
619 * should total to 0.
620 */
621 uint8_t checksum;
622
623 /* Command code */
624 uint16_t command;
625
626 /* Command version */
627 uint8_t command_version;
628
629 /* Unused byte in current protocol version; set to 0 */
630 uint8_t reserved;
631
632 /* Length of data which follows this header */
633 uint16_t data_len;
634} __packed;
635
636#define EC_HOST_RESPONSE_VERSION 3
637
638/* Version 3 response from EC */
639struct ec_host_response {
640 /* Struct version (=3) */
641 uint8_t struct_version;
642
643 /*
644 * Checksum of response and data; sum of all bytes including checksum
645 * should total to 0.
646 */
647 uint8_t checksum;
648
649 /* Result code (EC_RES_*) */
650 uint16_t result;
651
652 /* Length of data which follows this header */
653 uint16_t data_len;
654
655 /* Unused bytes in current protocol version; set to 0 */
656 uint16_t reserved;
657} __packed;
658
659/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800660/*
661 * Notes on commands:
662 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -0700663 * Each command is an 16-bit command value. Commands which take params or
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800664 * return response data specify structs for that data. If no struct is
665 * specified, the command does not input or output data, respectively.
666 * Parameter/response length is implicit in the structs. Some underlying
667 * communication protocols (I2C, SPI) may add length or checksum headers, but
668 * those are implementation-dependent and not defined here.
669 */
670
671/*****************************************************************************/
672/* General / test commands */
673
674/*
675 * Get protocol version, used to deal with non-backward compatible protocol
676 * changes.
677 */
678#define EC_CMD_PROTO_VERSION 0x00
679
680struct ec_response_proto_version {
681 uint32_t version;
682} __packed;
683
684/*
685 * Hello. This is a simple command to test the EC is responsive to
686 * commands.
687 */
688#define EC_CMD_HELLO 0x01
689
690struct ec_params_hello {
691 uint32_t in_data; /* Pass anything here */
692} __packed;
693
694struct ec_response_hello {
695 uint32_t out_data; /* Output will be in_data + 0x01020304 */
696} __packed;
697
698/* Get version number */
699#define EC_CMD_GET_VERSION 0x02
700
701enum ec_current_image {
702 EC_IMAGE_UNKNOWN = 0,
703 EC_IMAGE_RO,
704 EC_IMAGE_RW
705};
706
707struct ec_response_get_version {
708 /* Null-terminated version strings for RO, RW */
709 char version_string_ro[32];
710 char version_string_rw[32];
711 char reserved[32]; /* Was previously RW-B string */
712 uint32_t current_image; /* One of ec_current_image */
713} __packed;
714
715/* Read test */
716#define EC_CMD_READ_TEST 0x03
717
718struct ec_params_read_test {
719 uint32_t offset; /* Starting value for read buffer */
720 uint32_t size; /* Size to read in bytes */
721} __packed;
722
723struct ec_response_read_test {
724 uint32_t data[32];
725} __packed;
726
727/*
728 * Get build information
729 *
730 * Response is null-terminated string.
731 */
732#define EC_CMD_GET_BUILD_INFO 0x04
733
734/* Get chip info */
735#define EC_CMD_GET_CHIP_INFO 0x05
736
737struct ec_response_get_chip_info {
738 /* Null-terminated strings */
739 char vendor[32];
740 char name[32];
741 char revision[32]; /* Mask version */
742} __packed;
743
744/* Get board HW version */
745#define EC_CMD_GET_BOARD_VERSION 0x06
746
747struct ec_response_board_version {
748 uint16_t board_version; /* A monotonously incrementing number. */
749} __packed;
750
751/*
752 * Read memory-mapped data.
753 *
754 * This is an alternate interface to memory-mapped data for bus protocols
755 * which don't support direct-mapped memory - I2C, SPI, etc.
756 *
757 * Response is params.size bytes of data.
758 */
759#define EC_CMD_READ_MEMMAP 0x07
760
761struct ec_params_read_memmap {
762 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
763 uint8_t size; /* Size to read in bytes */
764} __packed;
765
766/* Read versions supported for a command */
767#define EC_CMD_GET_CMD_VERSIONS 0x08
768
769struct ec_params_get_cmd_versions {
770 uint8_t cmd; /* Command to check */
771} __packed;
772
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700773struct ec_params_get_cmd_versions_v1 {
774 uint16_t cmd; /* Command to check */
775} __packed;
776
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800777struct ec_response_get_cmd_versions {
778 /*
779 * Mask of supported versions; use EC_VER_MASK() to compare with a
780 * desired version.
781 */
782 uint32_t version_mask;
783} __packed;
784
Duncan Laurie433432b2013-06-03 10:38:22 -0700785/*
786 * Check EC communcations status (busy). This is needed on i2c/spi but not
787 * on lpc since it has its own out-of-band busy indicator.
788 *
789 * lpc must read the status from the command register. Attempting this on
790 * lpc will overwrite the args/parameter space and corrupt its data.
791 */
792#define EC_CMD_GET_COMMS_STATUS 0x09
793
794/* Avoid using ec_status which is for return values */
795enum ec_comms_status {
796 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
797};
798
799struct ec_response_get_comms_status {
800 uint32_t flags; /* Mask of enum ec_comms_status */
801} __packed;
802
Duncan Laurie93e24442014-01-06 12:30:52 -0800803/* Fake a variety of responses, purely for testing purposes. */
804#define EC_CMD_TEST_PROTOCOL 0x0a
805
806/* Tell the EC what to send back to us. */
807struct ec_params_test_protocol {
808 uint32_t ec_result;
809 uint32_t ret_len;
810 uint8_t buf[32];
811} __packed;
812
813/* Here it comes... */
814struct ec_response_test_protocol {
815 uint8_t buf[32];
816} __packed;
817
818/* Get prococol information */
819#define EC_CMD_GET_PROTOCOL_INFO 0x0b
820
821/* Flags for ec_response_get_protocol_info.flags */
822/* EC_RES_IN_PROGRESS may be returned if a command is slow */
823#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
824
825struct ec_response_get_protocol_info {
826 /* Fields which exist if at least protocol version 3 supported */
827
828 /* Bitmask of protocol versions supported (1 << n means version n)*/
829 uint32_t protocol_versions;
830
831 /* Maximum request packet size, in bytes */
832 uint16_t max_request_packet_size;
833
834 /* Maximum response packet size, in bytes */
835 uint16_t max_response_packet_size;
836
837 /* Flags; see EC_PROTOCOL_INFO_* */
838 uint32_t flags;
839} __packed;
840
841
842/*****************************************************************************/
843/* Get/Set miscellaneous values */
844
845/* The upper byte of .flags tells what to do (nothing means "get") */
846#define EC_GSV_SET 0x80000000
847
848/* The lower three bytes of .flags identifies the parameter, if that has
849 meaning for an individual command. */
850#define EC_GSV_PARAM_MASK 0x00ffffff
851
852struct ec_params_get_set_value {
853 uint32_t flags;
854 uint32_t value;
855} __packed;
856
857struct ec_response_get_set_value {
858 uint32_t flags;
859 uint32_t value;
860} __packed;
861
862/* More than one command can use these structs to get/set paramters. */
863#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
864
Duncan Laurie433432b2013-06-03 10:38:22 -0700865
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800866/*****************************************************************************/
867/* Flash commands */
868
869/* Get flash info */
870#define EC_CMD_FLASH_INFO 0x10
871
Duncan Laurie93e24442014-01-06 12:30:52 -0800872/* Version 0 returns these fields */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800873struct ec_response_flash_info {
874 /* Usable flash size, in bytes */
875 uint32_t flash_size;
876 /*
877 * Write block size. Write offset and size must be a multiple
878 * of this.
879 */
880 uint32_t write_block_size;
881 /*
882 * Erase block size. Erase offset and size must be a multiple
883 * of this.
884 */
885 uint32_t erase_block_size;
886 /*
887 * Protection block size. Protection offset and size must be a
888 * multiple of this.
889 */
890 uint32_t protect_block_size;
891} __packed;
892
Duncan Laurie93e24442014-01-06 12:30:52 -0800893/* Flags for version 1+ flash info command */
894/* EC flash erases bits to 0 instead of 1 */
895#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
896
897/*
898 * Version 1 returns the same initial fields as version 0, with additional
899 * fields following.
900 *
901 * gcc anonymous structs don't seem to get along with the __packed directive;
902 * if they did we'd define the version 0 struct as a sub-struct of this one.
903 */
904struct ec_response_flash_info_1 {
905 /* Version 0 fields; see above for description */
906 uint32_t flash_size;
907 uint32_t write_block_size;
908 uint32_t erase_block_size;
909 uint32_t protect_block_size;
910
911 /* Version 1 adds these fields: */
912 /*
913 * Ideal write size in bytes. Writes will be fastest if size is
914 * exactly this and offset is a multiple of this. For example, an EC
915 * may have a write buffer which can do half-page operations if data is
916 * aligned, and a slower word-at-a-time write mode.
917 */
918 uint32_t write_ideal_size;
919
920 /* Flags; see EC_FLASH_INFO_* */
921 uint32_t flags;
922} __packed;
923
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800924/*
925 * Read flash
926 *
927 * Response is params.size bytes of data.
928 */
929#define EC_CMD_FLASH_READ 0x11
930
931struct ec_params_flash_read {
932 uint32_t offset; /* Byte offset to read */
933 uint32_t size; /* Size to read in bytes */
934} __packed;
935
936/* Write flash */
937#define EC_CMD_FLASH_WRITE 0x12
Duncan Laurie93e24442014-01-06 12:30:52 -0800938#define EC_VER_FLASH_WRITE 1
939
940/* Version 0 of the flash command supported only 64 bytes of data */
941#define EC_FLASH_WRITE_VER0_SIZE 64
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800942
943struct ec_params_flash_write {
944 uint32_t offset; /* Byte offset to write */
945 uint32_t size; /* Size to write in bytes */
Duncan Laurie93e24442014-01-06 12:30:52 -0800946 /* Followed by data to write */
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800947} __packed;
948
949/* Erase flash */
950#define EC_CMD_FLASH_ERASE 0x13
951
952struct ec_params_flash_erase {
953 uint32_t offset; /* Byte offset to erase */
954 uint32_t size; /* Size to erase in bytes */
955} __packed;
956
957/*
958 * Get/set flash protection.
959 *
960 * If mask!=0, sets/clear the requested bits of flags. Depending on the
961 * firmware write protect GPIO, not all flags will take effect immediately;
962 * some flags require a subsequent hard reset to take effect. Check the
963 * returned flags bits to see what actually happened.
964 *
965 * If mask=0, simply returns the current flags state.
966 */
967#define EC_CMD_FLASH_PROTECT 0x15
968#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
969
970/* Flags for flash protection */
971/* RO flash code protected when the EC boots */
972#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
973/*
974 * RO flash code protected now. If this bit is set, at-boot status cannot
975 * be changed.
976 */
977#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
Duncan Laurie433432b2013-06-03 10:38:22 -0700978/* Entire flash code protected now, until reboot. */
979#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800980/* Flash write protect GPIO is asserted now */
981#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
982/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
983#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
984/*
985 * Error - flash protection is in inconsistent state. At least one bank of
986 * flash which should be protected is not protected. Usually fixed by
987 * re-requesting the desired flags, or by a hard reset if that fails.
988 */
989#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -0700990/* Entire flash code protected when the EC boots */
Duncan Laurie433432b2013-06-03 10:38:22 -0700991#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
Stefan Reinauerd6682e82013-02-21 15:39:35 -0800992
993struct ec_params_flash_protect {
994 uint32_t mask; /* Bits in flags to apply */
995 uint32_t flags; /* New flags to apply */
996} __packed;
997
998struct ec_response_flash_protect {
999 /* Current value of flash protect flags */
1000 uint32_t flags;
1001 /*
1002 * Flags which are valid on this platform. This allows the caller
1003 * to distinguish between flags which aren't set vs. flags which can't
1004 * be set on this platform.
1005 */
1006 uint32_t valid_flags;
1007 /* Flags which can be changed given the current protection state */
1008 uint32_t writable_flags;
1009} __packed;
1010
1011/*
1012 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1013 * write protect. These commands may be reused with version > 0.
1014 */
1015
1016/* Get the region offset/size */
1017#define EC_CMD_FLASH_REGION_INFO 0x16
1018#define EC_VER_FLASH_REGION_INFO 1
1019
1020enum ec_flash_region {
1021 /* Region which holds read-only EC image */
Duncan Laurie93e24442014-01-06 12:30:52 -08001022 EC_FLASH_REGION_RO = 0,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001023 /* Region which holds rewritable EC image */
1024 EC_FLASH_REGION_RW,
1025 /*
1026 * Region which should be write-protected in the factory (a superset of
1027 * EC_FLASH_REGION_RO)
1028 */
1029 EC_FLASH_REGION_WP_RO,
Duncan Laurie93e24442014-01-06 12:30:52 -08001030 /* Number of regions */
1031 EC_FLASH_REGION_COUNT,
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001032};
1033
1034struct ec_params_flash_region_info {
1035 uint32_t region; /* enum ec_flash_region */
1036} __packed;
1037
1038struct ec_response_flash_region_info {
1039 uint32_t offset;
1040 uint32_t size;
1041} __packed;
1042
Duncan Laurie433432b2013-06-03 10:38:22 -07001043/* Read/write VbNvContext */
1044#define EC_CMD_VBNV_CONTEXT 0x17
1045#define EC_VER_VBNV_CONTEXT 1
1046#define EC_VBNV_BLOCK_SIZE 16
1047
1048enum ec_vbnvcontext_op {
1049 EC_VBNV_CONTEXT_OP_READ,
1050 EC_VBNV_CONTEXT_OP_WRITE,
1051};
1052
1053struct ec_params_vbnvcontext {
1054 uint32_t op;
1055 uint8_t block[EC_VBNV_BLOCK_SIZE];
1056} __packed;
1057
1058struct ec_response_vbnvcontext {
1059 uint8_t block[EC_VBNV_BLOCK_SIZE];
1060} __packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001061
1062/*****************************************************************************/
1063/* PWM commands */
1064
1065/* Get fan target RPM */
1066#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1067
1068struct ec_response_pwm_get_fan_rpm {
1069 uint32_t rpm;
1070} __packed;
1071
1072/* Set target fan RPM */
1073#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1074
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001075/* Version 0 of input params */
1076struct ec_params_pwm_set_fan_target_rpm_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001077 uint32_t rpm;
1078} __packed;
1079
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001080/* Version 1 of input params */
1081struct ec_params_pwm_set_fan_target_rpm_v1 {
1082 uint32_t rpm;
1083 uint8_t fan_idx;
1084} __packed;
1085
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001086/* Get keyboard backlight */
1087#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1088
1089struct ec_response_pwm_get_keyboard_backlight {
1090 uint8_t percent;
1091 uint8_t enabled;
1092} __packed;
1093
1094/* Set keyboard backlight */
1095#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1096
1097struct ec_params_pwm_set_keyboard_backlight {
1098 uint8_t percent;
1099} __packed;
1100
1101/* Set target fan PWM duty cycle */
1102#define EC_CMD_PWM_SET_FAN_DUTY 0x24
1103
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001104/* Version 0 of input params */
1105struct ec_params_pwm_set_fan_duty_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001106 uint32_t percent;
1107} __packed;
1108
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001109/* Version 1 of input params */
1110struct ec_params_pwm_set_fan_duty_v1 {
1111 uint32_t percent;
1112 uint8_t fan_idx;
1113} __packed;
1114
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001115/*****************************************************************************/
1116/*
Duncan Laurie433432b2013-06-03 10:38:22 -07001117 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001118 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1119 * into a subcommand. We'll make separate structs for subcommands with
1120 * different input args, so that we know how much to expect.
1121 */
1122#define EC_CMD_LIGHTBAR_CMD 0x28
1123
Duncan Laurie433432b2013-06-03 10:38:22 -07001124struct rgb_s {
1125 uint8_t r, g, b;
1126};
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001127
Duncan Laurie433432b2013-06-03 10:38:22 -07001128#define LB_BATTERY_LEVELS 4
1129/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1130 * host command, but the alignment is the same regardless. Keep it that way.
1131 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001132struct lightbar_params_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001133 /* Timing */
Duncan Laurie93e24442014-01-06 12:30:52 -08001134 int32_t google_ramp_up;
1135 int32_t google_ramp_down;
1136 int32_t s3s0_ramp_up;
1137 int32_t s0_tick_delay[2]; /* AC=0/1 */
1138 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1139 int32_t s0s3_ramp_down;
1140 int32_t s3_sleep_for;
1141 int32_t s3_ramp_up;
1142 int32_t s3_ramp_down;
Duncan Laurie433432b2013-06-03 10:38:22 -07001143
1144 /* Oscillation */
1145 uint8_t new_s0;
1146 uint8_t osc_min[2]; /* AC=0/1 */
1147 uint8_t osc_max[2]; /* AC=0/1 */
1148 uint8_t w_ofs[2]; /* AC=0/1 */
1149
1150 /* Brightness limits based on the backlight and AC. */
1151 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1152 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1153 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1154
1155 /* Battery level thresholds */
1156 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1157
1158 /* Map [AC][battery_level] to color index */
1159 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1160 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1161
1162 /* Color palette */
1163 struct rgb_s color[8]; /* 0-3 are Google colors */
1164} __packed;
1165
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001166struct lightbar_params_v1 {
1167 /* Timing */
1168 int32_t google_ramp_up;
1169 int32_t google_ramp_down;
1170 int32_t s3s0_ramp_up;
1171 int32_t s0_tick_delay[2]; /* AC=0/1 */
1172 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1173 int32_t s0s3_ramp_down;
1174 int32_t s3_sleep_for;
1175 int32_t s3_ramp_up;
1176 int32_t s3_ramp_down;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001177 int32_t s5_ramp_up;
1178 int32_t s5_ramp_down;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001179 int32_t tap_tick_delay;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001180 int32_t tap_gate_delay;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001181 int32_t tap_display_time;
1182
1183 /* Tap-for-battery params */
1184 uint8_t tap_pct_red;
1185 uint8_t tap_pct_green;
1186 uint8_t tap_seg_min_on;
1187 uint8_t tap_seg_max_on;
1188 uint8_t tap_seg_osc;
1189 uint8_t tap_idx[3];
1190
1191 /* Oscillation */
1192 uint8_t osc_min[2]; /* AC=0/1 */
1193 uint8_t osc_max[2]; /* AC=0/1 */
1194 uint8_t w_ofs[2]; /* AC=0/1 */
1195
1196 /* Brightness limits based on the backlight and AC. */
1197 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1198 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1199 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1200
1201 /* Battery level thresholds */
1202 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1203
1204 /* Map [AC][battery_level] to color index */
1205 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1206 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1207
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001208 /* s5: single color pulse on inhibited power-up */
1209 uint8_t s5_idx;
1210
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001211 /* Color palette */
1212 struct rgb_s color[8]; /* 0-3 are Google colors */
1213} __packed;
1214
Duncan Lauried8401182014-09-29 08:32:19 -07001215/* Lightbyte program. */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001216#define EC_LB_PROG_LEN 192
1217struct lightbar_program {
Duncan Lauried8401182014-09-29 08:32:19 -07001218 uint8_t size;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001219 uint8_t data[EC_LB_PROG_LEN];
Duncan Lauried8401182014-09-29 08:32:19 -07001220};
1221
Duncan Laurie433432b2013-06-03 10:38:22 -07001222struct ec_params_lightbar {
1223 uint8_t cmd; /* Command (see enum lightbar_command) */
1224 union {
1225 struct {
1226 /* no args */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001227 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001228 version, get_brightness, get_demo, suspend, resume;
Duncan Laurie433432b2013-06-03 10:38:22 -07001229
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001230 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001231 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001232 } set_brightness, seq, demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001233
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001234 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001235 uint8_t ctrl, reg, value;
1236 } reg;
1237
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001238 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001239 uint8_t led, red, green, blue;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001240 } set_rgb;
Duncan Laurie433432b2013-06-03 10:38:22 -07001241
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001242 struct {
1243 uint8_t led;
1244 } get_rgb;
1245
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001246 struct {
1247 uint8_t enable;
1248 } manual_suspend_ctrl;
1249
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001250 struct lightbar_params_v0 set_params_v0;
1251 struct lightbar_params_v1 set_params_v1;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001252 struct lightbar_program set_program;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001253 };
1254} __packed;
1255
Duncan Laurie433432b2013-06-03 10:38:22 -07001256struct ec_response_lightbar {
1257 union {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001258 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001259 struct {
1260 uint8_t reg;
1261 uint8_t ic0;
1262 uint8_t ic1;
1263 } vals[23];
1264 } dump;
1265
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001266 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001267 uint8_t num;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001268 } get_seq, get_brightness, get_demo;
Duncan Laurie433432b2013-06-03 10:38:22 -07001269
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001270 struct lightbar_params_v0 get_params_v0;
1271 struct lightbar_params_v1 get_params_v1;
Duncan Laurie433432b2013-06-03 10:38:22 -07001272
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001273 struct {
Duncan Laurie93e24442014-01-06 12:30:52 -08001274 uint32_t num;
1275 uint32_t flags;
1276 } version;
1277
Duncan Laurie433432b2013-06-03 10:38:22 -07001278 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001279 uint8_t red, green, blue;
1280 } get_rgb;
1281
1282 struct {
Duncan Laurie433432b2013-06-03 10:38:22 -07001283 /* no return params */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001284 } off, on, init, set_brightness, seq, reg, set_rgb,
Duncan Lauried8401182014-09-29 08:32:19 -07001285 demo, set_params_v0, set_params_v1,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001286 set_program, manual_suspend_ctrl, suspend, resume;
Duncan Laurie433432b2013-06-03 10:38:22 -07001287 };
1288} __packed;
1289
1290/* Lightbar commands */
1291enum lightbar_command {
1292 LIGHTBAR_CMD_DUMP = 0,
1293 LIGHTBAR_CMD_OFF = 1,
1294 LIGHTBAR_CMD_ON = 2,
1295 LIGHTBAR_CMD_INIT = 3,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001296 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Duncan Laurie433432b2013-06-03 10:38:22 -07001297 LIGHTBAR_CMD_SEQ = 5,
1298 LIGHTBAR_CMD_REG = 6,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001299 LIGHTBAR_CMD_SET_RGB = 7,
Duncan Laurie433432b2013-06-03 10:38:22 -07001300 LIGHTBAR_CMD_GET_SEQ = 8,
1301 LIGHTBAR_CMD_DEMO = 9,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001302 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1303 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Duncan Laurie93e24442014-01-06 12:30:52 -08001304 LIGHTBAR_CMD_VERSION = 12,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001305 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1306 LIGHTBAR_CMD_GET_RGB = 14,
1307 LIGHTBAR_CMD_GET_DEMO = 15,
1308 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1309 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Duncan Lauried8401182014-09-29 08:32:19 -07001310 LIGHTBAR_CMD_SET_PROGRAM = 18,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001311 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1312 LIGHTBAR_CMD_SUSPEND = 20,
1313 LIGHTBAR_CMD_RESUME = 21,
Duncan Laurie433432b2013-06-03 10:38:22 -07001314 LIGHTBAR_NUM_CMDS
1315};
1316
1317/*****************************************************************************/
1318/* LED control commands */
1319
Bill Richardsone221aad2013-06-12 10:50:41 -07001320#define EC_CMD_LED_CONTROL 0x29
Duncan Laurie433432b2013-06-03 10:38:22 -07001321
Bill Richardsone221aad2013-06-12 10:50:41 -07001322enum ec_led_id {
Duncan Laurie93e24442014-01-06 12:30:52 -08001323 /* LED to indicate battery state of charge */
Bill Richardsone221aad2013-06-12 10:50:41 -07001324 EC_LED_ID_BATTERY_LED = 0,
Duncan Laurie93e24442014-01-06 12:30:52 -08001325 /*
1326 * LED to indicate system power state (on or in suspend).
1327 * May be on power button or on C-panel.
1328 */
1329 EC_LED_ID_POWER_LED,
1330 /* LED on power adapter or its plug */
Bill Richardsone221aad2013-06-12 10:50:41 -07001331 EC_LED_ID_ADAPTER_LED,
Duncan Laurie93e24442014-01-06 12:30:52 -08001332
1333 EC_LED_ID_COUNT
Bill Richardsone221aad2013-06-12 10:50:41 -07001334};
Duncan Laurie433432b2013-06-03 10:38:22 -07001335
Bill Richardsone221aad2013-06-12 10:50:41 -07001336/* LED control flags */
1337#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1338#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1339
1340enum ec_led_colors {
1341 EC_LED_COLOR_RED = 0,
1342 EC_LED_COLOR_GREEN,
1343 EC_LED_COLOR_BLUE,
1344 EC_LED_COLOR_YELLOW,
1345 EC_LED_COLOR_WHITE,
1346
1347 EC_LED_COLOR_COUNT
1348};
1349
1350struct ec_params_led_control {
1351 uint8_t led_id; /* Which LED to control */
1352 uint8_t flags; /* Control flags */
1353
1354 uint8_t brightness[EC_LED_COLOR_COUNT];
1355} __packed;
1356
1357struct ec_response_led_control {
1358 /*
1359 * Available brightness value range.
1360 *
1361 * Range 0 means color channel not present.
1362 * Range 1 means on/off control.
1363 * Other values means the LED is control by PWM.
1364 */
1365 uint8_t brightness_range[EC_LED_COLOR_COUNT];
Duncan Laurie433432b2013-06-03 10:38:22 -07001366} __packed;
1367
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001368/*****************************************************************************/
1369/* Verified boot commands */
1370
1371/*
1372 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1373 * reused for other purposes with version > 0.
1374 */
1375
1376/* Verified boot hash command */
1377#define EC_CMD_VBOOT_HASH 0x2A
1378
1379struct ec_params_vboot_hash {
1380 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1381 uint8_t hash_type; /* enum ec_vboot_hash_type */
1382 uint8_t nonce_size; /* Nonce size; may be 0 */
1383 uint8_t reserved0; /* Reserved; set 0 */
1384 uint32_t offset; /* Offset in flash to hash */
1385 uint32_t size; /* Number of bytes to hash */
1386 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1387} __packed;
1388
1389struct ec_response_vboot_hash {
1390 uint8_t status; /* enum ec_vboot_hash_status */
1391 uint8_t hash_type; /* enum ec_vboot_hash_type */
1392 uint8_t digest_size; /* Size of hash digest in bytes */
1393 uint8_t reserved0; /* Ignore; will be 0 */
1394 uint32_t offset; /* Offset in flash which was hashed */
1395 uint32_t size; /* Number of bytes hashed */
1396 uint8_t hash_digest[64]; /* Hash digest data */
1397} __packed;
1398
1399enum ec_vboot_hash_cmd {
Duncan Laurie433432b2013-06-03 10:38:22 -07001400 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1401 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1402 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1403 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001404};
1405
1406enum ec_vboot_hash_type {
Duncan Laurie433432b2013-06-03 10:38:22 -07001407 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001408};
1409
1410enum ec_vboot_hash_status {
Duncan Laurie433432b2013-06-03 10:38:22 -07001411 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1412 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1413 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001414};
1415
Duncan Laurie433432b2013-06-03 10:38:22 -07001416/*
1417 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1418 * If one of these is specified, the EC will automatically update offset and
1419 * size to the correct values for the specified image (RO or RW).
1420 */
1421#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1422#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1423
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001424/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001425/*
1426 * Motion sense commands. We'll make separate structs for sub-commands with
1427 * different input args, so that we know how much to expect.
1428 */
1429#define EC_CMD_MOTION_SENSE_CMD 0x2B
1430
1431/* Motion sense commands */
1432enum motionsense_command {
1433 /*
1434 * Dump command returns all motion sensor data including motion sense
1435 * module flags and individual sensor flags.
1436 */
1437 MOTIONSENSE_CMD_DUMP = 0,
1438
1439 /*
1440 * Info command returns data describing the details of a given sensor,
1441 * including enum motionsensor_type, enum motionsensor_location, and
1442 * enum motionsensor_chip.
1443 */
1444 MOTIONSENSE_CMD_INFO = 1,
1445
1446 /*
1447 * EC Rate command is a setter/getter command for the EC sampling rate
1448 * of all motion sensors in milliseconds.
1449 */
1450 MOTIONSENSE_CMD_EC_RATE = 2,
1451
1452 /*
1453 * Sensor ODR command is a setter/getter command for the output data
1454 * rate of a specific motion sensor in millihertz.
1455 */
1456 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1457
1458 /*
1459 * Sensor range command is a setter/getter command for the range of
1460 * a specified motion sensor in +/-G's or +/- deg/s.
1461 */
1462 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1463
1464 /*
1465 * Setter/getter command for the keyboard wake angle. When the lid
1466 * angle is greater than this value, keyboard wake is disabled in S3,
1467 * and when the lid angle goes less than this value, keyboard wake is
1468 * enabled. Note, the lid angle measurement is an approximate,
1469 * un-calibrated value, hence the wake angle isn't exact.
1470 */
1471 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1472
1473 /* Number of motionsense sub-commands. */
1474 MOTIONSENSE_NUM_CMDS
1475};
1476
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001477/* List of motion sensor types. */
1478enum motionsensor_type {
1479 MOTIONSENSE_TYPE_ACCEL = 0,
1480 MOTIONSENSE_TYPE_GYRO = 1,
1481};
1482
1483/* List of motion sensor locations. */
1484enum motionsensor_location {
1485 MOTIONSENSE_LOC_BASE = 0,
1486 MOTIONSENSE_LOC_LID = 1,
1487};
1488
1489/* List of motion sensor chips. */
1490enum motionsensor_chip {
1491 MOTIONSENSE_CHIP_KXCJ9 = 0,
1492 MOTIONSENSE_CHIP_LSM6DS0 = 1,
1493};
1494
1495/* Module flag masks used for the dump sub-command. */
1496#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1497
1498/* Sensor flag masks used for the dump sub-command. */
1499#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1500
1501/*
1502 * Send this value for the data element to only perform a read. If you
1503 * send any other value, the EC will interpret it as data to set and will
1504 * return the actual value set.
1505 */
1506#define EC_MOTION_SENSE_NO_VALUE -1
1507
1508struct ec_params_motion_sense {
1509 uint8_t cmd;
1510 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001511 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001512 struct {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001513 /*
1514 * Maximal number of sensor the host is expecting.
1515 * 0 means the host is only interested in the number
1516 * of sensors controlled by the EC.
1517 */
1518 uint8_t max_sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001519 } dump;
1520
1521 /*
1522 * Used for MOTIONSENSE_CMD_EC_RATE and
1523 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1524 */
1525 struct {
1526 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1527 int16_t data;
1528 } ec_rate, kb_wake_angle;
1529
1530 /* Used for MOTIONSENSE_CMD_INFO. */
1531 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001532 uint8_t sensor_num;
1533 } info;
1534
1535 /*
1536 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1537 * MOTIONSENSE_CMD_SENSOR_RANGE.
1538 */
1539 struct {
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001540 uint8_t sensor_num;
1541
1542 /* Rounding flag, true for round-up, false for down. */
1543 uint8_t roundup;
1544
1545 uint16_t reserved;
1546
1547 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1548 int32_t data;
1549 } sensor_odr, sensor_range;
1550 };
1551} __packed;
1552
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001553struct ec_response_motion_sensor_data {
1554 /* Flags for each sensor. */
1555 uint8_t flags;
1556 uint8_t padding;
1557
1558 /* Each sensor is up to 3-axis. */
1559 int16_t data[3];
1560} __packed;
1561
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001562struct ec_response_motion_sense {
1563 union {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001564 /* Used for MOTIONSENSE_CMD_DUMP */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001565 struct {
1566 /* Flags representing the motion sensor module. */
1567 uint8_t module_flags;
1568
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001569 /* Number of sensors managed directly by the EC */
1570 uint8_t sensor_count;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001571
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001572 /*
1573 * sensor data is truncated if response_max is too small
1574 * for holding all the data.
1575 */
1576 struct ec_response_motion_sensor_data sensor[0];
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001577 } dump;
1578
1579 /* Used for MOTIONSENSE_CMD_INFO. */
1580 struct {
1581 /* Should be element of enum motionsensor_type. */
1582 uint8_t type;
1583
1584 /* Should be element of enum motionsensor_location. */
1585 uint8_t location;
1586
1587 /* Should be element of enum motionsensor_chip. */
1588 uint8_t chip;
1589 } info;
1590
1591 /*
1592 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1593 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1594 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1595 */
1596 struct {
1597 /* Current value of the parameter queried. */
1598 int32_t ret;
1599 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1600 };
1601} __packed;
1602
1603/*****************************************************************************/
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001604/* Force lid open command */
1605
1606/* Make lid event always open */
1607#define EC_CMD_FORCE_LID_OPEN 0x2c
1608
1609struct ec_params_force_lid_open {
1610 uint8_t enabled;
1611} __packed;
1612
1613/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001614/* USB charging control commands */
1615
1616/* Set USB port charging mode */
1617#define EC_CMD_USB_CHARGE_SET_MODE 0x30
1618
1619struct ec_params_usb_charge_set_mode {
1620 uint8_t usb_port_id;
1621 uint8_t mode;
1622} __packed;
1623
1624/*****************************************************************************/
1625/* Persistent storage for host */
1626
1627/* Maximum bytes that can be read/written in a single command */
1628#define EC_PSTORE_SIZE_MAX 64
1629
1630/* Get persistent storage info */
1631#define EC_CMD_PSTORE_INFO 0x40
1632
1633struct ec_response_pstore_info {
1634 /* Persistent storage size, in bytes */
1635 uint32_t pstore_size;
1636 /* Access size; read/write offset and size must be a multiple of this */
1637 uint32_t access_size;
1638} __packed;
1639
1640/*
1641 * Read persistent storage
1642 *
1643 * Response is params.size bytes of data.
1644 */
1645#define EC_CMD_PSTORE_READ 0x41
1646
1647struct ec_params_pstore_read {
1648 uint32_t offset; /* Byte offset to read */
1649 uint32_t size; /* Size to read in bytes */
1650} __packed;
1651
1652/* Write persistent storage */
1653#define EC_CMD_PSTORE_WRITE 0x42
1654
1655struct ec_params_pstore_write {
1656 uint32_t offset; /* Byte offset to write */
1657 uint32_t size; /* Size to write in bytes */
1658 uint8_t data[EC_PSTORE_SIZE_MAX];
1659} __packed;
1660
1661/*****************************************************************************/
1662/* Real-time clock */
1663
1664/* RTC params and response structures */
1665struct ec_params_rtc {
1666 uint32_t time;
1667} __packed;
1668
1669struct ec_response_rtc {
1670 uint32_t time;
1671} __packed;
1672
1673/* These use ec_response_rtc */
1674#define EC_CMD_RTC_GET_VALUE 0x44
1675#define EC_CMD_RTC_GET_ALARM 0x45
1676
1677/* These all use ec_params_rtc */
1678#define EC_CMD_RTC_SET_VALUE 0x46
1679#define EC_CMD_RTC_SET_ALARM 0x47
1680
1681/*****************************************************************************/
1682/* Port80 log access */
1683
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001684/* Maximum entries that can be read/written in a single command */
1685#define EC_PORT80_SIZE_MAX 32
1686
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001687/* Get last port80 code from previous boot */
1688#define EC_CMD_PORT80_LAST_BOOT 0x48
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001689#define EC_CMD_PORT80_READ 0x48
1690
1691enum ec_port80_subcmd {
1692 EC_PORT80_GET_INFO = 0,
1693 EC_PORT80_READ_BUFFER,
1694};
1695
1696struct ec_params_port80_read {
1697 uint16_t subcmd;
1698 union {
1699 struct {
1700 uint32_t offset;
1701 uint32_t num_entries;
1702 } read_buffer;
1703 };
1704} __packed;
1705
1706struct ec_response_port80_read {
1707 union {
1708 struct {
1709 uint32_t writes;
1710 uint32_t history_size;
1711 uint32_t last_boot;
1712 } get_info;
1713 struct {
1714 uint16_t codes[EC_PORT80_SIZE_MAX];
1715 } data;
1716 };
1717} __packed;
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001718
1719struct ec_response_port80_last_boot {
1720 uint16_t code;
1721} __packed;
1722
1723/*****************************************************************************/
Duncan Laurie93e24442014-01-06 12:30:52 -08001724/* Thermal engine commands. Note that there are two implementations. We'll
1725 * reuse the command number, but the data and behavior is incompatible.
1726 * Version 0 is what originally shipped on Link.
1727 * Version 1 separates the CPU thermal limits from the fan control.
1728 */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001729
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001730#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
Duncan Laurie93e24442014-01-06 12:30:52 -08001731#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001732
Duncan Laurie93e24442014-01-06 12:30:52 -08001733/* The version 0 structs are opaque. You have to know what they are for
1734 * the get/set commands to make any sense.
1735 */
1736
1737/* Version 0 - set */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001738struct ec_params_thermal_set_threshold {
1739 uint8_t sensor_type;
1740 uint8_t threshold_id;
1741 uint16_t value;
1742} __packed;
1743
Duncan Laurie93e24442014-01-06 12:30:52 -08001744/* Version 0 - get */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001745struct ec_params_thermal_get_threshold {
1746 uint8_t sensor_type;
1747 uint8_t threshold_id;
1748} __packed;
1749
1750struct ec_response_thermal_get_threshold {
1751 uint16_t value;
1752} __packed;
1753
Duncan Laurie93e24442014-01-06 12:30:52 -08001754
1755/* The version 1 structs are visible. */
1756enum ec_temp_thresholds {
1757 EC_TEMP_THRESH_WARN = 0,
1758 EC_TEMP_THRESH_HIGH,
1759 EC_TEMP_THRESH_HALT,
1760
1761 EC_TEMP_THRESH_COUNT
1762};
1763
1764/* Thermal configuration for one temperature sensor. Temps are in degrees K.
1765 * Zero values will be silently ignored by the thermal task.
1766 */
1767struct ec_thermal_config {
1768 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1769 uint32_t temp_fan_off; /* no active cooling needed */
1770 uint32_t temp_fan_max; /* max active cooling needed */
1771} __packed;
1772
1773/* Version 1 - get config for one sensor. */
1774struct ec_params_thermal_get_threshold_v1 {
1775 uint32_t sensor_num;
1776} __packed;
1777/* This returns a struct ec_thermal_config */
1778
1779/* Version 1 - set config for one sensor.
1780 * Use read-modify-write for best results! */
1781struct ec_params_thermal_set_threshold_v1 {
1782 uint32_t sensor_num;
1783 struct ec_thermal_config cfg;
1784} __packed;
1785/* This returns no data */
1786
1787/****************************************************************************/
1788
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001789/* Toggle automatic fan control */
1790#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1791
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001792/* Version 1 of input params */
1793struct ec_params_auto_fan_ctrl_v1 {
1794 uint8_t fan_idx;
1795} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07001796
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001797/* Get/Set TMP006 calibration data */
1798#define EC_CMD_TMP006_GET_CALIBRATION 0x53
1799#define EC_CMD_TMP006_SET_CALIBRATION 0x54
1800
1801/*
1802 * The original TMP006 calibration only needed four params, but now we need
1803 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
1804 * the params opaque. The v1 "get" response will include the algorithm number
1805 * and how many params it requires. That way we can change the EC code without
1806 * needing to update this file. We can also use a different algorithm on each
1807 * sensor.
1808 */
1809
1810/* This is the same struct for both v0 and v1. */
Duncan Laurie433432b2013-06-03 10:38:22 -07001811struct ec_params_tmp006_get_calibration {
1812 uint8_t index;
1813} __packed;
1814
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001815/* Version 0 */
1816struct ec_response_tmp006_get_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001817 float s0;
1818 float b0;
1819 float b1;
1820 float b2;
1821} __packed;
1822
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001823struct ec_params_tmp006_set_calibration_v0 {
Duncan Laurie433432b2013-06-03 10:38:22 -07001824 uint8_t index;
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001825 uint8_t reserved[3];
Duncan Laurie433432b2013-06-03 10:38:22 -07001826 float s0;
1827 float b0;
1828 float b1;
1829 float b2;
1830} __packed;
1831
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001832/* Version 1 */
1833struct ec_response_tmp006_get_calibration_v1 {
1834 uint8_t algorithm;
1835 uint8_t num_params;
1836 uint8_t reserved[2];
1837 float val[0];
1838} __packed;
1839
1840struct ec_params_tmp006_set_calibration_v1 {
1841 uint8_t index;
1842 uint8_t algorithm;
1843 uint8_t num_params;
1844 uint8_t reserved;
1845 float val[0];
1846} __packed;
1847
1848
Duncan Laurie8caa80b2014-09-18 12:48:06 -07001849/* Read raw TMP006 data */
1850#define EC_CMD_TMP006_GET_RAW 0x55
1851
1852struct ec_params_tmp006_get_raw {
1853 uint8_t index;
1854} __packed;
1855
1856struct ec_response_tmp006_get_raw {
1857 int32_t t; /* In 1/100 K */
1858 int32_t v; /* In nV */
1859};
1860
Stefan Reinauerd6682e82013-02-21 15:39:35 -08001861/*****************************************************************************/
1862/* MKBP - Matrix KeyBoard Protocol */
1863
1864/*
1865 * Read key state
1866 *
1867 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1868 * expected response size.
1869 */
1870#define EC_CMD_MKBP_STATE 0x60
1871
1872/* Provide information about the matrix : number of rows and columns */
1873#define EC_CMD_MKBP_INFO 0x61
1874
1875struct ec_response_mkbp_info {
1876 uint32_t rows;
1877 uint32_t cols;
1878 uint8_t switches;
1879} __packed;
1880
1881/* Simulate key press */
1882#define EC_CMD_MKBP_SIMULATE_KEY 0x62
1883
1884struct ec_params_mkbp_simulate_key {
1885 uint8_t col;
1886 uint8_t row;
1887 uint8_t pressed;
1888} __packed;
1889
Duncan Laurie433432b2013-06-03 10:38:22 -07001890/* Configure keyboard scanning */
1891#define EC_CMD_MKBP_SET_CONFIG 0x64
1892#define EC_CMD_MKBP_GET_CONFIG 0x65
1893
1894/* flags */
1895enum mkbp_config_flags {
1896 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
1897};
1898
1899enum mkbp_config_valid {
1900 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
1901 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
1902 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
1903 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
1904 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
1905 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
1906 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
1907};
1908
1909/* Configuration for our key scanning algorithm */
1910struct ec_mkbp_config {
1911 uint32_t valid_mask; /* valid fields */
1912 uint8_t flags; /* some flags (enum mkbp_config_flags) */
1913 uint8_t valid_flags; /* which flags are valid */
1914 uint16_t scan_period_us; /* period between start of scans */
1915 /* revert to interrupt mode after no activity for this long */
1916 uint32_t poll_timeout_us;
1917 /*
1918 * minimum post-scan relax time. Once we finish a scan we check
1919 * the time until we are due to start the next one. If this time is
1920 * shorter this field, we use this instead.
1921 */
1922 uint16_t min_post_scan_delay_us;
1923 /* delay between setting up output and waiting for it to settle */
1924 uint16_t output_settle_us;
1925 uint16_t debounce_down_us; /* time for debounce on key down */
1926 uint16_t debounce_up_us; /* time for debounce on key up */
1927 /* maximum depth to allow for fifo (0 = no keyscan output) */
1928 uint8_t fifo_max_depth;
1929} __packed;
1930
1931struct ec_params_mkbp_set_config {
1932 struct ec_mkbp_config config;
1933} __packed;
1934
1935struct ec_response_mkbp_get_config {
1936 struct ec_mkbp_config config;
1937} __packed;
1938
1939/* Run the key scan emulation */
1940#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
1941
1942enum ec_keyscan_seq_cmd {
1943 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
1944 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
1945 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
1946 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
1947 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
1948};
1949
1950enum ec_collect_flags {
1951 /*
1952 * Indicates this scan was processed by the EC. Due to timing, some
1953 * scans may be skipped.
1954 */
1955 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
1956};
1957
1958struct ec_collect_item {
1959 uint8_t flags; /* some flags (enum ec_collect_flags) */
1960};
1961
1962struct ec_params_keyscan_seq_ctrl {
1963 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
1964 union {
1965 struct {
1966 uint8_t active; /* still active */
1967 uint8_t num_items; /* number of items */
1968 /* Current item being presented */
1969 uint8_t cur_item;
1970 } status;
1971 struct {
1972 /*
1973 * Absolute time for this scan, measured from the
1974 * start of the sequence.
1975 */
1976 uint32_t time_us;
1977 uint8_t scan[0]; /* keyscan data */
1978 } add;
1979 struct {
1980 uint8_t start_item; /* First item to return */
1981 uint8_t num_items; /* Number of items to return */
1982 } collect;
1983 };
1984} __packed;
1985
1986struct ec_result_keyscan_seq_ctrl {
1987 union {
1988 struct {
1989 uint8_t num_items; /* Number of items */
1990 /* Data for each item */
1991 struct ec_collect_item item[0];
1992 } collect;
1993 };
1994} __packed;
1995
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07001996/*
1997 * Get the next pending MKBP event.
1998 *
1999 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2000 */
2001#define EC_CMD_GET_NEXT_EVENT 0x67
2002
2003enum ec_mkbp_event {
2004 /* Keyboard matrix changed. The event data is the new matrix state. */
2005 EC_MKBP_EVENT_KEY_MATRIX = 0,
2006
2007 /* New host event. The event data is 4 bytes of host event flags. */
2008 EC_MKBP_EVENT_HOST_EVENT = 1,
2009
2010 /* Number of MKBP events */
2011 EC_MKBP_EVENT_COUNT,
2012};
2013
2014struct ec_response_get_next_event {
2015 uint8_t event_type;
2016 /* Followed by event data if any */
2017} __packed;
2018
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002019/*****************************************************************************/
2020/* Temperature sensor commands */
2021
2022/* Read temperature sensor info */
2023#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2024
2025struct ec_params_temp_sensor_get_info {
2026 uint8_t id;
2027} __packed;
2028
2029struct ec_response_temp_sensor_get_info {
2030 char sensor_name[32];
2031 uint8_t sensor_type;
2032} __packed;
2033
2034/*****************************************************************************/
2035
2036/*
2037 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2038 * commands accidentally sent to the wrong interface. See the ACPI section
2039 * below.
2040 */
2041
2042/*****************************************************************************/
2043/* Host event commands */
2044
2045/*
2046 * Host event mask params and response structures, shared by all of the host
2047 * event commands below.
2048 */
2049struct ec_params_host_event_mask {
2050 uint32_t mask;
2051} __packed;
2052
2053struct ec_response_host_event_mask {
2054 uint32_t mask;
2055} __packed;
2056
2057/* These all use ec_response_host_event_mask */
2058#define EC_CMD_HOST_EVENT_GET_B 0x87
2059#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2060#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2061#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2062
2063/* These all use ec_params_host_event_mask */
2064#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2065#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2066#define EC_CMD_HOST_EVENT_CLEAR 0x8c
2067#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2068#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2069
2070/*****************************************************************************/
2071/* Switch commands */
2072
2073/* Enable/disable LCD backlight */
2074#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2075
2076struct ec_params_switch_enable_backlight {
2077 uint8_t enabled;
2078} __packed;
2079
2080/* Enable/disable WLAN/Bluetooth */
2081#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002082#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002083
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002084/* Version 0 params; no response */
2085struct ec_params_switch_enable_wireless_v0 {
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002086 uint8_t enabled;
2087} __packed;
2088
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002089/* Version 1 params */
2090struct ec_params_switch_enable_wireless_v1 {
2091 /* Flags to enable now */
2092 uint8_t now_flags;
2093
2094 /* Which flags to copy from now_flags */
2095 uint8_t now_mask;
2096
2097 /*
2098 * Flags to leave enabled in S3, if they're on at the S0->S3
2099 * transition. (Other flags will be disabled by the S0->S3
2100 * transition.)
2101 */
2102 uint8_t suspend_flags;
2103
2104 /* Which flags to copy from suspend_flags */
2105 uint8_t suspend_mask;
2106} __packed;
2107
2108/* Version 1 response */
2109struct ec_response_switch_enable_wireless_v1 {
2110 /* Flags to enable now */
2111 uint8_t now_flags;
2112
2113 /* Flags to leave enabled in S3 */
2114 uint8_t suspend_flags;
2115} __packed;
2116
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002117/*****************************************************************************/
2118/* GPIO commands. Only available on EC if write protect has been disabled. */
2119
2120/* Set GPIO output value */
2121#define EC_CMD_GPIO_SET 0x92
2122
2123struct ec_params_gpio_set {
2124 char name[32];
2125 uint8_t val;
2126} __packed;
2127
2128/* Get GPIO value */
2129#define EC_CMD_GPIO_GET 0x93
2130
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002131/* Version 0 of input params and response */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002132struct ec_params_gpio_get {
2133 char name[32];
2134} __packed;
2135struct ec_response_gpio_get {
2136 uint8_t val;
2137} __packed;
2138
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002139/* Version 1 of input params and response */
2140struct ec_params_gpio_get_v1 {
2141 uint8_t subcmd;
2142 union {
2143 struct {
2144 char name[32];
2145 } get_value_by_name;
2146 struct {
2147 uint8_t index;
2148 } get_info;
2149 };
2150} __packed;
2151
2152struct ec_response_gpio_get_v1 {
2153 union {
2154 struct {
2155 uint8_t val;
2156 } get_value_by_name, get_count;
2157 struct {
2158 uint8_t val;
2159 char name[32];
2160 uint32_t flags;
2161 } get_info;
2162 };
2163} __packed;
2164
2165enum gpio_get_subcmd {
2166 EC_GPIO_GET_BY_NAME = 0,
2167 EC_GPIO_GET_COUNT = 1,
2168 EC_GPIO_GET_INFO = 2,
2169};
2170
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002171/*****************************************************************************/
2172/* I2C commands. Only available when flash write protect is unlocked. */
2173
Duncan Laurie93e24442014-01-06 12:30:52 -08002174/*
2175 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2176 * removed soon. Use EC_CMD_I2C_XFER instead.
2177 */
2178
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002179/* Read I2C bus */
2180#define EC_CMD_I2C_READ 0x94
2181
2182struct ec_params_i2c_read {
Duncan Laurie433432b2013-06-03 10:38:22 -07002183 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002184 uint8_t read_size; /* Either 8 or 16. */
2185 uint8_t port;
2186 uint8_t offset;
2187} __packed;
2188struct ec_response_i2c_read {
2189 uint16_t data;
2190} __packed;
2191
2192/* Write I2C bus */
2193#define EC_CMD_I2C_WRITE 0x95
2194
2195struct ec_params_i2c_write {
2196 uint16_t data;
Duncan Laurie433432b2013-06-03 10:38:22 -07002197 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002198 uint8_t write_size; /* Either 8 or 16. */
2199 uint8_t port;
2200 uint8_t offset;
2201} __packed;
2202
2203/*****************************************************************************/
2204/* Charge state commands. Only available when flash write protect unlocked. */
2205
Duncan Laurie93e24442014-01-06 12:30:52 -08002206/* Force charge state machine to stop charging the battery or force it to
2207 * discharge the battery.
2208 */
2209#define EC_CMD_CHARGE_CONTROL 0x96
2210#define EC_VER_CHARGE_CONTROL 1
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002211
Duncan Laurie93e24442014-01-06 12:30:52 -08002212enum ec_charge_control_mode {
2213 CHARGE_CONTROL_NORMAL = 0,
2214 CHARGE_CONTROL_IDLE,
2215 CHARGE_CONTROL_DISCHARGE,
2216};
2217
2218struct ec_params_charge_control {
2219 uint32_t mode; /* enum charge_control_mode */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002220} __packed;
2221
2222/*****************************************************************************/
2223/* Console commands. Only available when flash write protect is unlocked. */
2224
2225/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2226#define EC_CMD_CONSOLE_SNAPSHOT 0x97
2227
2228/*
2229 * Read next chunk of data from saved snapshot.
2230 *
2231 * Response is null-terminated string. Empty string, if there is no more
2232 * remaining output.
2233 */
2234#define EC_CMD_CONSOLE_READ 0x98
2235
2236/*****************************************************************************/
Duncan Laurie433432b2013-06-03 10:38:22 -07002237
2238/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002239 * Cut off battery power immediately or after the host has shut down.
Duncan Laurie433432b2013-06-03 10:38:22 -07002240 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002241 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2242 * EC_RES_SUCCESS if the command was successful.
2243 * EC_RES_ERROR if the cut off command failed.
Duncan Laurie433432b2013-06-03 10:38:22 -07002244 */
2245#define EC_CMD_BATTERY_CUT_OFF 0x99
2246
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002247#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2248
2249struct ec_params_battery_cutoff {
2250 uint8_t flags;
2251} __packed;
2252
Duncan Laurie433432b2013-06-03 10:38:22 -07002253/*****************************************************************************/
2254/* USB port mux control. */
2255
2256/*
2257 * Switch USB mux or return to automatic switching.
2258 */
2259#define EC_CMD_USB_MUX 0x9a
2260
2261struct ec_params_usb_mux {
2262 uint8_t mux;
2263} __packed;
2264
2265/*****************************************************************************/
2266/* LDOs / FETs control. */
2267
2268enum ec_ldo_state {
2269 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2270 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2271};
2272
2273/*
2274 * Switch on/off a LDO.
2275 */
2276#define EC_CMD_LDO_SET 0x9b
2277
2278struct ec_params_ldo_set {
2279 uint8_t index;
2280 uint8_t state;
2281} __packed;
2282
2283/*
2284 * Get LDO state.
2285 */
2286#define EC_CMD_LDO_GET 0x9c
2287
2288struct ec_params_ldo_get {
2289 uint8_t index;
2290} __packed;
2291
2292struct ec_response_ldo_get {
2293 uint8_t state;
2294} __packed;
2295
2296/*****************************************************************************/
2297/* Power info. */
2298
2299/*
2300 * Get power info.
2301 */
2302#define EC_CMD_POWER_INFO 0x9d
2303
2304struct ec_response_power_info {
2305 uint32_t usb_dev_type;
2306 uint16_t voltage_ac;
2307 uint16_t voltage_system;
2308 uint16_t current_system;
2309 uint16_t usb_current_limit;
2310} __packed;
2311
2312/*****************************************************************************/
2313/* I2C passthru command */
2314
2315#define EC_CMD_I2C_PASSTHRU 0x9e
2316
Duncan Laurie433432b2013-06-03 10:38:22 -07002317/* Read data; if not present, message is a write */
2318#define EC_I2C_FLAG_READ (1 << 15)
2319
2320/* Mask for address */
2321#define EC_I2C_ADDR_MASK 0x3ff
2322
2323#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2324#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2325
2326/* Any error */
2327#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2328
2329struct ec_params_i2c_passthru_msg {
2330 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2331 uint16_t len; /* Number of bytes to read or write */
2332} __packed;
2333
2334struct ec_params_i2c_passthru {
2335 uint8_t port; /* I2C port number */
2336 uint8_t num_msgs; /* Number of messages */
2337 struct ec_params_i2c_passthru_msg msg[];
2338 /* Data to write for all messages is concatenated here */
2339} __packed;
2340
2341struct ec_response_i2c_passthru {
2342 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2343 uint8_t num_msgs; /* Number of messages processed */
2344 uint8_t data[]; /* Data read by messages concatenated here */
2345} __packed;
2346
Duncan Lauriee6b280e2014-02-10 16:21:05 -08002347/*****************************************************************************/
2348/* Power button hang detect */
2349
2350#define EC_CMD_HANG_DETECT 0x9f
2351
2352/* Reasons to start hang detection timer */
2353/* Power button pressed */
2354#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2355
2356/* Lid closed */
2357#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2358
2359 /* Lid opened */
2360#define EC_HANG_START_ON_LID_OPEN (1 << 2)
2361
2362/* Start of AP S3->S0 transition (booting or resuming from suspend) */
2363#define EC_HANG_START_ON_RESUME (1 << 3)
2364
2365/* Reasons to cancel hang detection */
2366
2367/* Power button released */
2368#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2369
2370/* Any host command from AP received */
2371#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2372
2373/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2374#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2375
2376/*
2377 * If this flag is set, all the other fields are ignored, and the hang detect
2378 * timer is started. This provides the AP a way to start the hang timer
2379 * without reconfiguring any of the other hang detect settings. Note that
2380 * you must previously have configured the timeouts.
2381 */
2382#define EC_HANG_START_NOW (1 << 30)
2383
2384/*
2385 * If this flag is set, all the other fields are ignored (including
2386 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2387 * without reconfiguring any of the other hang detect settings.
2388 */
2389#define EC_HANG_STOP_NOW (1 << 31)
2390
2391struct ec_params_hang_detect {
2392 /* Flags; see EC_HANG_* */
2393 uint32_t flags;
2394
2395 /* Timeout in msec before generating host event, if enabled */
2396 uint16_t host_event_timeout_msec;
2397
2398 /* Timeout in msec before generating warm reboot, if enabled */
2399 uint16_t warm_reboot_timeout_msec;
2400} __packed;
Duncan Laurie433432b2013-06-03 10:38:22 -07002401
2402/*****************************************************************************/
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002403/* Commands for battery charging */
Duncan Laurie433432b2013-06-03 10:38:22 -07002404
2405/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002406 * This is the single catch-all host command to exchange data regarding the
2407 * charge state machine (v2 and up).
Duncan Laurie433432b2013-06-03 10:38:22 -07002408 */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002409#define EC_CMD_CHARGE_STATE 0xa0
2410
2411/* Subcommands for this host command */
2412enum charge_state_command {
2413 CHARGE_STATE_CMD_GET_STATE,
2414 CHARGE_STATE_CMD_GET_PARAM,
2415 CHARGE_STATE_CMD_SET_PARAM,
2416 CHARGE_STATE_NUM_CMDS
2417};
2418
2419/*
2420 * Known param numbers are defined here. Ranges are reserved for board-specific
2421 * params, which are handled by the particular implementations.
2422 */
2423enum charge_state_params {
2424 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2425 CS_PARAM_CHG_CURRENT, /* charger current limit */
2426 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2427 CS_PARAM_CHG_STATUS, /* charger-specific status */
2428 CS_PARAM_CHG_OPTION, /* charger-specific options */
2429 /* How many so far? */
2430 CS_NUM_BASE_PARAMS,
2431
2432 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2433 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2434 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2435
2436 /* Other custom param ranges go here... */
2437};
2438
2439struct ec_params_charge_state {
2440 uint8_t cmd; /* enum charge_state_command */
2441 union {
2442 struct {
2443 /* no args */
2444 } get_state;
2445
2446 struct {
2447 uint32_t param; /* enum charge_state_param */
2448 } get_param;
2449
2450 struct {
2451 uint32_t param; /* param to set */
2452 uint32_t value; /* value to set */
2453 } set_param;
2454 };
2455} __packed;
2456
2457struct ec_response_charge_state {
2458 union {
2459 struct {
2460 int ac;
2461 int chg_voltage;
2462 int chg_current;
2463 int chg_input_current;
2464 int batt_state_of_charge;
2465 } get_state;
2466
2467 struct {
2468 uint32_t value;
2469 } get_param;
2470 struct {
2471 /* no return values */
2472 } set_param;
2473 };
2474} __packed;
2475
Duncan Laurie433432b2013-06-03 10:38:22 -07002476
2477/*
2478 * Set maximum battery charging current.
2479 */
2480#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2481
2482struct ec_params_current_limit {
2483 uint32_t limit; /* in mA */
2484} __packed;
2485
2486/*
2487 * Set maximum external power current.
2488 */
2489#define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
2490
2491struct ec_params_ext_power_current_limit {
2492 uint32_t limit; /* in mA */
2493} __packed;
2494
2495/*****************************************************************************/
2496/* Smart battery pass-through */
2497
2498/* Get / Set 16-bit smart battery registers */
2499#define EC_CMD_SB_READ_WORD 0xb0
2500#define EC_CMD_SB_WRITE_WORD 0xb1
2501
2502/* Get / Set string smart battery parameters
2503 * formatted as SMBUS "block".
2504 */
2505#define EC_CMD_SB_READ_BLOCK 0xb2
2506#define EC_CMD_SB_WRITE_BLOCK 0xb3
2507
2508struct ec_params_sb_rd {
2509 uint8_t reg;
2510} __packed;
2511
2512struct ec_response_sb_rd_word {
2513 uint16_t value;
2514} __packed;
2515
2516struct ec_params_sb_wr_word {
2517 uint8_t reg;
2518 uint16_t value;
2519} __packed;
2520
2521struct ec_response_sb_rd_block {
2522 uint8_t data[32];
2523} __packed;
2524
2525struct ec_params_sb_wr_block {
2526 uint8_t reg;
2527 uint16_t data[32];
2528} __packed;
2529
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002530
2531/*****************************************************************************/
2532/* Battery vendor parameters
2533 *
2534 * Get or set vendor-specific parameters in the battery. Implementations may
2535 * differ between boards or batteries. On a set operation, the response
2536 * contains the actual value set, which may be rounded or clipped from the
2537 * requested value.
2538 */
2539
2540#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2541
2542enum ec_battery_vendor_param_mode {
2543 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2544 BATTERY_VENDOR_PARAM_MODE_SET,
2545};
2546
2547struct ec_params_battery_vendor_param {
2548 uint32_t param;
2549 uint32_t value;
2550 uint8_t mode;
2551} __packed;
2552
2553struct ec_response_battery_vendor_param {
2554 uint32_t value;
2555} __packed;
2556
2557/*****************************************************************************/
2558/*
2559 * Smart Battery Firmware Update Commands
2560 */
2561#define EC_CMD_SB_FW_UPDATE 0xb5
2562
2563enum ec_sb_fw_update_subcmd {
2564 EC_SB_FW_UPDATE_PREPARE = 0x0,
2565 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
2566 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
2567 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
2568 EC_SB_FW_UPDATE_END = 0x4,
2569 EC_SB_FW_UPDATE_STATUS = 0x5,
2570 EC_SB_FW_UPDATE_PROTECT = 0x6,
2571 EC_SB_FW_UPDATE_MAX = 0x7,
2572};
2573
2574#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
2575#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
2576#define SB_FW_UPDATE_CMD_INFO_SIZE 8
2577
2578struct ec_sb_fw_update_header {
2579 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
2580 uint16_t fw_id; /* firmware id */
2581} __packed;
2582
2583struct ec_params_sb_fw_update {
2584 struct ec_sb_fw_update_header hdr;
2585 union {
2586 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
2587 /* EC_SB_FW_UPDATE_INFO = 0x1 */
2588 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
2589 /* EC_SB_FW_UPDATE_END = 0x4 */
2590 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
2591 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
2592 struct {
2593 /* no args */
2594 } dummy;
2595
2596 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
2597 struct {
2598 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
2599 } write;
2600 };
2601} __packed;
2602
2603struct ec_response_sb_fw_update {
2604 union {
2605 /* EC_SB_FW_UPDATE_INFO = 0x1 */
2606 struct {
2607 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
2608 } info;
2609
2610 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
2611 struct {
2612 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
2613 } status;
2614 };
2615} __packed;
2616
2617/*
2618 * Entering Verified Boot Mode Command
2619 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
2620 * Valid Modes are: normal, developer, and recovery.
2621 */
2622#define EC_CMD_ENTERING_MODE 0xb6
2623
2624struct ec_params_entering_mode {
2625 int vboot_mode;
2626} __packed;
2627
2628#define VBOOT_MODE_NORMAL 0
2629#define VBOOT_MODE_DEVELOPER 1
2630#define VBOOT_MODE_RECOVERY 2
2631
Duncan Laurie433432b2013-06-03 10:38:22 -07002632/*****************************************************************************/
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002633/* System commands */
2634
2635/*
Duncan Laurie93e24442014-01-06 12:30:52 -08002636 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2637 * necessarily reboot the EC. Rename to "image" or something similar?
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002638 */
2639#define EC_CMD_REBOOT_EC 0xd2
2640
2641/* Command */
2642enum ec_reboot_cmd {
2643 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07002644 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2645 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002646 /* (command 3 was jump to RW-B) */
2647 EC_REBOOT_COLD = 4, /* Cold-reboot */
Duncan Laurie433432b2013-06-03 10:38:22 -07002648 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2649 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002650};
2651
2652/* Flags for ec_params_reboot_ec.reboot_flags */
2653#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
Duncan Laurie433432b2013-06-03 10:38:22 -07002654#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002655
2656struct ec_params_reboot_ec {
2657 uint8_t cmd; /* enum ec_reboot_cmd */
2658 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2659} __packed;
2660
Duncan Laurie433432b2013-06-03 10:38:22 -07002661/*
2662 * Get information on last EC panic.
2663 *
2664 * Returns variable-length platform-dependent panic information. See panic.h
2665 * for details.
2666 */
2667#define EC_CMD_GET_PANIC_INFO 0xd3
2668
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002669/*****************************************************************************/
2670/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002671 * Special commands
2672 *
2673 * These do not follow the normal rules for commands. See each command for
2674 * details.
2675 */
2676
2677/*
2678 * Reboot NOW
2679 *
2680 * This command will work even when the EC LPC interface is busy, because the
2681 * reboot command is processed at interrupt level. Note that when the EC
2682 * reboots, the host will reboot too, so there is no response to this command.
2683 *
2684 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
2685 */
2686#define EC_CMD_REBOOT 0xd1 /* Think "die" */
2687
2688/*
Duncan Laurie433432b2013-06-03 10:38:22 -07002689 * Resend last response (not supported on LPC).
2690 *
2691 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
2692 * there was no previous command, or the previous command's response was too
2693 * big to save.
2694 */
2695#define EC_CMD_RESEND_RESPONSE 0xdb
2696
2697/*
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002698 * This header byte on a command indicate version 0. Any header byte less
2699 * than this means that we are talking to an old EC which doesn't support
2700 * versioning. In that case, we assume version 0.
2701 *
2702 * Header bytes greater than this indicate a later version. For example,
2703 * EC_CMD_VERSION0 + 1 means we are using version 1.
2704 *
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002705 * The old EC interface must not use commands 0xdc or higher.
Stefan Reinauerd6682e82013-02-21 15:39:35 -08002706 */
2707#define EC_CMD_VERSION0 0xdc
2708
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002709/*****************************************************************************/
2710/*
2711 * PD commands
2712 *
2713 * These commands are for PD MCU communication.
2714 */
2715
2716/* EC to PD MCU exchange status command */
2717#define EC_CMD_PD_EXCHANGE_STATUS 0x100
2718
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002719enum pd_charge_state {
2720 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
2721 PD_CHARGE_NONE, /* No charging allowed */
2722 PD_CHARGE_5V, /* 5V charging only */
2723 PD_CHARGE_MAX /* Charge at max voltage */
2724};
2725
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002726/* Status of EC being sent to PD */
2727struct ec_params_pd_status {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002728 int8_t batt_soc; /* battery state of charge */
2729 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002730} __packed;
2731
2732/* Status of PD being sent back to EC */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002733#define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
2734#define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
2735#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002736struct ec_response_pd_status {
2737 uint32_t status; /* PD MCU status */
2738 uint32_t curr_lim_ma; /* input current limit */
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002739 int32_t active_charge_port; /* active charging port */
2740} __packed;
2741
2742/* AP to PD MCU host event status command, cleared on read */
2743#define EC_CMD_PD_HOST_EVENT_STATUS 0x104
2744
2745/* PD MCU host event status bits */
2746#define PD_EVENT_UPDATE_DEVICE (1 << 0)
2747#define PD_EVENT_POWER_CHANGE (1 << 1)
2748#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
2749struct ec_response_host_event_status {
2750 uint32_t status; /* PD MCU host event status */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002751} __packed;
2752
2753/* Set USB type-C port role and muxes */
2754#define EC_CMD_USB_PD_CONTROL 0x101
2755
2756enum usb_pd_control_role {
2757 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
2758 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
2759 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
2760 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
2761 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
2762 USB_PD_CTRL_ROLE_COUNT
2763};
2764
2765enum usb_pd_control_mux {
2766 USB_PD_CTRL_MUX_NO_CHANGE = 0,
2767 USB_PD_CTRL_MUX_NONE = 1,
2768 USB_PD_CTRL_MUX_USB = 2,
2769 USB_PD_CTRL_MUX_DP = 3,
2770 USB_PD_CTRL_MUX_DOCK = 4,
2771 USB_PD_CTRL_MUX_AUTO = 5,
2772 USB_PD_CTRL_MUX_COUNT
2773};
2774
2775struct ec_params_usb_pd_control {
2776 uint8_t port;
2777 uint8_t role;
2778 uint8_t mux;
2779} __packed;
2780
2781struct ec_response_usb_pd_control {
2782 uint8_t enabled;
2783 uint8_t role;
2784 uint8_t polarity;
2785 uint8_t state;
2786} __packed;
2787
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002788struct ec_response_usb_pd_control_v1 {
2789 uint8_t enabled;
2790 uint8_t role; /* [0] power: 0=SNK/1=SRC [1] data: 0=UFP/1=DFP */
2791 uint8_t polarity;
2792 char state[32];
2793} __packed;
2794
2795#define EC_CMD_USB_PD_PORTS 0x102
2796
2797struct ec_response_usb_pd_ports {
2798 uint8_t num_ports;
2799} __packed;
2800
2801#define EC_CMD_USB_PD_POWER_INFO 0x103
2802
2803#define PD_POWER_CHARGING_PORT 0xff
2804struct ec_params_usb_pd_power_info {
2805 uint8_t port;
2806} __packed;
2807
2808enum usb_chg_type {
2809 USB_CHG_TYPE_NONE,
2810 USB_CHG_TYPE_PD,
2811 USB_CHG_TYPE_C,
2812 USB_CHG_TYPE_PROPRIETARY,
2813 USB_CHG_TYPE_BC12_DCP,
2814 USB_CHG_TYPE_BC12_CDP,
2815 USB_CHG_TYPE_BC12_SDP,
2816 USB_CHG_TYPE_OTHER,
2817 USB_CHG_TYPE_VBUS,
2818};
2819enum usb_power_roles {
2820 USB_PD_PORT_POWER_DISCONNECTED,
2821 USB_PD_PORT_POWER_SOURCE,
2822 USB_PD_PORT_POWER_SINK,
2823 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
2824};
2825
2826struct usb_chg_measures {
2827 uint16_t voltage_max;
2828 uint16_t voltage_now;
2829 uint16_t current_max;
2830 /*
2831 * this structure is used below in struct ec_response_usb_pd_power_info,
2832 * and currently expects an odd number of uint16_t for alignment.
2833 */
2834} __packed;
2835
2836struct ec_response_usb_pd_power_info {
2837 uint8_t role;
2838 uint8_t type;
2839 uint8_t dualrole;
2840 uint8_t reserved1;
2841 struct usb_chg_measures meas;
2842 uint16_t reserved2;
2843 uint32_t max_power;
2844} __packed;
2845
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002846/* Write USB-PD device FW */
2847#define EC_CMD_USB_PD_FW_UPDATE 0x110
2848
2849enum usb_pd_fw_update_cmds {
2850 USB_PD_FW_REBOOT,
2851 USB_PD_FW_FLASH_ERASE,
2852 USB_PD_FW_FLASH_WRITE,
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002853 USB_PD_FW_ERASE_SIG,
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002854};
2855
2856struct ec_params_usb_pd_fw_update {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002857 uint16_t dev_id;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002858 uint8_t cmd;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002859 uint8_t port;
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002860 uint32_t size; /* Size to write in bytes */
2861 /* Followed by data to write */
2862} __packed;
2863
2864/* Write USB-PD Accessory RW_HASH table entry */
2865#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x111
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002866/* RW hash is first 20 bytes of SHA-256 of RW section */
2867#define PD_RW_HASH_SIZE 20
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002868struct ec_params_usb_pd_rw_hash_entry {
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002869 uint16_t dev_id;
2870 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
2871 uint8_t reserved; /* For alignment of current_image */
2872 uint32_t current_image; /* One of ec_current_image */
Duncan Laurie8caa80b2014-09-18 12:48:06 -07002873} __packed;
2874
2875/* Read USB-PD Accessory info */
2876#define EC_CMD_USB_PD_DEV_INFO 0x112
2877
2878struct ec_params_usb_pd_info_request {
2879 uint8_t port;
2880} __packed;
2881
Shawn Nematbakhsh235f9222015-03-24 11:47:18 -07002882/* Read USB-PD Device discovery info */
2883#define EC_CMD_USB_PD_DISCOVERY 0x113
2884struct ec_params_usb_pd_discovery_entry {
2885 uint16_t vid; /* USB-IF VID */
2886 uint16_t pid; /* USB-IF PID */
2887 uint8_t ptype; /* product type (hub,periph,cable,ama) */
2888} __packed;
2889
2890/* Override default charge behavior */
2891#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x114
2892
2893/* Negative port parameters have special meaning */
2894enum usb_pd_override_ports {
2895 OVERRIDE_DONT_CHARGE = -2,
2896 OVERRIDE_OFF = -1,
2897 /* [0, PD_PORT_COUNT): Port# */
2898};
2899
2900struct ec_params_charge_port_override {
2901 int16_t override_port; /* Override port# */
2902} __packed;
2903
2904/* Read (and delete) one entry of PD event log */
2905#define EC_CMD_PD_GET_LOG_ENTRY 0x115
2906
2907struct ec_response_pd_log {
2908 uint32_t timestamp; /* relative timestamp in milliseconds */
2909 uint8_t type; /* event type : see PD_EVENT_xx below */
2910 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
2911 uint16_t data; /* type-defined data payload */
2912 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
2913} __packed;
2914
2915
2916/* The timestamp is the microsecond counter shifted to get about a ms. */
2917#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
2918
2919#define PD_LOG_SIZE_MASK 0x1F
2920#define PD_LOG_PORT_MASK 0xE0
2921#define PD_LOG_PORT_SHIFT 5
2922#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
2923 ((size) & PD_LOG_SIZE_MASK))
2924#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
2925#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
2926
2927/* PD event log : entry types */
2928/* PD MCU events */
2929#define PD_EVENT_MCU_BASE 0x00
2930#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
2931#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
2932/* Reserved for custom board event */
2933#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
2934/* PD generic accessory events */
2935#define PD_EVENT_ACC_BASE 0x20
2936#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
2937#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
2938/* PD power supply events */
2939#define PD_EVENT_PS_BASE 0x40
2940#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
2941/* PD video dongles events */
2942#define PD_EVENT_VIDEO_BASE 0x60
2943#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
2944#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
2945/* Returned in the "type" field, when there is no entry available */
2946#define PD_EVENT_NO_ENTRY 0xFF
2947
2948/*
2949 * PD_EVENT_MCU_CHARGE event definition :
2950 * the payload is "struct usb_chg_measures"
2951 * the data field contains the port state flags as defined below :
2952 */
2953/* Port partner is a dual role device */
2954#define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
2955/* Port is the pending override port */
2956#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
2957/* Port is the override port */
2958#define CHARGE_FLAGS_OVERRIDE (1 << 13)
2959/* Charger type */
2960#define CHARGE_FLAGS_TYPE_SHIFT 3
2961#define CHARGE_FLAGS_TYPE_MASK (0xF << CHARGE_FLAGS_TYPE_SHIFT)
2962/* Power delivery role */
2963#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
2964
2965/*
2966 * PD_EVENT_PS_FAULT data field flags definition :
2967 */
2968#define PS_FAULT_OCP 1
2969#define PS_FAULT_FAST_OCP 2
2970#define PS_FAULT_OVP 3
2971#define PS_FAULT_DISCH 4
2972
2973/*
2974 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
2975 */
2976struct mcdp_version {
2977 uint8_t major;
2978 uint8_t minor;
2979 uint16_t build;
2980} __packed;
2981
2982struct mcdp_info {
2983 uint8_t family[2];
2984 uint8_t chipid[2];
2985 struct mcdp_version irom;
2986 struct mcdp_version fw;
2987} __packed;
2988
2989/* struct mcdp_info field decoding */
2990#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
2991#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
2992
2993/* Get/Set USB-PD Alternate mode info */
2994#define EC_CMD_USB_PD_GET_AMODE 0x116
2995struct ec_params_usb_pd_get_mode_request {
2996 uint16_t svid_idx; /* SVID index to get */
2997 uint8_t port; /* port */
2998} __packed;
2999
3000struct ec_params_usb_pd_get_mode_response {
3001 uint16_t svid; /* SVID */
3002 uint16_t opos; /* Object Position */
3003 uint32_t vdo[6]; /* Mode VDOs */
3004} __packed;
3005
3006#define EC_CMD_USB_PD_SET_AMODE 0x117
3007
3008enum pd_mode_cmd {
3009 PD_EXIT_MODE = 0,
3010 PD_ENTER_MODE = 1,
3011 /* Not a command. Do NOT remove. */
3012 PD_MODE_CMD_COUNT,
3013};
3014
3015struct ec_params_usb_pd_set_mode_request {
3016 uint32_t cmd; /* enum pd_mode_cmd */
3017 uint16_t svid; /* SVID to set */
3018 uint8_t opos; /* Object Position */
3019 uint8_t port; /* port */
3020} __packed;
3021
3022/* Ask the PD MCU to record a log of a requested type */
3023#define EC_CMD_PD_WRITE_LOG_ENTRY 0x118
3024
3025struct ec_params_pd_write_log_entry {
3026 uint8_t type; /* event type : see PD_EVENT_xx above */
3027 uint8_t port; /* port#, or 0 for events unrelated to a given port */
3028} __packed;
3029
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003030#endif /* !__ACPI__ */
3031
Duncan Laurie93e24442014-01-06 12:30:52 -08003032/*****************************************************************************/
3033/*
Duncan Laurie8caa80b2014-09-18 12:48:06 -07003034 * Passthru commands
3035 *
3036 * Some platforms have sub-processors chained to each other. For example.
3037 *
3038 * AP <--> EC <--> PD MCU
3039 *
3040 * The top 2 bits of the command number are used to indicate which device the
3041 * command is intended for. Device 0 is always the device receiving the
3042 * command; other device mapping is board-specific.
3043 *
3044 * When a device receives a command to be passed to a sub-processor, it passes
3045 * it on with the device number set back to 0. This allows the sub-processor
3046 * to remain blissfully unaware of whether the command originated on the next
3047 * device up the chain, or was passed through from the AP.
3048 *
3049 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3050 * AP sends command 0x4002 to the EC
3051 * EC sends command 0x0002 to the PD MCU
3052 * EC forwards PD MCU response back to the AP
3053 */
3054
3055/* Offset and max command number for sub-device n */
3056#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3057#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3058
3059/*****************************************************************************/
3060/*
Duncan Laurie93e24442014-01-06 12:30:52 -08003061 * Deprecated constants. These constants have been renamed for clarity. The
3062 * meaning and size has not changed. Programs that use the old names should
3063 * switch to the new names soon, as the old names may not be carried forward
3064 * forever.
3065 */
3066#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3067#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3068#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3069
Stefan Reinauerd6682e82013-02-21 15:39:35 -08003070#endif /* __CROS_EC_COMMANDS_H */