drivers/leds/rgb/leds-ktd202x.c
Source file repositories/reference/linux-study-clean/drivers/leds/rgb/leds-ktd202x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/rgb/leds-ktd202x.c- Extension
.c- Size
- 16521 bytes
- Lines
- 636
- 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/i2c.hlinux/led-class-multicolor.hlinux/module.hlinux/mutex.hlinux/of.hlinux/of_device.hlinux/regmap.hlinux/regulator/consumer.h
Detected Declarations
struct ktd202x_ledstruct ktd202xfunction ktd202x_chip_disablefunction ktd202x_chip_enablefunction ktd202x_chip_in_usefunction ktd202x_brightness_setfunction ktd202x_brightness_single_setfunction ktd202x_brightness_mc_setfunction ktd202x_blink_setfunction ktd202x_blink_single_setfunction ktd202x_blink_mc_setfunction ktd202x_setup_led_rgbfunction fwnode_for_each_child_nodefunction ktd202x_setup_led_singlefunction ktd202x_add_ledfunction ktd202x_probe_fwfunction device_for_each_child_node_scopedfunction ktd202x_probefunction ktd202x_removefunction ktd202x_shutdown
Annotated Snippet
struct ktd202x_led {
struct ktd202x *chip;
union {
struct led_classdev cdev;
struct led_classdev_mc mcdev;
};
u32 index;
};
struct ktd202x {
struct mutex mutex;
struct regulator_bulk_data regulators[2];
struct device *dev;
struct regmap *regmap;
bool enabled;
unsigned long num_leds;
struct ktd202x_led leds[] __counted_by(num_leds);
};
static int ktd202x_chip_disable(struct ktd202x *chip)
{
int ret;
if (!chip->enabled)
return 0;
regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL, KTD202X_ENABLE_CTRL_SLEEP);
ret = regulator_bulk_disable(ARRAY_SIZE(chip->regulators), chip->regulators);
if (ret) {
dev_err(chip->dev, "Failed to disable regulators: %d\n", ret);
return ret;
}
chip->enabled = false;
return 0;
}
static int ktd202x_chip_enable(struct ktd202x *chip)
{
int ret;
if (chip->enabled)
return 0;
ret = regulator_bulk_enable(ARRAY_SIZE(chip->regulators), chip->regulators);
if (ret) {
dev_err(chip->dev, "Failed to enable regulators: %d\n", ret);
return ret;
}
chip->enabled = true;
ret = regmap_write(chip->regmap, KTD202X_REG_RESET_CONTROL, KTD202X_ENABLE_CTRL_WAKE);
if (ret) {
dev_err(chip->dev, "Failed to enable the chip: %d\n", ret);
ktd202x_chip_disable(chip);
}
return ret;
}
static bool ktd202x_chip_in_use(struct ktd202x *chip)
{
int i;
for (i = 0; i < chip->num_leds; i++) {
if (chip->leds[i].cdev.brightness)
return true;
}
return false;
}
static int ktd202x_brightness_set(struct ktd202x_led *led,
struct mc_subled *subleds,
unsigned int num_channels)
{
bool mode_blink = false;
int channel;
int state;
int ret;
int i;
if (ktd202x_chip_in_use(led->chip)) {
ret = ktd202x_chip_enable(led->chip);
if (ret)
return ret;
}
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/led-class-multicolor.h`, `linux/module.h`, `linux/mutex.h`, `linux/of.h`, `linux/of_device.h`, `linux/regmap.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct ktd202x_led`, `struct ktd202x`, `function ktd202x_chip_disable`, `function ktd202x_chip_enable`, `function ktd202x_chip_in_use`, `function ktd202x_brightness_set`, `function ktd202x_brightness_single_set`, `function ktd202x_brightness_mc_set`, `function ktd202x_blink_set`, `function ktd202x_blink_single_set`.
- 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.