drivers/usb/serial/mos7840.c
Source file repositories/reference/linux-study-clean/drivers/usb/serial/mos7840.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/serial/mos7840.c- Extension
.c- Size
- 54503 bytes
- Lines
- 1807
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/errno.hlinux/slab.hlinux/tty.hlinux/tty_driver.hlinux/tty_flip.hlinux/module.hlinux/serial.hlinux/usb.hlinux/usb/serial.hlinux/uaccess.h
Detected Declarations
struct moschip_portenum mos7840_flagfunction mos7840_set_reg_syncfunction mos7840_get_reg_syncfunction mos7840_set_uart_regfunction mos7840_get_uart_regfunction mos7840_dump_serial_portfunction mos7840_set_led_callbackfunction mos7840_set_led_asyncfunction mos7840_set_led_syncfunction mos7840_led_offfunction mos7840_led_flag_offfunction mos7840_led_activityfunction mos7840_bulk_in_callbackfunction mos7840_bulk_out_data_callbackfunction mos7840_openfunction portfunction mos7840_closefunction mos7840_breakfunction mos7840_write_roomfunction mos7840_writefunction mos7840_throttlefunction portfunction mos7840_tiocmgetfunction mos7840_tiocmsetfunction mos7840_calc_baud_rate_divisorfunction mos7840_send_cmd_write_baud_ratefunction mos7840_change_port_settingsfunction mos7840_set_termiosfunction mos7840_get_lsr_infofunction mos7840_ioctlfunction GPOfunction mos7840_probefunction mos7840_calc_num_portsfunction mos7840_attachfunction mos7840_port_probefunction mos7840_port_removefunction mos7840_suspendfunction mos7840_resume
Annotated Snippet
struct moschip_port {
int port_num; /*Actual port number in the device(1,2,etc) */
struct urb *read_urb; /* read URB for this port */
__u8 shadowLCR; /* last LCR value received */
__u8 shadowMCR; /* last MCR value received */
struct usb_serial_port *port; /* loop back to the owner of this object */
/* Offsets */
__u8 SpRegOffset;
__u8 ControlRegOffset;
__u8 DcrRegOffset;
spinlock_t pool_lock;
struct urb *write_urb_pool[NUM_URBS];
char busy[NUM_URBS];
bool read_urb_busy;
/* For device(s) with LED indicator */
bool has_led;
struct timer_list led_timer1; /* Timer for LED on */
struct timer_list led_timer2; /* Timer for LED off */
struct urb *led_urb;
struct usb_ctrlrequest *led_dr;
unsigned long flags;
};
/*
* mos7840_set_reg_sync
* To set the Control register by calling usb_fill_control_urb function
* by passing usb_sndctrlpipe function as parameter.
*/
static int mos7840_set_reg_sync(struct usb_serial_port *port, __u16 reg,
__u16 val)
{
struct usb_device *dev = port->serial->dev;
val = val & 0x00ff;
dev_dbg(&port->dev, "mos7840_set_reg_sync offset is %x, value %x\n", reg, val);
return usb_control_msg(dev, usb_sndctrlpipe(dev, 0), MCS_WRREQ,
MCS_WR_RTYPE, val, reg, NULL, 0,
MOS_WDR_TIMEOUT);
}
/*
* mos7840_get_reg_sync
* To set the Uart register by calling usb_fill_control_urb function by
* passing usb_rcvctrlpipe function as parameter.
*/
static int mos7840_get_reg_sync(struct usb_serial_port *port, __u16 reg,
__u16 *val)
{
struct usb_device *dev = port->serial->dev;
int ret = 0;
u8 *buf;
buf = kmalloc(VENDOR_READ_LENGTH, GFP_KERNEL);
if (!buf)
return -ENOMEM;
ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ,
MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH,
MOS_WDR_TIMEOUT);
if (ret < VENDOR_READ_LENGTH) {
if (ret >= 0)
ret = -EIO;
goto out;
}
*val = buf[0];
dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *val);
out:
kfree(buf);
return ret;
}
/*
* mos7840_set_uart_reg
* To set the Uart register by calling usb_fill_control_urb function by
* passing usb_sndctrlpipe function as parameter.
*/
static int mos7840_set_uart_reg(struct usb_serial_port *port, __u16 reg,
__u16 val)
{
struct usb_device *dev = port->serial->dev;
val = val & 0x00ff;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/slab.h`, `linux/tty.h`, `linux/tty_driver.h`, `linux/tty_flip.h`, `linux/module.h`, `linux/serial.h`.
- Detected declarations: `struct moschip_port`, `enum mos7840_flag`, `function mos7840_set_reg_sync`, `function mos7840_get_reg_sync`, `function mos7840_set_uart_reg`, `function mos7840_get_uart_reg`, `function mos7840_dump_serial_port`, `function mos7840_set_led_callback`, `function mos7840_set_led_async`, `function mos7840_set_led_sync`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.