drivers/leds/leds-cpcap.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-cpcap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-cpcap.c- Extension
.c- Size
- 4993 bytes
- Lines
- 227
- 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/leds.hlinux/mfd/motorola-cpcap.hlinux/module.hlinux/mutex.hlinux/of.hlinux/platform_device.hlinux/regmap.hlinux/regulator/consumer.h
Detected Declarations
struct cpcap_led_infostruct cpcap_ledfunction cpcap_led_valfunction cpcap_led_set_powerfunction cpcap_led_setfunction cpcap_led_probe
Annotated Snippet
struct cpcap_led_info {
u16 reg;
u16 mask;
u16 limit;
u16 init_mask;
u16 init_val;
};
static const struct cpcap_led_info cpcap_led_red = {
.reg = CPCAP_REG_REDC,
.mask = 0x03FF,
.limit = 31,
};
static const struct cpcap_led_info cpcap_led_green = {
.reg = CPCAP_REG_GREENC,
.mask = 0x03FF,
.limit = 31,
};
static const struct cpcap_led_info cpcap_led_blue = {
.reg = CPCAP_REG_BLUEC,
.mask = 0x03FF,
.limit = 31,
};
/* aux display light */
static const struct cpcap_led_info cpcap_led_adl = {
.reg = CPCAP_REG_ADLC,
.mask = 0x000F,
.limit = 1,
.init_mask = 0x7FFF,
.init_val = 0x5FF0,
};
/* camera privacy led */
static const struct cpcap_led_info cpcap_led_cp = {
.reg = CPCAP_REG_CLEDC,
.mask = 0x0007,
.limit = 1,
.init_mask = 0x03FF,
.init_val = 0x0008,
};
struct cpcap_led {
struct led_classdev led;
const struct cpcap_led_info *info;
struct device *dev;
struct regmap *regmap;
struct mutex update_lock;
struct regulator *vdd;
bool powered;
u32 current_limit;
};
static u16 cpcap_led_val(u8 current_limit, u8 duty_cycle)
{
current_limit &= 0x1f; /* 5 bit */
duty_cycle &= 0x0f; /* 4 bit */
return current_limit << 4 | duty_cycle;
}
static int cpcap_led_set_power(struct cpcap_led *led, bool status)
{
int err;
if (status == led->powered)
return 0;
if (status)
err = regulator_enable(led->vdd);
else
err = regulator_disable(led->vdd);
if (err) {
dev_err(led->dev, "regulator failure: %d", err);
return err;
}
led->powered = status;
return 0;
}
static int cpcap_led_set(struct led_classdev *ledc, enum led_brightness value)
{
struct cpcap_led *led = container_of(ledc, struct cpcap_led, led);
int brightness;
Annotation
- Immediate include surface: `linux/leds.h`, `linux/mfd/motorola-cpcap.h`, `linux/module.h`, `linux/mutex.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct cpcap_led_info`, `struct cpcap_led`, `function cpcap_led_val`, `function cpcap_led_set_power`, `function cpcap_led_set`, `function cpcap_led_probe`.
- 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.