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