]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
ARM: at91/rtc-at91sam9: each SoC can select the RTT device to use
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Wed, 15 Feb 2012 12:51:37 +0000 (20:51 +0800)
committerNicolas Ferre <nicolas.ferre@atmel.com>
Thu, 23 Feb 2012 13:57:57 +0000 (14:57 +0100)
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>
arch/arm/mach-at91/at91sam9260_devices.c
arch/arm/mach-at91/at91sam9261_devices.c
arch/arm/mach-at91/at91sam9263_devices.c
arch/arm/mach-at91/at91sam9g45_devices.c
arch/arm/mach-at91/at91sam9rl_devices.c
drivers/rtc/rtc-at91sam9.c

index b93a3376e7bb88ce77e8284a14d5d2a8f4942b32..2071017a475a7f99e56e75fd404aa12bf04f7cec 100644 (file)
@@ -728,8 +728,19 @@ static struct platform_device at91sam9260_rtt_device = {
        .num_resources  = ARRAY_SIZE(rtt_resources),
 };
 
+
+#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
+static void __init at91_add_device_rtt_rtc(void)
+{
+       at91sam9260_rtt_device.name = "rtc-at91sam9";
+}
+#else
+static void __init at91_add_device_rtt_rtc(void) {}
+#endif
+
 static void __init at91_add_device_rtt(void)
 {
+       at91_add_device_rtt_rtc();
        platform_device_register(&at91sam9260_rtt_device);
 }
 
index 52c1f1a3819fbc994351917f6b3f42d87356aa9f..b3ceb97d722df0772c5d38a2c590779e3a2c143d 100644 (file)
@@ -614,8 +614,18 @@ static struct platform_device at91sam9261_rtt_device = {
        .num_resources  = ARRAY_SIZE(rtt_resources),
 };
 
+#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
+static void __init at91_add_device_rtt_rtc(void)
+{
+       at91sam9261_rtt_device.name = "rtc-at91sam9";
+}
+#else
+static void __init at91_add_device_rtt_rtc(void) {}
+#endif
+
 static void __init at91_add_device_rtt(void)
 {
+       at91_add_device_rtt_rtc();
        platform_device_register(&at91sam9261_rtt_device);
 }
 
index 545826b16a87421171dd5e8bbd802905f06a40d0..b4a6adb39b224fc49b650e5fee49af56274cffe2 100644 (file)
@@ -992,8 +992,33 @@ static struct platform_device at91sam9263_rtt1_device = {
        .num_resources  = ARRAY_SIZE(rtt1_resources),
 };
 
+#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
+static void __init at91_add_device_rtt_rtc(void)
+{
+       struct platform_device *pdev;
+
+       switch (CONFIG_RTC_DRV_AT91SAM9_RTT) {
+       case 0:
+               pdev = &at91sam9263_rtt0_device;
+               break;
+       case 1:
+               pdev = &at91sam9263_rtt1_device;
+               break;
+       default:
+               pr_err("at91sam9263: support only 2 RTT (%d)\n",
+                        CONFIG_RTC_DRV_AT91SAM9_RTT);
+               return;
+       }
+
+       pdev->name = "rtc-at91sam9";
+}
+#else
+static void __init at91_add_device_rtt_rtc(void) {}
+#endif
+
 static void __init at91_add_device_rtt(void)
 {
+       at91_add_device_rtt_rtc();
        platform_device_register(&at91sam9263_rtt0_device);
        platform_device_register(&at91sam9263_rtt1_device);
 }
index 8c036ff10bb6a98bb82bef0f0a9c10f052b47c3c..81d1adf1d97882d699afb8426b57f7d7962818ba 100644 (file)
@@ -1204,8 +1204,18 @@ static struct platform_device at91sam9g45_rtt_device = {
        .num_resources  = ARRAY_SIZE(rtt_resources),
 };
 
+#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
+static void __init at91_add_device_rtt_rtc(void)
+{
+       at91sam9g45_rtt_device.name = "rtc-at91sam9";
+}
+#else
+static void __init at91_add_device_rtt_rtc(void) {}
+#endif
+
 static void __init at91_add_device_rtt(void)
 {
+       at91_add_device_rtt_rtc();
        platform_device_register(&at91sam9g45_rtt_device);
 }
 
