blob: 190c8f4afa026706a3befa71734c572760f6f6e9 [file] [log] [blame]
Simon Glassdeaf39e2013-02-25 14:08:36 -08001/*
2 * Host communication command constants for ChromeOS EC
3 *
4 * Copyright (C) 2012 Google, Inc
5 *
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * The ChromeOS EC multi function device is used to mux all the requests
16 * to the EC device for its multiple features: keyboard controller,
17 * battery charging and regulator control, firmware update.
18 *
19 * NOTE: This file is copied verbatim from the ChromeOS EC Open Source
20 * project in an attempt to make future updates easy to make.
21 */
22
23#ifndef __CROS_EC_COMMANDS_H
24#define __CROS_EC_COMMANDS_H
25
26/*
Bill Richardson5271db22014-04-30 10:44:08 -070027 * Current version of this protocol
Simon Glassdeaf39e2013-02-25 14:08:36 -080028 *
Bill Richardson5271db22014-04-30 10:44:08 -070029 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
30 * determined in other ways. Remove this once the kernel code no longer
31 * depends on it.
Simon Glassdeaf39e2013-02-25 14:08:36 -080032 */
Simon Glassdeaf39e2013-02-25 14:08:36 -080033#define EC_PROTO_VERSION 0x00000002
34
35/* Command version mask */
36#define EC_VER_MASK(version) (1UL << (version))
37
38/* I/O addresses for ACPI commands */
39#define EC_LPC_ADDR_ACPI_DATA 0x62
40#define EC_LPC_ADDR_ACPI_CMD 0x66
41
42/* I/O addresses for host command */
43#define EC_LPC_ADDR_HOST_DATA 0x200
44#define EC_LPC_ADDR_HOST_CMD 0x204
45
46/* I/O addresses for host command args and params */
Bill Richardson5271db22014-04-30 10:44:08 -070047/* Protocol version 2 */
48#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
49#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
50 * EC_PROTO2_MAX_PARAM_SIZE */
51/* Protocol version 3 */
52#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
53#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Simon Glassdeaf39e2013-02-25 14:08:36 -080054
Bill Richardson5271db22014-04-30 10:44:08 -070055/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
56 * and they tell the kernel that so we have to think of it as two parts. */
57#define EC_HOST_CMD_REGION0 0x800
58#define EC_HOST_CMD_REGION1 0x880
59#define EC_HOST_CMD_REGION_SIZE 0x80
Simon Glassdeaf39e2013-02-25 14:08:36 -080060
61/* EC command register bit functions */
62#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
63#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
64#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
65#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
66#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
67#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
68#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
69
70#define EC_LPC_ADDR_MEMMAP 0x900
71#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
72#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
73
74/* The offset address of each type of data in mapped memory. */
Bill Richardson5271db22014-04-30 10:44:08 -070075#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
76#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
77#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
78#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Simon Glassdeaf39e2013-02-25 14:08:36 -080079#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
80#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
81#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
82#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
83#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Bill Richardson5271db22014-04-30 10:44:08 -070084#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
85/* Unused 0x28 - 0x2f */
86#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
87/* Unused 0x31 - 0x33 */
88#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
89/* Reserve 0x38 - 0x3f for additional host event-related stuff */
90/* Battery values are all 32 bits */
Simon Glassdeaf39e2013-02-25 14:08:36 -080091#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
92#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
93#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
94#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
95#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
96#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
97#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
98#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Bill Richardson5271db22014-04-30 10:44:08 -070099/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800100#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
101#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
102#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
103#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Bill Richardson5271db22014-04-30 10:44:08 -0700104#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
105/* Unused 0x84 - 0x8f */
106#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
107/* Unused 0x91 */
108#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
109#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
110/* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
111
112
113/* Define the format of the accelerometer mapped memory status byte. */
114#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
115#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
116#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
Simon Glassdeaf39e2013-02-25 14:08:36 -0800117
118/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
119#define EC_TEMP_SENSOR_ENTRIES 16
120/*
121 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
122 *
123 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
124 */
125#define EC_TEMP_SENSOR_B_ENTRIES 8
Bill Richardson5271db22014-04-30 10:44:08 -0700126
127/* Special values for mapped temperature sensors */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800128#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
129#define EC_TEMP_SENSOR_ERROR 0xfe
130#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
131#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
132/*
133 * The offset of temperature value stored in mapped memory. This allows
134 * reporting a temperature range of 200K to 454K = -73C to 181C.
135 */
136#define EC_TEMP_SENSOR_OFFSET 200
137
Bill Richardson5271db22014-04-30 10:44:08 -0700138/*
139 * Number of ALS readings at EC_MEMMAP_ALS
140 */
141#define EC_ALS_ENTRIES 2
142
143/*
144 * The default value a temperature sensor will return when it is present but
145 * has not been read this boot. This is a reasonable number to avoid
146 * triggering alarms on the host.
147 */
148#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
149
Simon Glassdeaf39e2013-02-25 14:08:36 -0800150#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
151#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
152#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
153
154/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
155#define EC_BATT_FLAG_AC_PRESENT 0x01
156#define EC_BATT_FLAG_BATT_PRESENT 0x02
157#define EC_BATT_FLAG_DISCHARGING 0x04
158#define EC_BATT_FLAG_CHARGING 0x08
159#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
160
161/* Switch flags at EC_MEMMAP_SWITCHES */
162#define EC_SWITCH_LID_OPEN 0x01
163#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
164#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Bill Richardson5271db22014-04-30 10:44:08 -0700165/* Was recovery requested via keyboard; now unused. */
166#define EC_SWITCH_IGNORE1 0x08
Simon Glassdeaf39e2013-02-25 14:08:36 -0800167/* Recovery requested via dedicated signal (from servo board) */
168#define EC_SWITCH_DEDICATED_RECOVERY 0x10
169/* Was fake developer mode switch; now unused. Remove in next refactor. */
170#define EC_SWITCH_IGNORE0 0x20
171
172/* Host command interface flags */
173/* Host command interface supports LPC args (LPC interface only) */
174#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Bill Richardson5271db22014-04-30 10:44:08 -0700175/* Host command interface supports version 3 protocol */
176#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Simon Glassdeaf39e2013-02-25 14:08:36 -0800177
178/* Wireless switch flags */
Bill Richardson5271db22014-04-30 10:44:08 -0700179#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
180#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
181#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
182#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
183#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800184
185/*
186 * This header file is used in coreboot both in C and ACPI code. The ACPI code
187 * is pre-processed to handle constants but the ASL compiler is unable to
188 * handle actual C code so keep it separate.
189 */
190#ifndef __ACPI__
191
Bill Richardson5271db22014-04-30 10:44:08 -0700192/*
193 * Define __packed if someone hasn't beat us to it. Linux kernel style
194 * checking prefers __packed over __attribute__((packed)).
195 */
196#ifndef __packed
197#define __packed __attribute__((packed))
198#endif
199
Simon Glassdeaf39e2013-02-25 14:08:36 -0800200/* LPC command status byte masks */
201/* EC has written a byte in the data register and host hasn't read it yet */
202#define EC_LPC_STATUS_TO_HOST 0x01
203/* Host has written a command/data byte and the EC hasn't read it yet */
204#define EC_LPC_STATUS_FROM_HOST 0x02
205/* EC is processing a command */
206#define EC_LPC_STATUS_PROCESSING 0x04
207/* Last write to EC was a command, not data */
208#define EC_LPC_STATUS_LAST_CMD 0x08
209/* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
210#define EC_LPC_STATUS_BURST_MODE 0x10
211/* SCI event is pending (requesting SCI query) */
212#define EC_LPC_STATUS_SCI_PENDING 0x20
213/* SMI event is pending (requesting SMI query) */
214#define EC_LPC_STATUS_SMI_PENDING 0x40
215/* (reserved) */
216#define EC_LPC_STATUS_RESERVED 0x80
217
218/*
219 * EC is busy. This covers both the EC processing a command, and the host has
220 * written a new command but the EC hasn't picked it up yet.
221 */
222#define EC_LPC_STATUS_BUSY_MASK \
223 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
224
225/* Host command response codes */
226enum ec_status {
227 EC_RES_SUCCESS = 0,
228 EC_RES_INVALID_COMMAND = 1,
229 EC_RES_ERROR = 2,
230 EC_RES_INVALID_PARAM = 3,
231 EC_RES_ACCESS_DENIED = 4,
232 EC_RES_INVALID_RESPONSE = 5,
233 EC_RES_INVALID_VERSION = 6,
234 EC_RES_INVALID_CHECKSUM = 7,
235 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
236 EC_RES_UNAVAILABLE = 9, /* No response available */
237 EC_RES_TIMEOUT = 10, /* We got a timeout */
238 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Bill Richardson5271db22014-04-30 10:44:08 -0700239 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
240 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
241 EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800242};
243
244/*
245 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
246 * EC command uses code 0 to mean "no event pending". We explicitly specify
247 * each value in the enum listing so they won't change if we delete/insert an
248 * item or rearrange the list (it needs to be stable across platforms, not
249 * just within a single compiled instance).
250 */
251enum host_event_code {
252 EC_HOST_EVENT_LID_CLOSED = 1,
253 EC_HOST_EVENT_LID_OPEN = 2,
254 EC_HOST_EVENT_POWER_BUTTON = 3,
255 EC_HOST_EVENT_AC_CONNECTED = 4,
256 EC_HOST_EVENT_AC_DISCONNECTED = 5,
257 EC_HOST_EVENT_BATTERY_LOW = 6,
258 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
259 EC_HOST_EVENT_BATTERY = 8,
260 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
261 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
262 EC_HOST_EVENT_THERMAL = 11,
263 EC_HOST_EVENT_USB_CHARGER = 12,
264 EC_HOST_EVENT_KEY_PRESSED = 13,
265 /*
266 * EC has finished initializing the host interface. The host can check
267 * for this event following sending a EC_CMD_REBOOT_EC command to
268 * determine when the EC is ready to accept subsequent commands.
269 */
270 EC_HOST_EVENT_INTERFACE_READY = 14,
271 /* Keyboard recovery combo has been pressed */
272 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
273
274 /* Shutdown due to thermal overload */
275 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
276 /* Shutdown due to battery level too low */
277 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
278
Bill Richardson5271db22014-04-30 10:44:08 -0700279 /* Suggest that the AP throttle itself */
280 EC_HOST_EVENT_THROTTLE_START = 18,
281 /* Suggest that the AP resume normal speed */
282 EC_HOST_EVENT_THROTTLE_STOP = 19,
283
284 /* Hang detect logic detected a hang and host event timeout expired */
285 EC_HOST_EVENT_HANG_DETECT = 20,
286 /* Hang detect logic detected a hang and warm rebooted the AP */
287 EC_HOST_EVENT_HANG_REBOOT = 21,
288
Simon Glassdeaf39e2013-02-25 14:08:36 -0800289 /*
290 * The high bit of the event mask is not used as a host event code. If
291 * it reads back as set, then the entire event mask should be
292 * considered invalid by the host. This can happen when reading the
293 * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
294 * not initialized on the EC, or improperly configured on the host.
295 */
296 EC_HOST_EVENT_INVALID = 32
297};
298/* Host event mask */
299#define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
300
301/* Arguments at EC_LPC_ADDR_HOST_ARGS */
302struct ec_lpc_host_args {
303 uint8_t flags;
304 uint8_t command_version;
305 uint8_t data_size;
306 /*
307 * Checksum; sum of command + flags + command_version + data_size +
308 * all params/response data bytes.
309 */
310 uint8_t checksum;
311} __packed;
312
313/* Flags for ec_lpc_host_args.flags */
314/*
315 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
316 * params.
317 *
318 * If EC gets a command and this flag is not set, this is an old-style command.
319 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
320 * unknown length. EC must respond with an old-style response (that is,
321 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
322 */
323#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
324/*
325 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
326 *
327 * If EC responds to a command and this flag is not set, this is an old-style
328 * response. Command version is 0 and response data from EC is at
329 * EC_LPC_ADDR_OLD_PARAM with unknown length.
330 */
331#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
332
Bill Richardson5271db22014-04-30 10:44:08 -0700333/*****************************************************************************/
334/*
335 * Byte codes returned by EC over SPI interface.
336 *
337 * These can be used by the AP to debug the EC interface, and to determine
338 * when the EC is not in a state where it will ever get around to responding
339 * to the AP.
340 *
341 * Example of sequence of bytes read from EC for a current good transfer:
342 * 1. - - AP asserts chip select (CS#)
343 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
344 * 3. - - EC starts handling CS# interrupt
345 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
346 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
347 * bytes looking for EC_SPI_FRAME_START
348 * 6. - - EC finishes processing and sets up response
349 * 7. EC_SPI_FRAME_START - AP reads frame byte
350 * 8. (response packet) - AP reads response packet
351 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
352 * 10 - - AP deasserts chip select
353 * 11 - - EC processes CS# interrupt and sets up DMA for
354 * next request
355 *
356 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
357 * the following byte values:
358 * EC_SPI_OLD_READY
359 * EC_SPI_RX_READY
360 * EC_SPI_RECEIVING
361 * EC_SPI_PROCESSING
362 *
363 * Then the EC found an error in the request, or was not ready for the request
364 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
365 * because the EC is unable to tell when the AP is done sending its request.
366 */
367
368/*
369 * Framing byte which precedes a response packet from the EC. After sending a
370 * request, the AP will clock in bytes until it sees the framing byte, then
371 * clock in the response packet.
372 */
373#define EC_SPI_FRAME_START 0xec
374
375/*
376 * Padding bytes which are clocked out after the end of a response packet.
377 */
378#define EC_SPI_PAST_END 0xed
379
380/*
381 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
382 * that the AP will send a valid packet header (starting with
383 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
384 */
385#define EC_SPI_RX_READY 0xf8
386
387/*
388 * EC has started receiving the request from the AP, but hasn't started
389 * processing it yet.
390 */
391#define EC_SPI_RECEIVING 0xf9
392
393/* EC has received the entire request from the AP and is processing it. */
394#define EC_SPI_PROCESSING 0xfa
395
396/*
397 * EC received bad data from the AP, such as a packet header with an invalid
398 * length. EC will ignore all data until chip select deasserts.
399 */
400#define EC_SPI_RX_BAD_DATA 0xfb
401
402/*
403 * EC received data from the AP before it was ready. That is, the AP asserted
404 * chip select and started clocking data before the EC was ready to receive it.
405 * EC will ignore all data until chip select deasserts.
406 */
407#define EC_SPI_NOT_READY 0xfc
408
409/*
410 * EC was ready to receive a request from the AP. EC has treated the byte sent
411 * by the AP as part of a request packet, or (for old-style ECs) is processing
412 * a fully received packet but is not ready to respond yet.
413 */
414#define EC_SPI_OLD_READY 0xfd
415
416/*****************************************************************************/
417
418/*
419 * Protocol version 2 for I2C and SPI send a request this way:
420 *
421 * 0 EC_CMD_VERSION0 + (command version)
422 * 1 Command number
423 * 2 Length of params = N
424 * 3..N+2 Params, if any
425 * N+3 8-bit checksum of bytes 0..N+2
426 *
427 * The corresponding response is:
428 *
429 * 0 Result code (EC_RES_*)
430 * 1 Length of params = M
431 * 2..M+1 Params, if any
432 * M+2 8-bit checksum of bytes 0..M+1
433 */
434#define EC_PROTO2_REQUEST_HEADER_BYTES 3
435#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
436#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
437 EC_PROTO2_REQUEST_TRAILER_BYTES)
438
439#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
440#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
441#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
442 EC_PROTO2_RESPONSE_TRAILER_BYTES)
443
444/* Parameter length was limited by the LPC interface */
445#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
446
447/* Maximum request and response packet sizes for protocol version 2 */
448#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
449 EC_PROTO2_MAX_PARAM_SIZE)
450#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
451 EC_PROTO2_MAX_PARAM_SIZE)
452
453/*****************************************************************************/
454
455/*
456 * Value written to legacy command port / prefix byte to indicate protocol
457 * 3+ structs are being used. Usage is bus-dependent.
458 */
459#define EC_COMMAND_PROTOCOL_3 0xda
460
461#define EC_HOST_REQUEST_VERSION 3
462
463/* Version 3 request from host */
464struct ec_host_request {
465 /* Struct version (=3)
466 *
467 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
468 * version it doesn't know how to parse.
469 */
470 uint8_t struct_version;
471
472 /*
473 * Checksum of request and data; sum of all bytes including checksum
474 * should total to 0.
475 */
476 uint8_t checksum;
477
478 /* Command code */
479 uint16_t command;
480
481 /* Command version */
482 uint8_t command_version;
483
484 /* Unused byte in current protocol version; set to 0 */
485 uint8_t reserved;
486
487 /* Length of data which follows this header */
488 uint16_t data_len;
489} __packed;
490
491#define EC_HOST_RESPONSE_VERSION 3
492
493/* Version 3 response from EC */
494struct ec_host_response {
495 /* Struct version (=3) */
496 uint8_t struct_version;
497
498 /*
499 * Checksum of response and data; sum of all bytes including checksum
500 * should total to 0.
501 */
502 uint8_t checksum;
503
504 /* Result code (EC_RES_*) */
505 uint16_t result;
506
507 /* Length of data which follows this header */
508 uint16_t data_len;
509
510 /* Unused bytes in current protocol version; set to 0 */
511 uint16_t reserved;
512} __packed;
513
514/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -0800515/*
516 * Notes on commands:
517 *
Stephen Barber256ab952015-06-09 13:04:43 +0200518 * Each command is an 16-bit command value. Commands which take params or
Simon Glassdeaf39e2013-02-25 14:08:36 -0800519 * return response data specify structs for that data. If no struct is
520 * specified, the command does not input or output data, respectively.
521 * Parameter/response length is implicit in the structs. Some underlying
522 * communication protocols (I2C, SPI) may add length or checksum headers, but
523 * those are implementation-dependent and not defined here.
524 */
525
526/*****************************************************************************/
527/* General / test commands */
528
529/*
530 * Get protocol version, used to deal with non-backward compatible protocol
531 * changes.
532 */
533#define EC_CMD_PROTO_VERSION 0x00
534
535struct ec_response_proto_version {
536 uint32_t version;
537} __packed;
538
539/*
540 * Hello. This is a simple command to test the EC is responsive to
541 * commands.
542 */
543#define EC_CMD_HELLO 0x01
544
545struct ec_params_hello {
546 uint32_t in_data; /* Pass anything here */
547} __packed;
548
549struct ec_response_hello {
550 uint32_t out_data; /* Output will be in_data + 0x01020304 */
551} __packed;
552
553/* Get version number */
554#define EC_CMD_GET_VERSION 0x02
555
556enum ec_current_image {
557 EC_IMAGE_UNKNOWN = 0,
558 EC_IMAGE_RO,
559 EC_IMAGE_RW
560};
561
562struct ec_response_get_version {
563 /* Null-terminated version strings for RO, RW */
564 char version_string_ro[32];
565 char version_string_rw[32];
566 char reserved[32]; /* Was previously RW-B string */
567 uint32_t current_image; /* One of ec_current_image */
568} __packed;
569
570/* Read test */
571#define EC_CMD_READ_TEST 0x03
572
573struct ec_params_read_test {
574 uint32_t offset; /* Starting value for read buffer */
575 uint32_t size; /* Size to read in bytes */
576} __packed;
577
578struct ec_response_read_test {
579 uint32_t data[32];
580} __packed;
581
582/*
583 * Get build information
584 *
585 * Response is null-terminated string.
586 */
587#define EC_CMD_GET_BUILD_INFO 0x04
588
589/* Get chip info */
590#define EC_CMD_GET_CHIP_INFO 0x05
591
592struct ec_response_get_chip_info {
593 /* Null-terminated strings */
594 char vendor[32];
595 char name[32];
596 char revision[32]; /* Mask version */
597} __packed;
598
599/* Get board HW version */
600#define EC_CMD_GET_BOARD_VERSION 0x06
601
602struct ec_response_board_version {
603 uint16_t board_version; /* A monotonously incrementing number. */
604} __packed;
605
606/*
607 * Read memory-mapped data.
608 *
609 * This is an alternate interface to memory-mapped data for bus protocols
610 * which don't support direct-mapped memory - I2C, SPI, etc.
611 *
612 * Response is params.size bytes of data.
613 */
614#define EC_CMD_READ_MEMMAP 0x07
615
616struct ec_params_read_memmap {
617 uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
618 uint8_t size; /* Size to read in bytes */
619} __packed;
620
621/* Read versions supported for a command */
622#define EC_CMD_GET_CMD_VERSIONS 0x08
623
624struct ec_params_get_cmd_versions {
625 uint8_t cmd; /* Command to check */
626} __packed;
627
Nicolas Boichat0aa877c2017-05-16 17:46:48 +0200628struct ec_params_get_cmd_versions_v1 {
629 uint16_t cmd; /* Command to check */
630} __packed;
631
Simon Glassdeaf39e2013-02-25 14:08:36 -0800632struct ec_response_get_cmd_versions {
633 /*
634 * Mask of supported versions; use EC_VER_MASK() to compare with a
635 * desired version.
636 */
637 uint32_t version_mask;
638} __packed;
639
640/*
641 * Check EC communcations status (busy). This is needed on i2c/spi but not
642 * on lpc since it has its own out-of-band busy indicator.
643 *
644 * lpc must read the status from the command register. Attempting this on
645 * lpc will overwrite the args/parameter space and corrupt its data.
646 */
647#define EC_CMD_GET_COMMS_STATUS 0x09
648
649/* Avoid using ec_status which is for return values */
650enum ec_comms_status {
651 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
652};
653
654struct ec_response_get_comms_status {
655 uint32_t flags; /* Mask of enum ec_comms_status */
656} __packed;
657
Bill Richardson5271db22014-04-30 10:44:08 -0700658/* Fake a variety of responses, purely for testing purposes. */
659#define EC_CMD_TEST_PROTOCOL 0x0a
660
661/* Tell the EC what to send back to us. */
662struct ec_params_test_protocol {
663 uint32_t ec_result;
664 uint32_t ret_len;
665 uint8_t buf[32];
666} __packed;
667
668/* Here it comes... */
669struct ec_response_test_protocol {
670 uint8_t buf[32];
671} __packed;
672
673/* Get prococol information */
674#define EC_CMD_GET_PROTOCOL_INFO 0x0b
675
676/* Flags for ec_response_get_protocol_info.flags */
677/* EC_RES_IN_PROGRESS may be returned if a command is slow */
678#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
679
680struct ec_response_get_protocol_info {
681 /* Fields which exist if at least protocol version 3 supported */
682
683 /* Bitmask of protocol versions supported (1 << n means version n)*/
684 uint32_t protocol_versions;
685
686 /* Maximum request packet size, in bytes */
687 uint16_t max_request_packet_size;
688
689 /* Maximum response packet size, in bytes */
690 uint16_t max_response_packet_size;
691
692 /* Flags; see EC_PROTOCOL_INFO_* */
693 uint32_t flags;
694} __packed;
695
696
697/*****************************************************************************/
698/* Get/Set miscellaneous values */
699
700/* The upper byte of .flags tells what to do (nothing means "get") */
701#define EC_GSV_SET 0x80000000
702
703/* The lower three bytes of .flags identifies the parameter, if that has
704 meaning for an individual command. */
705#define EC_GSV_PARAM_MASK 0x00ffffff
706
707struct ec_params_get_set_value {
708 uint32_t flags;
709 uint32_t value;
710} __packed;
711
712struct ec_response_get_set_value {
713 uint32_t flags;
714 uint32_t value;
715} __packed;
716
717/* More than one command can use these structs to get/set paramters. */
718#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
719
Vincent Palatine4244eb2016-08-01 11:54:37 +0200720/*****************************************************************************/
721/* List the features supported by the firmware */
722#define EC_CMD_GET_FEATURES 0x0d
723
724/* Supported features */
725enum ec_feature_code {
726 /*
727 * This image contains a limited set of features. Another image
728 * in RW partition may support more features.
729 */
730 EC_FEATURE_LIMITED = 0,
731 /*
732 * Commands for probing/reading/writing/erasing the flash in the
733 * EC are present.
734 */
735 EC_FEATURE_FLASH = 1,
736 /*
737 * Can control the fan speed directly.
738 */
739 EC_FEATURE_PWM_FAN = 2,
740 /*
741 * Can control the intensity of the keyboard backlight.
742 */
743 EC_FEATURE_PWM_KEYB = 3,
744 /*
745 * Support Google lightbar, introduced on Pixel.
746 */
747 EC_FEATURE_LIGHTBAR = 4,
748 /* Control of LEDs */
749 EC_FEATURE_LED = 5,
750 /* Exposes an interface to control gyro and sensors.
751 * The host goes through the EC to access these sensors.
752 * In addition, the EC may provide composite sensors, like lid angle.
753 */
754 EC_FEATURE_MOTION_SENSE = 6,
755 /* The keyboard is controlled by the EC */
756 EC_FEATURE_KEYB = 7,
757 /* The AP can use part of the EC flash as persistent storage. */
758 EC_FEATURE_PSTORE = 8,
759 /* The EC monitors BIOS port 80h, and can return POST codes. */
760 EC_FEATURE_PORT80 = 9,
761 /*
762 * Thermal management: include TMP specific commands.
763 * Higher level than direct fan control.
764 */
765 EC_FEATURE_THERMAL = 10,
766 /* Can switch the screen backlight on/off */
767 EC_FEATURE_BKLIGHT_SWITCH = 11,
768 /* Can switch the wifi module on/off */
769 EC_FEATURE_WIFI_SWITCH = 12,
770 /* Monitor host events, through for example SMI or SCI */
771 EC_FEATURE_HOST_EVENTS = 13,
772 /* The EC exposes GPIO commands to control/monitor connected devices. */
773 EC_FEATURE_GPIO = 14,
774 /* The EC can send i2c messages to downstream devices. */
775 EC_FEATURE_I2C = 15,
776 /* Command to control charger are included */
777 EC_FEATURE_CHARGER = 16,
778 /* Simple battery support. */
779 EC_FEATURE_BATTERY = 17,
780 /*
781 * Support Smart battery protocol
782 * (Common Smart Battery System Interface Specification)
783 */
784 EC_FEATURE_SMART_BATTERY = 18,
785 /* EC can dectect when the host hangs. */
786 EC_FEATURE_HANG_DETECT = 19,
787 /* Report power information, for pit only */
788 EC_FEATURE_PMU = 20,
789 /* Another Cros EC device is present downstream of this one */
790 EC_FEATURE_SUB_MCU = 21,
791 /* Support USB Power delivery (PD) commands */
792 EC_FEATURE_USB_PD = 22,
793 /* Control USB multiplexer, for audio through USB port for instance. */
794 EC_FEATURE_USB_MUX = 23,
795 /* Motion Sensor code has an internal software FIFO */
796 EC_FEATURE_MOTION_SENSE_FIFO = 24,
797};
798
799#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
800#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
801struct ec_response_get_features {
802 uint32_t flags[2];
803} __packed;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800804
805/*****************************************************************************/
806/* Flash commands */
807
808/* Get flash info */
809#define EC_CMD_FLASH_INFO 0x10
810
Bill Richardson5271db22014-04-30 10:44:08 -0700811/* Version 0 returns these fields */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800812struct ec_response_flash_info {
813 /* Usable flash size, in bytes */
814 uint32_t flash_size;
815 /*
816 * Write block size. Write offset and size must be a multiple
817 * of this.
818 */
819 uint32_t write_block_size;
820 /*
821 * Erase block size. Erase offset and size must be a multiple
822 * of this.
823 */
824 uint32_t erase_block_size;
825 /*
826 * Protection block size. Protection offset and size must be a
827 * multiple of this.
828 */
829 uint32_t protect_block_size;
830} __packed;
831
Bill Richardson5271db22014-04-30 10:44:08 -0700832/* Flags for version 1+ flash info command */
833/* EC flash erases bits to 0 instead of 1 */
834#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
835
836/*
837 * Version 1 returns the same initial fields as version 0, with additional
838 * fields following.
839 *
840 * gcc anonymous structs don't seem to get along with the __packed directive;
841 * if they did we'd define the version 0 struct as a sub-struct of this one.
842 */
843struct ec_response_flash_info_1 {
844 /* Version 0 fields; see above for description */
845 uint32_t flash_size;
846 uint32_t write_block_size;
847 uint32_t erase_block_size;
848 uint32_t protect_block_size;
849
850 /* Version 1 adds these fields: */
851 /*
852 * Ideal write size in bytes. Writes will be fastest if size is
853 * exactly this and offset is a multiple of this. For example, an EC
854 * may have a write buffer which can do half-page operations if data is
855 * aligned, and a slower word-at-a-time write mode.
856 */
857 uint32_t write_ideal_size;
858
859 /* Flags; see EC_FLASH_INFO_* */
860 uint32_t flags;
861} __packed;
862
Simon Glassdeaf39e2013-02-25 14:08:36 -0800863/*
864 * Read flash
865 *
866 * Response is params.size bytes of data.
867 */
868#define EC_CMD_FLASH_READ 0x11
869
870struct ec_params_flash_read {
871 uint32_t offset; /* Byte offset to read */
872 uint32_t size; /* Size to read in bytes */
873} __packed;
874
875/* Write flash */
876#define EC_CMD_FLASH_WRITE 0x12
Bill Richardson5271db22014-04-30 10:44:08 -0700877#define EC_VER_FLASH_WRITE 1
878
879/* Version 0 of the flash command supported only 64 bytes of data */
880#define EC_FLASH_WRITE_VER0_SIZE 64
Simon Glassdeaf39e2013-02-25 14:08:36 -0800881
882struct ec_params_flash_write {
883 uint32_t offset; /* Byte offset to write */
884 uint32_t size; /* Size to write in bytes */
Bill Richardson5271db22014-04-30 10:44:08 -0700885 /* Followed by data to write */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800886} __packed;
887
888/* Erase flash */
889#define EC_CMD_FLASH_ERASE 0x13
890
891struct ec_params_flash_erase {
892 uint32_t offset; /* Byte offset to erase */
893 uint32_t size; /* Size to erase in bytes */
894} __packed;
895
896/*
897 * Get/set flash protection.
898 *
899 * If mask!=0, sets/clear the requested bits of flags. Depending on the
900 * firmware write protect GPIO, not all flags will take effect immediately;
901 * some flags require a subsequent hard reset to take effect. Check the
902 * returned flags bits to see what actually happened.
903 *
904 * If mask=0, simply returns the current flags state.
905 */
906#define EC_CMD_FLASH_PROTECT 0x15
907#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
908
909/* Flags for flash protection */
910/* RO flash code protected when the EC boots */
911#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
912/*
913 * RO flash code protected now. If this bit is set, at-boot status cannot
914 * be changed.
915 */
916#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
917/* Entire flash code protected now, until reboot. */
918#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
919/* Flash write protect GPIO is asserted now */
920#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
921/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
922#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
923/*
924 * Error - flash protection is in inconsistent state. At least one bank of
925 * flash which should be protected is not protected. Usually fixed by
926 * re-requesting the desired flags, or by a hard reset if that fails.
927 */
928#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
929/* Entile flash code protected when the EC boots */
930#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
931
932struct ec_params_flash_protect {
933 uint32_t mask; /* Bits in flags to apply */
934 uint32_t flags; /* New flags to apply */
935} __packed;
936
937struct ec_response_flash_protect {
938 /* Current value of flash protect flags */
939 uint32_t flags;
940 /*
941 * Flags which are valid on this platform. This allows the caller
942 * to distinguish between flags which aren't set vs. flags which can't
943 * be set on this platform.
944 */
945 uint32_t valid_flags;
946 /* Flags which can be changed given the current protection state */
947 uint32_t writable_flags;
948} __packed;
949
950/*
951 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
952 * write protect. These commands may be reused with version > 0.
953 */
954
955/* Get the region offset/size */
956#define EC_CMD_FLASH_REGION_INFO 0x16
957#define EC_VER_FLASH_REGION_INFO 1
958
959enum ec_flash_region {
960 /* Region which holds read-only EC image */
Bill Richardson5271db22014-04-30 10:44:08 -0700961 EC_FLASH_REGION_RO = 0,
Simon Glassdeaf39e2013-02-25 14:08:36 -0800962 /* Region which holds rewritable EC image */
963 EC_FLASH_REGION_RW,
964 /*
965 * Region which should be write-protected in the factory (a superset of
966 * EC_FLASH_REGION_RO)
967 */
968 EC_FLASH_REGION_WP_RO,
Bill Richardson5271db22014-04-30 10:44:08 -0700969 /* Number of regions */
970 EC_FLASH_REGION_COUNT,
Simon Glassdeaf39e2013-02-25 14:08:36 -0800971};
972
973struct ec_params_flash_region_info {
974 uint32_t region; /* enum ec_flash_region */
975} __packed;
976
977struct ec_response_flash_region_info {
978 uint32_t offset;
979 uint32_t size;
980} __packed;
981
982/* Read/write VbNvContext */
983#define EC_CMD_VBNV_CONTEXT 0x17
984#define EC_VER_VBNV_CONTEXT 1
985#define EC_VBNV_BLOCK_SIZE 16
986
987enum ec_vbnvcontext_op {
988 EC_VBNV_CONTEXT_OP_READ,
989 EC_VBNV_CONTEXT_OP_WRITE,
990};
991
992struct ec_params_vbnvcontext {
993 uint32_t op;
994 uint8_t block[EC_VBNV_BLOCK_SIZE];
995} __packed;
996
997struct ec_response_vbnvcontext {
998 uint8_t block[EC_VBNV_BLOCK_SIZE];
999} __packed;
1000
1001/*****************************************************************************/
1002/* PWM commands */
1003
1004/* Get fan target RPM */
1005#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1006
1007struct ec_response_pwm_get_fan_rpm {
1008 uint32_t rpm;
1009} __packed;
1010
1011/* Set target fan RPM */
1012#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1013
1014struct ec_params_pwm_set_fan_target_rpm {
1015 uint32_t rpm;
1016} __packed;
1017
1018/* Get keyboard backlight */
1019#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1020
1021struct ec_response_pwm_get_keyboard_backlight {
1022 uint8_t percent;
1023 uint8_t enabled;
1024} __packed;
1025
1026/* Set keyboard backlight */
1027#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1028
1029struct ec_params_pwm_set_keyboard_backlight {
1030 uint8_t percent;
1031} __packed;
1032
1033/* Set target fan PWM duty cycle */
1034#define EC_CMD_PWM_SET_FAN_DUTY 0x24
1035
1036struct ec_params_pwm_set_fan_duty {
1037 uint32_t percent;
1038} __packed;
1039
Brian Norris2b66bd62016-07-15 16:28:42 -07001040#define EC_CMD_PWM_SET_DUTY 0x25
1041/* 16 bit duty cycle, 0xffff = 100% */
1042#define EC_PWM_MAX_DUTY 0xffff
1043
1044enum ec_pwm_type {
1045 /* All types, indexed by board-specific enum pwm_channel */
1046 EC_PWM_TYPE_GENERIC = 0,
1047 /* Keyboard backlight */
1048 EC_PWM_TYPE_KB_LIGHT,
1049 /* Display backlight */
1050 EC_PWM_TYPE_DISPLAY_LIGHT,
1051 EC_PWM_TYPE_COUNT,
1052};
1053
1054struct ec_params_pwm_set_duty {
1055 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1056 uint8_t pwm_type; /* ec_pwm_type */
1057 uint8_t index; /* Type-specific index, or 0 if unique */
1058} __packed;
1059
1060#define EC_CMD_PWM_GET_DUTY 0x26
1061
1062struct ec_params_pwm_get_duty {
1063 uint8_t pwm_type; /* ec_pwm_type */
1064 uint8_t index; /* Type-specific index, or 0 if unique */
1065} __packed;
1066
1067struct ec_response_pwm_get_duty {
1068 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1069} __packed;
1070
Simon Glassdeaf39e2013-02-25 14:08:36 -08001071/*****************************************************************************/
1072/*
1073 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1074 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1075 * into a subcommand. We'll make separate structs for subcommands with
1076 * different input args, so that we know how much to expect.
1077 */
1078#define EC_CMD_LIGHTBAR_CMD 0x28
1079
1080struct rgb_s {
1081 uint8_t r, g, b;
1082};
1083
1084#define LB_BATTERY_LEVELS 4
1085/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
1086 * host command, but the alignment is the same regardless. Keep it that way.
1087 */
Stephen Barber256ab952015-06-09 13:04:43 +02001088struct lightbar_params_v0 {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001089 /* Timing */
Bill Richardson5271db22014-04-30 10:44:08 -07001090 int32_t google_ramp_up;
1091 int32_t google_ramp_down;
1092 int32_t s3s0_ramp_up;
1093 int32_t s0_tick_delay[2]; /* AC=0/1 */
1094 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1095 int32_t s0s3_ramp_down;
1096 int32_t s3_sleep_for;
1097 int32_t s3_ramp_up;
1098 int32_t s3_ramp_down;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001099
1100 /* Oscillation */
1101 uint8_t new_s0;
1102 uint8_t osc_min[2]; /* AC=0/1 */
1103 uint8_t osc_max[2]; /* AC=0/1 */
1104 uint8_t w_ofs[2]; /* AC=0/1 */
1105
1106 /* Brightness limits based on the backlight and AC. */
1107 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1108 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1109 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1110
1111 /* Battery level thresholds */
1112 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1113
1114 /* Map [AC][battery_level] to color index */
1115 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1116 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1117
1118 /* Color palette */
1119 struct rgb_s color[8]; /* 0-3 are Google colors */
1120} __packed;
1121
Stephen Barber256ab952015-06-09 13:04:43 +02001122struct lightbar_params_v1 {
1123 /* Timing */
1124 int32_t google_ramp_up;
1125 int32_t google_ramp_down;
1126 int32_t s3s0_ramp_up;
1127 int32_t s0_tick_delay[2]; /* AC=0/1 */
1128 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1129 int32_t s0s3_ramp_down;
1130 int32_t s3_sleep_for;
1131 int32_t s3_ramp_up;
1132 int32_t s3_ramp_down;
1133 int32_t tap_tick_delay;
1134 int32_t tap_display_time;
1135
1136 /* Tap-for-battery params */
1137 uint8_t tap_pct_red;
1138 uint8_t tap_pct_green;
1139 uint8_t tap_seg_min_on;
1140 uint8_t tap_seg_max_on;
1141 uint8_t tap_seg_osc;
1142 uint8_t tap_idx[3];
1143
1144 /* Oscillation */
1145 uint8_t osc_min[2]; /* AC=0/1 */
1146 uint8_t osc_max[2]; /* AC=0/1 */
1147 uint8_t w_ofs[2]; /* AC=0/1 */
1148
1149 /* Brightness limits based on the backlight and AC. */
1150 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1151 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1152 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1153
1154 /* Battery level thresholds */
1155 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1156
1157 /* Map [AC][battery_level] to color index */
1158 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1159 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1160
1161 /* Color palette */
1162 struct rgb_s color[8]; /* 0-3 are Google colors */
1163} __packed;
1164
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001165/* Lightbar program */
1166#define EC_LB_PROG_LEN 192
1167struct lightbar_program {
1168 uint8_t size;
1169 uint8_t data[EC_LB_PROG_LEN];
1170};
1171
Simon Glassdeaf39e2013-02-25 14:08:36 -08001172struct ec_params_lightbar {
1173 uint8_t cmd; /* Command (see enum lightbar_command) */
1174 union {
1175 struct {
1176 /* no args */
Stephen Barber256ab952015-06-09 13:04:43 +02001177 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
Eric Caruso405c8432017-05-16 17:46:48 +02001178 version, get_brightness, get_demo, suspend, resume;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001179
Stephen Barber256ab952015-06-09 13:04:43 +02001180 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001181 uint8_t num;
Stephen Barber256ab952015-06-09 13:04:43 +02001182 } set_brightness, seq, demo;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001183
Stephen Barber256ab952015-06-09 13:04:43 +02001184 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001185 uint8_t ctrl, reg, value;
1186 } reg;
1187
Stephen Barber256ab952015-06-09 13:04:43 +02001188 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001189 uint8_t led, red, green, blue;
Stephen Barber256ab952015-06-09 13:04:43 +02001190 } set_rgb;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001191
Stephen Barber256ab952015-06-09 13:04:43 +02001192 struct {
1193 uint8_t led;
1194 } get_rgb;
1195
Eric Caruso405c8432017-05-16 17:46:48 +02001196 struct {
1197 uint8_t enable;
1198 } manual_suspend_ctrl;
1199
Stephen Barber256ab952015-06-09 13:04:43 +02001200 struct lightbar_params_v0 set_params_v0;
1201 struct lightbar_params_v1 set_params_v1;
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001202 struct lightbar_program set_program;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001203 };
1204} __packed;
1205
1206struct ec_response_lightbar {
1207 union {
Stephen Barber256ab952015-06-09 13:04:43 +02001208 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001209 struct {
1210 uint8_t reg;
1211 uint8_t ic0;
1212 uint8_t ic1;
1213 } vals[23];
1214 } dump;
1215
Stephen Barber256ab952015-06-09 13:04:43 +02001216 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001217 uint8_t num;
Stephen Barber256ab952015-06-09 13:04:43 +02001218 } get_seq, get_brightness, get_demo;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001219
Stephen Barber256ab952015-06-09 13:04:43 +02001220 struct lightbar_params_v0 get_params_v0;
1221 struct lightbar_params_v1 get_params_v1;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001222
Stephen Barber256ab952015-06-09 13:04:43 +02001223 struct {
Bill Richardson5271db22014-04-30 10:44:08 -07001224 uint32_t num;
1225 uint32_t flags;
1226 } version;
1227
Simon Glassdeaf39e2013-02-25 14:08:36 -08001228 struct {
Stephen Barber256ab952015-06-09 13:04:43 +02001229 uint8_t red, green, blue;
1230 } get_rgb;
1231
1232 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001233 /* no return params */
Stephen Barber256ab952015-06-09 13:04:43 +02001234 } off, on, init, set_brightness, seq, reg, set_rgb,
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001235 demo, set_params_v0, set_params_v1,
Eric Caruso405c8432017-05-16 17:46:48 +02001236 set_program, manual_suspend_ctrl, suspend, resume;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001237 };
1238} __packed;
1239
1240/* Lightbar commands */
1241enum lightbar_command {
1242 LIGHTBAR_CMD_DUMP = 0,
1243 LIGHTBAR_CMD_OFF = 1,
1244 LIGHTBAR_CMD_ON = 2,
1245 LIGHTBAR_CMD_INIT = 3,
Stephen Barber256ab952015-06-09 13:04:43 +02001246 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001247 LIGHTBAR_CMD_SEQ = 5,
1248 LIGHTBAR_CMD_REG = 6,
Stephen Barber256ab952015-06-09 13:04:43 +02001249 LIGHTBAR_CMD_SET_RGB = 7,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001250 LIGHTBAR_CMD_GET_SEQ = 8,
1251 LIGHTBAR_CMD_DEMO = 9,
Stephen Barber256ab952015-06-09 13:04:43 +02001252 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1253 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Bill Richardson5271db22014-04-30 10:44:08 -07001254 LIGHTBAR_CMD_VERSION = 12,
Stephen Barber256ab952015-06-09 13:04:43 +02001255 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1256 LIGHTBAR_CMD_GET_RGB = 14,
1257 LIGHTBAR_CMD_GET_DEMO = 15,
1258 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1259 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001260 LIGHTBAR_CMD_SET_PROGRAM = 18,
Eric Caruso405c8432017-05-16 17:46:48 +02001261 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1262 LIGHTBAR_CMD_SUSPEND = 20,
1263 LIGHTBAR_CMD_RESUME = 21,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001264 LIGHTBAR_NUM_CMDS
1265};
1266
1267/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001268/* LED control commands */
1269
1270#define EC_CMD_LED_CONTROL 0x29
1271
1272enum ec_led_id {
1273 /* LED to indicate battery state of charge */
1274 EC_LED_ID_BATTERY_LED = 0,
1275 /*
1276 * LED to indicate system power state (on or in suspend).
1277 * May be on power button or on C-panel.
1278 */
1279 EC_LED_ID_POWER_LED,
1280 /* LED on power adapter or its plug */
1281 EC_LED_ID_ADAPTER_LED,
1282
1283 EC_LED_ID_COUNT
1284};
1285
1286/* LED control flags */
1287#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1288#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1289
1290enum ec_led_colors {
1291 EC_LED_COLOR_RED = 0,
1292 EC_LED_COLOR_GREEN,
1293 EC_LED_COLOR_BLUE,
1294 EC_LED_COLOR_YELLOW,
1295 EC_LED_COLOR_WHITE,
1296
1297 EC_LED_COLOR_COUNT
1298};
1299
1300struct ec_params_led_control {
1301 uint8_t led_id; /* Which LED to control */
1302 uint8_t flags; /* Control flags */
1303
1304 uint8_t brightness[EC_LED_COLOR_COUNT];
1305} __packed;
1306
1307struct ec_response_led_control {
1308 /*
1309 * Available brightness value range.
1310 *
1311 * Range 0 means color channel not present.
1312 * Range 1 means on/off control.
1313 * Other values means the LED is control by PWM.
1314 */
1315 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1316} __packed;
1317
1318/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08001319/* Verified boot commands */
1320
1321/*
1322 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1323 * reused for other purposes with version > 0.
1324 */
1325
1326/* Verified boot hash command */
1327#define EC_CMD_VBOOT_HASH 0x2A
1328
1329struct ec_params_vboot_hash {
1330 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1331 uint8_t hash_type; /* enum ec_vboot_hash_type */
1332 uint8_t nonce_size; /* Nonce size; may be 0 */
1333 uint8_t reserved0; /* Reserved; set 0 */
1334 uint32_t offset; /* Offset in flash to hash */
1335 uint32_t size; /* Number of bytes to hash */
1336 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1337} __packed;
1338
1339struct ec_response_vboot_hash {
1340 uint8_t status; /* enum ec_vboot_hash_status */
1341 uint8_t hash_type; /* enum ec_vboot_hash_type */
1342 uint8_t digest_size; /* Size of hash digest in bytes */
1343 uint8_t reserved0; /* Ignore; will be 0 */
1344 uint32_t offset; /* Offset in flash which was hashed */
1345 uint32_t size; /* Number of bytes hashed */
1346 uint8_t hash_digest[64]; /* Hash digest data */
1347} __packed;
1348
1349enum ec_vboot_hash_cmd {
1350 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1351 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1352 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1353 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1354};
1355
1356enum ec_vboot_hash_type {
1357 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1358};
1359
1360enum ec_vboot_hash_status {
1361 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1362 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1363 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1364};
1365
1366/*
1367 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1368 * If one of these is specified, the EC will automatically update offset and
1369 * size to the correct values for the specified image (RO or RW).
1370 */
1371#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1372#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1373
1374/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001375/*
1376 * Motion sense commands. We'll make separate structs for sub-commands with
1377 * different input args, so that we know how much to expect.
1378 */
1379#define EC_CMD_MOTION_SENSE_CMD 0x2B
1380
1381/* Motion sense commands */
1382enum motionsense_command {
1383 /*
1384 * Dump command returns all motion sensor data including motion sense
1385 * module flags and individual sensor flags.
1386 */
1387 MOTIONSENSE_CMD_DUMP = 0,
1388
1389 /*
1390 * Info command returns data describing the details of a given sensor,
1391 * including enum motionsensor_type, enum motionsensor_location, and
1392 * enum motionsensor_chip.
1393 */
1394 MOTIONSENSE_CMD_INFO = 1,
1395
1396 /*
1397 * EC Rate command is a setter/getter command for the EC sampling rate
1398 * of all motion sensors in milliseconds.
1399 */
1400 MOTIONSENSE_CMD_EC_RATE = 2,
1401
1402 /*
1403 * Sensor ODR command is a setter/getter command for the output data
1404 * rate of a specific motion sensor in millihertz.
1405 */
1406 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1407
1408 /*
1409 * Sensor range command is a setter/getter command for the range of
1410 * a specified motion sensor in +/-G's or +/- deg/s.
1411 */
1412 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1413
1414 /*
1415 * Setter/getter command for the keyboard wake angle. When the lid
1416 * angle is greater than this value, keyboard wake is disabled in S3,
1417 * and when the lid angle goes less than this value, keyboard wake is
1418 * enabled. Note, the lid angle measurement is an approximate,
1419 * un-calibrated value, hence the wake angle isn't exact.
1420 */
1421 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1422
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001423 /*
1424 * Returns a single sensor data.
1425 */
1426 MOTIONSENSE_CMD_DATA = 6,
1427
1428 /*
1429 * Perform low level calibration.. On sensors that support it, ask to
1430 * do offset calibration.
1431 */
1432 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1433
1434 /*
1435 * Sensor Offset command is a setter/getter command for the offset used
1436 * for calibration. The offsets can be calculated by the host, or via
1437 * PERFORM_CALIB command.
1438 */
1439 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1440
Bill Richardson5271db22014-04-30 10:44:08 -07001441 /* Number of motionsense sub-commands. */
1442 MOTIONSENSE_NUM_CMDS
1443};
1444
1445enum motionsensor_id {
1446 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1447 EC_MOTION_SENSOR_ACCEL_LID = 1,
1448 EC_MOTION_SENSOR_GYRO = 2,
1449
1450 /*
1451 * Note, if more sensors are added and this count changes, the padding
1452 * in ec_response_motion_sense dump command must be modified.
1453 */
1454 EC_MOTION_SENSOR_COUNT = 3
1455};
1456
1457/* List of motion sensor types. */
1458enum motionsensor_type {
1459 MOTIONSENSE_TYPE_ACCEL = 0,
1460 MOTIONSENSE_TYPE_GYRO = 1,
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001461 MOTIONSENSE_TYPE_MAG = 2,
1462 MOTIONSENSE_TYPE_PROX = 3,
1463 MOTIONSENSE_TYPE_LIGHT = 4,
1464 MOTIONSENSE_TYPE_ACTIVITY = 5,
Gwendal Grignoud7322482017-01-24 14:41:41 +01001465 MOTIONSENSE_TYPE_BARO = 6,
1466 MOTIONSENSE_TYPE_MAX,
Bill Richardson5271db22014-04-30 10:44:08 -07001467};
1468
1469/* List of motion sensor locations. */
1470enum motionsensor_location {
1471 MOTIONSENSE_LOC_BASE = 0,
1472 MOTIONSENSE_LOC_LID = 1,
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001473 MOTIONSENSE_LOC_MAX,
Bill Richardson5271db22014-04-30 10:44:08 -07001474};
1475
1476/* List of motion sensor chips. */
1477enum motionsensor_chip {
1478 MOTIONSENSE_CHIP_KXCJ9 = 0,
1479};
1480
1481/* Module flag masks used for the dump sub-command. */
1482#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1483
1484/* Sensor flag masks used for the dump sub-command. */
1485#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1486
1487/*
1488 * Send this value for the data element to only perform a read. If you
1489 * send any other value, the EC will interpret it as data to set and will
1490 * return the actual value set.
1491 */
1492#define EC_MOTION_SENSE_NO_VALUE -1
1493
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001494#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1495
1496/* Set Calibration information */
1497#define MOTION_SENSE_SET_OFFSET 1
1498
1499struct ec_response_motion_sensor_data {
1500 /* Flags for each sensor. */
1501 uint8_t flags;
1502 /* Sensor number the data comes from */
1503 uint8_t sensor_num;
1504 /* Each sensor is up to 3-axis. */
1505 union {
1506 int16_t data[3];
1507 struct {
1508 uint16_t rsvd;
1509 uint32_t timestamp;
1510 } __packed;
1511 struct {
1512 uint8_t activity; /* motionsensor_activity */
1513 uint8_t state;
1514 int16_t add_info[2];
1515 };
1516 };
1517} __packed;
1518
Bill Richardson5271db22014-04-30 10:44:08 -07001519struct ec_params_motion_sense {
1520 uint8_t cmd;
1521 union {
1522 /* Used for MOTIONSENSE_CMD_DUMP. */
1523 struct {
1524 /* no args */
1525 } dump;
1526
1527 /*
1528 * Used for MOTIONSENSE_CMD_EC_RATE and
1529 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1530 */
1531 struct {
1532 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1533 int16_t data;
1534 } ec_rate, kb_wake_angle;
1535
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001536 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1537 struct {
1538 uint8_t sensor_num;
1539
1540 /*
1541 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1542 * the calibration information in the EC.
1543 * If unset, just retrieve calibration information.
1544 */
1545 uint16_t flags;
1546
1547 /*
1548 * Temperature at calibration, in units of 0.01 C
1549 * 0x8000: invalid / unknown.
1550 * 0x0: 0C
1551 * 0x7fff: +327.67C
1552 */
1553 int16_t temp;
1554
1555 /*
1556 * Offset for calibration.
1557 * Unit:
1558 * Accelerometer: 1/1024 g
1559 * Gyro: 1/1024 deg/s
1560 * Compass: 1/16 uT
1561 */
1562 int16_t offset[3];
1563 } __packed sensor_offset;
1564
Bill Richardson5271db22014-04-30 10:44:08 -07001565 /* Used for MOTIONSENSE_CMD_INFO. */
1566 struct {
Bill Richardson5271db22014-04-30 10:44:08 -07001567 uint8_t sensor_num;
1568 } info;
1569
1570 /*
1571 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1572 * MOTIONSENSE_CMD_SENSOR_RANGE.
1573 */
1574 struct {
1575 /* Should be element of enum motionsensor_id. */
1576 uint8_t sensor_num;
1577
1578 /* Rounding flag, true for round-up, false for down. */
1579 uint8_t roundup;
1580
1581 uint16_t reserved;
1582
1583 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1584 int32_t data;
1585 } sensor_odr, sensor_range;
1586 };
1587} __packed;
1588
1589struct ec_response_motion_sense {
1590 union {
1591 /* Used for MOTIONSENSE_CMD_DUMP. */
1592 struct {
1593 /* Flags representing the motion sensor module. */
1594 uint8_t module_flags;
1595
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001596 /* Number of sensors managed directly by the EC. */
1597 uint8_t sensor_count;
Bill Richardson5271db22014-04-30 10:44:08 -07001598
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001599 /*
1600 * Sensor data is truncated if response_max is too small
1601 * for holding all the data.
1602 */
1603 struct ec_response_motion_sensor_data sensor[0];
Bill Richardson5271db22014-04-30 10:44:08 -07001604 } dump;
1605
1606 /* Used for MOTIONSENSE_CMD_INFO. */
1607 struct {
1608 /* Should be element of enum motionsensor_type. */
1609 uint8_t type;
1610
1611 /* Should be element of enum motionsensor_location. */
1612 uint8_t location;
1613
1614 /* Should be element of enum motionsensor_chip. */
1615 uint8_t chip;
1616 } info;
1617
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001618 /* Used for MOTIONSENSE_CMD_DATA */
1619 struct ec_response_motion_sensor_data data;
1620
Bill Richardson5271db22014-04-30 10:44:08 -07001621 /*
1622 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1623 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1624 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1625 */
1626 struct {
1627 /* Current value of the parameter queried. */
1628 int32_t ret;
1629 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001630
1631 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1632 struct {
1633 int16_t temp;
1634 int16_t offset[3];
1635 } sensor_offset, perform_calib;
Bill Richardson5271db22014-04-30 10:44:08 -07001636 };
1637} __packed;
1638
1639/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08001640/* USB charging control commands */
1641
1642/* Set USB port charging mode */
1643#define EC_CMD_USB_CHARGE_SET_MODE 0x30
1644
1645struct ec_params_usb_charge_set_mode {
1646 uint8_t usb_port_id;
1647 uint8_t mode;
1648} __packed;
1649
1650/*****************************************************************************/
1651/* Persistent storage for host */
1652
1653/* Maximum bytes that can be read/written in a single command */
1654#define EC_PSTORE_SIZE_MAX 64
1655
1656/* Get persistent storage info */
1657#define EC_CMD_PSTORE_INFO 0x40
1658
1659struct ec_response_pstore_info {
1660 /* Persistent storage size, in bytes */
1661 uint32_t pstore_size;
1662 /* Access size; read/write offset and size must be a multiple of this */
1663 uint32_t access_size;
1664} __packed;
1665
1666/*
1667 * Read persistent storage
1668 *
1669 * Response is params.size bytes of data.
1670 */
1671#define EC_CMD_PSTORE_READ 0x41
1672
1673struct ec_params_pstore_read {
1674 uint32_t offset; /* Byte offset to read */
1675 uint32_t size; /* Size to read in bytes */
1676} __packed;
1677
1678/* Write persistent storage */
1679#define EC_CMD_PSTORE_WRITE 0x42
1680
1681struct ec_params_pstore_write {
1682 uint32_t offset; /* Byte offset to write */
1683 uint32_t size; /* Size to write in bytes */
1684 uint8_t data[EC_PSTORE_SIZE_MAX];
1685} __packed;
1686
1687/*****************************************************************************/
1688/* Real-time clock */
1689
1690/* RTC params and response structures */
1691struct ec_params_rtc {
1692 uint32_t time;
1693} __packed;
1694
1695struct ec_response_rtc {
1696 uint32_t time;
1697} __packed;
1698
1699/* These use ec_response_rtc */
1700#define EC_CMD_RTC_GET_VALUE 0x44
1701#define EC_CMD_RTC_GET_ALARM 0x45
1702
1703/* These all use ec_params_rtc */
1704#define EC_CMD_RTC_SET_VALUE 0x46
1705#define EC_CMD_RTC_SET_ALARM 0x47
1706
1707/*****************************************************************************/
1708/* Port80 log access */
1709
Stephen Barber256ab952015-06-09 13:04:43 +02001710/* Maximum entries that can be read/written in a single command */
1711#define EC_PORT80_SIZE_MAX 32
1712
Simon Glassdeaf39e2013-02-25 14:08:36 -08001713/* Get last port80 code from previous boot */
1714#define EC_CMD_PORT80_LAST_BOOT 0x48
Stephen Barber256ab952015-06-09 13:04:43 +02001715#define EC_CMD_PORT80_READ 0x48
1716
1717enum ec_port80_subcmd {
1718 EC_PORT80_GET_INFO = 0,
1719 EC_PORT80_READ_BUFFER,
1720};
1721
1722struct ec_params_port80_read {
1723 uint16_t subcmd;
1724 union {
1725 struct {
1726 uint32_t offset;
1727 uint32_t num_entries;
1728 } read_buffer;
1729 };
1730} __packed;
1731
1732struct ec_response_port80_read {
1733 union {
1734 struct {
1735 uint32_t writes;
1736 uint32_t history_size;
1737 uint32_t last_boot;
1738 } get_info;
1739 struct {
1740 uint16_t codes[EC_PORT80_SIZE_MAX];
1741 } data;
1742 };
1743} __packed;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001744
1745struct ec_response_port80_last_boot {
1746 uint16_t code;
1747} __packed;
1748
1749/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001750/* Thermal engine commands. Note that there are two implementations. We'll
1751 * reuse the command number, but the data and behavior is incompatible.
1752 * Version 0 is what originally shipped on Link.
1753 * Version 1 separates the CPU thermal limits from the fan control.
1754 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001755
Simon Glassdeaf39e2013-02-25 14:08:36 -08001756#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
Bill Richardson5271db22014-04-30 10:44:08 -07001757#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
Simon Glassdeaf39e2013-02-25 14:08:36 -08001758
Bill Richardson5271db22014-04-30 10:44:08 -07001759/* The version 0 structs are opaque. You have to know what they are for
1760 * the get/set commands to make any sense.
1761 */
1762
1763/* Version 0 - set */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001764struct ec_params_thermal_set_threshold {
1765 uint8_t sensor_type;
1766 uint8_t threshold_id;
1767 uint16_t value;
1768} __packed;
1769
Bill Richardson5271db22014-04-30 10:44:08 -07001770/* Version 0 - get */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001771struct ec_params_thermal_get_threshold {
1772 uint8_t sensor_type;
1773 uint8_t threshold_id;
1774} __packed;
1775
1776struct ec_response_thermal_get_threshold {
1777 uint16_t value;
1778} __packed;
1779
Bill Richardson5271db22014-04-30 10:44:08 -07001780
1781/* The version 1 structs are visible. */
1782enum ec_temp_thresholds {
1783 EC_TEMP_THRESH_WARN = 0,
1784 EC_TEMP_THRESH_HIGH,
1785 EC_TEMP_THRESH_HALT,
1786
1787 EC_TEMP_THRESH_COUNT
1788};
1789
1790/* Thermal configuration for one temperature sensor. Temps are in degrees K.
1791 * Zero values will be silently ignored by the thermal task.
1792 */
1793struct ec_thermal_config {
1794 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1795 uint32_t temp_fan_off; /* no active cooling needed */
1796 uint32_t temp_fan_max; /* max active cooling needed */
1797} __packed;
1798
1799/* Version 1 - get config for one sensor. */
1800struct ec_params_thermal_get_threshold_v1 {
1801 uint32_t sensor_num;
1802} __packed;
1803/* This returns a struct ec_thermal_config */
1804
1805/* Version 1 - set config for one sensor.
1806 * Use read-modify-write for best results! */
1807struct ec_params_thermal_set_threshold_v1 {
1808 uint32_t sensor_num;
1809 struct ec_thermal_config cfg;
1810} __packed;
1811/* This returns no data */
1812
1813/****************************************************************************/
1814
Simon Glassdeaf39e2013-02-25 14:08:36 -08001815/* Toggle automatic fan control */
1816#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1817
1818/* Get TMP006 calibration data */
1819#define EC_CMD_TMP006_GET_CALIBRATION 0x53
1820
1821struct ec_params_tmp006_get_calibration {
1822 uint8_t index;
1823} __packed;
1824
1825struct ec_response_tmp006_get_calibration {
1826 float s0;
1827 float b0;
1828 float b1;
1829 float b2;
1830} __packed;
1831
1832/* Set TMP006 calibration data */
1833#define EC_CMD_TMP006_SET_CALIBRATION 0x54
1834
1835struct ec_params_tmp006_set_calibration {
1836 uint8_t index;
1837 uint8_t reserved[3]; /* Reserved; set 0 */
1838 float s0;
1839 float b0;
1840 float b1;
1841 float b2;
1842} __packed;
1843
Bill Richardson5271db22014-04-30 10:44:08 -07001844/* Read raw TMP006 data */
1845#define EC_CMD_TMP006_GET_RAW 0x55
1846
1847struct ec_params_tmp006_get_raw {
1848 uint8_t index;
1849} __packed;
1850
1851struct ec_response_tmp006_get_raw {
1852 int32_t t; /* In 1/100 K */
1853 int32_t v; /* In nV */
1854};
1855
Simon Glassdeaf39e2013-02-25 14:08:36 -08001856/*****************************************************************************/
1857/* MKBP - Matrix KeyBoard Protocol */
1858
1859/*
1860 * Read key state
1861 *
1862 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1863 * expected response size.
Douglas Andersonb44c4d32017-01-20 11:14:14 +01001864 *
1865 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
1866 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1867 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Simon Glassdeaf39e2013-02-25 14:08:36 -08001868 */
1869#define EC_CMD_MKBP_STATE 0x60
1870
Douglas Andersonb44c4d32017-01-20 11:14:14 +01001871/*
1872 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
1873 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001874#define EC_CMD_MKBP_INFO 0x61
1875
1876struct ec_response_mkbp_info {
1877 uint32_t rows;
1878 uint32_t cols;
Douglas Andersonb44c4d32017-01-20 11:14:14 +01001879 /* Formerly "switches", which was 0. */
1880 uint8_t reserved;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001881} __packed;
1882
Douglas Andersonb44c4d32017-01-20 11:14:14 +01001883struct ec_params_mkbp_info {
1884 uint8_t info_type;
1885 uint8_t event_type;
1886} __packed;
1887
1888enum ec_mkbp_info_type {
1889 /*
1890 * Info about the keyboard matrix: number of rows and columns.
1891 *
1892 * Returns struct ec_response_mkbp_info.
1893 */
1894 EC_MKBP_INFO_KBD = 0,
1895
1896 /*
1897 * For buttons and switches, info about which specifically are
1898 * supported. event_type must be set to one of the values in enum
1899 * ec_mkbp_event.
1900 *
1901 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
1902 * bitmask indicating which buttons or switches are present. See the
1903 * bit inidices below.
1904 */
1905 EC_MKBP_INFO_SUPPORTED = 1,
1906
1907 /*
1908 * Instantaneous state of buttons and switches.
1909 *
1910 * event_type must be set to one of the values in enum ec_mkbp_event.
1911 *
1912 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
1913 * indicating the current state of the keyboard matrix.
1914 *
1915 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
1916 * event state.
1917 *
1918 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
1919 * state of supported buttons.
1920 *
1921 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
1922 * state of supported switches.
1923 */
1924 EC_MKBP_INFO_CURRENT = 2,
1925};
1926
Simon Glassdeaf39e2013-02-25 14:08:36 -08001927/* Simulate key press */
1928#define EC_CMD_MKBP_SIMULATE_KEY 0x62
1929
1930struct ec_params_mkbp_simulate_key {
1931 uint8_t col;
1932 uint8_t row;
1933 uint8_t pressed;
1934} __packed;
1935
1936/* Configure keyboard scanning */
1937#define EC_CMD_MKBP_SET_CONFIG 0x64
1938#define EC_CMD_MKBP_GET_CONFIG 0x65
1939
1940/* flags */
1941enum mkbp_config_flags {
1942 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
1943};
1944
1945enum mkbp_config_valid {
1946 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
1947 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
1948 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
1949 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
1950 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
1951 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
1952 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
1953};
1954
1955/* Configuration for our key scanning algorithm */
1956struct ec_mkbp_config {
1957 uint32_t valid_mask; /* valid fields */
1958 uint8_t flags; /* some flags (enum mkbp_config_flags) */
1959 uint8_t valid_flags; /* which flags are valid */
1960 uint16_t scan_period_us; /* period between start of scans */
1961 /* revert to interrupt mode after no activity for this long */
1962 uint32_t poll_timeout_us;
1963 /*
1964 * minimum post-scan relax time. Once we finish a scan we check
1965 * the time until we are due to start the next one. If this time is
1966 * shorter this field, we use this instead.
1967 */
1968 uint16_t min_post_scan_delay_us;
1969 /* delay between setting up output and waiting for it to settle */
1970 uint16_t output_settle_us;
1971 uint16_t debounce_down_us; /* time for debounce on key down */
1972 uint16_t debounce_up_us; /* time for debounce on key up */
1973 /* maximum depth to allow for fifo (0 = no keyscan output) */
1974 uint8_t fifo_max_depth;
1975} __packed;
1976
1977struct ec_params_mkbp_set_config {
1978 struct ec_mkbp_config config;
1979} __packed;
1980
1981struct ec_response_mkbp_get_config {
1982 struct ec_mkbp_config config;
1983} __packed;
1984
1985/* Run the key scan emulation */
1986#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
1987
1988enum ec_keyscan_seq_cmd {
1989 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
1990 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
1991 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
1992 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
1993 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
1994};
1995
1996enum ec_collect_flags {
1997 /*
1998 * Indicates this scan was processed by the EC. Due to timing, some
1999 * scans may be skipped.
2000 */
2001 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2002};
2003
2004struct ec_collect_item {
2005 uint8_t flags; /* some flags (enum ec_collect_flags) */
2006};
2007
2008struct ec_params_keyscan_seq_ctrl {
2009 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2010 union {
2011 struct {
2012 uint8_t active; /* still active */
2013 uint8_t num_items; /* number of items */
2014 /* Current item being presented */
2015 uint8_t cur_item;
2016 } status;
2017 struct {
2018 /*
2019 * Absolute time for this scan, measured from the
2020 * start of the sequence.
2021 */
2022 uint32_t time_us;
2023 uint8_t scan[0]; /* keyscan data */
2024 } add;
2025 struct {
2026 uint8_t start_item; /* First item to return */
2027 uint8_t num_items; /* Number of items to return */
2028 } collect;
2029 };
2030} __packed;
2031
2032struct ec_result_keyscan_seq_ctrl {
2033 union {
2034 struct {
2035 uint8_t num_items; /* Number of items */
2036 /* Data for each item */
2037 struct ec_collect_item item[0];
2038 } collect;
2039 };
2040} __packed;
2041
Vic Yang6f1d9122016-08-10 19:05:24 +02002042/*
2043 * Command for retrieving the next pending MKBP event from the EC device
2044 *
2045 * The device replies with UNAVAILABLE if there aren't any pending events.
2046 */
2047#define EC_CMD_GET_NEXT_EVENT 0x67
2048
2049enum ec_mkbp_event {
2050 /* Keyboard matrix changed. The event data is the new matrix state. */
2051 EC_MKBP_EVENT_KEY_MATRIX = 0,
2052
2053 /* New host event. The event data is 4 bytes of host event flags. */
2054 EC_MKBP_EVENT_HOST_EVENT = 1,
2055
2056 /* New Sensor FIFO data. The event data is fifo_info structure. */
2057 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2058
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002059 /* The state of the non-matrixed buttons have changed. */
2060 EC_MKBP_EVENT_BUTTON = 3,
2061
2062 /* The state of the switches have changed. */
2063 EC_MKBP_EVENT_SWITCH = 4,
2064
Rajat Jaine6eba3f2017-04-03 11:53:41 -07002065 /* EC sent a sysrq command */
2066 EC_MKBP_EVENT_SYSRQ = 6,
2067
Vic Yang6f1d9122016-08-10 19:05:24 +02002068 /* Number of MKBP events */
2069 EC_MKBP_EVENT_COUNT,
2070};
2071
2072union ec_response_get_next_data {
2073 uint8_t key_matrix[13];
2074
2075 /* Unaligned */
2076 uint32_t host_event;
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002077
2078 uint32_t buttons;
2079 uint32_t switches;
Rajat Jaine6eba3f2017-04-03 11:53:41 -07002080 uint32_t sysrq;
Vic Yang6f1d9122016-08-10 19:05:24 +02002081} __packed;
2082
2083struct ec_response_get_next_event {
2084 uint8_t event_type;
2085 /* Followed by event data if any */
2086 union ec_response_get_next_data data;
2087} __packed;
2088
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002089/* Bit indices for buttons and switches.*/
2090/* Buttons */
2091#define EC_MKBP_POWER_BUTTON 0
2092#define EC_MKBP_VOL_UP 1
2093#define EC_MKBP_VOL_DOWN 2
2094
2095/* Switches */
2096#define EC_MKBP_LID_OPEN 0
Gwendal Grignou6ccc3a32017-01-27 11:52:35 +01002097#define EC_MKBP_TABLET_MODE 1
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002098
Simon Glassdeaf39e2013-02-25 14:08:36 -08002099/*****************************************************************************/
2100/* Temperature sensor commands */
2101
2102/* Read temperature sensor info */
2103#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2104
2105struct ec_params_temp_sensor_get_info {
2106 uint8_t id;
2107} __packed;
2108
2109struct ec_response_temp_sensor_get_info {
2110 char sensor_name[32];
2111 uint8_t sensor_type;
2112} __packed;
2113
2114/*****************************************************************************/
2115
2116/*
2117 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2118 * commands accidentally sent to the wrong interface. See the ACPI section
2119 * below.
2120 */
2121
2122/*****************************************************************************/
2123/* Host event commands */
2124
2125/*
2126 * Host event mask params and response structures, shared by all of the host
2127 * event commands below.
2128 */
2129struct ec_params_host_event_mask {
2130 uint32_t mask;
2131} __packed;
2132
2133struct ec_response_host_event_mask {
2134 uint32_t mask;
2135} __packed;
2136
2137/* These all use ec_response_host_event_mask */
2138#define EC_CMD_HOST_EVENT_GET_B 0x87
2139#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2140#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2141#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2142
2143/* These all use ec_params_host_event_mask */
2144#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2145#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2146#define EC_CMD_HOST_EVENT_CLEAR 0x8c
2147#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2148#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2149
2150/*****************************************************************************/
2151/* Switch commands */
2152
2153/* Enable/disable LCD backlight */
2154#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2155
2156struct ec_params_switch_enable_backlight {
2157 uint8_t enabled;
2158} __packed;
2159
2160/* Enable/disable WLAN/Bluetooth */
2161#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
Bill Richardson5271db22014-04-30 10:44:08 -07002162#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Simon Glassdeaf39e2013-02-25 14:08:36 -08002163
Bill Richardson5271db22014-04-30 10:44:08 -07002164/* Version 0 params; no response */
2165struct ec_params_switch_enable_wireless_v0 {
Simon Glassdeaf39e2013-02-25 14:08:36 -08002166 uint8_t enabled;
2167} __packed;
2168
Bill Richardson5271db22014-04-30 10:44:08 -07002169/* Version 1 params */
2170struct ec_params_switch_enable_wireless_v1 {
2171 /* Flags to enable now */
2172 uint8_t now_flags;
2173
2174 /* Which flags to copy from now_flags */
2175 uint8_t now_mask;
2176
2177 /*
2178 * Flags to leave enabled in S3, if they're on at the S0->S3
2179 * transition. (Other flags will be disabled by the S0->S3
2180 * transition.)
2181 */
2182 uint8_t suspend_flags;
2183
2184 /* Which flags to copy from suspend_flags */
2185 uint8_t suspend_mask;
2186} __packed;
2187
2188/* Version 1 response */
2189struct ec_response_switch_enable_wireless_v1 {
2190 /* Flags to enable now */
2191 uint8_t now_flags;
2192
2193 /* Flags to leave enabled in S3 */
2194 uint8_t suspend_flags;
2195} __packed;
2196
Simon Glassdeaf39e2013-02-25 14:08:36 -08002197/*****************************************************************************/
2198/* GPIO commands. Only available on EC if write protect has been disabled. */
2199
2200/* Set GPIO output value */
2201#define EC_CMD_GPIO_SET 0x92
2202
2203struct ec_params_gpio_set {
2204 char name[32];
2205 uint8_t val;
2206} __packed;
2207
2208/* Get GPIO value */
2209#define EC_CMD_GPIO_GET 0x93
2210
Stephen Barber256ab952015-06-09 13:04:43 +02002211/* Version 0 of input params and response */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002212struct ec_params_gpio_get {
2213 char name[32];
2214} __packed;
2215struct ec_response_gpio_get {
2216 uint8_t val;
2217} __packed;
2218
Stephen Barber256ab952015-06-09 13:04:43 +02002219/* Version 1 of input params and response */
2220struct ec_params_gpio_get_v1 {
2221 uint8_t subcmd;
2222 union {
2223 struct {
2224 char name[32];
2225 } get_value_by_name;
2226 struct {
2227 uint8_t index;
2228 } get_info;
2229 };
2230} __packed;
2231
2232struct ec_response_gpio_get_v1 {
2233 union {
2234 struct {
2235 uint8_t val;
2236 } get_value_by_name, get_count;
2237 struct {
2238 uint8_t val;
2239 char name[32];
2240 uint32_t flags;
2241 } get_info;
2242 };
2243} __packed;
2244
2245enum gpio_get_subcmd {
2246 EC_GPIO_GET_BY_NAME = 0,
2247 EC_GPIO_GET_COUNT = 1,
2248 EC_GPIO_GET_INFO = 2,
2249};
2250
Simon Glassdeaf39e2013-02-25 14:08:36 -08002251/*****************************************************************************/
2252/* I2C commands. Only available when flash write protect is unlocked. */
2253
Bill Richardson5271db22014-04-30 10:44:08 -07002254/*
2255 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2256 * removed soon. Use EC_CMD_I2C_XFER instead.
2257 */
2258
Simon Glassdeaf39e2013-02-25 14:08:36 -08002259/* Read I2C bus */
2260#define EC_CMD_I2C_READ 0x94
2261
2262struct ec_params_i2c_read {
Bill Richardson5271db22014-04-30 10:44:08 -07002263 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002264 uint8_t read_size; /* Either 8 or 16. */
2265 uint8_t port;
2266 uint8_t offset;
2267} __packed;
2268struct ec_response_i2c_read {
2269 uint16_t data;
2270} __packed;
2271
2272/* Write I2C bus */
2273#define EC_CMD_I2C_WRITE 0x95
2274
2275struct ec_params_i2c_write {
2276 uint16_t data;
Bill Richardson5271db22014-04-30 10:44:08 -07002277 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002278 uint8_t write_size; /* Either 8 or 16. */
2279 uint8_t port;
2280 uint8_t offset;
2281} __packed;
2282
2283/*****************************************************************************/
2284/* Charge state commands. Only available when flash write protect unlocked. */
2285
Bill Richardson5271db22014-04-30 10:44:08 -07002286/* Force charge state machine to stop charging the battery or force it to
2287 * discharge the battery.
2288 */
2289#define EC_CMD_CHARGE_CONTROL 0x96
2290#define EC_VER_CHARGE_CONTROL 1
Simon Glassdeaf39e2013-02-25 14:08:36 -08002291
Bill Richardson5271db22014-04-30 10:44:08 -07002292enum ec_charge_control_mode {
2293 CHARGE_CONTROL_NORMAL = 0,
2294 CHARGE_CONTROL_IDLE,
2295 CHARGE_CONTROL_DISCHARGE,
2296};
2297
2298struct ec_params_charge_control {
2299 uint32_t mode; /* enum charge_control_mode */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002300} __packed;
2301
2302/*****************************************************************************/
2303/* Console commands. Only available when flash write protect is unlocked. */
2304
2305/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2306#define EC_CMD_CONSOLE_SNAPSHOT 0x97
2307
2308/*
Nicolas Boichat0aa877c2017-05-16 17:46:48 +02002309 * Read data from the saved snapshot. If the subcmd parameter is
2310 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2311 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2312 * end of the previous snapshot.
2313 *
2314 * The params are only looked at in version >= 1 of this command. Prior
2315 * versions will just default to CONSOLE_READ_NEXT behavior.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002316 *
2317 * Response is null-terminated string. Empty string, if there is no more
2318 * remaining output.
2319 */
2320#define EC_CMD_CONSOLE_READ 0x98
2321
Nicolas Boichat0aa877c2017-05-16 17:46:48 +02002322enum ec_console_read_subcmd {
2323 CONSOLE_READ_NEXT = 0,
2324 CONSOLE_READ_RECENT
2325};
2326
2327struct ec_params_console_read_v1 {
2328 uint8_t subcmd; /* enum ec_console_read_subcmd */
2329} __packed;
2330
Simon Glassdeaf39e2013-02-25 14:08:36 -08002331/*****************************************************************************/
2332
2333/*
Stephen Barber256ab952015-06-09 13:04:43 +02002334 * Cut off battery power immediately or after the host has shut down.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002335 *
Stephen Barber256ab952015-06-09 13:04:43 +02002336 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2337 * EC_RES_SUCCESS if the command was successful.
2338 * EC_RES_ERROR if the cut off command failed.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002339 */
Stephen Barber256ab952015-06-09 13:04:43 +02002340
Simon Glassdeaf39e2013-02-25 14:08:36 -08002341#define EC_CMD_BATTERY_CUT_OFF 0x99
2342
Stephen Barber256ab952015-06-09 13:04:43 +02002343#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2344
2345struct ec_params_battery_cutoff {
2346 uint8_t flags;
2347} __packed;
2348
Simon Glassdeaf39e2013-02-25 14:08:36 -08002349/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07002350/* USB port mux control. */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002351
2352/*
Bill Richardson5271db22014-04-30 10:44:08 -07002353 * Switch USB mux or return to automatic switching.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002354 */
Bill Richardson5271db22014-04-30 10:44:08 -07002355#define EC_CMD_USB_MUX 0x9a
2356
2357struct ec_params_usb_mux {
2358 uint8_t mux;
2359} __packed;
2360
2361/*****************************************************************************/
2362/* LDOs / FETs control. */
2363
2364enum ec_ldo_state {
2365 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2366 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2367};
2368
2369/*
2370 * Switch on/off a LDO.
2371 */
2372#define EC_CMD_LDO_SET 0x9b
2373
2374struct ec_params_ldo_set {
2375 uint8_t index;
2376 uint8_t state;
2377} __packed;
2378
2379/*
2380 * Get LDO state.
2381 */
2382#define EC_CMD_LDO_GET 0x9c
2383
2384struct ec_params_ldo_get {
2385 uint8_t index;
2386} __packed;
2387
2388struct ec_response_ldo_get {
2389 uint8_t state;
2390} __packed;
2391
2392/*****************************************************************************/
2393/* Power info. */
2394
2395/*
2396 * Get power info.
2397 */
2398#define EC_CMD_POWER_INFO 0x9d
2399
2400struct ec_response_power_info {
2401 uint32_t usb_dev_type;
2402 uint16_t voltage_ac;
2403 uint16_t voltage_system;
2404 uint16_t current_system;
2405 uint16_t usb_current_limit;
2406} __packed;
2407
2408/*****************************************************************************/
2409/* I2C passthru command */
2410
2411#define EC_CMD_I2C_PASSTHRU 0x9e
2412
Bill Richardson5271db22014-04-30 10:44:08 -07002413/* Read data; if not present, message is a write */
2414#define EC_I2C_FLAG_READ (1 << 15)
2415
2416/* Mask for address */
2417#define EC_I2C_ADDR_MASK 0x3ff
2418
2419#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2420#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2421
2422/* Any error */
2423#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2424
2425struct ec_params_i2c_passthru_msg {
2426 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2427 uint16_t len; /* Number of bytes to read or write */
2428} __packed;
2429
2430struct ec_params_i2c_passthru {
2431 uint8_t port; /* I2C port number */
2432 uint8_t num_msgs; /* Number of messages */
2433 struct ec_params_i2c_passthru_msg msg[];
2434 /* Data to write for all messages is concatenated here */
2435} __packed;
2436
2437struct ec_response_i2c_passthru {
2438 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2439 uint8_t num_msgs; /* Number of messages processed */
2440 uint8_t data[]; /* Data read by messages concatenated here */
2441} __packed;
2442
2443/*****************************************************************************/
2444/* Power button hang detect */
2445
2446#define EC_CMD_HANG_DETECT 0x9f
2447
2448/* Reasons to start hang detection timer */
2449/* Power button pressed */
2450#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2451
2452/* Lid closed */
2453#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2454
2455 /* Lid opened */
2456#define EC_HANG_START_ON_LID_OPEN (1 << 2)
2457
2458/* Start of AP S3->S0 transition (booting or resuming from suspend) */
2459#define EC_HANG_START_ON_RESUME (1 << 3)
2460
2461/* Reasons to cancel hang detection */
2462
2463/* Power button released */
2464#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2465
2466/* Any host command from AP received */
2467#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2468
2469/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2470#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2471
2472/*
2473 * If this flag is set, all the other fields are ignored, and the hang detect
2474 * timer is started. This provides the AP a way to start the hang timer
2475 * without reconfiguring any of the other hang detect settings. Note that
2476 * you must previously have configured the timeouts.
2477 */
2478#define EC_HANG_START_NOW (1 << 30)
2479
2480/*
2481 * If this flag is set, all the other fields are ignored (including
2482 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2483 * without reconfiguring any of the other hang detect settings.
2484 */
2485#define EC_HANG_STOP_NOW (1 << 31)
2486
2487struct ec_params_hang_detect {
2488 /* Flags; see EC_HANG_* */
2489 uint32_t flags;
2490
2491 /* Timeout in msec before generating host event, if enabled */
2492 uint16_t host_event_timeout_msec;
2493
2494 /* Timeout in msec before generating warm reboot, if enabled */
2495 uint16_t warm_reboot_timeout_msec;
2496} __packed;
2497
2498/*****************************************************************************/
2499/* Commands for battery charging */
2500
2501/*
2502 * This is the single catch-all host command to exchange data regarding the
2503 * charge state machine (v2 and up).
2504 */
2505#define EC_CMD_CHARGE_STATE 0xa0
2506
2507/* Subcommands for this host command */
2508enum charge_state_command {
2509 CHARGE_STATE_CMD_GET_STATE,
2510 CHARGE_STATE_CMD_GET_PARAM,
2511 CHARGE_STATE_CMD_SET_PARAM,
2512 CHARGE_STATE_NUM_CMDS
2513};
2514
2515/*
2516 * Known param numbers are defined here. Ranges are reserved for board-specific
2517 * params, which are handled by the particular implementations.
2518 */
2519enum charge_state_params {
2520 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2521 CS_PARAM_CHG_CURRENT, /* charger current limit */
2522 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2523 CS_PARAM_CHG_STATUS, /* charger-specific status */
2524 CS_PARAM_CHG_OPTION, /* charger-specific options */
2525 /* How many so far? */
2526 CS_NUM_BASE_PARAMS,
2527
2528 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2529 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2530 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2531
2532 /* Other custom param ranges go here... */
2533};
2534
2535struct ec_params_charge_state {
2536 uint8_t cmd; /* enum charge_state_command */
2537 union {
2538 struct {
2539 /* no args */
2540 } get_state;
2541
2542 struct {
2543 uint32_t param; /* enum charge_state_param */
2544 } get_param;
2545
2546 struct {
2547 uint32_t param; /* param to set */
2548 uint32_t value; /* value to set */
2549 } set_param;
2550 };
2551} __packed;
2552
2553struct ec_response_charge_state {
2554 union {
2555 struct {
2556 int ac;
2557 int chg_voltage;
2558 int chg_current;
2559 int chg_input_current;
2560 int batt_state_of_charge;
2561 } get_state;
2562
2563 struct {
2564 uint32_t value;
2565 } get_param;
2566 struct {
2567 /* no return values */
2568 } set_param;
2569 };
2570} __packed;
2571
Simon Glassdeaf39e2013-02-25 14:08:36 -08002572
2573/*
2574 * Set maximum battery charging current.
2575 */
2576#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2577
2578struct ec_params_current_limit {
Bill Richardson5271db22014-04-30 10:44:08 -07002579 uint32_t limit; /* in mA */
2580} __packed;
2581
2582/*
2583 * Set maximum external power current.
2584 */
2585#define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
2586
2587struct ec_params_ext_power_current_limit {
2588 uint32_t limit; /* in mA */
2589} __packed;
2590
Shawn Nematbakhshf00c06f2016-12-16 18:57:37 +01002591/* Inform the EC when entering a sleep state */
2592#define EC_CMD_HOST_SLEEP_EVENT 0xa9
2593
2594enum host_sleep_event {
2595 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2596 HOST_SLEEP_EVENT_S3_RESUME = 2,
2597 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2598 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2599};
2600
2601struct ec_params_host_sleep_event {
2602 uint8_t sleep_event;
2603} __packed;
2604
Bill Richardson5271db22014-04-30 10:44:08 -07002605/*****************************************************************************/
2606/* Smart battery pass-through */
2607
2608/* Get / Set 16-bit smart battery registers */
2609#define EC_CMD_SB_READ_WORD 0xb0
2610#define EC_CMD_SB_WRITE_WORD 0xb1
2611
2612/* Get / Set string smart battery parameters
2613 * formatted as SMBUS "block".
2614 */
2615#define EC_CMD_SB_READ_BLOCK 0xb2
2616#define EC_CMD_SB_WRITE_BLOCK 0xb3
2617
2618struct ec_params_sb_rd {
2619 uint8_t reg;
2620} __packed;
2621
2622struct ec_response_sb_rd_word {
2623 uint16_t value;
2624} __packed;
2625
2626struct ec_params_sb_wr_word {
2627 uint8_t reg;
2628 uint16_t value;
2629} __packed;
2630
2631struct ec_response_sb_rd_block {
2632 uint8_t data[32];
2633} __packed;
2634
2635struct ec_params_sb_wr_block {
2636 uint8_t reg;
2637 uint16_t data[32];
Simon Glassdeaf39e2013-02-25 14:08:36 -08002638} __packed;
2639
2640/*****************************************************************************/
Stephen Barber256ab952015-06-09 13:04:43 +02002641/* Battery vendor parameters
2642 *
2643 * Get or set vendor-specific parameters in the battery. Implementations may
2644 * differ between boards or batteries. On a set operation, the response
2645 * contains the actual value set, which may be rounded or clipped from the
2646 * requested value.
2647 */
2648
2649#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2650
2651enum ec_battery_vendor_param_mode {
2652 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2653 BATTERY_VENDOR_PARAM_MODE_SET,
2654};
2655
2656struct ec_params_battery_vendor_param {
2657 uint32_t param;
2658 uint32_t value;
2659 uint8_t mode;
2660} __packed;
2661
2662struct ec_response_battery_vendor_param {
2663 uint32_t value;
2664} __packed;
2665
2666/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08002667/* System commands */
2668
2669/*
Bill Richardson5271db22014-04-30 10:44:08 -07002670 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2671 * necessarily reboot the EC. Rename to "image" or something similar?
Simon Glassdeaf39e2013-02-25 14:08:36 -08002672 */
2673#define EC_CMD_REBOOT_EC 0xd2
2674
2675/* Command */
2676enum ec_reboot_cmd {
2677 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2678 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2679 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2680 /* (command 3 was jump to RW-B) */
2681 EC_REBOOT_COLD = 4, /* Cold-reboot */
2682 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2683 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
2684};
2685
2686/* Flags for ec_params_reboot_ec.reboot_flags */
2687#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2688#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2689
2690struct ec_params_reboot_ec {
2691 uint8_t cmd; /* enum ec_reboot_cmd */
2692 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2693} __packed;
2694
2695/*
2696 * Get information on last EC panic.
2697 *
2698 * Returns variable-length platform-dependent panic information. See panic.h
2699 * for details.
2700 */
2701#define EC_CMD_GET_PANIC_INFO 0xd3
2702
2703/*****************************************************************************/
2704/*
2705 * ACPI commands
2706 *
2707 * These are valid ONLY on the ACPI command/data port.
2708 */
2709
2710/*
2711 * ACPI Read Embedded Controller
2712 *
2713 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2714 *
2715 * Use the following sequence:
2716 *
2717 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
2718 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2719 * - Write address to EC_LPC_ADDR_ACPI_DATA
2720 * - Wait for EC_LPC_CMDR_DATA bit to set
2721 * - Read value from EC_LPC_ADDR_ACPI_DATA
2722 */
2723#define EC_CMD_ACPI_READ 0x80
2724
2725/*
2726 * ACPI Write Embedded Controller
2727 *
2728 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2729 *
2730 * Use the following sequence:
2731 *
2732 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
2733 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2734 * - Write address to EC_LPC_ADDR_ACPI_DATA
2735 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2736 * - Write value to EC_LPC_ADDR_ACPI_DATA
2737 */
2738#define EC_CMD_ACPI_WRITE 0x81
2739
2740/*
2741 * ACPI Query Embedded Controller
2742 *
2743 * This clears the lowest-order bit in the currently pending host events, and
2744 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
2745 * event 0x80000000 = 32), or 0 if no event was pending.
2746 */
2747#define EC_CMD_ACPI_QUERY_EVENT 0x84
2748
2749/* Valid addresses in ACPI memory space, for read/write commands */
Bill Richardson5271db22014-04-30 10:44:08 -07002750
Simon Glassdeaf39e2013-02-25 14:08:36 -08002751/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
2752#define EC_ACPI_MEM_VERSION 0x00
2753/*
2754 * Test location; writing value here updates test compliment byte to (0xff -
2755 * value).
2756 */
2757#define EC_ACPI_MEM_TEST 0x01
2758/* Test compliment; writes here are ignored. */
2759#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
Bill Richardson5271db22014-04-30 10:44:08 -07002760
Simon Glassdeaf39e2013-02-25 14:08:36 -08002761/* Keyboard backlight brightness percent (0 - 100) */
2762#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
Bill Richardson5271db22014-04-30 10:44:08 -07002763/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
2764#define EC_ACPI_MEM_FAN_DUTY 0x04
2765
2766/*
2767 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
2768 * independent thresholds attached to them. The current value of the ID
2769 * register determines which sensor is affected by the THRESHOLD and COMMIT
2770 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
2771 * as the memory-mapped sensors. The COMMIT register applies those settings.
2772 *
2773 * The spec does not mandate any way to read back the threshold settings
2774 * themselves, but when a threshold is crossed the AP needs a way to determine
2775 * which sensor(s) are responsible. Each reading of the ID register clears and
2776 * returns one sensor ID that has crossed one of its threshold (in either
2777 * direction) since the last read. A value of 0xFF means "no new thresholds
2778 * have tripped". Setting or enabling the thresholds for a sensor will clear
2779 * the unread event count for that sensor.
2780 */
2781#define EC_ACPI_MEM_TEMP_ID 0x05
2782#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
2783#define EC_ACPI_MEM_TEMP_COMMIT 0x07
2784/*
2785 * Here are the bits for the COMMIT register:
2786 * bit 0 selects the threshold index for the chosen sensor (0/1)
2787 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
2788 * Each write to the commit register affects one threshold.
2789 */
2790#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
2791#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
2792/*
2793 * Example:
2794 *
2795 * Set the thresholds for sensor 2 to 50 C and 60 C:
2796 * write 2 to [0x05] -- select temp sensor 2
2797 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
2798 * write 0x2 to [0x07] -- enable threshold 0 with this value
2799 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
2800 * write 0x3 to [0x07] -- enable threshold 1 with this value
2801 *
2802 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
2803 * write 2 to [0x05] -- select temp sensor 2
2804 * write 0x1 to [0x07] -- disable threshold 1
2805 */
2806
2807/* DPTF battery charging current limit */
2808#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
2809
2810/* Charging limit is specified in 64 mA steps */
2811#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
2812/* Value to disable DPTF battery charging limit */
2813#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Simon Glassdeaf39e2013-02-25 14:08:36 -08002814
2815/* Current version of ACPI memory address space */
2816#define EC_ACPI_MEM_VERSION_CURRENT 1
2817
2818
2819/*****************************************************************************/
2820/*
2821 * Special commands
2822 *
2823 * These do not follow the normal rules for commands. See each command for
2824 * details.
2825 */
2826
2827/*
2828 * Reboot NOW
2829 *
2830 * This command will work even when the EC LPC interface is busy, because the
2831 * reboot command is processed at interrupt level. Note that when the EC
2832 * reboots, the host will reboot too, so there is no response to this command.
2833 *
2834 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
2835 */
2836#define EC_CMD_REBOOT 0xd1 /* Think "die" */
2837
2838/*
2839 * Resend last response (not supported on LPC).
2840 *
2841 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
2842 * there was no previous command, or the previous command's response was too
2843 * big to save.
2844 */
2845#define EC_CMD_RESEND_RESPONSE 0xdb
2846
2847/*
2848 * This header byte on a command indicate version 0. Any header byte less
2849 * than this means that we are talking to an old EC which doesn't support
2850 * versioning. In that case, we assume version 0.
2851 *
2852 * Header bytes greater than this indicate a later version. For example,
2853 * EC_CMD_VERSION0 + 1 means we are using version 1.
2854 *
Bill Richardson5271db22014-04-30 10:44:08 -07002855 * The old EC interface must not use commands 0xdc or higher.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002856 */
2857#define EC_CMD_VERSION0 0xdc
2858
2859#endif /* !__ACPI__ */
2860
Bill Richardson5271db22014-04-30 10:44:08 -07002861/*****************************************************************************/
2862/*
Stephen Barber256ab952015-06-09 13:04:43 +02002863 * PD commands
2864 *
2865 * These commands are for PD MCU communication.
2866 */
2867
2868/* EC to PD MCU exchange status command */
2869#define EC_CMD_PD_EXCHANGE_STATUS 0x100
2870
2871/* Status of EC being sent to PD */
2872struct ec_params_pd_status {
2873 int8_t batt_soc; /* battery state of charge */
2874} __packed;
2875
2876/* Status of PD being sent back to EC */
2877struct ec_response_pd_status {
2878 int8_t status; /* PD MCU status */
2879 uint32_t curr_lim_ma; /* input current limit */
2880} __packed;
2881
2882/* Set USB type-C port role and muxes */
2883#define EC_CMD_USB_PD_CONTROL 0x101
2884
2885enum usb_pd_control_role {
2886 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
2887 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
2888 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
2889 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
2890 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
2891};
2892
2893enum usb_pd_control_mux {
2894 USB_PD_CTRL_MUX_NO_CHANGE = 0,
2895 USB_PD_CTRL_MUX_NONE = 1,
2896 USB_PD_CTRL_MUX_USB = 2,
2897 USB_PD_CTRL_MUX_DP = 3,
2898 USB_PD_CTRL_MUX_DOCK = 4,
2899 USB_PD_CTRL_MUX_AUTO = 5,
2900};
2901
2902struct ec_params_usb_pd_control {
2903 uint8_t port;
2904 uint8_t role;
2905 uint8_t mux;
2906} __packed;
2907
2908/*****************************************************************************/
2909/*
2910 * Passthru commands
2911 *
2912 * Some platforms have sub-processors chained to each other. For example.
2913 *
2914 * AP <--> EC <--> PD MCU
2915 *
2916 * The top 2 bits of the command number are used to indicate which device the
2917 * command is intended for. Device 0 is always the device receiving the
2918 * command; other device mapping is board-specific.
2919 *
2920 * When a device receives a command to be passed to a sub-processor, it passes
2921 * it on with the device number set back to 0. This allows the sub-processor
2922 * to remain blissfully unaware of whether the command originated on the next
2923 * device up the chain, or was passed through from the AP.
2924 *
2925 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
2926 * AP sends command 0x4002 to the EC
2927 * EC sends command 0x0002 to the PD MCU
2928 * EC forwards PD MCU response back to the AP
2929 */
2930
2931/* Offset and max command number for sub-device n */
2932#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
2933#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
2934
2935/*****************************************************************************/
2936/*
Bill Richardson5271db22014-04-30 10:44:08 -07002937 * Deprecated constants. These constants have been renamed for clarity. The
2938 * meaning and size has not changed. Programs that use the old names should
2939 * switch to the new names soon, as the old names may not be carried forward
2940 * forever.
2941 */
2942#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
2943#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
2944#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
2945
Simon Glassdeaf39e2013-02-25 14:08:36 -08002946#endif /* __CROS_EC_COMMANDS_H */