drivers/hid/hid-gt683r.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-gt683r.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-gt683r.c- Extension
.c- Size
- 6428 bytes
- Lines
- 311
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/device.hlinux/hid.hlinux/kernel.hlinux/leds.hlinux/module.hhid-ids.h
Detected Declarations
struct gt683r_ledenum gt683r_led_modeenum gt683r_panelsfunction gt683r_brightness_setfunction mode_showfunction mode_storefunction gt683r_led_snd_msgfunction gt683r_leds_setfunction gt683r_mode_setfunction gt683r_led_workfunction gt683r_led_probefunction gt683r_led_remove
Annotated Snippet
struct gt683r_led {
struct hid_device *hdev;
struct led_classdev led_devs[GT683R_LED_COUNT];
struct mutex lock;
struct work_struct work;
enum led_brightness brightnesses[GT683R_LED_COUNT];
enum gt683r_led_mode mode;
};
static const struct hid_device_id gt683r_led_id[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_MSI, USB_DEVICE_ID_MSI_GT683R_LED_PANEL) },
{ }
};
MODULE_DEVICE_TABLE(hid, gt683r_led_id);
static void gt683r_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
int i;
struct device *dev = led_cdev->dev->parent;
struct hid_device *hdev = to_hid_device(dev);
struct gt683r_led *led = hid_get_drvdata(hdev);
for (i = 0; i < GT683R_LED_COUNT; i++) {
if (led_cdev == &led->led_devs[i])
break;
}
if (i < GT683R_LED_COUNT) {
led->brightnesses[i] = brightness;
schedule_work(&led->work);
}
}
static ssize_t mode_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
u8 sysfs_mode;
struct hid_device *hdev = to_hid_device(dev->parent);
struct gt683r_led *led = hid_get_drvdata(hdev);
if (led->mode == GT683R_LED_NORMAL)
sysfs_mode = 0;
else if (led->mode == GT683R_LED_AUDIO)
sysfs_mode = 1;
else
sysfs_mode = 2;
return scnprintf(buf, PAGE_SIZE, "%u\n", sysfs_mode);
}
static ssize_t mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
u8 sysfs_mode;
struct hid_device *hdev = to_hid_device(dev->parent);
struct gt683r_led *led = hid_get_drvdata(hdev);
if (kstrtou8(buf, 10, &sysfs_mode) || sysfs_mode > 2)
return -EINVAL;
mutex_lock(&led->lock);
if (sysfs_mode == 0)
led->mode = GT683R_LED_NORMAL;
else if (sysfs_mode == 1)
led->mode = GT683R_LED_AUDIO;
else
led->mode = GT683R_LED_BREATHING;
mutex_unlock(&led->lock);
schedule_work(&led->work);
return count;
}
static int gt683r_led_snd_msg(struct gt683r_led *led, u8 *msg)
{
int ret;
ret = hid_hw_raw_request(led->hdev, msg[0], msg, GT683R_BUFFER_SIZE,
HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
if (ret != GT683R_BUFFER_SIZE) {
hid_err(led->hdev,
"failed to send set report request: %i\n", ret);
if (ret < 0)
return ret;
Annotation
- Immediate include surface: `linux/device.h`, `linux/hid.h`, `linux/kernel.h`, `linux/leds.h`, `linux/module.h`, `hid-ids.h`.
- Detected declarations: `struct gt683r_led`, `enum gt683r_led_mode`, `enum gt683r_panels`, `function gt683r_brightness_set`, `function mode_show`, `function mode_store`, `function gt683r_led_snd_msg`, `function gt683r_leds_set`, `function gt683r_mode_set`, `function gt683r_led_work`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.