summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2019-05-30 05:28:56 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-02-03 22:02:37 +0300
commit952830607c23c861991b1e9a1250bf1e6827af90 (patch)
tree2b1581b64bb065b1e48cd3338b5bf63fede16073 /src
parent1254e370cc786a8a87f6f60a5cbd9381a6e196ab (diff)
ec/apple: Add ACPI code for Apple MacBooks
- Move ACPI code for Apple MacBooks to a separate directory to avoid its duplication in mainboards - Add AC and lid implementations for newer generations - Rewrite old code using the new ASL syntax Tested on MBA 5,2, MBP 8,1 and MBP 10,1. Change-Id: I3d4585aac8e3ebbfed6ce4d4e39fbc33ac983069 Signed-off-by: Evgeny Zinoviev <me@ch1p.io>
Diffstat (limited to 'src')
-rw-r--r--src/ec/apple/acpi/ac.asl28
-rw-r--r--src/ec/apple/acpi/battery.asl153
-rw-r--r--src/ec/apple/acpi/ec.asl45
-rw-r--r--src/ec/apple/acpi/lid.asl41
4 files changed, 267 insertions, 0 deletions
diff --git a/src/ec/apple/acpi/ac.asl b/src/ec/apple/acpi/ac.asl
new file mode 100644
index 0000000000..0103229936
--- /dev/null
+++ b/src/ec/apple/acpi/ac.asl
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+Scope(\_SB.PCI0.LPCB.EC)
+{
+ Field(ERAM, ByteAcc, NoLock, Preserve)
+ {
+ Offset(HPAC_OFFSET),
+ , 1,
+ HPAC, 1, /* AC status */
+ }
+
+ Device(AC)
+ {
+ Name(_HID, "ACPI0003")
+ Name(_UID, 0x00)
+ Name(_PCL, Package() { \_SB } )
+
+ Method(_PSR, 0, NotSerialized)
+ {
+ Return(HPAC)
+ }
+
+ Method(_STA, 0, NotSerialized)
+ {
+ Return(0x0f)
+ }
+ }
+}
diff --git a/src/ec/apple/acpi/battery.asl b/src/ec/apple/acpi/battery.asl
new file mode 100644
index 0000000000..291451f414
--- /dev/null
+++ b/src/ec/apple/acpi/battery.asl
@@ -0,0 +1,153 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+Field(ERAM, ByteAcc, NoLock, Preserve)
+{
+ Offset(0x20),
+ SPTR, 8,
+ SSTS, 8,
+ SADR, 8,
+ SCMD, 8,
+ SBFR, 256,
+}
+
+Field(ERAM, ByteAcc, Lock, Preserve)
+{
+ Offset(0x24),
+ SBDW, 16,
+}
+
+Method(SBPC, 0, NotSerialized)
+{
+ Local0 = 1000
+ While (Local0)
+ {
+ If (SPTR == 0x00)
+ {
+ Return()
+ }
+
+ Sleep(1)
+ Local0--
+ }
+}
+
+Method(SBRW, 2, NotSerialized)
+{
+ Acquire(ECLK, 0xFFFF)
+ SADR = ShiftLeft(Arg0, 0x01)
+ SCMD = Arg1
+ SPTR = 0x09
+ SBPC()
+ Local0 = SBDW
+ Release(ECLK)
+ Return(Local0)
+}
+
+Method(SBRB, 2, NotSerialized)
+{
+ Acquire(ECLK, 0xFFFF)
+ SADR = ShiftLeft(Arg0, 0x01)
+ SCMD = Arg1
+ SPTR = 0x0B
+ SBPC()
+ Local0 = SBFR
+ Release(ECLK)
+ Return(Local0)
+}
+
+Device(BAT0)
+{
+ Name(_HID, EisaId("PNP0C0A"))
+ Name(_UID, 0x00)
+ Name(_PCL, Package() { \_SB })
+
+ Name(BATS, Package()
+ {
+ 0x00, // 0: PowerUnit: Report in mWh
+ 0xFFFFFFFF, // 1: Design cap
+ 0xFFFFFFFF, // 2: Last full charge cap
+ 0x01, // 3: Battery Technology
+ 10800, // 4: Design Voltage(mV)
+ 0x00, // 5: Warning design capacity
+ 200, // 6: Low design capacity
+ 10, // 7: granularity1
+ 10, // 8: granularity2
+ "", // 9: Model number
+ "", // A: Serial number
+ "", // B: Battery Type
+ "" // C: OEM information
+ })
+
+ Name(BATI, Package()
+ {
+ 0, // Battery State
+ // Bit 0 - discharge
+ // Bit 1 - charge
+ // Bit 2 - critical state
+ 0, // Battery present Rate
+ 0, // Battery remaining capacity
+ 0 // Battery present voltage
+ })
+
+ Method(_BIF, 0, NotSerialized)
+ {
+ Index(BATS, 0x01) = ^^SBRW(0x0B, 0x18) * 10
+ Index(BATS, 0x02) = ^^SBRW(0x0B, 0x10) * 10
+
+ Index(BATS, 0x04) = ^^SBRW(0x0B, 0x19)
+ Index(BATS, 0x09) = ^^SBRB(0x0B, 0x21)
+ Index(BATS, 0x0B) = ^^SBRB(0x0B, 0x22)
+ Index(BATS, 0x0C) = ^^SBRB(0x0B, 0x20)
+
+ Return(BATS)
+ }
+
+ Method(_STA, 0, NotSerialized)
+ {
+ If (^^SBRW(0x0A, 0x01) & 0x01) {
+ Return(0x1f)
+ } else {
+ Return(0x0f)
+ }
+ }
+
+ Method(_BST, 0, NotSerialized)
+ {
+ /* Check for battery presence. */
+ If (!(^^SBRW(0x0A, 0x01) & 0x01)) {
+ Return(Package(4) {
+ 0,
+ 0xFFFFFFFF,
+ 0xFFFFFFFF,
+ 0xFFFFFFFF
+ })
+ }
+
+ Local1 = ^^SBRW(0x0B, 0x09)
+ Index(BATI, 0x03) = Local1
+ Local0 = ^^SBRW(0x0B, 0x0A)
+
+ /* Sign-extend Local0. */
+ If (Local0 & 0x8000)
+ {
+ Local0 = ~Local0
+ Local0++
+ Local0 &= 0xFFFF
+ }
+
+ Local0 *= Local1
+ Index(BATI, 1) = Local0 / 1000
+ Index(BATI, 2) = ^^SBRW(0x0B, 0x0F) * 10
+ If (HPAC) {
+ If (!(^^SBRW(0x0B, 0x16) & 0x40)) {
+ Index(BATI, 0) = 2
+ } Else {
+ Index(BATI, 0) = 0
+ }
+ } Else {
+ Index(BATI, 0) = 1
+ }
+
+ Return(BATI)
+ }
+}
diff --git a/src/ec/apple/acpi/ec.asl b/src/ec/apple/acpi/ec.asl
new file mode 100644
index 0000000000..3adb7f6ab3
--- /dev/null
+++ b/src/ec/apple/acpi/ec.asl
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+Device(EC)
+{
+ Name(_HID, EISAID("PNP0C09"))
+ Name(_UID, 0)
+
+ Name(_GPE, 0x17)
+ Mutex(ECLK, 0)
+
+ OperationRegion(ERAM, EmbeddedControl, 0x00, 0x100)
+
+ /* LID status change. */
+ Method(_Q20, 0, NotSerialized)
+ {
+ Notify(LID, 0x80)
+ }
+
+ /* AC status change. */
+ Method(_Q21, 0, NotSerialized)
+ {
+ Notify(AC, 0x80)
+ }
+
+ Method(_CRS, 0)
+ {
+ Name(ECMD, ResourceTemplate()
+ {
+ IO(Decode16, 0x62, 0x62, 1, 1)
+ IO(Decode16, 0x66, 0x66, 1, 1)
+ })
+ Return(ECMD)
+ }
+
+ Method(_PRW, 0, NotSerialized)
+ {
+ Return(Package () { 0x23, 0x04 })
+ }
+
+ Method(_INI, 0, NotSerialized)
+ {
+ }
+
+#include "battery.asl"
+}
diff --git a/src/ec/apple/acpi/lid.asl b/src/ec/apple/acpi/lid.asl
new file mode 100644
index 0000000000..ec91d8f106
--- /dev/null
+++ b/src/ec/apple/acpi/lid.asl
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+Scope(\_SB.PCI0.LPCB.EC)
+{
+ Field(ERAM, ByteAcc, NoLock, Preserve)
+ {
+ Offset(LIDS_OFFSET),
+ LIDS, 1, /* Lid status */
+
+ Offset(WKLD_OFFSET),
+ WKLD, 1, /* Lid wake */
+ }
+
+ Device(LID)
+ {
+ Name(_HID, "PNP0C0D")
+
+ Method(_LID, 0, NotSerialized)
+ {
+ Return(LIDS)
+ }
+
+ Method(_PRW, 0, NotSerialized)
+ {
+#if LIDS_OFFSET == 0x01
+ Return(Package() { 0x1d, 0x03 })
+#else
+ Return(Package() { 0x23, 0x04 })
+#endif
+ }
+
+ Method(_PSW, 1, NotSerialized)
+ {
+ if (Arg0) {
+ WKLD = 1
+ } else {
+ WKLD = 0
+ }
+ }
+ }
+}