drivers/power/supply/da9052-battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/da9052-battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/da9052-battery.c- Extension
.c- Size
- 15419 bytes
- Lines
- 662
- 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/delay.hlinux/freezer.hlinux/fs.hlinux/jiffies.hlinux/module.hlinux/timer.hlinux/uaccess.hlinux/platform_device.hlinux/power_supply.hlinux/mfd/da9052/da9052.hlinux/mfd/da9052/pdata.hlinux/mfd/da9052/reg.h
Detected Declarations
struct da9052_batteryenum charger_type_enumfunction volt_reg_to_mVfunction ichg_reg_to_mAfunction da9052_read_chgend_currentfunction da9052_read_chg_currentfunction da9052_bat_check_statusfunction da9052_bat_read_voltfunction da9052_bat_check_presencefunction da9052_bat_interpolatefunction da9052_determine_vc_tbl_indexfunction da9052_bat_read_capacityfunction da9052_bat_check_healthfunction da9052_bat_irqfunction da9052_USB_current_notifierfunction da9052_bat_get_propertyfunction da9052_bat_probefunction da9052_bat_remove
Annotated Snippet
struct da9052_battery {
struct da9052 *da9052;
struct power_supply *psy;
struct notifier_block nb;
int charger_type;
int status;
int health;
};
static inline int volt_reg_to_mV(int value)
{
return ((value * 1000) / 512) + 2500;
}
static inline int ichg_reg_to_mA(int value)
{
return (value * 3900) / 1000;
}
static int da9052_read_chgend_current(struct da9052_battery *bat,
int *current_mA)
{
int ret;
if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING)
return -EINVAL;
ret = da9052_reg_read(bat->da9052, DA9052_ICHG_END_REG);
if (ret < 0)
return ret;
*current_mA = ichg_reg_to_mA(ret & DA9052_ICHGEND_ICHGEND);
return 0;
}
static int da9052_read_chg_current(struct da9052_battery *bat, int *current_mA)
{
int ret;
if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING)
return -EINVAL;
ret = da9052_reg_read(bat->da9052, DA9052_ICHG_AV_REG);
if (ret < 0)
return ret;
*current_mA = ichg_reg_to_mA(ret & DA9052_ICHGAV_ICHGAV);
return 0;
}
static int da9052_bat_check_status(struct da9052_battery *bat, int *status)
{
u8 v[2] = {0, 0};
u8 bat_status;
u8 chg_end;
int ret;
int chg_current;
int chg_end_current;
bool dcinsel;
bool dcindet;
bool vbussel;
bool vbusdet;
bool dc;
bool vbus;
ret = da9052_group_read(bat->da9052, DA9052_STATUS_A_REG, 2, v);
if (ret < 0)
return ret;
bat_status = v[0];
chg_end = v[1];
dcinsel = bat_status & DA9052_STATUSA_DCINSEL;
dcindet = bat_status & DA9052_STATUSA_DCINDET;
vbussel = bat_status & DA9052_STATUSA_VBUSSEL;
vbusdet = bat_status & DA9052_STATUSA_VBUSDET;
dc = dcinsel && dcindet;
vbus = vbussel && vbusdet;
/* Preference to WALL(DCIN) charger unit */
if (dc || vbus) {
bat->charger_type = DA9052_CHARGER;
/* If charging end flag is set and Charging current is greater
* than charging end limit then battery is charging
*/
if ((chg_end & DA9052_STATUSB_CHGEND) != 0) {
ret = da9052_read_chg_current(bat, &chg_current);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/freezer.h`, `linux/fs.h`, `linux/jiffies.h`, `linux/module.h`, `linux/timer.h`, `linux/uaccess.h`, `linux/platform_device.h`.
- Detected declarations: `struct da9052_battery`, `enum charger_type_enum`, `function volt_reg_to_mV`, `function ichg_reg_to_mA`, `function da9052_read_chgend_current`, `function da9052_read_chg_current`, `function da9052_bat_check_status`, `function da9052_bat_read_volt`, `function da9052_bat_check_presence`, `function da9052_bat_interpolate`.
- 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.