drivers/leds/leds-lm3642.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-lm3642.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-lm3642.c- Extension
.c- Size
- 10281 bytes
- Lines
- 413
- 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.
- 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/delay.hlinux/fs.hlinux/i2c.hlinux/leds.hlinux/module.hlinux/platform_data/leds-lm3642.hlinux/platform_device.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct lm3642_chip_dataenum lm3642_modefunction lm3642_chip_initfunction lm3642_controlfunction torch_pin_storefunction lm3642_torch_brightness_setfunction strobe_pin_storefunction lm3642_strobe_brightness_setfunction lm3642_indicator_brightness_setfunction lm3642_probefunction lm3642_remove
Annotated Snippet
struct lm3642_chip_data {
struct device *dev;
struct led_classdev cdev_flash;
struct led_classdev cdev_torch;
struct led_classdev cdev_indicator;
u8 br_flash;
u8 br_torch;
u8 br_indicator;
enum lm3642_torch_pin_enable torch_pin;
enum lm3642_strobe_pin_enable strobe_pin;
enum lm3642_tx_pin_enable tx_pin;
struct lm3642_platform_data *pdata;
struct regmap *regmap;
struct mutex lock;
unsigned int last_flag;
};
/* chip initialize */
static int lm3642_chip_init(struct lm3642_chip_data *chip)
{
int ret;
struct lm3642_platform_data *pdata = chip->pdata;
/* set enable register */
ret = regmap_update_bits(chip->regmap, REG_ENABLE, EX_PIN_ENABLE_MASK,
pdata->tx_pin);
if (ret < 0)
dev_err(chip->dev, "Failed to update REG_ENABLE Register\n");
return ret;
}
/* chip control */
static int lm3642_control(struct lm3642_chip_data *chip,
u8 brightness, enum lm3642_mode opmode)
{
int ret;
ret = regmap_read(chip->regmap, REG_FLAG, &chip->last_flag);
if (ret < 0) {
dev_err(chip->dev, "Failed to read REG_FLAG Register\n");
return ret;
}
if (chip->last_flag)
dev_info(chip->dev, "Last FLAG is 0x%x\n", chip->last_flag);
/* brightness 0 means off-state */
if (!brightness)
opmode = MODES_STASNDBY;
switch (opmode) {
case MODES_TORCH:
ret = regmap_update_bits(chip->regmap, REG_I_CTRL,
TORCH_I_MASK << TORCH_I_SHIFT,
(brightness - 1) << TORCH_I_SHIFT);
if (chip->torch_pin)
opmode |= (TORCH_PIN_EN_MASK << TORCH_PIN_EN_SHIFT);
break;
case MODES_FLASH:
ret = regmap_update_bits(chip->regmap, REG_I_CTRL,
FLASH_I_MASK << FLASH_I_SHIFT,
(brightness - 1) << FLASH_I_SHIFT);
if (chip->strobe_pin)
opmode |= (STROBE_PIN_EN_MASK << STROBE_PIN_EN_SHIFT);
break;
case MODES_INDIC:
ret = regmap_update_bits(chip->regmap, REG_I_CTRL,
TORCH_I_MASK << TORCH_I_SHIFT,
(brightness - 1) << TORCH_I_SHIFT);
break;
case MODES_STASNDBY:
break;
default:
return -EINVAL;
}
if (ret < 0) {
dev_err(chip->dev, "Failed to write REG_I_CTRL Register\n");
return ret;
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/delay.h`, `linux/fs.h`, `linux/i2c.h`, `linux/leds.h`, `linux/module.h`, `linux/platform_data/leds-lm3642.h`, `linux/platform_device.h`.
- Detected declarations: `struct lm3642_chip_data`, `enum lm3642_mode`, `function lm3642_chip_init`, `function lm3642_control`, `function torch_pin_store`, `function lm3642_torch_brightness_set`, `function strobe_pin_store`, `function lm3642_strobe_brightness_set`, `function lm3642_indicator_brightness_set`, `function lm3642_probe`.
- Atlas domain: Driver Families / drivers/leds.
- 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.