drivers/leds/leds-tlc591xx.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-tlc591xx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-tlc591xx.c- Extension
.c- Size
- 5430 bytes
- Lines
- 237
- 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/i2c.hlinux/leds.hlinux/module.hlinux/of.hlinux/regmap.hlinux/slab.h
Detected Declarations
struct tlc591xx_ledstruct tlc591xx_privstruct tlc591xxfunction tlc591xx_set_modefunction tlc591xx_set_ledoutfunction tlc591xx_set_pwmfunction tlc591xx_brightness_setfunction tlc591xx_probefunction for_each_available_child_of_node_scoped
Annotated Snippet
struct tlc591xx_led {
bool active;
unsigned int led_no;
struct led_classdev ldev;
struct tlc591xx_priv *priv;
};
struct tlc591xx_priv {
struct tlc591xx_led leds[TLC591XX_MAX_LEDS];
struct regmap *regmap;
unsigned int reg_ledout_offset;
};
struct tlc591xx {
unsigned int max_leds;
unsigned int reg_ledout_offset;
};
static const struct tlc591xx tlc59116 = {
.max_leds = 16,
.reg_ledout_offset = 0x14,
};
static const struct tlc591xx tlc59108 = {
.max_leds = 8,
.reg_ledout_offset = 0x0c,
};
static int
tlc591xx_set_mode(struct regmap *regmap, u8 mode)
{
int err;
u8 val;
err = regmap_write(regmap, TLC591XX_REG_MODE1, MODE1_NORMAL_MODE);
if (err)
return err;
val = MODE2_OCH_STOP | mode;
return regmap_write(regmap, TLC591XX_REG_MODE2, val);
}
static int
tlc591xx_set_ledout(struct tlc591xx_priv *priv, struct tlc591xx_led *led,
u8 val)
{
unsigned int i = (led->led_no % 4) * 2;
unsigned int mask = LEDOUT_MASK << i;
unsigned int addr = priv->reg_ledout_offset + (led->led_no >> 2);
val = val << i;
return regmap_update_bits(priv->regmap, addr, mask, val);
}
static int
tlc591xx_set_pwm(struct tlc591xx_priv *priv, struct tlc591xx_led *led,
u8 brightness)
{
u8 pwm = TLC591XX_REG_PWM(led->led_no);
return regmap_write(priv->regmap, pwm, brightness);
}
static int
tlc591xx_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct tlc591xx_led *led = ldev_to_led(led_cdev);
struct tlc591xx_priv *priv = led->priv;
int err;
switch ((int)brightness) {
case 0:
err = tlc591xx_set_ledout(priv, led, LEDOUT_OFF);
break;
case TLC591XX_MAX_BRIGHTNESS:
err = tlc591xx_set_ledout(priv, led, LEDOUT_ON);
break;
default:
err = tlc591xx_set_ledout(priv, led, LEDOUT_DIM);
if (!err)
err = tlc591xx_set_pwm(priv, led, brightness);
}
return err;
}
static const struct regmap_config tlc591xx_regmap = {
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/leds.h`, `linux/module.h`, `linux/of.h`, `linux/regmap.h`, `linux/slab.h`.
- Detected declarations: `struct tlc591xx_led`, `struct tlc591xx_priv`, `struct tlc591xx`, `function tlc591xx_set_mode`, `function tlc591xx_set_ledout`, `function tlc591xx_set_pwm`, `function tlc591xx_brightness_set`, `function tlc591xx_probe`, `function for_each_available_child_of_node_scoped`.
- 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.