drivers/power/supply/rk817_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/rk817_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/rk817_charger.c- Extension
.c- Size
- 36931 bytes
- Lines
- 1250
- 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/unaligned.hlinux/devm-helpers.hlinux/mfd/rk808.hlinux/irq.hlinux/of.hlinux/platform_device.hlinux/power_supply.hlinux/regmap.h
Detected Declarations
struct rk817_chargerenum rk817_charge_statusenum rk817_chg_curfunction rk817_chg_cur_to_regfunction rk817_chg_cur_from_regfunction rk817_bat_calib_volfunction rk817_bat_calib_curfunction rk817_record_battery_nvram_valuesfunction rk817_bat_calib_capfunction rk817_read_propsfunction rk817_bat_get_propfunction rk817_chg_get_propfunction rk817_plug_in_isrfunction rk817_plug_out_isrfunction rk817_bat_set_propfunction rk817_bat_prop_writeablefunction rk817_read_battery_nvram_valuesfunction devicefunction rk817_read_or_set_full_charge_on_bootfunction voltagefunction rk817_battery_initfunction rk817_charging_monitorfunction rk817_cleanup_nodefunction rk817_charger_probefunction rk817_suspendfunction rk817_resume
Annotated Snippet
struct rk817_charger {
struct device *dev;
struct rk808 *rk808;
struct power_supply *bat_ps;
struct power_supply *chg_ps;
bool plugged_in;
bool battery_present;
/*
* voltage_k and voltage_b values are used to calibrate the ADC
* voltage readings. While they are documented in the BSP kernel and
* datasheet as voltage_k and voltage_b, there is no further
* information explaining them in more detail.
*/
uint32_t voltage_k;
uint32_t voltage_b;
/*
* soc - state of charge - like the BSP this is stored as a percentage,
* to the thousandth. BSP has a display state of charge (dsoc) and a
* remaining state of charge (rsoc). This value will be used for both
* purposes here so we don't do any fancy math to try and "smooth" the
* charge and just report it as it is. Note for example an soc of 100
* is stored as 100000, an soc of 50 is stored as 50000, etc.
*/
int soc;
/*
* Capacity of battery when fully charged, equal or less than design
* capacity depending upon wear. BSP kernel saves to nvram in mAh,
* so this value is in mAh not the standard uAh.
*/
int fcc_mah;
/*
* Calibrate the SOC on a fully charged battery, this way we can use
* the calibrated SOC value to correct for columb counter drift.
*/
bool soc_cal;
/* Implementation specific immutable properties from device tree */
int res_div;
int sleep_enter_current_ua;
int sleep_filter_current_ua;
int bat_charge_full_design_uah;
int bat_voltage_min_design_uv;
int bat_voltage_max_design_uv;
/* Values updated periodically by driver for display. */
int charge_now_uah;
int volt_avg_uv;
int cur_avg_ua;
int max_chg_cur_ua;
int max_chg_volt_uv;
int charge_status;
int charger_input_volt_avg_uv;
/* Work queue to periodically update values. */
struct delayed_work work;
};
/* ADC coefficients extracted from BSP kernel */
#define ADC_TO_CURRENT(adc_value, res_div) \
(adc_value * 172 / res_div)
#define CURRENT_TO_ADC(current, samp_res) \
(current * samp_res / 172)
#define CHARGE_TO_ADC(capacity, res_div) \
(capacity * res_div * 3600 / 172 * 1000)
#define ADC_TO_CHARGE_UAH(adc_value, res_div) \
(adc_value / 3600 * 172 / res_div)
static int rk817_chg_cur_to_reg(u32 chg_cur_ma)
{
if (chg_cur_ma >= 3500)
return CHG_3_5A;
else if (chg_cur_ma >= 3000)
return CHG_3A;
else if (chg_cur_ma >= 2750)
return CHG_2_75A;
else if (chg_cur_ma >= 2500)
return CHG_2_5A;
else if (chg_cur_ma >= 2000)
return CHG_2A;
else if (chg_cur_ma >= 1500)
return CHG_1_5A;
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/devm-helpers.h`, `linux/mfd/rk808.h`, `linux/irq.h`, `linux/of.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/regmap.h`.
- Detected declarations: `struct rk817_charger`, `enum rk817_charge_status`, `enum rk817_chg_cur`, `function rk817_chg_cur_to_reg`, `function rk817_chg_cur_from_reg`, `function rk817_bat_calib_vol`, `function rk817_bat_calib_cur`, `function rk817_record_battery_nvram_values`, `function rk817_bat_calib_cap`, `function rk817_read_props`.
- 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.