Jump to content

AppleACPIBatteryManager/AppleSmartBatteryManager For Lion


  • Please log in to reply
175 replies to this topic

#1
Zprood

Zprood

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 251 posts
  • Gender:Male
  • Location:CHN
First Of All, Thanks these people for the battery driver:Chun-Nan, zenglg1977, gsly, bcc9, VIVXIX, weizh126. Cause without what they do can't get it work.Now start the topic.

Since apple changes some things on lion, the Appleacpibatterymanager does't work any more under the Lion, so people use roll backed next to get is work, but this has shortage. At the first, bcc9 found that lion reads battery info from EC by 8bit, and most laptop's EC region use 16bit to store battery information, so the legacy driver doesn't work include voodoo battery. This information is important for next.

The guy zenglg1977 takes some time to rewrite the sources code of Appleacpibatterymanager to make it work for lion. It is needed to edit the code of battery in the dsdt, so divide 16bit register into two 8bit can make sense. Like:
Before
//
Field (RAM, ByteAcc, Lock, Preserve)
		{
					Offset (0xE0),
			BSDC,   16,
			BSDV,   16,
			BSSN,   16
		}
//
Later
//
Field (RAM, ByteAcc, Lock, Preserve)
		{
					Offset (0xE0),
			SDC0,   8,
			SDC1,   8,
			SDV0,   8,
			SDV1,   8,
			SSN0,   8,
			SSN1,   8
		}
//
then, the transmit part can be done like this:
For example:

Before:
Multiply (BSDC, 0x0A, Local1)

Later:
Multiply (SDC1, 0x100, Local1)
Add (SDC0, Local1, Local1)
Multiply (Local1, 0x0A, Local1)

Before:
Store (BSDC, Local1)

Later:
Multiply (SDC1, 0x100, Local1)
Add (SDC0, Local1, Local1)

This way created by zenglg1977, after done with this can make it work.
But when compare VIVXIX with others method, i found his method is simple and easy to reach, it named "B1B2".
Here is his method:
1, create the "Method (B1B2, 2, NotSerialized)" as global:
Method (B1B2, 2, NotSerialized)
   {
		Or (ShiftLeft(Arg1,0x08), Arg0, Local0)
		Return (Local0)
	} //for 16bit

   Method (B1B4, 4, NotSerialized)	
  {
		Or (ShiftLeft(Arg1,0x08), Arg0, Local0)
		Or (ShiftLeft(Arg2,0x10), Local0, Local0)
		Or (ShiftLeft(Arg3,0x18), Local0, Local0)
		Return (Local0)
   } //for 32bit
  
   Method (L1L4, 4, NotSerialized)//32*4=128
  {
		Or (ShiftLeft(Arg1,0x20), Arg0, Local0)
		Or (ShiftLeft(Arg2,0x40), Local0, Local0)
		Or (ShiftLeft(Arg3,0x60), Local0, Local0)
		Return (Local0)
   }//for 128bit

2, change the 16bit register into two 8bit register, like:
//BPV0,  
	 SPV0,   8,
	 SPV1,   8,
3, here is some collections of example editing work he finished before.
A:
//Store (^^EC0.BAC0, Local5)
   Store (B1B2(^^EC0.SAC0,^^EC0.SAC1), Local5)

B:
//Store (^^EC0.BDC0, Index (STAT, One))
   Store (B1B2(^^EC0.SDC0,^^EC0.SDC1), Index (STAT, One))

C:
//Multiply (BGU1, BFC1 ,Local2)
   Multiply (BGU1, B1B2 (BFC0, BFC1), Local2)

Some special parts as below:
D:
//If (^^EC0.BDC0 )
   If (B1B2(^^EC0.SDC0,^^EC0.SDC1))

