drivers/power/supply/bq2415x_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/bq2415x_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/bq2415x_charger.c- Extension
.c- Size
- 47560 bytes
- Lines
- 1812
- 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.
- 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/kernel.hlinux/module.hlinux/param.hlinux/err.hlinux/workqueue.hlinux/sysfs.hlinux/platform_device.hlinux/power_supply.hlinux/idr.hlinux/i2c.hlinux/slab.hlinux/acpi.hlinux/power/bq2415x_charger.h
Detected Declarations
struct bq2415x_deviceenum bq2415x_commandenum bq2415x_chipfunction bq2415x_i2c_readfunction bq2415x_i2c_read_maskfunction bq2415x_i2c_read_bitfunction bq2415x_i2c_writefunction bq2415x_i2c_write_maskfunction bq2415x_i2c_write_bitfunction bq2415x_exec_commandfunction bq2415x_detect_chipfunction bq2415x_detect_revisionfunction bq2415x_get_vender_codefunction bq2415x_reset_chipfunction bq2415x_set_current_limitfunction bq2415x_get_current_limitfunction bq2415x_set_weak_battery_voltagefunction bq2415x_get_weak_battery_voltagefunction bq2415x_set_battery_regulation_voltagefunction bq2415x_get_battery_regulation_voltagefunction bq2415x_set_charge_currentfunction bq2415x_get_charge_currentfunction bq2415x_set_termination_currentfunction bq2415x_get_termination_currentfunction bq2415x_set_defaultsfunction bq2415x_set_modefunction bq2415x_update_reported_modefunction bq2415x_notifier_callfunction bq2415x_set_autotimerfunction bq2415x_timer_errorfunction bq2415x_timer_workfunction bq2415x_power_supply_get_propertyfunction bq2415x_power_supply_exitfunction bq2415x_sysfs_show_statusfunction bq2415x_sysfs_set_timerfunction bq2415x_sysfs_show_timerfunction bq2415x_sysfs_set_modefunction bq2415x_sysfs_show_modefunction bq2415x_sysfs_show_reported_modefunction bq2415x_sysfs_set_registersfunction bq2415x_sysfs_print_regfunction bq2415x_sysfs_show_registersfunction bq2415x_sysfs_set_limitfunction bq2415x_sysfs_show_limitfunction bq2415x_sysfs_set_enablefunction bq2415x_sysfs_show_enablefunction bq2415x_power_supply_initfunction bq2415x_probe
Annotated Snippet
struct bq2415x_device {
struct device *dev;
struct bq2415x_platform_data init_data;
struct power_supply *charger;
struct power_supply_desc charger_desc;
struct delayed_work work;
struct device_node *notify_node;
struct notifier_block nb;
enum bq2415x_mode reported_mode;/* mode reported by hook function */
enum bq2415x_mode mode; /* currently configured mode */
enum bq2415x_chip chip;
const char *timer_error;
char *model;
char *name;
int autotimer; /* 1 - if driver automatically reset timer, 0 - not */
int automode; /* 1 - enabled, 0 - disabled; -1 - not supported */
int charge_status;
int id;
};
/* each registered chip must have unique id */
static DEFINE_IDR(bq2415x_id);
static DEFINE_MUTEX(bq2415x_id_mutex);
static DEFINE_MUTEX(bq2415x_timer_mutex);
static DEFINE_MUTEX(bq2415x_i2c_mutex);
/**** i2c read functions ****/
/* read value from register */
static int bq2415x_i2c_read(struct bq2415x_device *bq, u8 reg)
{
struct i2c_client *client = to_i2c_client(bq->dev);
struct i2c_msg msg[2];
u8 val;
int ret;
if (!client->adapter)
return -ENODEV;
msg[0].addr = client->addr;
msg[0].flags = 0;
msg[0].buf = ®
msg[0].len = sizeof(reg);
msg[1].addr = client->addr;
msg[1].flags = I2C_M_RD;
msg[1].buf = &val;
msg[1].len = sizeof(val);
mutex_lock(&bq2415x_i2c_mutex);
ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
mutex_unlock(&bq2415x_i2c_mutex);
if (ret < 0)
return ret;
return val;
}
/* read value from register, apply mask and right shift it */
static int bq2415x_i2c_read_mask(struct bq2415x_device *bq, u8 reg,
u8 mask, u8 shift)
{
int ret;
if (shift > 8)
return -EINVAL;
ret = bq2415x_i2c_read(bq, reg);
if (ret < 0)
return ret;
return (ret & mask) >> shift;
}
/* read value from register and return one specified bit */
static int bq2415x_i2c_read_bit(struct bq2415x_device *bq, u8 reg, u8 bit)
{
if (bit > 8)
return -EINVAL;
return bq2415x_i2c_read_mask(bq, reg, BIT(bit), bit);
}
/**** i2c write functions ****/
/* write value to register */
static int bq2415x_i2c_write(struct bq2415x_device *bq, u8 reg, u8 val)
{
struct i2c_client *client = to_i2c_client(bq->dev);
struct i2c_msg msg[1];
u8 data[2];
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/param.h`, `linux/err.h`, `linux/workqueue.h`, `linux/sysfs.h`, `linux/platform_device.h`, `linux/power_supply.h`.
- Detected declarations: `struct bq2415x_device`, `enum bq2415x_command`, `enum bq2415x_chip`, `function bq2415x_i2c_read`, `function bq2415x_i2c_read_mask`, `function bq2415x_i2c_read_bit`, `function bq2415x_i2c_write`, `function bq2415x_i2c_write_mask`, `function bq2415x_i2c_write_bit`, `function bq2415x_exec_command`.
- 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.
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.