drivers/hid/hid-roccat-common.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-roccat-common.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-roccat-common.c- Extension
.c- Size
- 4565 bytes
- Lines
- 176
- Domain
- Driver Families
- Bucket
- drivers/hid
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/slab.hlinux/module.hhid-roccat-common.h
Detected Declarations
enum roccat_common2_control_statesfunction Copyrightfunction roccat_common2_receivefunction roccat_common2_sendfunction roccat_common2_receive_control_statusfunction roccat_common2_send_with_statusfunction roccat_common2_device_init_structfunction roccat_common2_sysfs_readfunction roccat_common2_sysfs_writeexport roccat_common2_receiveexport roccat_common2_sendexport roccat_common2_send_with_statusexport roccat_common2_device_init_structexport roccat_common2_sysfs_readexport roccat_common2_sysfs_write
Annotated Snippet
switch (control.value) {
case ROCCAT_COMMON_CONTROL_STATUS_OK:
return 0;
case ROCCAT_COMMON_CONTROL_STATUS_BUSY:
msleep(500);
continue;
case ROCCAT_COMMON_CONTROL_STATUS_INVALID:
case ROCCAT_COMMON_CONTROL_STATUS_CRITICAL:
case ROCCAT_COMMON_CONTROL_STATUS_CRITICAL_NEW:
return -EINVAL;
default:
dev_err(&usb_dev->dev,
"roccat_common2_receive_control_status: "
"unknown response value 0x%x\n",
control.value);
return -EINVAL;
}
} while (1);
}
int roccat_common2_send_with_status(struct usb_device *usb_dev,
uint command, void const *buf, uint size)
{
int retval;
retval = roccat_common2_send(usb_dev, command, buf, size);
if (retval)
return retval;
msleep(100);
return roccat_common2_receive_control_status(usb_dev);
}
EXPORT_SYMBOL_GPL(roccat_common2_send_with_status);
int roccat_common2_device_init_struct(struct usb_device *usb_dev,
struct roccat_common2_device *dev)
{
mutex_init(&dev->lock);
return 0;
}
EXPORT_SYMBOL_GPL(roccat_common2_device_init_struct);
ssize_t roccat_common2_sysfs_read(struct file *fp, struct kobject *kobj,
char *buf, loff_t off, size_t count,
size_t real_size, uint command)
{
struct device *dev = kobj_to_dev(kobj)->parent->parent;
struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev));
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
int retval;
if (off >= real_size)
return 0;
if (off != 0 || count != real_size)
return -EINVAL;
mutex_lock(&roccat_dev->lock);
retval = roccat_common2_receive(usb_dev, command, buf, real_size);
mutex_unlock(&roccat_dev->lock);
return retval ? retval : real_size;
}
EXPORT_SYMBOL_GPL(roccat_common2_sysfs_read);
ssize_t roccat_common2_sysfs_write(struct file *fp, struct kobject *kobj,
void const *buf, loff_t off, size_t count,
size_t real_size, uint command)
{
struct device *dev = kobj_to_dev(kobj)->parent->parent;
struct roccat_common2_device *roccat_dev = hid_get_drvdata(dev_get_drvdata(dev));
struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
int retval;
if (off != 0 || count != real_size)
return -EINVAL;
mutex_lock(&roccat_dev->lock);
retval = roccat_common2_send_with_status(usb_dev, command, buf, real_size);
mutex_unlock(&roccat_dev->lock);
return retval ? retval : real_size;
}
EXPORT_SYMBOL_GPL(roccat_common2_sysfs_write);
MODULE_AUTHOR("Stefan Achatz");
MODULE_DESCRIPTION("USB Roccat common driver");
MODULE_LICENSE("GPL v2");
Annotation
- Immediate include surface: `linux/hid.h`, `linux/slab.h`, `linux/module.h`, `hid-roccat-common.h`.
- Detected declarations: `enum roccat_common2_control_states`, `function Copyright`, `function roccat_common2_receive`, `function roccat_common2_send`, `function roccat_common2_receive_control_status`, `function roccat_common2_send_with_status`, `function roccat_common2_device_init_struct`, `function roccat_common2_sysfs_read`, `function roccat_common2_sysfs_write`, `export roccat_common2_receive`.
- Atlas domain: Driver Families / drivers/hid.
- Implementation status: integration 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.