diff options
Diffstat (limited to 'drivers/rtc/rtc-omap.c')
-rw-r--r-- | drivers/rtc/rtc-omap.c | 81 |
1 files changed, 20 insertions, 61 deletions
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c index 600971407aac..4e1bdb832e37 100644 --- a/drivers/rtc/rtc-omap.c +++ b/drivers/rtc/rtc-omap.c | |||
@@ -324,7 +324,7 @@ MODULE_DEVICE_TABLE(of, omap_rtc_of_match); | |||
324 | 324 | ||
325 | static int __init omap_rtc_probe(struct platform_device *pdev) | 325 | static int __init omap_rtc_probe(struct platform_device *pdev) |
326 | { | 326 | { |
327 | struct resource *res, *mem; | 327 | struct resource *res; |
328 | struct rtc_device *rtc; | 328 | struct rtc_device *rtc; |
329 | u8 reg, new_ctrl; | 329 | u8 reg, new_ctrl; |
330 | const struct platform_device_id *id_entry; | 330 | const struct platform_device_id *id_entry; |
@@ -352,18 +352,9 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
352 | return -ENOENT; | 352 | return -ENOENT; |
353 | } | 353 | } |
354 | 354 | ||
355 | mem = request_mem_region(res->start, resource_size(res), pdev->name); | 355 | rtc_base = devm_ioremap_resource(&pdev->dev, res); |
356 | if (!mem) { | 356 | if (IS_ERR(rtc_base)) |
357 | pr_debug("%s: RTC registers at %08x are not free\n", | 357 | return PTR_ERR(rtc_base); |
358 | pdev->name, res->start); | ||
359 | return -EBUSY; | ||
360 | } | ||
361 | |||
362 | rtc_base = ioremap(res->start, resource_size(res)); | ||
363 | if (!rtc_base) { | ||
364 | pr_debug("%s: RTC registers can't be mapped\n", pdev->name); | ||
365 | goto fail; | ||
366 | } | ||
367 | 358 | ||
368 | /* Enable the clock/module so that we can access the registers */ | 359 | /* Enable the clock/module so that we can access the registers */ |
369 | pm_runtime_enable(&pdev->dev); | 360 | pm_runtime_enable(&pdev->dev); |
@@ -375,7 +366,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
375 | rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG); | 366 | rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG); |
376 | } | 367 | } |
377 | 368 | ||
378 | rtc = rtc_device_register(pdev->name, &pdev->dev, | 369 | rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
379 | &omap_rtc_ops, THIS_MODULE); | 370 | &omap_rtc_ops, THIS_MODULE); |
380 | if (IS_ERR(rtc)) { | 371 | if (IS_ERR(rtc)) { |
381 | pr_debug("%s: can't register RTC device, err %ld\n", | 372 | pr_debug("%s: can't register RTC device, err %ld\n", |
@@ -383,7 +374,6 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
383 | goto fail0; | 374 | goto fail0; |
384 | } | 375 | } |
385 | platform_set_drvdata(pdev, rtc); | 376 | platform_set_drvdata(pdev, rtc); |
386 | dev_set_drvdata(&rtc->dev, mem); | ||
387 | 377 | ||
388 | /* clear pending irqs, and set 1/second periodic, | 378 | /* clear pending irqs, and set 1/second periodic, |
389 | * which we'll use instead of update irqs | 379 | * which we'll use instead of update irqs |
@@ -401,18 +391,18 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
401 | rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG); | 391 | rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG); |
402 | 392 | ||
403 | /* handle periodic and alarm irqs */ | 393 | /* handle periodic and alarm irqs */ |
404 | if (request_irq(omap_rtc_timer, rtc_irq, 0, | 394 | if (devm_request_irq(&pdev->dev, omap_rtc_timer, rtc_irq, 0, |
405 | dev_name(&rtc->dev), rtc)) { | 395 | dev_name(&rtc->dev), rtc)) { |
406 | pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", | 396 | pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", |
407 | pdev->name, omap_rtc_timer); | 397 | pdev->name, omap_rtc_timer); |
408 | goto fail1; | 398 | goto fail0; |
409 | } | 399 | } |
410 | if ((omap_rtc_timer != omap_rtc_alarm) && | 400 | if ((omap_rtc_timer != omap_rtc_alarm) && |
411 | (request_irq(omap_rtc_alarm, rtc_irq, 0, | 401 | (devm_request_irq(&pdev->dev, omap_rtc_alarm, rtc_irq, 0, |
412 | dev_name(&rtc->dev), rtc))) { | 402 | dev_name(&rtc->dev), rtc))) { |
413 | pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", | 403 | pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", |
414 | pdev->name, omap_rtc_alarm); | 404 | pdev->name, omap_rtc_alarm); |
415 | goto fail2; | 405 | goto fail0; |
416 | } | 406 | } |
417 | 407 | ||
418 | /* On boards with split power, RTC_ON_NOFF won't reset the RTC */ | 408 | /* On boards with split power, RTC_ON_NOFF won't reset the RTC */ |
@@ -446,25 +436,16 @@ static int __init omap_rtc_probe(struct platform_device *pdev) | |||
446 | 436 | ||
447 | return 0; | 437 | return 0; |
448 | 438 | ||
449 | fail2: | ||
450 | free_irq(omap_rtc_timer, rtc); | ||
451 | fail1: | ||
452 | rtc_device_unregister(rtc); | ||
453 | fail0: | 439 | fail0: |
454 | if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) | 440 | if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) |
455 | rtc_writel(0, OMAP_RTC_KICK0_REG); | 441 | rtc_writel(0, OMAP_RTC_KICK0_REG); |
456 | pm_runtime_put_sync(&pdev->dev); | 442 | pm_runtime_put_sync(&pdev->dev); |
457 | pm_runtime_disable(&pdev->dev); | 443 | pm_runtime_disable(&pdev->dev); |
458 | iounmap(rtc_base); | ||
459 | fail: | ||
460 | release_mem_region(mem->start, resource_size(mem)); | ||
461 | return -EIO; | 444 | return -EIO; |
462 | } | 445 | } |
463 | 446 | ||
464 | static int __exit omap_rtc_remove(struct platform_device *pdev) | 447 | static int __exit omap_rtc_remove(struct platform_device *pdev) |
465 | { | 448 | { |
466 | struct rtc_device *rtc = platform_get_drvdata(pdev); | ||
467 | struct resource *mem = dev_get_drvdata(&rtc->dev); | ||
468 | const struct platform_device_id *id_entry = | 449 | const struct platform_device_id *id_entry = |
469 | platform_get_device_id(pdev); | 450 | platform_get_device_id(pdev); |
470 | 451 | ||
@@ -473,12 +454,6 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) | |||
473 | /* leave rtc running, but disable irqs */ | 454 | /* leave rtc running, but disable irqs */ |
474 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); | 455 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); |
475 | 456 | ||
476 | free_irq(omap_rtc_timer, rtc); | ||
477 | |||
478 | if (omap_rtc_timer != omap_rtc_alarm) | ||
479 | free_irq(omap_rtc_alarm, rtc); | ||
480 | |||
481 | rtc_device_unregister(rtc); | ||
482 | if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) | 457 | if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) |
483 | rtc_writel(0, OMAP_RTC_KICK0_REG); | 458 | rtc_writel(0, OMAP_RTC_KICK0_REG); |
484 | 459 | ||
@@ -486,16 +461,13 @@ static int __exit omap_rtc_remove(struct platform_device *pdev) | |||
486 | pm_runtime_put_sync(&pdev->dev); | 461 | pm_runtime_put_sync(&pdev->dev); |
487 | pm_runtime_disable(&pdev->dev); | 462 | pm_runtime_disable(&pdev->dev); |
488 | 463 | ||
489 | iounmap(rtc_base); | ||
490 | release_mem_region(mem->start, resource_size(mem)); | ||
491 | return 0; | 464 | return 0; |
492 | } | 465 | } |
493 | 466 | ||
494 | #ifdef CONFIG_PM | 467 | #ifdef CONFIG_PM_SLEEP |
495 | |||
496 | static u8 irqstat; | 468 | static u8 irqstat; |
497 | 469 | ||
498 | static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state) | 470 | static int omap_rtc_suspend(struct device *dev) |
499 | { | 471 | { |
500 | irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG); | 472 | irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG); |
501 | 473 | ||
@@ -503,34 +475,32 @@ static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state) | |||
503 | * source, and in fact this enable() call is just saving a flag | 475 | * source, and in fact this enable() call is just saving a flag |
504 | * that's never used... | 476 | * that's never used... |
505 | */ | 477 | */ |
506 | if (device_may_wakeup(&pdev->dev)) | 478 | if (device_may_wakeup(dev)) |
507 | enable_irq_wake(omap_rtc_alarm); | 479 | enable_irq_wake(omap_rtc_alarm); |
508 | else | 480 | else |
509 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); | 481 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); |
510 | 482 | ||
511 | /* Disable the clock/module */ | 483 | /* Disable the clock/module */ |
512 | pm_runtime_put_sync(&pdev->dev); | 484 | pm_runtime_put_sync(dev); |
513 | 485 | ||
514 | return 0; | 486 | return 0; |
515 | } | 487 | } |
516 | 488 | ||
517 | static int omap_rtc_resume(struct platform_device *pdev) | 489 | static int omap_rtc_resume(struct device *dev) |
518 | { | 490 | { |
519 | /* Enable the clock/module so that we can access the registers */ | 491 | /* Enable the clock/module so that we can access the registers */ |
520 | pm_runtime_get_sync(&pdev->dev); | 492 | pm_runtime_get_sync(dev); |
521 | 493 | ||
522 | if (device_may_wakeup(&pdev->dev)) | 494 | if (device_may_wakeup(dev)) |
523 | disable_irq_wake(omap_rtc_alarm); | 495 | disable_irq_wake(omap_rtc_alarm); |
524 | else | 496 | else |
525 | rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG); | 497 | rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG); |
526 | return 0; | 498 | return 0; |
527 | } | 499 | } |
528 | |||
529 | #else | ||
530 | #define omap_rtc_suspend NULL | ||
531 | #define omap_rtc_resume NULL | ||
532 | #endif | 500 | #endif |
533 | 501 | ||
502 | static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume); | ||
503 | |||
534 | static void omap_rtc_shutdown(struct platform_device *pdev) | 504 | static void omap_rtc_shutdown(struct platform_device *pdev) |
535 | { | 505 | { |
536 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); | 506 | rtc_write(0, OMAP_RTC_INTERRUPTS_REG); |
@@ -539,28 +509,17 @@ static void omap_rtc_shutdown(struct platform_device *pdev) | |||
539 | MODULE_ALIAS("platform:omap_rtc"); | 509 | MODULE_ALIAS("platform:omap_rtc"); |
540 | static struct platform_driver omap_rtc_driver = { | 510 | static struct platform_driver omap_rtc_driver = { |
541 | .remove = __exit_p(omap_rtc_remove), | 511 | .remove = __exit_p(omap_rtc_remove), |
542 | .suspend = omap_rtc_suspend, | ||
543 | .resume = omap_rtc_resume, | ||
544 | .shutdown = omap_rtc_shutdown, | 512 | .shutdown = omap_rtc_shutdown, |
545 | .driver = { | 513 | .driver = { |
546 | .name = DRIVER_NAME, | 514 | .name = DRIVER_NAME, |
547 | .owner = THIS_MODULE, | 515 | .owner = THIS_MODULE, |
516 | .pm = &omap_rtc_pm_ops, | ||
548 | .of_match_table = of_match_ptr(omap_rtc_of_match), | 517 | .of_match_table = of_match_ptr(omap_rtc_of_match), |
549 | }, | 518 | }, |
550 | .id_table = omap_rtc_devtype, | 519 | .id_table = omap_rtc_devtype, |
551 | }; | 520 | }; |
552 | 521 | ||
553 | static int __init rtc_init(void) | 522 | module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); |
554 | { | ||
555 | return platform_driver_probe(&omap_rtc_driver, omap_rtc_probe); | ||
556 | } | ||
557 | module_init(rtc_init); | ||
558 | |||
559 | static void __exit rtc_exit(void) | ||
560 | { | ||
561 | platform_driver_unregister(&omap_rtc_driver); | ||
562 | } | ||
563 | module_exit(rtc_exit); | ||
564 | 523 | ||
565 | MODULE_AUTHOR("George G. Davis (and others)"); | 524 | MODULE_AUTHOR("George G. Davis (and others)"); |
566 | MODULE_LICENSE("GPL"); | 525 | MODULE_LICENSE("GPL"); |