drivers/power/supply/huawei-gaokun-battery.c

Source file repositories/reference/linux-study-clean/drivers/power/supply/huawei-gaokun-battery.c

File Facts

System
Linux kernel
Corpus path
drivers/power/supply/huawei-gaokun-battery.c
Extension
.c
Size
16610 bytes
Lines
646
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 gaokun_psy_bat_status {
	__le16 percentage_now;	/* 0x90 */
	__le16 voltage_now;
	__le16 capacity_now;
	__le16 full_capacity;
	__le16 unknown1;
	__le16 rate_now;
	__le16 unknown2;	/* 0x9C */
} __packed;

struct gaokun_psy_bat_info {
	__le16 unknown3;	/* 0xA0 */
	__le16 design_capacity;
	__le16 design_voltage;
	__le16 serial_number;
	__le16 padding2;
	__le16 cycle_count;	/* 0xAA */
} __packed;

struct gaokun_psy {
	struct gaokun_ec *ec;
	struct device *dev;
	struct notifier_block nb;

	struct power_supply *bat_psy;
	struct power_supply *adp_psy;

	unsigned long update_time;
	struct gaokun_psy_bat_status status;
	struct gaokun_psy_bat_info info;

	char battery_model[0x10]; /* HB30A8P9ECW-22T, the real one is XXX-22A */
	char battery_serial[0x10];
	char battery_vendor[0x10];

	int charge_now;
	int online;
	int bat_present;
};

/* -------------------------------------------------------------------------- */
/* Adapter */

static int gaokun_psy_get_adp_status(struct gaokun_psy *ecbat)
{
	/* _PSR */
	int ret;
	u8 online;

	ret = gaokun_ec_psy_read_byte(ecbat->ec, EC_ADP_STATUS, &online);
	if (ret)
		return ret;

	ecbat->online = !!(online & EC_AC_STATUS);

	return 0;
}

static int gaokun_psy_get_adp_property(struct power_supply *psy,
				       enum power_supply_property psp,
				       union power_supply_propval *val)
{
	struct gaokun_psy *ecbat = power_supply_get_drvdata(psy);
	int ret;

	ret = gaokun_psy_get_adp_status(ecbat);
	if (ret)
		return ret;

	switch (psp) {
	case POWER_SUPPLY_PROP_ONLINE:
		val->intval = ecbat->online;
		break;
	case POWER_SUPPLY_PROP_USB_TYPE:
		val->intval = POWER_SUPPLY_USB_TYPE_C;
		break;
	default:
		return -EINVAL;
	}

	return 0;
}

static enum power_supply_property gaokun_psy_adp_props[] = {
	POWER_SUPPLY_PROP_ONLINE,
	POWER_SUPPLY_PROP_USB_TYPE,
};

static const struct power_supply_desc gaokun_psy_adp_desc = {
	.name		= "gaokun-ec-adapter",

Annotation

Implementation Notes