drivers/power/supply/twl6030_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/twl6030_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/twl6030_charger.c- Extension
.c- Size
- 16262 bytes
- Lines
- 582
- 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/init.hlinux/module.hlinux/slab.hlinux/err.hlinux/of.hlinux/bits.hlinux/platform_device.hlinux/interrupt.hlinux/mfd/twl.hlinux/power_supply.hlinux/notifier.hlinux/usb/otg.hlinux/iio/consumer.hlinux/devm-helpers.h
Detected Declarations
struct twl6030_charger_infostruct twl6030_charger_chip_datafunction twl6030_charger_readfunction twl6030_charger_writefunction twl6030_config_cinlimit_regfunction twl6030_enable_usbfunction twl6030_charger_wdgfunction twl6030_charger_interruptfunction twl6030_charger_usb_get_propertyfunction twl6030_charger_usb_set_propertyfunction twl6030_charger_usb_property_is_writeablefunction twl6030_charger_probe
Annotated Snippet
struct twl6030_charger_info {
struct device *dev;
struct power_supply *usb;
struct power_supply_battery_info *binfo;
struct work_struct work;
int irq_chg;
int input_current_limit;
struct iio_channel *channel_vusb;
struct delayed_work charger_monitor;
bool extended_current_range;
};
struct twl6030_charger_chip_data {
bool extended_current_range;
};
static int twl6030_charger_read(u8 reg, u8 *val)
{
return twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, val, reg);
}
static int twl6030_charger_write(u8 reg, u8 val)
{
return twl_i2c_write_u8(TWL_MODULE_MAIN_CHARGE, val, reg);
}
static int twl6030_config_cinlimit_reg(struct twl6030_charger_info *charger,
unsigned int ua)
{
if (ua >= 50000 && ua <= 750000) {
ua = (ua - 50000) / 50000;
} else if ((ua > 750000) && (ua <= 1500000) && charger->extended_current_range) {
ua = ((ua % 100000) ? 0x30 : 0x20) + ((ua - 100000) / 100000);
} else {
if (ua < 50000) {
dev_err(charger->dev, "invalid input current limit\n");
return -EINVAL;
}
/* This is no current limit */
ua = 0x0F;
}
return twl6030_charger_write(CHARGERUSB_CINLIMIT, ua);
}
/*
* rewriting all stuff here, resets to extremely conservative defaults were
* seen under some circumstances, like charge voltage to 3.5V
*/
static int twl6030_enable_usb(struct twl6030_charger_info *charger)
{
int ret;
ret = twl6030_charger_write(CHARGERUSB_VICHRG,
UA_TO_VICHRG(charger->binfo->constant_charge_current_max_ua));
if (ret < 0)
return ret;
ret = twl6030_charger_write(CONTROLLER_WDG, 0xff);
if (ret < 0)
return ret;
charger->input_current_limit = 500000;
ret = twl6030_config_cinlimit_reg(charger, charger->input_current_limit);
if (ret < 0)
return ret;
ret = twl6030_charger_write(CHARGERUSB_CINLIMIT, CHARGERUSB_CIN_LIMIT_500);
if (ret < 0)
return ret;
ret = twl6030_charger_write(CHARGERUSB_VOREG,
UV_TO_VOREG(charger->binfo->constant_charge_voltage_max_uv));
if (ret < 0)
return ret;
ret = twl6030_charger_write(CHARGERUSB_CTRL1, TERM);
if (ret < 0)
return ret;
if (charger->binfo->charge_term_current_ua != -EINVAL) {
ret = twl6030_charger_write(CHARGERUSB_CTRL2,
UA_TO_VITERM(charger->binfo->charge_term_current_ua));
if (ret < 0)
return ret;
}
return twl6030_charger_write(CONTROLLER_CTRL1, CONTROLLER_CTRL1_EN_CHARGER);
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/slab.h`, `linux/err.h`, `linux/of.h`, `linux/bits.h`, `linux/platform_device.h`, `linux/interrupt.h`.
- Detected declarations: `struct twl6030_charger_info`, `struct twl6030_charger_chip_data`, `function twl6030_charger_read`, `function twl6030_charger_write`, `function twl6030_config_cinlimit_reg`, `function twl6030_enable_usb`, `function twl6030_charger_wdg`, `function twl6030_charger_interrupt`, `function twl6030_charger_usb_get_property`, `function twl6030_charger_usb_set_property`.
- 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.