drivers/hid/hid-cp2112.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-cp2112.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-cp2112.c- Extension
.c- Size
- 38341 bytes
- Lines
- 1498
- 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/bitops.hlinux/cleanup.hlinux/gpio/driver.hlinux/hid.hlinux/hidraw.hlinux/i2c.hlinux/module.hlinux/mutex.hlinux/nls.hlinux/string_choices.hlinux/usb/ch9.hhid-ids.h
Detected Declarations
struct cp2112_smbus_config_reportstruct cp2112_usb_config_reportstruct cp2112_read_req_reportstruct cp2112_write_read_req_reportstruct cp2112_write_req_reportstruct cp2112_force_read_reportstruct cp2112_xfer_status_reportstruct cp2112_string_reportstruct cp2112_deviceenum cp2112_child_acpi_cell_addrsfunction cp2112_gpio_direction_inputfunction cp2112_gpio_set_unlockedfunction cp2112_gpio_setfunction cp2112_gpio_get_allfunction cp2112_gpio_getfunction cp2112_gpio_direction_outputfunction cp2112_hid_getfunction cp2112_hid_outputfunction cp2112_waitfunction cp2112_xfer_statusfunction cp2112_readfunction cp2112_read_reqfunction cp2112_write_read_reqfunction cp2112_write_reqfunction cp2112_i2c_write_reqfunction cp2112_i2c_write_read_reqfunction cp2112_i2c_xferfunction cp2112_xferfunction cp2112_functionalityfunction cp2112_get_usb_configfunction cp2112_set_usb_configfunction pstr_storefunction pstr_showfunction chmod_sysfs_attrsfunction cp2112_gpio_irq_ackfunction cp2112_gpio_irq_unmaskfunction cp2112_gpio_poll_callbackfunction cp2112_gpio_irq_startupfunction cp2112_gpio_irq_shutdownfunction cp2112_gpio_irq_typefunction cp2112_probefunction fwnode_for_each_child_nodefunction cp2112_removefunction cp2112_raw_event
Annotated Snippet
struct cp2112_smbus_config_report {
u8 report; /* CP2112_SMBUS_CONFIG */
__be32 clock_speed; /* Hz */
u8 device_address; /* Stored in the upper 7 bits */
u8 auto_send_read; /* 1 = enabled, 0 = disabled */
__be16 write_timeout; /* ms, 0 = no timeout */
__be16 read_timeout; /* ms, 0 = no timeout */
u8 scl_low_timeout; /* 1 = enabled, 0 = disabled */
__be16 retry_time; /* # of retries, 0 = no limit */
} __packed;
struct cp2112_usb_config_report {
u8 report; /* CP2112_USB_CONFIG */
__le16 vid; /* Vendor ID */
__le16 pid; /* Product ID */
u8 max_power; /* Power requested in 2mA units */
u8 power_mode; /* 0x00 = bus powered
0x01 = self powered & regulator off
0x02 = self powered & regulator on */
u8 release_major;
u8 release_minor;
u8 mask; /* What fields to program */
} __packed;
struct cp2112_read_req_report {
u8 report; /* CP2112_DATA_READ_REQUEST */
u8 slave_address;
__be16 length;
} __packed;
struct cp2112_write_read_req_report {
u8 report; /* CP2112_DATA_WRITE_READ_REQUEST */
u8 slave_address;
__be16 length;
u8 target_address_length;
u8 target_address[16];
} __packed;
struct cp2112_write_req_report {
u8 report; /* CP2112_DATA_WRITE_REQUEST */
u8 slave_address;
u8 length;
u8 data[61];
} __packed;
struct cp2112_force_read_report {
u8 report; /* CP2112_DATA_READ_FORCE_SEND */
__be16 length;
} __packed;
struct cp2112_xfer_status_report {
u8 report; /* CP2112_TRANSFER_STATUS_RESPONSE */
u8 status0; /* STATUS0_* */
u8 status1; /* STATUS1_* */
__be16 retries;
__be16 length;
} __packed;
struct cp2112_string_report {
u8 dummy; /* force .string to be aligned */
struct_group_attr(contents, __packed,
u8 report; /* CP2112_*_STRING */
u8 length; /* length in bytes of everything after .report */
u8 type; /* USB_DT_STRING */
wchar_t string[30]; /* UTF16_LITTLE_ENDIAN string */
);
} __packed;
/* Number of times to request transfer status before giving up waiting for a
transfer to complete. This may need to be changed if SMBUS clock, retries,
or read/write/scl_low timeout settings are changed. */
static const int XFER_STATUS_RETRIES = 10;
/* Time in ms to wait for a CP2112_DATA_READ_RESPONSE or
CP2112_TRANSFER_STATUS_RESPONSE. */
static const int RESPONSE_TIMEOUT = 50;
static const struct hid_device_id cp2112_devices[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
{ }
};
MODULE_DEVICE_TABLE(hid, cp2112_devices);
struct cp2112_device {
struct i2c_adapter adap;
struct hid_device *hdev;
wait_queue_head_t wait;
u8 read_data[61];
u8 read_length;
u8 hwversion;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/cleanup.h`, `linux/gpio/driver.h`, `linux/hid.h`, `linux/hidraw.h`, `linux/i2c.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct cp2112_smbus_config_report`, `struct cp2112_usb_config_report`, `struct cp2112_read_req_report`, `struct cp2112_write_read_req_report`, `struct cp2112_write_req_report`, `struct cp2112_force_read_report`, `struct cp2112_xfer_status_report`, `struct cp2112_string_report`, `struct cp2112_device`, `enum cp2112_child_acpi_cell_addrs`.
- 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.