drivers/power/supply/s2mu005-battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/s2mu005-battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/s2mu005-battery.c- Extension
.c- Size
- 7748 bytes
- Lines
- 308
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/interrupt.hlinux/mod_devicetable.hlinux/mutex.hlinux/power_supply.hlinux/property.hlinux/regmap.hlinux/units.h
Detected Declarations
struct s2mu005_fgfunction s2mu005_handle_irqfunction s2mu005_fg_get_voltage_nowfunction s2mu005_fg_get_voltage_avgfunction s2mu005_fg_get_current_nowfunction s2mu005_fg_get_current_avgfunction s2mu005_fg_get_capacityfunction s2mu005_fg_get_statusfunction s2mu005_fg_get_propertyfunction s2mu005_fg_i2c_probe
Annotated Snippet
struct s2mu005_fg {
struct device *dev;
struct regmap *regmap;
struct power_supply *psy;
struct mutex monout_mutex;
};
static const struct regmap_config s2mu005_fg_regmap_config = {
.reg_bits = 8,
.val_bits = 16,
.val_format_endian = REGMAP_ENDIAN_LITTLE,
};
static irqreturn_t s2mu005_handle_irq(int irq, void *data)
{
struct s2mu005_fg *priv = data;
msleep(100);
power_supply_changed(priv->psy);
return IRQ_HANDLED;
}
static int s2mu005_fg_get_voltage_now(struct s2mu005_fg *priv, int *value)
{
struct regmap *regmap = priv->regmap;
u32 val;
int ret;
ret = regmap_read(regmap, S2MU005_FG_REG_RVBAT, &val);
if (ret < 0) {
dev_err(priv->dev, "failed to read voltage register (%d)\n", ret);
return ret;
}
*value = (val * MICRO) >> 13;
return 0;
}
static int s2mu005_fg_get_voltage_avg(struct s2mu005_fg *priv, int *value)
{
struct regmap *regmap = priv->regmap;
u32 val;
int ret;
mutex_lock(&priv->monout_mutex);
ret = regmap_write(regmap, S2MU005_FG_REG_MONOUTSEL,
S2MU005_FG_MONOUTSEL_AVGVOLTAGE);
if (ret < 0) {
dev_err(priv->dev, "failed to enable average voltage monitoring (%d)\n",
ret);
goto unlock;
}
ret = regmap_read(regmap, S2MU005_FG_REG_MONOUT, &val);
if (ret < 0) {
dev_err(priv->dev, "failed to read current register (%d)\n", ret);
goto unlock;
}
*value = (val * MICRO) >> 12;
unlock:
mutex_unlock(&priv->monout_mutex);
return ret;
}
static int s2mu005_fg_get_current_now(struct s2mu005_fg *priv, int *value)
{
struct regmap *regmap = priv->regmap;
u32 val;
int ret;
ret = regmap_read(regmap, S2MU005_FG_REG_RCURCC, &val);
if (ret < 0) {
dev_err(priv->dev, "failed to read current register (%d)\n", ret);
return ret;
}
*value = -((s16)val * MICRO) >> 12;
return 0;
}
static int s2mu005_fg_get_current_avg(struct s2mu005_fg *priv, int *value)
{
struct regmap *regmap = priv->regmap;
u32 val;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/mutex.h`, `linux/power_supply.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct s2mu005_fg`, `function s2mu005_handle_irq`, `function s2mu005_fg_get_voltage_now`, `function s2mu005_fg_get_voltage_avg`, `function s2mu005_fg_get_current_now`, `function s2mu005_fg_get_current_avg`, `function s2mu005_fg_get_capacity`, `function s2mu005_fg_get_status`, `function s2mu005_fg_get_property`, `function s2mu005_fg_i2c_probe`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.