aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mfd/cros_ec_commands.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2014-06-06 15:08:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-06 15:08:39 -0400
commit1fe9eb184721132c7254d76d9ef31c96edad8870 (patch)
treec055ffb7f201bc2370714ebe186a922d0eb39d0d /include/linux/mfd/cros_ec_commands.h
parent0bb464624140bfdd8389d4c5464ba134b2856049 (diff)
parent89abd4df28c6f85645e32f37ffab6426f800e4a1 (diff)
Merge tag 'mfd-for-linus-3.16' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd into next
Pull MFD updates from Lee Jones: "Changes to existing drivers: - increase DT coverage: arizona, mc13xxx, stmpe-i2c, syscon, sun6i-prcm - regmap use of and/or clean-up: tps65090, twl6040 - basic renaming: max14577 - use new cpufreq helpers: db8500-prcmu - increase regulator support: stmpe, arizona, wm5102 - reduce legacy GPIO overhead: stmpe - provide necessary remove path: bcm590xx - expand sysfs presence: kempld - move driver specific code out to drivers: rtc-s5m, arizona - clk handling: twl6040 - use managed (devm_*) resources: ipaq-micro - clean-up/remove unused/duplicated code: tps65218, sec, pm8921, abx500-core, db8500-prcmu, menelaus - build/boot/sematic bug fixes: rtsx_usb, stmpe, bcm590xx, abx500, mc13xxx, rdc321x-southbridge, mfd-core, sec, max14577, syscon, cros_ec_spi - constify stuff: sm501, tps65910, tps6507x, tps6586x, max77686, max8997, kempld, max77693, max8907, rtsx_usb, db8500-prcmu, max8998, wm8400, sec, lp3943, max14577, as3711, omap-usb-host, ipaq-micro Support for new devices: - add support for max77836 into max14577 - add support for tps658640 into tps6586x - add support for cros-ec-i2c-tunnel into cros_ec - add new driver for rtsx_usb_sdmmc and rtsx_usb_ms - add new driver for axp20x - add new driver for sun6i-prcm - add new driver for ipaq-micro" * tag 'mfd-for-linus-3.16' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd: (77 commits) mfd: wm5102: Correct default for LDO Control 2 register mfd: menelaus: Use module_i2c_driver mfd: tps65218: Terminate of match table mfd: db8500-prcmu: Remove check for CONFIG_DBX500_PRCMU_DEBUG mfd: ti-keystone-devctrl: Add bindings for device state control mfd: palmas: Format the header file mfd: abx500-core: Remove unused function abx500_dump_all_banks() mfd: arizona: Correct addresses of always-on trigger registers mfd: max14577: Cast to architecture agnostic data type i2c: ChromeOS EC tunnel driver mfd: cros_ec: Sync to the latest cros_ec_commands.h from EC sources mfd: cros_ec: spi: Increase cros_ec_spi deadline from 5ms to 100ms mfd: cros_ec: spi: Make the cros_ec_spi timeout more reliable mfd: cros_ec: spi: Add mutex to cros_ec_spi mfd: cros_ec: spi: Calculate delay between transfers correctly mfd: arizona: Correct error message for addition of main IRQ chip mfd: wm8997: Add registers for high power mode mfd: arizona: Add MICVDD to mapped regulators mfd: ipaq-micro: Make mfd_cell array const mfd: ipaq-micro: Use devm_ioremap_resource() ...
Diffstat (limited to 'include/linux/mfd/cros_ec_commands.h')
-rw-r--r--include/linux/mfd/cros_ec_commands.h1128
1 files changed, 1056 insertions, 72 deletions
diff --git a/include/linux/mfd/cros_ec_commands.h b/include/linux/mfd/cros_ec_commands.h
index 86fd06953bcd..7853a6410d14 100644
--- a/include/linux/mfd/cros_ec_commands.h
+++ b/include/linux/mfd/cros_ec_commands.h
@@ -24,25 +24,12 @@
24#define __CROS_EC_COMMANDS_H 24#define __CROS_EC_COMMANDS_H
25 25
26/* 26/*
27 * Protocol overview 27 * Current version of this protocol
28 * 28 *
29 * request: CMD [ P0 P1 P2 ... Pn S ] 29 * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
30 * response: ERR [ P0 P1 P2 ... Pn S ] 30 * determined in other ways. Remove this once the kernel code no longer
31 * 31 * depends on it.
32 * where the bytes are defined as follow :
33 * - CMD is the command code. (defined by EC_CMD_ constants)
34 * - ERR is the error code. (defined by EC_RES_ constants)
35 * - Px is the optional payload.
36 * it is not sent if the error code is not success.
37 * (defined by ec_params_ and ec_response_ structures)
38 * - S is the checksum which is the sum of all payload bytes.
39 *
40 * On LPC, CMD and ERR are sent/received at EC_LPC_ADDR_KERNEL|USER_CMD
41 * and the payloads are sent/received at EC_LPC_ADDR_KERNEL|USER_PARAM.
42 * On I2C, all bytes are sent serially in the same message.
43 */ 32 */
44
45/* Current version of this protocol */
46#define EC_PROTO_VERSION 0x00000002 33#define EC_PROTO_VERSION 0x00000002
47 34
48/* Command version mask */ 35/* Command version mask */
@@ -57,13 +44,19 @@
57#define EC_LPC_ADDR_HOST_CMD 0x204 44#define EC_LPC_ADDR_HOST_CMD 0x204
58 45
59/* I/O addresses for host command args and params */ 46/* I/O addresses for host command args and params */
60#define EC_LPC_ADDR_HOST_ARGS 0x800 47/* Protocol version 2 */
61#define EC_LPC_ADDR_HOST_PARAM 0x804 48#define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
62#define EC_HOST_PARAM_SIZE 0x0fc /* Size of param area in bytes */ 49#define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
63 50 * EC_PROTO2_MAX_PARAM_SIZE */
64/* I/O addresses for host command params, old interface */ 51/* Protocol version 3 */
65#define EC_LPC_ADDR_OLD_PARAM 0x880 52#define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
66#define EC_OLD_PARAM_SIZE 0x080 /* Size of param area in bytes */ 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
67 60
68/* EC command register bit functions */ 61/* EC command register bit functions */
69#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */ 62#define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
@@ -79,18 +72,22 @@
79#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */ 72#define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
80 73
81/* The offset address of each type of data in mapped memory. */ 74/* The offset address of each type of data in mapped memory. */
82#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors */ 75#define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
83#define EC_MEMMAP_FAN 0x10 /* Fan speeds */ 76#define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
84#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* Temp sensors (second set) */ 77#define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
85#define EC_MEMMAP_ID 0x20 /* 'E' 'C' */ 78#define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
86#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */ 79#define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
87#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */ 80#define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
88#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */ 81#define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
89#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */ 82#define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
90#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */ 83#define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
91#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host command interface flags */ 84#define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
92#define EC_MEMMAP_SWITCHES 0x30 85/* Unused 0x28 - 0x2f */
93#define EC_MEMMAP_HOST_EVENTS 0x34 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 */
94#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */ 91#define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
95#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */ 92#define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
96#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */ 93#define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
@@ -99,10 +96,24 @@
99#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */ 96#define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
100#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */ 97#define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
101#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */ 98#define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
99/* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
102#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */ 100#define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
103#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */ 101#define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
104#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */ 102#define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
105#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */ 103#define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
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)
106 117
107/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */ 118/* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
108#define EC_TEMP_SENSOR_ENTRIES 16 119#define EC_TEMP_SENSOR_ENTRIES 16
@@ -112,6 +123,8 @@
112 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2. 123 * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
113 */ 124 */
114#define EC_TEMP_SENSOR_B_ENTRIES 8 125#define EC_TEMP_SENSOR_B_ENTRIES 8
126
127/* Special values for mapped temperature sensors */
115#define EC_TEMP_SENSOR_NOT_PRESENT 0xff 128#define EC_TEMP_SENSOR_NOT_PRESENT 0xff
116#define EC_TEMP_SENSOR_ERROR 0xfe 129#define EC_TEMP_SENSOR_ERROR 0xfe
117#define EC_TEMP_SENSOR_NOT_POWERED 0xfd 130#define EC_TEMP_SENSOR_NOT_POWERED 0xfd
@@ -122,6 +135,18 @@
122 */ 135 */
123#define EC_TEMP_SENSOR_OFFSET 200 136#define EC_TEMP_SENSOR_OFFSET 200
124 137
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
125#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */ 150#define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
126#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */ 151#define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
127#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */ 152#define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
@@ -137,8 +162,8 @@
137#define EC_SWITCH_LID_OPEN 0x01 162#define EC_SWITCH_LID_OPEN 0x01
138#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02 163#define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
139#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04 164#define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
140/* Recovery requested via keyboard */ 165/* Was recovery requested via keyboard; now unused. */
141#define EC_SWITCH_KEYBOARD_RECOVERY 0x08 166#define EC_SWITCH_IGNORE1 0x08
142/* Recovery requested via dedicated signal (from servo board) */ 167/* Recovery requested via dedicated signal (from servo board) */
143#define EC_SWITCH_DEDICATED_RECOVERY 0x10 168#define EC_SWITCH_DEDICATED_RECOVERY 0x10
144/* Was fake developer mode switch; now unused. Remove in next refactor. */ 169/* Was fake developer mode switch; now unused. Remove in next refactor. */
@@ -147,10 +172,15 @@
147/* Host command interface flags */ 172/* Host command interface flags */
148/* Host command interface supports LPC args (LPC interface only) */ 173/* Host command interface supports LPC args (LPC interface only) */
149#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01 174#define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
175/* Host command interface supports version 3 protocol */
176#define EC_HOST_CMD_FLAG_VERSION_3 0x02
150 177
151/* Wireless switch flags */ 178/* Wireless switch flags */
152#define EC_WIRELESS_SWITCH_WLAN 0x01 179#define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
153#define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 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 */
154 184
155/* 185/*
156 * This header file is used in coreboot both in C and ACPI code. The ACPI code 186 * This header file is used in coreboot both in C and ACPI code. The ACPI code
@@ -159,6 +189,14 @@
159 */ 189 */
160#ifndef __ACPI__ 190#ifndef __ACPI__
161 191
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
162/* LPC command status byte masks */ 200/* LPC command status byte masks */
163/* EC has written a byte in the data register and host hasn't read it yet */ 201/* EC has written a byte in the data register and host hasn't read it yet */
164#define EC_LPC_STATUS_TO_HOST 0x01 202#define EC_LPC_STATUS_TO_HOST 0x01
@@ -198,6 +236,9 @@ enum ec_status {
198 EC_RES_UNAVAILABLE = 9, /* No response available */ 236 EC_RES_UNAVAILABLE = 9, /* No response available */
199 EC_RES_TIMEOUT = 10, /* We got a timeout */ 237 EC_RES_TIMEOUT = 10, /* We got a timeout */
200 EC_RES_OVERFLOW = 11, /* Table / data overflow */ 238 EC_RES_OVERFLOW = 11, /* Table / data overflow */
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 */
201}; 242};
202 243
203/* 244/*
@@ -235,6 +276,16 @@ enum host_event_code {
235 /* Shutdown due to battery level too low */ 276 /* Shutdown due to battery level too low */
236 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17, 277 EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
237 278
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,
288
238 /* 289 /*
239 * The high bit of the event mask is not used as a host event code. If 290 * The high bit of the event mask is not used as a host event code. If
240 * it reads back as set, then the entire event mask should be 291 * it reads back as set, then the entire event mask should be
@@ -279,6 +330,188 @@ struct ec_lpc_host_args {
279 */ 330 */
280#define EC_HOST_ARGS_FLAG_TO_HOST 0x02 331#define EC_HOST_ARGS_FLAG_TO_HOST 0x02
281 332
333/*****************************************************************************/
334/*
335 * Byte codes returned by EC over SPI interface.
336 *
337 * These can be used by the AP to debug the EC interface, and to determine
338 * when the EC is not in a state where it will ever get around to responding
339 * to the AP.
340 *
341 * Example of sequence of bytes read from EC for a current good transfer:
342 * 1. - - AP asserts chip select (CS#)
343 * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
344 * 3. - - EC starts handling CS# interrupt
345 * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
346 * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
347 * bytes looking for EC_SPI_FRAME_START
348 * 6. - - EC finishes processing and sets up response
349 * 7. EC_SPI_FRAME_START - AP reads frame byte
350 * 8. (response packet) - AP reads response packet
351 * 9. EC_SPI_PAST_END - Any additional bytes read by AP
352 * 10 - - AP deasserts chip select
353 * 11 - - EC processes CS# interrupt and sets up DMA for
354 * next request
355 *
356 * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
357 * the following byte values:
358 * EC_SPI_OLD_READY
359 * EC_SPI_RX_READY
360 * EC_SPI_RECEIVING
361 * EC_SPI_PROCESSING
362 *
363 * Then the EC found an error in the request, or was not ready for the request
364 * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
365 * because the EC is unable to tell when the AP is done sending its request.
366 */
367
368/*
369 * Framing byte which precedes a response packet from the EC. After sending a
370 * request, the AP will clock in bytes until it sees the framing byte, then
371 * clock in the response packet.
372 */
373#define EC_SPI_FRAME_START 0xec
374
375/*
376 * Padding bytes which are clocked out after the end of a response packet.
377 */
378#define EC_SPI_PAST_END 0xed
379
380/*
381 * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
382 * that the AP will send a valid packet header (starting with
383 * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
384 */
385#define EC_SPI_RX_READY 0xf8
386
387/*
388 * EC has started receiving the request from the AP, but hasn't started
389 * processing it yet.
390 */
391#define EC_SPI_RECEIVING 0xf9
392
393/* EC has received the entire request from the AP and is processing it. */
394#define EC_SPI_PROCESSING 0xfa
395
396/*
397 * EC received bad data from the AP, such as a packet header with an invalid
398 * length. EC will ignore all data until chip select deasserts.
399 */
400#define EC_SPI_RX_BAD_DATA 0xfb
401
402/*
403 * EC received data from the AP before it was ready. That is, the AP asserted
404 * chip select and started clocking data before the EC was ready to receive it.
405 * EC will ignore all data until chip select deasserts.
406 */
407#define EC_SPI_NOT_READY 0xfc
408
409/*
410 * EC was ready to receive a request from the AP. EC has treated the byte sent
411 * by the AP as part of a request packet, or (for old-style ECs) is processing
412 * a fully received packet but is not ready to respond yet.
413 */
414#define EC_SPI_OLD_READY 0xfd
415
416/*****************************************************************************/
417
418/*
419 * Protocol version 2 for I2C and SPI send a request this way:
420 *
421 * 0 EC_CMD_VERSION0 + (command version)
422 * 1 Command number
423 * 2 Length of params = N
424 * 3..N+2 Params, if any
425 * N+3 8-bit checksum of bytes 0..N+2
426 *
427 * The corresponding response is:
428 *
429 * 0 Result code (EC_RES_*)
430 * 1 Length of params = M
431 * 2..M+1 Params, if any
432 * M+2 8-bit checksum of bytes 0..M+1
433 */
434#define EC_PROTO2_REQUEST_HEADER_BYTES 3
435#define EC_PROTO2_REQUEST_TRAILER_BYTES 1
436#define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
437 EC_PROTO2_REQUEST_TRAILER_BYTES)
438
439#define EC_PROTO2_RESPONSE_HEADER_BYTES 2
440#define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
441#define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
442 EC_PROTO2_RESPONSE_TRAILER_BYTES)
443
444/* Parameter length was limited by the LPC interface */
445#define EC_PROTO2_MAX_PARAM_SIZE 0xfc
446
447/* Maximum request and response packet sizes for protocol version 2 */
448#define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
449 EC_PROTO2_MAX_PARAM_SIZE)
450#define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
451 EC_PROTO2_MAX_PARAM_SIZE)
452
453/*****************************************************************************/
454
455/*
456 * Value written to legacy command port / prefix byte to indicate protocol
457 * 3+ structs are being used. Usage is bus-dependent.
458 */
459#define EC_COMMAND_PROTOCOL_3 0xda
460
461#define EC_HOST_REQUEST_VERSION 3
462
463/* Version 3 request from host */
464struct ec_host_request {
465 /* Struct version (=3)
466 *
467 * EC will return EC_RES_INVALID_HEADER if it receives a header with a
468 * version it doesn't know how to parse.
469 */
470 uint8_t struct_version;
471
472 /*
473 * Checksum of request and data; sum of all bytes including checksum
474 * should total to 0.
475 */
476 uint8_t checksum;
477
478 /* Command code */
479 uint16_t command;
480
481 /* Command version */
482 uint8_t command_version;
483
484 /* Unused byte in current protocol version; set to 0 */
485 uint8_t reserved;
486
487 /* Length of data which follows this header */
488 uint16_t data_len;
489} __packed;
490
491#define EC_HOST_RESPONSE_VERSION 3
492
493/* Version 3 response from EC */
494struct ec_host_response {
495 /* Struct version (=3) */
496 uint8_t struct_version;
497
498 /*
499 * Checksum of response and data; sum of all bytes including checksum
500 * should total to 0.
501 */
502 uint8_t checksum;
503
504 /* Result code (EC_RES_*) */
505 uint16_t result;
506
507 /* Length of data which follows this header */
508 uint16_t data_len;
509
510 /* Unused bytes in current protocol version; set to 0 */
511 uint16_t reserved;
512} __packed;
513
514/*****************************************************************************/
282/* 515/*
283 * Notes on commands: 516 * Notes on commands:
284 * 517 *
@@ -418,6 +651,68 @@ struct ec_response_get_comms_status {
418 uint32_t flags; /* Mask of enum ec_comms_status */ 651 uint32_t flags; /* Mask of enum ec_comms_status */
419} __packed; 652} __packed;
420 653
654/* Fake a variety of responses, purely for testing purposes. */
655#define EC_CMD_TEST_PROTOCOL 0x0a
656
657/* Tell the EC what to send back to us. */
658struct ec_params_test_protocol {
659 uint32_t ec_result;
660 uint32_t ret_len;
661 uint8_t buf[32];
662} __packed;
663
664/* Here it comes... */
665struct ec_response_test_protocol {
666 uint8_t buf[32];
667} __packed;
668
669/* Get prococol information */
670#define EC_CMD_GET_PROTOCOL_INFO 0x0b
671
672/* Flags for ec_response_get_protocol_info.flags */
673/* EC_RES_IN_PROGRESS may be returned if a command is slow */
674#define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
675
676struct ec_response_get_protocol_info {
677 /* Fields which exist if at least protocol version 3 supported */
678
679 /* Bitmask of protocol versions supported (1 << n means version n)*/
680 uint32_t protocol_versions;
681
682 /* Maximum request packet size, in bytes */
683 uint16_t max_request_packet_size;
684
685 /* Maximum response packet size, in bytes */
686 uint16_t max_response_packet_size;
687
688 /* Flags; see EC_PROTOCOL_INFO_* */
689 uint32_t flags;
690} __packed;
691
692
693/*****************************************************************************/
694/* Get/Set miscellaneous values */
695
696/* The upper byte of .flags tells what to do (nothing means "get") */
697#define EC_GSV_SET 0x80000000
698
699/* The lower three bytes of .flags identifies the parameter, if that has
700 meaning for an individual command. */
701#define EC_GSV_PARAM_MASK 0x00ffffff
702
703struct ec_params_get_set_value {
704 uint32_t flags;
705 uint32_t value;
706} __packed;
707
708struct ec_response_get_set_value {
709 uint32_t flags;
710 uint32_t value;
711} __packed;
712
713/* More than one command can use these structs to get/set paramters. */
714#define EC_CMD_GSV_PAUSE_IN_S5 0x0c
715
421 716
422/*****************************************************************************/ 717/*****************************************************************************/
423/* Flash commands */ 718/* Flash commands */
@@ -425,6 +720,7 @@ struct ec_response_get_comms_status {
425/* Get flash info */ 720/* Get flash info */
426#define EC_CMD_FLASH_INFO 0x10 721#define EC_CMD_FLASH_INFO 0x10
427 722
723/* Version 0 returns these fields */
428struct ec_response_flash_info { 724struct ec_response_flash_info {
429 /* Usable flash size, in bytes */ 725 /* Usable flash size, in bytes */
430 uint32_t flash_size; 726 uint32_t flash_size;
@@ -445,6 +741,37 @@ struct ec_response_flash_info {
445 uint32_t protect_block_size; 741 uint32_t protect_block_size;
446} __packed; 742} __packed;
447 743
744/* Flags for version 1+ flash info command */
745/* EC flash erases bits to 0 instead of 1 */
746#define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
747
748/*
749 * Version 1 returns the same initial fields as version 0, with additional
750 * fields following.
751 *
752 * gcc anonymous structs don't seem to get along with the __packed directive;
753 * if they did we'd define the version 0 struct as a sub-struct of this one.
754 */
755struct ec_response_flash_info_1 {
756 /* Version 0 fields; see above for description */
757 uint32_t flash_size;
758 uint32_t write_block_size;
759 uint32_t erase_block_size;
760 uint32_t protect_block_size;
761
762 /* Version 1 adds these fields: */
763 /*
764 * Ideal write size in bytes. Writes will be fastest if size is
765 * exactly this and offset is a multiple of this. For example, an EC
766 * may have a write buffer which can do half-page operations if data is
767 * aligned, and a slower word-at-a-time write mode.
768 */
769 uint32_t write_ideal_size;
770
771 /* Flags; see EC_FLASH_INFO_* */
772 uint32_t flags;
773} __packed;
774
448/* 775/*
449 * Read flash 776 * Read flash
450 * 777 *
@@ -459,15 +786,15 @@ struct ec_params_flash_read {
459 786
460/* Write flash */ 787/* Write flash */
461#define EC_CMD_FLASH_WRITE 0x12 788#define EC_CMD_FLASH_WRITE 0x12
789#define EC_VER_FLASH_WRITE 1
790
791/* Version 0 of the flash command supported only 64 bytes of data */
792#define EC_FLASH_WRITE_VER0_SIZE 64
462 793
463struct ec_params_flash_write { 794struct ec_params_flash_write {
464 uint32_t offset; /* Byte offset to write */ 795 uint32_t offset; /* Byte offset to write */
465 uint32_t size; /* Size to write in bytes */ 796 uint32_t size; /* Size to write in bytes */
466 /* 797 /* Followed by data to write */
467 * Data to write. Could really use EC_PARAM_SIZE - 8, but tidiest to
468 * use a power of 2 so writes stay aligned.
469 */
470 uint8_t data[64];
471} __packed; 798} __packed;
472 799
473/* Erase flash */ 800/* Erase flash */
@@ -543,7 +870,7 @@ struct ec_response_flash_protect {
543 870
544enum ec_flash_region { 871enum ec_flash_region {
545 /* Region which holds read-only EC image */ 872 /* Region which holds read-only EC image */
546 EC_FLASH_REGION_RO, 873 EC_FLASH_REGION_RO = 0,
547 /* Region which holds rewritable EC image */ 874 /* Region which holds rewritable EC image */
548 EC_FLASH_REGION_RW, 875 EC_FLASH_REGION_RW,
549 /* 876 /*
@@ -551,6 +878,8 @@ enum ec_flash_region {
551 * EC_FLASH_REGION_RO) 878 * EC_FLASH_REGION_RO)
552 */ 879 */
553 EC_FLASH_REGION_WP_RO, 880 EC_FLASH_REGION_WP_RO,
881 /* Number of regions */
882 EC_FLASH_REGION_COUNT,
554}; 883};
555 884
556struct ec_params_flash_region_info { 885struct ec_params_flash_region_info {
@@ -639,15 +968,15 @@ struct rgb_s {
639 */ 968 */
640struct lightbar_params { 969struct lightbar_params {
641 /* Timing */ 970 /* Timing */
642 int google_ramp_up; 971 int32_t google_ramp_up;
643 int google_ramp_down; 972 int32_t google_ramp_down;
644 int s3s0_ramp_up; 973 int32_t s3s0_ramp_up;
645 int s0_tick_delay[2]; /* AC=0/1 */ 974 int32_t s0_tick_delay[2]; /* AC=0/1 */
646 int s0a_tick_delay[2]; /* AC=0/1 */ 975 int32_t s0a_tick_delay[2]; /* AC=0/1 */
647 int s0s3_ramp_down; 976 int32_t s0s3_ramp_down;
648 int s3_sleep_for; 977 int32_t s3_sleep_for;
649 int s3_ramp_up; 978 int32_t s3_ramp_up;
650 int s3_ramp_down; 979 int32_t s3_ramp_down;
651 980
652 /* Oscillation */ 981 /* Oscillation */
653 uint8_t new_s0; 982 uint8_t new_s0;
@@ -676,7 +1005,7 @@ struct ec_params_lightbar {
676 union { 1005 union {
677 struct { 1006 struct {
678 /* no args */ 1007 /* no args */
679 } dump, off, on, init, get_seq, get_params; 1008 } dump, off, on, init, get_seq, get_params, version;
680 1009
681 struct num { 1010 struct num {
682 uint8_t num; 1011 uint8_t num;
@@ -710,6 +1039,11 @@ struct ec_response_lightbar {
710 1039
711 struct lightbar_params get_params; 1040 struct lightbar_params get_params;
712 1041
1042 struct version {
1043 uint32_t num;
1044 uint32_t flags;
1045 } version;
1046
713 struct { 1047 struct {
714 /* no return params */ 1048 /* no return params */
715 } off, on, init, brightness, seq, reg, rgb, demo, set_params; 1049 } off, on, init, brightness, seq, reg, rgb, demo, set_params;
@@ -730,10 +1064,62 @@ enum lightbar_command {
730 LIGHTBAR_CMD_DEMO = 9, 1064 LIGHTBAR_CMD_DEMO = 9,
731 LIGHTBAR_CMD_GET_PARAMS = 10, 1065 LIGHTBAR_CMD_GET_PARAMS = 10,
732 LIGHTBAR_CMD_SET_PARAMS = 11, 1066 LIGHTBAR_CMD_SET_PARAMS = 11,
1067 LIGHTBAR_CMD_VERSION = 12,
733 LIGHTBAR_NUM_CMDS 1068 LIGHTBAR_NUM_CMDS
734}; 1069};
735 1070
736/*****************************************************************************/ 1071/*****************************************************************************/
1072/* LED control commands */
1073
1074#define EC_CMD_LED_CONTROL 0x29
1075
1076enum ec_led_id {
1077 /* LED to indicate battery state of charge */
1078 EC_LED_ID_BATTERY_LED = 0,
1079 /*
1080 * LED to indicate system power state (on or in suspend).
1081 * May be on power button or on C-panel.
1082 */
1083 EC_LED_ID_POWER_LED,
1084 /* LED on power adapter or its plug */
1085 EC_LED_ID_ADAPTER_LED,
1086
1087 EC_LED_ID_COUNT
1088};
1089
1090/* LED control flags */
1091#define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
1092#define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
1093
1094enum ec_led_colors {
1095 EC_LED_COLOR_RED = 0,
1096 EC_LED_COLOR_GREEN,
1097 EC_LED_COLOR_BLUE,
1098 EC_LED_COLOR_YELLOW,
1099 EC_LED_COLOR_WHITE,
1100
1101 EC_LED_COLOR_COUNT
1102};
1103
1104struct ec_params_led_control {
1105 uint8_t led_id; /* Which LED to control */
1106 uint8_t flags; /* Control flags */
1107
1108 uint8_t brightness[EC_LED_COLOR_COUNT];
1109} __packed;
1110
1111struct ec_response_led_control {
1112 /*
1113 * Available brightness value range.
1114 *
1115 * Range 0 means color channel not present.
1116 * Range 1 means on/off control.
1117 * Other values means the LED is control by PWM.
1118 */
1119 uint8_t brightness_range[EC_LED_COLOR_COUNT];
1120} __packed;
1121
1122/*****************************************************************************/
737/* Verified boot commands */ 1123/* Verified boot commands */
738 1124
739/* 1125/*
@@ -790,6 +1176,181 @@ enum ec_vboot_hash_status {
790#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd 1176#define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
791 1177
792/*****************************************************************************/ 1178/*****************************************************************************/
1179/*
1180 * Motion sense commands. We'll make separate structs for sub-commands with
1181 * different input args, so that we know how much to expect.
1182 */
1183#define EC_CMD_MOTION_SENSE_CMD 0x2B
1184
1185/* Motion sense commands */
1186enum motionsense_command {
1187 /*
1188 * Dump command returns all motion sensor data including motion sense
1189 * module flags and individual sensor flags.
1190 */
1191 MOTIONSENSE_CMD_DUMP = 0,
1192
1193 /*
1194 * Info command returns data describing the details of a given sensor,
1195 * including enum motionsensor_type, enum motionsensor_location, and
1196 * enum motionsensor_chip.
1197 */
1198 MOTIONSENSE_CMD_INFO = 1,
1199
1200 /*
1201 * EC Rate command is a setter/getter command for the EC sampling rate
1202 * of all motion sensors in milliseconds.
1203 */
1204 MOTIONSENSE_CMD_EC_RATE = 2,
1205
1206 /*
1207 * Sensor ODR command is a setter/getter command for the output data
1208 * rate of a specific motion sensor in millihertz.
1209 */
1210 MOTIONSENSE_CMD_SENSOR_ODR = 3,
1211
1212 /*
1213 * Sensor range command is a setter/getter command for the range of
1214 * a specified motion sensor in +/-G's or +/- deg/s.
1215 */
1216 MOTIONSENSE_CMD_SENSOR_RANGE = 4,
1217
1218 /*
1219 * Setter/getter command for the keyboard wake angle. When the lid
1220 * angle is greater than this value, keyboard wake is disabled in S3,
1221 * and when the lid angle goes less than this value, keyboard wake is
1222 * enabled. Note, the lid angle measurement is an approximate,
1223 * un-calibrated value, hence the wake angle isn't exact.
1224 */
1225 MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
1226
1227 /* Number of motionsense sub-commands. */
1228 MOTIONSENSE_NUM_CMDS
1229};
1230
1231enum motionsensor_id {
1232 EC_MOTION_SENSOR_ACCEL_BASE = 0,
1233 EC_MOTION_SENSOR_ACCEL_LID = 1,
1234 EC_MOTION_SENSOR_GYRO = 2,
1235
1236 /*
1237 * Note, if more sensors are added and this count changes, the padding
1238 * in ec_response_motion_sense dump command must be modified.
1239 */
1240 EC_MOTION_SENSOR_COUNT = 3
1241};
1242
1243/* List of motion sensor types. */
1244enum motionsensor_type {
1245 MOTIONSENSE_TYPE_ACCEL = 0,
1246 MOTIONSENSE_TYPE_GYRO = 1,
1247};
1248
1249/* List of motion sensor locations. */
1250enum motionsensor_location {
1251 MOTIONSENSE_LOC_BASE = 0,
1252 MOTIONSENSE_LOC_LID = 1,
1253};
1254
1255/* List of motion sensor chips. */
1256enum motionsensor_chip {
1257 MOTIONSENSE_CHIP_KXCJ9 = 0,
1258};
1259
1260/* Module flag masks used for the dump sub-command. */
1261#define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
1262
1263/* Sensor flag masks used for the dump sub-command. */
1264#define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
1265
1266/*
1267 * Send this value for the data element to only perform a read. If you
1268 * send any other value, the EC will interpret it as data to set and will
1269 * return the actual value set.
1270 */
1271#define EC_MOTION_SENSE_NO_VALUE -1
1272
1273struct ec_params_motion_sense {
1274 uint8_t cmd;
1275 union {
1276 /* Used for MOTIONSENSE_CMD_DUMP. */
1277 struct {
1278 /* no args */
1279 } dump;
1280
1281 /*
1282 * Used for MOTIONSENSE_CMD_EC_RATE and
1283 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1284 */
1285 struct {
1286 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1287 int16_t data;
1288 } ec_rate, kb_wake_angle;
1289
1290 /* Used for MOTIONSENSE_CMD_INFO. */
1291 struct {
1292 /* Should be element of enum motionsensor_id. */
1293 uint8_t sensor_num;
1294 } info;
1295
1296 /*
1297 * Used for MOTIONSENSE_CMD_SENSOR_ODR and
1298 * MOTIONSENSE_CMD_SENSOR_RANGE.
1299 */
1300 struct {
1301 /* Should be element of enum motionsensor_id. */
1302 uint8_t sensor_num;
1303
1304 /* Rounding flag, true for round-up, false for down. */
1305 uint8_t roundup;
1306
1307 uint16_t reserved;
1308
1309 /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
1310 int32_t data;
1311 } sensor_odr, sensor_range;
1312 };
1313} __packed;
1314
1315struct ec_response_motion_sense {
1316 union {
1317 /* Used for MOTIONSENSE_CMD_DUMP. */
1318 struct {
1319 /* Flags representing the motion sensor module. */
1320 uint8_t module_flags;
1321
1322 /* Flags for each sensor in enum motionsensor_id. */
1323 uint8_t sensor_flags[EC_MOTION_SENSOR_COUNT];
1324
1325 /* Array of all sensor data. Each sensor is 3-axis. */
1326 int16_t data[3*EC_MOTION_SENSOR_COUNT];
1327 } dump;
1328
1329 /* Used for MOTIONSENSE_CMD_INFO. */
1330 struct {
1331 /* Should be element of enum motionsensor_type. */
1332 uint8_t type;
1333
1334 /* Should be element of enum motionsensor_location. */
1335 uint8_t location;
1336
1337 /* Should be element of enum motionsensor_chip. */
1338 uint8_t chip;
1339 } info;
1340
1341 /*
1342 * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
1343 * MOTIONSENSE_CMD_SENSOR_RANGE, and
1344 * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
1345 */
1346 struct {
1347 /* Current value of the parameter queried. */
1348 int32_t ret;
1349 } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
1350 };
1351} __packed;
1352
1353/*****************************************************************************/
793/* USB charging control commands */ 1354/* USB charging control commands */
794 1355
795/* Set USB port charging mode */ 1356/* Set USB port charging mode */
@@ -868,20 +1429,27 @@ struct ec_response_port80_last_boot {
868} __packed; 1429} __packed;
869 1430
870/*****************************************************************************/ 1431/*****************************************************************************/
871/* Thermal engine commands */ 1432/* Thermal engine commands. Note that there are two implementations. We'll
1433 * reuse the command number, but the data and behavior is incompatible.
1434 * Version 0 is what originally shipped on Link.
1435 * Version 1 separates the CPU thermal limits from the fan control.
1436 */
872 1437
873/* Set thershold value */
874#define EC_CMD_THERMAL_SET_THRESHOLD 0x50 1438#define EC_CMD_THERMAL_SET_THRESHOLD 0x50
1439#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
1440
1441/* The version 0 structs are opaque. You have to know what they are for
1442 * the get/set commands to make any sense.
1443 */
875 1444
1445/* Version 0 - set */
876struct ec_params_thermal_set_threshold { 1446struct ec_params_thermal_set_threshold {
877 uint8_t sensor_type; 1447 uint8_t sensor_type;
878 uint8_t threshold_id; 1448 uint8_t threshold_id;
879 uint16_t value; 1449 uint16_t value;
880} __packed; 1450} __packed;
881 1451
882/* Get threshold value */ 1452/* Version 0 - get */
883#define EC_CMD_THERMAL_GET_THRESHOLD 0x51
884
885struct ec_params_thermal_get_threshold { 1453struct ec_params_thermal_get_threshold {
886 uint8_t sensor_type; 1454 uint8_t sensor_type;
887 uint8_t threshold_id; 1455 uint8_t threshold_id;
@@ -891,6 +1459,41 @@ struct ec_response_thermal_get_threshold {
891 uint16_t value; 1459 uint16_t value;
892} __packed; 1460} __packed;
893 1461
1462
1463/* The version 1 structs are visible. */
1464enum ec_temp_thresholds {
1465 EC_TEMP_THRESH_WARN = 0,
1466 EC_TEMP_THRESH_HIGH,
1467 EC_TEMP_THRESH_HALT,
1468
1469 EC_TEMP_THRESH_COUNT
1470};
1471
1472/* Thermal configuration for one temperature sensor. Temps are in degrees K.
1473 * Zero values will be silently ignored by the thermal task.
1474 */
1475struct ec_thermal_config {
1476 uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
1477 uint32_t temp_fan_off; /* no active cooling needed */
1478 uint32_t temp_fan_max; /* max active cooling needed */
1479} __packed;
1480
1481/* Version 1 - get config for one sensor. */
1482struct ec_params_thermal_get_threshold_v1 {
1483 uint32_t sensor_num;
1484} __packed;
1485/* This returns a struct ec_thermal_config */
1486
1487/* Version 1 - set config for one sensor.
1488 * Use read-modify-write for best results! */
1489struct ec_params_thermal_set_threshold_v1 {
1490 uint32_t sensor_num;
1491 struct ec_thermal_config cfg;
1492} __packed;
1493/* This returns no data */
1494
1495/****************************************************************************/
1496
894/* Toggle automatic fan control */ 1497/* Toggle automatic fan control */
895#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52 1498#define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
896 1499
@@ -920,6 +1523,18 @@ struct ec_params_tmp006_set_calibration {
920 float b2; 1523 float b2;
921} __packed; 1524} __packed;
922 1525
1526/* Read raw TMP006 data */
1527#define EC_CMD_TMP006_GET_RAW 0x55
1528
1529struct ec_params_tmp006_get_raw {
1530 uint8_t index;
1531} __packed;
1532
1533struct ec_response_tmp006_get_raw {
1534 int32_t t; /* In 1/100 K */
1535 int32_t v; /* In nV */
1536};
1537
923/*****************************************************************************/ 1538/*****************************************************************************/
924/* MKBP - Matrix KeyBoard Protocol */ 1539/* MKBP - Matrix KeyBoard Protocol */
925 1540
@@ -1118,11 +1733,41 @@ struct ec_params_switch_enable_backlight {
1118 1733
1119/* Enable/disable WLAN/Bluetooth */ 1734/* Enable/disable WLAN/Bluetooth */
1120#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91 1735#define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
1736#define EC_VER_SWITCH_ENABLE_WIRELESS 1
1121 1737
1122struct ec_params_switch_enable_wireless { 1738/* Version 0 params; no response */
1739struct ec_params_switch_enable_wireless_v0 {
1123 uint8_t enabled; 1740 uint8_t enabled;
1124} __packed; 1741} __packed;
1125 1742
1743/* Version 1 params */
1744struct ec_params_switch_enable_wireless_v1 {
1745 /* Flags to enable now */
1746 uint8_t now_flags;
1747
1748 /* Which flags to copy from now_flags */
1749 uint8_t now_mask;
1750
1751 /*
1752 * Flags to leave enabled in S3, if they're on at the S0->S3
1753 * transition. (Other flags will be disabled by the S0->S3
1754 * transition.)
1755 */
1756 uint8_t suspend_flags;
1757
1758 /* Which flags to copy from suspend_flags */
1759 uint8_t suspend_mask;
1760} __packed;
1761
1762/* Version 1 response */
1763struct ec_response_switch_enable_wireless_v1 {
1764 /* Flags to enable now */
1765 uint8_t now_flags;
1766
1767 /* Flags to leave enabled in S3 */
1768 uint8_t suspend_flags;
1769} __packed;
1770
1126/*****************************************************************************/ 1771/*****************************************************************************/
1127/* GPIO commands. Only available on EC if write protect has been disabled. */ 1772/* GPIO commands. Only available on EC if write protect has been disabled. */
1128 1773
@@ -1147,11 +1792,16 @@ struct ec_response_gpio_get {
1147/*****************************************************************************/ 1792/*****************************************************************************/
1148/* I2C commands. Only available when flash write protect is unlocked. */ 1793/* I2C commands. Only available when flash write protect is unlocked. */
1149 1794
1795/*
1796 * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
1797 * removed soon. Use EC_CMD_I2C_XFER instead.
1798 */
1799
1150/* Read I2C bus */ 1800/* Read I2C bus */
1151#define EC_CMD_I2C_READ 0x94 1801#define EC_CMD_I2C_READ 0x94
1152 1802
1153struct ec_params_i2c_read { 1803struct ec_params_i2c_read {
1154 uint16_t addr; 1804 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
1155 uint8_t read_size; /* Either 8 or 16. */ 1805 uint8_t read_size; /* Either 8 or 16. */
1156 uint8_t port; 1806 uint8_t port;
1157 uint8_t offset; 1807 uint8_t offset;
@@ -1165,7 +1815,7 @@ struct ec_response_i2c_read {
1165 1815
1166struct ec_params_i2c_write { 1816struct ec_params_i2c_write {
1167 uint16_t data; 1817 uint16_t data;
1168 uint16_t addr; 1818 uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
1169 uint8_t write_size; /* Either 8 or 16. */ 1819 uint8_t write_size; /* Either 8 or 16. */
1170 uint8_t port; 1820 uint8_t port;
1171 uint8_t offset; 1821 uint8_t offset;
@@ -1174,11 +1824,20 @@ struct ec_params_i2c_write {
1174/*****************************************************************************/ 1824/*****************************************************************************/
1175/* Charge state commands. Only available when flash write protect unlocked. */ 1825/* Charge state commands. Only available when flash write protect unlocked. */
1176 1826
1177/* Force charge state machine to stop in idle mode */ 1827/* Force charge state machine to stop charging the battery or force it to
1178#define EC_CMD_CHARGE_FORCE_IDLE 0x96 1828 * discharge the battery.
1829 */
1830#define EC_CMD_CHARGE_CONTROL 0x96
1831#define EC_VER_CHARGE_CONTROL 1
1179 1832
1180struct ec_params_force_idle { 1833enum ec_charge_control_mode {
1181 uint8_t enabled; 1834 CHARGE_CONTROL_NORMAL = 0,
1835 CHARGE_CONTROL_IDLE,
1836 CHARGE_CONTROL_DISCHARGE,
1837};
1838
1839struct ec_params_charge_control {
1840 uint32_t mode; /* enum charge_control_mode */
1182} __packed; 1841} __packed;
1183 1842
1184/*****************************************************************************/ 1843/*****************************************************************************/
@@ -1206,14 +1865,231 @@ struct ec_params_force_idle {
1206#define EC_CMD_BATTERY_CUT_OFF 0x99 1865#define EC_CMD_BATTERY_CUT_OFF 0x99
1207 1866
1208/*****************************************************************************/ 1867/*****************************************************************************/
1209/* Temporary debug commands. TODO: remove this crosbug.com/p/13849 */ 1868/* USB port mux control. */
1210 1869
1211/* 1870/*
1212 * Dump charge state machine context. 1871 * Switch USB mux or return to automatic switching.
1213 * 1872 */
1214 * Response is a binary dump of charge state machine context. 1873#define EC_CMD_USB_MUX 0x9a
1874
1875struct ec_params_usb_mux {
1876 uint8_t mux;
1877} __packed;
1878
1879/*****************************************************************************/
1880/* LDOs / FETs control. */
1881
1882enum ec_ldo_state {
1883 EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
1884 EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
1885};
1886
1887/*
1888 * Switch on/off a LDO.
1889 */
1890#define EC_CMD_LDO_SET 0x9b
1891
1892struct ec_params_ldo_set {
1893 uint8_t index;
1894 uint8_t state;
1895} __packed;
1896
1897/*
1898 * Get LDO state.
1899 */
1900#define EC_CMD_LDO_GET 0x9c
1901
1902struct ec_params_ldo_get {
1903 uint8_t index;
1904} __packed;
1905
1906struct ec_response_ldo_get {
1907 uint8_t state;
1908} __packed;
1909
1910/*****************************************************************************/
1911/* Power info. */
1912
1913/*
1914 * Get power info.
1915 */
1916#define EC_CMD_POWER_INFO 0x9d
1917
1918struct ec_response_power_info {
1919 uint32_t usb_dev_type;
1920 uint16_t voltage_ac;
1921 uint16_t voltage_system;
1922 uint16_t current_system;
1923 uint16_t usb_current_limit;
1924} __packed;
1925
1926/*****************************************************************************/
1927/* I2C passthru command */
1928
1929#define EC_CMD_I2C_PASSTHRU 0x9e
1930
1931/* Slave address is 10 (not 7) bit */
1932#define EC_I2C_FLAG_10BIT (1 << 16)
1933
1934/* Read data; if not present, message is a write */
1935#define EC_I2C_FLAG_READ (1 << 15)
1936
1937/* Mask for address */
1938#define EC_I2C_ADDR_MASK 0x3ff
1939
1940#define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
1941#define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
1942
1943/* Any error */
1944#define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
1945
1946struct ec_params_i2c_passthru_msg {
1947 uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
1948 uint16_t len; /* Number of bytes to read or write */
1949} __packed;
1950
1951struct ec_params_i2c_passthru {
1952 uint8_t port; /* I2C port number */
1953 uint8_t num_msgs; /* Number of messages */
1954 struct ec_params_i2c_passthru_msg msg[];
1955 /* Data to write for all messages is concatenated here */
1956} __packed;
1957
1958struct ec_response_i2c_passthru {
1959 uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
1960 uint8_t num_msgs; /* Number of messages processed */
1961 uint8_t data[]; /* Data read by messages concatenated here */
1962} __packed;
1963
1964/*****************************************************************************/
1965/* Power button hang detect */
1966
1967#define EC_CMD_HANG_DETECT 0x9f
1968
1969/* Reasons to start hang detection timer */
1970/* Power button pressed */
1971#define EC_HANG_START_ON_POWER_PRESS (1 << 0)
1972
1973/* Lid closed */
1974#define EC_HANG_START_ON_LID_CLOSE (1 << 1)
1975
1976 /* Lid opened */
1977#define EC_HANG_START_ON_LID_OPEN (1 << 2)
1978
1979/* Start of AP S3->S0 transition (booting or resuming from suspend) */
1980#define EC_HANG_START_ON_RESUME (1 << 3)
1981
1982/* Reasons to cancel hang detection */
1983
1984/* Power button released */
1985#define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
1986
1987/* Any host command from AP received */
1988#define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
1989
1990/* Stop on end of AP S0->S3 transition (suspending or shutting down) */
1991#define EC_HANG_STOP_ON_SUSPEND (1 << 10)
1992
1993/*
1994 * If this flag is set, all the other fields are ignored, and the hang detect
1995 * timer is started. This provides the AP a way to start the hang timer
1996 * without reconfiguring any of the other hang detect settings. Note that
1997 * you must previously have configured the timeouts.
1998 */
1999#define EC_HANG_START_NOW (1 << 30)
2000
2001/*
2002 * If this flag is set, all the other fields are ignored (including
2003 * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
2004 * without reconfiguring any of the other hang detect settings.
1215 */ 2005 */
1216#define EC_CMD_CHARGE_DUMP 0xa0 2006#define EC_HANG_STOP_NOW (1 << 31)
2007
2008struct ec_params_hang_detect {
2009 /* Flags; see EC_HANG_* */
2010 uint32_t flags;
2011
2012 /* Timeout in msec before generating host event, if enabled */
2013 uint16_t host_event_timeout_msec;
2014
2015 /* Timeout in msec before generating warm reboot, if enabled */
2016 uint16_t warm_reboot_timeout_msec;
2017} __packed;
2018
2019/*****************************************************************************/
2020/* Commands for battery charging */
2021
2022/*
2023 * This is the single catch-all host command to exchange data regarding the
2024 * charge state machine (v2 and up).
2025 */
2026#define EC_CMD_CHARGE_STATE 0xa0
2027
2028/* Subcommands for this host command */
2029enum charge_state_command {
2030 CHARGE_STATE_CMD_GET_STATE,
2031 CHARGE_STATE_CMD_GET_PARAM,
2032 CHARGE_STATE_CMD_SET_PARAM,
2033 CHARGE_STATE_NUM_CMDS
2034};
2035
2036/*
2037 * Known param numbers are defined here. Ranges are reserved for board-specific
2038 * params, which are handled by the particular implementations.
2039 */
2040enum charge_state_params {
2041 CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
2042 CS_PARAM_CHG_CURRENT, /* charger current limit */
2043 CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
2044 CS_PARAM_CHG_STATUS, /* charger-specific status */
2045 CS_PARAM_CHG_OPTION, /* charger-specific options */
2046 /* How many so far? */
2047 CS_NUM_BASE_PARAMS,
2048
2049 /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
2050 CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
2051 CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
2052
2053 /* Other custom param ranges go here... */
2054};
2055
2056struct ec_params_charge_state {
2057 uint8_t cmd; /* enum charge_state_command */
2058 union {
2059 struct {
2060 /* no args */
2061 } get_state;
2062
2063 struct {
2064 uint32_t param; /* enum charge_state_param */
2065 } get_param;
2066
2067 struct {
2068 uint32_t param; /* param to set */
2069 uint32_t value; /* value to set */
2070 } set_param;
2071 };
2072} __packed;
2073
2074struct ec_response_charge_state {
2075 union {
2076 struct {
2077 int ac;
2078 int chg_voltage;
2079 int chg_current;
2080 int chg_input_current;
2081 int batt_state_of_charge;
2082 } get_state;
2083
2084 struct {
2085 uint32_t value;
2086 } get_param;
2087 struct {
2088 /* no return values */
2089 } set_param;
2090 };
2091} __packed;
2092
1217 2093
1218/* 2094/*
1219 * Set maximum battery charging current. 2095 * Set maximum battery charging current.
@@ -1221,15 +2097,59 @@ struct ec_params_force_idle {
1221#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1 2097#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
1222 2098
1223struct ec_params_current_limit { 2099struct ec_params_current_limit {
1224 uint32_t limit; 2100 uint32_t limit; /* in mA */
2101} __packed;
2102
2103/*
2104 * Set maximum external power current.
2105 */
2106#define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
2107
2108struct ec_params_ext_power_current_limit {
2109 uint32_t limit; /* in mA */
2110} __packed;
2111
2112/*****************************************************************************/
2113/* Smart battery pass-through */
2114
2115/* Get / Set 16-bit smart battery registers */
2116#define EC_CMD_SB_READ_WORD 0xb0
2117#define EC_CMD_SB_WRITE_WORD 0xb1
2118
2119/* Get / Set string smart battery parameters
2120 * formatted as SMBUS "block".
2121 */
2122#define EC_CMD_SB_READ_BLOCK 0xb2
2123#define EC_CMD_SB_WRITE_BLOCK 0xb3
2124
2125struct ec_params_sb_rd {
2126 uint8_t reg;
2127} __packed;
2128
2129struct ec_response_sb_rd_word {
2130 uint16_t value;
2131} __packed;
2132
2133struct ec_params_sb_wr_word {
2134 uint8_t reg;
2135 uint16_t value;
2136} __packed;
2137
2138struct ec_response_sb_rd_block {
2139 uint8_t data[32];
2140} __packed;
2141
2142struct ec_params_sb_wr_block {
2143 uint8_t reg;
2144 uint16_t data[32];
1225} __packed; 2145} __packed;
1226 2146
1227/*****************************************************************************/ 2147/*****************************************************************************/
1228/* System commands */ 2148/* System commands */
1229 2149
1230/* 2150/*
1231 * TODO: this is a confusing name, since it doesn't necessarily reboot the EC. 2151 * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
1232 * Rename to "set image" or something similar. 2152 * necessarily reboot the EC. Rename to "image" or something similar?
1233 */ 2153 */
1234#define EC_CMD_REBOOT_EC 0xd2 2154#define EC_CMD_REBOOT_EC 0xd2
1235 2155
@@ -1308,6 +2228,7 @@ struct ec_params_reboot_ec {
1308#define EC_CMD_ACPI_QUERY_EVENT 0x84 2228#define EC_CMD_ACPI_QUERY_EVENT 0x84
1309 2229
1310/* Valid addresses in ACPI memory space, for read/write commands */ 2230/* Valid addresses in ACPI memory space, for read/write commands */
2231
1311/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */ 2232/* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
1312#define EC_ACPI_MEM_VERSION 0x00 2233#define EC_ACPI_MEM_VERSION 0x00
1313/* 2234/*
@@ -1317,8 +2238,60 @@ struct ec_params_reboot_ec {
1317#define EC_ACPI_MEM_TEST 0x01 2238#define EC_ACPI_MEM_TEST 0x01
1318/* Test compliment; writes here are ignored. */ 2239/* Test compliment; writes here are ignored. */
1319#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02 2240#define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
2241
1320/* Keyboard backlight brightness percent (0 - 100) */ 2242/* Keyboard backlight brightness percent (0 - 100) */
1321#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03 2243#define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
2244/* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
2245#define EC_ACPI_MEM_FAN_DUTY 0x04
2246
2247/*
2248 * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
2249 * independent thresholds attached to them. The current value of the ID
2250 * register determines which sensor is affected by the THRESHOLD and COMMIT
2251 * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
2252 * as the memory-mapped sensors. The COMMIT register applies those settings.
2253 *
2254 * The spec does not mandate any way to read back the threshold settings
2255 * themselves, but when a threshold is crossed the AP needs a way to determine
2256 * which sensor(s) are responsible. Each reading of the ID register clears and
2257 * returns one sensor ID that has crossed one of its threshold (in either
2258 * direction) since the last read. A value of 0xFF means "no new thresholds
2259 * have tripped". Setting or enabling the thresholds for a sensor will clear
2260 * the unread event count for that sensor.
2261 */
2262#define EC_ACPI_MEM_TEMP_ID 0x05
2263#define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
2264#define EC_ACPI_MEM_TEMP_COMMIT 0x07
2265/*
2266 * Here are the bits for the COMMIT register:
2267 * bit 0 selects the threshold index for the chosen sensor (0/1)
2268 * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
2269 * Each write to the commit register affects one threshold.
2270 */
2271#define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
2272#define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
2273/*
2274 * Example:
2275 *
2276 * Set the thresholds for sensor 2 to 50 C and 60 C:
2277 * write 2 to [0x05] -- select temp sensor 2
2278 * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
2279 * write 0x2 to [0x07] -- enable threshold 0 with this value
2280 * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
2281 * write 0x3 to [0x07] -- enable threshold 1 with this value
2282 *
2283 * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
2284 * write 2 to [0x05] -- select temp sensor 2
2285 * write 0x1 to [0x07] -- disable threshold 1
2286 */
2287
2288/* DPTF battery charging current limit */
2289#define EC_ACPI_MEM_CHARGING_LIMIT 0x08
2290
2291/* Charging limit is specified in 64 mA steps */
2292#define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
2293/* Value to disable DPTF battery charging limit */
2294#define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
1322 2295
1323/* Current version of ACPI memory address space */ 2296/* Current version of ACPI memory address space */
1324#define EC_ACPI_MEM_VERSION_CURRENT 1 2297#define EC_ACPI_MEM_VERSION_CURRENT 1
@@ -1360,10 +2333,21 @@ struct ec_params_reboot_ec {
1360 * Header bytes greater than this indicate a later version. For example, 2333 * Header bytes greater than this indicate a later version. For example,
1361 * EC_CMD_VERSION0 + 1 means we are using version 1. 2334 * EC_CMD_VERSION0 + 1 means we are using version 1.
1362 * 2335 *
1363 * The old EC interface must not use commands 0dc or higher. 2336 * The old EC interface must not use commands 0xdc or higher.
1364 */ 2337 */
1365#define EC_CMD_VERSION0 0xdc 2338#define EC_CMD_VERSION0 0xdc
1366 2339
1367#endif /* !__ACPI__ */ 2340#endif /* !__ACPI__ */
1368 2341
2342/*****************************************************************************/
2343/*
2344 * Deprecated constants. These constants have been renamed for clarity. The
2345 * meaning and size has not changed. Programs that use the old names should
2346 * switch to the new names soon, as the old names may not be carried forward
2347 * forever.
2348 */
2349#define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
2350#define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
2351#define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
2352
1369#endif /* __CROS_EC_COMMANDS_H */ 2353#endif /* __CROS_EC_COMMANDS_H */