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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/auxiliary_bus.hlinux/bits.hlinux/delay.hlinux/jiffies.hlinux/module.hlinux/notifier.hlinux/platform_data/huawei-gaokun-ec.hlinux/power_supply.hlinux/sprintf.h
Detected Declarations
struct gaokun_psy_bat_statusstruct gaokun_psy_bat_infostruct gaokun_psyfunction gaokun_psy_get_adp_statusfunction gaokun_psy_get_adp_propertyfunction gaokun_psy_get_bat_presentfunction gaokun_psy_bat_presentfunction gaokun_psy_get_bat_infofunction gaokun_psy_update_bat_chargefunction gaokun_psy_get_bat_statusfunction gaokun_psy_initfunction gaokun_psy_get_bat_propertyfunction gaokun_psy_set_bat_propertyfunction gaokun_psy_is_bat_property_writeablefunction battery_adaptive_charge_showfunction battery_adaptive_charge_storefunction get_charge_delayfunction set_charge_delayfunction smart_charge_delay_showfunction smart_charge_delay_storefunction gaokun_psy_notifyfunction gaokun_psy_probefunction gaokun_psy_remove
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
- Immediate include surface: `linux/auxiliary_bus.h`, `linux/bits.h`, `linux/delay.h`, `linux/jiffies.h`, `linux/module.h`, `linux/notifier.h`, `linux/platform_data/huawei-gaokun-ec.h`, `linux/power_supply.h`.
- Detected declarations: `struct gaokun_psy_bat_status`, `struct gaokun_psy_bat_info`, `struct gaokun_psy`, `function gaokun_psy_get_adp_status`, `function gaokun_psy_get_adp_property`, `function gaokun_psy_get_bat_present`, `function gaokun_psy_bat_present`, `function gaokun_psy_get_bat_info`, `function gaokun_psy_update_bat_charge`, `function gaokun_psy_get_bat_status`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.