drivers/power/supply/lp8727_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/lp8727_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/lp8727_charger.c- Extension
.c- Size
- 14074 bytes
- Lines
- 606
- 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/module.hlinux/slab.hlinux/interrupt.hlinux/i2c.hlinux/power_supply.hlinux/platform_data/lp8727.hlinux/of.h
Detected Declarations
struct lp8727_psystruct lp8727_chgenum lp8727_dev_idenum lp8727_die_tempfunction lp8727_read_bytesfunction lp8727_read_bytefunction lp8727_write_bytefunction lp8727_is_charger_attachedfunction lp8727_init_devicefunction lp8727_is_dedicated_chargerfunction lp8727_is_usb_chargerfunction lp8727_ctrl_switchfunction lp8727_id_detectionfunction lp8727_enable_chgdetfunction lp8727_delayed_funcfunction lp8727_isr_funcfunction lp8727_setup_irqfunction lp8727_release_irqfunction lp8727_charger_get_propertyfunction lp8727_is_high_temperaturefunction lp8727_battery_get_propertyfunction lp8727_charger_changedfunction lp8727_register_psyfunction for_each_child_of_nodefunction lp8727_probefunction lp8727_remove
Annotated Snippet
struct lp8727_psy {
struct power_supply *ac;
struct power_supply *usb;
struct power_supply *batt;
};
struct lp8727_chg {
struct device *dev;
struct i2c_client *client;
struct mutex xfer_lock;
struct lp8727_psy *psy;
struct lp8727_platform_data *pdata;
/* Charger Data */
enum lp8727_dev_id devid;
struct lp8727_chg_param *chg_param;
/* Interrupt Handling */
int irq;
struct delayed_work work;
unsigned long debounce_jiffies;
};
static int lp8727_read_bytes(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len)
{
s32 ret;
mutex_lock(&pchg->xfer_lock);
ret = i2c_smbus_read_i2c_block_data(pchg->client, reg, len, data);
mutex_unlock(&pchg->xfer_lock);
return (ret != len) ? -EIO : 0;
}
static inline int lp8727_read_byte(struct lp8727_chg *pchg, u8 reg, u8 *data)
{
return lp8727_read_bytes(pchg, reg, data, 1);
}
static int lp8727_write_byte(struct lp8727_chg *pchg, u8 reg, u8 data)
{
int ret;
mutex_lock(&pchg->xfer_lock);
ret = i2c_smbus_write_byte_data(pchg->client, reg, data);
mutex_unlock(&pchg->xfer_lock);
return ret;
}
static bool lp8727_is_charger_attached(const char *name, int id)
{
if (!strcmp(name, "ac"))
return id == LP8727_ID_TA || id == LP8727_ID_DEDICATED_CHG;
else if (!strcmp(name, "usb"))
return id == LP8727_ID_USB_CHG;
return id >= LP8727_ID_TA && id <= LP8727_ID_USB_CHG;
}
static int lp8727_init_device(struct lp8727_chg *pchg)
{
u8 val;
int ret;
u8 intstat[LP8788_NUM_INTREGS];
/* clear interrupts */
ret = lp8727_read_bytes(pchg, LP8727_INT1, intstat, LP8788_NUM_INTREGS);
if (ret)
return ret;
val = LP8727_ID200_EN | LP8727_ADC_EN | LP8727_CP_EN;
ret = lp8727_write_byte(pchg, LP8727_CTRL1, val);
if (ret)
return ret;
val = LP8727_INT_EN | LP8727_CHGDET_EN;
return lp8727_write_byte(pchg, LP8727_CTRL2, val);
}
static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg)
{
u8 val;
lp8727_read_byte(pchg, LP8727_STATUS1, &val);
return val & LP8727_DCPORT;
}
static int lp8727_is_usb_charger(struct lp8727_chg *pchg)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/interrupt.h`, `linux/i2c.h`, `linux/power_supply.h`, `linux/platform_data/lp8727.h`, `linux/of.h`.
- Detected declarations: `struct lp8727_psy`, `struct lp8727_chg`, `enum lp8727_dev_id`, `enum lp8727_die_temp`, `function lp8727_read_bytes`, `function lp8727_read_byte`, `function lp8727_write_byte`, `function lp8727_is_charger_attached`, `function lp8727_init_device`, `function lp8727_is_dedicated_charger`.
- 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.