Contribute
Register

[Guide] How to patch DSDT for working battery status

How to patch DSDT for working battery status

:ch:
 
How to patch DSDT for working battery status

Hi. I followed your guide, but i got a little problem.

All the 16-bit patches went well, but with the others I get 3 errors: "6088, Object is not accessible from this scope (RECB)" linking the lines:
Store (RECB(0xC1,64), Local3)
Store (RECB(0x30,128), Local3)
Store (RECB(0x08,112), Local3)
Here are the patches I used:
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 EC code_regex RTTE,\s+16 replace_matched begin TTE0,8,TTE1,8 end;
into device label EC code_regex ATTE,\s+16 replace_matched begin TZE0,8,TZE1,8 end;
into device label EC code_regex ATTF,\s+16 replace_matched begin TTF0,8,TTF1,8 end;
into device label EC code_regex AVGC,\s+16 replace_matched begin VGC0,8,VGC1,8 end;
into device label EC code_regex CHGV,\s+16 replace_matched begin HGV0,8,HGV1,8 end;
into device label EC code_regex CHGC,\s+16 replace_matched begin HGC0,8,HGC1,8 end;
into device label EC code_regex BDC,\s+16 replace_matched begin BDC0,8,BDC1,8 end;
into device label EC code_regex BFC,\s+16 replace_matched begin BFC0,8,BFC1,8 end;
into device label EC code_regex BTEC,\s+16 replace_matched begin TEC0,8,TEC1,8 end;
into device label EC code_regex BDV,\s+16 replace_matched begin BDV0,8,BDV1,8 end;
into device label EC code_regex BST,\s+16 replace_matched begin BST0,8,BST1,8 end;
into device label EC code_regex BPR,\s+16 replace_matched begin BPR0,8,BPR1,8 end;
into device label EC code_regex BRC,\s+16 replace_matched begin BRC0,8,BRC1,8 end;
into device label EC code_regex BPV,\s+16 replace_matched begin BPV0,8,BPV1,8 end;
into device label EC code_regex BMD,\s+16 replace_matched begin BMD0,8,BMD1,8 end;
into device label EC code_regex BCW,\s+16 replace_matched begin BCW0,8,BCW1,8 end;
into device label EC code_regex BCL,\s+16 replace_matched begin BCL0,8,BCL1,8 end;
into device label EC code_regex BMN,\s+16 replace_matched begin BMN0,8,BMN1,8 end;
into device label EC code_regex BSN,\s+16 replace_matched begin BSN0,8,BSN1,8 end;
into device label EC code_regex BTY,\s+16 replace_matched begin BTY0,8,BTY1,8 end;
into device label EC code_regex BC4,\s+16 replace_matched begin BC40,8,BC41,8 end;
into device label EC code_regex BC3,\s+16 replace_matched begin BC30,8,BC31,8 end;
into device label EC code_regex BC2,\s+16 replace_matched begin BC20,8,BC21,8 end;
into device label EC code_regex BC1,\s+16 replace_matched begin BC10,8,BC11,8 end;
into device label EC code_regex BTT,\s+16 replace_matched begin BTT0,8,BTT1,8 end;


