ARM-Linux驱动--RTC(实时时钟)驱动分析
时间:11-20
来源:互联网
点击:
- rtc_tm->tm_min=bcd2bin(rtc_tm->rtc_tm->tm_min=bcd2bin(rtc_tm->tm_min);
- rtc_tm->tm_hour=bcd2bin(rtc_tm->tm_hour);
- rtc_tm->tm_mday=bcd2bin(rtc_tm->tm_mday);
- rtc_tm->tm_mon=bcd2bin(rtc_tm->tm_mon);
- rtc_tm->tm_year=bcd2bin(rtc_tm->tm_year);
- rtc_tm->tm_year+=100;
- rtc_tm->tm_mon-=1;
- return0;
- }
- staticints3c_rtc_settime(structdevice*dev,structrtc_time*tm)
- {
- void__iomem*base=s3c_rtc_base;
- intyear=tm->tm_year-100;
- pr_debug("settime%02d.%02d.%02d%02d/%02d/%02d\n",
- tm->tm_year,tm->tm_mon,tm->tm_mday,
- tm->tm_hour,tm->tm_min,tm->tm_sec);
- /*wegetaroundy2kbysimplynotsupportingit*/
- if(year<0||year>=100){
- dev_err(dev,"rtconlysupports100years\n");
- return-EINVAL;
- }
- 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;
- }
- #include
- #include
- #include
- #include
- #include
- #include
interrupt.h> - #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- staticstructresource*s3c_rtc_mem;
- staticvoid__iomem*s3c_rtc_base;
- staticints3c_rtc_tickno=NO_IRQ;
- staticDEFINE_SPINLOCK(s3c_rtc_pie_lock);
- staticirqreturn_ts3c_rtc_tickirq(intirq,void*id)
- {
- structrtc_device*rdev=id;
- rtc_update_irq(rdev,1,RTC_PF|RTC_IRQF);
- returnIRQ_HANDLED;
- }
- /*Updatecontrolregisters*/
- staticvoids3c_rtc_setaie(intto)
- {
- unsignedinttmp;
- pr_debug("%s:aie=%d\n",__func__,to);
- tmp=readb(s3c_rtc_base+S3C2410_RTCALM)&~S3C2410_RTCALM_ALMEN;
- if(to)
- tmp|=S3C2410_RTCALM_ALMEN;
- writeb(tmp,s3c_rtc_base+S3C2410_RTCALM);
- }
- staticints3c_rtc_setpie(structdevice*dev,intenabled)
- {
- unsignedinttmp;
- pr_debug("%s:pie=%d\n",__func__,enabled);
- spin_lock_irq(&s3c_rtc_pie_lock);
- tmp=readb(s3c_rtc_base+S3C2410_TICNT)&~S3C2410_TICNT_ENABLE;
- if(enabled)
- tmp|=S3C2410_TICNT_ENABLE;
- writeb(tmp,s3c_rtc_base+S3C2410_TICNT);
- spin_unlock_irq(&s3c_rtc_pie_lock);
- return0;
- }
- staticints3c_rtc_setfreq(structdevice*dev,intfreq)
- {
- unsignedinttmp;
- spin_lock_irq(&s3c_rtc_pie_lock);
- tmp=readb(s3c_rtc_base+S3C2410_TICNT)&S3C2410_TICNT_ENABLE;
- tmp|=(128/freq)-1;
- writeb(tmp,s3c_rtc_base+S3C2410_TICNT);
- spin_unlock_irq(&s3c_rtc_pie_lock);
- return0;
- }
- /*Timeread/write*/
- staticints3c_rtc_gettime(structdevice*dev,structrtc_time*rtc_tm)
- {
- unsignedinthave_retried=0;
- void__iomem*base=s3c_rtc_base;
- retry_get_time:
- rtc_tm->tm_min=readb(base+S3C2410_RTCMIN);
- rtc_tm->tm_hour=readb(base+S3C2410_RTCHOUR);
- rtc_tm->tm_mday=readb(base+S3C2410_RTCDATE);
- rtc_tm->tm_mon=readb(base+S3C2410_RTCMON);
- rtc_tm->tm_year=readb(base+S3C2410_RTCYEAR);
- rtc_tm->tm_sec=readb(base+S3C2410_RTCSEC);
- /*theonlywaytoworkoutwetherthesystemwasmid-update
- *whenwereaditistocheckthesecondcounter,andifit
- *iszero,thenwere-trytheentireread
- */
- if(rtc_tm->tm_sec==0&&!have_retried){
- have_retried=1;
- gotoretry_get_time;
- }
- pr_debug("readtime%02x.%02x.%02x%02x/%02x/%02x\n",
- rtc_tm->tm_year,rtc_tm->tm_mon,rtc_tm->tm_mday,
- rtc_tm->tm_hour,rtc_tm->tm_min,rtc_tm->tm_sec);
- rtc_tm->tm_sec=bcd2bin(rtc_tm->tm_sec);
- rtc_tm->tm_min=bcd2bin(rtc_tm->tm_min);
- rtc_tm->tm_hour=bcd2bin(rtc_tm->tm_hour);
- rtc_tm->tm_mday=bcd2bin(rtc_tm->tm_mday);
- rtc_tm->tm_mon=bcd2bin(rtc_tm->tm_mon);
- rtc_tm->tm_year=bcd2bin(rtc_tm->tm_year);
- rtc_tm->tm_year+=100;
- rtc_tm->tm_mon-=1;
- return0;
- }
- staticints3c_rtc_settime(structdevice*dev,structrtc_time*tm)
- {
- void__iomem*base=s3c_rtc_base;
- intyear=tm->tm_year-100;
- pr_debug("settime%02d.%02d.%02d%02d/%02d/%02d\n",
- tm->tm_year,tm->tm_mon,tm->tm_mday,
- tm->tm_hour,tm->tm_min,tm->tm_sec);
- /*wegetaroundy2kbysimplynotsupportingit*/
- if(year<0||year>=100){
- dev_err(dev,"rtconlysupports100years\n");
- return-EINVAL;
- }
- writeb(bin2bcd(tm->writeb(bin2bcd(tm->tm_sec)
ARMLinux驱动RTC实时时钟驱动分 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)