drivers/comedi/drivers/ni_usb6501.c
Source file repositories/reference/linux-study-clean/drivers/comedi/drivers/ni_usb6501.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/comedi/drivers/ni_usb6501.c- Extension
.c- Size
- 14593 bytes
- Lines
- 597
- Domain
- Driver Families
- Bucket
- drivers/comedi
- 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/kernel.hlinux/module.hlinux/slab.hlinux/comedi/comedi_usb.h
Detected Declarations
struct ni6501_privateenum commandsfunction ni6501_port_commandfunction ni6501_counter_commandfunction ni6501_dio_insn_configfunction ni6501_dio_insn_bitsfunction ni6501_cnt_insn_configfunction ni6501_cnt_insn_readfunction ni6501_cnt_insn_writefunction ni6501_alloc_usb_buffersfunction ni6501_find_endpointsfunction ni6501_auto_attachfunction ni6501_detachfunction ni6501_usb_probe
Annotated Snippet
struct ni6501_private {
struct usb_endpoint_descriptor *ep_rx;
struct usb_endpoint_descriptor *ep_tx;
struct mutex mut;
u8 *usb_rx_buf;
u8 *usb_tx_buf;
};
static int ni6501_port_command(struct comedi_device *dev, int command,
unsigned int val, u8 *bitmap)
{
struct usb_device *usb = comedi_to_usb_dev(dev);
struct ni6501_private *devpriv = dev->private;
int request_size, response_size;
u8 *tx = devpriv->usb_tx_buf;
int ret;
if (command != SET_PORT_DIR && !bitmap)
return -EINVAL;
mutex_lock(&devpriv->mut);
switch (command) {
case READ_PORT:
request_size = sizeof(READ_PORT_REQUEST);
response_size = sizeof(READ_PORT_RESPONSE);
memcpy(tx, READ_PORT_REQUEST, request_size);
tx[14] = val & 0xff;
break;
case WRITE_PORT:
request_size = sizeof(WRITE_PORT_REQUEST);
response_size = sizeof(GENERIC_RESPONSE);
memcpy(tx, WRITE_PORT_REQUEST, request_size);
tx[14] = val & 0xff;
tx[17] = *bitmap;
break;
case SET_PORT_DIR:
request_size = sizeof(SET_PORT_DIR_REQUEST);
response_size = sizeof(GENERIC_RESPONSE);
memcpy(tx, SET_PORT_DIR_REQUEST, request_size);
tx[14] = val & 0xff;
tx[15] = (val >> 8) & 0xff;
tx[16] = (val >> 16) & 0xff;
break;
default:
ret = -EINVAL;
goto end;
}
ret = usb_bulk_msg(usb,
usb_sndbulkpipe(usb,
devpriv->ep_tx->bEndpointAddress),
devpriv->usb_tx_buf,
request_size,
NULL,
NI6501_TIMEOUT);
if (ret)
goto end;
ret = usb_bulk_msg(usb,
usb_rcvbulkpipe(usb,
devpriv->ep_rx->bEndpointAddress),
devpriv->usb_rx_buf,
response_size,
NULL,
NI6501_TIMEOUT);
if (ret)
goto end;
/* Check if results are valid */
if (command == READ_PORT) {
*bitmap = devpriv->usb_rx_buf[14];
/* mask bitmap for comparing */
devpriv->usb_rx_buf[14] = 0x00;
if (memcmp(devpriv->usb_rx_buf, READ_PORT_RESPONSE,
sizeof(READ_PORT_RESPONSE))) {
ret = -EINVAL;
}
} else if (memcmp(devpriv->usb_rx_buf, GENERIC_RESPONSE,
sizeof(GENERIC_RESPONSE))) {
ret = -EINVAL;
}
end:
mutex_unlock(&devpriv->mut);
return ret;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/comedi/comedi_usb.h`.
- Detected declarations: `struct ni6501_private`, `enum commands`, `function ni6501_port_command`, `function ni6501_counter_command`, `function ni6501_dio_insn_config`, `function ni6501_dio_insn_bits`, `function ni6501_cnt_insn_config`, `function ni6501_cnt_insn_read`, `function ni6501_cnt_insn_write`, `function ni6501_alloc_usb_buffers`.
- Atlas domain: Driver Families / drivers/comedi.
- 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.