当前位置:嗨网首页>书籍在线阅读

17-S3C6410串口UART驱动

  
选择背景色: 黄橙 洋红 淡粉 水蓝 草绿 白色 选择字体: 宋体 黑体 微软雅黑 楷体 选择字体大小: 恢复默认

14.8.2 S3C6410串口UART驱动

在samsung.c的模块加载和卸载函数中,通过uart_register_driver()、uart_unregister_driver()注册和注销了s3c24xx_uart_drv,如代码清单14.25。

代码清单14.25 S3C6410串口驱动核心模块加载与卸载函数

1 static struct uart_driver s3c24xx_uart_drv = {

2 .owner = THIS_MODULE,

3 .dev_name = "s3c2410_serial",

4 .nr = 3,

5 .cons = S3C24XX_SERIAL_CONSOLE,

6 .driver_name = S3C24XX_SERIAL_NAME,

7 .major = S3C24XX_SERIAL_MAJOR,

8 .minor = S3C24XX_SERIAL_MINOR,

9 };

10

11 static int _ _init s3c24xx_serial_modinit(void)

12 {

13 int ret;

14

15 ret = uart_register_driver(&s3c24xx_uart_drv);

16 if (ret < 0) {

17 printk(KERN_ERR "failed to register UART driver\n");

18 return -1;

19 }

20

21 return 0;

22 }

23

24 static void _ _exit s3c24xx_serial_modexit(void)

25 {

26 uart_unregister_driver(&s3c24xx_uart_drv);

27 }

28

29 module_init(s3c24xx_serial_modinit);

30 module_exit(s3c24xx_serial_modexit);

s3c6400.c是一个platform驱动,在其probe()成员函数s3c6400_serial_probe()中,会调用samsung.c中的s3c24xx_serial_probe(),而该函数会添加uart_port:

int s3c24xx_serial_probe(struct platform_device *dev,

struct s3c24xx_uart_info *info)

{

...

uart_add_one_port(&s3c24xx_uart_drv, &ourport->port);

...

}

相反的,在s3c6400.c这一platform驱动的remove()成员函数s3c24xx_serial_remove()中,会调用uart_remove_one_port()去除uart_port。

注意被添加的uart_port的uart_ops成员定义在samsung.c文件中,如代码清单12.26。

代码清单12.26 S3C6410串口驱动的uart_ops

1 static struct uart_ops s3c24xx_serial_ops = {

2 .pm = s3c24xx_serial_pm,

3 .tx_empty = s3c24xx_serial_tx_empty,

4 .get_mctrl = s3c24xx_serial_get_mctrl,

5 .set_mctrl = s3c24xx_serial_set_mctrl,

6 .stop_tx = s3c24xx_serial_stop_tx,

7 .start_tx = s3c24xx_serial_start_tx,

8 .stop_rx = s3c24xx_serial_stop_rx,

9 .enable_ms = s3c24xx_serial_enable_ms,

10 .break_ctl = s3c24xx_serial_break_ctl,

11 .startup = s3c24xx_serial_startup,

12 .shutdown = s3c24xx_serial_shutdown,

13 .set_termios = s3c24xx_serial_set_termios,

14 .type = s3c24xx_serial_type,

15 .release_port = s3c24xx_serial_release_port,

16 .request_port = s3c24xx_serial_request_port,

17 .config_port = s3c24xx_serial_config_port,

18 .verify_port = s3c24xx_serial_verify_port,

19 #if defined(CONFIG_S5P_UART_DMA_EN)

20 .flush_buffer = s3c24xx_flush_buffer,

21 #endif

22 };