drivers/power/supply/olpc_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/olpc_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/olpc_battery.c- Extension
.c- Size
- 17860 bytes
- Lines
- 733
- 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/kernel.hlinux/module.hlinux/mod_devicetable.hlinux/types.hlinux/err.hlinux/device.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/jiffies.hlinux/sched.hlinux/olpc-ec.h
Detected Declarations
struct olpc_battery_datafunction olpc_ac_get_propfunction olpc_bat_get_statusfunction olpc_bat_get_healthfunction olpc_bat_get_mfrfunction olpc_bat_get_techfunction olpc_bat_get_charge_full_designfunction olpc_bat_get_charge_nowfunction olpc_bat_get_voltage_max_designfunction ecword_to_cpufunction olpc_bat_get_propertyfunction olpc_bat_eeprom_readfunction olpc_bat_error_readfunction olpc_battery_suspendfunction olpc_battery_probe
Annotated Snippet
struct olpc_battery_data {
struct power_supply *olpc_ac;
struct power_supply *olpc_bat;
char bat_serial[17];
bool new_proto;
bool little_endian;
};
/*********************************************************************
* Power
*********************************************************************/
static int olpc_ac_get_prop(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
int ret = 0;
uint8_t status;
switch (psp) {
case POWER_SUPPLY_PROP_ONLINE:
ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &status, 1);
if (ret)
return ret;
val->intval = !!(status & BAT_STAT_AC);
break;
default:
ret = -EINVAL;
break;
}
return ret;
}
static enum power_supply_property olpc_ac_props[] = {
POWER_SUPPLY_PROP_ONLINE,
};
static const struct power_supply_desc olpc_ac_desc = {
.name = "olpc_ac",
.type = POWER_SUPPLY_TYPE_MAINS,
.properties = olpc_ac_props,
.num_properties = ARRAY_SIZE(olpc_ac_props),
.get_property = olpc_ac_get_prop,
};
static int olpc_bat_get_status(struct olpc_battery_data *data,
union power_supply_propval *val, uint8_t ec_byte)
{
if (data->new_proto) {
if (ec_byte & (BAT_STAT_CHARGING | BAT_STAT_TRICKLE))
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else if (ec_byte & BAT_STAT_DISCHARGING)
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
else if (ec_byte & BAT_STAT_FULL)
val->intval = POWER_SUPPLY_STATUS_FULL;
else /* er,... */
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
} else {
/* Older EC didn't report charge/discharge bits */
if (!(ec_byte & BAT_STAT_AC)) /* No AC means discharging */
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
else if (ec_byte & BAT_STAT_FULL)
val->intval = POWER_SUPPLY_STATUS_FULL;
else /* Not _necessarily_ true but EC doesn't tell all yet */
val->intval = POWER_SUPPLY_STATUS_CHARGING;
}
return 0;
}
static int olpc_bat_get_health(union power_supply_propval *val)
{
uint8_t ec_byte;
int ret;
ret = olpc_ec_cmd(EC_BAT_ERRCODE, NULL, 0, &ec_byte, 1);
if (ret)
return ret;
switch (ec_byte) {
case 0:
val->intval = POWER_SUPPLY_HEALTH_GOOD;
break;
case BAT_ERR_OVERTEMP:
val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
break;
case BAT_ERR_OVERVOLTAGE:
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/types.h`, `linux/err.h`, `linux/device.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct olpc_battery_data`, `function olpc_ac_get_prop`, `function olpc_bat_get_status`, `function olpc_bat_get_health`, `function olpc_bat_get_mfr`, `function olpc_bat_get_tech`, `function olpc_bat_get_charge_full_design`, `function olpc_bat_get_charge_now`, `function olpc_bat_get_voltage_max_design`, `function ecword_to_cpu`.
- 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.