drivers/power/supply/twl4030_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/twl4030_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/twl4030_charger.c- Extension
.c- Size
- 29710 bytes
- Lines
- 1147
- 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/platform_device.hlinux/interrupt.hlinux/mfd/twl.hlinux/power_supply.hlinux/notifier.hlinux/usb/otg.hlinux/iio/consumer.h
Detected Declarations
struct twl4030_bcifunction Copyrightfunction twl4030_clear_setfunction twl4030_bci_readfunction twl4030_clear_set_boot_bcifunction twl4030bci_read_adc_valfunction regval2uafunction ua2regvalfunction twl4030_charger_update_currentfunction ACfunction twl4030_current_workerfunction twl4030_charger_enable_usbfunction twl4030_charger_enable_acfunction twl4030_charger_enable_backupfunction CHG_PRESfunction twl4030_bci_interruptfunction twl4030_bci_usb_workfunction twl4030_bci_usb_ncbfunction twl4030_bci_mode_storefunction twl4030_bci_mode_showfunction twl4030_charger_get_currentfunction twl4030bci_statefunction twl4030_bci_state_to_statusfunction twl4030_bci_get_propertyfunction twl4030_bci_set_propertyfunction twl4030_bci_property_is_writeablefunction twl4030_bci_parse_dtfunction twl4030_bci_parse_dtfunction twl4030_bci_probefunction twl4030_bci_remove
Annotated Snippet
struct twl4030_bci {
struct device *dev;
struct power_supply *ac;
struct power_supply *usb;
struct usb_phy *transceiver;
struct notifier_block usb_nb;
struct work_struct work;
int irq_chg;
int irq_bci;
int usb_enabled;
/*
* ichg_* and *_cur values in uA. If any are 'large', we set
* CGAIN to '1' which doubles the range for half the
* precision.
*/
unsigned int ichg_eoc, ichg_lo, ichg_hi;
unsigned int usb_cur, ac_cur;
struct iio_channel *channel_vac;
bool ac_is_active;
int usb_mode, ac_mode; /* charging mode requested */
#define CHARGE_OFF 0
#define CHARGE_AUTO 1
#define CHARGE_LINEAR 2
/* When setting the USB current we slowly increase the
* requested current until target is reached or the voltage
* drops below 4.75V. In the latter case we step back one
* step.
*/
unsigned int usb_cur_target;
struct delayed_work current_worker;
#define USB_CUR_STEP 20000 /* 20mA at a time */
#define USB_MIN_VOLT 4750000 /* 4.75V */
#define USB_CUR_DELAY msecs_to_jiffies(100)
#define USB_MAX_CURRENT 1700000 /* TWL4030 caps at 1.7A */
unsigned long event;
};
/* strings for 'usb_mode' values */
static const char *modes[] = { "off", "auto", "continuous" };
/*
* clear and set bits on an given register on a given module
*/
static int twl4030_clear_set(u8 mod_no, u8 clear, u8 set, u8 reg)
{
u8 val = 0;
int ret;
ret = twl_i2c_read_u8(mod_no, &val, reg);
if (ret)
return ret;
val &= ~clear;
val |= set;
return twl_i2c_write_u8(mod_no, val, reg);
}
static int twl4030_bci_read(u8 reg, u8 *val)
{
return twl_i2c_read_u8(TWL_MODULE_MAIN_CHARGE, val, reg);
}
static int twl4030_clear_set_boot_bci(u8 clear, u8 set)
{
return twl4030_clear_set(TWL_MODULE_PM_MASTER, clear,
TWL4030_CONFIG_DONE | TWL4030_BCIAUTOWEN | set,
TWL4030_PM_MASTER_BOOT_BCI);
}
static int twl4030bci_read_adc_val(u8 reg)
{
int ret, temp;
u8 val;
/* read MSB */
ret = twl4030_bci_read(reg + 1, &val);
if (ret)
return ret;
temp = (int)(val & 0x03) << 8;
/* read LSB */
ret = twl4030_bci_read(reg, &val);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/slab.h`, `linux/err.h`, `linux/of.h`, `linux/platform_device.h`, `linux/interrupt.h`, `linux/mfd/twl.h`.
- Detected declarations: `struct twl4030_bci`, `function Copyright`, `function twl4030_clear_set`, `function twl4030_bci_read`, `function twl4030_clear_set_boot_bci`, `function twl4030bci_read_adc_val`, `function regval2ua`, `function ua2regval`, `function twl4030_charger_update_current`, `function AC`.
- 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.