drivers/leds/leds-lm3697.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-lm3697.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-lm3697.c- Extension
.c- Size
- 9646 bytes
- Lines
- 382
- 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/bits.hlinux/gpio/consumer.hlinux/i2c.hlinux/mod_devicetable.hlinux/module.hlinux/property.hlinux/regmap.hlinux/regulator/consumer.hlinux/types.hlinux/leds-ti-lmu-common.h
Detected Declarations
struct lm3697_ledstruct lm3697function lm3697_brightness_setfunction lm3697_initfunction lm3697_probe_dtfunction device_for_each_child_node_scopedfunction lm3697_probefunction lm3697_remove
Annotated Snippet
struct lm3697_led {
u32 hvled_strings[LM3697_MAX_LED_STRINGS];
char label[LED_MAX_NAME_SIZE];
struct led_classdev led_dev;
struct lm3697 *priv;
struct ti_lmu_bank lmu_data;
int control_bank;
int enabled;
int num_leds;
};
/**
* struct lm3697 -
* @enable_gpio: Hardware enable gpio
* @regulator: LED supply regulator pointer
* @client: Pointer to the I2C client
* @regmap: Devices register map
* @dev: Pointer to the devices device struct
* @lock: Lock for reading/writing the device
* @leds: Array of LED strings
* @bank_cfg: OUTPUT_CONFIG register values
* @num_banks: Number of control banks
*/
struct lm3697 {
struct gpio_desc *enable_gpio;
struct regulator *regulator;
struct i2c_client *client;
struct regmap *regmap;
struct device *dev;
struct mutex lock;
int bank_cfg;
int num_banks;
struct lm3697_led leds[] __counted_by(num_banks);
};
static const struct reg_default lm3697_reg_defs[] = {
{LM3697_OUTPUT_CONFIG, 0x6},
{LM3697_CTRL_A_RAMP, 0x0},
{LM3697_CTRL_B_RAMP, 0x0},
{LM3697_CTRL_A_B_RT_RAMP, 0x0},
{LM3697_CTRL_A_B_RAMP_CFG, 0x0},
{LM3697_CTRL_A_B_BRT_CFG, 0x0},
{LM3697_CTRL_A_FS_CURR_CFG, 0x13},
{LM3697_CTRL_B_FS_CURR_CFG, 0x13},
{LM3697_PWM_CFG, 0xc},
{LM3697_CTRL_A_BRT_LSB, 0x0},
{LM3697_CTRL_A_BRT_MSB, 0x0},
{LM3697_CTRL_B_BRT_LSB, 0x0},
{LM3697_CTRL_B_BRT_MSB, 0x0},
{LM3697_CTRL_ENABLE, 0x0},
};
static const struct regmap_config lm3697_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = LM3697_CTRL_ENABLE,
.reg_defaults = lm3697_reg_defs,
.num_reg_defaults = ARRAY_SIZE(lm3697_reg_defs),
.cache_type = REGCACHE_FLAT,
};
static int lm3697_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brt_val)
{
struct lm3697_led *led = container_of(led_cdev, struct lm3697_led,
led_dev);
int ctrl_en_val = (1 << led->control_bank);
struct device *dev = led->priv->dev;
int ret;
mutex_lock(&led->priv->lock);
if (brt_val == LED_OFF) {
ret = regmap_update_bits(led->priv->regmap, LM3697_CTRL_ENABLE,
ctrl_en_val, ~ctrl_en_val);
if (ret) {
dev_err(dev, "Cannot write ctrl register\n");
goto brightness_out;
}
led->enabled = LED_OFF;
} else {
ret = ti_lmu_common_set_brightness(&led->lmu_data, brt_val);
if (ret) {
dev_err(dev, "Cannot write brightness\n");
goto brightness_out;
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/property.h`, `linux/regmap.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct lm3697_led`, `struct lm3697`, `function lm3697_brightness_set`, `function lm3697_init`, `function lm3697_probe_dt`, `function device_for_each_child_node_scoped`, `function lm3697_probe`, `function lm3697_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.