drivers/power/supply/rt5033_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/rt5033_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/rt5033_battery.c- Extension
.c- Size
- 5141 bytes
- Lines
- 201
- 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/i2c.hlinux/module.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.hlinux/mfd/rt5033-private.h
Detected Declarations
struct rt5033_batteryfunction rt5033_battery_get_statusfunction rt5033_battery_get_capacityfunction rt5033_battery_get_presentfunction rt5033_battery_get_watt_propfunction rt5033_battery_get_propertyfunction rt5033_battery_probe
Annotated Snippet
struct rt5033_battery {
struct i2c_client *client;
struct regmap *regmap;
struct power_supply *psy;
};
static int rt5033_battery_get_status(struct i2c_client *client)
{
struct rt5033_battery *battery = i2c_get_clientdata(client);
union power_supply_propval val;
int ret;
ret = power_supply_get_property_from_supplier(battery->psy,
POWER_SUPPLY_PROP_STATUS,
&val);
if (ret)
val.intval = POWER_SUPPLY_STATUS_UNKNOWN;
return val.intval;
}
static int rt5033_battery_get_capacity(struct i2c_client *client)
{
struct rt5033_battery *battery = i2c_get_clientdata(client);
u32 msb;
regmap_read(battery->regmap, RT5033_FUEL_REG_SOC_H, &msb);
return msb;
}
static int rt5033_battery_get_present(struct i2c_client *client)
{
struct rt5033_battery *battery = i2c_get_clientdata(client);
u32 val;
regmap_read(battery->regmap, RT5033_FUEL_REG_CONFIG_L, &val);
return (val & RT5033_FUEL_BAT_PRESENT) ? true : false;
}
static int rt5033_battery_get_watt_prop(struct i2c_client *client,
enum power_supply_property psp)
{
struct rt5033_battery *battery = i2c_get_clientdata(client);
unsigned int regh, regl;
int ret;
u32 msb, lsb;
switch (psp) {
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
regh = RT5033_FUEL_REG_VBAT_H;
regl = RT5033_FUEL_REG_VBAT_L;
break;
case POWER_SUPPLY_PROP_VOLTAGE_AVG:
regh = RT5033_FUEL_REG_AVG_VOLT_H;
regl = RT5033_FUEL_REG_AVG_VOLT_L;
break;
case POWER_SUPPLY_PROP_VOLTAGE_OCV:
regh = RT5033_FUEL_REG_OCV_H;
regl = RT5033_FUEL_REG_OCV_L;
break;
default:
return -EINVAL;
}
regmap_read(battery->regmap, regh, &msb);
regmap_read(battery->regmap, regl, &lsb);
ret = ((msb << 4) + (lsb >> 4)) * 1250;
return ret;
}
static int rt5033_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct rt5033_battery *battery = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
case POWER_SUPPLY_PROP_VOLTAGE_AVG:
case POWER_SUPPLY_PROP_VOLTAGE_OCV:
val->intval = rt5033_battery_get_watt_prop(battery->client,
psp);
break;
case POWER_SUPPLY_PROP_PRESENT:
val->intval = rt5033_battery_get_present(battery->client);
break;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/module.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/regmap.h`, `linux/mfd/rt5033-private.h`.
- Detected declarations: `struct rt5033_battery`, `function rt5033_battery_get_status`, `function rt5033_battery_get_capacity`, `function rt5033_battery_get_present`, `function rt5033_battery_get_watt_prop`, `function rt5033_battery_get_property`, `function rt5033_battery_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.