drivers/power/supply/chagall-battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/chagall-battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/chagall-battery.c- Extension
.c- Size
- 8579 bytes
- Lines
- 292
- 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/array_size.hlinux/delay.hlinux/devm-helpers.hlinux/err.hlinux/i2c.hlinux/leds.hlinux/mod_devicetable.hlinux/module.hlinux/power_supply.hlinux/regmap.h
Detected Declarations
struct chagall_battery_datafunction chagall_led_set_brightness_amberfunction chagall_led_set_brightness_whitefunction chagall_battery_get_valuefunction chagall_battery_get_statusfunction chagall_battery_get_propertyfunction chagall_battery_poll_workfunction chagall_battery_probefunction chagall_battery_suspendfunction chagall_battery_resume
Annotated Snippet
struct chagall_battery_data {
struct regmap *regmap;
struct led_classdev amber_led;
struct led_classdev white_led;
struct power_supply *battery;
struct delayed_work poll_work;
u16 last_state;
};
static void chagall_led_set_brightness_amber(struct led_classdev *led,
enum led_brightness brightness)
{
struct chagall_battery_data *cg =
container_of(led, struct chagall_battery_data, amber_led);
regmap_write(cg->regmap, CHAGALL_REG_LED_AMBER, brightness);
}
static void chagall_led_set_brightness_white(struct led_classdev *led,
enum led_brightness brightness)
{
struct chagall_battery_data *cg =
container_of(led, struct chagall_battery_data, white_led);
regmap_write(cg->regmap, CHAGALL_REG_LED_WHITE, brightness);
}
static const enum power_supply_property chagall_battery_properties[] = {
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CURRENT_MAX,
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_NOW,
};
static const unsigned int chagall_battery_prop_offs[] = {
[POWER_SUPPLY_PROP_STATUS] = CHAGALL_REG_BATTERY_STATUS,
[POWER_SUPPLY_PROP_VOLTAGE_NOW] = CHAGALL_REG_BATTERY_VOLTAGE,
[POWER_SUPPLY_PROP_VOLTAGE_MAX] = CHAGALL_REG_BATTERY_CHARGING_VOLTAGE,
[POWER_SUPPLY_PROP_CURRENT_NOW] = CHAGALL_REG_BATTERY_CURRENT,
[POWER_SUPPLY_PROP_CURRENT_MAX] = CHAGALL_REG_BATTERY_CHARGING_CURRENT,
[POWER_SUPPLY_PROP_CAPACITY] = CHAGALL_REG_BATTERY_CAPACITY,
[POWER_SUPPLY_PROP_TEMP] = CHAGALL_REG_BATTERY_TEMPERATURE,
[POWER_SUPPLY_PROP_CHARGE_FULL] = CHAGALL_REG_BATTERY_FULL_CAPACITY,
[POWER_SUPPLY_PROP_CHARGE_NOW] = CHAGALL_REG_BATTERY_REMAIN_CAPACITY,
};
static int chagall_battery_get_value(struct chagall_battery_data *cg,
enum power_supply_property psp, u32 *val)
{
if (psp >= ARRAY_SIZE(chagall_battery_prop_offs))
return -EINVAL;
if (!chagall_battery_prop_offs[psp])
return -EINVAL;
/* Battery data is stored in 2 consecutive registers with little-endian */
return regmap_bulk_read(cg->regmap, chagall_battery_prop_offs[psp], val, 2);
}
static int chagall_battery_get_status(u32 status_reg)
{
if (status_reg & BATTERY_FULL_CHARGED)
return POWER_SUPPLY_STATUS_FULL;
else if (status_reg & BATTERY_DISCHARGING)
return POWER_SUPPLY_STATUS_DISCHARGING;
else
return POWER_SUPPLY_STATUS_CHARGING;
}
static int chagall_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct chagall_battery_data *cg = power_supply_get_drvdata(psy);
int ret;
switch (psp) {
case POWER_SUPPLY_PROP_PRESENT:
val->intval = 1;
break;
default:
ret = chagall_battery_get_value(cg, psp, &val->intval);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/delay.h`, `linux/devm-helpers.h`, `linux/err.h`, `linux/i2c.h`, `linux/leds.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct chagall_battery_data`, `function chagall_led_set_brightness_amber`, `function chagall_led_set_brightness_white`, `function chagall_battery_get_value`, `function chagall_battery_get_status`, `function chagall_battery_get_property`, `function chagall_battery_poll_work`, `function chagall_battery_probe`, `function chagall_battery_suspend`, `function chagall_battery_resume`.
- 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.