blob: 8826e0f64b0e0ec54b8d5474ae4012ae8f67b1fd [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
628struct ec_response_get_cmd_versions {
629 /*
630 * Mask of supported versions; use EC_VER_MASK() to compare with a
631 * desired version.
632 */
633 uint32_t version_mask;
634} __packed;
635
636/*
637 * Check EC communcations status (busy). This is needed on i2c/spi but not
638 * on lpc since it has its own out-of-band busy indicator.
639 *
640 * lpc must read the status from the command register. Attempting this on
641 * lpc will overwrite the args/parameter space and corrupt its data.
642 */
643#define EC_CMD_GET_COMMS_STATUS 0x09
644
645/* Avoid using ec_status which is for return values */
646enum ec_comms_status {
647 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
648};
649
650struct ec_response_get_comms_status {
651 uint32_t flags; /* Mask of enum ec_comms_status */
652} __packed;
653
Bill Richardson5271db22014-04-30 10:44:08 -0700654/* Fake a variety of responses, purely for testing purposes. */
655#define EC_CMD_TEST_PROTOCOL 0x0a
656
657/* Tell the EC what to send back to us. */
658struct ec_params_test_protocol {
659 uint32_t ec_result;
660 uint32_t ret_len;
661 uint8_t buf[32];
662} __packed;
663
664/* Here it comes... */
665struct ec_response_test_protocol {
666 uint8_t buf[32];
667} __packed;
668
669/* Get prococol information */
670#define EC_CMD_GET_PROTOCOL_INFO 0x0b
671
672/* Flags for ec_response_get_protocol_info.flags */
673/* EC_RES_IN_PROGRESS may be returned if a command is slow */
674#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
675
676struct ec_response_get_protocol_info {
677 /* Fields which exist if at least protocol version 3 supported */
678
679 /* Bitmask of protocol versions supported (1 << n means version n)*/
680 uint32_t protocol_versions;
681
682 /* Maximum request packet size, in bytes */
683 uint16_t max_request_packet_size;
684
685 /* Maximum response packet size, in bytes */
686 uint16_t max_response_packet_size;
687
688 /* Flags; see EC_PROTOCOL_INFO_* */
689 uint32_t flags;
690} __packed;
691
692
693/*****************************************************************************/
694/* Get/Set miscellaneous values */
695
696/* The upper byte of .flags tells what to do (nothing means "get") */
697#define EC_GSV_SET 0x80000000
698
699/* The lower three bytes of .flags identifies the parameter, if that has
700 meaning for an individual command. */
701#define EC_GSV_PARAM_MASK 0x00ffffff
702
703struct ec_params_get_set_value {
704 uint32_t flags;
705 uint32_t value;
706} __packed;
707
708struct ec_response_get_set_value {
709 uint32_t flags;
710 uint32_t value;
711} __packed;
712
713/* More than one command can use these structs to get/set paramters. */
714#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
715
Simon Glassdeaf39e2013-02-25 14:08:36 -0800716
717/*****************************************************************************/
718/* Flash commands */
719
720/* Get flash info */
721#define EC_CMD_FLASH_INFO 0x10
722
Bill Richardson5271db22014-04-30 10:44:08 -0700723/* Version 0 returns these fields */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800724struct ec_response_flash_info {
725 /* Usable flash size, in bytes */
726 uint32_t flash_size;
727 /*
728 * Write block size. Write offset and size must be a multiple
729 * of this.
730 */
731 uint32_t write_block_size;
732 /*
733 * Erase block size. Erase offset and size must be a multiple
734 * of this.
735 */
736 uint32_t erase_block_size;
737 /*
738 * Protection block size. Protection offset and size must be a
739 * multiple of this.
740 */
741 uint32_t protect_block_size;
742} __packed;
743
Bill Richardson5271db22014-04-30 10:44:08 -0700744/* Flags for version 1+ flash info command */
745/* EC flash erases bits to 0 instead of 1 */
746#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
747
748/*
749 * Version 1 returns the same initial fields as version 0, with additional
750 * fields following.
751 *
752 * gcc anonymous structs don't seem to get along with the __packed directive;
753 * if they did we'd define the version 0 struct as a sub-struct of this one.
754 */
755struct ec_response_flash_info_1 {
756 /* Version 0 fields; see above for description */
757 uint32_t flash_size;
758 uint32_t write_block_size;
759 uint32_t erase_block_size;
760 uint32_t protect_block_size;
761
762 /* Version 1 adds these fields: */
763 /*
764 * Ideal write size in bytes. Writes will be fastest if size is
765 * exactly this and offset is a multiple of this. For example, an EC
766 * may have a write buffer which can do half-page operations if data is
767 * aligned, and a slower word-at-a-time write mode.
768 */
769 uint32_t write_ideal_size;
770
771 /* Flags; see EC_FLASH_INFO_* */
772 uint32_t flags;
773} __packed;
774
Simon Glassdeaf39e2013-02-25 14:08:36 -0800775/*
776 * Read flash
777 *
778 * Response is params.size bytes of data.
779 */
780#define EC_CMD_FLASH_READ 0x11
781
782struct ec_params_flash_read {
783 uint32_t offset; /* Byte offset to read */
784 uint32_t size; /* Size to read in bytes */
785} __packed;
786
787/* Write flash */
788#define EC_CMD_FLASH_WRITE 0x12
Bill Richardson5271db22014-04-30 10:44:08 -0700789#define EC_VER_FLASH_WRITE 1
790
791/* Version 0 of the flash command supported only 64 bytes of data */
792#define EC_FLASH_WRITE_VER0_SIZE 64
Simon Glassdeaf39e2013-02-25 14:08:36 -0800793
794struct ec_params_flash_write {
795 uint32_t offset; /* Byte offset to write */
796 uint32_t size; /* Size to write in bytes */
Bill Richardson5271db22014-04-30 10:44:08 -0700797 /* Followed by data to write */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800798} __packed;
799
800/* Erase flash */
801#define EC_CMD_FLASH_ERASE 0x13
802
803struct ec_params_flash_erase {
804 uint32_t offset; /* Byte offset to erase */
805 uint32_t size; /* Size to erase in bytes */
806} __packed;
807
808/*
809 * Get/set flash protection.
810 *
811 * If mask!=0, sets/clear the requested bits of flags. Depending on the
812 * firmware write protect GPIO, not all flags will take effect immediately;
813 * some flags require a subsequent hard reset to take effect. Check the
814 * returned flags bits to see what actually happened.
815 *
816 * If mask=0, simply returns the current flags state.
817 */
818#define EC_CMD_FLASH_PROTECT 0x15
819#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
820
821/* Flags for flash protection */
822/* RO flash code protected when the EC boots */
823#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
824/*
825 * RO flash code protected now. If this bit is set, at-boot status cannot
826 * be changed.
827 */
828#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
829/* Entire flash code protected now, until reboot. */
830#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
831/* Flash write protect GPIO is asserted now */
832#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
833/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
834#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
835/*
836 * Error - flash protection is in inconsistent state. At least one bank of
837 * flash which should be protected is not protected. Usually fixed by
838 * re-requesting the desired flags, or by a hard reset if that fails.
839 */
840#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
841/* Entile flash code protected when the EC boots */
842#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
843
844struct ec_params_flash_protect {
845 uint32_t mask; /* Bits in flags to apply */
846 uint32_t flags; /* New flags to apply */
847} __packed;
848
849struct ec_response_flash_protect {
850 /* Current value of flash protect flags */
851 uint32_t flags;
852 /*
853 * Flags which are valid on this platform. This allows the caller
854 * to distinguish between flags which aren't set vs. flags which can't
855 * be set on this platform.
856 */
857 uint32_t valid_flags;
858 /* Flags which can be changed given the current protection state */
859 uint32_t writable_flags;
860} __packed;
861
862/*
863 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
864 * write protect. These commands may be reused with version > 0.
865 */
866
867/* Get the region offset/size */
868#define EC_CMD_FLASH_REGION_INFO 0x16
869#define EC_VER_FLASH_REGION_INFO 1
870
871enum ec_flash_region {
872 /* Region which holds read-only EC image */
Bill Richardson5271db22014-04-30 10:44:08 -0700873 EC_FLASH_REGION_RO = 0,
Simon Glassdeaf39e2013-02-25 14:08:36 -0800874 /* Region which holds rewritable EC image */
875 EC_FLASH_REGION_RW,
876 /*
877 * Region which should be write-protected in the factory (a superset of
878 * EC_FLASH_REGION_RO)
879 */
880 EC_FLASH_REGION_WP_RO,
Bill Richardson5271db22014-04-30 10:44:08 -0700881 /* Number of regions */
882 EC_FLASH_REGION_COUNT,
Simon Glassdeaf39e2013-02-25 14:08:36 -0800883};
884
885struct ec_params_flash_region_info {
886 uint32_t region; /* enum ec_flash_region */
887} __packed;
888
889struct ec_response_flash_region_info {
890 uint32_t offset;
891 uint32_t size;
892} __packed;
893
894/* Read/write VbNvContext */
895#define EC_CMD_VBNV_CONTEXT 0x17
896#define EC_VER_VBNV_CONTEXT 1
897#define EC_VBNV_BLOCK_SIZE 16
898
899enum ec_vbnvcontext_op {
900 EC_VBNV_CONTEXT_OP_READ,
901 EC_VBNV_CONTEXT_OP_WRITE,
902};
903
904struct ec_params_vbnvcontext {
905 uint32_t op;
906 uint8_t block[EC_VBNV_BLOCK_SIZE];
907} __packed;
908
909struct ec_response_vbnvcontext {
910 uint8_t block[EC_VBNV_BLOCK_SIZE];
911} __packed;
912
913/*****************************************************************************/
914/* PWM commands */
915
916/* Get fan target RPM */
917#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
918
919struct ec_response_pwm_get_fan_rpm {
920 uint32_t rpm;
921} __packed;
922
923/* Set target fan RPM */
924#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
925
926struct ec_params_pwm_set_fan_target_rpm {
927 uint32_t rpm;
928} __packed;
929
930/* Get keyboard backlight */
931#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
932
933struct ec_response_pwm_get_keyboard_backlight {
934 uint8_t percent;
935 uint8_t enabled;
936} __packed;
937
938/* Set keyboard backlight */
939#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
940
941struct ec_params_pwm_set_keyboard_backlight {
942 uint8_t percent;
943} __packed;
944
945/* Set target fan PWM duty cycle */
946#define EC_CMD_PWM_SET_FAN_DUTY 0x24
947
948struct ec_params_pwm_set_fan_duty {
949 uint32_t percent;
950} __packed;
951
Brian Norris2b66bd62016-07-15 16:28:42 -0700952#define EC_CMD_PWM_SET_DUTY 0x25
953/* 16 bit duty cycle, 0xffff = 100% */
954#define EC_PWM_MAX_DUTY 0xffff
955
956enum ec_pwm_type {
957 /* All types, indexed by board-specific enum pwm_channel */
958 EC_PWM_TYPE_GENERIC = 0,
959 /* Keyboard backlight */
960 EC_PWM_TYPE_KB_LIGHT,
961 /* Display backlight */
962 EC_PWM_TYPE_DISPLAY_LIGHT,
963 EC_PWM_TYPE_COUNT,
964};
965
966struct ec_params_pwm_set_duty {
967 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
968 uint8_t pwm_type; /* ec_pwm_type */
969 uint8_t index; /* Type-specific index, or 0 if unique */
970} __packed;
971
972#define EC_CMD_PWM_GET_DUTY 0x26
973
974struct ec_params_pwm_get_duty {
975 uint8_t pwm_type; /* ec_pwm_type */
976 uint8_t index; /* Type-specific index, or 0 if unique */
977} __packed;
978
979struct ec_response_pwm_get_duty {
980 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
981} __packed;
982
Simon Glassdeaf39e2013-02-25 14:08:36 -0800983/*****************************************************************************/
984/*
985 * Lightbar commands. This looks worse than it is. Since we only use one HOST
986 * command to say "talk to the lightbar", we put the "and tell it to do X" part
987 * into a subcommand. We'll make separate structs for subcommands with
988 * different input args, so that we know how much to expect.
989 */
990#define EC_CMD_LIGHTBAR_CMD 0x28
991
992struct rgb_s {
993 uint8_t r, g, b;
994};
995
996#define LB_BATTERY_LEVELS 4
997/* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
998 * host command, but the alignment is the same regardless. Keep it that way.
999 */
Stephen Barber256ab952015-06-09 13:04:43 +02001000struct lightbar_params_v0 {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001001 /* Timing */
Bill Richardson5271db22014-04-30 10:44:08 -07001002 int32_t google_ramp_up;
1003 int32_t google_ramp_down;
1004 int32_t s3s0_ramp_up;
1005 int32_t s0_tick_delay[2]; /* AC=0/1 */
1006 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1007 int32_t s0s3_ramp_down;
1008 int32_t s3_sleep_for;
1009 int32_t s3_ramp_up;
1010 int32_t s3_ramp_down;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001011
1012 /* Oscillation */
1013 uint8_t new_s0;
1014 uint8_t osc_min[2]; /* AC=0/1 */
1015 uint8_t osc_max[2]; /* AC=0/1 */
1016 uint8_t w_ofs[2]; /* AC=0/1 */
1017
1018 /* Brightness limits based on the backlight and AC. */
1019 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1020 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1021 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1022
1023 /* Battery level thresholds */
1024 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1025
1026 /* Map [AC][battery_level] to color index */
1027 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1028 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1029
1030 /* Color palette */
1031 struct rgb_s color[8]; /* 0-3 are Google colors */
1032} __packed;
1033
Stephen Barber256ab952015-06-09 13:04:43 +02001034struct lightbar_params_v1 {
1035 /* Timing */
1036 int32_t google_ramp_up;
1037 int32_t google_ramp_down;
1038 int32_t s3s0_ramp_up;
1039 int32_t s0_tick_delay[2]; /* AC=0/1 */
1040 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1041 int32_t s0s3_ramp_down;
1042 int32_t s3_sleep_for;
1043 int32_t s3_ramp_up;
1044 int32_t s3_ramp_down;
1045 int32_t tap_tick_delay;
1046 int32_t tap_display_time;
1047
1048 /* Tap-for-battery params */
1049 uint8_t tap_pct_red;
1050 uint8_t tap_pct_green;
1051 uint8_t tap_seg_min_on;
1052 uint8_t tap_seg_max_on;
1053 uint8_t tap_seg_osc;
1054 uint8_t tap_idx[3];
1055
1056 /* Oscillation */
1057 uint8_t osc_min[2]; /* AC=0/1 */
1058 uint8_t osc_max[2]; /* AC=0/1 */
1059 uint8_t w_ofs[2]; /* AC=0/1 */
1060
1061 /* Brightness limits based on the backlight and AC. */
1062 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1063 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1064 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1065
1066 /* Battery level thresholds */
1067 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1068
1069 /* Map [AC][battery_level] to color index */
1070 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1071 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1072
1073 /* Color palette */
1074 struct rgb_s color[8]; /* 0-3 are Google colors */
1075} __packed;
1076
Simon Glassdeaf39e2013-02-25 14:08:36 -08001077struct ec_params_lightbar {
1078 uint8_t cmd; /* Command (see enum lightbar_command) */
1079 union {
1080 struct {
1081 /* no args */
Stephen Barber256ab952015-06-09 13:04:43 +02001082 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
1083 version, get_brightness, get_demo;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001084
Stephen Barber256ab952015-06-09 13:04:43 +02001085 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001086 uint8_t num;
Stephen Barber256ab952015-06-09 13:04:43 +02001087 } set_brightness, seq, demo;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001088
Stephen Barber256ab952015-06-09 13:04:43 +02001089 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001090 uint8_t ctrl, reg, value;
1091 } reg;
1092
Stephen Barber256ab952015-06-09 13:04:43 +02001093 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001094 uint8_t led, red, green, blue;
Stephen Barber256ab952015-06-09 13:04:43 +02001095 } set_rgb;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001096
Stephen Barber256ab952015-06-09 13:04:43 +02001097 struct {
1098 uint8_t led;
1099 } get_rgb;
1100
1101 struct lightbar_params_v0 set_params_v0;
1102 struct lightbar_params_v1 set_params_v1;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001103 };
1104} __packed;
1105
1106struct ec_response_lightbar {
1107 union {
Stephen Barber256ab952015-06-09 13:04:43 +02001108 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001109 struct {
1110 uint8_t reg;
1111 uint8_t ic0;
1112 uint8_t ic1;
1113 } vals[23];
1114 } dump;
1115
Stephen Barber256ab952015-06-09 13:04:43 +02001116 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001117 uint8_t num;
Stephen Barber256ab952015-06-09 13:04:43 +02001118 } get_seq, get_brightness, get_demo;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001119
Stephen Barber256ab952015-06-09 13:04:43 +02001120 struct lightbar_params_v0 get_params_v0;
1121 struct lightbar_params_v1 get_params_v1;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001122
Stephen Barber256ab952015-06-09 13:04:43 +02001123 struct {
Bill Richardson5271db22014-04-30 10:44:08 -07001124 uint32_t num;
1125 uint32_t flags;
1126 } version;
1127
Simon Glassdeaf39e2013-02-25 14:08:36 -08001128 struct {
Stephen Barber256ab952015-06-09 13:04:43 +02001129 uint8_t red, green, blue;
1130 } get_rgb;
1131
1132 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001133 /* no return params */
Stephen Barber256ab952015-06-09 13:04:43 +02001134 } off, on, init, set_brightness, seq, reg, set_rgb,
1135 demo, set_params_v0, set_params_v1;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001136 };
1137} __packed;
1138
1139/* Lightbar commands */
1140enum lightbar_command {
1141 LIGHTBAR_CMD_DUMP = 0,
1142 LIGHTBAR_CMD_OFF = 1,
1143 LIGHTBAR_CMD_ON = 2,
1144 LIGHTBAR_CMD_INIT = 3,
Stephen Barber256ab952015-06-09 13:04:43 +02001145 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001146 LIGHTBAR_CMD_SEQ = 5,
1147 LIGHTBAR_CMD_REG = 6,
Stephen Barber256ab952015-06-09 13:04:43 +02001148 LIGHTBAR_CMD_SET_RGB = 7,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001149 LIGHTBAR_CMD_GET_SEQ = 8,
1150 LIGHTBAR_CMD_DEMO = 9,
Stephen Barber256ab952015-06-09 13:04:43 +02001151 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1152 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Bill Richardson5271db22014-04-30 10:44:08 -07001153 LIGHTBAR_CMD_VERSION = 12,
Stephen Barber256ab952015-06-09 13:04:43 +02001154 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1155 LIGHTBAR_CMD_GET_RGB = 14,
1156 LIGHTBAR_CMD_GET_DEMO = 15,
1157 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1158 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001159 LIGHTBAR_NUM_CMDS
1160};
1161
1162/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001163/* LED control commands */
1164
1165#define EC_CMD_LED_CONTROL 0x29
1166
1167enum ec_led_id {
1168 /* LED to indicate battery state of charge */
1169 EC_LED_ID_BATTERY_LED = 0,
1170 /*
1171 * LED to indicate system power state (on or in suspend).
1172 * May be on power button or on C-panel.
1173 */
1174 EC_LED_ID_POWER_LED,
1175 /* LED on power adapter or its plug */
1176 EC_LED_ID_ADAPTER_LED,
1177
1178 EC_LED_ID_COUNT
1179};
1180
1181/* LED control flags */
1182#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1183#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1184
1185enum ec_led_colors {
1186 EC_LED_COLOR_RED = 0,
1187 EC_LED_COLOR_GREEN,
1188 EC_LED_COLOR_BLUE,
1189 EC_LED_COLOR_YELLOW,
1190 EC_LED_COLOR_WHITE,
1191
1192 EC_LED_COLOR_COUNT
1193};
1194
1195struct ec_params_led_control {
1196 uint8_t led_id; /* Which LED to control */
1197 uint8_t flags; /* Control flags */
1198
1199 uint8_t brightness[EC_LED_COLOR_COUNT];
1200} __packed;
1201
1202struct ec_response_led_control {
1203 /*
1204 * Available brightness value range.
1205 *
1206 * Range 0 means color channel not present.
1207 * Range 1 means on/off control.
1208 * Other values means the LED is control by PWM.
1209 */
1210 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1211} __packed;
1212
1213/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08001214/* Verified boot commands */
1215
1216/*
1217 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1218 * reused for other purposes with version > 0.
1219 */
1220
1221/* Verified boot hash command */
1222#define EC_CMD_VBOOT_HASH 0x2A
1223
1224struct ec_params_vboot_hash {
1225 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1226 uint8_t hash_type; /* enum ec_vboot_hash_type */
1227 uint8_t nonce_size; /* Nonce size; may be 0 */
1228 uint8_t reserved0; /* Reserved; set 0 */
1229 uint32_t offset; /* Offset in flash to hash */
1230 uint32_t size; /* Number of bytes to hash */
1231 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1232} __packed;
1233
1234struct ec_response_vboot_hash {
1235 uint8_t status; /* enum ec_vboot_hash_status */
1236 uint8_t hash_type; /* enum ec_vboot_hash_type */
1237 uint8_t digest_size; /* Size of hash digest in bytes */
1238 uint8_t reserved0; /* Ignore; will be 0 */
1239 uint32_t offset; /* Offset in flash which was hashed */
1240 uint32_t size; /* Number of bytes hashed */
1241 uint8_t hash_digest[64]; /* Hash digest data */
1242} __packed;
1243
1244enum ec_vboot_hash_cmd {
1245 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1246 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1247 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1248 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1249};
1250
1251enum ec_vboot_hash_type {
1252 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1253};
1254
1255enum ec_vboot_hash_status {
1256 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1257 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1258 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1259};
1260
1261/*
1262 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1263 * If one of these is specified, the EC will automatically update offset and
1264 * size to the correct values for the specified image (RO or RW).
1265 */
1266#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1267#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1268
1269/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001270/*
1271 * Motion sense commands. We'll make separate structs for sub-commands with
1272 * different input args, so that we know how much to expect.
1273 */
1274#define EC_CMD_MOTION_SENSE_CMD 0x2B
1275
1276/* Motion sense commands */
1277enum motionsense_command {
1278 /*
1279 * Dump command returns all motion sensor data including motion sense
1280 * module flags and individual sensor flags.
1281 */
1282 MOTIONSENSE_CMD_DUMP = 0,
1283
1284 /*
1285 * Info command returns data describing the details of a given sensor,
1286 * including enum motionsensor_type, enum motionsensor_location, and
1287 * enum motionsensor_chip.
1288 */
1289 MOTIONSENSE_CMD_INFO = 1,
1290
1291 /*
1292 * EC Rate command is a setter/getter command for the EC sampling rate
1293 * of all motion sensors in milliseconds.
1294 */
1295 MOTIONSENSE_CMD_EC_RATE = 2,
1296
1297 /*
1298 * Sensor ODR command is a setter/getter command for the output data
1299 * rate of a specific motion sensor in millihertz.
1300 */
1301 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1302
1303 /*
1304 * Sensor range command is a setter/getter command for the range of
1305 * a specified motion sensor in +/-G's or +/- deg/s.
1306 */
1307 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1308
1309 /*
1310 * Setter/getter command for the keyboard wake angle. When the lid
1311 * angle is greater than this value, keyboard wake is disabled in S3,
1312 * and when the lid angle goes less than this value, keyboard wake is
1313 * enabled. Note, the lid angle measurement is an approximate,
1314 * un-calibrated value, hence the wake angle isn't exact.
1315 */
1316 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1317
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001318 /*
1319 * Returns a single sensor data.
1320 */
1321 MOTIONSENSE_CMD_DATA = 6,
1322
1323 /*
1324 * Perform low level calibration.. On sensors that support it, ask to
1325 * do offset calibration.
1326 */
1327 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1328
1329 /*
1330 * Sensor Offset command is a setter/getter command for the offset used
1331 * for calibration. The offsets can be calculated by the host, or via
1332 * PERFORM_CALIB command.
1333 */
1334 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1335
Bill Richardson5271db22014-04-30 10:44:08 -07001336 /* Number of motionsense sub-commands. */
1337 MOTIONSENSE_NUM_CMDS
1338};
1339
1340enum motionsensor_id {
1341 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1342 EC_MOTION_SENSOR_ACCEL_LID = 1,
1343 EC_MOTION_SENSOR_GYRO = 2,
1344
1345 /*
1346 * Note, if more sensors are added and this count changes, the padding
1347 * in ec_response_motion_sense dump command must be modified.
1348 */
1349 EC_MOTION_SENSOR_COUNT = 3
1350};
1351
1352/* List of motion sensor types. */
1353enum motionsensor_type {
1354 MOTIONSENSE_TYPE_ACCEL = 0,
1355 MOTIONSENSE_TYPE_GYRO = 1,
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001356 MOTIONSENSE_TYPE_MAG = 2,
1357 MOTIONSENSE_TYPE_PROX = 3,
1358 MOTIONSENSE_TYPE_LIGHT = 4,
1359 MOTIONSENSE_TYPE_ACTIVITY = 5,
1360 MOTIONSENSE_TYPE_MAX
Bill Richardson5271db22014-04-30 10:44:08 -07001361};
1362
1363/* List of motion sensor locations. */
1364enum motionsensor_location {
1365 MOTIONSENSE_LOC_BASE = 0,
1366 MOTIONSENSE_LOC_LID = 1,
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001367 MOTIONSENSE_LOC_MAX,
Bill Richardson5271db22014-04-30 10:44:08 -07001368};
1369
1370/* List of motion sensor chips. */
1371enum motionsensor_chip {
1372 MOTIONSENSE_CHIP_KXCJ9 = 0,
1373};
1374
1375/* Module flag masks used for the dump sub-command. */
1376#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1377
1378/* Sensor flag masks used for the dump sub-command. */
1379#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1380
1381/*
1382 * Send this value for the data element to only perform a read. If you
1383 * send any other value, the EC will interpret it as data to set and will
1384 * return the actual value set.
1385 */
1386#define EC_MOTION_SENSE_NO_VALUE -1
1387
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001388#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1389
1390/* Set Calibration information */
1391#define MOTION_SENSE_SET_OFFSET 1
1392
1393struct ec_response_motion_sensor_data {
1394 /* Flags for each sensor. */
1395 uint8_t flags;
1396 /* Sensor number the data comes from */
1397 uint8_t sensor_num;
1398 /* Each sensor is up to 3-axis. */
1399 union {
1400 int16_t data[3];
1401 struct {
1402 uint16_t rsvd;
1403 uint32_t timestamp;
1404 } __packed;
1405 struct {
1406 uint8_t activity; /* motionsensor_activity */
1407 uint8_t state;
1408 int16_t add_info[2];
1409 };
1410 };
1411} __packed;
1412
Bill Richardson5271db22014-04-30 10:44:08 -07001413struct ec_params_motion_sense {
1414 uint8_t cmd;
1415 union {
1416 /* Used for MOTIONSENSE_CMD_DUMP. */
1417 struct {
1418 /* no args */
1419 } dump;
1420
1421 /*
1422 * Used for MOTIONSENSE_CMD_EC_RATE and
1423 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1424 */
1425 struct {
1426 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1427 int16_t data;
1428 } ec_rate, kb_wake_angle;
1429
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001430 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1431 struct {
1432 uint8_t sensor_num;
1433
1434 /*
1435 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1436 * the calibration information in the EC.
1437 * If unset, just retrieve calibration information.
1438 */
1439 uint16_t flags;
1440
1441 /*
1442 * Temperature at calibration, in units of 0.01 C
1443 * 0x8000: invalid / unknown.
1444 * 0x0: 0C
1445 * 0x7fff: +327.67C
1446 */
1447 int16_t temp;
1448
1449 /*
1450 * Offset for calibration.
1451 * Unit:
1452 * Accelerometer: 1/1024 g
1453 * Gyro: 1/1024 deg/s
1454 * Compass: 1/16 uT
1455 */
1456 int16_t offset[3];
1457 } __packed sensor_offset;
1458
Bill Richardson5271db22014-04-30 10:44:08 -07001459 /* Used for MOTIONSENSE_CMD_INFO. */
1460 struct {
Bill Richardson5271db22014-04-30 10:44:08 -07001461 uint8_t sensor_num;
1462 } info;
1463
1464 /*
1465 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1466 * MOTIONSENSE_CMD_SENSOR_RANGE.
1467 */
1468 struct {
1469 /* Should be element of enum motionsensor_id. */
1470 uint8_t sensor_num;
1471
1472 /* Rounding flag, true for round-up, false for down. */
1473 uint8_t roundup;
1474
1475 uint16_t reserved;
1476
1477 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1478 int32_t data;
1479 } sensor_odr, sensor_range;
1480 };
1481} __packed;
1482
1483struct ec_response_motion_sense {
1484 union {
1485 /* Used for MOTIONSENSE_CMD_DUMP. */
1486 struct {
1487 /* Flags representing the motion sensor module. */
1488 uint8_t module_flags;
1489
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001490 /* Number of sensors managed directly by the EC. */
1491 uint8_t sensor_count;
Bill Richardson5271db22014-04-30 10:44:08 -07001492
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001493 /*
1494 * Sensor data is truncated if response_max is too small
1495 * for holding all the data.
1496 */
1497 struct ec_response_motion_sensor_data sensor[0];
Bill Richardson5271db22014-04-30 10:44:08 -07001498 } dump;
1499
1500 /* Used for MOTIONSENSE_CMD_INFO. */
1501 struct {
1502 /* Should be element of enum motionsensor_type. */
1503 uint8_t type;
1504
1505 /* Should be element of enum motionsensor_location. */
1506 uint8_t location;
1507
1508 /* Should be element of enum motionsensor_chip. */
1509 uint8_t chip;
1510 } info;
1511
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001512 /* Used for MOTIONSENSE_CMD_DATA */
1513 struct ec_response_motion_sensor_data data;
1514
Bill Richardson5271db22014-04-30 10:44:08 -07001515 /*
1516 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1517 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1518 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1519 */
1520 struct {
1521 /* Current value of the parameter queried. */
1522 int32_t ret;
1523 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001524
1525 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1526 struct {
1527 int16_t temp;
1528 int16_t offset[3];
1529 } sensor_offset, perform_calib;
Bill Richardson5271db22014-04-30 10:44:08 -07001530 };
1531} __packed;
1532
1533/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08001534/* USB charging control commands */
1535
1536/* Set USB port charging mode */
1537#define EC_CMD_USB_CHARGE_SET_MODE 0x30
1538
1539struct ec_params_usb_charge_set_mode {
1540 uint8_t usb_port_id;
1541 uint8_t mode;
1542} __packed;
1543
1544/*****************************************************************************/
1545/* Persistent storage for host */
1546
1547/* Maximum bytes that can be read/written in a single command */
1548#define EC_PSTORE_SIZE_MAX 64
1549
1550/* Get persistent storage info */
1551#define EC_CMD_PSTORE_INFO 0x40
1552
1553struct ec_response_pstore_info {
1554 /* Persistent storage size, in bytes */
1555 uint32_t pstore_size;
1556 /* Access size; read/write offset and size must be a multiple of this */
1557 uint32_t access_size;
1558} __packed;
1559
1560/*
1561 * Read persistent storage
1562 *
1563 * Response is params.size bytes of data.
1564 */
1565#define EC_CMD_PSTORE_READ 0x41
1566
1567struct ec_params_pstore_read {
1568 uint32_t offset; /* Byte offset to read */
1569 uint32_t size; /* Size to read in bytes */
1570} __packed;
1571
1572/* Write persistent storage */
1573#define EC_CMD_PSTORE_WRITE 0x42
1574
1575struct ec_params_pstore_write {
1576 uint32_t offset; /* Byte offset to write */
1577 uint32_t size; /* Size to write in bytes */
1578 uint8_t data[EC_PSTORE_SIZE_MAX];
1579} __packed;
1580
1581/*****************************************************************************/
1582/* Real-time clock */
1583
1584/* RTC params and response structures */
1585struct ec_params_rtc {
1586 uint32_t time;
1587} __packed;
1588
1589struct ec_response_rtc {
1590 uint32_t time;
1591} __packed;
1592
1593/* These use ec_response_rtc */
1594#define EC_CMD_RTC_GET_VALUE 0x44
1595#define EC_CMD_RTC_GET_ALARM 0x45
1596
1597/* These all use ec_params_rtc */
1598#define EC_CMD_RTC_SET_VALUE 0x46
1599#define EC_CMD_RTC_SET_ALARM 0x47
1600
1601/*****************************************************************************/
1602/* Port80 log access */
1603
Stephen Barber256ab952015-06-09 13:04:43 +02001604/* Maximum entries that can be read/written in a single command */
1605#define EC_PORT80_SIZE_MAX 32
1606
Simon Glassdeaf39e2013-02-25 14:08:36 -08001607/* Get last port80 code from previous boot */
1608#define EC_CMD_PORT80_LAST_BOOT 0x48
Stephen Barber256ab952015-06-09 13:04:43 +02001609#define EC_CMD_PORT80_READ 0x48
1610
1611enum ec_port80_subcmd {
1612 EC_PORT80_GET_INFO = 0,
1613 EC_PORT80_READ_BUFFER,
1614};
1615
1616struct ec_params_port80_read {
1617 uint16_t subcmd;
1618 union {
1619 struct {
1620 uint32_t offset;
1621 uint32_t num_entries;
1622 } read_buffer;
1623 };
1624} __packed;
1625
1626struct ec_response_port80_read {
1627 union {
1628 struct {
1629 uint32_t writes;
1630 uint32_t history_size;
1631 uint32_t last_boot;
1632 } get_info;
1633 struct {
1634 uint16_t codes[EC_PORT80_SIZE_MAX];
1635 } data;
1636 };
1637} __packed;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001638
1639struct ec_response_port80_last_boot {
1640 uint16_t code;
1641} __packed;
1642
1643/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001644/* Thermal engine commands. Note that there are two implementations. We'll
1645 * reuse the command number, but the data and behavior is incompatible.
1646 * Version 0 is what originally shipped on Link.
1647 * Version 1 separates the CPU thermal limits from the fan control.
1648 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001649
Simon Glassdeaf39e2013-02-25 14:08:36 -08001650#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
Bill Richardson5271db22014-04-30 10:44:08 -07001651#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
Simon Glassdeaf39e2013-02-25 14:08:36 -08001652
Bill Richardson5271db22014-04-30 10:44:08 -07001653/* The version 0 structs are opaque. You have to know what they are for
1654 * the get/set commands to make any sense.
1655 */
1656
1657/* Version 0 - set */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001658struct ec_params_thermal_set_threshold {
1659 uint8_t sensor_type;
1660 uint8_t threshold_id;
1661 uint16_t value;
1662} __packed;
1663
Bill Richardson5271db22014-04-30 10:44:08 -07001664/* Version 0 - get */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001665struct ec_params_thermal_get_threshold {
1666 uint8_t sensor_type;
1667 uint8_t threshold_id;
1668} __packed;
1669
1670struct ec_response_thermal_get_threshold {
1671 uint16_t value;
1672} __packed;
1673
Bill Richardson5271db22014-04-30 10:44:08 -07001674
1675/* The version 1 structs are visible. */
1676enum ec_temp_thresholds {
1677 EC_TEMP_THRESH_WARN = 0,
1678 EC_TEMP_THRESH_HIGH,
1679 EC_TEMP_THRESH_HALT,
1680
1681 EC_TEMP_THRESH_COUNT
1682};
1683
1684/* Thermal configuration for one temperature sensor. Temps are in degrees K.
1685 * Zero values will be silently ignored by the thermal task.
1686 */
1687struct ec_thermal_config {
1688 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1689 uint32_t temp_fan_off; /* no active cooling needed */
1690 uint32_t temp_fan_max; /* max active cooling needed */
1691} __packed;
1692
1693/* Version 1 - get config for one sensor. */
1694struct ec_params_thermal_get_threshold_v1 {
1695 uint32_t sensor_num;
1696} __packed;
1697/* This returns a struct ec_thermal_config */
1698
1699/* Version 1 - set config for one sensor.
1700 * Use read-modify-write for best results! */
1701struct ec_params_thermal_set_threshold_v1 {
1702 uint32_t sensor_num;
1703 struct ec_thermal_config cfg;
1704} __packed;
1705/* This returns no data */
1706
1707/****************************************************************************/
1708
Simon Glassdeaf39e2013-02-25 14:08:36 -08001709/* Toggle automatic fan control */
1710#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1711
1712/* Get TMP006 calibration data */
1713#define EC_CMD_TMP006_GET_CALIBRATION 0x53
1714
1715struct ec_params_tmp006_get_calibration {
1716 uint8_t index;
1717} __packed;
1718
1719struct ec_response_tmp006_get_calibration {
1720 float s0;
1721 float b0;
1722 float b1;
1723 float b2;
1724} __packed;
1725
1726/* Set TMP006 calibration data */
1727#define EC_CMD_TMP006_SET_CALIBRATION 0x54
1728
1729struct ec_params_tmp006_set_calibration {
1730 uint8_t index;
1731 uint8_t reserved[3]; /* Reserved; set 0 */
1732 float s0;
1733 float b0;
1734 float b1;
1735 float b2;
1736} __packed;
1737
Bill Richardson5271db22014-04-30 10:44:08 -07001738/* Read raw TMP006 data */
1739#define EC_CMD_TMP006_GET_RAW 0x55
1740
1741struct ec_params_tmp006_get_raw {
1742 uint8_t index;
1743} __packed;
1744
1745struct ec_response_tmp006_get_raw {
1746 int32_t t; /* In 1/100 K */
1747 int32_t v; /* In nV */
1748};
1749
Simon Glassdeaf39e2013-02-25 14:08:36 -08001750/*****************************************************************************/
1751/* MKBP - Matrix KeyBoard Protocol */
1752
1753/*
1754 * Read key state
1755 *
1756 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1757 * expected response size.
1758 */
1759#define EC_CMD_MKBP_STATE 0x60
1760
1761/* Provide information about the matrix : number of rows and columns */
1762#define EC_CMD_MKBP_INFO 0x61
1763
1764struct ec_response_mkbp_info {
1765 uint32_t rows;
1766 uint32_t cols;
1767 uint8_t switches;
1768} __packed;
1769
1770/* Simulate key press */
1771#define EC_CMD_MKBP_SIMULATE_KEY 0x62
1772
1773struct ec_params_mkbp_simulate_key {
1774 uint8_t col;
1775 uint8_t row;
1776 uint8_t pressed;
1777} __packed;
1778
1779/* Configure keyboard scanning */
1780#define EC_CMD_MKBP_SET_CONFIG 0x64
1781#define EC_CMD_MKBP_GET_CONFIG 0x65
1782
1783/* flags */
1784enum mkbp_config_flags {
1785 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
1786};
1787
1788enum mkbp_config_valid {
1789 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
1790 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
1791 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
1792 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
1793 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
1794 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
1795 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
1796};
1797
1798/* Configuration for our key scanning algorithm */
1799struct ec_mkbp_config {
1800 uint32_t valid_mask; /* valid fields */
1801 uint8_t flags; /* some flags (enum mkbp_config_flags) */
1802 uint8_t valid_flags; /* which flags are valid */
1803 uint16_t scan_period_us; /* period between start of scans */
1804 /* revert to interrupt mode after no activity for this long */
1805 uint32_t poll_timeout_us;
1806 /*
1807 * minimum post-scan relax time. Once we finish a scan we check
1808 * the time until we are due to start the next one. If this time is
1809 * shorter this field, we use this instead.
1810 */
1811 uint16_t min_post_scan_delay_us;
1812 /* delay between setting up output and waiting for it to settle */
1813 uint16_t output_settle_us;
1814 uint16_t debounce_down_us; /* time for debounce on key down */
1815 uint16_t debounce_up_us; /* time for debounce on key up */
1816 /* maximum depth to allow for fifo (0 = no keyscan output) */
1817 uint8_t fifo_max_depth;
1818} __packed;
1819
1820struct ec_params_mkbp_set_config {
1821 struct ec_mkbp_config config;
1822} __packed;
1823
1824struct ec_response_mkbp_get_config {
1825 struct ec_mkbp_config config;
1826} __packed;
1827
1828/* Run the key scan emulation */
1829#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
1830
1831enum ec_keyscan_seq_cmd {
1832 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
1833 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
1834 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
1835 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
1836 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
1837};
1838
1839enum ec_collect_flags {
1840 /*
1841 * Indicates this scan was processed by the EC. Due to timing, some
1842 * scans may be skipped.
1843 */
1844 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
1845};
1846
1847struct ec_collect_item {
1848 uint8_t flags; /* some flags (enum ec_collect_flags) */
1849};
1850
1851struct ec_params_keyscan_seq_ctrl {
1852 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
1853 union {
1854 struct {
1855 uint8_t active; /* still active */
1856 uint8_t num_items; /* number of items */
1857 /* Current item being presented */
1858 uint8_t cur_item;
1859 } status;
1860 struct {
1861 /*
1862 * Absolute time for this scan, measured from the
1863 * start of the sequence.
1864 */
1865 uint32_t time_us;
1866 uint8_t scan[0]; /* keyscan data */
1867 } add;
1868 struct {
1869 uint8_t start_item; /* First item to return */
1870 uint8_t num_items; /* Number of items to return */
1871 } collect;
1872 };
1873} __packed;
1874
1875struct ec_result_keyscan_seq_ctrl {
1876 union {
1877 struct {
1878 uint8_t num_items; /* Number of items */
1879 /* Data for each item */
1880 struct ec_collect_item item[0];
1881 } collect;
1882 };
1883} __packed;
1884
Vic Yang6f1d9122016-08-10 19:05:24 +02001885/*
1886 * Command for retrieving the next pending MKBP event from the EC device
1887 *
1888 * The device replies with UNAVAILABLE if there aren't any pending events.
1889 */
1890#define EC_CMD_GET_NEXT_EVENT 0x67
1891
1892enum ec_mkbp_event {
1893 /* Keyboard matrix changed. The event data is the new matrix state. */
1894 EC_MKBP_EVENT_KEY_MATRIX = 0,
1895
1896 /* New host event. The event data is 4 bytes of host event flags. */
1897 EC_MKBP_EVENT_HOST_EVENT = 1,
1898
1899 /* New Sensor FIFO data. The event data is fifo_info structure. */
1900 EC_MKBP_EVENT_SENSOR_FIFO = 2,
1901
1902 /* Number of MKBP events */
1903 EC_MKBP_EVENT_COUNT,
1904};
1905
1906union ec_response_get_next_data {
1907 uint8_t key_matrix[13];
1908
1909 /* Unaligned */
1910 uint32_t host_event;
1911} __packed;
1912
1913struct ec_response_get_next_event {
1914 uint8_t event_type;
1915 /* Followed by event data if any */
1916 union ec_response_get_next_data data;
1917} __packed;
1918
Simon Glassdeaf39e2013-02-25 14:08:36 -08001919/*****************************************************************************/
1920/* Temperature sensor commands */
1921
1922/* Read temperature sensor info */
1923#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
1924
1925struct ec_params_temp_sensor_get_info {
1926 uint8_t id;
1927} __packed;
1928
1929struct ec_response_temp_sensor_get_info {
1930 char sensor_name[32];
1931 uint8_t sensor_type;
1932} __packed;
1933
1934/*****************************************************************************/
1935
1936/*
1937 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
1938 * commands accidentally sent to the wrong interface. See the ACPI section
1939 * below.
1940 */
1941
1942/*****************************************************************************/
1943/* Host event commands */
1944
1945/*
1946 * Host event mask params and response structures, shared by all of the host
1947 * event commands below.
1948 */
1949struct ec_params_host_event_mask {
1950 uint32_t mask;
1951} __packed;
1952
1953struct ec_response_host_event_mask {
1954 uint32_t mask;
1955} __packed;
1956
1957/* These all use ec_response_host_event_mask */
1958#define EC_CMD_HOST_EVENT_GET_B 0x87
1959#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
1960#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
1961#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
1962
1963/* These all use ec_params_host_event_mask */
1964#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
1965#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
1966#define EC_CMD_HOST_EVENT_CLEAR 0x8c
1967#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
1968#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
1969
1970/*****************************************************************************/
1971/* Switch commands */
1972
1973/* Enable/disable LCD backlight */
1974#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
1975
1976struct ec_params_switch_enable_backlight {
1977 uint8_t enabled;
1978} __packed;
1979
1980/* Enable/disable WLAN/Bluetooth */
1981#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
Bill Richardson5271db22014-04-30 10:44:08 -07001982#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Simon Glassdeaf39e2013-02-25 14:08:36 -08001983
Bill Richardson5271db22014-04-30 10:44:08 -07001984/* Version 0 params; no response */
1985struct ec_params_switch_enable_wireless_v0 {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001986 uint8_t enabled;
1987} __packed;
1988
Bill Richardson5271db22014-04-30 10:44:08 -07001989/* Version 1 params */
1990struct ec_params_switch_enable_wireless_v1 {
1991 /* Flags to enable now */
1992 uint8_t now_flags;
1993
1994 /* Which flags to copy from now_flags */
1995 uint8_t now_mask;
1996
1997 /*
1998 * Flags to leave enabled in S3, if they're on at the S0->S3
1999 * transition. (Other flags will be disabled by the S0->S3
2000 * transition.)
2001 */
2002 uint8_t suspend_flags;
2003
2004 /* Which flags to copy from suspend_flags */
2005 uint8_t suspend_mask;
2006} __packed;
2007
2008/* Version 1 response */
2009struct ec_response_switch_enable_wireless_v1 {
2010 /* Flags to enable now */
2011 uint8_t now_flags;
2012
2013 /* Flags to leave enabled in S3 */
2014 uint8_t suspend_flags;
2015} __packed;
2016
Simon Glassdeaf39e2013-02-25 14:08:36 -08002017/*****************************************************************************/
2018/* GPIO commands. Only available on EC if write protect has been disabled. */
2019
2020/* Set GPIO output value */
2021#define EC_CMD_GPIO_SET 0x92
2022
2023struct ec_params_gpio_set {
2024 char name[32];
2025 uint8_t val;
2026} __packed;
2027
2028/* Get GPIO value */
2029#define EC_CMD_GPIO_GET 0x93
2030
Stephen Barber256ab952015-06-09 13:04:43 +02002031/* Version 0 of input params and response */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002032struct ec_params_gpio_get {
2033 char name[32];
2034} __packed;
2035struct ec_response_gpio_get {
2036 uint8_t val;
2037} __packed;
2038
Stephen Barber256ab952015-06-09 13:04:43 +02002039/* Version 1 of input params and response */
2040struct ec_params_gpio_get_v1 {
2041 uint8_t subcmd;
2042 union {
2043 struct {
2044 char name[32];
2045 } get_value_by_name;
2046 struct {
2047 uint8_t index;
2048 } get_info;
2049 };
2050} __packed;
2051
2052struct ec_response_gpio_get_v1 {
2053 union {
2054 struct {
2055 uint8_t val;
2056 } get_value_by_name, get_count;
2057 struct {
2058 uint8_t val;
2059 char name[32];
2060 uint32_t flags;
2061 } get_info;
2062 };
2063} __packed;
2064
2065enum gpio_get_subcmd {
2066 EC_GPIO_GET_BY_NAME = 0,
2067 EC_GPIO_GET_COUNT = 1,
2068 EC_GPIO_GET_INFO = 2,
2069};
2070
Simon Glassdeaf39e2013-02-25 14:08:36 -08002071/*****************************************************************************/
2072/* I2C commands. Only available when flash write protect is unlocked. */
2073
Bill Richardson5271db22014-04-30 10:44:08 -07002074/*
2075 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2076 * removed soon. Use EC_CMD_I2C_XFER instead.
2077 */
2078
Simon Glassdeaf39e2013-02-25 14:08:36 -08002079/* Read I2C bus */
2080#define EC_CMD_I2C_READ 0x94
2081
2082struct ec_params_i2c_read {
Bill Richardson5271db22014-04-30 10:44:08 -07002083 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002084 uint8_t read_size; /* Either 8 or 16. */
2085 uint8_t port;
2086 uint8_t offset;
2087} __packed;
2088struct ec_response_i2c_read {
2089 uint16_t data;
2090} __packed;
2091
2092/* Write I2C bus */
2093#define EC_CMD_I2C_WRITE 0x95
2094
2095struct ec_params_i2c_write {
2096 uint16_t data;
Bill Richardson5271db22014-04-30 10:44:08 -07002097 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002098 uint8_t write_size; /* Either 8 or 16. */
2099 uint8_t port;
2100 uint8_t offset;
2101} __packed;
2102
2103/*****************************************************************************/
2104/* Charge state commands. Only available when flash write protect unlocked. */
2105
Bill Richardson5271db22014-04-30 10:44:08 -07002106/* Force charge state machine to stop charging the battery or force it to
2107 * discharge the battery.
2108 */
2109#define EC_CMD_CHARGE_CONTROL 0x96
2110#define EC_VER_CHARGE_CONTROL 1
Simon Glassdeaf39e2013-02-25 14:08:36 -08002111
Bill Richardson5271db22014-04-30 10:44:08 -07002112enum ec_charge_control_mode {
2113 CHARGE_CONTROL_NORMAL = 0,
2114 CHARGE_CONTROL_IDLE,
2115 CHARGE_CONTROL_DISCHARGE,
2116};
2117
2118struct ec_params_charge_control {
2119 uint32_t mode; /* enum charge_control_mode */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002120} __packed;
2121
2122/*****************************************************************************/
2123/* Console commands. Only available when flash write protect is unlocked. */
2124
2125/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2126#define EC_CMD_CONSOLE_SNAPSHOT 0x97
2127
2128/*
2129 * Read next chunk of data from saved snapshot.
2130 *
2131 * Response is null-terminated string. Empty string, if there is no more
2132 * remaining output.
2133 */
2134#define EC_CMD_CONSOLE_READ 0x98
2135
2136/*****************************************************************************/
2137
2138/*
Stephen Barber256ab952015-06-09 13:04:43 +02002139 * Cut off battery power immediately or after the host has shut down.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002140 *
Stephen Barber256ab952015-06-09 13:04:43 +02002141 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2142 * EC_RES_SUCCESS if the command was successful.
2143 * EC_RES_ERROR if the cut off command failed.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002144 */
Stephen Barber256ab952015-06-09 13:04:43 +02002145
Simon Glassdeaf39e2013-02-25 14:08:36 -08002146#define EC_CMD_BATTERY_CUT_OFF 0x99
2147
Stephen Barber256ab952015-06-09 13:04:43 +02002148#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2149
2150struct ec_params_battery_cutoff {
2151 uint8_t flags;
2152} __packed;
2153
Simon Glassdeaf39e2013-02-25 14:08:36 -08002154/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07002155/* USB port mux control. */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002156
2157/*
Bill Richardson5271db22014-04-30 10:44:08 -07002158 * Switch USB mux or return to automatic switching.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002159 */
Bill Richardson5271db22014-04-30 10:44:08 -07002160#define EC_CMD_USB_MUX 0x9a
2161
2162struct ec_params_usb_mux {
2163 uint8_t mux;
2164} __packed;
2165
2166/*****************************************************************************/
2167/* LDOs / FETs control. */
2168
2169enum ec_ldo_state {
2170 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2171 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2172};
2173
2174/*
2175 * Switch on/off a LDO.
2176 */
2177#define EC_CMD_LDO_SET 0x9b
2178
2179struct ec_params_ldo_set {
2180 uint8_t index;
2181 uint8_t state;
2182} __packed;
2183
2184/*
2185 * Get LDO state.
2186 */
2187#define EC_CMD_LDO_GET 0x9c
2188
2189struct ec_params_ldo_get {
2190 uint8_t index;
2191} __packed;
2192
2193struct ec_response_ldo_get {
2194 uint8_t state;
2195} __packed;
2196
2197/*****************************************************************************/
2198/* Power info. */
2199
2200/*
2201 * Get power info.
2202 */
2203#define EC_CMD_POWER_INFO 0x9d
2204
2205struct ec_response_power_info {
2206 uint32_t usb_dev_type;
2207 uint16_t voltage_ac;
2208 uint16_t voltage_system;
2209 uint16_t current_system;
2210 uint16_t usb_current_limit;
2211} __packed;
2212
2213/*****************************************************************************/
2214/* I2C passthru command */
2215
2216#define EC_CMD_I2C_PASSTHRU 0x9e
2217
Bill Richardson5271db22014-04-30 10:44:08 -07002218/* Read data; if not present, message is a write */
2219#define EC_I2C_FLAG_READ (1 << 15)
2220
2221/* Mask for address */
2222#define EC_I2C_ADDR_MASK 0x3ff
2223
2224#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2225#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2226
2227/* Any error */
2228#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2229
2230struct ec_params_i2c_passthru_msg {
2231 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2232 uint16_t len; /* Number of bytes to read or write */
2233} __packed;
2234
2235struct ec_params_i2c_passthru {
2236 uint8_t port; /* I2C port number */
2237 uint8_t num_msgs; /* Number of messages */
2238 struct ec_params_i2c_passthru_msg msg[];
2239 /* Data to write for all messages is concatenated here */
2240} __packed;
2241
2242struct ec_response_i2c_passthru {
2243 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2244 uint8_t num_msgs; /* Number of messages processed */
2245 uint8_t data[]; /* Data read by messages concatenated here */
2246} __packed;
2247
2248/*****************************************************************************/
2249/* Power button hang detect */
2250
2251#define EC_CMD_HANG_DETECT 0x9f
2252
2253/* Reasons to start hang detection timer */
2254/* Power button pressed */
2255#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2256
2257/* Lid closed */
2258#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2259
2260 /* Lid opened */
2261#define EC_HANG_START_ON_LID_OPEN (1 << 2)
2262
2263/* Start of AP S3->S0 transition (booting or resuming from suspend) */
2264#define EC_HANG_START_ON_RESUME (1 << 3)
2265
2266/* Reasons to cancel hang detection */
2267
2268/* Power button released */
2269#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2270
2271/* Any host command from AP received */
2272#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2273
2274/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2275#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2276
2277/*
2278 * If this flag is set, all the other fields are ignored, and the hang detect
2279 * timer is started. This provides the AP a way to start the hang timer
2280 * without reconfiguring any of the other hang detect settings. Note that
2281 * you must previously have configured the timeouts.
2282 */
2283#define EC_HANG_START_NOW (1 << 30)
2284
2285/*
2286 * If this flag is set, all the other fields are ignored (including
2287 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2288 * without reconfiguring any of the other hang detect settings.
2289 */
2290#define EC_HANG_STOP_NOW (1 << 31)
2291
2292struct ec_params_hang_detect {
2293 /* Flags; see EC_HANG_* */
2294 uint32_t flags;
2295
2296 /* Timeout in msec before generating host event, if enabled */
2297 uint16_t host_event_timeout_msec;
2298
2299 /* Timeout in msec before generating warm reboot, if enabled */
2300 uint16_t warm_reboot_timeout_msec;
2301} __packed;
2302
2303/*****************************************************************************/
2304/* Commands for battery charging */
2305
2306/*
2307 * This is the single catch-all host command to exchange data regarding the
2308 * charge state machine (v2 and up).
2309 */
2310#define EC_CMD_CHARGE_STATE 0xa0
2311
2312/* Subcommands for this host command */
2313enum charge_state_command {
2314 CHARGE_STATE_CMD_GET_STATE,
2315 CHARGE_STATE_CMD_GET_PARAM,
2316 CHARGE_STATE_CMD_SET_PARAM,
2317 CHARGE_STATE_NUM_CMDS
2318};
2319
2320/*
2321 * Known param numbers are defined here. Ranges are reserved for board-specific
2322 * params, which are handled by the particular implementations.
2323 */
2324enum charge_state_params {
2325 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2326 CS_PARAM_CHG_CURRENT, /* charger current limit */
2327 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2328 CS_PARAM_CHG_STATUS, /* charger-specific status */
2329 CS_PARAM_CHG_OPTION, /* charger-specific options */
2330 /* How many so far? */
2331 CS_NUM_BASE_PARAMS,
2332
2333 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2334 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2335 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2336
2337 /* Other custom param ranges go here... */
2338};
2339
2340struct ec_params_charge_state {
2341 uint8_t cmd; /* enum charge_state_command */
2342 union {
2343 struct {
2344 /* no args */
2345 } get_state;
2346
2347 struct {
2348 uint32_t param; /* enum charge_state_param */
2349 } get_param;
2350
2351 struct {
2352 uint32_t param; /* param to set */
2353 uint32_t value; /* value to set */
2354 } set_param;
2355 };
2356} __packed;
2357
2358struct ec_response_charge_state {
2359 union {
2360 struct {
2361 int ac;
2362 int chg_voltage;
2363 int chg_current;
2364 int chg_input_current;
2365 int batt_state_of_charge;
2366 } get_state;
2367
2368 struct {
2369 uint32_t value;
2370 } get_param;
2371 struct {
2372 /* no return values */
2373 } set_param;
2374 };
2375} __packed;
2376
Simon Glassdeaf39e2013-02-25 14:08:36 -08002377
2378/*
2379 * Set maximum battery charging current.
2380 */
2381#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2382
2383struct ec_params_current_limit {
Bill Richardson5271db22014-04-30 10:44:08 -07002384 uint32_t limit; /* in mA */
2385} __packed;
2386
2387/*
2388 * Set maximum external power current.
2389 */
2390#define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
2391
2392struct ec_params_ext_power_current_limit {
2393 uint32_t limit; /* in mA */
2394} __packed;
2395
2396/*****************************************************************************/
2397/* Smart battery pass-through */
2398
2399/* Get / Set 16-bit smart battery registers */
2400#define EC_CMD_SB_READ_WORD 0xb0
2401#define EC_CMD_SB_WRITE_WORD 0xb1
2402
2403/* Get / Set string smart battery parameters
2404 * formatted as SMBUS "block".
2405 */
2406#define EC_CMD_SB_READ_BLOCK 0xb2
2407#define EC_CMD_SB_WRITE_BLOCK 0xb3
2408
2409struct ec_params_sb_rd {
2410 uint8_t reg;
2411} __packed;
2412
2413struct ec_response_sb_rd_word {
2414 uint16_t value;
2415} __packed;
2416
2417struct ec_params_sb_wr_word {
2418 uint8_t reg;
2419 uint16_t value;
2420} __packed;
2421
2422struct ec_response_sb_rd_block {
2423 uint8_t data[32];
2424} __packed;
2425
2426struct ec_params_sb_wr_block {
2427 uint8_t reg;
2428 uint16_t data[32];
Simon Glassdeaf39e2013-02-25 14:08:36 -08002429} __packed;
2430
2431/*****************************************************************************/
Stephen Barber256ab952015-06-09 13:04:43 +02002432/* Battery vendor parameters
2433 *
2434 * Get or set vendor-specific parameters in the battery. Implementations may
2435 * differ between boards or batteries. On a set operation, the response
2436 * contains the actual value set, which may be rounded or clipped from the
2437 * requested value.
2438 */
2439
2440#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2441
2442enum ec_battery_vendor_param_mode {
2443 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2444 BATTERY_VENDOR_PARAM_MODE_SET,
2445};
2446
2447struct ec_params_battery_vendor_param {
2448 uint32_t param;
2449 uint32_t value;
2450 uint8_t mode;
2451} __packed;
2452
2453struct ec_response_battery_vendor_param {
2454 uint32_t value;
2455} __packed;
2456
2457/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08002458/* System commands */
2459
2460/*
Bill Richardson5271db22014-04-30 10:44:08 -07002461 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2462 * necessarily reboot the EC. Rename to "image" or something similar?
Simon Glassdeaf39e2013-02-25 14:08:36 -08002463 */
2464#define EC_CMD_REBOOT_EC 0xd2
2465
2466/* Command */
2467enum ec_reboot_cmd {
2468 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2469 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2470 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2471 /* (command 3 was jump to RW-B) */
2472 EC_REBOOT_COLD = 4, /* Cold-reboot */
2473 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2474 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
2475};
2476
2477/* Flags for ec_params_reboot_ec.reboot_flags */
2478#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2479#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2480
2481struct ec_params_reboot_ec {
2482 uint8_t cmd; /* enum ec_reboot_cmd */
2483 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2484} __packed;
2485
2486/*
2487 * Get information on last EC panic.
2488 *
2489 * Returns variable-length platform-dependent panic information. See panic.h
2490 * for details.
2491 */
2492#define EC_CMD_GET_PANIC_INFO 0xd3
2493
2494/*****************************************************************************/
2495/*
2496 * ACPI commands
2497 *
2498 * These are valid ONLY on the ACPI command/data port.
2499 */
2500
2501/*
2502 * ACPI Read Embedded Controller
2503 *
2504 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2505 *
2506 * Use the following sequence:
2507 *
2508 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
2509 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2510 * - Write address to EC_LPC_ADDR_ACPI_DATA
2511 * - Wait for EC_LPC_CMDR_DATA bit to set
2512 * - Read value from EC_LPC_ADDR_ACPI_DATA
2513 */
2514#define EC_CMD_ACPI_READ 0x80
2515
2516/*
2517 * ACPI Write Embedded Controller
2518 *
2519 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
2520 *
2521 * Use the following sequence:
2522 *
2523 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
2524 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2525 * - Write address to EC_LPC_ADDR_ACPI_DATA
2526 * - Wait for EC_LPC_CMDR_PENDING bit to clear
2527 * - Write value to EC_LPC_ADDR_ACPI_DATA
2528 */
2529#define EC_CMD_ACPI_WRITE 0x81
2530
2531/*
2532 * ACPI Query Embedded Controller
2533 *
2534 * This clears the lowest-order bit in the currently pending host events, and
2535 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
2536 * event 0x80000000 = 32), or 0 if no event was pending.
2537 */
2538#define EC_CMD_ACPI_QUERY_EVENT 0x84
2539
2540/* Valid addresses in ACPI memory space, for read/write commands */
Bill Richardson5271db22014-04-30 10:44:08 -07002541
Simon Glassdeaf39e2013-02-25 14:08:36 -08002542/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
2543#define EC_ACPI_MEM_VERSION 0x00
2544/*
2545 * Test location; writing value here updates test compliment byte to (0xff -
2546 * value).
2547 */
2548#define EC_ACPI_MEM_TEST 0x01
2549/* Test compliment; writes here are ignored. */
2550#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
Bill Richardson5271db22014-04-30 10:44:08 -07002551
Simon Glassdeaf39e2013-02-25 14:08:36 -08002552/* Keyboard backlight brightness percent (0 - 100) */
2553#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
Bill Richardson5271db22014-04-30 10:44:08 -07002554/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
2555#define EC_ACPI_MEM_FAN_DUTY 0x04
2556
2557/*
2558 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
2559 * independent thresholds attached to them. The current value of the ID
2560 * register determines which sensor is affected by the THRESHOLD and COMMIT
2561 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
2562 * as the memory-mapped sensors. The COMMIT register applies those settings.
2563 *
2564 * The spec does not mandate any way to read back the threshold settings
2565 * themselves, but when a threshold is crossed the AP needs a way to determine
2566 * which sensor(s) are responsible. Each reading of the ID register clears and
2567 * returns one sensor ID that has crossed one of its threshold (in either
2568 * direction) since the last read. A value of 0xFF means "no new thresholds
2569 * have tripped". Setting or enabling the thresholds for a sensor will clear
2570 * the unread event count for that sensor.
2571 */
2572#define EC_ACPI_MEM_TEMP_ID 0x05
2573#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
2574#define EC_ACPI_MEM_TEMP_COMMIT 0x07
2575/*
2576 * Here are the bits for the COMMIT register:
2577 * bit 0 selects the threshold index for the chosen sensor (0/1)
2578 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
2579 * Each write to the commit register affects one threshold.
2580 */
2581#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
2582#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
2583/*
2584 * Example:
2585 *
2586 * Set the thresholds for sensor 2 to 50 C and 60 C:
2587 * write 2 to [0x05] -- select temp sensor 2
2588 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
2589 * write 0x2 to [0x07] -- enable threshold 0 with this value
2590 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
2591 * write 0x3 to [0x07] -- enable threshold 1 with this value
2592 *
2593 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
2594 * write 2 to [0x05] -- select temp sensor 2
2595 * write 0x1 to [0x07] -- disable threshold 1
2596 */
2597
2598/* DPTF battery charging current limit */
2599#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
2600
2601/* Charging limit is specified in 64 mA steps */
2602#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
2603/* Value to disable DPTF battery charging limit */
2604#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Simon Glassdeaf39e2013-02-25 14:08:36 -08002605
2606/* Current version of ACPI memory address space */
2607#define EC_ACPI_MEM_VERSION_CURRENT 1
2608
2609
2610/*****************************************************************************/
2611/*
2612 * Special commands
2613 *
2614 * These do not follow the normal rules for commands. See each command for
2615 * details.
2616 */
2617
2618/*
2619 * Reboot NOW
2620 *
2621 * This command will work even when the EC LPC interface is busy, because the
2622 * reboot command is processed at interrupt level. Note that when the EC
2623 * reboots, the host will reboot too, so there is no response to this command.
2624 *
2625 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
2626 */
2627#define EC_CMD_REBOOT 0xd1 /* Think "die" */
2628
2629/*
2630 * Resend last response (not supported on LPC).
2631 *
2632 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
2633 * there was no previous command, or the previous command's response was too
2634 * big to save.
2635 */
2636#define EC_CMD_RESEND_RESPONSE 0xdb
2637
2638/*
2639 * This header byte on a command indicate version 0. Any header byte less
2640 * than this means that we are talking to an old EC which doesn't support
2641 * versioning. In that case, we assume version 0.
2642 *
2643 * Header bytes greater than this indicate a later version. For example,
2644 * EC_CMD_VERSION0 + 1 means we are using version 1.
2645 *
Bill Richardson5271db22014-04-30 10:44:08 -07002646 * The old EC interface must not use commands 0xdc or higher.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002647 */
2648#define EC_CMD_VERSION0 0xdc
2649
2650#endif /* !__ACPI__ */
2651
Bill Richardson5271db22014-04-30 10:44:08 -07002652/*****************************************************************************/
2653/*
Stephen Barber256ab952015-06-09 13:04:43 +02002654 * PD commands
2655 *
2656 * These commands are for PD MCU communication.
2657 */
2658
2659/* EC to PD MCU exchange status command */
2660#define EC_CMD_PD_EXCHANGE_STATUS 0x100
2661
2662/* Status of EC being sent to PD */
2663struct ec_params_pd_status {
2664 int8_t batt_soc; /* battery state of charge */
2665} __packed;
2666
2667/* Status of PD being sent back to EC */
2668struct ec_response_pd_status {
2669 int8_t status; /* PD MCU status */
2670 uint32_t curr_lim_ma; /* input current limit */
2671} __packed;
2672
2673/* Set USB type-C port role and muxes */
2674#define EC_CMD_USB_PD_CONTROL 0x101
2675
2676enum usb_pd_control_role {
2677 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
2678 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
2679 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
2680 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
2681 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
2682};
2683
2684enum usb_pd_control_mux {
2685 USB_PD_CTRL_MUX_NO_CHANGE = 0,
2686 USB_PD_CTRL_MUX_NONE = 1,
2687 USB_PD_CTRL_MUX_USB = 2,
2688 USB_PD_CTRL_MUX_DP = 3,
2689 USB_PD_CTRL_MUX_DOCK = 4,
2690 USB_PD_CTRL_MUX_AUTO = 5,
2691};
2692
2693struct ec_params_usb_pd_control {
2694 uint8_t port;
2695 uint8_t role;
2696 uint8_t mux;
2697} __packed;
2698
2699/*****************************************************************************/
2700/*
2701 * Passthru commands
2702 *
2703 * Some platforms have sub-processors chained to each other. For example.
2704 *
2705 * AP <--> EC <--> PD MCU
2706 *
2707 * The top 2 bits of the command number are used to indicate which device the
2708 * command is intended for. Device 0 is always the device receiving the
2709 * command; other device mapping is board-specific.
2710 *
2711 * When a device receives a command to be passed to a sub-processor, it passes
2712 * it on with the device number set back to 0. This allows the sub-processor
2713 * to remain blissfully unaware of whether the command originated on the next
2714 * device up the chain, or was passed through from the AP.
2715 *
2716 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
2717 * AP sends command 0x4002 to the EC
2718 * EC sends command 0x0002 to the PD MCU
2719 * EC forwards PD MCU response back to the AP
2720 */
2721
2722/* Offset and max command number for sub-device n */
2723#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
2724#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
2725
2726/*****************************************************************************/
2727/*
Bill Richardson5271db22014-04-30 10:44:08 -07002728 * Deprecated constants. These constants have been renamed for clarity. The
2729 * meaning and size has not changed. Programs that use the old names should
2730 * switch to the new names soon, as the old names may not be carried forward
2731 * forever.
2732 */
2733#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
2734#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
2735#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
2736
Simon Glassdeaf39e2013-02-25 14:08:36 -08002737#endif /* __CROS_EC_COMMANDS_H */