drivers/power/supply/acer_a500_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/acer_a500_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/acer_a500_battery.c- Extension
.c- Size
- 7268 bytes
- Lines
- 298
- 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/platform_device.hlinux/power_supply.hlinux/regmap.hlinux/sched.hlinux/slab.hlinux/workqueue.hlinux/property.h
Detected Declarations
struct a500_batteryfunction a500_battery_update_capacityfunction a500_battery_get_statusfunction a500_battery_unit_adjustmentfunction a500_battery_get_ec_data_indexfunction a500_battery_get_propertyfunction a500_battery_poll_workfunction a500_battery_probefunction a500_battery_removefunction a500_battery_suspendfunction a500_battery_resume
Annotated Snippet
struct a500_battery {
struct delayed_work poll_work;
struct power_supply *psy;
struct regmap *regmap;
unsigned int capacity;
};
static bool a500_battery_update_capacity(struct a500_battery *bat)
{
unsigned int capacity;
int err;
err = regmap_read(bat->regmap, ec_data[REG_CAPACITY].reg, &capacity);
if (err)
return false;
/* capacity can be >100% even if max value is 100% */
capacity = min(capacity, 100u);
if (bat->capacity != capacity) {
bat->capacity = capacity;
return true;
}
return false;
}
static int a500_battery_get_status(struct a500_battery *bat)
{
if (bat->capacity < 100) {
if (power_supply_am_i_supplied(bat->psy))
return POWER_SUPPLY_STATUS_CHARGING;
else
return POWER_SUPPLY_STATUS_DISCHARGING;
}
return POWER_SUPPLY_STATUS_FULL;
}
static void a500_battery_unit_adjustment(struct device *dev,
enum power_supply_property psp,
union power_supply_propval *val)
{
const unsigned int base_unit_conversion = 1000;
const unsigned int temp_kelvin_to_celsius = 2731;
switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
case POWER_SUPPLY_PROP_CURRENT_NOW:
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
val->intval *= base_unit_conversion;
break;
case POWER_SUPPLY_PROP_TEMP:
val->intval -= temp_kelvin_to_celsius;
break;
case POWER_SUPPLY_PROP_PRESENT:
val->intval = !!val->intval;
break;
default:
dev_dbg(dev,
"%s: no need for unit conversion %d\n", __func__, psp);
}
}
static int a500_battery_get_ec_data_index(struct device *dev,
enum power_supply_property psp)
{
unsigned int i;
/*
* DESIGN_CAPACITY register always returns a non-zero value if
* battery is connected and zero if disconnected, hence we'll use
* it for judging the battery presence.
*/
if (psp == POWER_SUPPLY_PROP_PRESENT)
psp = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
for (i = 0; i < ARRAY_SIZE(ec_data); i++)
if (psp == ec_data[i].psp)
return i;
dev_dbg(dev, "%s: invalid property %u\n", __func__, psp);
return -EINVAL;
}
static int a500_battery_get_property(struct power_supply *psy,
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/regmap.h`, `linux/sched.h`, `linux/slab.h`, `linux/workqueue.h`, `linux/property.h`.
- Detected declarations: `struct a500_battery`, `function a500_battery_update_capacity`, `function a500_battery_get_status`, `function a500_battery_unit_adjustment`, `function a500_battery_get_ec_data_index`, `function a500_battery_get_property`, `function a500_battery_poll_work`, `function a500_battery_probe`, `function a500_battery_remove`, `function a500_battery_suspend`.
- 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.