drivers/tty/moxa.c
Source file repositories/reference/linux-study-clean/drivers/tty/moxa.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/moxa.c- Extension
.c- Size
- 55453 bytes
- Lines
- 2138
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/types.hlinux/mm.hlinux/ioport.hlinux/errno.hlinux/firmware.hlinux/signal.hlinux/sched.hlinux/timer.hlinux/interrupt.hlinux/tty.hlinux/tty_flip.hlinux/major.hlinux/string.hlinux/fcntl.hlinux/ptrace.hlinux/serial.hlinux/tty_driver.hlinux/delay.hlinux/pci.hlinux/init.hlinux/bitops.hlinux/slab.hlinux/ratelimit.hasm/io.h
Detected Declarations
struct moxa_portstruct moxa_portfunction moxa_wait_finishfunction moxafuncfunction moxafuncretfunction moxa_low_water_checkfunction moxa_break_ctlfunction moxa_check_fw_modelfunction moxa_check_fwfunction moxa_load_biosfunction moxa_load_320bfunction moxa_real_load_codefunction moxa_load_codefunction moxa_load_fwfunction moxa_init_boardfunction scoped_guardfunction moxa_board_deinitfunction scoped_guardfunction moxa_pci_probefunction moxa_pci_removefunction moxa_initfunction moxa_exitfunction moxa_shutdownfunction moxa_carrier_raisedfunction moxa_dtr_rtsfunction moxa_openfunction scoped_cond_guardfunction moxa_closefunction moxa_writefunction moxa_write_roomfunction moxa_flush_bufferfunction moxa_chars_in_bufferfunction moxa_tiocmgetfunction moxa_tiocmsetfunction moxa_set_termiosfunction moxa_stopfunction moxa_startfunction moxa_hangupfunction moxa_new_dcdstatefunction scoped_guardfunction moxa_poll_portfunction moxa_pollfunction moxa_set_tty_paramfunction MoxaPortFlushDatafunction MoxaPortEnablefunction MoxaPortDisablefunction MoxaPortSetBaudfunction MoxaPortSetTermio
Annotated Snippet
static struct pci_driver moxa_pci_driver = {
.name = "moxa",
.id_table = moxa_pcibrds,
.probe = moxa_pci_probe,
.remove = moxa_pci_remove
};
static int __init moxa_init(void)
{
int retval = 0;
moxaDriver = tty_alloc_driver(MAX_PORTS,
TTY_DRIVER_REAL_RAW |
TTY_DRIVER_DYNAMIC_DEV);
if (IS_ERR(moxaDriver))
return PTR_ERR(moxaDriver);
moxaDriver->name = "ttyMX";
moxaDriver->major = ttymajor;
moxaDriver->minor_start = 0;
moxaDriver->type = TTY_DRIVER_TYPE_SERIAL;
moxaDriver->subtype = SERIAL_TYPE_NORMAL;
moxaDriver->init_termios = tty_std_termios;
moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
moxaDriver->init_termios.c_ispeed = 9600;
moxaDriver->init_termios.c_ospeed = 9600;
tty_set_operations(moxaDriver, &moxa_ops);
if (tty_register_driver(moxaDriver)) {
printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
tty_driver_kref_put(moxaDriver);
return -1;
}
retval = pci_register_driver(&moxa_pci_driver);
if (retval)
printk(KERN_ERR "Can't register MOXA pci driver!\n");
return retval;
}
static void __exit moxa_exit(void)
{
pci_unregister_driver(&moxa_pci_driver);
timer_delete_sync(&moxaTimer);
tty_unregister_driver(moxaDriver);
tty_driver_kref_put(moxaDriver);
}
module_init(moxa_init);
module_exit(moxa_exit);
static void moxa_shutdown(struct tty_port *port)
{
struct moxa_port *ch = container_of(port, struct moxa_port, port);
MoxaPortDisable(ch);
MoxaPortFlushData(ch, 2);
}
static bool moxa_carrier_raised(struct tty_port *port)
{
struct moxa_port *ch = container_of(port, struct moxa_port, port);
guard(spinlock_irq)(&port->lock);
return ch->DCDState;
}
static void moxa_dtr_rts(struct tty_port *port, bool active)
{
struct moxa_port *ch = container_of(port, struct moxa_port, port);
MoxaPortLineCtrl(ch, active, active);
}
static int moxa_open(struct tty_struct *tty, struct file *filp)
{
struct moxa_board_conf *brd;
struct moxa_port *ch;
int port = tty->index;
scoped_cond_guard(mutex_intr, return -ERESTARTSYS, &moxa_openlock) {
brd = &moxa_boards[port / MAX_PORTS_PER_BOARD];
if (!brd->ready)
return -ENODEV;
if (port % MAX_PORTS_PER_BOARD >= brd->numPorts)
return -ENODEV;
Annotation
- Immediate include surface: `linux/module.h`, `linux/types.h`, `linux/mm.h`, `linux/ioport.h`, `linux/errno.h`, `linux/firmware.h`, `linux/signal.h`, `linux/sched.h`.
- Detected declarations: `struct moxa_port`, `struct moxa_port`, `function moxa_wait_finish`, `function moxafunc`, `function moxafuncret`, `function moxa_low_water_check`, `function moxa_break_ctl`, `function moxa_check_fw_model`, `function moxa_check_fw`, `function moxa_load_bios`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: pattern 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.