drivers/video/backlight/ktd2801-backlight.c
Source file repositories/reference/linux-study-clean/drivers/video/backlight/ktd2801-backlight.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/backlight/ktd2801-backlight.c- Extension
.c- Size
- 3520 bytes
- Lines
- 131
- 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/gpio/consumer.hlinux/leds-expresswire.hlinux/mod_devicetable.hlinux/platform_device.hlinux/property.h
Detected Declarations
struct ktd2801_backlightfunction ktd2801_update_statusfunction ktd2801_backlight_probe
Annotated Snippet
struct ktd2801_backlight {
struct expresswire_common_props props;
struct backlight_device *bd;
bool was_on;
};
static int ktd2801_update_status(struct backlight_device *bd)
{
struct ktd2801_backlight *ktd2801 = bl_get_data(bd);
u8 brightness = (u8) backlight_get_brightness(bd);
if (backlight_is_blank(bd)) {
expresswire_power_off(&ktd2801->props);
ktd2801->was_on = false;
return 0;
}
if (!ktd2801->was_on) {
expresswire_enable(&ktd2801->props);
ktd2801->was_on = true;
}
expresswire_write_u8(&ktd2801->props, brightness);
return 0;
}
static const struct backlight_ops ktd2801_backlight_ops = {
.options = BL_CORE_SUSPENDRESUME,
.update_status = ktd2801_update_status,
};
static int ktd2801_backlight_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct backlight_device *bd;
struct ktd2801_backlight *ktd2801;
u32 brightness, max_brightness;
int ret;
ktd2801 = devm_kzalloc(dev, sizeof(*ktd2801), GFP_KERNEL);
if (!ktd2801)
return -ENOMEM;
ktd2801->was_on = true;
ktd2801->props.timing = ktd2801_timing;
ret = device_property_read_u32(dev, "max-brightness", &max_brightness);
if (ret)
max_brightness = KTD2801_MAX_BRIGHTNESS;
if (max_brightness > KTD2801_MAX_BRIGHTNESS) {
dev_err(dev, "illegal max brightness specified\n");
max_brightness = KTD2801_MAX_BRIGHTNESS;
}
ret = device_property_read_u32(dev, "default-brightness", &brightness);
if (ret)
brightness = KTD2801_DEFAULT_BRIGHTNESS;
if (brightness > max_brightness) {
dev_err(dev, "default brightness exceeds max\n");
brightness = max_brightness;
}
ktd2801->props.ctrl_gpio = devm_gpiod_get(dev, "ctrl", GPIOD_OUT_HIGH);
if (IS_ERR(ktd2801->props.ctrl_gpio))
return dev_err_probe(dev, PTR_ERR(ktd2801->props.ctrl_gpio),
"failed to get backlight GPIO");
gpiod_set_consumer_name(ktd2801->props.ctrl_gpio, dev_name(dev));
bd = devm_backlight_device_register(dev, dev_name(dev), dev, ktd2801,
&ktd2801_backlight_ops, NULL);
if (IS_ERR(bd))
return dev_err_probe(dev, PTR_ERR(bd),
"failed to register backlight");
bd->props.max_brightness = max_brightness;
bd->props.brightness = brightness;
ktd2801->bd = bd;
platform_set_drvdata(pdev, bd);
backlight_update_status(bd);
return 0;
}
static const struct of_device_id ktd2801_of_match[] = {
{ .compatible = "kinetic,ktd2801" },
{ }
};
MODULE_DEVICE_TABLE(of, ktd2801_of_match);
Annotation
- Immediate include surface: `linux/backlight.h`, `linux/gpio/consumer.h`, `linux/leds-expresswire.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct ktd2801_backlight`, `function ktd2801_update_status`, `function ktd2801_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.