ec_commands.h 41 KB

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