aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-mxc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/rtc-mxc.c')
-rw-r--r--drivers/rtc/rtc-mxc.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 6bd5072d4eb7..d71fe61db1d6 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -12,6 +12,7 @@
12#include <linux/io.h> 12#include <linux/io.h>
13#include <linux/rtc.h> 13#include <linux/rtc.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/slab.h>
15#include <linux/interrupt.h> 16#include <linux/interrupt.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/clk.h> 18#include <linux/clk.h>
@@ -383,21 +384,29 @@ static int __init mxc_rtc_probe(struct platform_device *pdev)
383 struct rtc_device *rtc; 384 struct rtc_device *rtc;
384 struct rtc_plat_data *pdata = NULL; 385 struct rtc_plat_data *pdata = NULL;
385 u32 reg; 386 u32 reg;
386 int ret, rate; 387 unsigned long rate;
388 int ret;
387 389
388 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 390 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
389 if (!res) 391 if (!res)
390 return -ENODEV; 392 return -ENODEV;
391 393
392 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 394 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
393 if (!pdata) 395 if (!pdata)
394 return -ENOMEM; 396 return -ENOMEM;
395 397
396 pdata->ioaddr = ioremap(res->start, resource_size(res)); 398 if (!devm_request_mem_region(&pdev->dev, res->start,
399 resource_size(res), pdev->name))
400 return -EBUSY;
401
402 pdata->ioaddr = devm_ioremap(&pdev->dev, res->start,
403 resource_size(res));
397 404
398 clk = clk_get(&pdev->dev, "ckil"); 405 clk = clk_get(&pdev->dev, "ckil");
399 if (IS_ERR(clk)) 406 if (IS_ERR(clk)) {
400 return PTR_ERR(clk); 407 ret = PTR_ERR(clk);
408 goto exit_free_pdata;
409 }
401 410
402 rate = clk_get_rate(clk); 411 rate = clk_get_rate(clk);
403 clk_put(clk); 412 clk_put(clk);
@@ -409,8 +418,7 @@ static int __init mxc_rtc_probe(struct platform_device *pdev)
409 else if (rate == 38400) 418 else if (rate == 38400)
410 reg = RTC_INPUT_CLK_38400HZ; 419 reg = RTC_INPUT_CLK_38400HZ;
411 else { 420 else {
412 dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", 421 dev_err(&pdev->dev, "rtc clock is not valid (%lu)\n", rate);
413 clk_get_rate(clk));
414 ret = -EINVAL; 422 ret = -EINVAL;
415 goto exit_free_pdata; 423 goto exit_free_pdata;
416 } 424 }
@@ -446,8 +454,8 @@ static int __init mxc_rtc_probe(struct platform_device *pdev)
446 pdata->irq = platform_get_irq(pdev, 0); 454 pdata->irq = platform_get_irq(pdev, 0);
447 455
448 if (pdata->irq >= 0 && 456 if (pdata->irq >= 0 &&
449 request_irq(pdata->irq, mxc_rtc_interrupt, IRQF_SHARED, 457 devm_request_irq(&pdev->dev, pdata->irq, mxc_rtc_interrupt,
450 pdev->name, pdev) < 0) { 458 IRQF_SHARED, pdev->name, pdev) < 0) {
451 dev_warn(&pdev->dev, "interrupt not available.\n"); 459 dev_warn(&pdev->dev, "interrupt not available.\n");
452 pdata->irq = -1; 460 pdata->irq = -1;
453 } 461 }
@@ -455,10 +463,10 @@ static int __init mxc_rtc_probe(struct platform_device *pdev)
455 return 0; 463 return 0;
456 464
457exit_put_clk: 465exit_put_clk:
466 clk_disable(pdata->clk);
458 clk_put(pdata->clk); 467 clk_put(pdata->clk);
459 468
460exit_free_pdata: 469exit_free_pdata:
461 kfree(pdata);
462 470
463 return ret; 471 return ret;
464} 472}
@@ -469,12 +477,8 @@ static int __exit mxc_rtc_remove(struct platform_device *pdev)
469 477
470 rtc_device_unregister(pdata->rtc); 478 rtc_device_unregister(pdata->rtc);
471 479
472 if (pdata->irq >= 0)
473 free_irq(pdata->irq, pdev);
474
475 clk_disable(pdata->clk); 480 clk_disable(pdata->clk);
476 clk_put(pdata->clk); 481 clk_put(pdata->clk);
477 kfree(pdata);
478 platform_set_drvdata(pdev, NULL); 482 platform_set_drvdata(pdev, NULL);
479 483
480 return 0; 484 return 0;