drivers/hid/hid-led.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-led.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-led.c- Extension
.c- Size
- 12389 bytes
- Lines
- 536
- Domain
- Driver Families
- Bucket
- drivers/hid
- 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/hid.hlinux/hidraw.hlinux/leds.hlinux/module.hlinux/mutex.hhid-ids.h
Detected Declarations
struct hidled_devicestruct hidled_rgbstruct hidled_configstruct hidled_ledstruct hidled_rgbstruct hidled_deviceenum hidled_report_typeenum hidled_typefunction hidled_sendfunction hidled_recvfunction riso_kagaku_indexfunction riso_kagaku_writefunction dream_cheeky_writefunction dream_cheeky_initfunction _thingm_writefunction thingm_write_v1function thingm_writefunction thingm_initfunction delcom_get_lednumfunction delcom_enable_ledfunction delcom_set_pwmfunction delcom_writefunction delcom_initfunction luxafor_writefunction hidled_init_ledfunction hidled_init_rgbfunction hidled_probe
Annotated Snippet
struct hidled_config {
enum hidled_type type;
const char *name;
const char *short_name;
enum led_brightness max_brightness;
int num_leds;
size_t report_size;
enum hidled_report_type report_type;
int (*init)(struct hidled_device *ldev);
int (*write)(struct led_classdev *cdev, enum led_brightness br);
};
struct hidled_led {
struct led_classdev cdev;
struct hidled_rgb *rgb;
char name[32];
};
struct hidled_rgb {
struct hidled_device *ldev;
struct hidled_led red;
struct hidled_led green;
struct hidled_led blue;
u8 num;
};
struct hidled_device {
const struct hidled_config *config;
struct hid_device *hdev;
struct hidled_rgb *rgb;
u8 *buf;
struct mutex lock;
};
#define MAX_REPORT_SIZE 16
#define to_hidled_led(arg) container_of(arg, struct hidled_led, cdev)
static bool riso_kagaku_switch_green_blue;
module_param(riso_kagaku_switch_green_blue, bool, S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(riso_kagaku_switch_green_blue,
"switch green and blue RGB component for Riso Kagaku devices");
static int hidled_send(struct hidled_device *ldev, __u8 *buf)
{
int ret;
mutex_lock(&ldev->lock);
/*
* buffer provided to hid_hw_raw_request must not be on the stack
* and must not be part of a data structure
*/
memcpy(ldev->buf, buf, ldev->config->report_size);
if (ldev->config->report_type == RAW_REQUEST)
ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
ldev->config->report_size,
HID_FEATURE_REPORT,
HID_REQ_SET_REPORT);
else if (ldev->config->report_type == OUTPUT_REPORT)
ret = hid_hw_output_report(ldev->hdev, ldev->buf,
ldev->config->report_size);
else
ret = -EINVAL;
mutex_unlock(&ldev->lock);
if (ret < 0)
return ret;
return ret == ldev->config->report_size ? 0 : -EMSGSIZE;
}
/* reading data is supported for report type RAW_REQUEST only */
static int hidled_recv(struct hidled_device *ldev, __u8 *buf)
{
int ret;
if (ldev->config->report_type != RAW_REQUEST)
return -EINVAL;
mutex_lock(&ldev->lock);
memcpy(ldev->buf, buf, ldev->config->report_size);
ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
ldev->config->report_size,
HID_FEATURE_REPORT,
HID_REQ_SET_REPORT);
Annotation
- Immediate include surface: `linux/hid.h`, `linux/hidraw.h`, `linux/leds.h`, `linux/module.h`, `linux/mutex.h`, `hid-ids.h`.
- Detected declarations: `struct hidled_device`, `struct hidled_rgb`, `struct hidled_config`, `struct hidled_led`, `struct hidled_rgb`, `struct hidled_device`, `enum hidled_report_type`, `enum hidled_type`, `function hidled_send`, `function hidled_recv`.
- Atlas domain: Driver Families / drivers/hid.
- 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.