#Maintained by: RehabMan for: Laptop Patches #battery_Lenovo-Yoga-900-13ISK.txt # Created by GeneralCuster 2017-06-01 # initial fixes after review by RehabMan # added support for Lenovo Mixx 510 (RehabMan) # works for: # Lenovo Yoga 900-13ISK # Lenovo Miix 510-12ISK # Lenovo Yoga Pro 3 (per zohaad@github) # assumes offsets as follows # Field (ECF2, ByteAcc, Lock, Preserve) # { #... # Offset (0x06), # BARL, 64, //0x06 # BARH, 64, //0x0e # Offset (0x18), # SMPR, 8, //18 # SMST, 8, //1a # SMAD, 8, //1c # SMCM, 8, //1e # SMD0, 256, //0x20 #.. # Offset (0x76), # B1DC, 16, //76 # B1DV, 16, //78 # BDCW, 16, //7a # BDCL, 16, //7c # B1AR, 16, //7e # B1MA, 64, //0x80 # B1DN, 64, //0x88 #for 16 bit registers into method label B1B2 remove_entry; into definitionblock code_regex . insert begin Method (B1B2, 2, NotSerialized) { Return(Or(Arg0, ShiftLeft(Arg1, 8))) }\n end; #For 32 bit registers into method label B1B4 remove_entry; into definitionblock code_regex . insert begin Method (B1B4, 4, NotSerialized)\n {\n Store(Arg3, Local0)\n Or(Arg2, ShiftLeft(Local0, 8), Local0)\n Or(Arg1, ShiftLeft(Local0, 8), Local0)\n Or(Arg0, ShiftLeft(Local0, 8), Local0)\n Return(Local0)\n }\n end; # utility methods to read/write buffers from/to EC into method label RE1B parent_label H_EC remove_entry; into method label RECB parent_label H_EC remove_entry; into device label H_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(Add(Arg1,7), 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 method label WE1B parent_label H_EC remove_entry; into method label WECB parent_label H_EC remove_entry; into device label H_EC insert begin Method (WE1B, 2, NotSerialized)\n {\n OperationRegion(ERAM, EmbeddedControl, Arg0, 1)\n Field(ERAM, ByteAcc, NoLock, Preserve) { BYTE, 8 }\n Store(Arg1, BYTE)\n }\n Method (WECB, 3, Serialized)\n // Arg0 - offset in bytes from zero-based EC\n // Arg1 - size of buffer in bits\n // Arg2 - value to write\n {\n ShiftRight(Add(Arg1,7), 3, Arg1)\n Name(TEMP, Buffer(Arg1) { })\n Store(Arg2, TEMP)\n Add(Arg0, Arg1, Arg1)\n Store(0, Local0)\n While (LLess(Arg0, Arg1))\n {\n WE1B(Arg0, DerefOf(Index(TEMP, Local0)))\n Increment(Arg0)\n Increment(Local0)\n }\n }\n end; #Replace declarations in embedded_control appropriately #16 bit into device label H_EC code_regex B1TM,\s+16, replace_matched begin BTM0,8,BTM1,8, end; into device label H_EC code_regex B1VT,\s+16, replace_matched begin BVT0,8,BVT1,8, end; into device label H_EC code_regex B1CR,\s+16, replace_matched begin BCR0,8,BCR1,8, end; into device label H_EC code_regex B1RC,\s+16, replace_matched begin B1R0,8,B1R1,8, end; into device label H_EC code_regex B1FC,\s+16, replace_matched begin BFC0,8,BFC1,8, end; into device label H_EC code_regex B1DC,\s+16, replace_matched begin BDC0,8,BDC1,8, end; into device label H_EC code_regex B1DV,\s+16, replace_matched begin BDV0,8,BDV1,8, end; into device label H_EC code_regex BDCW,\s+16, replace_matched begin DCW0,8,DCW1,8, end; into device label H_EC code_regex BDCL,\s+16, replace_matched begin DCL0,8,DCL1,8, end; into device label H_EC code_regex B1DT,\s+16, replace_matched begin BDT0,8,BDT1,8, end; into device label H_EC code_regex B2DT,\s+16, replace_matched begin BDT2,8,BDT3,8, end; into device label H_EC code_regex B1CY,\s+16, replace_matched begin BCY0,8,BCY1,8, end; into device label H_EC code_regex BCRT,\s+16, replace_matched begin CRT0,8,CRT1,8, end; #added for Miix 510 into device label H_EC code_regex B1FV,\s+16, replace_matched begin BFV0,8,BFV1,8, end; into method label _BST code_regex B1FV replaceall_matched begin B1B2(BFV0,BFV1) end; #32 bit into device label H_EC code_regex B1CH,\s+32, replace_matched begin BCH0,8,BCH1,8,BCH2,8,BCH3,8, end; #64 bit into device label H_EC code_regex (BARL,)\s+(64) replace_matched begin BARX,%2,//%1%2 end; into device label H_EC code_regex (BARH,)\s+(64) replace_matched begin BARY,%2,//%1%2 end; into device label H_EC code_regex (B1MA,)\s+(64) replace_matched begin BMAX,%2,//%1%2 end; into device label H_EC code_regex (B1DN,)\s+(64) replace_matched begin BDNY,%2,//%1%2 end; #256 bit into device label H_EC code_regex (SMD0,)\s+(256) replace_matched begin SMDX,%2,//%1%2 end; #Patch the accessors to use the method(s) we added into method label GSBI code_regex \(B1TM, replaceall_matched begin (B1B2(BTM0,BTM1), end; into method label _BST code_regex \(B1VT, replaceall_matched begin (B1B2(BVT0,BVT1), end; into method label GSBI code_regex \(B1VT, replaceall_matched begin (B1B2(BVT0,BVT1), end; into method label _BST code_regex \(B1CR, replaceall_matched begin (B1B2(BCR0,BCR1), end; into method label GSBI code_regex \(B1CR, replaceall_matched begin (B1B2(BCR0,BCR1), end; into method label _BST code_regex \(B1RC, replaceall_matched begin (B1B2(B1R0,B1R1), end; into method label GSBI code_regex \(B1RC, replaceall_matched begin (B1B2(B1R0,B1R1), end; into method label _BIF code_regex \(B1FC, replaceall_matched begin (B1B2(BFC0,BFC1), end; into method label _BIF code_regex \(B1FC\) replaceall_matched begin (B1B2(BFC0,BFC1)) end; into method label GSBI code_regex \(B1FC, replaceall_matched begin (B1B2(BFC0,BFC1), end; into method label _BIF code_regex \(B1DC, replaceall_matched begin (B1B2(BDC0,BDC1), end; into method label GSBI code_regex \(B1DC, replaceall_matched begin (B1B2(BDC0,BDC1), end; into method label _BIF code_regex \(B1DV, replaceall_matched begin (B1B2(BDV0,BDV1), end; into method label GSBI code_regex \(B1DV, replaceall_matched begin (B1B2(BDV0,BDV1), end; into method label GSBI code_regex \(BDCW, replaceall_matched begin (B1B2(DCW0,DCW1), end; into method label GSBI code_regex \(BDCL, replaceall_matched begin (B1B2(DCL0,DCL1), end; into method label GSBI code_regex \(B1DT, replaceall_matched begin (B1B2(BDT0,BDT1), end; into method label GSBI code_regex \(B2DT, replaceall_matched begin (B1B2(BDT2,BDT3), end; into method label GBID code_regex \(B1CY, replaceall_matched begin (B1B2(BCY0,BCY1), end; into method label SMTF code_regex \(BCRT, replaceall_matched begin (B1B2(CRT0,CRT1), end; into method label GSBI code_regex \(B1CH, replaceall_matched begin (B1B4(BCH0,BCH1,BCH2,BCH3), end; into method label GSBI code_regex \(BARL, replaceall_matched begin (RECB(0x06,64), end; into method label GSBI code_regex \(BARH, replaceall_matched begin (RECB(0x0e,64), end; into method label GSBI code_regex \(B1MA, replaceall_matched begin (RECB(0x80,64), end; into method label _BIF code_regex \(B1MA, replaceall_matched begin (RECB(0x80,64), end; into method label GSBI code_regex \(B1DN, replaceall_matched begin (RECB(0x88,64), end; into method label MHPF code_regex \(SMD0, replaceall_matched begin (RECB(0x20,256), end; into method label MHPF code_regex Store\s+\(\w+,\s+SMD0\) replaceall_matched begin WECB(0x20,256,FB4) end;