drivers/usb/serial/mos7720.c
Source file repositories/reference/linux-study-clean/drivers/usb/serial/mos7720.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/serial/mos7720.c- Extension
.c- Size
- 48433 bytes
- Lines
- 1764
- 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/spinlock.hlinux/serial.hlinux/serial_reg.hlinux/usb.hlinux/usb/serial.hlinux/uaccess.hlinux/parport.h
Detected Declarations
struct moschip_portstruct mos7715_parportstruct divisor_table_entryenum mos7715_pp_modesenum mos_regsfunction get_reg_indexfunction get_reg_valuefunction write_mos_regfunction read_mos_regfunction mos7715_change_modefunction destroy_mos_parportfunction parport_prologuefunction parport_epiloguefunction deferred_restore_writesfunction parport_mos7715_write_datafunction parport_mos7715_read_datafunction parport_mos7715_write_controlfunction parport_mos7715_read_controlfunction parport_mos7715_frob_controlfunction parport_mos7715_read_statusfunction parport_mos7715_enable_irqfunction parport_mos7715_data_reversefunction parport_mos7715_init_statefunction parport_mos7715_save_statefunction parport_mos7715_restore_statefunction parport_mos7715_write_compatfunction mos7715_parport_initfunction mos7720_interrupt_callbackfunction mos7715_interrupt_callbackfunction mos7720_bulk_in_callbackfunction mos7720_bulk_out_data_callbackfunction mos77xx_calc_num_portsfunction mos7720_openfunction portfunction mos7720_closefunction mos7720_breakfunction mos7720_write_roomfunction mos7720_writefunction mos7720_throttlefunction mos7720_unthrottlefunction set_higher_ratesfunction calc_baud_rate_divisorfunction send_cmd_write_baud_ratefunction change_port_settingsfunction mos7720_set_termiosfunction get_lsr_infofunction mos7720_tiocmgetfunction mos7720_tiocmset
Annotated Snippet
struct moschip_port {
__u8 shadowLCR; /* last LCR value received */
__u8 shadowMCR; /* last MCR value received */
__u8 shadowMSR; /* last MSR value received */
char open;
struct usb_serial_port *port; /* loop back to the owner */
struct urb *write_urb_pool[NUM_URBS];
};
#define USB_VENDOR_ID_MOSCHIP 0x9710
#define MOSCHIP_DEVICE_ID_7720 0x7720
#define MOSCHIP_DEVICE_ID_7715 0x7715
static const struct usb_device_id id_table[] = {
{ USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7720) },
{ USB_DEVICE(USB_VENDOR_ID_MOSCHIP, MOSCHIP_DEVICE_ID_7715) },
{ } /* terminating entry */
};
MODULE_DEVICE_TABLE(usb, id_table);
#ifdef CONFIG_USB_SERIAL_MOS7715_PARPORT
/* initial values for parport regs */
#define DCR_INIT_VAL 0x0c /* SLCTIN, nINIT */
#define ECR_INIT_VAL 0x00 /* SPP mode */
enum mos7715_pp_modes {
SPP = 0<<5,
PS2 = 1<<5, /* moschip calls this 'NIBBLE' mode */
PPF = 2<<5, /* moschip calls this 'CB-FIFO mode */
};
struct mos7715_parport {
struct parport *pp; /* back to containing struct */
struct kref ref_count; /* to instance of this struct */
bool msg_pending; /* usb sync call pending */
struct completion syncmsg_compl; /* usb sync call completed */
struct work_struct work; /* restore deferred writes */
struct usb_serial *serial; /* back to containing struct */
__u8 shadowECR; /* parallel port regs... */
__u8 shadowDCR;
atomic_t shadowDSR; /* updated in int-in callback */
};
/* lock guards against dereferencing NULL ptr in parport ops callbacks */
static DEFINE_SPINLOCK(release_lock);
#endif /* CONFIG_USB_SERIAL_MOS7715_PARPORT */
static const unsigned int dummy; /* for clarity in register access fns */
enum mos_regs {
MOS7720_THR, /* serial port regs */
MOS7720_RHR,
MOS7720_IER,
MOS7720_FCR,
MOS7720_ISR,
MOS7720_LCR,
MOS7720_MCR,
MOS7720_LSR,
MOS7720_MSR,
MOS7720_SPR,
MOS7720_DLL,
MOS7720_DLM,
MOS7720_DPR, /* parallel port regs */
MOS7720_DSR,
MOS7720_DCR,
MOS7720_ECR,
MOS7720_SP1_REG, /* device control regs */
MOS7720_SP2_REG, /* serial port 2 (7720 only) */
MOS7720_PP_REG,
MOS7720_SP_CONTROL_REG,
};
/*
* Return the correct value for the Windex field of the setup packet
* for a control endpoint message. See the 7715 datasheet.
*/
static inline __u16 get_reg_index(enum mos_regs reg)
{
static const __u16 mos7715_index_lookup_table[] = {
0x00, /* MOS7720_THR */
0x00, /* MOS7720_RHR */
0x01, /* MOS7720_IER */
0x02, /* MOS7720_FCR */
0x02, /* MOS7720_ISR */
0x03, /* MOS7720_LCR */
0x04, /* MOS7720_MCR */
0x05, /* MOS7720_LSR */
0x06, /* MOS7720_MSR */
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/spinlock.h`.
- Detected declarations: `struct moschip_port`, `struct mos7715_parport`, `struct divisor_table_entry`, `enum mos7715_pp_modes`, `enum mos_regs`, `function get_reg_index`, `function get_reg_value`, `function write_mos_reg`, `function read_mos_reg`, `function mos7715_change_mode`.
- 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.