drivers/power/supply/pm8916_bms_vm.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/pm8916_bms_vm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/pm8916_bms_vm.c- Extension
.c- Size
- 8524 bytes
- Lines
- 306
- Domain
- Driver Families
- Bucket
- drivers/power
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hlinux/module.hlinux/platform_device.hlinux/power_supply.hlinux/property.hlinux/regmap.hlinux/slab.hlinux/delay.hlinux/interrupt.hlinux/timekeeping.hlinux/mod_devicetable.h
Detected Declarations
struct pm8916_bms_vm_batteryfunction pm8916_bms_vm_battery_get_propertyfunction pm8916_bms_vm_fifo_update_done_irqfunction pm8916_bms_vm_battery_probefunction pm8916_bms_vm_battery_suspendfunction pm8916_bms_vm_battery_resume
Annotated Snippet
struct pm8916_bms_vm_battery {
struct device *dev;
struct power_supply *battery;
struct power_supply_battery_info *info;
struct regmap *regmap;
unsigned int reg;
unsigned int last_ocv;
time64_t last_ocv_time;
unsigned int vbat_now;
};
static int pm8916_bms_vm_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct pm8916_bms_vm_battery *bat = power_supply_get_drvdata(psy);
struct power_supply_battery_info *info = bat->info;
int supplied;
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
supplied = power_supply_am_i_supplied(psy);
if (supplied < 0 && supplied != -ENODEV)
return supplied;
else if (supplied && supplied != -ENODEV)
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
return 0;
case POWER_SUPPLY_PROP_HEALTH:
if (bat->vbat_now < info->voltage_min_design_uv)
val->intval = POWER_SUPPLY_HEALTH_DEAD;
else if (bat->vbat_now > info->voltage_max_design_uv)
val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
else
val->intval = POWER_SUPPLY_HEALTH_GOOD;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval = bat->vbat_now;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_OCV:
/*
* Hardware only reliably measures OCV when the system is off or suspended.
* We expose the last known OCV value on boot, invalidating it after 180 seconds.
*/
if (ktime_get_seconds() - bat->last_ocv_time > 180)
return -ENODATA;
val->intval = bat->last_ocv;
return 0;
default:
return -EINVAL;
}
}
static enum power_supply_property pm8916_bms_vm_battery_properties[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_VOLTAGE_OCV,
POWER_SUPPLY_PROP_HEALTH,
};
static irqreturn_t pm8916_bms_vm_fifo_update_done_irq(int irq, void *data)
{
struct pm8916_bms_vm_battery *bat = data;
u16 vbat_data[PM8916_BMS_VM_FIFO_COUNT];
int ret;
ret = regmap_bulk_read(bat->regmap, bat->reg + PM8916_BMS_VM_BMS_FIFO_REG_0_LSB,
&vbat_data, PM8916_BMS_VM_FIFO_COUNT * 2);
if (ret)
return IRQ_HANDLED;
/*
* The VM-BMS hardware only collects voltage data and the software
* has to process it to calculate the OCV and SoC. Hardware provides
* up to 8 averaged measurements for software to take in account.
*
* Just use the last measured value for now to report the current
* battery voltage.
*/
bat->vbat_now = vbat_data[PM8916_BMS_VM_FIFO_COUNT - 1] * 300;
power_supply_changed(bat->battery);
Annotation
- Immediate include surface: `linux/errno.h`, `linux/module.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/property.h`, `linux/regmap.h`, `linux/slab.h`, `linux/delay.h`.
- Detected declarations: `struct pm8916_bms_vm_battery`, `function pm8916_bms_vm_battery_get_property`, `function pm8916_bms_vm_fifo_update_done_irq`, `function pm8916_bms_vm_battery_probe`, `function pm8916_bms_vm_battery_suspend`, `function pm8916_bms_vm_battery_resume`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.