Skip to content

Instantly share code, notes, and snippets.

@snizovtsev
Created July 1, 2021 12:02
Show Gist options
  • Select an option

  • Save snizovtsev/854364663444f8ac172b6e1ceeaceee4 to your computer and use it in GitHub Desktop.

Select an option

Save snizovtsev/854364663444f8ac172b6e1ceeaceee4 to your computer and use it in GitHub Desktop.

Revisions

  1. snizovtsev created this gist Jul 1, 2021.
    132 changes: 132 additions & 0 deletions battery.asl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,132 @@
    DefinitionBlock ("", "SSDT", 1, "BOCHS ", "BATTERY", 0x00000001)
    {
    // TODO: declare area size here?
    // Handle reconnects?
    External (BPTR, IntObj)

    Device (\_SB.BRES)
    {
    Name (_HID, "PNP0A06")
    Name (_UID, "Battery resources")

    OperationRegion(BMEM, SystemMemory, BPTR, 0x1000)
    Field (BMEM) {
    BELL, 32,
    }

    Method (_STA, 0, NotSerialized)
    {
    If (BPTR) {
    //Return (0x8) /* functional */
    Return (0xB)
    } Else {
    Return (0)
    }
    }

    //Field (BMEM)
    //{
    // BSTA, 8,
    // Offset(0x4),
    // FBST, 0x080,
    // FBIF, 0x360,
    //}

    Method(RBIF, 2, NotSerialized)
    {
    CreateDWordField(Arg0, 0x00, DSGN)
    CreateDWordField(Arg0, 0x04, FULL)
    CreateDWordField(Arg0, 0x08, DVLT)
    CreateField(Arg0, 0x060, 0x100, PART)
    CreateField(Arg0, 0x160, 0x100, SNID)
    CreateField(Arg0, 0x260, 0x100, DESC)
    Arg1[0] = 0 /* Power Unit: mWh */
    Arg1[1] = DSGN /* Factory capacity */
    Arg1[2] = FULL /* Full capacity */
    Arg1[3] = 1 /* Rechargable */
    Arg1[4] = DVLT
    Arg1[5] = 0xFFFFFFFF /* warning level */
    Arg1[6] = 0xFFFFFFFF /* low level */
    Arg1[7] = 1 /* granularity 1 */
    Arg1[8] = 1 /* granularity 2 */
    Arg1[9] = PART
    Arg1[10] = SNID
    Arg1[11] = "LION"
    Arg1[12] = DESC
    // Ack 0 -> 1? BELL.
    }

    Method (RBST, 2, NotSerialized)
    {
    CreateDWordField(Arg0, 0x00, FLAG)
    CreateDWordField(Arg0, 0x04, RATE)
    CreateDWordField(Arg0, 0x08, ENRG)
    CreateDWordField(Arg0, 0x0C, VOLT)
    Arg1[0] = FLAG
    Arg1[1] = RATE
    Arg1[2] = ENRG
    Arg1[3] = VOLT
    }

    Device(AC)
    {
    Name (_HID, "ACPI0003")
    Name (_PCL, Package (0x02) {
    _SB,
    BAT0
    })

    Method (_INI, 0, NotSerialized)
    {
    // copy from field
    }

    Method (_STA, 0, NotSerialized)
    {
    Return (0xF)
    }

    Method (_PSR, 0, NotSerialized)
    {
    Return (0xFF) /* Unknown */
    }
    }

    Device(BAT0)
    {
    Name (_HID, EisaId ("PNP0C0A"))
    Name (_UID, 0x0)

    Method (_STA, 0, NotSerialized)
    {
    If (BSTA) {
    Return (0x1F)
    } Else {
    Return (0)
    }
    }

    Name (PBIF, Package(13) {})
    Method (_BIF, 0, NotSerialized)
    {
    RBIF (FBIF, PBIF)
    Return (PBIF)
    }

    Name (PBST, Package(4) {})
    Method (_BST, 0, NotSerialized)
    {
    RBST (FBST, PBST)
    Return (PBST)
    }
    }
    }

    Method (\_GPE._E07, 0, NotSerialized)
    {
    If (BELL != 0x1a7f3c93) {

    } Else {
    }
    }
    }