1 /* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems.
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/delay.h>
11 #include <linux/init.h>
12 #include <linux/rtc.h>
13 #include <linux/platform_device.h>
15 #include <asm/hypervisor.h>
17 static unsigned long hypervisor_get_time(void)
19 unsigned long ret
, time
;
23 ret
= sun4v_tod_get(&time
);
26 if (ret
== HV_EWOULDBLOCK
) {
31 pr_warn("tod_get() timed out.\n");
34 pr_warn("tod_get() not supported.\n");
38 static int sun4v_read_time(struct device
*dev
, struct rtc_time
*tm
)
40 rtc_time_to_tm(hypervisor_get_time(), tm
);
44 static int hypervisor_set_time(unsigned long secs
)
50 ret
= sun4v_tod_set(secs
);
53 if (ret
== HV_EWOULDBLOCK
) {
58 pr_warn("tod_set() timed out.\n");
61 pr_warn("tod_set() not supported.\n");
65 static int sun4v_set_time(struct device
*dev
, struct rtc_time
*tm
)
70 err
= rtc_tm_to_time(tm
, &secs
);
74 return hypervisor_set_time(secs
);
77 static const struct rtc_class_ops sun4v_rtc_ops
= {
78 .read_time
= sun4v_read_time
,
79 .set_time
= sun4v_set_time
,
82 static int __init
sun4v_rtc_probe(struct platform_device
*pdev
)
84 struct rtc_device
*rtc
;
86 rtc
= devm_rtc_device_register(&pdev
->dev
, "sun4v",
87 &sun4v_rtc_ops
, THIS_MODULE
);
91 platform_set_drvdata(pdev
, rtc
);
95 static struct platform_driver sun4v_rtc_driver
= {
101 module_platform_driver_probe(sun4v_rtc_driver
, sun4v_rtc_probe
);
103 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
104 MODULE_DESCRIPTION("SUN4V RTC driver");
105 MODULE_LICENSE("GPL");