drivers/power/supply/goldfish_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/goldfish_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/goldfish_battery.c- Extension
.c- Size
- 7392 bytes
- Lines
- 278
- 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.
- 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/module.hlinux/err.hlinux/platform_device.hlinux/power_supply.hlinux/types.hlinux/pci.hlinux/interrupt.hlinux/io.hlinux/acpi.h
Detected Declarations
struct goldfish_battery_datafunction goldfish_ac_get_propertyfunction goldfish_battery_get_propertyfunction goldfish_battery_interruptfunction goldfish_battery_probe
Annotated Snippet
struct goldfish_battery_data {
void __iomem *reg_base;
int irq;
spinlock_t lock;
struct power_supply *battery;
struct power_supply *ac;
};
#define GOLDFISH_BATTERY_READ(data, addr) \
(readl(data->reg_base + addr))
#define GOLDFISH_BATTERY_WRITE(data, addr, x) \
(writel(x, data->reg_base + addr))
enum {
/* status register */
BATTERY_INT_STATUS = 0x00,
/* set this to enable IRQ */
BATTERY_INT_ENABLE = 0x04,
BATTERY_AC_ONLINE = 0x08,
BATTERY_STATUS = 0x0C,
BATTERY_HEALTH = 0x10,
BATTERY_PRESENT = 0x14,
BATTERY_CAPACITY = 0x18,
BATTERY_VOLTAGE = 0x1C,
BATTERY_TEMP = 0x20,
BATTERY_CHARGE_COUNTER = 0x24,
BATTERY_VOLTAGE_MAX = 0x28,
BATTERY_CURRENT_MAX = 0x2C,
BATTERY_CURRENT_NOW = 0x30,
BATTERY_CURRENT_AVG = 0x34,
BATTERY_CHARGE_FULL_UAH = 0x38,
BATTERY_CYCLE_COUNT = 0x40,
BATTERY_STATUS_CHANGED = 1U << 0,
AC_STATUS_CHANGED = 1U << 1,
BATTERY_INT_MASK = BATTERY_STATUS_CHANGED | AC_STATUS_CHANGED,
};
static int goldfish_ac_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct goldfish_battery_data *data = power_supply_get_drvdata(psy);
int ret = 0;
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_AC_ONLINE);
break;
case POWER_SUPPLY_PROP_VOLTAGE_MAX:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_VOLTAGE_MAX);
break;
case POWER_SUPPLY_PROP_CURRENT_MAX:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_CURRENT_MAX);
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static int goldfish_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct goldfish_battery_data *data = power_supply_get_drvdata(psy);
int ret = 0;
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_STATUS);
break;
case POWER_SUPPLY_PROP_HEALTH:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_HEALTH);
break;
case POWER_SUPPLY_PROP_PRESENT:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_PRESENT);
break;
case POWER_SUPPLY_PROP_TECHNOLOGY:
val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
break;
case POWER_SUPPLY_PROP_CAPACITY:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_CAPACITY);
break;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_VOLTAGE);
Annotation
- Immediate include surface: `linux/module.h`, `linux/err.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/types.h`, `linux/pci.h`, `linux/interrupt.h`, `linux/io.h`.
- Detected declarations: `struct goldfish_battery_data`, `function goldfish_ac_get_property`, `function goldfish_battery_get_property`, `function goldfish_battery_interrupt`, `function goldfish_battery_probe`.
- 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.
- 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.