blob: bffc5713e16f1599e1c40b08139a6ac9a40c50c0 [file] [log] [blame]
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +01001/*
2 * PS3 RTC Driver
3 *
4 * Copyright 2009 Sony Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.
17 * If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <linux/rtc.h>
24
25#include <asm/lv1call.h>
26#include <asm/ps3.h>
27
28
29static u64 read_rtc(void)
30{
31 int result;
32 u64 rtc_val;
33 u64 tb_val;
34
35 result = lv1_get_rtc(&rtc_val, &tb_val);
36 BUG_ON(result);
37
38 return rtc_val;
39}
40
41static int ps3_get_time(struct device *dev, struct rtc_time *tm)
42{
Alexandre Belloni70c805c2019-03-20 13:44:25 +010043 rtc_time64_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
Alexandre Belloniab626702018-02-19 16:23:55 +010044 return 0;
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010045}
46
47static int ps3_set_time(struct device *dev, struct rtc_time *tm)
48{
Alexandre Belloni70c805c2019-03-20 13:44:25 +010049 ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010050 return 0;
51}
52
53static const struct rtc_class_ops ps3_rtc_ops = {
54 .read_time = ps3_get_time,
55 .set_time = ps3_set_time,
56};
57
58static int __init ps3_rtc_probe(struct platform_device *dev)
59{
60 struct rtc_device *rtc;
61
Jingoo Han9dc37c32013-04-29 16:19:44 -070062 rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops,
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010063 THIS_MODULE);
64 if (IS_ERR(rtc))
65 return PTR_ERR(rtc);
66
67 platform_set_drvdata(dev, rtc);
68 return 0;
69}
70
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010071static struct platform_driver ps3_rtc_driver = {
72 .driver = {
73 .name = "rtc-ps3",
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010074 },
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010075};
76
Jingoo Han050bf1e2013-04-29 16:18:48 -070077module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010078
79MODULE_AUTHOR("Sony Corporation");
80MODULE_LICENSE("GPL");
81MODULE_DESCRIPTION("ps3 RTC driver");
82MODULE_ALIAS("platform:rtc-ps3");