一、首先看一下uart_register_driver();
int uart_register_driver(struct uart_driver *drv)
{
struct tty_driver *normal = NULL;
int i, retval;
BUG_ON(drv->state);
/*
* Maybe we should be using a slab cache for this, especially if
* we have a large number of ports to handle.
*/
drv->state = kzalloc(sizeof(struct uart_state) * drv->nr, GFP_KERNEL);
retval = -ENOMEM;
if (!drv->state)
goto out;
normal = alloc_tty_driver(drv->nr);
if (!normal)
goto out;
drv->tty_driver = normal;
normal->owner = drv->owner;
normal->driver_name = drv->driver_name;
normal->name = drv->dev_name;
normal->major = drv->major;
normal->minor_start = drv->minor;
normal->type = TTY_DRIVER_TYPE_SERIAL;
normal->subtype = SERIAL_TYPE_NORMAL;
normal->init_termios = tty_std_termios;
normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
normal->init_termios.c_ispeed = normal->init_termios.c_ospeed = 9600;
normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
normal->driver_state = drv;
tty_set_operations(normal, &uart_ops);
/*
* Initialise the UART state(s).
*/
for (i = 0; i < drv->nr; i++) {
struct uart_state *state = drv->state + i;
state->close_delay = 500; /* .5 seconds */
state->closing_wait = 30000; /* 30 seconds */
mutex_init(&state->mutex);
}
retval = tty_register_driver(normal);
out:
if (retval < 0) {
put_tty_driver(normal);
kfree(drv->state);
}
return retval;
}
这里的注册了drv->nr个设备节点,主设备号为drv->major,从设备号依次从drv->minor,
tty_set_operations(normal, &uart_ops),对tty_driver操作集赋值,然后设置每个设备状态,
最后调用tty_register_driver,注册为tty设备驱动。
二、 uart_port
调用uart_add_one_port();
uart_port是具体设备的代表
这里的注册了drv->nr个设备节点,主设备号为drv->major,从设备号依次从drv->minor,
tty_set_operations(normal, &uart_ops),对tty_driver操作集赋值,然后设置每个设备状态,
最后调用tty_register_driver,注册为tty设备驱动。
二、 uart_port
调用uart_add_one_port();
uart_port是具体设备的代表