ARM-Linux s3c2440 之UART分析(五)
串口的硬件平臺實現(xiàn)smdk2440_map_io()初始化入口:
本文引用地址:http://www.ex-cimer.com/article/201611/318135.htm- staticvoid__initsmdk2440_map_io(void)
- {
- s3c24xx_init_io(smdk2440_iodesc,ARRAY_SIZE(smdk2440_iodesc));
- s3c24xx_init_clocks(12000000);
- s3c24xx_init_uarts(smdk2440_uartcfgs,ARRAY_SIZE(smdk2440_uartcfgs));//串口初始化
- }
s3c24xx_init_uarts()初始化串口, 主要完成platform device結(jié)構相關參數(shù)的賦值,如IO,中斷,以及platform device私有數(shù)據(jù)賦值等。
串口platform_device結(jié)構:
- staticstructplatform_devices3c24xx_uart_device0={
- .id=0,//ID號
- };
- staticstructplatform_devices3c24xx_uart_device1={
- .id=1,
- };
- staticstructplatform_devices3c24xx_uart_device2={
- .id=2,
- };
要完成platform_device參數(shù)初始化,主要涉及到一下數(shù)據(jù)結(jié)構:
串口配置數(shù)據(jù)結(jié)構:
- staticstructs3c2410_uartcfgtq2440_uartcfgs[]__initdata={
- [0]={
- .hwport=0,
- .flags=0,
- .ucon=0x3c5,//rx,tx采用中斷方式
- .ulcon=0x03,//數(shù)據(jù)長度設置為8-bits
- .ufcon=0x51,//開啟FIFO,并設置rx,tx觸發(fā)字節(jié)數(shù)
- },
- [1]={
- .hwport=1,
- .flags=0,
- .ucon=0x3c5,
- .ulcon=0x03,
- .ufcon=0x51,
- },
- [2]={
- .hwport=2,
- .flags=0,
- .ucon=0x3c5,
- .ulcon=0x03,
- .ufcon=0x51,
- }
- };
串口資源:
- staticstructresources3c2410_uart0_resource[]={
- [0]={
- .start=S3C2410_PA_UART0,
- .end=S3C2410_PA_UART0+0x3fff,
- .flags=IORESOURCE_MEM,
- },
- [1]={
- .start=IRQ_S3CUART_RX0,
- .end=IRQ_S3CUART_ERR0,
- .flags=IORESOURCE_IRQ,
- }
- };
- structs3c24xx_uart_resourcess3c2410_uart_resources[]__initdata={
- [0]={
- .resources=s3c2410_uart0_resource,
- .nr_resources=ARRAY_SIZE(s3c2410_uart0_resource),
- },
- [1]={
- .resources=s3c2410_uart1_resource,
- .nr_resources=ARRAY_SIZE(s3c2410_uart1_resource),
- },
- [2]={
- .resources=s3c2410_uart2_resource,
- .nr_resources=ARRAY_SIZE(s3c2410_uart2_resource),
- },
- [3]={
- .resources=s3c2410_uart3_resource,
- .nr_resources=ARRAY_SIZE(s3c2410_uart3_resource),
- },
- };
最后通過函數(shù)s3c24xx_init_uartdevs()完成 串口platform_device的初始化:
- void__inits3c24xx_init_uartdevs(char*name,
- structs3c24xx_uart_resources*res,
- structs3c2410_uartcfg*cfg,intno)
- {//name=s3c2440-uart,res=s3c2410_uart_resources[],cfg=tq2440_uartcfgs,no=3
- structplatform_device*platdev;
- structs3c2410_uartcfg*cfgptr=uart_cfgs;
- structs3c24xx_uart_resources*resp;
- intuart;
- memcpy(cfgptr,cfg,sizeof(structs3c2410_uartcfg)*no);
- for(uart=0;uart
- platdev=s3c24xx_uart_src[cfgptr->hwport];//platdev=s3c24xx_uart_device0
- resp=res+cfgptr->hwport;//resp=s3c2410_uart_resources[]+tq2440_uartcfgs.hwport
- s3c24xx_uart_devs[uart]=platdev;//
- platdev->name=name;
- platdev->resource=resp->resources;
- platdev->num_resources=resp->nr_resources;
- platdev->dev.platform_data=cfgptr;//plat_form_data=cfgptr=tq2440_uartcfgs
- }
- nr_uarts=no;
- }
最終在platform_add_device()中完成注冊
- platform_add_devices(s3c24xx_uart_devs,nr_uarts);
- intplatform_add_devices(structplatform_device**devs,intnum)
- {
- inti,ret=0;
- for(i=0;i
- ret=platform_device_register(devs[i]);
- if(ret){
- while(--i>=0)
- platform_device_unregister(devs[i]);
- break;
- }
- }
- returnret;
- }
評論