drivers/staging/greybus/power_supply.c
Source file repositories/reference/linux-study-clean/drivers/staging/greybus/power_supply.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/greybus/power_supply.c- Extension
.c- Size
- 29105 bytes
- Lines
- 1139
- Domain
- Driver Families
- Bucket
- drivers/staging
- 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/kernel.hlinux/module.hlinux/power_supply.hlinux/slab.hlinux/greybus.h
Detected Declarations
struct gb_power_supply_propstruct gb_power_supplystruct gb_power_suppliesstruct gb_power_supply_changesfunction get_psp_from_gb_propfunction is_psy_prop_writeablefunction is_prop_valintfunction next_intervalfunction __gb_power_supply_changedfunction gb_power_supply_state_changefunction check_changedfunction total_propsfunction prop_appendfunction __gb_power_supply_set_namefunction _gb_power_supply_append_propsfunction gb_power_supply_description_getfunction gb_power_supply_prop_descriptors_getfunction __gb_power_supply_property_updatefunction __gb_power_supply_property_getfunction __gb_power_supply_property_strval_getfunction _gb_power_supply_property_getfunction is_cache_validfunction gb_power_supply_status_getfunction gb_power_supply_status_updatefunction gb_power_supply_workfunction get_propertyfunction gb_power_supply_property_setfunction set_propertyfunction property_is_writeablefunction gb_power_supply_registerfunction _gb_power_supply_freefunction _gb_power_supply_releasefunction _gb_power_supplies_releasefunction gb_power_supplies_get_countfunction gb_power_supply_configfunction gb_power_supply_enablefunction gb_power_supplies_setupfunction gb_power_supplies_registerfunction gb_supplies_request_handlerfunction gb_power_supply_probefunction gb_power_supply_disconnect
Annotated Snippet
struct gb_power_supply_prop {
enum power_supply_property prop;
u8 gb_prop;
int val;
int previous_val;
bool is_writeable;
};
struct gb_power_supply {
u8 id;
bool registered;
struct power_supply *psy;
struct power_supply_desc desc;
char name[64];
struct gb_power_supplies *supplies;
struct delayed_work work;
char *manufacturer;
char *model_name;
char *serial_number;
u8 type;
u8 properties_count;
u8 properties_count_str;
unsigned long last_update;
u8 cache_invalid;
unsigned int update_interval;
bool changed;
struct gb_power_supply_prop *props;
enum power_supply_property *props_raw;
bool pm_acquired;
struct mutex supply_lock;
};
struct gb_power_supplies {
struct gb_connection *connection;
u8 supplies_count;
struct gb_power_supply *supply;
struct mutex supplies_lock;
};
#define to_gb_power_supply(x) power_supply_get_drvdata(x)
/*
* General power supply properties that could be absent from various reasons,
* like kernel versions or vendor specific versions
*/
#ifndef POWER_SUPPLY_PROP_VOLTAGE_BOOT
#define POWER_SUPPLY_PROP_VOLTAGE_BOOT -1
#endif
#ifndef POWER_SUPPLY_PROP_CURRENT_BOOT
#define POWER_SUPPLY_PROP_CURRENT_BOOT -1
#endif
#ifndef POWER_SUPPLY_PROP_CALIBRATE
#define POWER_SUPPLY_PROP_CALIBRATE -1
#endif
/* cache time in milliseconds, if cache_time is set to 0 cache is disable */
static unsigned int cache_time = 1000;
/*
* update interval initial and maximum value, between the two will
* back-off exponential
*/
static unsigned int update_interval_init = 1 * HZ;
static unsigned int update_interval_max = 30 * HZ;
struct gb_power_supply_changes {
enum power_supply_property prop;
u32 tolerance_change;
void (*prop_changed)(struct gb_power_supply *gbpsy,
struct gb_power_supply_prop *prop);
};
static void gb_power_supply_state_change(struct gb_power_supply *gbpsy,
struct gb_power_supply_prop *prop);
static const struct gb_power_supply_changes psy_props_changes[] = {
{ .prop = GB_POWER_SUPPLY_PROP_STATUS,
.tolerance_change = 0,
.prop_changed = gb_power_supply_state_change,
},
{ .prop = GB_POWER_SUPPLY_PROP_TEMP,
.tolerance_change = 500,
.prop_changed = NULL,
},
{ .prop = GB_POWER_SUPPLY_PROP_ONLINE,
.tolerance_change = 0,
.prop_changed = NULL,
},
};
static int get_psp_from_gb_prop(int gb_prop, enum power_supply_property *psp)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/power_supply.h`, `linux/slab.h`, `linux/greybus.h`.
- Detected declarations: `struct gb_power_supply_prop`, `struct gb_power_supply`, `struct gb_power_supplies`, `struct gb_power_supply_changes`, `function get_psp_from_gb_prop`, `function is_psy_prop_writeable`, `function is_prop_valint`, `function next_interval`, `function __gb_power_supply_changed`, `function gb_power_supply_state_change`.
- Atlas domain: Driver Families / drivers/staging.
- 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.