drivers/power/supply/mm8013.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/mm8013.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/mm8013.c- Extension
.c- Size
- 8069 bytes
- Lines
- 309
- 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/delay.hlinux/i2c.hlinux/power_supply.hlinux/regmap.h
Detected Declarations
struct mm8013_chipfunction mm8013_checkdevicefunction mm8013_get_propertyfunction mm8013_probe
Annotated Snippet
struct mm8013_chip {
struct i2c_client *client;
struct regmap *regmap;
};
static int mm8013_checkdevice(struct mm8013_chip *chip)
{
int battery_id, ret;
u32 val;
ret = regmap_write(chip->regmap, REG_BATID, 0x0008);
if (ret < 0)
return ret;
ret = regmap_read(chip->regmap, REG_BATID, &val);
if (ret < 0)
return ret;
if (val == BATID_102)
battery_id = 2;
else if (val == BATID_101)
battery_id = 1;
else
return -EINVAL;
dev_dbg(&chip->client->dev, "battery_id: %d\n", battery_id);
return 0;
}
static enum power_supply_property mm8013_battery_props[] = {
POWER_SUPPLY_PROP_CAPACITY,
POWER_SUPPLY_PROP_CHARGE_FULL,
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_CURRENT_MAX,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CYCLE_COUNT,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_TEMP,
POWER_SUPPLY_PROP_TIME_TO_EMPTY_AVG,
POWER_SUPPLY_PROP_TIME_TO_FULL_AVG,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
};
static int mm8013_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct mm8013_chip *chip = power_supply_get_drvdata(psy);
int ret = 0;
u32 regval;
switch (psp) {
case POWER_SUPPLY_PROP_CAPACITY:
ret = regmap_read(chip->regmap, REG_STATE_OF_CHARGE, ®val);
if (ret < 0)
return ret;
val->intval = regval;
break;
case POWER_SUPPLY_PROP_CHARGE_FULL:
ret = regmap_read(chip->regmap, REG_FULL_CHARGE_CAPACITY, ®val);
if (ret < 0)
return ret;
val->intval = 1000 * regval;
break;
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
ret = regmap_read(chip->regmap, REG_DESIGN_CAPACITY, ®val);
if (ret < 0)
return ret;
val->intval = 1000 * regval;
break;
case POWER_SUPPLY_PROP_CHARGE_NOW:
ret = regmap_read(chip->regmap, REG_NOMINAL_CHARGE_CAPACITY, ®val);
if (ret < 0)
return ret;
val->intval = 1000 * regval;
break;
case POWER_SUPPLY_PROP_CURRENT_MAX:
ret = regmap_read(chip->regmap, REG_MAX_LOAD_CURRENT, ®val);
if (ret < 0)
return ret;
val->intval = -1000 * (s16)regval;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/power_supply.h`, `linux/regmap.h`.
- Detected declarations: `struct mm8013_chip`, `function mm8013_checkdevice`, `function mm8013_get_property`, `function mm8013_probe`.
- 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.