ec_commands.h 48 KB

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