blob: 114614e20e4dc634150bb231b8b9540a11a4abd5 [file] [log] [blame]
Thomas Gleixner9c92ab62019-05-29 07:17:56 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002/*
3 * Host communication command constants for ChromeOS EC
4 *
5 * Copyright (C) 2012 Google, Inc
6 *
Simon Glassdeaf39e2013-02-25 14:08:36 -08007 * The ChromeOS EC multi function device is used to mux all the requests
8 * to the EC device for its multiple features: keyboard controller,
9 * battery charging and regulator control, firmware update.
10 *
11 * NOTE: This file is copied verbatim from the ChromeOS EC Open Source
12 * project in an attempt to make future updates easy to make.
13 */
14
15#ifndef __CROS_EC_COMMANDS_H
16#define __CROS_EC_COMMANDS_H
17
18/*
Bill Richardson5271db22014-04-30 10:44:08 -070019 * Current version of this protocol
Simon Glassdeaf39e2013-02-25 14:08:36 -080020 *
Bill Richardson5271db22014-04-30 10:44:08 -070021 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
22 * determined in other ways. Remove this once the kernel code no longer
23 * depends on it.
Simon Glassdeaf39e2013-02-25 14:08:36 -080024 */
Simon Glassdeaf39e2013-02-25 14:08:36 -080025#define EC_PROTO_VERSION 0x00000002
26
27/* Command version mask */
28#define EC_VER_MASK(version) (1UL << (version))
29
30/* I/O addresses for ACPI commands */
31#define EC_LPC_ADDR_ACPI_DATA 0x62
32#define EC_LPC_ADDR_ACPI_CMD 0x66
33
34/* I/O addresses for host command */
35#define EC_LPC_ADDR_HOST_DATA 0x200
36#define EC_LPC_ADDR_HOST_CMD 0x204
37
38/* I/O addresses for host command args and params */
Bill Richardson5271db22014-04-30 10:44:08 -070039/* Protocol version 2 */
40#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
41#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
42 * EC_PROTO2_MAX_PARAM_SIZE */
43/* Protocol version 3 */
44#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
45#define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
Simon Glassdeaf39e2013-02-25 14:08:36 -080046
Bill Richardson5271db22014-04-30 10:44:08 -070047/* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
48 * and they tell the kernel that so we have to think of it as two parts. */
49#define EC_HOST_CMD_REGION0 0x800
50#define EC_HOST_CMD_REGION1 0x880
51#define EC_HOST_CMD_REGION_SIZE 0x80
Simon Glassdeaf39e2013-02-25 14:08:36 -080052
53/* EC command register bit functions */
54#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
55#define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
56#define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
57#define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
58#define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
59#define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
60#define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
61
62#define EC_LPC_ADDR_MEMMAP 0x900
63#define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
64#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
65
66/* The offset address of each type of data in mapped memory. */
Bill Richardson5271db22014-04-30 10:44:08 -070067#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
68#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
69#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
70#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
Simon Glassdeaf39e2013-02-25 14:08:36 -080071#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
72#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
73#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
74#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
75#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
Bill Richardson5271db22014-04-30 10:44:08 -070076#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
77/* Unused 0x28 - 0x2f */
78#define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
79/* Unused 0x31 - 0x33 */
80#define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
81/* Reserve 0x38 - 0x3f for additional host event-related stuff */
82/* Battery values are all 32 bits */
Simon Glassdeaf39e2013-02-25 14:08:36 -080083#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
84#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
85#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
86#define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
87#define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
88#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
89#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
90#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
Bill Richardson5271db22014-04-30 10:44:08 -070091/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
Simon Glassdeaf39e2013-02-25 14:08:36 -080092#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
93#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
94#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
95#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
Bill Richardson5271db22014-04-30 10:44:08 -070096#define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
97/* Unused 0x84 - 0x8f */
98#define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
99/* Unused 0x91 */
100#define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
101#define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
102/* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
103
104
105/* Define the format of the accelerometer mapped memory status byte. */
106#define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
107#define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
108#define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
Simon Glassdeaf39e2013-02-25 14:08:36 -0800109
110/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
111#define EC_TEMP_SENSOR_ENTRIES 16
112/*
113 * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
114 *
115 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
116 */
117#define EC_TEMP_SENSOR_B_ENTRIES 8
Bill Richardson5271db22014-04-30 10:44:08 -0700118
119/* Special values for mapped temperature sensors */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800120#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
121#define EC_TEMP_SENSOR_ERROR 0xfe
122#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
123#define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
124/*
125 * The offset of temperature value stored in mapped memory. This allows
126 * reporting a temperature range of 200K to 454K = -73C to 181C.
127 */
128#define EC_TEMP_SENSOR_OFFSET 200
129
Bill Richardson5271db22014-04-30 10:44:08 -0700130/*
131 * Number of ALS readings at EC_MEMMAP_ALS
132 */
133#define EC_ALS_ENTRIES 2
134
135/*
136 * The default value a temperature sensor will return when it is present but
137 * has not been read this boot. This is a reasonable number to avoid
138 * triggering alarms on the host.
139 */
140#define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
141
Simon Glassdeaf39e2013-02-25 14:08:36 -0800142#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
143#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
144#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
145
146/* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
147#define EC_BATT_FLAG_AC_PRESENT 0x01
148#define EC_BATT_FLAG_BATT_PRESENT 0x02
149#define EC_BATT_FLAG_DISCHARGING 0x04
150#define EC_BATT_FLAG_CHARGING 0x08
151#define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
152
153/* Switch flags at EC_MEMMAP_SWITCHES */
154#define EC_SWITCH_LID_OPEN 0x01
155#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
156#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
Bill Richardson5271db22014-04-30 10:44:08 -0700157/* Was recovery requested via keyboard; now unused. */
158#define EC_SWITCH_IGNORE1 0x08
Simon Glassdeaf39e2013-02-25 14:08:36 -0800159/* Recovery requested via dedicated signal (from servo board) */
160#define EC_SWITCH_DEDICATED_RECOVERY 0x10
161/* Was fake developer mode switch; now unused. Remove in next refactor. */
162#define EC_SWITCH_IGNORE0 0x20
163
164/* Host command interface flags */
165/* Host command interface supports LPC args (LPC interface only) */
166#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
Bill Richardson5271db22014-04-30 10:44:08 -0700167/* Host command interface supports version 3 protocol */
168#define EC_HOST_CMD_FLAG_VERSION_3 0x02
Simon Glassdeaf39e2013-02-25 14:08:36 -0800169
170/* Wireless switch flags */
Bill Richardson5271db22014-04-30 10:44:08 -0700171#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
172#define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
173#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
174#define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
175#define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800176
177/*
178 * This header file is used in coreboot both in C and ACPI code. The ACPI code
179 * is pre-processed to handle constants but the ASL compiler is unable to
180 * handle actual C code so keep it separate.
181 */
182#ifndef __ACPI__
183
Bill Richardson5271db22014-04-30 10:44:08 -0700184/*
185 * Define __packed if someone hasn't beat us to it. Linux kernel style
186 * checking prefers __packed over __attribute__((packed)).
187 */
188#ifndef __packed
189#define __packed __attribute__((packed))
190#endif
191
Simon Glassdeaf39e2013-02-25 14:08:36 -0800192/* LPC command status byte masks */
193/* EC has written a byte in the data register and host hasn't read it yet */
194#define EC_LPC_STATUS_TO_HOST 0x01
195/* Host has written a command/data byte and the EC hasn't read it yet */
196#define EC_LPC_STATUS_FROM_HOST 0x02
197/* EC is processing a command */
198#define EC_LPC_STATUS_PROCESSING 0x04
199/* Last write to EC was a command, not data */
200#define EC_LPC_STATUS_LAST_CMD 0x08
201/* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
202#define EC_LPC_STATUS_BURST_MODE 0x10
203/* SCI event is pending (requesting SCI query) */
204#define EC_LPC_STATUS_SCI_PENDING 0x20
205/* SMI event is pending (requesting SMI query) */
206#define EC_LPC_STATUS_SMI_PENDING 0x40
207/* (reserved) */
208#define EC_LPC_STATUS_RESERVED 0x80
209
210/*
211 * EC is busy. This covers both the EC processing a command, and the host has
212 * written a new command but the EC hasn't picked it up yet.
213 */
214#define EC_LPC_STATUS_BUSY_MASK \
215 (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
216
217/* Host command response codes */
218enum ec_status {
219 EC_RES_SUCCESS = 0,
220 EC_RES_INVALID_COMMAND = 1,
221 EC_RES_ERROR = 2,
222 EC_RES_INVALID_PARAM = 3,
223 EC_RES_ACCESS_DENIED = 4,
224 EC_RES_INVALID_RESPONSE = 5,
225 EC_RES_INVALID_VERSION = 6,
226 EC_RES_INVALID_CHECKSUM = 7,
227 EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
228 EC_RES_UNAVAILABLE = 9, /* No response available */
229 EC_RES_TIMEOUT = 10, /* We got a timeout */
230 EC_RES_OVERFLOW = 11, /* Table / data overflow */
Bill Richardson5271db22014-04-30 10:44:08 -0700231 EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
232 EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
233 EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800234};
235
236/*
237 * Host event codes. Note these are 1-based, not 0-based, because ACPI query
238 * EC command uses code 0 to mean "no event pending". We explicitly specify
239 * each value in the enum listing so they won't change if we delete/insert an
240 * item or rearrange the list (it needs to be stable across platforms, not
241 * just within a single compiled instance).
242 */
243enum host_event_code {
244 EC_HOST_EVENT_LID_CLOSED = 1,
245 EC_HOST_EVENT_LID_OPEN = 2,
246 EC_HOST_EVENT_POWER_BUTTON = 3,
247 EC_HOST_EVENT_AC_CONNECTED = 4,
248 EC_HOST_EVENT_AC_DISCONNECTED = 5,
249 EC_HOST_EVENT_BATTERY_LOW = 6,
250 EC_HOST_EVENT_BATTERY_CRITICAL = 7,
251 EC_HOST_EVENT_BATTERY = 8,
252 EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
253 EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
254 EC_HOST_EVENT_THERMAL = 11,
255 EC_HOST_EVENT_USB_CHARGER = 12,
256 EC_HOST_EVENT_KEY_PRESSED = 13,
257 /*
258 * EC has finished initializing the host interface. The host can check
259 * for this event following sending a EC_CMD_REBOOT_EC command to
260 * determine when the EC is ready to accept subsequent commands.
261 */
262 EC_HOST_EVENT_INTERFACE_READY = 14,
263 /* Keyboard recovery combo has been pressed */
264 EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
265
266 /* Shutdown due to thermal overload */
267 EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
268 /* Shutdown due to battery level too low */
269 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
270
Bill Richardson5271db22014-04-30 10:44:08 -0700271 /* Suggest that the AP throttle itself */
272 EC_HOST_EVENT_THROTTLE_START = 18,
273 /* Suggest that the AP resume normal speed */
274 EC_HOST_EVENT_THROTTLE_STOP = 19,
275
276 /* Hang detect logic detected a hang and host event timeout expired */
277 EC_HOST_EVENT_HANG_DETECT = 20,
278 /* Hang detect logic detected a hang and warm rebooted the AP */
279 EC_HOST_EVENT_HANG_REBOOT = 21,
Benson Leungc6983162017-07-17 11:41:39 +0200280 /* PD MCU triggering host event */
281 EC_HOST_EVENT_PD_MCU = 22,
282
283 /* EC desires to change state of host-controlled USB mux */
284 EC_HOST_EVENT_USB_MUX = 28,
Bill Richardson5271db22014-04-30 10:44:08 -0700285
Stephen Barber3eff6d22017-11-10 22:55:52 +0100286 /* EC RTC event occurred */
287 EC_HOST_EVENT_RTC = 26,
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
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200301/**
302 * struct ec_lpc_host_args - Arguments at EC_LPC_ADDR_HOST_ARGS
303 * @flags: The host argument flags.
304 * @command_version: Command version.
305 * @data_size: The length of data.
306 * @checksum: Checksum; sum of command + flags + command_version + data_size +
307 * all params/response data bytes.
308 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800309struct ec_lpc_host_args {
310 uint8_t flags;
311 uint8_t command_version;
312 uint8_t data_size;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800313 uint8_t checksum;
314} __packed;
315
316/* Flags for ec_lpc_host_args.flags */
317/*
318 * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
319 * params.
320 *
321 * If EC gets a command and this flag is not set, this is an old-style command.
322 * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
323 * unknown length. EC must respond with an old-style response (that is,
324 * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
325 */
326#define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
327/*
328 * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
329 *
330 * If EC responds to a command and this flag is not set, this is an old-style
331 * response. Command version is 0 and response data from EC is at
332 * EC_LPC_ADDR_OLD_PARAM with unknown length.
333 */
334#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
335
Bill Richardson5271db22014-04-30 10:44:08 -0700336/*****************************************************************************/
337/*
338 * Byte codes returned by EC over SPI interface.
339 *
340 * These can be used by the AP to debug the EC interface, and to determine
341 * when the EC is not in a state where it will ever get around to responding
342 * to the AP.
343 *
344 * Example of sequence of bytes read from EC for a current good transfer:
345 * 1. - - AP asserts chip select (CS#)
346 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
347 * 3. - - EC starts handling CS# interrupt
348 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
349 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
350 * bytes looking for EC_SPI_FRAME_START
351 * 6. - - EC finishes processing and sets up response
352 * 7. EC_SPI_FRAME_START - AP reads frame byte
353 * 8. (response packet) - AP reads response packet
354 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
355 * 10 - - AP deasserts chip select
356 * 11 - - EC processes CS# interrupt and sets up DMA for
357 * next request
358 *
359 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
360 * the following byte values:
361 * EC_SPI_OLD_READY
362 * EC_SPI_RX_READY
363 * EC_SPI_RECEIVING
364 * EC_SPI_PROCESSING
365 *
366 * Then the EC found an error in the request, or was not ready for the request
367 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
368 * because the EC is unable to tell when the AP is done sending its request.
369 */
370
371/*
372 * Framing byte which precedes a response packet from the EC. After sending a
373 * request, the AP will clock in bytes until it sees the framing byte, then
374 * clock in the response packet.
375 */
376#define EC_SPI_FRAME_START 0xec
377
378/*
379 * Padding bytes which are clocked out after the end of a response packet.
380 */
381#define EC_SPI_PAST_END 0xed
382
383/*
384 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
385 * that the AP will send a valid packet header (starting with
386 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
387 */
388#define EC_SPI_RX_READY 0xf8
389
390/*
391 * EC has started receiving the request from the AP, but hasn't started
392 * processing it yet.
393 */
394#define EC_SPI_RECEIVING 0xf9
395
396/* EC has received the entire request from the AP and is processing it. */
397#define EC_SPI_PROCESSING 0xfa
398
399/*
400 * EC received bad data from the AP, such as a packet header with an invalid
401 * length. EC will ignore all data until chip select deasserts.
402 */
403#define EC_SPI_RX_BAD_DATA 0xfb
404
405/*
406 * EC received data from the AP before it was ready. That is, the AP asserted
407 * chip select and started clocking data before the EC was ready to receive it.
408 * EC will ignore all data until chip select deasserts.
409 */
410#define EC_SPI_NOT_READY 0xfc
411
412/*
413 * EC was ready to receive a request from the AP. EC has treated the byte sent
414 * by the AP as part of a request packet, or (for old-style ECs) is processing
415 * a fully received packet but is not ready to respond yet.
416 */
417#define EC_SPI_OLD_READY 0xfd
418
419/*****************************************************************************/
420
421/*
422 * Protocol version 2 for I2C and SPI send a request this way:
423 *
424 * 0 EC_CMD_VERSION0 + (command version)
425 * 1 Command number
426 * 2 Length of params = N
427 * 3..N+2 Params, if any
428 * N+3 8-bit checksum of bytes 0..N+2
429 *
430 * The corresponding response is:
431 *
432 * 0 Result code (EC_RES_*)
433 * 1 Length of params = M
434 * 2..M+1 Params, if any
435 * M+2 8-bit checksum of bytes 0..M+1
436 */
437#define EC_PROTO2_REQUEST_HEADER_BYTES 3
438#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
439#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
440 EC_PROTO2_REQUEST_TRAILER_BYTES)
441
442#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
443#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
444#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
445 EC_PROTO2_RESPONSE_TRAILER_BYTES)
446
447/* Parameter length was limited by the LPC interface */
448#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
449
450/* Maximum request and response packet sizes for protocol version 2 */
451#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
452 EC_PROTO2_MAX_PARAM_SIZE)
453#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
454 EC_PROTO2_MAX_PARAM_SIZE)
455
456/*****************************************************************************/
457
458/*
459 * Value written to legacy command port / prefix byte to indicate protocol
460 * 3+ structs are being used. Usage is bus-dependent.
461 */
462#define EC_COMMAND_PROTOCOL_3 0xda
463
464#define EC_HOST_REQUEST_VERSION 3
465
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200466/**
467 * struct ec_host_request - Version 3 request from host.
468 * @struct_version: Should be 3. The EC will return EC_RES_INVALID_HEADER if it
469 * receives a header with a version it doesn't know how to
470 * parse.
471 * @checksum: Checksum of request and data; sum of all bytes including checksum
472 * should total to 0.
473 * @command: Command to send (EC_CMD_...)
474 * @command_version: Command version.
475 * @reserved: Unused byte in current protocol version; set to 0.
476 * @data_len: Length of data which follows this header.
477 */
Bill Richardson5271db22014-04-30 10:44:08 -0700478struct ec_host_request {
Bill Richardson5271db22014-04-30 10:44:08 -0700479 uint8_t struct_version;
Bill Richardson5271db22014-04-30 10:44:08 -0700480 uint8_t checksum;
Bill Richardson5271db22014-04-30 10:44:08 -0700481 uint16_t command;
Bill Richardson5271db22014-04-30 10:44:08 -0700482 uint8_t command_version;
Bill Richardson5271db22014-04-30 10:44:08 -0700483 uint8_t reserved;
Bill Richardson5271db22014-04-30 10:44:08 -0700484 uint16_t data_len;
485} __packed;
486
487#define EC_HOST_RESPONSE_VERSION 3
488
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200489/**
490 * struct ec_host_response - Version 3 response from EC.
491 * @struct_version: Struct version (=3).
492 * @checksum: Checksum of response and data; sum of all bytes including
493 * checksum should total to 0.
494 * @result: EC's response to the command (separate from communication failure)
495 * @data_len: Length of data which follows this header.
496 * @reserved: Unused bytes in current protocol version; set to 0.
497 */
Bill Richardson5271db22014-04-30 10:44:08 -0700498struct ec_host_response {
Bill Richardson5271db22014-04-30 10:44:08 -0700499 uint8_t struct_version;
Bill Richardson5271db22014-04-30 10:44:08 -0700500 uint8_t checksum;
Bill Richardson5271db22014-04-30 10:44:08 -0700501 uint16_t result;
Bill Richardson5271db22014-04-30 10:44:08 -0700502 uint16_t data_len;
Bill Richardson5271db22014-04-30 10:44:08 -0700503 uint16_t reserved;
504} __packed;
505
506/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -0800507/*
508 * Notes on commands:
509 *
Stephen Barber256ab952015-06-09 13:04:43 +0200510 * Each command is an 16-bit command value. Commands which take params or
Simon Glassdeaf39e2013-02-25 14:08:36 -0800511 * return response data specify structs for that data. If no struct is
512 * specified, the command does not input or output data, respectively.
513 * Parameter/response length is implicit in the structs. Some underlying
514 * communication protocols (I2C, SPI) may add length or checksum headers, but
515 * those are implementation-dependent and not defined here.
516 */
517
518/*****************************************************************************/
519/* General / test commands */
520
521/*
522 * Get protocol version, used to deal with non-backward compatible protocol
523 * changes.
524 */
525#define EC_CMD_PROTO_VERSION 0x00
526
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200527/**
528 * struct ec_response_proto_version - Response to the proto version command.
529 * @version: The protocol version.
530 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800531struct ec_response_proto_version {
532 uint32_t version;
533} __packed;
534
535/*
536 * Hello. This is a simple command to test the EC is responsive to
537 * commands.
538 */
539#define EC_CMD_HELLO 0x01
540
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200541/**
542 * struct ec_params_hello - Parameters to the hello command.
543 * @in_data: Pass anything here.
544 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800545struct ec_params_hello {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200546 uint32_t in_data;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800547} __packed;
548
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200549/**
550 * struct ec_response_hello - Response to the hello command.
551 * @out_data: Output will be in_data + 0x01020304.
552 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800553struct ec_response_hello {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200554 uint32_t out_data;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800555} __packed;
556
557/* Get version number */
558#define EC_CMD_GET_VERSION 0x02
559
560enum ec_current_image {
561 EC_IMAGE_UNKNOWN = 0,
562 EC_IMAGE_RO,
563 EC_IMAGE_RW
564};
565
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200566/**
567 * struct ec_response_get_version - Response to the get version command.
568 * @version_string_ro: Null-terminated RO firmware version string.
569 * @version_string_rw: Null-terminated RW firmware version string.
570 * @reserved: Unused bytes; was previously RW-B firmware version string.
571 * @current_image: One of ec_current_image.
572 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800573struct ec_response_get_version {
Simon Glassdeaf39e2013-02-25 14:08:36 -0800574 char version_string_ro[32];
575 char version_string_rw[32];
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200576 char reserved[32];
577 uint32_t current_image;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800578} __packed;
579
580/* Read test */
581#define EC_CMD_READ_TEST 0x03
582
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200583/**
584 * struct ec_params_read_test - Parameters for the read test command.
585 * @offset: Starting value for read buffer.
586 * @size: Size to read in bytes.
587 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800588struct ec_params_read_test {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200589 uint32_t offset;
590 uint32_t size;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800591} __packed;
592
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200593/**
594 * struct ec_response_read_test - Response to the read test command.
595 * @data: Data returned by the read test command.
596 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800597struct ec_response_read_test {
598 uint32_t data[32];
599} __packed;
600
601/*
602 * Get build information
603 *
604 * Response is null-terminated string.
605 */
606#define EC_CMD_GET_BUILD_INFO 0x04
607
608/* Get chip info */
609#define EC_CMD_GET_CHIP_INFO 0x05
610
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200611/**
612 * struct ec_response_get_chip_info - Response to the get chip info command.
613 * @vendor: Null-terminated string for chip vendor.
614 * @name: Null-terminated string for chip name.
615 * @revision: Null-terminated string for chip mask version.
616 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800617struct ec_response_get_chip_info {
Simon Glassdeaf39e2013-02-25 14:08:36 -0800618 char vendor[32];
619 char name[32];
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200620 char revision[32];
Simon Glassdeaf39e2013-02-25 14:08:36 -0800621} __packed;
622
623/* Get board HW version */
624#define EC_CMD_GET_BOARD_VERSION 0x06
625
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200626/**
627 * struct ec_response_board_version - Response to the board version command.
628 * @board_version: A monotonously incrementing number.
629 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800630struct ec_response_board_version {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200631 uint16_t board_version;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800632} __packed;
633
634/*
635 * Read memory-mapped data.
636 *
637 * This is an alternate interface to memory-mapped data for bus protocols
638 * which don't support direct-mapped memory - I2C, SPI, etc.
639 *
640 * Response is params.size bytes of data.
641 */
642#define EC_CMD_READ_MEMMAP 0x07
643
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200644/**
645 * struct ec_params_read_memmap - Parameters for the read memory map command.
646 * @offset: Offset in memmap (EC_MEMMAP_*).
647 * @size: Size to read in bytes.
648 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800649struct ec_params_read_memmap {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200650 uint8_t offset;
651 uint8_t size;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800652} __packed;
653
654/* Read versions supported for a command */
655#define EC_CMD_GET_CMD_VERSIONS 0x08
656
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200657/**
658 * struct ec_params_get_cmd_versions - Parameters for the get command versions.
659 * @cmd: Command to check.
660 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800661struct ec_params_get_cmd_versions {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200662 uint8_t cmd;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800663} __packed;
664
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200665/**
666 * struct ec_params_get_cmd_versions_v1 - Parameters for the get command
667 * versions (v1)
668 * @cmd: Command to check.
669 */
Nicolas Boichat0aa877c2017-05-16 17:46:48 +0200670struct ec_params_get_cmd_versions_v1 {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200671 uint16_t cmd;
Nicolas Boichat0aa877c2017-05-16 17:46:48 +0200672} __packed;
673
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200674/**
675 * struct ec_response_get_cmd_version - Response to the get command versions.
676 * @version_mask: Mask of supported versions; use EC_VER_MASK() to compare with
677 * a desired version.
678 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800679struct ec_response_get_cmd_versions {
Simon Glassdeaf39e2013-02-25 14:08:36 -0800680 uint32_t version_mask;
681} __packed;
682
683/*
684 * Check EC communcations status (busy). This is needed on i2c/spi but not
685 * on lpc since it has its own out-of-band busy indicator.
686 *
687 * lpc must read the status from the command register. Attempting this on
688 * lpc will overwrite the args/parameter space and corrupt its data.
689 */
690#define EC_CMD_GET_COMMS_STATUS 0x09
691
692/* Avoid using ec_status which is for return values */
693enum ec_comms_status {
694 EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
695};
696
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200697/**
698 * struct ec_response_get_comms_status - Response to the get comms status
699 * command.
700 * @flags: Mask of enum ec_comms_status.
701 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800702struct ec_response_get_comms_status {
703 uint32_t flags; /* Mask of enum ec_comms_status */
704} __packed;
705
Bill Richardson5271db22014-04-30 10:44:08 -0700706/* Fake a variety of responses, purely for testing purposes. */
707#define EC_CMD_TEST_PROTOCOL 0x0a
708
709/* Tell the EC what to send back to us. */
710struct ec_params_test_protocol {
711 uint32_t ec_result;
712 uint32_t ret_len;
713 uint8_t buf[32];
714} __packed;
715
716/* Here it comes... */
717struct ec_response_test_protocol {
718 uint8_t buf[32];
719} __packed;
720
721/* Get prococol information */
722#define EC_CMD_GET_PROTOCOL_INFO 0x0b
723
724/* Flags for ec_response_get_protocol_info.flags */
725/* EC_RES_IN_PROGRESS may be returned if a command is slow */
726#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
727
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200728/**
729 * struct ec_response_get_protocol_info - Response to the get protocol info.
730 * @protocol_versions: Bitmask of protocol versions supported (1 << n means
731 * version n).
732 * @max_request_packet_size: Maximum request packet size in bytes.
733 * @max_response_packet_size: Maximum response packet size in bytes.
734 * @flags: see EC_PROTOCOL_INFO_*
735 */
Bill Richardson5271db22014-04-30 10:44:08 -0700736struct ec_response_get_protocol_info {
737 /* Fields which exist if at least protocol version 3 supported */
Bill Richardson5271db22014-04-30 10:44:08 -0700738 uint32_t protocol_versions;
Bill Richardson5271db22014-04-30 10:44:08 -0700739 uint16_t max_request_packet_size;
Bill Richardson5271db22014-04-30 10:44:08 -0700740 uint16_t max_response_packet_size;
Bill Richardson5271db22014-04-30 10:44:08 -0700741 uint32_t flags;
742} __packed;
743
744
745/*****************************************************************************/
746/* Get/Set miscellaneous values */
747
748/* The upper byte of .flags tells what to do (nothing means "get") */
749#define EC_GSV_SET 0x80000000
750
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200751/*
752 * The lower three bytes of .flags identifies the parameter, if that has
753 * meaning for an individual command.
754 */
Bill Richardson5271db22014-04-30 10:44:08 -0700755#define EC_GSV_PARAM_MASK 0x00ffffff
756
757struct ec_params_get_set_value {
758 uint32_t flags;
759 uint32_t value;
760} __packed;
761
762struct ec_response_get_set_value {
763 uint32_t flags;
764 uint32_t value;
765} __packed;
766
767/* More than one command can use these structs to get/set paramters. */
768#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
769
Vincent Palatine4244eb2016-08-01 11:54:37 +0200770/*****************************************************************************/
771/* List the features supported by the firmware */
772#define EC_CMD_GET_FEATURES 0x0d
773
774/* Supported features */
775enum ec_feature_code {
776 /*
777 * This image contains a limited set of features. Another image
778 * in RW partition may support more features.
779 */
780 EC_FEATURE_LIMITED = 0,
781 /*
782 * Commands for probing/reading/writing/erasing the flash in the
783 * EC are present.
784 */
785 EC_FEATURE_FLASH = 1,
786 /*
787 * Can control the fan speed directly.
788 */
789 EC_FEATURE_PWM_FAN = 2,
790 /*
791 * Can control the intensity of the keyboard backlight.
792 */
793 EC_FEATURE_PWM_KEYB = 3,
794 /*
795 * Support Google lightbar, introduced on Pixel.
796 */
797 EC_FEATURE_LIGHTBAR = 4,
798 /* Control of LEDs */
799 EC_FEATURE_LED = 5,
800 /* Exposes an interface to control gyro and sensors.
801 * The host goes through the EC to access these sensors.
802 * In addition, the EC may provide composite sensors, like lid angle.
803 */
804 EC_FEATURE_MOTION_SENSE = 6,
805 /* The keyboard is controlled by the EC */
806 EC_FEATURE_KEYB = 7,
807 /* The AP can use part of the EC flash as persistent storage. */
808 EC_FEATURE_PSTORE = 8,
809 /* The EC monitors BIOS port 80h, and can return POST codes. */
810 EC_FEATURE_PORT80 = 9,
811 /*
812 * Thermal management: include TMP specific commands.
813 * Higher level than direct fan control.
814 */
815 EC_FEATURE_THERMAL = 10,
816 /* Can switch the screen backlight on/off */
817 EC_FEATURE_BKLIGHT_SWITCH = 11,
818 /* Can switch the wifi module on/off */
819 EC_FEATURE_WIFI_SWITCH = 12,
820 /* Monitor host events, through for example SMI or SCI */
821 EC_FEATURE_HOST_EVENTS = 13,
822 /* The EC exposes GPIO commands to control/monitor connected devices. */
823 EC_FEATURE_GPIO = 14,
824 /* The EC can send i2c messages to downstream devices. */
825 EC_FEATURE_I2C = 15,
826 /* Command to control charger are included */
827 EC_FEATURE_CHARGER = 16,
828 /* Simple battery support. */
829 EC_FEATURE_BATTERY = 17,
830 /*
831 * Support Smart battery protocol
832 * (Common Smart Battery System Interface Specification)
833 */
834 EC_FEATURE_SMART_BATTERY = 18,
Enric Balletbo i Serra93abf682019-05-08 11:19:54 +0200835 /* EC can detect when the host hangs. */
Vincent Palatine4244eb2016-08-01 11:54:37 +0200836 EC_FEATURE_HANG_DETECT = 19,
837 /* Report power information, for pit only */
838 EC_FEATURE_PMU = 20,
839 /* Another Cros EC device is present downstream of this one */
840 EC_FEATURE_SUB_MCU = 21,
841 /* Support USB Power delivery (PD) commands */
842 EC_FEATURE_USB_PD = 22,
843 /* Control USB multiplexer, for audio through USB port for instance. */
844 EC_FEATURE_USB_MUX = 23,
845 /* Motion Sensor code has an internal software FIFO */
846 EC_FEATURE_MOTION_SENSE_FIFO = 24,
Enric Balletbo i Serra93abf682019-05-08 11:19:54 +0200847 /* Support temporary secure vstore */
848 EC_FEATURE_VSTORE = 25,
849 /* EC decides on USB-C SS mux state, muxes configured by host */
850 EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
Stephen Barber3eff6d22017-11-10 22:55:52 +0100851 /* EC has RTC feature that can be controlled by host commands */
852 EC_FEATURE_RTC = 27,
Enric Balletbo i Serra93abf682019-05-08 11:19:54 +0200853 /* The MCU exposes a Fingerprint sensor */
854 EC_FEATURE_FINGERPRINT = 28,
855 /* The MCU exposes a Touchpad */
856 EC_FEATURE_TOUCHPAD = 29,
857 /* The MCU has RWSIG task enabled */
858 EC_FEATURE_RWSIG = 30,
859 /* EC has device events support */
860 EC_FEATURE_DEVICE_EVENT = 31,
861 /* EC supports the unified wake masks for LPC/eSPI systems */
862 EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
863 /* EC supports 64-bit host events */
864 EC_FEATURE_HOST_EVENT64 = 33,
865 /* EC runs code in RAM (not in place, a.k.a. XIP) */
866 EC_FEATURE_EXEC_IN_RAM = 34,
Neil Armstrongf47674e2018-07-04 17:08:19 +0200867 /* EC supports CEC commands */
868 EC_FEATURE_CEC = 35,
Enric Balletbo i Serra93abf682019-05-08 11:19:54 +0200869 /* EC supports tight sensor timestamping. */
870 EC_FEATURE_MOTION_SENSE_TIGHT_TIMESTAMPS = 36,
871 /*
872 * EC supports tablet mode detection aligned to Chrome and allows
873 * setting of threshold by host command using
874 * MOTIONSENSE_CMD_TABLET_MODE_LID_ANGLE.
875 */
876 EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS = 37,
877 /* EC supports audio codec. */
878 EC_FEATURE_AUDIO_CODEC = 38,
879 /* EC Supports SCP. */
880 EC_FEATURE_SCP = 39,
Rushikesh S Kadamd4cee952019-03-01 13:50:54 +0530881 /* The MCU is an Integrated Sensor Hub */
882 EC_FEATURE_ISH = 40,
Vincent Palatine4244eb2016-08-01 11:54:37 +0200883};
884
885#define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
886#define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200887
Vincent Palatine4244eb2016-08-01 11:54:37 +0200888struct ec_response_get_features {
889 uint32_t flags[2];
890} __packed;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800891
892/*****************************************************************************/
893/* Flash commands */
894
895/* Get flash info */
896#define EC_CMD_FLASH_INFO 0x10
897
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200898/**
899 * struct ec_response_flash_info - Response to the flash info command.
900 * @flash_size: Usable flash size in bytes.
901 * @write_block_size: Write block size. Write offset and size must be a
902 * multiple of this.
903 * @erase_block_size: Erase block size. Erase offset and size must be a
904 * multiple of this.
905 * @protect_block_size: Protection block size. Protection offset and size
906 * must be a multiple of this.
907 *
908 * Version 0 returns these fields.
909 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800910struct ec_response_flash_info {
Simon Glassdeaf39e2013-02-25 14:08:36 -0800911 uint32_t flash_size;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800912 uint32_t write_block_size;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800913 uint32_t erase_block_size;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800914 uint32_t protect_block_size;
915} __packed;
916
Bill Richardson5271db22014-04-30 10:44:08 -0700917/* Flags for version 1+ flash info command */
918/* EC flash erases bits to 0 instead of 1 */
919#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
920
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200921/**
922 * struct ec_response_flash_info_1 - Response to the flash info v1 command.
923 * @flash_size: Usable flash size in bytes.
924 * @write_block_size: Write block size. Write offset and size must be a
925 * multiple of this.
926 * @erase_block_size: Erase block size. Erase offset and size must be a
927 * multiple of this.
928 * @protect_block_size: Protection block size. Protection offset and size
929 * must be a multiple of this.
930 * @write_ideal_size: Ideal write size in bytes. Writes will be fastest if
931 * size is exactly this and offset is a multiple of this.
932 * For example, an EC may have a write buffer which can do
933 * half-page operations if data is aligned, and a slower
934 * word-at-a-time write mode.
935 * @flags: Flags; see EC_FLASH_INFO_*
936 *
Bill Richardson5271db22014-04-30 10:44:08 -0700937 * Version 1 returns the same initial fields as version 0, with additional
938 * fields following.
939 *
940 * gcc anonymous structs don't seem to get along with the __packed directive;
941 * if they did we'd define the version 0 struct as a sub-struct of this one.
942 */
943struct ec_response_flash_info_1 {
944 /* Version 0 fields; see above for description */
945 uint32_t flash_size;
946 uint32_t write_block_size;
947 uint32_t erase_block_size;
948 uint32_t protect_block_size;
949
950 /* Version 1 adds these fields: */
Bill Richardson5271db22014-04-30 10:44:08 -0700951 uint32_t write_ideal_size;
Bill Richardson5271db22014-04-30 10:44:08 -0700952 uint32_t flags;
953} __packed;
954
Simon Glassdeaf39e2013-02-25 14:08:36 -0800955/*
956 * Read flash
957 *
958 * Response is params.size bytes of data.
959 */
960#define EC_CMD_FLASH_READ 0x11
961
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200962/**
963 * struct ec_params_flash_read - Parameters for the flash read command.
964 * @offset: Byte offset to read.
965 * @size: Size to read in bytes.
966 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800967struct ec_params_flash_read {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200968 uint32_t offset;
969 uint32_t size;
Simon Glassdeaf39e2013-02-25 14:08:36 -0800970} __packed;
971
972/* Write flash */
973#define EC_CMD_FLASH_WRITE 0x12
Bill Richardson5271db22014-04-30 10:44:08 -0700974#define EC_VER_FLASH_WRITE 1
975
976/* Version 0 of the flash command supported only 64 bytes of data */
977#define EC_FLASH_WRITE_VER0_SIZE 64
Simon Glassdeaf39e2013-02-25 14:08:36 -0800978
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200979/**
980 * struct ec_params_flash_write - Parameters for the flash write command.
981 * @offset: Byte offset to write.
982 * @size: Size to write in bytes.
983 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800984struct ec_params_flash_write {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200985 uint32_t offset;
986 uint32_t size;
Bill Richardson5271db22014-04-30 10:44:08 -0700987 /* Followed by data to write */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800988} __packed;
989
990/* Erase flash */
991#define EC_CMD_FLASH_ERASE 0x13
992
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200993/**
994 * struct ec_params_flash_erase - Parameters for the flash erase command.
995 * @offset: Byte offset to erase.
996 * @size: Size to erase in bytes.
997 */
Simon Glassdeaf39e2013-02-25 14:08:36 -0800998struct ec_params_flash_erase {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +0200999 uint32_t offset;
1000 uint32_t size;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001001} __packed;
1002
1003/*
1004 * Get/set flash protection.
1005 *
1006 * If mask!=0, sets/clear the requested bits of flags. Depending on the
1007 * firmware write protect GPIO, not all flags will take effect immediately;
1008 * some flags require a subsequent hard reset to take effect. Check the
1009 * returned flags bits to see what actually happened.
1010 *
1011 * If mask=0, simply returns the current flags state.
1012 */
1013#define EC_CMD_FLASH_PROTECT 0x15
1014#define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
1015
1016/* Flags for flash protection */
1017/* RO flash code protected when the EC boots */
1018#define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
1019/*
1020 * RO flash code protected now. If this bit is set, at-boot status cannot
1021 * be changed.
1022 */
1023#define EC_FLASH_PROTECT_RO_NOW (1 << 1)
1024/* Entire flash code protected now, until reboot. */
1025#define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
1026/* Flash write protect GPIO is asserted now */
1027#define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
1028/* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
1029#define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
1030/*
1031 * Error - flash protection is in inconsistent state. At least one bank of
1032 * flash which should be protected is not protected. Usually fixed by
1033 * re-requesting the desired flags, or by a hard reset if that fails.
1034 */
1035#define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
1036/* Entile flash code protected when the EC boots */
1037#define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
1038
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +02001039/**
1040 * struct ec_params_flash_protect - Parameters for the flash protect command.
1041 * @mask: Bits in flags to apply.
1042 * @flags: New flags to apply.
1043 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001044struct ec_params_flash_protect {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +02001045 uint32_t mask;
1046 uint32_t flags;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001047} __packed;
1048
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +02001049/**
1050 * struct ec_response_flash_protect - Response to the flash protect command.
1051 * @flags: Current value of flash protect flags.
1052 * @valid_flags: Flags which are valid on this platform. This allows the
1053 * caller to distinguish between flags which aren't set vs. flags
1054 * which can't be set on this platform.
1055 * @writable_flags: Flags which can be changed given the current protection
1056 * state.
1057 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001058struct ec_response_flash_protect {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001059 uint32_t flags;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001060 uint32_t valid_flags;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001061 uint32_t writable_flags;
1062} __packed;
1063
1064/*
1065 * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
1066 * write protect. These commands may be reused with version > 0.
1067 */
1068
1069/* Get the region offset/size */
1070#define EC_CMD_FLASH_REGION_INFO 0x16
1071#define EC_VER_FLASH_REGION_INFO 1
1072
1073enum ec_flash_region {
1074 /* Region which holds read-only EC image */
Bill Richardson5271db22014-04-30 10:44:08 -07001075 EC_FLASH_REGION_RO = 0,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001076 /* Region which holds rewritable EC image */
1077 EC_FLASH_REGION_RW,
1078 /*
1079 * Region which should be write-protected in the factory (a superset of
1080 * EC_FLASH_REGION_RO)
1081 */
1082 EC_FLASH_REGION_WP_RO,
Bill Richardson5271db22014-04-30 10:44:08 -07001083 /* Number of regions */
1084 EC_FLASH_REGION_COUNT,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001085};
1086
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +02001087/**
1088 * struct ec_params_flash_region_info - Parameters for the flash region info
1089 * command.
1090 * @region: Flash region; see EC_FLASH_REGION_*
1091 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001092struct ec_params_flash_region_info {
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +02001093 uint32_t region;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001094} __packed;
1095
1096struct ec_response_flash_region_info {
1097 uint32_t offset;
1098 uint32_t size;
1099} __packed;
1100
1101/* Read/write VbNvContext */
1102#define EC_CMD_VBNV_CONTEXT 0x17
1103#define EC_VER_VBNV_CONTEXT 1
1104#define EC_VBNV_BLOCK_SIZE 16
1105
1106enum ec_vbnvcontext_op {
1107 EC_VBNV_CONTEXT_OP_READ,
1108 EC_VBNV_CONTEXT_OP_WRITE,
1109};
1110
1111struct ec_params_vbnvcontext {
1112 uint32_t op;
1113 uint8_t block[EC_VBNV_BLOCK_SIZE];
1114} __packed;
1115
1116struct ec_response_vbnvcontext {
1117 uint8_t block[EC_VBNV_BLOCK_SIZE];
1118} __packed;
1119
1120/*****************************************************************************/
1121/* PWM commands */
1122
1123/* Get fan target RPM */
1124#define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
1125
1126struct ec_response_pwm_get_fan_rpm {
1127 uint32_t rpm;
1128} __packed;
1129
1130/* Set target fan RPM */
1131#define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
1132
1133struct ec_params_pwm_set_fan_target_rpm {
1134 uint32_t rpm;
1135} __packed;
1136
1137/* Get keyboard backlight */
1138#define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
1139
1140struct ec_response_pwm_get_keyboard_backlight {
1141 uint8_t percent;
1142 uint8_t enabled;
1143} __packed;
1144
1145/* Set keyboard backlight */
1146#define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
1147
1148struct ec_params_pwm_set_keyboard_backlight {
1149 uint8_t percent;
1150} __packed;
1151
1152/* Set target fan PWM duty cycle */
1153#define EC_CMD_PWM_SET_FAN_DUTY 0x24
1154
1155struct ec_params_pwm_set_fan_duty {
1156 uint32_t percent;
1157} __packed;
1158
Brian Norris2b66bd62016-07-15 16:28:42 -07001159#define EC_CMD_PWM_SET_DUTY 0x25
1160/* 16 bit duty cycle, 0xffff = 100% */
1161#define EC_PWM_MAX_DUTY 0xffff
1162
1163enum ec_pwm_type {
1164 /* All types, indexed by board-specific enum pwm_channel */
1165 EC_PWM_TYPE_GENERIC = 0,
1166 /* Keyboard backlight */
1167 EC_PWM_TYPE_KB_LIGHT,
1168 /* Display backlight */
1169 EC_PWM_TYPE_DISPLAY_LIGHT,
1170 EC_PWM_TYPE_COUNT,
1171};
1172
1173struct ec_params_pwm_set_duty {
1174 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1175 uint8_t pwm_type; /* ec_pwm_type */
1176 uint8_t index; /* Type-specific index, or 0 if unique */
1177} __packed;
1178
1179#define EC_CMD_PWM_GET_DUTY 0x26
1180
1181struct ec_params_pwm_get_duty {
1182 uint8_t pwm_type; /* ec_pwm_type */
1183 uint8_t index; /* Type-specific index, or 0 if unique */
1184} __packed;
1185
1186struct ec_response_pwm_get_duty {
1187 uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
1188} __packed;
1189
Simon Glassdeaf39e2013-02-25 14:08:36 -08001190/*****************************************************************************/
1191/*
1192 * Lightbar commands. This looks worse than it is. Since we only use one HOST
1193 * command to say "talk to the lightbar", we put the "and tell it to do X" part
1194 * into a subcommand. We'll make separate structs for subcommands with
1195 * different input args, so that we know how much to expect.
1196 */
1197#define EC_CMD_LIGHTBAR_CMD 0x28
1198
1199struct rgb_s {
1200 uint8_t r, g, b;
1201};
1202
1203#define LB_BATTERY_LEVELS 4
Enric Balletbo i Serrae2bbf912018-07-18 18:09:56 +02001204
1205/*
1206 * List of tweakable parameters. NOTE: It's __packed so it can be sent in a
Simon Glassdeaf39e2013-02-25 14:08:36 -08001207 * host command, but the alignment is the same regardless. Keep it that way.
1208 */
Stephen Barber256ab952015-06-09 13:04:43 +02001209struct lightbar_params_v0 {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001210 /* Timing */
Bill Richardson5271db22014-04-30 10:44:08 -07001211 int32_t google_ramp_up;
1212 int32_t google_ramp_down;
1213 int32_t s3s0_ramp_up;
1214 int32_t s0_tick_delay[2]; /* AC=0/1 */
1215 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1216 int32_t s0s3_ramp_down;
1217 int32_t s3_sleep_for;
1218 int32_t s3_ramp_up;
1219 int32_t s3_ramp_down;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001220
1221 /* Oscillation */
1222 uint8_t new_s0;
1223 uint8_t osc_min[2]; /* AC=0/1 */
1224 uint8_t osc_max[2]; /* AC=0/1 */
1225 uint8_t w_ofs[2]; /* AC=0/1 */
1226
1227 /* Brightness limits based on the backlight and AC. */
1228 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1229 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1230 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1231
1232 /* Battery level thresholds */
1233 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1234
1235 /* Map [AC][battery_level] to color index */
1236 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1237 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1238
1239 /* Color palette */
1240 struct rgb_s color[8]; /* 0-3 are Google colors */
1241} __packed;
1242
Stephen Barber256ab952015-06-09 13:04:43 +02001243struct lightbar_params_v1 {
1244 /* Timing */
1245 int32_t google_ramp_up;
1246 int32_t google_ramp_down;
1247 int32_t s3s0_ramp_up;
1248 int32_t s0_tick_delay[2]; /* AC=0/1 */
1249 int32_t s0a_tick_delay[2]; /* AC=0/1 */
1250 int32_t s0s3_ramp_down;
1251 int32_t s3_sleep_for;
1252 int32_t s3_ramp_up;
1253 int32_t s3_ramp_down;
1254 int32_t tap_tick_delay;
1255 int32_t tap_display_time;
1256
1257 /* Tap-for-battery params */
1258 uint8_t tap_pct_red;
1259 uint8_t tap_pct_green;
1260 uint8_t tap_seg_min_on;
1261 uint8_t tap_seg_max_on;
1262 uint8_t tap_seg_osc;
1263 uint8_t tap_idx[3];
1264
1265 /* Oscillation */
1266 uint8_t osc_min[2]; /* AC=0/1 */
1267 uint8_t osc_max[2]; /* AC=0/1 */
1268 uint8_t w_ofs[2]; /* AC=0/1 */
1269
1270 /* Brightness limits based on the backlight and AC. */
1271 uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
1272 uint8_t bright_bl_on_min[2]; /* AC=0/1 */
1273 uint8_t bright_bl_on_max[2]; /* AC=0/1 */
1274
1275 /* Battery level thresholds */
1276 uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
1277
1278 /* Map [AC][battery_level] to color index */
1279 uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
1280 uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
1281
1282 /* Color palette */
1283 struct rgb_s color[8]; /* 0-3 are Google colors */
1284} __packed;
1285
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001286/* Lightbar program */
1287#define EC_LB_PROG_LEN 192
1288struct lightbar_program {
1289 uint8_t size;
1290 uint8_t data[EC_LB_PROG_LEN];
1291};
1292
Simon Glassdeaf39e2013-02-25 14:08:36 -08001293struct ec_params_lightbar {
1294 uint8_t cmd; /* Command (see enum lightbar_command) */
1295 union {
1296 struct {
1297 /* no args */
Stephen Barber256ab952015-06-09 13:04:43 +02001298 } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
Eric Caruso405c8432017-05-16 17:46:48 +02001299 version, get_brightness, get_demo, suspend, resume;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001300
Stephen Barber256ab952015-06-09 13:04:43 +02001301 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001302 uint8_t num;
Stephen Barber256ab952015-06-09 13:04:43 +02001303 } set_brightness, seq, demo;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001304
Stephen Barber256ab952015-06-09 13:04:43 +02001305 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001306 uint8_t ctrl, reg, value;
1307 } reg;
1308
Stephen Barber256ab952015-06-09 13:04:43 +02001309 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001310 uint8_t led, red, green, blue;
Stephen Barber256ab952015-06-09 13:04:43 +02001311 } set_rgb;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001312
Stephen Barber256ab952015-06-09 13:04:43 +02001313 struct {
1314 uint8_t led;
1315 } get_rgb;
1316
Eric Caruso405c8432017-05-16 17:46:48 +02001317 struct {
1318 uint8_t enable;
1319 } manual_suspend_ctrl;
1320
Stephen Barber256ab952015-06-09 13:04:43 +02001321 struct lightbar_params_v0 set_params_v0;
1322 struct lightbar_params_v1 set_params_v1;
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001323 struct lightbar_program set_program;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001324 };
1325} __packed;
1326
1327struct ec_response_lightbar {
1328 union {
Stephen Barber256ab952015-06-09 13:04:43 +02001329 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001330 struct {
1331 uint8_t reg;
1332 uint8_t ic0;
1333 uint8_t ic1;
1334 } vals[23];
1335 } dump;
1336
Stephen Barber256ab952015-06-09 13:04:43 +02001337 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001338 uint8_t num;
Stephen Barber256ab952015-06-09 13:04:43 +02001339 } get_seq, get_brightness, get_demo;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001340
Stephen Barber256ab952015-06-09 13:04:43 +02001341 struct lightbar_params_v0 get_params_v0;
1342 struct lightbar_params_v1 get_params_v1;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001343
Stephen Barber256ab952015-06-09 13:04:43 +02001344 struct {
Bill Richardson5271db22014-04-30 10:44:08 -07001345 uint32_t num;
1346 uint32_t flags;
1347 } version;
1348
Simon Glassdeaf39e2013-02-25 14:08:36 -08001349 struct {
Stephen Barber256ab952015-06-09 13:04:43 +02001350 uint8_t red, green, blue;
1351 } get_rgb;
1352
1353 struct {
Simon Glassdeaf39e2013-02-25 14:08:36 -08001354 /* no return params */
Stephen Barber256ab952015-06-09 13:04:43 +02001355 } off, on, init, set_brightness, seq, reg, set_rgb,
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001356 demo, set_params_v0, set_params_v1,
Eric Caruso405c8432017-05-16 17:46:48 +02001357 set_program, manual_suspend_ctrl, suspend, resume;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001358 };
1359} __packed;
1360
1361/* Lightbar commands */
1362enum lightbar_command {
1363 LIGHTBAR_CMD_DUMP = 0,
1364 LIGHTBAR_CMD_OFF = 1,
1365 LIGHTBAR_CMD_ON = 2,
1366 LIGHTBAR_CMD_INIT = 3,
Stephen Barber256ab952015-06-09 13:04:43 +02001367 LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001368 LIGHTBAR_CMD_SEQ = 5,
1369 LIGHTBAR_CMD_REG = 6,
Stephen Barber256ab952015-06-09 13:04:43 +02001370 LIGHTBAR_CMD_SET_RGB = 7,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001371 LIGHTBAR_CMD_GET_SEQ = 8,
1372 LIGHTBAR_CMD_DEMO = 9,
Stephen Barber256ab952015-06-09 13:04:43 +02001373 LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
1374 LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
Bill Richardson5271db22014-04-30 10:44:08 -07001375 LIGHTBAR_CMD_VERSION = 12,
Stephen Barber256ab952015-06-09 13:04:43 +02001376 LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
1377 LIGHTBAR_CMD_GET_RGB = 14,
1378 LIGHTBAR_CMD_GET_DEMO = 15,
1379 LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
1380 LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
Eric Carusobe3ebeb2017-05-16 17:46:48 +02001381 LIGHTBAR_CMD_SET_PROGRAM = 18,
Eric Caruso405c8432017-05-16 17:46:48 +02001382 LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
1383 LIGHTBAR_CMD_SUSPEND = 20,
1384 LIGHTBAR_CMD_RESUME = 21,
Simon Glassdeaf39e2013-02-25 14:08:36 -08001385 LIGHTBAR_NUM_CMDS
1386};
1387
1388/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001389/* LED control commands */
1390
1391#define EC_CMD_LED_CONTROL 0x29
1392
1393enum ec_led_id {
1394 /* LED to indicate battery state of charge */
1395 EC_LED_ID_BATTERY_LED = 0,
1396 /*
1397 * LED to indicate system power state (on or in suspend).
1398 * May be on power button or on C-panel.
1399 */
1400 EC_LED_ID_POWER_LED,
1401 /* LED on power adapter or its plug */
1402 EC_LED_ID_ADAPTER_LED,
1403
1404 EC_LED_ID_COUNT
1405};
1406
1407/* LED control flags */
1408#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1409#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1410
1411enum ec_led_colors {
1412 EC_LED_COLOR_RED = 0,
1413 EC_LED_COLOR_GREEN,
1414 EC_LED_COLOR_BLUE,
1415 EC_LED_COLOR_YELLOW,
1416 EC_LED_COLOR_WHITE,
1417
1418 EC_LED_COLOR_COUNT
1419};
1420
1421struct ec_params_led_control {
1422 uint8_t led_id; /* Which LED to control */
1423 uint8_t flags; /* Control flags */
1424
1425 uint8_t brightness[EC_LED_COLOR_COUNT];
1426} __packed;
1427
1428struct ec_response_led_control {
1429 /*
1430 * Available brightness value range.
1431 *
1432 * Range 0 means color channel not present.
1433 * Range 1 means on/off control.
1434 * Other values means the LED is control by PWM.
1435 */
1436 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1437} __packed;
1438
1439/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08001440/* Verified boot commands */
1441
1442/*
1443 * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
1444 * reused for other purposes with version > 0.
1445 */
1446
1447/* Verified boot hash command */
1448#define EC_CMD_VBOOT_HASH 0x2A
1449
1450struct ec_params_vboot_hash {
1451 uint8_t cmd; /* enum ec_vboot_hash_cmd */
1452 uint8_t hash_type; /* enum ec_vboot_hash_type */
1453 uint8_t nonce_size; /* Nonce size; may be 0 */
1454 uint8_t reserved0; /* Reserved; set 0 */
1455 uint32_t offset; /* Offset in flash to hash */
1456 uint32_t size; /* Number of bytes to hash */
1457 uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
1458} __packed;
1459
1460struct ec_response_vboot_hash {
1461 uint8_t status; /* enum ec_vboot_hash_status */
1462 uint8_t hash_type; /* enum ec_vboot_hash_type */
1463 uint8_t digest_size; /* Size of hash digest in bytes */
1464 uint8_t reserved0; /* Ignore; will be 0 */
1465 uint32_t offset; /* Offset in flash which was hashed */
1466 uint32_t size; /* Number of bytes hashed */
1467 uint8_t hash_digest[64]; /* Hash digest data */
1468} __packed;
1469
1470enum ec_vboot_hash_cmd {
1471 EC_VBOOT_HASH_GET = 0, /* Get current hash status */
1472 EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
1473 EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
1474 EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
1475};
1476
1477enum ec_vboot_hash_type {
1478 EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
1479};
1480
1481enum ec_vboot_hash_status {
1482 EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
1483 EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
1484 EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
1485};
1486
1487/*
1488 * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
1489 * If one of these is specified, the EC will automatically update offset and
1490 * size to the correct values for the specified image (RO or RW).
1491 */
1492#define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
1493#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
1494
1495/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001496/*
1497 * Motion sense commands. We'll make separate structs for sub-commands with
1498 * different input args, so that we know how much to expect.
1499 */
1500#define EC_CMD_MOTION_SENSE_CMD 0x2B
1501
1502/* Motion sense commands */
1503enum motionsense_command {
1504 /*
1505 * Dump command returns all motion sensor data including motion sense
1506 * module flags and individual sensor flags.
1507 */
1508 MOTIONSENSE_CMD_DUMP = 0,
1509
1510 /*
1511 * Info command returns data describing the details of a given sensor,
1512 * including enum motionsensor_type, enum motionsensor_location, and
1513 * enum motionsensor_chip.
1514 */
1515 MOTIONSENSE_CMD_INFO = 1,
1516
1517 /*
1518 * EC Rate command is a setter/getter command for the EC sampling rate
1519 * of all motion sensors in milliseconds.
1520 */
1521 MOTIONSENSE_CMD_EC_RATE = 2,
1522
1523 /*
1524 * Sensor ODR command is a setter/getter command for the output data
1525 * rate of a specific motion sensor in millihertz.
1526 */
1527 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1528
1529 /*
1530 * Sensor range command is a setter/getter command for the range of
1531 * a specified motion sensor in +/-G's or +/- deg/s.
1532 */
1533 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1534
1535 /*
1536 * Setter/getter command for the keyboard wake angle. When the lid
1537 * angle is greater than this value, keyboard wake is disabled in S3,
1538 * and when the lid angle goes less than this value, keyboard wake is
1539 * enabled. Note, the lid angle measurement is an approximate,
1540 * un-calibrated value, hence the wake angle isn't exact.
1541 */
1542 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1543
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001544 /*
1545 * Returns a single sensor data.
1546 */
1547 MOTIONSENSE_CMD_DATA = 6,
1548
1549 /*
1550 * Perform low level calibration.. On sensors that support it, ask to
1551 * do offset calibration.
1552 */
1553 MOTIONSENSE_CMD_PERFORM_CALIB = 10,
1554
1555 /*
1556 * Sensor Offset command is a setter/getter command for the offset used
1557 * for calibration. The offsets can be calculated by the host, or via
1558 * PERFORM_CALIB command.
1559 */
1560 MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
1561
Bill Richardson5271db22014-04-30 10:44:08 -07001562 /* Number of motionsense sub-commands. */
1563 MOTIONSENSE_NUM_CMDS
1564};
1565
1566enum motionsensor_id {
1567 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1568 EC_MOTION_SENSOR_ACCEL_LID = 1,
1569 EC_MOTION_SENSOR_GYRO = 2,
1570
1571 /*
1572 * Note, if more sensors are added and this count changes, the padding
1573 * in ec_response_motion_sense dump command must be modified.
1574 */
1575 EC_MOTION_SENSOR_COUNT = 3
1576};
1577
1578/* List of motion sensor types. */
1579enum motionsensor_type {
1580 MOTIONSENSE_TYPE_ACCEL = 0,
1581 MOTIONSENSE_TYPE_GYRO = 1,
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001582 MOTIONSENSE_TYPE_MAG = 2,
1583 MOTIONSENSE_TYPE_PROX = 3,
1584 MOTIONSENSE_TYPE_LIGHT = 4,
1585 MOTIONSENSE_TYPE_ACTIVITY = 5,
Gwendal Grignoud7322482017-01-24 14:41:41 +01001586 MOTIONSENSE_TYPE_BARO = 6,
1587 MOTIONSENSE_TYPE_MAX,
Bill Richardson5271db22014-04-30 10:44:08 -07001588};
1589
1590/* List of motion sensor locations. */
1591enum motionsensor_location {
1592 MOTIONSENSE_LOC_BASE = 0,
1593 MOTIONSENSE_LOC_LID = 1,
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001594 MOTIONSENSE_LOC_MAX,
Bill Richardson5271db22014-04-30 10:44:08 -07001595};
1596
1597/* List of motion sensor chips. */
1598enum motionsensor_chip {
1599 MOTIONSENSE_CHIP_KXCJ9 = 0,
1600};
1601
1602/* Module flag masks used for the dump sub-command. */
1603#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1604
1605/* Sensor flag masks used for the dump sub-command. */
1606#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1607
1608/*
1609 * Send this value for the data element to only perform a read. If you
1610 * send any other value, the EC will interpret it as data to set and will
1611 * return the actual value set.
1612 */
1613#define EC_MOTION_SENSE_NO_VALUE -1
1614
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001615#define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
1616
1617/* Set Calibration information */
1618#define MOTION_SENSE_SET_OFFSET 1
1619
1620struct ec_response_motion_sensor_data {
1621 /* Flags for each sensor. */
1622 uint8_t flags;
1623 /* Sensor number the data comes from */
1624 uint8_t sensor_num;
1625 /* Each sensor is up to 3-axis. */
1626 union {
1627 int16_t data[3];
1628 struct {
1629 uint16_t rsvd;
1630 uint32_t timestamp;
1631 } __packed;
1632 struct {
1633 uint8_t activity; /* motionsensor_activity */
1634 uint8_t state;
1635 int16_t add_info[2];
1636 };
1637 };
1638} __packed;
1639
Bill Richardson5271db22014-04-30 10:44:08 -07001640struct ec_params_motion_sense {
1641 uint8_t cmd;
1642 union {
1643 /* Used for MOTIONSENSE_CMD_DUMP. */
1644 struct {
1645 /* no args */
1646 } dump;
1647
1648 /*
1649 * Used for MOTIONSENSE_CMD_EC_RATE and
1650 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1651 */
1652 struct {
1653 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1654 int16_t data;
1655 } ec_rate, kb_wake_angle;
1656
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001657 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1658 struct {
1659 uint8_t sensor_num;
1660
1661 /*
1662 * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
1663 * the calibration information in the EC.
1664 * If unset, just retrieve calibration information.
1665 */
1666 uint16_t flags;
1667
1668 /*
1669 * Temperature at calibration, in units of 0.01 C
1670 * 0x8000: invalid / unknown.
1671 * 0x0: 0C
1672 * 0x7fff: +327.67C
1673 */
1674 int16_t temp;
1675
1676 /*
1677 * Offset for calibration.
1678 * Unit:
1679 * Accelerometer: 1/1024 g
1680 * Gyro: 1/1024 deg/s
1681 * Compass: 1/16 uT
1682 */
1683 int16_t offset[3];
1684 } __packed sensor_offset;
1685
Bill Richardson5271db22014-04-30 10:44:08 -07001686 /* Used for MOTIONSENSE_CMD_INFO. */
1687 struct {
Bill Richardson5271db22014-04-30 10:44:08 -07001688 uint8_t sensor_num;
1689 } info;
1690
1691 /*
1692 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1693 * MOTIONSENSE_CMD_SENSOR_RANGE.
1694 */
1695 struct {
1696 /* Should be element of enum motionsensor_id. */
1697 uint8_t sensor_num;
1698
1699 /* Rounding flag, true for round-up, false for down. */
1700 uint8_t roundup;
1701
1702 uint16_t reserved;
1703
1704 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1705 int32_t data;
1706 } sensor_odr, sensor_range;
1707 };
1708} __packed;
1709
1710struct ec_response_motion_sense {
1711 union {
1712 /* Used for MOTIONSENSE_CMD_DUMP. */
1713 struct {
1714 /* Flags representing the motion sensor module. */
1715 uint8_t module_flags;
1716
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001717 /* Number of sensors managed directly by the EC. */
1718 uint8_t sensor_count;
Bill Richardson5271db22014-04-30 10:44:08 -07001719
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001720 /*
1721 * Sensor data is truncated if response_max is too small
1722 * for holding all the data.
1723 */
1724 struct ec_response_motion_sensor_data sensor[0];
Bill Richardson5271db22014-04-30 10:44:08 -07001725 } dump;
1726
1727 /* Used for MOTIONSENSE_CMD_INFO. */
1728 struct {
1729 /* Should be element of enum motionsensor_type. */
1730 uint8_t type;
1731
1732 /* Should be element of enum motionsensor_location. */
1733 uint8_t location;
1734
1735 /* Should be element of enum motionsensor_chip. */
1736 uint8_t chip;
1737 } info;
1738
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001739 /* Used for MOTIONSENSE_CMD_DATA */
1740 struct ec_response_motion_sensor_data data;
1741
Bill Richardson5271db22014-04-30 10:44:08 -07001742 /*
1743 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1744 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1745 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1746 */
1747 struct {
1748 /* Current value of the parameter queried. */
1749 int32_t ret;
1750 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
Enric Balletbo i Serra974e6f02016-08-01 11:54:35 +02001751
1752 /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
1753 struct {
1754 int16_t temp;
1755 int16_t offset[3];
1756 } sensor_offset, perform_calib;
Bill Richardson5271db22014-04-30 10:44:08 -07001757 };
1758} __packed;
1759
1760/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08001761/* USB charging control commands */
1762
1763/* Set USB port charging mode */
1764#define EC_CMD_USB_CHARGE_SET_MODE 0x30
1765
1766struct ec_params_usb_charge_set_mode {
1767 uint8_t usb_port_id;
1768 uint8_t mode;
1769} __packed;
1770
1771/*****************************************************************************/
1772/* Persistent storage for host */
1773
1774/* Maximum bytes that can be read/written in a single command */
1775#define EC_PSTORE_SIZE_MAX 64
1776
1777/* Get persistent storage info */
1778#define EC_CMD_PSTORE_INFO 0x40
1779
1780struct ec_response_pstore_info {
1781 /* Persistent storage size, in bytes */
1782 uint32_t pstore_size;
1783 /* Access size; read/write offset and size must be a multiple of this */
1784 uint32_t access_size;
1785} __packed;
1786
1787/*
1788 * Read persistent storage
1789 *
1790 * Response is params.size bytes of data.
1791 */
1792#define EC_CMD_PSTORE_READ 0x41
1793
1794struct ec_params_pstore_read {
1795 uint32_t offset; /* Byte offset to read */
1796 uint32_t size; /* Size to read in bytes */
1797} __packed;
1798
1799/* Write persistent storage */
1800#define EC_CMD_PSTORE_WRITE 0x42
1801
1802struct ec_params_pstore_write {
1803 uint32_t offset; /* Byte offset to write */
1804 uint32_t size; /* Size to write in bytes */
1805 uint8_t data[EC_PSTORE_SIZE_MAX];
1806} __packed;
1807
1808/*****************************************************************************/
1809/* Real-time clock */
1810
1811/* RTC params and response structures */
1812struct ec_params_rtc {
1813 uint32_t time;
1814} __packed;
1815
1816struct ec_response_rtc {
1817 uint32_t time;
1818} __packed;
1819
1820/* These use ec_response_rtc */
1821#define EC_CMD_RTC_GET_VALUE 0x44
1822#define EC_CMD_RTC_GET_ALARM 0x45
1823
1824/* These all use ec_params_rtc */
1825#define EC_CMD_RTC_SET_VALUE 0x46
1826#define EC_CMD_RTC_SET_ALARM 0x47
1827
Stephen Barber3eff6d22017-11-10 22:55:52 +01001828/* Pass as param to SET_ALARM to clear the current alarm */
1829#define EC_RTC_ALARM_CLEAR 0
1830
Simon Glassdeaf39e2013-02-25 14:08:36 -08001831/*****************************************************************************/
1832/* Port80 log access */
1833
Stephen Barber256ab952015-06-09 13:04:43 +02001834/* Maximum entries that can be read/written in a single command */
1835#define EC_PORT80_SIZE_MAX 32
1836
Simon Glassdeaf39e2013-02-25 14:08:36 -08001837/* Get last port80 code from previous boot */
1838#define EC_CMD_PORT80_LAST_BOOT 0x48
Stephen Barber256ab952015-06-09 13:04:43 +02001839#define EC_CMD_PORT80_READ 0x48
1840
1841enum ec_port80_subcmd {
1842 EC_PORT80_GET_INFO = 0,
1843 EC_PORT80_READ_BUFFER,
1844};
1845
1846struct ec_params_port80_read {
1847 uint16_t subcmd;
1848 union {
1849 struct {
1850 uint32_t offset;
1851 uint32_t num_entries;
1852 } read_buffer;
1853 };
1854} __packed;
1855
1856struct ec_response_port80_read {
1857 union {
1858 struct {
1859 uint32_t writes;
1860 uint32_t history_size;
1861 uint32_t last_boot;
1862 } get_info;
1863 struct {
1864 uint16_t codes[EC_PORT80_SIZE_MAX];
1865 } data;
1866 };
1867} __packed;
Simon Glassdeaf39e2013-02-25 14:08:36 -08001868
1869struct ec_response_port80_last_boot {
1870 uint16_t code;
1871} __packed;
1872
1873/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07001874/* Thermal engine commands. Note that there are two implementations. We'll
1875 * reuse the command number, but the data and behavior is incompatible.
1876 * Version 0 is what originally shipped on Link.
1877 * Version 1 separates the CPU thermal limits from the fan control.
1878 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001879
Simon Glassdeaf39e2013-02-25 14:08:36 -08001880#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
Bill Richardson5271db22014-04-30 10:44:08 -07001881#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
Simon Glassdeaf39e2013-02-25 14:08:36 -08001882
Bill Richardson5271db22014-04-30 10:44:08 -07001883/* The version 0 structs are opaque. You have to know what they are for
1884 * the get/set commands to make any sense.
1885 */
1886
1887/* Version 0 - set */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001888struct ec_params_thermal_set_threshold {
1889 uint8_t sensor_type;
1890 uint8_t threshold_id;
1891 uint16_t value;
1892} __packed;
1893
Bill Richardson5271db22014-04-30 10:44:08 -07001894/* Version 0 - get */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001895struct ec_params_thermal_get_threshold {
1896 uint8_t sensor_type;
1897 uint8_t threshold_id;
1898} __packed;
1899
1900struct ec_response_thermal_get_threshold {
1901 uint16_t value;
1902} __packed;
1903
Bill Richardson5271db22014-04-30 10:44:08 -07001904
1905/* The version 1 structs are visible. */
1906enum ec_temp_thresholds {
1907 EC_TEMP_THRESH_WARN = 0,
1908 EC_TEMP_THRESH_HIGH,
1909 EC_TEMP_THRESH_HALT,
1910
1911 EC_TEMP_THRESH_COUNT
1912};
1913
1914/* Thermal configuration for one temperature sensor. Temps are in degrees K.
1915 * Zero values will be silently ignored by the thermal task.
1916 */
1917struct ec_thermal_config {
1918 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1919 uint32_t temp_fan_off; /* no active cooling needed */
1920 uint32_t temp_fan_max; /* max active cooling needed */
1921} __packed;
1922
1923/* Version 1 - get config for one sensor. */
1924struct ec_params_thermal_get_threshold_v1 {
1925 uint32_t sensor_num;
1926} __packed;
1927/* This returns a struct ec_thermal_config */
1928
1929/* Version 1 - set config for one sensor.
1930 * Use read-modify-write for best results! */
1931struct ec_params_thermal_set_threshold_v1 {
1932 uint32_t sensor_num;
1933 struct ec_thermal_config cfg;
1934} __packed;
1935/* This returns no data */
1936
1937/****************************************************************************/
1938
Simon Glassdeaf39e2013-02-25 14:08:36 -08001939/* Toggle automatic fan control */
1940#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
1941
1942/* Get TMP006 calibration data */
1943#define EC_CMD_TMP006_GET_CALIBRATION 0x53
1944
1945struct ec_params_tmp006_get_calibration {
1946 uint8_t index;
1947} __packed;
1948
1949struct ec_response_tmp006_get_calibration {
1950 float s0;
1951 float b0;
1952 float b1;
1953 float b2;
1954} __packed;
1955
1956/* Set TMP006 calibration data */
1957#define EC_CMD_TMP006_SET_CALIBRATION 0x54
1958
1959struct ec_params_tmp006_set_calibration {
1960 uint8_t index;
1961 uint8_t reserved[3]; /* Reserved; set 0 */
1962 float s0;
1963 float b0;
1964 float b1;
1965 float b2;
1966} __packed;
1967
Bill Richardson5271db22014-04-30 10:44:08 -07001968/* Read raw TMP006 data */
1969#define EC_CMD_TMP006_GET_RAW 0x55
1970
1971struct ec_params_tmp006_get_raw {
1972 uint8_t index;
1973} __packed;
1974
1975struct ec_response_tmp006_get_raw {
1976 int32_t t; /* In 1/100 K */
1977 int32_t v; /* In nV */
1978};
1979
Simon Glassdeaf39e2013-02-25 14:08:36 -08001980/*****************************************************************************/
1981/* MKBP - Matrix KeyBoard Protocol */
1982
1983/*
1984 * Read key state
1985 *
1986 * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
1987 * expected response size.
Douglas Andersonb44c4d32017-01-20 11:14:14 +01001988 *
1989 * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
1990 * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
1991 * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
Simon Glassdeaf39e2013-02-25 14:08:36 -08001992 */
1993#define EC_CMD_MKBP_STATE 0x60
1994
Douglas Andersonb44c4d32017-01-20 11:14:14 +01001995/*
1996 * Provide information about various MKBP things. See enum ec_mkbp_info_type.
1997 */
Simon Glassdeaf39e2013-02-25 14:08:36 -08001998#define EC_CMD_MKBP_INFO 0x61
1999
2000struct ec_response_mkbp_info {
2001 uint32_t rows;
2002 uint32_t cols;
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002003 /* Formerly "switches", which was 0. */
2004 uint8_t reserved;
Simon Glassdeaf39e2013-02-25 14:08:36 -08002005} __packed;
2006
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002007struct ec_params_mkbp_info {
2008 uint8_t info_type;
2009 uint8_t event_type;
2010} __packed;
2011
2012enum ec_mkbp_info_type {
2013 /*
2014 * Info about the keyboard matrix: number of rows and columns.
2015 *
2016 * Returns struct ec_response_mkbp_info.
2017 */
2018 EC_MKBP_INFO_KBD = 0,
2019
2020 /*
2021 * For buttons and switches, info about which specifically are
2022 * supported. event_type must be set to one of the values in enum
2023 * ec_mkbp_event.
2024 *
2025 * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
2026 * bitmask indicating which buttons or switches are present. See the
2027 * bit inidices below.
2028 */
2029 EC_MKBP_INFO_SUPPORTED = 1,
2030
2031 /*
2032 * Instantaneous state of buttons and switches.
2033 *
2034 * event_type must be set to one of the values in enum ec_mkbp_event.
2035 *
2036 * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
2037 * indicating the current state of the keyboard matrix.
2038 *
2039 * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
2040 * event state.
2041 *
2042 * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
2043 * state of supported buttons.
2044 *
2045 * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
2046 * state of supported switches.
2047 */
2048 EC_MKBP_INFO_CURRENT = 2,
2049};
2050
Simon Glassdeaf39e2013-02-25 14:08:36 -08002051/* Simulate key press */
2052#define EC_CMD_MKBP_SIMULATE_KEY 0x62
2053
2054struct ec_params_mkbp_simulate_key {
2055 uint8_t col;
2056 uint8_t row;
2057 uint8_t pressed;
2058} __packed;
2059
2060/* Configure keyboard scanning */
2061#define EC_CMD_MKBP_SET_CONFIG 0x64
2062#define EC_CMD_MKBP_GET_CONFIG 0x65
2063
2064/* flags */
2065enum mkbp_config_flags {
2066 EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
2067};
2068
2069enum mkbp_config_valid {
2070 EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
2071 EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
2072 EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
2073 EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
2074 EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
2075 EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
2076 EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
2077};
2078
2079/* Configuration for our key scanning algorithm */
2080struct ec_mkbp_config {
2081 uint32_t valid_mask; /* valid fields */
2082 uint8_t flags; /* some flags (enum mkbp_config_flags) */
2083 uint8_t valid_flags; /* which flags are valid */
2084 uint16_t scan_period_us; /* period between start of scans */
2085 /* revert to interrupt mode after no activity for this long */
2086 uint32_t poll_timeout_us;
2087 /*
2088 * minimum post-scan relax time. Once we finish a scan we check
2089 * the time until we are due to start the next one. If this time is
2090 * shorter this field, we use this instead.
2091 */
2092 uint16_t min_post_scan_delay_us;
2093 /* delay between setting up output and waiting for it to settle */
2094 uint16_t output_settle_us;
2095 uint16_t debounce_down_us; /* time for debounce on key down */
2096 uint16_t debounce_up_us; /* time for debounce on key up */
2097 /* maximum depth to allow for fifo (0 = no keyscan output) */
2098 uint8_t fifo_max_depth;
2099} __packed;
2100
2101struct ec_params_mkbp_set_config {
2102 struct ec_mkbp_config config;
2103} __packed;
2104
2105struct ec_response_mkbp_get_config {
2106 struct ec_mkbp_config config;
2107} __packed;
2108
2109/* Run the key scan emulation */
2110#define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
2111
2112enum ec_keyscan_seq_cmd {
2113 EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
2114 EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
2115 EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
2116 EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
2117 EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
2118};
2119
2120enum ec_collect_flags {
2121 /*
2122 * Indicates this scan was processed by the EC. Due to timing, some
2123 * scans may be skipped.
2124 */
2125 EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
2126};
2127
2128struct ec_collect_item {
2129 uint8_t flags; /* some flags (enum ec_collect_flags) */
2130};
2131
2132struct ec_params_keyscan_seq_ctrl {
2133 uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
2134 union {
2135 struct {
2136 uint8_t active; /* still active */
2137 uint8_t num_items; /* number of items */
2138 /* Current item being presented */
2139 uint8_t cur_item;
2140 } status;
2141 struct {
2142 /*
2143 * Absolute time for this scan, measured from the
2144 * start of the sequence.
2145 */
2146 uint32_t time_us;
2147 uint8_t scan[0]; /* keyscan data */
2148 } add;
2149 struct {
2150 uint8_t start_item; /* First item to return */
2151 uint8_t num_items; /* Number of items to return */
2152 } collect;
2153 };
2154} __packed;
2155
2156struct ec_result_keyscan_seq_ctrl {
2157 union {
2158 struct {
2159 uint8_t num_items; /* Number of items */
2160 /* Data for each item */
2161 struct ec_collect_item item[0];
2162 } collect;
2163 };
2164} __packed;
2165
Vic Yang6f1d9122016-08-10 19:05:24 +02002166/*
2167 * Command for retrieving the next pending MKBP event from the EC device
2168 *
2169 * The device replies with UNAVAILABLE if there aren't any pending events.
2170 */
2171#define EC_CMD_GET_NEXT_EVENT 0x67
2172
2173enum ec_mkbp_event {
2174 /* Keyboard matrix changed. The event data is the new matrix state. */
2175 EC_MKBP_EVENT_KEY_MATRIX = 0,
2176
2177 /* New host event. The event data is 4 bytes of host event flags. */
2178 EC_MKBP_EVENT_HOST_EVENT = 1,
2179
2180 /* New Sensor FIFO data. The event data is fifo_info structure. */
2181 EC_MKBP_EVENT_SENSOR_FIFO = 2,
2182
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002183 /* The state of the non-matrixed buttons have changed. */
2184 EC_MKBP_EVENT_BUTTON = 3,
2185
2186 /* The state of the switches have changed. */
2187 EC_MKBP_EVENT_SWITCH = 4,
2188
Rajat Jaine6eba3f2017-04-03 11:53:41 -07002189 /* EC sent a sysrq command */
2190 EC_MKBP_EVENT_SYSRQ = 6,
2191
Neil Armstrongf47674e2018-07-04 17:08:19 +02002192 /* Notify the AP that something happened on CEC */
2193 EC_MKBP_EVENT_CEC_EVENT = 8,
2194
2195 /* Send an incoming CEC message to the AP */
2196 EC_MKBP_EVENT_CEC_MESSAGE = 9,
2197
Vic Yang6f1d9122016-08-10 19:05:24 +02002198 /* Number of MKBP events */
2199 EC_MKBP_EVENT_COUNT,
2200};
2201
2202union ec_response_get_next_data {
2203 uint8_t key_matrix[13];
2204
2205 /* Unaligned */
2206 uint32_t host_event;
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002207
2208 uint32_t buttons;
2209 uint32_t switches;
Rajat Jaine6eba3f2017-04-03 11:53:41 -07002210 uint32_t sysrq;
Vic Yang6f1d9122016-08-10 19:05:24 +02002211} __packed;
2212
Neil Armstrong57e94c82018-07-04 17:08:18 +02002213union ec_response_get_next_data_v1 {
2214 uint8_t key_matrix[16];
2215 uint32_t host_event;
2216 uint32_t buttons;
2217 uint32_t switches;
2218 uint32_t sysrq;
2219 uint32_t cec_events;
2220 uint8_t cec_message[16];
2221} __packed;
2222
Vic Yang6f1d9122016-08-10 19:05:24 +02002223struct ec_response_get_next_event {
2224 uint8_t event_type;
2225 /* Followed by event data if any */
2226 union ec_response_get_next_data data;
2227} __packed;
2228
Neil Armstrong57e94c82018-07-04 17:08:18 +02002229struct ec_response_get_next_event_v1 {
2230 uint8_t event_type;
2231 /* Followed by event data if any */
2232 union ec_response_get_next_data_v1 data;
2233} __packed;
2234
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002235/* Bit indices for buttons and switches.*/
2236/* Buttons */
2237#define EC_MKBP_POWER_BUTTON 0
2238#define EC_MKBP_VOL_UP 1
2239#define EC_MKBP_VOL_DOWN 2
2240
2241/* Switches */
2242#define EC_MKBP_LID_OPEN 0
Gwendal Grignou6ccc3a32017-01-27 11:52:35 +01002243#define EC_MKBP_TABLET_MODE 1
Dmitry Torokhov78d8f8f2018-10-05 11:41:13 -07002244#define EC_MKBP_BASE_ATTACHED 2
Douglas Andersonb44c4d32017-01-20 11:14:14 +01002245
Simon Glassdeaf39e2013-02-25 14:08:36 -08002246/*****************************************************************************/
2247/* Temperature sensor commands */
2248
2249/* Read temperature sensor info */
2250#define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
2251
2252struct ec_params_temp_sensor_get_info {
2253 uint8_t id;
2254} __packed;
2255
2256struct ec_response_temp_sensor_get_info {
2257 char sensor_name[32];
2258 uint8_t sensor_type;
2259} __packed;
2260
2261/*****************************************************************************/
2262
2263/*
2264 * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
2265 * commands accidentally sent to the wrong interface. See the ACPI section
2266 * below.
2267 */
2268
2269/*****************************************************************************/
2270/* Host event commands */
2271
2272/*
2273 * Host event mask params and response structures, shared by all of the host
2274 * event commands below.
2275 */
2276struct ec_params_host_event_mask {
2277 uint32_t mask;
2278} __packed;
2279
2280struct ec_response_host_event_mask {
2281 uint32_t mask;
2282} __packed;
2283
2284/* These all use ec_response_host_event_mask */
2285#define EC_CMD_HOST_EVENT_GET_B 0x87
2286#define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
2287#define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
2288#define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
2289
2290/* These all use ec_params_host_event_mask */
2291#define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
2292#define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
2293#define EC_CMD_HOST_EVENT_CLEAR 0x8c
2294#define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
2295#define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
2296
2297/*****************************************************************************/
2298/* Switch commands */
2299
2300/* Enable/disable LCD backlight */
2301#define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
2302
2303struct ec_params_switch_enable_backlight {
2304 uint8_t enabled;
2305} __packed;
2306
2307/* Enable/disable WLAN/Bluetooth */
2308#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
Bill Richardson5271db22014-04-30 10:44:08 -07002309#define EC_VER_SWITCH_ENABLE_WIRELESS 1
Simon Glassdeaf39e2013-02-25 14:08:36 -08002310
Bill Richardson5271db22014-04-30 10:44:08 -07002311/* Version 0 params; no response */
2312struct ec_params_switch_enable_wireless_v0 {
Simon Glassdeaf39e2013-02-25 14:08:36 -08002313 uint8_t enabled;
2314} __packed;
2315
Bill Richardson5271db22014-04-30 10:44:08 -07002316/* Version 1 params */
2317struct ec_params_switch_enable_wireless_v1 {
2318 /* Flags to enable now */
2319 uint8_t now_flags;
2320
2321 /* Which flags to copy from now_flags */
2322 uint8_t now_mask;
2323
2324 /*
2325 * Flags to leave enabled in S3, if they're on at the S0->S3
2326 * transition. (Other flags will be disabled by the S0->S3
2327 * transition.)
2328 */
2329 uint8_t suspend_flags;
2330
2331 /* Which flags to copy from suspend_flags */
2332 uint8_t suspend_mask;
2333} __packed;
2334
2335/* Version 1 response */
2336struct ec_response_switch_enable_wireless_v1 {
2337 /* Flags to enable now */
2338 uint8_t now_flags;
2339
2340 /* Flags to leave enabled in S3 */
2341 uint8_t suspend_flags;
2342} __packed;
2343
Simon Glassdeaf39e2013-02-25 14:08:36 -08002344/*****************************************************************************/
2345/* GPIO commands. Only available on EC if write protect has been disabled. */
2346
2347/* Set GPIO output value */
2348#define EC_CMD_GPIO_SET 0x92
2349
2350struct ec_params_gpio_set {
2351 char name[32];
2352 uint8_t val;
2353} __packed;
2354
2355/* Get GPIO value */
2356#define EC_CMD_GPIO_GET 0x93
2357
Stephen Barber256ab952015-06-09 13:04:43 +02002358/* Version 0 of input params and response */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002359struct ec_params_gpio_get {
2360 char name[32];
2361} __packed;
2362struct ec_response_gpio_get {
2363 uint8_t val;
2364} __packed;
2365
Stephen Barber256ab952015-06-09 13:04:43 +02002366/* Version 1 of input params and response */
2367struct ec_params_gpio_get_v1 {
2368 uint8_t subcmd;
2369 union {
2370 struct {
2371 char name[32];
2372 } get_value_by_name;
2373 struct {
2374 uint8_t index;
2375 } get_info;
2376 };
2377} __packed;
2378
2379struct ec_response_gpio_get_v1 {
2380 union {
2381 struct {
2382 uint8_t val;
2383 } get_value_by_name, get_count;
2384 struct {
2385 uint8_t val;
2386 char name[32];
2387 uint32_t flags;
2388 } get_info;
2389 };
2390} __packed;
2391
2392enum gpio_get_subcmd {
2393 EC_GPIO_GET_BY_NAME = 0,
2394 EC_GPIO_GET_COUNT = 1,
2395 EC_GPIO_GET_INFO = 2,
2396};
2397
Simon Glassdeaf39e2013-02-25 14:08:36 -08002398/*****************************************************************************/
2399/* I2C commands. Only available when flash write protect is unlocked. */
2400
Bill Richardson5271db22014-04-30 10:44:08 -07002401/*
2402 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
2403 * removed soon. Use EC_CMD_I2C_XFER instead.
2404 */
2405
Simon Glassdeaf39e2013-02-25 14:08:36 -08002406/* Read I2C bus */
2407#define EC_CMD_I2C_READ 0x94
2408
2409struct ec_params_i2c_read {
Bill Richardson5271db22014-04-30 10:44:08 -07002410 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002411 uint8_t read_size; /* Either 8 or 16. */
2412 uint8_t port;
2413 uint8_t offset;
2414} __packed;
2415struct ec_response_i2c_read {
2416 uint16_t data;
2417} __packed;
2418
2419/* Write I2C bus */
2420#define EC_CMD_I2C_WRITE 0x95
2421
2422struct ec_params_i2c_write {
2423 uint16_t data;
Bill Richardson5271db22014-04-30 10:44:08 -07002424 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002425 uint8_t write_size; /* Either 8 or 16. */
2426 uint8_t port;
2427 uint8_t offset;
2428} __packed;
2429
2430/*****************************************************************************/
2431/* Charge state commands. Only available when flash write protect unlocked. */
2432
Bill Richardson5271db22014-04-30 10:44:08 -07002433/* Force charge state machine to stop charging the battery or force it to
2434 * discharge the battery.
2435 */
2436#define EC_CMD_CHARGE_CONTROL 0x96
2437#define EC_VER_CHARGE_CONTROL 1
Simon Glassdeaf39e2013-02-25 14:08:36 -08002438
Bill Richardson5271db22014-04-30 10:44:08 -07002439enum ec_charge_control_mode {
2440 CHARGE_CONTROL_NORMAL = 0,
2441 CHARGE_CONTROL_IDLE,
2442 CHARGE_CONTROL_DISCHARGE,
2443};
2444
2445struct ec_params_charge_control {
2446 uint32_t mode; /* enum charge_control_mode */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002447} __packed;
2448
2449/*****************************************************************************/
2450/* Console commands. Only available when flash write protect is unlocked. */
2451
2452/* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
2453#define EC_CMD_CONSOLE_SNAPSHOT 0x97
2454
2455/*
Nicolas Boichat0aa877c2017-05-16 17:46:48 +02002456 * Read data from the saved snapshot. If the subcmd parameter is
2457 * CONSOLE_READ_NEXT, this will return data starting from the beginning of
2458 * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
2459 * end of the previous snapshot.
2460 *
2461 * The params are only looked at in version >= 1 of this command. Prior
2462 * versions will just default to CONSOLE_READ_NEXT behavior.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002463 *
2464 * Response is null-terminated string. Empty string, if there is no more
2465 * remaining output.
2466 */
2467#define EC_CMD_CONSOLE_READ 0x98
2468
Nicolas Boichat0aa877c2017-05-16 17:46:48 +02002469enum ec_console_read_subcmd {
2470 CONSOLE_READ_NEXT = 0,
2471 CONSOLE_READ_RECENT
2472};
2473
2474struct ec_params_console_read_v1 {
2475 uint8_t subcmd; /* enum ec_console_read_subcmd */
2476} __packed;
2477
Simon Glassdeaf39e2013-02-25 14:08:36 -08002478/*****************************************************************************/
2479
2480/*
Stephen Barber256ab952015-06-09 13:04:43 +02002481 * Cut off battery power immediately or after the host has shut down.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002482 *
Stephen Barber256ab952015-06-09 13:04:43 +02002483 * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
2484 * EC_RES_SUCCESS if the command was successful.
2485 * EC_RES_ERROR if the cut off command failed.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002486 */
Stephen Barber256ab952015-06-09 13:04:43 +02002487
Simon Glassdeaf39e2013-02-25 14:08:36 -08002488#define EC_CMD_BATTERY_CUT_OFF 0x99
2489
Stephen Barber256ab952015-06-09 13:04:43 +02002490#define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
2491
2492struct ec_params_battery_cutoff {
2493 uint8_t flags;
2494} __packed;
2495
Simon Glassdeaf39e2013-02-25 14:08:36 -08002496/*****************************************************************************/
Bill Richardson5271db22014-04-30 10:44:08 -07002497/* USB port mux control. */
Simon Glassdeaf39e2013-02-25 14:08:36 -08002498
2499/*
Bill Richardson5271db22014-04-30 10:44:08 -07002500 * Switch USB mux or return to automatic switching.
Simon Glassdeaf39e2013-02-25 14:08:36 -08002501 */
Bill Richardson5271db22014-04-30 10:44:08 -07002502#define EC_CMD_USB_MUX 0x9a
2503
2504struct ec_params_usb_mux {
2505 uint8_t mux;
2506} __packed;
2507
2508/*****************************************************************************/
2509/* LDOs / FETs control. */
2510
2511enum ec_ldo_state {
2512 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
2513 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
2514};
2515
2516/*
2517 * Switch on/off a LDO.
2518 */
2519#define EC_CMD_LDO_SET 0x9b
2520
2521struct ec_params_ldo_set {
2522 uint8_t index;
2523 uint8_t state;
2524} __packed;
2525
2526/*
2527 * Get LDO state.
2528 */
2529#define EC_CMD_LDO_GET 0x9c
2530
2531struct ec_params_ldo_get {
2532 uint8_t index;
2533} __packed;
2534
2535struct ec_response_ldo_get {
2536 uint8_t state;
2537} __packed;
2538
2539/*****************************************************************************/
2540/* Power info. */
2541
2542/*
2543 * Get power info.
2544 */
2545#define EC_CMD_POWER_INFO 0x9d
2546
2547struct ec_response_power_info {
2548 uint32_t usb_dev_type;
2549 uint16_t voltage_ac;
2550 uint16_t voltage_system;
2551 uint16_t current_system;
2552 uint16_t usb_current_limit;
2553} __packed;
2554
2555/*****************************************************************************/
2556/* I2C passthru command */
2557
2558#define EC_CMD_I2C_PASSTHRU 0x9e
2559
Bill Richardson5271db22014-04-30 10:44:08 -07002560/* Read data; if not present, message is a write */
2561#define EC_I2C_FLAG_READ (1 << 15)
2562
2563/* Mask for address */
2564#define EC_I2C_ADDR_MASK 0x3ff
2565
2566#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
2567#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
2568
2569/* Any error */
2570#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
2571
2572struct ec_params_i2c_passthru_msg {
2573 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
2574 uint16_t len; /* Number of bytes to read or write */
2575} __packed;
2576
2577struct ec_params_i2c_passthru {
2578 uint8_t port; /* I2C port number */
2579 uint8_t num_msgs; /* Number of messages */
2580 struct ec_params_i2c_passthru_msg msg[];
2581 /* Data to write for all messages is concatenated here */
2582} __packed;
2583
2584struct ec_response_i2c_passthru {
2585 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
2586 uint8_t num_msgs; /* Number of messages processed */
2587 uint8_t data[]; /* Data read by messages concatenated here */
2588} __packed;
2589
2590/*****************************************************************************/
2591/* Power button hang detect */
2592
2593#define EC_CMD_HANG_DETECT 0x9f
2594
2595/* Reasons to start hang detection timer */
2596/* Power button pressed */
2597#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
2598
2599/* Lid closed */
2600#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
2601
2602 /* Lid opened */
2603#define EC_HANG_START_ON_LID_OPEN (1 << 2)
2604
2605/* Start of AP S3->S0 transition (booting or resuming from suspend) */
2606#define EC_HANG_START_ON_RESUME (1 << 3)
2607
2608/* Reasons to cancel hang detection */
2609
2610/* Power button released */
2611#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
2612
2613/* Any host command from AP received */
2614#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
2615
2616/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
2617#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
2618
2619/*
2620 * If this flag is set, all the other fields are ignored, and the hang detect
2621 * timer is started. This provides the AP a way to start the hang timer
2622 * without reconfiguring any of the other hang detect settings. Note that
2623 * you must previously have configured the timeouts.
2624 */
2625#define EC_HANG_START_NOW (1 << 30)
2626
2627/*
2628 * If this flag is set, all the other fields are ignored (including
2629 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2630 * without reconfiguring any of the other hang detect settings.
2631 */
2632#define EC_HANG_STOP_NOW (1 << 31)
2633
2634struct ec_params_hang_detect {
2635 /* Flags; see EC_HANG_* */
2636 uint32_t flags;
2637
2638 /* Timeout in msec before generating host event, if enabled */
2639 uint16_t host_event_timeout_msec;
2640
2641 /* Timeout in msec before generating warm reboot, if enabled */
2642 uint16_t warm_reboot_timeout_msec;
2643} __packed;
2644
2645/*****************************************************************************/
2646/* Commands for battery charging */
2647
2648/*
2649 * This is the single catch-all host command to exchange data regarding the
2650 * charge state machine (v2 and up).
2651 */
2652#define EC_CMD_CHARGE_STATE 0xa0
2653
2654/* Subcommands for this host command */
2655enum charge_state_command {
2656 CHARGE_STATE_CMD_GET_STATE,
2657 CHARGE_STATE_CMD_GET_PARAM,
2658 CHARGE_STATE_CMD_SET_PARAM,
2659 CHARGE_STATE_NUM_CMDS
2660};
2661
2662/*
2663 * Known param numbers are defined here. Ranges are reserved for board-specific
2664 * params, which are handled by the particular implementations.
2665 */
2666enum charge_state_params {
2667 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2668 CS_PARAM_CHG_CURRENT, /* charger current limit */
2669 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2670 CS_PARAM_CHG_STATUS, /* charger-specific status */
2671 CS_PARAM_CHG_OPTION, /* charger-specific options */
2672 /* How many so far? */
2673 CS_NUM_BASE_PARAMS,
2674
2675 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2676 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2677 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2678
2679 /* Other custom param ranges go here... */
2680};
2681
2682struct ec_params_charge_state {
2683 uint8_t cmd; /* enum charge_state_command */
2684 union {
2685 struct {
2686 /* no args */
2687 } get_state;
2688
2689 struct {
2690 uint32_t param; /* enum charge_state_param */
2691 } get_param;
2692
2693 struct {
2694 uint32_t param; /* param to set */
2695 uint32_t value; /* value to set */
2696 } set_param;
2697 };
2698} __packed;
2699
2700struct ec_response_charge_state {
2701 union {
2702 struct {
2703 int ac;
2704 int chg_voltage;
2705 int chg_current;
2706 int chg_input_current;
2707 int batt_state_of_charge;
2708 } get_state;
2709
2710 struct {
2711 uint32_t value;
2712 } get_param;
2713 struct {
2714 /* no return values */
2715 } set_param;
2716 };
2717} __packed;
2718
Simon Glassdeaf39e2013-02-25 14:08:36 -08002719
2720/*
2721 * Set maximum battery charging current.
2722 */
2723#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
2724
2725struct ec_params_current_limit {
Bill Richardson5271db22014-04-30 10:44:08 -07002726 uint32_t limit; /* in mA */
2727} __packed;
2728
2729/*
Sameer Nanda06635892018-05-02 17:44:16 +02002730 * Set maximum external voltage / current.
Bill Richardson5271db22014-04-30 10:44:08 -07002731 */
Sameer Nanda06635892018-05-02 17:44:16 +02002732#define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
Bill Richardson5271db22014-04-30 10:44:08 -07002733
Sameer Nanda06635892018-05-02 17:44:16 +02002734/* Command v0 is used only on Spring and is obsolete + unsupported */
2735struct ec_params_external_power_limit_v1 {
2736 uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
2737 uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
Bill Richardson5271db22014-04-30 10:44:08 -07002738} __packed;
2739
Sameer Nanda06635892018-05-02 17:44:16 +02002740#define EC_POWER_LIMIT_NONE 0xffff
2741
Shawn Nematbakhshf00c06f2016-12-16 18:57:37 +01002742/* Inform the EC when entering a sleep state */
2743#define EC_CMD_HOST_SLEEP_EVENT 0xa9
2744
2745enum host_sleep_event {
2746 HOST_SLEEP_EVENT_S3_SUSPEND = 1,
2747 HOST_SLEEP_EVENT_S3_RESUME = 2,
2748 HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
2749 HOST_SLEEP_EVENT_S0IX_RESUME = 4
2750};
2751
2752struct ec_params_host_sleep_event {
2753 uint8_t sleep_event;
2754} __packed;
2755
Evan Greenafe2bb52019-04-03 14:34:27 -07002756/*
2757 * Use a default timeout value (CONFIG_SLEEP_TIMEOUT_MS) for detecting sleep
2758 * transition failures
2759 */
2760#define EC_HOST_SLEEP_TIMEOUT_DEFAULT 0
2761
2762/* Disable timeout detection for this sleep transition */
2763#define EC_HOST_SLEEP_TIMEOUT_INFINITE 0xFFFF
2764
2765struct ec_params_host_sleep_event_v1 {
2766 /* The type of sleep being entered or exited. */
2767 uint8_t sleep_event;
2768
2769 /* Padding */
2770 uint8_t reserved;
2771 union {
2772 /* Parameters that apply for suspend messages. */
2773 struct {
2774 /*
2775 * The timeout in milliseconds between when this message
2776 * is received and when the EC will declare sleep
2777 * transition failure if the sleep signal is not
2778 * asserted.
2779 */
2780 uint16_t sleep_timeout_ms;
2781 } suspend_params;
2782
2783 /* No parameters for non-suspend messages. */
2784 };
2785} __packed;
2786
2787/* A timeout occurred when this bit is set */
2788#define EC_HOST_RESUME_SLEEP_TIMEOUT 0x80000000
2789
2790/*
2791 * The mask defining which bits correspond to the number of sleep transitions,
2792 * as well as the maximum number of suspend line transitions that will be
2793 * reported back to the host.
2794 */
2795#define EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK 0x7FFFFFFF
2796
2797struct ec_response_host_sleep_event_v1 {
2798 union {
2799 /* Response fields that apply for resume messages. */
2800 struct {
2801 /*
2802 * The number of sleep power signal transitions that
2803 * occurred since the suspend message. The high bit
2804 * indicates a timeout occurred.
2805 */
2806 uint32_t sleep_transitions;
2807 } resume_response;
2808
2809 /* No response fields for non-resume messages. */
2810 };
2811} __packed;
2812
Bill Richardson5271db22014-04-30 10:44:08 -07002813/*****************************************************************************/
2814/* Smart battery pass-through */
2815
2816/* Get / Set 16-bit smart battery registers */
2817#define EC_CMD_SB_READ_WORD 0xb0
2818#define EC_CMD_SB_WRITE_WORD 0xb1
2819
2820/* Get / Set string smart battery parameters
2821 * formatted as SMBUS "block".
2822 */
2823#define EC_CMD_SB_READ_BLOCK 0xb2
2824#define EC_CMD_SB_WRITE_BLOCK 0xb3
2825
2826struct ec_params_sb_rd {
2827 uint8_t reg;
2828} __packed;
2829
2830struct ec_response_sb_rd_word {
2831 uint16_t value;
2832} __packed;
2833
2834struct ec_params_sb_wr_word {
2835 uint8_t reg;
2836 uint16_t value;
2837} __packed;
2838
2839struct ec_response_sb_rd_block {
2840 uint8_t data[32];
2841} __packed;
2842
2843struct ec_params_sb_wr_block {
2844 uint8_t reg;
2845 uint16_t data[32];
Simon Glassdeaf39e2013-02-25 14:08:36 -08002846} __packed;
2847
2848/*****************************************************************************/
Stephen Barber256ab952015-06-09 13:04:43 +02002849/* Battery vendor parameters
2850 *
2851 * Get or set vendor-specific parameters in the battery. Implementations may
2852 * differ between boards or batteries. On a set operation, the response
2853 * contains the actual value set, which may be rounded or clipped from the
2854 * requested value.
2855 */
2856
2857#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
2858
2859enum ec_battery_vendor_param_mode {
2860 BATTERY_VENDOR_PARAM_MODE_GET = 0,
2861 BATTERY_VENDOR_PARAM_MODE_SET,
2862};
2863
2864struct ec_params_battery_vendor_param {
2865 uint32_t param;
2866 uint32_t value;
2867 uint8_t mode;
2868} __packed;
2869
2870struct ec_response_battery_vendor_param {
2871 uint32_t value;
2872} __packed;
2873
2874/*****************************************************************************/
Cheng-Yi Chiangc1f33752018-12-18 17:06:26 +08002875/* Commands for I2S recording on audio codec. */
2876
2877#define EC_CMD_CODEC_I2S 0x00BC
2878
2879enum ec_codec_i2s_subcmd {
2880 EC_CODEC_SET_SAMPLE_DEPTH = 0x0,
2881 EC_CODEC_SET_GAIN = 0x1,
2882 EC_CODEC_GET_GAIN = 0x2,
2883 EC_CODEC_I2S_ENABLE = 0x3,
2884 EC_CODEC_I2S_SET_CONFIG = 0x4,
2885 EC_CODEC_I2S_SET_TDM_CONFIG = 0x5,
2886 EC_CODEC_I2S_SET_BCLK = 0x6,
2887};
2888
2889enum ec_sample_depth_value {
2890 EC_CODEC_SAMPLE_DEPTH_16 = 0,
2891 EC_CODEC_SAMPLE_DEPTH_24 = 1,
2892};
2893
2894enum ec_i2s_config {
2895 EC_DAI_FMT_I2S = 0,
2896 EC_DAI_FMT_RIGHT_J = 1,
2897 EC_DAI_FMT_LEFT_J = 2,
2898 EC_DAI_FMT_PCM_A = 3,
2899 EC_DAI_FMT_PCM_B = 4,
2900 EC_DAI_FMT_PCM_TDM = 5,
2901};
2902
2903struct ec_param_codec_i2s {
2904 /*
2905 * enum ec_codec_i2s_subcmd
2906 */
2907 uint8_t cmd;
2908 union {
2909 /*
2910 * EC_CODEC_SET_SAMPLE_DEPTH
2911 * Value should be one of ec_sample_depth_value.
2912 */
2913 uint8_t depth;
2914
2915 /*
2916 * EC_CODEC_SET_GAIN
2917 * Value should be 0~43 for both channels.
2918 */
2919 struct ec_param_codec_i2s_set_gain {
2920 uint8_t left;
2921 uint8_t right;
2922 } __packed gain;
2923
2924 /*
2925 * EC_CODEC_I2S_ENABLE
2926 * 1 to enable, 0 to disable.
2927 */
2928 uint8_t i2s_enable;
2929
2930 /*
2931 * EC_CODEC_I2S_SET_COFNIG
2932 * Value should be one of ec_i2s_config.
2933 */
2934 uint8_t i2s_config;
2935
2936 /*
2937 * EC_CODEC_I2S_SET_TDM_CONFIG
2938 * Value should be one of ec_i2s_config.
2939 */
2940 struct ec_param_codec_i2s_tdm {
2941 /*
2942 * 0 to 496
2943 */
2944 int16_t ch0_delay;
2945 /*
2946 * -1 to 496
2947 */
2948 int16_t ch1_delay;
2949 uint8_t adjacent_to_ch0;
2950 uint8_t adjacent_to_ch1;
2951 } __packed tdm_param;
2952
2953 /*
2954 * EC_CODEC_I2S_SET_BCLK
2955 */
2956 uint32_t bclk;
2957 };
2958} __packed;
2959
2960/*
2961 * For subcommand EC_CODEC_GET_GAIN.
2962 */
2963struct ec_response_codec_gain {
2964 uint8_t left;
2965 uint8_t right;
2966} __packed;
2967
2968/*****************************************************************************/
Simon Glassdeaf39e2013-02-25 14:08:36 -08002969/* System commands */
2970
2971/*
Bill Richardson5271db22014-04-30 10:44:08 -07002972 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
2973 * necessarily reboot the EC. Rename to "image" or something similar?
Simon Glassdeaf39e2013-02-25 14:08:36 -08002974 */
2975#define EC_CMD_REBOOT_EC 0xd2
2976
2977/* Command */
2978enum ec_reboot_cmd {
2979 EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
2980 EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
2981 EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
2982 /* (command 3 was jump to RW-B) */
2983 EC_REBOOT_COLD = 4, /* Cold-reboot */
2984 EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
2985 EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
2986};
2987
2988/* Flags for ec_params_reboot_ec.reboot_flags */
2989#define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
2990#define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
2991
2992struct ec_params_reboot_ec {
2993 uint8_t cmd; /* enum ec_reboot_cmd */
2994 uint8_t flags; /* See EC_REBOOT_FLAG_* */
2995} __packed;
2996
2997/*
2998 * Get information on last EC panic.
2999 *
3000 * Returns variable-length platform-dependent panic information. See panic.h
3001 * for details.
3002 */
3003#define EC_CMD_GET_PANIC_INFO 0xd3
3004
3005/*****************************************************************************/
3006/*
3007 * ACPI commands
3008 *
3009 * These are valid ONLY on the ACPI command/data port.
3010 */
3011
3012/*
3013 * ACPI Read Embedded Controller
3014 *
3015 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3016 *
3017 * Use the following sequence:
3018 *
3019 * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
3020 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3021 * - Write address to EC_LPC_ADDR_ACPI_DATA
3022 * - Wait for EC_LPC_CMDR_DATA bit to set
3023 * - Read value from EC_LPC_ADDR_ACPI_DATA
3024 */
3025#define EC_CMD_ACPI_READ 0x80
3026
3027/*
3028 * ACPI Write Embedded Controller
3029 *
3030 * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
3031 *
3032 * Use the following sequence:
3033 *
3034 * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
3035 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3036 * - Write address to EC_LPC_ADDR_ACPI_DATA
3037 * - Wait for EC_LPC_CMDR_PENDING bit to clear
3038 * - Write value to EC_LPC_ADDR_ACPI_DATA
3039 */
3040#define EC_CMD_ACPI_WRITE 0x81
3041
3042/*
3043 * ACPI Query Embedded Controller
3044 *
3045 * This clears the lowest-order bit in the currently pending host events, and
3046 * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
3047 * event 0x80000000 = 32), or 0 if no event was pending.
3048 */
3049#define EC_CMD_ACPI_QUERY_EVENT 0x84
3050
3051/* Valid addresses in ACPI memory space, for read/write commands */
Bill Richardson5271db22014-04-30 10:44:08 -07003052
Simon Glassdeaf39e2013-02-25 14:08:36 -08003053/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
3054#define EC_ACPI_MEM_VERSION 0x00
3055/*
3056 * Test location; writing value here updates test compliment byte to (0xff -
3057 * value).
3058 */
3059#define EC_ACPI_MEM_TEST 0x01
3060/* Test compliment; writes here are ignored. */
3061#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
Bill Richardson5271db22014-04-30 10:44:08 -07003062
Simon Glassdeaf39e2013-02-25 14:08:36 -08003063/* Keyboard backlight brightness percent (0 - 100) */
3064#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
Bill Richardson5271db22014-04-30 10:44:08 -07003065/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
3066#define EC_ACPI_MEM_FAN_DUTY 0x04
3067
3068/*
3069 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
3070 * independent thresholds attached to them. The current value of the ID
3071 * register determines which sensor is affected by the THRESHOLD and COMMIT
3072 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
3073 * as the memory-mapped sensors. The COMMIT register applies those settings.
3074 *
3075 * The spec does not mandate any way to read back the threshold settings
3076 * themselves, but when a threshold is crossed the AP needs a way to determine
3077 * which sensor(s) are responsible. Each reading of the ID register clears and
3078 * returns one sensor ID that has crossed one of its threshold (in either
3079 * direction) since the last read. A value of 0xFF means "no new thresholds
3080 * have tripped". Setting or enabling the thresholds for a sensor will clear
3081 * the unread event count for that sensor.
3082 */
3083#define EC_ACPI_MEM_TEMP_ID 0x05
3084#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
3085#define EC_ACPI_MEM_TEMP_COMMIT 0x07
3086/*
3087 * Here are the bits for the COMMIT register:
3088 * bit 0 selects the threshold index for the chosen sensor (0/1)
3089 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
3090 * Each write to the commit register affects one threshold.
3091 */
3092#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
3093#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
3094/*
3095 * Example:
3096 *
3097 * Set the thresholds for sensor 2 to 50 C and 60 C:
3098 * write 2 to [0x05] -- select temp sensor 2
3099 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
3100 * write 0x2 to [0x07] -- enable threshold 0 with this value
3101 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
3102 * write 0x3 to [0x07] -- enable threshold 1 with this value
3103 *
3104 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
3105 * write 2 to [0x05] -- select temp sensor 2
3106 * write 0x1 to [0x07] -- disable threshold 1
3107 */
3108
3109/* DPTF battery charging current limit */
3110#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
3111
3112/* Charging limit is specified in 64 mA steps */
3113#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
3114/* Value to disable DPTF battery charging limit */
3115#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
Simon Glassdeaf39e2013-02-25 14:08:36 -08003116
3117/* Current version of ACPI memory address space */
3118#define EC_ACPI_MEM_VERSION_CURRENT 1
3119
3120
3121/*****************************************************************************/
3122/*
Neil Armstrongf47674e2018-07-04 17:08:19 +02003123 * HDMI CEC commands
3124 *
3125 * These commands are for sending and receiving message via HDMI CEC
3126 */
3127#define EC_MAX_CEC_MSG_LEN 16
3128
3129/* CEC message from the AP to be written on the CEC bus */
3130#define EC_CMD_CEC_WRITE_MSG 0x00B8
3131
3132/**
3133 * struct ec_params_cec_write - Message to write to the CEC bus
3134 * @msg: message content to write to the CEC bus
3135 */
3136struct ec_params_cec_write {
3137 uint8_t msg[EC_MAX_CEC_MSG_LEN];
3138} __packed;
3139
3140/* Set various CEC parameters */
3141#define EC_CMD_CEC_SET 0x00BA
3142
3143/**
3144 * struct ec_params_cec_set - CEC parameters set
3145 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3146 * @val: in case cmd is CEC_CMD_ENABLE, this field can be 0 to disable CEC
3147 * or 1 to enable CEC functionality, in case cmd is CEC_CMD_LOGICAL_ADDRESS,
3148 * this field encodes the requested logical address between 0 and 15
3149 * or 0xff to unregister
3150 */
3151struct ec_params_cec_set {
3152 uint8_t cmd; /* enum cec_command */
3153 uint8_t val;
3154} __packed;
3155
3156/* Read various CEC parameters */
3157#define EC_CMD_CEC_GET 0x00BB
3158
3159/**
3160 * struct ec_params_cec_get - CEC parameters get
3161 * @cmd: parameter type, can be CEC_CMD_ENABLE or CEC_CMD_LOGICAL_ADDRESS
3162 */
3163struct ec_params_cec_get {
3164 uint8_t cmd; /* enum cec_command */
3165} __packed;
3166
3167/**
3168 * struct ec_response_cec_get - CEC parameters get response
3169 * @val: in case cmd was CEC_CMD_ENABLE, this field will 0 if CEC is
3170 * disabled or 1 if CEC functionality is enabled,
3171 * in case cmd was CEC_CMD_LOGICAL_ADDRESS, this will encode the
3172 * configured logical address between 0 and 15 or 0xff if unregistered
3173 */
3174struct ec_response_cec_get {
3175 uint8_t val;
3176} __packed;
3177
3178/* CEC parameters command */
3179enum ec_cec_command {
3180 /* CEC reading, writing and events enable */
3181 CEC_CMD_ENABLE,
3182 /* CEC logical address */
3183 CEC_CMD_LOGICAL_ADDRESS,
3184};
3185
3186/* Events from CEC to AP */
3187enum mkbp_cec_event {
3188 /* Outgoing message was acknowledged by a follower */
3189 EC_MKBP_CEC_SEND_OK = BIT(0),
3190 /* Outgoing message was not acknowledged */
3191 EC_MKBP_CEC_SEND_FAILED = BIT(1),
3192};
3193
3194/*****************************************************************************/
3195/*
Simon Glassdeaf39e2013-02-25 14:08:36 -08003196 * Special commands
3197 *
3198 * These do not follow the normal rules for commands. See each command for
3199 * details.
3200 */
3201
3202/*
3203 * Reboot NOW
3204 *
3205 * This command will work even when the EC LPC interface is busy, because the
3206 * reboot command is processed at interrupt level. Note that when the EC
3207 * reboots, the host will reboot too, so there is no response to this command.
3208 *
3209 * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
3210 */
3211#define EC_CMD_REBOOT 0xd1 /* Think "die" */
3212
3213/*
3214 * Resend last response (not supported on LPC).
3215 *
3216 * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
3217 * there was no previous command, or the previous command's response was too
3218 * big to save.
3219 */
3220#define EC_CMD_RESEND_RESPONSE 0xdb
3221
3222/*
3223 * This header byte on a command indicate version 0. Any header byte less
3224 * than this means that we are talking to an old EC which doesn't support
3225 * versioning. In that case, we assume version 0.
3226 *
3227 * Header bytes greater than this indicate a later version. For example,
3228 * EC_CMD_VERSION0 + 1 means we are using version 1.
3229 *
Bill Richardson5271db22014-04-30 10:44:08 -07003230 * The old EC interface must not use commands 0xdc or higher.
Simon Glassdeaf39e2013-02-25 14:08:36 -08003231 */
3232#define EC_CMD_VERSION0 0xdc
3233
3234#endif /* !__ACPI__ */
3235
Bill Richardson5271db22014-04-30 10:44:08 -07003236/*****************************************************************************/
3237/*
Stephen Barber256ab952015-06-09 13:04:43 +02003238 * PD commands
3239 *
3240 * These commands are for PD MCU communication.
3241 */
3242
3243/* EC to PD MCU exchange status command */
3244#define EC_CMD_PD_EXCHANGE_STATUS 0x100
3245
3246/* Status of EC being sent to PD */
3247struct ec_params_pd_status {
3248 int8_t batt_soc; /* battery state of charge */
3249} __packed;
3250
3251/* Status of PD being sent back to EC */
3252struct ec_response_pd_status {
3253 int8_t status; /* PD MCU status */
3254 uint32_t curr_lim_ma; /* input current limit */
3255} __packed;
3256
3257/* Set USB type-C port role and muxes */
3258#define EC_CMD_USB_PD_CONTROL 0x101
3259
3260enum usb_pd_control_role {
3261 USB_PD_CTRL_ROLE_NO_CHANGE = 0,
3262 USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
3263 USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
3264 USB_PD_CTRL_ROLE_FORCE_SINK = 3,
3265 USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
3266};
3267
3268enum usb_pd_control_mux {
3269 USB_PD_CTRL_MUX_NO_CHANGE = 0,
3270 USB_PD_CTRL_MUX_NONE = 1,
3271 USB_PD_CTRL_MUX_USB = 2,
3272 USB_PD_CTRL_MUX_DP = 3,
3273 USB_PD_CTRL_MUX_DOCK = 4,
3274 USB_PD_CTRL_MUX_AUTO = 5,
3275};
3276
Benson Leungc7eb47f2017-12-13 11:32:15 +01003277enum usb_pd_control_swap {
3278 USB_PD_CTRL_SWAP_NONE = 0,
3279 USB_PD_CTRL_SWAP_DATA = 1,
3280 USB_PD_CTRL_SWAP_POWER = 2,
3281 USB_PD_CTRL_SWAP_VCONN = 3,
3282 USB_PD_CTRL_SWAP_COUNT
3283};
3284
Stephen Barber256ab952015-06-09 13:04:43 +02003285struct ec_params_usb_pd_control {
3286 uint8_t port;
3287 uint8_t role;
3288 uint8_t mux;
Benson Leungc7eb47f2017-12-13 11:32:15 +01003289 uint8_t swap;
Stephen Barber256ab952015-06-09 13:04:43 +02003290} __packed;
3291
Benson Leungc6983162017-07-17 11:41:39 +02003292#define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
3293#define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
3294#define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
3295
Benson Leungc7eb47f2017-12-13 11:32:15 +01003296#define PD_CTRL_RESP_ROLE_POWER BIT(0) /* 0=SNK/1=SRC */
3297#define PD_CTRL_RESP_ROLE_DATA BIT(1) /* 0=UFP/1=DFP */
3298#define PD_CTRL_RESP_ROLE_VCONN BIT(2) /* Vconn status */
3299#define PD_CTRL_RESP_ROLE_DR_POWER BIT(3) /* Partner is dualrole power */
3300#define PD_CTRL_RESP_ROLE_DR_DATA BIT(4) /* Partner is dualrole data */
3301#define PD_CTRL_RESP_ROLE_USB_COMM BIT(5) /* Partner USB comm capable */
3302#define PD_CTRL_RESP_ROLE_EXT_POWERED BIT(6) /* Partner externally powerd */
3303
Benson Leungc6983162017-07-17 11:41:39 +02003304struct ec_response_usb_pd_control_v1 {
3305 uint8_t enabled;
3306 uint8_t role;
3307 uint8_t polarity;
3308 char state[32];
3309} __packed;
3310
3311#define EC_CMD_USB_PD_PORTS 0x102
3312
Shawn Nematbakhshb082b2e2018-03-23 18:42:46 +01003313/* Maximum number of PD ports on a device, num_ports will be <= this */
3314#define EC_USB_PD_MAX_PORTS 8
3315
Benson Leungc6983162017-07-17 11:41:39 +02003316struct ec_response_usb_pd_ports {
3317 uint8_t num_ports;
3318} __packed;
3319
3320#define EC_CMD_USB_PD_POWER_INFO 0x103
3321
3322#define PD_POWER_CHARGING_PORT 0xff
3323struct ec_params_usb_pd_power_info {
3324 uint8_t port;
3325} __packed;
3326
3327enum usb_chg_type {
3328 USB_CHG_TYPE_NONE,
3329 USB_CHG_TYPE_PD,
3330 USB_CHG_TYPE_C,
3331 USB_CHG_TYPE_PROPRIETARY,
3332 USB_CHG_TYPE_BC12_DCP,
3333 USB_CHG_TYPE_BC12_CDP,
3334 USB_CHG_TYPE_BC12_SDP,
3335 USB_CHG_TYPE_OTHER,
3336 USB_CHG_TYPE_VBUS,
3337 USB_CHG_TYPE_UNKNOWN,
3338};
Sameer Nanda06635892018-05-02 17:44:16 +02003339enum usb_power_roles {
3340 USB_PD_PORT_POWER_DISCONNECTED,
3341 USB_PD_PORT_POWER_SOURCE,
3342 USB_PD_PORT_POWER_SINK,
3343 USB_PD_PORT_POWER_SINK_NOT_CHARGING,
3344};
Benson Leungc6983162017-07-17 11:41:39 +02003345
3346struct usb_chg_measures {
3347 uint16_t voltage_max;
3348 uint16_t voltage_now;
3349 uint16_t current_max;
3350 uint16_t current_lim;
3351} __packed;
3352
3353struct ec_response_usb_pd_power_info {
3354 uint8_t role;
3355 uint8_t type;
3356 uint8_t dualrole;
3357 uint8_t reserved1;
3358 struct usb_chg_measures meas;
3359 uint32_t max_power;
3360} __packed;
3361
Sameer Nanda06635892018-05-02 17:44:16 +02003362struct ec_params_usb_pd_info_request {
3363 uint8_t port;
3364} __packed;
3365
Fabien Parent36f47382018-08-10 15:13:47 +02003366/*
3367 * This command will return the number of USB PD charge port + the number
3368 * of dedicated port present.
3369 * EC_CMD_USB_PD_PORTS does NOT include the dedicated ports
3370 */
3371#define EC_CMD_CHARGE_PORT_COUNT 0x0105
3372struct ec_response_charge_port_count {
3373 uint8_t port_count;
3374} __packed;
3375
Sameer Nanda06635892018-05-02 17:44:16 +02003376/* Read USB-PD Device discovery info */
3377#define EC_CMD_USB_PD_DISCOVERY 0x0113
3378struct ec_params_usb_pd_discovery_entry {
3379 uint16_t vid; /* USB-IF VID */
3380 uint16_t pid; /* USB-IF PID */
3381 uint8_t ptype; /* product type (hub,periph,cable,ama) */
3382} __packed;
3383
3384/* Override default charge behavior */
3385#define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
3386
3387/* Negative port parameters have special meaning */
3388enum usb_pd_override_ports {
3389 OVERRIDE_DONT_CHARGE = -2,
3390 OVERRIDE_OFF = -1,
3391 /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
3392};
3393
3394struct ec_params_charge_port_override {
3395 int16_t override_port; /* Override port# */
3396} __packed;
3397
3398/* Read (and delete) one entry of PD event log */
3399#define EC_CMD_PD_GET_LOG_ENTRY 0x0115
3400
3401struct ec_response_pd_log {
3402 uint32_t timestamp; /* relative timestamp in milliseconds */
3403 uint8_t type; /* event type : see PD_EVENT_xx below */
3404 uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
3405 uint16_t data; /* type-defined data payload */
3406 uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
3407} __packed;
3408
3409/* The timestamp is the microsecond counter shifted to get about a ms. */
3410#define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
3411
3412#define PD_LOG_SIZE_MASK 0x1f
3413#define PD_LOG_PORT_MASK 0xe0
3414#define PD_LOG_PORT_SHIFT 5
3415#define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
3416 ((size) & PD_LOG_SIZE_MASK))
3417#define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
3418#define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
3419
3420/* PD event log : entry types */
3421/* PD MCU events */
3422#define PD_EVENT_MCU_BASE 0x00
3423#define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
3424#define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
3425/* Reserved for custom board event */
3426#define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
3427/* PD generic accessory events */
3428#define PD_EVENT_ACC_BASE 0x20
3429#define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
3430#define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
3431/* PD power supply events */
3432#define PD_EVENT_PS_BASE 0x40
3433#define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
3434/* PD video dongles events */
3435#define PD_EVENT_VIDEO_BASE 0x60
3436#define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
3437#define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
3438/* Returned in the "type" field, when there is no entry available */
3439#define PD_EVENT_NO_ENTRY 0xff
3440
3441/*
3442 * PD_EVENT_MCU_CHARGE event definition :
3443 * the payload is "struct usb_chg_measures"
3444 * the data field contains the port state flags as defined below :
3445 */
3446/* Port partner is a dual role device */
3447#define CHARGE_FLAGS_DUAL_ROLE BIT(15)
3448/* Port is the pending override port */
3449#define CHARGE_FLAGS_DELAYED_OVERRIDE BIT(14)
3450/* Port is the override port */
3451#define CHARGE_FLAGS_OVERRIDE BIT(13)
3452/* Charger type */
3453#define CHARGE_FLAGS_TYPE_SHIFT 3
3454#define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
3455/* Power delivery role */
3456#define CHARGE_FLAGS_ROLE_MASK (7 << 0)
3457
3458/*
3459 * PD_EVENT_PS_FAULT data field flags definition :
3460 */
3461#define PS_FAULT_OCP 1
3462#define PS_FAULT_FAST_OCP 2
3463#define PS_FAULT_OVP 3
3464#define PS_FAULT_DISCH 4
3465
3466/*
3467 * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
3468 */
3469struct mcdp_version {
3470 uint8_t major;
3471 uint8_t minor;
3472 uint16_t build;
3473} __packed;
3474
3475struct mcdp_info {
3476 uint8_t family[2];
3477 uint8_t chipid[2];
3478 struct mcdp_version irom;
3479 struct mcdp_version fw;
3480} __packed;
3481
3482/* struct mcdp_info field decoding */
3483#define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
3484#define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
3485
Benson Leungc6983162017-07-17 11:41:39 +02003486/* Get info about USB-C SS muxes */
3487#define EC_CMD_USB_PD_MUX_INFO 0x11a
3488
3489struct ec_params_usb_pd_mux_info {
3490 uint8_t port; /* USB-C port number */
3491} __packed;
3492
3493/* Flags representing mux state */
3494#define USB_PD_MUX_USB_ENABLED (1 << 0)
3495#define USB_PD_MUX_DP_ENABLED (1 << 1)
3496#define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
3497#define USB_PD_MUX_HPD_IRQ (1 << 3)
3498
3499struct ec_response_usb_pd_mux_info {
3500 uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
3501} __packed;
3502
Stephen Barber256ab952015-06-09 13:04:43 +02003503/*****************************************************************************/
3504/*
3505 * Passthru commands
3506 *
3507 * Some platforms have sub-processors chained to each other. For example.
3508 *
3509 * AP <--> EC <--> PD MCU
3510 *
3511 * The top 2 bits of the command number are used to indicate which device the
3512 * command is intended for. Device 0 is always the device receiving the
3513 * command; other device mapping is board-specific.
3514 *
3515 * When a device receives a command to be passed to a sub-processor, it passes
3516 * it on with the device number set back to 0. This allows the sub-processor
3517 * to remain blissfully unaware of whether the command originated on the next
3518 * device up the chain, or was passed through from the AP.
3519 *
3520 * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
3521 * AP sends command 0x4002 to the EC
3522 * EC sends command 0x0002 to the PD MCU
3523 * EC forwards PD MCU response back to the AP
3524 */
3525
3526/* Offset and max command number for sub-device n */
3527#define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
3528#define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
3529
3530/*****************************************************************************/
3531/*
Bill Richardson5271db22014-04-30 10:44:08 -07003532 * Deprecated constants. These constants have been renamed for clarity. The
3533 * meaning and size has not changed. Programs that use the old names should
3534 * switch to the new names soon, as the old names may not be carried forward
3535 * forever.
3536 */
3537#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
3538#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
3539#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
3540
Simon Glassdeaf39e2013-02-25 14:08:36 -08003541#endif /* __CROS_EC_COMMANDS_H */