diff options
author | Alessandro Zummo <a.zummo@towertech.it> | 2008-11-14 19:37:54 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-11-14 19:37:54 -0500 |
commit | cecf61bdee426a3e0a014f7e26990d09c71ed458 (patch) | |
tree | 6a35a56424bbf23dd669f5faa7c0192dd2412c1e /drivers | |
parent | e64ed0225bd82d4c108c9f78f46070cfade14fac (diff) |
rtc: rtc-sun4v fixes, revised
- simplified code
- use platform_driver_probe
- removed locking: it's provided by rtc subsystem
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/rtc/rtc-sun4v.c | 69 |
1 files changed, 19 insertions, 50 deletions
diff --git a/drivers/rtc/rtc-sun4v.c b/drivers/rtc/rtc-sun4v.c index 2012ccbb4a53..5b2261052a65 100644 --- a/drivers/rtc/rtc-sun4v.c +++ b/drivers/rtc/rtc-sun4v.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* rtc-sun4c.c: Hypervisor based RTC for SUN4V systems. | 1 | /* rtc-sun4v.c: Hypervisor based RTC for SUN4V systems. |
2 | * | 2 | * |
3 | * Copyright (C) 2008 David S. Miller <davem@davemloft.net> | 3 | * Copyright (C) 2008 David S. Miller <davem@davemloft.net> |
4 | */ | 4 | */ |
@@ -7,21 +7,11 @@ | |||
7 | #include <linux/module.h> | 7 | #include <linux/module.h> |
8 | #include <linux/delay.h> | 8 | #include <linux/delay.h> |
9 | #include <linux/init.h> | 9 | #include <linux/init.h> |
10 | #include <linux/time.h> | ||
11 | #include <linux/rtc.h> | 10 | #include <linux/rtc.h> |
12 | #include <linux/platform_device.h> | 11 | #include <linux/platform_device.h> |
13 | 12 | ||
14 | #include <asm/hypervisor.h> | 13 | #include <asm/hypervisor.h> |
15 | 14 | ||
16 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); | ||
17 | MODULE_DESCRIPTION("SUN4V RTC driver"); | ||
18 | MODULE_LICENSE("GPL"); | ||
19 | |||
20 | struct sun4v_rtc { | ||
21 | struct rtc_device *rtc; | ||
22 | spinlock_t lock; | ||
23 | }; | ||
24 | |||
25 | static unsigned long hypervisor_get_time(void) | 15 | static unsigned long hypervisor_get_time(void) |
26 | { | 16 | { |
27 | unsigned long ret, time; | 17 | unsigned long ret, time; |
@@ -45,15 +35,7 @@ retry: | |||
45 | 35 | ||
46 | static int sun4v_read_time(struct device *dev, struct rtc_time *tm) | 36 | static int sun4v_read_time(struct device *dev, struct rtc_time *tm) |
47 | { | 37 | { |
48 | struct sun4v_rtc *p = dev_get_drvdata(dev); | 38 | rtc_time_to_tm(hypervisor_get_time(), tm); |
49 | unsigned long flags, secs; | ||
50 | |||
51 | spin_lock_irqsave(&p->lock, flags); | ||
52 | secs = hypervisor_get_time(); | ||
53 | spin_unlock_irqrestore(&p->lock, flags); | ||
54 | |||
55 | rtc_time_to_tm(secs, tm); | ||
56 | |||
57 | return 0; | 39 | return 0; |
58 | } | 40 | } |
59 | 41 | ||
@@ -80,19 +62,14 @@ retry: | |||
80 | 62 | ||
81 | static int sun4v_set_time(struct device *dev, struct rtc_time *tm) | 63 | static int sun4v_set_time(struct device *dev, struct rtc_time *tm) |
82 | { | 64 | { |
83 | struct sun4v_rtc *p = dev_get_drvdata(dev); | 65 | unsigned long secs; |
84 | unsigned long flags, secs; | ||
85 | int err; | 66 | int err; |
86 | 67 | ||
87 | err = rtc_tm_to_time(tm, &secs); | 68 | err = rtc_tm_to_time(tm, &secs); |
88 | if (err) | 69 | if (err) |
89 | return err; | 70 | return err; |
90 | 71 | ||
91 | spin_lock_irqsave(&p->lock, flags); | 72 | return hypervisor_set_time(secs); |
92 | err = hypervisor_set_time(secs); | ||
93 | spin_unlock_irqrestore(&p->lock, flags); | ||
94 | |||
95 | return err; | ||
96 | } | 73 | } |
97 | 74 | ||
98 | static const struct rtc_class_ops sun4v_rtc_ops = { | 75 | static const struct rtc_class_ops sun4v_rtc_ops = { |
@@ -100,33 +77,22 @@ static const struct rtc_class_ops sun4v_rtc_ops = { | |||
100 | .set_time = sun4v_set_time, | 77 | .set_time = sun4v_set_time, |
101 | }; | 78 | }; |
102 | 79 | ||
103 | static int __devinit sun4v_rtc_probe(struct platform_device *pdev) | 80 | static int __init sun4v_rtc_probe(struct platform_device *pdev) |
104 | { | 81 | { |
105 | struct sun4v_rtc *p = kzalloc(sizeof(*p), GFP_KERNEL); | 82 | struct rtc_device *rtc = rtc_device_register("sun4v", &pdev->dev, |
106 | |||
107 | if (!p) | ||
108 | return -ENOMEM; | ||
109 | |||
110 | spin_lock_init(&p->lock); | ||
111 | |||
112 | p->rtc = rtc_device_register("sun4v", &pdev->dev, | ||
113 | &sun4v_rtc_ops, THIS_MODULE); | 83 | &sun4v_rtc_ops, THIS_MODULE); |
114 | if (IS_ERR(p->rtc)) { | 84 | if (IS_ERR(rtc)) |
115 | int err = PTR_ERR(p->rtc); | 85 | return PTR_ERR(rtc); |
116 | kfree(p); | 86 | |
117 | return err; | 87 | platform_set_drvdata(pdev, rtc); |
118 | } | ||
119 | platform_set_drvdata(pdev, p); | ||
120 | return 0; | 88 | return 0; |
121 | } | 89 | } |
122 | 90 | ||
123 | static int __devexit sun4v_rtc_remove(struct platform_device *pdev) | 91 | static int __exit sun4v_rtc_remove(struct platform_device *pdev) |
124 | { | 92 | { |
125 | struct sun4v_rtc *p = platform_get_drvdata(pdev); | 93 | struct rtc_device *rtc = platform_get_drvdata(pdev); |
126 | |||
127 | rtc_device_unregister(p->rtc); | ||
128 | kfree(p); | ||
129 | 94 | ||
95 | rtc_device_unregister(rtc); | ||
130 | return 0; | 96 | return 0; |
131 | } | 97 | } |
132 | 98 | ||
@@ -135,13 +101,12 @@ static struct platform_driver sun4v_rtc_driver = { | |||
135 | .name = "rtc-sun4v", | 101 | .name = "rtc-sun4v", |
136 | .owner = THIS_MODULE, | 102 | .owner = THIS_MODULE, |
137 | }, | 103 | }, |
138 | .probe = sun4v_rtc_probe, | 104 | .remove = __exit_p(sun4v_rtc_remove), |
139 | .remove = __devexit_p(sun4v_rtc_remove), | ||
140 | }; | 105 | }; |
141 | 106 | ||
142 | static int __init sun4v_rtc_init(void) | 107 | static int __init sun4v_rtc_init(void) |
143 | { | 108 | { |
144 | return platform_driver_register(&sun4v_rtc_driver); | 109 | return platform_driver_probe(&sun4v_rtc_driver, sun4v_rtc_probe); |
145 | } | 110 | } |
146 | 111 | ||
147 | static void __exit sun4v_rtc_exit(void) | 112 | static void __exit sun4v_rtc_exit(void) |
@@ -151,3 +116,7 @@ static void __exit sun4v_rtc_exit(void) | |||
151 | 116 | ||
152 | module_init(sun4v_rtc_init); | 117 | module_init(sun4v_rtc_init); |
153 | module_exit(sun4v_rtc_exit); | 118 | module_exit(sun4v_rtc_exit); |
119 | |||
120 | MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); | ||
121 | MODULE_DESCRIPTION("SUN4V RTC driver"); | ||
122 | MODULE_LICENSE("GPL"); | ||