drivers/power/supply/lp8788-charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/lp8788-charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/lp8788-charger.c- Extension
.c- Size
- 18003 bytes
- Lines
- 730
- 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/err.hlinux/iio/consumer.hlinux/interrupt.hlinux/irqdomain.hlinux/mfd/lp8788.hlinux/module.hlinux/platform_device.hlinux/power_supply.hlinux/slab.hlinux/workqueue.h
Detected Declarations
struct lp8788_chg_irqstruct lp8788_chargerenum lp8788_charging_stateenum lp8788_charger_adc_selenum lp8788_charger_input_statefunction lp8788_is_charger_detectedfunction lp8788_charger_get_propertyfunction lp8788_get_battery_statusfunction lp8788_get_battery_healthfunction lp8788_get_battery_presentfunction lp8788_get_vbatt_adcfunction lp8788_get_battery_voltagefunction lp8788_get_battery_capacityfunction lp8788_get_battery_temperaturefunction lp8788_get_battery_charging_currentfunction lp8788_get_charging_termination_voltagefunction lp8788_battery_get_propertyfunction lp8788_is_valid_charger_registerfunction lp8788_update_charger_paramsfunction lp8788_charger_eventfunction lp8788_find_irq_idfunction lp8788_charger_irq_threadfunction lp8788_set_irqsfunction lp8788_irq_registerfunction lp8788_irq_unregisterfunction lp8788_setup_adc_channelfunction lp8788_show_charger_statusfunction lp8788_show_eoc_timefunction lp8788_show_eoc_levelfunction lp8788_psy_registerfunction lp8788_charger_probefunction lp8788_charger_remove
Annotated Snippet
struct lp8788_chg_irq {
enum lp8788_int_id which;
int virq;
};
/*
* struct lp8788_charger
* @lp : used for accessing the registers of mfd lp8788 device
* @charger : power supply driver for the battery charger
* @battery : power supply driver for the battery
* @charger_work : work queue for charger input interrupts
* @chan : iio channels for getting adc values
* eg) battery voltage, capacity and temperature
* @irqs : charger dedicated interrupts
* @num_irqs : total numbers of charger interrupts
* @pdata : charger platform specific data
*/
struct lp8788_charger {
struct lp8788 *lp;
struct power_supply *charger;
struct power_supply *battery;
struct work_struct charger_work;
struct iio_channel *chan[LP8788_NUM_CHG_ADC];
struct lp8788_chg_irq irqs[LP8788_MAX_CHG_IRQS];
int num_irqs;
struct lp8788_charger_platform_data *pdata;
};
static char *battery_supplied_to[] = {
LP8788_BATTERY_NAME,
};
static enum power_supply_property lp8788_charger_prop[] = {
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_CURRENT_MAX,
};
static enum power_supply_property lp8788_battery_prop[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_TEMP,
};
static bool lp8788_is_charger_detected(struct lp8788_charger *pchg)
{
u8 data;
lp8788_read_byte(pchg->lp, LP8788_CHG_STATUS, &data);
data &= LP8788_CHG_INPUT_STATE_M;
return data == LP8788_SYSTEM_SUPPLY || data == LP8788_FULL_FUNCTION;
}
static int lp8788_charger_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct lp8788_charger *pchg = dev_get_drvdata(psy->dev.parent);
u8 read;
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
val->intval = lp8788_is_charger_detected(pchg);
break;
case POWER_SUPPLY_PROP_CURRENT_MAX:
lp8788_read_byte(pchg->lp, LP8788_CHG_IDCIN, &read);
val->intval = LP8788_ISEL_STEP *
(min_t(int, read, LP8788_ISEL_MAX) + 1);
break;
default:
return -EINVAL;
}
return 0;
}
static int lp8788_get_battery_status(struct lp8788_charger *pchg,
union power_supply_propval *val)
{
enum lp8788_charging_state state;
u8 data;
int ret;
ret = lp8788_read_byte(pchg->lp, LP8788_CHG_STATUS, &data);
if (ret)
Annotation
- Immediate include surface: `linux/err.h`, `linux/iio/consumer.h`, `linux/interrupt.h`, `linux/irqdomain.h`, `linux/mfd/lp8788.h`, `linux/module.h`, `linux/platform_device.h`, `linux/power_supply.h`.
- Detected declarations: `struct lp8788_chg_irq`, `struct lp8788_charger`, `enum lp8788_charging_state`, `enum lp8788_charger_adc_sel`, `enum lp8788_charger_input_state`, `function lp8788_is_charger_detected`, `function lp8788_charger_get_property`, `function lp8788_get_battery_status`, `function lp8788_get_battery_health`, `function lp8788_get_battery_present`.
- 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.