drivers/video/backlight/gpio_backlight.c
Source file repositories/reference/linux-study-clean/drivers/video/backlight/gpio_backlight.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/backlight/gpio_backlight.c- Extension
.c- Size
- 3334 bytes
- Lines
- 124
- 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.
- 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/err.hlinux/gpio/consumer.hlinux/init.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_data/gpio_backlight.hlinux/platform_device.hlinux/property.hlinux/slab.h
Detected Declarations
struct gpio_backlightfunction gpio_backlight_update_statusfunction gpio_backlight_controls_devicefunction gpio_backlight_probe
Annotated Snippet
struct gpio_backlight {
struct device *dev;
struct gpio_desc *gpiod;
};
static int gpio_backlight_update_status(struct backlight_device *bl)
{
struct gpio_backlight *gbl = bl_get_data(bl);
gpiod_set_value_cansleep(gbl->gpiod, backlight_get_brightness(bl));
return 0;
}
static bool gpio_backlight_controls_device(struct backlight_device *bl,
struct device *display_dev)
{
struct gpio_backlight *gbl = bl_get_data(bl);
return !gbl->dev || gbl->dev == display_dev;
}
static const struct backlight_ops gpio_backlight_ops = {
.options = BL_CORE_SUSPENDRESUME,
.update_status = gpio_backlight_update_status,
.controls_device = gpio_backlight_controls_device,
};
static int gpio_backlight_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev);
struct device_node *of_node = dev->of_node;
struct backlight_properties props;
struct backlight_device *bl;
struct gpio_backlight *gbl;
int ret, init_brightness, def_value;
gbl = devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL);
if (gbl == NULL)
return -ENOMEM;
if (pdata)
gbl->dev = pdata->dev;
def_value = device_property_read_bool(dev, "default-on");
gbl->gpiod = devm_gpiod_get(dev, NULL, GPIOD_ASIS);
if (IS_ERR(gbl->gpiod))
return dev_err_probe(dev, PTR_ERR(gbl->gpiod),
"The gpios parameter is missing or invalid\n");
memset(&props, 0, sizeof(props));
props.type = BACKLIGHT_RAW;
props.max_brightness = 1;
bl = devm_backlight_device_register(dev, dev_name(dev), dev, gbl,
&gpio_backlight_ops, &props);
if (IS_ERR(bl)) {
dev_err(dev, "failed to register backlight\n");
return PTR_ERR(bl);
}
/* Set the initial power state */
if (!of_node || !of_node->phandle)
/* Not booted with device tree or no phandle link to the node */
bl->props.power = def_value ? BACKLIGHT_POWER_ON
: BACKLIGHT_POWER_OFF;
else if (gpiod_get_value_cansleep(gbl->gpiod) == 0)
bl->props.power = BACKLIGHT_POWER_OFF;
else
bl->props.power = BACKLIGHT_POWER_ON;
bl->props.brightness = 1;
init_brightness = backlight_get_brightness(bl);
ret = gpiod_direction_output(gbl->gpiod, init_brightness);
if (ret) {
dev_err(dev, "failed to set initial brightness\n");
return ret;
}
platform_set_drvdata(pdev, bl);
return 0;
}
static struct of_device_id gpio_backlight_of_match[] = {
{ .compatible = "gpio-backlight" },
{ /* sentinel */ }
};
Annotation
- Immediate include surface: `linux/backlight.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/platform_data/gpio_backlight.h`.
- Detected declarations: `struct gpio_backlight`, `function gpio_backlight_update_status`, `function gpio_backlight_controls_device`, `function gpio_backlight_probe`.
- Atlas domain: Driver Families / drivers/video.
- 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.