回忆一下上文,s3c2440串口底层驱动环绕三个数据结构打开:
UART特定的驱动程序结构界说:struct uart_driver s3c24xx_uart_drv;
UART端口结构界说: struct uart_port s3c24xx_serial_ops;
UART相关操作函数结构界说: struct uart_ops s3c24xx_serial_ops;
完成了这三个数据结构体,基本完成了驱动操作函数的完成,紧接着需要对串口设备及设备驱动进行初始化,首先是模块初始化module_init(s3c24xx_serial_modinit):
- staticint__inits3c24xx_serial_modinit(void)
- {
- intret;
- ret=uart_register_driver(&s3c24xx_uart_drv);//注册uart驱动,在serial_core.c中完成
- if(ret<0){
- printk(KERN_ERR”failedtoregisterUARTdriver\n”);
- return-1;
- }
- return0;
- }
uart_register_driver在串口中心及TTY层间进行相关注册:
- intuart_register_driver(structuart_driver*drv)
- {
structtty_driver*normal=NULL; … - 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);
- ….
- retval=tty_register_driver(normal);//tty驱动注册
- out:
- if(retval<0){
- put_tty_driver(normal);
- kfree(drv->state);
- }
- returnretval;
- }
接着进行总线驱动platform_driver_register:
- ints3c24xx_serial_init(structplatform_driver*drv,
- structs3c24xx_uart_info*info)
- {
- #ifdefCONFIG_PM
- drv->suspend=s3c24xx_serial_suspend;
- drv->resume=s3c24xx_serial_resume;
- #endif
- returnplatform_driver_register(drv);//
- }
其间s3c24xx_serial_init为__init段,模块加载时初始化:
- staticint__inits3c2440_serial_init(void)
- {
- returns3c24xx_serial_init(&s3c2440_serial_drv,&s3c2440_uart_inf);//
- }
platfrom_driver_register()中调用driver_register()
- intplatform_driver_register(structplatform_driver*drv)
- {
- drv->driver.bus=&platform_bus_type;//
- if(drv->probe)
- drv->driver.probe=platform_drv_probe;
- if(drv->remove)
- drv->driver.remove=platform_drv_remove;
- if(drv->shutdown)
- drv->driver.shutdown=platform_drv_shutdown;
- if(drv->suspend)
- drv->driver.suspend=platform_drv_suspend;
- if(drv->resume)
- drv->driver.resume=platform_drv_resume;
- returndriver_register(&drv->driver);//
- }
由于串口设备在体系是一种platform_device所以是一种总线驱动类型,总线设备驱动注册platform_driver_register()之后,串口设备即可和相应的驱动相关起来了,这样就完成了串口设备与串口驱动的注册进程。
下一篇讲进一步结合源码剖析。