1 /* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems.
3 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/delay.h>
9 #include <linux/init.h>
10 #include <linux/rtc.h>
11 #include <linux/platform_device.h>
13 #include <asm/hypervisor.h>
15 static unsigned long hypervisor_get_time(void)
17 unsigned long ret, time;
21 ret = sun4v_tod_get(&time);
24 if (ret == HV_EWOULDBLOCK) {
29 printk(KERN_WARNING "SUN4V: tod_get() timed out.\n");
32 printk(KERN_WARNING "SUN4V: tod_get() not supported.\n");
36 static int sun4v_read_time(struct device *dev, struct rtc_time *tm)
38 rtc_time_to_tm(hypervisor_get_time(), tm);
42 static int hypervisor_set_time(unsigned long secs)
48 ret = sun4v_tod_set(secs);
51 if (ret == HV_EWOULDBLOCK) {
56 printk(KERN_WARNING "SUN4V: tod_set() timed out.\n");
59 printk(KERN_WARNING "SUN4V: tod_set() not supported.\n");
63 static int sun4v_set_time(struct device *dev, struct rtc_time *tm)
68 err = rtc_tm_to_time(tm, &secs);
72 return hypervisor_set_time(secs);
75 static const struct rtc_class_ops sun4v_rtc_ops = {
76 .read_time = sun4v_read_time,
77 .set_time = sun4v_set_time,
80 static int __init sun4v_rtc_probe(struct platform_device *pdev)
82 struct rtc_device *rtc = rtc_device_register("sun4v", &pdev->dev,
83 &sun4v_rtc_ops, THIS_MODULE);
87 platform_set_drvdata(pdev, rtc);
91 static int __exit sun4v_rtc_remove(struct platform_device *pdev)
93 struct rtc_device *rtc = platform_get_drvdata(pdev);
95 rtc_device_unregister(rtc);
99 static struct platform_driver sun4v_rtc_driver = {
102 .owner = THIS_MODULE,
104 .remove = __exit_p(sun4v_rtc_remove),
107 static int __init sun4v_rtc_init(void)
109 return platform_driver_probe(&sun4v_rtc_driver, sun4v_rtc_probe);
112 static void __exit sun4v_rtc_exit(void)
114 platform_driver_unregister(&sun4v_rtc_driver);
117 module_init(sun4v_rtc_init);
118 module_exit(sun4v_rtc_exit);
120 MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
121 MODULE_DESCRIPTION("SUN4V RTC driver");
122 MODULE_LICENSE("GPL");