Linux and batteries
Hi, this is 2nd part of our series on understanding the things that power our devices. This part will be dedicated to how the Linux kernel communicates with the physical battery.

The Linux Battery Subsystem
Contrary to what you might think, Linux does not communicate directly with the individual battery cells. Instead, it gets battery information through the laptop's Embedded Controller (EC).
On the hardware side, the battery pack contains a Smart Battery controller, a small microcontroller that monitors things like cell voltage, current, and temperature using built-in sensors. It communicates this information to the laptop, commonly through interfaces such as SMBus. Meanwhile, from the kernel, linux accesses this battery information through the system's ACPI and firmware interfaces, which may involve the EC. The kernel then converts the hardware-specific information into a standardized interface that software can use.
Linux exposes this information through the Sysfs Interface, specifically in the /sys/class/power_supply/BATx/ directory. Important files include:
energy_full_design: How much energy the battery could hold when it was new.energy_full: How much energy the battery can hold now. This slowly decreases as the battery gets older.energy_now: How much energy is currently left in the battery.cycle_count: How many charge cycles the battery has gone through, if the hardware reports it.voltage_now,current_now: The battery's current voltage and current.charge_control_start_thresholdandcharge_control_end_threshold: Lets supported laptops control when charging starts and stops.
Then finally, in the userspace, programs such as UPower read this information and use it to calculate the battery percentage and estimate remaining battery time. They then expose the information through D-Bus, allowing desktop environments such as GNOME and KDE to display it in their user interfaces.
TLP: Architecture and Battery Health Mechanisms
TLP is a Linux power management tool that automatically applies difference profiles of power usage depending on the source of power of your laptop, i.e. AC or battery connection. Not to be confused with Tehreek-e-Labbaik Pakistan since google seems to like it more, than the software.

Unlike tools which offer a GUI, TLP has a text conf file, which is mostly consistent with the culture of the neckbeards that I have come to love. It resides in the /etc directory with the name tlp.conf runs its settings automatically.
A. Charge Thresholds: Direct Battery Health Management
One of TLP's MOST useful features for battery health is charge thresholds. hinting back to the last article, a battery doesn't like to be fully charged, it damages its lifespan. This helps in exactly that. Instead of keeping the battery at 100%, you can tell the laptop to only charge within a specific range.
For example:
Start charging when the battery drops below 70%
Stop charging when it reaches 80%
Keeping a lithium-ion battery away from a constant 100% charge reduces voltage stress, which can slow down long-term battery degradation.
TLP uses settings such as:
START_CHARGE_THRESH_BAT0=70
STOP_CHARGE_THRESH_BAT0=80TLP itself does not physically control the battery. Instead, it sends the threshold values to interfaces provided by the laptop's hardware and Linux kernel. On supported modern laptops, these values are exposed through:
/sys/class/power_supply/BAT0/charge_control_start_threshold
/sys/class/power_supply/BAT0/charge_control_end_thresholdThe kernel then communicates with the laptop's firmware and battery controller to enforce the limits. Support depends on the laptop manufacturer and model, because naturally, battery hardware compatibility could not possibly be simple.
Battery Recalibration
TLP can also help recalibrate a battery's charge measurement.
Over time, the battery controller's estimate of the remaining capacity can become inaccurate. Recalibration performs a controlled full charge and discharge cycle, allowing the battery controller to measure the battery's actual capacity more accurately.
This does not repair or restore battery capacity. It only improves the accuracy of the reported battery percentage and capacity.
B. Power Management: Indirect Battery Health Benefits
TLP also reduces power consumption across different parts of the laptop. Lower power consumption generally means less heat, and excessive heat accelerates battery aging.
Some of the areas TLP can manage include:
- CPU: TLP can configure CPU power settings to prioritize efficiency while running on battery. This can reduce power consumption and heat generation.
- PCIe devices: TLP can enable PCIe Active State Power Management (ASPM), allowing devices such as NVMe drives and Wi-Fi cards to enter lower-power states when idle.
- USB devices: TLP can enable USB autosuspend, allowing idle USB devices to enter a low-power state.
- Storage devices: Depending on the hardware, TLP can configure power-saving features for SATA drives, NVMe SSDs, and mechanical hard drives.
- Audio and wireless devices: TLP can enable power-saving features for audio hardware and manage wireless devices such as Wi-Fi and Bluetooth.
These features do not directly change the battery's chemistry. Their benefit is indirect: using less power can produce less heat, which reduces one of the factors that accelerates battery degradation.
Hope you had fun learning this stuff and sorry if it was too dense and without any comic relief or images. Not many ways to spin this topic towards memes. ;)
Have fun and keep learning. byeeeee