cros_ec_commands.h 86 KB

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