diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-02-15 07:51:37 -0500 |
---|---|---|
committer | Nicolas Ferre <nicolas.ferre@atmel.com> | 2012-02-23 08:57:57 -0500 |
commit | 205056a3ea33f5aca7adffa4584eb6572b1d3273 (patch) | |
tree | 1672d459205d815001b097ff951a55c8a1299b86 | |
parent | b55149529d265718a989b67468c4f03de0d3af7a (diff) |
ARM: at91/rtc-at91sam9: each SoC can select the RTT device to use
For the RTT as RTC driver rtc-at91sam9, the platform_device structure
is filled during SoC initialization. This will allow to convert this
RTC driver as a standard platform driver.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
-rw-r--r-- | arch/arm/mach-at91/at91sam9260_devices.c | 11 | ||||
-rw-r--r-- | arch/arm/mach-at91/at91sam9261_devices.c | 10 | ||||
-rw-r--r-- | arch/arm/mach-at91/at91sam9263_devices.c | 25 | ||||
-rw-r--r-- | arch/arm/mach-at91/at91sam9g45_devices.c | 10 | ||||
-rw-r--r-- | arch/arm/mach-at91/at91sam9rl_devices.c | 10 | ||||
-rw-r--r-- | drivers/rtc/rtc-at91sam9.c | 61 |
6 files changed, 75 insertions, 52 deletions
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c index b93a3376e7bb..2071017a475a 100644 --- a/arch/arm/mach-at91/at91sam9260_devices.c +++ b/arch/arm/mach-at91/at91sam9260_devices.c | |||
@@ -728,8 +728,19 @@ static struct platform_device at91sam9260_rtt_device = { | |||
728 | .num_resources = ARRAY_SIZE(rtt_resources), | 728 | .num_resources = ARRAY_SIZE(rtt_resources), |
729 | }; | 729 | }; |
730 | 730 | ||
731 | |||
732 | #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9) | ||
733 | static void __init at91_add_device_rtt_rtc(void) | ||
734 | { | ||
735 | at91sam9260_rtt_device.name = "rtc-at91sam9"; | ||
736 | } | ||
737 | #else | ||
738 | static void __init at91_add_device_rtt_rtc(void) {} | ||
739 | #endif | ||
740 | |||
731 | static void __init at91_add_device_rtt(void) | 741 | static void __init at91_add_device_rtt(void) |
732 | { | 742 | { |
743 | at91_add_device_rtt_rtc(); | ||
733 | platform_device_register(&at91sam9260_rtt_device); | 744 | platform_device_register(&at91sam9260_rtt_device); |
734 | } | 745 | } |
735 | 746 | ||
diff --git a/arch/arm/mach-at91/at91sam9261_devices.c b/arch/arm/mach-at91/at91sam9261_devices.c index 52c1f1a3819f..b3ceb97d722d 100644 --- a/arch/arm/mach-at91/at91sam9261_devices.c +++ b/arch/arm/mach-at91/at91sam9261_devices.c | |||
@@ -614,8 +614,18 @@ static struct platform_device at91sam9261_rtt_device = { | |||
614 | .num_resources = ARRAY_SIZE(rtt_resources), | 614 | .num_resources = ARRAY_SIZE(rtt_resources), |
615 | }; | 615 | }; |
616 | 616 | ||
617 | #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9) | ||
618 | static void __init at91_add_device_rtt_rtc(void) | ||
619 | { | ||
620 | at91sam9261_rtt_device.name = "rtc-at91sam9"; | ||
621 | } | ||
622 | #else | ||
623 | static void __init at91_add_device_rtt_rtc(void) {} | ||
624 | #endif | ||
625 | |||
617 | static void __init at91_add_device_rtt(void) | 626 | static void __init at91_add_device_rtt(void) |
618 | { | 627 | { |
628 | at91_add_device_rtt_rtc(); | ||
619 | platform_device_register(&at91sam9261_rtt_device); | 629 | platform_device_register(&at91sam9261_rtt_device); |
620 | } | 630 | } |
621 | 631 | ||
diff --git a/arch/arm/mach-at91/at91sam9263_devices.c b/arch/arm/mach-at91/at91sam9263_devices.c index 545826b16a87..b4a6adb39b22 100644 --- a/arch/arm/mach-at91/at91sam9263_devices.c +++ b/arch/arm/mach-at91/at91sam9263_devices.c | |||
@@ -992,8 +992,33 @@ static struct platform_device at91sam9263_rtt1_device = { | |||
992 | .num_resources = ARRAY_SIZE(rtt1_resources), | 992 | .num_resources = ARRAY_SIZE(rtt1_resources), |
993 | }; | 993 | }; |
994 | 994 | ||
995 | #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9) | ||
996 | static void __init at91_add_device_rtt_rtc(void) | ||
997 | { | ||
998 | struct platform_device *pdev; | ||
999 | |||
1000 | switch (CONFIG_RTC_DRV_AT91SAM9_RTT) { | ||
1001 | case 0: | ||
1002 | pdev = &at91sam9263_rtt0_device; | ||
1003 | break; | ||
1004 | case 1: | ||
1005 | pdev = &at91sam9263_rtt1_device; | ||
1006 | break; | ||
1007 | default: | ||
1008 | pr_err("at91sam9263: support only 2 RTT (%d)\n", | ||
1009 | CONFIG_RTC_DRV_AT91SAM9_RTT); | ||
1010 | return; | ||
1011 | } | ||
1012 | |||
1013 | pdev->name = "rtc-at91sam9"; | ||
1014 | } | ||
1015 | #else | ||
1016 | static void __init at91_add_device_rtt_rtc(void) {} | ||
1017 | #endif | ||
1018 | |||
995 | static void __init at91_add_device_rtt(void) | 1019 | static void __init at91_add_device_rtt(void) |
996 | { | 1020 | { |
1021 | at91_add_device_rtt_rtc(); | ||
997 | platform_device_register(&at91sam9263_rtt0_device); | 1022 | platform_device_register(&at91sam9263_rtt0_device); |
998 | platform_device_register(&at91sam9263_rtt1_device); | 1023 | platform_device_register(&at91sam9263_rtt1_device); |
999 | } | 1024 | } |
diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c b/arch/arm/mach-at91/at91sam9g45_devices.c index 8c036ff10bb6..81d1adf1d978 100644 --- a/arch/arm/mach-at91/at91sam9g45_devices.c +++ b/arch/arm/mach-at91/at91sam9g45_devices.c | |||
@@ -1204,8 +1204,18 @@ static struct platform_device at91sam9g45_rtt_device = { | |||
1204 | .num_resources = ARRAY_SIZE(rtt_resources), | 1204 | .num_resources = ARRAY_SIZE(rtt_resources), |
1205 | }; | 1205 | }; |
1206 | 1206 | ||
1207 | #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9) | ||
1208 | static void __init at91_add_device_rtt_rtc(void) | ||
1209 | { | ||
1210 | at91sam9g45_rtt_device.name = "rtc-at91sam9"; | ||
1211 | } | ||
1212 | #else | ||
1213 | static void __init at91_add_device_rtt_rtc(void) {} | ||
1214 | #endif | ||
1215 | |||
1207 | static void __init at91_add_device_rtt(void) | 1216 | static void __init at91_add_device_rtt(void) |
1208 | { | 1217 | { |
1218 | at91_add_device_rtt_rtc(); | ||
1209 | platform_device_register(&at91sam9g45_rtt_device); | 1219 | platform_device_register(&at91sam9g45_rtt_device); |
1210 | } | 1220 | } |
1211 | 1221 | ||
diff --git a/arch/arm/mach-at91/at91sam9rl_devices.c b/arch/arm/mach-at91/at91sam9rl_devices.c index 936cf20bc54f..dd248c837a77 100644 --- a/arch/arm/mach-at91/at91sam9rl_devices.c +++ b/arch/arm/mach-at91/at91sam9rl_devices.c | |||
@@ -693,8 +693,18 @@ static struct platform_device at91sam9rl_rtt_device = { | |||
693 | .num_resources = ARRAY_SIZE(rtt_resources), | 693 | .num_resources = ARRAY_SIZE(rtt_resources), |
694 | }; | 694 | }; |
695 | 695 | ||
696 | #if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9) | ||
697 | static void __init at91_add_device_rtt_rtc(void) | ||
698 | { | ||
699 | at91sam9rl_rtt_device.name = "rtc-at91sam9"; | ||
700 | } | ||
701 | #else | ||
702 | static void __init at91_add_device_rtt_rtc(void) {} | ||
703 | #endif | ||
704 | |||
696 | static void __init at91_add_device_rtt(void) | 705 | static void __init at91_add_device_rtt(void) |
697 | { | 706 | { |
707 | at91_add_device_rtt_rtc(); | ||
698 | platform_device_register(&at91sam9rl_rtt_device); | 708 | platform_device_register(&at91sam9rl_rtt_device); |
699 | } | 709 | } |
700 | 710 | ||
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c index a3ad957507dc..65896a3a352f 100644 --- a/drivers/rtc/rtc-at91sam9.c +++ b/drivers/rtc/rtc-at91sam9.c | |||
@@ -287,7 +287,7 @@ static const struct rtc_class_ops at91_rtc_ops = { | |||
287 | /* | 287 | /* |
288 | * Initialize and install RTC driver | 288 | * Initialize and install RTC driver |
289 | */ | 289 | */ |
290 | static int __init at91_rtc_probe(struct platform_device *pdev) | 290 | static int __devinit at91_rtc_probe(struct platform_device *pdev) |
291 | { | 291 | { |
292 | struct resource *r; | 292 | struct resource *r; |
293 | struct sam9_rtc *rtc; | 293 | struct sam9_rtc *rtc; |
@@ -360,7 +360,7 @@ fail: | |||
360 | /* | 360 | /* |
361 | * Disable and remove the RTC driver | 361 | * Disable and remove the RTC driver |
362 | */ | 362 | */ |
363 | static int __exit at91_rtc_remove(struct platform_device *pdev) | 363 | static int __devexit at91_rtc_remove(struct platform_device *pdev) |
364 | { | 364 | { |
365 | struct sam9_rtc *rtc = platform_get_drvdata(pdev); | 365 | struct sam9_rtc *rtc = platform_get_drvdata(pdev); |
366 | u32 mr = rtt_readl(rtc, MR); | 366 | u32 mr = rtt_readl(rtc, MR); |
@@ -433,63 +433,20 @@ static int at91_rtc_resume(struct platform_device *pdev) | |||
433 | #endif | 433 | #endif |
434 | 434 | ||
435 | static struct platform_driver at91_rtc_driver = { | 435 | static struct platform_driver at91_rtc_driver = { |
436 | .driver.name = "rtc-at91sam9", | 436 | .probe = at91_rtc_probe, |
437 | .driver.owner = THIS_MODULE, | 437 | .remove = __devexit_p(at91_rtc_remove), |
438 | .remove = __exit_p(at91_rtc_remove), | ||
439 | .shutdown = at91_rtc_shutdown, | 438 | .shutdown = at91_rtc_shutdown, |
440 | .suspend = at91_rtc_suspend, | 439 | .suspend = at91_rtc_suspend, |
441 | .resume = at91_rtc_resume, | 440 | .resume = at91_rtc_resume, |
441 | .driver = { | ||
442 | .name = "rtc-at91sam9", | ||
443 | .owner = THIS_MODULE, | ||
444 | }, | ||
442 | }; | 445 | }; |
443 | 446 | ||
444 | /* Chips can have more than one RTT module, and they can be used for more | ||
445 | * than just RTCs. So we can't just register as "the" RTT driver. | ||
446 | * | ||
447 | * A normal approach in such cases is to create a library to allocate and | ||
448 | * free the modules. Here we just use bus_find_device() as like such a | ||
449 | * library, binding directly ... no runtime "library" footprint is needed. | ||
450 | */ | ||
451 | static int __init at91_rtc_match(struct device *dev, void *v) | ||
452 | { | ||
453 | struct platform_device *pdev = to_platform_device(dev); | ||
454 | int ret; | ||
455 | |||
456 | /* continue searching if this isn't the RTT we need */ | ||
457 | if (strcmp("at91_rtt", pdev->name) != 0 | ||
458 | || pdev->id != CONFIG_RTC_DRV_AT91SAM9_RTT) | ||
459 | goto fail; | ||
460 | |||
461 | /* else we found it ... but fail unless we can bind to the RTC driver */ | ||
462 | if (dev->driver) { | ||
463 | dev_dbg(dev, "busy, can't use as RTC!\n"); | ||
464 | goto fail; | ||
465 | } | ||
466 | dev->driver = &at91_rtc_driver.driver; | ||
467 | if (device_attach(dev) == 0) { | ||
468 | dev_dbg(dev, "can't attach RTC!\n"); | ||
469 | goto fail; | ||
470 | } | ||
471 | ret = at91_rtc_probe(pdev); | ||
472 | if (ret == 0) | ||
473 | return true; | ||
474 | |||
475 | dev_dbg(dev, "RTC probe err %d!\n", ret); | ||
476 | fail: | ||
477 | return false; | ||
478 | } | ||
479 | |||
480 | static int __init at91_rtc_init(void) | 447 | static int __init at91_rtc_init(void) |
481 | { | 448 | { |
482 | int status; | 449 | return platform_driver_register(&at91_rtc_driver); |
483 | struct device *rtc; | ||
484 | |||
485 | status = platform_driver_register(&at91_rtc_driver); | ||
486 | if (status) | ||
487 | return status; | ||
488 | rtc = bus_find_device(&platform_bus_type, NULL, | ||
489 | NULL, at91_rtc_match); | ||
490 | if (!rtc) | ||
491 | platform_driver_unregister(&at91_rtc_driver); | ||
492 | return rtc ? 0 : -ENODEV; | ||
493 | } | 450 | } |
494 | module_init(at91_rtc_init); | 451 | module_init(at91_rtc_init); |
495 | 452 | ||