E:
//If (LGreater (^^EC0.BAC0, 0xFB00))
   If (LGreater (B1B2(^^EC0.SAC0,^^EC0.SAC1), 0xFB00)

F:
//Store (^^EC0.BDC0, BFC1)  
   Store (^^EC0.SDC1, BFC1)
   Sleep (0x14)
   Store (^^EC0.SDC0, BFC0)

More about the sources code, zenglg1977 combines gsly's AppleSmartBatteryManger code into whole project, then people get two choice. And weizh126 plays a trick about battery cycle count in the _BIF method part, the _BIF just contains 13 items in the package and he adds "Zero" to it become 14, and store the cycle count register info in it, it sounds illegal, but it works.

Last, here is the sources code and attachments.

Attached File  AppleBatteryManager_src.zip   72.32KB   364 downloads
Attached File  AppleACPIBatteryManager.kext.zip   30.93KB   785 downloads
Attached File  AppleSmartBatteryManager.kext.zip   34.52KB   759 downloads

Update for 10.7.3
Attached File  AppleBatteryManager_src.zip   72.32KB   435 downloads
Attached File  AppleSmartBatteryManager.kext.zip   35.13KB   1127 downloads
Attached File  AppleACPIBatteryManager.kext.zip   35.14KB   971 downloads

Also screenshots:
Attached File  Screen_Shot_2011_11_21_at_12.41.24_AM.png   63.99KB   954 downloads
Attached File  Screen_Shot_2011_11_21_at_12.41.47_AM.png   30.83KB   712 downloads

Original link address:
http://bbs.pcbeta.co...935509-1-1.html
http://bbs.pcbeta.co...935582-1-1.html

#2
mindlessmissy

mindlessmissy

    InsanelyMac Protégé

  • Members
  • PipPip
  • 99 posts
  • Gender:Male
Works perfectamente !!! :D

EDIT: Found a niggle ...

Start with a fully charged battery, take out the adapter and before the remaining percentage gets to 96% plug back in the adapter ...

For some reason previous kexts like voodoo battery will automatically go back to 100% but this kext just stays at the current level (96%, 97%, 98% or 99%) but still say fully charged ...

#3
fc bayern

fc bayern

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 210 posts
  • Gender:Male
  • Location:Macedonia
Works perfect, also shows the cycle info and the power tab in system profiler .But is it supposed to work with latest Appleacpiplatform.kext(10.7.2) or with the from SL(10.6.8). On my case work only with the one from 10.6.8, everything OK, but with the latest acpiplattform I can no infos at all.

#4
DarwinX

DarwinX

    InsanelyMac Legend

  • Members
  • PipPipPipPipPipPipPip
  • 615 posts
  • Gender:Male
  • Location:Florida
Thank You for this fantastic battery implementation! :D I have only one issue at this point, the fully charged battery percentage is at 121%. :wacko: Please advise.

Attached File  System_Information.png   124.38KB   364 downloadsAttached File  iStat___Temperatures.png   23.43KB   296 downloadsAttached File  iStat___Battery.png   14.33KB   187 downloads

#5
juanerson

juanerson

    InsanelyMac Legend

  • Local Moderators
  • 1,415 posts
  • Gender:Male
  • Location:Tru, Venezuela
YES. Thank You my friend! In my case (previous 8bit fixed code, thanks to bcc9 found) it was ONLY needed install the driver and voilá!... Very complete information in System profiler. I will do more tests. Best Regards.

#6
Zprood

Zprood

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 251 posts
  • Gender:Male
  • Location:CHN
@fc Bayern:
It works both 10.6.8 10.7.2 too, do you correct your dsdt ? i have test it under 10.6.8 turn out works with 8bit register.
@DarwinX mindlessmissy
Maybe some things you do wrong, i mean the code edit in the battery device, some registers are placed in other place not EC.

For those battery indicator percentage shows problem, maybe can take a look this:
In my case, also some other users get this phenomenon, it is like below:
Store (^^EC0.BDC0, BFC1)
under _BIF method, note the BDC0 is in the EC region, but BFC1 also exists both Field (ERAM, ByteAcc, Lock, Preserve) and the Field (GNVS, AnyAcc, Lock, Preserve), but the right place should be the latter. So, the right way is like this:
divide BFC1 into two 8bit register under Field (GNVS, AnyAcc, Lock, Preserve), ignore the BFC1 under EC.
//BFC1,   16,  
BFC0,   8,
BFC1,   8,
--------------------------------------------------------
//Store (^^EC0.BDC0, BFC1)
Store (^^EC0.SDC1, BFC1)
Sleep (0x14)
Store (^^EC0.SDC0, BFC0)

The _BST method part:
A:
//If (BFC1)
If (B1B2(BFC0,BFC1))

B:
// Multiply (BGU1,BFC1, Local2)
Multiply (BGU1, B1B2(BFC0,BFC1), Local2)

EDIT:
If you have over 16bit battery register in the EC region of dsdt, you should take look of this, below are some examples.

For people get 32bit registers, like:

Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0), 
						SBCH,   32
					}
