drivers/power/supply/sc27xx_fuel_gauge.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/sc27xx_fuel_gauge.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/sc27xx_fuel_gauge.c- Extension
.c- Size
- 35463 bytes
- Lines
- 1353
- 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/gpio/consumer.hlinux/iio/consumer.hlinux/interrupt.hlinux/kernel.hlinux/math64.hlinux/module.hlinux/nvmem-consumer.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct sc27xx_fgu_datafunction sc27xx_fgu_adc_to_currentfunction sc27xx_fgu_adc_to_voltagefunction sc27xx_fgu_voltage_to_adcfunction sc27xx_fgu_is_first_poweronfunction sc27xx_fgu_save_boot_modefunction sc27xx_fgu_save_last_capfunction sc27xx_fgu_read_last_capfunction sc27xx_fgu_get_boot_capacityfunction sc27xx_fgu_set_clbcntfunction sc27xx_fgu_get_clbcntfunction sc27xx_fgu_get_vol_nowfunction sc27xx_fgu_get_cur_nowfunction sc27xx_fgu_get_capacityfunction sc27xx_fgu_get_vbat_volfunction sc27xx_fgu_get_currentfunction sc27xx_fgu_get_vbat_ocvfunction sc27xx_fgu_get_charge_volfunction sc27xx_fgu_get_tempfunction sc27xx_fgu_get_healthfunction sc27xx_fgu_get_statusfunction sc27xx_fgu_get_propertyfunction sc27xx_fgu_set_propertyfunction sc27xx_fgu_property_is_writeablefunction sc27xx_fgu_adjust_capfunction sc27xx_fgu_capacity_calibrationfunction sc27xx_fgu_interruptfunction sc27xx_fgu_bat_detectionfunction sc27xx_fgu_disablefunction sc27xx_fgu_cap_to_clbcntfunction sc27xx_fgu_calibrationfunction sc27xx_fgu_hw_initfunction sc27xx_fgu_probefunction sc27xx_fgu_resumefunction sc27xx_fgu_suspend
Annotated Snippet
struct sc27xx_fgu_data {
struct regmap *regmap;
struct device *dev;
struct power_supply *battery;
u32 base;
struct mutex lock;
struct gpio_desc *gpiod;
struct iio_channel *channel;
struct iio_channel *charge_chan;
bool bat_present;
int internal_resist;
int total_cap;
int init_cap;
int alarm_cap;
int init_clbcnt;
int max_volt;
int min_volt;
int boot_volt;
int table_len;
int resist_table_len;
int cur_1000ma_adc;
int vol_1000mv_adc;
int calib_resist;
struct power_supply_battery_ocv_table *cap_table;
struct power_supply_resistance_temp_table *resist_table;
};
static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity);
static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data,
int cap, bool int_mode);
static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap);
static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp);
static const char * const sc27xx_charger_supply_name[] = {
"sc2731_charger",
"sc2720_charger",
"sc2721_charger",
"sc2723_charger",
};
static int sc27xx_fgu_adc_to_current(struct sc27xx_fgu_data *data, s64 adc)
{
return DIV_S64_ROUND_CLOSEST(adc * 1000, data->cur_1000ma_adc);
}
static int sc27xx_fgu_adc_to_voltage(struct sc27xx_fgu_data *data, s64 adc)
{
return DIV_S64_ROUND_CLOSEST(adc * 1000, data->vol_1000mv_adc);
}
static int sc27xx_fgu_voltage_to_adc(struct sc27xx_fgu_data *data, int vol)
{
return DIV_ROUND_CLOSEST(vol * data->vol_1000mv_adc, 1000);
}
static bool sc27xx_fgu_is_first_poweron(struct sc27xx_fgu_data *data)
{
int ret, status, cap, mode;
ret = regmap_read(data->regmap,
data->base + SC27XX_FGU_USER_AREA_STATUS, &status);
if (ret)
return false;
/*
* We use low 4 bits to save the last battery capacity and high 12 bits
* to save the system boot mode.
*/
mode = (status & SC27XX_FGU_MODE_AREA_MASK) >> SC27XX_FGU_MODE_AREA_SHIFT;
cap = status & SC27XX_FGU_CAP_AREA_MASK;
/*
* When FGU has been powered down, the user area registers became
* default value (0xffff), which can be used to valid if the system is
* first power on or not.
*/
if (mode == SC27XX_FGU_FIRST_POWERTON || cap == SC27XX_FGU_DEFAULT_CAP)
return true;
return false;
}
static int sc27xx_fgu_save_boot_mode(struct sc27xx_fgu_data *data,
int boot_mode)
{
int ret;
ret = regmap_update_bits(data->regmap,
data->base + SC27XX_FGU_USER_AREA_CLEAR,
SC27XX_FGU_MODE_AREA_MASK,
Annotation
- Immediate include surface: `linux/gpio/consumer.h`, `linux/iio/consumer.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/math64.h`, `linux/module.h`, `linux/nvmem-consumer.h`, `linux/of.h`.
- Detected declarations: `struct sc27xx_fgu_data`, `function sc27xx_fgu_adc_to_current`, `function sc27xx_fgu_adc_to_voltage`, `function sc27xx_fgu_voltage_to_adc`, `function sc27xx_fgu_is_first_poweron`, `function sc27xx_fgu_save_boot_mode`, `function sc27xx_fgu_save_last_cap`, `function sc27xx_fgu_read_last_cap`, `function sc27xx_fgu_get_boot_capacity`, `function sc27xx_fgu_set_clbcnt`.
- 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.