**************************************************************
*Added support for apmsleep by supporting legacy alarm calls in the rtc driver
*Removed several debug statements
*Author: ngustavson
*Date: 2007-11-07 12:06:12 -0600 (Wed, 07 Nov 2007)
*New Revision: 412
**************************************************************
diff -uprN linux-2.6.20-at92_e1.3.1/drivers/rtc/rtc-at91sam926x.c linux-2.6.20.AT91_svn/drivers/rtc/rtc-at91sam926x.c
--- linux-2.6.20-at92_e1.3.1/drivers/rtc/rtc-at91sam926x.c	2007-11-08 10:42:35.000000000 -0500
+++ linux-2.6.20.AT91_svn/drivers/rtc/rtc-at91sam926x.c	2007-11-07 13:06:12.000000000 -0500
@@ -5,8 +5,10 @@
  *      of the General Purpose Backup Registers (GPBR). 
  *
  *	2007 Michel Benoit
- *
+ *  2007 update by EMAC.Inc to support legacy alarm set calls and a minor bug fix.
+ * 
  *      Based on rtc-at91rm9200.c by Rick Bronson
+ * 
  *
  *	This program is free software; you can redistribute it and/or
  *	modify it under the terms of the GNU General Public License
@@ -45,10 +47,7 @@ static int at91_rtc_readtime(struct devi
     unsigned long secs1;
     unsigned long secs2;
     unsigned long base;
-    
-
-    printk(KERN_INFO "at91_rtc_readtime called\n");
-    
+        
     /* retrieve time base from battery backup register */ 
     base = at91_sys_read( AT91_GPBR + gpbr_offset );
     if( base == 0 ){
@@ -82,8 +81,6 @@ static int at91_rtc_set_mmss(struct devi
     unsigned long alarm;
     unsigned long mr;
     
-    printk(KERN_INFO "at91_rtc_set_mmss called\n");
-    
     mr = at91_sys_read( AT91_RTT_MR );
 
     /* disable interrupts */
@@ -126,8 +123,6 @@ static int at91_rtc_settime(struct devic
     int err;
     unsigned long secs;
 
-    printk(KERN_INFO "at91_rtc_settime called\n");
-
     pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
              1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
              tm->tm_hour, tm->tm_min, tm->tm_sec);
@@ -148,8 +143,6 @@ static int at91_rtc_readalarm(struct dev
 	struct rtc_time *tm = &alrm->time;
         unsigned long base;
         unsigned long alarm;
-    
-    printk(KERN_INFO "at91_rtc_readalarm called\n"); 
 
        alarm = at91_sys_read( AT91_RTT_AR );
         
@@ -166,7 +159,6 @@ static int at91_rtc_readalarm(struct dev
             pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
                      1900 + tm->tm_year, tm->tm_mon, tm->tm_mday,
                      tm->tm_hour, tm->tm_min, tm->tm_sec);
-            
         }
 
 	return 0;
@@ -177,13 +169,14 @@ static int at91_rtc_readalarm(struct dev
  */
 static int at91_rtc_setalarm(struct device *dev, struct rtc_wkalrm *alrm)
 {
-        struct rtc_time *tm = &alrm->time;
+		struct rtc_time *tm = &alrm->time;
         unsigned long secs;
         unsigned long base;
         int err; 
-    
-  printk(KERN_INFO "at91_rtc_setalarm called\n");
-
+		struct rtc_time now;//alarm merge with current time to support legacy alarm calls
+        at91_rtc_readtime(dev, &now);//get current time
+        rtc_merge_alarm(&now, tm);//replace invalid fields with the current time
+     
             err = rtc_tm_to_time(tm, &secs);
             if (err != 0)
 		return err;
@@ -207,8 +200,7 @@ static int at91_rtc_setalarm(struct devi
 
                 pr_debug("%s(): INVALID %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
                          tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour,
-                         tm->tm_min, tm->tm_sec);
-                
+                         tm->tm_min, tm->tm_sec);               
                 return -1;
             }
         
@@ -224,8 +216,6 @@ static int at91_rtc_ioctl(struct device 
 	int ret = 0;
         unsigned long mr = at91_sys_read(AT91_RTT_MR);
     
-printk(KERN_INFO "at91_rtc_ioctl called\n");
-
 	pr_debug("%s(): cmd=%08x, arg=%08lx.\n", __FUNCTION__, cmd, arg);
 
 	switch (cmd) {
@@ -265,8 +255,6 @@ static int at91_rtc_proc(struct device *
 {
 	unsigned long mr = at91_sys_read(AT91_RTT_MR);
 
-     printk(KERN_INFO "at91_rtc_proc called\n");
-
 	seq_printf(seq, "alarm_IRQ\t: %s\n",
 			(mr & AT91_RTT_ALMIEN) ? "yes" : "no");
 	seq_printf(seq, "periodic_IRQ\t: %s\n",
@@ -334,10 +322,7 @@ static int __init at91_rtc_probe(struct 
 	struct rtc_device *rtc;
 	int ret;
         unsigned long mr;
-        //struct at91_rtt_data *rtt_data = (struct at91_rtt_data*) pdev->dev.platform_data;
-        
-        printk(KERN_INFO "at91_rtc_probe called\n");
-        
+        //struct at91_rtt_data *rtt_data = (struct at91_rtt_data*) pdev->dev.platform_data;     
         /* save offset into GPBR to use for the base time */
         //gpbr_offset = 1;//(pdev->dev.platform_data)->gpbr_offset;
         //if( gpbr_offset > 3 ){
@@ -413,7 +398,7 @@ static int at91_rtc_suspend(struct platf
 	struct rtc_time tm;
 	struct timespec time;
         unsigned long mr;
- 
+        
 	time.tv_nsec = 0;
 
 	/* calculate time delta for suspend */
@@ -437,7 +422,7 @@ static int at91_rtc_suspend(struct platf
 	pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
 		1900 + tm.tm_year, tm.tm_mon, tm.tm_mday,
 		tm.tm_hour, tm.tm_min, tm.tm_sec);
-
+	
 	return 0;
 }
 
@@ -445,7 +430,8 @@ static int at91_rtc_resume(struct platfo
 {
 	struct rtc_time tm;
 	struct timespec time;
-
+    unsigned long mr;
+    
 	time.tv_nsec = 0;
 
 	at91_rtc_readtime(&pdev->dev, &tm);
