cros_ec_commands.h 109 KB

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