ARM-Linux驱动--RTC(实时时钟)驱动分析
时间:11-20
来源:互联网
点击:
- writeb(bin2bcd(tm->writeb(bin2bcd(tm->tm_sec),base+S3C2410_RTCSEC);
- writeb(bin2bcd(tm->tm_min),base+S3C2410_RTCMIN);
- writeb(bin2bcd(tm->tm_hour),base+S3C2410_RTCHOUR);
- writeb(bin2bcd(tm->tm_mday),base+S3C2410_RTCDATE);
- writeb(bin2bcd(tm->tm_mon+1),base+S3C2410_RTCMON);
- writeb(bin2bcd(year),base+S3C2410_RTCYEAR);
- return0;
- }
- staticints3c_rtc_open(structdevice*dev)
- {
- structplatform_device*pdev=to_platform_device(dev);
- structrtc_device*rtc_dev=platform_get_drvdata(pdev);
- intret;
- ret=request_irq(s3c_rtc_tickno,s3c_rtc_tickirq,
- IRQF_DISABLED,"s3c2410-rtctick",rtc_dev);
- if(ret){
- dev_err(dev,"IRQ%derror%d\n",s3c_rtc_tickno,ret);
- gototick_err;
- }
- tick_err:
- returnret;
- }
- staticvoids3c_rtc_release(structdevice*dev)
- {
- structplatform_device*pdev=to_platform_device(dev);
- structrtc_device*rtc_dev=platform_get_drvdata(pdev);
- /*donotclearAIEhere,itmaybeneededforwake*/
- s3c_rtc_setpie(dev,0);
- free_irq(s3c_rtc_tickno,rtc_dev);
- }
- staticconststructrtc_class_opss3c_rtcops={
- .open=s3c_rtc_open,
- .release=s3c_rtc_release,
- .read_time=s3c_rtc_gettime,
- .set_time=s3c_rtc_settime,
- .irq_set_freq=s3c_rtc_setfreq,
- .irq_set_state=s3c_rtc_setpie,
- };
- staticvoids3c_rtc_enable(structplatform_device*pdev,inten)
- {
- void__iomem*base=s3c_rtc_base;
- unsignedinttmp;
- if(s3c_rtc_base==NULL)
- return;
- if(!en){
- tmp=readb(base+S3C2410_RTCCON);
- writeb(tmp&~S3C2410_RTCCON_RTCEN,base+S3C2410_RTCCON);
- tmp=readb(base+S3C2410_TICNT);
- writeb(tmp&~S3C2410_TICNT_ENABLE,base+S3C2410_TICNT);
- }else{
- /*re-enablethedevice,andcheckitisok*/
- if((readb(base+S3C2410_RTCCON)&S3C2410_RTCCON_RTCEN)==0){
- dev_info(&pdev->dev,"rtcdisabled,re-enabling\n");
- tmp=readb(base+S3C2410_RTCCON);
- writeb(tmp|S3C2410_RTCCON_RTCEN,base+S3C2410_RTCCON);
- }
- if((readb(base+S3C2410_RTCCON)&S3C2410_RTCCON_CNTSEL)){
- dev_info(&pdev->dev,"removingRTCCON_CNTSEL\n");
- tmp=readb(base+S3C2410_RTCCON);
- writeb(tmp&~S3C2410_RTCCON_CNTSEL,base+S3C2410_RTCCON);
- }
- if((readb(base+S3C2410_RTCCON)&S3C2410_RTCCON_CLKRST)){
- dev_info(&pdev->dev,"removingRTCCON_CLKRST\n");
- tmp=readb(base+S3C2410_RTCCON);
- writeb(tmp&~S3C2410_RTCCON_CLKRST,base+S3C2410_RTCCON);
- }
- }
- }
- staticint__devexits3c_rtc_remove(structplatform_device*dev)
- {
- structrtc_device*rtc=platform_get_drvdata(dev);
- platform_set_drvdata(dev,NULL);
- rtc_device_unregister(rtc);
- s3c_rtc_setpie(&dev->dev,0);
- s3c_rtc_setaie(0);
- iounmap(s3c_rtc_base);
- release_resource(s3c_rtc_mem);
- kfree(s3c_rtc_mem);
- return0;
- }
- staticint__devinits3c_rtc_probe(structplatform_device*pdev)
- {
- structrtc_device*rtc;
- structresource*res;
- intret;
- pr_debug("%s:probe=%p\n",__func__,pdev);
- /*findtheIRQs*/
- s3c_rtc_tickno=platform_get_irq(pdev,1);
- if(s3c_rtc_tickno<0){
- dev_err(&pdev->dev,"noirqforrtctick\n");
- return-ENOENT;
- }
- /*getthememoryregion*/
- res=platform_get_resource(pdev,IORESOURCE_MEM,0);
- if(res==NULL){
- dev_err(&pdev->dev,"failedtogetmemoryregionresource\n");
- return-ENOENT;
- }
- s3c_rtc_mem=request_mem_region(res->start,
- res->end-res->start+1,
- pdev->name);
- if(s3c_rtc_mem==NULL){
- dev_err(&pdev->dev,"failedtoreservememoryregion\n");
- ret=-ENOENT;
- gotoerr_nores;
- }
- s3c_rtc_base=ioremap(res->start,res->end-res->start+1);
- if(s3c_rtc_base==NULL){
- dev_err(&pdev->dev,"failedioremap()\n");
- ret=-EINVAL;
- gotoerr_nomap;
- }
- /*checktoseeifeverythingissetupcorrectly*/
- s3c_rtc_enable(pdev,1);
- pr_debug("s3c2410_rtc:RTCCON=%02x\n",
- readb(s3c_rtc_base+S3C2410_RTCCON));
- s3c_rtc_setfreq(&pdev->dev,1);
- /*registerRTCandexit*/
- rtc=rtc_device_register("s3c",&pdev->dev,&s3c_rtcops,
- THIS_MODULE);
- if(IS_ERR(rtc)){
- dev_err(&pdev->dev,"cannotattachrtc\n");
- ret=PTR_ERR(rtc);
- gotoerr_nortc;
- }
- rtc->max_user_freq=128;
- platform_set_drvdata(pdev,rtc);
- return0;
- err_nortc:
- s3c_rtc_enable(pdev,0);
- iounmap(s3c_rtc_base);
- err_nomap:
- release_resource(s3c_rtc_mem);
- err_nores:
- returnret;
- }
- staticstructplatform_drivers3c2410_rtc
ARMLinux驱动RTC实时时钟驱动分 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)