drivers/power/supply/max8903_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/max8903_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/max8903_charger.c- Extension
.c- Size
- 11172 bytes
- Lines
- 423
- 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/gpio/consumer.hlinux/interrupt.hlinux/module.hlinux/of.hlinux/slab.hlinux/power_supply.hlinux/platform_device.h
Detected Declarations
struct max8903_datafunction max8903_get_propertyfunction max8903_dcinfunction max8903_usbinfunction max8903_faultfunction max8903_setup_gpiosfunction max8903_probe
Annotated Snippet
struct max8903_data {
struct device *dev;
struct power_supply *psy;
struct power_supply_desc psy_desc;
/*
* GPIOs
* chg, flt, dcm and usus are optional.
* dok or uok must be present.
* If dok is present, cen must be present.
*/
struct gpio_desc *cen; /* Charger Enable input */
struct gpio_desc *dok; /* DC (Adapter) Power OK output */
struct gpio_desc *uok; /* USB Power OK output */
struct gpio_desc *chg; /* Charger status output */
struct gpio_desc *flt; /* Fault output */
struct gpio_desc *dcm; /* Current-Limit Mode input (1: DC, 2: USB) */
struct gpio_desc *usus; /* USB Suspend Input (1: suspended) */
bool fault;
bool usb_in;
bool ta_in;
};
static enum power_supply_property max8903_charger_props[] = {
POWER_SUPPLY_PROP_STATUS, /* Charger status output */
POWER_SUPPLY_PROP_ONLINE, /* External power source */
POWER_SUPPLY_PROP_HEALTH, /* Fault or OK */
};
static int max8903_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct max8903_data *data = power_supply_get_drvdata(psy);
switch (psp) {
case POWER_SUPPLY_PROP_STATUS:
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
if (data->chg) {
if (gpiod_get_value(data->chg))
/* CHG asserted */
val->intval = POWER_SUPPLY_STATUS_CHARGING;
else if (data->usb_in || data->ta_in)
val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
else
val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
}
break;
case POWER_SUPPLY_PROP_ONLINE:
val->intval = 0;
if (data->usb_in || data->ta_in)
val->intval = 1;
break;
case POWER_SUPPLY_PROP_HEALTH:
val->intval = POWER_SUPPLY_HEALTH_GOOD;
if (data->fault)
val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
break;
default:
return -EINVAL;
}
return 0;
}
static irqreturn_t max8903_dcin(int irq, void *_data)
{
struct max8903_data *data = _data;
bool ta_in;
enum power_supply_type old_type;
/*
* This means the line is asserted.
*
* The signal is active low, but the inversion is handled in the GPIO
* library as the line should be flagged GPIO_ACTIVE_LOW in the device
* tree.
*/
ta_in = gpiod_get_value(data->dok);
if (ta_in == data->ta_in)
return IRQ_HANDLED;
data->ta_in = ta_in;
/* Set Current-Limit-Mode 1:DC 0:USB */
if (data->dcm)
gpiod_set_value(data->dcm, ta_in);
/* Charger Enable / Disable */
if (data->cen) {
Annotation
- Immediate include surface: `linux/gpio/consumer.h`, `linux/interrupt.h`, `linux/module.h`, `linux/of.h`, `linux/slab.h`, `linux/power_supply.h`, `linux/platform_device.h`.
- Detected declarations: `struct max8903_data`, `function max8903_get_property`, `function max8903_dcin`, `function max8903_usbin`, `function max8903_fault`, `function max8903_setup_gpios`, `function max8903_probe`.
- 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.