Merge branch 'linus' into x86/urgent
[pandora-kernel.git] / drivers / char / ds1286.c
index 21c8229..fb58493 100644 (file)
@@ -27,6 +27,7 @@
  * option) any later version.
  */
 #include <linux/ds1286.h>
+#include <linux/smp_lock.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/miscdevice.h>
@@ -39,6 +40,7 @@
 #include <linux/spinlock.h>
 #include <linux/bcd.h>
 #include <linux/proc_fs.h>
+#include <linux/jiffies.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -104,7 +106,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
        switch (cmd) {
        case RTC_AIE_OFF:       /* Mask alarm int. enab. bit    */
        {
-               unsigned int flags;
+               unsigned long flags;
                unsigned char val;
 
                if (!capable(CAP_SYS_TIME))
@@ -120,7 +122,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
        }
        case RTC_AIE_ON:        /* Allow alarm interrupts.      */
        {
-               unsigned int flags;
+               unsigned long flags;
                unsigned char val;
 
                if (!capable(CAP_SYS_TIME))
@@ -136,7 +138,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
        }
        case RTC_WIE_OFF:       /* Mask watchdog int. enab. bit */
        {
-               unsigned int flags;
+               unsigned long flags;
                unsigned char val;
 
                if (!capable(CAP_SYS_TIME))
@@ -152,7 +154,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
        }
        case RTC_WIE_ON:        /* Allow watchdog interrupts.   */
        {
-               unsigned int flags;
+               unsigned long flags;
                unsigned char val;
 
                if (!capable(CAP_SYS_TIME))
@@ -197,6 +199,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
 
                hrs = alm_tm.tm_hour;
                min = alm_tm.tm_min;
+               sec = alm_tm.tm_sec;
 
                if (hrs >= 24)
                        hrs = 0xff;
@@ -204,9 +207,11 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
                if (min >= 60)
                        min = 0xff;
 
-               BIN_TO_BCD(sec);
-               BIN_TO_BCD(min);
-               BIN_TO_BCD(hrs);
+               if (sec != 0)
+                       return -EINVAL;
+
+               min = BIN2BCD(min);
+               min = BIN2BCD(hrs);
 
                spin_lock(&ds1286_lock);
                rtc_write(hrs, RTC_HOURS_ALARM);
@@ -248,6 +253,7 @@ static int ds1286_ioctl(struct inode *inode, struct file *file,
 
 static int ds1286_open(struct inode *inode, struct file *file)
 {
+       lock_kernel();
        spin_lock_irq(&ds1286_lock);
 
        if (ds1286_status & RTC_IS_OPEN)
@@ -256,10 +262,12 @@ static int ds1286_open(struct inode *inode, struct file *file)
        ds1286_status |= RTC_IS_OPEN;
 
        spin_unlock_irq(&ds1286_lock);
+       unlock_kernel();
        return 0;
 
 out_busy:
        spin_lock_irq(&ds1286_lock);
+       unlock_kernel();
        return -EBUSY;
 }
 
@@ -434,7 +442,7 @@ static inline unsigned char ds1286_is_updating(void)
 static void ds1286_get_time(struct rtc_time *rtc_tm)
 {
        unsigned char save_control;
-       unsigned int flags;
+       unsigned long flags;
        unsigned long uip_watchdog = jiffies;
 
        /*
@@ -448,7 +456,7 @@ static void ds1286_get_time(struct rtc_time *rtc_tm)
         */
 
        if (ds1286_is_updating() != 0)
-               while (jiffies - uip_watchdog < 2*HZ/100)
+               while (time_before(jiffies, uip_watchdog + 2*HZ/100))
                        barrier();
 
        /*
@@ -494,7 +502,8 @@ static int ds1286_set_time(struct rtc_time *rtc_tm)
 {
        unsigned char mon, day, hrs, min, sec, leap_yr;
        unsigned char save_control;
-       unsigned int yrs, flags;
+       unsigned int yrs;
+       unsigned long flags;
 
 
        yrs = rtc_tm->tm_year + 1900;
@@ -552,7 +561,7 @@ static int ds1286_set_time(struct rtc_time *rtc_tm)
 static void ds1286_get_alm_time(struct rtc_time *alm_tm)
 {
        unsigned char cmd;
-       unsigned int flags;
+       unsigned long flags;
 
        /*
         * Only the values that we read from the RTC are set. That