drivers/hid/hid-mcp2200.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-mcp2200.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-mcp2200.c- Extension
.c- Size
- 9364 bytes
- Lines
- 398
- 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/completion.hlinux/delay.hlinux/err.hlinux/gpio/driver.hlinux/hid.hlinux/hidraw.hlinux/module.hlinux/mutex.hhid-ids.h
Detected Declarations
struct mcp_set_clear_outputsstruct mcp_configurestruct mcp_read_allstruct mcp_read_all_respstruct mcp2200enum MCP_IO_DIRfunction mcp_cmd_read_allfunction mcp_set_multiplefunction mcp_setfunction mcp_get_multiplefunction mcp_getfunction mcp_get_directionfunction mcp_set_directionfunction mcp_direction_inputfunction mcp_direction_outputfunction mcp2200_raw_eventfunction mcp2200_probefunction mcp2200_remove
Annotated Snippet
struct mcp_set_clear_outputs {
u8 cmd;
u8 dummys1[10];
u8 set_bmap;
u8 clear_bmap;
u8 dummys2[3];
} __packed;
/* CMD to configure the IOs */
struct mcp_configure {
u8 cmd;
u8 dummys1[3];
u8 io_bmap;
u8 config_alt_pins;
u8 io_default_val_bmap;
u8 config_alt_options;
u8 baud_h;
u8 baud_l;
u8 dummys2[6];
} __packed;
/* CMD to read all parameters */
struct mcp_read_all {
u8 cmd;
u8 dummys[15];
} __packed;
/* Response to the read all cmd */
struct mcp_read_all_resp {
u8 cmd;
u8 eep_addr;
u8 dummy;
u8 eep_val;
u8 io_bmap;
u8 config_alt_pins;
u8 io_default_val_bmap;
u8 config_alt_options;
u8 baud_h;
u8 baud_l;
u8 io_port_val_bmap;
u8 dummys[5];
} __packed;
struct mcp2200 {
struct hid_device *hdev;
struct mutex lock;
struct completion wait_in_report;
u8 gpio_dir;
u8 gpio_val;
u8 gpio_inval;
u8 baud_h;
u8 baud_l;
u8 config_alt_pins;
u8 gpio_reset_val;
u8 config_alt_options;
int status;
struct gpio_chip gc;
u8 hid_report[16];
};
/* this executes the READ_ALL cmd */
static int mcp_cmd_read_all(struct mcp2200 *mcp)
{
struct mcp_read_all *read_all;
int len, t;
reinit_completion(&mcp->wait_in_report);
mutex_lock(&mcp->lock);
read_all = (struct mcp_read_all *) mcp->hid_report;
read_all->cmd = READ_ALL;
len = hid_hw_output_report(mcp->hdev, (u8 *) read_all,
sizeof(struct mcp_read_all));
mutex_unlock(&mcp->lock);
if (len != sizeof(struct mcp_read_all))
return -EINVAL;
t = wait_for_completion_timeout(&mcp->wait_in_report,
msecs_to_jiffies(4000));
if (!t)
return -ETIMEDOUT;
/* return status, negative value if wrong response was received */
return mcp->status;
}
static int mcp_set_multiple(struct gpio_chip *gc, unsigned long *mask,
Annotation
- Immediate include surface: `linux/completion.h`, `linux/delay.h`, `linux/err.h`, `linux/gpio/driver.h`, `linux/hid.h`, `linux/hidraw.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct mcp_set_clear_outputs`, `struct mcp_configure`, `struct mcp_read_all`, `struct mcp_read_all_resp`, `struct mcp2200`, `enum MCP_IO_DIR`, `function mcp_cmd_read_all`, `function mcp_set_multiple`, `function mcp_set`, `function mcp_get_multiple`.
- 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.