cros_ec_commands.h 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649
  1. /*
  2. * Host communication command constants for ChromeOS EC
  3. *
  4. * Copyright (C) 2012 Google, Inc
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * The ChromeOS EC multi function device is used to mux all the requests
  16. * to the EC device for its multiple features: keyboard controller,
  17. * battery charging and regulator control, firmware update.
  18. *
  19. * NOTE: This file is copied verbatim from the ChromeOS EC Open Source
  20. * project in an attempt to make future updates easy to make.
  21. */
  22. #ifndef __CROS_EC_COMMANDS_H
  23. #define __CROS_EC_COMMANDS_H
  24. /*
  25. * Current version of this protocol
  26. *
  27. * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
  28. * determined in other ways. Remove this once the kernel code no longer
  29. * depends on it.
  30. */
  31. #define EC_PROTO_VERSION 0x00000002
  32. /* Command version mask */
  33. #define EC_VER_MASK(version) (1UL << (version))
  34. /* I/O addresses for ACPI commands */
  35. #define EC_LPC_ADDR_ACPI_DATA 0x62
  36. #define EC_LPC_ADDR_ACPI_CMD 0x66
  37. /* I/O addresses for host command */
  38. #define EC_LPC_ADDR_HOST_DATA 0x200
  39. #define EC_LPC_ADDR_HOST_CMD 0x204
  40. /* I/O addresses for host command args and params */
  41. /* Protocol version 2 */
  42. #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
  43. #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
  44. * EC_PROTO2_MAX_PARAM_SIZE */
  45. /* Protocol version 3 */
  46. #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
  47. #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
  48. /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
  49. * and they tell the kernel that so we have to think of it as two parts. */
  50. #define EC_HOST_CMD_REGION0 0x800
  51. #define EC_HOST_CMD_REGION1 0x880
  52. #define EC_HOST_CMD_REGION_SIZE 0x80
  53. /* EC command register bit functions */
  54. #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
  55. #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
  56. #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
  57. #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
  58. #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
  59. #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
  60. #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
  61. #define EC_LPC_ADDR_MEMMAP 0x900
  62. #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
  63. #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
  64. /* The offset address of each type of data in mapped memory. */
  65. #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
  66. #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
  67. #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
  68. #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
  69. #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
  70. #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
  71. #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
  72. #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
  73. #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
  74. #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
  75. /* Unused 0x28 - 0x2f */
  76. #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
  77. /* Unused 0x31 - 0x33 */
  78. #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
  79. /* Reserve 0x38 - 0x3f for additional host event-related stuff */
  80. /* Battery values are all 32 bits */
  81. #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
  82. #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
  83. #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
  84. #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
  85. #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
  86. #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
  87. #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
  88. #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
  89. /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
  90. #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
  91. #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
  92. #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
  93. #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
  94. #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
  95. /* Unused 0x84 - 0x8f */
  96. #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
  97. /* Unused 0x91 */
  98. #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometer data 0x92 - 0x9f */
  99. #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
  100. /* Unused 0xa6 - 0xfe (remember, 0xff is NOT part of the memmap region) */
  101. /* Define the format of the accelerometer mapped memory status byte. */
  102. #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
  103. #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
  104. #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
  105. /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
  106. #define EC_TEMP_SENSOR_ENTRIES 16
  107. /*
  108. * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
  109. *
  110. * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
  111. */
  112. #define EC_TEMP_SENSOR_B_ENTRIES 8
  113. /* Special values for mapped temperature sensors */
  114. #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
  115. #define EC_TEMP_SENSOR_ERROR 0xfe
  116. #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
  117. #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
  118. /*
  119. * The offset of temperature value stored in mapped memory. This allows
  120. * reporting a temperature range of 200K to 454K = -73C to 181C.
  121. */
  122. #define EC_TEMP_SENSOR_OFFSET 200
  123. /*
  124. * Number of ALS readings at EC_MEMMAP_ALS
  125. */
  126. #define EC_ALS_ENTRIES 2
  127. /*
  128. * The default value a temperature sensor will return when it is present but
  129. * has not been read this boot. This is a reasonable number to avoid
  130. * triggering alarms on the host.
  131. */
  132. #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
  133. #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
  134. #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
  135. #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
  136. /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
  137. #define EC_BATT_FLAG_AC_PRESENT 0x01
  138. #define EC_BATT_FLAG_BATT_PRESENT 0x02
  139. #define EC_BATT_FLAG_DISCHARGING 0x04
  140. #define EC_BATT_FLAG_CHARGING 0x08
  141. #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
  142. /* Switch flags at EC_MEMMAP_SWITCHES */
  143. #define EC_SWITCH_LID_OPEN 0x01
  144. #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
  145. #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
  146. /* Was recovery requested via keyboard; now unused. */
  147. #define EC_SWITCH_IGNORE1 0x08
  148. /* Recovery requested via dedicated signal (from servo board) */
  149. #define EC_SWITCH_DEDICATED_RECOVERY 0x10
  150. /* Was fake developer mode switch; now unused. Remove in next refactor. */
  151. #define EC_SWITCH_IGNORE0 0x20
  152. /* Host command interface flags */
  153. /* Host command interface supports LPC args (LPC interface only) */
  154. #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
  155. /* Host command interface supports version 3 protocol */
  156. #define EC_HOST_CMD_FLAG_VERSION_3 0x02
  157. /* Wireless switch flags */
  158. #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
  159. #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
  160. #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
  161. #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
  162. #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
  163. /*
  164. * This header file is used in coreboot both in C and ACPI code. The ACPI code
  165. * is pre-processed to handle constants but the ASL compiler is unable to
  166. * handle actual C code so keep it separate.
  167. */
  168. #ifndef __ACPI__
  169. /*
  170. * Define __packed if someone hasn't beat us to it. Linux kernel style
  171. * checking prefers __packed over __attribute__((packed)).
  172. */
  173. #ifndef __packed
  174. #define __packed __attribute__((packed))
  175. #endif
  176. /* LPC command status byte masks */
  177. /* EC has written a byte in the data register and host hasn't read it yet */
  178. #define EC_LPC_STATUS_TO_HOST 0x01
  179. /* Host has written a command/data byte and the EC hasn't read it yet */
  180. #define EC_LPC_STATUS_FROM_HOST 0x02
  181. /* EC is processing a command */
  182. #define EC_LPC_STATUS_PROCESSING 0x04
  183. /* Last write to EC was a command, not data */
  184. #define EC_LPC_STATUS_LAST_CMD 0x08
  185. /* EC is in burst mode. Unsupported by Chrome EC, so this bit is never set */
  186. #define EC_LPC_STATUS_BURST_MODE 0x10
  187. /* SCI event is pending (requesting SCI query) */
  188. #define EC_LPC_STATUS_SCI_PENDING 0x20
  189. /* SMI event is pending (requesting SMI query) */
  190. #define EC_LPC_STATUS_SMI_PENDING 0x40
  191. /* (reserved) */
  192. #define EC_LPC_STATUS_RESERVED 0x80
  193. /*
  194. * EC is busy. This covers both the EC processing a command, and the host has
  195. * written a new command but the EC hasn't picked it up yet.
  196. */
  197. #define EC_LPC_STATUS_BUSY_MASK \
  198. (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
  199. /* Host command response codes */
  200. enum ec_status {
  201. EC_RES_SUCCESS = 0,
  202. EC_RES_INVALID_COMMAND = 1,
  203. EC_RES_ERROR = 2,
  204. EC_RES_INVALID_PARAM = 3,
  205. EC_RES_ACCESS_DENIED = 4,
  206. EC_RES_INVALID_RESPONSE = 5,
  207. EC_RES_INVALID_VERSION = 6,
  208. EC_RES_INVALID_CHECKSUM = 7,
  209. EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
  210. EC_RES_UNAVAILABLE = 9, /* No response available */
  211. EC_RES_TIMEOUT = 10, /* We got a timeout */
  212. EC_RES_OVERFLOW = 11, /* Table / data overflow */
  213. EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
  214. EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
  215. EC_RES_RESPONSE_TOO_BIG = 14 /* Response was too big to handle */
  216. };
  217. /*
  218. * Host event codes. Note these are 1-based, not 0-based, because ACPI query
  219. * EC command uses code 0 to mean "no event pending". We explicitly specify
  220. * each value in the enum listing so they won't change if we delete/insert an
  221. * item or rearrange the list (it needs to be stable across platforms, not
  222. * just within a single compiled instance).
  223. */
  224. enum host_event_code {
  225. EC_HOST_EVENT_LID_CLOSED = 1,
  226. EC_HOST_EVENT_LID_OPEN = 2,
  227. EC_HOST_EVENT_POWER_BUTTON = 3,
  228. EC_HOST_EVENT_AC_CONNECTED = 4,
  229. EC_HOST_EVENT_AC_DISCONNECTED = 5,
  230. EC_HOST_EVENT_BATTERY_LOW = 6,
  231. EC_HOST_EVENT_BATTERY_CRITICAL = 7,
  232. EC_HOST_EVENT_BATTERY = 8,
  233. EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
  234. EC_HOST_EVENT_THERMAL_OVERLOAD = 10,
  235. EC_HOST_EVENT_THERMAL = 11,
  236. EC_HOST_EVENT_USB_CHARGER = 12,
  237. EC_HOST_EVENT_KEY_PRESSED = 13,
  238. /*
  239. * EC has finished initializing the host interface. The host can check
  240. * for this event following sending a EC_CMD_REBOOT_EC command to
  241. * determine when the EC is ready to accept subsequent commands.
  242. */
  243. EC_HOST_EVENT_INTERFACE_READY = 14,
  244. /* Keyboard recovery combo has been pressed */
  245. EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
  246. /* Shutdown due to thermal overload */
  247. EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
  248. /* Shutdown due to battery level too low */
  249. EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
  250. /* Suggest that the AP throttle itself */
  251. EC_HOST_EVENT_THROTTLE_START = 18,
  252. /* Suggest that the AP resume normal speed */
  253. EC_HOST_EVENT_THROTTLE_STOP = 19,
  254. /* Hang detect logic detected a hang and host event timeout expired */
  255. EC_HOST_EVENT_HANG_DETECT = 20,
  256. /* Hang detect logic detected a hang and warm rebooted the AP */
  257. EC_HOST_EVENT_HANG_REBOOT = 21,
  258. /*
  259. * The high bit of the event mask is not used as a host event code. If
  260. * it reads back as set, then the entire event mask should be
  261. * considered invalid by the host. This can happen when reading the
  262. * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
  263. * not initialized on the EC, or improperly configured on the host.
  264. */
  265. EC_HOST_EVENT_INVALID = 32
  266. };
  267. /* Host event mask */
  268. #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
  269. /* Arguments at EC_LPC_ADDR_HOST_ARGS */
  270. struct ec_lpc_host_args {
  271. uint8_t flags;
  272. uint8_t command_version;
  273. uint8_t data_size;
  274. /*
  275. * Checksum; sum of command + flags + command_version + data_size +
  276. * all params/response data bytes.
  277. */
  278. uint8_t checksum;
  279. } __packed;
  280. /* Flags for ec_lpc_host_args.flags */
  281. /*
  282. * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
  283. * params.
  284. *
  285. * If EC gets a command and this flag is not set, this is an old-style command.
  286. * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
  287. * unknown length. EC must respond with an old-style response (that is,
  288. * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
  289. */
  290. #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
  291. /*
  292. * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
  293. *
  294. * If EC responds to a command and this flag is not set, this is an old-style
  295. * response. Command version is 0 and response data from EC is at
  296. * EC_LPC_ADDR_OLD_PARAM with unknown length.
  297. */
  298. #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
  299. /*****************************************************************************/
  300. /*
  301. * Byte codes returned by EC over SPI interface.
  302. *
  303. * These can be used by the AP to debug the EC interface, and to determine
  304. * when the EC is not in a state where it will ever get around to responding
  305. * to the AP.
  306. *
  307. * Example of sequence of bytes read from EC for a current good transfer:
  308. * 1. - - AP asserts chip select (CS#)
  309. * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
  310. * 3. - - EC starts handling CS# interrupt
  311. * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
  312. * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
  313. * bytes looking for EC_SPI_FRAME_START
  314. * 6. - - EC finishes processing and sets up response
  315. * 7. EC_SPI_FRAME_START - AP reads frame byte
  316. * 8. (response packet) - AP reads response packet
  317. * 9. EC_SPI_PAST_END - Any additional bytes read by AP
  318. * 10 - - AP deasserts chip select
  319. * 11 - - EC processes CS# interrupt and sets up DMA for
  320. * next request
  321. *
  322. * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
  323. * the following byte values:
  324. * EC_SPI_OLD_READY
  325. * EC_SPI_RX_READY
  326. * EC_SPI_RECEIVING
  327. * EC_SPI_PROCESSING
  328. *
  329. * Then the EC found an error in the request, or was not ready for the request
  330. * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
  331. * because the EC is unable to tell when the AP is done sending its request.
  332. */
  333. /*
  334. * Framing byte which precedes a response packet from the EC. After sending a
  335. * request, the AP will clock in bytes until it sees the framing byte, then
  336. * clock in the response packet.
  337. */
  338. #define EC_SPI_FRAME_START 0xec
  339. /*
  340. * Padding bytes which are clocked out after the end of a response packet.
  341. */
  342. #define EC_SPI_PAST_END 0xed
  343. /*
  344. * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
  345. * that the AP will send a valid packet header (starting with
  346. * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
  347. */
  348. #define EC_SPI_RX_READY 0xf8
  349. /*
  350. * EC has started receiving the request from the AP, but hasn't started
  351. * processing it yet.
  352. */
  353. #define EC_SPI_RECEIVING 0xf9
  354. /* EC has received the entire request from the AP and is processing it. */
  355. #define EC_SPI_PROCESSING 0xfa
  356. /*
  357. * EC received bad data from the AP, such as a packet header with an invalid
  358. * length. EC will ignore all data until chip select deasserts.
  359. */
  360. #define EC_SPI_RX_BAD_DATA 0xfb
  361. /*
  362. * EC received data from the AP before it was ready. That is, the AP asserted
  363. * chip select and started clocking data before the EC was ready to receive it.
  364. * EC will ignore all data until chip select deasserts.
  365. */
  366. #define EC_SPI_NOT_READY 0xfc
  367. /*
  368. * EC was ready to receive a request from the AP. EC has treated the byte sent
  369. * by the AP as part of a request packet, or (for old-style ECs) is processing
  370. * a fully received packet but is not ready to respond yet.
  371. */
  372. #define EC_SPI_OLD_READY 0xfd
  373. /*****************************************************************************/
  374. /*
  375. * Protocol version 2 for I2C and SPI send a request this way:
  376. *
  377. * 0 EC_CMD_VERSION0 + (command version)
  378. * 1 Command number
  379. * 2 Length of params = N
  380. * 3..N+2 Params, if any
  381. * N+3 8-bit checksum of bytes 0..N+2
  382. *
  383. * The corresponding response is:
  384. *
  385. * 0 Result code (EC_RES_*)
  386. * 1 Length of params = M
  387. * 2..M+1 Params, if any
  388. * M+2 8-bit checksum of bytes 0..M+1
  389. */
  390. #define EC_PROTO2_REQUEST_HEADER_BYTES 3
  391. #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
  392. #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
  393. EC_PROTO2_REQUEST_TRAILER_BYTES)
  394. #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
  395. #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
  396. #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
  397. EC_PROTO2_RESPONSE_TRAILER_BYTES)
  398. /* Parameter length was limited by the LPC interface */
  399. #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
  400. /* Maximum request and response packet sizes for protocol version 2 */
  401. #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
  402. EC_PROTO2_MAX_PARAM_SIZE)
  403. #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
  404. EC_PROTO2_MAX_PARAM_SIZE)
  405. /*****************************************************************************/
  406. /*
  407. * Value written to legacy command port / prefix byte to indicate protocol
  408. * 3+ structs are being used. Usage is bus-dependent.
  409. */
  410. #define EC_COMMAND_PROTOCOL_3 0xda
  411. #define EC_HOST_REQUEST_VERSION 3
  412. /* Version 3 request from host */
  413. struct ec_host_request {
  414. /* Struct version (=3)
  415. *
  416. * EC will return EC_RES_INVALID_HEADER if it receives a header with a
  417. * version it doesn't know how to parse.
  418. */
  419. uint8_t struct_version;
  420. /*
  421. * Checksum of request and data; sum of all bytes including checksum
  422. * should total to 0.
  423. */
  424. uint8_t checksum;
  425. /* Command code */
  426. uint16_t command;
  427. /* Command version */
  428. uint8_t command_version;
  429. /* Unused byte in current protocol version; set to 0 */
  430. uint8_t reserved;
  431. /* Length of data which follows this header */
  432. uint16_t data_len;
  433. } __packed;
  434. #define EC_HOST_RESPONSE_VERSION 3
  435. /* Version 3 response from EC */
  436. struct ec_host_response {
  437. /* Struct version (=3) */
  438. uint8_t struct_version;
  439. /*
  440. * Checksum of response and data; sum of all bytes including checksum
  441. * should total to 0.
  442. */
  443. uint8_t checksum;
  444. /* Result code (EC_RES_*) */
  445. uint16_t result;
  446. /* Length of data which follows this header */
  447. uint16_t data_len;
  448. /* Unused bytes in current protocol version; set to 0 */
  449. uint16_t reserved;
  450. } __packed;
  451. /*****************************************************************************/
  452. /*
  453. * Notes on commands:
  454. *
  455. * Each command is an 16-bit command value. Commands which take params or
  456. * return response data specify structs for that data. If no struct is
  457. * specified, the command does not input or output data, respectively.
  458. * Parameter/response length is implicit in the structs. Some underlying
  459. * communication protocols (I2C, SPI) may add length or checksum headers, but
  460. * those are implementation-dependent and not defined here.
  461. */
  462. /*****************************************************************************/
  463. /* General / test commands */
  464. /*
  465. * Get protocol version, used to deal with non-backward compatible protocol
  466. * changes.
  467. */
  468. #define EC_CMD_PROTO_VERSION 0x00
  469. struct ec_response_proto_version {
  470. uint32_t version;
  471. } __packed;
  472. /*
  473. * Hello. This is a simple command to test the EC is responsive to
  474. * commands.
  475. */
  476. #define EC_CMD_HELLO 0x01
  477. struct ec_params_hello {
  478. uint32_t in_data; /* Pass anything here */
  479. } __packed;
  480. struct ec_response_hello {
  481. uint32_t out_data; /* Output will be in_data + 0x01020304 */
  482. } __packed;
  483. /* Get version number */
  484. #define EC_CMD_GET_VERSION 0x02
  485. enum ec_current_image {
  486. EC_IMAGE_UNKNOWN = 0,
  487. EC_IMAGE_RO,
  488. EC_IMAGE_RW
  489. };
  490. struct ec_response_get_version {
  491. /* Null-terminated version strings for RO, RW */
  492. char version_string_ro[32];
  493. char version_string_rw[32];
  494. char reserved[32]; /* Was previously RW-B string */
  495. uint32_t current_image; /* One of ec_current_image */
  496. } __packed;
  497. /* Read test */
  498. #define EC_CMD_READ_TEST 0x03
  499. struct ec_params_read_test {
  500. uint32_t offset; /* Starting value for read buffer */
  501. uint32_t size; /* Size to read in bytes */
  502. } __packed;
  503. struct ec_response_read_test {
  504. uint32_t data[32];
  505. } __packed;
  506. /*
  507. * Get build information
  508. *
  509. * Response is null-terminated string.
  510. */
  511. #define EC_CMD_GET_BUILD_INFO 0x04
  512. /* Get chip info */
  513. #define EC_CMD_GET_CHIP_INFO 0x05
  514. struct ec_response_get_chip_info {
  515. /* Null-terminated strings */
  516. char vendor[32];
  517. char name[32];
  518. char revision[32]; /* Mask version */
  519. } __packed;
  520. /* Get board HW version */
  521. #define EC_CMD_GET_BOARD_VERSION 0x06
  522. struct ec_response_board_version {
  523. uint16_t board_version; /* A monotonously incrementing number. */
  524. } __packed;
  525. /*
  526. * Read memory-mapped data.
  527. *
  528. * This is an alternate interface to memory-mapped data for bus protocols
  529. * which don't support direct-mapped memory - I2C, SPI, etc.
  530. *
  531. * Response is params.size bytes of data.
  532. */
  533. #define EC_CMD_READ_MEMMAP 0x07
  534. struct ec_params_read_memmap {
  535. uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
  536. uint8_t size; /* Size to read in bytes */
  537. } __packed;
  538. /* Read versions supported for a command */
  539. #define EC_CMD_GET_CMD_VERSIONS 0x08
  540. struct ec_params_get_cmd_versions {
  541. uint8_t cmd; /* Command to check */
  542. } __packed;
  543. struct ec_response_get_cmd_versions {
  544. /*
  545. * Mask of supported versions; use EC_VER_MASK() to compare with a
  546. * desired version.
  547. */
  548. uint32_t version_mask;
  549. } __packed;
  550. /*
  551. * Check EC communcations status (busy). This is needed on i2c/spi but not
  552. * on lpc since it has its own out-of-band busy indicator.
  553. *
  554. * lpc must read the status from the command register. Attempting this on
  555. * lpc will overwrite the args/parameter space and corrupt its data.
  556. */
  557. #define EC_CMD_GET_COMMS_STATUS 0x09
  558. /* Avoid using ec_status which is for return values */
  559. enum ec_comms_status {
  560. EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
  561. };
  562. struct ec_response_get_comms_status {
  563. uint32_t flags; /* Mask of enum ec_comms_status */
  564. } __packed;
  565. /* Fake a variety of responses, purely for testing purposes. */
  566. #define EC_CMD_TEST_PROTOCOL 0x0a
  567. /* Tell the EC what to send back to us. */
  568. struct ec_params_test_protocol {
  569. uint32_t ec_result;
  570. uint32_t ret_len;
  571. uint8_t buf[32];
  572. } __packed;
  573. /* Here it comes... */
  574. struct ec_response_test_protocol {
  575. uint8_t buf[32];
  576. } __packed;
  577. /* Get prococol information */
  578. #define EC_CMD_GET_PROTOCOL_INFO 0x0b
  579. /* Flags for ec_response_get_protocol_info.flags */
  580. /* EC_RES_IN_PROGRESS may be returned if a command is slow */
  581. #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
  582. struct ec_response_get_protocol_info {
  583. /* Fields which exist if at least protocol version 3 supported */
  584. /* Bitmask of protocol versions supported (1 << n means version n)*/
  585. uint32_t protocol_versions;
  586. /* Maximum request packet size, in bytes */
  587. uint16_t max_request_packet_size;
  588. /* Maximum response packet size, in bytes */
  589. uint16_t max_response_packet_size;
  590. /* Flags; see EC_PROTOCOL_INFO_* */
  591. uint32_t flags;
  592. } __packed;
  593. /*****************************************************************************/
  594. /* Get/Set miscellaneous values */
  595. /* The upper byte of .flags tells what to do (nothing means "get") */
  596. #define EC_GSV_SET 0x80000000
  597. /* The lower three bytes of .flags identifies the parameter, if that has
  598. meaning for an individual command. */
  599. #define EC_GSV_PARAM_MASK 0x00ffffff
  600. struct ec_params_get_set_value {
  601. uint32_t flags;
  602. uint32_t value;
  603. } __packed;
  604. struct ec_response_get_set_value {
  605. uint32_t flags;
  606. uint32_t value;
  607. } __packed;
  608. /* More than one command can use these structs to get/set paramters. */
  609. #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
  610. /*****************************************************************************/
  611. /* Flash commands */
  612. /* Get flash info */
  613. #define EC_CMD_FLASH_INFO 0x10
  614. /* Version 0 returns these fields */
  615. struct ec_response_flash_info {
  616. /* Usable flash size, in bytes */
  617. uint32_t flash_size;
  618. /*
  619. * Write block size. Write offset and size must be a multiple
  620. * of this.
  621. */
  622. uint32_t write_block_size;
  623. /*
  624. * Erase block size. Erase offset and size must be a multiple
  625. * of this.
  626. */
  627. uint32_t erase_block_size;
  628. /*
  629. * Protection block size. Protection offset and size must be a
  630. * multiple of this.
  631. */
  632. uint32_t protect_block_size;
  633. } __packed;
  634. /* Flags for version 1+ flash info command */
  635. /* EC flash erases bits to 0 instead of 1 */
  636. #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
  637. /*
  638. * Version 1 returns the same initial fields as version 0, with additional
  639. * fields following.
  640. *
  641. * gcc anonymous structs don't seem to get along with the __packed directive;
  642. * if they did we'd define the version 0 struct as a sub-struct of this one.
  643. */
  644. struct ec_response_flash_info_1 {
  645. /* Version 0 fields; see above for description */
  646. uint32_t flash_size;
  647. uint32_t write_block_size;
  648. uint32_t erase_block_size;
  649. uint32_t protect_block_size;
  650. /* Version 1 adds these fields: */
  651. /*
  652. * Ideal write size in bytes. Writes will be fastest if size is
  653. * exactly this and offset is a multiple of this. For example, an EC
  654. * may have a write buffer which can do half-page operations if data is
  655. * aligned, and a slower word-at-a-time write mode.
  656. */
  657. uint32_t write_ideal_size;
  658. /* Flags; see EC_FLASH_INFO_* */
  659. uint32_t flags;
  660. } __packed;
  661. /*
  662. * Read flash
  663. *
  664. * Response is params.size bytes of data.
  665. */
  666. #define EC_CMD_FLASH_READ 0x11
  667. struct ec_params_flash_read {
  668. uint32_t offset; /* Byte offset to read */
  669. uint32_t size; /* Size to read in bytes */
  670. } __packed;
  671. /* Write flash */
  672. #define EC_CMD_FLASH_WRITE 0x12
  673. #define EC_VER_FLASH_WRITE 1
  674. /* Version 0 of the flash command supported only 64 bytes of data */
  675. #define EC_FLASH_WRITE_VER0_SIZE 64
  676. struct ec_params_flash_write {
  677. uint32_t offset; /* Byte offset to write */
  678. uint32_t size; /* Size to write in bytes */
  679. /* Followed by data to write */
  680. } __packed;
  681. /* Erase flash */
  682. #define EC_CMD_FLASH_ERASE 0x13
  683. struct ec_params_flash_erase {
  684. uint32_t offset; /* Byte offset to erase */
  685. uint32_t size; /* Size to erase in bytes */
  686. } __packed;
  687. /*
  688. * Get/set flash protection.
  689. *
  690. * If mask!=0, sets/clear the requested bits of flags. Depending on the
  691. * firmware write protect GPIO, not all flags will take effect immediately;
  692. * some flags require a subsequent hard reset to take effect. Check the
  693. * returned flags bits to see what actually happened.
  694. *
  695. * If mask=0, simply returns the current flags state.
  696. */
  697. #define EC_CMD_FLASH_PROTECT 0x15
  698. #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
  699. /* Flags for flash protection */
  700. /* RO flash code protected when the EC boots */
  701. #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
  702. /*
  703. * RO flash code protected now. If this bit is set, at-boot status cannot
  704. * be changed.
  705. */
  706. #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
  707. /* Entire flash code protected now, until reboot. */
  708. #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
  709. /* Flash write protect GPIO is asserted now */
  710. #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
  711. /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
  712. #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
  713. /*
  714. * Error - flash protection is in inconsistent state. At least one bank of
  715. * flash which should be protected is not protected. Usually fixed by
  716. * re-requesting the desired flags, or by a hard reset if that fails.
  717. */
  718. #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
  719. /* Entile flash code protected when the EC boots */
  720. #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
  721. struct ec_params_flash_protect {
  722. uint32_t mask; /* Bits in flags to apply */
  723. uint32_t flags; /* New flags to apply */
  724. } __packed;
  725. struct ec_response_flash_protect {
  726. /* Current value of flash protect flags */
  727. uint32_t flags;
  728. /*
  729. * Flags which are valid on this platform. This allows the caller
  730. * to distinguish between flags which aren't set vs. flags which can't
  731. * be set on this platform.
  732. */
  733. uint32_t valid_flags;
  734. /* Flags which can be changed given the current protection state */
  735. uint32_t writable_flags;
  736. } __packed;
  737. /*
  738. * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
  739. * write protect. These commands may be reused with version > 0.
  740. */
  741. /* Get the region offset/size */
  742. #define EC_CMD_FLASH_REGION_INFO 0x16
  743. #define EC_VER_FLASH_REGION_INFO 1
  744. enum ec_flash_region {
  745. /* Region which holds read-only EC image */
  746. EC_FLASH_REGION_RO = 0,
  747. /* Region which holds rewritable EC image */
  748. EC_FLASH_REGION_RW,
  749. /*
  750. * Region which should be write-protected in the factory (a superset of
  751. * EC_FLASH_REGION_RO)
  752. */
  753. EC_FLASH_REGION_WP_RO,
  754. /* Number of regions */
  755. EC_FLASH_REGION_COUNT,
  756. };
  757. struct ec_params_flash_region_info {
  758. uint32_t region; /* enum ec_flash_region */
  759. } __packed;
  760. struct ec_response_flash_region_info {
  761. uint32_t offset;
  762. uint32_t size;
  763. } __packed;
  764. /* Read/write VbNvContext */
  765. #define EC_CMD_VBNV_CONTEXT 0x17
  766. #define EC_VER_VBNV_CONTEXT 1
  767. #define EC_VBNV_BLOCK_SIZE 16
  768. enum ec_vbnvcontext_op {
  769. EC_VBNV_CONTEXT_OP_READ,
  770. EC_VBNV_CONTEXT_OP_WRITE,
  771. };
  772. struct ec_params_vbnvcontext {
  773. uint32_t op;
  774. uint8_t block[EC_VBNV_BLOCK_SIZE];
  775. } __packed;
  776. struct ec_response_vbnvcontext {
  777. uint8_t block[EC_VBNV_BLOCK_SIZE];
  778. } __packed;
  779. /*****************************************************************************/
  780. /* PWM commands */
  781. /* Get fan target RPM */
  782. #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
  783. struct ec_response_pwm_get_fan_rpm {
  784. uint32_t rpm;
  785. } __packed;
  786. /* Set target fan RPM */
  787. #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
  788. struct ec_params_pwm_set_fan_target_rpm {
  789. uint32_t rpm;
  790. } __packed;
  791. /* Get keyboard backlight */
  792. #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
  793. struct ec_response_pwm_get_keyboard_backlight {
  794. uint8_t percent;
  795. uint8_t enabled;
  796. } __packed;
  797. /* Set keyboard backlight */
  798. #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
  799. struct ec_params_pwm_set_keyboard_backlight {
  800. uint8_t percent;
  801. } __packed;
  802. /* Set target fan PWM duty cycle */
  803. #define EC_CMD_PWM_SET_FAN_DUTY 0x24
  804. struct ec_params_pwm_set_fan_duty {
  805. uint32_t percent;
  806. } __packed;
  807. #define EC_CMD_PWM_SET_DUTY 0x25
  808. /* 16 bit duty cycle, 0xffff = 100% */
  809. #define EC_PWM_MAX_DUTY 0xffff
  810. enum ec_pwm_type {
  811. /* All types, indexed by board-specific enum pwm_channel */
  812. EC_PWM_TYPE_GENERIC = 0,
  813. /* Keyboard backlight */
  814. EC_PWM_TYPE_KB_LIGHT,
  815. /* Display backlight */
  816. EC_PWM_TYPE_DISPLAY_LIGHT,
  817. EC_PWM_TYPE_COUNT,
  818. };
  819. struct ec_params_pwm_set_duty {
  820. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  821. uint8_t pwm_type; /* ec_pwm_type */
  822. uint8_t index; /* Type-specific index, or 0 if unique */
  823. } __packed;
  824. #define EC_CMD_PWM_GET_DUTY 0x26
  825. struct ec_params_pwm_get_duty {
  826. uint8_t pwm_type; /* ec_pwm_type */
  827. uint8_t index; /* Type-specific index, or 0 if unique */
  828. } __packed;
  829. struct ec_response_pwm_get_duty {
  830. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  831. } __packed;
  832. /*****************************************************************************/
  833. /*
  834. * Lightbar commands. This looks worse than it is. Since we only use one HOST
  835. * command to say "talk to the lightbar", we put the "and tell it to do X" part
  836. * into a subcommand. We'll make separate structs for subcommands with
  837. * different input args, so that we know how much to expect.
  838. */
  839. #define EC_CMD_LIGHTBAR_CMD 0x28
  840. struct rgb_s {
  841. uint8_t r, g, b;
  842. };
  843. #define LB_BATTERY_LEVELS 4
  844. /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
  845. * host command, but the alignment is the same regardless. Keep it that way.
  846. */
  847. struct lightbar_params_v0 {
  848. /* Timing */
  849. int32_t google_ramp_up;
  850. int32_t google_ramp_down;
  851. int32_t s3s0_ramp_up;
  852. int32_t s0_tick_delay[2]; /* AC=0/1 */
  853. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  854. int32_t s0s3_ramp_down;
  855. int32_t s3_sleep_for;
  856. int32_t s3_ramp_up;
  857. int32_t s3_ramp_down;
  858. /* Oscillation */
  859. uint8_t new_s0;
  860. uint8_t osc_min[2]; /* AC=0/1 */
  861. uint8_t osc_max[2]; /* AC=0/1 */
  862. uint8_t w_ofs[2]; /* AC=0/1 */
  863. /* Brightness limits based on the backlight and AC. */
  864. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  865. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  866. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  867. /* Battery level thresholds */
  868. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  869. /* Map [AC][battery_level] to color index */
  870. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  871. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  872. /* Color palette */
  873. struct rgb_s color[8]; /* 0-3 are Google colors */
  874. } __packed;
  875. struct lightbar_params_v1 {
  876. /* Timing */
  877. int32_t google_ramp_up;
  878. int32_t google_ramp_down;
  879. int32_t s3s0_ramp_up;
  880. int32_t s0_tick_delay[2]; /* AC=0/1 */
  881. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  882. int32_t s0s3_ramp_down;
  883. int32_t s3_sleep_for;
  884. int32_t s3_ramp_up;
  885. int32_t s3_ramp_down;
  886. int32_t tap_tick_delay;
  887. int32_t tap_display_time;
  888. /* Tap-for-battery params */
  889. uint8_t tap_pct_red;
  890. uint8_t tap_pct_green;
  891. uint8_t tap_seg_min_on;
  892. uint8_t tap_seg_max_on;
  893. uint8_t tap_seg_osc;
  894. uint8_t tap_idx[3];
  895. /* Oscillation */
  896. uint8_t osc_min[2]; /* AC=0/1 */
  897. uint8_t osc_max[2]; /* AC=0/1 */
  898. uint8_t w_ofs[2]; /* AC=0/1 */
  899. /* Brightness limits based on the backlight and AC. */
  900. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  901. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  902. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  903. /* Battery level thresholds */
  904. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  905. /* Map [AC][battery_level] to color index */
  906. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  907. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  908. /* Color palette */
  909. struct rgb_s color[8]; /* 0-3 are Google colors */
  910. } __packed;
  911. struct ec_params_lightbar {
  912. uint8_t cmd; /* Command (see enum lightbar_command) */
  913. union {
  914. struct {
  915. /* no args */
  916. } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
  917. version, get_brightness, get_demo;
  918. struct {
  919. uint8_t num;
  920. } set_brightness, seq, demo;
  921. struct {
  922. uint8_t ctrl, reg, value;
  923. } reg;
  924. struct {
  925. uint8_t led, red, green, blue;
  926. } set_rgb;
  927. struct {
  928. uint8_t led;
  929. } get_rgb;
  930. struct lightbar_params_v0 set_params_v0;
  931. struct lightbar_params_v1 set_params_v1;
  932. };
  933. } __packed;
  934. struct ec_response_lightbar {
  935. union {
  936. struct {
  937. struct {
  938. uint8_t reg;
  939. uint8_t ic0;
  940. uint8_t ic1;
  941. } vals[23];
  942. } dump;
  943. struct {
  944. uint8_t num;
  945. } get_seq, get_brightness, get_demo;
  946. struct lightbar_params_v0 get_params_v0;
  947. struct lightbar_params_v1 get_params_v1;
  948. struct {
  949. uint32_t num;
  950. uint32_t flags;
  951. } version;
  952. struct {
  953. uint8_t red, green, blue;
  954. } get_rgb;
  955. struct {
  956. /* no return params */
  957. } off, on, init, set_brightness, seq, reg, set_rgb,
  958. demo, set_params_v0, set_params_v1;
  959. };
  960. } __packed;
  961. /* Lightbar commands */
  962. enum lightbar_command {
  963. LIGHTBAR_CMD_DUMP = 0,
  964. LIGHTBAR_CMD_OFF = 1,
  965. LIGHTBAR_CMD_ON = 2,
  966. LIGHTBAR_CMD_INIT = 3,
  967. LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
  968. LIGHTBAR_CMD_SEQ = 5,
  969. LIGHTBAR_CMD_REG = 6,
  970. LIGHTBAR_CMD_SET_RGB = 7,
  971. LIGHTBAR_CMD_GET_SEQ = 8,
  972. LIGHTBAR_CMD_DEMO = 9,
  973. LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
  974. LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
  975. LIGHTBAR_CMD_VERSION = 12,
  976. LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
  977. LIGHTBAR_CMD_GET_RGB = 14,
  978. LIGHTBAR_CMD_GET_DEMO = 15,
  979. LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
  980. LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
  981. LIGHTBAR_NUM_CMDS
  982. };
  983. /*****************************************************************************/
  984. /* LED control commands */
  985. #define EC_CMD_LED_CONTROL 0x29
  986. enum ec_led_id {
  987. /* LED to indicate battery state of charge */
  988. EC_LED_ID_BATTERY_LED = 0,
  989. /*
  990. * LED to indicate system power state (on or in suspend).
  991. * May be on power button or on C-panel.
  992. */
  993. EC_LED_ID_POWER_LED,
  994. /* LED on power adapter or its plug */
  995. EC_LED_ID_ADAPTER_LED,
  996. EC_LED_ID_COUNT
  997. };
  998. /* LED control flags */
  999. #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
  1000. #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
  1001. enum ec_led_colors {
  1002. EC_LED_COLOR_RED = 0,
  1003. EC_LED_COLOR_GREEN,
  1004. EC_LED_COLOR_BLUE,
  1005. EC_LED_COLOR_YELLOW,
  1006. EC_LED_COLOR_WHITE,
  1007. EC_LED_COLOR_COUNT
  1008. };
  1009. struct ec_params_led_control {
  1010. uint8_t led_id; /* Which LED to control */
  1011. uint8_t flags; /* Control flags */
  1012. uint8_t brightness[EC_LED_COLOR_COUNT];
  1013. } __packed;
  1014. struct ec_response_led_control {
  1015. /*
  1016. * Available brightness value range.
  1017. *
  1018. * Range 0 means color channel not present.
  1019. * Range 1 means on/off control.
  1020. * Other values means the LED is control by PWM.
  1021. */
  1022. uint8_t brightness_range[EC_LED_COLOR_COUNT];
  1023. } __packed;
  1024. /*****************************************************************************/
  1025. /* Verified boot commands */
  1026. /*
  1027. * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
  1028. * reused for other purposes with version > 0.
  1029. */
  1030. /* Verified boot hash command */
  1031. #define EC_CMD_VBOOT_HASH 0x2A
  1032. struct ec_params_vboot_hash {
  1033. uint8_t cmd; /* enum ec_vboot_hash_cmd */
  1034. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1035. uint8_t nonce_size; /* Nonce size; may be 0 */
  1036. uint8_t reserved0; /* Reserved; set 0 */
  1037. uint32_t offset; /* Offset in flash to hash */
  1038. uint32_t size; /* Number of bytes to hash */
  1039. uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
  1040. } __packed;
  1041. struct ec_response_vboot_hash {
  1042. uint8_t status; /* enum ec_vboot_hash_status */
  1043. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1044. uint8_t digest_size; /* Size of hash digest in bytes */
  1045. uint8_t reserved0; /* Ignore; will be 0 */
  1046. uint32_t offset; /* Offset in flash which was hashed */
  1047. uint32_t size; /* Number of bytes hashed */
  1048. uint8_t hash_digest[64]; /* Hash digest data */
  1049. } __packed;
  1050. enum ec_vboot_hash_cmd {
  1051. EC_VBOOT_HASH_GET = 0, /* Get current hash status */
  1052. EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
  1053. EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
  1054. EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
  1055. };
  1056. enum ec_vboot_hash_type {
  1057. EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
  1058. };
  1059. enum ec_vboot_hash_status {
  1060. EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
  1061. EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
  1062. EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
  1063. };
  1064. /*
  1065. * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
  1066. * If one of these is specified, the EC will automatically update offset and
  1067. * size to the correct values for the specified image (RO or RW).
  1068. */
  1069. #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
  1070. #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
  1071. /*****************************************************************************/
  1072. /*
  1073. * Motion sense commands. We'll make separate structs for sub-commands with
  1074. * different input args, so that we know how much to expect.
  1075. */
  1076. #define EC_CMD_MOTION_SENSE_CMD 0x2B
  1077. /* Motion sense commands */
  1078. enum motionsense_command {
  1079. /*
  1080. * Dump command returns all motion sensor data including motion sense
  1081. * module flags and individual sensor flags.
  1082. */
  1083. MOTIONSENSE_CMD_DUMP = 0,
  1084. /*
  1085. * Info command returns data describing the details of a given sensor,
  1086. * including enum motionsensor_type, enum motionsensor_location, and
  1087. * enum motionsensor_chip.
  1088. */
  1089. MOTIONSENSE_CMD_INFO = 1,
  1090. /*
  1091. * EC Rate command is a setter/getter command for the EC sampling rate
  1092. * of all motion sensors in milliseconds.
  1093. */
  1094. MOTIONSENSE_CMD_EC_RATE = 2,
  1095. /*
  1096. * Sensor ODR command is a setter/getter command for the output data
  1097. * rate of a specific motion sensor in millihertz.
  1098. */
  1099. MOTIONSENSE_CMD_SENSOR_ODR = 3,
  1100. /*
  1101. * Sensor range command is a setter/getter command for the range of
  1102. * a specified motion sensor in +/-G's or +/- deg/s.
  1103. */
  1104. MOTIONSENSE_CMD_SENSOR_RANGE = 4,
  1105. /*
  1106. * Setter/getter command for the keyboard wake angle. When the lid
  1107. * angle is greater than this value, keyboard wake is disabled in S3,
  1108. * and when the lid angle goes less than this value, keyboard wake is
  1109. * enabled. Note, the lid angle measurement is an approximate,
  1110. * un-calibrated value, hence the wake angle isn't exact.
  1111. */
  1112. MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
  1113. /* Number of motionsense sub-commands. */
  1114. MOTIONSENSE_NUM_CMDS
  1115. };
  1116. enum motionsensor_id {
  1117. EC_MOTION_SENSOR_ACCEL_BASE = 0,
  1118. EC_MOTION_SENSOR_ACCEL_LID = 1,
  1119. EC_MOTION_SENSOR_GYRO = 2,
  1120. /*
  1121. * Note, if more sensors are added and this count changes, the padding
  1122. * in ec_response_motion_sense dump command must be modified.
  1123. */
  1124. EC_MOTION_SENSOR_COUNT = 3
  1125. };
  1126. /* List of motion sensor types. */
  1127. enum motionsensor_type {
  1128. MOTIONSENSE_TYPE_ACCEL = 0,
  1129. MOTIONSENSE_TYPE_GYRO = 1,
  1130. };
  1131. /* List of motion sensor locations. */
  1132. enum motionsensor_location {
  1133. MOTIONSENSE_LOC_BASE = 0,
  1134. MOTIONSENSE_LOC_LID = 1,
  1135. };
  1136. /* List of motion sensor chips. */
  1137. enum motionsensor_chip {
  1138. MOTIONSENSE_CHIP_KXCJ9 = 0,
  1139. };
  1140. /* Module flag masks used for the dump sub-command. */
  1141. #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
  1142. /* Sensor flag masks used for the dump sub-command. */
  1143. #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
  1144. /*
  1145. * Send this value for the data element to only perform a read. If you
  1146. * send any other value, the EC will interpret it as data to set and will
  1147. * return the actual value set.
  1148. */
  1149. #define EC_MOTION_SENSE_NO_VALUE -1
  1150. struct ec_params_motion_sense {
  1151. uint8_t cmd;
  1152. union {
  1153. /* Used for MOTIONSENSE_CMD_DUMP. */
  1154. struct {
  1155. /* no args */
  1156. } dump;
  1157. /*
  1158. * Used for MOTIONSENSE_CMD_EC_RATE and
  1159. * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
  1160. */
  1161. struct {
  1162. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
  1163. int16_t data;
  1164. } ec_rate, kb_wake_angle;
  1165. /* Used for MOTIONSENSE_CMD_INFO. */
  1166. struct {
  1167. /* Should be element of enum motionsensor_id. */
  1168. uint8_t sensor_num;
  1169. } info;
  1170. /*
  1171. * Used for MOTIONSENSE_CMD_SENSOR_ODR and
  1172. * MOTIONSENSE_CMD_SENSOR_RANGE.
  1173. */
  1174. struct {
  1175. /* Should be element of enum motionsensor_id. */
  1176. uint8_t sensor_num;
  1177. /* Rounding flag, true for round-up, false for down. */
  1178. uint8_t roundup;
  1179. uint16_t reserved;
  1180. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
  1181. int32_t data;
  1182. } sensor_odr, sensor_range;
  1183. };
  1184. } __packed;
  1185. struct ec_response_motion_sense {
  1186. union {
  1187. /* Used for MOTIONSENSE_CMD_DUMP. */
  1188. struct {
  1189. /* Flags representing the motion sensor module. */
  1190. uint8_t module_flags;
  1191. /* Flags for each sensor in enum motionsensor_id. */
  1192. uint8_t sensor_flags[EC_MOTION_SENSOR_COUNT];
  1193. /* Array of all sensor data. Each sensor is 3-axis. */
  1194. int16_t data[3*EC_MOTION_SENSOR_COUNT];
  1195. } dump;
  1196. /* Used for MOTIONSENSE_CMD_INFO. */
  1197. struct {
  1198. /* Should be element of enum motionsensor_type. */
  1199. uint8_t type;
  1200. /* Should be element of enum motionsensor_location. */
  1201. uint8_t location;
  1202. /* Should be element of enum motionsensor_chip. */
  1203. uint8_t chip;
  1204. } info;
  1205. /*
  1206. * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
  1207. * MOTIONSENSE_CMD_SENSOR_RANGE, and
  1208. * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
  1209. */
  1210. struct {
  1211. /* Current value of the parameter queried. */
  1212. int32_t ret;
  1213. } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
  1214. };
  1215. } __packed;
  1216. /*****************************************************************************/
  1217. /* USB charging control commands */
  1218. /* Set USB port charging mode */
  1219. #define EC_CMD_USB_CHARGE_SET_MODE 0x30
  1220. struct ec_params_usb_charge_set_mode {
  1221. uint8_t usb_port_id;
  1222. uint8_t mode;
  1223. } __packed;
  1224. /*****************************************************************************/
  1225. /* Persistent storage for host */
  1226. /* Maximum bytes that can be read/written in a single command */
  1227. #define EC_PSTORE_SIZE_MAX 64
  1228. /* Get persistent storage info */
  1229. #define EC_CMD_PSTORE_INFO 0x40
  1230. struct ec_response_pstore_info {
  1231. /* Persistent storage size, in bytes */
  1232. uint32_t pstore_size;
  1233. /* Access size; read/write offset and size must be a multiple of this */
  1234. uint32_t access_size;
  1235. } __packed;
  1236. /*
  1237. * Read persistent storage
  1238. *
  1239. * Response is params.size bytes of data.
  1240. */
  1241. #define EC_CMD_PSTORE_READ 0x41
  1242. struct ec_params_pstore_read {
  1243. uint32_t offset; /* Byte offset to read */
  1244. uint32_t size; /* Size to read in bytes */
  1245. } __packed;
  1246. /* Write persistent storage */
  1247. #define EC_CMD_PSTORE_WRITE 0x42
  1248. struct ec_params_pstore_write {
  1249. uint32_t offset; /* Byte offset to write */
  1250. uint32_t size; /* Size to write in bytes */
  1251. uint8_t data[EC_PSTORE_SIZE_MAX];
  1252. } __packed;
  1253. /*****************************************************************************/
  1254. /* Real-time clock */
  1255. /* RTC params and response structures */
  1256. struct ec_params_rtc {
  1257. uint32_t time;
  1258. } __packed;
  1259. struct ec_response_rtc {
  1260. uint32_t time;
  1261. } __packed;
  1262. /* These use ec_response_rtc */
  1263. #define EC_CMD_RTC_GET_VALUE 0x44
  1264. #define EC_CMD_RTC_GET_ALARM 0x45
  1265. /* These all use ec_params_rtc */
  1266. #define EC_CMD_RTC_SET_VALUE 0x46
  1267. #define EC_CMD_RTC_SET_ALARM 0x47
  1268. /*****************************************************************************/
  1269. /* Port80 log access */
  1270. /* Maximum entries that can be read/written in a single command */
  1271. #define EC_PORT80_SIZE_MAX 32
  1272. /* Get last port80 code from previous boot */
  1273. #define EC_CMD_PORT80_LAST_BOOT 0x48
  1274. #define EC_CMD_PORT80_READ 0x48
  1275. enum ec_port80_subcmd {
  1276. EC_PORT80_GET_INFO = 0,
  1277. EC_PORT80_READ_BUFFER,
  1278. };
  1279. struct ec_params_port80_read {
  1280. uint16_t subcmd;
  1281. union {
  1282. struct {
  1283. uint32_t offset;
  1284. uint32_t num_entries;
  1285. } read_buffer;
  1286. };
  1287. } __packed;
  1288. struct ec_response_port80_read {
  1289. union {
  1290. struct {
  1291. uint32_t writes;
  1292. uint32_t history_size;
  1293. uint32_t last_boot;
  1294. } get_info;
  1295. struct {
  1296. uint16_t codes[EC_PORT80_SIZE_MAX];
  1297. } data;
  1298. };
  1299. } __packed;
  1300. struct ec_response_port80_last_boot {
  1301. uint16_t code;
  1302. } __packed;
  1303. /*****************************************************************************/
  1304. /* Thermal engine commands. Note that there are two implementations. We'll
  1305. * reuse the command number, but the data and behavior is incompatible.
  1306. * Version 0 is what originally shipped on Link.
  1307. * Version 1 separates the CPU thermal limits from the fan control.
  1308. */
  1309. #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
  1310. #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
  1311. /* The version 0 structs are opaque. You have to know what they are for
  1312. * the get/set commands to make any sense.
  1313. */
  1314. /* Version 0 - set */
  1315. struct ec_params_thermal_set_threshold {
  1316. uint8_t sensor_type;
  1317. uint8_t threshold_id;
  1318. uint16_t value;
  1319. } __packed;
  1320. /* Version 0 - get */
  1321. struct ec_params_thermal_get_threshold {
  1322. uint8_t sensor_type;
  1323. uint8_t threshold_id;
  1324. } __packed;
  1325. struct ec_response_thermal_get_threshold {
  1326. uint16_t value;
  1327. } __packed;
  1328. /* The version 1 structs are visible. */
  1329. enum ec_temp_thresholds {
  1330. EC_TEMP_THRESH_WARN = 0,
  1331. EC_TEMP_THRESH_HIGH,
  1332. EC_TEMP_THRESH_HALT,
  1333. EC_TEMP_THRESH_COUNT
  1334. };
  1335. /* Thermal configuration for one temperature sensor. Temps are in degrees K.
  1336. * Zero values will be silently ignored by the thermal task.
  1337. */
  1338. struct ec_thermal_config {
  1339. uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
  1340. uint32_t temp_fan_off; /* no active cooling needed */
  1341. uint32_t temp_fan_max; /* max active cooling needed */
  1342. } __packed;
  1343. /* Version 1 - get config for one sensor. */
  1344. struct ec_params_thermal_get_threshold_v1 {
  1345. uint32_t sensor_num;
  1346. } __packed;
  1347. /* This returns a struct ec_thermal_config */
  1348. /* Version 1 - set config for one sensor.
  1349. * Use read-modify-write for best results! */
  1350. struct ec_params_thermal_set_threshold_v1 {
  1351. uint32_t sensor_num;
  1352. struct ec_thermal_config cfg;
  1353. } __packed;
  1354. /* This returns no data */
  1355. /****************************************************************************/
  1356. /* Toggle automatic fan control */
  1357. #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
  1358. /* Get TMP006 calibration data */
  1359. #define EC_CMD_TMP006_GET_CALIBRATION 0x53
  1360. struct ec_params_tmp006_get_calibration {
  1361. uint8_t index;
  1362. } __packed;
  1363. struct ec_response_tmp006_get_calibration {
  1364. float s0;
  1365. float b0;
  1366. float b1;
  1367. float b2;
  1368. } __packed;
  1369. /* Set TMP006 calibration data */
  1370. #define EC_CMD_TMP006_SET_CALIBRATION 0x54
  1371. struct ec_params_tmp006_set_calibration {
  1372. uint8_t index;
  1373. uint8_t reserved[3]; /* Reserved; set 0 */
  1374. float s0;
  1375. float b0;
  1376. float b1;
  1377. float b2;
  1378. } __packed;
  1379. /* Read raw TMP006 data */
  1380. #define EC_CMD_TMP006_GET_RAW 0x55
  1381. struct ec_params_tmp006_get_raw {
  1382. uint8_t index;
  1383. } __packed;
  1384. struct ec_response_tmp006_get_raw {
  1385. int32_t t; /* In 1/100 K */
  1386. int32_t v; /* In nV */
  1387. };
  1388. /*****************************************************************************/
  1389. /* MKBP - Matrix KeyBoard Protocol */
  1390. /*
  1391. * Read key state
  1392. *
  1393. * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
  1394. * expected response size.
  1395. */
  1396. #define EC_CMD_MKBP_STATE 0x60
  1397. /* Provide information about the matrix : number of rows and columns */
  1398. #define EC_CMD_MKBP_INFO 0x61
  1399. struct ec_response_mkbp_info {
  1400. uint32_t rows;
  1401. uint32_t cols;
  1402. uint8_t switches;
  1403. } __packed;
  1404. /* Simulate key press */
  1405. #define EC_CMD_MKBP_SIMULATE_KEY 0x62
  1406. struct ec_params_mkbp_simulate_key {
  1407. uint8_t col;
  1408. uint8_t row;
  1409. uint8_t pressed;
  1410. } __packed;
  1411. /* Configure keyboard scanning */
  1412. #define EC_CMD_MKBP_SET_CONFIG 0x64
  1413. #define EC_CMD_MKBP_GET_CONFIG 0x65
  1414. /* flags */
  1415. enum mkbp_config_flags {
  1416. EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
  1417. };
  1418. enum mkbp_config_valid {
  1419. EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
  1420. EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
  1421. EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
  1422. EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
  1423. EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
  1424. EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
  1425. EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
  1426. };
  1427. /* Configuration for our key scanning algorithm */
  1428. struct ec_mkbp_config {
  1429. uint32_t valid_mask; /* valid fields */
  1430. uint8_t flags; /* some flags (enum mkbp_config_flags) */
  1431. uint8_t valid_flags; /* which flags are valid */
  1432. uint16_t scan_period_us; /* period between start of scans */
  1433. /* revert to interrupt mode after no activity for this long */
  1434. uint32_t poll_timeout_us;
  1435. /*
  1436. * minimum post-scan relax time. Once we finish a scan we check
  1437. * the time until we are due to start the next one. If this time is
  1438. * shorter this field, we use this instead.
  1439. */
  1440. uint16_t min_post_scan_delay_us;
  1441. /* delay between setting up output and waiting for it to settle */
  1442. uint16_t output_settle_us;
  1443. uint16_t debounce_down_us; /* time for debounce on key down */
  1444. uint16_t debounce_up_us; /* time for debounce on key up */
  1445. /* maximum depth to allow for fifo (0 = no keyscan output) */
  1446. uint8_t fifo_max_depth;
  1447. } __packed;
  1448. struct ec_params_mkbp_set_config {
  1449. struct ec_mkbp_config config;
  1450. } __packed;
  1451. struct ec_response_mkbp_get_config {
  1452. struct ec_mkbp_config config;
  1453. } __packed;
  1454. /* Run the key scan emulation */
  1455. #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
  1456. enum ec_keyscan_seq_cmd {
  1457. EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
  1458. EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
  1459. EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
  1460. EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
  1461. EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
  1462. };
  1463. enum ec_collect_flags {
  1464. /*
  1465. * Indicates this scan was processed by the EC. Due to timing, some
  1466. * scans may be skipped.
  1467. */
  1468. EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
  1469. };
  1470. struct ec_collect_item {
  1471. uint8_t flags; /* some flags (enum ec_collect_flags) */
  1472. };
  1473. struct ec_params_keyscan_seq_ctrl {
  1474. uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
  1475. union {
  1476. struct {
  1477. uint8_t active; /* still active */
  1478. uint8_t num_items; /* number of items */
  1479. /* Current item being presented */
  1480. uint8_t cur_item;
  1481. } status;
  1482. struct {
  1483. /*
  1484. * Absolute time for this scan, measured from the
  1485. * start of the sequence.
  1486. */
  1487. uint32_t time_us;
  1488. uint8_t scan[0]; /* keyscan data */
  1489. } add;
  1490. struct {
  1491. uint8_t start_item; /* First item to return */
  1492. uint8_t num_items; /* Number of items to return */
  1493. } collect;
  1494. };
  1495. } __packed;
  1496. struct ec_result_keyscan_seq_ctrl {
  1497. union {
  1498. struct {
  1499. uint8_t num_items; /* Number of items */
  1500. /* Data for each item */
  1501. struct ec_collect_item item[0];
  1502. } collect;
  1503. };
  1504. } __packed;
  1505. /*
  1506. * Command for retrieving the next pending MKBP event from the EC device
  1507. *
  1508. * The device replies with UNAVAILABLE if there aren't any pending events.
  1509. */
  1510. #define EC_CMD_GET_NEXT_EVENT 0x67
  1511. enum ec_mkbp_event {
  1512. /* Keyboard matrix changed. The event data is the new matrix state. */
  1513. EC_MKBP_EVENT_KEY_MATRIX = 0,
  1514. /* New host event. The event data is 4 bytes of host event flags. */
  1515. EC_MKBP_EVENT_HOST_EVENT = 1,
  1516. /* New Sensor FIFO data. The event data is fifo_info structure. */
  1517. EC_MKBP_EVENT_SENSOR_FIFO = 2,
  1518. /* Number of MKBP events */
  1519. EC_MKBP_EVENT_COUNT,
  1520. };
  1521. union ec_response_get_next_data {
  1522. uint8_t key_matrix[13];
  1523. /* Unaligned */
  1524. uint32_t host_event;
  1525. } __packed;
  1526. struct ec_response_get_next_event {
  1527. uint8_t event_type;
  1528. /* Followed by event data if any */
  1529. union ec_response_get_next_data data;
  1530. } __packed;
  1531. /*****************************************************************************/
  1532. /* Temperature sensor commands */
  1533. /* Read temperature sensor info */
  1534. #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
  1535. struct ec_params_temp_sensor_get_info {
  1536. uint8_t id;
  1537. } __packed;
  1538. struct ec_response_temp_sensor_get_info {
  1539. char sensor_name[32];
  1540. uint8_t sensor_type;
  1541. } __packed;
  1542. /*****************************************************************************/
  1543. /*
  1544. * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
  1545. * commands accidentally sent to the wrong interface. See the ACPI section
  1546. * below.
  1547. */
  1548. /*****************************************************************************/
  1549. /* Host event commands */
  1550. /*
  1551. * Host event mask params and response structures, shared by all of the host
  1552. * event commands below.
  1553. */
  1554. struct ec_params_host_event_mask {
  1555. uint32_t mask;
  1556. } __packed;
  1557. struct ec_response_host_event_mask {
  1558. uint32_t mask;
  1559. } __packed;
  1560. /* These all use ec_response_host_event_mask */
  1561. #define EC_CMD_HOST_EVENT_GET_B 0x87
  1562. #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
  1563. #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
  1564. #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
  1565. /* These all use ec_params_host_event_mask */
  1566. #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
  1567. #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
  1568. #define EC_CMD_HOST_EVENT_CLEAR 0x8c
  1569. #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
  1570. #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
  1571. /*****************************************************************************/
  1572. /* Switch commands */
  1573. /* Enable/disable LCD backlight */
  1574. #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
  1575. struct ec_params_switch_enable_backlight {
  1576. uint8_t enabled;
  1577. } __packed;
  1578. /* Enable/disable WLAN/Bluetooth */
  1579. #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
  1580. #define EC_VER_SWITCH_ENABLE_WIRELESS 1
  1581. /* Version 0 params; no response */
  1582. struct ec_params_switch_enable_wireless_v0 {
  1583. uint8_t enabled;
  1584. } __packed;
  1585. /* Version 1 params */
  1586. struct ec_params_switch_enable_wireless_v1 {
  1587. /* Flags to enable now */
  1588. uint8_t now_flags;
  1589. /* Which flags to copy from now_flags */
  1590. uint8_t now_mask;
  1591. /*
  1592. * Flags to leave enabled in S3, if they're on at the S0->S3
  1593. * transition. (Other flags will be disabled by the S0->S3
  1594. * transition.)
  1595. */
  1596. uint8_t suspend_flags;
  1597. /* Which flags to copy from suspend_flags */
  1598. uint8_t suspend_mask;
  1599. } __packed;
  1600. /* Version 1 response */
  1601. struct ec_response_switch_enable_wireless_v1 {
  1602. /* Flags to enable now */
  1603. uint8_t now_flags;
  1604. /* Flags to leave enabled in S3 */
  1605. uint8_t suspend_flags;
  1606. } __packed;
  1607. /*****************************************************************************/
  1608. /* GPIO commands. Only available on EC if write protect has been disabled. */
  1609. /* Set GPIO output value */
  1610. #define EC_CMD_GPIO_SET 0x92
  1611. struct ec_params_gpio_set {
  1612. char name[32];
  1613. uint8_t val;
  1614. } __packed;
  1615. /* Get GPIO value */
  1616. #define EC_CMD_GPIO_GET 0x93
  1617. /* Version 0 of input params and response */
  1618. struct ec_params_gpio_get {
  1619. char name[32];
  1620. } __packed;
  1621. struct ec_response_gpio_get {
  1622. uint8_t val;
  1623. } __packed;
  1624. /* Version 1 of input params and response */
  1625. struct ec_params_gpio_get_v1 {
  1626. uint8_t subcmd;
  1627. union {
  1628. struct {
  1629. char name[32];
  1630. } get_value_by_name;
  1631. struct {
  1632. uint8_t index;
  1633. } get_info;
  1634. };
  1635. } __packed;
  1636. struct ec_response_gpio_get_v1 {
  1637. union {
  1638. struct {
  1639. uint8_t val;
  1640. } get_value_by_name, get_count;
  1641. struct {
  1642. uint8_t val;
  1643. char name[32];
  1644. uint32_t flags;
  1645. } get_info;
  1646. };
  1647. } __packed;
  1648. enum gpio_get_subcmd {
  1649. EC_GPIO_GET_BY_NAME = 0,
  1650. EC_GPIO_GET_COUNT = 1,
  1651. EC_GPIO_GET_INFO = 2,
  1652. };
  1653. /*****************************************************************************/
  1654. /* I2C commands. Only available when flash write protect is unlocked. */
  1655. /*
  1656. * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
  1657. * removed soon. Use EC_CMD_I2C_XFER instead.
  1658. */
  1659. /* Read I2C bus */
  1660. #define EC_CMD_I2C_READ 0x94
  1661. struct ec_params_i2c_read {
  1662. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  1663. uint8_t read_size; /* Either 8 or 16. */
  1664. uint8_t port;
  1665. uint8_t offset;
  1666. } __packed;
  1667. struct ec_response_i2c_read {
  1668. uint16_t data;
  1669. } __packed;
  1670. /* Write I2C bus */
  1671. #define EC_CMD_I2C_WRITE 0x95
  1672. struct ec_params_i2c_write {
  1673. uint16_t data;
  1674. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  1675. uint8_t write_size; /* Either 8 or 16. */
  1676. uint8_t port;
  1677. uint8_t offset;
  1678. } __packed;
  1679. /*****************************************************************************/
  1680. /* Charge state commands. Only available when flash write protect unlocked. */
  1681. /* Force charge state machine to stop charging the battery or force it to
  1682. * discharge the battery.
  1683. */
  1684. #define EC_CMD_CHARGE_CONTROL 0x96
  1685. #define EC_VER_CHARGE_CONTROL 1
  1686. enum ec_charge_control_mode {
  1687. CHARGE_CONTROL_NORMAL = 0,
  1688. CHARGE_CONTROL_IDLE,
  1689. CHARGE_CONTROL_DISCHARGE,
  1690. };
  1691. struct ec_params_charge_control {
  1692. uint32_t mode; /* enum charge_control_mode */
  1693. } __packed;
  1694. /*****************************************************************************/
  1695. /* Console commands. Only available when flash write protect is unlocked. */
  1696. /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
  1697. #define EC_CMD_CONSOLE_SNAPSHOT 0x97
  1698. /*
  1699. * Read next chunk of data from saved snapshot.
  1700. *
  1701. * Response is null-terminated string. Empty string, if there is no more
  1702. * remaining output.
  1703. */
  1704. #define EC_CMD_CONSOLE_READ 0x98
  1705. /*****************************************************************************/
  1706. /*
  1707. * Cut off battery power immediately or after the host has shut down.
  1708. *
  1709. * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
  1710. * EC_RES_SUCCESS if the command was successful.
  1711. * EC_RES_ERROR if the cut off command failed.
  1712. */
  1713. #define EC_CMD_BATTERY_CUT_OFF 0x99
  1714. #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
  1715. struct ec_params_battery_cutoff {
  1716. uint8_t flags;
  1717. } __packed;
  1718. /*****************************************************************************/
  1719. /* USB port mux control. */
  1720. /*
  1721. * Switch USB mux or return to automatic switching.
  1722. */
  1723. #define EC_CMD_USB_MUX 0x9a
  1724. struct ec_params_usb_mux {
  1725. uint8_t mux;
  1726. } __packed;
  1727. /*****************************************************************************/
  1728. /* LDOs / FETs control. */
  1729. enum ec_ldo_state {
  1730. EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
  1731. EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
  1732. };
  1733. /*
  1734. * Switch on/off a LDO.
  1735. */
  1736. #define EC_CMD_LDO_SET 0x9b
  1737. struct ec_params_ldo_set {
  1738. uint8_t index;
  1739. uint8_t state;
  1740. } __packed;
  1741. /*
  1742. * Get LDO state.
  1743. */
  1744. #define EC_CMD_LDO_GET 0x9c
  1745. struct ec_params_ldo_get {
  1746. uint8_t index;
  1747. } __packed;
  1748. struct ec_response_ldo_get {
  1749. uint8_t state;
  1750. } __packed;
  1751. /*****************************************************************************/
  1752. /* Power info. */
  1753. /*
  1754. * Get power info.
  1755. */
  1756. #define EC_CMD_POWER_INFO 0x9d
  1757. struct ec_response_power_info {
  1758. uint32_t usb_dev_type;
  1759. uint16_t voltage_ac;
  1760. uint16_t voltage_system;
  1761. uint16_t current_system;
  1762. uint16_t usb_current_limit;
  1763. } __packed;
  1764. /*****************************************************************************/
  1765. /* I2C passthru command */
  1766. #define EC_CMD_I2C_PASSTHRU 0x9e
  1767. /* Read data; if not present, message is a write */
  1768. #define EC_I2C_FLAG_READ (1 << 15)
  1769. /* Mask for address */
  1770. #define EC_I2C_ADDR_MASK 0x3ff
  1771. #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
  1772. #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
  1773. /* Any error */
  1774. #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
  1775. struct ec_params_i2c_passthru_msg {
  1776. uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
  1777. uint16_t len; /* Number of bytes to read or write */
  1778. } __packed;
  1779. struct ec_params_i2c_passthru {
  1780. uint8_t port; /* I2C port number */
  1781. uint8_t num_msgs; /* Number of messages */
  1782. struct ec_params_i2c_passthru_msg msg[];
  1783. /* Data to write for all messages is concatenated here */
  1784. } __packed;
  1785. struct ec_response_i2c_passthru {
  1786. uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
  1787. uint8_t num_msgs; /* Number of messages processed */
  1788. uint8_t data[]; /* Data read by messages concatenated here */
  1789. } __packed;
  1790. /*****************************************************************************/
  1791. /* Power button hang detect */
  1792. #define EC_CMD_HANG_DETECT 0x9f
  1793. /* Reasons to start hang detection timer */
  1794. /* Power button pressed */
  1795. #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
  1796. /* Lid closed */
  1797. #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
  1798. /* Lid opened */
  1799. #define EC_HANG_START_ON_LID_OPEN (1 << 2)
  1800. /* Start of AP S3->S0 transition (booting or resuming from suspend) */
  1801. #define EC_HANG_START_ON_RESUME (1 << 3)
  1802. /* Reasons to cancel hang detection */
  1803. /* Power button released */
  1804. #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
  1805. /* Any host command from AP received */
  1806. #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
  1807. /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
  1808. #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
  1809. /*
  1810. * If this flag is set, all the other fields are ignored, and the hang detect
  1811. * timer is started. This provides the AP a way to start the hang timer
  1812. * without reconfiguring any of the other hang detect settings. Note that
  1813. * you must previously have configured the timeouts.
  1814. */
  1815. #define EC_HANG_START_NOW (1 << 30)
  1816. /*
  1817. * If this flag is set, all the other fields are ignored (including
  1818. * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
  1819. * without reconfiguring any of the other hang detect settings.
  1820. */
  1821. #define EC_HANG_STOP_NOW (1 << 31)
  1822. struct ec_params_hang_detect {
  1823. /* Flags; see EC_HANG_* */
  1824. uint32_t flags;
  1825. /* Timeout in msec before generating host event, if enabled */
  1826. uint16_t host_event_timeout_msec;
  1827. /* Timeout in msec before generating warm reboot, if enabled */
  1828. uint16_t warm_reboot_timeout_msec;
  1829. } __packed;
  1830. /*****************************************************************************/
  1831. /* Commands for battery charging */
  1832. /*
  1833. * This is the single catch-all host command to exchange data regarding the
  1834. * charge state machine (v2 and up).
  1835. */
  1836. #define EC_CMD_CHARGE_STATE 0xa0
  1837. /* Subcommands for this host command */
  1838. enum charge_state_command {
  1839. CHARGE_STATE_CMD_GET_STATE,
  1840. CHARGE_STATE_CMD_GET_PARAM,
  1841. CHARGE_STATE_CMD_SET_PARAM,
  1842. CHARGE_STATE_NUM_CMDS
  1843. };
  1844. /*
  1845. * Known param numbers are defined here. Ranges are reserved for board-specific
  1846. * params, which are handled by the particular implementations.
  1847. */
  1848. enum charge_state_params {
  1849. CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
  1850. CS_PARAM_CHG_CURRENT, /* charger current limit */
  1851. CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
  1852. CS_PARAM_CHG_STATUS, /* charger-specific status */
  1853. CS_PARAM_CHG_OPTION, /* charger-specific options */
  1854. /* How many so far? */
  1855. CS_NUM_BASE_PARAMS,
  1856. /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
  1857. CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
  1858. CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
  1859. /* Other custom param ranges go here... */
  1860. };
  1861. struct ec_params_charge_state {
  1862. uint8_t cmd; /* enum charge_state_command */
  1863. union {
  1864. struct {
  1865. /* no args */
  1866. } get_state;
  1867. struct {
  1868. uint32_t param; /* enum charge_state_param */
  1869. } get_param;
  1870. struct {
  1871. uint32_t param; /* param to set */
  1872. uint32_t value; /* value to set */
  1873. } set_param;
  1874. };
  1875. } __packed;
  1876. struct ec_response_charge_state {
  1877. union {
  1878. struct {
  1879. int ac;
  1880. int chg_voltage;
  1881. int chg_current;
  1882. int chg_input_current;
  1883. int batt_state_of_charge;
  1884. } get_state;
  1885. struct {
  1886. uint32_t value;
  1887. } get_param;
  1888. struct {
  1889. /* no return values */
  1890. } set_param;
  1891. };
  1892. } __packed;
  1893. /*
  1894. * Set maximum battery charging current.
  1895. */
  1896. #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
  1897. struct ec_params_current_limit {
  1898. uint32_t limit; /* in mA */
  1899. } __packed;
  1900. /*
  1901. * Set maximum external power current.
  1902. */
  1903. #define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
  1904. struct ec_params_ext_power_current_limit {
  1905. uint32_t limit; /* in mA */
  1906. } __packed;
  1907. /*****************************************************************************/
  1908. /* Smart battery pass-through */
  1909. /* Get / Set 16-bit smart battery registers */
  1910. #define EC_CMD_SB_READ_WORD 0xb0
  1911. #define EC_CMD_SB_WRITE_WORD 0xb1
  1912. /* Get / Set string smart battery parameters
  1913. * formatted as SMBUS "block".
  1914. */
  1915. #define EC_CMD_SB_READ_BLOCK 0xb2
  1916. #define EC_CMD_SB_WRITE_BLOCK 0xb3
  1917. struct ec_params_sb_rd {
  1918. uint8_t reg;
  1919. } __packed;
  1920. struct ec_response_sb_rd_word {
  1921. uint16_t value;
  1922. } __packed;
  1923. struct ec_params_sb_wr_word {
  1924. uint8_t reg;
  1925. uint16_t value;
  1926. } __packed;
  1927. struct ec_response_sb_rd_block {
  1928. uint8_t data[32];
  1929. } __packed;
  1930. struct ec_params_sb_wr_block {
  1931. uint8_t reg;
  1932. uint16_t data[32];
  1933. } __packed;
  1934. /*****************************************************************************/
  1935. /* Battery vendor parameters
  1936. *
  1937. * Get or set vendor-specific parameters in the battery. Implementations may
  1938. * differ between boards or batteries. On a set operation, the response
  1939. * contains the actual value set, which may be rounded or clipped from the
  1940. * requested value.
  1941. */
  1942. #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
  1943. enum ec_battery_vendor_param_mode {
  1944. BATTERY_VENDOR_PARAM_MODE_GET = 0,
  1945. BATTERY_VENDOR_PARAM_MODE_SET,
  1946. };
  1947. struct ec_params_battery_vendor_param {
  1948. uint32_t param;
  1949. uint32_t value;
  1950. uint8_t mode;
  1951. } __packed;
  1952. struct ec_response_battery_vendor_param {
  1953. uint32_t value;
  1954. } __packed;
  1955. /*****************************************************************************/
  1956. /* System commands */
  1957. /*
  1958. * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
  1959. * necessarily reboot the EC. Rename to "image" or something similar?
  1960. */
  1961. #define EC_CMD_REBOOT_EC 0xd2
  1962. /* Command */
  1963. enum ec_reboot_cmd {
  1964. EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
  1965. EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
  1966. EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
  1967. /* (command 3 was jump to RW-B) */
  1968. EC_REBOOT_COLD = 4, /* Cold-reboot */
  1969. EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
  1970. EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
  1971. };
  1972. /* Flags for ec_params_reboot_ec.reboot_flags */
  1973. #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
  1974. #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
  1975. struct ec_params_reboot_ec {
  1976. uint8_t cmd; /* enum ec_reboot_cmd */
  1977. uint8_t flags; /* See EC_REBOOT_FLAG_* */
  1978. } __packed;
  1979. /*
  1980. * Get information on last EC panic.
  1981. *
  1982. * Returns variable-length platform-dependent panic information. See panic.h
  1983. * for details.
  1984. */
  1985. #define EC_CMD_GET_PANIC_INFO 0xd3
  1986. /*****************************************************************************/
  1987. /*
  1988. * ACPI commands
  1989. *
  1990. * These are valid ONLY on the ACPI command/data port.
  1991. */
  1992. /*
  1993. * ACPI Read Embedded Controller
  1994. *
  1995. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  1996. *
  1997. * Use the following sequence:
  1998. *
  1999. * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
  2000. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  2001. * - Write address to EC_LPC_ADDR_ACPI_DATA
  2002. * - Wait for EC_LPC_CMDR_DATA bit to set
  2003. * - Read value from EC_LPC_ADDR_ACPI_DATA
  2004. */
  2005. #define EC_CMD_ACPI_READ 0x80
  2006. /*
  2007. * ACPI Write Embedded Controller
  2008. *
  2009. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  2010. *
  2011. * Use the following sequence:
  2012. *
  2013. * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
  2014. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  2015. * - Write address to EC_LPC_ADDR_ACPI_DATA
  2016. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  2017. * - Write value to EC_LPC_ADDR_ACPI_DATA
  2018. */
  2019. #define EC_CMD_ACPI_WRITE 0x81
  2020. /*
  2021. * ACPI Query Embedded Controller
  2022. *
  2023. * This clears the lowest-order bit in the currently pending host events, and
  2024. * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
  2025. * event 0x80000000 = 32), or 0 if no event was pending.
  2026. */
  2027. #define EC_CMD_ACPI_QUERY_EVENT 0x84
  2028. /* Valid addresses in ACPI memory space, for read/write commands */
  2029. /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
  2030. #define EC_ACPI_MEM_VERSION 0x00
  2031. /*
  2032. * Test location; writing value here updates test compliment byte to (0xff -
  2033. * value).
  2034. */
  2035. #define EC_ACPI_MEM_TEST 0x01
  2036. /* Test compliment; writes here are ignored. */
  2037. #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
  2038. /* Keyboard backlight brightness percent (0 - 100) */
  2039. #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
  2040. /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
  2041. #define EC_ACPI_MEM_FAN_DUTY 0x04
  2042. /*
  2043. * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
  2044. * independent thresholds attached to them. The current value of the ID
  2045. * register determines which sensor is affected by the THRESHOLD and COMMIT
  2046. * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
  2047. * as the memory-mapped sensors. The COMMIT register applies those settings.
  2048. *
  2049. * The spec does not mandate any way to read back the threshold settings
  2050. * themselves, but when a threshold is crossed the AP needs a way to determine
  2051. * which sensor(s) are responsible. Each reading of the ID register clears and
  2052. * returns one sensor ID that has crossed one of its threshold (in either
  2053. * direction) since the last read. A value of 0xFF means "no new thresholds
  2054. * have tripped". Setting or enabling the thresholds for a sensor will clear
  2055. * the unread event count for that sensor.
  2056. */
  2057. #define EC_ACPI_MEM_TEMP_ID 0x05
  2058. #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
  2059. #define EC_ACPI_MEM_TEMP_COMMIT 0x07
  2060. /*
  2061. * Here are the bits for the COMMIT register:
  2062. * bit 0 selects the threshold index for the chosen sensor (0/1)
  2063. * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
  2064. * Each write to the commit register affects one threshold.
  2065. */
  2066. #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
  2067. #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
  2068. /*
  2069. * Example:
  2070. *
  2071. * Set the thresholds for sensor 2 to 50 C and 60 C:
  2072. * write 2 to [0x05] -- select temp sensor 2
  2073. * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
  2074. * write 0x2 to [0x07] -- enable threshold 0 with this value
  2075. * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
  2076. * write 0x3 to [0x07] -- enable threshold 1 with this value
  2077. *
  2078. * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
  2079. * write 2 to [0x05] -- select temp sensor 2
  2080. * write 0x1 to [0x07] -- disable threshold 1
  2081. */
  2082. /* DPTF battery charging current limit */
  2083. #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
  2084. /* Charging limit is specified in 64 mA steps */
  2085. #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
  2086. /* Value to disable DPTF battery charging limit */
  2087. #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
  2088. /* Current version of ACPI memory address space */
  2089. #define EC_ACPI_MEM_VERSION_CURRENT 1
  2090. /*****************************************************************************/
  2091. /*
  2092. * Special commands
  2093. *
  2094. * These do not follow the normal rules for commands. See each command for
  2095. * details.
  2096. */
  2097. /*
  2098. * Reboot NOW
  2099. *
  2100. * This command will work even when the EC LPC interface is busy, because the
  2101. * reboot command is processed at interrupt level. Note that when the EC
  2102. * reboots, the host will reboot too, so there is no response to this command.
  2103. *
  2104. * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
  2105. */
  2106. #define EC_CMD_REBOOT 0xd1 /* Think "die" */
  2107. /*
  2108. * Resend last response (not supported on LPC).
  2109. *
  2110. * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
  2111. * there was no previous command, or the previous command's response was too
  2112. * big to save.
  2113. */
  2114. #define EC_CMD_RESEND_RESPONSE 0xdb
  2115. /*
  2116. * This header byte on a command indicate version 0. Any header byte less
  2117. * than this means that we are talking to an old EC which doesn't support
  2118. * versioning. In that case, we assume version 0.
  2119. *
  2120. * Header bytes greater than this indicate a later version. For example,
  2121. * EC_CMD_VERSION0 + 1 means we are using version 1.
  2122. *
  2123. * The old EC interface must not use commands 0xdc or higher.
  2124. */
  2125. #define EC_CMD_VERSION0 0xdc
  2126. #endif /* !__ACPI__ */
  2127. /*****************************************************************************/
  2128. /*
  2129. * PD commands
  2130. *
  2131. * These commands are for PD MCU communication.
  2132. */
  2133. /* EC to PD MCU exchange status command */
  2134. #define EC_CMD_PD_EXCHANGE_STATUS 0x100
  2135. /* Status of EC being sent to PD */
  2136. struct ec_params_pd_status {
  2137. int8_t batt_soc; /* battery state of charge */
  2138. } __packed;
  2139. /* Status of PD being sent back to EC */
  2140. struct ec_response_pd_status {
  2141. int8_t status; /* PD MCU status */
  2142. uint32_t curr_lim_ma; /* input current limit */
  2143. } __packed;
  2144. /* Set USB type-C port role and muxes */
  2145. #define EC_CMD_USB_PD_CONTROL 0x101
  2146. enum usb_pd_control_role {
  2147. USB_PD_CTRL_ROLE_NO_CHANGE = 0,
  2148. USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
  2149. USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
  2150. USB_PD_CTRL_ROLE_FORCE_SINK = 3,
  2151. USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
  2152. };
  2153. enum usb_pd_control_mux {
  2154. USB_PD_CTRL_MUX_NO_CHANGE = 0,
  2155. USB_PD_CTRL_MUX_NONE = 1,
  2156. USB_PD_CTRL_MUX_USB = 2,
  2157. USB_PD_CTRL_MUX_DP = 3,
  2158. USB_PD_CTRL_MUX_DOCK = 4,
  2159. USB_PD_CTRL_MUX_AUTO = 5,
  2160. };
  2161. struct ec_params_usb_pd_control {
  2162. uint8_t port;
  2163. uint8_t role;
  2164. uint8_t mux;
  2165. } __packed;
  2166. /*****************************************************************************/
  2167. /*
  2168. * Passthru commands
  2169. *
  2170. * Some platforms have sub-processors chained to each other. For example.
  2171. *
  2172. * AP <--> EC <--> PD MCU
  2173. *
  2174. * The top 2 bits of the command number are used to indicate which device the
  2175. * command is intended for. Device 0 is always the device receiving the
  2176. * command; other device mapping is board-specific.
  2177. *
  2178. * When a device receives a command to be passed to a sub-processor, it passes
  2179. * it on with the device number set back to 0. This allows the sub-processor
  2180. * to remain blissfully unaware of whether the command originated on the next
  2181. * device up the chain, or was passed through from the AP.
  2182. *
  2183. * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
  2184. * AP sends command 0x4002 to the EC
  2185. * EC sends command 0x0002 to the PD MCU
  2186. * EC forwards PD MCU response back to the AP
  2187. */
  2188. /* Offset and max command number for sub-device n */
  2189. #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
  2190. #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
  2191. /*****************************************************************************/
  2192. /*
  2193. * Deprecated constants. These constants have been renamed for clarity. The
  2194. * meaning and size has not changed. Programs that use the old names should
  2195. * switch to the new names soon, as the old names may not be carried forward
  2196. * forever.
  2197. */
  2198. #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
  2199. #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
  2200. #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
  2201. #endif /* __CROS_EC_COMMANDS_H */