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.

Dependency Surface

Detected Declarations

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

Implementation Notes