blob: 6b098734c7155f35ed5d29e2b58b30491d0768f6 [file] [log] [blame]
Alexandre Bellonie85b9302019-03-20 13:44:26 +01001// SPDX-License-Identifier: GPL-2.0
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +01002/*
3 * PS3 RTC Driver
4 *
5 * Copyright 2009 Sony Corporation
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +01006 */
7
8#include <linux/kernel.h>
9#include <linux/module.h>
10#include <linux/platform_device.h>
11#include <linux/rtc.h>
12
13#include <asm/lv1call.h>
14#include <asm/ps3.h>
15
16
17static u64 read_rtc(void)
18{
19 int result;
20 u64 rtc_val;
21 u64 tb_val;
22
23 result = lv1_get_rtc(&rtc_val, &tb_val);
24 BUG_ON(result);
25
26 return rtc_val;
27}
28
29static int ps3_get_time(struct device *dev, struct rtc_time *tm)
30{
Alexandre Belloni70c805c2019-03-20 13:44:25 +010031 rtc_time64_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
Alexandre Belloniab626702018-02-19 16:23:55 +010032 return 0;
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010033}
34
35static int ps3_set_time(struct device *dev, struct rtc_time *tm)
36{
Alexandre Belloni70c805c2019-03-20 13:44:25 +010037 ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010038 return 0;
39}
40
41static const struct rtc_class_ops ps3_rtc_ops = {
42 .read_time = ps3_get_time,
43 .set_time = ps3_set_time,
44};
45
46static int __init ps3_rtc_probe(struct platform_device *dev)
47{
48 struct rtc_device *rtc;
49
Alexandre Belloni0b5e47b2019-03-20 13:44:27 +010050 rtc = devm_rtc_allocate_device(&dev->dev);
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010051 if (IS_ERR(rtc))
52 return PTR_ERR(rtc);
53
Alexandre Belloni0b5e47b2019-03-20 13:44:27 +010054 rtc->ops = &ps3_rtc_ops;
Alexandre Belloni72dd89c2019-03-20 13:44:28 +010055 rtc->range_max = U64_MAX;
Alexandre Belloni0b5e47b2019-03-20 13:44:27 +010056
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010057 platform_set_drvdata(dev, rtc);
Alexandre Belloni0b5e47b2019-03-20 13:44:27 +010058
Bartosz Golaszewskifdcfd852020-11-09 17:34:08 +010059 return devm_rtc_register_device(rtc);
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010060}
61
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010062static struct platform_driver ps3_rtc_driver = {
63 .driver = {
64 .name = "rtc-ps3",
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010065 },
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010066};
67
Jingoo Han050bf1e2013-04-29 16:18:48 -070068module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
Geert Uytterhoeven0b5f0372009-02-24 14:04:20 +010069
70MODULE_AUTHOR("Sony Corporation");
71MODULE_LICENSE("GPL");
72MODULE_DESCRIPTION("ps3 RTC driver");
73MODULE_ALIAS("platform:rtc-ps3");