drivers/leds/flash/leds-rt8515.c
Source file repositories/reference/linux-study-clean/drivers/leds/flash/leds-rt8515.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/flash/leds-rt8515.c- Extension
.c- Size
- 10525 bytes
- Lines
- 398
- 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.
- 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/delay.hlinux/err.hlinux/gpio/consumer.hlinux/led-class-flash.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/regulator/consumer.hmedia/v4l2-flash-led-class.h
Detected Declarations
struct rt8515function rt8515_gpio_led_offfunction rt8515_gpio_brightness_commitfunction rt8515_led_brightness_setfunction rt8515_led_flash_strobe_setfunction rt8515_led_flash_strobe_getfunction rt8515_led_flash_timeout_setfunction rt8515_powerdown_timerfunction rt8515_init_flash_timeoutfunction rt8515_init_v4l2_flash_configfunction rt8515_v4l2_flash_releasefunction rt8515_init_v4l2_flash_configfunction rt8515_probefunction rt8515_remove
Annotated Snippet
struct rt8515 {
struct led_classdev_flash fled;
struct device *dev;
struct v4l2_flash *v4l2_flash;
struct mutex lock;
struct regulator *reg;
struct gpio_desc *enable_torch;
struct gpio_desc *enable_flash;
struct timer_list powerdown_timer;
u32 max_timeout; /* Flash max timeout */
int flash_max_intensity;
int torch_max_intensity;
};
static struct rt8515 *to_rt8515(struct led_classdev_flash *fled)
{
return container_of(fled, struct rt8515, fled);
}
static void rt8515_gpio_led_off(struct rt8515 *rt)
{
gpiod_set_value(rt->enable_flash, 0);
gpiod_set_value(rt->enable_torch, 0);
}
static void rt8515_gpio_brightness_commit(struct gpio_desc *gpiod,
int brightness)
{
int i;
/*
* Toggling a GPIO line with a small delay increases the
* brightness one step at a time.
*/
for (i = 0; i < brightness; i++) {
gpiod_set_value(gpiod, 0);
udelay(1);
gpiod_set_value(gpiod, 1);
udelay(1);
}
}
/* This is setting the torch light level */
static int rt8515_led_brightness_set(struct led_classdev *led,
enum led_brightness brightness)
{
struct led_classdev_flash *fled = lcdev_to_flcdev(led);
struct rt8515 *rt = to_rt8515(fled);
mutex_lock(&rt->lock);
if (brightness == LED_OFF) {
/* Off */
rt8515_gpio_led_off(rt);
} else if (brightness < RT8515_TORCH_MAX) {
/* Step it up to movie mode brightness using the flash pin */
rt8515_gpio_brightness_commit(rt->enable_torch, brightness);
} else {
/* Max torch brightness requested */
gpiod_set_value(rt->enable_torch, 1);
}
mutex_unlock(&rt->lock);
return 0;
}
static int rt8515_led_flash_strobe_set(struct led_classdev_flash *fled,
bool state)
{
struct rt8515 *rt = to_rt8515(fled);
struct led_flash_setting *timeout = &fled->timeout;
int brightness = rt->flash_max_intensity;
mutex_lock(&rt->lock);
if (state) {
/* Enable LED flash mode and set brightness */
rt8515_gpio_brightness_commit(rt->enable_flash, brightness);
/* Set timeout */
mod_timer(&rt->powerdown_timer,
jiffies + usecs_to_jiffies(timeout->val));
} else {
timer_delete_sync(&rt->powerdown_timer);
/* Turn the LED off */
rt8515_gpio_led_off(rt);
}
fled->led_cdev.brightness = LED_OFF;
/* After this the torch LED will be disabled */
Annotation
- Immediate include surface: `linux/delay.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/led-class-flash.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct rt8515`, `function rt8515_gpio_led_off`, `function rt8515_gpio_brightness_commit`, `function rt8515_led_brightness_set`, `function rt8515_led_flash_strobe_set`, `function rt8515_led_flash_strobe_get`, `function rt8515_led_flash_timeout_set`, `function rt8515_powerdown_timer`, `function rt8515_init_flash_timeout`, `function rt8515_init_v4l2_flash_config`.
- Atlas domain: Driver Families / drivers/leds.
- 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.