drivers/power/supply/surface_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/surface_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/surface_battery.c- Extension
.c- Size
- 22437 bytes
- Lines
- 876
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/unaligned.hlinux/jiffies.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/power_supply.hlinux/sysfs.hlinux/types.hlinux/workqueue.hlinux/surface_aggregator/device.h
Detected Declarations
struct spwr_bixstruct spwr_bststruct spwr_psy_propertiesstruct spwr_battery_deviceenum sam_event_cid_batenum sam_battery_staenum sam_battery_stateenum sam_battery_power_unitfunction spwr_battery_presentfunction spwr_battery_load_stafunction spwr_battery_load_bixfunction spwr_battery_load_bstfunction spwr_battery_set_alarm_unlockedfunction spwr_battery_update_bst_unlockedfunction spwr_battery_update_bstfunction spwr_battery_update_bix_unlockedfunction sprw_battery_get_full_cap_safefunction spwr_battery_is_fullfunction spwr_battery_recheck_fullfunction spwr_battery_recheck_statusfunction spwr_notify_batfunction spwr_battery_update_bst_workfnfunction spwr_external_power_changedfunction spwr_battery_prop_statusfunction spwr_battery_prop_technologyfunction spwr_battery_prop_capacityfunction spwr_battery_prop_capacity_levelfunction spwr_battery_get_propertyfunction alarm_showfunction alarm_storefunction spwr_battery_initfunction spwr_battery_registerfunction surface_battery_resumefunction surface_battery_probefunction surface_battery_remove
Annotated Snippet
struct spwr_bix {
u8 revision;
__le32 power_unit;
__le32 design_cap;
__le32 last_full_charge_cap;
__le32 technology;
__le32 design_voltage;
__le32 design_cap_warn;
__le32 design_cap_low;
__le32 cycle_count;
__le32 measurement_accuracy;
__le32 max_sampling_time;
__le32 min_sampling_time;
__le32 max_avg_interval;
__le32 min_avg_interval;
__le32 bat_cap_granularity_1;
__le32 bat_cap_granularity_2;
__u8 model[21];
__u8 serial[11];
__u8 type[5];
__u8 oem_info[21];
} __packed;
static_assert(sizeof(struct spwr_bix) == 119);
/* Equivalent to data returned in ACPI _BST method. */
struct spwr_bst {
__le32 state;
__le32 present_rate;
__le32 remaining_cap;
__le32 present_voltage;
} __packed;
static_assert(sizeof(struct spwr_bst) == 16);
#define SPWR_BIX_REVISION 0
#define SPWR_BATTERY_VALUE_UNKNOWN 0xffffffff
/* Get battery status (_STA) */
SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_sta, __le32, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x01,
});
/* Get battery static information (_BIX). */
SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_bix, struct spwr_bix, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x02,
});
/* Get battery dynamic information (_BST). */
SSAM_DEFINE_SYNC_REQUEST_CL_R(ssam_bat_get_bst, struct spwr_bst, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x03,
});
/* Set battery trip point (_BTP). */
SSAM_DEFINE_SYNC_REQUEST_CL_W(ssam_bat_set_btp, __le32, {
.target_category = SSAM_SSH_TC_BAT,
.command_id = 0x04,
});
/* -- Device structures. ---------------------------------------------------- */
struct spwr_psy_properties {
const char *name;
struct ssam_event_registry registry;
};
struct spwr_battery_device {
struct ssam_device *sdev;
char name[32];
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct delayed_work update_work;
struct ssam_event_notifier notif;
struct mutex lock; /* Guards access to state data below. */
unsigned long timestamp;
__le32 sta;
struct spwr_bix bix;
struct spwr_bst bst;
u32 alarm;
};
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/jiffies.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/power_supply.h`, `linux/sysfs.h`, `linux/types.h`.
- Detected declarations: `struct spwr_bix`, `struct spwr_bst`, `struct spwr_psy_properties`, `struct spwr_battery_device`, `enum sam_event_cid_bat`, `enum sam_battery_sta`, `enum sam_battery_state`, `enum sam_battery_power_unit`, `function spwr_battery_present`, `function spwr_battery_load_sta`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.