nfsd4: setclientid_confirm callback-change fixes
[safe/jmp/linux-2.6] / drivers / rtc / rtc-ds1216.c
index 83efb88..4aedc70 100644 (file)
@@ -10,7 +10,7 @@
 #include <linux/platform_device.h>
 #include <linux/bcd.h>
 
-#define DRV_VERSION "0.1"
+#define DRV_VERSION "0.2"
 
 struct ds1216_regs {
        u8 tsec;
@@ -86,22 +86,23 @@ static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm)
        ds1216_switch_ds_to_clock(priv->ioaddr);
        ds1216_read(priv->ioaddr, (u8 *)&regs);
 
-       tm->tm_sec = BCD2BIN(regs.sec);
-       tm->tm_min = BCD2BIN(regs.min);
+       tm->tm_sec = bcd2bin(regs.sec);
+       tm->tm_min = bcd2bin(regs.min);
        if (regs.hour & DS1216_HOUR_1224) {
                /* AM/PM mode */
-               tm->tm_hour = BCD2BIN(regs.hour & 0x1f);
+               tm->tm_hour = bcd2bin(regs.hour & 0x1f);
                if (regs.hour & DS1216_HOUR_AMPM)
                        tm->tm_hour += 12;
        } else
-               tm->tm_hour = BCD2BIN(regs.hour & 0x3f);
+               tm->tm_hour = bcd2bin(regs.hour & 0x3f);
        tm->tm_wday = (regs.wday & 7) - 1;
-       tm->tm_mday = BCD2BIN(regs.mday & 0x3f);
-       tm->tm_mon = BCD2BIN(regs.month & 0x1f);
-       tm->tm_year = BCD2BIN(regs.year);
+       tm->tm_mday = bcd2bin(regs.mday & 0x3f);
+       tm->tm_mon = bcd2bin(regs.month & 0x1f);
+       tm->tm_year = bcd2bin(regs.year);
        if (tm->tm_year < 70)
                tm->tm_year += 100;
-       return 0;
+
+       return rtc_valid_tm(tm);
 }
 
 static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -114,19 +115,19 @@ static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm)
        ds1216_read(priv->ioaddr, (u8 *)&regs);
 
        regs.tsec = 0; /* clear 0.1 and 0.01 seconds */
-       regs.sec = BIN2BCD(tm->tm_sec);
-       regs.min = BIN2BCD(tm->tm_min);
+       regs.sec = bin2bcd(tm->tm_sec);
+       regs.min = bin2bcd(tm->tm_min);
        regs.hour &= DS1216_HOUR_1224;
        if (regs.hour && tm->tm_hour > 12) {
                regs.hour |= DS1216_HOUR_AMPM;
                tm->tm_hour -= 12;
        }
-       regs.hour |= BIN2BCD(tm->tm_hour);
+       regs.hour |= bin2bcd(tm->tm_hour);
        regs.wday &= ~7;
        regs.wday |= tm->tm_wday;
-       regs.mday = BIN2BCD(tm->tm_mday);
-       regs.month = BIN2BCD(tm->tm_mon);
-       regs.year = BIN2BCD(tm->tm_year % 100);
+       regs.mday = bin2bcd(tm->tm_mday);
+       regs.month = bin2bcd(tm->tm_mon);
+       regs.year = bin2bcd(tm->tm_year % 100);
 
        ds1216_switch_ds_to_clock(priv->ioaddr);
        ds1216_write(priv->ioaddr, (u8 *)&regs);
@@ -138,9 +139,8 @@ static const struct rtc_class_ops ds1216_rtc_ops = {
        .set_time       = ds1216_rtc_set_time,
 };
 
-static int __devinit ds1216_rtc_probe(struct platform_device *pdev)
+static int __init ds1216_rtc_probe(struct platform_device *pdev)
 {
-       struct rtc_device *rtc;
        struct resource *res;
        struct ds1216_priv *priv;
        int ret = 0;
@@ -152,7 +152,10 @@ static int __devinit ds1216_rtc_probe(struct platform_device *pdev)
        priv = kzalloc(sizeof *priv, GFP_KERNEL);
        if (!priv)
                return -ENOMEM;
-       priv->size = res->end - res->start + 1;
+
+       platform_set_drvdata(pdev, priv);
+
+       priv->size = resource_size(res);
        if (!request_mem_region(res->start, priv->size, pdev->name)) {
                ret = -EBUSY;
                goto out;
@@ -163,22 +166,18 @@ static int __devinit ds1216_rtc_probe(struct platform_device *pdev)
                ret = -ENOMEM;
                goto out;
        }
-       rtc = rtc_device_register("ds1216", &pdev->dev,
+       priv->rtc = rtc_device_register("ds1216", &pdev->dev,
                                  &ds1216_rtc_ops, THIS_MODULE);
-       if (IS_ERR(rtc)) {
-               ret = PTR_ERR(rtc);
+       if (IS_ERR(priv->rtc)) {
+               ret = PTR_ERR(priv->rtc);
                goto out;
        }
-       priv->rtc = rtc;
-       platform_set_drvdata(pdev, priv);
 
        /* dummy read to get clock into a known state */
        ds1216_read(priv->ioaddr, dummy);
        return 0;
 
 out:
-       if (priv->rtc)
-               rtc_device_unregister(priv->rtc);
        if (priv->ioaddr)
                iounmap(priv->ioaddr);
        if (priv->baseaddr)
@@ -187,7 +186,7 @@ out:
        return ret;
 }
 
-static int __devexit ds1216_rtc_remove(struct platform_device *pdev)
+static int __exit ds1216_rtc_remove(struct platform_device *pdev)
 {
        struct ds1216_priv *priv = platform_get_drvdata(pdev);
 
@@ -203,13 +202,12 @@ static struct platform_driver ds1216_rtc_platform_driver = {
                .name   = "rtc-ds1216",
                .owner  = THIS_MODULE,
        },
-       .probe          = ds1216_rtc_probe,
-       .remove         = __devexit_p(ds1216_rtc_remove),
+       .remove         = __exit_p(ds1216_rtc_remove),
 };
 
 static int __init ds1216_rtc_init(void)
 {
-       return platform_driver_register(&ds1216_rtc_platform_driver);
+       return platform_driver_probe(&ds1216_rtc_platform_driver, ds1216_rtc_probe);
 }
 
 static void __exit ds1216_rtc_exit(void)
@@ -221,6 +219,7 @@ MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
 MODULE_DESCRIPTION("DS1216 RTC driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);
+MODULE_ALIAS("platform:rtc-ds1216");
 
 module_init(ds1216_rtc_init);
 module_exit(ds1216_rtc_exit);