drivers/power/supply/generic-adc-battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/generic-adc-battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/generic-adc-battery.c- Extension
.c- Size
- 8254 bytes
- Lines
- 301
- 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/interrupt.hlinux/platform_device.hlinux/power_supply.hlinux/gpio/consumer.hlinux/err.hlinux/timer.hlinux/jiffies.hlinux/errno.hlinux/init.hlinux/module.hlinux/slab.hlinux/iio/consumer.hlinux/iio/types.hlinux/of.hlinux/devm-helpers.h
Detected Declarations
struct gabenum gab_chan_typefunction gab_ext_power_changedfunction gab_charge_finishedfunction gab_read_channelfunction gab_get_propertyfunction gab_workfunction gab_chargedfunction gab_probefunction gab_suspendfunction gab_resume
Annotated Snippet
struct gab {
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
struct delayed_work bat_work;
int status;
struct gpio_desc *charge_finished;
};
static struct gab *to_generic_bat(struct power_supply *psy)
{
return power_supply_get_drvdata(psy);
}
static void gab_ext_power_changed(struct power_supply *psy)
{
struct gab *adc_bat = to_generic_bat(psy);
schedule_delayed_work(&adc_bat->bat_work, msecs_to_jiffies(0));
}
static const enum power_supply_property gab_props[] = {
POWER_SUPPLY_PROP_STATUS,
};
/*
* This properties are set based on the received platform data and this
* should correspond one-to-one with enum chan_type.
*/
static const enum power_supply_property gab_dyn_props[] = {
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_POWER_NOW,
POWER_SUPPLY_PROP_TEMP,
};
static bool gab_charge_finished(struct gab *adc_bat)
{
if (!adc_bat->charge_finished)
return false;
return gpiod_get_value(adc_bat->charge_finished);
}
static int gab_read_channel(struct gab *adc_bat, enum gab_chan_type channel,
int *result)
{
int ret;
ret = iio_read_channel_processed(adc_bat->channel[channel], result);
if (ret < 0)
dev_err(&adc_bat->psy->dev, "read channel error: %d\n", ret);
else
*result *= 1000;
return ret;
}
static int gab_get_property(struct power_supply *psy,
enum power_supply_property psp, union power_supply_propval *val)
{
struct gab *adc_bat = to_generic_bat(psy);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
val->intval = adc_bat->status;
return 0;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
return gab_read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
case POWER_SUPPLY_PROP_CURRENT_NOW:
return gab_read_channel(adc_bat, GAB_CURRENT, &val->intval);
case POWER_SUPPLY_PROP_POWER_NOW:
return gab_read_channel(adc_bat, GAB_POWER, &val->intval);
case POWER_SUPPLY_PROP_TEMP:
return gab_read_channel(adc_bat, GAB_TEMP, &val->intval);
default:
return -EINVAL;
}
}
static void gab_work(struct work_struct *work)
{
struct gab *adc_bat;
struct delayed_work *delayed_work;
int status;
delayed_work = to_delayed_work(work);
adc_bat = container_of(delayed_work, struct gab, bat_work);
status = adc_bat->status;
if (!power_supply_am_i_supplied(adc_bat->psy))
Annotation
- Immediate include surface: `linux/interrupt.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/gpio/consumer.h`, `linux/err.h`, `linux/timer.h`, `linux/jiffies.h`, `linux/errno.h`.
- Detected declarations: `struct gab`, `enum gab_chan_type`, `function gab_ext_power_changed`, `function gab_charge_finished`, `function gab_read_channel`, `function gab_get_property`, `function gab_work`, `function gab_charged`, `function gab_probe`, `function gab_suspend`.
- 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.