@@ -1896,4 +1896,14 @@ config RTC_DRV_WILCO_EC
This can also be built as a module. If so, the module will
be named "rtc_wilco_ec".
+config RTC_DRV_PS2
+ tristate "PlayStation 2 RTC"
+ depends on SONY_PS2
+ default y
+ help
+ Say yes here to get support for the PlayStation 2 real-time clock.
+
+ This driver can also be built as a module. If so, the module
+ will be called rtc-ps2.
+
endif # RTC_CLASS
@@ -130,6 +130,7 @@ obj-$(CONFIG_RTC_DRV_PIC32) += rtc-pic32.o
obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o
obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
obj-$(CONFIG_RTC_DRV_PM8XXX) += rtc-pm8xxx.o
+obj-$(CONFIG_RTC_DRV_PS2) += rtc-ps2.o
obj-$(CONFIG_RTC_DRV_PS3) += rtc-ps3.o
obj-$(CONFIG_RTC_DRV_PUV3) += rtc-puv3.o
obj-$(CONFIG_RTC_DRV_PXA) += rtc-pxa.o
new file mode 100644
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * PlayStation 2 real-time clock (RTC)
+ *
+ * Copyright (C) 2019 Fredrik Noring
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/rtc.h>
+
+#include "asm/mach-ps2/scmd.h"
+
+#define DRVNAME "rtc-ps2"
+
+static int read_time(struct device *dev, struct rtc_time *tm)
+{
+ time64_t t;
+ int err = scmd_read_rtc(&t);
+
+ if (!err)
+ rtc_time64_to_tm(t, tm);
+
+ return err;
+}
+
+static int set_time(struct device *dev, struct rtc_time *tm)
+{
+ return scmd_set_rtc(rtc_tm_to_time64(tm));
+}
+
+static const struct rtc_class_ops ps2_rtc_ops = {
+ .read_time = read_time,
+ .set_time = set_time,
+};
+
+static int ps2_rtc_probe(struct platform_device *pdev)
+{
+ struct rtc_device *rtc;
+
+ rtc = devm_rtc_device_register(&pdev->dev,
+ DRVNAME, &ps2_rtc_ops, THIS_MODULE);
+ if (IS_ERR(rtc))
+ return PTR_ERR(rtc);
+
+ rtc->uie_unsupported = 1;
+
+ return 0;
+}
+
+static struct platform_driver ps2_rtc_driver = {
+ .probe = ps2_rtc_probe,
+ .driver = {
+ .name = DRVNAME,
+ },
+};
+
+static int __init ps2_rtc_init(void)
+{
+ return platform_driver_register(&ps2_rtc_driver);
+}
+
+static void __exit ps2_rtc_exit(void)
+{
+ platform_driver_unregister(&ps2_rtc_driver);
+}
+
+module_init(ps2_rtc_init);
+module_exit(ps2_rtc_exit);
+
+MODULE_DESCRIPTION("PlayStation 2 real-time clock (RTC)");
+MODULE_AUTHOR("Fredrik Noring");
+MODULE_LICENSE("GPL");
Signed-off-by: Fredrik Noring <noring@nocrew.org> --- drivers/rtc/Kconfig | 10 ++++++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-ps2.c | 74 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 drivers/rtc/rtc-ps2.c