drivers/power/supply/twl4030_madc_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/twl4030_madc_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/twl4030_madc_battery.c- Extension
.c- Size
- 6775 bytes
- Lines
- 238
- 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/delay.hlinux/platform_device.hlinux/power_supply.hlinux/slab.hlinux/sort.hlinux/power/twl4030_madc_battery.hlinux/iio/consumer.h
Detected Declarations
struct twl4030_madc_batteryfunction madc_readfunction twl4030_madc_bat_get_charging_statusfunction twl4030_madc_bat_get_voltagefunction twl4030_madc_bat_get_currentfunction twl4030_madc_bat_get_tempfunction twl4030_madc_bat_voltscalefunction twl4030_madc_bat_get_propertyfunction twl4030_cmpfunction twl4030_madc_battery_probe
Annotated Snippet
struct twl4030_madc_battery {
struct power_supply *psy;
struct twl4030_madc_bat_platform_data *pdata;
struct iio_channel *channel_temp;
struct iio_channel *channel_ichg;
struct iio_channel *channel_vbat;
};
static enum power_supply_property twl4030_madc_bat_props[] = {
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_TECHNOLOGY,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW,
};
static int madc_read(struct iio_channel *channel)
{
int val, err;
err = iio_read_channel_processed(channel, &val);
if (err < 0)
return err;
return val;
}
static int twl4030_madc_bat_get_charging_status(struct twl4030_madc_battery *bt)
{
return (madc_read(bt->channel_ichg) > 0) ? 1 : 0;
}
static int twl4030_madc_bat_get_voltage(struct twl4030_madc_battery *bt)
{
return madc_read(bt->channel_vbat);
}
static int twl4030_madc_bat_get_current(struct twl4030_madc_battery *bt)
{
return madc_read(bt->channel_ichg) * 1000;
}
static int twl4030_madc_bat_get_temp(struct twl4030_madc_battery *bt)
{
return madc_read(bt->channel_temp) * 10;
}
static int twl4030_madc_bat_voltscale(struct twl4030_madc_battery *bat,
int volt)
{
struct twl4030_madc_bat_calibration *calibration;
int i, res = 0;
/* choose charging curve */
if (twl4030_madc_bat_get_charging_status(bat))
calibration = bat->pdata->charging;
else
calibration = bat->pdata->discharging;
if (volt > calibration[0].voltage) {
res = calibration[0].level;
} else {
for (i = 0; calibration[i+1].voltage >= 0; i++) {
if (volt <= calibration[i].voltage &&
volt >= calibration[i+1].voltage) {
/* interval found - interpolate within range */
res = calibration[i].level -
((calibration[i].voltage - volt) *
(calibration[i].level -
calibration[i+1].level)) /
(calibration[i].voltage -
calibration[i+1].voltage);
break;
}
}
}
return res;
}
static int twl4030_madc_bat_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct twl4030_madc_battery *bat = power_supply_get_drvdata(psy);
switch (psp) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/delay.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/slab.h`, `linux/sort.h`, `linux/power/twl4030_madc_battery.h`, `linux/iio/consumer.h`.
- Detected declarations: `struct twl4030_madc_battery`, `function madc_read`, `function twl4030_madc_bat_get_charging_status`, `function twl4030_madc_bat_get_voltage`, `function twl4030_madc_bat_get_current`, `function twl4030_madc_bat_get_temp`, `function twl4030_madc_bat_voltscale`, `function twl4030_madc_bat_get_property`, `function twl4030_cmp`, `function twl4030_madc_battery_probe`.
- 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.