Contribute
Register

[Guide] How to patch DSDT for working battery status

Rehabman, I presume that the issue are the following lines:
Store (Arg1, TD38)​
where I tried to switch the TD38 with a B1B2 function? But how should I tackle this then? I could find some info in your first post about this using the Method (WECB, 3, Serialized)\n..... functions? But this is using offsets for bigger fields with a bytesize bigger the 32? You mention that I can find examples in the existing repo? Could you perhaps point me to a patch in which this issue is fixed?

Guys... no idea without "Problem Reporting" files...
 
Guys... no idea without "Problem Reporting" files...

Here it is!
Still not working even after EC reset performed several times.
 

Attachments

  • Problem Reporting 3.zip
    5.4 MB · Views: 85
Okay, maybe I found out what is not working.

I have 4 EmbeddedControl regions, and I patched only one.
In 2 other regions, I have two fields at 256-bits size, that are accessed 13 times (the first) and 3 (I think) times (the second), I tried to follow the guide but I have the following doubts:
- Do I have to use RECB or WECB? How can I choose? From what I think to have understood, I only have writes to EC buffers, so I should use WECB (?);
- How can I get the offsets if before the fields I don't have any "offset" written? I do have offsets but in the already patched EmbeddedControl region, which contained 8 and 16-bits fields.

Code:
OperationRegion (ECOR, EmbeddedControl, Zero, 0xFF)
            Field (ECOR, ByteAcc, Lock, Preserve)
            {
                Offset (0x04),
                CMD1,   8,
                CDT1,   8,
                CDT2,   8,
                CDT3,   8,
                Offset (0x80),
                Offset (0x81),
                Offset (0x82),
                Offset (0x83),
                EB0R,   8,
                EB1R,   8,
                EPWF,   8,
                Offset (0x87),
                Offset (0x88),
                Offset (0x89),
                Offset (0x8A),
                HKEN,   1,
                Offset (0x93),
                AH00,   8,
                AH01,   8,
                AH10,   8,
                AH11,   8,
                TSTP,   8,
                Offset (0x9C),
                CDT4,   8,
                CDT5,   8,
                Offset (0xA0),
                Offset (0xA1),
                Offset (0xA2),
                Offset (0xA3),
                EACT,   8,
                TH1R,   8,
                TH1L,   8,
                TH0R,   8,
                TH0L,   8,
                Offset (0xB0),
                B0PN,   16,
                Offset (0xB4),
                Offset (0xB6),
                Offset (0xB8),
                Offset (0xBA),
                Offset (0xBC),
                Offset (0xBE),
                B0TM,   16,
                B0C1,   16,
                B0C2,   16,
                CC30,   8,
                CC31,   8,
                B0C4,   16,
                Offset (0xD0),
                B1PN,   16,
                Offset (0xD4),
                Offset (0xD6),
                Offset (0xD8),
                Offset (0xDA),
                Offset (0xDC),
                Offset (0xDE),
                B1TM,   16,
                B1C1,   16,
                B1C2,   16,
                B1C3,   16,
                B1C4,   16,
                Offset (0xF0),
                Offset (0xF2),
                Offset (0xF4),
                GSN0,   8,
                GSN1,   8,
                Offset (0xF8),
                Offset (0xFA),
                Offset (0xFC),
                FSN0,   8,
                FSN1,   8
            }

            Name (SMBF, Zero)
            OperationRegion (SMBX, EmbeddedControl, 0x18, 0x28)
            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                PRTC,   8,
                SSTS,   5,
                    ,   1,
                ALFG,   1,
                CDFG,   1,
                ADDR,   8,
                CMDB,   8,
                BDAT,   256,
                BCNT,   8,
                    ,   1,
                ALAD,   7,
                ALD0,   8,
                ALD1,   8
            }

            OperationRegion (SMB2, EmbeddedControl, 0x40, 0x28)
            Field (SMB2, ByteAcc, NoLock, Preserve)
            {
                PRT2,   8,
                SST2,   5,
                    ,   1,
                ALF2,   1,
                CDF2,   1,
                ADD2,   8,
                CMD2,   8,
                BDA2,   256,
                BCN2,   8,
                    ,   1,
                ALA2,   7,
                ALR0,   8,
                ALR1,   8
            }

            Field (SMB2, ByteAcc, NoLock, Preserve)
            {
                Offset (0x04),
                DA20,   8,
                DA21,   8
            }

            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                Offset (0x04),
                DAT0,   8,
                DAT1,   8
            }

            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                Offset (0x04),
                DT2B,   16
            }
 
