Merge tag 'lsk-v3.10-15.05-android' into develop-3.10
[firefly-linux-kernel-4.4.55.git] / drivers / rtc / rtc-wm831x.c
index eed33532e8f7e4e5989a9a328dbf322b34c22c90..8d65b94e5a7eb428fccfadf3d3db77f38a22f1ed 100644 (file)
@@ -344,15 +344,6 @@ static irqreturn_t wm831x_alm_irq(int irq, void *data)
        return IRQ_HANDLED;
 }
 
-static irqreturn_t wm831x_per_irq(int irq, void *data)
-{
-       struct wm831x_rtc *wm831x_rtc = data;
-
-       rtc_update_irq(wm831x_rtc->rtc, 1, RTC_IRQF | RTC_UF);
-
-       return IRQ_HANDLED;
-}
-
 static const struct rtc_class_ops wm831x_rtc_ops = {
        .read_time = wm831x_rtc_readtime,
        .set_mmss = wm831x_rtc_set_mmss,
@@ -425,26 +416,16 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
 {
        struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
        struct wm831x_rtc *wm831x_rtc;
-       int per_irq = platform_get_irq_byname(pdev, "PER");
-       int alm_irq = platform_get_irq_byname(pdev, "ALM");
+       int alm_irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "ALM"));
        int ret = 0;
-       struct rtc_time tm;
 
-       //printk("wm831x_rtc_probe\n");
-       wm831x_rtc = kzalloc(sizeof(*wm831x_rtc), GFP_KERNEL);
+       wm831x_rtc = devm_kzalloc(&pdev->dev, sizeof(*wm831x_rtc), GFP_KERNEL);
        if (wm831x_rtc == NULL)
                return -ENOMEM;
 
        platform_set_drvdata(pdev, wm831x_rtc);
        wm831x_rtc->wm831x = wm831x;
 
-#ifdef CONFIG_ARCH_RK30
-       wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_1);
-       wm831x_set_bits(wm831x, WM831X_SECURITY_KEY, 0x9716, 0x9716);  //0x4090h bit15 is encrypted, if this bit need modify, we must write 0x4008h as 0x9716 first.
-       wm831x_set_bits(wm831x, WM831X_CLOCK_CONTROL_1, 0x8700, 0x8100); //open the clk out
-       wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_1);
-#endif
-
        ret = wm831x_reg_read(wm831x, WM831X_RTC_CONTROL);
        if (ret < 0) {
                dev_err(&pdev->dev, "Failed to read RTC control: %d\n", ret);
@@ -453,37 +434,19 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
        if (ret & WM831X_RTC_ALM_ENA)
                wm831x_rtc->alarm_enabled = 1;
 
-       ret = wm831x_rtc_readtime(&pdev->dev, &tm);
-       if (ret < 0 || tm.tm_year < 111) {
-               if (ret)
-                       dev_err(&pdev->dev, "Failed to read RTC time\n");
-               else
-                       dev_err(&pdev->dev, "Invalid RTC date/time %4d-%02d-%02d(%d) %02d:%02d:%02d\n",
-                               1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday, tm.tm_wday,
-                               tm.tm_hour, tm.tm_min, tm.tm_sec);
-               wm831x_rtc_set_mmss(&pdev->dev, 1293883200); // 2011-01-01 12:00:00
-       }
-
        device_init_wakeup(&pdev->dev, 1);
 
-       wm831x_rtc->rtc = rtc_device_register("wm831x", &pdev->dev,
+       wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x",
                                              &wm831x_rtc_ops, THIS_MODULE);
        if (IS_ERR(wm831x_rtc->rtc)) {
                ret = PTR_ERR(wm831x_rtc->rtc);
                goto err;
        }
 
-       ret = request_threaded_irq(per_irq, NULL, wm831x_per_irq,
-                                  IRQF_TRIGGER_RISING, "RTC period",
-                                  wm831x_rtc);
-       if (ret != 0) {
-               dev_err(&pdev->dev, "Failed to request periodic IRQ %d: %d\n",
-                       per_irq, ret);
-       }
-
-       ret = request_threaded_irq(alm_irq, NULL, wm831x_alm_irq,
-                                  IRQF_TRIGGER_RISING, "RTC alarm",
-                                  wm831x_rtc);
+       ret = devm_request_threaded_irq(&pdev->dev, alm_irq, NULL,
+                               wm831x_alm_irq,
+                               IRQF_TRIGGER_RISING, "RTC alarm",
+                               wm831x_rtc);
        if (ret != 0) {
                dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
                        alm_irq, ret);
@@ -494,21 +457,11 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
        return 0;
 
 err:
-       kfree(wm831x_rtc);
        return ret;
 }
 
-static int __devexit wm831x_rtc_remove(struct platform_device *pdev)
+static int wm831x_rtc_remove(struct platform_device *pdev)
 {
-       struct wm831x_rtc *wm831x_rtc = platform_get_drvdata(pdev);
-       int per_irq = platform_get_irq_byname(pdev, "PER");
-       int alm_irq = platform_get_irq_byname(pdev, "ALM");
-
-       free_irq(alm_irq, wm831x_rtc);
-       free_irq(per_irq, wm831x_rtc);
-       rtc_device_unregister(wm831x_rtc->rtc);
-       kfree(wm831x_rtc);
-
        return 0;
 }
 
@@ -525,24 +478,14 @@ static const struct dev_pm_ops wm831x_rtc_pm_ops = {
 
 static struct platform_driver wm831x_rtc_driver = {
        .probe = wm831x_rtc_probe,
-       .remove = __devexit_p(wm831x_rtc_remove),
+       .remove = wm831x_rtc_remove,
        .driver = {
                .name = "wm831x-rtc",
                .pm = &wm831x_rtc_pm_ops,
        },
 };
 
-static int __init wm831x_rtc_init(void)
-{
-       return platform_driver_register(&wm831x_rtc_driver);
-}
-module_init(wm831x_rtc_init);
-
-static void __exit wm831x_rtc_exit(void)
-{
-       platform_driver_unregister(&wm831x_rtc_driver);
-}
-module_exit(wm831x_rtc_exit);
+module_platform_driver(wm831x_rtc_driver);
 
 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
 MODULE_DESCRIPTION("RTC driver for the WM831x series PMICs");