drivers/power/supply/ds2760_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/ds2760_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/ds2760_battery.c- Extension
.c- Size
- 20718 bytes
- Lines
- 757
- 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/module.hlinux/param.hlinux/jiffies.hlinux/workqueue.hlinux/pm.hlinux/slab.hlinux/platform_device.hlinux/power_supply.hlinux/suspend.hlinux/w1.hlinux/of.h
Detected Declarations
struct ds2760_device_infofunction w1_ds2760_iofunction w1_ds2760_readfunction w1_ds2760_writefunction w1_ds2760_eeprom_cmdfunction w1_ds2760_store_eepromfunction w1_ds2760_recall_eepromfunction w1_slave_readfunction battery_interpolatefunction ds2760_battery_read_statusfunction ds2760_battery_set_current_accumfunction ds2760_battery_update_statusfunction ds2760_battery_write_statusfunction ds2760_battery_write_rated_capacityfunction ds2760_battery_write_active_fullfunction ds2760_battery_workfunction ds2760_battery_external_power_changedfunction ds2760_battery_get_propertyfunction ds2760_battery_set_propertyfunction ds2760_battery_property_is_writeablefunction ds2760_pm_notifierfunction w1_ds2760_add_slavefunction w1_ds2760_remove_slave
Annotated Snippet
struct ds2760_device_info {
struct device *dev;
/* DS2760 data, valid after calling ds2760_battery_read_status() */
unsigned long update_time; /* jiffies when data read */
char raw[DS2760_DATA_SIZE]; /* raw DS2760 data */
int voltage_raw; /* units of 4.88 mV */
int voltage_uV; /* units of µV */
int current_raw; /* units of 0.625 mA */
int current_uA; /* units of µA */
int accum_current_raw; /* units of 0.25 mAh */
int accum_current_uAh; /* units of µAh */
int temp_raw; /* units of 0.125 °C */
int temp_C; /* units of 0.1 °C */
int rated_capacity; /* units of µAh */
int rem_capacity; /* percentage */
int full_active_uAh; /* units of µAh */
int empty_uAh; /* units of µAh */
int life_sec; /* units of seconds */
int charge_status; /* POWER_SUPPLY_STATUS_* */
int full_counter;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct workqueue_struct *monitor_wqueue;
struct delayed_work monitor_work;
struct notifier_block pm_notifier;
};
static int w1_ds2760_io(struct device *dev, char *buf, int addr, size_t count,
int io)
{
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
if (!dev)
return 0;
mutex_lock(&sl->master->bus_mutex);
if (addr > DS2760_DATA_SIZE || addr < 0) {
count = 0;
goto out;
}
if (addr + count > DS2760_DATA_SIZE)
count = DS2760_DATA_SIZE - addr;
if (!w1_reset_select_slave(sl)) {
if (!io) {
w1_write_8(sl->master, W1_DS2760_READ_DATA);
w1_write_8(sl->master, addr);
count = w1_read_block(sl->master, buf, count);
} else {
w1_write_8(sl->master, W1_DS2760_WRITE_DATA);
w1_write_8(sl->master, addr);
w1_write_block(sl->master, buf, count);
/* XXX w1_write_block returns void, not n_written */
}
}
out:
mutex_unlock(&sl->master->bus_mutex);
return count;
}
static int w1_ds2760_read(struct device *dev,
char *buf, int addr,
size_t count)
{
return w1_ds2760_io(dev, buf, addr, count, 0);
}
static int w1_ds2760_write(struct device *dev,
char *buf,
int addr, size_t count)
{
return w1_ds2760_io(dev, buf, addr, count, 1);
}
static int w1_ds2760_eeprom_cmd(struct device *dev, int addr, int cmd)
{
struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
if (!dev)
return -EINVAL;
mutex_lock(&sl->master->bus_mutex);
if (w1_reset_select_slave(sl) == 0) {
w1_write_8(sl->master, cmd);
Annotation
- Immediate include surface: `linux/module.h`, `linux/param.h`, `linux/jiffies.h`, `linux/workqueue.h`, `linux/pm.h`, `linux/slab.h`, `linux/platform_device.h`, `linux/power_supply.h`.
- Detected declarations: `struct ds2760_device_info`, `function w1_ds2760_io`, `function w1_ds2760_read`, `function w1_ds2760_write`, `function w1_ds2760_eeprom_cmd`, `function w1_ds2760_store_eeprom`, `function w1_ds2760_recall_eeprom`, `function w1_slave_read`, `function battery_interpolate`, `function ds2760_battery_read_status`.
- 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.