drivers/power/supply/axp20x_usb_power.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/axp20x_usb_power.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/axp20x_usb_power.c- Extension
.c- Size
- 29580 bytes
- Lines
- 1083
- 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/bitops.hlinux/device.hlinux/devm-helpers.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/mfd/axp20x.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm.hlinux/power_supply.hlinux/regmap.hlinux/slab.hlinux/iio/consumer.hlinux/workqueue.h
Detected Declarations
struct axp20x_usb_powerstruct axp_datastruct axp20x_usb_powerfunction axp20x_usb_vbus_needs_pollingfunction axp20x_usb_power_irqfunction axp20x_usb_power_poll_vbusfunction axp717_usb_power_poll_vbusfunction axp20x_get_usb_typefunction axp20x_usb_power_get_propertyfunction axp717_usb_power_get_propertyfunction axp20x_usb_power_set_voltage_minfunction axp717_usb_power_set_voltage_minfunction axp20x_usb_power_set_input_current_limitfunction axp717_usb_power_set_input_current_limitfunction axp20x_usb_power_set_propertyfunction axp717_usb_power_set_propertyfunction axp20x_usb_power_prop_writeablefunction axp717_usb_power_prop_writeablefunction axp20x_configure_iio_channelsfunction axp717_configure_iio_channelsfunction axp20x_configure_adc_registersfunction axp717_configure_adc_registersfunction axp20x_usb_power_suspendfunction axp20x_usb_power_resumefunction axp20x_regmap_field_alloc_optionalfunction axp20x_usb_power_parse_dtfunction axp20x_usb_power_probe
Annotated Snippet
struct axp_data {
const struct power_supply_desc *power_desc;
const char * const *irq_names;
unsigned int num_irq_names;
const int *curr_lim_table;
int curr_lim_table_size;
struct reg_field curr_lim_fld;
struct reg_field vbus_valid_bit;
struct reg_field vbus_mon_bit;
struct reg_field usb_bc_en_bit;
struct reg_field usb_bc_det_fld;
struct reg_field vbus_disable_bit;
bool vbus_needs_polling: 1;
void (*axp20x_read_vbus)(struct work_struct *work);
int (*axp20x_cfg_iio_chan)(struct platform_device *pdev,
struct axp20x_usb_power *power);
int (*axp20x_cfg_adc_reg)(struct axp20x_usb_power *power);
};
struct axp20x_usb_power {
struct device *dev;
struct regmap *regmap;
struct regmap_field *curr_lim_fld;
struct regmap_field *vbus_valid_bit;
struct regmap_field *vbus_mon_bit;
struct regmap_field *usb_bc_en_bit;
struct regmap_field *usb_bc_det_fld;
struct regmap_field *vbus_disable_bit;
struct power_supply *supply;
const struct axp_data *axp_data;
struct iio_channel *vbus_v;
struct iio_channel *vbus_i;
struct delayed_work vbus_detect;
int max_input_cur;
unsigned int old_status;
unsigned int online;
unsigned int num_irqs;
unsigned int irqs[] __counted_by(num_irqs);
};
static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power)
{
/*
* Polling is only necessary while VBUS is offline. While online, a
* present->absent transition implies an online->offline transition
* and will trigger the VBUS_REMOVAL IRQ.
*/
if (power->axp_data->vbus_needs_polling && !power->online)
return true;
return false;
}
static irqreturn_t axp20x_usb_power_irq(int irq, void *devid)
{
struct axp20x_usb_power *power = devid;
power_supply_changed(power->supply);
mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME);
return IRQ_HANDLED;
}
static void axp20x_usb_power_poll_vbus(struct work_struct *work)
{
struct axp20x_usb_power *power =
container_of(work, struct axp20x_usb_power, vbus_detect.work);
unsigned int val;
int ret;
ret = regmap_read(power->regmap, AXP20X_PWR_INPUT_STATUS, &val);
if (ret)
goto out;
val &= (AXP20X_PWR_STATUS_VBUS_PRESENT | AXP20X_PWR_STATUS_VBUS_USED);
if (val != power->old_status)
power_supply_changed(power->supply);
if (power->usb_bc_en_bit && (val & AXP20X_PWR_STATUS_VBUS_PRESENT) !=
(power->old_status & AXP20X_PWR_STATUS_VBUS_PRESENT)) {
dev_dbg(power->dev, "Cable status changed, re-enabling USB BC");
ret = regmap_field_write(power->usb_bc_en_bit, 1);
if (ret)
dev_err(power->dev, "failed to enable USB BC: errno %d",
ret);
}
power->old_status = val;
power->online = val & AXP20X_PWR_STATUS_VBUS_USED;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/device.h`, `linux/devm-helpers.h`, `linux/init.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/mfd/axp20x.h`, `linux/module.h`.
- Detected declarations: `struct axp20x_usb_power`, `struct axp_data`, `struct axp20x_usb_power`, `function axp20x_usb_vbus_needs_polling`, `function axp20x_usb_power_irq`, `function axp20x_usb_power_poll_vbus`, `function axp717_usb_power_poll_vbus`, `function axp20x_get_usb_type`, `function axp20x_usb_power_get_property`, `function axp717_usb_power_get_property`.
- 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.