cros_ec_commands.h 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614
  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. /*
  259. * The high bit of the event mask is not used as a host event code. If
  260. * it reads back as set, then the entire event mask should be
  261. * considered invalid by the host. This can happen when reading the
  262. * raw event status via EC_MEMMAP_HOST_EVENTS but the LPC interface is
  263. * not initialized on the EC, or improperly configured on the host.
  264. */
  265. EC_HOST_EVENT_INVALID = 32
  266. };
  267. /* Host event mask */
  268. #define EC_HOST_EVENT_MASK(event_code) (1UL << ((event_code) - 1))
  269. /* Arguments at EC_LPC_ADDR_HOST_ARGS */
  270. struct ec_lpc_host_args {
  271. uint8_t flags;
  272. uint8_t command_version;
  273. uint8_t data_size;
  274. /*
  275. * Checksum; sum of command + flags + command_version + data_size +
  276. * all params/response data bytes.
  277. */
  278. uint8_t checksum;
  279. } __packed;
  280. /* Flags for ec_lpc_host_args.flags */
  281. /*
  282. * Args are from host. Data area at EC_LPC_ADDR_HOST_PARAM contains command
  283. * params.
  284. *
  285. * If EC gets a command and this flag is not set, this is an old-style command.
  286. * Command version is 0 and params from host are at EC_LPC_ADDR_OLD_PARAM with
  287. * unknown length. EC must respond with an old-style response (that is,
  288. * withouth setting EC_HOST_ARGS_FLAG_TO_HOST).
  289. */
  290. #define EC_HOST_ARGS_FLAG_FROM_HOST 0x01
  291. /*
  292. * Args are from EC. Data area at EC_LPC_ADDR_HOST_PARAM contains response.
  293. *
  294. * If EC responds to a command and this flag is not set, this is an old-style
  295. * response. Command version is 0 and response data from EC is at
  296. * EC_LPC_ADDR_OLD_PARAM with unknown length.
  297. */
  298. #define EC_HOST_ARGS_FLAG_TO_HOST 0x02
  299. /*****************************************************************************/
  300. /*
  301. * Byte codes returned by EC over SPI interface.
  302. *
  303. * These can be used by the AP to debug the EC interface, and to determine
  304. * when the EC is not in a state where it will ever get around to responding
  305. * to the AP.
  306. *
  307. * Example of sequence of bytes read from EC for a current good transfer:
  308. * 1. - - AP asserts chip select (CS#)
  309. * 2. EC_SPI_OLD_READY - AP sends first byte(s) of request
  310. * 3. - - EC starts handling CS# interrupt
  311. * 4. EC_SPI_RECEIVING - AP sends remaining byte(s) of request
  312. * 5. EC_SPI_PROCESSING - EC starts processing request; AP is clocking in
  313. * bytes looking for EC_SPI_FRAME_START
  314. * 6. - - EC finishes processing and sets up response
  315. * 7. EC_SPI_FRAME_START - AP reads frame byte
  316. * 8. (response packet) - AP reads response packet
  317. * 9. EC_SPI_PAST_END - Any additional bytes read by AP
  318. * 10 - - AP deasserts chip select
  319. * 11 - - EC processes CS# interrupt and sets up DMA for
  320. * next request
  321. *
  322. * If the AP is waiting for EC_SPI_FRAME_START and sees any value other than
  323. * the following byte values:
  324. * EC_SPI_OLD_READY
  325. * EC_SPI_RX_READY
  326. * EC_SPI_RECEIVING
  327. * EC_SPI_PROCESSING
  328. *
  329. * Then the EC found an error in the request, or was not ready for the request
  330. * and lost data. The AP should give up waiting for EC_SPI_FRAME_START,
  331. * because the EC is unable to tell when the AP is done sending its request.
  332. */
  333. /*
  334. * Framing byte which precedes a response packet from the EC. After sending a
  335. * request, the AP will clock in bytes until it sees the framing byte, then
  336. * clock in the response packet.
  337. */
  338. #define EC_SPI_FRAME_START 0xec
  339. /*
  340. * Padding bytes which are clocked out after the end of a response packet.
  341. */
  342. #define EC_SPI_PAST_END 0xed
  343. /*
  344. * EC is ready to receive, and has ignored the byte sent by the AP. EC expects
  345. * that the AP will send a valid packet header (starting with
  346. * EC_COMMAND_PROTOCOL_3) in the next 32 bytes.
  347. */
  348. #define EC_SPI_RX_READY 0xf8
  349. /*
  350. * EC has started receiving the request from the AP, but hasn't started
  351. * processing it yet.
  352. */
  353. #define EC_SPI_RECEIVING 0xf9
  354. /* EC has received the entire request from the AP and is processing it. */
  355. #define EC_SPI_PROCESSING 0xfa
  356. /*
  357. * EC received bad data from the AP, such as a packet header with an invalid
  358. * length. EC will ignore all data until chip select deasserts.
  359. */
  360. #define EC_SPI_RX_BAD_DATA 0xfb
  361. /*
  362. * EC received data from the AP before it was ready. That is, the AP asserted
  363. * chip select and started clocking data before the EC was ready to receive it.
  364. * EC will ignore all data until chip select deasserts.
  365. */
  366. #define EC_SPI_NOT_READY 0xfc
  367. /*
  368. * EC was ready to receive a request from the AP. EC has treated the byte sent
  369. * by the AP as part of a request packet, or (for old-style ECs) is processing
  370. * a fully received packet but is not ready to respond yet.
  371. */
  372. #define EC_SPI_OLD_READY 0xfd
  373. /*****************************************************************************/
  374. /*
  375. * Protocol version 2 for I2C and SPI send a request this way:
  376. *
  377. * 0 EC_CMD_VERSION0 + (command version)
  378. * 1 Command number
  379. * 2 Length of params = N
  380. * 3..N+2 Params, if any
  381. * N+3 8-bit checksum of bytes 0..N+2
  382. *
  383. * The corresponding response is:
  384. *
  385. * 0 Result code (EC_RES_*)
  386. * 1 Length of params = M
  387. * 2..M+1 Params, if any
  388. * M+2 8-bit checksum of bytes 0..M+1
  389. */
  390. #define EC_PROTO2_REQUEST_HEADER_BYTES 3
  391. #define EC_PROTO2_REQUEST_TRAILER_BYTES 1
  392. #define EC_PROTO2_REQUEST_OVERHEAD (EC_PROTO2_REQUEST_HEADER_BYTES + \
  393. EC_PROTO2_REQUEST_TRAILER_BYTES)
  394. #define EC_PROTO2_RESPONSE_HEADER_BYTES 2
  395. #define EC_PROTO2_RESPONSE_TRAILER_BYTES 1
  396. #define EC_PROTO2_RESPONSE_OVERHEAD (EC_PROTO2_RESPONSE_HEADER_BYTES + \
  397. EC_PROTO2_RESPONSE_TRAILER_BYTES)
  398. /* Parameter length was limited by the LPC interface */
  399. #define EC_PROTO2_MAX_PARAM_SIZE 0xfc
  400. /* Maximum request and response packet sizes for protocol version 2 */
  401. #define EC_PROTO2_MAX_REQUEST_SIZE (EC_PROTO2_REQUEST_OVERHEAD + \
  402. EC_PROTO2_MAX_PARAM_SIZE)
  403. #define EC_PROTO2_MAX_RESPONSE_SIZE (EC_PROTO2_RESPONSE_OVERHEAD + \
  404. EC_PROTO2_MAX_PARAM_SIZE)
  405. /*****************************************************************************/
  406. /*
  407. * Value written to legacy command port / prefix byte to indicate protocol
  408. * 3+ structs are being used. Usage is bus-dependent.
  409. */
  410. #define EC_COMMAND_PROTOCOL_3 0xda
  411. #define EC_HOST_REQUEST_VERSION 3
  412. /* Version 3 request from host */
  413. struct ec_host_request {
  414. /* Struct version (=3)
  415. *
  416. * EC will return EC_RES_INVALID_HEADER if it receives a header with a
  417. * version it doesn't know how to parse.
  418. */
  419. uint8_t struct_version;
  420. /*
  421. * Checksum of request and data; sum of all bytes including checksum
  422. * should total to 0.
  423. */
  424. uint8_t checksum;
  425. /* Command code */
  426. uint16_t command;
  427. /* Command version */
  428. uint8_t command_version;
  429. /* Unused byte in current protocol version; set to 0 */
  430. uint8_t reserved;
  431. /* Length of data which follows this header */
  432. uint16_t data_len;
  433. } __packed;
  434. #define EC_HOST_RESPONSE_VERSION 3
  435. /* Version 3 response from EC */
  436. struct ec_host_response {
  437. /* Struct version (=3) */
  438. uint8_t struct_version;
  439. /*
  440. * Checksum of response and data; sum of all bytes including checksum
  441. * should total to 0.
  442. */
  443. uint8_t checksum;
  444. /* Result code (EC_RES_*) */
  445. uint16_t result;
  446. /* Length of data which follows this header */
  447. uint16_t data_len;
  448. /* Unused bytes in current protocol version; set to 0 */
  449. uint16_t reserved;
  450. } __packed;
  451. /*****************************************************************************/
  452. /*
  453. * Notes on commands:
  454. *
  455. * Each command is an 16-bit command value. Commands which take params or
  456. * return response data specify structs for that data. If no struct is
  457. * specified, the command does not input or output data, respectively.
  458. * Parameter/response length is implicit in the structs. Some underlying
  459. * communication protocols (I2C, SPI) may add length or checksum headers, but
  460. * those are implementation-dependent and not defined here.
  461. */
  462. /*****************************************************************************/
  463. /* General / test commands */
  464. /*
  465. * Get protocol version, used to deal with non-backward compatible protocol
  466. * changes.
  467. */
  468. #define EC_CMD_PROTO_VERSION 0x00
  469. struct ec_response_proto_version {
  470. uint32_t version;
  471. } __packed;
  472. /*
  473. * Hello. This is a simple command to test the EC is responsive to
  474. * commands.
  475. */
  476. #define EC_CMD_HELLO 0x01
  477. struct ec_params_hello {
  478. uint32_t in_data; /* Pass anything here */
  479. } __packed;
  480. struct ec_response_hello {
  481. uint32_t out_data; /* Output will be in_data + 0x01020304 */
  482. } __packed;
  483. /* Get version number */
  484. #define EC_CMD_GET_VERSION 0x02
  485. enum ec_current_image {
  486. EC_IMAGE_UNKNOWN = 0,
  487. EC_IMAGE_RO,
  488. EC_IMAGE_RW
  489. };
  490. struct ec_response_get_version {
  491. /* Null-terminated version strings for RO, RW */
  492. char version_string_ro[32];
  493. char version_string_rw[32];
  494. char reserved[32]; /* Was previously RW-B string */
  495. uint32_t current_image; /* One of ec_current_image */
  496. } __packed;
  497. /* Read test */
  498. #define EC_CMD_READ_TEST 0x03
  499. struct ec_params_read_test {
  500. uint32_t offset; /* Starting value for read buffer */
  501. uint32_t size; /* Size to read in bytes */
  502. } __packed;
  503. struct ec_response_read_test {
  504. uint32_t data[32];
  505. } __packed;
  506. /*
  507. * Get build information
  508. *
  509. * Response is null-terminated string.
  510. */
  511. #define EC_CMD_GET_BUILD_INFO 0x04
  512. /* Get chip info */
  513. #define EC_CMD_GET_CHIP_INFO 0x05
  514. struct ec_response_get_chip_info {
  515. /* Null-terminated strings */
  516. char vendor[32];
  517. char name[32];
  518. char revision[32]; /* Mask version */
  519. } __packed;
  520. /* Get board HW version */
  521. #define EC_CMD_GET_BOARD_VERSION 0x06
  522. struct ec_response_board_version {
  523. uint16_t board_version; /* A monotonously incrementing number. */
  524. } __packed;
  525. /*
  526. * Read memory-mapped data.
  527. *
  528. * This is an alternate interface to memory-mapped data for bus protocols
  529. * which don't support direct-mapped memory - I2C, SPI, etc.
  530. *
  531. * Response is params.size bytes of data.
  532. */
  533. #define EC_CMD_READ_MEMMAP 0x07
  534. struct ec_params_read_memmap {
  535. uint8_t offset; /* Offset in memmap (EC_MEMMAP_*) */
  536. uint8_t size; /* Size to read in bytes */
  537. } __packed;
  538. /* Read versions supported for a command */
  539. #define EC_CMD_GET_CMD_VERSIONS 0x08
  540. struct ec_params_get_cmd_versions {
  541. uint8_t cmd; /* Command to check */
  542. } __packed;
  543. struct ec_response_get_cmd_versions {
  544. /*
  545. * Mask of supported versions; use EC_VER_MASK() to compare with a
  546. * desired version.
  547. */
  548. uint32_t version_mask;
  549. } __packed;
  550. /*
  551. * Check EC communcations status (busy). This is needed on i2c/spi but not
  552. * on lpc since it has its own out-of-band busy indicator.
  553. *
  554. * lpc must read the status from the command register. Attempting this on
  555. * lpc will overwrite the args/parameter space and corrupt its data.
  556. */
  557. #define EC_CMD_GET_COMMS_STATUS 0x09
  558. /* Avoid using ec_status which is for return values */
  559. enum ec_comms_status {
  560. EC_COMMS_STATUS_PROCESSING = 1 << 0, /* Processing cmd */
  561. };
  562. struct ec_response_get_comms_status {
  563. uint32_t flags; /* Mask of enum ec_comms_status */
  564. } __packed;
  565. /* Fake a variety of responses, purely for testing purposes. */
  566. #define EC_CMD_TEST_PROTOCOL 0x0a
  567. /* Tell the EC what to send back to us. */
  568. struct ec_params_test_protocol {
  569. uint32_t ec_result;
  570. uint32_t ret_len;
  571. uint8_t buf[32];
  572. } __packed;
  573. /* Here it comes... */
  574. struct ec_response_test_protocol {
  575. uint8_t buf[32];
  576. } __packed;
  577. /* Get prococol information */
  578. #define EC_CMD_GET_PROTOCOL_INFO 0x0b
  579. /* Flags for ec_response_get_protocol_info.flags */
  580. /* EC_RES_IN_PROGRESS may be returned if a command is slow */
  581. #define EC_PROTOCOL_INFO_IN_PROGRESS_SUPPORTED (1 << 0)
  582. struct ec_response_get_protocol_info {
  583. /* Fields which exist if at least protocol version 3 supported */
  584. /* Bitmask of protocol versions supported (1 << n means version n)*/
  585. uint32_t protocol_versions;
  586. /* Maximum request packet size, in bytes */
  587. uint16_t max_request_packet_size;
  588. /* Maximum response packet size, in bytes */
  589. uint16_t max_response_packet_size;
  590. /* Flags; see EC_PROTOCOL_INFO_* */
  591. uint32_t flags;
  592. } __packed;
  593. /*****************************************************************************/
  594. /* Get/Set miscellaneous values */
  595. /* The upper byte of .flags tells what to do (nothing means "get") */
  596. #define EC_GSV_SET 0x80000000
  597. /* The lower three bytes of .flags identifies the parameter, if that has
  598. meaning for an individual command. */
  599. #define EC_GSV_PARAM_MASK 0x00ffffff
  600. struct ec_params_get_set_value {
  601. uint32_t flags;
  602. uint32_t value;
  603. } __packed;
  604. struct ec_response_get_set_value {
  605. uint32_t flags;
  606. uint32_t value;
  607. } __packed;
  608. /* More than one command can use these structs to get/set paramters. */
  609. #define EC_CMD_GSV_PAUSE_IN_S5 0x0c
  610. /*****************************************************************************/
  611. /* Flash commands */
  612. /* Get flash info */
  613. #define EC_CMD_FLASH_INFO 0x10
  614. /* Version 0 returns these fields */
  615. struct ec_response_flash_info {
  616. /* Usable flash size, in bytes */
  617. uint32_t flash_size;
  618. /*
  619. * Write block size. Write offset and size must be a multiple
  620. * of this.
  621. */
  622. uint32_t write_block_size;
  623. /*
  624. * Erase block size. Erase offset and size must be a multiple
  625. * of this.
  626. */
  627. uint32_t erase_block_size;
  628. /*
  629. * Protection block size. Protection offset and size must be a
  630. * multiple of this.
  631. */
  632. uint32_t protect_block_size;
  633. } __packed;
  634. /* Flags for version 1+ flash info command */
  635. /* EC flash erases bits to 0 instead of 1 */
  636. #define EC_FLASH_INFO_ERASE_TO_0 (1 << 0)
  637. /*
  638. * Version 1 returns the same initial fields as version 0, with additional
  639. * fields following.
  640. *
  641. * gcc anonymous structs don't seem to get along with the __packed directive;
  642. * if they did we'd define the version 0 struct as a sub-struct of this one.
  643. */
  644. struct ec_response_flash_info_1 {
  645. /* Version 0 fields; see above for description */
  646. uint32_t flash_size;
  647. uint32_t write_block_size;
  648. uint32_t erase_block_size;
  649. uint32_t protect_block_size;
  650. /* Version 1 adds these fields: */
  651. /*
  652. * Ideal write size in bytes. Writes will be fastest if size is
  653. * exactly this and offset is a multiple of this. For example, an EC
  654. * may have a write buffer which can do half-page operations if data is
  655. * aligned, and a slower word-at-a-time write mode.
  656. */
  657. uint32_t write_ideal_size;
  658. /* Flags; see EC_FLASH_INFO_* */
  659. uint32_t flags;
  660. } __packed;
  661. /*
  662. * Read flash
  663. *
  664. * Response is params.size bytes of data.
  665. */
  666. #define EC_CMD_FLASH_READ 0x11
  667. struct ec_params_flash_read {
  668. uint32_t offset; /* Byte offset to read */
  669. uint32_t size; /* Size to read in bytes */
  670. } __packed;
  671. /* Write flash */
  672. #define EC_CMD_FLASH_WRITE 0x12
  673. #define EC_VER_FLASH_WRITE 1
  674. /* Version 0 of the flash command supported only 64 bytes of data */
  675. #define EC_FLASH_WRITE_VER0_SIZE 64
  676. struct ec_params_flash_write {
  677. uint32_t offset; /* Byte offset to write */
  678. uint32_t size; /* Size to write in bytes */
  679. /* Followed by data to write */
  680. } __packed;
  681. /* Erase flash */
  682. #define EC_CMD_FLASH_ERASE 0x13
  683. struct ec_params_flash_erase {
  684. uint32_t offset; /* Byte offset to erase */
  685. uint32_t size; /* Size to erase in bytes */
  686. } __packed;
  687. /*
  688. * Get/set flash protection.
  689. *
  690. * If mask!=0, sets/clear the requested bits of flags. Depending on the
  691. * firmware write protect GPIO, not all flags will take effect immediately;
  692. * some flags require a subsequent hard reset to take effect. Check the
  693. * returned flags bits to see what actually happened.
  694. *
  695. * If mask=0, simply returns the current flags state.
  696. */
  697. #define EC_CMD_FLASH_PROTECT 0x15
  698. #define EC_VER_FLASH_PROTECT 1 /* Command version 1 */
  699. /* Flags for flash protection */
  700. /* RO flash code protected when the EC boots */
  701. #define EC_FLASH_PROTECT_RO_AT_BOOT (1 << 0)
  702. /*
  703. * RO flash code protected now. If this bit is set, at-boot status cannot
  704. * be changed.
  705. */
  706. #define EC_FLASH_PROTECT_RO_NOW (1 << 1)
  707. /* Entire flash code protected now, until reboot. */
  708. #define EC_FLASH_PROTECT_ALL_NOW (1 << 2)
  709. /* Flash write protect GPIO is asserted now */
  710. #define EC_FLASH_PROTECT_GPIO_ASSERTED (1 << 3)
  711. /* Error - at least one bank of flash is stuck locked, and cannot be unlocked */
  712. #define EC_FLASH_PROTECT_ERROR_STUCK (1 << 4)
  713. /*
  714. * Error - flash protection is in inconsistent state. At least one bank of
  715. * flash which should be protected is not protected. Usually fixed by
  716. * re-requesting the desired flags, or by a hard reset if that fails.
  717. */
  718. #define EC_FLASH_PROTECT_ERROR_INCONSISTENT (1 << 5)
  719. /* Entile flash code protected when the EC boots */
  720. #define EC_FLASH_PROTECT_ALL_AT_BOOT (1 << 6)
  721. struct ec_params_flash_protect {
  722. uint32_t mask; /* Bits in flags to apply */
  723. uint32_t flags; /* New flags to apply */
  724. } __packed;
  725. struct ec_response_flash_protect {
  726. /* Current value of flash protect flags */
  727. uint32_t flags;
  728. /*
  729. * Flags which are valid on this platform. This allows the caller
  730. * to distinguish between flags which aren't set vs. flags which can't
  731. * be set on this platform.
  732. */
  733. uint32_t valid_flags;
  734. /* Flags which can be changed given the current protection state */
  735. uint32_t writable_flags;
  736. } __packed;
  737. /*
  738. * Note: commands 0x14 - 0x19 version 0 were old commands to get/set flash
  739. * write protect. These commands may be reused with version > 0.
  740. */
  741. /* Get the region offset/size */
  742. #define EC_CMD_FLASH_REGION_INFO 0x16
  743. #define EC_VER_FLASH_REGION_INFO 1
  744. enum ec_flash_region {
  745. /* Region which holds read-only EC image */
  746. EC_FLASH_REGION_RO = 0,
  747. /* Region which holds rewritable EC image */
  748. EC_FLASH_REGION_RW,
  749. /*
  750. * Region which should be write-protected in the factory (a superset of
  751. * EC_FLASH_REGION_RO)
  752. */
  753. EC_FLASH_REGION_WP_RO,
  754. /* Number of regions */
  755. EC_FLASH_REGION_COUNT,
  756. };
  757. struct ec_params_flash_region_info {
  758. uint32_t region; /* enum ec_flash_region */
  759. } __packed;
  760. struct ec_response_flash_region_info {
  761. uint32_t offset;
  762. uint32_t size;
  763. } __packed;
  764. /* Read/write VbNvContext */
  765. #define EC_CMD_VBNV_CONTEXT 0x17
  766. #define EC_VER_VBNV_CONTEXT 1
  767. #define EC_VBNV_BLOCK_SIZE 16
  768. enum ec_vbnvcontext_op {
  769. EC_VBNV_CONTEXT_OP_READ,
  770. EC_VBNV_CONTEXT_OP_WRITE,
  771. };
  772. struct ec_params_vbnvcontext {
  773. uint32_t op;
  774. uint8_t block[EC_VBNV_BLOCK_SIZE];
  775. } __packed;
  776. struct ec_response_vbnvcontext {
  777. uint8_t block[EC_VBNV_BLOCK_SIZE];
  778. } __packed;
  779. /*****************************************************************************/
  780. /* PWM commands */
  781. /* Get fan target RPM */
  782. #define EC_CMD_PWM_GET_FAN_TARGET_RPM 0x20
  783. struct ec_response_pwm_get_fan_rpm {
  784. uint32_t rpm;
  785. } __packed;
  786. /* Set target fan RPM */
  787. #define EC_CMD_PWM_SET_FAN_TARGET_RPM 0x21
  788. struct ec_params_pwm_set_fan_target_rpm {
  789. uint32_t rpm;
  790. } __packed;
  791. /* Get keyboard backlight */
  792. #define EC_CMD_PWM_GET_KEYBOARD_BACKLIGHT 0x22
  793. struct ec_response_pwm_get_keyboard_backlight {
  794. uint8_t percent;
  795. uint8_t enabled;
  796. } __packed;
  797. /* Set keyboard backlight */
  798. #define EC_CMD_PWM_SET_KEYBOARD_BACKLIGHT 0x23
  799. struct ec_params_pwm_set_keyboard_backlight {
  800. uint8_t percent;
  801. } __packed;
  802. /* Set target fan PWM duty cycle */
  803. #define EC_CMD_PWM_SET_FAN_DUTY 0x24
  804. struct ec_params_pwm_set_fan_duty {
  805. uint32_t percent;
  806. } __packed;
  807. #define EC_CMD_PWM_SET_DUTY 0x25
  808. /* 16 bit duty cycle, 0xffff = 100% */
  809. #define EC_PWM_MAX_DUTY 0xffff
  810. enum ec_pwm_type {
  811. /* All types, indexed by board-specific enum pwm_channel */
  812. EC_PWM_TYPE_GENERIC = 0,
  813. /* Keyboard backlight */
  814. EC_PWM_TYPE_KB_LIGHT,
  815. /* Display backlight */
  816. EC_PWM_TYPE_DISPLAY_LIGHT,
  817. EC_PWM_TYPE_COUNT,
  818. };
  819. struct ec_params_pwm_set_duty {
  820. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  821. uint8_t pwm_type; /* ec_pwm_type */
  822. uint8_t index; /* Type-specific index, or 0 if unique */
  823. } __packed;
  824. #define EC_CMD_PWM_GET_DUTY 0x26
  825. struct ec_params_pwm_get_duty {
  826. uint8_t pwm_type; /* ec_pwm_type */
  827. uint8_t index; /* Type-specific index, or 0 if unique */
  828. } __packed;
  829. struct ec_response_pwm_get_duty {
  830. uint16_t duty; /* Duty cycle, EC_PWM_MAX_DUTY = 100% */
  831. } __packed;
  832. /*****************************************************************************/
  833. /*
  834. * Lightbar commands. This looks worse than it is. Since we only use one HOST
  835. * command to say "talk to the lightbar", we put the "and tell it to do X" part
  836. * into a subcommand. We'll make separate structs for subcommands with
  837. * different input args, so that we know how much to expect.
  838. */
  839. #define EC_CMD_LIGHTBAR_CMD 0x28
  840. struct rgb_s {
  841. uint8_t r, g, b;
  842. };
  843. #define LB_BATTERY_LEVELS 4
  844. /* List of tweakable parameters. NOTE: It's __packed so it can be sent in a
  845. * host command, but the alignment is the same regardless. Keep it that way.
  846. */
  847. struct lightbar_params_v0 {
  848. /* Timing */
  849. int32_t google_ramp_up;
  850. int32_t google_ramp_down;
  851. int32_t s3s0_ramp_up;
  852. int32_t s0_tick_delay[2]; /* AC=0/1 */
  853. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  854. int32_t s0s3_ramp_down;
  855. int32_t s3_sleep_for;
  856. int32_t s3_ramp_up;
  857. int32_t s3_ramp_down;
  858. /* Oscillation */
  859. uint8_t new_s0;
  860. uint8_t osc_min[2]; /* AC=0/1 */
  861. uint8_t osc_max[2]; /* AC=0/1 */
  862. uint8_t w_ofs[2]; /* AC=0/1 */
  863. /* Brightness limits based on the backlight and AC. */
  864. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  865. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  866. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  867. /* Battery level thresholds */
  868. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  869. /* Map [AC][battery_level] to color index */
  870. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  871. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  872. /* Color palette */
  873. struct rgb_s color[8]; /* 0-3 are Google colors */
  874. } __packed;
  875. struct lightbar_params_v1 {
  876. /* Timing */
  877. int32_t google_ramp_up;
  878. int32_t google_ramp_down;
  879. int32_t s3s0_ramp_up;
  880. int32_t s0_tick_delay[2]; /* AC=0/1 */
  881. int32_t s0a_tick_delay[2]; /* AC=0/1 */
  882. int32_t s0s3_ramp_down;
  883. int32_t s3_sleep_for;
  884. int32_t s3_ramp_up;
  885. int32_t s3_ramp_down;
  886. int32_t tap_tick_delay;
  887. int32_t tap_display_time;
  888. /* Tap-for-battery params */
  889. uint8_t tap_pct_red;
  890. uint8_t tap_pct_green;
  891. uint8_t tap_seg_min_on;
  892. uint8_t tap_seg_max_on;
  893. uint8_t tap_seg_osc;
  894. uint8_t tap_idx[3];
  895. /* Oscillation */
  896. uint8_t osc_min[2]; /* AC=0/1 */
  897. uint8_t osc_max[2]; /* AC=0/1 */
  898. uint8_t w_ofs[2]; /* AC=0/1 */
  899. /* Brightness limits based on the backlight and AC. */
  900. uint8_t bright_bl_off_fixed[2]; /* AC=0/1 */
  901. uint8_t bright_bl_on_min[2]; /* AC=0/1 */
  902. uint8_t bright_bl_on_max[2]; /* AC=0/1 */
  903. /* Battery level thresholds */
  904. uint8_t battery_threshold[LB_BATTERY_LEVELS - 1];
  905. /* Map [AC][battery_level] to color index */
  906. uint8_t s0_idx[2][LB_BATTERY_LEVELS]; /* AP is running */
  907. uint8_t s3_idx[2][LB_BATTERY_LEVELS]; /* AP is sleeping */
  908. /* Color palette */
  909. struct rgb_s color[8]; /* 0-3 are Google colors */
  910. } __packed;
  911. struct ec_params_lightbar {
  912. uint8_t cmd; /* Command (see enum lightbar_command) */
  913. union {
  914. struct {
  915. /* no args */
  916. } dump, off, on, init, get_seq, get_params_v0, get_params_v1,
  917. version, get_brightness, get_demo;
  918. struct {
  919. uint8_t num;
  920. } set_brightness, seq, demo;
  921. struct {
  922. uint8_t ctrl, reg, value;
  923. } reg;
  924. struct {
  925. uint8_t led, red, green, blue;
  926. } set_rgb;
  927. struct {
  928. uint8_t led;
  929. } get_rgb;
  930. struct lightbar_params_v0 set_params_v0;
  931. struct lightbar_params_v1 set_params_v1;
  932. };
  933. } __packed;
  934. struct ec_response_lightbar {
  935. union {
  936. struct {
  937. struct {
  938. uint8_t reg;
  939. uint8_t ic0;
  940. uint8_t ic1;
  941. } vals[23];
  942. } dump;
  943. struct {
  944. uint8_t num;
  945. } get_seq, get_brightness, get_demo;
  946. struct lightbar_params_v0 get_params_v0;
  947. struct lightbar_params_v1 get_params_v1;
  948. struct {
  949. uint32_t num;
  950. uint32_t flags;
  951. } version;
  952. struct {
  953. uint8_t red, green, blue;
  954. } get_rgb;
  955. struct {
  956. /* no return params */
  957. } off, on, init, set_brightness, seq, reg, set_rgb,
  958. demo, set_params_v0, set_params_v1;
  959. };
  960. } __packed;
  961. /* Lightbar commands */
  962. enum lightbar_command {
  963. LIGHTBAR_CMD_DUMP = 0,
  964. LIGHTBAR_CMD_OFF = 1,
  965. LIGHTBAR_CMD_ON = 2,
  966. LIGHTBAR_CMD_INIT = 3,
  967. LIGHTBAR_CMD_SET_BRIGHTNESS = 4,
  968. LIGHTBAR_CMD_SEQ = 5,
  969. LIGHTBAR_CMD_REG = 6,
  970. LIGHTBAR_CMD_SET_RGB = 7,
  971. LIGHTBAR_CMD_GET_SEQ = 8,
  972. LIGHTBAR_CMD_DEMO = 9,
  973. LIGHTBAR_CMD_GET_PARAMS_V0 = 10,
  974. LIGHTBAR_CMD_SET_PARAMS_V0 = 11,
  975. LIGHTBAR_CMD_VERSION = 12,
  976. LIGHTBAR_CMD_GET_BRIGHTNESS = 13,
  977. LIGHTBAR_CMD_GET_RGB = 14,
  978. LIGHTBAR_CMD_GET_DEMO = 15,
  979. LIGHTBAR_CMD_GET_PARAMS_V1 = 16,
  980. LIGHTBAR_CMD_SET_PARAMS_V1 = 17,
  981. LIGHTBAR_NUM_CMDS
  982. };
  983. /*****************************************************************************/
  984. /* LED control commands */
  985. #define EC_CMD_LED_CONTROL 0x29
  986. enum ec_led_id {
  987. /* LED to indicate battery state of charge */
  988. EC_LED_ID_BATTERY_LED = 0,
  989. /*
  990. * LED to indicate system power state (on or in suspend).
  991. * May be on power button or on C-panel.
  992. */
  993. EC_LED_ID_POWER_LED,
  994. /* LED on power adapter or its plug */
  995. EC_LED_ID_ADAPTER_LED,
  996. EC_LED_ID_COUNT
  997. };
  998. /* LED control flags */
  999. #define EC_LED_FLAGS_QUERY (1 << 0) /* Query LED capability only */
  1000. #define EC_LED_FLAGS_AUTO (1 << 1) /* Switch LED back to automatic control */
  1001. enum ec_led_colors {
  1002. EC_LED_COLOR_RED = 0,
  1003. EC_LED_COLOR_GREEN,
  1004. EC_LED_COLOR_BLUE,
  1005. EC_LED_COLOR_YELLOW,
  1006. EC_LED_COLOR_WHITE,
  1007. EC_LED_COLOR_COUNT
  1008. };
  1009. struct ec_params_led_control {
  1010. uint8_t led_id; /* Which LED to control */
  1011. uint8_t flags; /* Control flags */
  1012. uint8_t brightness[EC_LED_COLOR_COUNT];
  1013. } __packed;
  1014. struct ec_response_led_control {
  1015. /*
  1016. * Available brightness value range.
  1017. *
  1018. * Range 0 means color channel not present.
  1019. * Range 1 means on/off control.
  1020. * Other values means the LED is control by PWM.
  1021. */
  1022. uint8_t brightness_range[EC_LED_COLOR_COUNT];
  1023. } __packed;
  1024. /*****************************************************************************/
  1025. /* Verified boot commands */
  1026. /*
  1027. * Note: command code 0x29 version 0 was VBOOT_CMD in Link EVT; it may be
  1028. * reused for other purposes with version > 0.
  1029. */
  1030. /* Verified boot hash command */
  1031. #define EC_CMD_VBOOT_HASH 0x2A
  1032. struct ec_params_vboot_hash {
  1033. uint8_t cmd; /* enum ec_vboot_hash_cmd */
  1034. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1035. uint8_t nonce_size; /* Nonce size; may be 0 */
  1036. uint8_t reserved0; /* Reserved; set 0 */
  1037. uint32_t offset; /* Offset in flash to hash */
  1038. uint32_t size; /* Number of bytes to hash */
  1039. uint8_t nonce_data[64]; /* Nonce data; ignored if nonce_size=0 */
  1040. } __packed;
  1041. struct ec_response_vboot_hash {
  1042. uint8_t status; /* enum ec_vboot_hash_status */
  1043. uint8_t hash_type; /* enum ec_vboot_hash_type */
  1044. uint8_t digest_size; /* Size of hash digest in bytes */
  1045. uint8_t reserved0; /* Ignore; will be 0 */
  1046. uint32_t offset; /* Offset in flash which was hashed */
  1047. uint32_t size; /* Number of bytes hashed */
  1048. uint8_t hash_digest[64]; /* Hash digest data */
  1049. } __packed;
  1050. enum ec_vboot_hash_cmd {
  1051. EC_VBOOT_HASH_GET = 0, /* Get current hash status */
  1052. EC_VBOOT_HASH_ABORT = 1, /* Abort calculating current hash */
  1053. EC_VBOOT_HASH_START = 2, /* Start computing a new hash */
  1054. EC_VBOOT_HASH_RECALC = 3, /* Synchronously compute a new hash */
  1055. };
  1056. enum ec_vboot_hash_type {
  1057. EC_VBOOT_HASH_TYPE_SHA256 = 0, /* SHA-256 */
  1058. };
  1059. enum ec_vboot_hash_status {
  1060. EC_VBOOT_HASH_STATUS_NONE = 0, /* No hash (not started, or aborted) */
  1061. EC_VBOOT_HASH_STATUS_DONE = 1, /* Finished computing a hash */
  1062. EC_VBOOT_HASH_STATUS_BUSY = 2, /* Busy computing a hash */
  1063. };
  1064. /*
  1065. * Special values for offset for EC_VBOOT_HASH_START and EC_VBOOT_HASH_RECALC.
  1066. * If one of these is specified, the EC will automatically update offset and
  1067. * size to the correct values for the specified image (RO or RW).
  1068. */
  1069. #define EC_VBOOT_HASH_OFFSET_RO 0xfffffffe
  1070. #define EC_VBOOT_HASH_OFFSET_RW 0xfffffffd
  1071. /*****************************************************************************/
  1072. /*
  1073. * Motion sense commands. We'll make separate structs for sub-commands with
  1074. * different input args, so that we know how much to expect.
  1075. */
  1076. #define EC_CMD_MOTION_SENSE_CMD 0x2B
  1077. /* Motion sense commands */
  1078. enum motionsense_command {
  1079. /*
  1080. * Dump command returns all motion sensor data including motion sense
  1081. * module flags and individual sensor flags.
  1082. */
  1083. MOTIONSENSE_CMD_DUMP = 0,
  1084. /*
  1085. * Info command returns data describing the details of a given sensor,
  1086. * including enum motionsensor_type, enum motionsensor_location, and
  1087. * enum motionsensor_chip.
  1088. */
  1089. MOTIONSENSE_CMD_INFO = 1,
  1090. /*
  1091. * EC Rate command is a setter/getter command for the EC sampling rate
  1092. * of all motion sensors in milliseconds.
  1093. */
  1094. MOTIONSENSE_CMD_EC_RATE = 2,
  1095. /*
  1096. * Sensor ODR command is a setter/getter command for the output data
  1097. * rate of a specific motion sensor in millihertz.
  1098. */
  1099. MOTIONSENSE_CMD_SENSOR_ODR = 3,
  1100. /*
  1101. * Sensor range command is a setter/getter command for the range of
  1102. * a specified motion sensor in +/-G's or +/- deg/s.
  1103. */
  1104. MOTIONSENSE_CMD_SENSOR_RANGE = 4,
  1105. /*
  1106. * Setter/getter command for the keyboard wake angle. When the lid
  1107. * angle is greater than this value, keyboard wake is disabled in S3,
  1108. * and when the lid angle goes less than this value, keyboard wake is
  1109. * enabled. Note, the lid angle measurement is an approximate,
  1110. * un-calibrated value, hence the wake angle isn't exact.
  1111. */
  1112. MOTIONSENSE_CMD_KB_WAKE_ANGLE = 5,
  1113. /* Number of motionsense sub-commands. */
  1114. MOTIONSENSE_NUM_CMDS
  1115. };
  1116. enum motionsensor_id {
  1117. EC_MOTION_SENSOR_ACCEL_BASE = 0,
  1118. EC_MOTION_SENSOR_ACCEL_LID = 1,
  1119. EC_MOTION_SENSOR_GYRO = 2,
  1120. /*
  1121. * Note, if more sensors are added and this count changes, the padding
  1122. * in ec_response_motion_sense dump command must be modified.
  1123. */
  1124. EC_MOTION_SENSOR_COUNT = 3
  1125. };
  1126. /* List of motion sensor types. */
  1127. enum motionsensor_type {
  1128. MOTIONSENSE_TYPE_ACCEL = 0,
  1129. MOTIONSENSE_TYPE_GYRO = 1,
  1130. };
  1131. /* List of motion sensor locations. */
  1132. enum motionsensor_location {
  1133. MOTIONSENSE_LOC_BASE = 0,
  1134. MOTIONSENSE_LOC_LID = 1,
  1135. };
  1136. /* List of motion sensor chips. */
  1137. enum motionsensor_chip {
  1138. MOTIONSENSE_CHIP_KXCJ9 = 0,
  1139. };
  1140. /* Module flag masks used for the dump sub-command. */
  1141. #define MOTIONSENSE_MODULE_FLAG_ACTIVE (1<<0)
  1142. /* Sensor flag masks used for the dump sub-command. */
  1143. #define MOTIONSENSE_SENSOR_FLAG_PRESENT (1<<0)
  1144. /*
  1145. * Send this value for the data element to only perform a read. If you
  1146. * send any other value, the EC will interpret it as data to set and will
  1147. * return the actual value set.
  1148. */
  1149. #define EC_MOTION_SENSE_NO_VALUE -1
  1150. struct ec_params_motion_sense {
  1151. uint8_t cmd;
  1152. union {
  1153. /* Used for MOTIONSENSE_CMD_DUMP. */
  1154. struct {
  1155. /* no args */
  1156. } dump;
  1157. /*
  1158. * Used for MOTIONSENSE_CMD_EC_RATE and
  1159. * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
  1160. */
  1161. struct {
  1162. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
  1163. int16_t data;
  1164. } ec_rate, kb_wake_angle;
  1165. /* Used for MOTIONSENSE_CMD_INFO. */
  1166. struct {
  1167. /* Should be element of enum motionsensor_id. */
  1168. uint8_t sensor_num;
  1169. } info;
  1170. /*
  1171. * Used for MOTIONSENSE_CMD_SENSOR_ODR and
  1172. * MOTIONSENSE_CMD_SENSOR_RANGE.
  1173. */
  1174. struct {
  1175. /* Should be element of enum motionsensor_id. */
  1176. uint8_t sensor_num;
  1177. /* Rounding flag, true for round-up, false for down. */
  1178. uint8_t roundup;
  1179. uint16_t reserved;
  1180. /* Data to set or EC_MOTION_SENSE_NO_VALUE to read. */
  1181. int32_t data;
  1182. } sensor_odr, sensor_range;
  1183. };
  1184. } __packed;
  1185. struct ec_response_motion_sense {
  1186. union {
  1187. /* Used for MOTIONSENSE_CMD_DUMP. */
  1188. struct {
  1189. /* Flags representing the motion sensor module. */
  1190. uint8_t module_flags;
  1191. /* Flags for each sensor in enum motionsensor_id. */
  1192. uint8_t sensor_flags[EC_MOTION_SENSOR_COUNT];
  1193. /* Array of all sensor data. Each sensor is 3-axis. */
  1194. int16_t data[3*EC_MOTION_SENSOR_COUNT];
  1195. } dump;
  1196. /* Used for MOTIONSENSE_CMD_INFO. */
  1197. struct {
  1198. /* Should be element of enum motionsensor_type. */
  1199. uint8_t type;
  1200. /* Should be element of enum motionsensor_location. */
  1201. uint8_t location;
  1202. /* Should be element of enum motionsensor_chip. */
  1203. uint8_t chip;
  1204. } info;
  1205. /*
  1206. * Used for MOTIONSENSE_CMD_EC_RATE, MOTIONSENSE_CMD_SENSOR_ODR,
  1207. * MOTIONSENSE_CMD_SENSOR_RANGE, and
  1208. * MOTIONSENSE_CMD_KB_WAKE_ANGLE.
  1209. */
  1210. struct {
  1211. /* Current value of the parameter queried. */
  1212. int32_t ret;
  1213. } ec_rate, sensor_odr, sensor_range, kb_wake_angle;
  1214. };
  1215. } __packed;
  1216. /*****************************************************************************/
  1217. /* USB charging control commands */
  1218. /* Set USB port charging mode */
  1219. #define EC_CMD_USB_CHARGE_SET_MODE 0x30
  1220. struct ec_params_usb_charge_set_mode {
  1221. uint8_t usb_port_id;
  1222. uint8_t mode;
  1223. } __packed;
  1224. /*****************************************************************************/
  1225. /* Persistent storage for host */
  1226. /* Maximum bytes that can be read/written in a single command */
  1227. #define EC_PSTORE_SIZE_MAX 64
  1228. /* Get persistent storage info */
  1229. #define EC_CMD_PSTORE_INFO 0x40
  1230. struct ec_response_pstore_info {
  1231. /* Persistent storage size, in bytes */
  1232. uint32_t pstore_size;
  1233. /* Access size; read/write offset and size must be a multiple of this */
  1234. uint32_t access_size;
  1235. } __packed;
  1236. /*
  1237. * Read persistent storage
  1238. *
  1239. * Response is params.size bytes of data.
  1240. */
  1241. #define EC_CMD_PSTORE_READ 0x41
  1242. struct ec_params_pstore_read {
  1243. uint32_t offset; /* Byte offset to read */
  1244. uint32_t size; /* Size to read in bytes */
  1245. } __packed;
  1246. /* Write persistent storage */
  1247. #define EC_CMD_PSTORE_WRITE 0x42
  1248. struct ec_params_pstore_write {
  1249. uint32_t offset; /* Byte offset to write */
  1250. uint32_t size; /* Size to write in bytes */
  1251. uint8_t data[EC_PSTORE_SIZE_MAX];
  1252. } __packed;
  1253. /*****************************************************************************/
  1254. /* Real-time clock */
  1255. /* RTC params and response structures */
  1256. struct ec_params_rtc {
  1257. uint32_t time;
  1258. } __packed;
  1259. struct ec_response_rtc {
  1260. uint32_t time;
  1261. } __packed;
  1262. /* These use ec_response_rtc */
  1263. #define EC_CMD_RTC_GET_VALUE 0x44
  1264. #define EC_CMD_RTC_GET_ALARM 0x45
  1265. /* These all use ec_params_rtc */
  1266. #define EC_CMD_RTC_SET_VALUE 0x46
  1267. #define EC_CMD_RTC_SET_ALARM 0x47
  1268. /*****************************************************************************/
  1269. /* Port80 log access */
  1270. /* Maximum entries that can be read/written in a single command */
  1271. #define EC_PORT80_SIZE_MAX 32
  1272. /* Get last port80 code from previous boot */
  1273. #define EC_CMD_PORT80_LAST_BOOT 0x48
  1274. #define EC_CMD_PORT80_READ 0x48
  1275. enum ec_port80_subcmd {
  1276. EC_PORT80_GET_INFO = 0,
  1277. EC_PORT80_READ_BUFFER,
  1278. };
  1279. struct ec_params_port80_read {
  1280. uint16_t subcmd;
  1281. union {
  1282. struct {
  1283. uint32_t offset;
  1284. uint32_t num_entries;
  1285. } read_buffer;
  1286. };
  1287. } __packed;
  1288. struct ec_response_port80_read {
  1289. union {
  1290. struct {
  1291. uint32_t writes;
  1292. uint32_t history_size;
  1293. uint32_t last_boot;
  1294. } get_info;
  1295. struct {
  1296. uint16_t codes[EC_PORT80_SIZE_MAX];
  1297. } data;
  1298. };
  1299. } __packed;
  1300. struct ec_response_port80_last_boot {
  1301. uint16_t code;
  1302. } __packed;
  1303. /*****************************************************************************/
  1304. /* Thermal engine commands. Note that there are two implementations. We'll
  1305. * reuse the command number, but the data and behavior is incompatible.
  1306. * Version 0 is what originally shipped on Link.
  1307. * Version 1 separates the CPU thermal limits from the fan control.
  1308. */
  1309. #define EC_CMD_THERMAL_SET_THRESHOLD 0x50
  1310. #define EC_CMD_THERMAL_GET_THRESHOLD 0x51
  1311. /* The version 0 structs are opaque. You have to know what they are for
  1312. * the get/set commands to make any sense.
  1313. */
  1314. /* Version 0 - set */
  1315. struct ec_params_thermal_set_threshold {
  1316. uint8_t sensor_type;
  1317. uint8_t threshold_id;
  1318. uint16_t value;
  1319. } __packed;
  1320. /* Version 0 - get */
  1321. struct ec_params_thermal_get_threshold {
  1322. uint8_t sensor_type;
  1323. uint8_t threshold_id;
  1324. } __packed;
  1325. struct ec_response_thermal_get_threshold {
  1326. uint16_t value;
  1327. } __packed;
  1328. /* The version 1 structs are visible. */
  1329. enum ec_temp_thresholds {
  1330. EC_TEMP_THRESH_WARN = 0,
  1331. EC_TEMP_THRESH_HIGH,
  1332. EC_TEMP_THRESH_HALT,
  1333. EC_TEMP_THRESH_COUNT
  1334. };
  1335. /* Thermal configuration for one temperature sensor. Temps are in degrees K.
  1336. * Zero values will be silently ignored by the thermal task.
  1337. */
  1338. struct ec_thermal_config {
  1339. uint32_t temp_host[EC_TEMP_THRESH_COUNT]; /* levels of hotness */
  1340. uint32_t temp_fan_off; /* no active cooling needed */
  1341. uint32_t temp_fan_max; /* max active cooling needed */
  1342. } __packed;
  1343. /* Version 1 - get config for one sensor. */
  1344. struct ec_params_thermal_get_threshold_v1 {
  1345. uint32_t sensor_num;
  1346. } __packed;
  1347. /* This returns a struct ec_thermal_config */
  1348. /* Version 1 - set config for one sensor.
  1349. * Use read-modify-write for best results! */
  1350. struct ec_params_thermal_set_threshold_v1 {
  1351. uint32_t sensor_num;
  1352. struct ec_thermal_config cfg;
  1353. } __packed;
  1354. /* This returns no data */
  1355. /****************************************************************************/
  1356. /* Toggle automatic fan control */
  1357. #define EC_CMD_THERMAL_AUTO_FAN_CTRL 0x52
  1358. /* Get TMP006 calibration data */
  1359. #define EC_CMD_TMP006_GET_CALIBRATION 0x53
  1360. struct ec_params_tmp006_get_calibration {
  1361. uint8_t index;
  1362. } __packed;
  1363. struct ec_response_tmp006_get_calibration {
  1364. float s0;
  1365. float b0;
  1366. float b1;
  1367. float b2;
  1368. } __packed;
  1369. /* Set TMP006 calibration data */
  1370. #define EC_CMD_TMP006_SET_CALIBRATION 0x54
  1371. struct ec_params_tmp006_set_calibration {
  1372. uint8_t index;
  1373. uint8_t reserved[3]; /* Reserved; set 0 */
  1374. float s0;
  1375. float b0;
  1376. float b1;
  1377. float b2;
  1378. } __packed;
  1379. /* Read raw TMP006 data */
  1380. #define EC_CMD_TMP006_GET_RAW 0x55
  1381. struct ec_params_tmp006_get_raw {
  1382. uint8_t index;
  1383. } __packed;
  1384. struct ec_response_tmp006_get_raw {
  1385. int32_t t; /* In 1/100 K */
  1386. int32_t v; /* In nV */
  1387. };
  1388. /*****************************************************************************/
  1389. /* MKBP - Matrix KeyBoard Protocol */
  1390. /*
  1391. * Read key state
  1392. *
  1393. * Returns raw data for keyboard cols; see ec_response_mkbp_info.cols for
  1394. * expected response size.
  1395. */
  1396. #define EC_CMD_MKBP_STATE 0x60
  1397. /* Provide information about the matrix : number of rows and columns */
  1398. #define EC_CMD_MKBP_INFO 0x61
  1399. struct ec_response_mkbp_info {
  1400. uint32_t rows;
  1401. uint32_t cols;
  1402. uint8_t switches;
  1403. } __packed;
  1404. /* Simulate key press */
  1405. #define EC_CMD_MKBP_SIMULATE_KEY 0x62
  1406. struct ec_params_mkbp_simulate_key {
  1407. uint8_t col;
  1408. uint8_t row;
  1409. uint8_t pressed;
  1410. } __packed;
  1411. /* Configure keyboard scanning */
  1412. #define EC_CMD_MKBP_SET_CONFIG 0x64
  1413. #define EC_CMD_MKBP_GET_CONFIG 0x65
  1414. /* flags */
  1415. enum mkbp_config_flags {
  1416. EC_MKBP_FLAGS_ENABLE = 1, /* Enable keyboard scanning */
  1417. };
  1418. enum mkbp_config_valid {
  1419. EC_MKBP_VALID_SCAN_PERIOD = 1 << 0,
  1420. EC_MKBP_VALID_POLL_TIMEOUT = 1 << 1,
  1421. EC_MKBP_VALID_MIN_POST_SCAN_DELAY = 1 << 3,
  1422. EC_MKBP_VALID_OUTPUT_SETTLE = 1 << 4,
  1423. EC_MKBP_VALID_DEBOUNCE_DOWN = 1 << 5,
  1424. EC_MKBP_VALID_DEBOUNCE_UP = 1 << 6,
  1425. EC_MKBP_VALID_FIFO_MAX_DEPTH = 1 << 7,
  1426. };
  1427. /* Configuration for our key scanning algorithm */
  1428. struct ec_mkbp_config {
  1429. uint32_t valid_mask; /* valid fields */
  1430. uint8_t flags; /* some flags (enum mkbp_config_flags) */
  1431. uint8_t valid_flags; /* which flags are valid */
  1432. uint16_t scan_period_us; /* period between start of scans */
  1433. /* revert to interrupt mode after no activity for this long */
  1434. uint32_t poll_timeout_us;
  1435. /*
  1436. * minimum post-scan relax time. Once we finish a scan we check
  1437. * the time until we are due to start the next one. If this time is
  1438. * shorter this field, we use this instead.
  1439. */
  1440. uint16_t min_post_scan_delay_us;
  1441. /* delay between setting up output and waiting for it to settle */
  1442. uint16_t output_settle_us;
  1443. uint16_t debounce_down_us; /* time for debounce on key down */
  1444. uint16_t debounce_up_us; /* time for debounce on key up */
  1445. /* maximum depth to allow for fifo (0 = no keyscan output) */
  1446. uint8_t fifo_max_depth;
  1447. } __packed;
  1448. struct ec_params_mkbp_set_config {
  1449. struct ec_mkbp_config config;
  1450. } __packed;
  1451. struct ec_response_mkbp_get_config {
  1452. struct ec_mkbp_config config;
  1453. } __packed;
  1454. /* Run the key scan emulation */
  1455. #define EC_CMD_KEYSCAN_SEQ_CTRL 0x66
  1456. enum ec_keyscan_seq_cmd {
  1457. EC_KEYSCAN_SEQ_STATUS = 0, /* Get status information */
  1458. EC_KEYSCAN_SEQ_CLEAR = 1, /* Clear sequence */
  1459. EC_KEYSCAN_SEQ_ADD = 2, /* Add item to sequence */
  1460. EC_KEYSCAN_SEQ_START = 3, /* Start running sequence */
  1461. EC_KEYSCAN_SEQ_COLLECT = 4, /* Collect sequence summary data */
  1462. };
  1463. enum ec_collect_flags {
  1464. /*
  1465. * Indicates this scan was processed by the EC. Due to timing, some
  1466. * scans may be skipped.
  1467. */
  1468. EC_KEYSCAN_SEQ_FLAG_DONE = 1 << 0,
  1469. };
  1470. struct ec_collect_item {
  1471. uint8_t flags; /* some flags (enum ec_collect_flags) */
  1472. };
  1473. struct ec_params_keyscan_seq_ctrl {
  1474. uint8_t cmd; /* Command to send (enum ec_keyscan_seq_cmd) */
  1475. union {
  1476. struct {
  1477. uint8_t active; /* still active */
  1478. uint8_t num_items; /* number of items */
  1479. /* Current item being presented */
  1480. uint8_t cur_item;
  1481. } status;
  1482. struct {
  1483. /*
  1484. * Absolute time for this scan, measured from the
  1485. * start of the sequence.
  1486. */
  1487. uint32_t time_us;
  1488. uint8_t scan[0]; /* keyscan data */
  1489. } add;
  1490. struct {
  1491. uint8_t start_item; /* First item to return */
  1492. uint8_t num_items; /* Number of items to return */
  1493. } collect;
  1494. };
  1495. } __packed;
  1496. struct ec_result_keyscan_seq_ctrl {
  1497. union {
  1498. struct {
  1499. uint8_t num_items; /* Number of items */
  1500. /* Data for each item */
  1501. struct ec_collect_item item[0];
  1502. } collect;
  1503. };
  1504. } __packed;
  1505. /*****************************************************************************/
  1506. /* Temperature sensor commands */
  1507. /* Read temperature sensor info */
  1508. #define EC_CMD_TEMP_SENSOR_GET_INFO 0x70
  1509. struct ec_params_temp_sensor_get_info {
  1510. uint8_t id;
  1511. } __packed;
  1512. struct ec_response_temp_sensor_get_info {
  1513. char sensor_name[32];
  1514. uint8_t sensor_type;
  1515. } __packed;
  1516. /*****************************************************************************/
  1517. /*
  1518. * Note: host commands 0x80 - 0x87 are reserved to avoid conflict with ACPI
  1519. * commands accidentally sent to the wrong interface. See the ACPI section
  1520. * below.
  1521. */
  1522. /*****************************************************************************/
  1523. /* Host event commands */
  1524. /*
  1525. * Host event mask params and response structures, shared by all of the host
  1526. * event commands below.
  1527. */
  1528. struct ec_params_host_event_mask {
  1529. uint32_t mask;
  1530. } __packed;
  1531. struct ec_response_host_event_mask {
  1532. uint32_t mask;
  1533. } __packed;
  1534. /* These all use ec_response_host_event_mask */
  1535. #define EC_CMD_HOST_EVENT_GET_B 0x87
  1536. #define EC_CMD_HOST_EVENT_GET_SMI_MASK 0x88
  1537. #define EC_CMD_HOST_EVENT_GET_SCI_MASK 0x89
  1538. #define EC_CMD_HOST_EVENT_GET_WAKE_MASK 0x8d
  1539. /* These all use ec_params_host_event_mask */
  1540. #define EC_CMD_HOST_EVENT_SET_SMI_MASK 0x8a
  1541. #define EC_CMD_HOST_EVENT_SET_SCI_MASK 0x8b
  1542. #define EC_CMD_HOST_EVENT_CLEAR 0x8c
  1543. #define EC_CMD_HOST_EVENT_SET_WAKE_MASK 0x8e
  1544. #define EC_CMD_HOST_EVENT_CLEAR_B 0x8f
  1545. /*****************************************************************************/
  1546. /* Switch commands */
  1547. /* Enable/disable LCD backlight */
  1548. #define EC_CMD_SWITCH_ENABLE_BKLIGHT 0x90
  1549. struct ec_params_switch_enable_backlight {
  1550. uint8_t enabled;
  1551. } __packed;
  1552. /* Enable/disable WLAN/Bluetooth */
  1553. #define EC_CMD_SWITCH_ENABLE_WIRELESS 0x91
  1554. #define EC_VER_SWITCH_ENABLE_WIRELESS 1
  1555. /* Version 0 params; no response */
  1556. struct ec_params_switch_enable_wireless_v0 {
  1557. uint8_t enabled;
  1558. } __packed;
  1559. /* Version 1 params */
  1560. struct ec_params_switch_enable_wireless_v1 {
  1561. /* Flags to enable now */
  1562. uint8_t now_flags;
  1563. /* Which flags to copy from now_flags */
  1564. uint8_t now_mask;
  1565. /*
  1566. * Flags to leave enabled in S3, if they're on at the S0->S3
  1567. * transition. (Other flags will be disabled by the S0->S3
  1568. * transition.)
  1569. */
  1570. uint8_t suspend_flags;
  1571. /* Which flags to copy from suspend_flags */
  1572. uint8_t suspend_mask;
  1573. } __packed;
  1574. /* Version 1 response */
  1575. struct ec_response_switch_enable_wireless_v1 {
  1576. /* Flags to enable now */
  1577. uint8_t now_flags;
  1578. /* Flags to leave enabled in S3 */
  1579. uint8_t suspend_flags;
  1580. } __packed;
  1581. /*****************************************************************************/
  1582. /* GPIO commands. Only available on EC if write protect has been disabled. */
  1583. /* Set GPIO output value */
  1584. #define EC_CMD_GPIO_SET 0x92
  1585. struct ec_params_gpio_set {
  1586. char name[32];
  1587. uint8_t val;
  1588. } __packed;
  1589. /* Get GPIO value */
  1590. #define EC_CMD_GPIO_GET 0x93
  1591. /* Version 0 of input params and response */
  1592. struct ec_params_gpio_get {
  1593. char name[32];
  1594. } __packed;
  1595. struct ec_response_gpio_get {
  1596. uint8_t val;
  1597. } __packed;
  1598. /* Version 1 of input params and response */
  1599. struct ec_params_gpio_get_v1 {
  1600. uint8_t subcmd;
  1601. union {
  1602. struct {
  1603. char name[32];
  1604. } get_value_by_name;
  1605. struct {
  1606. uint8_t index;
  1607. } get_info;
  1608. };
  1609. } __packed;
  1610. struct ec_response_gpio_get_v1 {
  1611. union {
  1612. struct {
  1613. uint8_t val;
  1614. } get_value_by_name, get_count;
  1615. struct {
  1616. uint8_t val;
  1617. char name[32];
  1618. uint32_t flags;
  1619. } get_info;
  1620. };
  1621. } __packed;
  1622. enum gpio_get_subcmd {
  1623. EC_GPIO_GET_BY_NAME = 0,
  1624. EC_GPIO_GET_COUNT = 1,
  1625. EC_GPIO_GET_INFO = 2,
  1626. };
  1627. /*****************************************************************************/
  1628. /* I2C commands. Only available when flash write protect is unlocked. */
  1629. /*
  1630. * TODO(crosbug.com/p/23570): These commands are deprecated, and will be
  1631. * removed soon. Use EC_CMD_I2C_XFER instead.
  1632. */
  1633. /* Read I2C bus */
  1634. #define EC_CMD_I2C_READ 0x94
  1635. struct ec_params_i2c_read {
  1636. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  1637. uint8_t read_size; /* Either 8 or 16. */
  1638. uint8_t port;
  1639. uint8_t offset;
  1640. } __packed;
  1641. struct ec_response_i2c_read {
  1642. uint16_t data;
  1643. } __packed;
  1644. /* Write I2C bus */
  1645. #define EC_CMD_I2C_WRITE 0x95
  1646. struct ec_params_i2c_write {
  1647. uint16_t data;
  1648. uint16_t addr; /* 8-bit address (7-bit shifted << 1) */
  1649. uint8_t write_size; /* Either 8 or 16. */
  1650. uint8_t port;
  1651. uint8_t offset;
  1652. } __packed;
  1653. /*****************************************************************************/
  1654. /* Charge state commands. Only available when flash write protect unlocked. */
  1655. /* Force charge state machine to stop charging the battery or force it to
  1656. * discharge the battery.
  1657. */
  1658. #define EC_CMD_CHARGE_CONTROL 0x96
  1659. #define EC_VER_CHARGE_CONTROL 1
  1660. enum ec_charge_control_mode {
  1661. CHARGE_CONTROL_NORMAL = 0,
  1662. CHARGE_CONTROL_IDLE,
  1663. CHARGE_CONTROL_DISCHARGE,
  1664. };
  1665. struct ec_params_charge_control {
  1666. uint32_t mode; /* enum charge_control_mode */
  1667. } __packed;
  1668. /*****************************************************************************/
  1669. /* Console commands. Only available when flash write protect is unlocked. */
  1670. /* Snapshot console output buffer for use by EC_CMD_CONSOLE_READ. */
  1671. #define EC_CMD_CONSOLE_SNAPSHOT 0x97
  1672. /*
  1673. * Read next chunk of data from saved snapshot.
  1674. *
  1675. * Response is null-terminated string. Empty string, if there is no more
  1676. * remaining output.
  1677. */
  1678. #define EC_CMD_CONSOLE_READ 0x98
  1679. /*****************************************************************************/
  1680. /*
  1681. * Cut off battery power immediately or after the host has shut down.
  1682. *
  1683. * return EC_RES_INVALID_COMMAND if unsupported by a board/battery.
  1684. * EC_RES_SUCCESS if the command was successful.
  1685. * EC_RES_ERROR if the cut off command failed.
  1686. */
  1687. #define EC_CMD_BATTERY_CUT_OFF 0x99
  1688. #define EC_BATTERY_CUTOFF_FLAG_AT_SHUTDOWN (1 << 0)
  1689. struct ec_params_battery_cutoff {
  1690. uint8_t flags;
  1691. } __packed;
  1692. /*****************************************************************************/
  1693. /* USB port mux control. */
  1694. /*
  1695. * Switch USB mux or return to automatic switching.
  1696. */
  1697. #define EC_CMD_USB_MUX 0x9a
  1698. struct ec_params_usb_mux {
  1699. uint8_t mux;
  1700. } __packed;
  1701. /*****************************************************************************/
  1702. /* LDOs / FETs control. */
  1703. enum ec_ldo_state {
  1704. EC_LDO_STATE_OFF = 0, /* the LDO / FET is shut down */
  1705. EC_LDO_STATE_ON = 1, /* the LDO / FET is ON / providing power */
  1706. };
  1707. /*
  1708. * Switch on/off a LDO.
  1709. */
  1710. #define EC_CMD_LDO_SET 0x9b
  1711. struct ec_params_ldo_set {
  1712. uint8_t index;
  1713. uint8_t state;
  1714. } __packed;
  1715. /*
  1716. * Get LDO state.
  1717. */
  1718. #define EC_CMD_LDO_GET 0x9c
  1719. struct ec_params_ldo_get {
  1720. uint8_t index;
  1721. } __packed;
  1722. struct ec_response_ldo_get {
  1723. uint8_t state;
  1724. } __packed;
  1725. /*****************************************************************************/
  1726. /* Power info. */
  1727. /*
  1728. * Get power info.
  1729. */
  1730. #define EC_CMD_POWER_INFO 0x9d
  1731. struct ec_response_power_info {
  1732. uint32_t usb_dev_type;
  1733. uint16_t voltage_ac;
  1734. uint16_t voltage_system;
  1735. uint16_t current_system;
  1736. uint16_t usb_current_limit;
  1737. } __packed;
  1738. /*****************************************************************************/
  1739. /* I2C passthru command */
  1740. #define EC_CMD_I2C_PASSTHRU 0x9e
  1741. /* Read data; if not present, message is a write */
  1742. #define EC_I2C_FLAG_READ (1 << 15)
  1743. /* Mask for address */
  1744. #define EC_I2C_ADDR_MASK 0x3ff
  1745. #define EC_I2C_STATUS_NAK (1 << 0) /* Transfer was not acknowledged */
  1746. #define EC_I2C_STATUS_TIMEOUT (1 << 1) /* Timeout during transfer */
  1747. /* Any error */
  1748. #define EC_I2C_STATUS_ERROR (EC_I2C_STATUS_NAK | EC_I2C_STATUS_TIMEOUT)
  1749. struct ec_params_i2c_passthru_msg {
  1750. uint16_t addr_flags; /* I2C slave address (7 or 10 bits) and flags */
  1751. uint16_t len; /* Number of bytes to read or write */
  1752. } __packed;
  1753. struct ec_params_i2c_passthru {
  1754. uint8_t port; /* I2C port number */
  1755. uint8_t num_msgs; /* Number of messages */
  1756. struct ec_params_i2c_passthru_msg msg[];
  1757. /* Data to write for all messages is concatenated here */
  1758. } __packed;
  1759. struct ec_response_i2c_passthru {
  1760. uint8_t i2c_status; /* Status flags (EC_I2C_STATUS_...) */
  1761. uint8_t num_msgs; /* Number of messages processed */
  1762. uint8_t data[]; /* Data read by messages concatenated here */
  1763. } __packed;
  1764. /*****************************************************************************/
  1765. /* Power button hang detect */
  1766. #define EC_CMD_HANG_DETECT 0x9f
  1767. /* Reasons to start hang detection timer */
  1768. /* Power button pressed */
  1769. #define EC_HANG_START_ON_POWER_PRESS (1 << 0)
  1770. /* Lid closed */
  1771. #define EC_HANG_START_ON_LID_CLOSE (1 << 1)
  1772. /* Lid opened */
  1773. #define EC_HANG_START_ON_LID_OPEN (1 << 2)
  1774. /* Start of AP S3->S0 transition (booting or resuming from suspend) */
  1775. #define EC_HANG_START_ON_RESUME (1 << 3)
  1776. /* Reasons to cancel hang detection */
  1777. /* Power button released */
  1778. #define EC_HANG_STOP_ON_POWER_RELEASE (1 << 8)
  1779. /* Any host command from AP received */
  1780. #define EC_HANG_STOP_ON_HOST_COMMAND (1 << 9)
  1781. /* Stop on end of AP S0->S3 transition (suspending or shutting down) */
  1782. #define EC_HANG_STOP_ON_SUSPEND (1 << 10)
  1783. /*
  1784. * If this flag is set, all the other fields are ignored, and the hang detect
  1785. * timer is started. This provides the AP a way to start the hang timer
  1786. * without reconfiguring any of the other hang detect settings. Note that
  1787. * you must previously have configured the timeouts.
  1788. */
  1789. #define EC_HANG_START_NOW (1 << 30)
  1790. /*
  1791. * If this flag is set, all the other fields are ignored (including
  1792. * EC_HANG_START_NOW). This provides the AP a way to stop the hang timer
  1793. * without reconfiguring any of the other hang detect settings.
  1794. */
  1795. #define EC_HANG_STOP_NOW (1 << 31)
  1796. struct ec_params_hang_detect {
  1797. /* Flags; see EC_HANG_* */
  1798. uint32_t flags;
  1799. /* Timeout in msec before generating host event, if enabled */
  1800. uint16_t host_event_timeout_msec;
  1801. /* Timeout in msec before generating warm reboot, if enabled */
  1802. uint16_t warm_reboot_timeout_msec;
  1803. } __packed;
  1804. /*****************************************************************************/
  1805. /* Commands for battery charging */
  1806. /*
  1807. * This is the single catch-all host command to exchange data regarding the
  1808. * charge state machine (v2 and up).
  1809. */
  1810. #define EC_CMD_CHARGE_STATE 0xa0
  1811. /* Subcommands for this host command */
  1812. enum charge_state_command {
  1813. CHARGE_STATE_CMD_GET_STATE,
  1814. CHARGE_STATE_CMD_GET_PARAM,
  1815. CHARGE_STATE_CMD_SET_PARAM,
  1816. CHARGE_STATE_NUM_CMDS
  1817. };
  1818. /*
  1819. * Known param numbers are defined here. Ranges are reserved for board-specific
  1820. * params, which are handled by the particular implementations.
  1821. */
  1822. enum charge_state_params {
  1823. CS_PARAM_CHG_VOLTAGE, /* charger voltage limit */
  1824. CS_PARAM_CHG_CURRENT, /* charger current limit */
  1825. CS_PARAM_CHG_INPUT_CURRENT, /* charger input current limit */
  1826. CS_PARAM_CHG_STATUS, /* charger-specific status */
  1827. CS_PARAM_CHG_OPTION, /* charger-specific options */
  1828. /* How many so far? */
  1829. CS_NUM_BASE_PARAMS,
  1830. /* Range for CONFIG_CHARGER_PROFILE_OVERRIDE params */
  1831. CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000,
  1832. CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff,
  1833. /* Other custom param ranges go here... */
  1834. };
  1835. struct ec_params_charge_state {
  1836. uint8_t cmd; /* enum charge_state_command */
  1837. union {
  1838. struct {
  1839. /* no args */
  1840. } get_state;
  1841. struct {
  1842. uint32_t param; /* enum charge_state_param */
  1843. } get_param;
  1844. struct {
  1845. uint32_t param; /* param to set */
  1846. uint32_t value; /* value to set */
  1847. } set_param;
  1848. };
  1849. } __packed;
  1850. struct ec_response_charge_state {
  1851. union {
  1852. struct {
  1853. int ac;
  1854. int chg_voltage;
  1855. int chg_current;
  1856. int chg_input_current;
  1857. int batt_state_of_charge;
  1858. } get_state;
  1859. struct {
  1860. uint32_t value;
  1861. } get_param;
  1862. struct {
  1863. /* no return values */
  1864. } set_param;
  1865. };
  1866. } __packed;
  1867. /*
  1868. * Set maximum battery charging current.
  1869. */
  1870. #define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
  1871. struct ec_params_current_limit {
  1872. uint32_t limit; /* in mA */
  1873. } __packed;
  1874. /*
  1875. * Set maximum external power current.
  1876. */
  1877. #define EC_CMD_EXT_POWER_CURRENT_LIMIT 0xa2
  1878. struct ec_params_ext_power_current_limit {
  1879. uint32_t limit; /* in mA */
  1880. } __packed;
  1881. /*****************************************************************************/
  1882. /* Smart battery pass-through */
  1883. /* Get / Set 16-bit smart battery registers */
  1884. #define EC_CMD_SB_READ_WORD 0xb0
  1885. #define EC_CMD_SB_WRITE_WORD 0xb1
  1886. /* Get / Set string smart battery parameters
  1887. * formatted as SMBUS "block".
  1888. */
  1889. #define EC_CMD_SB_READ_BLOCK 0xb2
  1890. #define EC_CMD_SB_WRITE_BLOCK 0xb3
  1891. struct ec_params_sb_rd {
  1892. uint8_t reg;
  1893. } __packed;
  1894. struct ec_response_sb_rd_word {
  1895. uint16_t value;
  1896. } __packed;
  1897. struct ec_params_sb_wr_word {
  1898. uint8_t reg;
  1899. uint16_t value;
  1900. } __packed;
  1901. struct ec_response_sb_rd_block {
  1902. uint8_t data[32];
  1903. } __packed;
  1904. struct ec_params_sb_wr_block {
  1905. uint8_t reg;
  1906. uint16_t data[32];
  1907. } __packed;
  1908. /*****************************************************************************/
  1909. /* Battery vendor parameters
  1910. *
  1911. * Get or set vendor-specific parameters in the battery. Implementations may
  1912. * differ between boards or batteries. On a set operation, the response
  1913. * contains the actual value set, which may be rounded or clipped from the
  1914. * requested value.
  1915. */
  1916. #define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
  1917. enum ec_battery_vendor_param_mode {
  1918. BATTERY_VENDOR_PARAM_MODE_GET = 0,
  1919. BATTERY_VENDOR_PARAM_MODE_SET,
  1920. };
  1921. struct ec_params_battery_vendor_param {
  1922. uint32_t param;
  1923. uint32_t value;
  1924. uint8_t mode;
  1925. } __packed;
  1926. struct ec_response_battery_vendor_param {
  1927. uint32_t value;
  1928. } __packed;
  1929. /*****************************************************************************/
  1930. /* System commands */
  1931. /*
  1932. * TODO(crosbug.com/p/23747): This is a confusing name, since it doesn't
  1933. * necessarily reboot the EC. Rename to "image" or something similar?
  1934. */
  1935. #define EC_CMD_REBOOT_EC 0xd2
  1936. /* Command */
  1937. enum ec_reboot_cmd {
  1938. EC_REBOOT_CANCEL = 0, /* Cancel a pending reboot */
  1939. EC_REBOOT_JUMP_RO = 1, /* Jump to RO without rebooting */
  1940. EC_REBOOT_JUMP_RW = 2, /* Jump to RW without rebooting */
  1941. /* (command 3 was jump to RW-B) */
  1942. EC_REBOOT_COLD = 4, /* Cold-reboot */
  1943. EC_REBOOT_DISABLE_JUMP = 5, /* Disable jump until next reboot */
  1944. EC_REBOOT_HIBERNATE = 6 /* Hibernate EC */
  1945. };
  1946. /* Flags for ec_params_reboot_ec.reboot_flags */
  1947. #define EC_REBOOT_FLAG_RESERVED0 (1 << 0) /* Was recovery request */
  1948. #define EC_REBOOT_FLAG_ON_AP_SHUTDOWN (1 << 1) /* Reboot after AP shutdown */
  1949. struct ec_params_reboot_ec {
  1950. uint8_t cmd; /* enum ec_reboot_cmd */
  1951. uint8_t flags; /* See EC_REBOOT_FLAG_* */
  1952. } __packed;
  1953. /*
  1954. * Get information on last EC panic.
  1955. *
  1956. * Returns variable-length platform-dependent panic information. See panic.h
  1957. * for details.
  1958. */
  1959. #define EC_CMD_GET_PANIC_INFO 0xd3
  1960. /*****************************************************************************/
  1961. /*
  1962. * ACPI commands
  1963. *
  1964. * These are valid ONLY on the ACPI command/data port.
  1965. */
  1966. /*
  1967. * ACPI Read Embedded Controller
  1968. *
  1969. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  1970. *
  1971. * Use the following sequence:
  1972. *
  1973. * - Write EC_CMD_ACPI_READ to EC_LPC_ADDR_ACPI_CMD
  1974. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  1975. * - Write address to EC_LPC_ADDR_ACPI_DATA
  1976. * - Wait for EC_LPC_CMDR_DATA bit to set
  1977. * - Read value from EC_LPC_ADDR_ACPI_DATA
  1978. */
  1979. #define EC_CMD_ACPI_READ 0x80
  1980. /*
  1981. * ACPI Write Embedded Controller
  1982. *
  1983. * This reads from ACPI memory space on the EC (EC_ACPI_MEM_*).
  1984. *
  1985. * Use the following sequence:
  1986. *
  1987. * - Write EC_CMD_ACPI_WRITE to EC_LPC_ADDR_ACPI_CMD
  1988. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  1989. * - Write address to EC_LPC_ADDR_ACPI_DATA
  1990. * - Wait for EC_LPC_CMDR_PENDING bit to clear
  1991. * - Write value to EC_LPC_ADDR_ACPI_DATA
  1992. */
  1993. #define EC_CMD_ACPI_WRITE 0x81
  1994. /*
  1995. * ACPI Query Embedded Controller
  1996. *
  1997. * This clears the lowest-order bit in the currently pending host events, and
  1998. * sets the result code to the 1-based index of the bit (event 0x00000001 = 1,
  1999. * event 0x80000000 = 32), or 0 if no event was pending.
  2000. */
  2001. #define EC_CMD_ACPI_QUERY_EVENT 0x84
  2002. /* Valid addresses in ACPI memory space, for read/write commands */
  2003. /* Memory space version; set to EC_ACPI_MEM_VERSION_CURRENT */
  2004. #define EC_ACPI_MEM_VERSION 0x00
  2005. /*
  2006. * Test location; writing value here updates test compliment byte to (0xff -
  2007. * value).
  2008. */
  2009. #define EC_ACPI_MEM_TEST 0x01
  2010. /* Test compliment; writes here are ignored. */
  2011. #define EC_ACPI_MEM_TEST_COMPLIMENT 0x02
  2012. /* Keyboard backlight brightness percent (0 - 100) */
  2013. #define EC_ACPI_MEM_KEYBOARD_BACKLIGHT 0x03
  2014. /* DPTF Target Fan Duty (0-100, 0xff for auto/none) */
  2015. #define EC_ACPI_MEM_FAN_DUTY 0x04
  2016. /*
  2017. * DPTF temp thresholds. Any of the EC's temp sensors can have up to two
  2018. * independent thresholds attached to them. The current value of the ID
  2019. * register determines which sensor is affected by the THRESHOLD and COMMIT
  2020. * registers. The THRESHOLD register uses the same EC_TEMP_SENSOR_OFFSET scheme
  2021. * as the memory-mapped sensors. The COMMIT register applies those settings.
  2022. *
  2023. * The spec does not mandate any way to read back the threshold settings
  2024. * themselves, but when a threshold is crossed the AP needs a way to determine
  2025. * which sensor(s) are responsible. Each reading of the ID register clears and
  2026. * returns one sensor ID that has crossed one of its threshold (in either
  2027. * direction) since the last read. A value of 0xFF means "no new thresholds
  2028. * have tripped". Setting or enabling the thresholds for a sensor will clear
  2029. * the unread event count for that sensor.
  2030. */
  2031. #define EC_ACPI_MEM_TEMP_ID 0x05
  2032. #define EC_ACPI_MEM_TEMP_THRESHOLD 0x06
  2033. #define EC_ACPI_MEM_TEMP_COMMIT 0x07
  2034. /*
  2035. * Here are the bits for the COMMIT register:
  2036. * bit 0 selects the threshold index for the chosen sensor (0/1)
  2037. * bit 1 enables/disables the selected threshold (0 = off, 1 = on)
  2038. * Each write to the commit register affects one threshold.
  2039. */
  2040. #define EC_ACPI_MEM_TEMP_COMMIT_SELECT_MASK (1 << 0)
  2041. #define EC_ACPI_MEM_TEMP_COMMIT_ENABLE_MASK (1 << 1)
  2042. /*
  2043. * Example:
  2044. *
  2045. * Set the thresholds for sensor 2 to 50 C and 60 C:
  2046. * write 2 to [0x05] -- select temp sensor 2
  2047. * write 0x7b to [0x06] -- C_TO_K(50) - EC_TEMP_SENSOR_OFFSET
  2048. * write 0x2 to [0x07] -- enable threshold 0 with this value
  2049. * write 0x85 to [0x06] -- C_TO_K(60) - EC_TEMP_SENSOR_OFFSET
  2050. * write 0x3 to [0x07] -- enable threshold 1 with this value
  2051. *
  2052. * Disable the 60 C threshold, leaving the 50 C threshold unchanged:
  2053. * write 2 to [0x05] -- select temp sensor 2
  2054. * write 0x1 to [0x07] -- disable threshold 1
  2055. */
  2056. /* DPTF battery charging current limit */
  2057. #define EC_ACPI_MEM_CHARGING_LIMIT 0x08
  2058. /* Charging limit is specified in 64 mA steps */
  2059. #define EC_ACPI_MEM_CHARGING_LIMIT_STEP_MA 64
  2060. /* Value to disable DPTF battery charging limit */
  2061. #define EC_ACPI_MEM_CHARGING_LIMIT_DISABLED 0xff
  2062. /* Current version of ACPI memory address space */
  2063. #define EC_ACPI_MEM_VERSION_CURRENT 1
  2064. /*****************************************************************************/
  2065. /*
  2066. * Special commands
  2067. *
  2068. * These do not follow the normal rules for commands. See each command for
  2069. * details.
  2070. */
  2071. /*
  2072. * Reboot NOW
  2073. *
  2074. * This command will work even when the EC LPC interface is busy, because the
  2075. * reboot command is processed at interrupt level. Note that when the EC
  2076. * reboots, the host will reboot too, so there is no response to this command.
  2077. *
  2078. * Use EC_CMD_REBOOT_EC to reboot the EC more politely.
  2079. */
  2080. #define EC_CMD_REBOOT 0xd1 /* Think "die" */
  2081. /*
  2082. * Resend last response (not supported on LPC).
  2083. *
  2084. * Returns EC_RES_UNAVAILABLE if there is no response available - for example,
  2085. * there was no previous command, or the previous command's response was too
  2086. * big to save.
  2087. */
  2088. #define EC_CMD_RESEND_RESPONSE 0xdb
  2089. /*
  2090. * This header byte on a command indicate version 0. Any header byte less
  2091. * than this means that we are talking to an old EC which doesn't support
  2092. * versioning. In that case, we assume version 0.
  2093. *
  2094. * Header bytes greater than this indicate a later version. For example,
  2095. * EC_CMD_VERSION0 + 1 means we are using version 1.
  2096. *
  2097. * The old EC interface must not use commands 0xdc or higher.
  2098. */
  2099. #define EC_CMD_VERSION0 0xdc
  2100. #endif /* !__ACPI__ */
  2101. /*****************************************************************************/
  2102. /*
  2103. * PD commands
  2104. *
  2105. * These commands are for PD MCU communication.
  2106. */
  2107. /* EC to PD MCU exchange status command */
  2108. #define EC_CMD_PD_EXCHANGE_STATUS 0x100
  2109. /* Status of EC being sent to PD */
  2110. struct ec_params_pd_status {
  2111. int8_t batt_soc; /* battery state of charge */
  2112. } __packed;
  2113. /* Status of PD being sent back to EC */
  2114. struct ec_response_pd_status {
  2115. int8_t status; /* PD MCU status */
  2116. uint32_t curr_lim_ma; /* input current limit */
  2117. } __packed;
  2118. /* Set USB type-C port role and muxes */
  2119. #define EC_CMD_USB_PD_CONTROL 0x101
  2120. enum usb_pd_control_role {
  2121. USB_PD_CTRL_ROLE_NO_CHANGE = 0,
  2122. USB_PD_CTRL_ROLE_TOGGLE_ON = 1, /* == AUTO */
  2123. USB_PD_CTRL_ROLE_TOGGLE_OFF = 2,
  2124. USB_PD_CTRL_ROLE_FORCE_SINK = 3,
  2125. USB_PD_CTRL_ROLE_FORCE_SOURCE = 4,
  2126. };
  2127. enum usb_pd_control_mux {
  2128. USB_PD_CTRL_MUX_NO_CHANGE = 0,
  2129. USB_PD_CTRL_MUX_NONE = 1,
  2130. USB_PD_CTRL_MUX_USB = 2,
  2131. USB_PD_CTRL_MUX_DP = 3,
  2132. USB_PD_CTRL_MUX_DOCK = 4,
  2133. USB_PD_CTRL_MUX_AUTO = 5,
  2134. };
  2135. struct ec_params_usb_pd_control {
  2136. uint8_t port;
  2137. uint8_t role;
  2138. uint8_t mux;
  2139. } __packed;
  2140. /*****************************************************************************/
  2141. /*
  2142. * Passthru commands
  2143. *
  2144. * Some platforms have sub-processors chained to each other. For example.
  2145. *
  2146. * AP <--> EC <--> PD MCU
  2147. *
  2148. * The top 2 bits of the command number are used to indicate which device the
  2149. * command is intended for. Device 0 is always the device receiving the
  2150. * command; other device mapping is board-specific.
  2151. *
  2152. * When a device receives a command to be passed to a sub-processor, it passes
  2153. * it on with the device number set back to 0. This allows the sub-processor
  2154. * to remain blissfully unaware of whether the command originated on the next
  2155. * device up the chain, or was passed through from the AP.
  2156. *
  2157. * In the above example, if the AP wants to send command 0x0002 to the PD MCU,
  2158. * AP sends command 0x4002 to the EC
  2159. * EC sends command 0x0002 to the PD MCU
  2160. * EC forwards PD MCU response back to the AP
  2161. */
  2162. /* Offset and max command number for sub-device n */
  2163. #define EC_CMD_PASSTHRU_OFFSET(n) (0x4000 * (n))
  2164. #define EC_CMD_PASSTHRU_MAX(n) (EC_CMD_PASSTHRU_OFFSET(n) + 0x3fff)
  2165. /*****************************************************************************/
  2166. /*
  2167. * Deprecated constants. These constants have been renamed for clarity. The
  2168. * meaning and size has not changed. Programs that use the old names should
  2169. * switch to the new names soon, as the old names may not be carried forward
  2170. * forever.
  2171. */
  2172. #define EC_HOST_PARAM_SIZE EC_PROTO2_MAX_PARAM_SIZE
  2173. #define EC_LPC_ADDR_OLD_PARAM EC_HOST_CMD_REGION1
  2174. #define EC_OLD_PARAM_SIZE EC_HOST_CMD_REGION_SIZE
  2175. #endif /* __CROS_EC_COMMANDS_H */