index 936cf20bc54f085936dd638c2f6fbadb59f42d98..dd248c837a77ba2ac3961031e5ba00716bc41431 100644 (file)
@@ -693,8 +693,18 @@ static struct platform_device at91sam9rl_rtt_device = {
        .num_resources  = ARRAY_SIZE(rtt_resources),
 };
 
+#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
+static void __init at91_add_device_rtt_rtc(void)
+{
+       at91sam9rl_rtt_device.name = "rtc-at91sam9";
+}
+#else
+static void __init at91_add_device_rtt_rtc(void) {}
+#endif
+
 static void __init at91_add_device_rtt(void)
 {
+       at91_add_device_rtt_rtc();
        platform_device_register(&at91sam9rl_rtt_device);
 }
 
index a3ad957507dc9ebce9a360c85330e067d5576f9f..65896a3a352f0990047cc91bf628f10c9a886319 100644 (file)
@@ -287,7 +287,7 @@ static const struct rtc_class_ops at91_rtc_ops = {
 /*
  * Initialize and install RTC driver
  */
-static int __init at91_rtc_probe(struct platform_device *pdev)
+static int __devinit at91_rtc_probe(struct platform_device *pdev)
 {
        struct resource *r;
        struct sam9_rtc *rtc;
@@ -360,7 +360,7 @@ fail:
 /*
  * Disable and remove the RTC driver
  */
-static int __exit at91_rtc_remove(struct platform_device *pdev)
+static int __devexit at91_rtc_remove(struct platform_device *pdev)
 {
        struct sam9_rtc *rtc = platform_get_drvdata(pdev);
        u32             mr = rtt_readl(rtc, MR);
@@ -433,63 +433,20 @@ static int at91_rtc_resume(struct platform_device *pdev)
 #endif
 
 static struct platform_driver at91_rtc_driver = {
-       .driver.name    = "rtc-at91sam9",
-       .driver.owner   = THIS_MODULE,
-       .remove         = __exit_p(at91_rtc_remove),
+       .probe          = at91_rtc_probe,
+       .remove         = __devexit_p(at91_rtc_remove),
        .shutdown       = at91_rtc_shutdown,
        .suspend        = at91_rtc_suspend,
        .resume         = at91_rtc_resume,
+       .driver         = {
+               .name   = "rtc-at91sam9",
+               .owner  = THIS_MODULE,
+       },
 };
 
-/* Chips can have more than one RTT module, and they can be used for more
- * than just RTCs.  So we can't just register as "the" RTT driver.
- *
- * A normal approach in such cases is to create a library to allocate and
- * free the modules.  Here we just use bus_find_device() as like such a
- * library, binding directly ... no runtime "library" footprint is needed.
- */
-static int __init at91_rtc_match(struct device *dev, void *v)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       int ret;
-
-       /* continue searching if this isn't the RTT we need */
-       if (strcmp("at91_rtt", pdev->name) != 0
-                       || pdev->id != CONFIG_RTC_DRV_AT91SAM9_RTT)
-               goto fail;
-
-       /* else we found it ... but fail unless we can bind to the RTC driver */
-       if (dev->driver) {
-               dev_dbg(dev, "busy, can't use as RTC!\n");
-               goto fail;
-       }
-       dev->driver = &at91_rtc_driver.driver;
-       if (device_attach(dev) == 0) {
-               dev_dbg(dev, "can't attach RTC!\n");
-               goto fail;
-       }
-       ret = at91_rtc_probe(pdev);
-       if (ret == 0)
-               return true;
-
-       dev_dbg(dev, "RTC probe err %d!\n", ret);
-fail:
-       return false;
-}
-
 static int __init at91_rtc_init(void)
 {
-       int status;
-       struct device *rtc;
-
-       status = platform_driver_register(&at91_rtc_driver);
-       if (status)
-               return status;
-       rtc = bus_find_device(&platform_bus_type, NULL,
-                       NULL, at91_rtc_match);
-       if (!rtc)
-               platform_driver_unregister(&at91_rtc_driver);
-       return rtc ? 0 : -ENODEV;
+       return platform_driver_register(&at91_rtc_driver);
 }
 module_init(at91_rtc_init);