Solution:
A, you should add B1B4 first as global.
Method (B1B4, 4, NotSerialized)///8*4=32
	 {
		 Or (ShiftLeft (Arg1, 0x08), Arg0, Local0)
		 Or (ShiftLeft (Arg2, 0x10),Local0, Local0)
		 Or (ShiftLeft (Arg3, 0x18),Local0, Local0)
		 Return (Local0)
	}

B, divide 32bit register into 4*8bit:
Before:
Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0), 
						SBCH,   32
					}
Later:
Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0), 
						BCH0,   8, 
						BCH1,   8, 
						BCH2,   8, 
						BCH3,   8
					}

C, edit the exists code. (PS: you should click "Update tree" first, if you use DSDT Editor.)
//Store (SBCH, BTYP)
	Store (B1B4 (BCH0, BCH1, BCH2, BCH3), BTYP)

Also if you get 128bit register, you can do it in same way.
A, you should add B1B4 first as global.
Method (L1L4, 4, NotSerialized)//32*4=128
	 {
		 Or (ShiftLeft (Arg1, 0x20), Arg0, Local0)
		 Or (ShiftLeft (Arg2, 0x40),Local0, Local0)
		 Or (ShiftLeft (Arg3, 0x60),Local0, Local0)
		 Return (Local0)
	 }
	}

B, divide 128bit register into 16*8bit:
Before:
Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0), 
						SBMN,   128
					}
Later:
Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0), 
						BMN0,   8, 
						BMN1,   8, 
						BMN2,   8, 
						BMN3,   8, 
						BMN4,   8, 
						BMN5,   8, 
						BMN6,   8, 
						BMN7,   8, 
						BMN8,   8, 
						BMN9,   8, 
						BMNA,   8, 
						BMNB,   8, 
						BMNC,   8, 
						BMND,   8, 
						BMNE,   8, 
						BMNF,   8
					}

C, edit the exists code. (PS: you should click "Update tree" first, if you use DSDT Editor.)
//Store (SBMN, Index (Arg1, 0x0C))
	Store (L1L4 (B1B4 (BMN0, BMN1, BMN2, BMN3), B1B4 (BMN4, BMN5, 
								BMN6, BMN7), B1B4 (BMN8, BMN9, BMNA, BMNB), B1B4 (BMNC, BMND, BMNE, 
								BMNF)), Index (Arg1, 0x0C))

This code appears in the a little old laptop, but the way can be used by who get it. Credit @VIVXIX
More read here:http://bbs.pcbeta.com/viewthread-937628-1-1.html

#7
fc bayern

fc bayern

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 210 posts
  • Gender:Male
  • Location:Macedonia

@fc Bayern:
It works both 10.6.8 10.7.2 too, do you correct your dsdt ? i have test it under 10.6.8 turn out works with 8bit register.
@DarwinX mindlessmissy
Maybe some things you do wrong, i mean the code edit in the battery device, some registers are placed in other place not EC.

For those battery indicator percentage shows problem, maybe can take a look this:
In my case, also some other users get this phenomenon, it is like below:

