drivers/power/supply/cpcap-charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/cpcap-charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/cpcap-charger.c- Extension
.c- Size
- 25429 bytes
- Lines
- 981
- 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/atomic.hlinux/init.hlinux/module.hlinux/slab.hlinux/string_choices.hlinux/err.hlinux/interrupt.hlinux/notifier.hlinux/mod_devicetable.hlinux/platform_device.hlinux/power_supply.hlinux/property.hlinux/regmap.hlinux/gpio/consumer.hlinux/usb/phy_companion.hlinux/phy/omap_usb.hlinux/usb/otg.hlinux/iio/consumer.hlinux/mfd/motorola-cpcap.h
Detected Declarations
struct cpcap_charger_ddatastruct cpcap_interrupt_descstruct cpcap_charger_ints_statefunction cpcap_charger_get_charge_voltagefunction cpcap_charger_get_charge_currentfunction cpcap_charger_get_propertyfunction cpcap_charger_match_voltagefunction cpcap_charger_get_bat_const_charge_voltagefunction cpcap_charger_current_to_regvalfunction cpcap_charger_set_propertyfunction cpcap_charger_property_is_writeablefunction cpcap_charger_set_cable_pathfunction cpcap_charger_set_inductive_pathfunction cpcap_charger_update_statefunction cpcap_charger_disablefunction cpcap_charger_enablefunction cpcap_charger_vbus_validfunction cpcap_charger_vbus_workfunction cpcap_charger_set_vbusfunction cpcap_charger_get_ints_statefunction cpcap_charger_voltage_to_regvalfunction cpcap_charger_disconnectfunction cpcap_usb_detectfunction cpcap_charger_irq_threadfunction cpcap_usb_init_irqfunction cpcap_usb_init_interruptsfunction cpcap_charger_init_optional_gpiosfunction cpcap_charger_init_iiofunction cpcap_charger_probefunction cpcap_charger_shutdownfunction cpcap_charger_remove
Annotated Snippet
struct cpcap_charger_ddata {
struct device *dev;
struct regmap *reg;
struct list_head irq_list;
struct delayed_work detect_work;
struct delayed_work vbus_work;
struct gpio_desc *gpio[2]; /* gpio_reven0 & 1 */
struct iio_channel *channels[CPCAP_CHARGER_IIO_NR];
struct power_supply *usb;
struct phy_companion comparator; /* For USB VBUS */
unsigned int vbus_enabled:1;
unsigned int feeding_vbus:1;
atomic_t active;
int status;
int voltage;
int limit_current;
};
struct cpcap_interrupt_desc {
int irq;
struct list_head node;
const char *name;
};
struct cpcap_charger_ints_state {
bool chrg_det;
bool rvrs_chrg;
bool vbusov;
bool chrg_se1b;
bool rvrs_mode;
bool chrgcurr2;
bool chrgcurr1;
bool vbusvld;
bool battdetb;
};
static enum power_supply_property cpcap_charger_props[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
};
static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)
{
struct iio_channel *channel;
int error, value = 0;
channel = ddata->channels[CPCAP_CHARGER_IIO_VOLTAGE];
error = iio_read_channel_processed(channel, &value);
if (error < 0) {
dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
return 0;
}
return value;
}
static int cpcap_charger_get_charge_current(struct cpcap_charger_ddata *ddata)
{
struct iio_channel *channel;
int error, value = 0;
channel = ddata->channels[CPCAP_CHARGER_IIO_CHRG_CURRENT];
error = iio_read_channel_processed(channel, &value);
if (error < 0) {
dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);
return 0;
}
return value;
}
static int cpcap_charger_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct cpcap_charger_ddata *ddata = dev_get_drvdata(psy->dev.parent);
switch (psp) {
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/init.h`, `linux/module.h`, `linux/slab.h`, `linux/string_choices.h`, `linux/err.h`, `linux/interrupt.h`, `linux/notifier.h`.
- Detected declarations: `struct cpcap_charger_ddata`, `struct cpcap_interrupt_desc`, `struct cpcap_charger_ints_state`, `function cpcap_charger_get_charge_voltage`, `function cpcap_charger_get_charge_current`, `function cpcap_charger_get_property`, `function cpcap_charger_match_voltage`, `function cpcap_charger_get_bat_const_charge_voltage`, `function cpcap_charger_current_to_regval`, `function cpcap_charger_set_property`.
- 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.