drivers/power/supply/sc2731_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/sc2731_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/sc2731_charger.c- Extension
.c- Size
- 12861 bytes
- Lines
- 540
- 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.
- 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/module.hlinux/platform_device.hlinux/power_supply.hlinux/usb/phy.hlinux/regmap.hlinux/notifier.hlinux/of.h
Detected Declarations
struct sc2731_charger_infofunction sc2731_charger_stop_chargefunction sc2731_charger_start_chargefunction sc2731_charger_set_current_limitfunction sc2731_charger_set_currentfunction sc2731_charger_get_statusfunction sc2731_charger_get_currentfunction sc2731_charger_get_current_limitfunction sc2731_charger_usb_set_propertyfunction sc2731_charger_usb_get_propertyfunction sc2731_charger_property_is_writeablefunction sc2731_charger_workfunction sc2731_charger_usb_changefunction sc2731_charger_hw_initfunction sc2731_charger_detect_statusfunction sc2731_charger_probefunction sc2731_charger_remove
Annotated Snippet
struct sc2731_charger_info {
struct device *dev;
struct regmap *regmap;
struct usb_phy *usb_phy;
struct notifier_block usb_notify;
struct power_supply *psy_usb;
struct work_struct work;
struct mutex lock;
bool charging;
u32 base;
u32 limit;
};
static void sc2731_charger_stop_charge(struct sc2731_charger_info *info)
{
regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0,
SC2731_CC_EN, 0);
regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0,
SC2731_CHARGER_PD, SC2731_CHARGER_PD);
}
static int sc2731_charger_start_charge(struct sc2731_charger_info *info)
{
int ret;
/* Enable charger constant current mode */
ret = regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0,
SC2731_CC_EN, SC2731_CC_EN);
if (ret)
return ret;
/* Start charging */
return regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0,
SC2731_CHARGER_PD, 0);
}
static int sc2731_charger_set_current_limit(struct sc2731_charger_info *info,
u32 limit)
{
u32 val;
if (limit <= SC2731_CURRENT_LIMIT_100)
val = 0;
else if (limit <= SC2731_CURRENT_LIMIT_500)
val = 3;
else if (limit <= SC2731_CURRENT_LIMIT_900)
val = 2;
else
val = 1;
return regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG5,
SC2731_CUR_LIMIT_MASK,
val << SC2731_CUR_LIMIT_SHIFT);
}
static int sc2731_charger_set_current(struct sc2731_charger_info *info, u32 cur)
{
u32 val;
int ret;
if (cur > SC2731_CURRENT_LIMIT_2000)
cur = SC2731_CURRENT_LIMIT_2000;
else if (cur < SC2731_CURRENT_PRECHG)
cur = SC2731_CURRENT_PRECHG;
/* Calculate the step value, each step is 50 mA */
val = (cur - SC2731_CURRENT_PRECHG) / SC2731_CURRENT_STEP;
/* Set pre-charge current as 450 mA */
ret = regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG0,
SC2731_PRECHG_RNG_MASK,
0x3 << SC2731_PRECHG_RNG_SHIFT);
if (ret)
return ret;
return regmap_update_bits(info->regmap, info->base + SC2731_CHG_CFG1,
SC2731_CUR_MASK, val);
}
static int sc2731_charger_get_status(struct sc2731_charger_info *info)
{
u32 val;
int ret;
ret = regmap_read(info->regmap, SC2731_CHARGE_STATUS, &val);
if (ret)
return ret;
if (val & SC2731_CHARGE_FULL)
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/usb/phy.h`, `linux/regmap.h`, `linux/notifier.h`, `linux/of.h`.
- Detected declarations: `struct sc2731_charger_info`, `function sc2731_charger_stop_charge`, `function sc2731_charger_start_charge`, `function sc2731_charger_set_current_limit`, `function sc2731_charger_set_current`, `function sc2731_charger_get_status`, `function sc2731_charger_get_current`, `function sc2731_charger_get_current_limit`, `function sc2731_charger_usb_set_property`, `function sc2731_charger_usb_get_property`.
- 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.
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.