ec_commands.h 131 KB

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