Skip to content

diegojfer/kmod-cw2217b

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CW2217B Battery Fuel Gauge Linux Driver

Linux kernel driver for the Cellwise CW2217B battery fuel gauge IC. Communicates over I2C and exposes battery and mains data through the Linux power_supply subsystem.

Reported Properties

Property Unit Description
POWER_SUPPLY_PROP_PRESENT boolean Always reports battery as present
POWER_SUPPLY_PROP_STATUS enum Charging or discharging based on current direction
POWER_SUPPLY_PROP_CAPACITY % State of charge (0-100)
POWER_SUPPLY_PROP_VOLTAGE_NOW uV Battery voltage
POWER_SUPPLY_PROP_CURRENT_NOW uA Battery current (positive = charging)
POWER_SUPPLY_PROP_TEMP 0.1 C Battery temperature

The driver polls the CW2217B registers every 1 second via a delayed work queue.

Configuration

The sense resistor value is defined at the top of cw2217b.c:

#define CW2217B_RSENSE_MOHM (10)

Adjust this to match the sense resistor on your board (in milliohms).

Building

Requires kernel headers for the running kernel.

make

The compiled module will be at cw2217b.ko.

Loading / Unloading

sudo insmod cw2217b.ko
sudo rmmod cw2217b

The CW2217B must be registered as an I2C device on the appropriate bus. For example, via a device tree overlay or manual instantiation:

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2711", "brcm,bcm2712", "brcm,bcm2835";

    fragment@0 {
        target = <&i2c1>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            cw2217b: cw2217b@64 {
                reg = <0x64>;
                compatible = "cellwise,cw2217b";
            };
        };
    };
};
echo cw2217b 0x64 | sudo tee /sys/bus/i2c/devices/i2c-1/new_device
echo 0x64 | sudo tee /sys/bus/i2c/devices/i2c-1/delete_device

Once loaded, battery data is available under /sys/class/power_supply/BAT0/.

Cleaning

make clean

License

GPL License

About

Cellwise CW2217 I2C battery fuel gauge driver with Linux power_supply support

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors