drivers/power/supply/cpcap-charger.c

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

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/cpcap-charger.c
Extension
.c
Size
25429 bytes
Lines
981
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 cpcap_charger_ddata {
	struct device *dev;
	struct regmap *reg;
	struct list_head irq_list;
	struct delayed_work detect_work;
	struct delayed_work vbus_work;
	struct gpio_desc *gpio[2];		/* gpio_reven0 & 1 */

	struct iio_channel *channels[CPCAP_CHARGER_IIO_NR];

	struct power_supply *usb;

	struct phy_companion comparator;	/* For USB VBUS */
	unsigned int vbus_enabled:1;
	unsigned int feeding_vbus:1;
	atomic_t active;

	int status;
	int voltage;
	int limit_current;
};

struct cpcap_interrupt_desc {
	int irq;
	struct list_head node;
	const char *name;
};

struct cpcap_charger_ints_state {
	bool chrg_det;
	bool rvrs_chrg;
	bool vbusov;

	bool chrg_se1b;
	bool rvrs_mode;
	bool chrgcurr2;
	bool chrgcurr1;
	bool vbusvld;

	bool battdetb;
};

static enum power_supply_property cpcap_charger_props[] = {
	POWER_SUPPLY_PROP_STATUS,
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
	POWER_SUPPLY_PROP_VOLTAGE_NOW,
	POWER_SUPPLY_PROP_CURRENT_NOW,
};

static int cpcap_charger_get_charge_voltage(struct cpcap_charger_ddata *ddata)
{
	struct iio_channel *channel;
	int error, value = 0;

	channel = ddata->channels[CPCAP_CHARGER_IIO_VOLTAGE];
	error = iio_read_channel_processed(channel, &value);
	if (error < 0) {
		dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);

		return 0;
	}

	return value;
}

static int cpcap_charger_get_charge_current(struct cpcap_charger_ddata *ddata)
{
	struct iio_channel *channel;
	int error, value = 0;

	channel = ddata->channels[CPCAP_CHARGER_IIO_CHRG_CURRENT];
	error = iio_read_channel_processed(channel, &value);
	if (error < 0) {
		dev_warn(ddata->dev, "%s failed: %i\n", __func__, error);

		return 0;
	}

	return value;
}

static int cpcap_charger_get_property(struct power_supply *psy,
				      enum power_supply_property psp,
				      union power_supply_propval *val)
{
	struct cpcap_charger_ddata *ddata = dev_get_drvdata(psy->dev.parent);

	switch (psp) {

Annotation

Implementation Notes