Battery Charging Monitoring and Control
Battery Charging Monitoring
The ACT8945A device driver exposes some charging information in the user space at /sys/devices/platform/ahb/ahb:apb/fc018000.flexcom/fc018600.i2c/i2c-0/0-005b/act8945a-charger/power_supply/act8945a-charger
.
Below is the list of all files provided, along with the API documentation quoted from Documentation/ABI/testing/sysfs-class-power
and a comment about how it applies to the ACT8945A driver specifically.
type:
Describes the main type of the supply. Access: Read Valid values: "Battery", "UPS", "Mains", "USB", "Wireless"
Supported values:
"Battery",
"Mains",
"USB"
status:
Represents the charging status of the battery. Normally this is read-only reporting although for some supplies this can be used to enable/disable charging to the battery. Access: Read, Write Valid values: "Unknown", "Charging", "Discharging", "Not charging", "Full"
The file is actually read only, the driver not allowing to control the charging phase. Supported values:
"Charging"
"Full"
"Discharging"
"Not charging"
capacity_level:
Coarse representation of battery capacity. Access: Read Valid values: "Unknown", "Critical", "Low", "Normal", "High", "Full"
All values are supported by the driver.
charge_type:
Represents the type of charging currently being applied to the battery. "Trickle", "Fast", and "Standard" all mean different charging speeds. "Adaptive" means that the charger uses some algorithm to adjust the charge rate dynamically, without any user configuration required. "Custom" means that the charger uses the charge_control_* properties as configuration for some different algorithm. "Long Life" means the charger reduces its charging rate in order to prolong the battery health. "Bypass" means the charger bypasses the charging path around the integrated converter allowing for a "smart" wall adaptor to perform the power conversion externally. Access: Read, Write Valid values: "Unknown", "N/A", "Trickle", "Fast", "Standard", "Adaptive", "Custom", "Long Life", "Bypass"
The file is actually read-only, driver not allowing to change the charging type. Supported values:
"N/A",
"Fast"
"Trickle"
"Unknown"
health:
Reports the health of the battery or battery side of charger functionality. Access: Read Valid values: "Unknown", "Good", "Overheat", "Dead", "Over voltage", "Unspecified failure", "Cold", "Watchdog timer expire", "Safety timer expire", "Over current", "Calibration required", "Warm", "Cool", "Hot", "No battery"
Supported values:
"Good"
"Over voltage"
"Safety timer expire"
"Overheat"
"Unknown"
current_max:
Battery: Reports the maximum IBAT current allowed into the battery. USB: Reports the maximum IBUS current the supply can support. Access: Read Valid values: Represented in microamps
In cases of
unplugged USB,
unplugged battery,
both battery and USB plugged, battery fully charged,
this value is always 0. Otherwise the charging current is given.
technology:
Describes the battery technology supported by the supply. Access: Read Valid values: "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd", "LiMn"
Always "Li-ion".
manufacturer:
Reports the name of the device manufacturer. Access: Read Valid values: Represented as string
Always "Active-semi".
model_name:
Reports the name of the device model. Access: Read Valid values: Represented as string
Always "ACT8945A"
Example
Real world values of some of the files in 3 different powering scenarios:
| Scenario 1 | Scenario 2 | Scenario 3 |
---|---|---|---|
USB | Plugged | Plugged | Unplugged |
Battery | Plugged | Unplugged | Plugged |
| Full | Normal | Critical |
| N/A | Unknown | N/A |
| Good | Overheat | Good |
| Full | Not charging | Discharging |
| Mains | Mains | Battery |
Battery Charging Control
Overview
The ACT8945A PMIC provides a couple of charging-related parameters which can be programmed dynamically. However, the device's driver doesn't allow to do this from the userspace. Instead a direct communication through I2C for reading/writing PMIC's registers must be carried out. Conclusive provides a bash script /opt/act8945a-i2c-api.sh
simplifying this task. See how to use it in detail with
root@kstr-sama5d27:~# /opt/act8945a-i2c-api.sh -h
All charging-related registers can be listed with:
root@kstr-sama5d27:~# /opt/act8945a-i2c-api.sh print pat APCH _
<output> <name>
APCH SUSCHG
APCH TOTTIMO
APCH PRETIMO
APCH OVPSET
APCH TIMRSTAT
APCH TEMPSTAT
APCH INSTAT
APCH CHGSTAT
APCH TIMRDAT
APCH TEMPDAT
APCH INDAT
APCH CHGDAT
APCH TIMRTOT
APCH TEMPIN
APCH INCON
APCH CHGEOCIN
APCH TIMRPRE
APCH TEMPOUT
APCH INDIS
APCH CHGEOCOUT
APCH CSTATE
APCH ACINSTAT
"APCH" stands for "Active Path Charging" and designates a specific registers group (named "output" in ACT8945A's nomenclature).
Of these the TIMRDAT
, TEMPDAT
, INDAT
, CHGDAT
, CSTATE
, ACINSTAT
registers are read-only and describe the powering and charging state, which is sufficiently covered by the built-in driver, and their state is reflected in sysfs.
Registers TIMRSTAT
, TEMPSTAT
, INSTAT
, CHGSTAT
, TIMRTOT
, TEMPIN
, INCON
, CHGEOCIN
, TIMRPRE
, TEMPOUT
, INDIS
, CHGEOCOUT
are all single-bit flags enabling interrupts related to various phases of the charging process. By default all of them are disabled.
The TOTTIMO
, PRETIMO
, OVPSET
registers control some charging parameters:
TOTTIMO | Total Charge Time-out |
PRETIMO | Precondition Charge Time-out |
OVPSET | Input Over-Voltage Protection Threshold |
Finally, SUSCHG
is a flag enabling/disabling charging of the battery.
For more details about these registers refer to the ACT8945A's datasheet.
Example: Disabling Charging
Assume the KSTR-SAMA5D27 board is connected to a host through USB and has a semi-discharged battery plugged in. Checking the charging status with
root@kstr-sama5d27:~# cat /sys/devices/platform/ahb/ahb:apb/fc018000.flexcom/fc018600.i2c/i2c-0/0-005b/act8945a-charger/power_supply/act8945a-charger/status
Charging
shows that the battery is charging. Reading the SUSCHG
("Suspend Charging") register confirms this
root@kstr-sama5d27:~# /opt/act8945a-i2c-api.sh get 0 pat APCH SUSCHG
<output> <name> Dec Hex
APCH SUSCHG 0 0x0
Value 0 means that the charging is not suspended. This can be changed with
root@kstr-sama5d27:~# /opt/act8945a-i2c-api.sh set 0 1 pat APCH SUSCHG
<output> <name> <value> Status
APCH SUSCHG 1 OK
The PMIC's state is reflected in sysfs:
cat /sys/devices/platform/ahb/ahb:apb/fc018000.flexcom/fc018600.i2c/i2c-0/0-005b/act8945a-charger/power_supply/act8945a-charger/status
Not charging