rtc: rtc-ds1216 fixes

Fixes a few issues with the rtc-ds1216 driver

- use rtc_valid_tm

- use platform_driver_probe

- fix init sequence - it was using rtc_unregister_driver where not
  needed.  I also added resource_size and removed an useless pointer
  assignment.

Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Tested-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Alessandro Zummo 2009-01-06 14:42:23 -08:00 committed by Linus Torvalds
parent 0e1492330c
commit 97a1f9532e

View file

@ -10,7 +10,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/bcd.h> #include <linux/bcd.h>
#define DRV_VERSION "0.1" #define DRV_VERSION "0.2"
struct ds1216_regs { struct ds1216_regs {
u8 tsec; u8 tsec;
@ -101,7 +101,8 @@ static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm)
tm->tm_year = bcd2bin(regs.year); tm->tm_year = bcd2bin(regs.year);
if (tm->tm_year < 70) if (tm->tm_year < 70)
tm->tm_year += 100; tm->tm_year += 100;
return 0;
return rtc_valid_tm(tm);
} }
static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm) static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm)
@ -138,9 +139,8 @@ static const struct rtc_class_ops ds1216_rtc_ops = {
.set_time = ds1216_rtc_set_time, .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 resource *res;
struct ds1216_priv *priv; struct ds1216_priv *priv;
int ret = 0; int ret = 0;
@ -152,7 +152,10 @@ static int __devinit ds1216_rtc_probe(struct platform_device *pdev)
priv = kzalloc(sizeof *priv, GFP_KERNEL); priv = kzalloc(sizeof *priv, GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; 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)) { if (!request_mem_region(res->start, priv->size, pdev->name)) {
ret = -EBUSY; ret = -EBUSY;
goto out; goto out;
@ -163,22 +166,18 @@ static int __devinit ds1216_rtc_probe(struct platform_device *pdev)
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
rtc = rtc_device_register("ds1216", &pdev->dev, priv->rtc = rtc_device_register("ds1216", &pdev->dev,
&ds1216_rtc_ops, THIS_MODULE); &ds1216_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) { if (IS_ERR(priv->rtc)) {
ret = PTR_ERR(rtc); ret = PTR_ERR(priv->rtc);
goto out; goto out;
} }
priv->rtc = rtc;
platform_set_drvdata(pdev, priv);
/* dummy read to get clock into a known state */ /* dummy read to get clock into a known state */
ds1216_read(priv->ioaddr, dummy); ds1216_read(priv->ioaddr, dummy);
return 0; return 0;
out: out:
if (priv->rtc)
rtc_device_unregister(priv->rtc);
if (priv->ioaddr) if (priv->ioaddr)
iounmap(priv->ioaddr); iounmap(priv->ioaddr);
if (priv->baseaddr) if (priv->baseaddr)
@ -187,7 +186,7 @@ out:
return ret; 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); struct ds1216_priv *priv = platform_get_drvdata(pdev);
@ -203,13 +202,12 @@ static struct platform_driver ds1216_rtc_platform_driver = {
.name = "rtc-ds1216", .name = "rtc-ds1216",
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.probe = ds1216_rtc_probe, .remove = __exit_p(ds1216_rtc_remove),
.remove = __devexit_p(ds1216_rtc_remove),
}; };
static int __init ds1216_rtc_init(void) 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) static void __exit ds1216_rtc_exit(void)