powerpc/ps3: Add rtc-ps3
authorGeert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Tue, 24 Feb 2009 13:04:20 +0000 (14:04 +0100)
committerKyle McMartin <kyle@mcmartin.ca>
Thu, 2 Apr 2009 01:05:32 +0000 (01:05 +0000)
Create a real RTC driver for PS3, and unhook the deprecated
ppc_md.[gs]et_rtc_time.

Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Acked-by: Alessandro Zummo <a.zummo@towertech.it>
Acked-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Kyle McMartin <kyle@mcmartin.ca>
arch/powerpc/include/asm/ps3.h
arch/powerpc/platforms/ps3/os-area.c
arch/powerpc/platforms/ps3/platform.h
arch/powerpc/platforms/ps3/setup.c
arch/powerpc/platforms/ps3/time.c
drivers/rtc/Kconfig
drivers/rtc/Makefile
drivers/rtc/rtc-ps3.c [new file with mode: 0644]

index 67f1812698d2703e02cad2c561fd1d0e6c6d84b2..cdb6fd814de8880541d2c4130b33ea7e7b9f6234 100644 (file)
@@ -50,6 +50,9 @@ enum ps3_param_av_multi_out {
 
 enum ps3_param_av_multi_out ps3_os_area_get_av_multi_out(void);
 
+extern u64 ps3_os_area_get_rtc_diff(void);
+extern void ps3_os_area_set_rtc_diff(u64 rtc_diff);
+
 /* dma routines */
 
 enum ps3_dma_page_size {
index e1c83c23b435a2f8032093def6afa1a844d5d1ab..86e392b1b049ab6855ac8b8f077a26b84a77132b 100644 (file)
@@ -808,6 +808,7 @@ u64 ps3_os_area_get_rtc_diff(void)
 {
        return saved_params.rtc_diff;
 }
+EXPORT_SYMBOL(ps3_os_area_get_rtc_diff);
 
 /**
  * ps3_os_area_set_rtc_diff - Set the rtc diff value.
@@ -823,6 +824,7 @@ void ps3_os_area_set_rtc_diff(u64 rtc_diff)
                os_area_queue_work();
        }
 }
+EXPORT_SYMBOL(ps3_os_area_set_rtc_diff);
 
 /**
  * ps3_os_area_get_av_multi_out - Returns the default video mode.
index 235c13ebacd9a459b2a584de9d536828e945c690..136aa0637d9c0bbc67e10f13b98d96f5540aa288 100644 (file)
@@ -64,8 +64,6 @@ int ps3_set_rtc_time(struct rtc_time *time);
 
 void __init ps3_os_area_save_params(void);
 void __init ps3_os_area_init(void);
-u64 ps3_os_area_get_rtc_diff(void);
-void ps3_os_area_set_rtc_diff(u64 rtc_diff);
 
 /* spu */
 
index 3331ccbb8d389c6d76dd4c548beeb3c30d6404b8..66181821322acc2dba892e26ef3a52182a3ca894 100644 (file)
@@ -270,8 +270,6 @@ define_machine(ps3) {
        .init_IRQ                       = ps3_init_IRQ,
        .panic                          = ps3_panic,
        .get_boot_time                  = ps3_get_boot_time,
-       .set_rtc_time                   = ps3_set_rtc_time,
-       .get_rtc_time                   = ps3_get_rtc_time,
        .set_dabr                       = ps3_set_dabr,
        .calibrate_decr                 = ps3_calibrate_decr,
        .progress                       = ps3_progress,
index d0daf7d6d3b26407d5ec87c0d5caef127943c4fe..b178a1e66c915e8ab6e85b0eec51830b6a05adf1 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/platform_device.h>
 
 #include <asm/rtc.h>
 #include <asm/lv1call.h>
@@ -74,23 +75,20 @@ static u64 read_rtc(void)
        return rtc_val;
 }
 
-int ps3_set_rtc_time(struct rtc_time *tm)
+unsigned long __init ps3_get_boot_time(void)
 {
-       u64 now = mktime(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
-               tm->tm_hour, tm->tm_min, tm->tm_sec);
-
-       ps3_os_area_set_rtc_diff(now - read_rtc());
-       return 0;
+       return read_rtc() + ps3_os_area_get_rtc_diff();
 }
 
-void ps3_get_rtc_time(struct rtc_time *tm)
+static int __init ps3_rtc_init(void)
 {
-       to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
-       tm->tm_year -= 1900;
-       tm->tm_mon -= 1;
-}
+       struct platform_device *pdev;
 
-unsigned long __init ps3_get_boot_time(void)
-{
-       return read_rtc() + ps3_os_area_get_rtc_diff();
+       pdev = platform_device_register_simple("rtc-ps3", -1, NULL, 0);
+       if (IS_ERR(pdev))
+               return PTR_ERR(pdev);
+
+       return 0;
 }
+
+module_init(ps3_rtc_init);
index fa66d10dd5a009746c29eed10fee0bc109435fcf..b072826c9ee1226ebf711f99ffdb121c2017705b 100644 (file)
@@ -741,4 +741,13 @@ config RTC_DRV_MV
          This driver can also be built as a module. If so, the module
          will be called rtc-mv.
 
+config RTC_DRV_PS3
+       tristate "PS3 RTC"
+       depends on PPC_PS3
+       help
+         If you say yes here you will get support for the RTC on PS3.
+
+         This driver can also be built as a module. If so, the module
+         will be called rtc-ps3.
+
 endif # RTC_CLASS
index 2b022f19a6ed48346b614f00366b8301ecb1c4a5..6c0639a14f09446d09de01f42a8a8a74314a95c5 100644 (file)
@@ -76,3 +76,4 @@ obj-$(CONFIG_RTC_DRV_VR41XX)  += rtc-vr41xx.o
 obj-$(CONFIG_RTC_DRV_WM8350)   += rtc-wm8350.o
 obj-$(CONFIG_RTC_DRV_X1205)    += rtc-x1205.o
 obj-$(CONFIG_RTC_DRV_PCF50633) += rtc-pcf50633.o
+obj-$(CONFIG_RTC_DRV_PS3)      += rtc-ps3.o
diff --git a/drivers/rtc/rtc-ps3.c b/drivers/rtc/rtc-ps3.c
new file mode 100644 (file)
index 0000000..968133c
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * PS3 RTC Driver
+ *
+ * Copyright 2009 Sony Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+#include <asm/lv1call.h>
+#include <asm/ps3.h>
+
+
+static u64 read_rtc(void)
+{
+       int result;
+       u64 rtc_val;
+       u64 tb_val;
+
+       result = lv1_get_rtc(&rtc_val, &tb_val);
+       BUG_ON(result);
+
+       return rtc_val;
+}
+
+static int ps3_get_time(struct device *dev, struct rtc_time *tm)
+{
+       rtc_time_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
+       return rtc_valid_tm(tm);
+}
+
+static int ps3_set_time(struct device *dev, struct rtc_time *tm)
+{
+       unsigned long now;
+
+       rtc_tm_to_time(tm, &now);
+       ps3_os_area_set_rtc_diff(now - read_rtc());
+       return 0;
+}
+
+static const struct rtc_class_ops ps3_rtc_ops = {
+       .read_time = ps3_get_time,
+       .set_time = ps3_set_time,
+};
+
+static int __init ps3_rtc_probe(struct platform_device *dev)
+{
+       struct rtc_device *rtc;
+
+       rtc = rtc_device_register("rtc-ps3", &dev->dev, &ps3_rtc_ops,
+                                 THIS_MODULE);
+       if (IS_ERR(rtc))
+               return PTR_ERR(rtc);
+
+       platform_set_drvdata(dev, rtc);
+       return 0;
+}
+
+static int __exit ps3_rtc_remove(struct platform_device *dev)
+{
+       rtc_device_unregister(platform_get_drvdata(dev));
+       return 0;
+}
+
+static struct platform_driver ps3_rtc_driver = {
+       .driver = {
+               .name = "rtc-ps3",
+               .owner = THIS_MODULE,
+       },
+       .remove = __exit_p(ps3_rtc_remove),
+};
+
+static int __init ps3_rtc_init(void)
+{
+       return platform_driver_probe(&ps3_rtc_driver, ps3_rtc_probe);
+}
+
+static void __exit ps3_rtc_fini(void)
+{
+       platform_driver_unregister(&ps3_rtc_driver);
+}
+
+module_init(ps3_rtc_init);
+module_exit(ps3_rtc_fini);
+
+MODULE_AUTHOR("Sony Corporation");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("ps3 RTC driver");
+MODULE_ALIAS("platform:rtc-ps3");