ftgmac100: Cleanup tx queue handling
[linux-2.6/btrfs-unstable.git] / drivers / rtc / rtc-sun4v.c
blob11bc562eba5dfb7d9aa749ff9e951397b9d6c7a8
1 /* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems.
3 * Author: David S. Miller
4 * License: GPL
6 * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
7 */
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/kernel.h>
12 #include <linux/delay.h>
13 #include <linux/init.h>
14 #include <linux/rtc.h>
15 #include <linux/platform_device.h>
17 #include <asm/hypervisor.h>
19 static unsigned long hypervisor_get_time(void)
21 unsigned long ret, time;
22 int retries = 10000;
24 retry:
25 ret = sun4v_tod_get(&time);
26 if (ret == HV_EOK)
27 return time;
28 if (ret == HV_EWOULDBLOCK) {
29 if (--retries > 0) {
30 udelay(100);
31 goto retry;
33 pr_warn("tod_get() timed out.\n");
34 return 0;
36 pr_warn("tod_get() not supported.\n");
37 return 0;
40 static int sun4v_read_time(struct device *dev, struct rtc_time *tm)
42 rtc_time_to_tm(hypervisor_get_time(), tm);
43 return 0;
46 static int hypervisor_set_time(unsigned long secs)
48 unsigned long ret;
49 int retries = 10000;
51 retry:
52 ret = sun4v_tod_set(secs);
53 if (ret == HV_EOK)
54 return 0;
55 if (ret == HV_EWOULDBLOCK) {
56 if (--retries > 0) {
57 udelay(100);
58 goto retry;
60 pr_warn("tod_set() timed out.\n");
61 return -EAGAIN;
63 pr_warn("tod_set() not supported.\n");
64 return -EOPNOTSUPP;
67 static int sun4v_set_time(struct device *dev, struct rtc_time *tm)
69 unsigned long secs;
70 int err;
72 err = rtc_tm_to_time(tm, &secs);
73 if (err)
74 return err;
76 return hypervisor_set_time(secs);
79 static const struct rtc_class_ops sun4v_rtc_ops = {
80 .read_time = sun4v_read_time,
81 .set_time = sun4v_set_time,
84 static int __init sun4v_rtc_probe(struct platform_device *pdev)
86 struct rtc_device *rtc;
88 rtc = devm_rtc_device_register(&pdev->dev, "sun4v",
89 &sun4v_rtc_ops, THIS_MODULE);
90 if (IS_ERR(rtc))
91 return PTR_ERR(rtc);
93 platform_set_drvdata(pdev, rtc);
94 return 0;
97 static struct platform_driver sun4v_rtc_driver = {
98 .driver = {
99 .name = "rtc-sun4v",
103 builtin_platform_driver_probe(sun4v_rtc_driver, sun4v_rtc_probe);