ec.asl 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /** @file
  2. Copyright (c) 2021, Baruch Binyamin Doron
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. **/
  5. /* Global TODO: (externally: Optimus GC6 and GPS)
  6. * - TRPS: This is SMI 0xDD, likely in SmmOemDriver. This SW SMI adds to and executes
  7. * a table of function pointers produced throughout the OEM 'value-add' stack.
  8. * - WMI: This is likely SMI 0xD0 in A01WMISmmCallback. This SW SMI likely uses the WMI
  9. * object and consumes the OEM 'value-add' stack for EC and presumably the A01*
  10. * OEM/ODM 'value-add' stack.
  11. *
  12. * Generally, more reversing is needed.
  13. */
  14. /* TODO: Implement more features around reference code (except, check BoardAcpiDxe first) */
  15. // TODO: Enable and test
  16. #undef LGMR_ENABLED
  17. // "DIDX" - "DeviceIdX" is uninitialised, cannot use "BRTN" method yet
  18. External (\_SB.PCI0.GFX0.DD1F, DeviceObj)
  19. // TODO: Might need fixed VBT - didn't port display toggle tables previously
  20. External (\_SB.PCI0.GFX0.GHDS, MethodObj)
  21. External (\_SB.PCI0.LPCB, DeviceObj)
  22. Device (\_SB.PCI0.LPCB.EC0)
  23. {
  24. Name (_HID, EisaId ("PNP0C09") /* Embedded Controller Device */) // _HID: Hardware ID
  25. Name (_GPE, 0x50) // _GPE: General Purpose Events
  26. Name (\ECOK, 0)
  27. #ifdef LGMR_ENABLED
  28. Name (LGMR, 0xFE800000) // Static, may depend on EC configuration. Unsure which register.
  29. #endif
  30. Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
  31. {
  32. IO (Decode16, 0x62, 0x62, 0, 1)
  33. IO (Decode16, 0x66, 0x66, 0, 1)
  34. })
  35. OperationRegion (ECO1, SystemIO, 0x62, 1)
  36. Field (ECO1, ByteAcc, Lock, Preserve)
  37. {
  38. PX62, 8
  39. }
  40. OperationRegion (ECO2, SystemIO, 0x66, 1)
  41. Field (ECO2, ByteAcc, Lock, Preserve)
  42. {
  43. PX66, 8
  44. }
  45. #ifdef LGMR_ENABLED
  46. OperationRegion (ECMB, SystemMemory, LGMR, 0x200)
  47. #endif
  48. OperationRegion (RAM, EmbeddedControl, 0, 0xFF)
  49. Field (RAM, ByteAcc, Lock, Preserve)
  50. {
  51. CMDB, 8, /* EC commands */
  52. ETID, 8, /* Thermal page selector */
  53. EBID, 8, /* Battery page selector */
  54. Offset (0x06),
  55. CMD2, 8, /* param 2: UNUSED */
  56. CMD1, 8, /* param 1: UNUSED */
  57. CMD0, 8, /* param 0 to EC command */
  58. Offset (0x0A),
  59. , 1,
  60. , 1,
  61. Offset (0x10),
  62. EQEN, 1, /* EQ enable */
  63. ETEE, 1, /* TODO */
  64. Offset (0x4E),
  65. ISEN, 1, /* TODO */
  66. Offset (0x4F),
  67. ECTP, 8, /* Touchpad ID */
  68. Offset (0x51),
  69. , 3,
  70. TPEN, 1, /* Touchpad enable */
  71. Offset (0x52),
  72. WLEX, 1, /* WLAN present */
  73. BTEX, 1, /* Bluetooth present */
  74. EX3G, 1, /* 3G */
  75. , 3,
  76. RFEX, 1, /* RF present */
  77. #if 0 // Merely a guess
  78. Offset (0x55),
  79. BTH0, 8, /* Battery threshold? TODO: Actually diff in modified vendor FW */
  80. #endif
  81. Offset (0x57),
  82. , 7,
  83. AHKB, 1, /* Hotkey triggered */
  84. AHKE, 8, /* Hotkey data */
  85. Offset (0x5C),
  86. Offset (0x5D),
  87. Offset (0x6C),
  88. PWLT, 1, /* NVIDIA GPS: Panel? */
  89. , 3,
  90. GCON, 1, /* Enter Optimus GC6 */
  91. Offset (0x70),
  92. , 1,
  93. ELID, 1, /* Lid state */
  94. , 3,
  95. EACS, 1, /* AC state */
  96. Offset (0x71),
  97. WLEN, 1, /* WLAN enable */
  98. BTEN, 1, /* Bluetooth enable */
  99. , 3,
  100. ISS3, 1,
  101. ISS4, 1,
  102. ISS5, 1,
  103. , 4,
  104. EIDW, 1, /* Device wake */
  105. Offset (0x74),
  106. , 2,
  107. , 1,
  108. TPEX, 1, /* Touchpad present */
  109. Offset (0x75),
  110. BLST, 1, /* Bluetooth state */
  111. LMIB, 1, /* TODO */
  112. Offset (0x76),
  113. ECSS, 4, /* EC Notify of power state */
  114. EOSS, 4, /* EC Notify of power state */
  115. Offset (0x88), /* TODO: Aliased to "EB0S" */
  116. EB0A, 1,
  117. , 2,
  118. EB0R, 1,
  119. EB0L, 1,
  120. EB0F, 1,
  121. EB0N, 1,
  122. Offset (0x90),
  123. SCPM, 1, /* Set cooling policy */
  124. Offset (0x92), /* TODO: Aliased to "ETAF" */
  125. ESSF, 1,
  126. ECTT, 1,
  127. EDTT, 1,
  128. EOSD, 1, /* Trip */
  129. EVTP, 1,
  130. ECP1, 1,
  131. , 1,
  132. ECP2, 1,
  133. Offset (0xA8),
  134. ES0T, 8, /* Temperature */
  135. ES1T, 8, /* Temperature */
  136. Offset (0xD0),
  137. ESP0, 8, /* Passive temp */
  138. ESC0, 8, /* Critical temp */
  139. ESP1, 8, /* Passive temp */
  140. ESC1, 8, /* Critical temp */
  141. }
  142. /* Aliases several battery registers */
  143. Field (RAM, ByteAcc, Lock, Preserve)
  144. {
  145. Offset (0x88),
  146. EB0S, 8, /* Battery 0 state */
  147. }
  148. /* Aliases several thermal registers */
  149. Field (RAM, ByteAcc, Lock, Preserve)
  150. {
  151. Offset (0x92),
  152. ETAF, 8,
  153. }
  154. #ifdef LGMR_ENABLED
  155. Field (ECMB, ByteAcc, Lock, Preserve)
  156. {
  157. Offset (0x02),
  158. , 1,
  159. MLID, 1,
  160. , 3,
  161. MACS, 1,
  162. Offset (0x06),
  163. MBTP, 8,
  164. Offset (0x08),
  165. MB0S, 8,
  166. Offset (0x20),
  167. MS0T, 8,
  168. MS1T, 8,
  169. MS2T, 8,
  170. MS3T, 8,
  171. MS4T, 8,
  172. MS5T, 8,
  173. Offset (0x53),
  174. MCSS, 1,
  175. MCTT, 1,
  176. MDTT, 1,
  177. MOSD, 1,
  178. MVTP, 1,
  179. Offset (0x54),
  180. MSP0, 8,
  181. MSC0, 8,
  182. MCC0, 8,
  183. MSC1, 8,
  184. }
  185. #endif
  186. Method (_REG, 2, NotSerialized) // _REG: Region Availability
  187. {
  188. If (Arg0 == 3)
  189. {
  190. ECOK = Arg1 // OS can clear region availability
  191. If (Arg1 == 1) // On initialise
  192. {
  193. TINI ()
  194. EOSS = 0x05
  195. // OSIN ()
  196. /* Other pages return valid data too, but this seems to be the page
  197. * we are expecting - persistently in ectool dump with vendor firmware
  198. * FIXME: Contents of other pages? */
  199. ETID = 0x20
  200. }
  201. }
  202. }
  203. Method (TINI, 0, NotSerialized)
  204. {
  205. If (ECOK)
  206. {
  207. ETAF = 0
  208. ETEE = 1
  209. }
  210. Else
  211. {
  212. /* WBEC: Called SMI function 0x11 */
  213. // EC_WRITE (0x92, 0) // ETAF = 0
  214. /* MBEC: Called SMI function 0x12 */
  215. // MBEC (0x10, 0xFD, 0x02) // ETEE = 1
  216. }
  217. }
  218. Name (RFST, 0) /* RF state */
  219. Method (ECPS, 1, NotSerialized) // _PTS: Prepare To Sleep
  220. {
  221. ECSS = Arg0
  222. // COSI = OSYS
  223. // SPR1 = Arg0
  224. /* TRPS: Generic SMI trap handler */
  225. // TRPS (0x82, 0x02)
  226. If ((Arg0 == 3) || (Arg0 == 4))
  227. {
  228. RFST = RFEX
  229. }
  230. }
  231. Method (ECWK, 1, NotSerialized) // _WAK: Wake
  232. {
  233. EQEN = 1
  234. EOSS = Arg0
  235. TINI ()
  236. Notify (BAT0, 0x81) // Information Change
  237. // COSI = OSYS
  238. // SPR1 = Arg0
  239. /* TRPS: Generic SMI trap handler */
  240. // TRPS (0x82, 0x03)
  241. If ((Arg0 == 3) || (Arg0 == 4))
  242. {
  243. RFEX = RFST
  244. Notify (SLPB, 0x02) // Device Wake
  245. }
  246. }
  247. #if 0 // TODO: Figure out what this is for
  248. Method (OSIN, 0, NotSerialized)
  249. {
  250. COSI = OSYS
  251. /* TRPS: Generic SMI trap handler */
  252. TRPS (0x82, 1)
  253. }
  254. #endif
  255. #if 0 // TODO: Implement
  256. Method (MBEC, 3, Serialized) // Read-Modify-Write
  257. {
  258. /* Based on similar methods/tables at
  259. * https://github.com/linuxhw/ACPI/blob/master/Notebook/Sony/SVE1713/SVE1713S1RW/506CDC50E671#L9359
  260. * which use ASL instead of SMM calls */
  261. Local0 = EC_READ (Arg0)
  262. Local0 &= Arg1
  263. Local0 |= Arg2
  264. EC_WRITE (Arg0, Local0)
  265. }
  266. #endif
  267. /* Graphical hotkey */
  268. Method (_Q19, 0, NotSerialized)
  269. {
  270. ^^^GFX0.GHDS (0x03)
  271. }
  272. /* Increase brightness */
  273. Method (_Q1C, 0, NotSerialized)
  274. {
  275. Notify (^^^GFX0.DD1F, 0x86)
  276. }
  277. /* Decrease brightness */
  278. Method (_Q1D, 0, NotSerialized)
  279. {
  280. Notify (^^^GFX0.DD1F, 0x87)
  281. }
  282. /* Hotkeys */
  283. Method (_Q2C, 0, NotSerialized)
  284. {
  285. If (LMIB)
  286. {
  287. If (!AHKB) /* Else, WMI clears its buffer? */
  288. {
  289. Local1 = AHKE
  290. If ((Local1 > 0) && (Local1 < 0x80))
  291. {
  292. \DBGH ("Hotkeys - TODO: Airplane mode?")
  293. /* WMI -> "GCMS" method */
  294. }
  295. ElseIf ((Local1 > 0x80) && (Local1 < 0xA0))
  296. {
  297. TPEN ^= 1 /* TODO: Not working. What else does WMI do here? */
  298. }
  299. }
  300. }
  301. }
  302. Method (_Q36, 0, NotSerialized)
  303. {
  304. If (ECOK)
  305. {
  306. EOSD = 1 // Thermal trip
  307. }
  308. Else
  309. {
  310. /* MBEC: Called SMI function 0x12 */
  311. // MBEC (0x92, 0xF7, 0x08) // EOSD = 1
  312. }
  313. Sleep (500)
  314. Notify (\_TZ.TZ01, 0x80) // Thermal Status Change
  315. Notify (\_TZ.TZ00, 0x80) // Thermal Status Change
  316. }
  317. Method (_Q3F, 0, NotSerialized)
  318. {
  319. \DBGH ("EC Query: 0x3F - TRPS")
  320. /* TRPS: Generic SMI trap handler */
  321. // TRPS (0x80, 0)
  322. }
  323. Method (_Q40, 0, NotSerialized)
  324. {
  325. Notify (BAT0, 0x81) // Information Change
  326. }
  327. Method (_Q41, 0, NotSerialized)
  328. {
  329. Notify (BAT0, 0x81) // Information Change
  330. }
  331. /* Battery status change */
  332. Method (_Q48, 0, NotSerialized)
  333. {
  334. Notify (BAT0, 0x80)
  335. }
  336. /* Battery critical? */
  337. Method (_Q4C, 0, NotSerialized)
  338. {
  339. If (B0ST)
  340. {
  341. Notify (BAT0, 0x80) // Status Change
  342. }
  343. }
  344. /* AC status change: present */
  345. Method (_Q50, 0, NotSerialized)
  346. {
  347. Notify (ADP1, 0x80)
  348. }
  349. /* AC status change: not present */
  350. Method (_Q51, 0, NotSerialized)
  351. {
  352. Notify (ADP1, 0x80)
  353. }
  354. /* Lid status change: open */
  355. Method (_Q52, 0, NotSerialized)
  356. {
  357. Notify (LID0, 0x80)
  358. }
  359. /* Lid status change: close */
  360. Method (_Q53, 0, NotSerialized)
  361. {
  362. Notify (LID0, 0x80)
  363. }
  364. Method (_Q60, 0, NotSerialized)
  365. {
  366. \DBGH ("EC Query: 0x60 -> WMI")
  367. }
  368. Method (_Q61, 0, NotSerialized)
  369. {
  370. \DBGH ("EC Query: 0x61 -> WMI")
  371. }
  372. Method (_Q62, 0, NotSerialized)
  373. {
  374. \DBGH ("EC Query: 0x62 -> Optimus GC6")
  375. }
  376. Method (_Q63, 0, NotSerialized)
  377. {
  378. \DBGH ("EC Query: 0x63 -> Optimus GC6")
  379. }
  380. Method (_Q67, 0, NotSerialized)
  381. {
  382. \DBGH ("EC Query: 0x67 -> NVIDIA GPS")
  383. }
  384. Method (_Q68, 0, NotSerialized)
  385. {
  386. \DBGH ("EC Query: 0x68 -> NVIDIA GPS")
  387. }
  388. Method (_Q6C, 0, NotSerialized)
  389. {
  390. \DBGH ("EC Query: 0x6C - TRPS")
  391. /* TRPS: Generic SMI trap handler */
  392. // TRPS (0x81, 0)
  393. }
  394. Method (_Q6D, 0, NotSerialized)
  395. {
  396. \DBGH ("EC Query: 0x6D - TRPS")
  397. /* TRPS: Generic SMI trap handler */
  398. // TRPS (0x81, 1)
  399. }
  400. #include "ac.asl"
  401. #include "battery.asl"
  402. }