0xless / battmngr

Battery manager to handle system performance modes and charge modes through acpi_calls (for ideapad 15are05/14are05/14alc05).
GNU General Public License v3.0
18 stars 3 forks source link

Support for Ideapad 5 Pro 16ACH6 #6

Open agorgl opened 2 years ago

agorgl commented 2 years ago

Laptop model: Lenovo IdeaPad 5 Pro 16ACH6 82L5005RMH Product name: 82L5

Getting 'Unrecognized battery mode, please retry' and 'Unrecognized battery charge mode, please retry' respectively for -r and -rc flags.

Tried both main and experimental_support branches.

I'm willing to make relevant PR provided some guidance on what I should look for to add support for my model.

0xless commented 2 years ago

Thanks for showing interest in this project!

The reason for this error is that battery/charge values read with ACPI calls are not the same as Ideapad 15are05's. Please check this function for reference: https://github.com/0xless/battmngr/blob/56be748c2c5aeb14581a040719c522c26a101b0f/battmngr#L308-L331

If the problem is present for read functions only, I think we could support your laptop! If you feel free to hack the script a little bit, you could report the hex values (and corresponding modes) read back by the read_operation and read_charge_operation functions. If you want to explore with supporting your laptop yourself, I would suggest you try the experimental_support branch as it uses a json configuration file to load the calls/values relative to a specific laptop.

In the mean time, if you could please provide us with the output of each battmngr command, it would be amazing to evaluate the support state of your laptop.

agorgl commented 2 years ago

Do you have the dsdt.dat or the decoded dsdt.dsl of your (working) model in order to compare it with mine? I see for example the SBMC method in mine that accepts argument that either is 0x03 0x05 0x07 0x08 but I need to know how your read op looks like in order to find mine similar one

0xless commented 2 years ago

Sure, you can find the zipped dsdt.dsl file attached. I've only gave a quick look to the code but I couldn't find some of the functions or argument values that works and that are in use in battmngr.

Let me know how it goes!

dsdt.zip

agorgl commented 2 years ago

Hmmm, your dsdt.dsl seems way more straightforward than mine, as in the SBMC method it sets the BTSM and QCHO values that you read back directly. In my case:

agorgl commented 2 years ago

Relevant acpi methods:

Method (SBMC, 1, NotSerialized)
{
    If ((Arg0 == 0x03))
    {
        ECCC (0x30, 0xA0, Zero, Zero)
        ECCC (0x31, 0xA1, Zero, Zero)
        Return (Zero)
    }

    If ((Arg0 == 0x05))
    {
        ECCC (0x30, 0xA1, Zero, Zero)
        Return (Zero)
    }

    If ((Arg0 == 0x07))
    {
        ECCC (0x31, 0xA0, Zero, Zero)
        ECCC (0x30, 0xA1, Zero, Zero)
        Return (Zero)
    }

    If ((Arg0 == 0x08))
    {
        ECCC (0x31, 0xA1, Zero, Zero)
        Return (Zero)
    }

    Return (Zero)
}

and

Method (ECCC, 4, Serialized)
{
    Local0 = Acquire (QEVT, 0x07D0)
    If ((Local0 == Zero))
    {
        DAT0 = Arg1
        DAT1 = Arg2
        DAT2 = Arg3
        CMDB = Arg0
        Local0 = 0x0100
        While ((Local0 && CMDB))
        {
            Sleep (0x02)
            Local0--
        }

        If ((CMDB == Zero))
        {
            Local0 = Zero
        }
        Else
        {
            Local0 = 0xFF
        }

        Release (QEVT)
        Return (Local0)
    }

    Release (QEVT)
    Return (0xFF)
}

The CMDB seems to be the type of operation (rapid charge / battery conservation) and DAT0 the on/off toggle

agorgl commented 2 years ago

The relevant memory region is this:

OperationRegion (SMA2, SystemMemory, 0xFEFF0A00, 0x80)
Field (SMA2, ByteAcc, Lock, Preserve)
{
    CMDB,   8, 
    STAT,   8, 
    NUMB,   8, 
    DAT0,   8, 
    DAT1,   8, 
    DAT2,   8, 
    DAT3,   8, 
    DAT4,   8, 
    DAT5,   8, 
    DAT6,   8, 
    DAT7,   8, 
    DAT8,   8, 
    DAT9,   8, 
    DATA,   8, 
    DATB,   8, 
    DATC,   8
}

I'm not really familiar with ACPI/DSDT but I cannot find any read references for CMDB or any reference for SMA2 at all.

0xless commented 2 years ago

You went way more in depth than I did analyzing the code, thanks for the effort. As you pointed out, references to some of the functions used are not present in the file.

In my opinion it would be easier to setup a Windows test environment, install Lenovo Vantage and sniff the ACPI calls sent by the software. I didn't try this yet, but looking around on the internet, this seems to be doable.

xaibex commented 2 years ago

@0xless : do you have recommendations on how to sniff ACPI calls (software etc,)?

0xless commented 2 years ago

@xaibex never attempted that, but if you find any interesting software, please let me know!