drivers/regulator/userspace-consumer.c
Source file repositories/reference/linux-study-clean/drivers/regulator/userspace-consumer.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/userspace-consumer.c- Extension
.c- Size
- 5694 bytes
- Lines
- 226
- Domain
- Driver Families
- Bucket
- drivers/regulator
- 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/err.hlinux/mutex.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/regulator/consumer.hlinux/regulator/userspace-consumer.hlinux/slab.h
Detected Declarations
struct userspace_consumer_datafunction name_showfunction state_showfunction state_storefunction attr_visiblefunction regulator_userspace_consumer_probefunction regulator_userspace_consumer_remove
Annotated Snippet
struct userspace_consumer_data {
const char *name;
struct mutex lock;
bool enabled;
bool no_autoswitch;
int num_supplies;
struct regulator_bulk_data *supplies;
};
static ssize_t name_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct userspace_consumer_data *data = dev_get_drvdata(dev);
return sprintf(buf, "%s\n", data->name);
}
static ssize_t state_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct userspace_consumer_data *data = dev_get_drvdata(dev);
if (data->enabled)
return sprintf(buf, "enabled\n");
return sprintf(buf, "disabled\n");
}
static ssize_t state_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct userspace_consumer_data *data = dev_get_drvdata(dev);
bool enabled;
int ret;
/*
* sysfs_streq() doesn't need the \n's, but we add them so the strings
* will be shared with show_state(), above.
*/
if (sysfs_streq(buf, "enabled\n") || sysfs_streq(buf, "1"))
enabled = true;
else if (sysfs_streq(buf, "disabled\n") || sysfs_streq(buf, "0"))
enabled = false;
else {
dev_err(dev, "Configuring invalid mode\n");
return count;
}
mutex_lock(&data->lock);
if (enabled != data->enabled) {
if (enabled)
ret = regulator_bulk_enable(data->num_supplies,
data->supplies);
else
ret = regulator_bulk_disable(data->num_supplies,
data->supplies);
if (ret == 0)
data->enabled = enabled;
else
dev_err(dev, "Failed to configure state: %d\n", ret);
}
mutex_unlock(&data->lock);
return count;
}
static DEVICE_ATTR_RO(name);
static DEVICE_ATTR_RW(state);
static struct attribute *attributes[] = {
&dev_attr_name.attr,
&dev_attr_state.attr,
NULL,
};
static umode_t attr_visible(struct kobject *kobj, struct attribute *attr, int idx)
{
struct device *dev = kobj_to_dev(kobj);
struct userspace_consumer_data *data = dev_get_drvdata(dev);
/* If a name hasn't been set, don't bother with the attribute */
if (attr == &dev_attr_name.attr && !data->name)
return 0;
return attr->mode;
}
Annotation
- Immediate include surface: `linux/err.h`, `linux/mutex.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regulator/consumer.h`, `linux/regulator/userspace-consumer.h`, `linux/slab.h`.
- Detected declarations: `struct userspace_consumer_data`, `function name_show`, `function state_show`, `function state_store`, `function attr_visible`, `function regulator_userspace_consumer_probe`, `function regulator_userspace_consumer_remove`.
- Atlas domain: Driver Families / drivers/regulator.
- 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.