drivers/leds/leds-el15203000.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-el15203000.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-el15203000.c- Extension
.c- Size
- 8758 bytes
- Lines
- 341
- 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/delay.hlinux/leds.hlinux/mod_devicetable.hlinux/module.hlinux/property.hlinux/spi/spi.h
Detected Declarations
struct el15203000_ledstruct el15203000enum el15203000_commandfunction el15203000_cmdfunction el15203000_set_blockingfunction el15203000_pattern_set_Sfunction is_cascadefunction is_bouncefunction el15203000_pattern_set_Pfunction el15203000_pattern_clearfunction el15203000_probe_dtfunction device_for_each_child_node_scopedfunction el15203000_probefunction el15203000_remove
Annotated Snippet
struct el15203000_led {
struct led_classdev ldev;
struct el15203000 *priv;
u32 reg;
};
struct el15203000 {
struct device *dev;
struct mutex lock;
struct spi_device *spi;
unsigned long delay;
size_t count;
struct el15203000_led leds[] __counted_by(count);
};
#define to_el15203000_led(d) container_of(d, struct el15203000_led, ldev)
static int el15203000_cmd(struct el15203000_led *led, u8 brightness)
{
int ret;
u8 cmd[2];
size_t i;
mutex_lock(&led->priv->lock);
dev_dbg(led->priv->dev, "Set brightness of 0x%02x(%c) to 0x%02x(%c)",
led->reg, led->reg, brightness, brightness);
/* to avoid SPI mistiming with firmware we should wait some time */
if (time_after(led->priv->delay, jiffies)) {
dev_dbg(led->priv->dev, "Wait %luus to sync",
EL_FW_DELAY_USEC);
usleep_range(EL_FW_DELAY_USEC,
EL_FW_DELAY_USEC + 1);
}
cmd[0] = led->reg;
cmd[1] = brightness;
for (i = 0; i < ARRAY_SIZE(cmd); i++) {
if (i)
usleep_range(EL_FW_DELAY_USEC,
EL_FW_DELAY_USEC + 1);
ret = spi_write(led->priv->spi, &cmd[i], sizeof(cmd[i]));
if (ret) {
dev_err(led->priv->dev,
"spi_write() error %d", ret);
break;
}
}
led->priv->delay = jiffies + usecs_to_jiffies(EL_FW_DELAY_USEC);
mutex_unlock(&led->priv->lock);
return ret;
}
static int el15203000_set_blocking(struct led_classdev *ldev,
enum led_brightness brightness)
{
struct el15203000_led *led = to_el15203000_led(ldev);
return el15203000_cmd(led, brightness == LED_OFF ? EL_OFF : EL_ON);
}
static int el15203000_pattern_set_S(struct led_classdev *ldev,
struct led_pattern *pattern,
u32 len, int repeat)
{
struct el15203000_led *led = to_el15203000_led(ldev);
if (repeat > 0 || len != 2 ||
pattern[0].delta_t != 4000 || pattern[0].brightness != 0 ||
pattern[1].delta_t != 4000 || pattern[1].brightness != 1)
return -EINVAL;
dev_dbg(led->priv->dev, "Breathing mode for 0x%02x(%c)",
led->reg, led->reg);
return el15203000_cmd(led, EL_SCREEN_BREATHING);
}
static bool is_cascade(const struct led_pattern *pattern, u32 len,
bool inv, bool right)
{
int val, t;
u32 i;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/leds.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/property.h`, `linux/spi/spi.h`.
- Detected declarations: `struct el15203000_led`, `struct el15203000`, `enum el15203000_command`, `function el15203000_cmd`, `function el15203000_set_blocking`, `function el15203000_pattern_set_S`, `function is_cascade`, `function is_bounce`, `function el15203000_pattern_set_P`, `function el15203000_pattern_clear`.
- 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.