rtc: Add max77660 rtc driver
[linux-3.10.git] / drivers / rtc / rtc-davinci.c
index fd95316..a55048c 100644 (file)
@@ -485,7 +485,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
        struct resource *res, *mem;
        int ret = 0;
 
-       davinci_rtc = kzalloc(sizeof(struct davinci_rtc), GFP_KERNEL);
+       davinci_rtc = devm_kzalloc(&pdev->dev, sizeof(struct davinci_rtc), GFP_KERNEL);
        if (!davinci_rtc) {
                dev_dbg(dev, "could not allocate memory for private data\n");
                return -ENOMEM;
@@ -494,45 +494,42 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
        davinci_rtc->irq = platform_get_irq(pdev, 0);
        if (davinci_rtc->irq < 0) {
                dev_err(dev, "no RTC irq\n");
-               ret = davinci_rtc->irq;
-               goto fail1;
+               return davinci_rtc->irq;
        }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!res) {
                dev_err(dev, "no mem resource\n");
-               ret = -EINVAL;
-               goto fail1;
+               return -EINVAL;
        }
 
        davinci_rtc->pbase = res->start;
        davinci_rtc->base_size = resource_size(res);
 
-       mem = request_mem_region(davinci_rtc->pbase, davinci_rtc->base_size,
-                                pdev->name);
+       mem = devm_request_mem_region(dev, davinci_rtc->pbase,
+                               davinci_rtc->base_size, pdev->name);
        if (!mem) {
                dev_err(dev, "RTC registers at %08x are not free\n",
                        davinci_rtc->pbase);
-               ret = -EBUSY;
-               goto fail1;
+               return -EBUSY;
        }
 
-       davinci_rtc->base = ioremap(davinci_rtc->pbase, davinci_rtc->base_size);
+       davinci_rtc->base = devm_ioremap(dev, davinci_rtc->pbase,
+                                       davinci_rtc->base_size);
        if (!davinci_rtc->base) {
                dev_err(dev, "unable to ioremap MEM resource\n");
-               ret = -ENOMEM;
-               goto fail2;
+               return -ENOMEM;
        }
 
        platform_set_drvdata(pdev, davinci_rtc);
 
-       davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev,
+       davinci_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
                                    &davinci_rtc_ops, THIS_MODULE);
        if (IS_ERR(davinci_rtc->rtc)) {
                ret = PTR_ERR(davinci_rtc->rtc);
                dev_err(dev, "unable to register RTC device, err %d\n",
                                ret);
-               goto fail3;
+               goto fail1;
        }
 
        rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG);
@@ -542,11 +539,11 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
        rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CTRL);
        rtcss_write(davinci_rtc, 0, PRTCSS_RTC_CCTRL);
 
-       ret = request_irq(davinci_rtc->irq, davinci_rtc_interrupt,
+       ret = devm_request_irq(dev, davinci_rtc->irq, davinci_rtc_interrupt,
                          0, "davinci_rtc", davinci_rtc);
        if (ret < 0) {
                dev_err(dev, "unable to register davinci RTC interrupt\n");
-               goto fail4;
+               goto fail1;
        }
 
        /* Enable interrupts */
@@ -560,20 +557,12 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
 
        return 0;
 
-fail4:
-       rtc_device_unregister(davinci_rtc->rtc);
-fail3:
-       platform_set_drvdata(pdev, NULL);
-       iounmap(davinci_rtc->base);
-fail2:
-       release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size);
 fail1:
-       kfree(davinci_rtc);
-
+       platform_set_drvdata(pdev, NULL);
        return ret;
 }
 
-static int __devexit davinci_rtc_remove(struct platform_device *pdev)
+static int __exit davinci_rtc_remove(struct platform_device *pdev)
 {
        struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev);
 
@@ -581,40 +570,21 @@ static int __devexit davinci_rtc_remove(struct platform_device *pdev)
 
        rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
 
-       free_irq(davinci_rtc->irq, davinci_rtc);
-
-       rtc_device_unregister(davinci_rtc->rtc);
-
-       iounmap(davinci_rtc->base);
-       release_mem_region(davinci_rtc->pbase, davinci_rtc->base_size);
-
        platform_set_drvdata(pdev, NULL);
 
-       kfree(davinci_rtc);
-
        return 0;
 }
 
 static struct platform_driver davinci_rtc_driver = {
        .probe          = davinci_rtc_probe,
-       .remove         = __devexit_p(davinci_rtc_remove),
+       .remove         = __exit_p(davinci_rtc_remove),
        .driver         = {
                .name = "rtc_davinci",
                .owner = THIS_MODULE,
        },
 };
 
-static int __init rtc_init(void)
-{
-       return platform_driver_probe(&davinci_rtc_driver, davinci_rtc_probe);
-}
-module_init(rtc_init);
-
-static void __exit rtc_exit(void)
-{
-       platform_driver_unregister(&davinci_rtc_driver);
-}
-module_exit(rtc_exit);
+module_platform_driver_probe(davinci_rtc_driver, davinci_rtc_probe);
 
 MODULE_AUTHOR("Miguel Aguilar <miguel.aguilar@ridgerun.com>");
 MODULE_DESCRIPTION("Texas Instruments DaVinci PRTC Driver");