drivers/video/backlight/led_bl.c
Source file repositories/reference/linux-study-clean/drivers/video/backlight/led_bl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/backlight/led_bl.c- Extension
.c- Size
- 6460 bytes
- Lines
- 274
- Domain
- Driver Families
- Bucket
- drivers/video
- 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/backlight.hlinux/leds.hlinux/module.hlinux/of.hlinux/platform_device.h
Detected Declarations
struct led_bl_datafunction led_bl_set_brightnessfunction led_bl_power_offfunction led_bl_update_statusfunction led_bl_get_ledsfunction led_bl_parse_levelsfunction led_bl_probefunction led_bl_remove
Annotated Snippet
struct led_bl_data {
struct device *dev;
struct backlight_device *bl_dev;
struct led_classdev **leds;
bool enabled;
int nb_leds;
unsigned int *levels;
unsigned int default_brightness;
unsigned int max_brightness;
};
static void led_bl_set_brightness(struct led_bl_data *priv, int level)
{
int i;
int bkl_brightness;
if (priv->levels)
bkl_brightness = priv->levels[level];
else
bkl_brightness = level;
for (i = 0; i < priv->nb_leds; i++)
led_set_brightness(priv->leds[i], bkl_brightness);
priv->enabled = true;
}
static void led_bl_power_off(struct led_bl_data *priv)
{
int i;
if (!priv->enabled)
return;
for (i = 0; i < priv->nb_leds; i++)
led_set_brightness(priv->leds[i], LED_OFF);
priv->enabled = false;
}
static int led_bl_update_status(struct backlight_device *bl)
{
struct led_bl_data *priv = bl_get_data(bl);
int brightness = backlight_get_brightness(bl);
if (brightness > 0)
led_bl_set_brightness(priv, brightness);
else
led_bl_power_off(priv);
return 0;
}
static const struct backlight_ops led_bl_ops = {
.update_status = led_bl_update_status,
};
static int led_bl_get_leds(struct device *dev,
struct led_bl_data *priv)
{
int i, nb_leds, ret;
struct device_node *node = dev->of_node;
struct led_classdev **leds;
unsigned int max_brightness;
unsigned int default_brightness;
ret = of_count_phandle_with_args(node, "leds", NULL);
if (ret < 0) {
dev_err(dev, "Unable to get led count\n");
return -EINVAL;
}
nb_leds = ret;
if (nb_leds < 1) {
dev_err(dev, "At least one LED must be specified!\n");
return -EINVAL;
}
leds = devm_kcalloc(dev, nb_leds, sizeof(struct led_classdev *),
GFP_KERNEL);
if (!leds)
return -ENOMEM;
for (i = 0; i < nb_leds; i++) {
leds[i] = devm_of_led_get(dev, i);
if (IS_ERR(leds[i]))
return PTR_ERR(leds[i]);
}
/* check that the LEDs all have the same brightness range */
Annotation
- Immediate include surface: `linux/backlight.h`, `linux/leds.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct led_bl_data`, `function led_bl_set_brightness`, `function led_bl_power_off`, `function led_bl_update_status`, `function led_bl_get_leds`, `function led_bl_parse_levels`, `function led_bl_probe`, `function led_bl_remove`.
- Atlas domain: Driver Families / drivers/video.
- 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.