Store (^^EC0.BDC0, BFC1)
under _BIF method, note the BDC0 is in the EC region, but BFC1 also exists both Field (ERAM, ByteAcc, Lock, Preserve) and the Field (GNVS, AnyAcc, Lock, Preserve), but the right place should be the latter. So, the right way is like this:
divide BFC1 into two 8bit register under Field (GNVS, AnyAcc, Lock, Preserve), ignore the BFC1 under EC.
 //BFC1,   16,  
 BFC0,   8,
 BFC1,   8,
--------------------------------------------------------
//Store (^^EC0.BDC0, BFC1)
 Store (^^EC0.SDC1, BFC1)
 Sleep (0x14)
 Store (^^EC0.SDC0, BFC0)

The _BST method part:
A:
 //If (BFC1)
 If (B1B2(BFC0,BFC1))
 
 B:
 // Multiply (BGU1,BFC1, Local2)
 Multiply (BGU1, B1B2(BFC0,BFC1), Local2)

This code appears in the a little old laptop, but the way can be used by who get it. Credit @VIVXIX


No, I havent modify my dsdt yet, I ll try later on but have doubts it will turn well out(You know dsdt hacking isnt easy and fun at all). What to modify - the lines You ve posted in the first post???

#8
Zprood

Zprood

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 251 posts
  • Gender:Male
  • Location:CHN

No, I havent modify my dsdt yet, I ll try later on but have doubts it will turn well out(You know dsdt hacking isnt easy and fun at all). What to modify - the lines You ve posted in the first post???

you just need to edit the code of battery part in the dsdt which includes the 16bit or higher register under EC region if you have, and change them as 8bit registesr.

#9
DarwinX

DarwinX

    InsanelyMac Legend

  • Members
  • PipPipPipPipPipPipPip
  • 615 posts
  • Gender:Male
  • Location:Florida

you just need to edit the code of battery part in the dsdt which includes the 16bit or higher register under EC region if you have, and change them as 8bit registesr.


As my ACPI coding expertise is simply non existent, would you mind taking a quick look at my DSDT.aml to see what I might have done wrong? :) Thank You.

Attached File  DarwinX.aml.zip   8.72KB   16 downloadsAttached File  DarwinX.ioreg.zip   380.57KB   12 downloads

#10
fc bayern

fc bayern

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 210 posts
  • Gender:Male
  • Location:Macedonia

you just need to edit the code of battery part in the dsdt which includes the 16bit or higher register under EC region if you have, and change them as 8bit registesr.


Zprood, here my dsdt:
Attached File  dsdt.aml.zip   24.4KB   42 downloads
I have tried but no success, can't find the proposed lines

Can You see it pls(no battery modification made)
Thanks

#11
Zprood

Zprood

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 251 posts
  • Gender:Male
  • Location:CHN
@DarwinX
Sorry about that, I don't know your dsdt structure much, can't help.
@fc Bayern
Try this:
Attached File  dsdt_fix.aml.zip   24.43KB   183 downloads

#12
robi62

robi62

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 264 posts
  • Gender:Male
  • Location:Javea Spain
@Zprood

