drivers/power/supply/cpcap-battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/cpcap-battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/cpcap-battery.c- Extension
.c- Size
- 32409 bytes
- Lines
- 1209
- 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/delay.hlinux/err.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/reboot.hlinux/regmap.hlinux/nvmem-consumer.hlinux/moduleparam.hlinux/iio/consumer.hlinux/iio/types.hlinux/mfd/motorola-cpcap.h
Detected Declarations
struct cpcap_interrupt_descstruct cpcap_battery_configstruct cpcap_coulomb_counter_datastruct cpcap_battery_state_datastruct cpcap_battery_ddataenum cpcap_battery_irq_actionenum cpcap_battery_statefunction cpcap_battery_get_statefunction cpcap_battery_latestfunction cpcap_battery_previousfunction cpcap_battery_get_emptyfunction cpcap_battery_get_fullfunction cpcap_charger_battery_temperaturefunction cpcap_battery_get_voltagefunction cpcap_battery_get_currentfunction data_get_avg_curr_uafunction cpcap_battery_cc_to_uahfunction cpcap_battery_cc_to_uafunction data_read_regsfunction cpcap_battery_match_nvmemfunction cpcap_battery_update_battery_datafunction cpcap_battery_detect_battery_typefunction cpcap_battery_cc_get_avg_currentfunction cpcap_battery_get_charger_statusfunction cpcap_battery_fullfunction cpcap_battery_lowfunction cpcap_battery_update_statusfunction cpcap_battery_external_power_changedfunction cpcap_battery_get_propertyfunction cpcap_battery_update_chargerfunction cpcap_battery_set_propertyfunction cpcap_battery_property_is_writeablefunction cpcap_battery_irq_threadfunction list_for_each_entryfunction cpcap_battery_init_irqfunction cpcap_battery_init_interruptsfunction cpcap_battery_init_iiofunction cpcap_battery_calibratefunction cpcap_battery_probefunction cpcap_battery_remove
Annotated Snippet
struct cpcap_interrupt_desc {
const char *name;
struct list_head node;
int irq;
enum cpcap_battery_irq_action action;
};
struct cpcap_battery_config {
int cd_factor;
struct power_supply_info info;
struct power_supply_battery_info bat;
};
struct cpcap_coulomb_counter_data {
s32 sample; /* 24 or 32 bits */
s32 accumulator;
s16 offset; /* 9 bits */
s16 integrator; /* 13 or 16 bits */
};
enum cpcap_battery_state {
CPCAP_BATTERY_STATE_PREVIOUS,
CPCAP_BATTERY_STATE_LATEST,
CPCAP_BATTERY_STATE_EMPTY,
CPCAP_BATTERY_STATE_FULL,
CPCAP_BATTERY_STATE_NR,
};
struct cpcap_battery_state_data {
int voltage;
int current_ua;
int counter_uah;
int temperature;
ktime_t time;
struct cpcap_coulomb_counter_data cc;
};
struct cpcap_battery_ddata {
struct device *dev;
struct regmap *reg;
struct list_head irq_list;
struct iio_channel *channels[CPCAP_BATTERY_IIO_NR];
struct power_supply *psy;
struct cpcap_battery_config config;
struct cpcap_battery_state_data state[CPCAP_BATTERY_STATE_NR];
u32 cc_lsb; /* μAms per LSB */
atomic_t active;
int charge_full;
int status;
u16 vendor;
bool check_nvmem;
unsigned int is_full:1;
};
#define CPCAP_NO_BATTERY -400
static bool ignore_temperature_probe;
module_param(ignore_temperature_probe, bool, 0660);
static struct cpcap_battery_state_data *
cpcap_battery_get_state(struct cpcap_battery_ddata *ddata,
enum cpcap_battery_state state)
{
if (state >= CPCAP_BATTERY_STATE_NR)
return NULL;
return &ddata->state[state];
}
static struct cpcap_battery_state_data *
cpcap_battery_latest(struct cpcap_battery_ddata *ddata)
{
return cpcap_battery_get_state(ddata, CPCAP_BATTERY_STATE_LATEST);
}
static struct cpcap_battery_state_data *
cpcap_battery_previous(struct cpcap_battery_ddata *ddata)
{
return cpcap_battery_get_state(ddata, CPCAP_BATTERY_STATE_PREVIOUS);
}
static struct cpcap_battery_state_data *
cpcap_battery_get_empty(struct cpcap_battery_ddata *ddata)
{
return cpcap_battery_get_state(ddata, CPCAP_BATTERY_STATE_EMPTY);
}
static struct cpcap_battery_state_data *
cpcap_battery_get_full(struct cpcap_battery_ddata *ddata)
{
Annotation
- Immediate include surface: `linux/delay.h`, `linux/err.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/power_supply.h`.
- Detected declarations: `struct cpcap_interrupt_desc`, `struct cpcap_battery_config`, `struct cpcap_coulomb_counter_data`, `struct cpcap_battery_state_data`, `struct cpcap_battery_ddata`, `enum cpcap_battery_irq_action`, `enum cpcap_battery_state`, `function cpcap_battery_get_state`, `function cpcap_battery_latest`, `function cpcap_battery_previous`.
- 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.