]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
parisc: add rtc platform driver
authorKyle McMartin <kyle@mcmartin.ca>
Wed, 10 Sep 2008 14:24:07 +0000 (14:24 +0000)
committerKyle McMartin <kyle@hera.kernel.org>
Fri, 10 Oct 2008 16:32:30 +0000 (16:32 +0000)
Signed-off-by: Kyle McMartin <kyle@mcmartin.ca>
arch/parisc/Kconfig
arch/parisc/kernel/time.c
drivers/rtc/Kconfig
drivers/rtc/Makefile
drivers/rtc/rtc-parisc.c [new file with mode: 0644]

index a7d4fd353c2b06fcaa8c7d6e1306e71b14ad440f..0a8ac703dbec296366a922de725c14d9dcf1c29d 100644 (file)
@@ -9,6 +9,8 @@ config PARISC
        def_bool y
        select HAVE_IDE
        select HAVE_OPROFILE
+       select RTC_CLASS
+       select RTC_DRV_PARISC
        help
          The PA-RISC microprocessor is designed by Hewlett-Packard and used
          in many of their workstations & servers (HP9000 700 and 800 series,
index 24be86bba94d6bdf93618109bb490bf6fbe68205..4d09203bc69307275afcb92f5f3a53d2bdff5057 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/smp.h>
 #include <linux/profile.h>
 #include <linux/clocksource.h>
+#include <linux/platform_device.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -215,6 +216,24 @@ void __init start_cpu_itimer(void)
        cpu_data[cpu].it_value = next_tick;
 }
 
+struct platform_device rtc_parisc_dev = {
+       .name = "rtc-parisc",
+       .id = -1,
+};
+
+static int __init rtc_init(void)
+{
+       int ret;
+
+       ret = platform_device_register(&rtc_parisc_dev);
+       if (ret < 0)
+               printk(KERN_ERR "unable to register rtc device...\n");
+
+       /* not necessarily an error */
+       return 0;
+}
+module_init(rtc_init);
+
 void __init time_init(void)
 {
        static struct pdc_tod tod_data;
@@ -245,4 +264,3 @@ void __init time_init(void)
                xtime.tv_nsec = 0;
        }
 }
-
index 9a9755c92fada3268f03f69ee7270964bf322818..30d40fe194a8476e87edd3c8a90b704aa730f5cb 100644 (file)
@@ -575,6 +575,14 @@ config RTC_DRV_RS5C313
        help
          If you say yes here you get support for the Ricoh RS5C313 RTC chips.
 
+config RTC_DRV_PARISC
+       tristate "PA-RISC firmware RTC support"
+       depends on PARISC
+       help
+         Say Y or M here to enable RTC support on PA-RISC systems using
+         firmware calls. If you do not know what you are doing, you should
+         just say Y.
+
 config RTC_DRV_PPC
        tristate "PowerPC machine dependent RTC support"
        depends on PPC_MERGE
index 18622ef84cab0c4f48e15aa437edccff357136e4..180ddacde730f6e024d6734831a5fe3bfd0daa85 100644 (file)
@@ -45,6 +45,7 @@ obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
 obj-$(CONFIG_RTC_DRV_PCF8583)  += rtc-pcf8583.o
 obj-$(CONFIG_RTC_DRV_PL030)    += rtc-pl030.o
 obj-$(CONFIG_RTC_DRV_PL031)    += rtc-pl031.o
+obj-$(CONFIG_RTC_DRV_PARISC)   += rtc-parisc.o
 obj-$(CONFIG_RTC_DRV_PPC)      += rtc-ppc.o
 obj-$(CONFIG_RTC_DRV_R9701)    += rtc-r9701.o
 obj-$(CONFIG_RTC_DRV_RS5C313)  += rtc-rs5c313.o
diff --git a/drivers/rtc/rtc-parisc.c b/drivers/rtc/rtc-parisc.c
new file mode 100644 (file)
index 0000000..346d633
--- /dev/null
@@ -0,0 +1,111 @@
+/* rtc-parisc: RTC for HP PA-RISC firmware
+ *
+ * Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/time.h>
+#include <linux/platform_device.h>
+
+#include <asm/rtc.h>
+
+/* as simple as can be, and no simpler. */
+struct parisc_rtc {
+       struct rtc_device *rtc;
+       spinlock_t lock;
+};
+
+static int parisc_get_time(struct device *dev, struct rtc_time *tm)
+{
+       struct parisc_rtc *p = dev_get_drvdata(dev);
+       unsigned long flags, ret;
+
+       spin_lock_irqsave(&p->lock, flags);
+       ret = get_rtc_time(tm);
+       spin_unlock_irqrestore(&p->lock, flags);
+
+       if (ret & RTC_BATT_BAD)
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
+static int parisc_set_time(struct device *dev, struct rtc_time *tm)
+{
+       struct parisc_rtc *p = dev_get_drvdata(dev);
+       unsigned long flags, ret;
+
+       spin_lock_irqsave(&p->lock, flags);
+       ret = set_rtc_time(tm);
+       spin_unlock_irqrestore(&p->lock, flags);
+
+       if (ret < 0)
+               return -EOPNOTSUPP;
+
+       return 0;
+}
+
+static const struct rtc_class_ops parisc_rtc_ops = {
+       .read_time = parisc_get_time,
+       .set_time = parisc_set_time,
+};
+
+static int __devinit parisc_rtc_probe(struct platform_device *dev)
+{
+       struct parisc_rtc *p;
+
+       p = kzalloc(sizeof (*p), GFP_KERNEL);
+       if (!p)
+               return -ENOMEM;
+
+       spin_lock_init(&p->lock);
+
+       p->rtc = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops,
+                                       THIS_MODULE);
+       if (IS_ERR(p->rtc)) {
+               int err = PTR_ERR(p->rtc);
+               kfree(p);
+               return err;
+       }
+
+       platform_set_drvdata(dev, p);
+
+       return 0;
+}
+
+static int __devexit parisc_rtc_remove(struct platform_device *dev)
+{
+       struct parisc_rtc *p = platform_get_drvdata(dev);
+
+       rtc_device_unregister(p->rtc);
+       kfree(p);
+
+       return 0;
+}
+
+static struct platform_driver parisc_rtc_driver = {
+       .driver = {
+               .name = "rtc-parisc",
+               .owner = THIS_MODULE,
+       },
+       .probe = parisc_rtc_probe,
+       .remove = __devexit_p(parisc_rtc_remove),
+};
+
+static int __init parisc_rtc_init(void)
+{
+       return platform_driver_register(&parisc_rtc_driver);
+}
+
+static void __exit parisc_rtc_fini(void)
+{
+       platform_driver_unregister(&parisc_rtc_driver);
+}
+
+module_init(parisc_rtc_init);
+module_exit(parisc_rtc_fini);
+
+MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("HP PA-RISC RTC driver");