drivers/power/supply/sbs-charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/sbs-charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/sbs-charger.c- Extension
.c- Size
- 6637 bytes
- Lines
- 265
- 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.
- 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/init.hlinux/module.hlinux/kernel.hlinux/err.hlinux/power_supply.hlinux/i2c.hlinux/slab.hlinux/interrupt.hlinux/regmap.hlinux/bitops.hlinux/devm-helpers.h
Detected Declarations
struct sbs_infofunction sbs_get_propertyfunction sbs_check_statefunction sbs_delayed_workfunction sbs_irq_threadfunction sbs_readable_regfunction sbs_volatile_regfunction sbs_probe
Annotated Snippet
struct sbs_info {
struct i2c_client *client;
struct power_supply *power_supply;
struct regmap *regmap;
struct delayed_work work;
unsigned int last_state;
};
static int sbs_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct sbs_info *chip = power_supply_get_drvdata(psy);
unsigned int reg;
reg = chip->last_state;
switch (psp) {
case POWER_SUPPLY_PROP_PRESENT:
val->intval = !!(reg & SBS_CHARGER_STATUS_BATTERY_PRESENT);
break;
case POWER_SUPPLY_PROP_ONLINE:
val->intval = !!(reg & SBS_CHARGER_STATUS_AC_PRESENT);
break;
case POWER_SUPPLY_PROP_STATUS:
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
if (!(reg & SBS_CHARGER_STATUS_BATTERY_PRESENT))
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
else if (reg & SBS_CHARGER_STATUS_AC_PRESENT &&
!(reg & SBS_CHARGER_STATUS_CHARGE_INHIBITED))
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
break;
case POWER_SUPPLY_PROP_HEALTH:
if (reg & SBS_CHARGER_STATUS_RES_COLD)
val->intval = POWER_SUPPLY_HEALTH_COLD;
if (reg & SBS_CHARGER_STATUS_RES_HOT)
val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
else
val->intval = POWER_SUPPLY_HEALTH_GOOD;
break;
default:
return -EINVAL;
}
return 0;
}
static int sbs_check_state(struct sbs_info *chip)
{
unsigned int reg;
int ret;
ret = regmap_read(chip->regmap, SBS_CHARGER_REG_STATUS, ®);
if (!ret && reg != chip->last_state) {
chip->last_state = reg;
power_supply_changed(chip->power_supply);
return 1;
}
return 0;
}
static void sbs_delayed_work(struct work_struct *work)
{
struct sbs_info *chip = container_of(work, struct sbs_info, work.work);
sbs_check_state(chip);
schedule_delayed_work(&chip->work,
msecs_to_jiffies(SBS_CHARGER_POLL_TIME));
}
static irqreturn_t sbs_irq_thread(int irq, void *data)
{
struct sbs_info *chip = data;
int ret;
ret = sbs_check_state(chip);
return ret ? IRQ_HANDLED : IRQ_NONE;
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/kernel.h`, `linux/err.h`, `linux/power_supply.h`, `linux/i2c.h`, `linux/slab.h`, `linux/interrupt.h`.
- Detected declarations: `struct sbs_info`, `function sbs_get_property`, `function sbs_check_state`, `function sbs_delayed_work`, `function sbs_irq_thread`, `function sbs_readable_reg`, `function sbs_volatile_reg`, `function sbs_probe`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- 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.