drivers/leds/flash/leds-lm3601x.c
Source file repositories/reference/linux-study-clean/drivers/leds/flash/leds-lm3601x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/flash/leds-lm3601x.c- Extension
.c- Size
- 12582 bytes
- Lines
- 495
- 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/i2c.hlinux/leds.hlinux/led-class-flash.hlinux/module.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct lm3601x_ledenum lm3601x_typefunction lm3601x_volatile_regfunction lm3601x_read_faultsfunction lm3601x_brightness_setfunction lm3601x_strobe_setfunction lm3601x_flash_brightness_setfunction lm3601x_flash_timeout_setfunction lm3601x_strobe_getfunction lm3601x_flash_fault_getfunction lm3601x_register_ledsfunction lm3601x_parse_nodefunction lm3601x_probefunction lm3601x_remove
Annotated Snippet
struct lm3601x_led {
struct led_classdev_flash fled_cdev;
struct i2c_client *client;
struct regmap *regmap;
struct mutex lock;
unsigned int flash_timeout;
unsigned int last_flag;
u32 torch_current_max;
u32 flash_current_max;
u32 max_flash_timeout;
u32 led_mode;
};
static const struct reg_default lm3601x_regmap_defs[] = {
{ LM3601X_ENABLE_REG, 0x20 },
{ LM3601X_CFG_REG, 0x15 },
{ LM3601X_LED_FLASH_REG, 0x00 },
{ LM3601X_LED_TORCH_REG, 0x00 },
};
static bool lm3601x_volatile_reg(struct device *dev, unsigned int reg)
{
switch (reg) {
case LM3601X_FLAGS_REG:
return true;
default:
return false;
}
}
static const struct regmap_config lm3601x_regmap = {
.reg_bits = 8,
.val_bits = 8,
.max_register = LM3601X_DEV_ID_REG,
.reg_defaults = lm3601x_regmap_defs,
.num_reg_defaults = ARRAY_SIZE(lm3601x_regmap_defs),
.cache_type = REGCACHE_MAPLE,
.volatile_reg = lm3601x_volatile_reg,
};
static struct lm3601x_led *fled_cdev_to_led(struct led_classdev_flash *fled_cdev)
{
return container_of(fled_cdev, struct lm3601x_led, fled_cdev);
}
static int lm3601x_read_faults(struct lm3601x_led *led)
{
int flags_val;
int ret;
ret = regmap_read(led->regmap, LM3601X_FLAGS_REG, &flags_val);
if (ret < 0)
return -EIO;
led->last_flag = 0;
if (flags_val & LM36010_OVP_FAULT)
led->last_flag |= LED_FAULT_OVER_VOLTAGE;
if (flags_val & (LM3601X_THERM_SHUTDOWN | LM3601X_THERM_CURR))
led->last_flag |= LED_FAULT_OVER_TEMPERATURE;
if (flags_val & LM3601X_SHORT_FAULT)
led->last_flag |= LED_FAULT_SHORT_CIRCUIT;
if (flags_val & LM36010_CURR_LIMIT)
led->last_flag |= LED_FAULT_OVER_CURRENT;
if (flags_val & LM3601X_UVLO_FAULT)
led->last_flag |= LED_FAULT_UNDER_VOLTAGE;
if (flags_val & LM3601X_IVFM_TRIP)
led->last_flag |= LED_FAULT_INPUT_VOLTAGE;
if (flags_val & LM3601X_THERM_SHUTDOWN)
led->last_flag |= LED_FAULT_LED_OVER_TEMPERATURE;
return led->last_flag;
}
static int lm3601x_brightness_set(struct led_classdev *cdev,
enum led_brightness brightness)
{
struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(cdev);
struct lm3601x_led *led = fled_cdev_to_led(fled_cdev);
int ret, led_mode_val;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/i2c.h`, `linux/leds.h`, `linux/led-class-flash.h`, `linux/module.h`, `linux/regmap.h`, `linux/slab.h`.
- Detected declarations: `struct lm3601x_led`, `enum lm3601x_type`, `function lm3601x_volatile_reg`, `function lm3601x_read_faults`, `function lm3601x_brightness_set`, `function lm3601x_strobe_set`, `function lm3601x_flash_brightness_set`, `function lm3601x_flash_timeout_set`, `function lm3601x_strobe_get`, `function lm3601x_flash_fault_get`.
- 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.