drivers/power/supply/rt9756.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/rt9756.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/rt9756.c- Extension
.c- Size
- 25852 bytes
- Lines
- 956
- 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/atomic.hlinux/cleanup.hlinux/i2c.hlinux/kernel.hlinux/linear_range.hlinux/interrupt.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/power_supply.hlinux/property.hlinux/regmap.hlinux/sysfs.hlinux/util_macros.h
Detected Declarations
struct charger_eventstruct rt9756_datastruct rt975x_dev_dataenum rt9756_modelenum rt9756_adc_chanenum rt9756_usb_typeenum rt9756_fieldsenum rt9756_rangesfunction rt9756_get_value_field_rangefunction rt9756_set_value_field_rangefunction rt9756_get_adcfunction rt9756_get_switching_statefunction rt9756_get_charger_healthfunction rt9756_get_charger_onlinefunction rt9756_get_vbus_ovpfunction rt9756_set_vbus_ovpfunction rt9756_psy_get_propertyfunction rt9756_psy_set_propertyfunction rt9756_bat_psy_get_propertyfunction rt9756_psy_property_is_writeablefunction watchdog_timer_showfunction watchdog_timer_storefunction operation_mode_showfunction operation_mode_storefunction rt9756_register_psyfunction rt9756_get_usb_typefunction rt9756_irq_handlerfunction rt9756_config_batsense_resistorfunction rt9756_check_device_modelfunction rt9770_check_device_modelfunction rt9756_probefunction rt9756_shutdown
Annotated Snippet
struct charger_event {
unsigned int flag1;
unsigned int flag2;
unsigned int flag3;
unsigned int flag4;
};
struct rt9756_data {
struct device *dev;
struct regmap *regmap;
struct regmap_field *rm_fields[F_MAX_FIELD];
struct power_supply *psy;
struct power_supply *bat_psy;
struct mutex adc_lock;
struct power_supply_desc psy_desc;
struct power_supply_desc bat_psy_desc;
struct charger_event chg_evt;
unsigned int rg_resistor;
unsigned int real_resistor;
enum rt9756_model model;
atomic_t usb_type;
};
struct rt975x_dev_data {
const struct regmap_config *regmap_config;
const struct reg_field *reg_fields;
const struct reg_sequence *init_regs;
size_t num_init_regs;
int (*check_device_model)(struct rt9756_data *data);
};
static int rt9756_get_value_field_range(struct rt9756_data *data, enum rt9756_fields en_field,
enum rt9756_fields field, enum rt9756_ranges rsel, int *val)
{
const struct linear_range *range = rt9756_chg_ranges + rsel;
unsigned int enable, selector, value;
int ret;
ret = regmap_field_read(data->rm_fields[en_field], &enable);
if (ret)
return ret;
if (!enable) {
*val = 0;
return 0;
}
ret = regmap_field_read(data->rm_fields[field], &selector);
if (ret)
return ret;
ret = linear_range_get_value(range, selector, &value);
if (ret)
return ret;
*val = (int)value;
return 0;
}
static int rt9756_set_value_field_range(struct rt9756_data *data, enum rt9756_fields en_field,
enum rt9756_fields field, enum rt9756_ranges rsel, int val)
{
const struct linear_range *range = rt9756_chg_ranges + rsel;
unsigned int selector, value;
int ret;
if (!val)
return regmap_field_write(data->rm_fields[en_field], 0);
value = (unsigned int)val;
linear_range_get_selector_within(range, value, &selector);
ret = regmap_field_write(data->rm_fields[field], selector);
if (ret)
return ret;
return regmap_field_write(data->rm_fields[en_field], 1);
}
static int rt9756_get_adc(struct rt9756_data *data, enum rt9756_adc_chan chan,
int *val)
{
struct regmap *regmap = data->regmap;
unsigned int reg_addr = RT9756_REG_VBUSADC + chan * 2;
unsigned int mask = RT9756_ADCEN_MASK | RT9756_ADCONCE_MASK;
unsigned int shift = 0, adc_cntl;
__be16 raws;
int scale, offset = 0, ret;
guard(mutex)(&data->adc_lock);
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/cleanup.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/linear_range.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct charger_event`, `struct rt9756_data`, `struct rt975x_dev_data`, `enum rt9756_model`, `enum rt9756_adc_chan`, `enum rt9756_usb_type`, `enum rt9756_fields`, `enum rt9756_ranges`, `function rt9756_get_value_field_range`, `function rt9756_set_value_field_range`.
- 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.