cros_ec_commands.h 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021
  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. /* PD MCU triggering host event */
  259. EC_HOST_EVENT_PD_MCU = 22,
  260. /* EC desires to change state of host-controlled USB mux */
  261. EC_HOST_EVENT_USB_MUX = 28,
  262. /*
  263. * The high bit of the event mask is not used as a host event code. If
  264. * it reads back as set, then the entire event mask should be
  265. * considered invalid by the host. This can happen when reading the
  266. * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
  267. * not initialized on the EC, or improperly configured on the host.
  268. */
  269. EC_HOST_EVENT_INVALID = 32
  270. };
  271. /* Host event mask */
  272. #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
  273. /* Arguments at EC_LPC_ADDR_HOST_ARGS */
  274. struct ec_lpc_host_args {
  275. uint8_t flags;
  276. uint8_t command_version;
  277. uint8_t data_size;
  278. /*
  279. * Checksum; sum of command + flags + command_version + data_size +
  280. * all params/response data bytes.
  281. */
  282. uint8_t checksum;
  283. } __packed;
  284. /* Flags for ec_lpc_host_args.flags */
  285. /*
  286. * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
  287. * params.
  288. *
  289. * If EC gets a command and this flag is not set, this is an old-style command.
  290. * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
  291. * unknown length. EC must respond with an old-style response (that is,
  292. * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
  293. */
  294. #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
  295. /*
  296. * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
  297. *
  298. * If EC responds to a command and this flag is not set, this is an old-style
  299. * response. Command version is 0 and response data from EC is at
  300. * EC_LPC_ADDR_OLD_PARAM with unknown length.
  301. */
  302. #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
  303. /*****************************************************************************/
  304. /*
  305. * Byte codes returned by EC over SPI interface.
  306. *
  307. * These can be used by the AP to debug the EC interface, and to determine
  308. * when the EC is not in a state where it will ever get around to responding
  309. * to the AP.
  310. *
  311. * Example of sequence of bytes read from EC for a current good transfer:
  312. * 1. - - AP asserts chip select (CS#)
  313. * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
  314. * 3. - - EC starts handling CS# interrupt
  315. * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
  316. * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
  317. * bytes looking for EC_SPI_FRAME_START
  318. * 6. - - EC finishes processing and sets up response
  319. * 7. EC_SPI_FRAME_START - AP reads frame byte
  320. * 8. (response packet) - AP reads response packet
  321. * 9. EC_SPI_PAST_END - Any additional bytes read by AP
  322. * 10 - - AP deasserts chip select
  323. * 11 - - EC processes CS# interrupt and sets up DMA for
  324. * next request
  325. *
  326. * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
  327. * the following byte values:
  328. * EC_SPI_OLD_READY
  329. * EC_SPI_RX_READY
  330. * EC_SPI_RECEIVING
  331. * EC_SPI_PROCESSING
  332. *
  333. * Then the EC found an error in the request, or was not ready for the request
  334. * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
  335. * because the EC is unable to tell when the AP is done sending its request.
  336. */
  337. /*
  338. * Framing byte which precedes a response packet from the EC. After sending a
  339. * request, the AP will clock in bytes until it sees the framing byte, then
  340. * clock in the response packet.
  341. */
  342. #define EC_SPI_FRAME_START 0xec
  343. /*
  344. * Padding bytes which are clocked out after the end of a response packet.
  345. */
  346. #define EC_SPI_PAST_END 0xed
  347. /*
  348. * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
  349. * that the AP will send a valid packet header (starting with
  350. * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
  351. */
  352. #define EC_SPI_RX_READY 0xf8
  353. /*
  354. * EC has started receiving the request from the AP, but hasn't started
  355. * processing it yet.
  356. */
  357. #define EC_SPI_RECEIVING 0xf9
  358. /* EC has received the entire request from the AP and is processing it. */
  359. #define EC_SPI_PROCESSING 0xfa
  360. /*
  361. * EC received bad data from the AP, such as a packet header with an invalid
  362. * length. EC will ignore all data until chip select deasserts.
  363. */
  364. #define EC_SPI_RX_BAD_DATA 0xfb
  365. /*
  366. * EC received data from the AP before it was ready. That is, the AP asserted
  367. * chip select and started clocking data before the EC was ready to receive it.
  368. * EC will ignore all data until chip select deasserts.
  369. */
  370. #define EC_SPI_NOT_READY 0xfc
  371. /*
  372. * EC was ready to receive a request from the AP. EC has treated the byte sent
  373. * by the AP as part of a request packet, or (for old-style ECs) is processing
  374. * a fully received packet but is not ready to respond yet.
  375. */
  376. #define EC_SPI_OLD_READY 0xfd
  377. /*****************************************************************************/
  378. /*
  379. * Protocol version 2 for I2C and SPI send a request this way:
  380. *
  381. * 0 EC_CMD_VERSION0 + (command version)
  382. * 1 Command number
  383. * 2 Length of params = N
  384. * 3..N+2 Params, if any
  385. * N+3 8-bit checksum of bytes 0..N+2
  386. *
  387. * The corresponding response is:
  388. *
  389. * 0 Result code (EC_RES_*)
  390. * 1 Length of params = M
  391. * 2..M+1 Params, if any
  392. * M+2 8-bit checksum of bytes 0..M+1
  393. */
  394. #define EC_PROTO2_REQUEST_HEADER_BYTES 3
  395. #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
  396. #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
  397. EC_PROTO2_REQUEST_TRAILER_BYTES)
  398. #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
  399. #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
  400. #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
  401. EC_PROTO2_RESPONSE_TRAILER_BYTES)
  402. /* Parameter length was limited by the LPC interface */
  403. #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
  404. /* Maximum request and response packet sizes for protocol version 2 */
  405. #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
  406. EC_PROTO2_MAX_PARAM_SIZE)
  407. #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
  408. EC_PROTO2_MAX_PARAM_SIZE)
  409. /*****************************************************************************/
  410. /*
  411. * Value written to legacy command port / prefix byte to indicate protocol
  412. * 3+ structs are being used. Usage is bus-dependent.
  413. */
  414. #define EC_COMMAND_PROTOCOL_3 0xda
  415. #define EC_HOST_REQUEST_VERSION 3
  416. /* Version 3 request from host */
  417. struct ec_host_request {
  418. /* Struct version (=3)
  419. *
  420. * EC will return EC_RES_INVALID_HEADER if it receives a header with a
  421. * version it doesn't know how to parse.
  422. */
  423. uint8_t struct_version;
  424. /*
  425. * Checksum of request and data; sum of all bytes including checksum
  426. * should total to 0.
  427. */
  428. uint8_t checksum;
  429. /* Command code */
  430. uint16_t command;
  431. /* Command version */
  432. uint8_t command_version;
  433. /* Unused byte in current protocol version; set to 0 */
  434. uint8_t reserved;
  435. /* Length of data which follows this header */
  436. uint16_t data_len;
  437. } __packed;
  438. #define EC_HOST_RESPONSE_VERSION 3
  439. /* Version 3 response from EC */
  440. struct ec_host_response {
  441. /* Struct version (=3) */
  442. uint8_t struct_version;
  443. /*
  444. * Checksum of response and data; sum of all bytes including checksum
  445. * should total to 0.
  446. */
  447. uint8_t checksum;
  448. /* Result code (EC_RES_*) */
  449. uint16_t result;
  450. /* Length of data which follows this header */
  451. uint16_t data_len;
  452. /* Unused bytes in current protocol version; set to 0 */
  453. uint16_t reserved;
  454. } __packed;
  455. /*****************************************************************************/
  456. /*
  457. * Notes on commands:
  458. *
  459. * Each command is an 16-bit command value. Commands which take params or
  460. * return response data specify structs for that data. If no struct is
  461. * specified, the command does not input or output data, respectively.
  462. * Parameter/response length is implicit in the structs. Some underlying
  463. * communication protocols (I2C, SPI) may add length or checksum headers, but
  464. * those are implementation-dependent and not defined here.
  465. */
  466. /*****************************************************************************/
  467. /* General / test commands */
  468. /*
  469. * Get protocol version, used to deal with non-backward compatible protocol
  470. * changes.
  471. */
  472. #define EC_CMD_PROTO_VERSION 0x00
  473. struct ec_response_proto_version {
  474. uint32_t version;
  475. } __packed;
  476. /*
  477. * Hello. This is a simple command to test the EC is responsive to
  478. * commands.
  479. */
  480. #define EC_CMD_HELLO 0x01
  481. struct ec_params_hello {
  482. uint32_t in_data; /* Pass anything here */
  483. } __packed;
  484. struct ec_response_hello {
  485. uint32_t out_data; /* Output will be in_data + 0x01020304 */
  486. } __packed;
  487. /* Get version number */
  488. #define EC_CMD_GET_VERSION 0x02
  489. enum ec_current_image {
  490. EC_IMAGE_UNKNOWN = 0,
  491. EC_IMAGE_RO,
  492. EC_IMAGE_RW
  493. };
  494. struct ec_response_get_version {
  495. /* Null-terminated version strings for RO, RW */
  496. char version_string_ro[32];
  497. char version_string_rw[32];
  498. char reserved[32]; /* Was previously RW-B string */
  499. uint32_t current_image; /* One of ec_current_image */
  500. } __packed;
  501. /* Read test */
  502. #define EC_CMD_READ_TEST 0x03
  503. struct ec_params_read_test {
  504. uint32_t offset; /* Starting value for read buffer */
  505. uint32_t size; /* Size to read in bytes */
  506. } __packed;
  507. struct ec_response_read_test {
  508. uint32_t data[32];
  509. } __packed;
  510. /*
  511. * Get build information
  512. *
  513. * Response is null-terminated string.
  514. */
  515. #define EC_CMD_GET_BUILD_INFO 0x04
  516. /* Get chip info */
  517. #define EC_CMD_GET_CHIP_INFO 0x05
  518. struct ec_response_get_chip_info {
  519. /* Null-terminated strings */
  520. char vendor[32];
  521. char name[32];
  522. char revision[32]; /* Mask version */
  523. } __packed;
  524. /* Get board HW version */
  525. #define EC_CMD_GET_BOARD_VERSION 0x06
  526. struct ec_response_board_version {
  527. uint16_t board_version; /* A monotonously incrementing number. */
  528. } __packed;
  529. /*
  530. * Read memory-mapped data.
  531. *
  532. * This is an alternate interface to memory-mapped data for bus protocols
  533. * which don't support direct-mapped memory - I2C, SPI, etc.
  534. *
  535. * Response is params.size bytes of data.
  536. */
  537. #define EC_CMD_READ_MEMMAP 0x07
  538. struct ec_params_read_memmap {
  539. uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
  540. uint8_t size; /* Size to read in bytes */
  541. } __packed;
  542. /* Read versions supported for a command */
  543. #define EC_CMD_GET_CMD_VERSIONS 0x08
  544. struct ec_params_get_cmd_versions {
  545. uint8_t cmd; /* Command to check */
  546. } __packed;
  547. struct ec_params_get_cmd_versions_v1 {
  548. uint16_t cmd; /* Command to check */
  549. } __packed;
  550. struct ec_response_get_cmd_versions {
  551. /*
  552. * Mask of supported versions; use EC_VER_MASK() to compare with a
  553. * desired version.
  554. */
  555. uint32_t version_mask;
  556. } __packed;
  557. /*
  558. * Check EC communcations status (busy). This is needed on i2c/spi but not
  559. * on lpc since it has its own out-of-band busy indicator.
  560. *
  561. * lpc must read the status from the command register. Attempting this on
  562. * lpc will overwrite the args/parameter space and corrupt its data.
  563. */
  564. #define EC_CMD_GET_COMMS_STATUS 0x09
  565. /* Avoid using ec_status which is for return values */
  566. enum ec_comms_status {
  567. EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
  568. };
  569. struct ec_response_get_comms_status {
  570. uint32_t flags; /* Mask of enum ec_comms_status */
  571. } __packed;
  572. /* Fake a variety of responses, purely for testing purposes. */
  573. #define EC_CMD_TEST_PROTOCOL 0x0a
  574. /* Tell the EC what to send back to us. */
  575. struct ec_params_test_protocol {
  576. uint32_t ec_result;
  577. uint32_t ret_len;
  578. uint8_t buf[32];
  579. } __packed;
  580. /* Here it comes... */
  581. struct ec_response_test_protocol {
  582. uint8_t buf[32];
  583. } __packed;
  584. /* Get prococol information */
  585. #define EC_CMD_GET_PROTOCOL_INFO 0x0b
  586. /* Flags for ec_response_get_protocol_info.flags */
  587. /* EC_RES_IN_PROGRESS may be returned if a command is slow */
  588. #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
  589. struct ec_response_get_protocol_info {
  590. /* Fields which exist if at least protocol version 3 supported */
  591. /* Bitmask of protocol versions supported (1 << n means version n)*/
  592. uint32_t protocol_versions;
  593. /* Maximum request packet size, in bytes */
  594. uint16_t max_request_packet_size;
  595. /* Maximum response packet size, in bytes */
  596. uint16_t max_response_packet_size;
  597. /* Flags; see EC_PROTOCOL_INFO_* */
  598. uint32_t flags;
  599. } __packed;
  600. /*****************************************************************************/
  601. /* Get/Set miscellaneous values */
  602. /* The upper byte of .flags tells what to do (nothing means "get") */
  603. #define EC_GSV_SET 0x80000000
  604. /* The lower three bytes of .flags identifies the parameter, if that has
  605. meaning for an individual command. */
  606. #define EC_GSV_PARAM_MASK 0x00ffffff
  607. struct ec_params_get_set_value {
  608. uint32_t flags;
  609. uint32_t value;
  610. } __packed;
  611. struct ec_response_get_set_value {
  612. uint32_t flags;
  613. uint32_t value;
  614. } __packed;
  615. /* More than one command can use these structs to get/set paramters. */
  616. #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
  617. /*****************************************************************************/
  618. /* List the features supported by the firmware */
  619. #define EC_CMD_GET_FEATURES 0x0d
  620. /* Supported features */
  621. enum ec_feature_code {
  622. /*
  623. * This image contains a limited set of features. Another image
  624. * in RW partition may support more features.
  625. */
  626. EC_FEATURE_LIMITED = 0,
  627. /*
  628. * Commands for probing/reading/writing/erasing the flash in the
  629. * EC are present.
  630. */
  631. EC_FEATURE_FLASH = 1,
  632. /*
  633. * Can control the fan speed directly.
  634. */
  635. EC_FEATURE_PWM_FAN = 2,
  636. /*
  637. * Can control the intensity of the keyboard backlight.
  638. */
  639. EC_FEATURE_PWM_KEYB = 3,
  640. /*
  641. * Support Google lightbar, introduced on Pixel.
  642. */
  643. EC_FEATURE_LIGHTBAR = 4,
  644. /* Control of LEDs */
  645. EC_FEATURE_LED = 5,
  646. /* Exposes an interface to control gyro and sensors.
  647. * The host goes through the EC to access these sensors.
  648. * In addition, the EC may provide composite sensors, like lid angle.
  649. */
  650. EC_FEATURE_MOTION_SENSE = 6,
  651. /* The keyboard is controlled by the EC */
  652. EC_FEATURE_KEYB = 7,
  653. /* The AP can use part of the EC flash as persistent storage. */
  654. EC_FEATURE_PSTORE = 8,
  655. /* The EC monitors BIOS port 80h, and can return POST codes. */
  656. EC_FEATURE_PORT80 = 9,
  657. /*
  658. * Thermal management: include TMP specific commands.
  659. * Higher level than direct fan control.
  660. */
  661. EC_FEATURE_THERMAL = 10,
  662. /* Can switch the screen backlight on/off */
  663. EC_FEATURE_BKLIGHT_SWITCH = 11,
  664. /* Can switch the wifi module on/off */
  665. EC_FEATURE_WIFI_SWITCH = 12,
  666. /* Monitor host events, through for example SMI or SCI */
  667. EC_FEATURE_HOST_EVENTS = 13,
  668. /* The EC exposes GPIO commands to control/monitor connected devices. */
  669. EC_FEATURE_GPIO = 14,
  670. /* The EC can send i2c messages to downstream devices. */
  671. EC_FEATURE_I2C = 15,
  672. /* Command to control charger are included */
  673. EC_FEATURE_CHARGER = 16,
  674. /* Simple battery support. */
  675. EC_FEATURE_BATTERY = 17,
  676. /*
  677. * Support Smart battery protocol
  678. * (Common Smart Battery System Interface Specification)
  679. */
  680. EC_FEATURE_SMART_BATTERY = 18,
  681. /* EC can dectect when the host hangs. */
  682. EC_FEATURE_HANG_DETECT = 19,
  683. /* Report power information, for pit only */
  684. EC_FEATURE_PMU = 20,
  685. /* Another Cros EC device is present downstream of this one */
  686. EC_FEATURE_SUB_MCU = 21,
  687. /* Support USB Power delivery (PD) commands */
  688. EC_FEATURE_USB_PD = 22,
  689. /* Control USB multiplexer, for audio through USB port for instance. */
  690. EC_FEATURE_USB_MUX = 23,
  691. /* Motion Sensor code has an internal software FIFO */
  692. EC_FEATURE_MOTION_SENSE_FIFO = 24,
  693. };
  694. #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
  695. #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
  696. struct ec_response_get_features {
  697. uint32_t flags[2];
  698. } __packed;
  699. /*****************************************************************************/
  700. /* Flash commands */
  701. /* Get flash info */
  702. #define EC_CMD_FLASH_INFO 0x10
  703. /* Version 0 returns these fields */
  704. struct ec_response_flash_info {
  705. /* Usable flash size, in bytes */
  706. uint32_t flash_size;
  707. /*
  708. * Write block size. Write offset and size must be a multiple
  709. * of this.
  710. */
  711. uint32_t write_block_size;
  712. /*
  713. * Erase block size. Erase offset and size must be a multiple
  714. * of this.
  715. */
  716. uint32_t erase_block_size;
  717. /*
  718. * Protection block size. Protection offset and size must be a
  719. * multiple of this.
  720. */
  721. uint32_t protect_block_size;
  722. } __packed;
  723. /* Flags for version 1+ flash info command */
  724. /* EC flash erases bits to 0 instead of 1 */
  725. #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
  726. /*
  727. * Version 1 returns the same initial fields as version 0, with additional
  728. * fields following.
  729. *
  730. * gcc anonymous structs don't seem to get along with the __packed directive;
  731. * if they did we'd define the version 0 struct as a sub-struct of this one.
  732. */
  733. struct ec_response_flash_info_1 {
  734. /* Version 0 fields; see above for description */
  735. uint32_t flash_size;
  736. uint32_t write_block_size;
  737. uint32_t erase_block_size;
  738. uint32_t protect_block_size;
  739. /* Version 1 adds these fields: */
  740. /*
  741. * Ideal write size in bytes. Writes will be fastest if size is
  742. * exactly this and offset is a multiple of this. For example, an EC
  743. * may have a write buffer which can do half-page operations if data is
  744. * aligned, and a slower word-at-a-time write mode.
  745. */
  746. uint32_t write_ideal_size;
  747. /* Flags; see EC_FLASH_INFO_* */
  748. uint32_t flags;
  749. } __packed;
  750. /*
  751. * Read flash
  752. *
  753. * Response is params.size bytes of data.
  754. */
  755. #define EC_CMD_FLASH_READ 0x11
  756. struct ec_params_flash_read {
  757. uint32_t offset; /* Byte offset to read */
  758. uint32_t size; /* Size to read in bytes */
  759. } __packed;
  760. /* Write flash */
  761. #define EC_CMD_FLASH_WRITE 0x12
  762. #define EC_VER_FLASH_WRITE 1
  763. /* Version 0 of the flash command supported only 64 bytes of data */
  764. #define EC_FLASH_WRITE_VER0_SIZE 64
  765. struct ec_params_flash_write {
  766. uint32_t offset; /* Byte offset to write */
  767. uint32_t size; /* Size to write in bytes */
  768. /* Followed by data to write */
  769. } __packed;
  770. /* Erase flash */
  771. #define EC_CMD_FLASH_ERASE 0x13
  772. struct ec_params_flash_erase {
  773. uint32_t offset; /* Byte offset to erase */
  774. uint32_t size; /* Size to erase in bytes */
  775. } __packed;
  776. /*
  777. * Get/set flash protection.
  778. *
  779. * If mask!=0, sets/clear the requested bits of flags. Depending on the
  780. * firmware write protect GPIO, not all flags will take effect immediately;
  781. * some flags require a subsequent hard reset to take effect. Check the
  782. * returned flags bits to see what actually happened.
  783. *
  784. * If mask=0, simply returns the current flags state.
  785. */
  786. #define EC_CMD_FLASH_PROTECT 0x15
  787. #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
  788. /* Flags for flash protection */
  789. /* RO flash code protected when the EC boots */
  790. #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
  791. /*
  792. * RO flash code protected now. If this bit is set, at-boot status cannot
  793. * be changed.
  794. */
  795. #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
  796. /* Entire flash code protected now, until reboot. */
  797. #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
  798. /* Flash write protect GPIO is asserted now */
  799. #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
  800. /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
  801. #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
  802. /*
  803. * Error - flash protection is in inconsistent state. At least one bank of
  804. * flash which should be protected is not protected. Usually fixed by
  805. * re-requesting the desired flags, or by a hard reset if that fails.
  806. */
  807. #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
  808. /* Entile flash code protected when the EC boots */
  809. #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
  810. struct ec_params_flash_protect {
  811. uint32_t mask; /* Bits in flags to apply */
  812. uint32_t flags; /* New flags to apply */
  813. } __packed;
  814. struct ec_response_flash_protect {
  815. /* Current value of flash protect flags */
  816. uint32_t flags;
  817. /*
  818. * Flags which are valid on this platform. This allows the caller
  819. * to distinguish between flags which aren't set vs. flags which can't
  820. * be set on this platform.
  821. */
  822. uint32_t valid_flags;
  823. /* Flags which can be changed given the current protection state */
  824. uint32_t writable_flags;
  825. } __packed;
  826. /*
  827. * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
  828. * write protect. These commands may be reused with version > 0.
  829. */
  830. /* Get the region offset/size */
  831. #define EC_CMD_FLASH_REGION_INFO 0x16
  832. #define EC_VER_FLASH_REGION_INFO 1
  833. enum ec_flash_region {
  834. /* Region which holds read-only EC image */
  835. EC_FLASH_REGION_RO = 0,
  836. /* Region which holds rewritable EC image */
  837. EC_FLASH_REGION_RW,
  838. /*
  839. * Region which should be write-protected in the factory (a superset of
  840. * EC_FLASH_REGION_RO)
  841. */
  842. EC_FLASH_REGION_WP_RO,
  843. /* Number of regions */
  844. EC_FLASH_REGION_COUNT,
  845. };
  846. struct ec_params_flash_region_info {
  847. uint32_t region; /* enum ec_flash_region */
  848. } __packed;
  849. struct ec_response_flash_region_info {
  850. uint32_t offset;
  851. uint32_t size;
  852. } __packed;
  853. /* Read/write VbNvContext */
  854. #define EC_CMD_VBNV_CONTEXT 0x17
  855. #define EC_VER_VBNV_CONTEXT 1
  856. #define EC_VBNV_BLOCK_SIZE 16
  857. enum ec_vbnvcontext_op {
  858. EC_VBNV_CONTEXT_OP_READ,
  859. EC_VBNV_CONTEXT_OP_WRITE,
  860. };
  861. struct ec_params_vbnvcontext {
  862. uint32_t op;
  863. uint8_t block[EC_VBNV_BLOCK_SIZE];
  864. } __packed;
  865. struct ec_response_vbnvcontext {
  866. uint8_t block[EC_VBNV_BLOCK_SIZE];
  867. } __packed;
  868. /*****************************************************************************/
  869. /* PWM commands */
  870. /* Get fan target RPM */
  871. #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
  872. struct ec_response_pwm_get_fan_rpm {
  873. uint32_t rpm;
  874. } __packed;
  875. /* Set target fan RPM */
  876. #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
  877. struct ec_params_pwm_set_fan_target_rpm {
  878. uint32_t rpm;
  879. } __packed;
  880. /* Get keyboard backlight */
  881. #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
  882. struct ec_response_pwm_get_keyboard_backlight {
  883. uint8_t percent;
  884. uint8_t enabled;
  885. } __packed;
  886. /* Set keyboard backlight */
  887. #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
  888. struct ec_params_pwm_set_keyboard_backlight {
  889. uint8_t percent;
  890. } __packed;
  891. /* Set target fan PWM duty cycle */
  892. #define EC_CMD_PWM_SET_FAN_DUTY 0x24
  893. struct ec_params_pwm_set_fan_duty {
  894. uint32_t percent;
  895. } __packed;
  896. #define EC_CMD_PWM_SET_DUTY 0x25
  897. /* 16 bit duty cycle, 0xffff = 100% */
  898. #define EC_PWM_MAX_DUTY 0xffff
  899. enum ec_pwm_type {
  900. /* All types, indexed by board-specific enum pwm_channel */
  901. EC_PWM_TYPE_GENERIC = 0,
  902. /* Keyboard backlight */
  903. EC_PWM_TYPE_KB_LIGHT,
  904. /* Display backlight */
  905. EC_PWM_TYPE_DISPLAY_LIGHT,
  906. EC_PWM_TYPE_COUNT,
  907. };
  908. struct ec_params_pwm_set_duty {
  909. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  910. uint8_t pwm_type; /* ec_pwm_type */
  911. uint8_t index; /* Type-specific index, or 0 if unique */
  912. } __packed;
  913. #define EC_CMD_PWM_GET_DUTY 0x26
  914. struct ec_params_pwm_get_duty {
  915. uint8_t pwm_type; /* ec_pwm_type */
  916. uint8_t index; /* Type-specific index, or 0 if unique */
  917. } __packed;
  918. struct ec_response_pwm_get_duty {
  919. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  920. } __packed;
  921. /*****************************************************************************/
  922. /*
  923. * Lightbar commands. This looks worse than it is. Since we only use one HOST
  924. * command to say "talk to the lightbar", we put the "and tell it to do X" part
  925. * into a subcommand. We'll make separate structs for subcommands with
  926. * different input args, so that we know how much to expect.
  927. */
  928. #define EC_CMD_LIGHTBAR_CMD 0x28
  929. struct rgb_s {
  930. uint8_t r, g, b;
  931. };
  932. #define LB_BATTERY_LEVELS 4
  933. /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
  934. * host command, but the alignment is the same regardless. Keep it that way.
  935. */
  936. struct lightbar_params_v0 {
  937. /* Timing */
  938. int32_t google_ramp_up;
  939. int32_t google_ramp_down;
  940. int32_t s3s0_ramp_up;
  941. int32_t s0_tick_delay[2]; /* AC=0/1 */
  942. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  943. int32_t s0s3_ramp_down;
  944. int32_t s3_sleep_for;
  945. int32_t s3_ramp_up;
  946. int32_t s3_ramp_down;
  947. /* Oscillation */
  948. uint8_t new_s0;
  949. uint8_t osc_min[2]; /* AC=0/1 */
  950. uint8_t osc_max[2]; /* AC=0/1 */
  951. uint8_t w_ofs[2]; /* AC=0/1 */
  952. /* Brightness limits based on the backlight and AC. */
  953. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  954. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  955. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  956. /* Battery level thresholds */
  957. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  958. /* Map [AC][battery_level] to color index */
  959. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  960. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  961. /* Color palette */
  962. struct rgb_s color[8]; /* 0-3 are Google colors */
  963. } __packed;
  964. struct lightbar_params_v1 {
  965. /* Timing */
  966. int32_t google_ramp_up;
  967. int32_t google_ramp_down;
  968. int32_t s3s0_ramp_up;
  969. int32_t s0_tick_delay[2]; /* AC=0/1 */
  970. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  971. int32_t s0s3_ramp_down;
  972. int32_t s3_sleep_for;
  973. int32_t s3_ramp_up;
  974. int32_t s3_ramp_down;
  975. int32_t tap_tick_delay;
  976. int32_t tap_display_time;
  977. /* Tap-for-battery params */
  978. uint8_t tap_pct_red;
  979. uint8_t tap_pct_green;
  980. uint8_t tap_seg_min_on;
  981. uint8_t tap_seg_max_on;
  982. uint8_t tap_seg_osc;
  983. uint8_t tap_idx[3];
  984. /* Oscillation */
  985. uint8_t osc_min[2]; /* AC=0/1 */
  986. uint8_t osc_max[2]; /* AC=0/1 */
  987. uint8_t w_ofs[2]; /* AC=0/1 */
  988. /* Brightness limits based on the backlight and AC. */
  989. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  990. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  991. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  992. /* Battery level thresholds */
  993. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  994. /* Map [AC][battery_level] to color index */
  995. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  996. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  997. /* Color palette */
  998. struct rgb_s color[8]; /* 0-3 are Google colors */
  999. } __packed;
  1000. /* Lightbar program */
  1001. #define EC_LB_PROG_LEN 192
  1002. struct lightbar_program {
  1003. uint8_t size;
  1004. uint8_t data[EC_LB_PROG_LEN];
  1005. };
  1006. struct ec_params_lightbar {
  1007. uint8_t cmd; /* Command (see enum lightbar_command) */
  1008. union {
  1009. struct {
  1010. /* no args */
  1011. } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
  1012. version, get_brightness, get_demo, suspend, resume;
  1013. struct {
  1014. uint8_t num;
  1015. } set_brightness, seq, demo;
  1016. struct {
  1017. uint8_t ctrl, reg, value;
  1018. } reg;
  1019. struct {
  1020. uint8_t led, red, green, blue;
  1021. } set_rgb;
  1022. struct {
  1023. uint8_t led;
  1024. } get_rgb;
  1025. struct {
  1026. uint8_t enable;
  1027. } manual_suspend_ctrl;
  1028. struct lightbar_params_v0 set_params_v0;
  1029. struct lightbar_params_v1 set_params_v1;
  1030. struct lightbar_program set_program;
  1031. };
  1032. } __packed;
  1033. struct ec_response_lightbar {
  1034. union {
  1035. struct {
  1036. struct {
  1037. uint8_t reg;
  1038. uint8_t ic0;
  1039. uint8_t ic1;
  1040. } vals[23];
  1041. } dump;
  1042. struct {
  1043. uint8_t num;
  1044. } get_seq, get_brightness, get_demo;
  1045. struct lightbar_params_v0 get_params_v0;
  1046. struct lightbar_params_v1 get_params_v1;
  1047. struct {
  1048. uint32_t num;
  1049. uint32_t flags;
  1050. } version;
  1051. struct {
  1052. uint8_t red, green, blue;
  1053. } get_rgb;
  1054. struct {
  1055. /* no return params */
  1056. } off, on, init, set_brightness, seq, reg, set_rgb,
  1057. demo, set_params_v0, set_params_v1,
  1058. set_program, manual_suspend_ctrl, suspend, resume;
  1059. };
  1060. } __packed;
  1061. /* Lightbar commands */
  1062. enum lightbar_command {
  1063. LIGHTBAR_CMD_DUMP = 0,
  1064. LIGHTBAR_CMD_OFF = 1,
  1065. LIGHTBAR_CMD_ON = 2,
  1066. LIGHTBAR_CMD_INIT = 3,
  1067. LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
  1068. LIGHTBAR_CMD_SEQ = 5,
  1069. LIGHTBAR_CMD_REG = 6,
  1070. LIGHTBAR_CMD_SET_RGB = 7,
  1071. LIGHTBAR_CMD_GET_SEQ = 8,
  1072. LIGHTBAR_CMD_DEMO = 9,
  1073. LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
  1074. LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
  1075. LIGHTBAR_CMD_VERSION = 12,
  1076. LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
  1077. LIGHTBAR_CMD_GET_RGB = 14,
  1078. LIGHTBAR_CMD_GET_DEMO = 15,
  1079. LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
  1080. LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
  1081. LIGHTBAR_CMD_SET_PROGRAM = 18,
  1082. LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
  1083. LIGHTBAR_CMD_SUSPEND = 20,
  1084. LIGHTBAR_CMD_RESUME = 21,
  1085. LIGHTBAR_NUM_CMDS
  1086. };
  1087. /*****************************************************************************/
  1088. /* LED control commands */
  1089. #define EC_CMD_LED_CONTROL 0x29
  1090. enum ec_led_id {
  1091. /* LED to indicate battery state of charge */
  1092. EC_LED_ID_BATTERY_LED = 0,
  1093. /*
  1094. * LED to indicate system power state (on or in suspend).
  1095. * May be on power button or on C-panel.
  1096. */
  1097. EC_LED_ID_POWER_LED,
  1098. /* LED on power adapter or its plug */
  1099. EC_LED_ID_ADAPTER_LED,
  1100. EC_LED_ID_COUNT
  1101. };
  1102. /* LED control flags */
  1103. #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
  1104. #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
  1105. enum ec_led_colors {
  1106. EC_LED_COLOR_RED = 0,
  1107. EC_LED_COLOR_GREEN,
  1108. EC_LED_COLOR_BLUE,
  1109. EC_LED_COLOR_YELLOW,
  1110. EC_LED_COLOR_WHITE,
  1111. EC_LED_COLOR_COUNT
  1112. };
  1113. struct ec_params_led_control {
  1114. uint8_t led_id; /* Which LED to control */
  1115. uint8_t flags; /* Control flags */
  1116. uint8_t brightness[EC_LED_COLOR_COUNT];
  1117. } __packed;
  1118. struct ec_response_led_control {
  1119. /*
  1120. * Available brightness value range.
  1121. *
  1122. * Range 0 means color channel not present.
  1123. * Range 1 means on/off control.
  1124. * Other values means the LED is control by PWM.
  1125. */
  1126. uint8_t brightness_range[EC_LED_COLOR_COUNT];
  1127. } __packed;
  1128. /*****************************************************************************/
  1129. /* Verified boot commands */
  1130. /*
  1131. * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
  1132. * reused for other purposes with version > 0.
  1133. */
  1134. /* Verified boot hash command */
  1135. #define EC_CMD_VBOOT_HASH 0x2A
  1136. struct ec_params_vboot_hash {
  1137. uint8_t cmd; /* enum ec_vboot_hash_cmd */
  1138. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1139. uint8_t nonce_size; /* Nonce size; may be 0 */
  1140. uint8_t reserved0; /* Reserved; set 0 */
  1141. uint32_t offset; /* Offset in flash to hash */
  1142. uint32_t size; /* Number of bytes to hash */
  1143. uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
  1144. } __packed;
  1145. struct ec_response_vboot_hash {
  1146. uint8_t status; /* enum ec_vboot_hash_status */
  1147. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1148. uint8_t digest_size; /* Size of hash digest in bytes */
  1149. uint8_t reserved0; /* Ignore; will be 0 */
  1150. uint32_t offset; /* Offset in flash which was hashed */
  1151. uint32_t size; /* Number of bytes hashed */
  1152. uint8_t hash_digest[64]; /* Hash digest data */
  1153. } __packed;
  1154. enum ec_vboot_hash_cmd {
  1155. EC_VBOOT_HASH_GET = 0, /* Get current hash status */
  1156. EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
  1157. EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
  1158. EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
  1159. };
  1160. enum ec_vboot_hash_type {
  1161. EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
  1162. };
  1163. enum ec_vboot_hash_status {
  1164. EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
  1165. EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
  1166. EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
  1167. };
  1168. /*
  1169. * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
  1170. * If one of these is specified, the EC will automatically update offset and
  1171. * size to the correct values for the specified image (RO or RW).
  1172. */
  1173. #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
  1174. #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
  1175. /*****************************************************************************/
  1176. /*
  1177. * Motion sense commands. We'll make separate structs for sub-commands with
  1178. * different input args, so that we know how much to expect.
  1179. */
  1180. #define EC_CMD_MOTION_SENSE_CMD 0x2B
  1181. /* Motion sense commands */
  1182. enum motionsense_command {
  1183. /*
  1184. * Dump command returns all motion sensor data including motion sense
  1185. * module flags and individual sensor flags.
  1186. */
  1187. MOTIONSENSE_CMD_DUMP = 0,
  1188. /*
  1189. * Info command returns data describing the details of a given sensor,
  1190. * including enum motionsensor_type, enum motionsensor_location, and
  1191. * enum motionsensor_chip.
  1192. */
  1193. MOTIONSENSE_CMD_INFO = 1,
  1194. /*
  1195. * EC Rate command is a setter/getter command for the EC sampling rate
  1196. * of all motion sensors in milliseconds.
  1197. */
  1198. MOTIONSENSE_CMD_EC_RATE = 2,
  1199. /*
  1200. * Sensor ODR command is a setter/getter command for the output data
  1201. * rate of a specific motion sensor in millihertz.
  1202. */
  1203. MOTIONSENSE_CMD_SENSOR_ODR = 3,
  1204. /*
  1205. * Sensor range command is a setter/getter command for the range of
  1206. * a specified motion sensor in +/-G's or +/- deg/s.
  1207. */
  1208. MOTIONSENSE_CMD_SENSOR_RANGE = 4,
  1209. /*
  1210. * Setter/getter command for the keyboard wake angle. When the lid
  1211. * angle is greater than this value, keyboard wake is disabled in S3,
  1212. * and when the lid angle goes less than this value, keyboard wake is
  1213. * enabled. Note, the lid angle measurement is an approximate,
  1214. * un-calibrated value, hence the wake angle isn't exact.
  1215. */
  1216. MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
  1217. /*
  1218. * Returns a single sensor data.
  1219. */
  1220. MOTIONSENSE_CMD_DATA = 6,
  1221. /*
  1222. * Perform low level calibration.. On sensors that support it, ask to
  1223. * do offset calibration.
  1224. */
  1225. MOTIONSENSE_CMD_PERFORM_CALIB = 10,
  1226. /*
  1227. * Sensor Offset command is a setter/getter command for the offset used
  1228. * for calibration. The offsets can be calculated by the host, or via
  1229. * PERFORM_CALIB command.
  1230. */
  1231. MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
  1232. /* Number of motionsense sub-commands. */
  1233. MOTIONSENSE_NUM_CMDS
  1234. };
  1235. enum motionsensor_id {
  1236. EC_MOTION_SENSOR_ACCEL_BASE = 0,
  1237. EC_MOTION_SENSOR_ACCEL_LID = 1,
  1238. EC_MOTION_SENSOR_GYRO = 2,
  1239. /*
  1240. * Note, if more sensors are added and this count changes, the padding
  1241. * in ec_response_motion_sense dump command must be modified.
  1242. */
  1243. EC_MOTION_SENSOR_COUNT = 3
  1244. };
  1245. /* List of motion sensor types. */
  1246. enum motionsensor_type {
  1247. MOTIONSENSE_TYPE_ACCEL = 0,
  1248. MOTIONSENSE_TYPE_GYRO = 1,
  1249. MOTIONSENSE_TYPE_MAG = 2,
  1250. MOTIONSENSE_TYPE_PROX = 3,
  1251. MOTIONSENSE_TYPE_LIGHT = 4,
  1252. MOTIONSENSE_TYPE_ACTIVITY = 5,
  1253. MOTIONSENSE_TYPE_BARO = 6,
  1254. MOTIONSENSE_TYPE_MAX,
  1255. };
  1256. /* List of motion sensor locations. */
  1257. enum motionsensor_location {
  1258. MOTIONSENSE_LOC_BASE = 0,
  1259. MOTIONSENSE_LOC_LID = 1,
  1260. MOTIONSENSE_LOC_MAX,
  1261. };
  1262. /* List of motion sensor chips. */
  1263. enum motionsensor_chip {
  1264. MOTIONSENSE_CHIP_KXCJ9 = 0,
  1265. };
  1266. /* Module flag masks used for the dump sub-command. */
  1267. #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
  1268. /* Sensor flag masks used for the dump sub-command. */
  1269. #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
  1270. /*
  1271. * Send this value for the data element to only perform a read. If you
  1272. * send any other value, the EC will interpret it as data to set and will
  1273. * return the actual value set.
  1274. */
  1275. #define EC_MOTION_SENSE_NO_VALUE -1
  1276. #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
  1277. /* Set Calibration information */
  1278. #define MOTION_SENSE_SET_OFFSET 1
  1279. struct ec_response_motion_sensor_data {
  1280. /* Flags for each sensor. */
  1281. uint8_t flags;
  1282. /* Sensor number the data comes from */
  1283. uint8_t sensor_num;
  1284. /* Each sensor is up to 3-axis. */
  1285. union {
  1286. int16_t data[3];
  1287. struct {
  1288. uint16_t rsvd;
  1289. uint32_t timestamp;
  1290. } __packed;
  1291. struct {
  1292. uint8_t activity; /* motionsensor_activity */
  1293. uint8_t state;
  1294. int16_t add_info[2];
  1295. };
  1296. };
  1297. } __packed;
  1298. struct ec_params_motion_sense {
  1299. uint8_t cmd;
  1300. union {
  1301. /* Used for MOTIONSENSE_CMD_DUMP. */
  1302. struct {
  1303. /* no args */
  1304. } dump;
  1305. /*
  1306. * Used for MOTIONSENSE_CMD_EC_RATE and
  1307. * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
  1308. */
  1309. struct {
  1310. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
  1311. int16_t data;
  1312. } ec_rate, kb_wake_angle;
  1313. /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
  1314. struct {
  1315. uint8_t sensor_num;
  1316. /*
  1317. * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
  1318. * the calibration information in the EC.
  1319. * If unset, just retrieve calibration information.
  1320. */
  1321. uint16_t flags;
  1322. /*
  1323. * Temperature at calibration, in units of 0.01 C
  1324. * 0x8000: invalid / unknown.
  1325. * 0x0: 0C
  1326. * 0x7fff: +327.67C
  1327. */
  1328. int16_t temp;
  1329. /*
  1330. * Offset for calibration.
  1331. * Unit:
  1332. * Accelerometer: 1/1024 g
  1333. * Gyro: 1/1024 deg/s
  1334. * Compass: 1/16 uT
  1335. */
  1336. int16_t offset[3];
  1337. } __packed sensor_offset;
  1338. /* Used for MOTIONSENSE_CMD_INFO. */
  1339. struct {
  1340. uint8_t sensor_num;
  1341. } info;
  1342. /*
  1343. * Used for MOTIONSENSE_CMD_SENSOR_ODR and
  1344. * MOTIONSENSE_CMD_SENSOR_RANGE.
  1345. */
  1346. struct {
  1347. /* Should be element of enum motionsensor_id. */
  1348. uint8_t sensor_num;
  1349. /* Rounding flag, true for round-up, false for down. */
  1350. uint8_t roundup;
  1351. uint16_t reserved;
  1352. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
  1353. int32_t data;
  1354. } sensor_odr, sensor_range;
  1355. };
  1356. } __packed;
  1357. struct ec_response_motion_sense {
  1358. union {
  1359. /* Used for MOTIONSENSE_CMD_DUMP. */
  1360. struct {
  1361. /* Flags representing the motion sensor module. */
  1362. uint8_t module_flags;
  1363. /* Number of sensors managed directly by the EC. */
  1364. uint8_t sensor_count;
  1365. /*
  1366. * Sensor data is truncated if response_max is too small
  1367. * for holding all the data.
  1368. */
  1369. struct ec_response_motion_sensor_data sensor[0];
  1370. } dump;
  1371. /* Used for MOTIONSENSE_CMD_INFO. */
  1372. struct {
  1373. /* Should be element of enum motionsensor_type. */
  1374. uint8_t type;
  1375. /* Should be element of enum motionsensor_location. */
  1376. uint8_t location;
  1377. /* Should be element of enum motionsensor_chip. */
  1378. uint8_t chip;
  1379. } info;
  1380. /* Used for MOTIONSENSE_CMD_DATA */
  1381. struct ec_response_motion_sensor_data data;
  1382. /*
  1383. * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
  1384. * MOTIONSENSE_CMD_SENSOR_RANGE, and
  1385. * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
  1386. */
  1387. struct {
  1388. /* Current value of the parameter queried. */
  1389. int32_t ret;
  1390. } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
  1391. /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
  1392. struct {
  1393. int16_t temp;
  1394. int16_t offset[3];
  1395. } sensor_offset, perform_calib;
  1396. };
  1397. } __packed;
  1398. /*****************************************************************************/
  1399. /* USB charging control commands */
  1400. /* Set USB port charging mode */
  1401. #define EC_CMD_USB_CHARGE_SET_MODE 0x30
  1402. struct ec_params_usb_charge_set_mode {
  1403. uint8_t usb_port_id;
  1404. uint8_t mode;
  1405. } __packed;
  1406. /*****************************************************************************/
  1407. /* Persistent storage for host */
  1408. /* Maximum bytes that can be read/written in a single command */
  1409. #define EC_PSTORE_SIZE_MAX 64
  1410. /* Get persistent storage info */
  1411. #define EC_CMD_PSTORE_INFO 0x40
  1412. struct ec_response_pstore_info {
  1413. /* Persistent storage size, in bytes */
  1414. uint32_t pstore_size;
  1415. /* Access size; read/write offset and size must be a multiple of this */
  1416. uint32_t access_size;
  1417. } __packed;
  1418. /*
  1419. * Read persistent storage
  1420. *
  1421. * Response is params.size bytes of data.
  1422. */
  1423. #define EC_CMD_PSTORE_READ 0x41
  1424. struct ec_params_pstore_read {
  1425. uint32_t offset; /* Byte offset to read */
  1426. uint32_t size; /* Size to read in bytes */
  1427. } __packed;
  1428. /* Write persistent storage */
  1429. #define EC_CMD_PSTORE_WRITE 0x42
  1430. struct ec_params_pstore_write {
  1431. uint32_t offset; /* Byte offset to write */
  1432. uint32_t size; /* Size to write in bytes */
  1433. uint8_t data[EC_PSTORE_SIZE_MAX];
  1434. } __packed;
  1435. /*****************************************************************************/
  1436. /* Real-time clock */
  1437. /* RTC params and response structures */
  1438. struct ec_params_rtc {
  1439. uint32_t time;
  1440. } __packed;
  1441. struct ec_response_rtc {
  1442. uint32_t time;
  1443. } __packed;
  1444. /* These use ec_response_rtc */
  1445. #define EC_CMD_RTC_GET_VALUE 0x44
  1446. #define EC_CMD_RTC_GET_ALARM 0x45
  1447. /* These all use ec_params_rtc */
  1448. #define EC_CMD_RTC_SET_VALUE 0x46
  1449. #define EC_CMD_RTC_SET_ALARM 0x47
  1450. /*****************************************************************************/
  1451. /* Port80 log access */
  1452. /* Maximum entries that can be read/written in a single command */
  1453. #define EC_PORT80_SIZE_MAX 32
  1454. /* Get last port80 code from previous boot */
  1455. #define EC_CMD_PORT80_LAST_BOOT 0x48
  1456. #define EC_CMD_PORT80_READ 0x48
  1457. enum ec_port80_subcmd {
  1458. EC_PORT80_GET_INFO = 0,
  1459. EC_PORT80_READ_BUFFER,
  1460. };
  1461. struct ec_params_port80_read {
  1462. uint16_t subcmd;
  1463. union {
  1464. struct {
  1465. uint32_t offset;
  1466. uint32_t num_entries;
  1467. } read_buffer;
  1468. };
  1469. } __packed;
  1470. struct ec_response_port80_read {
  1471. union {
  1472. struct {
  1473. uint32_t writes;
  1474. uint32_t history_size;
  1475. uint32_t last_boot;
  1476. } get_info;
  1477. struct {
  1478. uint16_t codes[EC_PORT80_SIZE_MAX];
  1479. } data;
  1480. };
  1481. } __packed;
  1482. struct ec_response_port80_last_boot {
  1483. uint16_t code;
  1484. } __packed;
  1485. /*****************************************************************************/
  1486. /* Thermal engine commands. Note that there are two implementations. We'll
  1487. * reuse the command number, but the data and behavior is incompatible.
  1488. * Version 0 is what originally shipped on Link.
  1489. * Version 1 separates the CPU thermal limits from the fan control.
  1490. */
  1491. #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
  1492. #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
  1493. /* The version 0 structs are opaque. You have to know what they are for
  1494. * the get/set commands to make any sense.
  1495. */
  1496. /* Version 0 - set */
  1497. struct ec_params_thermal_set_threshold {
  1498. uint8_t sensor_type;
  1499. uint8_t threshold_id;
  1500. uint16_t value;
  1501. } __packed;
  1502. /* Version 0 - get */
  1503. struct ec_params_thermal_get_threshold {
  1504. uint8_t sensor_type;
  1505. uint8_t threshold_id;
  1506. } __packed;
  1507. struct ec_response_thermal_get_threshold {
  1508. uint16_t value;
  1509. } __packed;
  1510. /* The version 1 structs are visible. */
  1511. enum ec_temp_thresholds {
  1512. EC_TEMP_THRESH_WARN = 0,
  1513. EC_TEMP_THRESH_HIGH,
  1514. EC_TEMP_THRESH_HALT,
  1515. EC_TEMP_THRESH_COUNT
  1516. };
  1517. /* Thermal configuration for one temperature sensor. Temps are in degrees K.
  1518. * Zero values will be silently ignored by the thermal task.
  1519. */
  1520. struct ec_thermal_config {
  1521. uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
  1522. uint32_t temp_fan_off; /* no active cooling needed */
  1523. uint32_t temp_fan_max; /* max active cooling needed */
  1524. } __packed;
  1525. /* Version 1 - get config for one sensor. */
  1526. struct ec_params_thermal_get_threshold_v1 {
  1527. uint32_t sensor_num;
  1528. } __packed;
  1529. /* This returns a struct ec_thermal_config */
  1530. /* Version 1 - set config for one sensor.
  1531. * Use read-modify-write for best results! */
  1532. struct ec_params_thermal_set_threshold_v1 {
  1533. uint32_t sensor_num;
  1534. struct ec_thermal_config cfg;
  1535. } __packed;
  1536. /* This returns no data */
  1537. /****************************************************************************/
  1538. /* Toggle automatic fan control */
  1539. #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
  1540. /* Get TMP006 calibration data */
  1541. #define EC_CMD_TMP006_GET_CALIBRATION 0x53
  1542. struct ec_params_tmp006_get_calibration {
  1543. uint8_t index;
  1544. } __packed;
  1545. struct ec_response_tmp006_get_calibration {
  1546. float s0;
  1547. float b0;
  1548. float b1;
  1549. float b2;
  1550. } __packed;
  1551. /* Set TMP006 calibration data */
  1552. #define EC_CMD_TMP006_SET_CALIBRATION 0x54
  1553. struct ec_params_tmp006_set_calibration {
  1554. uint8_t index;
  1555. uint8_t reserved[3]; /* Reserved; set 0 */
  1556. float s0;
  1557. float b0;
  1558. float b1;
  1559. float b2;
  1560. } __packed;
  1561. /* Read raw TMP006 data */
  1562. #define EC_CMD_TMP006_GET_RAW 0x55
  1563. struct ec_params_tmp006_get_raw {
  1564. uint8_t index;
  1565. } __packed;
  1566. struct ec_response_tmp006_get_raw {
  1567. int32_t t; /* In 1/100 K */
  1568. int32_t v; /* In nV */
  1569. };
  1570. /*****************************************************************************/
  1571. /* MKBP - Matrix KeyBoard Protocol */
  1572. /*
  1573. * Read key state
  1574. *
  1575. * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
  1576. * expected response size.
  1577. *
  1578. * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
  1579. * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
  1580. * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
  1581. */
  1582. #define EC_CMD_MKBP_STATE 0x60
  1583. /*
  1584. * Provide information about various MKBP things. See enum ec_mkbp_info_type.
  1585. */
  1586. #define EC_CMD_MKBP_INFO 0x61
  1587. struct ec_response_mkbp_info {
  1588. uint32_t rows;
  1589. uint32_t cols;
  1590. /* Formerly "switches", which was 0. */
  1591. uint8_t reserved;
  1592. } __packed;
  1593. struct ec_params_mkbp_info {
  1594. uint8_t info_type;
  1595. uint8_t event_type;
  1596. } __packed;
  1597. enum ec_mkbp_info_type {
  1598. /*
  1599. * Info about the keyboard matrix: number of rows and columns.
  1600. *
  1601. * Returns struct ec_response_mkbp_info.
  1602. */
  1603. EC_MKBP_INFO_KBD = 0,
  1604. /*
  1605. * For buttons and switches, info about which specifically are
  1606. * supported. event_type must be set to one of the values in enum
  1607. * ec_mkbp_event.
  1608. *
  1609. * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
  1610. * bitmask indicating which buttons or switches are present. See the
  1611. * bit inidices below.
  1612. */
  1613. EC_MKBP_INFO_SUPPORTED = 1,
  1614. /*
  1615. * Instantaneous state of buttons and switches.
  1616. *
  1617. * event_type must be set to one of the values in enum ec_mkbp_event.
  1618. *
  1619. * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
  1620. * indicating the current state of the keyboard matrix.
  1621. *
  1622. * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
  1623. * event state.
  1624. *
  1625. * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
  1626. * state of supported buttons.
  1627. *
  1628. * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
  1629. * state of supported switches.
  1630. */
  1631. EC_MKBP_INFO_CURRENT = 2,
  1632. };
  1633. /* Simulate key press */
  1634. #define EC_CMD_MKBP_SIMULATE_KEY 0x62
  1635. struct ec_params_mkbp_simulate_key {
  1636. uint8_t col;
  1637. uint8_t row;
  1638. uint8_t pressed;
  1639. } __packed;
  1640. /* Configure keyboard scanning */
  1641. #define EC_CMD_MKBP_SET_CONFIG 0x64
  1642. #define EC_CMD_MKBP_GET_CONFIG 0x65
  1643. /* flags */
  1644. enum mkbp_config_flags {
  1645. EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
  1646. };
  1647. enum mkbp_config_valid {
  1648. EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
  1649. EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
  1650. EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
  1651. EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
  1652. EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
  1653. EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
  1654. EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
  1655. };
  1656. /* Configuration for our key scanning algorithm */
  1657. struct ec_mkbp_config {
  1658. uint32_t valid_mask; /* valid fields */
  1659. uint8_t flags; /* some flags (enum mkbp_config_flags) */
  1660. uint8_t valid_flags; /* which flags are valid */
  1661. uint16_t scan_period_us; /* period between start of scans */
  1662. /* revert to interrupt mode after no activity for this long */
  1663. uint32_t poll_timeout_us;
  1664. /*
  1665. * minimum post-scan relax time. Once we finish a scan we check
  1666. * the time until we are due to start the next one. If this time is
  1667. * shorter this field, we use this instead.
  1668. */
  1669. uint16_t min_post_scan_delay_us;
  1670. /* delay between setting up output and waiting for it to settle */
  1671. uint16_t output_settle_us;
  1672. uint16_t debounce_down_us; /* time for debounce on key down */
  1673. uint16_t debounce_up_us; /* time for debounce on key up */
  1674. /* maximum depth to allow for fifo (0 = no keyscan output) */
  1675. uint8_t fifo_max_depth;
  1676. } __packed;
  1677. struct ec_params_mkbp_set_config {
  1678. struct ec_mkbp_config config;
  1679. } __packed;
  1680. struct ec_response_mkbp_get_config {
  1681. struct ec_mkbp_config config;
  1682. } __packed;
  1683. /* Run the key scan emulation */
  1684. #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
  1685. enum ec_keyscan_seq_cmd {
  1686. EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
  1687. EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
  1688. EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
  1689. EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
  1690. EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
  1691. };
  1692. enum ec_collect_flags {
  1693. /*
  1694. * Indicates this scan was processed by the EC. Due to timing, some
  1695. * scans may be skipped.
  1696. */
  1697. EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
  1698. };
  1699. struct ec_collect_item {
  1700. uint8_t flags; /* some flags (enum ec_collect_flags) */
  1701. };
  1702. struct ec_params_keyscan_seq_ctrl {
  1703. uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
  1704. union {
  1705. struct {
  1706. uint8_t active; /* still active */
  1707. uint8_t num_items; /* number of items */
  1708. /* Current item being presented */
  1709. uint8_t cur_item;
  1710. } status;
  1711. struct {
  1712. /*
  1713. * Absolute time for this scan, measured from the
  1714. * start of the sequence.
  1715. */
  1716. uint32_t time_us;
  1717. uint8_t scan[0]; /* keyscan data */
  1718. } add;
  1719. struct {
  1720. uint8_t start_item; /* First item to return */
  1721. uint8_t num_items; /* Number of items to return */
  1722. } collect;
  1723. };
  1724. } __packed;
  1725. struct ec_result_keyscan_seq_ctrl {
  1726. union {
  1727. struct {
  1728. uint8_t num_items; /* Number of items */
  1729. /* Data for each item */
  1730. struct ec_collect_item item[0];
  1731. } collect;
  1732. };
  1733. } __packed;
  1734. /*
  1735. * Command for retrieving the next pending MKBP event from the EC device
  1736. *
  1737. * The device replies with UNAVAILABLE if there aren't any pending events.
  1738. */
  1739. #define EC_CMD_GET_NEXT_EVENT 0x67
  1740. enum ec_mkbp_event {
  1741. /* Keyboard matrix changed. The event data is the new matrix state. */
  1742. EC_MKBP_EVENT_KEY_MATRIX = 0,
  1743. /* New host event. The event data is 4 bytes of host event flags. */
  1744. EC_MKBP_EVENT_HOST_EVENT = 1,
  1745. /* New Sensor FIFO data. The event data is fifo_info structure. */
  1746. EC_MKBP_EVENT_SENSOR_FIFO = 2,
  1747. /* The state of the non-matrixed buttons have changed. */
  1748. EC_MKBP_EVENT_BUTTON = 3,
  1749. /* The state of the switches have changed. */
  1750. EC_MKBP_EVENT_SWITCH = 4,
  1751. /* EC sent a sysrq command */
  1752. EC_MKBP_EVENT_SYSRQ = 6,
  1753. /* Number of MKBP events */
  1754. EC_MKBP_EVENT_COUNT,
  1755. };
  1756. union ec_response_get_next_data {
  1757. uint8_t key_matrix[13];
  1758. /* Unaligned */
  1759. uint32_t host_event;
  1760. uint32_t buttons;
  1761. uint32_t switches;
  1762. uint32_t sysrq;
  1763. } __packed;
  1764. struct ec_response_get_next_event {
  1765. uint8_t event_type;
  1766. /* Followed by event data if any */
  1767. union ec_response_get_next_data data;
  1768. } __packed;
  1769. /* Bit indices for buttons and switches.*/
  1770. /* Buttons */
  1771. #define EC_MKBP_POWER_BUTTON 0
  1772. #define EC_MKBP_VOL_UP 1
  1773. #define EC_MKBP_VOL_DOWN 2
  1774. /* Switches */
  1775. #define EC_MKBP_LID_OPEN 0
  1776. #define EC_MKBP_TABLET_MODE 1
  1777. /*****************************************************************************/
  1778. /* Temperature sensor commands */
  1779. /* Read temperature sensor info */
  1780. #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
  1781. struct ec_params_temp_sensor_get_info {
  1782. uint8_t id;
  1783. } __packed;
  1784. struct ec_response_temp_sensor_get_info {
  1785. char sensor_name[32];
  1786. uint8_t sensor_type;
  1787. } __packed;
  1788. /*****************************************************************************/
  1789. /*
  1790. * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
  1791. * commands accidentally sent to the wrong interface. See the ACPI section
  1792. * below.
  1793. */
  1794. /*****************************************************************************/
  1795. /* Host event commands */
  1796. /*
  1797. * Host event mask params and response structures, shared by all of the host
  1798. * event commands below.
  1799. */
  1800. struct ec_params_host_event_mask {
  1801. uint32_t mask;
  1802. } __packed;
  1803. struct ec_response_host_event_mask {
  1804. uint32_t mask;
  1805. } __packed;
  1806. /* These all use ec_response_host_event_mask */
  1807. #define EC_CMD_HOST_EVENT_GET_B 0x87
  1808. #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
  1809. #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
  1810. #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
  1811. /* These all use ec_params_host_event_mask */
  1812. #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
  1813. #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
  1814. #define EC_CMD_HOST_EVENT_CLEAR 0x8c
  1815. #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
  1816. #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
  1817. /*****************************************************************************/
  1818. /* Switch commands */
  1819. /* Enable/disable LCD backlight */
  1820. #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
  1821. struct ec_params_switch_enable_backlight {
  1822. uint8_t enabled;
  1823. } __packed;
  1824. /* Enable/disable WLAN/Bluetooth */
  1825. #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
  1826. #define EC_VER_SWITCH_ENABLE_WIRELESS 1
  1827. /* Version 0 params; no response */
  1828. struct ec_params_switch_enable_wireless_v0 {
  1829. uint8_t enabled;
  1830. } __packed;
  1831. /* Version 1 params */
  1832. struct ec_params_switch_enable_wireless_v1 {
  1833. /* Flags to enable now */
  1834. uint8_t now_flags;
  1835. /* Which flags to copy from now_flags */
  1836. uint8_t now_mask;
  1837. /*
  1838. * Flags to leave enabled in S3, if they're on at the S0->S3
  1839. * transition. (Other flags will be disabled by the S0->S3
  1840. * transition.)
  1841. */
  1842. uint8_t suspend_flags;
  1843. /* Which flags to copy from suspend_flags */
  1844. uint8_t suspend_mask;
  1845. } __packed;
  1846. /* Version 1 response */
  1847. struct ec_response_switch_enable_wireless_v1 {
  1848. /* Flags to enable now */
  1849. uint8_t now_flags;
  1850. /* Flags to leave enabled in S3 */
  1851. uint8_t suspend_flags;
  1852. } __packed;
  1853. /*****************************************************************************/
  1854. /* GPIO commands. Only available on EC if write protect has been disabled. */
  1855. /* Set GPIO output value */
  1856. #define EC_CMD_GPIO_SET 0x92
  1857. struct ec_params_gpio_set {
  1858. char name[32];
  1859. uint8_t val;
  1860. } __packed;
  1861. /* Get GPIO value */
  1862. #define EC_CMD_GPIO_GET 0x93
  1863. /* Version 0 of input params and response */
  1864. struct ec_params_gpio_get {
  1865. char name[32];
  1866. } __packed;
  1867. struct ec_response_gpio_get {
  1868. uint8_t val;
  1869. } __packed;
  1870. /* Version 1 of input params and response */
  1871. struct ec_params_gpio_get_v1 {
  1872. uint8_t subcmd;
  1873. union {
  1874. struct {
  1875. char name[32];
  1876. } get_value_by_name;
  1877. struct {
  1878. uint8_t index;
  1879. } get_info;
  1880. };
  1881. } __packed;
  1882. struct ec_response_gpio_get_v1 {
  1883. union {
  1884. struct {
  1885. uint8_t val;
  1886. } get_value_by_name, get_count;
  1887. struct {
  1888. uint8_t val;
  1889. char name[32];
  1890. uint32_t flags;
  1891. } get_info;
  1892. };
  1893. } __packed;
  1894. enum gpio_get_subcmd {
  1895. EC_GPIO_GET_BY_NAME = 0,
  1896. EC_GPIO_GET_COUNT = 1,
  1897. EC_GPIO_GET_INFO = 2,
  1898. };
  1899. /*****************************************************************************/
  1900. /* I2C commands. Only available when flash write protect is unlocked. */
  1901. /*
  1902. * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
  1903. * removed soon. Use EC_CMD_I2C_XFER instead.
  1904. */
  1905. /* Read I2C bus */
  1906. #define EC_CMD_I2C_READ 0x94
  1907. struct ec_params_i2c_read {
  1908. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  1909. uint8_t read_size; /* Either 8 or 16. */
  1910. uint8_t port;
  1911. uint8_t offset;
  1912. } __packed;
  1913. struct ec_response_i2c_read {
  1914. uint16_t data;
  1915. } __packed;
  1916. /* Write I2C bus */
  1917. #define EC_CMD_I2C_WRITE 0x95
  1918. struct ec_params_i2c_write {
  1919. uint16_t data;
  1920. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  1921. uint8_t write_size; /* Either 8 or 16. */
  1922. uint8_t port;
  1923. uint8_t offset;
  1924. } __packed;
  1925. /*****************************************************************************/
  1926. /* Charge state commands. Only available when flash write protect unlocked. */
  1927. /* Force charge state machine to stop charging the battery or force it to
  1928. * discharge the battery.
  1929. */
  1930. #define EC_CMD_CHARGE_CONTROL 0x96
  1931. #define EC_VER_CHARGE_CONTROL 1
  1932. enum ec_charge_control_mode {
  1933. CHARGE_CONTROL_NORMAL = 0,
  1934. CHARGE_CONTROL_IDLE,
  1935. CHARGE_CONTROL_DISCHARGE,
  1936. };
  1937. struct ec_params_charge_control {
  1938. uint32_t mode; /* enum charge_control_mode */
  1939. } __packed;
  1940. /*****************************************************************************/
  1941. /* Console commands. Only available when flash write protect is unlocked. */
  1942. /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
  1943. #define EC_CMD_CONSOLE_SNAPSHOT 0x97
  1944. /*
  1945. * Read data from the saved snapshot. If the subcmd parameter is
  1946. * CONSOLE_READ_NEXT, this will return data starting from the beginning of
  1947. * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
  1948. * end of the previous snapshot.
  1949. *
  1950. * The params are only looked at in version >= 1 of this command. Prior
  1951. * versions will just default to CONSOLE_READ_NEXT behavior.
  1952. *
  1953. * Response is null-terminated string. Empty string, if there is no more
  1954. * remaining output.
  1955. */
  1956. #define EC_CMD_CONSOLE_READ 0x98
  1957. enum ec_console_read_subcmd {
  1958. CONSOLE_READ_NEXT = 0,
  1959. CONSOLE_READ_RECENT
  1960. };
  1961. struct ec_params_console_read_v1 {
  1962. uint8_t subcmd; /* enum ec_console_read_subcmd */
  1963. } __packed;
  1964. /*****************************************************************************/
  1965. /*
  1966. * Cut off battery power immediately or after the host has shut down.
  1967. *
  1968. * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
  1969. * EC_RES_SUCCESS if the command was successful.
  1970. * EC_RES_ERROR if the cut off command failed.
  1971. */
  1972. #define EC_CMD_BATTERY_CUT_OFF 0x99
  1973. #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
  1974. struct ec_params_battery_cutoff {
  1975. uint8_t flags;
  1976. } __packed;
  1977. /*****************************************************************************/
  1978. /* USB port mux control. */
  1979. /*
  1980. * Switch USB mux or return to automatic switching.
  1981. */
  1982. #define EC_CMD_USB_MUX 0x9a
  1983. struct ec_params_usb_mux {
  1984. uint8_t mux;
  1985. } __packed;
  1986. /*****************************************************************************/
  1987. /* LDOs / FETs control. */
  1988. enum ec_ldo_state {
  1989. EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
  1990. EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
  1991. };
  1992. /*
  1993. * Switch on/off a LDO.
  1994. */
  1995. #define EC_CMD_LDO_SET 0x9b
  1996. struct ec_params_ldo_set {
  1997. uint8_t index;
  1998. uint8_t state;
  1999. } __packed;
  2000. /*
  2001. * Get LDO state.
  2002. */
  2003. #define EC_CMD_LDO_GET 0x9c
  2004. struct ec_params_ldo_get {
  2005. uint8_t index;
  2006. } __packed;
  2007. struct ec_response_ldo_get {
  2008. uint8_t state;
  2009. } __packed;
  2010. /*****************************************************************************/
  2011. /* Power info. */
  2012. /*
  2013. * Get power info.
  2014. */
  2015. #define EC_CMD_POWER_INFO 0x9d
  2016. struct ec_response_power_info {
  2017. uint32_t usb_dev_type;
  2018. uint16_t voltage_ac;
  2019. uint16_t voltage_system;
  2020. uint16_t current_system;
  2021. uint16_t usb_current_limit;
  2022. } __packed;
  2023. /*****************************************************************************/
  2024. /* I2C passthru command */
  2025. #define EC_CMD_I2C_PASSTHRU 0x9e
  2026. /* Read data; if not present, message is a write */
  2027. #define EC_I2C_FLAG_READ (1 << 15)
  2028. /* Mask for address */
  2029. #define EC_I2C_ADDR_MASK 0x3ff
  2030. #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
  2031. #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
  2032. /* Any error */
  2033. #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
  2034. struct ec_params_i2c_passthru_msg {
  2035. uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
  2036. uint16_t len; /* Number of bytes to read or write */
  2037. } __packed;
  2038. struct ec_params_i2c_passthru {
  2039. uint8_t port; /* I2C port number */
  2040. uint8_t num_msgs; /* Number of messages */
  2041. struct ec_params_i2c_passthru_msg msg[];
  2042. /* Data to write for all messages is concatenated here */
  2043. } __packed;
  2044. struct ec_response_i2c_passthru {
  2045. uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
  2046. uint8_t num_msgs; /* Number of messages processed */
  2047. uint8_t data[]; /* Data read by messages concatenated here */
  2048. } __packed;
  2049. /*****************************************************************************/
  2050. /* Power button hang detect */
  2051. #define EC_CMD_HANG_DETECT 0x9f
  2052. /* Reasons to start hang detection timer */
  2053. /* Power button pressed */
  2054. #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
  2055. /* Lid closed */
  2056. #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
  2057. /* Lid opened */
  2058. #define EC_HANG_START_ON_LID_OPEN (1 << 2)
  2059. /* Start of AP S3->S0 transition (booting or resuming from suspend) */
  2060. #define EC_HANG_START_ON_RESUME (1 << 3)
  2061. /* Reasons to cancel hang detection */
  2062. /* Power button released */
  2063. #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
  2064. /* Any host command from AP received */
  2065. #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
  2066. /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
  2067. #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
  2068. /*
  2069. * If this flag is set, all the other fields are ignored, and the hang detect
  2070. * timer is started. This provides the AP a way to start the hang timer
  2071. * without reconfiguring any of the other hang detect settings. Note that
  2072. * you must previously have configured the timeouts.
  2073. */
  2074. #define EC_HANG_START_NOW (1 << 30)
  2075. /*
  2076. * If this flag is set, all the other fields are ignored (including
  2077. * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
  2078. * without reconfiguring any of the other hang detect settings.
  2079. */
  2080. #define EC_HANG_STOP_NOW (1 << 31)
  2081. struct ec_params_hang_detect {
  2082. /* Flags; see EC_HANG_* */
  2083. uint32_t flags;
  2084. /* Timeout in msec before generating host event, if enabled */
  2085. uint16_t host_event_timeout_msec;
  2086. /* Timeout in msec before generating warm reboot, if enabled */
  2087. uint16_t warm_reboot_timeout_msec;
  2088. } __packed;
  2089. /*****************************************************************************/
  2090. /* Commands for battery charging */
  2091. /*
  2092. * This is the single catch-all host command to exchange data regarding the
  2093. * charge state machine (v2 and up).
  2094. */
  2095. #define EC_CMD_CHARGE_STATE 0xa0
  2096. /* Subcommands for this host command */
  2097. enum charge_state_command {
  2098. CHARGE_STATE_CMD_GET_STATE,
  2099. CHARGE_STATE_CMD_GET_PARAM,
  2100. CHARGE_STATE_CMD_SET_PARAM,
  2101. CHARGE_STATE_NUM_CMDS
  2102. };
  2103. /*
  2104. * Known param numbers are defined here. Ranges are reserved for board-specific
  2105. * params, which are handled by the particular implementations.
  2106. */
  2107. enum charge_state_params {
  2108. CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
  2109. CS_PARAM_CHG_CURRENT, /* charger current limit */
  2110. CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
  2111. CS_PARAM_CHG_STATUS, /* charger-specific status */
  2112. CS_PARAM_CHG_OPTION, /* charger-specific options */
  2113. /* How many so far? */
  2114. CS_NUM_BASE_PARAMS,
  2115. /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
  2116. CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
  2117. CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
  2118. /* Other custom param ranges go here... */
  2119. };
  2120. struct ec_params_charge_state {
  2121. uint8_t cmd; /* enum charge_state_command */
  2122. union {
  2123. struct {
  2124. /* no args */
  2125. } get_state;
  2126. struct {
  2127. uint32_t param; /* enum charge_state_param */
  2128. } get_param;
  2129. struct {
  2130. uint32_t param; /* param to set */
  2131. uint32_t value; /* value to set */
  2132. } set_param;
  2133. };
  2134. } __packed;
  2135. struct ec_response_charge_state {
  2136. union {
  2137. struct {
  2138. int ac;
  2139. int chg_voltage;
  2140. int chg_current;
  2141. int chg_input_current;
  2142. int batt_state_of_charge;
  2143. } get_state;
  2144. struct {
  2145. uint32_t value;
  2146. } get_param;
  2147. struct {
  2148. /* no return values */
  2149. } set_param;
  2150. };
  2151. } __packed;
  2152. /*
  2153. * Set maximum battery charging current.
  2154. */
  2155. #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
  2156. struct ec_params_current_limit {
  2157. uint32_t limit; /* in mA */
  2158. } __packed;
  2159. /*
  2160. * Set maximum external power current.
  2161. */
  2162. #define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
  2163. struct ec_params_ext_power_current_limit {
  2164. uint32_t limit; /* in mA */
  2165. } __packed;
  2166. /* Inform the EC when entering a sleep state */
  2167. #define EC_CMD_HOST_SLEEP_EVENT 0xa9
  2168. enum host_sleep_event {
  2169. HOST_SLEEP_EVENT_S3_SUSPEND = 1,
  2170. HOST_SLEEP_EVENT_S3_RESUME = 2,
  2171. HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
  2172. HOST_SLEEP_EVENT_S0IX_RESUME = 4
  2173. };
  2174. struct ec_params_host_sleep_event {
  2175. uint8_t sleep_event;
  2176. } __packed;
  2177. /*****************************************************************************/
  2178. /* Smart battery pass-through */
  2179. /* Get / Set 16-bit smart battery registers */
  2180. #define EC_CMD_SB_READ_WORD 0xb0
  2181. #define EC_CMD_SB_WRITE_WORD 0xb1
  2182. /* Get / Set string smart battery parameters
  2183. * formatted as SMBUS "block".
  2184. */
  2185. #define EC_CMD_SB_READ_BLOCK 0xb2
  2186. #define EC_CMD_SB_WRITE_BLOCK 0xb3
  2187. struct ec_params_sb_rd {
  2188. uint8_t reg;
  2189. } __packed;
  2190. struct ec_response_sb_rd_word {
  2191. uint16_t value;
  2192. } __packed;
  2193. struct ec_params_sb_wr_word {
  2194. uint8_t reg;
  2195. uint16_t value;
  2196. } __packed;
  2197. struct ec_response_sb_rd_block {
  2198. uint8_t data[32];
  2199. } __packed;
  2200. struct ec_params_sb_wr_block {
  2201. uint8_t reg;
  2202. uint16_t data[32];
  2203. } __packed;
  2204. /*****************************************************************************/
  2205. /* Battery vendor parameters
  2206. *
  2207. * Get or set vendor-specific parameters in the battery. Implementations may
  2208. * differ between boards or batteries. On a set operation, the response
  2209. * contains the actual value set, which may be rounded or clipped from the
  2210. * requested value.
  2211. */
  2212. #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
  2213. enum ec_battery_vendor_param_mode {
  2214. BATTERY_VENDOR_PARAM_MODE_GET = 0,
  2215. BATTERY_VENDOR_PARAM_MODE_SET,
  2216. };
  2217. struct ec_params_battery_vendor_param {
  2218. uint32_t param;
  2219. uint32_t value;
  2220. uint8_t mode;
  2221. } __packed;
  2222. struct ec_response_battery_vendor_param {
  2223. uint32_t value;
  2224. } __packed;
  2225. /*****************************************************************************/
  2226. /* System commands */
  2227. /*
  2228. * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
  2229. * necessarily reboot the EC. Rename to "image" or something similar?
  2230. */
  2231. #define EC_CMD_REBOOT_EC 0xd2
  2232. /* Command */
  2233. enum ec_reboot_cmd {
  2234. EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
  2235. EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
  2236. EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
  2237. /* (command 3 was jump to RW-B) */
  2238. EC_REBOOT_COLD = 4, /* Cold-reboot */
  2239. EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
  2240. EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
  2241. };
  2242. /* Flags for ec_params_reboot_ec.reboot_flags */
  2243. #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
  2244. #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
  2245. struct ec_params_reboot_ec {
  2246. uint8_t cmd; /* enum ec_reboot_cmd */
  2247. uint8_t flags; /* See EC_REBOOT_FLAG_* */
  2248. } __packed;
  2249. /*
  2250. * Get information on last EC panic.
  2251. *
  2252. * Returns variable-length platform-dependent panic information. See panic.h
  2253. * for details.
  2254. */
  2255. #define EC_CMD_GET_PANIC_INFO 0xd3
  2256. /*****************************************************************************/
  2257. /*
  2258. * ACPI commands
  2259. *
  2260. * These are valid ONLY on the ACPI command/data port.
  2261. */
  2262. /*
  2263. * ACPI Read Embedded Controller
  2264. *
  2265. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  2266. *
  2267. * Use the following sequence:
  2268. *
  2269. * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
  2270. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  2271. * - Write address to EC_LPC_ADDR_ACPI_DATA
  2272. * - Wait for EC_LPC_CMDR_DATA bit to set
  2273. * - Read value from EC_LPC_ADDR_ACPI_DATA
  2274. */
  2275. #define EC_CMD_ACPI_READ 0x80
  2276. /*
  2277. * ACPI Write Embedded Controller
  2278. *
  2279. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  2280. *
  2281. * Use the following sequence:
  2282. *
  2283. * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
  2284. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  2285. * - Write address to EC_LPC_ADDR_ACPI_DATA
  2286. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  2287. * - Write value to EC_LPC_ADDR_ACPI_DATA
  2288. */
  2289. #define EC_CMD_ACPI_WRITE 0x81
  2290. /*
  2291. * ACPI Query Embedded Controller
  2292. *
  2293. * This clears the lowest-order bit in the currently pending host events, and
  2294. * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
  2295. * event 0x80000000 = 32), or 0 if no event was pending.
  2296. */
  2297. #define EC_CMD_ACPI_QUERY_EVENT 0x84
  2298. /* Valid addresses in ACPI memory space, for read/write commands */
  2299. /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
  2300. #define EC_ACPI_MEM_VERSION 0x00
  2301. /*
  2302. * Test location; writing value here updates test compliment byte to (0xff -
  2303. * value).
  2304. */
  2305. #define EC_ACPI_MEM_TEST 0x01
  2306. /* Test compliment; writes here are ignored. */
  2307. #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
  2308. /* Keyboard backlight brightness percent (0 - 100) */
  2309. #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
  2310. /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
  2311. #define EC_ACPI_MEM_FAN_DUTY 0x04
  2312. /*
  2313. * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
  2314. * independent thresholds attached to them. The current value of the ID
  2315. * register determines which sensor is affected by the THRESHOLD and COMMIT
  2316. * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
  2317. * as the memory-mapped sensors. The COMMIT register applies those settings.
  2318. *
  2319. * The spec does not mandate any way to read back the threshold settings
  2320. * themselves, but when a threshold is crossed the AP needs a way to determine
  2321. * which sensor(s) are responsible. Each reading of the ID register clears and
  2322. * returns one sensor ID that has crossed one of its threshold (in either
  2323. * direction) since the last read. A value of 0xFF means "no new thresholds
  2324. * have tripped". Setting or enabling the thresholds for a sensor will clear
  2325. * the unread event count for that sensor.
  2326. */
  2327. #define EC_ACPI_MEM_TEMP_ID 0x05
  2328. #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
  2329. #define EC_ACPI_MEM_TEMP_COMMIT 0x07
  2330. /*
  2331. * Here are the bits for the COMMIT register:
  2332. * bit 0 selects the threshold index for the chosen sensor (0/1)
  2333. * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
  2334. * Each write to the commit register affects one threshold.
  2335. */
  2336. #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
  2337. #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
  2338. /*
  2339. * Example:
  2340. *
  2341. * Set the thresholds for sensor 2 to 50 C and 60 C:
  2342. * write 2 to [0x05] -- select temp sensor 2
  2343. * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
  2344. * write 0x2 to [0x07] -- enable threshold 0 with this value
  2345. * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
  2346. * write 0x3 to [0x07] -- enable threshold 1 with this value
  2347. *
  2348. * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
  2349. * write 2 to [0x05] -- select temp sensor 2
  2350. * write 0x1 to [0x07] -- disable threshold 1
  2351. */
  2352. /* DPTF battery charging current limit */
  2353. #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
  2354. /* Charging limit is specified in 64 mA steps */
  2355. #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
  2356. /* Value to disable DPTF battery charging limit */
  2357. #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
  2358. /* Current version of ACPI memory address space */
  2359. #define EC_ACPI_MEM_VERSION_CURRENT 1
  2360. /*****************************************************************************/
  2361. /*
  2362. * Special commands
  2363. *
  2364. * These do not follow the normal rules for commands. See each command for
  2365. * details.
  2366. */
  2367. /*
  2368. * Reboot NOW
  2369. *
  2370. * This command will work even when the EC LPC interface is busy, because the
  2371. * reboot command is processed at interrupt level. Note that when the EC
  2372. * reboots, the host will reboot too, so there is no response to this command.
  2373. *
  2374. * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
  2375. */
  2376. #define EC_CMD_REBOOT 0xd1 /* Think "die" */
  2377. /*
  2378. * Resend last response (not supported on LPC).
  2379. *
  2380. * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
  2381. * there was no previous command, or the previous command's response was too
  2382. * big to save.
  2383. */
  2384. #define EC_CMD_RESEND_RESPONSE 0xdb
  2385. /*
  2386. * This header byte on a command indicate version 0. Any header byte less
  2387. * than this means that we are talking to an old EC which doesn't support
  2388. * versioning. In that case, we assume version 0.
  2389. *
  2390. * Header bytes greater than this indicate a later version. For example,
  2391. * EC_CMD_VERSION0 + 1 means we are using version 1.
  2392. *
  2393. * The old EC interface must not use commands 0xdc or higher.
  2394. */
  2395. #define EC_CMD_VERSION0 0xdc
  2396. #endif /* !__ACPI__ */
  2397. /*****************************************************************************/
  2398. /*
  2399. * PD commands
  2400. *
  2401. * These commands are for PD MCU communication.
  2402. */
  2403. /* EC to PD MCU exchange status command */
  2404. #define EC_CMD_PD_EXCHANGE_STATUS 0x100
  2405. /* Status of EC being sent to PD */
  2406. struct ec_params_pd_status {
  2407. int8_t batt_soc; /* battery state of charge */
  2408. } __packed;
  2409. /* Status of PD being sent back to EC */
  2410. struct ec_response_pd_status {
  2411. int8_t status; /* PD MCU status */
  2412. uint32_t curr_lim_ma; /* input current limit */
  2413. } __packed;
  2414. /* Set USB type-C port role and muxes */
  2415. #define EC_CMD_USB_PD_CONTROL 0x101
  2416. enum usb_pd_control_role {
  2417. USB_PD_CTRL_ROLE_NO_CHANGE = 0,
  2418. USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
  2419. USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
  2420. USB_PD_CTRL_ROLE_FORCE_SINK = 3,
  2421. USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
  2422. };
  2423. enum usb_pd_control_mux {
  2424. USB_PD_CTRL_MUX_NO_CHANGE = 0,
  2425. USB_PD_CTRL_MUX_NONE = 1,
  2426. USB_PD_CTRL_MUX_USB = 2,
  2427. USB_PD_CTRL_MUX_DP = 3,
  2428. USB_PD_CTRL_MUX_DOCK = 4,
  2429. USB_PD_CTRL_MUX_AUTO = 5,
  2430. };
  2431. struct ec_params_usb_pd_control {
  2432. uint8_t port;
  2433. uint8_t role;
  2434. uint8_t mux;
  2435. } __packed;
  2436. #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
  2437. #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
  2438. #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
  2439. struct ec_response_usb_pd_control_v1 {
  2440. uint8_t enabled;
  2441. uint8_t role;
  2442. uint8_t polarity;
  2443. char state[32];
  2444. } __packed;
  2445. #define EC_CMD_USB_PD_PORTS 0x102
  2446. struct ec_response_usb_pd_ports {
  2447. uint8_t num_ports;
  2448. } __packed;
  2449. #define EC_CMD_USB_PD_POWER_INFO 0x103
  2450. #define PD_POWER_CHARGING_PORT 0xff
  2451. struct ec_params_usb_pd_power_info {
  2452. uint8_t port;
  2453. } __packed;
  2454. enum usb_chg_type {
  2455. USB_CHG_TYPE_NONE,
  2456. USB_CHG_TYPE_PD,
  2457. USB_CHG_TYPE_C,
  2458. USB_CHG_TYPE_PROPRIETARY,
  2459. USB_CHG_TYPE_BC12_DCP,
  2460. USB_CHG_TYPE_BC12_CDP,
  2461. USB_CHG_TYPE_BC12_SDP,
  2462. USB_CHG_TYPE_OTHER,
  2463. USB_CHG_TYPE_VBUS,
  2464. USB_CHG_TYPE_UNKNOWN,
  2465. };
  2466. struct usb_chg_measures {
  2467. uint16_t voltage_max;
  2468. uint16_t voltage_now;
  2469. uint16_t current_max;
  2470. uint16_t current_lim;
  2471. } __packed;
  2472. struct ec_response_usb_pd_power_info {
  2473. uint8_t role;
  2474. uint8_t type;
  2475. uint8_t dualrole;
  2476. uint8_t reserved1;
  2477. struct usb_chg_measures meas;
  2478. uint32_t max_power;
  2479. } __packed;
  2480. /* Get info about USB-C SS muxes */
  2481. #define EC_CMD_USB_PD_MUX_INFO 0x11a
  2482. struct ec_params_usb_pd_mux_info {
  2483. uint8_t port; /* USB-C port number */
  2484. } __packed;
  2485. /* Flags representing mux state */
  2486. #define USB_PD_MUX_USB_ENABLED (1 << 0)
  2487. #define USB_PD_MUX_DP_ENABLED (1 << 1)
  2488. #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
  2489. #define USB_PD_MUX_HPD_IRQ (1 << 3)
  2490. struct ec_response_usb_pd_mux_info {
  2491. uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
  2492. } __packed;
  2493. /*****************************************************************************/
  2494. /*
  2495. * Passthru commands
  2496. *
  2497. * Some platforms have sub-processors chained to each other. For example.
  2498. *
  2499. * AP <--> EC <--> PD MCU
  2500. *
  2501. * The top 2 bits of the command number are used to indicate which device the
  2502. * command is intended for. Device 0 is always the device receiving the
  2503. * command; other device mapping is board-specific.
  2504. *
  2505. * When a device receives a command to be passed to a sub-processor, it passes
  2506. * it on with the device number set back to 0. This allows the sub-processor
  2507. * to remain blissfully unaware of whether the command originated on the next
  2508. * device up the chain, or was passed through from the AP.
  2509. *
  2510. * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
  2511. * AP sends command 0x4002 to the EC
  2512. * EC sends command 0x0002 to the PD MCU
  2513. * EC forwards PD MCU response back to the AP
  2514. */
  2515. /* Offset and max command number for sub-device n */
  2516. #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
  2517. #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
  2518. /*****************************************************************************/
  2519. /*
  2520. * Deprecated constants. These constants have been renamed for clarity. The
  2521. * meaning and size has not changed. Programs that use the old names should
  2522. * switch to the new names soon, as the old names may not be carried forward
  2523. * forever.
  2524. */
  2525. #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
  2526. #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
  2527. #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
  2528. #endif /* __CROS_EC_COMMANDS_H */