drivers/video/backlight/pwm_bl.c
Source file repositories/reference/linux-study-clean/drivers/video/backlight/pwm_bl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/backlight/pwm_bl.c- Extension
.c- Size
- 18431 bytes
- Lines
- 709
- 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/delay.hlinux/gpio/consumer.hlinux/module.hlinux/kernel.hlinux/init.hlinux/platform_device.hlinux/backlight.hlinux/err.hlinux/pwm.hlinux/pwm_backlight.hlinux/regulator/consumer.hlinux/slab.h
Detected Declarations
struct pwm_bl_datafunction pwm_backlight_power_onfunction pwm_backlight_power_offfunction compute_duty_cyclefunction pwm_backlight_update_statusfunction cie1931function pwm_backlight_brightness_defaultfunction pwm_backlight_parse_dtfunction pwm_backlight_parse_dtfunction pwm_backlight_brightness_defaultfunction pwm_backlight_is_linearfunction pwm_backlight_initial_power_statefunction pwm_backlight_probefunction pwm_backlight_removefunction pwm_backlight_shutdownfunction pwm_backlight_suspendfunction pwm_backlight_resume
Annotated Snippet
struct pwm_bl_data {
struct pwm_device *pwm;
struct device *dev;
unsigned int lth_brightness;
unsigned int *levels;
bool enabled;
struct regulator *power_supply;
struct gpio_desc *enable_gpio;
unsigned int scale;
unsigned int post_pwm_on_delay;
unsigned int pwm_off_delay;
int (*notify)(struct device *,
int brightness);
void (*notify_after)(struct device *,
int brightness);
void (*exit)(struct device *);
};
static void pwm_backlight_power_on(struct pwm_bl_data *pb)
{
int err;
if (pb->enabled)
return;
if (pb->power_supply) {
err = regulator_enable(pb->power_supply);
if (err < 0)
dev_err(pb->dev, "failed to enable power supply\n");
}
if (pb->post_pwm_on_delay)
msleep(pb->post_pwm_on_delay);
gpiod_set_value_cansleep(pb->enable_gpio, 1);
pb->enabled = true;
}
static void pwm_backlight_power_off(struct pwm_bl_data *pb)
{
if (!pb->enabled)
return;
gpiod_set_value_cansleep(pb->enable_gpio, 0);
if (pb->pwm_off_delay)
msleep(pb->pwm_off_delay);
if (pb->power_supply)
regulator_disable(pb->power_supply);
pb->enabled = false;
}
static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness, struct pwm_state *state)
{
unsigned int lth = pb->lth_brightness;
u64 duty_cycle;
if (pb->levels)
duty_cycle = pb->levels[brightness];
else
duty_cycle = brightness;
duty_cycle *= state->period - lth;
do_div(duty_cycle, pb->scale);
return duty_cycle + lth;
}
static int pwm_backlight_update_status(struct backlight_device *bl)
{
struct pwm_bl_data *pb = bl_get_data(bl);
int brightness = backlight_get_brightness(bl);
struct pwm_state state;
if (pb->notify)
brightness = pb->notify(pb->dev, brightness);
if (brightness > 0) {
pwm_get_state(pb->pwm, &state);
state.duty_cycle = compute_duty_cycle(pb, brightness, &state);
state.enabled = true;
pwm_apply_might_sleep(pb->pwm, &state);
pwm_backlight_power_on(pb);
} else {
pwm_backlight_power_off(pb);
pwm_get_state(pb->pwm, &state);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/gpio/consumer.h`, `linux/module.h`, `linux/kernel.h`, `linux/init.h`, `linux/platform_device.h`, `linux/backlight.h`, `linux/err.h`.
- Detected declarations: `struct pwm_bl_data`, `function pwm_backlight_power_on`, `function pwm_backlight_power_off`, `function compute_duty_cycle`, `function pwm_backlight_update_status`, `function cie1931`, `function pwm_backlight_brightness_default`, `function pwm_backlight_parse_dt`, `function pwm_backlight_parse_dt`, `function pwm_backlight_brightness_default`.
- 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.