Linux Audio

Check our new training course

Loading...
v6.13.7
 1// SPDX-License-Identifier: GPL-2.0
 2/*
 3 * PS3 RTC Driver
 4 *
 5 * Copyright 2009 Sony Corporation
 
 
 
 
 
 
 
 
 
 
 
 
 
 6 */
 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{
31	rtc_time64_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
32	return 0;
33}
34
35static int ps3_set_time(struct device *dev, struct rtc_time *tm)
36{
37	ps3_os_area_set_rtc_diff(rtc_tm_to_time64(tm) - read_rtc());
 
 
 
38	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
50	rtc = devm_rtc_allocate_device(&dev->dev);
 
51	if (IS_ERR(rtc))
52		return PTR_ERR(rtc);
53
54	rtc->ops = &ps3_rtc_ops;
55	rtc->range_max = U64_MAX;
56
57	platform_set_drvdata(dev, rtc);
58
59	return devm_rtc_register_device(rtc);
60}
61
62static struct platform_driver ps3_rtc_driver = {
63	.driver = {
64		.name = "rtc-ps3",
65	},
66};
67
68module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
69
70MODULE_AUTHOR("Sony Corporation");
71MODULE_LICENSE("GPL");
72MODULE_DESCRIPTION("ps3 RTC driver");
73MODULE_ALIAS("platform:rtc-ps3");
v4.17
 
 1/*
 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{
43	rtc_time_to_tm(read_rtc() + ps3_os_area_get_rtc_diff(), tm);
44	return 0;
45}
46
47static int ps3_set_time(struct device *dev, struct rtc_time *tm)
48{
49	unsigned long now;
50
51	rtc_tm_to_time(tm, &now);
52	ps3_os_area_set_rtc_diff(now - read_rtc());
53	return 0;
54}
55
56static const struct rtc_class_ops ps3_rtc_ops = {
57	.read_time = ps3_get_time,
58	.set_time = ps3_set_time,
59};
60
61static int __init ps3_rtc_probe(struct platform_device *dev)
62{
63	struct rtc_device *rtc;
64
65	rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops,
66				  THIS_MODULE);
67	if (IS_ERR(rtc))
68		return PTR_ERR(rtc);
69
 
 
 
70	platform_set_drvdata(dev, rtc);
71	return 0;
 
72}
73
74static struct platform_driver ps3_rtc_driver = {
75	.driver = {
76		.name = "rtc-ps3",
77	},
78};
79
80module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
81
82MODULE_AUTHOR("Sony Corporation");
83MODULE_LICENSE("GPL");
84MODULE_DESCRIPTION("ps3 RTC driver");
85MODULE_ALIAS("platform:rtc-ps3");