drivers/power/supply/da9150-charger.c

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

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/da9150-charger.c
Extension
.c
Size
16419 bytes
Lines
647
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 da9150_charger {
	struct da9150 *da9150;
	struct device *dev;

	struct power_supply *usb;
	struct power_supply *battery;
	struct power_supply *supply_online;

	struct usb_phy *usb_phy;
	struct notifier_block otg_nb;
	struct work_struct otg_work;
	unsigned long usb_event;

	struct iio_channel *ibus_chan;
	struct iio_channel *vbus_chan;
	struct iio_channel *tjunc_chan;
	struct iio_channel *vbat_chan;
};

static inline int da9150_charger_supply_online(struct da9150_charger *charger,
					       struct power_supply *psy,
					       union power_supply_propval *val)
{
	val->intval = (psy == charger->supply_online) ? 1 : 0;

	return 0;
}

/* Charger Properties */
static int da9150_charger_vbus_voltage_now(struct da9150_charger *charger,
					   union power_supply_propval *val)
{
	int v_val, ret;

	/* Read processed value - mV units */
	ret = iio_read_channel_processed(charger->vbus_chan, &v_val);
	if (ret < 0)
		return ret;

	/* Convert voltage to expected uV units */
	val->intval = v_val * 1000;

	return 0;
}

static int da9150_charger_ibus_current_avg(struct da9150_charger *charger,
					   union power_supply_propval *val)
{
	int i_val, ret;

	/* Read processed value - mA units */
	ret = iio_read_channel_processed(charger->ibus_chan, &i_val);
	if (ret < 0)
		return ret;

	/* Convert current to expected uA units */
	val->intval = i_val * 1000;

	return 0;
}

static int da9150_charger_tjunc_temp(struct da9150_charger *charger,
				     union power_supply_propval *val)
{
	int t_val, ret;

	/* Read processed value - 0.001 degrees C units */
	ret = iio_read_channel_processed(charger->tjunc_chan, &t_val);
	if (ret < 0)
		return ret;

	/* Convert temp to expect 0.1 degrees C units */
	val->intval = t_val / 100;

	return 0;
}

static enum power_supply_property da9150_charger_props[] = {
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_VOLTAGE_NOW,
	POWER_SUPPLY_PROP_CURRENT_AVG,
	POWER_SUPPLY_PROP_TEMP,
};

static int da9150_charger_get_prop(struct power_supply *psy,
				   enum power_supply_property psp,
				   union power_supply_propval *val)
{
	struct da9150_charger *charger = dev_get_drvdata(psy->dev.parent);
	int ret;

Annotation

Implementation Notes