drivers/leds/leds-cr0014114.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-cr0014114.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-cr0014114.c- Extension
.c- Size
- 6841 bytes
- Lines
- 297
- 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/spi/spi.hlinux/workqueue.h
Detected Declarations
struct cr0014114_ledstruct cr0014114function cr0014114_calc_crcfunction cr0014114_recountfunction cr0014114_syncfunction cr0014114_recount_workfunction cr0014114_set_syncfunction cr0014114_probe_dtfunction device_for_each_child_node_scopedfunction cr0014114_probefunction cr0014114_remove
Annotated Snippet
struct cr0014114_led {
struct cr0014114 *priv;
struct led_classdev ldev;
u8 brightness;
};
struct cr0014114 {
bool do_recount;
size_t count;
struct delayed_work work;
struct device *dev;
struct mutex lock;
struct spi_device *spi;
u8 *buf;
unsigned long delay;
struct cr0014114_led leds[] __counted_by(count);
};
static void cr0014114_calc_crc(u8 *buf, const size_t len)
{
size_t i;
u8 crc;
for (i = 1, crc = 1; i < len - 1; i++)
crc += buf[i];
crc |= BIT(7);
/* special case when CRC matches the SPI commands */
if (crc == CR_SET_BRIGHTNESS ||
crc == CR_INIT_REENUMERATE ||
crc == CR_NEXT_REENUMERATE)
crc = 0xfe;
buf[len - 1] = crc;
}
static int cr0014114_recount(struct cr0014114 *priv)
{
int ret;
size_t i;
u8 cmd;
dev_dbg(priv->dev, "LEDs recount is started\n");
cmd = CR_INIT_REENUMERATE;
ret = spi_write(priv->spi, &cmd, sizeof(cmd));
if (ret)
goto err;
cmd = CR_NEXT_REENUMERATE;
for (i = 0; i < priv->count; i++) {
msleep(CR_FW_DELAY_MSEC);
ret = spi_write(priv->spi, &cmd, sizeof(cmd));
if (ret)
goto err;
}
err:
dev_dbg(priv->dev, "LEDs recount is finished\n");
if (ret)
dev_err(priv->dev, "with error %d", ret);
return ret;
}
static int cr0014114_sync(struct cr0014114 *priv)
{
int ret;
size_t i;
unsigned long udelay, now = jiffies;
/* to avoid SPI mistiming with firmware we should wait some time */
if (time_after(priv->delay, now)) {
udelay = jiffies_to_usecs(priv->delay - now);
usleep_range(udelay, udelay + 1);
}
if (unlikely(priv->do_recount)) {
ret = cr0014114_recount(priv);
if (ret)
goto err;
priv->do_recount = false;
msleep(CR_FW_DELAY_MSEC);
}
priv->buf[0] = CR_SET_BRIGHTNESS;
for (i = 0; i < priv->count; i++)
Annotation
- Immediate include surface: `linux/delay.h`, `linux/leds.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/spi/spi.h`, `linux/workqueue.h`.
- Detected declarations: `struct cr0014114_led`, `struct cr0014114`, `function cr0014114_calc_crc`, `function cr0014114_recount`, `function cr0014114_sync`, `function cr0014114_recount_work`, `function cr0014114_set_sync`, `function cr0014114_probe_dt`, `function device_for_each_child_node_scoped`, `function cr0014114_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.