drivers/leds/leds-max5970.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-max5970.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-max5970.c- Extension
.c- Size
- 2851 bytes
- Lines
- 113
- 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/bits.hlinux/container_of.hlinux/device.hlinux/leds.hlinux/mfd/max5970.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/regmap.h
Detected Declarations
struct max5970_ledfunction max5970_led_set_brightnessfunction max5970_led_probefunction fwnode_for_each_child_node
Annotated Snippet
struct max5970_led {
struct device *dev;
struct regmap *regmap;
struct led_classdev cdev;
unsigned int index;
};
static int max5970_led_set_brightness(struct led_classdev *cdev,
enum led_brightness brightness)
{
struct max5970_led *ddata = ldev_to_maxled(cdev);
int ret, val;
/* Set/clear corresponding bit for given led index */
val = !brightness ? BIT(ddata->index) : 0;
ret = regmap_update_bits(ddata->regmap, MAX5970_REG_LED_FLASH, BIT(ddata->index), val);
if (ret < 0)
dev_err(cdev->dev, "failed to set brightness %d", ret);
return ret;
}
static int max5970_led_probe(struct platform_device *pdev)
{
struct fwnode_handle *child;
struct device *dev = &pdev->dev;
struct regmap *regmap;
struct max5970_led *ddata;
int ret = -ENODEV;
regmap = dev_get_regmap(dev->parent, NULL);
if (!regmap)
return -ENODEV;
struct fwnode_handle *led_node __free(fwnode_handle) =
device_get_named_child_node(dev->parent, "leds");
if (!led_node)
return -ENODEV;
fwnode_for_each_child_node(led_node, child) {
u32 reg;
if (fwnode_property_read_u32(child, "reg", ®))
continue;
if (reg >= MAX5970_NUM_LEDS) {
dev_err_probe(dev, -EINVAL, "invalid LED (%u >= %d)\n", reg, MAX5970_NUM_LEDS);
continue;
}
ddata = devm_kzalloc(dev, sizeof(*ddata), GFP_KERNEL);
if (!ddata) {
fwnode_handle_put(child);
return -ENOMEM;
}
ddata->index = reg;
ddata->regmap = regmap;
ddata->dev = dev;
if (fwnode_property_read_string(child, "label", &ddata->cdev.name))
ddata->cdev.name = fwnode_get_name(child);
ddata->cdev.max_brightness = 1;
ddata->cdev.brightness_set_blocking = max5970_led_set_brightness;
ddata->cdev.default_trigger = "none";
ret = devm_led_classdev_register(dev, &ddata->cdev);
if (ret < 0) {
fwnode_handle_put(child);
return dev_err_probe(dev, ret, "Failed to initialize LED %u\n", reg);
}
}
return ret;
}
static struct platform_driver max5970_led_driver = {
.driver = {
.name = "max5970-led",
},
.probe = max5970_led_probe,
};
module_platform_driver(max5970_led_driver);
MODULE_AUTHOR("Patrick Rudolph <patrick.rudolph@9elements.com>");
MODULE_AUTHOR("Naresh Solanki <Naresh.Solanki@9elements.com>");
MODULE_DESCRIPTION("MAX5970_hot-swap controller LED driver");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `linux/bits.h`, `linux/container_of.h`, `linux/device.h`, `linux/leds.h`, `linux/mfd/max5970.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct max5970_led`, `function max5970_led_set_brightness`, `function max5970_led_probe`, `function fwnode_for_each_child_node`.
- 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.