# fix 16-bit methods
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BDV, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BDV0,\^\^PCI0.LPCB.EC.BDV1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BDC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BDC0,\^\^PCI0.LPCB.EC.BDC1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BFC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BFC0,\^\^PCI0.LPCB.EC.BFC1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BTEC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.TEC0,\^\^PCI0.LPCB.EC.TEC1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BDV, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BDV0,\^\^PCI0.LPCB.EC.BDV1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BCW, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BCW0,\^\^PCI0.LPCB.EC.BCW1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BCL, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BCL0,\^\^PCI0.LPCB.EC.BCL1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BFC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BFC0,\^\^PCI0.LPCB.EC.BFC1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BMN, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BMN0,\^\^PCI0.LPCB.EC.BMN1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BDC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BDC0,\^\^PCI0.LPCB.EC.BDC1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BSN, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BSN0,\^\^PCI0.LPCB.EC.BSN1), end;
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BTY, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BTY0,\^\^PCI0.LPCB.EC.BTY1), end;
into method label UBST code_regex \(\^\^PCI0.LPCB.EC.BST, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BST0,\^\^PCI0.LPCB.EC.BST1), end;
into method label UBST code_regex \(\^\^PCI0.LPCB.EC.BPR, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BPR0,\^\^PCI0.LPCB.EC.BPR1), end;
into method label UBST code_regex \(\^\^PCI0.LPCB.EC.BDV, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BDV0,\^\^PCI0.LPCB.EC.BDV1), end;
into method label UBST code_regex \(\^\^PCI0.LPCB.EC.BFC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BFC0,\^\^PCI0.LPCB.EC.BFC1), end;
into method label UBST code_regex \(\^\^PCI0.LPCB.EC.BPV, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BPV0,\^\^PCI0.LPCB.EC.BPV1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BDC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BDC0,\^\^PCI0.LPCB.EC.BDC1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BFC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BFC0,\^\^PCI0.LPCB.EC.BFC1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BTT, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BTT0,\^\^PCI0.LPCB.EC.BTT1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BPV, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BPV0,\^\^PCI0.LPCB.EC.BPV1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BPR, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BPR0,\^\^PCI0.LPCB.EC.BPR1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BDV, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BDV0,\^\^PCI0.LPCB.EC.BDV1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BST, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BST0,\^\^PCI0.LPCB.EC.BST1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BC1, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BC10,\^\^PCI0.LPCB.EC.BC11), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BC2, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BC20,\^\^PCI0.LPCB.EC.BC21), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BC3, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BC30,\^\^PCI0.LPCB.EC.BC31), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BC4, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BC40,\^\^PCI0.LPCB.EC.BC41), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BSN, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BSN0,\^\^PCI0.LPCB.EC.BSN1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BMD, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BMD0,\^\^PCI0.LPCB.EC.BMD1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.CHGC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.HGC0,\^\^PCI0.LPCB.EC.HGC1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.CHGV, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.HGV0,\^\^PCI0.LPCB.EC.HGV1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.AVGC, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.VGC0,\^\^PCI0.LPCB.EC.VGC1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.RTTE, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.TTE0,\^\^PCI0.LPCB.EC.TTE1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.ATTE, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.TZE0,\^\^PCI0.LPCB.EC.TZE1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.ATTF, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.TTF0,\^\^PCI0.LPCB.EC.TTF1), end;
into method label WMBG code_regex \(\^\^PCI0.LPCB.EC.BST, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BST0,\^\^PCI0.LPCB.EC.BST1), end;




# utility methods to read/write buffers from/to EC
into method label RE1B parent_label EC remove_entry;
into method label RECB parent_label EC remove_entry;
into device label EC insert
begin
Method (RE1B, 1, NotSerialized)\n
{\n
    OperationRegion(ERAM, EmbeddedControl, Arg0, 1)\n
    Field(ERAM, ByteAcc, NoLock, Preserve) { BYTE, 8 }\n
    Return(BYTE)\n
}\n
Method (RECB, 2, Serialized)\n
// Arg0 - offset in bytes from zero-based EC\n
// Arg1 - size of buffer in bits\n
{\n
    ShiftRight(Arg1, 3, Arg1)\n
    Name(TEMP, Buffer(Arg1) { })\n
    Add(Arg0, Arg1, Arg1)\n
    Store(0, Local0)\n
    While (LLess(Arg0, Arg1))\n
    {\n
        Store(RE1B(Arg0), Index(TEMP, Local0))\n
        Increment(Arg0)\n
        Increment(Local0)\n
    }\n
    Return(TEMP)\n
}\n
end;




into device label EC code_regex (BDNB,)\s+(112) replace_matched begin BDNY,%2,//%1%2 end;
into device label EC code_regex (CTL,)\s+(128) replace_matched begin CTLY,%2,//%1%2 end;
into device label EC code_regex (BTN,)\s+(64) replace_matched begin BTNY,%2,//%1%2 end;




