drivers/power/supply/acer_a500_battery.c

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

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/acer_a500_battery.c
Extension
.c
Size
7268 bytes
Lines
298
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 a500_battery {
	struct delayed_work poll_work;
	struct power_supply *psy;
	struct regmap *regmap;
	unsigned int capacity;
};

static bool a500_battery_update_capacity(struct a500_battery *bat)
{
	unsigned int capacity;
	int err;

	err = regmap_read(bat->regmap, ec_data[REG_CAPACITY].reg, &capacity);
	if (err)
		return false;

	/* capacity can be >100% even if max value is 100% */
	capacity = min(capacity, 100u);

	if (bat->capacity != capacity) {
		bat->capacity = capacity;
		return true;
	}

	return false;
}

static int a500_battery_get_status(struct a500_battery *bat)
{
	if (bat->capacity < 100) {
		if (power_supply_am_i_supplied(bat->psy))
			return POWER_SUPPLY_STATUS_CHARGING;
		else
			return POWER_SUPPLY_STATUS_DISCHARGING;
	}

	return POWER_SUPPLY_STATUS_FULL;
}

static void a500_battery_unit_adjustment(struct device *dev,
					 enum power_supply_property psp,
					 union power_supply_propval *val)
{
	const unsigned int base_unit_conversion = 1000;
	const unsigned int temp_kelvin_to_celsius = 2731;

	switch (psp) {
	case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
	case POWER_SUPPLY_PROP_CURRENT_NOW:
	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
		val->intval *= base_unit_conversion;
		break;

	case POWER_SUPPLY_PROP_TEMP:
		val->intval -= temp_kelvin_to_celsius;
		break;

	case POWER_SUPPLY_PROP_PRESENT:
		val->intval = !!val->intval;
		break;

	default:
		dev_dbg(dev,
			"%s: no need for unit conversion %d\n", __func__, psp);
	}
}

static int a500_battery_get_ec_data_index(struct device *dev,
					  enum power_supply_property psp)
{
	unsigned int i;

	/*
	 * DESIGN_CAPACITY register always returns a non-zero value if
	 * battery is connected and zero if disconnected, hence we'll use
	 * it for judging the battery presence.
	 */
	if (psp == POWER_SUPPLY_PROP_PRESENT)
		psp = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;

	for (i = 0; i < ARRAY_SIZE(ec_data); i++)
		if (psp == ec_data[i].psp)
			return i;

	dev_dbg(dev, "%s: invalid property %u\n", __func__, psp);

	return -EINVAL;
}

static int a500_battery_get_property(struct power_supply *psy,

Annotation

Implementation Notes