drivers/power/supply/lenovo_yoga_c630_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/lenovo_yoga_c630_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/lenovo_yoga_c630_battery.c- Extension
.c- Size
- 12770 bytes
- Lines
- 499
- 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/cleanup.hlinux/delay.hlinux/jiffies.hlinux/module.hlinux/mutex.hlinux/notifier.hlinux/power_supply.hlinux/platform_data/lenovo-yoga-c630.h
Detected Declarations
struct yoga_c630_psyfunction yoga_c630_psy_update_bat_infofunction yoga_c630_psy_maybe_update_bat_statusfunction yoga_c630_psy_update_adapter_statusfunction yoga_c630_psy_is_chargedfunction yoga_c630_psy_bat_get_propertyfunction yoga_c630_psy_adpt_get_propertyfunction yoga_c630_psy_register_bat_psyfunction yoga_c630_ec_refresh_bat_infofunction yoga_c630_psy_notifyfunction yoga_c630_psy_probefunction scoped_guardfunction yoga_c630_psy_remove
Annotated Snippet
struct yoga_c630_psy {
struct yoga_c630_ec *ec;
struct device *dev;
struct fwnode_handle *fwnode;
struct notifier_block nb;
/* guards all battery properties and registration of power supplies */
struct mutex lock;
struct power_supply *adp_psy;
struct power_supply *bat_psy;
unsigned long last_status_update;
bool adapter_online;
bool unit_mA;
bool bat_present;
unsigned int bat_status;
unsigned int design_capacity;
unsigned int design_voltage;
unsigned int full_charge_capacity;
unsigned int capacity_now;
unsigned int voltage_now;
int current_now;
int rate_now;
};
#define LENOVO_EC_CACHE_TIME (10 * HZ)
#define LENOVO_EC_ADPT_STATUS 0xa3
#define LENOVO_EC_ADPT_STATUS_PRESENT BIT(7)
#define LENOVO_EC_BAT_ATTRIBUTES 0xc0
#define LENOVO_EC_BAT_ATTRIBUTES_UNIT_IS_MA BIT(1)
#define LENOVO_EC_BAT_STATUS 0xc1
#define LENOVO_EC_BAT_STATUS_DISCHARGING BIT(0)
#define LENOVO_EC_BAT_STATUS_CHARGING BIT(1)
#define LENOVO_EC_BAT_REMAIN_CAPACITY 0xc2
#define LENOVO_EC_BAT_VOLTAGE 0xc6
#define LENOVO_EC_BAT_DESIGN_VOLTAGE 0xc8
#define LENOVO_EC_BAT_DESIGN_CAPACITY 0xca
#define LENOVO_EC_BAT_FULL_CAPACITY 0xcc
#define LENOVO_EC_BAT_CURRENT 0xd2
#define LENOVO_EC_BAT_FULL_FACTORY 0xd6
#define LENOVO_EC_BAT_PRESENT 0xda
#define LENOVO_EC_BAT_PRESENT_IS_PRESENT BIT(0)
#define LENOVO_EC_BAT_FULL_REGISTER 0xdb
#define LENOVO_EC_BAT_FULL_REGISTER_IS_FACTORY BIT(0)
static int yoga_c630_psy_update_bat_info(struct yoga_c630_psy *ecbat)
{
struct yoga_c630_ec *ec = ecbat->ec;
int val;
lockdep_assert_held(&ecbat->lock);
val = yoga_c630_ec_read8(ec, LENOVO_EC_BAT_PRESENT);
if (val < 0)
return val;
ecbat->bat_present = !!(val & LENOVO_EC_BAT_PRESENT_IS_PRESENT);
if (!ecbat->bat_present)
return val;
val = yoga_c630_ec_read8(ec, LENOVO_EC_BAT_ATTRIBUTES);
if (val < 0)
return val;
ecbat->unit_mA = val & LENOVO_EC_BAT_ATTRIBUTES_UNIT_IS_MA;
val = yoga_c630_ec_read16(ec, LENOVO_EC_BAT_DESIGN_CAPACITY);
if (val < 0)
return val;
ecbat->design_capacity = val * 1000;
/*
* DSDT has delays after most of EC reads in these methods.
* Having no documentation for the EC we have to follow and sleep here.
*/
msleep(50);
val = yoga_c630_ec_read16(ec, LENOVO_EC_BAT_DESIGN_VOLTAGE);
if (val < 0)
return val;
ecbat->design_voltage = val;
msleep(50);
val = yoga_c630_ec_read8(ec, LENOVO_EC_BAT_FULL_REGISTER);
Annotation
- Immediate include surface: `linux/auxiliary_bus.h`, `linux/bits.h`, `linux/cleanup.h`, `linux/delay.h`, `linux/jiffies.h`, `linux/module.h`, `linux/mutex.h`, `linux/notifier.h`.
- Detected declarations: `struct yoga_c630_psy`, `function yoga_c630_psy_update_bat_info`, `function yoga_c630_psy_maybe_update_bat_status`, `function yoga_c630_psy_update_adapter_status`, `function yoga_c630_psy_is_charged`, `function yoga_c630_psy_bat_get_property`, `function yoga_c630_psy_adpt_get_property`, `function yoga_c630_psy_register_bat_psy`, `function yoga_c630_ec_refresh_bat_info`, `function yoga_c630_psy_notify`.
- 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.