ec_commands.h 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605
  1. /* Copyright (c) 2018 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. */
  5. /* Host communication command constants for Chrome EC */
  6. #ifndef __CROS_EC_COMMANDS_H
  7. #define __CROS_EC_COMMANDS_H
  8. /*
  9. * Protocol overview
  10. *
  11. * request: CMD [ P0 P1 P2 ... Pn S ]
  12. * response: ERR [ P0 P1 P2 ... Pn S ]
  13. *
  14. * where the bytes are defined as follow :
  15. * - CMD is the command code. (defined by EC_CMD_ constants)
  16. * - ERR is the error code. (defined by EC_RES_ constants)
  17. * - Px is the optional payload.
  18. * it is not sent if the error code is not success.
  19. * (defined by ec_params_ and ec_response_ structures)
  20. * - S is the checksum which is the sum of all payload bytes.
  21. *
  22. * On LPC, CMD and ERR are sent/received at EC_LPC_ADDR_KERNEL|USER_CMD
  23. * and the payloads are sent/received at EC_LPC_ADDR_KERNEL|USER_PARAM.
  24. * On I2C, all bytes are sent serially in the same message.
  25. */
  26. /*
  27. * Current version of this protocol
  28. *
  29. * TODO(crosbug.com/p/11223): This is effectively useless; protocol is
  30. * determined in other ways. Remove this once the kernel code no longer
  31. * depends on it.
  32. */
  33. #define EC_PROTO_VERSION 0x00000002
  34. /* Command version mask */
  35. #define EC_VER_MASK(version) (1UL << (version))
  36. /* I/O addresses for ACPI commands */
  37. #define EC_LPC_ADDR_ACPI_DATA 0x62
  38. #define EC_LPC_ADDR_ACPI_CMD 0x66
  39. /* I/O addresses for host command */
  40. #define EC_LPC_ADDR_HOST_DATA 0x200
  41. #define EC_LPC_ADDR_HOST_CMD 0x204
  42. /* I/O addresses for host command args and params */
  43. /* Protocol version 2 */
  44. #define EC_LPC_ADDR_HOST_ARGS 0x800 /* And 0x801, 0x802, 0x803 */
  45. #define EC_LPC_ADDR_HOST_PARAM 0x804 /* For version 2 params; size is
  46. * EC_PROTO2_MAX_PARAM_SIZE */
  47. /* Protocol version 3 */
  48. #define EC_LPC_ADDR_HOST_PACKET 0x800 /* Offset of version 3 packet */
  49. #define EC_LPC_HOST_PACKET_SIZE 0x100 /* Max size of version 3 packet */
  50. /* The actual block is 0x800-0x8ff, but some BIOSes think it's 0x880-0x8ff
  51. * and they tell the kernel that so we have to think of it as two parts. */
  52. #define EC_HOST_CMD_REGION0 0x800
  53. #define EC_HOST_CMD_REGION1 0x880
  54. #define EC_HOST_CMD_REGION_SIZE 0x80
  55. /* EC command register bit functions */
  56. #define EC_LPC_CMDR_DATA (1 << 0) /* Data ready for host to read */
  57. #define EC_LPC_CMDR_PENDING (1 << 1) /* Write pending to EC */
  58. #define EC_LPC_CMDR_BUSY (1 << 2) /* EC is busy processing a command */
  59. #define EC_LPC_CMDR_CMD (1 << 3) /* Last host write was a command */
  60. #define EC_LPC_CMDR_ACPI_BRST (1 << 4) /* Burst mode (not used) */
  61. #define EC_LPC_CMDR_SCI (1 << 5) /* SCI event is pending */
  62. #define EC_LPC_CMDR_SMI (1 << 6) /* SMI event is pending */
  63. /* MEC uses 0x800/0x804 as register/index pair, thus an 8-byte resource */
  64. #define MEC_EMI_BASE 0x800
  65. #define MEC_EMI_SIZE 8
  66. #define EC_LPC_ADDR_MEMMAP 0x900
  67. #define EC_MEMMAP_SIZE 255 /* ACPI IO buffer max is 255 bytes */
  68. #define EC_MEMMAP_TEXT_MAX 8 /* Size of a string in the memory map */
  69. /* The offset address of each type of data in mapped memory. */
  70. #define EC_MEMMAP_TEMP_SENSOR 0x00 /* Temp sensors 0x00 - 0x0f */
  71. #define EC_MEMMAP_FAN 0x10 /* Fan speeds 0x10 - 0x17 */
  72. #define EC_MEMMAP_TEMP_SENSOR_B 0x18 /* More temp sensors 0x18 - 0x1f */
  73. #define EC_MEMMAP_ID 0x20 /* 0x20 == 'E', 0x21 == 'C' */
  74. #define EC_MEMMAP_ID_VERSION 0x22 /* Version of data in 0x20 - 0x2f */
  75. #define EC_MEMMAP_THERMAL_VERSION 0x23 /* Version of data in 0x00 - 0x1f */
  76. #define EC_MEMMAP_BATTERY_VERSION 0x24 /* Version of data in 0x40 - 0x7f */
  77. #define EC_MEMMAP_SWITCHES_VERSION 0x25 /* Version of data in 0x30 - 0x33 */
  78. #define EC_MEMMAP_EVENTS_VERSION 0x26 /* Version of data in 0x34 - 0x3f */
  79. #define EC_MEMMAP_HOST_CMD_FLAGS 0x27 /* Host cmd interface flags (8 bits) */
  80. /* Unused 0x28 - 0x2f */
  81. #define EC_MEMMAP_SWITCHES 0x30 /* 8 bits */
  82. /* Unused 0x31 - 0x33 */
  83. #define EC_MEMMAP_HOST_EVENTS 0x34 /* 32 bits */
  84. /* Reserve 0x38 - 0x3f for additional host event-related stuff */
  85. /* Battery values are all 32 bits */
  86. #define EC_MEMMAP_BATT_VOLT 0x40 /* Battery Present Voltage */
  87. #define EC_MEMMAP_BATT_RATE 0x44 /* Battery Present Rate */
  88. #define EC_MEMMAP_BATT_CAP 0x48 /* Battery Remaining Capacity */
  89. #define EC_MEMMAP_BATT_FLAG 0x4c /* Battery State, defined below */
  90. #define EC_MEMMAP_BATT_DCAP 0x50 /* Battery Design Capacity */
  91. #define EC_MEMMAP_BATT_DVLT 0x54 /* Battery Design Voltage */
  92. #define EC_MEMMAP_BATT_LFCC 0x58 /* Battery Last Full Charge Capacity */
  93. #define EC_MEMMAP_BATT_CCNT 0x5c /* Battery Cycle Count */
  94. /* Strings are all 8 bytes (EC_MEMMAP_TEXT_MAX) */
  95. #define EC_MEMMAP_BATT_MFGR 0x60 /* Battery Manufacturer String */
  96. #define EC_MEMMAP_BATT_MODEL 0x68 /* Battery Model Number String */
  97. #define EC_MEMMAP_BATT_SERIAL 0x70 /* Battery Serial Number String */
  98. #define EC_MEMMAP_BATT_TYPE 0x78 /* Battery Type String */
  99. #define EC_MEMMAP_ALS 0x80 /* ALS readings in lux (2 X 16 bits) */
  100. /* Unused 0x84 - 0x8f */
  101. #define EC_MEMMAP_ACC_STATUS 0x90 /* Accelerometer status (8 bits )*/
  102. /* Unused 0x91 */
  103. #define EC_MEMMAP_ACC_DATA 0x92 /* Accelerometers data 0x92 - 0x9f */
  104. /* 0x92: Lid Angle if available, LID_ANGLE_UNRELIABLE otherwise */
  105. /* 0x94 - 0x99: 1st Accelerometer */
  106. /* 0x9a - 0x9f: 2nd Accelerometer */
  107. #define EC_MEMMAP_GYRO_DATA 0xa0 /* Gyroscope data 0xa0 - 0xa5 */
  108. /* Unused 0xa6 - 0xdf */
  109. /*
  110. * ACPI is unable to access memory mapped data at or above this offset due to
  111. * limitations of the ACPI protocol. Do not place data in the range 0xe0 - 0xfe
  112. * which might be needed by ACPI.
  113. */
  114. #define EC_MEMMAP_NO_ACPI 0xe0
  115. /* Define the format of the accelerometer mapped memory status byte. */
  116. #define EC_MEMMAP_ACC_STATUS_SAMPLE_ID_MASK 0x0f
  117. #define EC_MEMMAP_ACC_STATUS_BUSY_BIT (1 << 4)
  118. #define EC_MEMMAP_ACC_STATUS_PRESENCE_BIT (1 << 7)
  119. /* Number of temp sensors at EC_MEMMAP_TEMP_SENSOR */
  120. #define EC_TEMP_SENSOR_ENTRIES 16
  121. /*
  122. * Number of temp sensors at EC_MEMMAP_TEMP_SENSOR_B.
  123. *
  124. * Valid only if EC_MEMMAP_THERMAL_VERSION returns >= 2.
  125. */
  126. #define EC_TEMP_SENSOR_B_ENTRIES 8
  127. /* Special values for mapped temperature sensors */
  128. #define EC_TEMP_SENSOR_NOT_PRESENT 0xff
  129. #define EC_TEMP_SENSOR_ERROR 0xfe
  130. #define EC_TEMP_SENSOR_NOT_POWERED 0xfd
  131. #define EC_TEMP_SENSOR_NOT_CALIBRATED 0xfc
  132. /*
  133. * The offset of temperature value stored in mapped memory. This allows
  134. * reporting a temperature range of 200K to 454K = -73C to 181C.
  135. */
  136. #define EC_TEMP_SENSOR_OFFSET 200
  137. /*
  138. * Number of ALS readings at EC_MEMMAP_ALS
  139. */
  140. #define EC_ALS_ENTRIES 2
  141. /*
  142. * The default value a temperature sensor will return when it is present but
  143. * has not been read this boot. This is a reasonable number to avoid
  144. * triggering alarms on the host.
  145. */
  146. #define EC_TEMP_SENSOR_DEFAULT (296 - EC_TEMP_SENSOR_OFFSET)
  147. #define EC_FAN_SPEED_ENTRIES 4 /* Number of fans at EC_MEMMAP_FAN */
  148. #define EC_FAN_SPEED_NOT_PRESENT 0xffff /* Entry not present */
  149. #define EC_FAN_SPEED_STALLED 0xfffe /* Fan stalled */
  150. /* Battery bit flags at EC_MEMMAP_BATT_FLAG. */
  151. #define EC_BATT_FLAG_AC_PRESENT 0x01
  152. #define EC_BATT_FLAG_BATT_PRESENT 0x02
  153. #define EC_BATT_FLAG_DISCHARGING 0x04
  154. #define EC_BATT_FLAG_CHARGING 0x08
  155. #define EC_BATT_FLAG_LEVEL_CRITICAL 0x10
  156. /* Switch flags at EC_MEMMAP_SWITCHES */
  157. #define EC_SWITCH_LID_OPEN 0x01
  158. #define EC_SWITCH_POWER_BUTTON_PRESSED 0x02
  159. #define EC_SWITCH_WRITE_PROTECT_DISABLED 0x04
  160. /* Was recovery requested via keyboard; now unused. */
  161. #define EC_SWITCH_IGNORE1 0x08
  162. /* Recovery requested via dedicated signal (from servo board) */
  163. #define EC_SWITCH_DEDICATED_RECOVERY 0x10
  164. /* Was fake developer mode switch; now unused. Remove in next refactor. */
  165. #define EC_SWITCH_IGNORE0 0x20
  166. /* Host command interface flags */
  167. /* Host command interface supports LPC args (LPC interface only) */
  168. #define EC_HOST_CMD_FLAG_LPC_ARGS_SUPPORTED 0x01
  169. /* Host command interface supports version 3 protocol */
  170. #define EC_HOST_CMD_FLAG_VERSION_3 0x02
  171. /* Wireless switch flags */
  172. #define EC_WIRELESS_SWITCH_ALL ~0x00 /* All flags */
  173. #define EC_WIRELESS_SWITCH_WLAN 0x01 /* WLAN radio */
  174. #define EC_WIRELESS_SWITCH_BLUETOOTH 0x02 /* Bluetooth radio */
  175. #define EC_WIRELESS_SWITCH_WWAN 0x04 /* WWAN power */
  176. #define EC_WIRELESS_SWITCH_WLAN_POWER 0x08 /* WLAN power */
  177. /*****************************************************************************/
  178. /*
  179. * ACPI commands
  180. *
  181. * These are valid ONLY on the ACPI command/data port.
  182. */
  183. /*
  184. * ACPI Read Embedded Controller
  185. *
  186. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  187. *
  188. * Use the following sequence:
  189. *
  190. * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
  191. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  192. * - Write address to EC_LPC_ADDR_ACPI_DATA
  193. * - Wait for EC_LPC_CMDR_DATA bit to set
  194. * - Read value from EC_LPC_ADDR_ACPI_DATA
  195. */
  196. #define EC_CMD_ACPI_READ 0x0080
  197. /*
  198. * ACPI Write Embedded Controller
  199. *
  200. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  201. *
  202. * Use the following sequence:
  203. *
  204. * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
  205. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  206. * - Write address to EC_LPC_ADDR_ACPI_DATA
  207. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  208. * - Write value to EC_LPC_ADDR_ACPI_DATA
  209. */
  210. #define EC_CMD_ACPI_WRITE 0x0081
  211. /*
  212. * ACPI Burst Enable Embedded Controller
  213. *
  214. * This enables burst mode on the EC to allow the host to issue several
  215. * commands back-to-back. While in this mode, writes to mapped multi-byte
  216. * data are locked out to ensure data consistency.
  217. */
  218. #define EC_CMD_ACPI_BURST_ENABLE 0x0082
  219. /*
  220. * ACPI Burst Disable Embedded Controller
  221. *
  222. * This disables burst mode on the EC and stops preventing EC writes to mapped
  223. * multi-byte data.
  224. */
  225. #define EC_CMD_ACPI_BURST_DISABLE 0x0083
  226. /*
  227. * ACPI Query Embedded Controller
  228. *
  229. * This clears the lowest-order bit in the currently pending host events, and
  230. * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
  231. * event 0x80000000 = 32), or 0 if no event was pending.
  232. */
  233. #define EC_CMD_ACPI_QUERY_EVENT 0x0084
  234. /* Valid addresses in ACPI memory space, for read/write commands */
  235. /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
  236. #define EC_ACPI_MEM_VERSION 0x00
  237. /*
  238. * Test location; writing value here updates test compliment byte to (0xff -
  239. * value).
  240. */
  241. #define EC_ACPI_MEM_TEST 0x01
  242. /* Test compliment; writes here are ignored. */
  243. #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
  244. /* Keyboard backlight brightness percent (0 - 100) */
  245. #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
  246. /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
  247. #define EC_ACPI_MEM_FAN_DUTY 0x04
  248. /*
  249. * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
  250. * independent thresholds attached to them. The current value of the ID
  251. * register determines which sensor is affected by the THRESHOLD and COMMIT
  252. * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
  253. * as the memory-mapped sensors. The COMMIT register applies those settings.
  254. *
  255. * The spec does not mandate any way to read back the threshold settings
  256. * themselves, but when a threshold is crossed the AP needs a way to determine
  257. * which sensor(s) are responsible. Each reading of the ID register clears and
  258. * returns one sensor ID that has crossed one of its threshold (in either
  259. * direction) since the last read. A value of 0xFF means "no new thresholds
  260. * have tripped". Setting or enabling the thresholds for a sensor will clear
  261. * the unread event count for that sensor.
  262. */
  263. #define EC_ACPI_MEM_TEMP_ID 0x05
  264. #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
  265. #define EC_ACPI_MEM_TEMP_COMMIT 0x07
  266. /*
  267. * Here are the bits for the COMMIT register:
  268. * bit 0 selects the threshold index for the chosen sensor (0/1)
  269. * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
  270. * Each write to the commit register affects one threshold.
  271. */
  272. #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
  273. #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
  274. /*
  275. * Example:
  276. *
  277. * Set the thresholds for sensor 2 to 50 C and 60 C:
  278. * write 2 to [0x05] -- select temp sensor 2
  279. * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
  280. * write 0x2 to [0x07] -- enable threshold 0 with this value
  281. * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
  282. * write 0x3 to [0x07] -- enable threshold 1 with this value
  283. *
  284. * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
  285. * write 2 to [0x05] -- select temp sensor 2
  286. * write 0x1 to [0x07] -- disable threshold 1
  287. */
  288. /* DPTF battery charging current limit */
  289. #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
  290. /* Charging limit is specified in 64 mA steps */
  291. #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
  292. /* Value to disable DPTF battery charging limit */
  293. #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
  294. /*
  295. * Report device orientation
  296. * bit 0 device is tablet mode
  297. */
  298. #define EC_ACPI_MEM_DEVICE_ORIENTATION 0x09
  299. #define EC_ACPI_MEM_DEVICE_TABLET_MODE 0x01
  300. /*
  301. * ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
  302. * is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
  303. */
  304. #define EC_ACPI_MEM_MAPPED_BEGIN 0x20
  305. #define EC_ACPI_MEM_MAPPED_SIZE 0xe0
  306. /* Current version of ACPI memory address space */
  307. #define EC_ACPI_MEM_VERSION_CURRENT 2
  308. /*
  309. * This header file is used in coreboot both in C and ACPI code. The ACPI code
  310. * is pre-processed to handle constants but the ASL compiler is unable to
  311. * handle actual C code so keep it separate.
  312. */
  313. #ifndef __ACPI__
  314. /*
  315. * Define __packed if someone hasn't beat us to it. Linux kernel style
  316. * checking prefers __packed over __attribute__((packed)).
  317. */
  318. #ifndef __packed
  319. #define __packed __attribute__((packed))
  320. #endif
  321. #ifndef __aligned
  322. #define __aligned(x) __attribute__((aligned(x)))
  323. #endif
  324. /*
  325. * Attributes for EC request and response packets. Just defining __packed
  326. * results in inefficient assembly code on ARM, if the structure is actually
  327. * 32-bit aligned, as it should be for all buffers.
  328. *
  329. * Be very careful when adding these to existing structures. They will round
  330. * up the structure size to the specified boundary.
  331. *
  332. * Also be very careful to make that if a structure is included in some other
  333. * parent structure that the alignment will still be true given the packing of
  334. * the parent structure. This is particularly important if the sub-structure
  335. * will be passed as a pointer to another function, since that function will
  336. * not know about the misaligment caused by the parent structure's packing.
  337. *
  338. * Also be very careful using __packed - particularly when nesting non-packed
  339. * structures inside packed ones. In fact, DO NOT use __packed directly;
  340. * always use one of these attributes.
  341. *
  342. * Once everything is annotated properly, the following search strings should
  343. * not return ANY matches in this file other than right here:
  344. *
  345. * "__packed" - generates inefficient code; all sub-structs must also be packed
  346. *
  347. * "struct [^_]" - all structs should be annotated, except for structs that are
  348. * members of other structs/unions (and their original declarations should be
  349. * annotated).
  350. */
  351. #ifdef CONFIG_HOSTCMD_ALIGNED
  352. /*
  353. * Packed structures where offset and size are always aligned to 1, 2, or 4
  354. * byte boundary.
  355. */
  356. #define __ec_align1 __packed
  357. #define __ec_align2 __packed __aligned(2)
  358. #define __ec_align4 __packed __aligned(4)
  359. /*
  360. * Packed structure which must be under-aligned, because its size is not a
  361. * 4-byte multiple. This is sub-optimal because it forces byte-wise access
  362. * of all multi-byte fields in it, even though they are themselves aligned.
  363. *
  364. * In theory, we could duplicate the structure with __aligned(4) for accessing
  365. * its members, but use the __packed version for sizeof().
  366. */
  367. #define __ec_align_size1 __packed
  368. /*
  369. * Packed structure which must be under-aligned, because its offset inside a
  370. * parent structure is not a 4-byte multiple.
  371. */
  372. #define __ec_align_offset1 __packed
  373. #define __ec_align_offset2 __packed __aligned(2)
  374. /*
  375. * Structures which are complicated enough that I'm skipping them on the first
  376. * pass. They are effectively unchanged from their previous definitions.
  377. *
  378. * TODO(rspangler): Figure out what to do with these. It's likely necessary
  379. * to work out the size and offset of each member and add explicit padding to
  380. * maintain those.
  381. */
  382. #define __ec_todo_packed __packed
  383. #define __ec_todo_unpacked
  384. #else /* !CONFIG_HOSTCMD_ALIGNED */
  385. /*
  386. * Packed structures make no assumption about alignment, so they do inefficient
  387. * byte-wise reads.
  388. */
  389. #define __ec_align1 __packed
  390. #define __ec_align2 __packed
  391. #define __ec_align4 __packed
  392. #define __ec_align_size1 __packed
  393. #define __ec_align_offset1 __packed
  394. #define __ec_align_offset2 __packed
  395. #define __ec_todo_packed __packed
  396. #define __ec_todo_unpacked
  397. #endif /* !CONFIG_HOSTCMD_ALIGNED */
  398. /* LPC command status byte masks */
  399. /* EC has written a byte in the data register and host hasn't read it yet */
  400. #define EC_LPC_STATUS_TO_HOST 0x01
  401. /* Host has written a command/data byte and the EC hasn't read it yet */
  402. #define EC_LPC_STATUS_FROM_HOST 0x02
  403. /* EC is processing a command */
  404. #define EC_LPC_STATUS_PROCESSING 0x04
  405. /* Last write to EC was a command, not data */
  406. #define EC_LPC_STATUS_LAST_CMD 0x08
  407. /* EC is in burst mode */
  408. #define EC_LPC_STATUS_BURST_MODE 0x10
  409. /* SCI event is pending (requesting SCI query) */
  410. #define EC_LPC_STATUS_SCI_PENDING 0x20
  411. /* SMI event is pending (requesting SMI query) */
  412. #define EC_LPC_STATUS_SMI_PENDING 0x40
  413. /* (reserved) */
  414. #define EC_LPC_STATUS_RESERVED 0x80
  415. /*
  416. * EC is busy. This covers both the EC processing a command, and the host has
  417. * written a new command but the EC hasn't picked it up yet.
  418. */
  419. #define EC_LPC_STATUS_BUSY_MASK \
  420. (EC_LPC_STATUS_FROM_HOST | EC_LPC_STATUS_PROCESSING)
  421. /* Host command response codes (16-bit). Note that response codes should be
  422. * stored in a uint16_t rather than directly in a value of this type.
  423. */
  424. enum ec_status {
  425. EC_RES_SUCCESS = 0,
  426. EC_RES_INVALID_COMMAND = 1,
  427. EC_RES_ERROR = 2,
  428. EC_RES_INVALID_PARAM = 3,
  429. EC_RES_ACCESS_DENIED = 4,
  430. EC_RES_INVALID_RESPONSE = 5,
  431. EC_RES_INVALID_VERSION = 6,
  432. EC_RES_INVALID_CHECKSUM = 7,
  433. EC_RES_IN_PROGRESS = 8, /* Accepted, command in progress */
  434. EC_RES_UNAVAILABLE = 9, /* No response available */
  435. EC_RES_TIMEOUT = 10, /* We got a timeout */
  436. EC_RES_OVERFLOW = 11, /* Table / data overflow */
  437. EC_RES_INVALID_HEADER = 12, /* Header contains invalid data */
  438. EC_RES_REQUEST_TRUNCATED = 13, /* Didn't get the entire request */
  439. EC_RES_RESPONSE_TOO_BIG = 14, /* Response was too big to handle */
  440. EC_RES_BUS_ERROR = 15, /* Communications bus error */
  441. EC_RES_BUSY = 16 /* Up but too busy. Should retry */
  442. };
  443. /*
  444. * Host event codes. Note these are 1-based, not 0-based, because ACPI query
  445. * EC command uses code 0 to mean "no event pending". We explicitly specify
  446. * each value in the enum listing so they won't change if we delete/insert an
  447. * item or rearrange the list (it needs to be stable across platforms, not
  448. * just within a single compiled instance).
  449. */
  450. enum host_event_code {
  451. EC_HOST_EVENT_LID_CLOSED = 1,
  452. EC_HOST_EVENT_LID_OPEN = 2,
  453. EC_HOST_EVENT_POWER_BUTTON = 3,
  454. EC_HOST_EVENT_AC_CONNECTED = 4,
  455. EC_HOST_EVENT_AC_DISCONNECTED = 5,
  456. EC_HOST_EVENT_BATTERY_LOW = 6,
  457. EC_HOST_EVENT_BATTERY_CRITICAL = 7,
  458. EC_HOST_EVENT_BATTERY = 8,
  459. EC_HOST_EVENT_THERMAL_THRESHOLD = 9,
  460. /* Event generated by a device attached to the EC */
  461. EC_HOST_EVENT_DEVICE = 10,
  462. EC_HOST_EVENT_THERMAL = 11,
  463. EC_HOST_EVENT_USB_CHARGER = 12,
  464. EC_HOST_EVENT_KEY_PRESSED = 13,
  465. /*
  466. * EC has finished initializing the host interface. The host can check
  467. * for this event following sending a EC_CMD_REBOOT_EC command to
  468. * determine when the EC is ready to accept subsequent commands.
  469. */
  470. EC_HOST_EVENT_INTERFACE_READY = 14,
  471. /* Keyboard recovery combo has been pressed */
  472. EC_HOST_EVENT_KEYBOARD_RECOVERY = 15,
  473. /* Shutdown due to thermal overload */
  474. EC_HOST_EVENT_THERMAL_SHUTDOWN = 16,
  475. /* Shutdown due to battery level too low */
  476. EC_HOST_EVENT_BATTERY_SHUTDOWN = 17,
  477. /* Suggest that the AP throttle itself */
  478. EC_HOST_EVENT_THROTTLE_START = 18,
  479. /* Suggest that the AP resume normal speed */
  480. EC_HOST_EVENT_THROTTLE_STOP = 19,
  481. /* Hang detect logic detected a hang and host event timeout expired */
  482. EC_HOST_EVENT_HANG_DETECT = 20,
  483. /* Hang detect logic detected a hang and warm rebooted the AP */
  484. EC_HOST_EVENT_HANG_REBOOT = 21,
  485. /* PD MCU triggering host event */
  486. EC_HOST_EVENT_PD_MCU = 22,
  487. /* Battery Status flags have changed */
  488. EC_HOST_EVENT_BATTERY_STATUS = 23,
  489. /* EC encountered a panic, triggering a reset */
  490. EC_HOST_EVENT_PANIC = 24,
  491. /* Keyboard fastboot combo has been pressed */
  492. EC_HOST_EVENT_KEYBOARD_FASTBOOT = 25,
  493. /* EC RTC event occurred */
  494. EC_HOST_EVENT_RTC = 26,
  495. /* Emulate MKBP event */
  496. EC_HOST_EVENT_MKBP = 27,
  497. /* EC desires to change state of host-controlled USB mux */
  498. EC_HOST_EVENT_USB_MUX = 28,
  499. /* TABLET/LAPTOP mode event*/
  500. EC_HOST_EVENT_MODE_CHANGE = 29,
  501. /* Keyboard recovery combo with hardware reinitialization */
  502. EC_HOST_EVENT_KEYBOARD_RECOVERY_HW_REINIT = 30,
  503. /*
  504. * Reserve this last bit to indicate that at least one bit in a
  505. * secondary host event word is set. See crbug.com/633646.
  506. */
  507. EC_HOST_EVENT_EXTENDED = 31,
  508. /*
  509. * The high bit of the event mask is not used as a host event code. If
  510. * it reads back as set, then the entire event mask should be
  511. * considered invalid by the host. This can happen when reading the
  512. * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
  513. * not initialized on the EC, or improperly configured on the host.
  514. */
  515. EC_HOST_EVENT_INVALID = 32
  516. };
  517. /* Host event mask */
  518. #define EC_HOST_EVENT_MASK(event_code) (1ULL << ((event_code) - 1))
  519. /* Arguments at EC_LPC_ADDR_HOST_ARGS */
  520. struct __ec_align4 ec_lpc_host_args {
  521. uint8_t flags;
  522. uint8_t command_version;
  523. uint8_t data_size;
  524. /*
  525. * Checksum; sum of command + flags + command_version + data_size +
  526. * all params/response data bytes.
  527. */
  528. uint8_t checksum;
  529. };
  530. /* Flags for ec_lpc_host_args.flags */
  531. /*
  532. * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
  533. * params.
  534. *
  535. * If EC gets a command and this flag is not set, this is an old-style command.
  536. * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
  537. * unknown length. EC must respond with an old-style response (that is,
  538. * without setting EC_HOST_ARGS_FLAG_TO_HOST).
  539. */
  540. #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
  541. /*
  542. * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
  543. *
  544. * If EC responds to a command and this flag is not set, this is an old-style
  545. * response. Command version is 0 and response data from EC is at
  546. * EC_LPC_ADDR_OLD_PARAM with unknown length.
  547. */
  548. #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
  549. /*****************************************************************************/
  550. /*
  551. * Byte codes returned by EC over SPI interface.
  552. *
  553. * These can be used by the AP to debug the EC interface, and to determine
  554. * when the EC is not in a state where it will ever get around to responding
  555. * to the AP.
  556. *
  557. * Example of sequence of bytes read from EC for a current good transfer:
  558. * 1. - - AP asserts chip select (CS#)
  559. * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
  560. * 3. - - EC starts handling CS# interrupt
  561. * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
  562. * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
  563. * bytes looking for EC_SPI_FRAME_START
  564. * 6. - - EC finishes processing and sets up response
  565. * 7. EC_SPI_FRAME_START - AP reads frame byte
  566. * 8. (response packet) - AP reads response packet
  567. * 9. EC_SPI_PAST_END - Any additional bytes read by AP
  568. * 10 - - AP deasserts chip select
  569. * 11 - - EC processes CS# interrupt and sets up DMA for
  570. * next request
  571. *
  572. * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
  573. * the following byte values:
  574. * EC_SPI_OLD_READY
  575. * EC_SPI_RX_READY
  576. * EC_SPI_RECEIVING
  577. * EC_SPI_PROCESSING
  578. *
  579. * Then the EC found an error in the request, or was not ready for the request
  580. * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
  581. * because the EC is unable to tell when the AP is done sending its request.
  582. */
  583. /*
  584. * Framing byte which precedes a response packet from the EC. After sending a
  585. * request, the AP will clock in bytes until it sees the framing byte, then
  586. * clock in the response packet.
  587. */
  588. #define EC_SPI_FRAME_START 0xec
  589. /*
  590. * Padding bytes which are clocked out after the end of a response packet.
  591. */
  592. #define EC_SPI_PAST_END 0xed
  593. /*
  594. * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
  595. * that the AP will send a valid packet header (starting with
  596. * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
  597. */
  598. #define EC_SPI_RX_READY 0xf8
  599. /*
  600. * EC has started receiving the request from the AP, but hasn't started
  601. * processing it yet.
  602. */
  603. #define EC_SPI_RECEIVING 0xf9
  604. /* EC has received the entire request from the AP and is processing it. */
  605. #define EC_SPI_PROCESSING 0xfa
  606. /*
  607. * EC received bad data from the AP, such as a packet header with an invalid
  608. * length. EC will ignore all data until chip select deasserts.
  609. */
  610. #define EC_SPI_RX_BAD_DATA 0xfb
  611. /*
  612. * EC received data from the AP before it was ready. That is, the AP asserted
  613. * chip select and started clocking data before the EC was ready to receive it.
  614. * EC will ignore all data until chip select deasserts.
  615. */
  616. #define EC_SPI_NOT_READY 0xfc
  617. /*
  618. * EC was ready to receive a request from the AP. EC has treated the byte sent
  619. * by the AP as part of a request packet, or (for old-style ECs) is processing
  620. * a fully received packet but is not ready to respond yet.
  621. */
  622. #define EC_SPI_OLD_READY 0xfd
  623. /*****************************************************************************/
  624. /*
  625. * Protocol version 2 for I2C and SPI send a request this way:
  626. *
  627. * 0 EC_CMD_VERSION0 + (command version)
  628. * 1 Command number
  629. * 2 Length of params = N
  630. * 3..N+2 Params, if any
  631. * N+3 8-bit checksum of bytes 0..N+2
  632. *
  633. * The corresponding response is:
  634. *
  635. * 0 Result code (EC_RES_*)
  636. * 1 Length of params = M
  637. * 2..M+1 Params, if any
  638. * M+2 8-bit checksum of bytes 0..M+1
  639. */
  640. #define EC_PROTO2_REQUEST_HEADER_BYTES 3
  641. #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
  642. #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
  643. EC_PROTO2_REQUEST_TRAILER_BYTES)
  644. #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
  645. #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
  646. #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
  647. EC_PROTO2_RESPONSE_TRAILER_BYTES)
  648. /* Parameter length was limited by the LPC interface */
  649. #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
  650. /* Maximum request and response packet sizes for protocol version 2 */
  651. #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
  652. EC_PROTO2_MAX_PARAM_SIZE)
  653. #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
  654. EC_PROTO2_MAX_PARAM_SIZE)
  655. /*****************************************************************************/
  656. /*
  657. * Value written to legacy command port / prefix byte to indicate protocol
  658. * 3+ structs are being used. Usage is bus-dependent.
  659. */
  660. #define EC_COMMAND_PROTOCOL_3 0xda
  661. #define EC_HOST_REQUEST_VERSION 3
  662. /* Version 3 request from host */
  663. struct __ec_align4 ec_host_request {
  664. /* Structure version (=3)
  665. *
  666. * EC will return EC_RES_INVALID_HEADER if it receives a header with a
  667. * version it doesn't know how to parse.
  668. */
  669. uint8_t struct_version;
  670. /*
  671. * Checksum of request and data; sum of all bytes including checksum
  672. * should total to 0.
  673. */
  674. uint8_t checksum;
  675. /* Command code */
  676. uint16_t command;
  677. /* Command version */
  678. uint8_t command_version;
  679. /* Unused byte in current protocol version; set to 0 */
  680. uint8_t reserved;
  681. /* Length of data which follows this header */
  682. uint16_t data_len;
  683. };
  684. #define EC_HOST_RESPONSE_VERSION 3
  685. /* Version 3 response from EC */
  686. struct __ec_align4 ec_host_response {
  687. /* Structure version (=3) */
  688. uint8_t struct_version;
  689. /*
  690. * Checksum of response and data; sum of all bytes including checksum
  691. * should total to 0.
  692. */
  693. uint8_t checksum;
  694. /* Result code (EC_RES_*) */
  695. uint16_t result;
  696. /* Length of data which follows this header */
  697. uint16_t data_len;
  698. /* Unused bytes in current protocol version; set to 0 */
  699. uint16_t reserved;
  700. };
  701. /*****************************************************************************/
  702. /*
  703. * Notes on commands:
  704. *
  705. * Each command is an 16-bit command value. Commands which take params or
  706. * return response data specify structures for that data. If no structure is
  707. * specified, the command does not input or output data, respectively.
  708. * Parameter/response length is implicit in the structs. Some underlying
  709. * communication protocols (I2C, SPI) may add length or checksum headers, but
  710. * those are implementation-dependent and not defined here.
  711. *
  712. * All commands MUST be #defined to be 4-digit UPPER CASE hex values
  713. * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
  714. */
  715. /*****************************************************************************/
  716. /* General / test commands */
  717. /*
  718. * Get protocol version, used to deal with non-backward compatible protocol
  719. * changes.
  720. */
  721. #define EC_CMD_PROTO_VERSION 0x0000
  722. struct __ec_align4 ec_response_proto_version {
  723. uint32_t version;
  724. };
  725. /*
  726. * Hello. This is a simple command to test the EC is responsive to
  727. * commands.
  728. */
  729. #define EC_CMD_HELLO 0x0001
  730. struct __ec_align4 ec_params_hello {
  731. uint32_t in_data; /* Pass anything here */
  732. };
  733. struct __ec_align4 ec_response_hello {
  734. uint32_t out_data; /* Output will be in_data + 0x01020304 */
  735. };
  736. /* Get version number */
  737. #define EC_CMD_GET_VERSION 0x0002
  738. enum ec_current_image {
  739. EC_IMAGE_UNKNOWN = 0,
  740. EC_IMAGE_RO,
  741. EC_IMAGE_RW
  742. };
  743. struct __ec_align4 ec_response_get_version {
  744. /* Null-terminated version strings for RO, RW */
  745. char version_string_ro[32];
  746. char version_string_rw[32];
  747. char reserved[32]; /* Was previously RW-B string */
  748. uint32_t current_image; /* One of ec_current_image */
  749. };
  750. /* Read test */
  751. #define EC_CMD_READ_TEST 0x0003
  752. struct __ec_align4 ec_params_read_test {
  753. uint32_t offset; /* Starting value for read buffer */
  754. uint32_t size; /* Size to read in bytes */
  755. };
  756. struct __ec_align4 ec_response_read_test {
  757. uint32_t data[32];
  758. };
  759. /*
  760. * Get build information
  761. *
  762. * Response is null-terminated string.
  763. */
  764. #define EC_CMD_GET_BUILD_INFO 0x0004
  765. /* Get chip info */
  766. #define EC_CMD_GET_CHIP_INFO 0x0005
  767. struct __ec_align4 ec_response_get_chip_info {
  768. /* Null-terminated strings */
  769. char vendor[32];
  770. char name[32];
  771. char revision[32]; /* Mask version */
  772. };
  773. /* Get board HW version */
  774. #define EC_CMD_GET_BOARD_VERSION 0x0006
  775. struct __ec_align2 ec_response_board_version {
  776. uint16_t board_version; /* A monotonously incrementing number. */
  777. };
  778. /*
  779. * Read memory-mapped data.
  780. *
  781. * This is an alternate interface to memory-mapped data for bus protocols
  782. * which don't support direct-mapped memory - I2C, SPI, etc.
  783. *
  784. * Response is params.size bytes of data.
  785. */
  786. #define EC_CMD_READ_MEMMAP 0x0007
  787. struct __ec_align1 ec_params_read_memmap {
  788. uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
  789. uint8_t size; /* Size to read in bytes */
  790. };
  791. /* Read versions supported for a command */
  792. #define EC_CMD_GET_CMD_VERSIONS 0x0008
  793. struct __ec_align1 ec_params_get_cmd_versions {
  794. uint8_t cmd; /* Command to check */
  795. };
  796. struct __ec_align2 ec_params_get_cmd_versions_v1 {
  797. uint16_t cmd; /* Command to check */
  798. };
  799. struct __ec_align4 ec_response_get_cmd_versions {
  800. /*
  801. * Mask of supported versions; use EC_VER_MASK() to compare with a
  802. * desired version.
  803. */
  804. uint32_t version_mask;
  805. };
  806. /*
  807. * Check EC communications status (busy). This is needed on i2c/spi but not
  808. * on lpc since it has its own out-of-band busy indicator.
  809. *
  810. * lpc must read the status from the command register. Attempting this on
  811. * lpc will overwrite the args/parameter space and corrupt its data.
  812. */
  813. #define EC_CMD_GET_COMMS_STATUS 0x0009
  814. /* Avoid using ec_status which is for return values */
  815. enum ec_comms_status {
  816. EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
  817. };
  818. struct __ec_align4 ec_response_get_comms_status {
  819. uint32_t flags; /* Mask of enum ec_comms_status */
  820. };
  821. /* Fake a variety of responses, purely for testing purposes. */
  822. #define EC_CMD_TEST_PROTOCOL 0x000A
  823. /* Tell the EC what to send back to us. */
  824. struct __ec_align4 ec_params_test_protocol {
  825. uint32_t ec_result;
  826. uint32_t ret_len;
  827. uint8_t buf[32];
  828. };
  829. /* Here it comes... */
  830. struct __ec_align4 ec_response_test_protocol {
  831. uint8_t buf[32];
  832. };
  833. /* Get protocol information */
  834. #define EC_CMD_GET_PROTOCOL_INFO 0x000B
  835. /* Flags for ec_response_get_protocol_info.flags */
  836. /* EC_RES_IN_PROGRESS may be returned if a command is slow */
  837. #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
  838. struct __ec_align4 ec_response_get_protocol_info {
  839. /* Fields which exist if at least protocol version 3 supported */
  840. /* Bitmask of protocol versions supported (1 << n means version n)*/
  841. uint32_t protocol_versions;
  842. /* Maximum request packet size, in bytes */
  843. uint16_t max_request_packet_size;
  844. /* Maximum response packet size, in bytes */
  845. uint16_t max_response_packet_size;
  846. /* Flags; see EC_PROTOCOL_INFO_* */
  847. uint32_t flags;
  848. };
  849. /*****************************************************************************/
  850. /* Get/Set miscellaneous values */
  851. /* The upper byte of .flags tells what to do (nothing means "get") */
  852. #define EC_GSV_SET 0x80000000
  853. /* The lower three bytes of .flags identifies the parameter, if that has
  854. meaning for an individual command. */
  855. #define EC_GSV_PARAM_MASK 0x00ffffff
  856. struct __ec_align4 ec_params_get_set_value {
  857. uint32_t flags;
  858. uint32_t value;
  859. };
  860. struct __ec_align4 ec_response_get_set_value {
  861. uint32_t flags;
  862. uint32_t value;
  863. };
  864. /* More than one command can use these structs to get/set parameters. */
  865. #define EC_CMD_GSV_PAUSE_IN_S5 0x000C
  866. /*****************************************************************************/
  867. /* List the features supported by the firmware */
  868. #define EC_CMD_GET_FEATURES 0x000D
  869. /* Supported features */
  870. enum ec_feature_code {
  871. /*
  872. * This image contains a limited set of features. Another image
  873. * in RW partition may support more features.
  874. */
  875. EC_FEATURE_LIMITED = 0,
  876. /*
  877. * Commands for probing/reading/writing/erasing the flash in the
  878. * EC are present.
  879. */
  880. EC_FEATURE_FLASH = 1,
  881. /*
  882. * Can control the fan speed directly.
  883. */
  884. EC_FEATURE_PWM_FAN = 2,
  885. /*
  886. * Can control the intensity of the keyboard backlight.
  887. */
  888. EC_FEATURE_PWM_KEYB = 3,
  889. /*
  890. * Support Google lightbar, introduced on Pixel.
  891. */
  892. EC_FEATURE_LIGHTBAR = 4,
  893. /* Control of LEDs */
  894. EC_FEATURE_LED = 5,
  895. /* Exposes an interface to control gyro and sensors.
  896. * The host goes through the EC to access these sensors.
  897. * In addition, the EC may provide composite sensors, like lid angle.
  898. */
  899. EC_FEATURE_MOTION_SENSE = 6,
  900. /* The keyboard is controlled by the EC */
  901. EC_FEATURE_KEYB = 7,
  902. /* The AP can use part of the EC flash as persistent storage. */
  903. EC_FEATURE_PSTORE = 8,
  904. /* The EC monitors BIOS port 80h, and can return POST codes. */
  905. EC_FEATURE_PORT80 = 9,
  906. /*
  907. * Thermal management: include TMP specific commands.
  908. * Higher level than direct fan control.
  909. */
  910. EC_FEATURE_THERMAL = 10,
  911. /* Can switch the screen backlight on/off */
  912. EC_FEATURE_BKLIGHT_SWITCH = 11,
  913. /* Can switch the wifi module on/off */
  914. EC_FEATURE_WIFI_SWITCH = 12,
  915. /* Monitor host events, through for example SMI or SCI */
  916. EC_FEATURE_HOST_EVENTS = 13,
  917. /* The EC exposes GPIO commands to control/monitor connected devices. */
  918. EC_FEATURE_GPIO = 14,
  919. /* The EC can send i2c messages to downstream devices. */
  920. EC_FEATURE_I2C = 15,
  921. /* Command to control charger are included */
  922. EC_FEATURE_CHARGER = 16,
  923. /* Simple battery support. */
  924. EC_FEATURE_BATTERY = 17,
  925. /*
  926. * Support Smart battery protocol
  927. * (Common Smart Battery System Interface Specification)
  928. */
  929. EC_FEATURE_SMART_BATTERY = 18,
  930. /* EC can detect when the host hangs. */
  931. EC_FEATURE_HANG_DETECT = 19,
  932. /* Report power information, for pit only */
  933. EC_FEATURE_PMU = 20,
  934. /* Another Cros EC device is present downstream of this one */
  935. EC_FEATURE_SUB_MCU = 21,
  936. /* Support USB Power delivery (PD) commands */
  937. EC_FEATURE_USB_PD = 22,
  938. /* Control USB multiplexer, for audio through USB port for instance. */
  939. EC_FEATURE_USB_MUX = 23,
  940. /* Motion Sensor code has an internal software FIFO */
  941. EC_FEATURE_MOTION_SENSE_FIFO = 24,
  942. /* Support temporary secure vstore */
  943. EC_FEATURE_VSTORE = 25,
  944. /* EC decides on USB-C SS mux state, muxes configured by host */
  945. EC_FEATURE_USBC_SS_MUX_VIRTUAL = 26,
  946. /* EC has RTC feature that can be controlled by host commands */
  947. EC_FEATURE_RTC = 27,
  948. /* The MCU exposes a Fingerprint sensor */
  949. EC_FEATURE_FINGERPRINT = 28,
  950. /* The MCU exposes a Touchpad */
  951. EC_FEATURE_TOUCHPAD = 29,
  952. /* The MCU has RWSIG task enabled */
  953. EC_FEATURE_RWSIG = 30,
  954. /* EC has device events support */
  955. EC_FEATURE_DEVICE_EVENT = 31,
  956. /* EC supports the unified wake masks for LPC/eSPI systems */
  957. EC_FEATURE_UNIFIED_WAKE_MASKS = 32,
  958. };
  959. #define EC_FEATURE_MASK_0(event_code) (1UL << (event_code % 32))
  960. #define EC_FEATURE_MASK_1(event_code) (1UL << (event_code - 32))
  961. struct __ec_align4 ec_response_get_features {
  962. uint32_t flags[2];
  963. };
  964. /*****************************************************************************/
  965. /* Get the board's SKU ID from EC */
  966. #define EC_CMD_GET_SKU_ID 0x000E
  967. /* Set SKU ID from AP */
  968. #define EC_CMD_SET_SKU_ID 0x000F
  969. struct __ec_align4 ec_sku_id_info {
  970. uint32_t sku_id;
  971. };
  972. /*****************************************************************************/
  973. /* Flash commands */
  974. /* Get flash info */
  975. #define EC_CMD_FLASH_INFO 0x0010
  976. #define EC_VER_FLASH_INFO 2
  977. /* Version 0 returns these fields */
  978. struct __ec_align4 ec_response_flash_info {
  979. /* Usable flash size, in bytes */
  980. uint32_t flash_size;
  981. /*
  982. * Write block size. Write offset and size must be a multiple
  983. * of this.
  984. */
  985. uint32_t write_block_size;
  986. /*
  987. * Erase block size. Erase offset and size must be a multiple
  988. * of this.
  989. */
  990. uint32_t erase_block_size;
  991. /*
  992. * Protection block size. Protection offset and size must be a
  993. * multiple of this.
  994. */
  995. uint32_t protect_block_size;
  996. };
  997. /* Flags for version 1+ flash info command */
  998. /* EC flash erases bits to 0 instead of 1 */
  999. #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
  1000. /* Flash must be selected for read/write/erase operations to succeed. This may
  1001. * be necessary on a chip where write/erase can be corrupted by other board
  1002. * activity, or where the chip needs to enable some sort of programming voltage,
  1003. * or where the read/write/erase operations require cleanly suspending other
  1004. * chip functionality. */
  1005. #define EC_FLASH_INFO_SELECT_REQUIRED (1 << 1)
  1006. /*
  1007. * Version 1 returns the same initial fields as version 0, with additional
  1008. * fields following.
  1009. *
  1010. * gcc anonymous structs don't seem to get along with the __packed directive;
  1011. * if they did we'd define the version 0 structure as a sub-structure of this
  1012. * one.
  1013. *
  1014. * Version 2 supports flash banks of different sizes:
  1015. * The caller specified the number of banks it has preallocated
  1016. * (num_banks_desc)
  1017. * The EC returns the number of banks describing the flash memory.
  1018. * It adds banks descriptions up to num_banks_desc.
  1019. */
  1020. struct __ec_align4 ec_response_flash_info_1 {
  1021. /* Version 0 fields; see above for description */
  1022. uint32_t flash_size;
  1023. uint32_t write_block_size;
  1024. uint32_t erase_block_size;
  1025. uint32_t protect_block_size;
  1026. /* Version 1 adds these fields: */
  1027. /*
  1028. * Ideal write size in bytes. Writes will be fastest if size is
  1029. * exactly this and offset is a multiple of this. For example, an EC
  1030. * may have a write buffer which can do half-page operations if data is
  1031. * aligned, and a slower word-at-a-time write mode.
  1032. */
  1033. uint32_t write_ideal_size;
  1034. /* Flags; see EC_FLASH_INFO_* */
  1035. uint32_t flags;
  1036. };
  1037. struct __ec_align4 ec_params_flash_info_2 {
  1038. /* Number of banks to describe */
  1039. uint16_t num_banks_desc;
  1040. /* Reserved; set 0; ignore on read */
  1041. uint8_t reserved[2];
  1042. };
  1043. struct ec_flash_bank {
  1044. /* Number of sector is in this bank. */
  1045. uint16_t count;
  1046. /* Size in power of 2 of each sector (8 --> 256 bytes) */
  1047. uint8_t size_exp;
  1048. /* Minimal write size for the sectors in this bank */
  1049. uint8_t write_size_exp;
  1050. /* Erase size for the sectors in this bank */
  1051. uint8_t erase_size_exp;
  1052. /* Size for write protection, usually identical to erase size. */
  1053. uint8_t protect_size_exp;
  1054. /* Reserved; set 0; ignore on read */
  1055. uint8_t reserved[2];
  1056. };
  1057. struct __ec_align4 ec_response_flash_info_2 {
  1058. /* Total flash in the EC. */
  1059. uint32_t flash_size;
  1060. /* Flags; see EC_FLASH_INFO_* */
  1061. uint32_t flags;
  1062. /* Maximum size to use to send data to write to the EC. */
  1063. uint32_t write_ideal_size;
  1064. /* Number of banks present in the EC. */
  1065. uint16_t num_banks_total;
  1066. /* Number of banks described in banks array. */
  1067. uint16_t num_banks_desc;
  1068. struct ec_flash_bank banks[0];
  1069. };
  1070. /*
  1071. * Read flash
  1072. *
  1073. * Response is params.size bytes of data.
  1074. */
  1075. #define EC_CMD_FLASH_READ 0x0011
  1076. struct __ec_align4 ec_params_flash_read {
  1077. uint32_t offset; /* Byte offset to read */
  1078. uint32_t size; /* Size to read in bytes */
  1079. };
  1080. /* Write flash */
  1081. #define EC_CMD_FLASH_WRITE 0x0012
  1082. #define EC_VER_FLASH_WRITE 1
  1083. /* Version 0 of the flash command supported only 64 bytes of data */
  1084. #define EC_FLASH_WRITE_VER0_SIZE 64
  1085. struct __ec_align4 ec_params_flash_write {
  1086. uint32_t offset; /* Byte offset to write */
  1087. uint32_t size; /* Size to write in bytes */
  1088. /* Followed by data to write */
  1089. };
  1090. /* Erase flash */
  1091. #define EC_CMD_FLASH_ERASE 0x0013
  1092. /* v0 */
  1093. struct __ec_align4 ec_params_flash_erase {
  1094. uint32_t offset; /* Byte offset to erase */
  1095. uint32_t size; /* Size to erase in bytes */
  1096. };
  1097. #define EC_VER_FLASH_WRITE 1
  1098. /* v1 add async erase:
  1099. * subcommands can returns:
  1100. * EC_RES_SUCCESS : erased (see ERASE_SECTOR_ASYNC case below).
  1101. * EC_RES_INVALID_PARAM : offset/size are not aligned on a erase boundary.
  1102. * EC_RES_ERROR : other errors.
  1103. * EC_RES_BUSY : an existing erase operation is in progress.
  1104. * EC_RES_ACCESS_DENIED: Trying to erase running image.
  1105. *
  1106. * When ERASE_SECTOR_ASYNC returns EC_RES_SUCCESS, the operation is just
  1107. * properly queued. The user must call ERASE_GET_RESULT subcommand to get
  1108. * the proper result.
  1109. * When ERASE_GET_RESULT returns EC_RES_BUSY, the caller must wait and send
  1110. * ERASE_GET_RESULT again to get the result of ERASE_SECTOR_ASYNC.
  1111. * ERASE_GET_RESULT command may timeout on EC where flash access is not
  1112. * permitted while erasing. (For instance, STM32F4).
  1113. */
  1114. enum ec_flash_erase_cmd {
  1115. FLASH_ERASE_SECTOR, /* Erase and wait for result */
  1116. FLASH_ERASE_SECTOR_ASYNC, /* Erase and return immediately. */
  1117. FLASH_ERASE_GET_RESULT, /* Ask for last erase result */
  1118. };
  1119. struct __ec_align4 ec_params_flash_erase_v1 {
  1120. /* One of ec_flash_erase_cmd. */
  1121. uint8_t cmd;
  1122. /* Pad byte; currently always contains 0 */
  1123. uint8_t reserved;
  1124. /* No flags defined yet; set to 0 */
  1125. uint16_t flag;
  1126. /* Same as v0 parameters. */
  1127. struct ec_params_flash_erase params;
  1128. };
  1129. /*
  1130. * Get/set flash protection.
  1131. *
  1132. * If mask!=0, sets/clear the requested bits of flags. Depending on the
  1133. * firmware write protect GPIO, not all flags will take effect immediately;
  1134. * some flags require a subsequent hard reset to take effect. Check the
  1135. * returned flags bits to see what actually happened.
  1136. *
  1137. * If mask=0, simply returns the current flags state.
  1138. */
  1139. #define EC_CMD_FLASH_PROTECT 0x0015
  1140. #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
  1141. /* Flags for flash protection */
  1142. /* RO flash code protected when the EC boots */
  1143. #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
  1144. /*
  1145. * RO flash code protected now. If this bit is set, at-boot status cannot
  1146. * be changed.
  1147. */
  1148. #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
  1149. /* Entire flash code protected now, until reboot. */
  1150. #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
  1151. /* Flash write protect GPIO is asserted now */
  1152. #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
  1153. /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
  1154. #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
  1155. /*
  1156. * Error - flash protection is in inconsistent state. At least one bank of
  1157. * flash which should be protected is not protected. Usually fixed by
  1158. * re-requesting the desired flags, or by a hard reset if that fails.
  1159. */
  1160. #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
  1161. /* Entire flash code protected when the EC boots */
  1162. #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
  1163. /* RW flash code protected when the EC boots */
  1164. #define EC_FLASH_PROTECT_RW_AT_BOOT (1 << 7)
  1165. /* RW flash code protected now. */
  1166. #define EC_FLASH_PROTECT_RW_NOW (1 << 8)
  1167. /* Rollback information flash region protected when the EC boots */
  1168. #define EC_FLASH_PROTECT_ROLLBACK_AT_BOOT (1 << 9)
  1169. /* Rollback information flash region protected now */
  1170. #define EC_FLASH_PROTECT_ROLLBACK_NOW (1 << 10)
  1171. struct __ec_align4 ec_params_flash_protect {
  1172. uint32_t mask; /* Bits in flags to apply */
  1173. uint32_t flags; /* New flags to apply */
  1174. };
  1175. struct __ec_align4 ec_response_flash_protect {
  1176. /* Current value of flash protect flags */
  1177. uint32_t flags;
  1178. /*
  1179. * Flags which are valid on this platform. This allows the caller
  1180. * to distinguish between flags which aren't set vs. flags which can't
  1181. * be set on this platform.
  1182. */
  1183. uint32_t valid_flags;
  1184. /* Flags which can be changed given the current protection state */
  1185. uint32_t writable_flags;
  1186. };
  1187. /*
  1188. * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
  1189. * write protect. These commands may be reused with version > 0.
  1190. */
  1191. /* Get the region offset/size */
  1192. #define EC_CMD_FLASH_REGION_INFO 0x0016
  1193. #define EC_VER_FLASH_REGION_INFO 1
  1194. enum ec_flash_region {
  1195. /* Region which holds read-only EC image */
  1196. EC_FLASH_REGION_RO = 0,
  1197. /* Region which holds active rewritable EC image */
  1198. EC_FLASH_REGION_ACTIVE,
  1199. /*
  1200. * Region which should be write-protected in the factory (a superset of
  1201. * EC_FLASH_REGION_RO)
  1202. */
  1203. EC_FLASH_REGION_WP_RO,
  1204. /* Region which holds updatable image */
  1205. EC_FLASH_REGION_UPDATE,
  1206. /* Number of regions */
  1207. EC_FLASH_REGION_COUNT,
  1208. };
  1209. struct __ec_align4 ec_params_flash_region_info {
  1210. uint32_t region; /* enum ec_flash_region */
  1211. };
  1212. struct __ec_align4 ec_response_flash_region_info {
  1213. uint32_t offset;
  1214. uint32_t size;
  1215. };
  1216. /* Read/write VbNvContext */
  1217. #define EC_CMD_VBNV_CONTEXT 0x0017
  1218. #define EC_VER_VBNV_CONTEXT 1
  1219. #define EC_VBNV_BLOCK_SIZE 16
  1220. #define EC_VBNV_BLOCK_SIZE_V2 64
  1221. enum ec_vbnvcontext_op {
  1222. EC_VBNV_CONTEXT_OP_READ,
  1223. EC_VBNV_CONTEXT_OP_WRITE,
  1224. };
  1225. struct __ec_align4 ec_params_vbnvcontext {
  1226. uint32_t op;
  1227. uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
  1228. };
  1229. struct __ec_align4 ec_response_vbnvcontext {
  1230. uint8_t block[EC_VBNV_BLOCK_SIZE_V2];
  1231. };
  1232. /* Get SPI flash information */
  1233. #define EC_CMD_FLASH_SPI_INFO 0x0018
  1234. struct __ec_align1 ec_response_flash_spi_info {
  1235. /* JEDEC info from command 0x9F (manufacturer, memory type, size) */
  1236. uint8_t jedec[3];
  1237. /* Pad byte; currently always contains 0 */
  1238. uint8_t reserved0;
  1239. /* Manufacturer / device ID from command 0x90 */
  1240. uint8_t mfr_dev_id[2];
  1241. /* Status registers from command 0x05 and 0x35 */
  1242. uint8_t sr1, sr2;
  1243. };
  1244. /* Select flash during flash operations */
  1245. #define EC_CMD_FLASH_SELECT 0x0019
  1246. struct __ec_align4 ec_params_flash_select {
  1247. /* 1 to select flash, 0 to deselect flash */
  1248. uint8_t select;
  1249. };
  1250. /*****************************************************************************/
  1251. /* PWM commands */
  1252. /* Get fan target RPM */
  1253. #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x0020
  1254. struct __ec_align4 ec_response_pwm_get_fan_rpm {
  1255. uint32_t rpm;
  1256. };
  1257. /* Set target fan RPM */
  1258. #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x0021
  1259. /* Version 0 of input params */
  1260. struct __ec_align4 ec_params_pwm_set_fan_target_rpm_v0 {
  1261. uint32_t rpm;
  1262. };
  1263. /* Version 1 of input params */
  1264. struct __ec_align_size1 ec_params_pwm_set_fan_target_rpm_v1 {
  1265. uint32_t rpm;
  1266. uint8_t fan_idx;
  1267. };
  1268. /* Get keyboard backlight */
  1269. /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
  1270. #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x0022
  1271. struct __ec_align1 ec_response_pwm_get_keyboard_backlight {
  1272. uint8_t percent;
  1273. uint8_t enabled;
  1274. };
  1275. /* Set keyboard backlight */
  1276. /* OBSOLETE - Use EC_CMD_PWM_SET_DUTY */
  1277. #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x0023
  1278. struct __ec_align1 ec_params_pwm_set_keyboard_backlight {
  1279. uint8_t percent;
  1280. };
  1281. /* Set target fan PWM duty cycle */
  1282. #define EC_CMD_PWM_SET_FAN_DUTY 0x0024
  1283. /* Version 0 of input params */
  1284. struct __ec_align4 ec_params_pwm_set_fan_duty_v0 {
  1285. uint32_t percent;
  1286. };
  1287. /* Version 1 of input params */
  1288. struct __ec_align_size1 ec_params_pwm_set_fan_duty_v1 {
  1289. uint32_t percent;
  1290. uint8_t fan_idx;
  1291. };
  1292. #define EC_CMD_PWM_SET_DUTY 0x0025
  1293. /* 16 bit duty cycle, 0xffff = 100% */
  1294. #define EC_PWM_MAX_DUTY 0xffff
  1295. enum ec_pwm_type {
  1296. /* All types, indexed by board-specific enum pwm_channel */
  1297. EC_PWM_TYPE_GENERIC = 0,
  1298. /* Keyboard backlight */
  1299. EC_PWM_TYPE_KB_LIGHT,
  1300. /* Display backlight */
  1301. EC_PWM_TYPE_DISPLAY_LIGHT,
  1302. EC_PWM_TYPE_COUNT,
  1303. };
  1304. struct __ec_align4 ec_params_pwm_set_duty {
  1305. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  1306. uint8_t pwm_type; /* ec_pwm_type */
  1307. uint8_t index; /* Type-specific index, or 0 if unique */
  1308. };
  1309. #define EC_CMD_PWM_GET_DUTY 0x0026
  1310. struct __ec_align1 ec_params_pwm_get_duty {
  1311. uint8_t pwm_type; /* ec_pwm_type */
  1312. uint8_t index; /* Type-specific index, or 0 if unique */
  1313. };
  1314. struct __ec_align2 ec_response_pwm_get_duty {
  1315. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  1316. };
  1317. /*****************************************************************************/
  1318. /*
  1319. * Lightbar commands. This looks worse than it is. Since we only use one HOST
  1320. * command to say "talk to the lightbar", we put the "and tell it to do X" part
  1321. * into a subcommand. We'll make separate structs for subcommands with
  1322. * different input args, so that we know how much to expect.
  1323. */
  1324. #define EC_CMD_LIGHTBAR_CMD 0x0028
  1325. struct __ec_todo_unpacked rgb_s {
  1326. uint8_t r, g, b;
  1327. };
  1328. #define LB_BATTERY_LEVELS 4
  1329. /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
  1330. * host command, but the alignment is the same regardless. Keep it that way.
  1331. */
  1332. struct __ec_todo_packed lightbar_params_v0 {
  1333. /* Timing */
  1334. int32_t google_ramp_up;
  1335. int32_t google_ramp_down;
  1336. int32_t s3s0_ramp_up;
  1337. int32_t s0_tick_delay[2]; /* AC=0/1 */
  1338. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  1339. int32_t s0s3_ramp_down;
  1340. int32_t s3_sleep_for;
  1341. int32_t s3_ramp_up;
  1342. int32_t s3_ramp_down;
  1343. /* Oscillation */
  1344. uint8_t new_s0;
  1345. uint8_t osc_min[2]; /* AC=0/1 */
  1346. uint8_t osc_max[2]; /* AC=0/1 */
  1347. uint8_t w_ofs[2]; /* AC=0/1 */
  1348. /* Brightness limits based on the backlight and AC. */
  1349. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  1350. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  1351. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  1352. /* Battery level thresholds */
  1353. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  1354. /* Map [AC][battery_level] to color index */
  1355. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  1356. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  1357. /* Color palette */
  1358. struct rgb_s color[8]; /* 0-3 are Google colors */
  1359. };
  1360. struct __ec_todo_packed lightbar_params_v1 {
  1361. /* Timing */
  1362. int32_t google_ramp_up;
  1363. int32_t google_ramp_down;
  1364. int32_t s3s0_ramp_up;
  1365. int32_t s0_tick_delay[2]; /* AC=0/1 */
  1366. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  1367. int32_t s0s3_ramp_down;
  1368. int32_t s3_sleep_for;
  1369. int32_t s3_ramp_up;
  1370. int32_t s3_ramp_down;
  1371. int32_t s5_ramp_up;
  1372. int32_t s5_ramp_down;
  1373. int32_t tap_tick_delay;
  1374. int32_t tap_gate_delay;
  1375. int32_t tap_display_time;
  1376. /* Tap-for-battery params */
  1377. uint8_t tap_pct_red;
  1378. uint8_t tap_pct_green;
  1379. uint8_t tap_seg_min_on;
  1380. uint8_t tap_seg_max_on;
  1381. uint8_t tap_seg_osc;
  1382. uint8_t tap_idx[3];
  1383. /* Oscillation */
  1384. uint8_t osc_min[2]; /* AC=0/1 */
  1385. uint8_t osc_max[2]; /* AC=0/1 */
  1386. uint8_t w_ofs[2]; /* AC=0/1 */
  1387. /* Brightness limits based on the backlight and AC. */
  1388. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  1389. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  1390. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  1391. /* Battery level thresholds */
  1392. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  1393. /* Map [AC][battery_level] to color index */
  1394. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  1395. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  1396. /* s5: single color pulse on inhibited power-up */
  1397. uint8_t s5_idx;
  1398. /* Color palette */
  1399. struct rgb_s color[8]; /* 0-3 are Google colors */
  1400. };
  1401. /* Lightbar command params v2
  1402. * crbug.com/467716
  1403. *
  1404. * lightbar_parms_v1 was too big for i2c, therefore in v2, we split them up by
  1405. * logical groups to make it more manageable ( < 120 bytes).
  1406. *
  1407. * NOTE: Each of these groups must be less than 120 bytes.
  1408. */
  1409. struct __ec_todo_packed lightbar_params_v2_timing {
  1410. /* Timing */
  1411. int32_t google_ramp_up;
  1412. int32_t google_ramp_down;
  1413. int32_t s3s0_ramp_up;
  1414. int32_t s0_tick_delay[2]; /* AC=0/1 */
  1415. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  1416. int32_t s0s3_ramp_down;
  1417. int32_t s3_sleep_for;
  1418. int32_t s3_ramp_up;
  1419. int32_t s3_ramp_down;
  1420. int32_t s5_ramp_up;
  1421. int32_t s5_ramp_down;
  1422. int32_t tap_tick_delay;
  1423. int32_t tap_gate_delay;
  1424. int32_t tap_display_time;
  1425. };
  1426. struct __ec_todo_packed lightbar_params_v2_tap {
  1427. /* Tap-for-battery params */
  1428. uint8_t tap_pct_red;
  1429. uint8_t tap_pct_green;
  1430. uint8_t tap_seg_min_on;
  1431. uint8_t tap_seg_max_on;
  1432. uint8_t tap_seg_osc;
  1433. uint8_t tap_idx[3];
  1434. };
  1435. struct __ec_todo_packed lightbar_params_v2_oscillation {
  1436. /* Oscillation */
  1437. uint8_t osc_min[2]; /* AC=0/1 */
  1438. uint8_t osc_max[2]; /* AC=0/1 */
  1439. uint8_t w_ofs[2]; /* AC=0/1 */
  1440. };
  1441. struct __ec_todo_packed lightbar_params_v2_brightness {
  1442. /* Brightness limits based on the backlight and AC. */
  1443. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  1444. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  1445. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  1446. };
  1447. struct __ec_todo_packed lightbar_params_v2_thresholds {
  1448. /* Battery level thresholds */
  1449. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  1450. };
  1451. struct __ec_todo_packed lightbar_params_v2_colors {
  1452. /* Map [AC][battery_level] to color index */
  1453. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  1454. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  1455. /* s5: single color pulse on inhibited power-up */
  1456. uint8_t s5_idx;
  1457. /* Color palette */
  1458. struct rgb_s color[8]; /* 0-3 are Google colors */
  1459. };
  1460. /* Lightbyte program. */
  1461. #define EC_LB_PROG_LEN 192
  1462. struct __ec_todo_unpacked lightbar_program {
  1463. uint8_t size;
  1464. uint8_t data[EC_LB_PROG_LEN];
  1465. };
  1466. struct __ec_todo_packed ec_params_lightbar {
  1467. uint8_t cmd; /* Command (see enum lightbar_command) */
  1468. union {
  1469. struct __ec_todo_unpacked {
  1470. /* no args */
  1471. } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
  1472. version, get_brightness, get_demo, suspend, resume,
  1473. get_params_v2_timing, get_params_v2_tap,
  1474. get_params_v2_osc, get_params_v2_bright,
  1475. get_params_v2_thlds, get_params_v2_colors;
  1476. struct __ec_todo_unpacked {
  1477. uint8_t num;
  1478. } set_brightness, seq, demo;
  1479. struct __ec_todo_unpacked {
  1480. uint8_t ctrl, reg, value;
  1481. } reg;
  1482. struct __ec_todo_unpacked {
  1483. uint8_t led, red, green, blue;
  1484. } set_rgb;
  1485. struct __ec_todo_unpacked {
  1486. uint8_t led;
  1487. } get_rgb;
  1488. struct __ec_todo_unpacked {
  1489. uint8_t enable;
  1490. } manual_suspend_ctrl;
  1491. struct lightbar_params_v0 set_params_v0;
  1492. struct lightbar_params_v1 set_params_v1;
  1493. struct lightbar_params_v2_timing set_v2par_timing;
  1494. struct lightbar_params_v2_tap set_v2par_tap;
  1495. struct lightbar_params_v2_oscillation set_v2par_osc;
  1496. struct lightbar_params_v2_brightness set_v2par_bright;
  1497. struct lightbar_params_v2_thresholds set_v2par_thlds;
  1498. struct lightbar_params_v2_colors set_v2par_colors;
  1499. struct lightbar_program set_program;
  1500. };
  1501. };
  1502. struct __ec_todo_packed ec_response_lightbar {
  1503. union {
  1504. struct __ec_todo_unpacked {
  1505. struct __ec_todo_unpacked {
  1506. uint8_t reg;
  1507. uint8_t ic0;
  1508. uint8_t ic1;
  1509. } vals[23];
  1510. } dump;
  1511. struct __ec_todo_unpacked {
  1512. uint8_t num;
  1513. } get_seq, get_brightness, get_demo;
  1514. struct lightbar_params_v0 get_params_v0;
  1515. struct lightbar_params_v1 get_params_v1;
  1516. struct lightbar_params_v2_timing get_params_v2_timing;
  1517. struct lightbar_params_v2_tap get_params_v2_tap;
  1518. struct lightbar_params_v2_oscillation get_params_v2_osc;
  1519. struct lightbar_params_v2_brightness get_params_v2_bright;
  1520. struct lightbar_params_v2_thresholds get_params_v2_thlds;
  1521. struct lightbar_params_v2_colors get_params_v2_colors;
  1522. struct __ec_todo_unpacked {
  1523. uint32_t num;
  1524. uint32_t flags;
  1525. } version;
  1526. struct __ec_todo_unpacked {
  1527. uint8_t red, green, blue;
  1528. } get_rgb;
  1529. struct __ec_todo_unpacked {
  1530. /* no return params */
  1531. } off, on, init, set_brightness, seq, reg, set_rgb,
  1532. demo, set_params_v0, set_params_v1,
  1533. set_program, manual_suspend_ctrl, suspend, resume,
  1534. set_v2par_timing, set_v2par_tap,
  1535. set_v2par_osc, set_v2par_bright, set_v2par_thlds,
  1536. set_v2par_colors;
  1537. };
  1538. };
  1539. /* Lightbar commands */
  1540. enum lightbar_command {
  1541. LIGHTBAR_CMD_DUMP = 0,
  1542. LIGHTBAR_CMD_OFF = 1,
  1543. LIGHTBAR_CMD_ON = 2,
  1544. LIGHTBAR_CMD_INIT = 3,
  1545. LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
  1546. LIGHTBAR_CMD_SEQ = 5,
  1547. LIGHTBAR_CMD_REG = 6,
  1548. LIGHTBAR_CMD_SET_RGB = 7,
  1549. LIGHTBAR_CMD_GET_SEQ = 8,
  1550. LIGHTBAR_CMD_DEMO = 9,
  1551. LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
  1552. LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
  1553. LIGHTBAR_CMD_VERSION = 12,
  1554. LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
  1555. LIGHTBAR_CMD_GET_RGB = 14,
  1556. LIGHTBAR_CMD_GET_DEMO = 15,
  1557. LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
  1558. LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
  1559. LIGHTBAR_CMD_SET_PROGRAM = 18,
  1560. LIGHTBAR_CMD_MANUAL_SUSPEND_CTRL = 19,
  1561. LIGHTBAR_CMD_SUSPEND = 20,
  1562. LIGHTBAR_CMD_RESUME = 21,
  1563. LIGHTBAR_CMD_GET_PARAMS_V2_TIMING = 22,
  1564. LIGHTBAR_CMD_SET_PARAMS_V2_TIMING = 23,
  1565. LIGHTBAR_CMD_GET_PARAMS_V2_TAP = 24,
  1566. LIGHTBAR_CMD_SET_PARAMS_V2_TAP = 25,
  1567. LIGHTBAR_CMD_GET_PARAMS_V2_OSCILLATION = 26,
  1568. LIGHTBAR_CMD_SET_PARAMS_V2_OSCILLATION = 27,
  1569. LIGHTBAR_CMD_GET_PARAMS_V2_BRIGHTNESS = 28,
  1570. LIGHTBAR_CMD_SET_PARAMS_V2_BRIGHTNESS = 29,
  1571. LIGHTBAR_CMD_GET_PARAMS_V2_THRESHOLDS = 30,
  1572. LIGHTBAR_CMD_SET_PARAMS_V2_THRESHOLDS = 31,
  1573. LIGHTBAR_CMD_GET_PARAMS_V2_COLORS = 32,
  1574. LIGHTBAR_CMD_SET_PARAMS_V2_COLORS = 33,
  1575. LIGHTBAR_NUM_CMDS
  1576. };
  1577. /*****************************************************************************/
  1578. /* LED control commands */
  1579. #define EC_CMD_LED_CONTROL 0x0029
  1580. enum ec_led_id {
  1581. /* LED to indicate battery state of charge */
  1582. EC_LED_ID_BATTERY_LED = 0,
  1583. /*
  1584. * LED to indicate system power state (on or in suspend).
  1585. * May be on power button or on C-panel.
  1586. */
  1587. EC_LED_ID_POWER_LED,
  1588. /* LED on power adapter or its plug */
  1589. EC_LED_ID_ADAPTER_LED,
  1590. /* LED to indicate left side */
  1591. EC_LED_ID_LEFT_LED,
  1592. /* LED to indicate right side */
  1593. EC_LED_ID_RIGHT_LED,
  1594. /* LED to indicate recovery mode with HW_REINIT */
  1595. EC_LED_ID_RECOVERY_HW_REINIT_LED,
  1596. /* LED to indicate sysrq debug mode. */
  1597. EC_LED_ID_SYSRQ_DEBUG_LED,
  1598. EC_LED_ID_COUNT
  1599. };
  1600. /* LED control flags */
  1601. #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
  1602. #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
  1603. enum ec_led_colors {
  1604. EC_LED_COLOR_RED = 0,
  1605. EC_LED_COLOR_GREEN,
  1606. EC_LED_COLOR_BLUE,
  1607. EC_LED_COLOR_YELLOW,
  1608. EC_LED_COLOR_WHITE,
  1609. EC_LED_COLOR_AMBER,
  1610. EC_LED_COLOR_COUNT
  1611. };
  1612. struct __ec_align1 ec_params_led_control {
  1613. uint8_t led_id; /* Which LED to control */
  1614. uint8_t flags; /* Control flags */
  1615. uint8_t brightness[EC_LED_COLOR_COUNT];
  1616. };
  1617. struct __ec_align1 ec_response_led_control {
  1618. /*
  1619. * Available brightness value range.
  1620. *
  1621. * Range 0 means color channel not present.
  1622. * Range 1 means on/off control.
  1623. * Other values means the LED is control by PWM.
  1624. */
  1625. uint8_t brightness_range[EC_LED_COLOR_COUNT];
  1626. };
  1627. /*****************************************************************************/
  1628. /* Verified boot commands */
  1629. /*
  1630. * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
  1631. * reused for other purposes with version > 0.
  1632. */
  1633. /* Verified boot hash command */
  1634. #define EC_CMD_VBOOT_HASH 0x002A
  1635. struct __ec_align4 ec_params_vboot_hash {
  1636. uint8_t cmd; /* enum ec_vboot_hash_cmd */
  1637. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1638. uint8_t nonce_size; /* Nonce size; may be 0 */
  1639. uint8_t reserved0; /* Reserved; set 0 */
  1640. uint32_t offset; /* Offset in flash to hash */
  1641. uint32_t size; /* Number of bytes to hash */
  1642. uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
  1643. };
  1644. struct __ec_align4 ec_response_vboot_hash {
  1645. uint8_t status; /* enum ec_vboot_hash_status */
  1646. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1647. uint8_t digest_size; /* Size of hash digest in bytes */
  1648. uint8_t reserved0; /* Ignore; will be 0 */
  1649. uint32_t offset; /* Offset in flash which was hashed */
  1650. uint32_t size; /* Number of bytes hashed */
  1651. uint8_t hash_digest[64]; /* Hash digest data */
  1652. };
  1653. enum ec_vboot_hash_cmd {
  1654. EC_VBOOT_HASH_GET = 0, /* Get current hash status */
  1655. EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
  1656. EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
  1657. EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
  1658. };
  1659. enum ec_vboot_hash_type {
  1660. EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
  1661. };
  1662. enum ec_vboot_hash_status {
  1663. EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
  1664. EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
  1665. EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
  1666. };
  1667. /*
  1668. * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
  1669. * If one of these is specified, the EC will automatically update offset and
  1670. * size to the correct values for the specified image (RO or RW).
  1671. */
  1672. #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
  1673. #define EC_VBOOT_HASH_OFFSET_ACTIVE 0xfffffffd
  1674. #define EC_VBOOT_HASH_OFFSET_UPDATE 0xfffffffc
  1675. /*****************************************************************************/
  1676. /*
  1677. * Motion sense commands. We'll make separate structs for sub-commands with
  1678. * different input args, so that we know how much to expect.
  1679. */
  1680. #define EC_CMD_MOTION_SENSE_CMD 0x002B
  1681. /* Motion sense commands */
  1682. enum motionsense_command {
  1683. /*
  1684. * Dump command returns all motion sensor data including motion sense
  1685. * module flags and individual sensor flags.
  1686. */
  1687. MOTIONSENSE_CMD_DUMP = 0,
  1688. /*
  1689. * Info command returns data describing the details of a given sensor,
  1690. * including enum motionsensor_type, enum motionsensor_location, and
  1691. * enum motionsensor_chip.
  1692. */
  1693. MOTIONSENSE_CMD_INFO = 1,
  1694. /*
  1695. * EC Rate command is a setter/getter command for the EC sampling rate
  1696. * in milliseconds.
  1697. * It is per sensor, the EC run sample task at the minimum of all
  1698. * sensors EC_RATE.
  1699. * For sensors without hardware FIFO, EC_RATE should be equals to 1/ODR
  1700. * to collect all the sensor samples.
  1701. * For sensor with hardware FIFO, EC_RATE is used as the maximal delay
  1702. * to process of all motion sensors in milliseconds.
  1703. */
  1704. MOTIONSENSE_CMD_EC_RATE = 2,
  1705. /*
  1706. * Sensor ODR command is a setter/getter command for the output data
  1707. * rate of a specific motion sensor in millihertz.
  1708. */
  1709. MOTIONSENSE_CMD_SENSOR_ODR = 3,
  1710. /*
  1711. * Sensor range command is a setter/getter command for the range of
  1712. * a specified motion sensor in +/-G's or +/- deg/s.
  1713. */
  1714. MOTIONSENSE_CMD_SENSOR_RANGE = 4,
  1715. /*
  1716. * Setter/getter command for the keyboard wake angle. When the lid
  1717. * angle is greater than this value, keyboard wake is disabled in S3,
  1718. * and when the lid angle goes less than this value, keyboard wake is
  1719. * enabled. Note, the lid angle measurement is an approximate,
  1720. * un-calibrated value, hence the wake angle isn't exact.
  1721. */
  1722. MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
  1723. /*
  1724. * Returns a single sensor data.
  1725. */
  1726. MOTIONSENSE_CMD_DATA = 6,
  1727. /*
  1728. * Return sensor fifo info.
  1729. */
  1730. MOTIONSENSE_CMD_FIFO_INFO = 7,
  1731. /*
  1732. * Insert a flush element in the fifo and return sensor fifo info.
  1733. * The host can use that element to synchronize its operation.
  1734. */
  1735. MOTIONSENSE_CMD_FIFO_FLUSH = 8,
  1736. /*
  1737. * Return a portion of the fifo.
  1738. */
  1739. MOTIONSENSE_CMD_FIFO_READ = 9,
  1740. /*
  1741. * Perform low level calibration.
  1742. * On sensors that support it, ask to do offset calibration.
  1743. */
  1744. MOTIONSENSE_CMD_PERFORM_CALIB = 10,
  1745. /*
  1746. * Sensor Offset command is a setter/getter command for the offset
  1747. * used for calibration.
  1748. * The offsets can be calculated by the host, or via
  1749. * PERFORM_CALIB command.
  1750. */
  1751. MOTIONSENSE_CMD_SENSOR_OFFSET = 11,
  1752. /*
  1753. * List available activities for a MOTION sensor.
  1754. * Indicates if they are enabled or disabled.
  1755. */
  1756. MOTIONSENSE_CMD_LIST_ACTIVITIES = 12,
  1757. /*
  1758. * Activity management
  1759. * Enable/Disable activity recognition.
  1760. */
  1761. MOTIONSENSE_CMD_SET_ACTIVITY = 13,
  1762. /*
  1763. * Lid Angle
  1764. */
  1765. MOTIONSENSE_CMD_LID_ANGLE = 14,
  1766. /*
  1767. * Allow the FIFO to trigger interrupt via MKBP events.
  1768. * By default the FIFO does not send interrupt to process the FIFO
  1769. * until the AP is ready or it is coming from a wakeup sensor.
  1770. */
  1771. MOTIONSENSE_CMD_FIFO_INT_ENABLE = 15,
  1772. /*
  1773. * Spoof the readings of the sensors. The spoofed readings can be set
  1774. * to arbitrary values, or will lock to the last read actual values.
  1775. */
  1776. MOTIONSENSE_CMD_SPOOF = 16,
  1777. /* Number of motionsense sub-commands. */
  1778. MOTIONSENSE_NUM_CMDS
  1779. };
  1780. /* List of motion sensor types. */
  1781. enum motionsensor_type {
  1782. MOTIONSENSE_TYPE_ACCEL = 0,
  1783. MOTIONSENSE_TYPE_GYRO = 1,
  1784. MOTIONSENSE_TYPE_MAG = 2,
  1785. MOTIONSENSE_TYPE_PROX = 3,
  1786. MOTIONSENSE_TYPE_LIGHT = 4,
  1787. MOTIONSENSE_TYPE_ACTIVITY = 5,
  1788. MOTIONSENSE_TYPE_BARO = 6,
  1789. MOTIONSENSE_TYPE_MAX,
  1790. };
  1791. /* List of motion sensor locations. */
  1792. enum motionsensor_location {
  1793. MOTIONSENSE_LOC_BASE = 0,
  1794. MOTIONSENSE_LOC_LID = 1,
  1795. MOTIONSENSE_LOC_MAX,
  1796. };
  1797. /* List of motion sensor chips. */
  1798. enum motionsensor_chip {
  1799. MOTIONSENSE_CHIP_KXCJ9 = 0,
  1800. MOTIONSENSE_CHIP_LSM6DS0 = 1,
  1801. MOTIONSENSE_CHIP_BMI160 = 2,
  1802. MOTIONSENSE_CHIP_SI1141 = 3,
  1803. MOTIONSENSE_CHIP_SI1142 = 4,
  1804. MOTIONSENSE_CHIP_SI1143 = 5,
  1805. MOTIONSENSE_CHIP_KX022 = 6,
  1806. MOTIONSENSE_CHIP_L3GD20H = 7,
  1807. MOTIONSENSE_CHIP_BMA255 = 8,
  1808. MOTIONSENSE_CHIP_BMP280 = 9,
  1809. MOTIONSENSE_CHIP_OPT3001 = 10,
  1810. };
  1811. struct __ec_todo_packed ec_response_motion_sensor_data {
  1812. /* Flags for each sensor. */
  1813. uint8_t flags;
  1814. /* sensor number the data comes from */
  1815. uint8_t sensor_num;
  1816. /* Each sensor is up to 3-axis. */
  1817. union {
  1818. int16_t data[3];
  1819. struct __ec_todo_packed {
  1820. uint16_t reserved;
  1821. uint32_t timestamp;
  1822. };
  1823. struct __ec_todo_unpacked {
  1824. uint8_t activity; /* motionsensor_activity */
  1825. uint8_t state;
  1826. int16_t add_info[2];
  1827. };
  1828. };
  1829. };
  1830. /* Note: used in ec_response_get_next_data */
  1831. struct __ec_todo_packed ec_response_motion_sense_fifo_info {
  1832. /* Size of the fifo */
  1833. uint16_t size;
  1834. /* Amount of space used in the fifo */
  1835. uint16_t count;
  1836. /* Timestamp recorded in us */
  1837. uint32_t timestamp;
  1838. /* Total amount of vector lost */
  1839. uint16_t total_lost;
  1840. /* Lost events since the last fifo_info, per sensors */
  1841. uint16_t lost[0];
  1842. };
  1843. struct __ec_todo_packed ec_response_motion_sense_fifo_data {
  1844. uint32_t number_data;
  1845. struct ec_response_motion_sensor_data data[0];
  1846. };
  1847. /* List supported activity recognition */
  1848. enum motionsensor_activity {
  1849. MOTIONSENSE_ACTIVITY_RESERVED = 0,
  1850. MOTIONSENSE_ACTIVITY_SIG_MOTION = 1,
  1851. MOTIONSENSE_ACTIVITY_DOUBLE_TAP = 2,
  1852. };
  1853. struct __ec_todo_unpacked ec_motion_sense_activity {
  1854. uint8_t sensor_num;
  1855. uint8_t activity; /* one of enum motionsensor_activity */
  1856. uint8_t enable; /* 1: enable, 0: disable */
  1857. uint8_t reserved;
  1858. uint16_t parameters[3]; /* activity dependent parameters */
  1859. };
  1860. /* Module flag masks used for the dump sub-command. */
  1861. #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
  1862. /* Sensor flag masks used for the dump sub-command. */
  1863. #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
  1864. /*
  1865. * Flush entry for synchronization.
  1866. * data contains time stamp
  1867. */
  1868. #define MOTIONSENSE_SENSOR_FLAG_FLUSH (1<<0)
  1869. #define MOTIONSENSE_SENSOR_FLAG_TIMESTAMP (1<<1)
  1870. #define MOTIONSENSE_SENSOR_FLAG_WAKEUP (1<<2)
  1871. #define MOTIONSENSE_SENSOR_FLAG_TABLET_MODE (1<<3)
  1872. /*
  1873. * Send this value for the data element to only perform a read. If you
  1874. * send any other value, the EC will interpret it as data to set and will
  1875. * return the actual value set.
  1876. */
  1877. #define EC_MOTION_SENSE_NO_VALUE -1
  1878. #define EC_MOTION_SENSE_INVALID_CALIB_TEMP 0x8000
  1879. /* MOTIONSENSE_CMD_SENSOR_OFFSET subcommand flag */
  1880. /* Set Calibration information */
  1881. #define MOTION_SENSE_SET_OFFSET 1
  1882. #define LID_ANGLE_UNRELIABLE 500
  1883. enum motionsense_spoof_mode {
  1884. /* Disable spoof mode. */
  1885. MOTIONSENSE_SPOOF_MODE_DISABLE = 0,
  1886. /* Enable spoof mode, but use provided component values. */
  1887. MOTIONSENSE_SPOOF_MODE_CUSTOM,
  1888. /* Enable spoof mode, but use the current sensor values. */
  1889. MOTIONSENSE_SPOOF_MODE_LOCK_CURRENT,
  1890. /* Query the current spoof mode status for the sensor. */
  1891. MOTIONSENSE_SPOOF_MODE_QUERY,
  1892. };
  1893. struct __ec_todo_packed ec_params_motion_sense {
  1894. uint8_t cmd;
  1895. union {
  1896. /* Used for MOTIONSENSE_CMD_DUMP */
  1897. struct __ec_todo_unpacked {
  1898. /*
  1899. * Maximal number of sensor the host is expecting.
  1900. * 0 means the host is only interested in the number
  1901. * of sensors controlled by the EC.
  1902. */
  1903. uint8_t max_sensor_count;
  1904. } dump;
  1905. /*
  1906. * Used for MOTIONSENSE_CMD_KB_WAKE_ANGLE.
  1907. */
  1908. struct __ec_todo_unpacked {
  1909. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read.
  1910. * kb_wake_angle: angle to wakup AP.
  1911. */
  1912. int16_t data;
  1913. } kb_wake_angle;
  1914. /* Used for MOTIONSENSE_CMD_INFO, MOTIONSENSE_CMD_DATA
  1915. * and MOTIONSENSE_CMD_PERFORM_CALIB. */
  1916. struct __ec_todo_unpacked {
  1917. uint8_t sensor_num;
  1918. } info, info_3, data, fifo_flush, perform_calib,
  1919. list_activities;
  1920. /*
  1921. * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR
  1922. * and MOTIONSENSE_CMD_SENSOR_RANGE.
  1923. */
  1924. struct __ec_todo_unpacked {
  1925. uint8_t sensor_num;
  1926. /* Rounding flag, true for round-up, false for down. */
  1927. uint8_t roundup;
  1928. uint16_t reserved;
  1929. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
  1930. int32_t data;
  1931. } ec_rate, sensor_odr, sensor_range;
  1932. /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
  1933. struct __ec_todo_packed {
  1934. uint8_t sensor_num;
  1935. /*
  1936. * bit 0: If set (MOTION_SENSE_SET_OFFSET), set
  1937. * the calibration information in the EC.
  1938. * If unset, just retrieve calibration information.
  1939. */
  1940. uint16_t flags;
  1941. /*
  1942. * Temperature at calibration, in units of 0.01 C
  1943. * 0x8000: invalid / unknown.
  1944. * 0x0: 0C
  1945. * 0x7fff: +327.67C
  1946. */
  1947. int16_t temp;
  1948. /*
  1949. * Offset for calibration.
  1950. * Unit:
  1951. * Accelerometer: 1/1024 g
  1952. * Gyro: 1/1024 deg/s
  1953. * Compass: 1/16 uT
  1954. */
  1955. int16_t offset[3];
  1956. } sensor_offset;
  1957. /* Used for MOTIONSENSE_CMD_FIFO_INFO */
  1958. struct __ec_todo_unpacked {
  1959. } fifo_info;
  1960. /* Used for MOTIONSENSE_CMD_FIFO_READ */
  1961. struct __ec_todo_unpacked {
  1962. /*
  1963. * Number of expected vector to return.
  1964. * EC may return less or 0 if none available.
  1965. */
  1966. uint32_t max_data_vector;
  1967. } fifo_read;
  1968. struct ec_motion_sense_activity set_activity;
  1969. /* Used for MOTIONSENSE_CMD_LID_ANGLE */
  1970. struct __ec_todo_unpacked {
  1971. } lid_angle;
  1972. /* Used for MOTIONSENSE_CMD_FIFO_INT_ENABLE */
  1973. struct __ec_todo_unpacked {
  1974. /*
  1975. * 1: enable, 0 disable fifo,
  1976. * EC_MOTION_SENSE_NO_VALUE return value.
  1977. */
  1978. int8_t enable;
  1979. } fifo_int_enable;
  1980. /* Used for MOTIONSENSE_CMD_SPOOF */
  1981. struct __ec_todo_packed {
  1982. uint8_t sensor_id;
  1983. /* See enum motionsense_spoof_mode. */
  1984. uint8_t spoof_enable;
  1985. /* Ignored, used for alignment. */
  1986. uint8_t reserved;
  1987. /* Individual component values to spoof. */
  1988. int16_t components[3];
  1989. } spoof;
  1990. };
  1991. };
  1992. struct __ec_todo_packed ec_response_motion_sense {
  1993. union {
  1994. /* Used for MOTIONSENSE_CMD_DUMP */
  1995. struct __ec_todo_unpacked {
  1996. /* Flags representing the motion sensor module. */
  1997. uint8_t module_flags;
  1998. /* Number of sensors managed directly by the EC */
  1999. uint8_t sensor_count;
  2000. /*
  2001. * sensor data is truncated if response_max is too small
  2002. * for holding all the data.
  2003. */
  2004. struct ec_response_motion_sensor_data sensor[0];
  2005. } dump;
  2006. /* Used for MOTIONSENSE_CMD_INFO. */
  2007. struct __ec_todo_unpacked {
  2008. /* Should be element of enum motionsensor_type. */
  2009. uint8_t type;
  2010. /* Should be element of enum motionsensor_location. */
  2011. uint8_t location;
  2012. /* Should be element of enum motionsensor_chip. */
  2013. uint8_t chip;
  2014. } info;
  2015. /* Used for MOTIONSENSE_CMD_INFO version 3 */
  2016. struct __ec_todo_unpacked {
  2017. /* Should be element of enum motionsensor_type. */
  2018. uint8_t type;
  2019. /* Should be element of enum motionsensor_location. */
  2020. uint8_t location;
  2021. /* Should be element of enum motionsensor_chip. */
  2022. uint8_t chip;
  2023. /* Minimum sensor sampling frequency */
  2024. uint32_t min_frequency;
  2025. /* Maximum sensor sampling frequency */
  2026. uint32_t max_frequency;
  2027. /* Max number of sensor events that could be in fifo */
  2028. uint32_t fifo_max_event_count;
  2029. } info_3;
  2030. /* Used for MOTIONSENSE_CMD_DATA */
  2031. struct ec_response_motion_sensor_data data;
  2032. /*
  2033. * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
  2034. * MOTIONSENSE_CMD_SENSOR_RANGE,
  2035. * MOTIONSENSE_CMD_KB_WAKE_ANGLE,
  2036. * MOTIONSENSE_CMD_FIFO_INT_ENABLE and
  2037. * MOTIONSENSE_CMD_SPOOF.
  2038. */
  2039. struct __ec_todo_unpacked {
  2040. /* Current value of the parameter queried. */
  2041. int32_t ret;
  2042. } ec_rate, sensor_odr, sensor_range, kb_wake_angle,
  2043. fifo_int_enable, spoof;
  2044. /* Used for MOTIONSENSE_CMD_SENSOR_OFFSET */
  2045. struct __ec_todo_unpacked {
  2046. int16_t temp;
  2047. int16_t offset[3];
  2048. } sensor_offset, perform_calib;
  2049. struct ec_response_motion_sense_fifo_info fifo_info, fifo_flush;
  2050. struct ec_response_motion_sense_fifo_data fifo_read;
  2051. struct __ec_todo_packed {
  2052. uint16_t reserved;
  2053. uint32_t enabled;
  2054. uint32_t disabled;
  2055. } list_activities;
  2056. struct __ec_todo_unpacked {
  2057. } set_activity;
  2058. /* Used for MOTIONSENSE_CMD_LID_ANGLE */
  2059. struct __ec_todo_unpacked {
  2060. /*
  2061. * Angle between 0 and 360 degree if available,
  2062. * LID_ANGLE_UNRELIABLE otherwise.
  2063. */
  2064. uint16_t value;
  2065. } lid_angle;
  2066. };
  2067. };
  2068. /*****************************************************************************/
  2069. /* Force lid open command */
  2070. /* Make lid event always open */
  2071. #define EC_CMD_FORCE_LID_OPEN 0x002C
  2072. struct __ec_align1 ec_params_force_lid_open {
  2073. uint8_t enabled;
  2074. };
  2075. /*****************************************************************************/
  2076. /* Configure the behavior of the power button */
  2077. #define EC_CMD_CONFIG_POWER_BUTTON 0x002D
  2078. enum ec_config_power_button_flags {
  2079. /* Enable/Disable power button pulses for x86 devices */
  2080. EC_POWER_BUTTON_ENABLE_PULSE = (1 << 0),
  2081. };
  2082. struct __ec_align1 ec_params_config_power_button {
  2083. /* See enum ec_config_power_button_flags */
  2084. uint8_t flags;
  2085. };
  2086. /*****************************************************************************/
  2087. /* USB charging control commands */
  2088. /* Set USB port charging mode */
  2089. #define EC_CMD_USB_CHARGE_SET_MODE 0x0030
  2090. struct __ec_align1 ec_params_usb_charge_set_mode {
  2091. uint8_t usb_port_id;
  2092. uint8_t mode;
  2093. };
  2094. /*****************************************************************************/
  2095. /* Persistent storage for host */
  2096. /* Maximum bytes that can be read/written in a single command */
  2097. #define EC_PSTORE_SIZE_MAX 64
  2098. /* Get persistent storage info */
  2099. #define EC_CMD_PSTORE_INFO 0x0040
  2100. struct __ec_align4 ec_response_pstore_info {
  2101. /* Persistent storage size, in bytes */
  2102. uint32_t pstore_size;
  2103. /* Access size; read/write offset and size must be a multiple of this */
  2104. uint32_t access_size;
  2105. };
  2106. /*
  2107. * Read persistent storage
  2108. *
  2109. * Response is params.size bytes of data.
  2110. */
  2111. #define EC_CMD_PSTORE_READ 0x0041
  2112. struct __ec_align4 ec_params_pstore_read {
  2113. uint32_t offset; /* Byte offset to read */
  2114. uint32_t size; /* Size to read in bytes */
  2115. };
  2116. /* Write persistent storage */
  2117. #define EC_CMD_PSTORE_WRITE 0x0042
  2118. struct __ec_align4 ec_params_pstore_write {
  2119. uint32_t offset; /* Byte offset to write */
  2120. uint32_t size; /* Size to write in bytes */
  2121. uint8_t data[EC_PSTORE_SIZE_MAX];
  2122. };
  2123. /*****************************************************************************/
  2124. /* Real-time clock */
  2125. /* RTC params and response structures */
  2126. struct __ec_align4 ec_params_rtc {
  2127. uint32_t time;
  2128. };
  2129. struct __ec_align4 ec_response_rtc {
  2130. uint32_t time;
  2131. };
  2132. /* These use ec_response_rtc */
  2133. #define EC_CMD_RTC_GET_VALUE 0x0044
  2134. #define EC_CMD_RTC_GET_ALARM 0x0045
  2135. /* These all use ec_params_rtc */
  2136. #define EC_CMD_RTC_SET_VALUE 0x0046
  2137. #define EC_CMD_RTC_SET_ALARM 0x0047
  2138. /* Pass as time param to SET_ALARM to clear the current alarm */
  2139. #define EC_RTC_ALARM_CLEAR 0
  2140. /*****************************************************************************/
  2141. /* Port80 log access */
  2142. /* Maximum entries that can be read/written in a single command */
  2143. #define EC_PORT80_SIZE_MAX 32
  2144. /* Get last port80 code from previous boot */
  2145. #define EC_CMD_PORT80_LAST_BOOT 0x0048
  2146. #define EC_CMD_PORT80_READ 0x0048
  2147. enum ec_port80_subcmd {
  2148. EC_PORT80_GET_INFO = 0,
  2149. EC_PORT80_READ_BUFFER,
  2150. };
  2151. struct __ec_todo_packed ec_params_port80_read {
  2152. uint16_t subcmd;
  2153. union {
  2154. struct __ec_todo_unpacked {
  2155. uint32_t offset;
  2156. uint32_t num_entries;
  2157. } read_buffer;
  2158. };
  2159. };
  2160. struct __ec_todo_packed ec_response_port80_read {
  2161. union {
  2162. struct __ec_todo_unpacked {
  2163. uint32_t writes;
  2164. uint32_t history_size;
  2165. uint32_t last_boot;
  2166. } get_info;
  2167. struct __ec_todo_unpacked {
  2168. uint16_t codes[EC_PORT80_SIZE_MAX];
  2169. } data;
  2170. };
  2171. };
  2172. struct __ec_align2 ec_response_port80_last_boot {
  2173. uint16_t code;
  2174. };
  2175. /*****************************************************************************/
  2176. /* Temporary secure storage for host verified boot use */
  2177. /* Number of bytes in a vstore slot */
  2178. #define EC_VSTORE_SLOT_SIZE 64
  2179. /* Maximum number of vstore slots */
  2180. #define EC_VSTORE_SLOT_MAX 32
  2181. /* Get persistent storage info */
  2182. #define EC_CMD_VSTORE_INFO 0x0049
  2183. struct __ec_align_size1 ec_response_vstore_info {
  2184. /* Indicates which slots are locked */
  2185. uint32_t slot_locked;
  2186. /* Total number of slots available */
  2187. uint8_t slot_count;
  2188. };
  2189. /*
  2190. * Read temporary secure storage
  2191. *
  2192. * Response is EC_VSTORE_SLOT_SIZE bytes of data.
  2193. */
  2194. #define EC_CMD_VSTORE_READ 0x004A
  2195. struct __ec_align1 ec_params_vstore_read {
  2196. uint8_t slot; /* Slot to read from */
  2197. };
  2198. struct __ec_align1 ec_response_vstore_read {
  2199. uint8_t data[EC_VSTORE_SLOT_SIZE];
  2200. };
  2201. /*
  2202. * Write temporary secure storage and lock it.
  2203. */
  2204. #define EC_CMD_VSTORE_WRITE 0x004B
  2205. struct __ec_align1 ec_params_vstore_write {
  2206. uint8_t slot; /* Slot to write to */
  2207. uint8_t data[EC_VSTORE_SLOT_SIZE];
  2208. };
  2209. /*****************************************************************************/
  2210. /* Thermal engine commands. Note that there are two implementations. We'll
  2211. * reuse the command number, but the data and behavior is incompatible.
  2212. * Version 0 is what originally shipped on Link.
  2213. * Version 1 separates the CPU thermal limits from the fan control.
  2214. */
  2215. #define EC_CMD_THERMAL_SET_THRESHOLD 0x0050
  2216. #define EC_CMD_THERMAL_GET_THRESHOLD 0x0051
  2217. /* The version 0 structs are opaque. You have to know what they are for
  2218. * the get/set commands to make any sense.
  2219. */
  2220. /* Version 0 - set */
  2221. struct __ec_align2 ec_params_thermal_set_threshold {
  2222. uint8_t sensor_type;
  2223. uint8_t threshold_id;
  2224. uint16_t value;
  2225. };
  2226. /* Version 0 - get */
  2227. struct __ec_align1 ec_params_thermal_get_threshold {
  2228. uint8_t sensor_type;
  2229. uint8_t threshold_id;
  2230. };
  2231. struct __ec_align2 ec_response_thermal_get_threshold {
  2232. uint16_t value;
  2233. };
  2234. /* The version 1 structs are visible. */
  2235. enum ec_temp_thresholds {
  2236. EC_TEMP_THRESH_WARN = 0,
  2237. EC_TEMP_THRESH_HIGH,
  2238. EC_TEMP_THRESH_HALT,
  2239. EC_TEMP_THRESH_COUNT
  2240. };
  2241. /*
  2242. * Thermal configuration for one temperature sensor. Temps are in degrees K.
  2243. * Zero values will be silently ignored by the thermal task.
  2244. *
  2245. * Note that this structure is a sub-structure of
  2246. * ec_params_thermal_set_threshold_v1, but maintains its alignment there.
  2247. */
  2248. struct __ec_align4 ec_thermal_config {
  2249. uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
  2250. uint32_t temp_fan_off; /* no active cooling needed */
  2251. uint32_t temp_fan_max; /* max active cooling needed */
  2252. };
  2253. /* Version 1 - get config for one sensor. */
  2254. struct __ec_align4 ec_params_thermal_get_threshold_v1 {
  2255. uint32_t sensor_num;
  2256. };
  2257. /* This returns a struct ec_thermal_config */
  2258. /* Version 1 - set config for one sensor.
  2259. * Use read-modify-write for best results! */
  2260. struct __ec_align4 ec_params_thermal_set_threshold_v1 {
  2261. uint32_t sensor_num;
  2262. struct ec_thermal_config cfg;
  2263. };
  2264. /* This returns no data */
  2265. /****************************************************************************/
  2266. /* Toggle automatic fan control */
  2267. #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x0052
  2268. /* Version 1 of input params */
  2269. struct __ec_align1 ec_params_auto_fan_ctrl_v1 {
  2270. uint8_t fan_idx;
  2271. };
  2272. /* Get/Set TMP006 calibration data */
  2273. #define EC_CMD_TMP006_GET_CALIBRATION 0x0053
  2274. #define EC_CMD_TMP006_SET_CALIBRATION 0x0054
  2275. /*
  2276. * The original TMP006 calibration only needed four params, but now we need
  2277. * more. Since the algorithm is nothing but magic numbers anyway, we'll leave
  2278. * the params opaque. The v1 "get" response will include the algorithm number
  2279. * and how many params it requires. That way we can change the EC code without
  2280. * needing to update this file. We can also use a different algorithm on each
  2281. * sensor.
  2282. */
  2283. /* This is the same struct for both v0 and v1. */
  2284. struct __ec_align1 ec_params_tmp006_get_calibration {
  2285. uint8_t index;
  2286. };
  2287. /* Version 0 */
  2288. struct __ec_align4 ec_response_tmp006_get_calibration_v0 {
  2289. float s0;
  2290. float b0;
  2291. float b1;
  2292. float b2;
  2293. };
  2294. struct __ec_align4 ec_params_tmp006_set_calibration_v0 {
  2295. uint8_t index;
  2296. uint8_t reserved[3];
  2297. float s0;
  2298. float b0;
  2299. float b1;
  2300. float b2;
  2301. };
  2302. /* Version 1 */
  2303. struct __ec_align4 ec_response_tmp006_get_calibration_v1 {
  2304. uint8_t algorithm;
  2305. uint8_t num_params;
  2306. uint8_t reserved[2];
  2307. float val[0];
  2308. };
  2309. struct __ec_align4 ec_params_tmp006_set_calibration_v1 {
  2310. uint8_t index;
  2311. uint8_t algorithm;
  2312. uint8_t num_params;
  2313. uint8_t reserved;
  2314. float val[0];
  2315. };
  2316. /* Read raw TMP006 data */
  2317. #define EC_CMD_TMP006_GET_RAW 0x0055
  2318. struct __ec_align1 ec_params_tmp006_get_raw {
  2319. uint8_t index;
  2320. };
  2321. struct __ec_align4 ec_response_tmp006_get_raw {
  2322. int32_t t; /* In 1/100 K */
  2323. int32_t v; /* In nV */
  2324. };
  2325. /*****************************************************************************/
  2326. /* MKBP - Matrix KeyBoard Protocol */
  2327. /*
  2328. * Read key state
  2329. *
  2330. * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
  2331. * expected response size.
  2332. *
  2333. * NOTE: This has been superseded by EC_CMD_MKBP_GET_NEXT_EVENT. If you wish
  2334. * to obtain the instantaneous state, use EC_CMD_MKBP_INFO with the type
  2335. * EC_MKBP_INFO_CURRENT and event EC_MKBP_EVENT_KEY_MATRIX.
  2336. */
  2337. #define EC_CMD_MKBP_STATE 0x0060
  2338. /*
  2339. * Provide information about various MKBP things. See enum ec_mkbp_info_type.
  2340. */
  2341. #define EC_CMD_MKBP_INFO 0x0061
  2342. struct __ec_align_size1 ec_response_mkbp_info {
  2343. uint32_t rows;
  2344. uint32_t cols;
  2345. /* Formerly "switches", which was 0. */
  2346. uint8_t reserved;
  2347. };
  2348. struct __ec_align1 ec_params_mkbp_info {
  2349. uint8_t info_type;
  2350. uint8_t event_type;
  2351. };
  2352. enum ec_mkbp_info_type {
  2353. /*
  2354. * Info about the keyboard matrix: number of rows and columns.
  2355. *
  2356. * Returns struct ec_response_mkbp_info.
  2357. */
  2358. EC_MKBP_INFO_KBD = 0,
  2359. /*
  2360. * For buttons and switches, info about which specifically are
  2361. * supported. event_type must be set to one of the values in enum
  2362. * ec_mkbp_event.
  2363. *
  2364. * For EC_MKBP_EVENT_BUTTON and EC_MKBP_EVENT_SWITCH, returns a 4 byte
  2365. * bitmask indicating which buttons or switches are present. See the
  2366. * bit inidices below.
  2367. */
  2368. EC_MKBP_INFO_SUPPORTED = 1,
  2369. /*
  2370. * Instantaneous state of buttons and switches.
  2371. *
  2372. * event_type must be set to one of the values in enum ec_mkbp_event.
  2373. *
  2374. * For EC_MKBP_EVENT_KEY_MATRIX, returns uint8_t key_matrix[13]
  2375. * indicating the current state of the keyboard matrix.
  2376. *
  2377. * For EC_MKBP_EVENT_HOST_EVENT, return uint32_t host_event, the raw
  2378. * event state.
  2379. *
  2380. * For EC_MKBP_EVENT_BUTTON, returns uint32_t buttons, indicating the
  2381. * state of supported buttons.
  2382. *
  2383. * For EC_MKBP_EVENT_SWITCH, returns uint32_t switches, indicating the
  2384. * state of supported switches.
  2385. */
  2386. EC_MKBP_INFO_CURRENT = 2,
  2387. };
  2388. /* Simulate key press */
  2389. #define EC_CMD_MKBP_SIMULATE_KEY 0x0062
  2390. struct __ec_align1 ec_params_mkbp_simulate_key {
  2391. uint8_t col;
  2392. uint8_t row;
  2393. uint8_t pressed;
  2394. };
  2395. /* Configure keyboard scanning */
  2396. #define EC_CMD_MKBP_SET_CONFIG 0x0064
  2397. #define EC_CMD_MKBP_GET_CONFIG 0x0065
  2398. /* flags */
  2399. enum mkbp_config_flags {
  2400. EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
  2401. };
  2402. enum mkbp_config_valid {
  2403. EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
  2404. EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
  2405. EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
  2406. EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
  2407. EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
  2408. EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
  2409. EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
  2410. };
  2411. /*
  2412. * Configuration for our key scanning algorithm.
  2413. *
  2414. * Note that this is used as a sub-structure of
  2415. * ec_{params/response}_mkbp_get_config.
  2416. */
  2417. struct __ec_align_size1 ec_mkbp_config {
  2418. uint32_t valid_mask; /* valid fields */
  2419. uint8_t flags; /* some flags (enum mkbp_config_flags) */
  2420. uint8_t valid_flags; /* which flags are valid */
  2421. uint16_t scan_period_us; /* period between start of scans */
  2422. /* revert to interrupt mode after no activity for this long */
  2423. uint32_t poll_timeout_us;
  2424. /*
  2425. * minimum post-scan relax time. Once we finish a scan we check
  2426. * the time until we are due to start the next one. If this time is
  2427. * shorter this field, we use this instead.
  2428. */
  2429. uint16_t min_post_scan_delay_us;
  2430. /* delay between setting up output and waiting for it to settle */
  2431. uint16_t output_settle_us;
  2432. uint16_t debounce_down_us; /* time for debounce on key down */
  2433. uint16_t debounce_up_us; /* time for debounce on key up */
  2434. /* maximum depth to allow for fifo (0 = no keyscan output) */
  2435. uint8_t fifo_max_depth;
  2436. };
  2437. struct __ec_align_size1 ec_params_mkbp_set_config {
  2438. struct ec_mkbp_config config;
  2439. };
  2440. struct __ec_align_size1 ec_response_mkbp_get_config {
  2441. struct ec_mkbp_config config;
  2442. };
  2443. /* Run the key scan emulation */
  2444. #define EC_CMD_KEYSCAN_SEQ_CTRL 0x0066
  2445. enum ec_keyscan_seq_cmd {
  2446. EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
  2447. EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
  2448. EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
  2449. EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
  2450. EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
  2451. };
  2452. enum ec_collect_flags {
  2453. /*
  2454. * Indicates this scan was processed by the EC. Due to timing, some
  2455. * scans may be skipped.
  2456. */
  2457. EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
  2458. };
  2459. struct __ec_align1 ec_collect_item {
  2460. uint8_t flags; /* some flags (enum ec_collect_flags) */
  2461. };
  2462. struct __ec_todo_packed ec_params_keyscan_seq_ctrl {
  2463. uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
  2464. union {
  2465. struct __ec_align1 {
  2466. uint8_t active; /* still active */
  2467. uint8_t num_items; /* number of items */
  2468. /* Current item being presented */
  2469. uint8_t cur_item;
  2470. } status;
  2471. struct __ec_todo_unpacked {
  2472. /*
  2473. * Absolute time for this scan, measured from the
  2474. * start of the sequence.
  2475. */
  2476. uint32_t time_us;
  2477. uint8_t scan[0]; /* keyscan data */
  2478. } add;
  2479. struct __ec_align1 {
  2480. uint8_t start_item; /* First item to return */
  2481. uint8_t num_items; /* Number of items to return */
  2482. } collect;
  2483. };
  2484. };
  2485. struct __ec_todo_packed ec_result_keyscan_seq_ctrl {
  2486. union {
  2487. struct __ec_todo_unpacked {
  2488. uint8_t num_items; /* Number of items */
  2489. /* Data for each item */
  2490. struct ec_collect_item item[0];
  2491. } collect;
  2492. };
  2493. };
  2494. /*
  2495. * Get the next pending MKBP event.
  2496. *
  2497. * Returns EC_RES_UNAVAILABLE if there is no event pending.
  2498. */
  2499. #define EC_CMD_GET_NEXT_EVENT 0x0067
  2500. enum ec_mkbp_event {
  2501. /* Keyboard matrix changed. The event data is the new matrix state. */
  2502. EC_MKBP_EVENT_KEY_MATRIX = 0,
  2503. /* New host event. The event data is 4 bytes of host event flags. */
  2504. EC_MKBP_EVENT_HOST_EVENT = 1,
  2505. /* New Sensor FIFO data. The event data is fifo_info structure. */
  2506. EC_MKBP_EVENT_SENSOR_FIFO = 2,
  2507. /* The state of the non-matrixed buttons have changed. */
  2508. EC_MKBP_EVENT_BUTTON = 3,
  2509. /* The state of the switches have changed. */
  2510. EC_MKBP_EVENT_SWITCH = 4,
  2511. /* New Fingerprint sensor event, the event data is fp_events bitmap. */
  2512. EC_MKBP_EVENT_FINGERPRINT = 5,
  2513. /*
  2514. * Sysrq event: send emulated sysrq. The event data is sysrq,
  2515. * corresponding to the key to be pressed.
  2516. */
  2517. EC_MKBP_EVENT_SYSRQ = 6,
  2518. /* Number of MKBP events */
  2519. EC_MKBP_EVENT_COUNT,
  2520. };
  2521. union __ec_align_offset1 ec_response_get_next_data {
  2522. uint8_t key_matrix[13];
  2523. /* Unaligned */
  2524. uint32_t host_event;
  2525. struct __ec_todo_unpacked {
  2526. /* For aligning the fifo_info */
  2527. uint8_t reserved[3];
  2528. struct ec_response_motion_sense_fifo_info info;
  2529. } sensor_fifo;
  2530. uint32_t buttons;
  2531. uint32_t switches;
  2532. uint32_t fp_events;
  2533. uint32_t sysrq;
  2534. };
  2535. struct __ec_align1 ec_response_get_next_event {
  2536. uint8_t event_type;
  2537. /* Followed by event data if any */
  2538. union ec_response_get_next_data data;
  2539. };
  2540. /* Bit indices for buttons and switches.*/
  2541. /* Buttons */
  2542. #define EC_MKBP_POWER_BUTTON 0
  2543. #define EC_MKBP_VOL_UP 1
  2544. #define EC_MKBP_VOL_DOWN 2
  2545. #define EC_MKBP_RECOVERY 3
  2546. /* Switches */
  2547. #define EC_MKBP_LID_OPEN 0
  2548. #define EC_MKBP_TABLET_MODE 1
  2549. /* Run keyboard factory test scanning */
  2550. #define EC_CMD_KEYBOARD_FACTORY_TEST 0x0068
  2551. struct __ec_align2 ec_response_keyboard_factory_test {
  2552. uint16_t shorted; /* Keyboard pins are shorted */
  2553. };
  2554. /* Fingerprint events in 'fp_events' for EC_MKBP_EVENT_FINGERPRINT */
  2555. #define EC_MKBP_FP_RAW_EVENT(fp_events) ((fp_events) & 0x00FFFFFF)
  2556. #define EC_MKBP_FP_FINGER_DOWN (1 << 29)
  2557. #define EC_MKBP_FP_FINGER_UP (1 << 30)
  2558. #define EC_MKBP_FP_IMAGE_READY (1 << 31)
  2559. /*****************************************************************************/
  2560. /* Temperature sensor commands */
  2561. /* Read temperature sensor info */
  2562. #define EC_CMD_TEMP_SENSOR_GET_INFO 0x0070
  2563. struct __ec_align1 ec_params_temp_sensor_get_info {
  2564. uint8_t id;
  2565. };
  2566. struct __ec_align1 ec_response_temp_sensor_get_info {
  2567. char sensor_name[32];
  2568. uint8_t sensor_type;
  2569. };
  2570. /*****************************************************************************/
  2571. /*
  2572. * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
  2573. * commands accidentally sent to the wrong interface. See the ACPI section
  2574. * below.
  2575. */
  2576. /*****************************************************************************/
  2577. /* Host event commands */
  2578. /* Obsolete. New implementation should use EC_CMD_PROGRAM_HOST_EVENT instead */
  2579. /*
  2580. * Host event mask params and response structures, shared by all of the host
  2581. * event commands below.
  2582. */
  2583. struct __ec_align4 ec_params_host_event_mask {
  2584. uint32_t mask;
  2585. };
  2586. struct __ec_align4 ec_response_host_event_mask {
  2587. uint32_t mask;
  2588. };
  2589. /* These all use ec_response_host_event_mask */
  2590. #define EC_CMD_HOST_EVENT_GET_B 0x0087
  2591. #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x0088
  2592. #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x0089
  2593. #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x008D
  2594. /* These all use ec_params_host_event_mask */
  2595. #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x008A
  2596. #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x008B
  2597. #define EC_CMD_HOST_EVENT_CLEAR 0x008C
  2598. #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x008E
  2599. #define EC_CMD_HOST_EVENT_CLEAR_B 0x008F
  2600. /*
  2601. * Unified host event programming interface - Should be used by newer versions
  2602. * of BIOS/OS to program host events and masks
  2603. */
  2604. struct __ec_align4 ec_params_host_event {
  2605. /* Action requested by host - one of enum ec_host_event_action. */
  2606. uint8_t action;
  2607. /*
  2608. * Mask type that the host requested the action on - one of
  2609. * enum ec_host_event_mask_type.
  2610. */
  2611. uint8_t mask_type;
  2612. /* Set to 0, ignore on read */
  2613. uint16_t reserved;
  2614. /* Value to be used in case of set operations. */
  2615. uint64_t value;
  2616. };
  2617. /*
  2618. * Response structure returned by EC_CMD_HOST_EVENT.
  2619. * Update the value on a GET request. Set to 0 on GET/CLEAR
  2620. */
  2621. struct __ec_align4 ec_response_host_event {
  2622. /* Mask value in case of get operation */
  2623. uint64_t value;
  2624. };
  2625. enum ec_host_event_action {
  2626. /*
  2627. * params.value is ignored. Value of mask_type populated
  2628. * in response.value
  2629. */
  2630. EC_HOST_EVENT_GET,
  2631. /* Bits in params.value are set */
  2632. EC_HOST_EVENT_SET,
  2633. /* Bits in params.value are cleared */
  2634. EC_HOST_EVENT_CLEAR,
  2635. };
  2636. enum ec_host_event_mask_type {
  2637. /* Main host event copy */
  2638. EC_HOST_EVENT_MAIN,
  2639. /* Copy B of host events */
  2640. EC_HOST_EVENT_B,
  2641. /* SCI Mask */
  2642. EC_HOST_EVENT_SCI_MASK,
  2643. /* SMI Mask */
  2644. EC_HOST_EVENT_SMI_MASK,
  2645. /* Mask of events that should be always reported in hostevents */
  2646. EC_HOST_EVENT_ALWAYS_REPORT_MASK,
  2647. /* Active wake mask */
  2648. EC_HOST_EVENT_ACTIVE_WAKE_MASK,
  2649. /* Lazy wake mask for S0ix */
  2650. EC_HOST_EVENT_LAZY_WAKE_MASK_S0IX,
  2651. /* Lazy wake mask for S3 */
  2652. EC_HOST_EVENT_LAZY_WAKE_MASK_S3,
  2653. /* Lazy wake mask for S5 */
  2654. EC_HOST_EVENT_LAZY_WAKE_MASK_S5,
  2655. };
  2656. #define EC_CMD_HOST_EVENT 0x00A4
  2657. /*****************************************************************************/
  2658. /* Switch commands */
  2659. /* Enable/disable LCD backlight */
  2660. #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x0090
  2661. struct __ec_align1 ec_params_switch_enable_backlight {
  2662. uint8_t enabled;
  2663. };
  2664. /* Enable/disable WLAN/Bluetooth */
  2665. #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x0091
  2666. #define EC_VER_SWITCH_ENABLE_WIRELESS 1
  2667. /* Version 0 params; no response */
  2668. struct __ec_align1 ec_params_switch_enable_wireless_v0 {
  2669. uint8_t enabled;
  2670. };
  2671. /* Version 1 params */
  2672. struct __ec_align1 ec_params_switch_enable_wireless_v1 {
  2673. /* Flags to enable now */
  2674. uint8_t now_flags;
  2675. /* Which flags to copy from now_flags */
  2676. uint8_t now_mask;
  2677. /*
  2678. * Flags to leave enabled in S3, if they're on at the S0->S3
  2679. * transition. (Other flags will be disabled by the S0->S3
  2680. * transition.)
  2681. */
  2682. uint8_t suspend_flags;
  2683. /* Which flags to copy from suspend_flags */
  2684. uint8_t suspend_mask;
  2685. };
  2686. /* Version 1 response */
  2687. struct __ec_align1 ec_response_switch_enable_wireless_v1 {
  2688. /* Flags to enable now */
  2689. uint8_t now_flags;
  2690. /* Flags to leave enabled in S3 */
  2691. uint8_t suspend_flags;
  2692. };
  2693. /*****************************************************************************/
  2694. /* GPIO commands. Only available on EC if write protect has been disabled. */
  2695. /* Set GPIO output value */
  2696. #define EC_CMD_GPIO_SET 0x0092
  2697. struct __ec_align1 ec_params_gpio_set {
  2698. char name[32];
  2699. uint8_t val;
  2700. };
  2701. /* Get GPIO value */
  2702. #define EC_CMD_GPIO_GET 0x0093
  2703. /* Version 0 of input params and response */
  2704. struct __ec_align1 ec_params_gpio_get {
  2705. char name[32];
  2706. };
  2707. struct __ec_align1 ec_response_gpio_get {
  2708. uint8_t val;
  2709. };
  2710. /* Version 1 of input params and response */
  2711. struct __ec_align1 ec_params_gpio_get_v1 {
  2712. uint8_t subcmd;
  2713. union {
  2714. struct __ec_align1 {
  2715. char name[32];
  2716. } get_value_by_name;
  2717. struct __ec_align1 {
  2718. uint8_t index;
  2719. } get_info;
  2720. };
  2721. };
  2722. struct __ec_todo_packed ec_response_gpio_get_v1 {
  2723. union {
  2724. struct __ec_align1 {
  2725. uint8_t val;
  2726. } get_value_by_name, get_count;
  2727. struct __ec_todo_unpacked {
  2728. uint8_t val;
  2729. char name[32];
  2730. uint32_t flags;
  2731. } get_info;
  2732. };
  2733. };
  2734. enum gpio_get_subcmd {
  2735. EC_GPIO_GET_BY_NAME = 0,
  2736. EC_GPIO_GET_COUNT = 1,
  2737. EC_GPIO_GET_INFO = 2,
  2738. };
  2739. /*****************************************************************************/
  2740. /* I2C commands. Only available when flash write protect is unlocked. */
  2741. /*
  2742. * CAUTION: These commands are deprecated, and are not supported anymore in EC
  2743. * builds >= 8398.0.0 (see crosbug.com/p/23570).
  2744. *
  2745. * Use EC_CMD_I2C_PASSTHRU instead.
  2746. */
  2747. /* Read I2C bus */
  2748. #define EC_CMD_I2C_READ 0x0094
  2749. struct __ec_align_size1 ec_params_i2c_read {
  2750. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  2751. uint8_t read_size; /* Either 8 or 16. */
  2752. uint8_t port;
  2753. uint8_t offset;
  2754. };
  2755. struct __ec_align2 ec_response_i2c_read {
  2756. uint16_t data;
  2757. };
  2758. /* Write I2C bus */
  2759. #define EC_CMD_I2C_WRITE 0x0095
  2760. struct __ec_align_size1 ec_params_i2c_write {
  2761. uint16_t data;
  2762. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  2763. uint8_t write_size; /* Either 8 or 16. */
  2764. uint8_t port;
  2765. uint8_t offset;
  2766. };
  2767. /*****************************************************************************/
  2768. /* Charge state commands. Only available when flash write protect unlocked. */
  2769. /* Force charge state machine to stop charging the battery or force it to
  2770. * discharge the battery.
  2771. */
  2772. #define EC_CMD_CHARGE_CONTROL 0x0096
  2773. #define EC_VER_CHARGE_CONTROL 1
  2774. enum ec_charge_control_mode {
  2775. CHARGE_CONTROL_NORMAL = 0,
  2776. CHARGE_CONTROL_IDLE,
  2777. CHARGE_CONTROL_DISCHARGE,
  2778. };
  2779. struct __ec_align4 ec_params_charge_control {
  2780. uint32_t mode; /* enum charge_control_mode */
  2781. };
  2782. /*****************************************************************************/
  2783. /* Console commands. Only available when flash write protect is unlocked. */
  2784. /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
  2785. #define EC_CMD_CONSOLE_SNAPSHOT 0x0097
  2786. /*
  2787. * Read data from the saved snapshot. If the subcmd parameter is
  2788. * CONSOLE_READ_NEXT, this will return data starting from the beginning of
  2789. * the latest snapshot. If it is CONSOLE_READ_RECENT, it will start from the
  2790. * end of the previous snapshot.
  2791. *
  2792. * The params are only looked at in version >= 1 of this command. Prior
  2793. * versions will just default to CONSOLE_READ_NEXT behavior.
  2794. *
  2795. * Response is null-terminated string. Empty string, if there is no more
  2796. * remaining output.
  2797. */
  2798. #define EC_CMD_CONSOLE_READ 0x0098
  2799. enum ec_console_read_subcmd {
  2800. CONSOLE_READ_NEXT = 0,
  2801. CONSOLE_READ_RECENT
  2802. };
  2803. struct __ec_align1 ec_params_console_read_v1 {
  2804. uint8_t subcmd; /* enum ec_console_read_subcmd */
  2805. };
  2806. /*****************************************************************************/
  2807. /*
  2808. * Cut off battery power immediately or after the host has shut down.
  2809. *
  2810. * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
  2811. * EC_RES_SUCCESS if the command was successful.
  2812. * EC_RES_ERROR if the cut off command failed.
  2813. */
  2814. #define EC_CMD_BATTERY_CUT_OFF 0x0099
  2815. #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
  2816. struct __ec_align1 ec_params_battery_cutoff {
  2817. uint8_t flags;
  2818. };
  2819. /*****************************************************************************/
  2820. /* USB port mux control. */
  2821. /*
  2822. * Switch USB mux or return to automatic switching.
  2823. */
  2824. #define EC_CMD_USB_MUX 0x009A
  2825. struct __ec_align1 ec_params_usb_mux {
  2826. uint8_t mux;
  2827. };
  2828. /*****************************************************************************/
  2829. /* LDOs / FETs control. */
  2830. enum ec_ldo_state {
  2831. EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
  2832. EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
  2833. };
  2834. /*
  2835. * Switch on/off a LDO.
  2836. */
  2837. #define EC_CMD_LDO_SET 0x009B
  2838. struct __ec_align1 ec_params_ldo_set {
  2839. uint8_t index;
  2840. uint8_t state;
  2841. };
  2842. /*
  2843. * Get LDO state.
  2844. */
  2845. #define EC_CMD_LDO_GET 0x009C
  2846. struct __ec_align1 ec_params_ldo_get {
  2847. uint8_t index;
  2848. };
  2849. struct __ec_align1 ec_response_ldo_get {
  2850. uint8_t state;
  2851. };
  2852. /*****************************************************************************/
  2853. /* Power info. */
  2854. /*
  2855. * Get power info.
  2856. */
  2857. #define EC_CMD_POWER_INFO 0x009D
  2858. struct __ec_align4 ec_response_power_info {
  2859. uint32_t usb_dev_type;
  2860. uint16_t voltage_ac;
  2861. uint16_t voltage_system;
  2862. uint16_t current_system;
  2863. uint16_t usb_current_limit;
  2864. };
  2865. /*****************************************************************************/
  2866. /* I2C passthru command */
  2867. #define EC_CMD_I2C_PASSTHRU 0x009E
  2868. /* Read data; if not present, message is a write */
  2869. #define EC_I2C_FLAG_READ (1 << 15)
  2870. /* Mask for address */
  2871. #define EC_I2C_ADDR_MASK 0x3ff
  2872. #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
  2873. #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
  2874. /* Any error */
  2875. #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
  2876. struct __ec_align2 ec_params_i2c_passthru_msg {
  2877. uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
  2878. uint16_t len; /* Number of bytes to read or write */
  2879. };
  2880. struct __ec_align2 ec_params_i2c_passthru {
  2881. uint8_t port; /* I2C port number */
  2882. uint8_t num_msgs; /* Number of messages */
  2883. struct ec_params_i2c_passthru_msg msg[];
  2884. /* Data to write for all messages is concatenated here */
  2885. };
  2886. struct __ec_align1 ec_response_i2c_passthru {
  2887. uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
  2888. uint8_t num_msgs; /* Number of messages processed */
  2889. uint8_t data[]; /* Data read by messages concatenated here */
  2890. };
  2891. /*****************************************************************************/
  2892. /* Power button hang detect */
  2893. #define EC_CMD_HANG_DETECT 0x009F
  2894. /* Reasons to start hang detection timer */
  2895. /* Power button pressed */
  2896. #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
  2897. /* Lid closed */
  2898. #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
  2899. /* Lid opened */
  2900. #define EC_HANG_START_ON_LID_OPEN (1 << 2)
  2901. /* Start of AP S3->S0 transition (booting or resuming from suspend) */
  2902. #define EC_HANG_START_ON_RESUME (1 << 3)
  2903. /* Reasons to cancel hang detection */
  2904. /* Power button released */
  2905. #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
  2906. /* Any host command from AP received */
  2907. #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
  2908. /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
  2909. #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
  2910. /*
  2911. * If this flag is set, all the other fields are ignored, and the hang detect
  2912. * timer is started. This provides the AP a way to start the hang timer
  2913. * without reconfiguring any of the other hang detect settings. Note that
  2914. * you must previously have configured the timeouts.
  2915. */
  2916. #define EC_HANG_START_NOW (1 << 30)
  2917. /*
  2918. * If this flag is set, all the other fields are ignored (including
  2919. * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
  2920. * without reconfiguring any of the other hang detect settings.
  2921. */
  2922. #define EC_HANG_STOP_NOW (1 << 31)
  2923. struct __ec_align4 ec_params_hang_detect {
  2924. /* Flags; see EC_HANG_* */
  2925. uint32_t flags;
  2926. /* Timeout in msec before generating host event, if enabled */
  2927. uint16_t host_event_timeout_msec;
  2928. /* Timeout in msec before generating warm reboot, if enabled */
  2929. uint16_t warm_reboot_timeout_msec;
  2930. };
  2931. /*****************************************************************************/
  2932. /* Commands for battery charging */
  2933. /*
  2934. * This is the single catch-all host command to exchange data regarding the
  2935. * charge state machine (v2 and up).
  2936. */
  2937. #define EC_CMD_CHARGE_STATE 0x00A0
  2938. /* Subcommands for this host command */
  2939. enum charge_state_command {
  2940. CHARGE_STATE_CMD_GET_STATE,
  2941. CHARGE_STATE_CMD_GET_PARAM,
  2942. CHARGE_STATE_CMD_SET_PARAM,
  2943. CHARGE_STATE_NUM_CMDS
  2944. };
  2945. /*
  2946. * Known param numbers are defined here. Ranges are reserved for board-specific
  2947. * params, which are handled by the particular implementations.
  2948. */
  2949. enum charge_state_params {
  2950. CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
  2951. CS_PARAM_CHG_CURRENT, /* charger current limit */
  2952. CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
  2953. CS_PARAM_CHG_STATUS, /* charger-specific status */
  2954. CS_PARAM_CHG_OPTION, /* charger-specific options */
  2955. CS_PARAM_LIMIT_POWER, /*
  2956. * Check if power is limited due to
  2957. * low battery and / or a weak external
  2958. * charger. READ ONLY.
  2959. */
  2960. /* How many so far? */
  2961. CS_NUM_BASE_PARAMS,
  2962. /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
  2963. CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
  2964. CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
  2965. /* Other custom param ranges go here... */
  2966. };
  2967. struct __ec_todo_packed ec_params_charge_state {
  2968. uint8_t cmd; /* enum charge_state_command */
  2969. union {
  2970. struct __ec_align1 {
  2971. /* no args */
  2972. } get_state;
  2973. struct __ec_todo_unpacked {
  2974. uint32_t param; /* enum charge_state_param */
  2975. } get_param;
  2976. struct __ec_todo_unpacked {
  2977. uint32_t param; /* param to set */
  2978. uint32_t value; /* value to set */
  2979. } set_param;
  2980. };
  2981. };
  2982. struct __ec_align4 ec_response_charge_state {
  2983. union {
  2984. struct __ec_align4 {
  2985. int ac;
  2986. int chg_voltage;
  2987. int chg_current;
  2988. int chg_input_current;
  2989. int batt_state_of_charge;
  2990. } get_state;
  2991. struct __ec_align4 {
  2992. uint32_t value;
  2993. } get_param;
  2994. struct __ec_align4 {
  2995. /* no return values */
  2996. } set_param;
  2997. };
  2998. };
  2999. /*
  3000. * Set maximum battery charging current.
  3001. */
  3002. #define EC_CMD_CHARGE_CURRENT_LIMIT 0x00A1
  3003. struct __ec_align4 ec_params_current_limit {
  3004. uint32_t limit; /* in mA */
  3005. };
  3006. /*
  3007. * Set maximum external voltage / current.
  3008. */
  3009. #define EC_CMD_EXTERNAL_POWER_LIMIT 0x00A2
  3010. /* Command v0 is used only on Spring and is obsolete + unsupported */
  3011. struct __ec_align2 ec_params_external_power_limit_v1 {
  3012. uint16_t current_lim; /* in mA, or EC_POWER_LIMIT_NONE to clear limit */
  3013. uint16_t voltage_lim; /* in mV, or EC_POWER_LIMIT_NONE to clear limit */
  3014. };
  3015. #define EC_POWER_LIMIT_NONE 0xffff
  3016. /*
  3017. * Set maximum voltage & current of a dedicated charge port
  3018. */
  3019. #define EC_CMD_OVERRIDE_DEDICATED_CHARGER_LIMIT 0x00A3
  3020. struct __ec_align2 ec_params_dedicated_charger_limit {
  3021. uint16_t current_lim; /* in mA */
  3022. uint16_t voltage_lim; /* in mV */
  3023. };
  3024. /*****************************************************************************/
  3025. /* Hibernate/Deep Sleep Commands */
  3026. /* Set the delay before going into hibernation. */
  3027. #define EC_CMD_HIBERNATION_DELAY 0x00A8
  3028. struct __ec_align4 ec_params_hibernation_delay {
  3029. /*
  3030. * Seconds to wait in G3 before hibernate. Pass in 0 to read the
  3031. * current settings without changing them.
  3032. */
  3033. uint32_t seconds;
  3034. };
  3035. struct __ec_align4 ec_response_hibernation_delay {
  3036. /*
  3037. * The current time in seconds in which the system has been in the G3
  3038. * state. This value is reset if the EC transitions out of G3.
  3039. */
  3040. uint32_t time_g3;
  3041. /*
  3042. * The current time remaining in seconds until the EC should hibernate.
  3043. * This value is also reset if the EC transitions out of G3.
  3044. */
  3045. uint32_t time_remaining;
  3046. /*
  3047. * The current time in seconds that the EC should wait in G3 before
  3048. * hibernating.
  3049. */
  3050. uint32_t hibernate_delay;
  3051. };
  3052. /* Inform the EC when entering a sleep state */
  3053. #define EC_CMD_HOST_SLEEP_EVENT 0x00A9
  3054. enum host_sleep_event {
  3055. HOST_SLEEP_EVENT_S3_SUSPEND = 1,
  3056. HOST_SLEEP_EVENT_S3_RESUME = 2,
  3057. HOST_SLEEP_EVENT_S0IX_SUSPEND = 3,
  3058. HOST_SLEEP_EVENT_S0IX_RESUME = 4
  3059. };
  3060. struct __ec_align1 ec_params_host_sleep_event {
  3061. uint8_t sleep_event;
  3062. };
  3063. /*****************************************************************************/
  3064. /* Device events */
  3065. #define EC_CMD_DEVICE_EVENT 0x00AA
  3066. enum ec_device_event {
  3067. EC_DEVICE_EVENT_TRACKPAD,
  3068. EC_DEVICE_EVENT_DSP,
  3069. EC_DEVICE_EVENT_WIFI,
  3070. };
  3071. enum ec_device_event_param {
  3072. /* Get and clear pending device events */
  3073. EC_DEVICE_EVENT_PARAM_GET_CURRENT_EVENTS,
  3074. /* Get device event mask */
  3075. EC_DEVICE_EVENT_PARAM_GET_ENABLED_EVENTS,
  3076. /* Set device event mask */
  3077. EC_DEVICE_EVENT_PARAM_SET_ENABLED_EVENTS,
  3078. };
  3079. #define EC_DEVICE_EVENT_MASK(event_code) (1UL << (event_code % 32))
  3080. struct __ec_align_size1 ec_params_device_event {
  3081. uint32_t event_mask;
  3082. uint8_t param;
  3083. };
  3084. struct __ec_align4 ec_response_device_event {
  3085. uint32_t event_mask;
  3086. };
  3087. /*****************************************************************************/
  3088. /* Smart battery pass-through */
  3089. /* Get / Set 16-bit smart battery registers */
  3090. #define EC_CMD_SB_READ_WORD 0x00B0
  3091. #define EC_CMD_SB_WRITE_WORD 0x00B1
  3092. /* Get / Set string smart battery parameters
  3093. * formatted as SMBUS "block".
  3094. */
  3095. #define EC_CMD_SB_READ_BLOCK 0x00B2
  3096. #define EC_CMD_SB_WRITE_BLOCK 0x00B3
  3097. struct __ec_align1 ec_params_sb_rd {
  3098. uint8_t reg;
  3099. };
  3100. struct __ec_align2 ec_response_sb_rd_word {
  3101. uint16_t value;
  3102. };
  3103. struct __ec_align1 ec_params_sb_wr_word {
  3104. uint8_t reg;
  3105. uint16_t value;
  3106. };
  3107. struct __ec_align1 ec_response_sb_rd_block {
  3108. uint8_t data[32];
  3109. };
  3110. struct __ec_align1 ec_params_sb_wr_block {
  3111. uint8_t reg;
  3112. uint16_t data[32];
  3113. };
  3114. /*****************************************************************************/
  3115. /* Battery vendor parameters
  3116. *
  3117. * Get or set vendor-specific parameters in the battery. Implementations may
  3118. * differ between boards or batteries. On a set operation, the response
  3119. * contains the actual value set, which may be rounded or clipped from the
  3120. * requested value.
  3121. */
  3122. #define EC_CMD_BATTERY_VENDOR_PARAM 0x00B4
  3123. enum ec_battery_vendor_param_mode {
  3124. BATTERY_VENDOR_PARAM_MODE_GET = 0,
  3125. BATTERY_VENDOR_PARAM_MODE_SET,
  3126. };
  3127. struct __ec_align_size1 ec_params_battery_vendor_param {
  3128. uint32_t param;
  3129. uint32_t value;
  3130. uint8_t mode;
  3131. };
  3132. struct __ec_align4 ec_response_battery_vendor_param {
  3133. uint32_t value;
  3134. };
  3135. /*****************************************************************************/
  3136. /*
  3137. * Smart Battery Firmware Update Commands
  3138. */
  3139. #define EC_CMD_SB_FW_UPDATE 0x00B5
  3140. enum ec_sb_fw_update_subcmd {
  3141. EC_SB_FW_UPDATE_PREPARE = 0x0,
  3142. EC_SB_FW_UPDATE_INFO = 0x1, /*query sb info */
  3143. EC_SB_FW_UPDATE_BEGIN = 0x2, /*check if protected */
  3144. EC_SB_FW_UPDATE_WRITE = 0x3, /*check if protected */
  3145. EC_SB_FW_UPDATE_END = 0x4,
  3146. EC_SB_FW_UPDATE_STATUS = 0x5,
  3147. EC_SB_FW_UPDATE_PROTECT = 0x6,
  3148. EC_SB_FW_UPDATE_MAX = 0x7,
  3149. };
  3150. #define SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE 32
  3151. #define SB_FW_UPDATE_CMD_STATUS_SIZE 2
  3152. #define SB_FW_UPDATE_CMD_INFO_SIZE 8
  3153. struct __ec_align4 ec_sb_fw_update_header {
  3154. uint16_t subcmd; /* enum ec_sb_fw_update_subcmd */
  3155. uint16_t fw_id; /* firmware id */
  3156. };
  3157. struct __ec_align4 ec_params_sb_fw_update {
  3158. struct ec_sb_fw_update_header hdr;
  3159. union {
  3160. /* EC_SB_FW_UPDATE_PREPARE = 0x0 */
  3161. /* EC_SB_FW_UPDATE_INFO = 0x1 */
  3162. /* EC_SB_FW_UPDATE_BEGIN = 0x2 */
  3163. /* EC_SB_FW_UPDATE_END = 0x4 */
  3164. /* EC_SB_FW_UPDATE_STATUS = 0x5 */
  3165. /* EC_SB_FW_UPDATE_PROTECT = 0x6 */
  3166. struct __ec_align4 {
  3167. /* no args */
  3168. } dummy;
  3169. /* EC_SB_FW_UPDATE_WRITE = 0x3 */
  3170. struct __ec_align4 {
  3171. uint8_t data[SB_FW_UPDATE_CMD_WRITE_BLOCK_SIZE];
  3172. } write;
  3173. };
  3174. };
  3175. struct __ec_align1 ec_response_sb_fw_update {
  3176. union {
  3177. /* EC_SB_FW_UPDATE_INFO = 0x1 */
  3178. struct __ec_align1 {
  3179. uint8_t data[SB_FW_UPDATE_CMD_INFO_SIZE];
  3180. } info;
  3181. /* EC_SB_FW_UPDATE_STATUS = 0x5 */
  3182. struct __ec_align1 {
  3183. uint8_t data[SB_FW_UPDATE_CMD_STATUS_SIZE];
  3184. } status;
  3185. };
  3186. };
  3187. /*
  3188. * Entering Verified Boot Mode Command
  3189. * Default mode is VBOOT_MODE_NORMAL if EC did not receive this command.
  3190. * Valid Modes are: normal, developer, and recovery.
  3191. */
  3192. #define EC_CMD_ENTERING_MODE 0x00B6
  3193. struct __ec_align4 ec_params_entering_mode {
  3194. int vboot_mode;
  3195. };
  3196. #define VBOOT_MODE_NORMAL 0
  3197. #define VBOOT_MODE_DEVELOPER 1
  3198. #define VBOOT_MODE_RECOVERY 2
  3199. /*****************************************************************************/
  3200. /*
  3201. * I2C passthru protection command: Protects I2C tunnels against access on
  3202. * certain addresses (board-specific).
  3203. */
  3204. #define EC_CMD_I2C_PASSTHRU_PROTECT 0x00B7
  3205. enum ec_i2c_passthru_protect_subcmd {
  3206. EC_CMD_I2C_PASSTHRU_PROTECT_STATUS = 0x0,
  3207. EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE = 0x1,
  3208. };
  3209. struct __ec_align1 ec_params_i2c_passthru_protect {
  3210. uint8_t subcmd;
  3211. uint8_t port; /* I2C port number */
  3212. };
  3213. struct __ec_align1 ec_response_i2c_passthru_protect {
  3214. uint8_t status; /* Status flags (0: unlocked, 1: locked) */
  3215. };
  3216. /*****************************************************************************/
  3217. /* System commands */
  3218. /*
  3219. * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
  3220. * necessarily reboot the EC. Rename to "image" or something similar?
  3221. */
  3222. #define EC_CMD_REBOOT_EC 0x00D2
  3223. /* Command */
  3224. enum ec_reboot_cmd {
  3225. EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
  3226. EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
  3227. EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
  3228. /* (command 3 was jump to RW-B) */
  3229. EC_REBOOT_COLD = 4, /* Cold-reboot */
  3230. EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
  3231. EC_REBOOT_HIBERNATE = 6, /* Hibernate EC */
  3232. EC_REBOOT_HIBERNATE_CLEAR_AP_OFF = 7, /* and clears AP_OFF flag */
  3233. };
  3234. /* Flags for ec_params_reboot_ec.reboot_flags */
  3235. #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
  3236. #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
  3237. #define EC_REBOOT_FLAG_SWITCH_RW_SLOT (1 << 2) /* Switch RW slot */
  3238. struct __ec_align1 ec_params_reboot_ec {
  3239. uint8_t cmd; /* enum ec_reboot_cmd */
  3240. uint8_t flags; /* See EC_REBOOT_FLAG_* */
  3241. };
  3242. /*
  3243. * Get information on last EC panic.
  3244. *
  3245. * Returns variable-length platform-dependent panic information. See panic.h
  3246. * for details.
  3247. */
  3248. #define EC_CMD_GET_PANIC_INFO 0x00D3
  3249. /*****************************************************************************/
  3250. /*
  3251. * Special commands
  3252. *
  3253. * These do not follow the normal rules for commands. See each command for
  3254. * details.
  3255. */
  3256. /*
  3257. * Reboot NOW
  3258. *
  3259. * This command will work even when the EC LPC interface is busy, because the
  3260. * reboot command is processed at interrupt level. Note that when the EC
  3261. * reboots, the host will reboot too, so there is no response to this command.
  3262. *
  3263. * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
  3264. */
  3265. #define EC_CMD_REBOOT 0x00D1 /* Think "die" */
  3266. /*
  3267. * Resend last response (not supported on LPC).
  3268. *
  3269. * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
  3270. * there was no previous command, or the previous command's response was too
  3271. * big to save.
  3272. */
  3273. #define EC_CMD_RESEND_RESPONSE 0x00DB
  3274. /*
  3275. * This header byte on a command indicate version 0. Any header byte less
  3276. * than this means that we are talking to an old EC which doesn't support
  3277. * versioning. In that case, we assume version 0.
  3278. *
  3279. * Header bytes greater than this indicate a later version. For example,
  3280. * EC_CMD_VERSION0 + 1 means we are using version 1.
  3281. *
  3282. * The old EC interface must not use commands 0xdc or higher.
  3283. */
  3284. #define EC_CMD_VERSION0 0x00DC
  3285. /*****************************************************************************/
  3286. /*
  3287. * PD commands
  3288. *
  3289. * These commands are for PD MCU communication.
  3290. */
  3291. /* EC to PD MCU exchange status command */
  3292. #define EC_CMD_PD_EXCHANGE_STATUS 0x0100
  3293. #define EC_VER_PD_EXCHANGE_STATUS 2
  3294. enum pd_charge_state {
  3295. PD_CHARGE_NO_CHANGE = 0, /* Don't change charge state */
  3296. PD_CHARGE_NONE, /* No charging allowed */
  3297. PD_CHARGE_5V, /* 5V charging only */
  3298. PD_CHARGE_MAX /* Charge at max voltage */
  3299. };
  3300. /* Status of EC being sent to PD */
  3301. #define EC_STATUS_HIBERNATING (1 << 0)
  3302. struct __ec_align1 ec_params_pd_status {
  3303. uint8_t status; /* EC status */
  3304. int8_t batt_soc; /* battery state of charge */
  3305. uint8_t charge_state; /* charging state (from enum pd_charge_state) */
  3306. };
  3307. /* Status of PD being sent back to EC */
  3308. #define PD_STATUS_HOST_EVENT (1 << 0) /* Forward host event to AP */
  3309. #define PD_STATUS_IN_RW (1 << 1) /* Running RW image */
  3310. #define PD_STATUS_JUMPED_TO_IMAGE (1 << 2) /* Current image was jumped to */
  3311. #define PD_STATUS_TCPC_ALERT_0 (1 << 3) /* Alert active in port 0 TCPC */
  3312. #define PD_STATUS_TCPC_ALERT_1 (1 << 4) /* Alert active in port 1 TCPC */
  3313. #define PD_STATUS_TCPC_ALERT_2 (1 << 5) /* Alert active in port 2 TCPC */
  3314. #define PD_STATUS_TCPC_ALERT_3 (1 << 6) /* Alert active in port 3 TCPC */
  3315. #define PD_STATUS_EC_INT_ACTIVE (PD_STATUS_TCPC_ALERT_0 | \
  3316. PD_STATUS_TCPC_ALERT_1 | \
  3317. PD_STATUS_HOST_EVENT)
  3318. struct __ec_align_size1 ec_response_pd_status {
  3319. uint32_t curr_lim_ma; /* input current limit */
  3320. uint16_t status; /* PD MCU status */
  3321. int8_t active_charge_port; /* active charging port */
  3322. };
  3323. /* AP to PD MCU host event status command, cleared on read */
  3324. #define EC_CMD_PD_HOST_EVENT_STATUS 0x0104
  3325. /* PD MCU host event status bits */
  3326. #define PD_EVENT_UPDATE_DEVICE (1 << 0)
  3327. #define PD_EVENT_POWER_CHANGE (1 << 1)
  3328. #define PD_EVENT_IDENTITY_RECEIVED (1 << 2)
  3329. #define PD_EVENT_DATA_SWAP (1 << 3)
  3330. struct __ec_align4 ec_response_host_event_status {
  3331. uint32_t status; /* PD MCU host event status */
  3332. };
  3333. /* Set USB type-C port role and muxes */
  3334. #define EC_CMD_USB_PD_CONTROL 0x0101
  3335. enum usb_pd_control_role {
  3336. USB_PD_CTRL_ROLE_NO_CHANGE = 0,
  3337. USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
  3338. USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
  3339. USB_PD_CTRL_ROLE_FORCE_SINK = 3,
  3340. USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
  3341. USB_PD_CTRL_ROLE_COUNT
  3342. };
  3343. enum usb_pd_control_mux {
  3344. USB_PD_CTRL_MUX_NO_CHANGE = 0,
  3345. USB_PD_CTRL_MUX_NONE = 1,
  3346. USB_PD_CTRL_MUX_USB = 2,
  3347. USB_PD_CTRL_MUX_DP = 3,
  3348. USB_PD_CTRL_MUX_DOCK = 4,
  3349. USB_PD_CTRL_MUX_AUTO = 5,
  3350. USB_PD_CTRL_MUX_COUNT
  3351. };
  3352. enum usb_pd_control_swap {
  3353. USB_PD_CTRL_SWAP_NONE = 0,
  3354. USB_PD_CTRL_SWAP_DATA = 1,
  3355. USB_PD_CTRL_SWAP_POWER = 2,
  3356. USB_PD_CTRL_SWAP_VCONN = 3,
  3357. USB_PD_CTRL_SWAP_COUNT
  3358. };
  3359. struct __ec_align1 ec_params_usb_pd_control {
  3360. uint8_t port;
  3361. uint8_t role;
  3362. uint8_t mux;
  3363. uint8_t swap;
  3364. };
  3365. #define PD_CTRL_RESP_ENABLED_COMMS (1 << 0) /* Communication enabled */
  3366. #define PD_CTRL_RESP_ENABLED_CONNECTED (1 << 1) /* Device connected */
  3367. #define PD_CTRL_RESP_ENABLED_PD_CAPABLE (1 << 2) /* Partner is PD capable */
  3368. #define PD_CTRL_RESP_ROLE_POWER (1 << 0) /* 0=SNK/1=SRC */
  3369. #define PD_CTRL_RESP_ROLE_DATA (1 << 1) /* 0=UFP/1=DFP */
  3370. #define PD_CTRL_RESP_ROLE_VCONN (1 << 2) /* Vconn status */
  3371. #define PD_CTRL_RESP_ROLE_DR_POWER (1 << 3) /* Partner is dualrole power */
  3372. #define PD_CTRL_RESP_ROLE_DR_DATA (1 << 4) /* Partner is dualrole data */
  3373. #define PD_CTRL_RESP_ROLE_USB_COMM (1 << 5) /* Partner USB comm capable */
  3374. #define PD_CTRL_RESP_ROLE_EXT_POWERED (1 << 6) /* Partner externally powerd */
  3375. struct __ec_align1 ec_response_usb_pd_control {
  3376. uint8_t enabled;
  3377. uint8_t role;
  3378. uint8_t polarity;
  3379. uint8_t state;
  3380. };
  3381. struct __ec_align1 ec_response_usb_pd_control_v1 {
  3382. uint8_t enabled;
  3383. uint8_t role;
  3384. uint8_t polarity;
  3385. char state[32];
  3386. };
  3387. #define EC_CMD_USB_PD_PORTS 0x0102
  3388. /* Maximum number of PD ports on a device, num_ports will be <= this */
  3389. #define EC_USB_PD_MAX_PORTS 8
  3390. struct __ec_align1 ec_response_usb_pd_ports {
  3391. uint8_t num_ports;
  3392. };
  3393. #define EC_CMD_USB_PD_POWER_INFO 0x0103
  3394. #define PD_POWER_CHARGING_PORT 0xff
  3395. struct __ec_align1 ec_params_usb_pd_power_info {
  3396. uint8_t port;
  3397. };
  3398. enum usb_chg_type {
  3399. USB_CHG_TYPE_NONE,
  3400. USB_CHG_TYPE_PD,
  3401. USB_CHG_TYPE_C,
  3402. USB_CHG_TYPE_PROPRIETARY,
  3403. USB_CHG_TYPE_BC12_DCP,
  3404. USB_CHG_TYPE_BC12_CDP,
  3405. USB_CHG_TYPE_BC12_SDP,
  3406. USB_CHG_TYPE_OTHER,
  3407. USB_CHG_TYPE_VBUS,
  3408. USB_CHG_TYPE_UNKNOWN,
  3409. };
  3410. enum usb_power_roles {
  3411. USB_PD_PORT_POWER_DISCONNECTED,
  3412. USB_PD_PORT_POWER_SOURCE,
  3413. USB_PD_PORT_POWER_SINK,
  3414. USB_PD_PORT_POWER_SINK_NOT_CHARGING,
  3415. };
  3416. struct __ec_align2 usb_chg_measures {
  3417. uint16_t voltage_max;
  3418. uint16_t voltage_now;
  3419. uint16_t current_max;
  3420. uint16_t current_lim;
  3421. };
  3422. struct __ec_align4 ec_response_usb_pd_power_info {
  3423. uint8_t role;
  3424. uint8_t type;
  3425. uint8_t dualrole;
  3426. uint8_t reserved1;
  3427. struct usb_chg_measures meas;
  3428. uint32_t max_power;
  3429. };
  3430. /* Write USB-PD device FW */
  3431. #define EC_CMD_USB_PD_FW_UPDATE 0x0110
  3432. enum usb_pd_fw_update_cmds {
  3433. USB_PD_FW_REBOOT,
  3434. USB_PD_FW_FLASH_ERASE,
  3435. USB_PD_FW_FLASH_WRITE,
  3436. USB_PD_FW_ERASE_SIG,
  3437. };
  3438. struct __ec_align4 ec_params_usb_pd_fw_update {
  3439. uint16_t dev_id;
  3440. uint8_t cmd;
  3441. uint8_t port;
  3442. uint32_t size; /* Size to write in bytes */
  3443. /* Followed by data to write */
  3444. };
  3445. /* Write USB-PD Accessory RW_HASH table entry */
  3446. #define EC_CMD_USB_PD_RW_HASH_ENTRY 0x0111
  3447. /* RW hash is first 20 bytes of SHA-256 of RW section */
  3448. #define PD_RW_HASH_SIZE 20
  3449. struct __ec_align1 ec_params_usb_pd_rw_hash_entry {
  3450. uint16_t dev_id;
  3451. uint8_t dev_rw_hash[PD_RW_HASH_SIZE];
  3452. uint8_t reserved; /* For alignment of current_image
  3453. * TODO(rspangler) but it's not aligned!
  3454. * Should have been reserved[2]. */
  3455. uint32_t current_image; /* One of ec_current_image */
  3456. };
  3457. /* Read USB-PD Accessory info */
  3458. #define EC_CMD_USB_PD_DEV_INFO 0x0112
  3459. struct __ec_align1 ec_params_usb_pd_info_request {
  3460. uint8_t port;
  3461. };
  3462. /* Read USB-PD Device discovery info */
  3463. #define EC_CMD_USB_PD_DISCOVERY 0x0113
  3464. struct __ec_align_size1 ec_params_usb_pd_discovery_entry {
  3465. uint16_t vid; /* USB-IF VID */
  3466. uint16_t pid; /* USB-IF PID */
  3467. uint8_t ptype; /* product type (hub,periph,cable,ama) */
  3468. };
  3469. /* Override default charge behavior */
  3470. #define EC_CMD_PD_CHARGE_PORT_OVERRIDE 0x0114
  3471. /* Negative port parameters have special meaning */
  3472. enum usb_pd_override_ports {
  3473. OVERRIDE_DONT_CHARGE = -2,
  3474. OVERRIDE_OFF = -1,
  3475. /* [0, CONFIG_USB_PD_PORT_COUNT): Port# */
  3476. };
  3477. struct __ec_align2 ec_params_charge_port_override {
  3478. int16_t override_port; /* Override port# */
  3479. };
  3480. /* Read (and delete) one entry of PD event log */
  3481. #define EC_CMD_PD_GET_LOG_ENTRY 0x0115
  3482. struct __ec_align4 ec_response_pd_log {
  3483. uint32_t timestamp; /* relative timestamp in milliseconds */
  3484. uint8_t type; /* event type : see PD_EVENT_xx below */
  3485. uint8_t size_port; /* [7:5] port number [4:0] payload size in bytes */
  3486. uint16_t data; /* type-defined data payload */
  3487. uint8_t payload[0]; /* optional additional data payload: 0..16 bytes */
  3488. };
  3489. /* The timestamp is the microsecond counter shifted to get about a ms. */
  3490. #define PD_LOG_TIMESTAMP_SHIFT 10 /* 1 LSB = 1024us */
  3491. #define PD_LOG_SIZE_MASK 0x1f
  3492. #define PD_LOG_PORT_MASK 0xe0
  3493. #define PD_LOG_PORT_SHIFT 5
  3494. #define PD_LOG_PORT_SIZE(port, size) (((port) << PD_LOG_PORT_SHIFT) | \
  3495. ((size) & PD_LOG_SIZE_MASK))
  3496. #define PD_LOG_PORT(size_port) ((size_port) >> PD_LOG_PORT_SHIFT)
  3497. #define PD_LOG_SIZE(size_port) ((size_port) & PD_LOG_SIZE_MASK)
  3498. /* PD event log : entry types */
  3499. /* PD MCU events */
  3500. #define PD_EVENT_MCU_BASE 0x00
  3501. #define PD_EVENT_MCU_CHARGE (PD_EVENT_MCU_BASE+0)
  3502. #define PD_EVENT_MCU_CONNECT (PD_EVENT_MCU_BASE+1)
  3503. /* Reserved for custom board event */
  3504. #define PD_EVENT_MCU_BOARD_CUSTOM (PD_EVENT_MCU_BASE+2)
  3505. /* PD generic accessory events */
  3506. #define PD_EVENT_ACC_BASE 0x20
  3507. #define PD_EVENT_ACC_RW_FAIL (PD_EVENT_ACC_BASE+0)
  3508. #define PD_EVENT_ACC_RW_ERASE (PD_EVENT_ACC_BASE+1)
  3509. /* PD power supply events */
  3510. #define PD_EVENT_PS_BASE 0x40
  3511. #define PD_EVENT_PS_FAULT (PD_EVENT_PS_BASE+0)
  3512. /* PD video dongles events */
  3513. #define PD_EVENT_VIDEO_BASE 0x60
  3514. #define PD_EVENT_VIDEO_DP_MODE (PD_EVENT_VIDEO_BASE+0)
  3515. #define PD_EVENT_VIDEO_CODEC (PD_EVENT_VIDEO_BASE+1)
  3516. /* Returned in the "type" field, when there is no entry available */
  3517. #define PD_EVENT_NO_ENTRY 0xff
  3518. /*
  3519. * PD_EVENT_MCU_CHARGE event definition :
  3520. * the payload is "struct usb_chg_measures"
  3521. * the data field contains the port state flags as defined below :
  3522. */
  3523. /* Port partner is a dual role device */
  3524. #define CHARGE_FLAGS_DUAL_ROLE (1 << 15)
  3525. /* Port is the pending override port */
  3526. #define CHARGE_FLAGS_DELAYED_OVERRIDE (1 << 14)
  3527. /* Port is the override port */
  3528. #define CHARGE_FLAGS_OVERRIDE (1 << 13)
  3529. /* Charger type */
  3530. #define CHARGE_FLAGS_TYPE_SHIFT 3
  3531. #define CHARGE_FLAGS_TYPE_MASK (0xf << CHARGE_FLAGS_TYPE_SHIFT)
  3532. /* Power delivery role */
  3533. #define CHARGE_FLAGS_ROLE_MASK (7 << 0)
  3534. /*
  3535. * PD_EVENT_PS_FAULT data field flags definition :
  3536. */
  3537. #define PS_FAULT_OCP 1
  3538. #define PS_FAULT_FAST_OCP 2
  3539. #define PS_FAULT_OVP 3
  3540. #define PS_FAULT_DISCH 4
  3541. /*
  3542. * PD_EVENT_VIDEO_CODEC payload is "struct mcdp_info".
  3543. */
  3544. struct __ec_align4 mcdp_version {
  3545. uint8_t major;
  3546. uint8_t minor;
  3547. uint16_t build;
  3548. };
  3549. struct __ec_align4 mcdp_info {
  3550. uint8_t family[2];
  3551. uint8_t chipid[2];
  3552. struct mcdp_version irom;
  3553. struct mcdp_version fw;
  3554. };
  3555. /* struct mcdp_info field decoding */
  3556. #define MCDP_CHIPID(chipid) ((chipid[0] << 8) | chipid[1])
  3557. #define MCDP_FAMILY(family) ((family[0] << 8) | family[1])
  3558. /* Get/Set USB-PD Alternate mode info */
  3559. #define EC_CMD_USB_PD_GET_AMODE 0x0116
  3560. struct __ec_align_size1 ec_params_usb_pd_get_mode_request {
  3561. uint16_t svid_idx; /* SVID index to get */
  3562. uint8_t port; /* port */
  3563. };
  3564. struct __ec_align4 ec_params_usb_pd_get_mode_response {
  3565. uint16_t svid; /* SVID */
  3566. uint16_t opos; /* Object Position */
  3567. uint32_t vdo[6]; /* Mode VDOs */
  3568. };
  3569. #define EC_CMD_USB_PD_SET_AMODE 0x0117
  3570. enum pd_mode_cmd {
  3571. PD_EXIT_MODE = 0,
  3572. PD_ENTER_MODE = 1,
  3573. /* Not a command. Do NOT remove. */
  3574. PD_MODE_CMD_COUNT,
  3575. };
  3576. struct __ec_align4 ec_params_usb_pd_set_mode_request {
  3577. uint32_t cmd; /* enum pd_mode_cmd */
  3578. uint16_t svid; /* SVID to set */
  3579. uint8_t opos; /* Object Position */
  3580. uint8_t port; /* port */
  3581. };
  3582. /* Ask the PD MCU to record a log of a requested type */
  3583. #define EC_CMD_PD_WRITE_LOG_ENTRY 0x0118
  3584. struct __ec_align1 ec_params_pd_write_log_entry {
  3585. uint8_t type; /* event type : see PD_EVENT_xx above */
  3586. uint8_t port; /* port#, or 0 for events unrelated to a given port */
  3587. };
  3588. /* Control USB-PD chip */
  3589. #define EC_CMD_PD_CONTROL 0x0119
  3590. enum ec_pd_control_cmd {
  3591. PD_SUSPEND = 0, /* Suspend the PD chip (EC: stop talking to PD) */
  3592. PD_RESUME, /* Resume the PD chip (EC: start talking to PD) */
  3593. PD_RESET, /* Force reset the PD chip */
  3594. PD_CONTROL_DISABLE /* Disable further calls to this command */
  3595. };
  3596. struct __ec_align1 ec_params_pd_control {
  3597. uint8_t chip; /* chip id (should be 0) */
  3598. uint8_t subcmd;
  3599. };
  3600. /* Get info about USB-C SS muxes */
  3601. #define EC_CMD_USB_PD_MUX_INFO 0x011A
  3602. struct __ec_align1 ec_params_usb_pd_mux_info {
  3603. uint8_t port; /* USB-C port number */
  3604. };
  3605. /* Flags representing mux state */
  3606. #define USB_PD_MUX_USB_ENABLED (1 << 0)
  3607. #define USB_PD_MUX_DP_ENABLED (1 << 1)
  3608. #define USB_PD_MUX_POLARITY_INVERTED (1 << 2)
  3609. #define USB_PD_MUX_HPD_IRQ (1 << 3)
  3610. struct __ec_align1 ec_response_usb_pd_mux_info {
  3611. uint8_t flags; /* USB_PD_MUX_*-encoded USB mux state */
  3612. };
  3613. #define EC_CMD_PD_CHIP_INFO 0x011B
  3614. struct __ec_align1 ec_params_pd_chip_info {
  3615. uint8_t port; /* USB-C port number */
  3616. uint8_t renew; /* Force renewal */
  3617. };
  3618. struct __ec_align2 ec_response_pd_chip_info {
  3619. uint16_t vendor_id;
  3620. uint16_t product_id;
  3621. uint16_t device_id;
  3622. union {
  3623. uint8_t fw_version_string[8];
  3624. uint64_t fw_version_number;
  3625. };
  3626. };
  3627. /* Run RW signature verification and get status */
  3628. #define EC_CMD_RWSIG_CHECK_STATUS 0x011C
  3629. struct __ec_align4 ec_response_rwsig_check_status {
  3630. uint32_t status;
  3631. };
  3632. /* For controlling RWSIG task */
  3633. #define EC_CMD_RWSIG_ACTION 0x011D
  3634. enum rwsig_action {
  3635. RWSIG_ACTION_ABORT = 0, /* Abort RWSIG and prevent jumping */
  3636. RWSIG_ACTION_CONTINUE = 1, /* Jump to RW immediately */
  3637. };
  3638. struct __ec_align4 ec_params_rwsig_action {
  3639. uint32_t action;
  3640. };
  3641. /* Run verification on a slot */
  3642. #define EC_CMD_EFS_VERIFY 0x011E
  3643. struct __ec_align1 ec_params_efs_verify {
  3644. uint8_t region; /* enum ec_flash_region */
  3645. };
  3646. /*
  3647. * Retrieve info from Cros Board Info store. Response is based on the data
  3648. * type. Integers return a uint32. Strings return a string, using the response
  3649. * size to determine how big it is.
  3650. */
  3651. #define EC_CMD_GET_CROS_BOARD_INFO 0x011F
  3652. /*
  3653. * Write info into Cros Board Info on EEPROM. Write fails if the board has
  3654. * hardware write-protect enabled.
  3655. */
  3656. #define EC_CMD_SET_CROS_BOARD_INFO 0x0120
  3657. enum cbi_data_tag {
  3658. CBI_TAG_BOARD_VERSION = 0, /* uint16_t or uint8_t[] = {minor,major} */
  3659. CBI_TAG_OEM_ID = 1, /* uint8_t */
  3660. CBI_TAG_SKU_ID = 2, /* uint8_t */
  3661. CBI_TAG_COUNT,
  3662. };
  3663. /*
  3664. * Flags to control read operation
  3665. *
  3666. * RELOAD: Invalidate cache and read data from EEPROM. Useful to verify
  3667. * write was successful without reboot.
  3668. */
  3669. #define CBI_GET_RELOAD (1 << 0)
  3670. struct __ec_align4 ec_params_get_cbi {
  3671. uint32_t type; /* enum cbi_data_tag */
  3672. uint32_t flag; /* CBI_GET_* */
  3673. };
  3674. /*
  3675. * Flags to control write behavior.
  3676. *
  3677. * NO_SYNC: Makes EC update data in RAM but skip writing to EEPROM. It's
  3678. * useful when writing multiple fields in a row.
  3679. * INIT: Needs to be set when creating a new CBI from scratch. All fields
  3680. * will be initialized to zero first.
  3681. */
  3682. #define CBI_SET_NO_SYNC (1 << 0)
  3683. #define CBI_SET_INIT (1 << 1)
  3684. struct __ec_align1 ec_params_set_cbi {
  3685. uint32_t tag; /* enum cbi_data_tag */
  3686. uint32_t flag; /* CBI_SET_* */
  3687. uint32_t size; /* Data size */
  3688. uint8_t data[]; /* For string and raw data */
  3689. };
  3690. /*****************************************************************************/
  3691. /* The command range 0x200-0x2FF is reserved for Rotor. */
  3692. /*****************************************************************************/
  3693. /*
  3694. * Reserve a range of host commands for the CR51 firmware.
  3695. */
  3696. #define EC_CMD_CR51_BASE 0x0300
  3697. #define EC_CMD_CR51_LAST 0x03FF
  3698. /*****************************************************************************/
  3699. /* Fingerprint MCU commands: range 0x0400-0x040x */
  3700. /* Fingerprint SPI sensor passthru command: prototyping ONLY */
  3701. #define EC_CMD_FP_PASSTHRU 0x0400
  3702. #define EC_FP_FLAG_NOT_COMPLETE 0x1
  3703. struct __ec_align2 ec_params_fp_passthru {
  3704. uint16_t len; /* Number of bytes to write then read */
  3705. uint16_t flags; /* EC_FP_FLAG_xxx */
  3706. uint8_t data[]; /* Data to send */
  3707. };
  3708. /* Fingerprint sensor configuration command: prototyping ONLY */
  3709. #define EC_CMD_FP_SENSOR_CONFIG 0x0401
  3710. #define EC_FP_SENSOR_CONFIG_MAX_REGS 16
  3711. struct __ec_align2 ec_params_fp_sensor_config {
  3712. uint8_t count; /* Number of setup registers */
  3713. /*
  3714. * the value to send to each of the 'count' setup registers
  3715. * is stored in the 'data' array for 'len' bytes just after
  3716. * the previous one.
  3717. */
  3718. uint8_t len[EC_FP_SENSOR_CONFIG_MAX_REGS];
  3719. uint8_t data[];
  3720. };
  3721. /* Configure the Fingerprint MCU behavior */
  3722. #define EC_CMD_FP_MODE 0x0402
  3723. /* Put the sensor in its lowest power mode */
  3724. #define FP_MODE_DEEPSLEEP (1<<0)
  3725. /* Wait to see a finger on the sensor */
  3726. #define FP_MODE_FINGER_DOWN (1<<1)
  3727. /* Poll until the finger has left the sensor */
  3728. #define FP_MODE_FINGER_UP (1<<2)
  3729. /* Capture the current finger image */
  3730. #define FP_MODE_CAPTURE (1<<3)
  3731. /* special value: don't change anything just read back current mode */
  3732. #define FP_MODE_DONT_CHANGE (1<<31)
  3733. struct __ec_align4 ec_params_fp_mode {
  3734. uint32_t mode; /* as defined by FP_MODE_ constants */
  3735. /* TBD */
  3736. };
  3737. struct __ec_align4 ec_response_fp_mode {
  3738. uint32_t mode; /* as defined by FP_MODE_ constants */
  3739. /* TBD */
  3740. };
  3741. /* Retrieve Fingerprint sensor information */
  3742. #define EC_CMD_FP_INFO 0x0403
  3743. struct __ec_align2 ec_response_fp_info {
  3744. /* Sensor identification */
  3745. uint32_t vendor_id;
  3746. uint32_t product_id;
  3747. uint32_t model_id;
  3748. uint32_t version;
  3749. /* Image frame characteristics */
  3750. uint32_t frame_size;
  3751. uint32_t pixel_format; /* using V4L2_PIX_FMT_ */
  3752. uint16_t width;
  3753. uint16_t height;
  3754. uint16_t bpp;
  3755. };
  3756. /* Get the last captured finger frame: TODO: will be AES-encrypted */
  3757. #define EC_CMD_FP_FRAME 0x0404
  3758. struct __ec_align4 ec_params_fp_frame {
  3759. uint32_t offset;
  3760. uint32_t size;
  3761. };
  3762. /*****************************************************************************/
  3763. /* Touchpad MCU commands: range 0x0500-0x05FF */
  3764. /* Perform touchpad self test */
  3765. #define EC_CMD_TP_SELF_TEST 0x0500
  3766. /* Get number of frame types, and the size of each type */
  3767. #define EC_CMD_TP_FRAME_INFO 0x0501
  3768. struct __ec_align4 ec_response_tp_frame_info {
  3769. uint32_t n_frames;
  3770. uint32_t frame_sizes[0];
  3771. };
  3772. /* Create a snapshot of current frame readings */
  3773. #define EC_CMD_TP_FRAME_SNAPSHOT 0x0502
  3774. /* Read the frame */
  3775. #define EC_CMD_TP_FRAME_GET 0x0503
  3776. struct __ec_align4 ec_params_tp_frame_get {
  3777. uint32_t frame_index;
  3778. uint32_t offset;
  3779. uint32_t size;
  3780. };
  3781. /*****************************************************************************/
  3782. /*
  3783. * Reserve a range of host commands for board-specific, experimental, or
  3784. * special purpose features. These can be (re)used without updating this file.
  3785. *
  3786. * CAUTION: Don't go nuts with this. Shipping products should document ALL
  3787. * their EC commands for easier development, testing, debugging, and support.
  3788. *
  3789. * All commands MUST be #defined to be 4-digit UPPER CASE hex values
  3790. * (e.g., 0x00AB, not 0xab) for CONFIG_HOSTCMD_SECTION_SORTED to work.
  3791. *
  3792. * In your experimental code, you may want to do something like this:
  3793. *
  3794. * #define EC_CMD_MAGIC_FOO 0x0000
  3795. * #define EC_CMD_MAGIC_BAR 0x0001
  3796. * #define EC_CMD_MAGIC_HEY 0x0002
  3797. *
  3798. * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_FOO, magic_foo_handler,
  3799. * EC_VER_MASK(0);
  3800. *
  3801. * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_BAR, magic_bar_handler,
  3802. * EC_VER_MASK(0);
  3803. *
  3804. * DECLARE_PRIVATE_HOST_COMMAND(EC_CMD_MAGIC_HEY, magic_hey_handler,
  3805. * EC_VER_MASK(0);
  3806. */
  3807. #define EC_CMD_BOARD_SPECIFIC_BASE 0x3E00
  3808. #define EC_CMD_BOARD_SPECIFIC_LAST 0x3FFF
  3809. /*
  3810. * Given the private host command offset, calculate the true private host
  3811. * command value.
  3812. */
  3813. #define EC_PRIVATE_HOST_COMMAND_VALUE(command) \
  3814. (EC_CMD_BOARD_SPECIFIC_BASE + (command))
  3815. /*****************************************************************************/
  3816. /*
  3817. * Passthru commands
  3818. *
  3819. * Some platforms have sub-processors chained to each other. For example.
  3820. *
  3821. * AP <--> EC <--> PD MCU
  3822. *
  3823. * The top 2 bits of the command number are used to indicate which device the
  3824. * command is intended for. Device 0 is always the device receiving the
  3825. * command; other device mapping is board-specific.
  3826. *
  3827. * When a device receives a command to be passed to a sub-processor, it passes
  3828. * it on with the device number set back to 0. This allows the sub-processor
  3829. * to remain blissfully unaware of whether the command originated on the next
  3830. * device up the chain, or was passed through from the AP.
  3831. *
  3832. * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
  3833. * AP sends command 0x4002 to the EC
  3834. * EC sends command 0x0002 to the PD MCU
  3835. * EC forwards PD MCU response back to the AP
  3836. */
  3837. /* Offset and max command number for sub-device n */
  3838. #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
  3839. #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
  3840. /*****************************************************************************/
  3841. /*
  3842. * Deprecated constants. These constants have been renamed for clarity. The
  3843. * meaning and size has not changed. Programs that use the old names should
  3844. * switch to the new names soon, as the old names may not be carried forward
  3845. * forever.
  3846. */
  3847. #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
  3848. #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
  3849. #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
  3850. #endif /* !__ACPI__ && !__KERNEL__ */
  3851. #endif /* __CROS_EC_COMMANDS_H */