Okay, maybe I found out what is not working.

I have 4 EmbeddedControl regions, and I patched only one.
In 2 other regions, I have two fields at 256-bits size, that are accessed 13 times (the first) and 3 (I think) times (the second), I tried to follow the guide but I have the following doubts:
- Do I have to use RECB or WECB? How can I choose? From what I think to have understood, I only have writes to EC buffers, so I should use WECB (?);
- How can I get the offsets if before the fields I don't have any "offset" written? I do have offsets but in the already patched EmbeddedControl region, which contained 8 and 16-bits fields.

Code:
OperationRegion (ECOR, EmbeddedControl, Zero, 0xFF)
            Field (ECOR, ByteAcc, Lock, Preserve)
            {
                Offset (0x04),
                CMD1,   8,
                CDT1,   8,
                CDT2,   8,
                CDT3,   8,
                Offset (0x80),
                Offset (0x81),
                Offset (0x82),
                Offset (0x83),
                EB0R,   8,
                EB1R,   8,
                EPWF,   8,
                Offset (0x87),
                Offset (0x88),
                Offset (0x89),
                Offset (0x8A),
                HKEN,   1,
                Offset (0x93),
                AH00,   8,
                AH01,   8,
                AH10,   8,
                AH11,   8,
                TSTP,   8,
                Offset (0x9C),
                CDT4,   8,
                CDT5,   8,
                Offset (0xA0),
                Offset (0xA1),
                Offset (0xA2),
                Offset (0xA3),
                EACT,   8,
                TH1R,   8,
                TH1L,   8,
                TH0R,   8,
                TH0L,   8,
                Offset (0xB0),
                B0PN,   16,
                Offset (0xB4),
                Offset (0xB6),
                Offset (0xB8),
                Offset (0xBA),
                Offset (0xBC),
                Offset (0xBE),
                B0TM,   16,
                B0C1,   16,
                B0C2,   16,
                CC30,   8,
                CC31,   8,
                B0C4,   16,
                Offset (0xD0),
                B1PN,   16,
                Offset (0xD4),
                Offset (0xD6),
                Offset (0xD8),
                Offset (0xDA),
                Offset (0xDC),
                Offset (0xDE),
                B1TM,   16,
                B1C1,   16,
                B1C2,   16,
                B1C3,   16,
                B1C4,   16,
                Offset (0xF0),
                Offset (0xF2),
                Offset (0xF4),
                GSN0,   8,
                GSN1,   8,
                Offset (0xF8),
                Offset (0xFA),
                Offset (0xFC),
                FSN0,   8,
                FSN1,   8
            }

            Name (SMBF, Zero)
            OperationRegion (SMBX, EmbeddedControl, 0x18, 0x28)
            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                PRTC,   8,
                SSTS,   5,
                    ,   1,
                ALFG,   1,
                CDFG,   1,
                ADDR,   8,
                CMDB,   8,
                BDAT,   256,
                BCNT,   8,
                    ,   1,
                ALAD,   7,
                ALD0,   8,
                ALD1,   8
            }

            OperationRegion (SMB2, EmbeddedControl, 0x40, 0x28)
            Field (SMB2, ByteAcc, NoLock, Preserve)
            {
                PRT2,   8,
                SST2,   5,
                    ,   1,
                ALF2,   1,
                CDF2,   1,
                ADD2,   8,
                CMD2,   8,
                BDA2,   256,
                BCN2,   8,
                    ,   1,
                ALA2,   7,
                ALR0,   8,
                ALR1,   8
            }

            Field (SMB2, ByteAcc, NoLock, Preserve)
            {
                Offset (0x04),
                DA20,   8,
                DA21,   8
            }

            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                Offset (0x04),
                DAT0,   8,
                DAT1,   8
            }

            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                Offset (0x04),
                DT2B,   16
            }

