drivers/leds/leds-syscon.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-syscon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-syscon.c- Extension
.c- Size
- 3312 bytes
- Lines
- 138
- Domain
- Driver Families
- Bucket
- drivers/leds
- 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/io.hlinux/init.hlinux/of.hlinux/platform_device.hlinux/stat.hlinux/slab.hlinux/mfd/syscon.hlinux/regmap.hlinux/leds.h
Detected Declarations
struct syscon_ledfunction syscon_led_setfunction syscon_led_probe
Annotated Snippet
struct syscon_led {
struct led_classdev cdev;
struct regmap *map;
u32 offset;
u32 mask;
bool state;
};
static void syscon_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct syscon_led *sled =
container_of(led_cdev, struct syscon_led, cdev);
u32 val;
int ret;
if (value == LED_OFF) {
val = 0;
sled->state = false;
} else {
val = sled->mask;
sled->state = true;
}
ret = regmap_update_bits(sled->map, sled->offset, sled->mask, val);
if (ret < 0)
dev_err(sled->cdev.dev, "error updating LED status\n");
}
static int syscon_led_probe(struct platform_device *pdev)
{
struct led_init_data init_data = {};
struct device *dev = &pdev->dev;
struct device_node *np = dev_of_node(dev);
struct device *parent;
struct regmap *map;
struct syscon_led *sled;
enum led_default_state state;
u32 value;
int ret;
parent = dev->parent;
if (!parent) {
dev_err(dev, "no parent for syscon LED\n");
return -ENODEV;
}
map = syscon_node_to_regmap(dev_of_node(parent));
if (IS_ERR(map)) {
dev_err(dev, "no regmap for syscon LED parent\n");
return PTR_ERR(map);
}
sled = devm_kzalloc(dev, sizeof(*sled), GFP_KERNEL);
if (!sled)
return -ENOMEM;
sled->map = map;
if (of_property_read_u32(np, "reg", &sled->offset) &&
of_property_read_u32(np, "offset", &sled->offset))
return -EINVAL;
if (of_property_read_u32(np, "mask", &sled->mask))
return -EINVAL;
init_data.fwnode = of_fwnode_handle(np);
state = led_init_default_state_get(init_data.fwnode);
switch (state) {
case LEDS_DEFSTATE_ON:
ret = regmap_update_bits(map, sled->offset, sled->mask, sled->mask);
if (ret < 0)
return ret;
sled->state = true;
break;
case LEDS_DEFSTATE_KEEP:
ret = regmap_read(map, sled->offset, &value);
if (ret < 0)
return ret;
sled->state = !!(value & sled->mask);
break;
default:
ret = regmap_update_bits(map, sled->offset, sled->mask, 0);
if (ret < 0)
return ret;
sled->state = false;
}
sled->cdev.brightness_set = syscon_led_set;
ret = devm_led_classdev_register_ext(dev, &sled->cdev, &init_data);
if (ret < 0)
Annotation
- Immediate include surface: `linux/io.h`, `linux/init.h`, `linux/of.h`, `linux/platform_device.h`, `linux/stat.h`, `linux/slab.h`, `linux/mfd/syscon.h`, `linux/regmap.h`.
- Detected declarations: `struct syscon_led`, `function syscon_led_set`, `function syscon_led_probe`.
- Atlas domain: Driver Families / drivers/leds.
- 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.