drivers/power/supply/88pm860x_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/88pm860x_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/88pm860x_battery.c- Extension
.c- Size
- 25762 bytes
- Lines
- 1017
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kernel.hlinux/module.hlinux/platform_device.hlinux/slab.hlinux/mutex.hlinux/string.hlinux/power_supply.hlinux/string_choices.hlinux/mfd/88pm860x.hlinux/delay.h
Detected Declarations
struct pm860x_battery_infostruct ccntfunction measure_12bit_voltagefunction measure_vbattfunction measure_currentfunction set_charger_currentfunction read_ccntfunction calc_ccntfunction clear_ccntfunction calc_ocvfunction calc_socfunction pm860x_coulomb_handlerfunction pm860x_batt_handlerfunction pm860x_init_batteryfunction set_temp_thresholdfunction measure_tempfunction calc_resistorfunction calc_capacityfunction pm860x_external_power_changedfunction pm860x_batt_get_propfunction pm860x_batt_set_propfunction pm860x_battery_probefunction pm860x_battery_suspendfunction pm860x_battery_resume
Annotated Snippet
struct pm860x_battery_info {
struct pm860x_chip *chip;
struct i2c_client *i2c;
struct device *dev;
struct power_supply *battery;
struct mutex lock;
int status;
int irq_cc;
int irq_batt;
int max_capacity;
int resistor; /* Battery Internal Resistor */
int last_capacity;
int start_soc;
unsigned present:1;
unsigned temp_type:1; /* TINT or TBAT */
};
struct ccnt {
unsigned long long pos;
unsigned long long neg;
unsigned int spos;
unsigned int sneg;
int total_chg; /* mAh(3.6C) */
int total_dischg; /* mAh(3.6C) */
};
/*
* State of Charge.
* The first number is mAh(=3.6C), and the second number is percent point.
*/
static int array_soc[][2] = {
{4170, 100}, {4154, 99}, {4136, 98}, {4122, 97}, {4107, 96},
{4102, 95}, {4088, 94}, {4081, 93}, {4070, 92}, {4060, 91},
{4053, 90}, {4044, 89}, {4035, 88}, {4028, 87}, {4019, 86},
{4013, 85}, {4006, 84}, {3995, 83}, {3987, 82}, {3982, 81},
{3976, 80}, {3968, 79}, {3962, 78}, {3954, 77}, {3946, 76},
{3941, 75}, {3934, 74}, {3929, 73}, {3922, 72}, {3916, 71},
{3910, 70}, {3904, 69}, {3898, 68}, {3892, 67}, {3887, 66},
{3880, 65}, {3874, 64}, {3868, 63}, {3862, 62}, {3854, 61},
{3849, 60}, {3843, 59}, {3840, 58}, {3833, 57}, {3829, 56},
{3824, 55}, {3818, 54}, {3815, 53}, {3810, 52}, {3808, 51},
{3804, 50}, {3801, 49}, {3798, 48}, {3796, 47}, {3792, 46},
{3789, 45}, {3785, 44}, {3784, 43}, {3782, 42}, {3780, 41},
{3777, 40}, {3776, 39}, {3774, 38}, {3772, 37}, {3771, 36},
{3769, 35}, {3768, 34}, {3764, 33}, {3763, 32}, {3760, 31},
{3760, 30}, {3754, 29}, {3750, 28}, {3749, 27}, {3744, 26},
{3740, 25}, {3734, 24}, {3732, 23}, {3728, 22}, {3726, 21},
{3720, 20}, {3716, 19}, {3709, 18}, {3703, 17}, {3698, 16},
{3692, 15}, {3683, 14}, {3675, 13}, {3670, 12}, {3665, 11},
{3661, 10}, {3649, 9}, {3637, 8}, {3622, 7}, {3609, 6},
{3580, 5}, {3558, 4}, {3540, 3}, {3510, 2}, {3429, 1},
};
static struct ccnt ccnt_data;
/*
* register 1 bit[7:0] -- bit[11:4] of measured value of voltage
* register 0 bit[3:0] -- bit[3:0] of measured value of voltage
*/
static int measure_12bit_voltage(struct pm860x_battery_info *info,
int offset, int *data)
{
unsigned char buf[2];
int ret;
ret = pm860x_bulk_read(info->i2c, offset, 2, buf);
if (ret < 0)
return ret;
*data = ((buf[0] & 0xff) << 4) | (buf[1] & 0x0f);
/* V_MEAS(mV) = data * 1.8 * 1000 / (2^12) */
*data = ((*data & 0xfff) * 9 * 25) >> 9;
return 0;
}
static int measure_vbatt(struct pm860x_battery_info *info, int state,
int *data)
{
unsigned char buf[5];
int ret;
switch (state) {
case OCV_MODE_ACTIVE:
ret = measure_12bit_voltage(info, PM8607_VBAT_MEAS1, data);
if (ret)
return ret;
/* V_BATT_MEAS(mV) = value * 3 * 1.8 * 1000 / (2^12) */
*data *= 3;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/platform_device.h`, `linux/slab.h`, `linux/mutex.h`, `linux/string.h`, `linux/power_supply.h`, `linux/string_choices.h`.
- Detected declarations: `struct pm860x_battery_info`, `struct ccnt`, `function measure_12bit_voltage`, `function measure_vbatt`, `function measure_current`, `function set_charger_current`, `function read_ccnt`, `function calc_ccnt`, `function clear_ccnt`, `function calc_ocv`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.