into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BDNB, replaceall_matched begin (RECB(0x08,112), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.CTL, replaceall_matched begin (RECB(0x30,128), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BTN, replaceall_matched begin (RECB(0xC1,64), end;
(Applying the patches all together gives me a lot of error, but applying them "step by step" works just fine. What's more is that I manually have to correct one of the patches, I mean in the file: I have to replace "^^PCI0.LPCB.EC.BSN" with "^^PCI0.LPCB.EC.BSN0,^^PCI0.LPCB.EC.BSN1", to make it like all the others.)

Here I attach my DSDT.aml file, thank you in advance!

View attachment DSDT.aml
 
How to patch DSDT for working battery status

You are missing a patch for this line of code:
Code:
                    Store (^^BAT0.ITSN ([B]ToBCD (^^PCI0.LPCB.EC.BSN)[/B], 0x05), Local1)

The patches that use RECB are incorrect. RECB is in scope _SB.PCI0.LPCB.EC.
 
How to patch DSDT for working battery status

The patches that use RECB are incorrect. RECB is in scope _SB.PCI0.LPCB.EC.

Sorry if I still don't get the point, you mean I have to bring the RECB method to an other scope? If yes, where?

Regarding the missing patch, I don't know where the problem is, I wrote the patch, but anyway fixing it manually makes it work, as I said before.
 
How to patch DSDT for working battery status

Sorry if I still don't get the point, you mean I have to bring the RECB method to an other scope? If yes, where?

No. RECB is in the correct scope. But the code you're patching is in a different scope. In order for that code to reference RECB, it must refer to the correct scope (eg. \_SB.PCI0.LPCB.EC.RECB).

Regarding the missing patch, I don't know where the problem is, I wrote the patch, but anyway fixing it manually makes it work, as I said before.

Look at the line of code I showed. Determine why your regex patches do not match against it.
 
How to patch DSDT for working battery status

No. RECB is in the correct scope. But the code you're patching is in a different scope. In order for that code to reference RECB, it must refer to the correct scope (eg. \_SB.PCI0.LPCB.EC.RECB).
That's why!! I just missed the \slash before _SB.PCI0.LPCB.EC.
Anyway, adding it to the patch code with the \slash won't add the \slash in the file. Of course, manually fixing makes it perfect.



Look at the line of code I showed. Determine why your regex patches do not match against it.

Ok. ^^PCI0.LPCB.EC.BSN is repeated two times, one in _BIF method and one in GTBI method. So I have to write two patches:

Code:
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BSN, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BSN0,\^\^PCI0.LPCB.EC.BSN1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BSN, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BSN0,\^\^PCI0.LPCB.EC.BSN1), end;

The one in _BIF is being patched; the other one is not. What's wrong? Should I change names of the second one (BSN2; BSN3)?

Thank you for the help :)
 
How to patch DSDT for working battery status

That's why!! I just missed the \slash before _SB.PCI0.LPCB.EC.
Anyway, adding it to the patch code with the \slash won't add the \slash in the file. Of course, manually fixing makes it perfect.

You need to double up the backslash... \\_SB.PCI0.LPCB.EC.

Ok. ^^PCI0.LPCB.EC.BSN is repeated two times, one in _BIF method and one in GTBI method. So I have to write two patches:

Code:
into method label _BIF code_regex \(\^\^PCI0.LPCB.EC.BSN, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BSN0,\^\^PCI0.LPCB.EC.BSN1), end;
into method label GTBI code_regex \(\^\^PCI0.LPCB.EC.BSN, replaceall_matched begin (B1B2(\^\^PCI0.LPCB.EC.BSN0,\^\^PCI0.LPCB.EC.BSN1), end;

The one in _BIF is being patched; the other one is not. What's wrong? Should I change names of the second one (BSN2; BSN3)?

The code you need to patch does NOT end in a comma ','
 
How to patch DSDT for working battery status

I've already patched the DSDT and now the battery status seems to work perfectly :)

Here is the patch file I used (without fix for the NSB problem...)
View attachment Battery Status DSDT Patch DV6-6150sl.txt

To compile it search for "^^PCI0.LPCB.EC.BSN" and replace it with "^^PCI0.LPCB.EC.BSN0,^^PCI0.LPCB.EC.BSN1".

(I don't know if it influences this part of the DSDT, so I better say it. My laptop is not "stock": I've added 4GB RAM Kingston and changed hard disk.)

Thank you so much for the help :D
 
How to patch DSDT for working battery status

I've already patched the DSDT and now the battery status seems to work perfectly :)

Here is the patch file I used (without fix for the NSB problem...)
View attachment 109622

To compile it search for "^^PCI0.LPCB.EC.BSN" and replace it with "^^PCI0.LPCB.EC.BSN0,^^PCI0.LPCB.EC.BSN1".

(I don't know if it influences this part of the DSDT, so I better say it. My laptop is not "stock": I've added 4GB RAM Kingston and changed hard disk.)

Thank you so much for the help :D

It seems likely the existing patch for "HP DV6t-6b00" is a match for your DSDT.

I will add your model to the comments in the patch file.
 
How to patch DSDT for working battery status

Hello Rehabman,
This dsdt works. I've tried so many patches, and this one actually works on envy 4-1117nr 3317u i5.
View attachment 110260

Your GenericUSBXHCI.kext actually works for all USB 3.0 after sleep/wake.

Thanks,

Louis

As far as battery status is concerned, the two DSDTs are the same. The second one has an patch related to HPET. They may originate from a different computer.
 
Back
Top