drivers/leds/leds-blinkm.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-blinkm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-blinkm.c- Extension
.c- Size
- 21490 bytes
- Lines
- 835
- 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/module.hlinux/slab.hlinux/jiffies.hlinux/i2c.hlinux/err.hlinux/mutex.hlinux/sysfs.hlinux/printk.hlinux/pm_runtime.hlinux/leds.hlinux/delay.hlinux/led-class-multicolor.hlinux/kconfig.h
Detected Declarations
struct blinkm_ledstruct blinkm_datafunction show_color_commonfunction store_color_commonfunction red_showfunction red_storefunction green_showfunction green_storefunction blue_showfunction blue_storefunction test_showfunction test_storefunction blinkm_writefunction blinkm_readfunction blinkm_transfer_hwfunction blinkm_set_mc_brightnessfunction blinkm_led_common_setfunction blinkm_led_red_setfunction blinkm_led_green_setfunction blinkm_led_blue_setfunction blinkm_init_hwfunction blinkm_test_runfunction blinkm_detectfunction register_separate_colorsfunction register_multicolorfunction blinkm_probefunction blinkm_remove
Annotated Snippet
struct blinkm_led {
struct i2c_client *i2c_client;
union {
/* used when multicolor support is disabled */
struct led_classdev led_cdev;
struct led_classdev_mc mcled_cdev;
} cdev;
int id;
};
#define led_cdev_to_blmled(c) container_of(c, struct blinkm_led, cdev.led_cdev)
#define mcled_cdev_to_led(c) container_of(c, struct blinkm_led, cdev.mcled_cdev)
struct blinkm_data {
struct i2c_client *i2c_client;
struct mutex update_lock;
/* used for led class interface */
struct blinkm_led blinkm_leds[NUM_LEDS];
/* used for "blinkm" sysfs interface */
u8 red; /* color red */
u8 green; /* color green */
u8 blue; /* color blue */
/* next values to use for transfer */
u8 next_red; /* color red */
u8 next_green; /* color green */
u8 next_blue; /* color blue */
/* internal use */
u8 args[7]; /* set of args for transmission */
u8 i2c_addr; /* i2c addr */
u8 fw_ver; /* firmware version */
/* used, but not from userspace */
u8 hue; /* HSB hue */
u8 saturation; /* HSB saturation */
u8 brightness; /* HSB brightness */
u8 next_hue; /* HSB hue */
u8 next_saturation; /* HSB saturation */
u8 next_brightness; /* HSB brightness */
/* currently unused / todo */
u8 fade_speed; /* fade speed 1 - 255 */
s8 time_adjust; /* time adjust -128 - 127 */
u8 fade:1; /* fade on = 1, off = 0 */
u8 rand:1; /* rand fade mode on = 1 */
u8 script_id; /* script ID */
u8 script_repeats; /* repeats of script */
u8 script_startline; /* line to start */
};
/* Colors */
#define RED 0
#define GREEN 1
#define BLUE 2
/* mapping command names to cmd chars - see datasheet */
#define BLM_GO_RGB 0
#define BLM_FADE_RGB 1
#define BLM_FADE_HSB 2
#define BLM_FADE_RAND_RGB 3
#define BLM_FADE_RAND_HSB 4
#define BLM_PLAY_SCRIPT 5
#define BLM_STOP_SCRIPT 6
#define BLM_SET_FADE_SPEED 7
#define BLM_SET_TIME_ADJ 8
#define BLM_GET_CUR_RGB 9
#define BLM_WRITE_SCRIPT_LINE 10
#define BLM_READ_SCRIPT_LINE 11
#define BLM_SET_SCRIPT_LR 12 /* Length & Repeats */
#define BLM_SET_ADDR 13
#define BLM_GET_ADDR 14
#define BLM_GET_FW_VER 15
#define BLM_SET_STARTUP_PARAM 16
/* BlinkM Commands
* as extracted out of the datasheet:
*
* cmdchar = command (ascii)
* cmdbyte = command in hex
* nr_args = number of arguments (to send)
* nr_ret = number of return values (to read)
* dir = direction (0 = read, 1 = write, 2 = both)
*
*/
static const struct {
char cmdchar;
u8 cmdbyte;
u8 nr_args;
u8 nr_ret;
u8 dir:2;
} blinkm_cmds[17] = {
/* cmdchar, cmdbyte, nr_args, nr_ret, dir */
{ 'n', 0x6e, 3, 0, 1},
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/jiffies.h`, `linux/i2c.h`, `linux/err.h`, `linux/mutex.h`, `linux/sysfs.h`, `linux/printk.h`.
- Detected declarations: `struct blinkm_led`, `struct blinkm_data`, `function show_color_common`, `function store_color_common`, `function red_show`, `function red_store`, `function green_show`, `function green_store`, `function blue_show`, `function blue_store`.
- 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.