cros_ec_commands.h 92 KB

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