S3C2440 rtc 平台设备驱动 卸载问题 oops

发布时间: 2024-06-13
来源: 电子工程世界

(1)rtc平台设备驱动源码如下,gzliu_2440_rtc.c:

相关的函数及结构体参见:http://www.linuxidc.com/Linux/2011-08/41676p2.htm

  1. #include    

  2. #include    

  3. #include    

  4. #include    

  5. #include    

  6. #include    

  7. #include    

  8. #include    

  9. #include    

  10. #include    

  11. #include    

  12. #include    

  13. #include    

  14. #include    

  15. #include    

  16. #include    

  17. // 包含RTC_AF的声明   

  18. #include    

  19.   

  20. #undef S3C24XX_VA_RTC   

  21. #define S3C24XX_VA_RTC s3c2440_rtc_base   

  22.   

  23. static struct resource *s3c2440_rtc_mem = NULL;  

  24.   

  25. static void __iomem *s3c2440_rtc_base = NULL;  

  26. static int s3c2440_rtc_alarm_irq = NO_IRQ;  

  27. static int s3c2440_rtc_tick_irq  = NO_IRQ;  

  28. static int s3c2440_rtc_freq    = 1;                     // rtc tick中断频率   

  29.   

  30. static DEFINE_SPINLOCK(s3c2440_rtc_pie_lock);  

  31.   

  32. static int s3c2440_rtc_proc(char *buf)  

  33. {  

  34.     unsigned int rtcalm = readb(S3C2410_RTCALM);  

  35.     unsigned int ticnt = readb (S3C2410_TICNT);  

  36.     char *p = buf;  

  37. printk("@@@@@@@@@@@@@@@@@@@@@@ngzliu s3c2440_rtc_proc()n@@@@@@@@@@@@@@@@@@@@@@@@n");  

  38.   

  39.     p += sprintf(p, "alarm_IRQt: %sn", (rtcalm & S3C2410_RTCALM_ALMEN) ? "yes" : "no" );  

  40.     p += sprintf(p, "periodic_IRQt: %sn", (ticnt & S3C2410_TICNT_ENABLE) ? "yes" : "no" );  

  41.     p += sprintf(p, "periodic_freqt: %dn", s3c2440_rtc_freq);  

  42.   

  43.     return p - buf;  

  44. }  

  45.   

  46. static int s3c2440_rtc_getalarm(struct rtc_wkalrm *alrm)  

  47. {  

  48.     struct rtc_time *alm_tm = &alrm->time;  

  49.     unsigned int alm_en;  

  50. printk("@@@@@@@@@@@@@@@@@@@@@@ngzliu s3c2440_rtc_getalarm()n@@@@@@@@@@@@@@@@@@@@@@@@n");  

  51.   

  52.     alm_tm->tm_sec  = readb(S3C2410_ALMSEC);  

  53.     alm_tm->tm_min  = readb(S3C2410_ALMMIN);  

  54.     alm_tm->tm_hour = readb(S3C2410_ALMHOUR);  

  55.     alm_tm->tm_mon  = readb(S3C2410_ALMMON);  

  56.     alm_tm->tm_mday = readb(S3C2410_ALMDATE);  

  57.     alm_tm->tm_year = readb(S3C2410_ALMYEAR);  

  58.   

  59.     alm_en = readb(S3C2410_RTCALM);  

  60.   

  61.     pr_debug("read alarm %02x %02x.%02x.%02x %02x/%02x/%02xn", alm_en, alm_tm->tm_year, alm_tm->tm_mon, alm_tm->tm_mday, alm_tm->tm_hour, alm_tm->tm_min, alm_tm->tm_sec);  

  62.   

  63.   

  64.     /* decode the alarm enable field */  

  65.   

  66.     if (alm_en & S3C2410_RTCALM_SECEN)  

  67.     {  

  68.         BCD_TO_BIN(alm_tm->tm_sec);  

  69.     }  

  70.     else  

  71.     {  

  72.         alm_tm->tm_sec = 0xff;  

  73.     }  

  74.   

  75.     if (alm_en & S3C2410_RTCALM_MINEN)  

  76.     {  

  77.         BCD_TO_BIN(alm_tm->tm_min);  

  78.     }  

  79.     else  

  80.     {  

  81.         alm_tm->tm_min = 0xff;  

  82.     }  

  83.   

  84.     if (alm_en & S3C2410_RTCALM_HOUREN)  

  85.     {  

  86.         BCD_TO_BIN(alm_tm->tm_hour);  

  87.     }  

  88.     else  

  89.     {  

  90.         alm_tm->tm_hour = 0xff;  

  91.     }  

  92.   

  93.     if (alm_en & S3C2410_RTCALM_DAYEN)  

  94.     {  

  95.         BCD_TO_BIN(alm_tm->tm_mday);  

  96.     }  

  97.     else  

  98.     {  

  99.         alm_tm->tm_mday = 0xff;  

  100.     }  

  101.   

  102.     if (alm_en & S3C2410_RTCALM_MONEN)  

  103.     {  

  104.         BCD_TO_BIN(alm_tm->tm_mon);  

  105.         alm_tm->tm_mon -= 1;  

  106.     }  

  107.     else  

  108.     {  

  109.         alm_tm->tm_mon = 0xff;  

  110.     }  

  111.   

  112.     if (alm_en & S3C2410_RTCALM_YEAREN)  

  113.     {  

  114.         BCD_TO_BIN(alm_tm->tm_year);  

  115.     }  

  116.     else  

  117.     {  

  118.         alm_tm->tm_year = 0xffff;  

  119.     }  

  120.   

  121.     /* todo - set alrm->enabled ? */  

  122.   

  123.     return 0;  

  124.       

  125. }/* s3c2440_rtc_getalarm(struct rtc_wkalrm *alrm) */  

  126.   

  127. static int s3c2440_rtc_setalarm(struct rtc_wkalrm *alrm)  

  128. {  

  129.     struct rtc_time *tm = &alrm->time;  

  130.     unsigned int alrm_en;  

  131. printk("@@@@@@@@@@@@@@@@@@@@@@ngzliu s3c2440_rtc_setalarm()n@@@@@@@@@@@@@@@@@@@@@@@@n");  

  132.   

  133.     pr_debug("s3c2410_rtc_setalarm: %d, %02x/%02x/%02x %02x.%02x.%02xn", alrm->enabled, tm->tm_mday & 0xff, tm->tm_mon & 0xff, tm->tm_year & 0xff, tm->tm_hour & 0xff, tm->tm_min & 0xff, tm->tm_sec);  

  134.   

  135.     if (alrm->enabled || 1)  

  136.     {  

  137.         alrm_en = readb(S3C2410_RTCALM) & S3C2410_RTCALM_ALMEN;  

  138.         writeb(0x00, S3C2410_RTCALM);  

  139.   

  140.         if (tm->tm_sec < 60 && tm->tm_sec >= 0)  

  141.         {  

  142.             alrm_en |= S3C2410_RTCALM_SECEN;  

  143.             writeb(BIN2BCD(tm->tm_sec), S3C2410_ALMSEC);  

  144.         }  

  145.   

  146.         if (tm->tm_min < 60 && tm->tm_min >= 0)  

  147.         {  

  148.             alrm_en |= S3C2410_RTCALM_MINEN;  

  149.             writeb(BIN2BCD(tm->tm_min), S3C2410_ALMMIN);  

  150.         }  

  151.   

  152.         if (tm->tm_hour < 24 && tm->tm_hour >= 0)  

文章来源于: 电子工程世界 原文链接

本站所有转载文章系出于传递更多信息之目的,且明确注明来源,不希望被转载的媒体或个人可与我们联系,我们将立即进行删除处理。