drivers/power/supply/qcom_smbx.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/qcom_smbx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/qcom_smbx.c- Extension
.c- Size
- 31564 bytes
- Lines
- 1060
- 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/bits.hlinux/devm-helpers.hlinux/iio/consumer.hlinux/interrupt.hlinux/kernel.hlinux/minmax.hlinux/module.hlinux/platform_device.hlinux/pm_wakeirq.hlinux/of.hlinux/power_supply.hlinux/regmap.hlinux/types.hlinux/workqueue.h
Detected Declarations
struct smb_init_registerstruct smb_chipenum charger_statusfunction smb_get_prop_usb_onlinefunction smb_apsd_get_charger_typefunction smb_get_prop_statusfunction smb_get_current_limitfunction smb_set_current_limitfunction smb_status_change_workfunction smb_get_iio_chanfunction smb_get_prop_healthfunction smb_get_propertyfunction smb_set_propertyfunction smb_property_is_writablefunction smb_handle_batt_overvoltagefunction smb_handle_usb_pluginfunction smb_handle_usb_icl_changefunction smb_handle_wdog_barkfunction smb_init_hwfunction smb_init_irqfunction smb_probe
Annotated Snippet
struct smb_init_register {
u16 addr;
u8 mask;
u8 val;
};
/**
* struct smb_chip - smb chip structure
* @dev: Device reference for power_supply
* @name: The platform device name
* @base: Base address for smb registers
* @regmap: Register map
* @batt_info: Battery data from DT
* @status_change_work: Worker to handle plug/unplug events
* @cable_irq: USB plugin IRQ
* @wakeup_enabled: If the cable IRQ will cause a wakeup
* @usb_in_i_chan: USB_IN current measurement channel
* @usb_in_v_chan: USB_IN voltage measurement channel
* @chg_psy: Charger power supply instance
*/
struct smb_chip {
struct device *dev;
const char *name;
unsigned int base;
struct regmap *regmap;
struct power_supply_battery_info *batt_info;
struct delayed_work status_change_work;
int cable_irq;
bool wakeup_enabled;
struct iio_channel *usb_in_i_chan;
struct iio_channel *usb_in_v_chan;
struct power_supply *chg_psy;
};
static enum power_supply_property smb_properties[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_CURRENT_MAX,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_USB_TYPE,
};
static int smb_get_prop_usb_online(struct smb_chip *chip, int *val)
{
unsigned int stat;
int rc;
rc = regmap_read(chip->regmap, chip->base + POWER_PATH_STATUS, &stat);
if (rc < 0) {
dev_err(chip->dev, "Couldn't read power path status: %d\n", rc);
return rc;
}
*val = (stat & P_PATH_USE_USBIN_BIT) &&
(stat & P_PATH_VALID_INPUT_POWER_SOURCE_STS_BIT);
return 0;
}
/*
* Qualcomm "automatic power source detection" aka APSD
* tells us what type of charger we're connected to.
*/
static int smb_apsd_get_charger_type(struct smb_chip *chip, int *val)
{
unsigned int apsd_stat, stat;
int usb_online = 0;
int rc;
rc = smb_get_prop_usb_online(chip, &usb_online);
if (!usb_online) {
*val = POWER_SUPPLY_USB_TYPE_UNKNOWN;
return rc;
}
rc = regmap_read(chip->regmap, chip->base + APSD_STATUS, &apsd_stat);
if (rc < 0) {
dev_err(chip->dev, "Failed to read apsd status, rc = %d", rc);
return rc;
}
if (!(apsd_stat & APSD_DTC_STATUS_DONE_BIT)) {
dev_dbg(chip->dev, "Apsd not ready");
return -EAGAIN;
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/devm-helpers.h`, `linux/iio/consumer.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/minmax.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct smb_init_register`, `struct smb_chip`, `enum charger_status`, `function smb_get_prop_usb_online`, `function smb_apsd_get_charger_type`, `function smb_get_prop_status`, `function smb_get_current_limit`, `function smb_set_current_limit`, `function smb_status_change_work`, `function smb_get_iio_chan`.
- 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.