手机版
你好,游客 登录 注册
背景:
阅读新闻

ARM Linux S3C2440 之UART分析

[日期:2012-02-22] 来源:Linux社区  作者:yyplc [字体:大 中 小]

从上面四篇介绍文章中,已经清楚了串口设备与串口驱动实现的各层次关系流程。是一种从上而下的关系,从第二篇的层次流程图中可以看出。之前说过串口设备是一种platform device,下面看看串口作为platform device的实现细节。

串口的硬件平台实现smdk2440_map_io()初始化入口:

[cpp]
  1. static void __init smdk2440_map_io(void)  
  2. {  
  3.        s3c24xx_init_io(smdk2440_iodesc,ARRAY_SIZE(smdk2440_iodesc));  
  4.        s3c24xx_init_clocks(12000000);  
  5.        s3c24xx_init_uarts(smdk2440_uartcfgs,ARRAY_SIZE(smdk2440_uartcfgs));  //串口初始化   
  6. }  

s3c24xx_init_uarts()初始化串口, 主要完成platform device结构相关参数的赋值,如IO,中断,以及platform device私有数据赋值等。

串口platform_device结构:

[cpp]
  1. static struct platform_device s3c24xx_uart_device0= {  
  2.        .id           = 0,   // ID号   
  3. };  
  4.    
  5. static struct platform_devices3c24xx_uart_device1 = {  
  6.        .id           = 1,  
  7. };  
  8.    
  9. static struct platform_devices3c24xx_uart_device2 = {  
  10.        .id           = 2,  
  11. };  

要完成platform_device参数初始化,主要涉及到一下数据结构:

串口配置数据结构:

[cpp]
  1. static struct s3c2410_uartcfgtq2440_uartcfgs[] __initdata = {  
  2.        [0]= {  
  3.               .hwport        =0,  
  4.               .flags          = 0,  
  5.               .ucon          = 0x3c5,  // rx,tx采用中断方式   
  6.               .ulcon         = 0x03,   //数据长度设置为8-bits   
  7.               .ufcon         = 0x51,   //开启FIFO,并设置rx,tx触发字节数   
  8.        },  
  9.        [1]= {  
  10.               .hwport        =1,  
  11.               .flags          = 0,  
  12.               .ucon          = 0x3c5,   
  13.               .ulcon         = 0x03,              
  14. .ufcon          = 0x51,    
  15.        },  
  16.        [2]= {  
  17.               .hwport        =2,  
  18.               .flags          = 0,  
  19.               .ucon          = 0x3c5,  
  20.               .ulcon         = 0x03,  
  21.               .ufcon         = 0x51,  
  22.        }  
  23. };  

串口资源:

[cpp]
  1. static struct resources3c2410_uart0_resource[] = {  
  2.        [0]= {  
  3.               .start= S3C2410_PA_UART0,  
  4.               .end   = S3C2410_PA_UART0 + 0x3fff,    
  5.               .flags= IORESOURCE_MEM,         
  6.        },  
  7.        [1]= {  
  8.               .start= IRQ_S3CUART_RX0,  
  9.               .end   = IRQ_S3CUART_ERR0,  
  10.               .flags= IORESOURCE_IRQ,  
  11.        }  
  12. };  
  13.    
  14. struct s3c24xx_uart_resourcess3c2410_uart_resources[] __initdata = {  
  15.        [0]= {  
  16.               .resources      = s3c2410_uart0_resource,  
  17.               .nr_resources  = ARRAY_SIZE(s3c2410_uart0_resource),  
  18.        },  
  19.        [1]= {  
  20.               .resources      = s3c2410_uart1_resource,  
  21.               .nr_resources  = ARRAY_SIZE(s3c2410_uart1_resource),  
  22.        },  
  23.        [2]= {  
  24.               .resources      = s3c2410_uart2_resource,  
  25.               .nr_resources  = ARRAY_SIZE(s3c2410_uart2_resource),  
  26.        },  
  27.        [3]= {  
  28.               .resources      = s3c2410_uart3_resource,  
  29.               .nr_resources  = ARRAY_SIZE(s3c2410_uart3_resource),  
  30.        },  
  31. };  

最后通过函数s3c24xx_init_uartdevs()完成 串口platform_device的初始化:

[cpp]
  1. void __init s3c24xx_init_uartdevs(char*name,  
  2.                               struct s3c24xx_uart_resources *res,  
  3.                               struct s3c2410_uartcfg *cfg, int no)  
  4. {//name = s3c2440-uart, res =s3c2410_uart_resources[], cfg = tq2440_uartcfgs, no = 3   
  5.        structplatform_device *platdev;  
  6.        structs3c2410_uartcfg *cfgptr = uart_cfgs;  
  7.        structs3c24xx_uart_resources *resp;  
  8.        intuart;  
  9.    
  10.        memcpy(cfgptr,cfg, sizeof(struct s3c2410_uartcfg) * no);  
  11.    
  12.        for(uart = 0; uart < no; uart++, cfg++, cfgptr++) {  
  13.               platdev= s3c24xx_uart_src[cfgptr->hwport];  //platdev = s3c24xx_uart_device0   
  14.    
  15.               resp= res + cfgptr->hwport;  //resp =s3c2410_uart_resources[] + tq2440_uartcfgs.hwport   
  16.    
  17.               s3c24xx_uart_devs[uart]= platdev; //   
  18.    
  19.               platdev->name= name;  
  20.               platdev->resource= resp->resources;  
  21.               platdev->num_resources= resp->nr_resources;  
  22.    
  23.               platdev->dev.platform_data= cfgptr;//plat_form_data = cfgptr = tq2440_uartcfgs   
  24.        }  
  25.    
  26.        nr_uarts= no;  
  27. }  

最终在platform_add_device()中完成注册

[cpp]
  1. platform_add_devices(s3c24xx_uart_devs,nr_uarts);  
  2. int platform_add_devices(structplatform_device **devs, int num)  
  3. {  
  4.        inti, ret = 0;  
  5.    
  6.        for(i = 0; i < num; i++) {  
  7.               ret= platform_device_register(devs[i]);  
  8.               if(ret) {  
  9.                      while(--i >= 0)  
  10.                             platform_device_unregister(devs[i]);  
  11.                      break;  
  12.               }  
  13.        }  
  14.    
  15.        return ret;  
  16. }  
linux
相关资讯       arm  S3C2440 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款