drivers/power/supply/mp2629_charger.c

Source file repositories/reference/linux-study-clean/drivers/power/supply/mp2629_charger.c

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/mp2629_charger.c
Extension
.c
Size
17235 bytes
Lines
663
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct mp2629_charger {
	struct device *dev;
	int status;
	int fault;

	struct regmap *regmap;
	struct regmap_field *regmap_fields[MP2629_MAX_FIELD];
	struct mutex lock;
	struct power_supply *usb;
	struct power_supply *battery;
	struct iio_channel *iiochan[MP2629_ADC_CHAN_END];
};

struct mp2629_prop {
	int reg;
	int mask;
	int min;
	int max;
	int step;
	int shift;
};

static enum power_supply_property mp2629_charger_usb_props[] = {
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_USB_TYPE,
	POWER_SUPPLY_PROP_VOLTAGE_NOW,
	POWER_SUPPLY_PROP_CURRENT_NOW,
	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
	POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT,
};

static enum power_supply_property mp2629_charger_bat_props[] = {
	POWER_SUPPLY_PROP_STATUS,
	POWER_SUPPLY_PROP_HEALTH,
	POWER_SUPPLY_PROP_CHARGE_TYPE,
	POWER_SUPPLY_PROP_VOLTAGE_NOW,
	POWER_SUPPLY_PROP_CURRENT_NOW,
	POWER_SUPPLY_PROP_CAPACITY,
	POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
	POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
};

static struct mp2629_prop props[] = {
	MP2629_PROPS(INPUT_ILIM, 100000, 3250000, 50000),
	MP2629_PROPS(INPUT_VLIM, 3800000, 5300000, 100000),
	MP2629_PROPS(CHARGE_ILIM, 320000, 4520000, 40000),
	MP2629_PROPS(CHARGE_VLIM, 3400000, 4670000, 10000),
	MP2629_PROPS(PRECHARGE, 120000, 720000, 40000),
	MP2629_PROPS(TERM_CURRENT, 80000, 680000, 40000),
};

static const struct reg_field mp2629_reg_fields[] = {
	[INPUT_ILIM]	= REG_FIELD(MP2629_REG_INPUT_ILIM, 0, 5),
	[INPUT_VLIM]	= REG_FIELD(MP2629_REG_INPUT_VLIM, 0, 3),
	[CHARGE_ILIM]	= REG_FIELD(MP2629_REG_CHARGE_ILIM, 0, 6),
	[CHARGE_VLIM]	= REG_FIELD(MP2629_REG_CHARGE_VLIM, 1, 7),
	[PRECHARGE]	= REG_FIELD(MP2629_REG_PRECHARGE, 4, 7),
	[TERM_CURRENT]	= REG_FIELD(MP2629_REG_TERM_CURRENT, 0, 3),
};

static char *adc_chan_name[] = {
	"mp2629-batt-volt",
	"mp2629-system-volt",
	"mp2629-input-volt",
	"mp2629-batt-current",
	"mp2629-input-current",
};

static int mp2629_read_adc(struct mp2629_charger *charger,
			   enum mp2629_adc_chan ch,
			   union power_supply_propval *val)
{
	int ret;
	int chval;

	ret = iio_read_channel_processed(charger->iiochan[ch], &chval);
	if (ret)
		return ret;

	val->intval = chval * 1000;

	return 0;
}

static int mp2629_get_prop(struct mp2629_charger *charger,
			   enum mp2629_field fld,

Annotation

Implementation Notes