drivers/leds/flash/leds-ktd2692.c
Source file repositories/reference/linux-study-clean/drivers/leds/flash/leds-ktd2692.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/flash/leds-ktd2692.c- Extension
.c- Size
- 9289 bytes
- Lines
- 356
- 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/cleanup.hlinux/err.hlinux/gpio/consumer.hlinux/leds-expresswire.hlinux/led-class-flash.hlinux/module.hlinux/mutex.hlinux/of.hlinux/platform_device.hlinux/regulator/consumer.h
Detected Declarations
struct ktd2692_led_config_datastruct ktd2692_contextenum ktd2692_led_modefunction ktd2692_led_brightness_setfunction ktd2692_led_flash_strobe_setfunction ktd2692_led_flash_timeout_setfunction ktd2692_init_movie_current_maxfunction ktd2692_init_flash_timeoutfunction ktd2692_setupfunction regulator_disable_actionfunction ktd2692_parse_dtfunction ktd2692_probefunction ktd2692_remove
Annotated Snippet
struct ktd2692_led_config_data {
/* maximum LED current in movie mode */
u32 movie_max_microamp;
/* maximum LED current in flash mode */
u32 flash_max_microamp;
/* maximum flash timeout */
u32 flash_max_timeout;
/* max LED brightness level */
enum led_brightness max_brightness;
};
static const struct expresswire_timing ktd2692_timing = {
.poweroff_us = 700,
.data_start_us = 10,
.end_of_data_low_us = 10,
.end_of_data_high_us = 350,
.short_bitset_us = 4,
.long_bitset_us = 12
};
struct ktd2692_context {
/* Common ExpressWire properties (ctrl GPIO and timing) */
struct expresswire_common_props props;
/* Related LED Flash class device */
struct led_classdev_flash fled_cdev;
/* secures access to the device */
struct mutex lock;
struct regulator *regulator;
struct gpio_desc *aux_gpio;
enum ktd2692_led_mode mode;
enum led_brightness torch_brightness;
};
static struct ktd2692_context *fled_cdev_to_led(
struct led_classdev_flash *fled_cdev)
{
return container_of(fled_cdev, struct ktd2692_context, fled_cdev);
}
static int ktd2692_led_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev);
struct ktd2692_context *led = fled_cdev_to_led(fled_cdev);
mutex_lock(&led->lock);
if (brightness == LED_OFF) {
led->mode = KTD2692_MODE_DISABLE;
gpiod_direction_output(led->aux_gpio, 0);
} else {
expresswire_write_u8(&led->props, brightness |
KTD2692_REG_MOVIE_CURRENT_BASE);
led->mode = KTD2692_MODE_MOVIE;
}
expresswire_write_u8(&led->props, led->mode | KTD2692_REG_MODE_BASE);
mutex_unlock(&led->lock);
return 0;
}
static int ktd2692_led_flash_strobe_set(struct led_classdev_flash *fled_cdev,
bool state)
{
struct ktd2692_context *led = fled_cdev_to_led(fled_cdev);
struct led_flash_setting *timeout = &fled_cdev->timeout;
u32 flash_tm_reg;
mutex_lock(&led->lock);
if (state) {
flash_tm_reg = GET_TIMEOUT_OFFSET(timeout->val, timeout->step);
expresswire_write_u8(&led->props, flash_tm_reg
| KTD2692_REG_FLASH_TIMEOUT_BASE);
led->mode = KTD2692_MODE_FLASH;
gpiod_direction_output(led->aux_gpio, 1);
} else {
led->mode = KTD2692_MODE_DISABLE;
gpiod_direction_output(led->aux_gpio, 0);
}
expresswire_write_u8(&led->props, led->mode | KTD2692_REG_MODE_BASE);
fled_cdev->led_cdev.brightness = LED_OFF;
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/leds-expresswire.h`, `linux/led-class-flash.h`, `linux/module.h`, `linux/mutex.h`, `linux/of.h`.
- Detected declarations: `struct ktd2692_led_config_data`, `struct ktd2692_context`, `enum ktd2692_led_mode`, `function ktd2692_led_brightness_set`, `function ktd2692_led_flash_strobe_set`, `function ktd2692_led_flash_timeout_set`, `function ktd2692_init_movie_current_max`, `function ktd2692_init_flash_timeout`, `function ktd2692_setup`, `function regulator_disable_action`.
- 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.