p54usb: Add device ID for Dell WLA3310 USB
[safe/jmp/linux-2.6] / drivers / rtc / rtc-ds1302.c
index 1845566..532acf9 100644 (file)
@@ -1,26 +1,25 @@
 /*
  * Dallas DS1302 RTC Support
  *
- *  Copyright (C) 2002  David McCullough
- *  Copyright (C) 2003 - 2007  Paul Mundt
+ *  Copyright (C) 2002 David McCullough
+ *  Copyright (C) 2003 - 2007 Paul Mundt
  *
  * This file is subject to the terms and conditions of the GNU General Public
- * License version 2.  See the file "COPYING" in the main directory of
+ * License version 2. See the file "COPYING" in the main directory of
  * this archive for more details.
  */
+
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/platform_device.h>
-#include <linux/time.h>
 #include <linux/rtc.h>
-#include <linux/spinlock.h>
 #include <linux/io.h>
 #include <linux/bcd.h>
 #include <asm/rtc.h>
 
 #define DRV_NAME       "rtc-ds1302"
-#define DRV_VERSION    "0.1.0"
+#define DRV_VERSION    "0.1.1"
 
 #define        RTC_CMD_READ    0x81            /* Read command */
 #define        RTC_CMD_WRITE   0x80            /* Write command */
 #error "Add support for your platform"
 #endif
 
-struct ds1302_rtc {
-       struct rtc_device *rtc_dev;
-       spinlock_t lock;
-};
-
 static void ds1302_sendbits(unsigned int val)
 {
        int i;
@@ -103,10 +97,6 @@ static void ds1302_writebyte(unsigned int addr, unsigned int val)
 
 static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
-       struct ds1302_rtc *rtc = dev_get_drvdata(dev);
-
-       spin_lock_irq(&rtc->lock);
-
        tm->tm_sec      = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC));
        tm->tm_min      = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN));
        tm->tm_hour     = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR));
@@ -118,26 +108,17 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
        if (tm->tm_year < 70)
                tm->tm_year += 100;
 
-       spin_unlock_irq(&rtc->lock);
-
        dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
                "mday=%d, mon=%d, year=%d, wday=%d\n",
                __func__,
                tm->tm_sec, tm->tm_min, tm->tm_hour,
                tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
 
-       if (rtc_valid_tm(tm) < 0)
-               dev_err(dev, "invalid date\n");
-
-       return 0;
+       return rtc_valid_tm(tm);
 }
 
 static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
-       struct ds1302_rtc *rtc = dev_get_drvdata(dev);
-
-       spin_lock_irq(&rtc->lock);
-
        /* Stop RTC */
        ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);
 
@@ -152,8 +133,6 @@ static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
        /* Start RTC */
        ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
 
-       spin_unlock_irq(&rtc->lock);
-
        return 0;
 }
 
@@ -164,15 +143,12 @@ static int ds1302_rtc_ioctl(struct device *dev, unsigned int cmd,
 #ifdef RTC_SET_CHARGE
        case RTC_SET_CHARGE:
        {
-               struct ds1302_rtc *rtc = dev_get_drvdata(dev);
                int tcs_val;
 
                if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int)))
                        return -EFAULT;
 
-               spin_lock_irq(&rtc->lock);
                ds1302_writebyte(RTC_ADDR_TCR, (0xa0 | tcs_val * 0xf));
-               spin_unlock_irq(&rtc->lock);
                return 0;
        }
 #endif
@@ -187,10 +163,9 @@ static struct rtc_class_ops ds1302_rtc_ops = {
        .ioctl          = ds1302_rtc_ioctl,
 };
 
-static int __devinit ds1302_rtc_probe(struct platform_device *pdev)
+static int __init ds1302_rtc_probe(struct platform_device *pdev)
 {
-       struct ds1302_rtc *rtc;
-       int ret;
+       struct rtc_device *rtc;
 
        /* Reset */
        set_dp(get_dp() & ~(RTC_RESET | RTC_IODATA | RTC_SCLK));
@@ -200,37 +175,23 @@ static int __devinit ds1302_rtc_probe(struct platform_device *pdev)
        if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42)
                return -ENODEV;
 
-       rtc = kzalloc(sizeof(struct ds1302_rtc), GFP_KERNEL);
-       if (unlikely(!rtc))
-               return -ENOMEM;
-
-       spin_lock_init(&rtc->lock);
-       rtc->rtc_dev = rtc_device_register("ds1302", &pdev->dev,
+       rtc = rtc_device_register("ds1302", &pdev->dev,
                                           &ds1302_rtc_ops, THIS_MODULE);
-       if (IS_ERR(rtc->rtc_dev)) {
-               ret = PTR_ERR(rtc->rtc_dev);
-               goto out;
-       }
+       if (IS_ERR(rtc))
+               return PTR_ERR(rtc);
 
        platform_set_drvdata(pdev, rtc);
 
        return 0;
-out:
-       kfree(rtc);
-       return ret;
 }
 
 static int __devexit ds1302_rtc_remove(struct platform_device *pdev)
 {
-       struct ds1302_rtc *rtc = platform_get_drvdata(pdev);
-
-       if (likely(rtc->rtc_dev))
-               rtc_device_unregister(rtc->rtc_dev);
+       struct rtc_device *rtc = platform_get_drvdata(pdev);
 
+       rtc_device_unregister(rtc);
        platform_set_drvdata(pdev, NULL);
 
-       kfree(rtc);
-
        return 0;
 }
 
@@ -239,13 +200,12 @@ static struct platform_driver ds1302_platform_driver = {
                .name   = DRV_NAME,
                .owner  = THIS_MODULE,
        },
-       .probe          = ds1302_rtc_probe,
        .remove         = __devexit_p(ds1302_rtc_remove),
 };
 
 static int __init ds1302_rtc_init(void)
 {
-       return platform_driver_register(&ds1302_platform_driver);
+       return platform_driver_probe(&ds1302_platform_driver, ds1302_rtc_probe);
 }
 
 static void __exit ds1302_rtc_exit(void)