blob: b704459805e9cff41f6a17c6ccc3c72792178b13 [file] [log] [blame]
David Hendricks1649d162016-09-16 18:13:11 -07001/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +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
David Hendricks1649d162016-09-16 18:13:11 -07008#ifndef __CROS_EC_EC_COMMANDS_H
9#define __CROS_EC_EC_COMMANDS_H
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080010
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +080011#if !defined(__ACPI__) && !defined(__KERNEL__)
Wei-Ning Huang7b491f72017-05-05 21:43:22 +080012#include <stdint.h>
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +080013#endif
Wei-Ning Huang7b491f72017-05-05 21:43:22 +080014
15/*
16 * Include common.h for CONFIG_HOSTCMD_ALIGNED, if it's defined. This
17 * generates more efficient code for accessing request/response structures on
18 * ARM Cortex-M if the structures are guaranteed 32-bit aligned.
19 */
20#ifdef CHROMIUM_EC
21#include "common.h"
22#endif
23
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080024/*
David Hendricksb6847ac2014-08-17 17:59:24 -070025 * Current version of this protocol
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080026 *
David Hendricksb6847ac2014-08-17 17:59:24 -070027 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
28 * determined in other ways. Remove this once the kernel code no longer
29 * depends on it.
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080030 */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080031#define EC_PROTO_VERSION 0x00000002
32
33/* Command version mask */
34#define EC_VER_MASK(version) (1UL << (version))
35
36/* I/O addresses for ACPI commands */
37#define EC_LPC_ADDR_ACPI_DATA 0x62
38#define EC_LPC_ADDR_ACPI_CMD 0x66
39
40/* I/O addresses for host command */
41#define EC_LPC_ADDR_HOST_DATA 0x200
42#define EC_LPC_ADDR_HOST_CMD 0x204
43
44/* I/O addresses for host command args and params */
David Hendricks2d6db772013-07-10 21:07:48 -070045/* Protocol version 2 */
46#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
47#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
48 * EC_PROTO2_MAX_PARAM_SIZE */
49/* Protocol version 3 */
50#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
51#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080052
David Hendricks2d6db772013-07-10 21:07:48 -070053/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
54 * and they tell the kernel that so we have to think of it as two parts. */
55#define EC_HOST_CMD_REGION0 0x800
56#define EC_HOST_CMD_REGION1 0x880
57#define EC_HOST_CMD_REGION_SIZE 0x80
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080058
59/* EC command register bit functions */
60#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
61#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
62#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
63#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
64#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
65#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
66#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
67
68#define EC_LPC_ADDR_MEMMAP 0x900
69#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
70#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
71
72/* The offset address of each type of data in mapped memory. */
David Hendricksb6847ac2014-08-17 17:59:24 -070073#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
74#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
75#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
76#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080077#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
78#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
79#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
80#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
81#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
David Hendricksb6847ac2014-08-17 17:59:24 -070082#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
83/* Unused 0x28 - 0x2f */
84#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
85/* Unused 0x31 - 0x33 */
86#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
87/* Reserve 0x38 - 0x3f for additional host event-related stuff */
88/* Battery values are all 32 bits */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080089#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
90#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
91#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
92#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
93#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
94#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
95#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
96#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
David Hendricksb6847ac2014-08-17 17:59:24 -070097/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +080098#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
99#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
100#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
101#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
David Hendricksb6847ac2014-08-17 17:59:24 -0700102#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
103/* Unused 0x84 - 0x8f */
104#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
105/* Unused 0x91 */
David Hendricks1649d162016-09-16 18:13:11 -0700106#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
107/* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
108/* 0x94 - 0x99: 1st Accelerometer */
109/* 0x9a - 0x9f: 2nd Accelerometer */
David Hendricksb6847ac2014-08-17 17:59:24 -0700110#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
David Hendricks1649d162016-09-16 18:13:11 -0700111/* Unused 0xa6 - 0xdf */
David Hendricksb6847ac2014-08-17 17:59:24 -0700112
David Hendricks1649d162016-09-16 18:13:11 -0700113/*
114 * ACPI is unable to access memory mapped data at or above this offset due to
115 * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
116 * which might be needed by ACPI.
117 */
118#define EC_MEMMAP_NO_ACPI 0xe0
David Hendricksb6847ac2014-08-17 17:59:24 -0700119
120/* Define the format of the accelerometer mapped memory status byte. */
121#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
122#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
123#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800124
125/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
126#define EC_TEMP_SENSOR_ENTRIES 16
127/*
128 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
129 *
130 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
131 */
David Hendricks2d6db772013-07-10 21:07:48 -0700132#define EC_TEMP_SENSOR_B_ENTRIES 8
David Hendricksb6847ac2014-08-17 17:59:24 -0700133
134/* Special values for mapped temperature sensors */
David Hendricks2d6db772013-07-10 21:07:48 -0700135#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
136#define EC_TEMP_SENSOR_ERROR 0xfe
137#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
138#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800139/*
140 * The offset of temperature value stored in mapped memory. This allows
141 * reporting a temperature range of 200K to 454K = -73C to 181C.
142 */
143#define EC_TEMP_SENSOR_OFFSET 200
144
David Hendricksb6847ac2014-08-17 17:59:24 -0700145/*
146 * Number of ALS readings at EC_MEMMAP_ALS
147 */
148#define EC_ALS_ENTRIES 2
149
150/*
151 * The default value a temperature sensor will return when it is present but
152 * has not been read this boot. This is a reasonable number to avoid
153 * triggering alarms on the host.
154 */
155#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
156
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800157#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
158#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
159#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
160
161/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
162#define EC_BATT_FLAG_AC_PRESENT 0x01
163#define EC_BATT_FLAG_BATT_PRESENT 0x02
164#define EC_BATT_FLAG_DISCHARGING 0x04
165#define EC_BATT_FLAG_CHARGING 0x08
166#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
167
168/* Switch flags at EC_MEMMAP_SWITCHES */
169#define EC_SWITCH_LID_OPEN 0x01
170#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
171#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
David Hendricks2d6db772013-07-10 21:07:48 -0700172/* Was recovery requested via keyboard; now unused. */
173#define EC_SWITCH_IGNORE1 0x08
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800174/* Recovery requested via dedicated signal (from servo board) */
175#define EC_SWITCH_DEDICATED_RECOVERY 0x10
176/* Was fake developer mode switch; now unused. Remove in next refactor. */
177#define EC_SWITCH_IGNORE0 0x20
178
179/* Host command interface flags */
180/* Host command interface supports LPC args (LPC interface only) */
181#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
David Hendricks2d6db772013-07-10 21:07:48 -0700182/* Host command interface supports version 3 protocol */
183#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800184
185/* Wireless switch flags */
David Hendricksb6847ac2014-08-17 17:59:24 -0700186#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
187#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
188#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
189#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
190#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800191
David Hendricks1649d162016-09-16 18:13:11 -0700192/*****************************************************************************/
193/*
194 * ACPI commands
195 *
196 * These are valid ONLY on the ACPI command/data port.
197 */
198
199/*
200 * ACPI Read Embedded Controller
201 *
202 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
203 *
204 * Use the following sequence:
205 *
206 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
207 * - Wait for EC_LPC_CMDR_PENDING bit to clear
208 * - Write address to EC_LPC_ADDR_ACPI_DATA
209 * - Wait for EC_LPC_CMDR_DATA bit to set
210 * - Read value from EC_LPC_ADDR_ACPI_DATA
211 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800212#define EC_CMD_ACPI_READ 0x0080
David Hendricks1649d162016-09-16 18:13:11 -0700213
214/*
215 * ACPI Write Embedded Controller
216 *
217 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
218 *
219 * Use the following sequence:
220 *
221 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
222 * - Wait for EC_LPC_CMDR_PENDING bit to clear
223 * - Write address to EC_LPC_ADDR_ACPI_DATA
224 * - Wait for EC_LPC_CMDR_PENDING bit to clear
225 * - Write value to EC_LPC_ADDR_ACPI_DATA
226 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800227#define EC_CMD_ACPI_WRITE 0x0081
David Hendricks1649d162016-09-16 18:13:11 -0700228
229/*
230 * ACPI Burst Enable Embedded Controller
231 *
232 * This enables burst mode on the EC to allow the host to issue several
233 * commands back-to-back. While in this mode, writes to mapped multi-byte
234 * data are locked out to ensure data consistency.
235 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800236#define EC_CMD_ACPI_BURST_ENABLE 0x0082
David Hendricks1649d162016-09-16 18:13:11 -0700237
238/*
239 * ACPI Burst Disable Embedded Controller
240 *
241 * This disables burst mode on the EC and stops preventing EC writes to mapped
242 * multi-byte data.
243 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800244#define EC_CMD_ACPI_BURST_DISABLE 0x0083
David Hendricks1649d162016-09-16 18:13:11 -0700245
246/*
247 * ACPI Query Embedded Controller
248 *
249 * This clears the lowest-order bit in the currently pending host events, and
250 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
251 * event 0x80000000 = 32), or 0 if no event was pending.
252 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800253#define EC_CMD_ACPI_QUERY_EVENT 0x0084
David Hendricks1649d162016-09-16 18:13:11 -0700254
255/* Valid addresses in ACPI memory space, for read/write commands */
256
257/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
258#define EC_ACPI_MEM_VERSION 0x00
259/*
260 * Test location; writing value here updates test compliment byte to (0xff -
261 * value).
262 */
263#define EC_ACPI_MEM_TEST 0x01
264/* Test compliment; writes here are ignored. */
265#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
266
267/* Keyboard backlight brightness percent (0 - 100) */
268#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
269/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
270#define EC_ACPI_MEM_FAN_DUTY 0x04
271
272/*
273 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
274 * independent thresholds attached to them. The current value of the ID
275 * register determines which sensor is affected by the THRESHOLD and COMMIT
276 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
277 * as the memory-mapped sensors. The COMMIT register applies those settings.
278 *
279 * The spec does not mandate any way to read back the threshold settings
280 * themselves, but when a threshold is crossed the AP needs a way to determine
281 * which sensor(s) are responsible. Each reading of the ID register clears and
282 * returns one sensor ID that has crossed one of its threshold (in either
283 * direction) since the last read. A value of 0xFF means "no new thresholds
284 * have tripped". Setting or enabling the thresholds for a sensor will clear
285 * the unread event count for that sensor.
286 */
287#define EC_ACPI_MEM_TEMP_ID 0x05
288#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
289#define EC_ACPI_MEM_TEMP_COMMIT 0x07
290/*
291 * Here are the bits for the COMMIT register:
292 * bit 0 selects the threshold index for the chosen sensor (0/1)
293 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
294 * Each write to the commit register affects one threshold.
295 */
296#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
297#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
298/*
299 * Example:
300 *
301 * Set the thresholds for sensor 2 to 50 C and 60 C:
302 * write 2 to [0x05] -- select temp sensor 2
303 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
304 * write 0x2 to [0x07] -- enable threshold 0 with this value
305 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
306 * write 0x3 to [0x07] -- enable threshold 1 with this value
307 *
308 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
309 * write 2 to [0x05] -- select temp sensor 2
310 * write 0x1 to [0x07] -- disable threshold 1
311 */
312
313/* DPTF battery charging current limit */
314#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
315
316/* Charging limit is specified in 64 mA steps */
317#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
318/* Value to disable DPTF battery charging limit */
319#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
320
321/*
322 * Report device orientation
323 * bit 0 device is tablet mode
324 */
325#define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
326#define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
327
328/*
329 * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
330 * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
331 */
332#define EC_ACPI_MEM_MAPPED_BEGIN 0x20
333#define EC_ACPI_MEM_MAPPED_SIZE 0xe0
334
335/* Current version of ACPI memory address space */
336#define EC_ACPI_MEM_VERSION_CURRENT 2
337
338
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800339/*
340 * This header file is used in coreboot both in C and ACPI code. The ACPI code
341 * is pre-processed to handle constants but the ASL compiler is unable to
342 * handle actual C code so keep it separate.
343 */
344#ifndef __ACPI__
345
346/*
347 * Define __packed if someone hasn't beat us to it. Linux kernel style
348 * checking prefers __packed over __attribute__((packed)).
349 */
350#ifndef __packed
351#define __packed __attribute__((packed))
352#endif
353
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800354#ifndef __aligned
355#define __aligned(x) __attribute__((aligned(x)))
356#endif
357
358/*
359 * Attributes for EC request and response packets. Just defining __packed
360 * results in inefficient assembly code on ARM, if the structure is actually
361 * 32-bit aligned, as it should be for all buffers.
362 *
363 * Be very careful when adding these to existing structures. They will round
364 * up the structure size to the specified boundary.
365 *
366 * Also be very careful to make that if a structure is included in some other
367 * parent structure that the alignment will still be true given the packing of
368 * the parent structure. This is particularly important if the sub-structure
369 * will be passed as a pointer to another function, since that function will
370 * not know about the misaligment caused by the parent structure's packing.
371 *
372 * Also be very careful using __packed - particularly when nesting non-packed
373 * structures inside packed ones. In fact, DO NOT use __packed directly;
374 * always use one of these attributes.
375 *
376 * Once everything is annotated properly, the following search strings should
377 * not return ANY matches in this file other than right here:
378 *
379 * "__packed" - generates inefficient code; all sub-structs must also be packed
380 *
381 * "struct [^_]" - all structs should be annotated, except for structs that are
382 * members of other structs/unions (and their original declarations should be
383 * annotated).
384 */
385#ifdef CONFIG_HOSTCMD_ALIGNED
386
387/*
388 * Packed structures where offset and size are always aligned to 1, 2, or 4
389 * byte boundary.
390 */
391#define __ec_align1 __packed
392#define __ec_align2 __packed __aligned(2)
393#define __ec_align4 __packed __aligned(4)
394
395/*
396 * Packed structure which must be under-aligned, because its size is not a
397 * 4-byte multiple. This is sub-optimal because it forces byte-wise access
398 * of all multi-byte fields in it, even though they are themselves aligned.
399 *
400 * In theory, we could duplicate the structure with __aligned(4) for accessing
401 * its members, but use the __packed version for sizeof().
402 */
403#define __ec_align_size1 __packed
404
405/*
406 * Packed structure which must be under-aligned, because its offset inside a
407 * parent structure is not a 4-byte multiple.
408 */
409#define __ec_align_offset1 __packed
410#define __ec_align_offset2 __packed __aligned(2)
411
412/*
413 * Structures which are complicated enough that I'm skipping them on the first
414 * pass. They are effectively unchanged from their previous definitions.
415 *
416 * TODO(rspangler): Figure out what to do with these. It's likely necessary
417 * to work out the size and offset of each member and add explicit padding to
418 * maintain those.
419 */
420#define __ec_todo_packed __packed
421#define __ec_todo_unpacked
422
423#else /* !CONFIG_HOSTCMD_ALIGNED */
424
425/*
426 * Packed structures make no assumption about alignment, so they do inefficient
427 * byte-wise reads.
428 */
429#define __ec_align1 __packed
430#define __ec_align2 __packed
431#define __ec_align4 __packed
432#define __ec_align_size1 __packed
433#define __ec_align_offset1 __packed
434#define __ec_align_offset2 __packed
435#define __ec_todo_packed __packed
436#define __ec_todo_unpacked
437
438#endif /* !CONFIG_HOSTCMD_ALIGNED */
439
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800440/* LPC command status byte masks */
441/* EC has written a byte in the data register and host hasn't read it yet */
442#define EC_LPC_STATUS_TO_HOST 0x01
443/* Host has written a command/data byte and the EC hasn't read it yet */
444#define EC_LPC_STATUS_FROM_HOST 0x02
445/* EC is processing a command */
446#define EC_LPC_STATUS_PROCESSING 0x04
447/* Last write to EC was a command, not data */
448#define EC_LPC_STATUS_LAST_CMD 0x08
David Hendricks1649d162016-09-16 18:13:11 -0700449/* EC is in burst mode */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800450#define EC_LPC_STATUS_BURST_MODE 0x10
451/* SCI event is pending (requesting SCI query) */
452#define EC_LPC_STATUS_SCI_PENDING 0x20
453/* SMI event is pending (requesting SMI query) */
454#define EC_LPC_STATUS_SMI_PENDING 0x40
455/* (reserved) */
456#define EC_LPC_STATUS_RESERVED 0x80
457
458/*
459 * EC is busy. This covers both the EC processing a command, and the host has
460 * written a new command but the EC hasn't picked it up yet.
461 */
462#define EC_LPC_STATUS_BUSY_MASK \
463 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
464
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +0800465/* Host command response codes (16-bit). Note that response codes should be
466 * stored in a uint16_t rather than directly in a value of this type.
467 */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800468enum ec_status {
469 EC_RES_SUCCESS = 0,
470 EC_RES_INVALID_COMMAND = 1,
471 EC_RES_ERROR = 2,
472 EC_RES_INVALID_PARAM = 3,
473 EC_RES_ACCESS_DENIED = 4,
474 EC_RES_INVALID_RESPONSE = 5,
475 EC_RES_INVALID_VERSION = 6,
476 EC_RES_INVALID_CHECKSUM = 7,
David Hendricksd6f94492012-08-17 16:01:32 -0700477 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
478 EC_RES_UNAVAILABLE = 9, /* No response available */
479 EC_RES_TIMEOUT = 10, /* We got a timeout */
David Hendricks2d6db772013-07-10 21:07:48 -0700480 EC_RES_OVERFLOW = 11, /* Table / data overflow */
481 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
482 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
David Hendricks1649d162016-09-16 18:13:11 -0700483 EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +0800484 EC_RES_BUS_ERROR = 15, /* Communications bus error */
485 EC_RES_BUSY = 16 /* Up but too busy. Should retry */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800486};
487
488/*
489 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
490 * EC command uses code 0 to mean "no event pending". We explicitly specify
491 * each value in the enum listing so they won't change if we delete/insert an
492 * item or rearrange the list (it needs to be stable across platforms, not
493 * just within a single compiled instance).
494 */
495enum host_event_code {
496 EC_HOST_EVENT_LID_CLOSED = 1,
497 EC_HOST_EVENT_LID_OPEN = 2,
498 EC_HOST_EVENT_POWER_BUTTON = 3,
499 EC_HOST_EVENT_AC_CONNECTED = 4,
500 EC_HOST_EVENT_AC_DISCONNECTED = 5,
501 EC_HOST_EVENT_BATTERY_LOW = 6,
502 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
503 EC_HOST_EVENT_BATTERY = 8,
504 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +0800505 /* Event generated by a device attached to the EC */
506 EC_HOST_EVENT_DEVICE = 10,
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800507 EC_HOST_EVENT_THERMAL = 11,
508 EC_HOST_EVENT_USB_CHARGER = 12,
509 EC_HOST_EVENT_KEY_PRESSED = 13,
510 /*
511 * EC has finished initializing the host interface. The host can check
512 * for this event following sending a EC_CMD_REBOOT_EC command to
513 * determine when the EC is ready to accept subsequent commands.
514 */
515 EC_HOST_EVENT_INTERFACE_READY = 14,
516 /* Keyboard recovery combo has been pressed */
517 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
David Hendricksd6f94492012-08-17 16:01:32 -0700518
519 /* Shutdown due to thermal overload */
520 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
521 /* Shutdown due to battery level too low */
522 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
523
David Hendricksb6847ac2014-08-17 17:59:24 -0700524 /* Suggest that the AP throttle itself */
525 EC_HOST_EVENT_THROTTLE_START = 18,
526 /* Suggest that the AP resume normal speed */
527 EC_HOST_EVENT_THROTTLE_STOP = 19,
528
529 /* Hang detect logic detected a hang and host event timeout expired */
530 EC_HOST_EVENT_HANG_DETECT = 20,
531 /* Hang detect logic detected a hang and warm rebooted the AP */
532 EC_HOST_EVENT_HANG_REBOOT = 21,
533
David Hendricks1649d162016-09-16 18:13:11 -0700534 /* PD MCU triggering host event */
535 EC_HOST_EVENT_PD_MCU = 22,
536
537 /* Battery Status flags have changed */
538 EC_HOST_EVENT_BATTERY_STATUS = 23,
539
540 /* EC encountered a panic, triggering a reset */
541 EC_HOST_EVENT_PANIC = 24,
542
543 /* Keyboard fastboot combo has been pressed */
544 EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
545
546 /* EC RTC event occurred */
547 EC_HOST_EVENT_RTC = 26,
548
549 /* Emulate MKBP event */
550 EC_HOST_EVENT_MKBP = 27,
551
552 /* EC desires to change state of host-controlled USB mux */
553 EC_HOST_EVENT_USB_MUX = 28,
554
555 /* TABLET/LAPTOP mode event*/
556 EC_HOST_EVENT_MODE_CHANGE = 29,
557
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800558 /* Keyboard recovery combo with hardware reinitialization */
559 EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
560
561 /*
562 * Reserve this last bit to indicate that at least one bit in a
563 * secondary host event word is set. See crbug.com/633646.
564 */
565 EC_HOST_EVENT_EXTENDED = 31,
566
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800567 /*
568 * The high bit of the event mask is not used as a host event code. If
569 * it reads back as set, then the entire event mask should be
570 * considered invalid by the host. This can happen when reading the
571 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
572 * not initialized on the EC, or improperly configured on the host.
573 */
574 EC_HOST_EVENT_INVALID = 32
575};
576/* Host event mask */
577#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
578
579/* Arguments at EC_LPC_ADDR_HOST_ARGS */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800580struct __ec_align4 ec_lpc_host_args {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800581 uint8_t flags;
582 uint8_t command_version;
583 uint8_t data_size;
584 /*
585 * Checksum; sum of command + flags + command_version + data_size +
586 * all params/response data bytes.
587 */
588 uint8_t checksum;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800589};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800590
591/* Flags for ec_lpc_host_args.flags */
592/*
593 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
594 * params.
595 *
596 * If EC gets a command and this flag is not set, this is an old-style command.
597 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
598 * unknown length. EC must respond with an old-style response (that is,
David Hendricks1649d162016-09-16 18:13:11 -0700599 * without setting EC_HOST_ARGS_FLAG_TO_HOST).
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800600 */
601#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
602/*
603 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
604 *
605 * If EC responds to a command and this flag is not set, this is an old-style
606 * response. Command version is 0 and response data from EC is at
607 * EC_LPC_ADDR_OLD_PARAM with unknown length.
608 */
609#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
610
David Hendricks2d6db772013-07-10 21:07:48 -0700611/*****************************************************************************/
David Hendricksb6847ac2014-08-17 17:59:24 -0700612/*
613 * Byte codes returned by EC over SPI interface.
614 *
615 * These can be used by the AP to debug the EC interface, and to determine
616 * when the EC is not in a state where it will ever get around to responding
617 * to the AP.
618 *
619 * Example of sequence of bytes read from EC for a current good transfer:
620 * 1. - - AP asserts chip select (CS#)
621 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
622 * 3. - - EC starts handling CS# interrupt
623 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
624 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
625 * bytes looking for EC_SPI_FRAME_START
626 * 6. - - EC finishes processing and sets up response
627 * 7. EC_SPI_FRAME_START - AP reads frame byte
628 * 8. (response packet) - AP reads response packet
629 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
630 * 10 - - AP deasserts chip select
631 * 11 - - EC processes CS# interrupt and sets up DMA for
632 * next request
633 *
634 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
635 * the following byte values:
636 * EC_SPI_OLD_READY
637 * EC_SPI_RX_READY
638 * EC_SPI_RECEIVING
639 * EC_SPI_PROCESSING
640 *
641 * Then the EC found an error in the request, or was not ready for the request
642 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
643 * because the EC is unable to tell when the AP is done sending its request.
644 */
645
646/*
647 * Framing byte which precedes a response packet from the EC. After sending a
648 * request, the AP will clock in bytes until it sees the framing byte, then
649 * clock in the response packet.
650 */
651#define EC_SPI_FRAME_START 0xec
652
653/*
654 * Padding bytes which are clocked out after the end of a response packet.
655 */
656#define EC_SPI_PAST_END 0xed
657
658/*
659 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
660 * that the AP will send a valid packet header (starting with
661 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
662 */
663#define EC_SPI_RX_READY 0xf8
664
665/*
666 * EC has started receiving the request from the AP, but hasn't started
667 * processing it yet.
668 */
669#define EC_SPI_RECEIVING 0xf9
670
671/* EC has received the entire request from the AP and is processing it. */
672#define EC_SPI_PROCESSING 0xfa
673
674/*
675 * EC received bad data from the AP, such as a packet header with an invalid
676 * length. EC will ignore all data until chip select deasserts.
677 */
678#define EC_SPI_RX_BAD_DATA 0xfb
679
680/*
681 * EC received data from the AP before it was ready. That is, the AP asserted
682 * chip select and started clocking data before the EC was ready to receive it.
683 * EC will ignore all data until chip select deasserts.
684 */
685#define EC_SPI_NOT_READY 0xfc
686
687/*
688 * EC was ready to receive a request from the AP. EC has treated the byte sent
689 * by the AP as part of a request packet, or (for old-style ECs) is processing
690 * a fully received packet but is not ready to respond yet.
691 */
692#define EC_SPI_OLD_READY 0xfd
693
694/*****************************************************************************/
David Hendricks2d6db772013-07-10 21:07:48 -0700695
696/*
697 * Protocol version 2 for I2C and SPI send a request this way:
698 *
699 * 0 EC_CMD_VERSION0 + (command version)
700 * 1 Command number
701 * 2 Length of params = N
702 * 3..N+2 Params, if any
703 * N+3 8-bit checksum of bytes 0..N+2
704 *
705 * The corresponding response is:
706 *
707 * 0 Result code (EC_RES_*)
708 * 1 Length of params = M
709 * 2..M+1 Params, if any
710 * M+2 8-bit checksum of bytes 0..M+1
711 */
712#define EC_PROTO2_REQUEST_HEADER_BYTES 3
713#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
714#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
715 EC_PROTO2_REQUEST_TRAILER_BYTES)
716
717#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
718#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
719#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
720 EC_PROTO2_RESPONSE_TRAILER_BYTES)
721
722/* Parameter length was limited by the LPC interface */
723#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
724
725/* Maximum request and response packet sizes for protocol version 2 */
726#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
727 EC_PROTO2_MAX_PARAM_SIZE)
728#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
729 EC_PROTO2_MAX_PARAM_SIZE)
730
731/*****************************************************************************/
732
733/*
734 * Value written to legacy command port / prefix byte to indicate protocol
735 * 3+ structs are being used. Usage is bus-dependent.
736 */
737#define EC_COMMAND_PROTOCOL_3 0xda
738
739#define EC_HOST_REQUEST_VERSION 3
740
741/* Version 3 request from host */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800742struct __ec_align4 ec_host_request {
743 /* Structure version (=3)
David Hendricks2d6db772013-07-10 21:07:48 -0700744 *
745 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
746 * version it doesn't know how to parse.
747 */
748 uint8_t struct_version;
749
750 /*
751 * Checksum of request and data; sum of all bytes including checksum
752 * should total to 0.
753 */
754 uint8_t checksum;
755
756 /* Command code */
757 uint16_t command;
758
759 /* Command version */
760 uint8_t command_version;
761
762 /* Unused byte in current protocol version; set to 0 */
763 uint8_t reserved;
764
765 /* Length of data which follows this header */
766 uint16_t data_len;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800767};
David Hendricks2d6db772013-07-10 21:07:48 -0700768
769#define EC_HOST_RESPONSE_VERSION 3
770
771/* Version 3 response from EC */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800772struct __ec_align4 ec_host_response {
773 /* Structure version (=3) */
David Hendricks2d6db772013-07-10 21:07:48 -0700774 uint8_t struct_version;
775
776 /*
777 * Checksum of response and data; sum of all bytes including checksum
778 * should total to 0.
779 */
780 uint8_t checksum;
781
782 /* Result code (EC_RES_*) */
783 uint16_t result;
784
785 /* Length of data which follows this header */
786 uint16_t data_len;
787
788 /* Unused bytes in current protocol version; set to 0 */
789 uint16_t reserved;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800790};
David Hendricks2d6db772013-07-10 21:07:48 -0700791
792/*****************************************************************************/
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800793/*
794 * Notes on commands:
795 *
David Hendricksb6847ac2014-08-17 17:59:24 -0700796 * Each command is an 16-bit command value. Commands which take params or
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800797 * return response data specify structures for that data. If no structure is
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800798 * specified, the command does not input or output data, respectively.
799 * Parameter/response length is implicit in the structs. Some underlying
800 * communication protocols (I2C, SPI) may add length or checksum headers, but
801 * those are implementation-dependent and not defined here.
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800802 *
803 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
804 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800805 */
806
807/*****************************************************************************/
808/* General / test commands */
809
810/*
811 * Get protocol version, used to deal with non-backward compatible protocol
812 * changes.
813 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800814#define EC_CMD_PROTO_VERSION 0x0000
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800815
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800816struct __ec_align4 ec_response_proto_version {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800817 uint32_t version;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800818};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800819
820/*
821 * Hello. This is a simple command to test the EC is responsive to
822 * commands.
823 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800824#define EC_CMD_HELLO 0x0001
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800825
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800826struct __ec_align4 ec_params_hello {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800827 uint32_t in_data; /* Pass anything here */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800828};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800829
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800830struct __ec_align4 ec_response_hello {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800831 uint32_t out_data; /* Output will be in_data + 0x01020304 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800832};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800833
834/* Get version number */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800835#define EC_CMD_GET_VERSION 0x0002
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800836
837enum ec_current_image {
838 EC_IMAGE_UNKNOWN = 0,
839 EC_IMAGE_RO,
840 EC_IMAGE_RW
841};
842
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800843struct __ec_align4 ec_response_get_version {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800844 /* Null-terminated version strings for RO, RW */
845 char version_string_ro[32];
846 char version_string_rw[32];
847 char reserved[32]; /* Was previously RW-B string */
848 uint32_t current_image; /* One of ec_current_image */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800849};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800850
851/* Read test */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800852#define EC_CMD_READ_TEST 0x0003
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800853
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800854struct __ec_align4 ec_params_read_test {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800855 uint32_t offset; /* Starting value for read buffer */
856 uint32_t size; /* Size to read in bytes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800857};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800858
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800859struct __ec_align4 ec_response_read_test {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800860 uint32_t data[32];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800861};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800862
863/*
864 * Get build information
865 *
866 * Response is null-terminated string.
867 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800868#define EC_CMD_GET_BUILD_INFO 0x0004
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800869
870/* Get chip info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800871#define EC_CMD_GET_CHIP_INFO 0x0005
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800872
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800873struct __ec_align4 ec_response_get_chip_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800874 /* Null-terminated strings */
875 char vendor[32];
876 char name[32];
877 char revision[32]; /* Mask version */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800878};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800879
880/* Get board HW version */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800881#define EC_CMD_GET_BOARD_VERSION 0x0006
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800882
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800883struct __ec_align2 ec_response_board_version {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800884 uint16_t board_version; /* A monotonously incrementing number. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800885};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800886
887/*
888 * Read memory-mapped data.
889 *
890 * This is an alternate interface to memory-mapped data for bus protocols
891 * which don't support direct-mapped memory - I2C, SPI, etc.
892 *
893 * Response is params.size bytes of data.
894 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800895#define EC_CMD_READ_MEMMAP 0x0007
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800896
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800897struct __ec_align1 ec_params_read_memmap {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800898 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
899 uint8_t size; /* Size to read in bytes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800900};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800901
902/* Read versions supported for a command */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800903#define EC_CMD_GET_CMD_VERSIONS 0x0008
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800904
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800905struct __ec_align1 ec_params_get_cmd_versions {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800906 uint8_t cmd; /* Command to check */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800907};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800908
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800909struct __ec_align2 ec_params_get_cmd_versions_v1 {
David Hendricks1649d162016-09-16 18:13:11 -0700910 uint16_t cmd; /* Command to check */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800911};
David Hendricks1649d162016-09-16 18:13:11 -0700912
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800913struct __ec_align4 ec_response_get_cmd_versions {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800914 /*
915 * Mask of supported versions; use EC_VER_MASK() to compare with a
916 * desired version.
917 */
918 uint32_t version_mask;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800919};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +0800920
David Hendricksd6f94492012-08-17 16:01:32 -0700921/*
David Hendricks1649d162016-09-16 18:13:11 -0700922 * Check EC communications status (busy). This is needed on i2c/spi but not
David Hendricksd6f94492012-08-17 16:01:32 -0700923 * on lpc since it has its own out-of-band busy indicator.
924 *
925 * lpc must read the status from the command register. Attempting this on
926 * lpc will overwrite the args/parameter space and corrupt its data.
927 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800928#define EC_CMD_GET_COMMS_STATUS 0x0009
David Hendricksd6f94492012-08-17 16:01:32 -0700929
930/* Avoid using ec_status which is for return values */
931enum ec_comms_status {
932 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
933};
934
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800935struct __ec_align4 ec_response_get_comms_status {
David Hendricksd6f94492012-08-17 16:01:32 -0700936 uint32_t flags; /* Mask of enum ec_comms_status */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800937};
David Hendricksd6f94492012-08-17 16:01:32 -0700938
David Hendricksb6847ac2014-08-17 17:59:24 -0700939/* Fake a variety of responses, purely for testing purposes. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800940#define EC_CMD_TEST_PROTOCOL 0x000A
David Hendricks2d6db772013-07-10 21:07:48 -0700941
942/* Tell the EC what to send back to us. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800943struct __ec_align4 ec_params_test_protocol {
David Hendricks2d6db772013-07-10 21:07:48 -0700944 uint32_t ec_result;
945 uint32_t ret_len;
946 uint8_t buf[32];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800947};
David Hendricks2d6db772013-07-10 21:07:48 -0700948
949/* Here it comes... */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800950struct __ec_align4 ec_response_test_protocol {
David Hendricks2d6db772013-07-10 21:07:48 -0700951 uint8_t buf[32];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800952};
David Hendricks2d6db772013-07-10 21:07:48 -0700953
David Hendricks1649d162016-09-16 18:13:11 -0700954/* Get protocol information */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800955#define EC_CMD_GET_PROTOCOL_INFO 0x000B
David Hendricks2d6db772013-07-10 21:07:48 -0700956
957/* Flags for ec_response_get_protocol_info.flags */
958/* EC_RES_IN_PROGRESS may be returned if a command is slow */
959#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
960
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800961struct __ec_align4 ec_response_get_protocol_info {
David Hendricks2d6db772013-07-10 21:07:48 -0700962 /* Fields which exist if at least protocol version 3 supported */
963
964 /* Bitmask of protocol versions supported (1 << n means version n)*/
965 uint32_t protocol_versions;
966
967 /* Maximum request packet size, in bytes */
968 uint16_t max_request_packet_size;
969
970 /* Maximum response packet size, in bytes */
971 uint16_t max_response_packet_size;
972
973 /* Flags; see EC_PROTOCOL_INFO_* */
974 uint32_t flags;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800975};
David Hendricksd6f94492012-08-17 16:01:32 -0700976
David Hendricksb6847ac2014-08-17 17:59:24 -0700977
978/*****************************************************************************/
979/* Get/Set miscellaneous values */
980
981/* The upper byte of .flags tells what to do (nothing means "get") */
982#define EC_GSV_SET 0x80000000
983
984/* The lower three bytes of .flags identifies the parameter, if that has
985 meaning for an individual command. */
986#define EC_GSV_PARAM_MASK 0x00ffffff
987
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800988struct __ec_align4 ec_params_get_set_value {
David Hendricksb6847ac2014-08-17 17:59:24 -0700989 uint32_t flags;
990 uint32_t value;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800991};
David Hendricksb6847ac2014-08-17 17:59:24 -0700992
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800993struct __ec_align4 ec_response_get_set_value {
David Hendricksb6847ac2014-08-17 17:59:24 -0700994 uint32_t flags;
995 uint32_t value;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800996};
David Hendricksb6847ac2014-08-17 17:59:24 -0700997
David Hendricks1649d162016-09-16 18:13:11 -0700998/* More than one command can use these structs to get/set parameters. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +0800999#define EC_CMD_GSV_PAUSE_IN_S5 0x000C
David Hendricksb6847ac2014-08-17 17:59:24 -07001000
David Hendricks1649d162016-09-16 18:13:11 -07001001/*****************************************************************************/
1002/* List the features supported by the firmware */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001003#define EC_CMD_GET_FEATURES 0x000D
David Hendricks1649d162016-09-16 18:13:11 -07001004
1005/* Supported features */
1006enum ec_feature_code {
1007 /*
1008 * This image contains a limited set of features. Another image
1009 * in RW partition may support more features.
1010 */
1011 EC_FEATURE_LIMITED = 0,
1012 /*
1013 * Commands for probing/reading/writing/erasing the flash in the
1014 * EC are present.
1015 */
1016 EC_FEATURE_FLASH = 1,
1017 /*
1018 * Can control the fan speed directly.
1019 */
1020 EC_FEATURE_PWM_FAN = 2,
1021 /*
1022 * Can control the intensity of the keyboard backlight.
1023 */
1024 EC_FEATURE_PWM_KEYB = 3,
1025 /*
1026 * Support Google lightbar, introduced on Pixel.
1027 */
1028 EC_FEATURE_LIGHTBAR = 4,
1029 /* Control of LEDs */
1030 EC_FEATURE_LED = 5,
1031 /* Exposes an interface to control gyro and sensors.
1032 * The host goes through the EC to access these sensors.
1033 * In addition, the EC may provide composite sensors, like lid angle.
1034 */
1035 EC_FEATURE_MOTION_SENSE = 6,
1036 /* The keyboard is controlled by the EC */
1037 EC_FEATURE_KEYB = 7,
1038 /* The AP can use part of the EC flash as persistent storage. */
1039 EC_FEATURE_PSTORE = 8,
1040 /* The EC monitors BIOS port 80h, and can return POST codes. */
1041 EC_FEATURE_PORT80 = 9,
1042 /*
1043 * Thermal management: include TMP specific commands.
1044 * Higher level than direct fan control.
1045 */
1046 EC_FEATURE_THERMAL = 10,
1047 /* Can switch the screen backlight on/off */
1048 EC_FEATURE_BKLIGHT_SWITCH = 11,
1049 /* Can switch the wifi module on/off */
1050 EC_FEATURE_WIFI_SWITCH = 12,
1051 /* Monitor host events, through for example SMI or SCI */
1052 EC_FEATURE_HOST_EVENTS = 13,
1053 /* The EC exposes GPIO commands to control/monitor connected devices. */
1054 EC_FEATURE_GPIO = 14,
1055 /* The EC can send i2c messages to downstream devices. */
1056 EC_FEATURE_I2C = 15,
1057 /* Command to control charger are included */
1058 EC_FEATURE_CHARGER = 16,
1059 /* Simple battery support. */
1060 EC_FEATURE_BATTERY = 17,
1061 /*
1062 * Support Smart battery protocol
1063 * (Common Smart Battery System Interface Specification)
1064 */
1065 EC_FEATURE_SMART_BATTERY = 18,
1066 /* EC can detect when the host hangs. */
1067 EC_FEATURE_HANG_DETECT = 19,
1068 /* Report power information, for pit only */
1069 EC_FEATURE_PMU = 20,
1070 /* Another Cros EC device is present downstream of this one */
1071 EC_FEATURE_SUB_MCU = 21,
1072 /* Support USB Power delivery (PD) commands */
1073 EC_FEATURE_USB_PD = 22,
1074 /* Control USB multiplexer, for audio through USB port for instance. */
1075 EC_FEATURE_USB_MUX = 23,
1076 /* Motion Sensor code has an internal software FIFO */
1077 EC_FEATURE_MOTION_SENSE_FIFO = 24,
1078 /* Support temporary secure vstore */
1079 EC_FEATURE_VSTORE = 25,
1080 /* EC decides on USB-C SS mux state, muxes configured by host */
1081 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
1082 /* EC has RTC feature that can be controlled by host commands */
1083 EC_FEATURE_RTC = 27,
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001084 /* The MCU exposes a Fingerprint sensor */
1085 EC_FEATURE_FINGERPRINT = 28,
1086 /* The MCU exposes a Touchpad */
1087 EC_FEATURE_TOUCHPAD = 29,
Wei-Ning Huang04a04fb2017-05-09 02:44:48 +08001088 /* The MCU has RWSIG task enabled */
1089 EC_FEATURE_RWSIG = 30,
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001090 /* EC has device events support */
1091 EC_FEATURE_DEVICE_EVENT = 31,
Daisuke Nojiricfd7dfc2018-04-04 10:43:30 -07001092 /* EC supports the unified wake masks for LPC/eSPI systems */
1093 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
1094 /* EC supports 64-bit host events */
1095 EC_FEATURE_HOST_EVENT64 = 33,
1096 /* EC runs code in RAM (not in place, a.k.a. XIP) */
1097 EC_FEATURE_EXEC_IN_RAM = 34,
David Hendricks1649d162016-09-16 18:13:11 -07001098};
1099
1100#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
1101#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001102struct __ec_align4 ec_response_get_features {
David Hendricks1649d162016-09-16 18:13:11 -07001103 uint32_t flags[2];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001104};
David Hendricksb6847ac2014-08-17 17:59:24 -07001105
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001106/*****************************************************************************/
1107/* Flash commands */
1108
1109/* Get flash info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001110#define EC_CMD_FLASH_INFO 0x0010
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001111#define EC_VER_FLASH_INFO 2
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001112
David Hendricksb6847ac2014-08-17 17:59:24 -07001113/* Version 0 returns these fields */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001114struct __ec_align4 ec_response_flash_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001115 /* Usable flash size, in bytes */
1116 uint32_t flash_size;
1117 /*
1118 * Write block size. Write offset and size must be a multiple
1119 * of this.
1120 */
1121 uint32_t write_block_size;
1122 /*
1123 * Erase block size. Erase offset and size must be a multiple
1124 * of this.
1125 */
1126 uint32_t erase_block_size;
1127 /*
1128 * Protection block size. Protection offset and size must be a
1129 * multiple of this.
1130 */
1131 uint32_t protect_block_size;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001132};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001133
David Hendricksb6847ac2014-08-17 17:59:24 -07001134/* Flags for version 1+ flash info command */
1135/* EC flash erases bits to 0 instead of 1 */
1136#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
1137
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001138/* Flash must be selected for read/write/erase operations to succeed. This may
1139 * be necessary on a chip where write/erase can be corrupted by other board
1140 * activity, or where the chip needs to enable some sort of programming voltage,
1141 * or where the read/write/erase operations require cleanly suspending other
1142 * chip functionality. */
1143#define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
1144
David Hendricksb6847ac2014-08-17 17:59:24 -07001145/*
1146 * Version 1 returns the same initial fields as version 0, with additional
1147 * fields following.
1148 *
1149 * gcc anonymous structs don't seem to get along with the __packed directive;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001150 * if they did we'd define the version 0 structure as a sub-structure of this
1151 * one.
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001152 *
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001153 * Version 2 supports flash banks of different sizes:
1154 * The caller specified the number of banks it has preallocated
1155 * (num_banks_desc)
1156 * The EC returns the number of banks describing the flash memory.
1157 * It adds banks descriptions up to num_banks_desc.
David Hendricksb6847ac2014-08-17 17:59:24 -07001158 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001159struct __ec_align4 ec_response_flash_info_1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07001160 /* Version 0 fields; see above for description */
1161 uint32_t flash_size;
1162 uint32_t write_block_size;
1163 uint32_t erase_block_size;
1164 uint32_t protect_block_size;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001165
David Hendricksb6847ac2014-08-17 17:59:24 -07001166 /* Version 1 adds these fields: */
1167 /*
1168 * Ideal write size in bytes. Writes will be fastest if size is
1169 * exactly this and offset is a multiple of this. For example, an EC
1170 * may have a write buffer which can do half-page operations if data is
1171 * aligned, and a slower word-at-a-time write mode.
1172 */
1173 uint32_t write_ideal_size;
1174
1175 /* Flags; see EC_FLASH_INFO_* */
1176 uint32_t flags;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001177};
David Hendricksb6847ac2014-08-17 17:59:24 -07001178
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001179struct __ec_align4 ec_params_flash_info_2 {
1180 /* Number of banks to describe */
1181 uint16_t num_banks_desc;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001182 /* Reserved; set 0; ignore on read */
1183 uint8_t reserved[2];
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001184};
1185
1186struct ec_flash_bank {
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001187 /* Number of sector is in this bank. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001188 uint16_t count;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001189 /* Size in power of 2 of each sector (8 --> 256 bytes) */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001190 uint8_t size_exp;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001191 /* Minimal write size for the sectors in this bank */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001192 uint8_t write_size_exp;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001193 /* Erase size for the sectors in this bank */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001194 uint8_t erase_size_exp;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001195 /* Size for write protection, usually identical to erase size. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001196 uint8_t protect_size_exp;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001197 /* Reserved; set 0; ignore on read */
1198 uint8_t reserved[2];
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001199};
1200
1201struct __ec_align4 ec_response_flash_info_2 {
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001202 /* Total flash in the EC. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001203 uint32_t flash_size;
1204 /* Flags; see EC_FLASH_INFO_* */
1205 uint32_t flags;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001206 /* Maximum size to use to send data to write to the EC. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001207 uint32_t write_ideal_size;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001208 /* Number of banks present in the EC. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001209 uint16_t num_banks_total;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001210 /* Number of banks described in banks array. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001211 uint16_t num_banks_desc;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001212 struct ec_flash_bank banks[0];
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001213};
1214
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001215/*
1216 * Read flash
1217 *
1218 * Response is params.size bytes of data.
1219 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001220#define EC_CMD_FLASH_READ 0x0011
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001221
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001222struct __ec_align4 ec_params_flash_read {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001223 uint32_t offset; /* Byte offset to read */
1224 uint32_t size; /* Size to read in bytes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001225};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001226
1227/* Write flash */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001228#define EC_CMD_FLASH_WRITE 0x0012
David Hendricks2d6db772013-07-10 21:07:48 -07001229#define EC_VER_FLASH_WRITE 1
1230
1231/* Version 0 of the flash command supported only 64 bytes of data */
1232#define EC_FLASH_WRITE_VER0_SIZE 64
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001233
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001234struct __ec_align4 ec_params_flash_write {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001235 uint32_t offset; /* Byte offset to write */
1236 uint32_t size; /* Size to write in bytes */
David Hendricks2d6db772013-07-10 21:07:48 -07001237 /* Followed by data to write */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001238};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001239
1240/* Erase flash */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001241#define EC_CMD_FLASH_ERASE 0x0013
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001242
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001243/* v0 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001244struct __ec_align4 ec_params_flash_erase {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001245 uint32_t offset; /* Byte offset to erase */
1246 uint32_t size; /* Size to erase in bytes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001247};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001248
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001249
1250#define EC_VER_FLASH_WRITE 1
1251/* v1 add async erase:
1252 * subcommands can returns:
1253 * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
1254 * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
1255 * EC_RES_ERROR : other errors.
1256 * EC_RES_BUSY : an existing erase operation is in progress.
1257 * EC_RES_ACCESS_DENIED: Trying to erase running image.
1258 *
1259 * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001260 * properly queued. The user must call ERASE_GET_RESULT subcommand to get
1261 * the proper result.
1262 * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
1263 * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
1264 * ERASE_GET_RESULT command may timeout on EC where flash access is not
1265 * permitted while erasing. (For instance, STM32F4).
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001266 */
1267enum ec_flash_erase_cmd {
1268 FLASH_ERASE_SECTOR, /* Erase and wait for result */
1269 FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
1270 FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
1271};
1272
1273struct __ec_align4 ec_params_flash_erase_v1 {
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001274 /* One of ec_flash_erase_cmd. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001275 uint8_t cmd;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001276 /* Pad byte; currently always contains 0 */
1277 uint8_t reserved;
1278 /* No flags defined yet; set to 0 */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001279 uint16_t flag;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001280 /* Same as v0 parameters. */
Gwendal Grignouc79d1412017-05-16 11:47:16 -07001281 struct ec_params_flash_erase params;
1282};
1283
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001284/*
1285 * Get/set flash protection.
1286 *
1287 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1288 * firmware write protect GPIO, not all flags will take effect immediately;
1289 * some flags require a subsequent hard reset to take effect. Check the
1290 * returned flags bits to see what actually happened.
1291 *
1292 * If mask=0, simply returns the current flags state.
1293 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001294#define EC_CMD_FLASH_PROTECT 0x0015
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001295#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1296
1297/* Flags for flash protection */
1298/* RO flash code protected when the EC boots */
1299#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1300/*
1301 * RO flash code protected now. If this bit is set, at-boot status cannot
1302 * be changed.
1303 */
1304#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
Louis Yung-Chieh Loca052c42012-08-24 14:12:21 +08001305/* Entire flash code protected now, until reboot. */
1306#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001307/* Flash write protect GPIO is asserted now */
1308#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1309/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1310#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1311/*
1312 * Error - flash protection is in inconsistent state. At least one bank of
1313 * flash which should be protected is not protected. Usually fixed by
1314 * re-requesting the desired flags, or by a hard reset if that fails.
1315 */
1316#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
David Hendricks1649d162016-09-16 18:13:11 -07001317/* Entire flash code protected when the EC boots */
Louis Yung-Chieh Loca052c42012-08-24 14:12:21 +08001318#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001319/* RW flash code protected when the EC boots */
1320#define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
1321/* RW flash code protected now. */
1322#define EC_FLASH_PROTECT_RW_NOW (1 << 8)
1323/* Rollback information flash region protected when the EC boots */
1324#define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
1325/* Rollback information flash region protected now */
1326#define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001327
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001328struct __ec_align4 ec_params_flash_protect {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001329 uint32_t mask; /* Bits in flags to apply */
1330 uint32_t flags; /* New flags to apply */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001331};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001332
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001333struct __ec_align4 ec_response_flash_protect {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001334 /* Current value of flash protect flags */
1335 uint32_t flags;
1336 /*
1337 * Flags which are valid on this platform. This allows the caller
1338 * to distinguish between flags which aren't set vs. flags which can't
1339 * be set on this platform.
1340 */
1341 uint32_t valid_flags;
1342 /* Flags which can be changed given the current protection state */
1343 uint32_t writable_flags;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001344};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001345
1346/*
1347 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1348 * write protect. These commands may be reused with version > 0.
1349 */
1350
1351/* Get the region offset/size */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001352#define EC_CMD_FLASH_REGION_INFO 0x0016
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001353#define EC_VER_FLASH_REGION_INFO 1
1354
1355enum ec_flash_region {
1356 /* Region which holds read-only EC image */
David Hendricksb6847ac2014-08-17 17:59:24 -07001357 EC_FLASH_REGION_RO = 0,
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001358 /* Region which holds rewritable EC image */
1359 EC_FLASH_REGION_RW,
1360 /*
1361 * Region which should be write-protected in the factory (a superset of
1362 * EC_FLASH_REGION_RO)
1363 */
1364 EC_FLASH_REGION_WP_RO,
David Hendricksb6847ac2014-08-17 17:59:24 -07001365 /* Number of regions */
1366 EC_FLASH_REGION_COUNT,
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001367};
1368
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001369struct __ec_align4 ec_params_flash_region_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001370 uint32_t region; /* enum ec_flash_region */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001371};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001372
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001373struct __ec_align4 ec_response_flash_region_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001374 uint32_t offset;
1375 uint32_t size;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001376};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001377
David Hendricks2d6db772013-07-10 21:07:48 -07001378/* Read/write VbNvContext */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001379#define EC_CMD_VBNV_CONTEXT 0x0017
David Hendricks2d6db772013-07-10 21:07:48 -07001380#define EC_VER_VBNV_CONTEXT 1
1381#define EC_VBNV_BLOCK_SIZE 16
1382
1383enum ec_vbnvcontext_op {
1384 EC_VBNV_CONTEXT_OP_READ,
1385 EC_VBNV_CONTEXT_OP_WRITE,
1386};
1387
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001388struct __ec_align4 ec_params_vbnvcontext {
David Hendricks2d6db772013-07-10 21:07:48 -07001389 uint32_t op;
1390 uint8_t block[EC_VBNV_BLOCK_SIZE];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001391};
David Hendricks2d6db772013-07-10 21:07:48 -07001392
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001393struct __ec_align4 ec_response_vbnvcontext {
David Hendricks2d6db772013-07-10 21:07:48 -07001394 uint8_t block[EC_VBNV_BLOCK_SIZE];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001395};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001396
David Hendricks1649d162016-09-16 18:13:11 -07001397
1398/* Get SPI flash information */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001399#define EC_CMD_FLASH_SPI_INFO 0x0018
David Hendricks1649d162016-09-16 18:13:11 -07001400
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001401struct __ec_align1 ec_response_flash_spi_info {
David Hendricks1649d162016-09-16 18:13:11 -07001402 /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
1403 uint8_t jedec[3];
1404
1405 /* Pad byte; currently always contains 0 */
1406 uint8_t reserved0;
1407
1408 /* Manufacturer / device ID from command 0x90 */
1409 uint8_t mfr_dev_id[2];
1410
1411 /* Status registers from command 0x05 and 0x35 */
1412 uint8_t sr1, sr2;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001413};
David Hendricks1649d162016-09-16 18:13:11 -07001414
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001415
1416/* Select flash during flash operations */
1417#define EC_CMD_FLASH_SELECT 0x0019
1418
1419struct __ec_align4 ec_params_flash_select {
1420 /* 1 to select flash, 0 to deselect flash */
1421 uint8_t select;
1422};
1423
1424
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001425/*****************************************************************************/
1426/* PWM commands */
1427
1428/* Get fan target RPM */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001429#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001430
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001431struct __ec_align4 ec_response_pwm_get_fan_rpm {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001432 uint32_t rpm;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001433};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001434
1435/* Set target fan RPM */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001436#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001437
David Hendricks1649d162016-09-16 18:13:11 -07001438/* Version 0 of input params */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001439struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001440 uint32_t rpm;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001441};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001442
David Hendricks1649d162016-09-16 18:13:11 -07001443/* Version 1 of input params */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001444struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07001445 uint32_t rpm;
1446 uint8_t fan_idx;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001447};
David Hendricks1649d162016-09-16 18:13:11 -07001448
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001449/* Get keyboard backlight */
David Hendricks1649d162016-09-16 18:13:11 -07001450/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001451#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001452
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001453struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001454 uint8_t percent;
1455 uint8_t enabled;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001456};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001457
1458/* Set keyboard backlight */
David Hendricks1649d162016-09-16 18:13:11 -07001459/* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001460#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001461
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001462struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001463 uint8_t percent;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001464};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001465
1466/* Set target fan PWM duty cycle */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001467#define EC_CMD_PWM_SET_FAN_DUTY 0x0024
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001468
David Hendricks1649d162016-09-16 18:13:11 -07001469/* Version 0 of input params */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001470struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001471 uint32_t percent;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001472};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001473
David Hendricks1649d162016-09-16 18:13:11 -07001474/* Version 1 of input params */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001475struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07001476 uint32_t percent;
1477 uint8_t fan_idx;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001478};
David Hendricks1649d162016-09-16 18:13:11 -07001479
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001480#define EC_CMD_PWM_SET_DUTY 0x0025
David Hendricks1649d162016-09-16 18:13:11 -07001481/* 16 bit duty cycle, 0xffff = 100% */
1482#define EC_PWM_MAX_DUTY 0xffff
1483
1484enum ec_pwm_type {
1485 /* All types, indexed by board-specific enum pwm_channel */
1486 EC_PWM_TYPE_GENERIC = 0,
1487 /* Keyboard backlight */
1488 EC_PWM_TYPE_KB_LIGHT,
1489 /* Display backlight */
1490 EC_PWM_TYPE_DISPLAY_LIGHT,
1491 EC_PWM_TYPE_COUNT,
1492};
1493
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001494struct __ec_align4 ec_params_pwm_set_duty {
David Hendricks1649d162016-09-16 18:13:11 -07001495 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1496 uint8_t pwm_type; /* ec_pwm_type */
1497 uint8_t index; /* Type-specific index, or 0 if unique */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001498};
David Hendricks1649d162016-09-16 18:13:11 -07001499
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001500#define EC_CMD_PWM_GET_DUTY 0x0026
David Hendricks1649d162016-09-16 18:13:11 -07001501
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001502struct __ec_align1 ec_params_pwm_get_duty {
David Hendricks1649d162016-09-16 18:13:11 -07001503 uint8_t pwm_type; /* ec_pwm_type */
1504 uint8_t index; /* Type-specific index, or 0 if unique */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001505};
David Hendricks1649d162016-09-16 18:13:11 -07001506
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001507struct __ec_align2 ec_response_pwm_get_duty {
David Hendricks1649d162016-09-16 18:13:11 -07001508 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001509};
David Hendricks1649d162016-09-16 18:13:11 -07001510
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001511/*****************************************************************************/
1512/*
David Hendricks2d6db772013-07-10 21:07:48 -07001513 * Lightbar commands. This looks worse than it is. Since we only use one HOST
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001514 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1515 * into a subcommand. We'll make separate structs for subcommands with
1516 * different input args, so that we know how much to expect.
1517 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001518#define EC_CMD_LIGHTBAR_CMD 0x0028
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001519
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001520struct __ec_todo_unpacked rgb_s {
David Hendricks2d6db772013-07-10 21:07:48 -07001521 uint8_t r, g, b;
1522};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001523
David Hendricks2d6db772013-07-10 21:07:48 -07001524#define LB_BATTERY_LEVELS 4
1525/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1526 * host command, but the alignment is the same regardless. Keep it that way.
1527 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001528struct __ec_todo_packed lightbar_params_v0 {
David Hendricks2d6db772013-07-10 21:07:48 -07001529 /* Timing */
David Hendricksb6847ac2014-08-17 17:59:24 -07001530 int32_t google_ramp_up;
1531 int32_t google_ramp_down;
1532 int32_t s3s0_ramp_up;
1533 int32_t s0_tick_delay[2]; /* AC=0/1 */
1534 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1535 int32_t s0s3_ramp_down;
1536 int32_t s3_sleep_for;
1537 int32_t s3_ramp_up;
1538 int32_t s3_ramp_down;
David Hendricks2d6db772013-07-10 21:07:48 -07001539
1540 /* Oscillation */
1541 uint8_t new_s0;
1542 uint8_t osc_min[2]; /* AC=0/1 */
1543 uint8_t osc_max[2]; /* AC=0/1 */
1544 uint8_t w_ofs[2]; /* AC=0/1 */
1545
1546 /* Brightness limits based on the backlight and AC. */
1547 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1548 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1549 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1550
1551 /* Battery level thresholds */
1552 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1553
1554 /* Map [AC][battery_level] to color index */
1555 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1556 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1557
1558 /* Color palette */
1559 struct rgb_s color[8]; /* 0-3 are Google colors */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001560};
David Hendricks2d6db772013-07-10 21:07:48 -07001561
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001562struct __ec_todo_packed lightbar_params_v1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07001563 /* Timing */
1564 int32_t google_ramp_up;
1565 int32_t google_ramp_down;
1566 int32_t s3s0_ramp_up;
1567 int32_t s0_tick_delay[2]; /* AC=0/1 */
1568 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1569 int32_t s0s3_ramp_down;
1570 int32_t s3_sleep_for;
1571 int32_t s3_ramp_up;
1572 int32_t s3_ramp_down;
David Hendricks1649d162016-09-16 18:13:11 -07001573 int32_t s5_ramp_up;
1574 int32_t s5_ramp_down;
David Hendricksb6847ac2014-08-17 17:59:24 -07001575 int32_t tap_tick_delay;
David Hendricks1649d162016-09-16 18:13:11 -07001576 int32_t tap_gate_delay;
David Hendricksb6847ac2014-08-17 17:59:24 -07001577 int32_t tap_display_time;
1578
1579 /* Tap-for-battery params */
1580 uint8_t tap_pct_red;
1581 uint8_t tap_pct_green;
1582 uint8_t tap_seg_min_on;
1583 uint8_t tap_seg_max_on;
1584 uint8_t tap_seg_osc;
1585 uint8_t tap_idx[3];
1586
1587 /* Oscillation */
1588 uint8_t osc_min[2]; /* AC=0/1 */
1589 uint8_t osc_max[2]; /* AC=0/1 */
1590 uint8_t w_ofs[2]; /* AC=0/1 */
1591
1592 /* Brightness limits based on the backlight and AC. */
1593 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1594 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1595 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1596
1597 /* Battery level thresholds */
1598 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1599
1600 /* Map [AC][battery_level] to color index */
1601 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1602 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1603
David Hendricks1649d162016-09-16 18:13:11 -07001604 /* s5: single color pulse on inhibited power-up */
1605 uint8_t s5_idx;
1606
David Hendricksb6847ac2014-08-17 17:59:24 -07001607 /* Color palette */
1608 struct rgb_s color[8]; /* 0-3 are Google colors */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001609};
David Hendricksb6847ac2014-08-17 17:59:24 -07001610
David Hendricks1649d162016-09-16 18:13:11 -07001611/* Lightbar command params v2
1612 * crbug.com/467716
1613 *
1614 * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
1615 * logical groups to make it more manageable ( < 120 bytes).
1616 *
1617 * NOTE: Each of these groups must be less than 120 bytes.
1618 */
1619
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001620struct __ec_todo_packed lightbar_params_v2_timing {
David Hendricks1649d162016-09-16 18:13:11 -07001621 /* Timing */
1622 int32_t google_ramp_up;
1623 int32_t google_ramp_down;
1624 int32_t s3s0_ramp_up;
1625 int32_t s0_tick_delay[2]; /* AC=0/1 */
1626 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1627 int32_t s0s3_ramp_down;
1628 int32_t s3_sleep_for;
1629 int32_t s3_ramp_up;
1630 int32_t s3_ramp_down;
1631 int32_t s5_ramp_up;
1632 int32_t s5_ramp_down;
1633 int32_t tap_tick_delay;
1634 int32_t tap_gate_delay;
1635 int32_t tap_display_time;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001636};
David Hendricks1649d162016-09-16 18:13:11 -07001637
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001638struct __ec_todo_packed lightbar_params_v2_tap {
David Hendricks1649d162016-09-16 18:13:11 -07001639 /* Tap-for-battery params */
1640 uint8_t tap_pct_red;
1641 uint8_t tap_pct_green;
1642 uint8_t tap_seg_min_on;
1643 uint8_t tap_seg_max_on;
1644 uint8_t tap_seg_osc;
1645 uint8_t tap_idx[3];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001646};
David Hendricks1649d162016-09-16 18:13:11 -07001647
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001648struct __ec_todo_packed lightbar_params_v2_oscillation {
David Hendricks1649d162016-09-16 18:13:11 -07001649 /* Oscillation */
1650 uint8_t osc_min[2]; /* AC=0/1 */
1651 uint8_t osc_max[2]; /* AC=0/1 */
1652 uint8_t w_ofs[2]; /* AC=0/1 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001653};
David Hendricks1649d162016-09-16 18:13:11 -07001654
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001655struct __ec_todo_packed lightbar_params_v2_brightness {
David Hendricks1649d162016-09-16 18:13:11 -07001656 /* Brightness limits based on the backlight and AC. */
1657 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1658 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1659 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001660};
David Hendricks1649d162016-09-16 18:13:11 -07001661
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001662struct __ec_todo_packed lightbar_params_v2_thresholds {
David Hendricks1649d162016-09-16 18:13:11 -07001663 /* Battery level thresholds */
1664 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001665};
David Hendricks1649d162016-09-16 18:13:11 -07001666
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001667struct __ec_todo_packed lightbar_params_v2_colors {
David Hendricks1649d162016-09-16 18:13:11 -07001668 /* Map [AC][battery_level] to color index */
1669 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1670 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1671
1672 /* s5: single color pulse on inhibited power-up */
1673 uint8_t s5_idx;
1674
1675 /* Color palette */
1676 struct rgb_s color[8]; /* 0-3 are Google colors */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001677};
David Hendricks1649d162016-09-16 18:13:11 -07001678
1679/* Lightbyte program. */
1680#define EC_LB_PROG_LEN 192
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001681struct __ec_todo_unpacked lightbar_program {
David Hendricks1649d162016-09-16 18:13:11 -07001682 uint8_t size;
1683 uint8_t data[EC_LB_PROG_LEN];
1684};
1685
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001686struct __ec_todo_packed ec_params_lightbar {
David Hendricks2d6db772013-07-10 21:07:48 -07001687 uint8_t cmd; /* Command (see enum lightbar_command) */
1688 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001689 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07001690 /* no args */
David Hendricksb6847ac2014-08-17 17:59:24 -07001691 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
David Hendricks1649d162016-09-16 18:13:11 -07001692 version, get_brightness, get_demo, suspend, resume,
1693 get_params_v2_timing, get_params_v2_tap,
1694 get_params_v2_osc, get_params_v2_bright,
1695 get_params_v2_thlds, get_params_v2_colors;
David Hendricks2d6db772013-07-10 21:07:48 -07001696
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001697 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07001698 uint8_t num;
David Hendricksb6847ac2014-08-17 17:59:24 -07001699 } set_brightness, seq, demo;
David Hendricks2d6db772013-07-10 21:07:48 -07001700
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001701 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07001702 uint8_t ctrl, reg, value;
1703 } reg;
1704
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001705 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07001706 uint8_t led, red, green, blue;
David Hendricksb6847ac2014-08-17 17:59:24 -07001707 } set_rgb;
David Hendricks2d6db772013-07-10 21:07:48 -07001708
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001709 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07001710 uint8_t led;
1711 } get_rgb;
1712
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001713 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07001714 uint8_t enable;
1715 } manual_suspend_ctrl;
1716
David Hendricksb6847ac2014-08-17 17:59:24 -07001717 struct lightbar_params_v0 set_params_v0;
1718 struct lightbar_params_v1 set_params_v1;
David Hendricks1649d162016-09-16 18:13:11 -07001719
1720 struct lightbar_params_v2_timing set_v2par_timing;
1721 struct lightbar_params_v2_tap set_v2par_tap;
1722 struct lightbar_params_v2_oscillation set_v2par_osc;
1723 struct lightbar_params_v2_brightness set_v2par_bright;
1724 struct lightbar_params_v2_thresholds set_v2par_thlds;
1725 struct lightbar_params_v2_colors set_v2par_colors;
1726
1727 struct lightbar_program set_program;
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001728 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001729};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001730
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001731struct __ec_todo_packed ec_response_lightbar {
David Hendricks2d6db772013-07-10 21:07:48 -07001732 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001733 struct __ec_todo_unpacked {
1734 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07001735 uint8_t reg;
1736 uint8_t ic0;
1737 uint8_t ic1;
1738 } vals[23];
1739 } dump;
1740
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001741 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07001742 uint8_t num;
David Hendricksb6847ac2014-08-17 17:59:24 -07001743 } get_seq, get_brightness, get_demo;
David Hendricks2d6db772013-07-10 21:07:48 -07001744
David Hendricksb6847ac2014-08-17 17:59:24 -07001745 struct lightbar_params_v0 get_params_v0;
1746 struct lightbar_params_v1 get_params_v1;
1747
David Hendricks1649d162016-09-16 18:13:11 -07001748
1749 struct lightbar_params_v2_timing get_params_v2_timing;
1750 struct lightbar_params_v2_tap get_params_v2_tap;
1751 struct lightbar_params_v2_oscillation get_params_v2_osc;
1752 struct lightbar_params_v2_brightness get_params_v2_bright;
1753 struct lightbar_params_v2_thresholds get_params_v2_thlds;
1754 struct lightbar_params_v2_colors get_params_v2_colors;
1755
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001756 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07001757 uint32_t num;
1758 uint32_t flags;
1759 } version;
1760
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001761 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07001762 uint8_t red, green, blue;
1763 } get_rgb;
David Hendricks2d6db772013-07-10 21:07:48 -07001764
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001765 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07001766 /* no return params */
David Hendricksb6847ac2014-08-17 17:59:24 -07001767 } off, on, init, set_brightness, seq, reg, set_rgb,
David Hendricks1649d162016-09-16 18:13:11 -07001768 demo, set_params_v0, set_params_v1,
1769 set_program, manual_suspend_ctrl, suspend, resume,
1770 set_v2par_timing, set_v2par_tap,
1771 set_v2par_osc, set_v2par_bright, set_v2par_thlds,
1772 set_v2par_colors;
David Hendricks2d6db772013-07-10 21:07:48 -07001773 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001774};
David Hendricks2d6db772013-07-10 21:07:48 -07001775
1776/* Lightbar commands */
1777enum lightbar_command {
1778 LIGHTBAR_CMD_DUMP = 0,
1779 LIGHTBAR_CMD_OFF = 1,
1780 LIGHTBAR_CMD_ON = 2,
1781 LIGHTBAR_CMD_INIT = 3,
David Hendricksb6847ac2014-08-17 17:59:24 -07001782 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
David Hendricks2d6db772013-07-10 21:07:48 -07001783 LIGHTBAR_CMD_SEQ = 5,
1784 LIGHTBAR_CMD_REG = 6,
David Hendricksb6847ac2014-08-17 17:59:24 -07001785 LIGHTBAR_CMD_SET_RGB = 7,
David Hendricks2d6db772013-07-10 21:07:48 -07001786 LIGHTBAR_CMD_GET_SEQ = 8,
1787 LIGHTBAR_CMD_DEMO = 9,
David Hendricksb6847ac2014-08-17 17:59:24 -07001788 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1789 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
1790 LIGHTBAR_CMD_VERSION = 12,
1791 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1792 LIGHTBAR_CMD_GET_RGB = 14,
1793 LIGHTBAR_CMD_GET_DEMO = 15,
1794 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1795 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
David Hendricks1649d162016-09-16 18:13:11 -07001796 LIGHTBAR_CMD_SET_PROGRAM = 18,
1797 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1798 LIGHTBAR_CMD_SUSPEND = 20,
1799 LIGHTBAR_CMD_RESUME = 21,
1800 LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
1801 LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
1802 LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
1803 LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
1804 LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
1805 LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
1806 LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
1807 LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
1808 LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
1809 LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
1810 LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
1811 LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
David Hendricks2d6db772013-07-10 21:07:48 -07001812 LIGHTBAR_NUM_CMDS
1813};
1814
1815/*****************************************************************************/
1816/* LED control commands */
1817
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001818#define EC_CMD_LED_CONTROL 0x0029
David Hendricks2d6db772013-07-10 21:07:48 -07001819
1820enum ec_led_id {
David Hendricksb6847ac2014-08-17 17:59:24 -07001821 /* LED to indicate battery state of charge */
David Hendricks2d6db772013-07-10 21:07:48 -07001822 EC_LED_ID_BATTERY_LED = 0,
David Hendricksb6847ac2014-08-17 17:59:24 -07001823 /*
1824 * LED to indicate system power state (on or in suspend).
1825 * May be on power button or on C-panel.
1826 */
1827 EC_LED_ID_POWER_LED,
1828 /* LED on power adapter or its plug */
David Hendricks2d6db772013-07-10 21:07:48 -07001829 EC_LED_ID_ADAPTER_LED,
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001830 /* LED to indicate left side */
1831 EC_LED_ID_LEFT_LED,
1832 /* LED to indicate right side */
1833 EC_LED_ID_RIGHT_LED,
1834 /* LED to indicate recovery mode with HW_REINIT */
1835 EC_LED_ID_RECOVERY_HW_REINIT_LED,
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08001836 /* LED to indicate sysrq debug mode. */
1837 EC_LED_ID_SYSRQ_DEBUG_LED,
David Hendricksb6847ac2014-08-17 17:59:24 -07001838
1839 EC_LED_ID_COUNT
David Hendricks2d6db772013-07-10 21:07:48 -07001840};
1841
1842/* LED control flags */
1843#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1844#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1845
1846enum ec_led_colors {
1847 EC_LED_COLOR_RED = 0,
1848 EC_LED_COLOR_GREEN,
1849 EC_LED_COLOR_BLUE,
1850 EC_LED_COLOR_YELLOW,
1851 EC_LED_COLOR_WHITE,
David Hendricks1649d162016-09-16 18:13:11 -07001852 EC_LED_COLOR_AMBER,
David Hendricks2d6db772013-07-10 21:07:48 -07001853
1854 EC_LED_COLOR_COUNT
1855};
1856
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001857struct __ec_align1 ec_params_led_control {
David Hendricks2d6db772013-07-10 21:07:48 -07001858 uint8_t led_id; /* Which LED to control */
1859 uint8_t flags; /* Control flags */
1860
1861 uint8_t brightness[EC_LED_COLOR_COUNT];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001862};
David Hendricks2d6db772013-07-10 21:07:48 -07001863
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001864struct __ec_align1 ec_response_led_control {
David Hendricks2d6db772013-07-10 21:07:48 -07001865 /*
1866 * Available brightness value range.
1867 *
1868 * Range 0 means color channel not present.
1869 * Range 1 means on/off control.
1870 * Other values means the LED is control by PWM.
1871 */
1872 uint8_t brightness_range[EC_LED_COLOR_COUNT];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001873};
David Hendricks2d6db772013-07-10 21:07:48 -07001874
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001875/*****************************************************************************/
1876/* Verified boot commands */
1877
1878/*
David Hendricksd6f94492012-08-17 16:01:32 -07001879 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1880 * reused for other purposes with version > 0.
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001881 */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001882
1883/* Verified boot hash command */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001884#define EC_CMD_VBOOT_HASH 0x002A
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001885
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001886struct __ec_align4 ec_params_vboot_hash {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001887 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1888 uint8_t hash_type; /* enum ec_vboot_hash_type */
1889 uint8_t nonce_size; /* Nonce size; may be 0 */
1890 uint8_t reserved0; /* Reserved; set 0 */
1891 uint32_t offset; /* Offset in flash to hash */
1892 uint32_t size; /* Number of bytes to hash */
1893 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001894};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001895
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001896struct __ec_align4 ec_response_vboot_hash {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001897 uint8_t status; /* enum ec_vboot_hash_status */
1898 uint8_t hash_type; /* enum ec_vboot_hash_type */
1899 uint8_t digest_size; /* Size of hash digest in bytes */
1900 uint8_t reserved0; /* Ignore; will be 0 */
1901 uint32_t offset; /* Offset in flash which was hashed */
1902 uint32_t size; /* Number of bytes hashed */
1903 uint8_t hash_digest[64]; /* Hash digest data */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001904};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001905
1906enum ec_vboot_hash_cmd {
David Hendricks2d6db772013-07-10 21:07:48 -07001907 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1908 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1909 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1910 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001911};
1912
1913enum ec_vboot_hash_type {
David Hendricks2d6db772013-07-10 21:07:48 -07001914 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001915};
1916
1917enum ec_vboot_hash_status {
David Hendricks2d6db772013-07-10 21:07:48 -07001918 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1919 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1920 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001921};
1922
David Hendricks2d6db772013-07-10 21:07:48 -07001923/*
1924 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1925 * If one of these is specified, the EC will automatically update offset and
1926 * size to the correct values for the specified image (RO or RW).
1927 */
1928#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1929#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1930
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08001931/*****************************************************************************/
David Hendricksb6847ac2014-08-17 17:59:24 -07001932/*
1933 * Motion sense commands. We'll make separate structs for sub-commands with
1934 * different input args, so that we know how much to expect.
1935 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08001936#define EC_CMD_MOTION_SENSE_CMD 0x002B
David Hendricksb6847ac2014-08-17 17:59:24 -07001937
1938/* Motion sense commands */
1939enum motionsense_command {
1940 /*
1941 * Dump command returns all motion sensor data including motion sense
1942 * module flags and individual sensor flags.
1943 */
1944 MOTIONSENSE_CMD_DUMP = 0,
1945
1946 /*
1947 * Info command returns data describing the details of a given sensor,
1948 * including enum motionsensor_type, enum motionsensor_location, and
1949 * enum motionsensor_chip.
1950 */
1951 MOTIONSENSE_CMD_INFO = 1,
1952
1953 /*
1954 * EC Rate command is a setter/getter command for the EC sampling rate
David Hendricks1649d162016-09-16 18:13:11 -07001955 * in milliseconds.
1956 * It is per sensor, the EC run sample task at the minimum of all
1957 * sensors EC_RATE.
1958 * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
1959 * to collect all the sensor samples.
1960 * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
1961 * to process of all motion sensors in milliseconds.
David Hendricksb6847ac2014-08-17 17:59:24 -07001962 */
1963 MOTIONSENSE_CMD_EC_RATE = 2,
1964
1965 /*
1966 * Sensor ODR command is a setter/getter command for the output data
1967 * rate of a specific motion sensor in millihertz.
1968 */
1969 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1970
1971 /*
1972 * Sensor range command is a setter/getter command for the range of
1973 * a specified motion sensor in +/-G's or +/- deg/s.
1974 */
1975 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1976
1977 /*
1978 * Setter/getter command for the keyboard wake angle. When the lid
1979 * angle is greater than this value, keyboard wake is disabled in S3,
1980 * and when the lid angle goes less than this value, keyboard wake is
1981 * enabled. Note, the lid angle measurement is an approximate,
1982 * un-calibrated value, hence the wake angle isn't exact.
1983 */
1984 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1985
David Hendricks1649d162016-09-16 18:13:11 -07001986 /*
1987 * Returns a single sensor data.
1988 */
1989 MOTIONSENSE_CMD_DATA = 6,
David Hendricksb6847ac2014-08-17 17:59:24 -07001990
1991 /*
David Hendricks1649d162016-09-16 18:13:11 -07001992 * Return sensor fifo info.
David Hendricksb6847ac2014-08-17 17:59:24 -07001993 */
David Hendricks1649d162016-09-16 18:13:11 -07001994 MOTIONSENSE_CMD_FIFO_INFO = 7,
1995
1996 /*
1997 * Insert a flush element in the fifo and return sensor fifo info.
1998 * The host can use that element to synchronize its operation.
1999 */
2000 MOTIONSENSE_CMD_FIFO_FLUSH = 8,
2001
2002 /*
2003 * Return a portion of the fifo.
2004 */
2005 MOTIONSENSE_CMD_FIFO_READ = 9,
2006
2007 /*
2008 * Perform low level calibration.
2009 * On sensors that support it, ask to do offset calibration.
2010 */
2011 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
2012
2013 /*
2014 * Sensor Offset command is a setter/getter command for the offset
2015 * used for calibration.
2016 * The offsets can be calculated by the host, or via
2017 * PERFORM_CALIB command.
2018 */
2019 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
2020
2021 /*
2022 * List available activities for a MOTION sensor.
2023 * Indicates if they are enabled or disabled.
2024 */
2025 MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
2026
2027 /*
2028 * Activity management
2029 * Enable/Disable activity recognition.
2030 */
2031 MOTIONSENSE_CMD_SET_ACTIVITY = 13,
2032
2033 /*
2034 * Lid Angle
2035 */
2036 MOTIONSENSE_CMD_LID_ANGLE = 14,
2037
2038 /*
2039 * Allow the FIFO to trigger interrupt via MKBP events.
2040 * By default the FIFO does not send interrupt to process the FIFO
2041 * until the AP is ready or it is coming from a wakeup sensor.
2042 */
2043 MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
2044
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002045 /*
2046 * Spoof the readings of the sensors. The spoofed readings can be set
2047 * to arbitrary values, or will lock to the last read actual values.
2048 */
2049 MOTIONSENSE_CMD_SPOOF = 16,
2050
David Hendricks1649d162016-09-16 18:13:11 -07002051 /* Number of motionsense sub-commands. */
2052 MOTIONSENSE_NUM_CMDS
David Hendricksb6847ac2014-08-17 17:59:24 -07002053};
2054
2055/* List of motion sensor types. */
2056enum motionsensor_type {
2057 MOTIONSENSE_TYPE_ACCEL = 0,
2058 MOTIONSENSE_TYPE_GYRO = 1,
David Hendricks1649d162016-09-16 18:13:11 -07002059 MOTIONSENSE_TYPE_MAG = 2,
2060 MOTIONSENSE_TYPE_PROX = 3,
2061 MOTIONSENSE_TYPE_LIGHT = 4,
2062 MOTIONSENSE_TYPE_ACTIVITY = 5,
2063 MOTIONSENSE_TYPE_BARO = 6,
2064 MOTIONSENSE_TYPE_MAX,
David Hendricksb6847ac2014-08-17 17:59:24 -07002065};
2066
2067/* List of motion sensor locations. */
2068enum motionsensor_location {
2069 MOTIONSENSE_LOC_BASE = 0,
2070 MOTIONSENSE_LOC_LID = 1,
David Hendricks1649d162016-09-16 18:13:11 -07002071 MOTIONSENSE_LOC_MAX,
David Hendricksb6847ac2014-08-17 17:59:24 -07002072};
2073
2074/* List of motion sensor chips. */
2075enum motionsensor_chip {
2076 MOTIONSENSE_CHIP_KXCJ9 = 0,
David Hendricks1649d162016-09-16 18:13:11 -07002077 MOTIONSENSE_CHIP_LSM6DS0 = 1,
2078 MOTIONSENSE_CHIP_BMI160 = 2,
2079 MOTIONSENSE_CHIP_SI1141 = 3,
2080 MOTIONSENSE_CHIP_SI1142 = 4,
2081 MOTIONSENSE_CHIP_SI1143 = 5,
2082 MOTIONSENSE_CHIP_KX022 = 6,
2083 MOTIONSENSE_CHIP_L3GD20H = 7,
2084 MOTIONSENSE_CHIP_BMA255 = 8,
2085 MOTIONSENSE_CHIP_BMP280 = 9,
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002086 MOTIONSENSE_CHIP_OPT3001 = 10,
David Hendricks1649d162016-09-16 18:13:11 -07002087};
2088
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002089struct __ec_todo_packed ec_response_motion_sensor_data {
David Hendricks1649d162016-09-16 18:13:11 -07002090 /* Flags for each sensor. */
2091 uint8_t flags;
2092 /* sensor number the data comes from */
2093 uint8_t sensor_num;
2094 /* Each sensor is up to 3-axis. */
2095 union {
2096 int16_t data[3];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002097 struct __ec_todo_packed {
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08002098 uint16_t reserved;
David Hendricks1649d162016-09-16 18:13:11 -07002099 uint32_t timestamp;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002100 };
2101 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002102 uint8_t activity; /* motionsensor_activity */
2103 uint8_t state;
2104 int16_t add_info[2];
2105 };
2106 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002107};
David Hendricks1649d162016-09-16 18:13:11 -07002108
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002109/* Note: used in ec_response_get_next_data */
2110struct __ec_todo_packed ec_response_motion_sense_fifo_info {
David Hendricks1649d162016-09-16 18:13:11 -07002111 /* Size of the fifo */
2112 uint16_t size;
2113 /* Amount of space used in the fifo */
2114 uint16_t count;
2115 /* Timestamp recorded in us */
2116 uint32_t timestamp;
2117 /* Total amount of vector lost */
2118 uint16_t total_lost;
2119 /* Lost events since the last fifo_info, per sensors */
2120 uint16_t lost[0];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002121};
David Hendricks1649d162016-09-16 18:13:11 -07002122
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002123struct __ec_todo_packed ec_response_motion_sense_fifo_data {
David Hendricks1649d162016-09-16 18:13:11 -07002124 uint32_t number_data;
2125 struct ec_response_motion_sensor_data data[0];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002126};
David Hendricks1649d162016-09-16 18:13:11 -07002127
2128/* List supported activity recognition */
2129enum motionsensor_activity {
2130 MOTIONSENSE_ACTIVITY_RESERVED = 0,
2131 MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
2132 MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
2133};
2134
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002135struct __ec_todo_unpacked ec_motion_sense_activity {
David Hendricks1649d162016-09-16 18:13:11 -07002136 uint8_t sensor_num;
2137 uint8_t activity; /* one of enum motionsensor_activity */
2138 uint8_t enable; /* 1: enable, 0: disable */
2139 uint8_t reserved;
2140 uint16_t parameters[3]; /* activity dependent parameters */
David Hendricksb6847ac2014-08-17 17:59:24 -07002141};
2142
2143/* Module flag masks used for the dump sub-command. */
2144#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
2145
2146/* Sensor flag masks used for the dump sub-command. */
2147#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
2148
2149/*
David Hendricks1649d162016-09-16 18:13:11 -07002150 * Flush entry for synchronization.
2151 * data contains time stamp
2152 */
2153#define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
2154#define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
2155#define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
2156#define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
2157
2158/*
David Hendricksb6847ac2014-08-17 17:59:24 -07002159 * Send this value for the data element to only perform a read. If you
2160 * send any other value, the EC will interpret it as data to set and will
2161 * return the actual value set.
2162 */
2163#define EC_MOTION_SENSE_NO_VALUE -1
2164
David Hendricks1649d162016-09-16 18:13:11 -07002165#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
2166
2167/* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
2168/* Set Calibration information */
2169#define MOTION_SENSE_SET_OFFSET 1
2170
2171#define LID_ANGLE_UNRELIABLE 500
2172
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002173enum motionsense_spoof_mode {
2174 /* Disable spoof mode. */
2175 MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
2176
2177 /* Enable spoof mode, but use provided component values. */
2178 MOTIONSENSE_SPOOF_MODE_CUSTOM,
2179
2180 /* Enable spoof mode, but use the current sensor values. */
2181 MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
2182
2183 /* Query the current spoof mode status for the sensor. */
2184 MOTIONSENSE_SPOOF_MODE_QUERY,
2185};
2186
2187struct __ec_todo_packed ec_params_motion_sense {
David Hendricksb6847ac2014-08-17 17:59:24 -07002188 uint8_t cmd;
2189 union {
David Hendricks1649d162016-09-16 18:13:11 -07002190 /* Used for MOTIONSENSE_CMD_DUMP */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002191 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002192 /*
2193 * Maximal number of sensor the host is expecting.
2194 * 0 means the host is only interested in the number
2195 * of sensors controlled by the EC.
2196 */
2197 uint8_t max_sensor_count;
David Hendricksb6847ac2014-08-17 17:59:24 -07002198 } dump;
2199
2200 /*
David Hendricks1649d162016-09-16 18:13:11 -07002201 * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
David Hendricksb6847ac2014-08-17 17:59:24 -07002202 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002203 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002204 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
2205 * kb_wake_angle: angle to wakup AP.
2206 */
David Hendricksb6847ac2014-08-17 17:59:24 -07002207 int16_t data;
David Hendricks1649d162016-09-16 18:13:11 -07002208 } kb_wake_angle;
David Hendricksb6847ac2014-08-17 17:59:24 -07002209
David Hendricks1649d162016-09-16 18:13:11 -07002210 /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
2211 * and MOTIONSENSE_CMD_PERFORM_CALIB. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002212 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002213 uint8_t sensor_num;
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08002214 } info, info_3, data, fifo_flush, perform_calib,
2215 list_activities;
David Hendricksb6847ac2014-08-17 17:59:24 -07002216
2217 /*
David Hendricks1649d162016-09-16 18:13:11 -07002218 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
2219 * and MOTIONSENSE_CMD_SENSOR_RANGE.
David Hendricksb6847ac2014-08-17 17:59:24 -07002220 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002221 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002222 uint8_t sensor_num;
2223
2224 /* Rounding flag, true for round-up, false for down. */
2225 uint8_t roundup;
2226
2227 uint16_t reserved;
2228
2229 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
2230 int32_t data;
David Hendricks1649d162016-09-16 18:13:11 -07002231 } ec_rate, sensor_odr, sensor_range;
2232
2233 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002234 struct __ec_todo_packed {
David Hendricks1649d162016-09-16 18:13:11 -07002235 uint8_t sensor_num;
2236
2237 /*
2238 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
2239 * the calibration information in the EC.
2240 * If unset, just retrieve calibration information.
2241 */
2242 uint16_t flags;
2243
2244 /*
2245 * Temperature at calibration, in units of 0.01 C
2246 * 0x8000: invalid / unknown.
2247 * 0x0: 0C
2248 * 0x7fff: +327.67C
2249 */
2250 int16_t temp;
2251
2252 /*
2253 * Offset for calibration.
2254 * Unit:
2255 * Accelerometer: 1/1024 g
2256 * Gyro: 1/1024 deg/s
2257 * Compass: 1/16 uT
2258 */
2259 int16_t offset[3];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002260 } sensor_offset;
David Hendricks1649d162016-09-16 18:13:11 -07002261
2262 /* Used for MOTIONSENSE_CMD_FIFO_INFO */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002263 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002264 } fifo_info;
2265
2266 /* Used for MOTIONSENSE_CMD_FIFO_READ */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002267 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002268 /*
2269 * Number of expected vector to return.
2270 * EC may return less or 0 if none available.
2271 */
2272 uint32_t max_data_vector;
2273 } fifo_read;
2274
2275 struct ec_motion_sense_activity set_activity;
2276
2277 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002278 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002279 } lid_angle;
2280
2281 /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002282 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002283 /*
2284 * 1: enable, 0 disable fifo,
2285 * EC_MOTION_SENSE_NO_VALUE return value.
2286 */
2287 int8_t enable;
2288 } fifo_int_enable;
David Hendricksb6847ac2014-08-17 17:59:24 -07002289
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002290 /* Used for MOTIONSENSE_CMD_SPOOF */
2291 struct __ec_todo_packed {
2292 uint8_t sensor_id;
2293
2294 /* See enum motionsense_spoof_mode. */
2295 uint8_t spoof_enable;
2296
2297 /* Ignored, used for alignment. */
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08002298 uint8_t reserved;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002299
2300 /* Individual component values to spoof. */
2301 int16_t components[3];
2302 } spoof;
2303 };
2304};
2305
2306struct __ec_todo_packed ec_response_motion_sense {
David Hendricksb6847ac2014-08-17 17:59:24 -07002307 union {
David Hendricks1649d162016-09-16 18:13:11 -07002308 /* Used for MOTIONSENSE_CMD_DUMP */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002309 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002310 /* Flags representing the motion sensor module. */
2311 uint8_t module_flags;
2312
David Hendricks1649d162016-09-16 18:13:11 -07002313 /* Number of sensors managed directly by the EC */
2314 uint8_t sensor_count;
David Hendricksb6847ac2014-08-17 17:59:24 -07002315
David Hendricks1649d162016-09-16 18:13:11 -07002316 /*
2317 * sensor data is truncated if response_max is too small
2318 * for holding all the data.
2319 */
2320 struct ec_response_motion_sensor_data sensor[0];
David Hendricksb6847ac2014-08-17 17:59:24 -07002321 } dump;
2322
2323 /* Used for MOTIONSENSE_CMD_INFO. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002324 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002325 /* Should be element of enum motionsensor_type. */
2326 uint8_t type;
2327
2328 /* Should be element of enum motionsensor_location. */
2329 uint8_t location;
2330
2331 /* Should be element of enum motionsensor_chip. */
2332 uint8_t chip;
2333 } info;
2334
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08002335 /* Used for MOTIONSENSE_CMD_INFO version 3 */
2336 struct __ec_todo_unpacked {
2337 /* Should be element of enum motionsensor_type. */
2338 uint8_t type;
2339
2340 /* Should be element of enum motionsensor_location. */
2341 uint8_t location;
2342
2343 /* Should be element of enum motionsensor_chip. */
2344 uint8_t chip;
2345
2346 /* Minimum sensor sampling frequency */
2347 uint32_t min_frequency;
2348
2349 /* Maximum sensor sampling frequency */
2350 uint32_t max_frequency;
2351
2352 /* Max number of sensor events that could be in fifo */
2353 uint32_t fifo_max_event_count;
2354 } info_3;
2355
David Hendricks1649d162016-09-16 18:13:11 -07002356 /* Used for MOTIONSENSE_CMD_DATA */
2357 struct ec_response_motion_sensor_data data;
2358
David Hendricksb6847ac2014-08-17 17:59:24 -07002359 /*
2360 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
David Hendricks1649d162016-09-16 18:13:11 -07002361 * MOTIONSENSE_CMD_SENSOR_RANGE,
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002362 * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
2363 * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
2364 * MOTIONSENSE_CMD_SPOOF.
David Hendricksb6847ac2014-08-17 17:59:24 -07002365 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002366 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002367 /* Current value of the parameter queried. */
2368 int32_t ret;
David Hendricks1649d162016-09-16 18:13:11 -07002369 } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002370 fifo_int_enable, spoof;
David Hendricks1649d162016-09-16 18:13:11 -07002371
2372 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002373 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002374 int16_t temp;
2375 int16_t offset[3];
2376 } sensor_offset, perform_calib;
2377
2378 struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
2379
2380 struct ec_response_motion_sense_fifo_data fifo_read;
2381
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002382 struct __ec_todo_packed {
David Hendricks1649d162016-09-16 18:13:11 -07002383 uint16_t reserved;
2384 uint32_t enabled;
2385 uint32_t disabled;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002386 } list_activities;
David Hendricks1649d162016-09-16 18:13:11 -07002387
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002388 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002389 } set_activity;
2390
David Hendricks1649d162016-09-16 18:13:11 -07002391 /* Used for MOTIONSENSE_CMD_LID_ANGLE */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002392 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002393 /*
2394 * Angle between 0 and 360 degree if available,
2395 * LID_ANGLE_UNRELIABLE otherwise.
2396 */
2397 uint16_t value;
2398 } lid_angle;
David Hendricksb6847ac2014-08-17 17:59:24 -07002399 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002400};
David Hendricksb6847ac2014-08-17 17:59:24 -07002401
2402/*****************************************************************************/
David Hendricks1649d162016-09-16 18:13:11 -07002403/* Force lid open command */
2404
2405/* Make lid event always open */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002406#define EC_CMD_FORCE_LID_OPEN 0x002C
David Hendricks1649d162016-09-16 18:13:11 -07002407
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002408struct __ec_align1 ec_params_force_lid_open {
David Hendricks1649d162016-09-16 18:13:11 -07002409 uint8_t enabled;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002410};
2411
2412/*****************************************************************************/
2413/* Configure the behavior of the power button */
2414#define EC_CMD_CONFIG_POWER_BUTTON 0x002D
2415
2416enum ec_config_power_button_flags {
2417 /* Enable/Disable power button pulses for x86 devices */
2418 EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
2419};
2420
2421struct __ec_align1 ec_params_config_power_button {
2422 /* See enum ec_config_power_button_flags */
2423 uint8_t flags;
2424};
David Hendricks1649d162016-09-16 18:13:11 -07002425
2426/*****************************************************************************/
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002427/* USB charging control commands */
2428
2429/* Set USB port charging mode */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002430#define EC_CMD_USB_CHARGE_SET_MODE 0x0030
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002431
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002432struct __ec_align1 ec_params_usb_charge_set_mode {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002433 uint8_t usb_port_id;
2434 uint8_t mode;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002435};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002436
2437/*****************************************************************************/
2438/* Persistent storage for host */
2439
2440/* Maximum bytes that can be read/written in a single command */
2441#define EC_PSTORE_SIZE_MAX 64
2442
2443/* Get persistent storage info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002444#define EC_CMD_PSTORE_INFO 0x0040
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002445
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002446struct __ec_align4 ec_response_pstore_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002447 /* Persistent storage size, in bytes */
2448 uint32_t pstore_size;
2449 /* Access size; read/write offset and size must be a multiple of this */
2450 uint32_t access_size;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002451};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002452
2453/*
2454 * Read persistent storage
2455 *
2456 * Response is params.size bytes of data.
2457 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002458#define EC_CMD_PSTORE_READ 0x0041
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002459
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002460struct __ec_align4 ec_params_pstore_read {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002461 uint32_t offset; /* Byte offset to read */
2462 uint32_t size; /* Size to read in bytes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002463};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002464
2465/* Write persistent storage */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002466#define EC_CMD_PSTORE_WRITE 0x0042
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002467
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002468struct __ec_align4 ec_params_pstore_write {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002469 uint32_t offset; /* Byte offset to write */
2470 uint32_t size; /* Size to write in bytes */
2471 uint8_t data[EC_PSTORE_SIZE_MAX];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002472};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002473
2474/*****************************************************************************/
David Hendricksd6f94492012-08-17 16:01:32 -07002475/* Real-time clock */
2476
2477/* RTC params and response structures */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002478struct __ec_align4 ec_params_rtc {
David Hendricksd6f94492012-08-17 16:01:32 -07002479 uint32_t time;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002480};
David Hendricksd6f94492012-08-17 16:01:32 -07002481
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002482struct __ec_align4 ec_response_rtc {
David Hendricksd6f94492012-08-17 16:01:32 -07002483 uint32_t time;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002484};
David Hendricksd6f94492012-08-17 16:01:32 -07002485
2486/* These use ec_response_rtc */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002487#define EC_CMD_RTC_GET_VALUE 0x0044
2488#define EC_CMD_RTC_GET_ALARM 0x0045
David Hendricksd6f94492012-08-17 16:01:32 -07002489
2490/* These all use ec_params_rtc */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002491#define EC_CMD_RTC_SET_VALUE 0x0046
2492#define EC_CMD_RTC_SET_ALARM 0x0047
David Hendricksd6f94492012-08-17 16:01:32 -07002493
David Hendricks1649d162016-09-16 18:13:11 -07002494/* Pass as time param to SET_ALARM to clear the current alarm */
2495#define EC_RTC_ALARM_CLEAR 0
2496
David Hendricksd6f94492012-08-17 16:01:32 -07002497/*****************************************************************************/
2498/* Port80 log access */
2499
David Hendricksb6847ac2014-08-17 17:59:24 -07002500/* Maximum entries that can be read/written in a single command */
2501#define EC_PORT80_SIZE_MAX 32
2502
David Hendricksd6f94492012-08-17 16:01:32 -07002503/* Get last port80 code from previous boot */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002504#define EC_CMD_PORT80_LAST_BOOT 0x0048
2505#define EC_CMD_PORT80_READ 0x0048
David Hendricksb6847ac2014-08-17 17:59:24 -07002506
2507enum ec_port80_subcmd {
2508 EC_PORT80_GET_INFO = 0,
2509 EC_PORT80_READ_BUFFER,
2510};
2511
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002512struct __ec_todo_packed ec_params_port80_read {
David Hendricksb6847ac2014-08-17 17:59:24 -07002513 uint16_t subcmd;
2514 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002515 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002516 uint32_t offset;
2517 uint32_t num_entries;
2518 } read_buffer;
2519 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002520};
David Hendricksb6847ac2014-08-17 17:59:24 -07002521
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002522struct __ec_todo_packed ec_response_port80_read {
David Hendricksb6847ac2014-08-17 17:59:24 -07002523 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002524 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002525 uint32_t writes;
2526 uint32_t history_size;
2527 uint32_t last_boot;
2528 } get_info;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002529 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07002530 uint16_t codes[EC_PORT80_SIZE_MAX];
2531 } data;
2532 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002533};
David Hendricksd6f94492012-08-17 16:01:32 -07002534
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002535struct __ec_align2 ec_response_port80_last_boot {
David Hendricksd6f94492012-08-17 16:01:32 -07002536 uint16_t code;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002537};
David Hendricksd6f94492012-08-17 16:01:32 -07002538
2539/*****************************************************************************/
David Hendricks1649d162016-09-16 18:13:11 -07002540/* Temporary secure storage for host verified boot use */
2541
2542/* Number of bytes in a vstore slot */
2543#define EC_VSTORE_SLOT_SIZE 64
2544
2545/* Maximum number of vstore slots */
2546#define EC_VSTORE_SLOT_MAX 32
2547
2548/* Get persistent storage info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002549#define EC_CMD_VSTORE_INFO 0x0049
2550struct __ec_align_size1 ec_response_vstore_info {
David Hendricks1649d162016-09-16 18:13:11 -07002551 /* Indicates which slots are locked */
2552 uint32_t slot_locked;
2553 /* Total number of slots available */
2554 uint8_t slot_count;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002555};
David Hendricks1649d162016-09-16 18:13:11 -07002556
2557/*
2558 * Read temporary secure storage
2559 *
2560 * Response is EC_VSTORE_SLOT_SIZE bytes of data.
2561 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002562#define EC_CMD_VSTORE_READ 0x004A
David Hendricks1649d162016-09-16 18:13:11 -07002563
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002564struct __ec_align1 ec_params_vstore_read {
David Hendricks1649d162016-09-16 18:13:11 -07002565 uint8_t slot; /* Slot to read from */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002566};
David Hendricks1649d162016-09-16 18:13:11 -07002567
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002568struct __ec_align1 ec_response_vstore_read {
David Hendricks1649d162016-09-16 18:13:11 -07002569 uint8_t data[EC_VSTORE_SLOT_SIZE];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002570};
David Hendricks1649d162016-09-16 18:13:11 -07002571
2572/*
2573 * Write temporary secure storage and lock it.
2574 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002575#define EC_CMD_VSTORE_WRITE 0x004B
David Hendricks1649d162016-09-16 18:13:11 -07002576
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002577struct __ec_align1 ec_params_vstore_write {
David Hendricks1649d162016-09-16 18:13:11 -07002578 uint8_t slot; /* Slot to write to */
2579 uint8_t data[EC_VSTORE_SLOT_SIZE];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002580};
David Hendricks1649d162016-09-16 18:13:11 -07002581
2582/*****************************************************************************/
David Hendricksb6847ac2014-08-17 17:59:24 -07002583/* Thermal engine commands. Note that there are two implementations. We'll
2584 * reuse the command number, but the data and behavior is incompatible.
2585 * Version 0 is what originally shipped on Link.
2586 * Version 1 separates the CPU thermal limits from the fan control.
2587 */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002588
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002589#define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
2590#define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002591
David Hendricksb6847ac2014-08-17 17:59:24 -07002592/* The version 0 structs are opaque. You have to know what they are for
2593 * the get/set commands to make any sense.
2594 */
2595
2596/* Version 0 - set */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002597struct __ec_align2 ec_params_thermal_set_threshold {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002598 uint8_t sensor_type;
2599 uint8_t threshold_id;
2600 uint16_t value;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002601};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002602
David Hendricksb6847ac2014-08-17 17:59:24 -07002603/* Version 0 - get */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002604struct __ec_align1 ec_params_thermal_get_threshold {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002605 uint8_t sensor_type;
2606 uint8_t threshold_id;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002607};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002608
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002609struct __ec_align2 ec_response_thermal_get_threshold {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002610 uint16_t value;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002611};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002612
David Hendricksb6847ac2014-08-17 17:59:24 -07002613
2614/* The version 1 structs are visible. */
2615enum ec_temp_thresholds {
2616 EC_TEMP_THRESH_WARN = 0,
2617 EC_TEMP_THRESH_HIGH,
2618 EC_TEMP_THRESH_HALT,
2619
2620 EC_TEMP_THRESH_COUNT
2621};
2622
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002623/*
2624 * Thermal configuration for one temperature sensor. Temps are in degrees K.
David Hendricksb6847ac2014-08-17 17:59:24 -07002625 * Zero values will be silently ignored by the thermal task.
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002626 *
2627 * Note that this structure is a sub-structure of
2628 * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
David Hendricksb6847ac2014-08-17 17:59:24 -07002629 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002630struct __ec_align4 ec_thermal_config {
David Hendricksb6847ac2014-08-17 17:59:24 -07002631 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
2632 uint32_t temp_fan_off; /* no active cooling needed */
2633 uint32_t temp_fan_max; /* max active cooling needed */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002634};
David Hendricksb6847ac2014-08-17 17:59:24 -07002635
2636/* Version 1 - get config for one sensor. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002637struct __ec_align4 ec_params_thermal_get_threshold_v1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07002638 uint32_t sensor_num;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002639};
David Hendricksb6847ac2014-08-17 17:59:24 -07002640/* This returns a struct ec_thermal_config */
2641
2642/* Version 1 - set config for one sensor.
2643 * Use read-modify-write for best results! */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002644struct __ec_align4 ec_params_thermal_set_threshold_v1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07002645 uint32_t sensor_num;
2646 struct ec_thermal_config cfg;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002647};
David Hendricksb6847ac2014-08-17 17:59:24 -07002648/* This returns no data */
2649
2650/****************************************************************************/
2651
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002652/* Toggle automatic fan control */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002653#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002654
David Hendricks1649d162016-09-16 18:13:11 -07002655/* Version 1 of input params */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002656struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07002657 uint8_t fan_idx;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002658};
David Hendricks2d6db772013-07-10 21:07:48 -07002659
David Hendricks1649d162016-09-16 18:13:11 -07002660/* Get/Set TMP006 calibration data */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002661#define EC_CMD_TMP006_GET_CALIBRATION 0x0053
2662#define EC_CMD_TMP006_SET_CALIBRATION 0x0054
David Hendricks1649d162016-09-16 18:13:11 -07002663
2664/*
2665 * The original TMP006 calibration only needed four params, but now we need
2666 * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
2667 * the params opaque. The v1 "get" response will include the algorithm number
2668 * and how many params it requires. That way we can change the EC code without
2669 * needing to update this file. We can also use a different algorithm on each
2670 * sensor.
2671 */
2672
2673/* This is the same struct for both v0 and v1. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002674struct __ec_align1 ec_params_tmp006_get_calibration {
David Hendricks2d6db772013-07-10 21:07:48 -07002675 uint8_t index;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002676};
David Hendricks2d6db772013-07-10 21:07:48 -07002677
David Hendricks1649d162016-09-16 18:13:11 -07002678/* Version 0 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002679struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
David Hendricks2d6db772013-07-10 21:07:48 -07002680 float s0;
2681 float b0;
2682 float b1;
2683 float b2;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002684};
David Hendricks2d6db772013-07-10 21:07:48 -07002685
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002686struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
David Hendricks2d6db772013-07-10 21:07:48 -07002687 uint8_t index;
David Hendricks1649d162016-09-16 18:13:11 -07002688 uint8_t reserved[3];
David Hendricks2d6db772013-07-10 21:07:48 -07002689 float s0;
2690 float b0;
2691 float b1;
2692 float b2;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002693};
David Hendricks2d6db772013-07-10 21:07:48 -07002694
David Hendricks1649d162016-09-16 18:13:11 -07002695/* Version 1 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002696struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07002697 uint8_t algorithm;
2698 uint8_t num_params;
2699 uint8_t reserved[2];
2700 float val[0];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002701};
David Hendricks1649d162016-09-16 18:13:11 -07002702
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002703struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07002704 uint8_t index;
2705 uint8_t algorithm;
2706 uint8_t num_params;
2707 uint8_t reserved;
2708 float val[0];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002709};
David Hendricks1649d162016-09-16 18:13:11 -07002710
2711
David Hendricksb6847ac2014-08-17 17:59:24 -07002712/* Read raw TMP006 data */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002713#define EC_CMD_TMP006_GET_RAW 0x0055
David Hendricksb6847ac2014-08-17 17:59:24 -07002714
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002715struct __ec_align1 ec_params_tmp006_get_raw {
David Hendricksb6847ac2014-08-17 17:59:24 -07002716 uint8_t index;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002717};
David Hendricksb6847ac2014-08-17 17:59:24 -07002718
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002719struct __ec_align4 ec_response_tmp006_get_raw {
David Hendricksb6847ac2014-08-17 17:59:24 -07002720 int32_t t; /* In 1/100 K */
2721 int32_t v; /* In nV */
2722};
2723
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002724/*****************************************************************************/
2725/* MKBP - Matrix KeyBoard Protocol */
2726
2727/*
2728 * Read key state
2729 *
2730 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
2731 * expected response size.
David Hendricks1649d162016-09-16 18:13:11 -07002732 *
2733 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
2734 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
2735 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002736 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002737#define EC_CMD_MKBP_STATE 0x0060
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002738
David Hendricks1649d162016-09-16 18:13:11 -07002739/*
2740 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
2741 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002742#define EC_CMD_MKBP_INFO 0x0061
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002743
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002744struct __ec_align_size1 ec_response_mkbp_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002745 uint32_t rows;
2746 uint32_t cols;
David Hendricks1649d162016-09-16 18:13:11 -07002747 /* Formerly "switches", which was 0. */
2748 uint8_t reserved;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002749};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002750
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002751struct __ec_align1 ec_params_mkbp_info {
David Hendricks1649d162016-09-16 18:13:11 -07002752 uint8_t info_type;
2753 uint8_t event_type;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002754};
David Hendricks1649d162016-09-16 18:13:11 -07002755
2756enum ec_mkbp_info_type {
2757 /*
2758 * Info about the keyboard matrix: number of rows and columns.
2759 *
2760 * Returns struct ec_response_mkbp_info.
2761 */
2762 EC_MKBP_INFO_KBD = 0,
2763
2764 /*
2765 * For buttons and switches, info about which specifically are
2766 * supported. event_type must be set to one of the values in enum
2767 * ec_mkbp_event.
2768 *
2769 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2770 * bitmask indicating which buttons or switches are present. See the
2771 * bit inidices below.
2772 */
2773 EC_MKBP_INFO_SUPPORTED = 1,
2774
2775 /*
2776 * Instantaneous state of buttons and switches.
2777 *
2778 * event_type must be set to one of the values in enum ec_mkbp_event.
2779 *
2780 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2781 * indicating the current state of the keyboard matrix.
2782 *
2783 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2784 * event state.
2785 *
2786 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2787 * state of supported buttons.
2788 *
2789 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2790 * state of supported switches.
2791 */
2792 EC_MKBP_INFO_CURRENT = 2,
2793};
2794
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002795/* Simulate key press */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002796#define EC_CMD_MKBP_SIMULATE_KEY 0x0062
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002797
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002798struct __ec_align1 ec_params_mkbp_simulate_key {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002799 uint8_t col;
2800 uint8_t row;
2801 uint8_t pressed;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002802};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08002803
David Hendricks2d6db772013-07-10 21:07:48 -07002804/* Configure keyboard scanning */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002805#define EC_CMD_MKBP_SET_CONFIG 0x0064
2806#define EC_CMD_MKBP_GET_CONFIG 0x0065
David Hendricks2d6db772013-07-10 21:07:48 -07002807
2808/* flags */
2809enum mkbp_config_flags {
2810 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2811};
2812
2813enum mkbp_config_valid {
2814 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2815 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2816 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2817 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2818 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2819 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2820 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2821};
2822
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002823/*
2824 * Configuration for our key scanning algorithm.
2825 *
2826 * Note that this is used as a sub-structure of
2827 * ec_{params/response}_mkbp_get_config.
2828 */
2829struct __ec_align_size1 ec_mkbp_config {
David Hendricks2d6db772013-07-10 21:07:48 -07002830 uint32_t valid_mask; /* valid fields */
2831 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2832 uint8_t valid_flags; /* which flags are valid */
2833 uint16_t scan_period_us; /* period between start of scans */
2834 /* revert to interrupt mode after no activity for this long */
2835 uint32_t poll_timeout_us;
2836 /*
2837 * minimum post-scan relax time. Once we finish a scan we check
2838 * the time until we are due to start the next one. If this time is
2839 * shorter this field, we use this instead.
2840 */
2841 uint16_t min_post_scan_delay_us;
2842 /* delay between setting up output and waiting for it to settle */
2843 uint16_t output_settle_us;
2844 uint16_t debounce_down_us; /* time for debounce on key down */
2845 uint16_t debounce_up_us; /* time for debounce on key up */
2846 /* maximum depth to allow for fifo (0 = no keyscan output) */
2847 uint8_t fifo_max_depth;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002848};
David Hendricks2d6db772013-07-10 21:07:48 -07002849
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002850struct __ec_align_size1 ec_params_mkbp_set_config {
David Hendricks2d6db772013-07-10 21:07:48 -07002851 struct ec_mkbp_config config;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002852};
David Hendricks2d6db772013-07-10 21:07:48 -07002853
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002854struct __ec_align_size1 ec_response_mkbp_get_config {
David Hendricks2d6db772013-07-10 21:07:48 -07002855 struct ec_mkbp_config config;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002856};
David Hendricks2d6db772013-07-10 21:07:48 -07002857
2858/* Run the key scan emulation */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002859#define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
David Hendricks2d6db772013-07-10 21:07:48 -07002860
2861enum ec_keyscan_seq_cmd {
2862 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2863 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2864 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2865 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2866 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2867};
2868
2869enum ec_collect_flags {
2870 /*
2871 * Indicates this scan was processed by the EC. Due to timing, some
2872 * scans may be skipped.
2873 */
2874 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2875};
2876
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002877struct __ec_align1 ec_collect_item {
David Hendricks2d6db772013-07-10 21:07:48 -07002878 uint8_t flags; /* some flags (enum ec_collect_flags) */
2879};
2880
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002881struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
David Hendricks2d6db772013-07-10 21:07:48 -07002882 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2883 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002884 struct __ec_align1 {
David Hendricks2d6db772013-07-10 21:07:48 -07002885 uint8_t active; /* still active */
2886 uint8_t num_items; /* number of items */
2887 /* Current item being presented */
2888 uint8_t cur_item;
2889 } status;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002890 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07002891 /*
2892 * Absolute time for this scan, measured from the
2893 * start of the sequence.
2894 */
2895 uint32_t time_us;
2896 uint8_t scan[0]; /* keyscan data */
2897 } add;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002898 struct __ec_align1 {
David Hendricks2d6db772013-07-10 21:07:48 -07002899 uint8_t start_item; /* First item to return */
2900 uint8_t num_items; /* Number of items to return */
2901 } collect;
2902 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002903};
David Hendricks2d6db772013-07-10 21:07:48 -07002904
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002905struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
David Hendricks2d6db772013-07-10 21:07:48 -07002906 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002907 struct __ec_todo_unpacked {
David Hendricks2d6db772013-07-10 21:07:48 -07002908 uint8_t num_items; /* Number of items */
2909 /* Data for each item */
2910 struct ec_collect_item item[0];
2911 } collect;
2912 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002913};
David Hendricks2d6db772013-07-10 21:07:48 -07002914
David Hendricks1649d162016-09-16 18:13:11 -07002915/*
2916 * Get the next pending MKBP event.
2917 *
2918 * Returns EC_RES_UNAVAILABLE if there is no event pending.
2919 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002920#define EC_CMD_GET_NEXT_EVENT 0x0067
David Hendricks1649d162016-09-16 18:13:11 -07002921
2922enum ec_mkbp_event {
2923 /* Keyboard matrix changed. The event data is the new matrix state. */
2924 EC_MKBP_EVENT_KEY_MATRIX = 0,
2925
2926 /* New host event. The event data is 4 bytes of host event flags. */
2927 EC_MKBP_EVENT_HOST_EVENT = 1,
2928
2929 /* New Sensor FIFO data. The event data is fifo_info structure. */
2930 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2931
2932 /* The state of the non-matrixed buttons have changed. */
2933 EC_MKBP_EVENT_BUTTON = 3,
2934
2935 /* The state of the switches have changed. */
2936 EC_MKBP_EVENT_SWITCH = 4,
2937
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002938 /* New Fingerprint sensor event, the event data is fp_events bitmap. */
2939 EC_MKBP_EVENT_FINGERPRINT = 5,
2940
2941 /*
2942 * Sysrq event: send emulated sysrq. The event data is sysrq,
2943 * corresponding to the key to be pressed.
2944 */
2945 EC_MKBP_EVENT_SYSRQ = 6,
2946
David Hendricks1649d162016-09-16 18:13:11 -07002947 /* Number of MKBP events */
2948 EC_MKBP_EVENT_COUNT,
2949};
2950
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002951union __ec_align_offset1 ec_response_get_next_data {
2952 uint8_t key_matrix[13];
David Hendricks1649d162016-09-16 18:13:11 -07002953
2954 /* Unaligned */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002955 uint32_t host_event;
David Hendricks1649d162016-09-16 18:13:11 -07002956
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002957 struct __ec_todo_unpacked {
David Hendricks1649d162016-09-16 18:13:11 -07002958 /* For aligning the fifo_info */
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08002959 uint8_t reserved[3];
David Hendricks1649d162016-09-16 18:13:11 -07002960 struct ec_response_motion_sense_fifo_info info;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002961 } sensor_fifo;
David Hendricks1649d162016-09-16 18:13:11 -07002962
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002963 uint32_t buttons;
David Hendricks1649d162016-09-16 18:13:11 -07002964
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002965 uint32_t switches;
David Hendricks1649d162016-09-16 18:13:11 -07002966
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002967 uint32_t fp_events;
2968
2969 uint32_t sysrq;
2970};
2971
2972struct __ec_align1 ec_response_get_next_event {
David Hendricks1649d162016-09-16 18:13:11 -07002973 uint8_t event_type;
2974 /* Followed by event data if any */
2975 union ec_response_get_next_data data;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002976};
David Hendricks1649d162016-09-16 18:13:11 -07002977
2978/* Bit indices for buttons and switches.*/
2979/* Buttons */
2980#define EC_MKBP_POWER_BUTTON 0
2981#define EC_MKBP_VOL_UP 1
2982#define EC_MKBP_VOL_DOWN 2
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08002983#define EC_MKBP_RECOVERY 3
David Hendricks1649d162016-09-16 18:13:11 -07002984
2985/* Switches */
2986#define EC_MKBP_LID_OPEN 0
2987#define EC_MKBP_TABLET_MODE 1
2988
2989/* Run keyboard factory test scanning */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002990#define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
David Hendricks1649d162016-09-16 18:13:11 -07002991
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002992struct __ec_align2 ec_response_keyboard_factory_test {
David Hendricks1649d162016-09-16 18:13:11 -07002993 uint16_t shorted; /* Keyboard pins are shorted */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08002994};
David Hendricks1649d162016-09-16 18:13:11 -07002995
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08002996/* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
2997#define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
2998#define EC_MKBP_FP_FINGER_DOWN (1 << 29)
2999#define EC_MKBP_FP_FINGER_UP (1 << 30)
3000#define EC_MKBP_FP_IMAGE_READY (1 << 31)
3001
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003002/*****************************************************************************/
3003/* Temperature sensor commands */
3004
3005/* Read temperature sensor info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003006#define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003007
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003008struct __ec_align1 ec_params_temp_sensor_get_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003009 uint8_t id;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003010};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003011
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003012struct __ec_align1 ec_response_temp_sensor_get_info {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003013 char sensor_name[32];
3014 uint8_t sensor_type;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003015};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003016
3017/*****************************************************************************/
3018
3019/*
3020 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
3021 * commands accidentally sent to the wrong interface. See the ACPI section
3022 * below.
3023 */
3024
3025/*****************************************************************************/
3026/* Host event commands */
3027
3028/*
3029 * Host event mask params and response structures, shared by all of the host
3030 * event commands below.
3031 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003032struct __ec_align4 ec_params_host_event_mask {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003033 uint32_t mask;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003034};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003035
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003036struct __ec_align4 ec_response_host_event_mask {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003037 uint32_t mask;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003038};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003039
3040/* These all use ec_response_host_event_mask */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003041#define EC_CMD_HOST_EVENT_GET_B 0x0087
3042#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
3043#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
3044#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003045
3046/* These all use ec_params_host_event_mask */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003047#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
3048#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
3049#define EC_CMD_HOST_EVENT_CLEAR 0x008C
3050#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
3051#define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003052
3053/*****************************************************************************/
3054/* Switch commands */
3055
3056/* Enable/disable LCD backlight */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003057#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003058
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003059struct __ec_align1 ec_params_switch_enable_backlight {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003060 uint8_t enabled;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003061};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003062
3063/* Enable/disable WLAN/Bluetooth */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003064#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
David Hendricksb6847ac2014-08-17 17:59:24 -07003065#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003066
David Hendricksb6847ac2014-08-17 17:59:24 -07003067/* Version 0 params; no response */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003068struct __ec_align1 ec_params_switch_enable_wireless_v0 {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003069 uint8_t enabled;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003070};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003071
David Hendricksb6847ac2014-08-17 17:59:24 -07003072/* Version 1 params */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003073struct __ec_align1 ec_params_switch_enable_wireless_v1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003074 /* Flags to enable now */
3075 uint8_t now_flags;
3076
3077 /* Which flags to copy from now_flags */
3078 uint8_t now_mask;
3079
3080 /*
3081 * Flags to leave enabled in S3, if they're on at the S0->S3
3082 * transition. (Other flags will be disabled by the S0->S3
3083 * transition.)
3084 */
3085 uint8_t suspend_flags;
3086
3087 /* Which flags to copy from suspend_flags */
3088 uint8_t suspend_mask;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003089};
David Hendricksb6847ac2014-08-17 17:59:24 -07003090
3091/* Version 1 response */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003092struct __ec_align1 ec_response_switch_enable_wireless_v1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003093 /* Flags to enable now */
3094 uint8_t now_flags;
3095
3096 /* Flags to leave enabled in S3 */
3097 uint8_t suspend_flags;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003098};
David Hendricksb6847ac2014-08-17 17:59:24 -07003099
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003100/*****************************************************************************/
3101/* GPIO commands. Only available on EC if write protect has been disabled. */
3102
3103/* Set GPIO output value */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003104#define EC_CMD_GPIO_SET 0x0092
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003105
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003106struct __ec_align1 ec_params_gpio_set {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003107 char name[32];
3108 uint8_t val;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003109};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003110
3111/* Get GPIO value */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003112#define EC_CMD_GPIO_GET 0x0093
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003113
David Hendricksb6847ac2014-08-17 17:59:24 -07003114/* Version 0 of input params and response */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003115struct __ec_align1 ec_params_gpio_get {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003116 char name[32];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003117};
3118
3119struct __ec_align1 ec_response_gpio_get {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003120 uint8_t val;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003121};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003122
David Hendricksb6847ac2014-08-17 17:59:24 -07003123/* Version 1 of input params and response */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003124struct __ec_align1 ec_params_gpio_get_v1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003125 uint8_t subcmd;
3126 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003127 struct __ec_align1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003128 char name[32];
3129 } get_value_by_name;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003130 struct __ec_align1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003131 uint8_t index;
3132 } get_info;
3133 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003134};
David Hendricksb6847ac2014-08-17 17:59:24 -07003135
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003136struct __ec_todo_packed ec_response_gpio_get_v1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003137 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003138 struct __ec_align1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003139 uint8_t val;
3140 } get_value_by_name, get_count;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003141 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07003142 uint8_t val;
3143 char name[32];
3144 uint32_t flags;
3145 } get_info;
3146 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003147};
David Hendricksb6847ac2014-08-17 17:59:24 -07003148
3149enum gpio_get_subcmd {
3150 EC_GPIO_GET_BY_NAME = 0,
3151 EC_GPIO_GET_COUNT = 1,
3152 EC_GPIO_GET_INFO = 2,
3153};
3154
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003155/*****************************************************************************/
3156/* I2C commands. Only available when flash write protect is unlocked. */
3157
David Hendricksb6847ac2014-08-17 17:59:24 -07003158/*
David Hendricks1649d162016-09-16 18:13:11 -07003159 * CAUTION: These commands are deprecated, and are not supported anymore in EC
3160 * builds >= 8398.0.0 (see crosbug.com/p/23570).
3161 *
3162 * Use EC_CMD_I2C_PASSTHRU instead.
David Hendricksb6847ac2014-08-17 17:59:24 -07003163 */
3164
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003165/* Read I2C bus */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003166#define EC_CMD_I2C_READ 0x0094
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003167
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003168struct __ec_align_size1 ec_params_i2c_read {
David Hendricks2d6db772013-07-10 21:07:48 -07003169 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003170 uint8_t read_size; /* Either 8 or 16. */
3171 uint8_t port;
3172 uint8_t offset;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003173};
3174
3175struct __ec_align2 ec_response_i2c_read {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003176 uint16_t data;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003177};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003178
3179/* Write I2C bus */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003180#define EC_CMD_I2C_WRITE 0x0095
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003181
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003182struct __ec_align_size1 ec_params_i2c_write {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003183 uint16_t data;
David Hendricks2d6db772013-07-10 21:07:48 -07003184 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003185 uint8_t write_size; /* Either 8 or 16. */
3186 uint8_t port;
3187 uint8_t offset;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003188};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003189
3190/*****************************************************************************/
3191/* Charge state commands. Only available when flash write protect unlocked. */
3192
David Hendricksb6847ac2014-08-17 17:59:24 -07003193/* Force charge state machine to stop charging the battery or force it to
3194 * discharge the battery.
3195 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003196#define EC_CMD_CHARGE_CONTROL 0x0096
David Hendricksb6847ac2014-08-17 17:59:24 -07003197#define EC_VER_CHARGE_CONTROL 1
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003198
David Hendricksb6847ac2014-08-17 17:59:24 -07003199enum ec_charge_control_mode {
3200 CHARGE_CONTROL_NORMAL = 0,
3201 CHARGE_CONTROL_IDLE,
3202 CHARGE_CONTROL_DISCHARGE,
3203};
3204
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003205struct __ec_align4 ec_params_charge_control {
David Hendricksb6847ac2014-08-17 17:59:24 -07003206 uint32_t mode; /* enum charge_control_mode */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003207};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003208
3209/*****************************************************************************/
David Hendricksd6f94492012-08-17 16:01:32 -07003210/* Console commands. Only available when flash write protect is unlocked. */
3211
3212/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003213#define EC_CMD_CONSOLE_SNAPSHOT 0x0097
David Hendricksd6f94492012-08-17 16:01:32 -07003214
3215/*
David Hendricks1649d162016-09-16 18:13:11 -07003216 * Read data from the saved snapshot. If the subcmd parameter is
3217 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
3218 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
3219 * end of the previous snapshot.
3220 *
3221 * The params are only looked at in version >= 1 of this command. Prior
3222 * versions will just default to CONSOLE_READ_NEXT behavior.
David Hendricksd6f94492012-08-17 16:01:32 -07003223 *
3224 * Response is null-terminated string. Empty string, if there is no more
3225 * remaining output.
3226 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003227#define EC_CMD_CONSOLE_READ 0x0098
David Hendricksd6f94492012-08-17 16:01:32 -07003228
David Hendricks1649d162016-09-16 18:13:11 -07003229enum ec_console_read_subcmd {
3230 CONSOLE_READ_NEXT = 0,
3231 CONSOLE_READ_RECENT
3232};
3233
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003234struct __ec_align1 ec_params_console_read_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07003235 uint8_t subcmd; /* enum ec_console_read_subcmd */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003236};
David Hendricks1649d162016-09-16 18:13:11 -07003237
David Hendricksd6f94492012-08-17 16:01:32 -07003238/*****************************************************************************/
David Hendricks2d6db772013-07-10 21:07:48 -07003239
3240/*
David Hendricksb6847ac2014-08-17 17:59:24 -07003241 * Cut off battery power immediately or after the host has shut down.
David Hendricks2d6db772013-07-10 21:07:48 -07003242 *
David Hendricksb6847ac2014-08-17 17:59:24 -07003243 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
3244 * EC_RES_SUCCESS if the command was successful.
3245 * EC_RES_ERROR if the cut off command failed.
David Hendricks2d6db772013-07-10 21:07:48 -07003246 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003247#define EC_CMD_BATTERY_CUT_OFF 0x0099
David Hendricks2d6db772013-07-10 21:07:48 -07003248
David Hendricksb6847ac2014-08-17 17:59:24 -07003249#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
3250
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003251struct __ec_align1 ec_params_battery_cutoff {
David Hendricksb6847ac2014-08-17 17:59:24 -07003252 uint8_t flags;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003253};
David Hendricksb6847ac2014-08-17 17:59:24 -07003254
David Hendricks2d6db772013-07-10 21:07:48 -07003255/*****************************************************************************/
3256/* USB port mux control. */
3257
3258/*
3259 * Switch USB mux or return to automatic switching.
3260 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003261#define EC_CMD_USB_MUX 0x009A
David Hendricks2d6db772013-07-10 21:07:48 -07003262
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003263struct __ec_align1 ec_params_usb_mux {
David Hendricks2d6db772013-07-10 21:07:48 -07003264 uint8_t mux;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003265};
David Hendricks2d6db772013-07-10 21:07:48 -07003266
3267/*****************************************************************************/
3268/* LDOs / FETs control. */
3269
3270enum ec_ldo_state {
3271 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
3272 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
3273};
3274
3275/*
3276 * Switch on/off a LDO.
3277 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003278#define EC_CMD_LDO_SET 0x009B
David Hendricks2d6db772013-07-10 21:07:48 -07003279
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003280struct __ec_align1 ec_params_ldo_set {
David Hendricks2d6db772013-07-10 21:07:48 -07003281 uint8_t index;
3282 uint8_t state;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003283};
David Hendricks2d6db772013-07-10 21:07:48 -07003284
3285/*
3286 * Get LDO state.
3287 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003288#define EC_CMD_LDO_GET 0x009C
David Hendricks2d6db772013-07-10 21:07:48 -07003289
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003290struct __ec_align1 ec_params_ldo_get {
David Hendricks2d6db772013-07-10 21:07:48 -07003291 uint8_t index;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003292};
David Hendricks2d6db772013-07-10 21:07:48 -07003293
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003294struct __ec_align1 ec_response_ldo_get {
David Hendricks2d6db772013-07-10 21:07:48 -07003295 uint8_t state;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003296};
David Hendricks2d6db772013-07-10 21:07:48 -07003297
3298/*****************************************************************************/
3299/* Power info. */
3300
3301/*
3302 * Get power info.
3303 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003304#define EC_CMD_POWER_INFO 0x009D
David Hendricks2d6db772013-07-10 21:07:48 -07003305
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003306struct __ec_align4 ec_response_power_info {
David Hendricks2d6db772013-07-10 21:07:48 -07003307 uint32_t usb_dev_type;
3308 uint16_t voltage_ac;
3309 uint16_t voltage_system;
3310 uint16_t current_system;
3311 uint16_t usb_current_limit;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003312};
David Hendricks2d6db772013-07-10 21:07:48 -07003313
3314/*****************************************************************************/
3315/* I2C passthru command */
3316
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003317#define EC_CMD_I2C_PASSTHRU 0x009E
David Hendricks2d6db772013-07-10 21:07:48 -07003318
David Hendricks2d6db772013-07-10 21:07:48 -07003319/* Read data; if not present, message is a write */
3320#define EC_I2C_FLAG_READ (1 << 15)
3321
3322/* Mask for address */
3323#define EC_I2C_ADDR_MASK 0x3ff
3324
3325#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
3326#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
3327
3328/* Any error */
3329#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
3330
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003331struct __ec_align2 ec_params_i2c_passthru_msg {
David Hendricks2d6db772013-07-10 21:07:48 -07003332 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
3333 uint16_t len; /* Number of bytes to read or write */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003334};
David Hendricks2d6db772013-07-10 21:07:48 -07003335
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003336struct __ec_align2 ec_params_i2c_passthru {
David Hendricks2d6db772013-07-10 21:07:48 -07003337 uint8_t port; /* I2C port number */
3338 uint8_t num_msgs; /* Number of messages */
3339 struct ec_params_i2c_passthru_msg msg[];
3340 /* Data to write for all messages is concatenated here */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003341};
David Hendricks2d6db772013-07-10 21:07:48 -07003342
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003343struct __ec_align1 ec_response_i2c_passthru {
David Hendricks2d6db772013-07-10 21:07:48 -07003344 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
3345 uint8_t num_msgs; /* Number of messages processed */
3346 uint8_t data[]; /* Data read by messages concatenated here */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003347};
David Hendricks2d6db772013-07-10 21:07:48 -07003348
David Hendricks2d6db772013-07-10 21:07:48 -07003349/*****************************************************************************/
David Hendricksb6847ac2014-08-17 17:59:24 -07003350/* Power button hang detect */
3351
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003352#define EC_CMD_HANG_DETECT 0x009F
David Hendricksb6847ac2014-08-17 17:59:24 -07003353
3354/* Reasons to start hang detection timer */
3355/* Power button pressed */
3356#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
3357
3358/* Lid closed */
3359#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
3360
3361 /* Lid opened */
3362#define EC_HANG_START_ON_LID_OPEN (1 << 2)
3363
3364/* Start of AP S3->S0 transition (booting or resuming from suspend) */
3365#define EC_HANG_START_ON_RESUME (1 << 3)
3366
3367/* Reasons to cancel hang detection */
3368
3369/* Power button released */
3370#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
3371
3372/* Any host command from AP received */
3373#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
3374
3375/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
3376#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
David Hendricks2d6db772013-07-10 21:07:48 -07003377
3378/*
David Hendricksb6847ac2014-08-17 17:59:24 -07003379 * If this flag is set, all the other fields are ignored, and the hang detect
3380 * timer is started. This provides the AP a way to start the hang timer
3381 * without reconfiguring any of the other hang detect settings. Note that
3382 * you must previously have configured the timeouts.
David Hendricks2d6db772013-07-10 21:07:48 -07003383 */
David Hendricksb6847ac2014-08-17 17:59:24 -07003384#define EC_HANG_START_NOW (1 << 30)
3385
3386/*
3387 * If this flag is set, all the other fields are ignored (including
3388 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
3389 * without reconfiguring any of the other hang detect settings.
3390 */
3391#define EC_HANG_STOP_NOW (1 << 31)
3392
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003393struct __ec_align4 ec_params_hang_detect {
David Hendricksb6847ac2014-08-17 17:59:24 -07003394 /* Flags; see EC_HANG_* */
3395 uint32_t flags;
3396
3397 /* Timeout in msec before generating host event, if enabled */
3398 uint16_t host_event_timeout_msec;
3399
3400 /* Timeout in msec before generating warm reboot, if enabled */
3401 uint16_t warm_reboot_timeout_msec;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003402};
David Hendricksb6847ac2014-08-17 17:59:24 -07003403
3404/*****************************************************************************/
3405/* Commands for battery charging */
3406
3407/*
3408 * This is the single catch-all host command to exchange data regarding the
3409 * charge state machine (v2 and up).
3410 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003411#define EC_CMD_CHARGE_STATE 0x00A0
David Hendricksb6847ac2014-08-17 17:59:24 -07003412
3413/* Subcommands for this host command */
3414enum charge_state_command {
3415 CHARGE_STATE_CMD_GET_STATE,
3416 CHARGE_STATE_CMD_GET_PARAM,
3417 CHARGE_STATE_CMD_SET_PARAM,
3418 CHARGE_STATE_NUM_CMDS
3419};
3420
3421/*
3422 * Known param numbers are defined here. Ranges are reserved for board-specific
3423 * params, which are handled by the particular implementations.
3424 */
3425enum charge_state_params {
3426 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
3427 CS_PARAM_CHG_CURRENT, /* charger current limit */
3428 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
3429 CS_PARAM_CHG_STATUS, /* charger-specific status */
3430 CS_PARAM_CHG_OPTION, /* charger-specific options */
David Hendricks1649d162016-09-16 18:13:11 -07003431 CS_PARAM_LIMIT_POWER, /*
3432 * Check if power is limited due to
3433 * low battery and / or a weak external
3434 * charger. READ ONLY.
3435 */
David Hendricksb6847ac2014-08-17 17:59:24 -07003436 /* How many so far? */
3437 CS_NUM_BASE_PARAMS,
3438
3439 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
3440 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
3441 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
3442
3443 /* Other custom param ranges go here... */
3444};
3445
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003446struct __ec_todo_packed ec_params_charge_state {
David Hendricksb6847ac2014-08-17 17:59:24 -07003447 uint8_t cmd; /* enum charge_state_command */
3448 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003449 struct __ec_align1 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003450 /* no args */
3451 } get_state;
3452
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003453 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07003454 uint32_t param; /* enum charge_state_param */
3455 } get_param;
3456
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003457 struct __ec_todo_unpacked {
David Hendricksb6847ac2014-08-17 17:59:24 -07003458 uint32_t param; /* param to set */
3459 uint32_t value; /* value to set */
3460 } set_param;
3461 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003462};
David Hendricksb6847ac2014-08-17 17:59:24 -07003463
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003464struct __ec_align4 ec_response_charge_state {
David Hendricksb6847ac2014-08-17 17:59:24 -07003465 union {
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003466 struct __ec_align4 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003467 int ac;
3468 int chg_voltage;
3469 int chg_current;
3470 int chg_input_current;
3471 int batt_state_of_charge;
3472 } get_state;
3473
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003474 struct __ec_align4 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003475 uint32_t value;
3476 } get_param;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003477 struct __ec_align4 {
David Hendricksb6847ac2014-08-17 17:59:24 -07003478 /* no return values */
3479 } set_param;
3480 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003481};
David Hendricksb6847ac2014-08-17 17:59:24 -07003482
David Hendricks2d6db772013-07-10 21:07:48 -07003483
3484/*
3485 * Set maximum battery charging current.
3486 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003487#define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
David Hendricks2d6db772013-07-10 21:07:48 -07003488
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003489struct __ec_align4 ec_params_current_limit {
David Hendricks2d6db772013-07-10 21:07:48 -07003490 uint32_t limit; /* in mA */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003491};
David Hendricks2d6db772013-07-10 21:07:48 -07003492
3493/*
David Hendricks1649d162016-09-16 18:13:11 -07003494 * Set maximum external voltage / current.
David Hendricks2d6db772013-07-10 21:07:48 -07003495 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003496#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
David Hendricks2d6db772013-07-10 21:07:48 -07003497
David Hendricks1649d162016-09-16 18:13:11 -07003498/* Command v0 is used only on Spring and is obsolete + unsupported */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003499struct __ec_align2 ec_params_external_power_limit_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07003500 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
3501 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003502};
David Hendricks1649d162016-09-16 18:13:11 -07003503
3504#define EC_POWER_LIMIT_NONE 0xffff
3505
3506/*****************************************************************************/
3507/* Hibernate/Deep Sleep Commands */
3508
3509/* Set the delay before going into hibernation. */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003510#define EC_CMD_HIBERNATION_DELAY 0x00A8
David Hendricks1649d162016-09-16 18:13:11 -07003511
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003512struct __ec_align4 ec_params_hibernation_delay {
David Hendricks1649d162016-09-16 18:13:11 -07003513 /*
3514 * Seconds to wait in G3 before hibernate. Pass in 0 to read the
3515 * current settings without changing them.
3516 */
3517 uint32_t seconds;
3518};
3519
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003520struct __ec_align4 ec_response_hibernation_delay {
David Hendricks1649d162016-09-16 18:13:11 -07003521 /*
3522 * The current time in seconds in which the system has been in the G3
3523 * state. This value is reset if the EC transitions out of G3.
3524 */
3525 uint32_t time_g3;
3526
3527 /*
3528 * The current time remaining in seconds until the EC should hibernate.
3529 * This value is also reset if the EC transitions out of G3.
3530 */
3531 uint32_t time_remaining;
3532
3533 /*
3534 * The current time in seconds that the EC should wait in G3 before
3535 * hibernating.
3536 */
3537 uint32_t hibernate_delay;
3538};
3539
3540/* Inform the EC when entering a sleep state */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003541#define EC_CMD_HOST_SLEEP_EVENT 0x00A9
David Hendricks1649d162016-09-16 18:13:11 -07003542
3543enum host_sleep_event {
3544 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
3545 HOST_SLEEP_EVENT_S3_RESUME = 2,
3546 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
3547 HOST_SLEEP_EVENT_S0IX_RESUME = 4
3548};
3549
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003550struct __ec_align1 ec_params_host_sleep_event {
David Hendricks1649d162016-09-16 18:13:11 -07003551 uint8_t sleep_event;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003552};
David Hendricks2d6db772013-07-10 21:07:48 -07003553
3554/*****************************************************************************/
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08003555/* Device events */
3556#define EC_CMD_DEVICE_EVENT 0x00AA
3557
3558enum ec_device_event {
3559 EC_DEVICE_EVENT_TRACKPAD,
3560 EC_DEVICE_EVENT_DSP,
3561 EC_DEVICE_EVENT_WIFI,
3562};
3563
3564enum ec_device_event_param {
3565 /* Get and clear pending device events */
3566 EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
3567 /* Get device event mask */
3568 EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
3569 /* Set device event mask */
3570 EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
3571};
3572
3573#define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
3574
3575struct __ec_align_size1 ec_params_device_event {
3576 uint32_t event_mask;
3577 uint8_t param;
3578};
3579
3580struct __ec_align4 ec_response_device_event {
3581 uint32_t event_mask;
3582};
3583
3584/*****************************************************************************/
David Hendricks2d6db772013-07-10 21:07:48 -07003585/* Smart battery pass-through */
3586
3587/* Get / Set 16-bit smart battery registers */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003588#define EC_CMD_SB_READ_WORD 0x00B0
3589#define EC_CMD_SB_WRITE_WORD 0x00B1
David Hendricks2d6db772013-07-10 21:07:48 -07003590
3591/* Get / Set string smart battery parameters
3592 * formatted as SMBUS "block".
3593 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003594#define EC_CMD_SB_READ_BLOCK 0x00B2
3595#define EC_CMD_SB_WRITE_BLOCK 0x00B3
David Hendricks2d6db772013-07-10 21:07:48 -07003596
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003597struct __ec_align1 ec_params_sb_rd {
David Hendricks2d6db772013-07-10 21:07:48 -07003598 uint8_t reg;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003599};
David Hendricks2d6db772013-07-10 21:07:48 -07003600
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003601struct __ec_align2 ec_response_sb_rd_word {
David Hendricks2d6db772013-07-10 21:07:48 -07003602 uint16_t value;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003603};
David Hendricks2d6db772013-07-10 21:07:48 -07003604
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003605struct __ec_align1 ec_params_sb_wr_word {
David Hendricks2d6db772013-07-10 21:07:48 -07003606 uint8_t reg;
3607 uint16_t value;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003608};
David Hendricks2d6db772013-07-10 21:07:48 -07003609
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003610struct __ec_align1 ec_response_sb_rd_block {
David Hendricks2d6db772013-07-10 21:07:48 -07003611 uint8_t data[32];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003612};
David Hendricks2d6db772013-07-10 21:07:48 -07003613
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003614struct __ec_align1 ec_params_sb_wr_block {
David Hendricks2d6db772013-07-10 21:07:48 -07003615 uint8_t reg;
3616 uint16_t data[32];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003617};
David Hendricksb6847ac2014-08-17 17:59:24 -07003618
3619/*****************************************************************************/
3620/* Battery vendor parameters
3621 *
3622 * Get or set vendor-specific parameters in the battery. Implementations may
3623 * differ between boards or batteries. On a set operation, the response
3624 * contains the actual value set, which may be rounded or clipped from the
3625 * requested value.
3626 */
3627
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003628#define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
David Hendricksb6847ac2014-08-17 17:59:24 -07003629
3630enum ec_battery_vendor_param_mode {
3631 BATTERY_VENDOR_PARAM_MODE_GET = 0,
3632 BATTERY_VENDOR_PARAM_MODE_SET,
3633};
3634
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003635struct __ec_align_size1 ec_params_battery_vendor_param {
David Hendricksb6847ac2014-08-17 17:59:24 -07003636 uint32_t param;
3637 uint32_t value;
3638 uint8_t mode;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003639};
David Hendricksb6847ac2014-08-17 17:59:24 -07003640
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003641struct __ec_align4 ec_response_battery_vendor_param {
David Hendricksb6847ac2014-08-17 17:59:24 -07003642 uint32_t value;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003643};
David Hendricksb6847ac2014-08-17 17:59:24 -07003644
David Hendricks2d6db772013-07-10 21:07:48 -07003645/*****************************************************************************/
David Hendricks1649d162016-09-16 18:13:11 -07003646/*
3647 * Smart Battery Firmware Update Commands
3648 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003649#define EC_CMD_SB_FW_UPDATE 0x00B5
David Hendricks1649d162016-09-16 18:13:11 -07003650
3651enum ec_sb_fw_update_subcmd {
3652 EC_SB_FW_UPDATE_PREPARE = 0x0,
3653 EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
3654 EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
3655 EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
3656 EC_SB_FW_UPDATE_END = 0x4,
3657 EC_SB_FW_UPDATE_STATUS = 0x5,
3658 EC_SB_FW_UPDATE_PROTECT = 0x6,
3659 EC_SB_FW_UPDATE_MAX = 0x7,
3660};
3661
3662#define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
3663#define SB_FW_UPDATE_CMD_STATUS_SIZE 2
3664#define SB_FW_UPDATE_CMD_INFO_SIZE 8
3665
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003666struct __ec_align4 ec_sb_fw_update_header {
David Hendricks1649d162016-09-16 18:13:11 -07003667 uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
3668 uint16_t fw_id; /* firmware id */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003669};
David Hendricks1649d162016-09-16 18:13:11 -07003670
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003671struct __ec_align4 ec_params_sb_fw_update {
David Hendricks1649d162016-09-16 18:13:11 -07003672 struct ec_sb_fw_update_header hdr;
3673 union {
3674 /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
3675 /* EC_SB_FW_UPDATE_INFO = 0x1 */
3676 /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
3677 /* EC_SB_FW_UPDATE_END = 0x4 */
3678 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
3679 /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003680 struct __ec_align4 {
David Hendricks1649d162016-09-16 18:13:11 -07003681 /* no args */
3682 } dummy;
3683
3684 /* EC_SB_FW_UPDATE_WRITE = 0x3 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003685 struct __ec_align4 {
David Hendricks1649d162016-09-16 18:13:11 -07003686 uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
3687 } write;
3688 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003689};
David Hendricks1649d162016-09-16 18:13:11 -07003690
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003691struct __ec_align1 ec_response_sb_fw_update {
David Hendricks1649d162016-09-16 18:13:11 -07003692 union {
3693 /* EC_SB_FW_UPDATE_INFO = 0x1 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003694 struct __ec_align1 {
David Hendricks1649d162016-09-16 18:13:11 -07003695 uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
3696 } info;
3697
3698 /* EC_SB_FW_UPDATE_STATUS = 0x5 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003699 struct __ec_align1 {
David Hendricks1649d162016-09-16 18:13:11 -07003700 uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
3701 } status;
3702 };
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003703};
David Hendricks1649d162016-09-16 18:13:11 -07003704
3705/*
3706 * Entering Verified Boot Mode Command
3707 * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
3708 * Valid Modes are: normal, developer, and recovery.
3709 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003710#define EC_CMD_ENTERING_MODE 0x00B6
David Hendricks1649d162016-09-16 18:13:11 -07003711
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003712struct __ec_align4 ec_params_entering_mode {
David Hendricks1649d162016-09-16 18:13:11 -07003713 int vboot_mode;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003714};
David Hendricks1649d162016-09-16 18:13:11 -07003715
3716#define VBOOT_MODE_NORMAL 0
3717#define VBOOT_MODE_DEVELOPER 1
3718#define VBOOT_MODE_RECOVERY 2
3719
3720/*****************************************************************************/
3721/*
3722 * I2C passthru protection command: Protects I2C tunnels against access on
3723 * certain addresses (board-specific).
3724 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003725#define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
David Hendricks1649d162016-09-16 18:13:11 -07003726
3727enum ec_i2c_passthru_protect_subcmd {
3728 EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
3729 EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
3730};
3731
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003732struct __ec_align1 ec_params_i2c_passthru_protect {
David Hendricks1649d162016-09-16 18:13:11 -07003733 uint8_t subcmd;
3734 uint8_t port; /* I2C port number */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003735};
David Hendricks1649d162016-09-16 18:13:11 -07003736
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003737struct __ec_align1 ec_response_i2c_passthru_protect {
David Hendricks1649d162016-09-16 18:13:11 -07003738 uint8_t status; /* Status flags (0: unlocked, 1: locked) */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003739};
David Hendricks1649d162016-09-16 18:13:11 -07003740
3741/*****************************************************************************/
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003742/* System commands */
3743
3744/*
David Hendricksb6847ac2014-08-17 17:59:24 -07003745 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
3746 * necessarily reboot the EC. Rename to "image" or something similar?
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003747 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003748#define EC_CMD_REBOOT_EC 0x00D2
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003749
3750/* Command */
3751enum ec_reboot_cmd {
3752 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
David Hendricks2d6db772013-07-10 21:07:48 -07003753 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
3754 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003755 /* (command 3 was jump to RW-B) */
3756 EC_REBOOT_COLD = 4, /* Cold-reboot */
David Hendricks2d6db772013-07-10 21:07:48 -07003757 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
3758 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003759};
3760
3761/* Flags for ec_params_reboot_ec.reboot_flags */
3762#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
David Hendricks2d6db772013-07-10 21:07:48 -07003763#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003764
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003765struct __ec_align1 ec_params_reboot_ec {
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003766 uint8_t cmd; /* enum ec_reboot_cmd */
3767 uint8_t flags; /* See EC_REBOOT_FLAG_* */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003768};
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003769
David Hendricks2d6db772013-07-10 21:07:48 -07003770/*
3771 * Get information on last EC panic.
3772 *
3773 * Returns variable-length platform-dependent panic information. See panic.h
3774 * for details.
3775 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003776#define EC_CMD_GET_PANIC_INFO 0x00D3
David Hendricks2d6db772013-07-10 21:07:48 -07003777
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003778/*****************************************************************************/
3779/*
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003780 * Special commands
3781 *
3782 * These do not follow the normal rules for commands. See each command for
3783 * details.
3784 */
3785
3786/*
3787 * Reboot NOW
3788 *
3789 * This command will work even when the EC LPC interface is busy, because the
3790 * reboot command is processed at interrupt level. Note that when the EC
3791 * reboots, the host will reboot too, so there is no response to this command.
3792 *
3793 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3794 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003795#define EC_CMD_REBOOT 0x00D1 /* Think "die" */
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003796
3797/*
David Hendricksd6f94492012-08-17 16:01:32 -07003798 * Resend last response (not supported on LPC).
3799 *
3800 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3801 * there was no previous command, or the previous command's response was too
3802 * big to save.
3803 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003804#define EC_CMD_RESEND_RESPONSE 0x00DB
David Hendricksd6f94492012-08-17 16:01:32 -07003805
3806/*
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003807 * This header byte on a command indicate version 0. Any header byte less
3808 * than this means that we are talking to an old EC which doesn't support
3809 * versioning. In that case, we assume version 0.
3810 *
3811 * Header bytes greater than this indicate a later version. For example,
3812 * EC_CMD_VERSION0 + 1 means we are using version 1.
3813 *
David Hendricksb6847ac2014-08-17 17:59:24 -07003814 * The old EC interface must not use commands 0xdc or higher.
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003815 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003816#define EC_CMD_VERSION0 0x00DC
Louis Yung-Chieh Lof779a7b2012-07-30 18:20:39 +08003817
David Hendricksb6847ac2014-08-17 17:59:24 -07003818/*****************************************************************************/
3819/*
3820 * PD commands
3821 *
3822 * These commands are for PD MCU communication.
3823 */
3824
3825/* EC to PD MCU exchange status command */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003826#define EC_CMD_PD_EXCHANGE_STATUS 0x0100
David Hendricks1649d162016-09-16 18:13:11 -07003827#define EC_VER_PD_EXCHANGE_STATUS 2
3828
3829enum pd_charge_state {
3830 PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
3831 PD_CHARGE_NONE, /* No charging allowed */
3832 PD_CHARGE_5V, /* 5V charging only */
3833 PD_CHARGE_MAX /* Charge at max voltage */
3834};
David Hendricksb6847ac2014-08-17 17:59:24 -07003835
3836/* Status of EC being sent to PD */
David Hendricks1649d162016-09-16 18:13:11 -07003837#define EC_STATUS_HIBERNATING (1 << 0)
3838
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003839struct __ec_align1 ec_params_pd_status {
David Hendricks1649d162016-09-16 18:13:11 -07003840 uint8_t status; /* EC status */
3841 int8_t batt_soc; /* battery state of charge */
3842 uint8_t charge_state; /* charging state (from enum pd_charge_state) */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003843};
David Hendricksb6847ac2014-08-17 17:59:24 -07003844
3845/* Status of PD being sent back to EC */
David Hendricks1649d162016-09-16 18:13:11 -07003846#define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
3847#define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
3848#define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
3849#define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
3850#define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
3851#define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
3852#define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
3853#define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
3854 PD_STATUS_TCPC_ALERT_1 | \
3855 PD_STATUS_HOST_EVENT)
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003856struct __ec_align_size1 ec_response_pd_status {
David Hendricks1649d162016-09-16 18:13:11 -07003857 uint32_t curr_lim_ma; /* input current limit */
3858 uint16_t status; /* PD MCU status */
3859 int8_t active_charge_port; /* active charging port */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003860};
David Hendricks1649d162016-09-16 18:13:11 -07003861
3862/* AP to PD MCU host event status command, cleared on read */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003863#define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
David Hendricks1649d162016-09-16 18:13:11 -07003864
3865/* PD MCU host event status bits */
3866#define PD_EVENT_UPDATE_DEVICE (1 << 0)
3867#define PD_EVENT_POWER_CHANGE (1 << 1)
3868#define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
3869#define PD_EVENT_DATA_SWAP (1 << 3)
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003870struct __ec_align4 ec_response_host_event_status {
David Hendricks1649d162016-09-16 18:13:11 -07003871 uint32_t status; /* PD MCU host event status */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003872};
David Hendricksb6847ac2014-08-17 17:59:24 -07003873
3874/* Set USB type-C port role and muxes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003875#define EC_CMD_USB_PD_CONTROL 0x0101
David Hendricksb6847ac2014-08-17 17:59:24 -07003876
3877enum usb_pd_control_role {
3878 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3879 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3880 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3881 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3882 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
David Hendricks1649d162016-09-16 18:13:11 -07003883 USB_PD_CTRL_ROLE_COUNT
David Hendricksb6847ac2014-08-17 17:59:24 -07003884};
3885
3886enum usb_pd_control_mux {
3887 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3888 USB_PD_CTRL_MUX_NONE = 1,
3889 USB_PD_CTRL_MUX_USB = 2,
3890 USB_PD_CTRL_MUX_DP = 3,
3891 USB_PD_CTRL_MUX_DOCK = 4,
3892 USB_PD_CTRL_MUX_AUTO = 5,
David Hendricks1649d162016-09-16 18:13:11 -07003893 USB_PD_CTRL_MUX_COUNT
3894};
3895
3896enum usb_pd_control_swap {
3897 USB_PD_CTRL_SWAP_NONE = 0,
3898 USB_PD_CTRL_SWAP_DATA = 1,
3899 USB_PD_CTRL_SWAP_POWER = 2,
3900 USB_PD_CTRL_SWAP_VCONN = 3,
3901 USB_PD_CTRL_SWAP_COUNT
David Hendricksb6847ac2014-08-17 17:59:24 -07003902};
3903
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003904struct __ec_align1 ec_params_usb_pd_control {
David Hendricksb6847ac2014-08-17 17:59:24 -07003905 uint8_t port;
3906 uint8_t role;
3907 uint8_t mux;
David Hendricks1649d162016-09-16 18:13:11 -07003908 uint8_t swap;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003909};
David Hendricksb6847ac2014-08-17 17:59:24 -07003910
David Hendricks1649d162016-09-16 18:13:11 -07003911#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3912#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3913#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3914
3915#define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
3916#define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
3917#define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
3918#define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
3919#define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
3920#define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
3921#define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
3922
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003923struct __ec_align1 ec_response_usb_pd_control {
David Hendricks1649d162016-09-16 18:13:11 -07003924 uint8_t enabled;
3925 uint8_t role;
3926 uint8_t polarity;
3927 uint8_t state;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003928};
David Hendricks1649d162016-09-16 18:13:11 -07003929
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003930struct __ec_align1 ec_response_usb_pd_control_v1 {
David Hendricks1649d162016-09-16 18:13:11 -07003931 uint8_t enabled;
3932 uint8_t role;
3933 uint8_t polarity;
3934 char state[32];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003935};
David Hendricks1649d162016-09-16 18:13:11 -07003936
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003937#define EC_CMD_USB_PD_PORTS 0x0102
David Hendricks1649d162016-09-16 18:13:11 -07003938
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08003939/* Maximum number of PD ports on a device, num_ports will be <= this */
3940#define EC_USB_PD_MAX_PORTS 8
3941
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003942struct __ec_align1 ec_response_usb_pd_ports {
David Hendricks1649d162016-09-16 18:13:11 -07003943 uint8_t num_ports;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003944};
David Hendricks1649d162016-09-16 18:13:11 -07003945
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003946#define EC_CMD_USB_PD_POWER_INFO 0x0103
David Hendricks1649d162016-09-16 18:13:11 -07003947
3948#define PD_POWER_CHARGING_PORT 0xff
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003949struct __ec_align1 ec_params_usb_pd_power_info {
David Hendricks1649d162016-09-16 18:13:11 -07003950 uint8_t port;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003951};
David Hendricks1649d162016-09-16 18:13:11 -07003952
3953enum usb_chg_type {
3954 USB_CHG_TYPE_NONE,
3955 USB_CHG_TYPE_PD,
3956 USB_CHG_TYPE_C,
3957 USB_CHG_TYPE_PROPRIETARY,
3958 USB_CHG_TYPE_BC12_DCP,
3959 USB_CHG_TYPE_BC12_CDP,
3960 USB_CHG_TYPE_BC12_SDP,
3961 USB_CHG_TYPE_OTHER,
3962 USB_CHG_TYPE_VBUS,
3963 USB_CHG_TYPE_UNKNOWN,
3964};
3965enum usb_power_roles {
3966 USB_PD_PORT_POWER_DISCONNECTED,
3967 USB_PD_PORT_POWER_SOURCE,
3968 USB_PD_PORT_POWER_SINK,
3969 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3970};
3971
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003972struct __ec_align2 usb_chg_measures {
David Hendricks1649d162016-09-16 18:13:11 -07003973 uint16_t voltage_max;
3974 uint16_t voltage_now;
3975 uint16_t current_max;
3976 uint16_t current_lim;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003977};
David Hendricks1649d162016-09-16 18:13:11 -07003978
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003979struct __ec_align4 ec_response_usb_pd_power_info {
David Hendricks1649d162016-09-16 18:13:11 -07003980 uint8_t role;
3981 uint8_t type;
3982 uint8_t dualrole;
3983 uint8_t reserved1;
3984 struct usb_chg_measures meas;
3985 uint32_t max_power;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003986};
David Hendricks1649d162016-09-16 18:13:11 -07003987
3988/* Write USB-PD device FW */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003989#define EC_CMD_USB_PD_FW_UPDATE 0x0110
David Hendricks1649d162016-09-16 18:13:11 -07003990
3991enum usb_pd_fw_update_cmds {
3992 USB_PD_FW_REBOOT,
3993 USB_PD_FW_FLASH_ERASE,
3994 USB_PD_FW_FLASH_WRITE,
3995 USB_PD_FW_ERASE_SIG,
3996};
3997
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08003998struct __ec_align4 ec_params_usb_pd_fw_update {
David Hendricks1649d162016-09-16 18:13:11 -07003999 uint16_t dev_id;
4000 uint8_t cmd;
4001 uint8_t port;
4002 uint32_t size; /* Size to write in bytes */
4003 /* Followed by data to write */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004004};
David Hendricks1649d162016-09-16 18:13:11 -07004005
4006/* Write USB-PD Accessory RW_HASH table entry */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004007#define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
David Hendricks1649d162016-09-16 18:13:11 -07004008/* RW hash is first 20 bytes of SHA-256 of RW section */
4009#define PD_RW_HASH_SIZE 20
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004010struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
David Hendricks1649d162016-09-16 18:13:11 -07004011 uint16_t dev_id;
4012 uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004013 uint8_t reserved; /* For alignment of current_image
4014 * TODO(rspangler) but it's not aligned!
4015 * Should have been reserved[2]. */
David Hendricks1649d162016-09-16 18:13:11 -07004016 uint32_t current_image; /* One of ec_current_image */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004017};
David Hendricks1649d162016-09-16 18:13:11 -07004018
4019/* Read USB-PD Accessory info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004020#define EC_CMD_USB_PD_DEV_INFO 0x0112
David Hendricks1649d162016-09-16 18:13:11 -07004021
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004022struct __ec_align1 ec_params_usb_pd_info_request {
David Hendricks1649d162016-09-16 18:13:11 -07004023 uint8_t port;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004024};
David Hendricks1649d162016-09-16 18:13:11 -07004025
4026/* Read USB-PD Device discovery info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004027#define EC_CMD_USB_PD_DISCOVERY 0x0113
4028struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
David Hendricks1649d162016-09-16 18:13:11 -07004029 uint16_t vid; /* USB-IF VID */
4030 uint16_t pid; /* USB-IF PID */
4031 uint8_t ptype; /* product type (hub,periph,cable,ama) */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004032};
David Hendricks1649d162016-09-16 18:13:11 -07004033
4034/* Override default charge behavior */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004035#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
David Hendricks1649d162016-09-16 18:13:11 -07004036
4037/* Negative port parameters have special meaning */
4038enum usb_pd_override_ports {
4039 OVERRIDE_DONT_CHARGE = -2,
4040 OVERRIDE_OFF = -1,
4041 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
4042};
4043
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004044struct __ec_align2 ec_params_charge_port_override {
David Hendricks1649d162016-09-16 18:13:11 -07004045 int16_t override_port; /* Override port# */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004046};
David Hendricks1649d162016-09-16 18:13:11 -07004047
4048/* Read (and delete) one entry of PD event log */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004049#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
David Hendricks1649d162016-09-16 18:13:11 -07004050
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004051struct __ec_align4 ec_response_pd_log {
David Hendricks1649d162016-09-16 18:13:11 -07004052 uint32_t timestamp; /* relative timestamp in milliseconds */
4053 uint8_t type; /* event type : see PD_EVENT_xx below */
4054 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
4055 uint16_t data; /* type-defined data payload */
4056 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004057};
David Hendricks1649d162016-09-16 18:13:11 -07004058
4059
4060/* The timestamp is the microsecond counter shifted to get about a ms. */
4061#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
4062
4063#define PD_LOG_SIZE_MASK 0x1f
4064#define PD_LOG_PORT_MASK 0xe0
4065#define PD_LOG_PORT_SHIFT 5
4066#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
4067 ((size) & PD_LOG_SIZE_MASK))
4068#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
4069#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
4070
4071/* PD event log : entry types */
4072/* PD MCU events */
4073#define PD_EVENT_MCU_BASE 0x00
4074#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
4075#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
4076/* Reserved for custom board event */
4077#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
4078/* PD generic accessory events */
4079#define PD_EVENT_ACC_BASE 0x20
4080#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
4081#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
4082/* PD power supply events */
4083#define PD_EVENT_PS_BASE 0x40
4084#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
4085/* PD video dongles events */
4086#define PD_EVENT_VIDEO_BASE 0x60
4087#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
4088#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
4089/* Returned in the "type" field, when there is no entry available */
4090#define PD_EVENT_NO_ENTRY 0xff
4091
4092/*
4093 * PD_EVENT_MCU_CHARGE event definition :
4094 * the payload is "struct usb_chg_measures"
4095 * the data field contains the port state flags as defined below :
4096 */
4097/* Port partner is a dual role device */
4098#define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
4099/* Port is the pending override port */
4100#define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
4101/* Port is the override port */
4102#define CHARGE_FLAGS_OVERRIDE (1 << 13)
4103/* Charger type */
4104#define CHARGE_FLAGS_TYPE_SHIFT 3
4105#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
4106/* Power delivery role */
4107#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
4108
4109/*
4110 * PD_EVENT_PS_FAULT data field flags definition :
4111 */
4112#define PS_FAULT_OCP 1
4113#define PS_FAULT_FAST_OCP 2
4114#define PS_FAULT_OVP 3
4115#define PS_FAULT_DISCH 4
4116
4117/*
4118 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
4119 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004120struct __ec_align4 mcdp_version {
David Hendricks1649d162016-09-16 18:13:11 -07004121 uint8_t major;
4122 uint8_t minor;
4123 uint16_t build;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004124};
David Hendricks1649d162016-09-16 18:13:11 -07004125
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004126struct __ec_align4 mcdp_info {
David Hendricks1649d162016-09-16 18:13:11 -07004127 uint8_t family[2];
4128 uint8_t chipid[2];
4129 struct mcdp_version irom;
4130 struct mcdp_version fw;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004131};
David Hendricks1649d162016-09-16 18:13:11 -07004132
4133/* struct mcdp_info field decoding */
4134#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
4135#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
4136
4137/* Get/Set USB-PD Alternate mode info */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004138#define EC_CMD_USB_PD_GET_AMODE 0x0116
4139struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
David Hendricks1649d162016-09-16 18:13:11 -07004140 uint16_t svid_idx; /* SVID index to get */
4141 uint8_t port; /* port */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004142};
David Hendricks1649d162016-09-16 18:13:11 -07004143
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004144struct __ec_align4 ec_params_usb_pd_get_mode_response {
David Hendricks1649d162016-09-16 18:13:11 -07004145 uint16_t svid; /* SVID */
4146 uint16_t opos; /* Object Position */
4147 uint32_t vdo[6]; /* Mode VDOs */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004148};
David Hendricks1649d162016-09-16 18:13:11 -07004149
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004150#define EC_CMD_USB_PD_SET_AMODE 0x0117
David Hendricks1649d162016-09-16 18:13:11 -07004151
4152enum pd_mode_cmd {
4153 PD_EXIT_MODE = 0,
4154 PD_ENTER_MODE = 1,
4155 /* Not a command. Do NOT remove. */
4156 PD_MODE_CMD_COUNT,
4157};
4158
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004159struct __ec_align4 ec_params_usb_pd_set_mode_request {
David Hendricks1649d162016-09-16 18:13:11 -07004160 uint32_t cmd; /* enum pd_mode_cmd */
4161 uint16_t svid; /* SVID to set */
4162 uint8_t opos; /* Object Position */
4163 uint8_t port; /* port */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004164};
David Hendricks1649d162016-09-16 18:13:11 -07004165
4166/* Ask the PD MCU to record a log of a requested type */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004167#define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
David Hendricks1649d162016-09-16 18:13:11 -07004168
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004169struct __ec_align1 ec_params_pd_write_log_entry {
David Hendricks1649d162016-09-16 18:13:11 -07004170 uint8_t type; /* event type : see PD_EVENT_xx above */
4171 uint8_t port; /* port#, or 0 for events unrelated to a given port */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004172};
David Hendricks1649d162016-09-16 18:13:11 -07004173
4174
4175/* Control USB-PD chip */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004176#define EC_CMD_PD_CONTROL 0x0119
David Hendricks1649d162016-09-16 18:13:11 -07004177
4178enum ec_pd_control_cmd {
4179 PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
4180 PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
4181 PD_RESET, /* Force reset the PD chip */
4182 PD_CONTROL_DISABLE /* Disable further calls to this command */
4183};
4184
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004185struct __ec_align1 ec_params_pd_control {
David Hendricks1649d162016-09-16 18:13:11 -07004186 uint8_t chip; /* chip id (should be 0) */
4187 uint8_t subcmd;
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004188};
David Hendricks1649d162016-09-16 18:13:11 -07004189
4190/* Get info about USB-C SS muxes */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004191#define EC_CMD_USB_PD_MUX_INFO 0x011A
David Hendricks1649d162016-09-16 18:13:11 -07004192
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004193struct __ec_align1 ec_params_usb_pd_mux_info {
David Hendricks1649d162016-09-16 18:13:11 -07004194 uint8_t port; /* USB-C port number */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004195};
David Hendricks1649d162016-09-16 18:13:11 -07004196
4197/* Flags representing mux state */
4198#define USB_PD_MUX_USB_ENABLED (1 << 0)
4199#define USB_PD_MUX_DP_ENABLED (1 << 1)
4200#define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
4201#define USB_PD_MUX_HPD_IRQ (1 << 3)
4202
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004203struct __ec_align1 ec_response_usb_pd_mux_info {
David Hendricks1649d162016-09-16 18:13:11 -07004204 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004205};
4206
4207#define EC_CMD_PD_CHIP_INFO 0x011B
4208
4209struct __ec_align1 ec_params_pd_chip_info {
4210 uint8_t port; /* USB-C port number */
4211 uint8_t renew; /* Force renewal */
4212};
4213
4214struct __ec_align2 ec_response_pd_chip_info {
4215 uint16_t vendor_id;
4216 uint16_t product_id;
4217 uint16_t device_id;
4218 union {
4219 uint8_t fw_version_string[8];
4220 uint64_t fw_version_number;
4221 };
4222};
4223
4224/* Run RW signature verification and get status */
4225#define EC_CMD_RWSIG_CHECK_STATUS 0x011C
4226
4227struct __ec_align4 ec_response_rwsig_check_status {
4228 uint32_t status;
4229};
4230
4231/* For controlling RWSIG task */
4232#define EC_CMD_RWSIG_ACTION 0x011D
4233
4234enum rwsig_action {
4235 RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
4236 RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
4237};
4238
4239struct __ec_align4 ec_params_rwsig_action {
4240 uint32_t action;
4241};
David Hendricks1649d162016-09-16 18:13:11 -07004242
David Hendricks1649d162016-09-16 18:13:11 -07004243/*****************************************************************************/
4244/* The command range 0x200-0x2FF is reserved for Rotor. */
4245
4246/*****************************************************************************/
4247/*
4248 * Reserve a range of host commands for the CR51 firmware.
4249 */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004250#define EC_CMD_CR51_BASE 0x0300
4251#define EC_CMD_CR51_LAST 0x03FF
4252
4253/*****************************************************************************/
4254/* Fingerprint MCU commands: range 0x0400-0x040x */
4255
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08004256/* Fingerprint SPI sensor passthru command: prototyping ONLY */
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004257#define EC_CMD_FP_PASSTHRU 0x0400
4258
4259#define EC_FP_FLAG_NOT_COMPLETE 0x1
4260
4261struct __ec_align2 ec_params_fp_passthru {
4262 uint16_t len; /* Number of bytes to write then read */
4263 uint16_t flags; /* EC_FP_FLAG_xxx */
4264 uint8_t data[]; /* Data to send */
4265};
David Hendricks1649d162016-09-16 18:13:11 -07004266
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08004267/* Fingerprint sensor configuration command: prototyping ONLY */
4268#define EC_CMD_FP_SENSOR_CONFIG 0x0401
4269
4270#define EC_FP_SENSOR_CONFIG_MAX_REGS 16
4271
4272struct __ec_align2 ec_params_fp_sensor_config {
4273 uint8_t count; /* Number of setup registers */
4274 /*
4275 * the value to send to each of the 'count' setup registers
4276 * is stored in the 'data' array for 'len' bytes just after
4277 * the previous one.
4278 */
4279 uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
4280 uint8_t data[];
4281};
4282
4283/* Configure the Fingerprint MCU behavior */
4284#define EC_CMD_FP_MODE 0x0402
4285
4286/* Put the sensor in its lowest power mode */
4287#define FP_MODE_DEEPSLEEP (1<<0)
4288/* Wait to see a finger on the sensor */
4289#define FP_MODE_FINGER_DOWN (1<<1)
4290/* Poll until the finger has left the sensor */
4291#define FP_MODE_FINGER_UP (1<<2)
4292/* Capture the current finger image */
4293#define FP_MODE_CAPTURE (1<<3)
4294/* special value: don't change anything just read back current mode */
4295#define FP_MODE_DONT_CHANGE (1<<31)
4296
4297struct __ec_align4 ec_params_fp_mode {
4298 uint32_t mode; /* as defined by FP_MODE_ constants */
4299 /* TBD */
4300};
4301
4302struct __ec_align4 ec_response_fp_mode {
4303 uint32_t mode; /* as defined by FP_MODE_ constants */
4304 /* TBD */
4305};
4306
4307/* Retrieve Fingerprint sensor information */
4308#define EC_CMD_FP_INFO 0x0403
4309
4310struct __ec_align2 ec_response_fp_info {
4311 /* Sensor identification */
4312 uint32_t vendor_id;
4313 uint32_t product_id;
4314 uint32_t model_id;
4315 uint32_t version;
4316 /* Image frame characteristics */
4317 uint32_t frame_size;
4318 uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
4319 uint16_t width;
4320 uint16_t height;
4321 uint16_t bpp;
4322};
4323
4324/* Get the last captured finger frame: TODO: will be AES-encrypted */
4325#define EC_CMD_FP_FRAME 0x0404
4326
4327struct __ec_align4 ec_params_fp_frame {
4328 uint32_t offset;
4329 uint32_t size;
4330};
4331
4332/*****************************************************************************/
4333/* Touchpad MCU commands: range 0x0500-0x05FF */
4334
4335/* Perform touchpad self test */
4336#define EC_CMD_TP_SELF_TEST 0x0500
4337
4338/* Get number of frame types, and the size of each type */
4339#define EC_CMD_TP_FRAME_INFO 0x0501
4340
4341struct __ec_align4 ec_response_tp_frame_info {
4342 uint32_t n_frames;
4343 uint32_t frame_sizes[0];
4344};
4345
4346/* Create a snapshot of current frame readings */
4347#define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
4348
4349/* Read the frame */
4350#define EC_CMD_TP_FRAME_GET 0x0503
4351
4352struct __ec_align4 ec_params_tp_frame_get {
4353 uint32_t frame_index;
4354 uint32_t offset;
4355 uint32_t size;
4356};
4357
David Hendricks1649d162016-09-16 18:13:11 -07004358/*****************************************************************************/
4359/*
4360 * Reserve a range of host commands for board-specific, experimental, or
4361 * special purpose features. These can be (re)used without updating this file.
4362 *
4363 * CAUTION: Don't go nuts with this. Shipping products should document ALL
4364 * their EC commands for easier development, testing, debugging, and support.
4365 *
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004366 * All commands MUST be #defined to be 4-digit UPPER CASE hex values
4367 * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
4368 *
David Hendricks1649d162016-09-16 18:13:11 -07004369 * In your experimental code, you may want to do something like this:
4370 *
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004371 * #define EC_CMD_MAGIC_FOO 0x0000
4372 * #define EC_CMD_MAGIC_BAR 0x0001
4373 * #define EC_CMD_MAGIC_HEY 0x0002
4374 *
4375 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
4376 * EC_VER_MASK(0);
4377 *
4378 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
4379 * EC_VER_MASK(0);
4380 *
4381 * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
4382 * EC_VER_MASK(0);
David Hendricks1649d162016-09-16 18:13:11 -07004383 */
4384#define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
4385#define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
4386
Wei-Ning Huang7b491f72017-05-05 21:43:22 +08004387/*
4388 * Given the private host command offset, calculate the true private host
4389 * command value.
4390 */
4391#define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
4392 (EC_CMD_BOARD_SPECIFIC_BASE + (command))
4393
David Hendricksb6847ac2014-08-17 17:59:24 -07004394/*****************************************************************************/
4395/*
4396 * Passthru commands
4397 *
4398 * Some platforms have sub-processors chained to each other. For example.
4399 *
4400 * AP <--> EC <--> PD MCU
4401 *
4402 * The top 2 bits of the command number are used to indicate which device the
4403 * command is intended for. Device 0 is always the device receiving the
4404 * command; other device mapping is board-specific.
4405 *
4406 * When a device receives a command to be passed to a sub-processor, it passes
4407 * it on with the device number set back to 0. This allows the sub-processor
4408 * to remain blissfully unaware of whether the command originated on the next
4409 * device up the chain, or was passed through from the AP.
4410 *
4411 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
4412 * AP sends command 0x4002 to the EC
4413 * EC sends command 0x0002 to the PD MCU
4414 * EC forwards PD MCU response back to the AP
4415 */
4416
4417/* Offset and max command number for sub-device n */
4418#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
4419#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
4420
4421/*****************************************************************************/
4422/*
4423 * Deprecated constants. These constants have been renamed for clarity. The
4424 * meaning and size has not changed. Programs that use the old names should
4425 * switch to the new names soon, as the old names may not be carried forward
4426 * forever.
4427 */
4428#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
4429#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
4430#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
4431
Wei-Ning Huang26d9cc02017-07-24 14:59:45 +08004432#endif /* !__ACPI__ */
4433
David Hendricks1649d162016-09-16 18:13:11 -07004434#endif /* __CROS_EC_EC_COMMANDS_H */