drivers/power/supply/ds2781_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/ds2781_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/ds2781_battery.c- Extension
.c- Size
- 19854 bytes
- Lines
- 795
- 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.
- 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/param.hlinux/pm.hlinux/platform_device.hlinux/power_supply.hlinux/idr.hlinux/w1.h../../w1/slaves/w1_ds2781.h
Detected Declarations
struct ds2781_device_infoenum current_typesfunction to_ds2781_device_infofunction ds2781_battery_iofunction w1_ds2781_readfunction ds2781_read8function ds2781_read16function ds2781_read_blockfunction ds2781_writefunction ds2781_store_eepromfunction ds2781_recall_eepromfunction ds2781_save_eepromfunction ds2781_set_sense_registerfunction ds2781_get_rsgain_registerfunction ds2781_set_rsgain_registerfunction ds2781_get_voltagefunction ds2781_get_temperaturefunction ds2781_get_currentfunction ds2781_get_accumulated_currentfunction ds2781_get_capacityfunction ds2781_get_statusfunction ds2781_get_charge_nowfunction ds2781_get_control_registerfunction ds2781_set_control_registerfunction ds2781_battery_get_propertyfunction ds2781_get_pmod_enabledfunction ds2781_set_pmod_enabledfunction ds2781_get_sense_resistor_valuefunction ds2781_set_sense_resistor_valuefunction ds2781_get_rsgain_settingfunction ds2781_set_rsgain_settingfunction ds2781_get_pio_pinfunction ds2781_set_pio_pinfunction ds2781_read_param_eeprom_binfunction ds2781_write_param_eeprom_binfunction ds2781_read_user_eeprom_binfunction ds2781_write_user_eeprom_binfunction ds2781_battery_probe
Annotated Snippet
struct ds2781_device_info {
struct device *dev;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct device *w1_dev;
};
enum current_types {
CURRENT_NOW,
CURRENT_AVG,
};
static const char model[] = "DS2781";
static const char manufacturer[] = "Maxim/Dallas";
static inline struct ds2781_device_info *
to_ds2781_device_info(struct power_supply *psy)
{
return power_supply_get_drvdata(psy);
}
static inline int ds2781_battery_io(struct ds2781_device_info *dev_info,
char *buf, int addr, size_t count, int io)
{
return w1_ds2781_io(dev_info->w1_dev, buf, addr, count, io);
}
static int w1_ds2781_read(struct ds2781_device_info *dev_info, char *buf,
int addr, size_t count)
{
return ds2781_battery_io(dev_info, buf, addr, count, 0);
}
static inline int ds2781_read8(struct ds2781_device_info *dev_info, u8 *val,
int addr)
{
return ds2781_battery_io(dev_info, val, addr, sizeof(u8), 0);
}
static int ds2781_read16(struct ds2781_device_info *dev_info, s16 *val,
int addr)
{
int ret;
u8 raw[2];
ret = ds2781_battery_io(dev_info, raw, addr, sizeof(raw), 0);
if (ret < 0)
return ret;
*val = (raw[0] << 8) | raw[1];
return 0;
}
static inline int ds2781_read_block(struct ds2781_device_info *dev_info,
u8 *val, int addr, size_t count)
{
return ds2781_battery_io(dev_info, val, addr, count, 0);
}
static inline int ds2781_write(struct ds2781_device_info *dev_info, u8 *val,
int addr, size_t count)
{
return ds2781_battery_io(dev_info, val, addr, count, 1);
}
static inline int ds2781_store_eeprom(struct device *dev, int addr)
{
return w1_ds2781_eeprom_cmd(dev, addr, W1_DS2781_COPY_DATA);
}
static inline int ds2781_recall_eeprom(struct device *dev, int addr)
{
return w1_ds2781_eeprom_cmd(dev, addr, W1_DS2781_RECALL_DATA);
}
static int ds2781_save_eeprom(struct ds2781_device_info *dev_info, int reg)
{
int ret;
ret = ds2781_store_eeprom(dev_info->w1_dev, reg);
if (ret < 0)
return ret;
ret = ds2781_recall_eeprom(dev_info->w1_dev, reg);
if (ret < 0)
return ret;
return 0;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/param.h`, `linux/pm.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/idr.h`, `linux/w1.h`.
- Detected declarations: `struct ds2781_device_info`, `enum current_types`, `function to_ds2781_device_info`, `function ds2781_battery_io`, `function w1_ds2781_read`, `function ds2781_read8`, `function ds2781_read16`, `function ds2781_read_block`, `function ds2781_write`, `function ds2781_store_eeprom`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
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.