I tried to add method Method (B1B2 to my dsdt.aml

but I get compile errors :D

This is my dsdt.aml

I could not find field ram in my dsdt to edit them

Attached File  dsdt.aml.zip   14.04KB   111 downloads

any help would be appreciated

or tell me what I have to edit

This is my ioreg battery is showing there only thing does not show in system info I get There was an error while gathering this information.

Attached File  mymac.zip   336.98KB   12 downloads

#13
Zprood

Zprood

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 251 posts
  • Gender:Male
  • Location:CHN

@Zprood

I tried to add method Method (B1B2 to my dsdt.aml

but I get compile errors :D

This is my dsdt.aml

I could not find field ram in my dsdt to edit them

Attached File  dsdt.aml.zip   14.04KB   111 downloads

any help would be appreciated

or tell me what I have to edit

I wanna help, but your dsdt is the same situation i have good understanding on it. Also it doesn't match the 8bit and 16bit issue, i can't see 16bit register in the dsdt. Sorry.

#14
robi62

robi62

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 264 posts
  • Gender:Male
  • Location:Javea Spain
Thanks anyway :D

To make it work in my case I had to revert to appleacpiplatform from snowleopard


and now I get battery info in system profiler


Battery Information:

Model Information:
Serial Number: 02A-Z080417000473Z
Manufacturer: Fujitsu
Device Name: CP345705-01
Charge Information:
The battery's charge is below the critical level.: No
The battery's charge is below the warning level.: No
Charge Remaining (mAh): 1630
Fully Charged: No
Charging: Yes
Full Charge Capacity (mAh): 5418
Health Information:
Cycle Count: 54
Condition: Normal
Battery Installed: Yes
Amperage (mA): 1674
Voltage (mV): 11310

System Power Settings:

AC Power:
System Sleep Timer (Minutes): 10
Disk Sleep Timer (Minutes): 10
Display Sleep Timer (Minutes): 10
Automatic Restart on Power Loss: No
Wake on Clamshell Open: Yes
Wake on LAN: Yes
Current Power Source: Yes
Display Sleep Uses Dim: Yes
PrioritizeNetworkReachabilityOverSleep: 0
RestartAfterKernelPanic: 157680000
Battery Power:
System Sleep Timer (Minutes): 3
Disk Sleep Timer (Minutes): 10
Display Sleep Timer (Minutes): 3
Wake on Clamshell Open: Yes
Display Sleep Uses Dim: Yes
Reduce Brightness: Yes
RestartAfterKernelPanic: 157680000

Until I figure how to amend my dsdt this is easy solution for me.....

#15
archintosh

archintosh

    InsanelyMac Protégé

  • Members
  • Pip
  • 37 posts
  • Gender:Male

More about the sources code, zenglg1977 combines gsly's AppleSmartBatteryManger code into whole project, then people get two choice. And weizh126 plays a trick about battery cycle count in the _BIF method part, the _BIF just contains 13 items in the package and he adds "Zero" to it become 14, and store the cycle count register info in it, it sounds illegal, but it works.


Thanx mate, I have tried this on my Lenovo G470 n' I have patched my DSDT. Batt is showing alright, info n' percentage are all okay. But I got 'Condition: Replace Now', what do I have to check?

Thanx

#16
Bungo

Bungo

    InsanelyMac Sage

  • Coders
  • 296 posts
  • Gender:Male
Thanks Zprood, good work. Testing on my Samsung, works very good

#17
fc bayern

fc bayern

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 210 posts
  • Gender:Male
  • Location:Macedonia
[/quote]
@fc Bayern
Try this:
Attached File  dsdt_fix.aml.zip   24.43KB   183 downloads
[/quote]

Thanks Zprood, You feed my dsdt into 8bit registry. it works with the Appleacpiplatform.kext from 10.7.2
Thanks on Your help, i appriciate that.
Keep on going this community.

#18
Zprood

Zprood

    InsanelyMac Sage

  • Members
  • PipPipPipPipPip
  • 251 posts
  • Gender:Male
  • Location:CHN

Thanx mate, I have tried this on my Lenovo G470 n' I have patched my DSDT. Batt is showing alright, info n' percentage are all okay. But I got 'Condition: Replace Now', what do I have to check?

Thanx

check your dsdt carefully, it might be something wrong with your editing. I also have lenovo laptop, you should take a look of 1# and 6#.

#19
alexkidd

alexkidd

    InsanelyMac Protégé

  • Members
  • Pip
  • 13 posts
hi Zprood. can you take a look at my dsdt? i can't find the parts to edit

thanks

Attached Files



#20
archintosh

archintosh

    InsanelyMac Protégé

  • Members
  • Pip
  • 37 posts
  • Gender:Male

check your dsdt carefully, it might be something wrong with your editing. I also have lenovo laptop, you should take a look of 1# and 6#.


Ok, I've checked my dsdt n' now 'Condition: Replace Now' is gone. But now my laptop won't sleep (sleep was working fine before). Can you please take a look at my dsdt? Here I attached 2 version of my dsdt, without 8-bit batt patches and with 8-bit batt patches.

Thanx

Attached Files







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy