drivers/power/supply/rt9455_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/rt9455_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/rt9455_charger.c- Extension
.c- Size
- 49239 bytes
- Lines
- 1756
- 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/module.hlinux/interrupt.hlinux/delay.hlinux/of.hlinux/pm_runtime.hlinux/power_supply.hlinux/i2c.hlinux/acpi.hlinux/usb/phy.hlinux/regmap.h
Detected Declarations
struct rt9455_infoenum rt9455_fieldsfunction rt9455_find_idxfunction rt9455_get_field_valfunction rt9455_set_field_valfunction rt9455_register_resetfunction rt9455_charger_get_statusfunction rt9455_charger_get_healthfunction rt9455_charger_get_battery_presencefunction rt9455_charger_get_onlinefunction rt9455_charger_get_currentfunction rt9455_charger_get_current_maxfunction rt9455_charger_get_voltagefunction rt9455_charger_get_voltage_maxfunction rt9455_charger_get_term_currentfunction rt9455_charger_get_propertyfunction rt9455_hw_initfunction rt9455_set_boost_voltage_before_boost_modefunction rt9455_set_voreg_before_charge_modefunction rt9455_irq_handler_check_irq1_registerfunction rt9455_irq_handler_check_irq2_registerfunction rt9455_irq_handler_check_irq3_registerfunction rt9455_irq_handler_threadfunction rt9455_discover_chargerfunction rt9455_usb_event_nonefunction rt9455_usb_event_vbusfunction rt9455_usb_event_idfunction rt9455_usb_event_chargerfunction rt9455_usb_eventfunction rt9455_pwr_rdy_work_callbackfunction rt9455_max_charging_time_work_callbackfunction rt9455_batt_presence_work_callbackfunction rt9455_is_writeable_regfunction rt9455_is_volatile_regfunction rt9455_probefunction rt9455_remove
Annotated Snippet
struct rt9455_info {
struct i2c_client *client;
struct regmap *regmap;
struct regmap_field *regmap_fields[F_MAX_FIELDS];
struct power_supply *charger;
#if IS_ENABLED(CONFIG_USB_PHY)
struct usb_phy *usb_phy;
struct notifier_block nb;
#endif
struct delayed_work pwr_rdy_work;
struct delayed_work max_charging_time_work;
struct delayed_work batt_presence_work;
u32 voreg;
u32 boost_voltage;
};
/*
* Iterate through each element of the 'tbl' array until an element whose value
* is greater than v is found. Return the index of the respective element,
* or the index of the last element in the array, if no such element is found.
*/
static unsigned int rt9455_find_idx(const int tbl[], int tbl_size, int v)
{
int i;
/*
* No need to iterate until the last index in the table because
* if no element greater than v is found in the table,
* or if only the last element is greater than v,
* function returns the index of the last element.
*/
for (i = 0; i < tbl_size - 1; i++)
if (v <= tbl[i])
return i;
return (tbl_size - 1);
}
static int rt9455_get_field_val(struct rt9455_info *info,
enum rt9455_fields field,
const int tbl[], int tbl_size, int *val)
{
unsigned int v;
int ret;
ret = regmap_field_read(info->regmap_fields[field], &v);
if (ret)
return ret;
v = (v >= tbl_size) ? (tbl_size - 1) : v;
*val = tbl[v];
return 0;
}
static int rt9455_set_field_val(struct rt9455_info *info,
enum rt9455_fields field,
const int tbl[], int tbl_size, int val)
{
unsigned int idx = rt9455_find_idx(tbl, tbl_size, val);
return regmap_field_write(info->regmap_fields[field], idx);
}
static int rt9455_register_reset(struct rt9455_info *info)
{
struct device *dev = &info->client->dev;
unsigned int v;
int ret, limit = 100;
ret = regmap_field_write(info->regmap_fields[F_RST], 0x01);
if (ret) {
dev_err(dev, "Failed to set RST bit\n");
return ret;
}
/*
* To make sure that reset operation has finished, loop until RST bit
* is set to 0.
*/
do {
ret = regmap_field_read(info->regmap_fields[F_RST], &v);
if (ret) {
dev_err(dev, "Failed to read RST bit\n");
return ret;
}
if (!v)
break;
Annotation
- Immediate include surface: `linux/module.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/of.h`, `linux/pm_runtime.h`, `linux/power_supply.h`, `linux/i2c.h`, `linux/acpi.h`.
- Detected declarations: `struct rt9455_info`, `enum rt9455_fields`, `function rt9455_find_idx`, `function rt9455_get_field_val`, `function rt9455_set_field_val`, `function rt9455_register_reset`, `function rt9455_charger_get_status`, `function rt9455_charger_get_health`, `function rt9455_charger_get_battery_presence`, `function rt9455_charger_get_online`.
- 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.