Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the kernel module responsible for /sys/class/power_supply/BAT0?

After twiddling LEDs with /sys/class/leds/, I'm now trying to understand how to control the battery in my computer with linux kernel power supply attributes, specifically CHARGE_CONTROL_LIMIT. However, no such attribute exists in /sys/class/power_supply/BAT0/.

How I've tried to answer this question:

From what I understand reading man 5 sysfs, sysfs (usually mounted as sys) is an interface between userspace and kernelspace.

Hypothesis:

  1. There exists a kernel module that creates and updates the contents of /sys/class/power_supply/BAT0/

  2. That kernel module may, but does not seem to implement CHARGE_CONTROL_LIMIT. It does implement other attributes:

cat /sys/class/power_supply/BAT0/charge_full     
2884000
cat /sys/class/power_supply/BAT0/charge_now 
2884000
cat /sys/class/power_supply/BAT0/cycle_count
0                                                 <--- this seems broken
cat /sys/class/power_supply/BAT0/capacity
100

To test this hypothesis, I sought the documentation/source of the responsible kernel module.

A hang-up: Trying to find the kernel module that's responsible for /sys/class/power_supply/BAT0/

ArchWiki and this page demonstrate how to look-up a kernel module, given a modalias.

cat /sys/class/power_supply/BAT0/device/modalias
acpi:PNP0C0A:

sudo grep -E 'PNP0C0A' /lib/modules/*/modules.alias
# nothing is found

I see that the battery hardware is of type acpi, however, there's no exact match for its modalias in modules.alias. (I tried a a few combinations of wildcards to find it, to no avail).

@0andriy suggested checking /drivers/platform/x86, which I did as follows:

find /lib/modules/5.0.0-15-generic/kernel -type f -name '*.ko' | xargs modinfo | grep -E 'alias.*PNP0C0A'
# Nothing

# Trying another query, to check that the query works:
find /lib/modules/5.0.0-15-generic/kernel/drivers -type f -name '*.ko' | xargs modinfo | grep -E 'alias.*TOS'
alias:          acpi*:TOS1900:*
alias:          acpi*:TOS6208:*
alias:          acpi*:TOS6207:*
alias:          acpi*:TOS6200:*

This is an HP laptop with a recent kernel

uname -a                                                                     
Linux lithium 5.0.0-15-generic #16-Ubuntu SMP Mon May 6 17:41:33 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
like image 817
RemarkableBucket Avatar asked Sep 16 '25 02:09

RemarkableBucket


1 Answers

The problem is that the power source may be from a module already statically linked to the kernel (not visible in lsmod or present in /lib/modules), rather than left as a standalone module. So:

A) check /sys/module first. This is a directory which contains entries for both dynamically linked (i.e. visible by lsmod) and statically linked ones. Check if you see a (probably lowercase) pnp* entry there.

B) if you do, and it's not in lsmod, you'll need the kernel sources. These can possibly be obtained from HP, but you can start with the stock sources (http://kernel.org) since there's a good chance this is in the mainline kernel.

C) Those /sys entries are created by code calling "power_supply_register". Try a brute force grep over all the modules, to see which matches. You can also do this over the Linux source tree (something like find . -type f | xargs grep power_supply_register, or grep -R, etc).

Whether or not you can mess with the charging limits, etc, is up to the module in question. Good luck finding it.

like image 137
Technologeeks Avatar answered Sep 17 '25 19:09

Technologeeks