drivers/power/supply/adp5061.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/adp5061.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/adp5061.c- Extension
.c- Size
- 19291 bytes
- Lines
- 747
- 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/init.hlinux/module.hlinux/slab.hlinux/i2c.hlinux/delay.hlinux/pm.hlinux/mod_devicetable.hlinux/power_supply.hlinux/platform_device.hlinux/of.hlinux/regmap.h
Detected Declarations
struct adp5061_stateenum adp5061_chg_statusfunction adp5061_get_array_indexfunction adp5061_get_statusfunction adp5061_get_input_current_limitfunction adp5061_set_input_current_limitfunction adp5061_set_min_voltagefunction adp5061_get_min_voltagefunction adp5061_get_chg_volt_limfunction adp5061_get_max_voltagefunction adp5061_set_max_voltagefunction adp5061_set_const_chg_vmaxfunction adp5061_set_const_chg_currentfunction adp5061_get_const_chg_currentfunction adp5061_get_prechg_currentfunction adp5061_set_prechg_currentfunction adp5061_get_vweak_thfunction adp5061_set_vweak_thfunction adp5061_get_chg_typefunction adp5061_get_charger_statusfunction adp5061_get_battery_statusfunction adp5061_get_termination_currentfunction adp5061_set_termination_currentfunction adp5061_get_propertyfunction adp5061_set_propertyfunction adp5061_prop_writeablefunction adp5061_probe
Annotated Snippet
struct adp5061_state {
struct i2c_client *client;
struct regmap *regmap;
struct power_supply *psy;
};
static int adp5061_get_array_index(const int *array, u8 size, int val)
{
int i;
for (i = 1; i < size; i++) {
if (val < array[i])
break;
}
return i-1;
}
static int adp5061_get_status(struct adp5061_state *st,
u8 *status1, u8 *status2)
{
u8 buf[2];
int ret;
/* CHG_STATUS1 and CHG_STATUS2 are adjacent regs */
ret = regmap_bulk_read(st->regmap, ADP5061_CHG_STATUS_1,
&buf[0], 2);
if (ret < 0)
return ret;
*status1 = buf[0];
*status2 = buf[1];
return ret;
}
static int adp5061_get_input_current_limit(struct adp5061_state *st,
union power_supply_propval *val)
{
unsigned int regval;
int mode, ret;
ret = regmap_read(st->regmap, ADP5061_VINX_SET, ®val);
if (ret < 0)
return ret;
mode = ADP5061_VINX_SET_ILIM_MODE(regval);
val->intval = adp5061_in_current_lim[mode] * 1000;
return ret;
}
static int adp5061_set_input_current_limit(struct adp5061_state *st, int val)
{
int index;
/* Convert from uA to mA */
val /= 1000;
index = adp5061_get_array_index(adp5061_in_current_lim,
ARRAY_SIZE(adp5061_in_current_lim),
val);
if (index < 0)
return index;
return regmap_update_bits(st->regmap, ADP5061_VINX_SET,
ADP5061_VINX_SET_ILIM_MSK,
ADP5061_VINX_SET_ILIM_MODE(index));
}
static int adp5061_set_min_voltage(struct adp5061_state *st, int val)
{
int index;
/* Convert from uV to mV */
val /= 1000;
index = adp5061_get_array_index(adp5061_vmin,
ARRAY_SIZE(adp5061_vmin),
val);
if (index < 0)
return index;
return regmap_update_bits(st->regmap, ADP5061_VOLTAGE_TH,
ADP5061_VOLTAGE_TH_VTRK_DEAD_MSK,
ADP5061_VOLTAGE_TH_VTRK_DEAD_MODE(index));
}
static int adp5061_get_min_voltage(struct adp5061_state *st,
union power_supply_propval *val)
{
unsigned int regval;
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/slab.h`, `linux/i2c.h`, `linux/delay.h`, `linux/pm.h`, `linux/mod_devicetable.h`, `linux/power_supply.h`.
- Detected declarations: `struct adp5061_state`, `enum adp5061_chg_status`, `function adp5061_get_array_index`, `function adp5061_get_status`, `function adp5061_get_input_current_limit`, `function adp5061_set_input_current_limit`, `function adp5061_set_min_voltage`, `function adp5061_get_min_voltage`, `function adp5061_get_chg_volt_lim`, `function adp5061_get_max_voltage`.
- 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.