drivers/power/supply/surface_charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/surface_charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/surface_charger.c- Extension
.c- Size
- 6822 bytes
- Lines
- 283
- 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/kernel.hlinux/module.hlinux/mutex.hlinux/power_supply.hlinux/types.hlinux/surface_aggregator/device.h
Detected Declarations
struct spwr_psy_propertiesstruct spwr_ac_deviceenum sam_event_cid_batenum sam_battery_stafunction spwr_ac_update_unlockedfunction spwr_ac_updatefunction spwr_ac_recheckfunction spwr_notify_acfunction spwr_ac_get_propertyfunction spwr_ac_initfunction spwr_ac_registerfunction surface_ac_resumefunction surface_ac_probefunction surface_ac_remove
Annotated Snippet
struct spwr_psy_properties {
const char *name;
struct ssam_event_registry registry;
};
struct spwr_ac_device {
struct ssam_device *sdev;
char name[32];
struct power_supply *psy;
struct power_supply_desc psy_desc;
struct ssam_event_notifier notif;
struct mutex lock; /* Guards access to state below. */
__le32 state;
};
/* -- State management. ----------------------------------------------------- */
static int spwr_ac_update_unlocked(struct spwr_ac_device *ac)
{
__le32 old = ac->state;
int status;
lockdep_assert_held(&ac->lock);
status = ssam_retry(ssam_bat_get_psrc, ac->sdev, &ac->state);
if (status < 0)
return status;
return old != ac->state;
}
static int spwr_ac_update(struct spwr_ac_device *ac)
{
int status;
mutex_lock(&ac->lock);
status = spwr_ac_update_unlocked(ac);
mutex_unlock(&ac->lock);
return status;
}
static int spwr_ac_recheck(struct spwr_ac_device *ac)
{
int status;
status = spwr_ac_update(ac);
if (status > 0)
power_supply_changed(ac->psy);
return status >= 0 ? 0 : status;
}
static u32 spwr_notify_ac(struct ssam_event_notifier *nf, const struct ssam_event *event)
{
struct spwr_ac_device *ac;
int status;
ac = container_of(nf, struct spwr_ac_device, notif);
dev_dbg(&ac->sdev->dev, "power event (cid = %#04x, iid = %#04x, tid = %#04x)\n",
event->command_id, event->instance_id, event->target_id);
/*
* Allow events of all targets/instances here. Global adapter status
* seems to be handled via target=1 and instance=1, but events are
* reported on all targets/instances in use.
*
* While it should be enough to just listen on 1/1, listen everywhere to
* make sure we don't miss anything.
*/
switch (event->command_id) {
case SAM_EVENT_CID_BAT_ADP:
status = spwr_ac_recheck(ac);
return ssam_notifier_from_errno(status) | SSAM_NOTIF_HANDLED;
default:
return 0;
}
}
/* -- Properties. ----------------------------------------------------------- */
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/power_supply.h`, `linux/types.h`, `linux/surface_aggregator/device.h`.
- Detected declarations: `struct spwr_psy_properties`, `struct spwr_ac_device`, `enum sam_event_cid_bat`, `enum sam_battery_sta`, `function spwr_ac_update_unlocked`, `function spwr_ac_update`, `function spwr_ac_recheck`, `function spwr_notify_ac`, `function spwr_ac_get_property`, `function spwr_ac_init`.
- 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.