ec_commands.h 133 KB

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