drivers/leds/leds-lm3692x.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-lm3692x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-lm3692x.c- Extension
.c- Size
- 13380 bytes
- Lines
- 533
- 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/gpio/consumer.hlinux/i2c.hlinux/init.hlinux/leds.hlinux/log2.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/regmap.hlinux/regulator/consumer.hlinux/slab.h
Detected Declarations
struct lm3692x_ledfunction lm3692x_fault_checkfunction lm3692x_leds_enablefunction lm3692x_leds_disablefunction lm3692x_brightness_setfunction lm3692x_max_brightnessfunction lm3692x_probe_dtfunction lm3692x_probefunction lm3692x_remove
Annotated Snippet
struct lm3692x_led {
struct mutex lock;
struct i2c_client *client;
struct led_classdev led_dev;
struct regmap *regmap;
struct gpio_desc *enable_gpio;
struct regulator *regulator;
int led_enable;
int model_id;
u8 boost_ctrl, brightness_ctrl;
bool enabled;
};
static const struct reg_default lm3692x_reg_defs[] = {
{LM3692X_EN, 0xf},
{LM3692X_BRT_CTRL, 0x61},
{LM3692X_PWM_CTRL, 0x73},
{LM3692X_BOOST_CTRL, 0x6f},
{LM3692X_AUTO_FREQ_HI, 0x0},
{LM3692X_AUTO_FREQ_LO, 0x0},
{LM3692X_BL_ADJ_THRESH, 0x0},
{LM3692X_BRT_LSB, 0x7},
{LM3692X_BRT_MSB, 0xff},
{LM3692X_FAULT_CTRL, 0x7},
};
static const struct regmap_config lm3692x_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = LM3692X_FAULT_FLAGS,
.reg_defaults = lm3692x_reg_defs,
.num_reg_defaults = ARRAY_SIZE(lm3692x_reg_defs),
.cache_type = REGCACHE_MAPLE,
};
static int lm3692x_fault_check(struct lm3692x_led *led)
{
int ret;
unsigned int read_buf;
ret = regmap_read(led->regmap, LM3692X_FAULT_FLAGS, &read_buf);
if (ret)
return ret;
if (read_buf)
dev_err(&led->client->dev, "Detected a fault 0x%X\n", read_buf);
/* The first read may clear the fault. Check again to see if the fault
* still exits and return that value.
*/
regmap_read(led->regmap, LM3692X_FAULT_FLAGS, &read_buf);
if (read_buf)
dev_err(&led->client->dev, "Second read of fault flags 0x%X\n",
read_buf);
return read_buf;
}
static int lm3692x_leds_enable(struct lm3692x_led *led)
{
int enable_state;
int ret, reg_ret;
if (led->enabled)
return 0;
if (led->regulator) {
ret = regulator_enable(led->regulator);
if (ret) {
dev_err(&led->client->dev,
"Failed to enable regulator: %d\n", ret);
return ret;
}
}
if (led->enable_gpio)
gpiod_direction_output(led->enable_gpio, 1);
ret = lm3692x_fault_check(led);
if (ret) {
dev_err(&led->client->dev, "Cannot read/clear faults: %d\n",
ret);
goto out;
}
ret = regmap_write(led->regmap, LM3692X_BRT_CTRL, 0x00);
if (ret)
goto out;
Annotation
- Immediate include surface: `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/init.h`, `linux/leds.h`, `linux/log2.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct lm3692x_led`, `function lm3692x_fault_check`, `function lm3692x_leds_enable`, `function lm3692x_leds_disable`, `function lm3692x_brightness_set`, `function lm3692x_max_brightness`, `function lm3692x_probe_dt`, `function lm3692x_probe`, `function lm3692x_remove`.
- 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.