0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/kernel.h>
0009 #include <linux/module.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/rtc.h>
0012
0013 #include <asm/lv1call.h>
0014 #include <asm/ps3.h>
0015
0016
0017 static u64 read_rtc(void)
0018 {
0019 int result;
0020 u64 rtc_val;
0021 u64 tb_val;
0022
0023 result = lv1_get_rtc(&rtc_val, &tb_val);
0024 BUG_ON(result);
0025
0026 return rtc_val;
0027 }
0028
0029 static int ps3_get_time(struct device *dev, struct rtc_time *tm)
0030 {
0031 rtc_time64_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
0032 return 0;
0033 }
0034
0035 static int ps3_set_time(struct device *dev, struct rtc_time *tm)
0036 {
0037 ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
0038 return 0;
0039 }
0040
0041 static const struct rtc_class_ops ps3_rtc_ops = {
0042 .read_time = ps3_get_time,
0043 .set_time = ps3_set_time,
0044 };
0045
0046 static int __init ps3_rtc_probe(struct platform_device *dev)
0047 {
0048 struct rtc_device *rtc;
0049
0050 rtc = devm_rtc_allocate_device(&dev->dev);
0051 if (IS_ERR(rtc))
0052 return PTR_ERR(rtc);
0053
0054 rtc->ops = &ps3_rtc_ops;
0055 rtc->range_max = U64_MAX;
0056
0057 platform_set_drvdata(dev, rtc);
0058
0059 return devm_rtc_register_device(rtc);
0060 }
0061
0062 static struct platform_driver ps3_rtc_driver = {
0063 .driver = {
0064 .name = "rtc-ps3",
0065 },
0066 };
0067
0068 module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
0069
0070 MODULE_AUTHOR("Sony Corporation");
0071 MODULE_LICENSE("GPL");
0072 MODULE_DESCRIPTION("ps3 RTC driver");
0073 MODULE_ALIAS("platform:rtc-ps3");