Skip to content

Commit

Permalink
Fix and improve supplement info (acidanthera#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhen-zen committed Aug 13, 2020
1 parent da7d723 commit 460be0d
Show file tree
Hide file tree
Showing 13 changed files with 278 additions and 120 deletions.
82 changes: 61 additions & 21 deletions Docs/Battery Information Supplement.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,63 +13,99 @@ in `_BIF`, `_BIX` and `_BST`, but you still need to split them for proper readin
- [SSDT-BATS](https://github.com/acidanthera/VirtualSMC/blob/master/Docs/SSDT-BATS.dsl)

## Implementation
Required method (`CBIS`) for supplement infomation is under the same active battery device for `_BST` etc.,
and you can just append it to your battery's patched SSDT.
Required method (`CBIS`, `CBSS`) for supplement information is under the same active battery device for `_BST` etc.,
and you can just append them to your battery's patched SSDT.

The method wil return a package consisting of following information, currently all fields are 16-bit integer.
The methods wil return a package consisting of following information, currently all fields are 16-bit integer.

### Static Information `CBIS`

- Config (0x0)

### Config (0x0)
This number is used to indicate enabled information below by setting corresponding bit to 1.

Set calculator to programmer mode can help you a lot.

### ManufactureDate (0x1)
- ManufactureDate (0x1)

This data is in AppleSmartBattery format, while some battery manufacturer supplied same format in EC.

The number can be calculated using follow formula:

```
day + month << 5 + (year - 1980) << 9
```

- PackLotCode (0x2)

### PackLotCode (0x2)
This field seems to be empty on some Macbooks.

### PCBLotCode (0x3)
- PCBLotCode (0x3)

Same above.

### FirmwareVersion (0x4)
Fill it with corresponding EC fields.
- FirmwareVersion (0x4)

Fill it with corresponding EC fields, displayed as hex.

- HardwareVersion (0x5)

### HardwareVersion (0x5)
Same above.

### BatteryVersion (0x6)
- BatteryVersion (0x6)

Same above.

### Notice: an undefined field here!
### Dynamic Status `CBSS`

While index for dynamic status in config starts from 0x10, index in SSDT package still starts from 0.

- Temperature (0x10)

### Temperature (0x8)
This data is in AppleSmartBattery format, while some battery manufacturer supplied same format in EC.

The number can be calculated using follow formula:

```
celcius * 10 + 2731
Current issues:
```

Current issues (won't solve):

When battery's fully charged or not charging, temperature won't be updated since no ACPI polling happens.

### TimeToFull (0x9)
- TimeToFull (0x11)

If there's no such field in EC, ignore it and leave the calculation to SMCBatteryManger. Same for following fields.

Valid integer in minutes when charging, otherwise 0xFF.

### TimeToEmpty (0xa)
- TimeToEmpty (0x12)

Valid integer in minutes when discharging, otherwise 0.

### ChargeLevel (0xb)
- ChargeLevel (0x13)

0 - 100 for percentage.

### AverageRate (0xc)
Valid signed integer in mA.
- AverageRate (0x14)

Valid *signed* integer in mA. Double check if you have valid value since this bit will disable quickPoll.

- ChargingCurrent (0x15)

Valid integer in mA.

- ChargingVoltage (0x16)

Valid integer in mV.

## How to dump your EC fields
In windows, you can use [nbfc](https://github.com/hirschmann/nbfc/wiki/Probe-the-EC%27s-registers)
or [RWEverything](http://rweverything.com).
On macOS, you may try append a method to some known _QXX button and
[Enable ACPI Debugging](https://pikeralpha.wordpress.com/2013/12/23/enabling-acpi-debugging/).
Or here is another example using [OS-X-ACPI-Debug](https://github.com/RehabMan/OS-X-ACPI-Debug)
[Enable ACPI Debugging](https://pikeralpha.wordpress.com/2013/12/23/enabling-acpi-debugging/).
Or here is another example using [OS-X-ACPI-Debug](https://github.com/RehabMan/OS-X-ACPI-Debug).

```
Method (DBG0, 1, Serialized)
Expand All @@ -83,6 +119,7 @@ Method (DBG0, 1, Serialized)
}
}
```
Or there's an experimental driver [(YogaSMC)](https://github.com/zhen-zen/YogaSMC) to read EC fields.

## Special on IdeaPad laptops
This note is developed on EC layout of the Lenovo Yoga 900 series (same from 900 to C940), with battery-related
Expand Down Expand Up @@ -166,6 +203,9 @@ And other fields for those in interest

Offset (0x68),
BAPR, 16, // Percent / Charge Level
Offset (0x6E),
B1CC, 16, // ChargingCurrent
B1CV, 16, // ChargingVoltage
Offset (0x7E),
B1AR, 16, // Average Rate
Offset (0xA4),
Expand Down
63 changes: 43 additions & 20 deletions Docs/SSDT-BATS.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ DefinitionBlock ("", "SSDT", 2, "ACDT", "BATS", 0x00000000)
External (_SB_.PCI0.LPCB.H_EC.B1T2, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BAR1, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BAR2, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCC1, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCC2, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCL1, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCL2, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCV1, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCV2, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCW1, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BCW2, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.BMIH, FieldUnitObj)
Expand All @@ -30,16 +34,18 @@ DefinitionBlock ("", "SSDT", 2, "ACDT", "BATS", 0x00000000)
External (_SB_.PCI0.LPCB.H_EC.FUSL, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.HIDH, FieldUnitObj)
External (_SB_.PCI0.LPCB.H_EC.HIDL, FieldUnitObj)

External (\B1B2, MethodObj)

Scope (\_SB.PCI0.LPCB.H_EC.BAT1)
{
Method (CBIS, 0, Serialized)
{
Name (PKG1, Package (0x10)
Name (PKG1, Package (0x08)
{
// config
0x00001F7F,
// config, double check if you have valid AverageRate before
// fliping that bit to 0x007F007F since it will disable quickPoll
0x006F007F,
// ManufactureDate (0x1), AppleSmartBattery format
0xFFFFFFFF,
// PackLotCode (0x2)
Expand All @@ -53,38 +59,55 @@ DefinitionBlock ("", "SSDT", 2, "ACDT", "BATS", 0x00000000)
// BatteryVersion (0x6)
0xFFFFFFFF,
0xFFFFFFFF,
// Temperature (0x8), AppleSmartBattery format
})
// Check your _BST method for similiar condition of EC accessibility
If (ECAV)
{
PKG1 [One] = B1B2 (B1T1, B1T2)
PKG1 [0x02] = B1B2 (FUSL, FUSH)
PKG1 [0x03] = B1B2 (BMIL, BMIH)
PKG1 [0x04] = B1B2 (FMVL, FMVH)
PKG1 [0x05] = B1B2 (HIDL, HIDH)
PKG1 [0x06] = B1B2 (DAVL, DAVH)
}

Return (PKG1)
} // CBIS

Method (CBSS, 0, Serialized)
{
Name (PKG1, Package (0x08)
{
// Temperature (0x10), AppleSmartBattery format
0xFFFFFFFF,
// TimeToFull (0x9), minutes (0xFF)
// TimeToFull (0x11), minutes (0xFF)
0xFFFFFFFF,
// TimeToEmpty (0xa), minutes (0)
// TimeToEmpty (0x12), minutes (0)
0xFFFFFFFF,
// ChargeLevel (0xb), percentage
// ChargeLevel (0x13), percentage
0xFFFFFFFF,
// AverageRate (0xc), signed 16-bit integer
// AverageRate (0x14), mA (signed)
0xFFFFFFFF,
// ChargingCurrent (0x15), mA
0xFFFFFFFF,
// ChargingVoltage (0x16), mV
0xFFFFFFFF,
0xFFFFFFFF
})
// Check your _BST method for similiar condition of EC accessibility
If (ECAV)
{
PKG1 [One] = B1B2 (B1T1, B1T2)
PKG1 [0x02] = B1B2 (FUSL, FUSH)
PKG1 [0x03] = B1B2 (BMIL, BMIH)
PKG1 [0x04] = B1B2 (FMVL, FMVH)
PKG1 [0x05] = B1B2 (HIDL, HIDH)
PKG1 [0x06] = B1B2 (DAVL, DAVH)
PKG1 [0x08] = B1B2 (BTM1, BTM2)
PKG1 [0x09] = B1B2 (BCL1, BCL2)
PKG1 [0x0A] = B1B2 (BCW1, BCW2)
PKG1 [0x0B] = B1B2 (BPR1, BPR2)
PKG1 [0x0C] = B1B2 (BAR1, BAR2)
PKG1 [Zero] = B1B2 (BTM1, BTM2)
PKG1 [One] = B1B2 (BCL1, BCL2)
PKG1 [0x02] = B1B2 (BCW1, BCW2)
PKG1 [0x03] = B1B2 (BPR1, BPR2)
PKG1 [0x04] = B1B2 (BAR1, BAR2)
PKG1 [0x05] = B1B2 (BCC1, BCC2)
PKG1 [0x06] = B1B2 (BCV1, BCV2)
}

Return (PKG1)
} // CBIS
} // CBSS
} // BAT1
}
//EOF
2 changes: 0 additions & 2 deletions Docs/TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ BQD3
BQX1
BQX2
BQX3
CHBI
CHBV
D0IR
DPBR
HI0N
Expand Down
Loading

0 comments on commit 460be0d

Please sign in to comment.