]> err.no Git - linux-2.6/blobdiff - drivers/rtc/rtc-dev.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / drivers / rtc / rtc-dev.c
index 623cb8d06b02b2a0f27f0740eb425bfdfc784b6e..814583bd2fe709c1da0710808ed6f4cffbe8b50f 100644 (file)
@@ -34,7 +34,7 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
 
        file->private_data = rtc;
 
-       err = ops->open ? ops->open(rtc->class_dev.dev) : 0;
+       err = ops->open ? ops->open(rtc->dev.parent) : 0;
        if (err == 0) {
                spin_lock_irq(&rtc->irq_lock);
                rtc->irq_data = 0;
@@ -142,7 +142,7 @@ static int set_uie(struct rtc_device *rtc)
 static ssize_t
 rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 {
-       struct rtc_device *rtc = to_rtc_device(file->private_data);
+       struct rtc_device *rtc = file->private_data;
 
        DECLARE_WAITQUEUE(wait, current);
        unsigned long data;
@@ -180,7 +180,7 @@ rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        if (ret == 0) {
                /* Check for any data updates */
                if (rtc->ops->read_callback)
-                       data = rtc->ops->read_callback(rtc->class_dev.dev,
+                       data = rtc->ops->read_callback(rtc->dev.parent,
                                                       data);
 
                if (sizeof(int) != sizeof(long) &&
@@ -196,7 +196,7 @@ rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 
 static unsigned int rtc_dev_poll(struct file *file, poll_table *wait)
 {
-       struct rtc_device *rtc = to_rtc_device(file->private_data);
+       struct rtc_device *rtc = file->private_data;
        unsigned long data;
 
        poll_wait(file, &rtc->irq_queue, wait);
@@ -233,25 +233,15 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
                break;
 
        case RTC_PIE_ON:
-               if (!capable(CAP_SYS_RESOURCE))
+               if (rtc->irq_freq > rtc->max_user_freq &&
+                               !capable(CAP_SYS_RESOURCE))
                        return -EACCES;
                break;
        }
 
-       /* avoid conflicting IRQ users */
-       if (cmd == RTC_PIE_ON || cmd == RTC_PIE_OFF || cmd == RTC_IRQP_SET) {
-               spin_lock_irq(&rtc->irq_task_lock);
-               if (rtc->irq_task)
-                       err = -EBUSY;
-               spin_unlock_irq(&rtc->irq_task_lock);
-
-               if (err < 0)
-                       return err;
-       }
-
        /* try the driver's ioctl interface */
        if (ops->ioctl) {
-               err = ops->ioctl(rtc->class_dev.dev, cmd, arg);
+               err = ops->ioctl(rtc->dev.parent, cmd, arg);
                if (err != -ENOIOCTLCMD)
                        return err;
        }
@@ -277,12 +267,48 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
 
                alarm.enabled = 0;
                alarm.pending = 0;
-               alarm.time.tm_mday = -1;
-               alarm.time.tm_mon = -1;
-               alarm.time.tm_year = -1;
                alarm.time.tm_wday = -1;
                alarm.time.tm_yday = -1;
                alarm.time.tm_isdst = -1;
+
+               /* RTC_ALM_SET alarms may be up to 24 hours in the future.
+                * Rather than expecting every RTC to implement "don't care"
+                * for day/month/year fields, just force the alarm to have
+                * the right values for those fields.
+                *
+                * RTC_WKALM_SET should be used instead.  Not only does it
+                * eliminate the need for a separate RTC_AIE_ON call, it
+                * doesn't have the "alarm 23:59:59 in the future" race.
+                *
+                * NOTE:  some legacy code may have used invalid fields as
+                * wildcards, exposing hardware "periodic alarm" capabilities.
+                * Not supported here.
+                */
+               {
+                       unsigned long now, then;
+
+                       err = rtc_read_time(rtc, &tm);
+                       if (err < 0)
+                               return err;
+                       rtc_tm_to_time(&tm, &now);
+
+                       alarm.time.tm_mday = tm.tm_mday;
+                       alarm.time.tm_mon = tm.tm_mon;
+                       alarm.time.tm_year = tm.tm_year;
+                       err  = rtc_valid_tm(&alarm.time);
+                       if (err < 0)
+                               return err;
+                       rtc_tm_to_time(&alarm.time, &then);
+
+                       /* alarm may need to wrap into tomorrow */
+                       if (then < now) {
+                               rtc_time_to_tm(now + 24 * 60 * 60, &tm);
+                               alarm.time.tm_mday = tm.tm_mday;
+                               alarm.time.tm_mon = tm.tm_mon;
+                               alarm.time.tm_year = tm.tm_year;
+                       }
+               }
+
                err = rtc_set_alarm(rtc, &alarm);
                break;
 
@@ -302,14 +328,20 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
                err = rtc_set_time(rtc, &tm);
                break;
 
-       case RTC_IRQP_READ:
-               if (ops->irq_set_freq)
-                       err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
+       case RTC_PIE_ON:
+               err = rtc_irq_set_state(rtc, NULL, 1);
+               break;
+
+       case RTC_PIE_OFF:
+               err = rtc_irq_set_state(rtc, NULL, 0);
                break;
 
        case RTC_IRQP_SET:
-               if (ops->irq_set_freq)
-                       err = rtc_irq_set_freq(rtc, rtc->irq_task, arg);
+               err = rtc_irq_set_freq(rtc, NULL, arg);
+               break;
+
+       case RTC_IRQP_READ:
+               err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
                break;
 
 #if 0
@@ -365,13 +397,13 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
 
 static int rtc_dev_release(struct inode *inode, struct file *file)
 {
-       struct rtc_device *rtc = to_rtc_device(file->private_data);
+       struct rtc_device *rtc = file->private_data;
 
 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
        clear_uie(rtc);
 #endif
        if (rtc->ops->release)
-               rtc->ops->release(rtc->class_dev.dev);
+               rtc->ops->release(rtc->dev.parent);
 
        mutex_unlock(&rtc->char_lock);
        return 0;
@@ -379,7 +411,7 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
 
 static int rtc_dev_fasync(int fd, struct file *file, int on)
 {
-       struct rtc_device *rtc = to_rtc_device(file->private_data);
+       struct rtc_device *rtc = file->private_data;
        return fasync_helper(fd, file, on, &rtc->async_queue);
 }
 
@@ -396,7 +428,7 @@ static const struct file_operations rtc_dev_fops = {
 
 /* insertion/removal hooks */
 
-void rtc_dev_add_device(struct rtc_device *rtc)
+void rtc_dev_prepare(struct rtc_device *rtc)
 {
        if (!rtc_devt)
                return;
@@ -406,11 +438,9 @@ void rtc_dev_add_device(struct rtc_device *rtc)
                return;
        }
 
-       rtc->class_dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
+       rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
 
        mutex_init(&rtc->char_lock);
-       spin_lock_init(&rtc->irq_lock);
-       init_waitqueue_head(&rtc->irq_queue);
 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
        INIT_WORK(&rtc->uie_task, rtc_uie_task);
        setup_timer(&rtc->uie_timer, rtc_uie_timer, (unsigned long)rtc);
@@ -418,8 +448,11 @@ void rtc_dev_add_device(struct rtc_device *rtc)
 
        cdev_init(&rtc->char_dev, &rtc_dev_fops);
        rtc->char_dev.owner = rtc->owner;
+}
 
-       if (cdev_add(&rtc->char_dev, rtc->class_dev.devt, 1))
+void rtc_dev_add_device(struct rtc_device *rtc)
+{
+       if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1))
                printk(KERN_WARNING "%s: failed to add char device %d:%d\n",
                        rtc->name, MAJOR(rtc_devt), rtc->id);
        else
@@ -429,7 +462,7 @@ void rtc_dev_add_device(struct rtc_device *rtc)
 
 void rtc_dev_del_device(struct rtc_device *rtc)
 {
-       if (rtc->class_dev.devt)
+       if (rtc->dev.devt)
                cdev_del(&rtc->char_dev);
 }