cros_ec_commands.h 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  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. #ifndef __CROS_EC_COMMANDS_H
  23. #define __CROS_EC_COMMANDS_H
  24. /*
  25. * Protocol overview
  26. *
  27. * request: CMD [ P0 P1 P2 ... Pn S ]
  28. * response: ERR [ P0 P1 P2 ... Pn S ]
  29. *
  30. * where the bytes are defined as follow :
  31. * - CMD is the command code. (defined by EC_CMD_ constants)
  32. * - ERR is the error code. (defined by EC_RES_ constants)
  33. * - Px is the optional payload.
  34. * it is not sent if the error code is not success.
  35. * (defined by ec_params_ and ec_response_ structures)
  36. * - S is the checksum which is the sum of all payload bytes.
  37. *
  38. * On LPC, CMD and ERR are sent/received at EC_LPC_ADDR_KERNEL|USER_CMD
  39. * and the payloads are sent/received at EC_LPC_ADDR_KERNEL|USER_PARAM.
  40. * On I2C, all bytes are sent serially in the same message.
  41. */
  42. /* Current version of this protocol */
  43. #define EC_PROTO_VERSION 0x00000002
  44. /* Command version mask */
  45. #define EC_VER_MASK(version) (1UL << (version))
  46. /* I/O addresses for ACPI commands */
  47. #define EC_LPC_ADDR_ACPI_DATA 0x62
  48. #define EC_LPC_ADDR_ACPI_CMD 0x66
  49. /* I/O addresses for host command */
  50. #define EC_LPC_ADDR_HOST_DATA 0x200
  51. #define EC_LPC_ADDR_HOST_CMD 0x204
  52. /* I/O addresses for host command args and params */
  53. #define EC_LPC_ADDR_HOST_ARGS 0x800
  54. #define EC_LPC_ADDR_HOST_PARAM 0x804
  55. #define EC_HOST_PARAM_SIZE 0x0fc /* Size of param area in bytes */
  56. /* I/O addresses for host command params, old interface */
  57. #define EC_LPC_ADDR_OLD_PARAM 0x880
  58. #define EC_OLD_PARAM_SIZE 0x080 /* Size of param area in bytes */
  59. /* EC command register bit functions */
  60. #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
  61. #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
  62. #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
  63. #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
  64. #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
  65. #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
  66. #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
  67. #define EC_LPC_ADDR_MEMMAP 0x900
  68. #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
  69. #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
  70. /* The offset address of each type of data in mapped memory. */
  71. #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors */
  72. #define EC_MEMMAP_FAN 0x10 /* Fan speeds */
  73. #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* Temp sensors (second set) */
  74. #define EC_MEMMAP_ID 0x20 /* 'E' 'C' */
  75. #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
  76. #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
  77. #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
  78. #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
  79. #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
  80. #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host command interface flags */
  81. #define EC_MEMMAP_SWITCHES 0x30
  82. #define EC_MEMMAP_HOST_EVENTS 0x34
  83. #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
  84. #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
  85. #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
  86. #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
  87. #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
  88. #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
  89. #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
  90. #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
  91. #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
  92. #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
  93. #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
  94. #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
  95. /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
  96. #define EC_TEMP_SENSOR_ENTRIES 16
  97. /*
  98. * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
  99. *
  100. * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
  101. */
  102. #define EC_TEMP_SENSOR_B_ENTRIES 8
  103. #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
  104. #define EC_TEMP_SENSOR_ERROR 0xfe
  105. #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
  106. #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
  107. /*
  108. * The offset of temperature value stored in mapped memory. This allows
  109. * reporting a temperature range of 200K to 454K = -73C to 181C.
  110. */
  111. #define EC_TEMP_SENSOR_OFFSET 200
  112. #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
  113. #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
  114. #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
  115. /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
  116. #define EC_BATT_FLAG_AC_PRESENT 0x01
  117. #define EC_BATT_FLAG_BATT_PRESENT 0x02
  118. #define EC_BATT_FLAG_DISCHARGING 0x04
  119. #define EC_BATT_FLAG_CHARGING 0x08
  120. #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
  121. /* Switch flags at EC_MEMMAP_SWITCHES */
  122. #define EC_SWITCH_LID_OPEN 0x01
  123. #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
  124. #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
  125. /* Recovery requested via keyboard */
  126. #define EC_SWITCH_KEYBOARD_RECOVERY 0x08
  127. /* Recovery requested via dedicated signal (from servo board) */
  128. #define EC_SWITCH_DEDICATED_RECOVERY 0x10
  129. /* Was fake developer mode switch; now unused. Remove in next refactor. */
  130. #define EC_SWITCH_IGNORE0 0x20
  131. /* Host command interface flags */
  132. /* Host command interface supports LPC args (LPC interface only) */
  133. #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
  134. /* Wireless switch flags */
  135. #define EC_WIRELESS_SWITCH_WLAN 0x01
  136. #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02
  137. /*
  138. * This header file is used in coreboot both in C and ACPI code. The ACPI code
  139. * is pre-processed to handle constants but the ASL compiler is unable to
  140. * handle actual C code so keep it separate.
  141. */
  142. #ifndef __ACPI__
  143. /* LPC command status byte masks */
  144. /* EC has written a byte in the data register and host hasn't read it yet */
  145. #define EC_LPC_STATUS_TO_HOST 0x01
  146. /* Host has written a command/data byte and the EC hasn't read it yet */
  147. #define EC_LPC_STATUS_FROM_HOST 0x02
  148. /* EC is processing a command */
  149. #define EC_LPC_STATUS_PROCESSING 0x04
  150. /* Last write to EC was a command, not data */
  151. #define EC_LPC_STATUS_LAST_CMD 0x08
  152. /* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
  153. #define EC_LPC_STATUS_BURST_MODE 0x10
  154. /* SCI event is pending (requesting SCI query) */
  155. #define EC_LPC_STATUS_SCI_PENDING 0x20
  156. /* SMI event is pending (requesting SMI query) */
  157. #define EC_LPC_STATUS_SMI_PENDING 0x40
  158. /* (reserved) */
  159. #define EC_LPC_STATUS_RESERVED 0x80
  160. /*
  161. * EC is busy. This covers both the EC processing a command, and the host has
  162. * written a new command but the EC hasn't picked it up yet.
  163. */
  164. #define EC_LPC_STATUS_BUSY_MASK \
  165. (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
  166. /* Host command response codes */
  167. enum ec_status {
  168. EC_RES_SUCCESS = 0,
  169. EC_RES_INVALID_COMMAND = 1,
  170. EC_RES_ERROR = 2,
  171. EC_RES_INVALID_PARAM = 3,
  172. EC_RES_ACCESS_DENIED = 4,
  173. EC_RES_INVALID_RESPONSE = 5,
  174. EC_RES_INVALID_VERSION = 6,
  175. EC_RES_INVALID_CHECKSUM = 7,
  176. EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
  177. EC_RES_UNAVAILABLE = 9, /* No response available */
  178. EC_RES_TIMEOUT = 10, /* We got a timeout */
  179. EC_RES_OVERFLOW = 11, /* Table / data overflow */
  180. };
  181. /*
  182. * Host event codes. Note these are 1-based, not 0-based, because ACPI query
  183. * EC command uses code 0 to mean "no event pending". We explicitly specify
  184. * each value in the enum listing so they won't change if we delete/insert an
  185. * item or rearrange the list (it needs to be stable across platforms, not
  186. * just within a single compiled instance).
  187. */
  188. enum host_event_code {
  189. EC_HOST_EVENT_LID_CLOSED = 1,
  190. EC_HOST_EVENT_LID_OPEN = 2,
  191. EC_HOST_EVENT_POWER_BUTTON = 3,
  192. EC_HOST_EVENT_AC_CONNECTED = 4,
  193. EC_HOST_EVENT_AC_DISCONNECTED = 5,
  194. EC_HOST_EVENT_BATTERY_LOW = 6,
  195. EC_HOST_EVENT_BATTERY_CRITICAL = 7,
  196. EC_HOST_EVENT_BATTERY = 8,
  197. EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
  198. EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
  199. EC_HOST_EVENT_THERMAL = 11,
  200. EC_HOST_EVENT_USB_CHARGER = 12,
  201. EC_HOST_EVENT_KEY_PRESSED = 13,
  202. /*
  203. * EC has finished initializing the host interface. The host can check
  204. * for this event following sending a EC_CMD_REBOOT_EC command to
  205. * determine when the EC is ready to accept subsequent commands.
  206. */
  207. EC_HOST_EVENT_INTERFACE_READY = 14,
  208. /* Keyboard recovery combo has been pressed */
  209. EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
  210. /* Shutdown due to thermal overload */
  211. EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
  212. /* Shutdown due to battery level too low */
  213. EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
  214. /*
  215. * The high bit of the event mask is not used as a host event code. If
  216. * it reads back as set, then the entire event mask should be
  217. * considered invalid by the host. This can happen when reading the
  218. * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
  219. * not initialized on the EC, or improperly configured on the host.
  220. */
  221. EC_HOST_EVENT_INVALID = 32
  222. };
  223. /* Host event mask */
  224. #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
  225. /* Arguments at EC_LPC_ADDR_HOST_ARGS */
  226. struct ec_lpc_host_args {
  227. uint8_t flags;
  228. uint8_t command_version;
  229. uint8_t data_size;
  230. /*
  231. * Checksum; sum of command + flags + command_version + data_size +
  232. * all params/response data bytes.
  233. */
  234. uint8_t checksum;
  235. } __packed;
  236. /* Flags for ec_lpc_host_args.flags */
  237. /*
  238. * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
  239. * params.
  240. *
  241. * If EC gets a command and this flag is not set, this is an old-style command.
  242. * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
  243. * unknown length. EC must respond with an old-style response (that is,
  244. * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
  245. */
  246. #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
  247. /*
  248. * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
  249. *
  250. * If EC responds to a command and this flag is not set, this is an old-style
  251. * response. Command version is 0 and response data from EC is at
  252. * EC_LPC_ADDR_OLD_PARAM with unknown length.
  253. */
  254. #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
  255. /*
  256. * Notes on commands:
  257. *
  258. * Each command is an 8-byte command value. Commands which take params or
  259. * return response data specify structs for that data. If no struct is
  260. * specified, the command does not input or output data, respectively.
  261. * Parameter/response length is implicit in the structs. Some underlying
  262. * communication protocols (I2C, SPI) may add length or checksum headers, but
  263. * those are implementation-dependent and not defined here.
  264. */
  265. /*****************************************************************************/
  266. /* General / test commands */
  267. /*
  268. * Get protocol version, used to deal with non-backward compatible protocol
  269. * changes.
  270. */
  271. #define EC_CMD_PROTO_VERSION 0x00
  272. struct ec_response_proto_version {
  273. uint32_t version;
  274. } __packed;
  275. /*
  276. * Hello. This is a simple command to test the EC is responsive to
  277. * commands.
  278. */
  279. #define EC_CMD_HELLO 0x01
  280. struct ec_params_hello {
  281. uint32_t in_data; /* Pass anything here */
  282. } __packed;
  283. struct ec_response_hello {
  284. uint32_t out_data; /* Output will be in_data + 0x01020304 */
  285. } __packed;
  286. /* Get version number */
  287. #define EC_CMD_GET_VERSION 0x02
  288. enum ec_current_image {
  289. EC_IMAGE_UNKNOWN = 0,
  290. EC_IMAGE_RO,
  291. EC_IMAGE_RW
  292. };
  293. struct ec_response_get_version {
  294. /* Null-terminated version strings for RO, RW */
  295. char version_string_ro[32];
  296. char version_string_rw[32];
  297. char reserved[32]; /* Was previously RW-B string */
  298. uint32_t current_image; /* One of ec_current_image */
  299. } __packed;
  300. /* Read test */
  301. #define EC_CMD_READ_TEST 0x03
  302. struct ec_params_read_test {
  303. uint32_t offset; /* Starting value for read buffer */
  304. uint32_t size; /* Size to read in bytes */
  305. } __packed;
  306. struct ec_response_read_test {
  307. uint32_t data[32];
  308. } __packed;
  309. /*
  310. * Get build information
  311. *
  312. * Response is null-terminated string.
  313. */
  314. #define EC_CMD_GET_BUILD_INFO 0x04
  315. /* Get chip info */
  316. #define EC_CMD_GET_CHIP_INFO 0x05
  317. struct ec_response_get_chip_info {
  318. /* Null-terminated strings */
  319. char vendor[32];
  320. char name[32];
  321. char revision[32]; /* Mask version */
  322. } __packed;
  323. /* Get board HW version */
  324. #define EC_CMD_GET_BOARD_VERSION 0x06
  325. struct ec_response_board_version {
  326. uint16_t board_version; /* A monotonously incrementing number. */
  327. } __packed;
  328. /*
  329. * Read memory-mapped data.
  330. *
  331. * This is an alternate interface to memory-mapped data for bus protocols
  332. * which don't support direct-mapped memory - I2C, SPI, etc.
  333. *
  334. * Response is params.size bytes of data.
  335. */
  336. #define EC_CMD_READ_MEMMAP 0x07
  337. struct ec_params_read_memmap {
  338. uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
  339. uint8_t size; /* Size to read in bytes */
  340. } __packed;
  341. /* Read versions supported for a command */
  342. #define EC_CMD_GET_CMD_VERSIONS 0x08
  343. struct ec_params_get_cmd_versions {
  344. uint8_t cmd; /* Command to check */
  345. } __packed;
  346. struct ec_response_get_cmd_versions {
  347. /*
  348. * Mask of supported versions; use EC_VER_MASK() to compare with a
  349. * desired version.
  350. */
  351. uint32_t version_mask;
  352. } __packed;
  353. /*
  354. * Check EC communcations status (busy). This is needed on i2c/spi but not
  355. * on lpc since it has its own out-of-band busy indicator.
  356. *
  357. * lpc must read the status from the command register. Attempting this on
  358. * lpc will overwrite the args/parameter space and corrupt its data.
  359. */
  360. #define EC_CMD_GET_COMMS_STATUS 0x09
  361. /* Avoid using ec_status which is for return values */
  362. enum ec_comms_status {
  363. EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
  364. };
  365. struct ec_response_get_comms_status {
  366. uint32_t flags; /* Mask of enum ec_comms_status */
  367. } __packed;
  368. /*****************************************************************************/
  369. /* Flash commands */
  370. /* Get flash info */
  371. #define EC_CMD_FLASH_INFO 0x10
  372. struct ec_response_flash_info {
  373. /* Usable flash size, in bytes */
  374. uint32_t flash_size;
  375. /*
  376. * Write block size. Write offset and size must be a multiple
  377. * of this.
  378. */
  379. uint32_t write_block_size;
  380. /*
  381. * Erase block size. Erase offset and size must be a multiple
  382. * of this.
  383. */
  384. uint32_t erase_block_size;
  385. /*
  386. * Protection block size. Protection offset and size must be a
  387. * multiple of this.
  388. */
  389. uint32_t protect_block_size;
  390. } __packed;
  391. /*
  392. * Read flash
  393. *
  394. * Response is params.size bytes of data.
  395. */
  396. #define EC_CMD_FLASH_READ 0x11
  397. struct ec_params_flash_read {
  398. uint32_t offset; /* Byte offset to read */
  399. uint32_t size; /* Size to read in bytes */
  400. } __packed;
  401. /* Write flash */
  402. #define EC_CMD_FLASH_WRITE 0x12
  403. struct ec_params_flash_write {
  404. uint32_t offset; /* Byte offset to write */
  405. uint32_t size; /* Size to write in bytes */
  406. /*
  407. * Data to write. Could really use EC_PARAM_SIZE - 8, but tidiest to
  408. * use a power of 2 so writes stay aligned.
  409. */
  410. uint8_t data[64];
  411. } __packed;
  412. /* Erase flash */
  413. #define EC_CMD_FLASH_ERASE 0x13
  414. struct ec_params_flash_erase {
  415. uint32_t offset; /* Byte offset to erase */
  416. uint32_t size; /* Size to erase in bytes */
  417. } __packed;
  418. /*
  419. * Get/set flash protection.
  420. *
  421. * If mask!=0, sets/clear the requested bits of flags. Depending on the
  422. * firmware write protect GPIO, not all flags will take effect immediately;
  423. * some flags require a subsequent hard reset to take effect. Check the
  424. * returned flags bits to see what actually happened.
  425. *
  426. * If mask=0, simply returns the current flags state.
  427. */
  428. #define EC_CMD_FLASH_PROTECT 0x15
  429. #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
  430. /* Flags for flash protection */
  431. /* RO flash code protected when the EC boots */
  432. #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
  433. /*
  434. * RO flash code protected now. If this bit is set, at-boot status cannot
  435. * be changed.
  436. */
  437. #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
  438. /* Entire flash code protected now, until reboot. */
  439. #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
  440. /* Flash write protect GPIO is asserted now */
  441. #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
  442. /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
  443. #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
  444. /*
  445. * Error - flash protection is in inconsistent state. At least one bank of
  446. * flash which should be protected is not protected. Usually fixed by
  447. * re-requesting the desired flags, or by a hard reset if that fails.
  448. */
  449. #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
  450. /* Entile flash code protected when the EC boots */
  451. #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
  452. struct ec_params_flash_protect {
  453. uint32_t mask; /* Bits in flags to apply */
  454. uint32_t flags; /* New flags to apply */
  455. } __packed;
  456. struct ec_response_flash_protect {
  457. /* Current value of flash protect flags */
  458. uint32_t flags;
  459. /*
  460. * Flags which are valid on this platform. This allows the caller
  461. * to distinguish between flags which aren't set vs. flags which can't
  462. * be set on this platform.
  463. */
  464. uint32_t valid_flags;
  465. /* Flags which can be changed given the current protection state */
  466. uint32_t writable_flags;
  467. } __packed;
  468. /*
  469. * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
  470. * write protect. These commands may be reused with version > 0.
  471. */
  472. /* Get the region offset/size */
  473. #define EC_CMD_FLASH_REGION_INFO 0x16
  474. #define EC_VER_FLASH_REGION_INFO 1
  475. enum ec_flash_region {
  476. /* Region which holds read-only EC image */
  477. EC_FLASH_REGION_RO,
  478. /* Region which holds rewritable EC image */
  479. EC_FLASH_REGION_RW,
  480. /*
  481. * Region which should be write-protected in the factory (a superset of
  482. * EC_FLASH_REGION_RO)
  483. */
  484. EC_FLASH_REGION_WP_RO,
  485. };
  486. struct ec_params_flash_region_info {
  487. uint32_t region; /* enum ec_flash_region */
  488. } __packed;
  489. struct ec_response_flash_region_info {
  490. uint32_t offset;
  491. uint32_t size;
  492. } __packed;
  493. /* Read/write VbNvContext */
  494. #define EC_CMD_VBNV_CONTEXT 0x17
  495. #define EC_VER_VBNV_CONTEXT 1
  496. #define EC_VBNV_BLOCK_SIZE 16
  497. enum ec_vbnvcontext_op {
  498. EC_VBNV_CONTEXT_OP_READ,
  499. EC_VBNV_CONTEXT_OP_WRITE,
  500. };
  501. struct ec_params_vbnvcontext {
  502. uint32_t op;
  503. uint8_t block[EC_VBNV_BLOCK_SIZE];
  504. } __packed;
  505. struct ec_response_vbnvcontext {
  506. uint8_t block[EC_VBNV_BLOCK_SIZE];
  507. } __packed;
  508. /*****************************************************************************/
  509. /* PWM commands */
  510. /* Get fan target RPM */
  511. #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
  512. struct ec_response_pwm_get_fan_rpm {
  513. uint32_t rpm;
  514. } __packed;
  515. /* Set target fan RPM */
  516. #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
  517. struct ec_params_pwm_set_fan_target_rpm {
  518. uint32_t rpm;
  519. } __packed;
  520. /* Get keyboard backlight */
  521. #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
  522. struct ec_response_pwm_get_keyboard_backlight {
  523. uint8_t percent;
  524. uint8_t enabled;
  525. } __packed;
  526. /* Set keyboard backlight */
  527. #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
  528. struct ec_params_pwm_set_keyboard_backlight {
  529. uint8_t percent;
  530. } __packed;
  531. /* Set target fan PWM duty cycle */
  532. #define EC_CMD_PWM_SET_FAN_DUTY 0x24
  533. struct ec_params_pwm_set_fan_duty {
  534. uint32_t percent;
  535. } __packed;
  536. /*****************************************************************************/
  537. /*
  538. * Lightbar commands. This looks worse than it is. Since we only use one HOST
  539. * command to say "talk to the lightbar", we put the "and tell it to do X" part
  540. * into a subcommand. We'll make separate structs for subcommands with
  541. * different input args, so that we know how much to expect.
  542. */
  543. #define EC_CMD_LIGHTBAR_CMD 0x28
  544. struct rgb_s {
  545. uint8_t r, g, b;
  546. };
  547. #define LB_BATTERY_LEVELS 4
  548. /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
  549. * host command, but the alignment is the same regardless. Keep it that way.
  550. */
  551. struct lightbar_params {
  552. /* Timing */
  553. int google_ramp_up;
  554. int google_ramp_down;
  555. int s3s0_ramp_up;
  556. int s0_tick_delay[2]; /* AC=0/1 */
  557. int s0a_tick_delay[2]; /* AC=0/1 */
  558. int s0s3_ramp_down;
  559. int s3_sleep_for;
  560. int s3_ramp_up;
  561. int s3_ramp_down;
  562. /* Oscillation */
  563. uint8_t new_s0;
  564. uint8_t osc_min[2]; /* AC=0/1 */
  565. uint8_t osc_max[2]; /* AC=0/1 */
  566. uint8_t w_ofs[2]; /* AC=0/1 */
  567. /* Brightness limits based on the backlight and AC. */
  568. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  569. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  570. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  571. /* Battery level thresholds */
  572. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  573. /* Map [AC][battery_level] to color index */
  574. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  575. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  576. /* Color palette */
  577. struct rgb_s color[8]; /* 0-3 are Google colors */
  578. } __packed;
  579. struct ec_params_lightbar {
  580. uint8_t cmd; /* Command (see enum lightbar_command) */
  581. union {
  582. struct {
  583. /* no args */
  584. } dump, off, on, init, get_seq, get_params;
  585. struct num {
  586. uint8_t num;
  587. } brightness, seq, demo;
  588. struct reg {
  589. uint8_t ctrl, reg, value;
  590. } reg;
  591. struct rgb {
  592. uint8_t led, red, green, blue;
  593. } rgb;
  594. struct lightbar_params set_params;
  595. };
  596. } __packed;
  597. struct ec_response_lightbar {
  598. union {
  599. struct dump {
  600. struct {
  601. uint8_t reg;
  602. uint8_t ic0;
  603. uint8_t ic1;
  604. } vals[23];
  605. } dump;
  606. struct get_seq {
  607. uint8_t num;
  608. } get_seq;
  609. struct lightbar_params get_params;
  610. struct {
  611. /* no return params */
  612. } off, on, init, brightness, seq, reg, rgb, demo, set_params;
  613. };
  614. } __packed;
  615. /* Lightbar commands */
  616. enum lightbar_command {
  617. LIGHTBAR_CMD_DUMP = 0,
  618. LIGHTBAR_CMD_OFF = 1,
  619. LIGHTBAR_CMD_ON = 2,
  620. LIGHTBAR_CMD_INIT = 3,
  621. LIGHTBAR_CMD_BRIGHTNESS = 4,
  622. LIGHTBAR_CMD_SEQ = 5,
  623. LIGHTBAR_CMD_REG = 6,
  624. LIGHTBAR_CMD_RGB = 7,
  625. LIGHTBAR_CMD_GET_SEQ = 8,
  626. LIGHTBAR_CMD_DEMO = 9,
  627. LIGHTBAR_CMD_GET_PARAMS = 10,
  628. LIGHTBAR_CMD_SET_PARAMS = 11,
  629. LIGHTBAR_NUM_CMDS
  630. };
  631. /*****************************************************************************/
  632. /* Verified boot commands */
  633. /*
  634. * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
  635. * reused for other purposes with version > 0.
  636. */
  637. /* Verified boot hash command */
  638. #define EC_CMD_VBOOT_HASH 0x2A
  639. struct ec_params_vboot_hash {
  640. uint8_t cmd; /* enum ec_vboot_hash_cmd */
  641. uint8_t hash_type; /* enum ec_vboot_hash_type */
  642. uint8_t nonce_size; /* Nonce size; may be 0 */
  643. uint8_t reserved0; /* Reserved; set 0 */
  644. uint32_t offset; /* Offset in flash to hash */
  645. uint32_t size; /* Number of bytes to hash */
  646. uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
  647. } __packed;
  648. struct ec_response_vboot_hash {
  649. uint8_t status; /* enum ec_vboot_hash_status */
  650. uint8_t hash_type; /* enum ec_vboot_hash_type */
  651. uint8_t digest_size; /* Size of hash digest in bytes */
  652. uint8_t reserved0; /* Ignore; will be 0 */
  653. uint32_t offset; /* Offset in flash which was hashed */
  654. uint32_t size; /* Number of bytes hashed */
  655. uint8_t hash_digest[64]; /* Hash digest data */
  656. } __packed;
  657. enum ec_vboot_hash_cmd {
  658. EC_VBOOT_HASH_GET = 0, /* Get current hash status */
  659. EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
  660. EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
  661. EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
  662. };
  663. enum ec_vboot_hash_type {
  664. EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
  665. };
  666. enum ec_vboot_hash_status {
  667. EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
  668. EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
  669. EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
  670. };
  671. /*
  672. * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
  673. * If one of these is specified, the EC will automatically update offset and
  674. * size to the correct values for the specified image (RO or RW).
  675. */
  676. #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
  677. #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
  678. /*****************************************************************************/
  679. /* USB charging control commands */
  680. /* Set USB port charging mode */
  681. #define EC_CMD_USB_CHARGE_SET_MODE 0x30
  682. struct ec_params_usb_charge_set_mode {
  683. uint8_t usb_port_id;
  684. uint8_t mode;
  685. } __packed;
  686. /*****************************************************************************/
  687. /* Persistent storage for host */
  688. /* Maximum bytes that can be read/written in a single command */
  689. #define EC_PSTORE_SIZE_MAX 64
  690. /* Get persistent storage info */
  691. #define EC_CMD_PSTORE_INFO 0x40
  692. struct ec_response_pstore_info {
  693. /* Persistent storage size, in bytes */
  694. uint32_t pstore_size;
  695. /* Access size; read/write offset and size must be a multiple of this */
  696. uint32_t access_size;
  697. } __packed;
  698. /*
  699. * Read persistent storage
  700. *
  701. * Response is params.size bytes of data.
  702. */
  703. #define EC_CMD_PSTORE_READ 0x41
  704. struct ec_params_pstore_read {
  705. uint32_t offset; /* Byte offset to read */
  706. uint32_t size; /* Size to read in bytes */
  707. } __packed;
  708. /* Write persistent storage */
  709. #define EC_CMD_PSTORE_WRITE 0x42
  710. struct ec_params_pstore_write {
  711. uint32_t offset; /* Byte offset to write */
  712. uint32_t size; /* Size to write in bytes */
  713. uint8_t data[EC_PSTORE_SIZE_MAX];
  714. } __packed;
  715. /*****************************************************************************/
  716. /* Real-time clock */
  717. /* RTC params and response structures */
  718. struct ec_params_rtc {
  719. uint32_t time;
  720. } __packed;
  721. struct ec_response_rtc {
  722. uint32_t time;
  723. } __packed;
  724. /* These use ec_response_rtc */
  725. #define EC_CMD_RTC_GET_VALUE 0x44
  726. #define EC_CMD_RTC_GET_ALARM 0x45
  727. /* These all use ec_params_rtc */
  728. #define EC_CMD_RTC_SET_VALUE 0x46
  729. #define EC_CMD_RTC_SET_ALARM 0x47
  730. /*****************************************************************************/
  731. /* Port80 log access */
  732. /* Get last port80 code from previous boot */
  733. #define EC_CMD_PORT80_LAST_BOOT 0x48
  734. struct ec_response_port80_last_boot {
  735. uint16_t code;
  736. } __packed;
  737. /*****************************************************************************/
  738. /* Thermal engine commands */
  739. /* Set thershold value */
  740. #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
  741. struct ec_params_thermal_set_threshold {
  742. uint8_t sensor_type;
  743. uint8_t threshold_id;
  744. uint16_t value;
  745. } __packed;
  746. /* Get threshold value */
  747. #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
  748. struct ec_params_thermal_get_threshold {
  749. uint8_t sensor_type;
  750. uint8_t threshold_id;
  751. } __packed;
  752. struct ec_response_thermal_get_threshold {
  753. uint16_t value;
  754. } __packed;
  755. /* Toggle automatic fan control */
  756. #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
  757. /* Get TMP006 calibration data */
  758. #define EC_CMD_TMP006_GET_CALIBRATION 0x53
  759. struct ec_params_tmp006_get_calibration {
  760. uint8_t index;
  761. } __packed;
  762. struct ec_response_tmp006_get_calibration {
  763. float s0;
  764. float b0;
  765. float b1;
  766. float b2;
  767. } __packed;
  768. /* Set TMP006 calibration data */
  769. #define EC_CMD_TMP006_SET_CALIBRATION 0x54
  770. struct ec_params_tmp006_set_calibration {
  771. uint8_t index;
  772. uint8_t reserved[3]; /* Reserved; set 0 */
  773. float s0;
  774. float b0;
  775. float b1;
  776. float b2;
  777. } __packed;
  778. /*****************************************************************************/
  779. /* MKBP - Matrix KeyBoard Protocol */
  780. /*
  781. * Read key state
  782. *
  783. * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
  784. * expected response size.
  785. */
  786. #define EC_CMD_MKBP_STATE 0x60
  787. /* Provide information about the matrix : number of rows and columns */
  788. #define EC_CMD_MKBP_INFO 0x61
  789. struct ec_response_mkbp_info {
  790. uint32_t rows;
  791. uint32_t cols;
  792. uint8_t switches;
  793. } __packed;
  794. /* Simulate key press */
  795. #define EC_CMD_MKBP_SIMULATE_KEY 0x62
  796. struct ec_params_mkbp_simulate_key {
  797. uint8_t col;
  798. uint8_t row;
  799. uint8_t pressed;
  800. } __packed;
  801. /* Configure keyboard scanning */
  802. #define EC_CMD_MKBP_SET_CONFIG 0x64
  803. #define EC_CMD_MKBP_GET_CONFIG 0x65
  804. /* flags */
  805. enum mkbp_config_flags {
  806. EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
  807. };
  808. enum mkbp_config_valid {
  809. EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
  810. EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
  811. EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
  812. EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
  813. EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
  814. EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
  815. EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
  816. };
  817. /* Configuration for our key scanning algorithm */
  818. struct ec_mkbp_config {
  819. uint32_t valid_mask; /* valid fields */
  820. uint8_t flags; /* some flags (enum mkbp_config_flags) */
  821. uint8_t valid_flags; /* which flags are valid */
  822. uint16_t scan_period_us; /* period between start of scans */
  823. /* revert to interrupt mode after no activity for this long */
  824. uint32_t poll_timeout_us;
  825. /*
  826. * minimum post-scan relax time. Once we finish a scan we check
  827. * the time until we are due to start the next one. If this time is
  828. * shorter this field, we use this instead.
  829. */
  830. uint16_t min_post_scan_delay_us;
  831. /* delay between setting up output and waiting for it to settle */
  832. uint16_t output_settle_us;
  833. uint16_t debounce_down_us; /* time for debounce on key down */
  834. uint16_t debounce_up_us; /* time for debounce on key up */
  835. /* maximum depth to allow for fifo (0 = no keyscan output) */
  836. uint8_t fifo_max_depth;
  837. } __packed;
  838. struct ec_params_mkbp_set_config {
  839. struct ec_mkbp_config config;
  840. } __packed;
  841. struct ec_response_mkbp_get_config {
  842. struct ec_mkbp_config config;
  843. } __packed;
  844. /* Run the key scan emulation */
  845. #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
  846. enum ec_keyscan_seq_cmd {
  847. EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
  848. EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
  849. EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
  850. EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
  851. EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
  852. };
  853. enum ec_collect_flags {
  854. /*
  855. * Indicates this scan was processed by the EC. Due to timing, some
  856. * scans may be skipped.
  857. */
  858. EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
  859. };
  860. struct ec_collect_item {
  861. uint8_t flags; /* some flags (enum ec_collect_flags) */
  862. };
  863. struct ec_params_keyscan_seq_ctrl {
  864. uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
  865. union {
  866. struct {
  867. uint8_t active; /* still active */
  868. uint8_t num_items; /* number of items */
  869. /* Current item being presented */
  870. uint8_t cur_item;
  871. } status;
  872. struct {
  873. /*
  874. * Absolute time for this scan, measured from the
  875. * start of the sequence.
  876. */
  877. uint32_t time_us;
  878. uint8_t scan[0]; /* keyscan data */
  879. } add;
  880. struct {
  881. uint8_t start_item; /* First item to return */
  882. uint8_t num_items; /* Number of items to return */
  883. } collect;
  884. };
  885. } __packed;
  886. struct ec_result_keyscan_seq_ctrl {
  887. union {
  888. struct {
  889. uint8_t num_items; /* Number of items */
  890. /* Data for each item */
  891. struct ec_collect_item item[0];
  892. } collect;
  893. };
  894. } __packed;
  895. /*****************************************************************************/
  896. /* Temperature sensor commands */
  897. /* Read temperature sensor info */
  898. #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
  899. struct ec_params_temp_sensor_get_info {
  900. uint8_t id;
  901. } __packed;
  902. struct ec_response_temp_sensor_get_info {
  903. char sensor_name[32];
  904. uint8_t sensor_type;
  905. } __packed;
  906. /*****************************************************************************/
  907. /*
  908. * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
  909. * commands accidentally sent to the wrong interface. See the ACPI section
  910. * below.
  911. */
  912. /*****************************************************************************/
  913. /* Host event commands */
  914. /*
  915. * Host event mask params and response structures, shared by all of the host
  916. * event commands below.
  917. */
  918. struct ec_params_host_event_mask {
  919. uint32_t mask;
  920. } __packed;
  921. struct ec_response_host_event_mask {
  922. uint32_t mask;
  923. } __packed;
  924. /* These all use ec_response_host_event_mask */
  925. #define EC_CMD_HOST_EVENT_GET_B 0x87
  926. #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
  927. #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
  928. #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
  929. /* These all use ec_params_host_event_mask */
  930. #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
  931. #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
  932. #define EC_CMD_HOST_EVENT_CLEAR 0x8c
  933. #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
  934. #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
  935. /*****************************************************************************/
  936. /* Switch commands */
  937. /* Enable/disable LCD backlight */
  938. #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
  939. struct ec_params_switch_enable_backlight {
  940. uint8_t enabled;
  941. } __packed;
  942. /* Enable/disable WLAN/Bluetooth */
  943. #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
  944. struct ec_params_switch_enable_wireless {
  945. uint8_t enabled;
  946. } __packed;
  947. /*****************************************************************************/
  948. /* GPIO commands. Only available on EC if write protect has been disabled. */
  949. /* Set GPIO output value */
  950. #define EC_CMD_GPIO_SET 0x92
  951. struct ec_params_gpio_set {
  952. char name[32];
  953. uint8_t val;
  954. } __packed;
  955. /* Get GPIO value */
  956. #define EC_CMD_GPIO_GET 0x93
  957. struct ec_params_gpio_get {
  958. char name[32];
  959. } __packed;
  960. struct ec_response_gpio_get {
  961. uint8_t val;
  962. } __packed;
  963. /*****************************************************************************/
  964. /* I2C commands. Only available when flash write protect is unlocked. */
  965. /* Read I2C bus */
  966. #define EC_CMD_I2C_READ 0x94
  967. struct ec_params_i2c_read {
  968. uint16_t addr;
  969. uint8_t read_size; /* Either 8 or 16. */
  970. uint8_t port;
  971. uint8_t offset;
  972. } __packed;
  973. struct ec_response_i2c_read {
  974. uint16_t data;
  975. } __packed;
  976. /* Write I2C bus */
  977. #define EC_CMD_I2C_WRITE 0x95
  978. struct ec_params_i2c_write {
  979. uint16_t data;
  980. uint16_t addr;
  981. uint8_t write_size; /* Either 8 or 16. */
  982. uint8_t port;
  983. uint8_t offset;
  984. } __packed;
  985. /*****************************************************************************/
  986. /* Charge state commands. Only available when flash write protect unlocked. */
  987. /* Force charge state machine to stop in idle mode */
  988. #define EC_CMD_CHARGE_FORCE_IDLE 0x96
  989. struct ec_params_force_idle {
  990. uint8_t enabled;
  991. } __packed;
  992. /*****************************************************************************/
  993. /* Console commands. Only available when flash write protect is unlocked. */
  994. /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
  995. #define EC_CMD_CONSOLE_SNAPSHOT 0x97
  996. /*
  997. * Read next chunk of data from saved snapshot.
  998. *
  999. * Response is null-terminated string. Empty string, if there is no more
  1000. * remaining output.
  1001. */
  1002. #define EC_CMD_CONSOLE_READ 0x98
  1003. /*****************************************************************************/
  1004. /*
  1005. * Cut off battery power output if the battery supports.
  1006. *
  1007. * For unsupported battery, just don't implement this command and lets EC
  1008. * return EC_RES_INVALID_COMMAND.
  1009. */
  1010. #define EC_CMD_BATTERY_CUT_OFF 0x99
  1011. /*****************************************************************************/
  1012. /* Temporary debug commands. TODO: remove this crosbug.com/p/13849 */
  1013. /*
  1014. * Dump charge state machine context.
  1015. *
  1016. * Response is a binary dump of charge state machine context.
  1017. */
  1018. #define EC_CMD_CHARGE_DUMP 0xa0
  1019. /*
  1020. * Set maximum battery charging current.
  1021. */
  1022. #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
  1023. struct ec_params_current_limit {
  1024. uint32_t limit;
  1025. } __packed;
  1026. /*****************************************************************************/
  1027. /* System commands */
  1028. /*
  1029. * TODO: this is a confusing name, since it doesn't necessarily reboot the EC.
  1030. * Rename to "set image" or something similar.
  1031. */
  1032. #define EC_CMD_REBOOT_EC 0xd2
  1033. /* Command */
  1034. enum ec_reboot_cmd {
  1035. EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
  1036. EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
  1037. EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
  1038. /* (command 3 was jump to RW-B) */
  1039. EC_REBOOT_COLD = 4, /* Cold-reboot */
  1040. EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
  1041. EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
  1042. };
  1043. /* Flags for ec_params_reboot_ec.reboot_flags */
  1044. #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
  1045. #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
  1046. struct ec_params_reboot_ec {
  1047. uint8_t cmd; /* enum ec_reboot_cmd */
  1048. uint8_t flags; /* See EC_REBOOT_FLAG_* */
  1049. } __packed;
  1050. /*
  1051. * Get information on last EC panic.
  1052. *
  1053. * Returns variable-length platform-dependent panic information. See panic.h
  1054. * for details.
  1055. */
  1056. #define EC_CMD_GET_PANIC_INFO 0xd3
  1057. /*****************************************************************************/
  1058. /*
  1059. * ACPI commands
  1060. *
  1061. * These are valid ONLY on the ACPI command/data port.
  1062. */
  1063. /*
  1064. * ACPI Read Embedded Controller
  1065. *
  1066. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  1067. *
  1068. * Use the following sequence:
  1069. *
  1070. * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
  1071. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  1072. * - Write address to EC_LPC_ADDR_ACPI_DATA
  1073. * - Wait for EC_LPC_CMDR_DATA bit to set
  1074. * - Read value from EC_LPC_ADDR_ACPI_DATA
  1075. */
  1076. #define EC_CMD_ACPI_READ 0x80
  1077. /*
  1078. * ACPI Write Embedded Controller
  1079. *
  1080. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  1081. *
  1082. * Use the following sequence:
  1083. *
  1084. * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
  1085. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  1086. * - Write address to EC_LPC_ADDR_ACPI_DATA
  1087. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  1088. * - Write value to EC_LPC_ADDR_ACPI_DATA
  1089. */
  1090. #define EC_CMD_ACPI_WRITE 0x81
  1091. /*
  1092. * ACPI Query Embedded Controller
  1093. *
  1094. * This clears the lowest-order bit in the currently pending host events, and
  1095. * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
  1096. * event 0x80000000 = 32), or 0 if no event was pending.
  1097. */
  1098. #define EC_CMD_ACPI_QUERY_EVENT 0x84
  1099. /* Valid addresses in ACPI memory space, for read/write commands */
  1100. /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
  1101. #define EC_ACPI_MEM_VERSION 0x00
  1102. /*
  1103. * Test location; writing value here updates test compliment byte to (0xff -
  1104. * value).
  1105. */
  1106. #define EC_ACPI_MEM_TEST 0x01
  1107. /* Test compliment; writes here are ignored. */
  1108. #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
  1109. /* Keyboard backlight brightness percent (0 - 100) */
  1110. #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
  1111. /* Current version of ACPI memory address space */
  1112. #define EC_ACPI_MEM_VERSION_CURRENT 1
  1113. /*****************************************************************************/
  1114. /*
  1115. * Special commands
  1116. *
  1117. * These do not follow the normal rules for commands. See each command for
  1118. * details.
  1119. */
  1120. /*
  1121. * Reboot NOW
  1122. *
  1123. * This command will work even when the EC LPC interface is busy, because the
  1124. * reboot command is processed at interrupt level. Note that when the EC
  1125. * reboots, the host will reboot too, so there is no response to this command.
  1126. *
  1127. * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
  1128. */
  1129. #define EC_CMD_REBOOT 0xd1 /* Think "die" */
  1130. /*
  1131. * Resend last response (not supported on LPC).
  1132. *
  1133. * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
  1134. * there was no previous command, or the previous command's response was too
  1135. * big to save.
  1136. */
  1137. #define EC_CMD_RESEND_RESPONSE 0xdb
  1138. /*
  1139. * This header byte on a command indicate version 0. Any header byte less
  1140. * than this means that we are talking to an old EC which doesn't support
  1141. * versioning. In that case, we assume version 0.
  1142. *
  1143. * Header bytes greater than this indicate a later version. For example,
  1144. * EC_CMD_VERSION0 + 1 means we are using version 1.
  1145. *
  1146. * The old EC interface must not use commands 0dc or higher.
  1147. */
  1148. #define EC_CMD_VERSION0 0xdc
  1149. #endif /* !__ACPI__ */
  1150. #endif /* __CROS_EC_COMMANDS_H */