All multibyte EC fields that are accessed must be patched.
 
All multibyte EC fields that are accessed must be patched.
Yes I know but I don't know how to correctly determine the offset of those two 256-bits fields. Where do I take them from? In your example, offset are written just before the fields. Here there are none.
 
Yes I know but I don't know how to correctly determine the offset of those two 256-bits fields. Where do I take them from? In your example, offset are written just before the fields. Here there are none.

The OperationRegion declares the starting offset. Usually it is zero, but in your case it is 0x18.
You can read about it in the ACPI spec.

For example:
Code:
            OperationRegion (SMBX, EmbeddedControl, 0x18, 0x28)
            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                PRTC,   8, //0x18
                SSTS,   5, //0x19
                    ,   1,
                ALFG,   1,
                CDFG,   1,
                ADDR,   8,//0x1a
                CMDB,   8,//0x1b
                BDAT,   256,//0x1c
 
The OperationRegion declares the starting offset. Usually it is zero, but in your case it is 0x18.
You can read about it in the ACPI spec.

For example:
Code:
            OperationRegion (SMBX, EmbeddedControl, 0x18, 0x28)
            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                PRTC,   8, //0x18
                SSTS,   5, //0x19
                    ,   1,
                ALFG,   1,
                CDFG,   1,
                ADDR,   8,//0x1a
                CMDB,   8,//0x1b
                BDAT,   256,//0x1c
In the meantime, I tried to write those 256-bits fields as 8-bits ones since I couldn't figure that out and HOORAY!! It works!!

I'll take some time to write a patch using offsets and then I'll post :)

Thank you so much!

EDIT: this is what I've done.

First, I fixed 16-bits fields in the first region inside EC:

Code:
into method label B1B2 remove_entry;
into definitionblock code_regex . insert
begin
Method (B1B2, 2, NotSerialized) { Return(Or(Arg0, ShiftLeft(Arg1, 8))) }\n
end;# 16-bit registers
into device label EC0 code_regex TAH0,\s+16 replace_matched begin AH00,8,AH01,8 end;
into device label EC0 code_regex TAH1,\s+16 replace_matched begin TA00,8,TA01,8 end;
into device label EC0 code_regex B0C3,\s+16 replace_matched begin BC00,8,BC01,8 end;
into device label EC0 code_regex B0SN,\s+16 replace_matched begin BS00,8,BS01,8 end;
into device label EC0 code_regex B1SN,\s+16 replace_matched begin BF00,8,BF01,8 end;
into device label EC0 code_regex DT2B,\s+16 replace_matched begin DT00,8,DT01,8 end;
# fix 16-bit methods
into method label TACH code_regex \(TAH0, replaceall_matched begin (B1B2(AH00,AH01), end;
into method label TACH code_regex \(TAH1, replaceall_matched begin (B1B2(TA00,TA01), end;
into method label _BIX code_regex \(\^\^LPCB\.EC0\.B0C3, replaceall_matched begin (B1B2(^^LPCB.EC0.BC00,^^LPCB.EC0.BC01), end;
into method label BIFA code_regex \(B0SN, replace_matched begin (B1B2(BS00,BS01), end;
into method label BIFA code_regex \(B1SN, replaceall_matched begin (B1B2(BF00,BF01), end;
into method label SMBR code_regex \(DT2B, replaceall_matched begin (B1B2(DT00,DT01), end;
into method label SMBW code_regex \(DT2B, replaceall_matched begin (B1B2(DT00,DT01), end;

I wrote the 256-bits fields as 8-bits ones and redefining the offsets in OperationRegion:

Code:
Name (SMBF, Zero)
            OperationRegion (SMBX, EmbeddedControl, 0x18, 0x50)
            Field (SMBX, ByteAcc, NoLock, Preserve)
            {
                PRTC,   8,
                SSTS,   5,
                    ,   1,
                ALFG,   1,
                CDFG,   1,
                ADDR,   8,
                CMDB,   8,
                AD00,   8,
                AD01,   8,
                AD02,   8,
                AD03,   8,
                AD04,   8,
                AD05,   8,
                AD06,   8,
                AD07,   8,
                AD08,   8,
                AD09,   8,
                AD10,   8,
                AD11,   8,
                AD12,   8,
                AD13,   8,
                AD14,   8,
                AD15,   8,
                AD16,   8,
                AD17,   8,
                AD18,   8,
                AD19,   8,
                AD20,   8,
                AD21,   8,
                AD22,   8,
                AD23,   8,
                AD24,   8,
                AD25,   8,
                AD26,   8,
                AD27,   8,
                AD28,   8,
                AD29,   8,
                AD30,   8,
                AD31,   8,
                BCNT,   8,
                    ,   1,
                ALAD,   7,
                ALD0,   8,
                ALD1,   8
            }

            OperationRegion (SMB2, EmbeddedControl, 0x62, 0x84)
            Field (SMB2, ByteAcc, NoLock, Preserve)
            {
                PRT2,   8,
                SST2,   5,
                    ,   1,
                ALF2,   1,
                CDF2,   1,
                ADD2,   8,
                CMD2,   8,
                TB00,   8,
                TB01,   8,
                TB02,   8,
                TB03,   8,
                TB04,   8,
                TB05,   8,
                TB06,   8,
                TB07,   8,
                TB08,   8,
                TB09,   8,
                TB10,   8,
                TB11,   8,
                TB12,   8,
                TB13,   8,
                TB14,   8,
                TB15,   8,
                TB16,   8,
                TB17,   8,
                TB18,   8,
                TB19,   8,
                TB20,   8,
                TB21,   8,
                TB22,   8,
                TB23,   8,
                TB24,   8,
                TB25,   8,
                TB26,   8,
                TB27,   8,
                TB28,   8,
                TB29,   8,
                TB30,   8,
                TB31,   8,
                BCN2,   8,
                    ,   1,
                ALA2,   7,
                ALR0,   8,
                ALR1,   8
            }

Then I used B1B2 and B1B4 methods combined this way everytime the original fields were accessed (there were other fields named BDAT, but they were in other regions and independent from the specific field in EC):


Code:
Store (DerefOf (Index (Arg6, One)), B1B2 (B1B4 (B1B4 (TB00, TB01, TB02, TB03), B1B4 (TB04, TB05, TB06, TB07), B1B4 (TB08, TB09, TB10, TB11), B1B4 (TB12, TB13, TB14, TB15)), B1B4 (B1B4 (TB16, TB17, TB18, TB19), B1B4 (TB20, TB21, TB22, TB23), B1B4 (TB24, TB25, TB26, TB27), B1B4 (TB28, TB29, TB30, TB31))))

Probably, there is a simpler and better syntax to write that, but it works and that's the most important thing!

I'll post the patch when I get it all together.
 
Last edited:
Hi, Rehabman.
My Laptop's battery status is almost perfect with ACPIBatteryManager. When boot with AC Adapter, all is perfect.
But only problem is when I was booted without AC Adapter, battery status says it is connected to AC Adapter not "Power Source Battery".
of course after connecting to AC Adapter, all is perfect.
Can you take a look in my Files and Patches please?
 
Last edited:
Hi, Rehabman.
My Laptop's battery status is almost perfect with ACPIBatteryManager. When boot with AC Adapter, all is perfect.
But only problem is when I was booted without AC Adapter, battery status says it is connected to AC Adapter not "Power Source Battery".
of course after connecting to AC Adapter, all is perfect.
Can you take a look in my Files and Patches please?

Read post #1, "Problem Reporting" (you forgot to press F4 in Clover, therefore no files in ACPI/origin).

Note: ACPI is not patched correctly (no evidence of "OS Check Fix" patch, for example).
ACPI guide is linked from post #1.
 
Read post #1, "Problem Reporting" (you forgot to press F4 in Clover, therefore no files in ACPI/origin).

Note: ACPI is not patched correctly (no evidence of "OS Check Fix" patch, for example).
ACPI guide is linked from post #1.

Dear RehabMan.
I've attached the required files. Thanks again.
 
Back
Top