diff options
author | David Brownell <david-b@pacbell.net> | 2007-05-08 03:33:30 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-05-08 14:15:18 -0400 |
commit | ab6a2d70d18edc7a716ef3127b9e13382faec98c (patch) | |
tree | 6de624dfcbd0181e54e21f1730d2a52ae9822c47 /drivers/rtc/interface.c | |
parent | 5726fb2012f0d96153113ddb7f988a0daea587ce (diff) |
rtc: rtc interfaces don't use class_device
This patch removes class_device from the programming interface that the RTC
framework exposes to the rest of the kernel. Now an rtc_device is passed,
which is more type-safe and streamlines all the relevant code.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Acked-By: Alessandro Zummo <a.zummo@towertech.it>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/interface.c')
-rw-r--r-- | drivers/rtc/interface.c | 78 |
1 files changed, 36 insertions, 42 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index ef40df0f169d..d9d326ff6253 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c | |||
@@ -13,10 +13,9 @@ | |||
13 | 13 | ||
14 | #include <linux/rtc.h> | 14 | #include <linux/rtc.h> |
15 | 15 | ||
16 | int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm) | 16 | int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm) |
17 | { | 17 | { |
18 | int err; | 18 | int err; |
19 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
20 | 19 | ||
21 | err = mutex_lock_interruptible(&rtc->ops_lock); | 20 | err = mutex_lock_interruptible(&rtc->ops_lock); |
22 | if (err) | 21 | if (err) |
@@ -28,7 +27,7 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm) | |||
28 | err = -EINVAL; | 27 | err = -EINVAL; |
29 | else { | 28 | else { |
30 | memset(tm, 0, sizeof(struct rtc_time)); | 29 | memset(tm, 0, sizeof(struct rtc_time)); |
31 | err = rtc->ops->read_time(class_dev->dev, tm); | 30 | err = rtc->ops->read_time(rtc->class_dev.dev, tm); |
32 | } | 31 | } |
33 | 32 | ||
34 | mutex_unlock(&rtc->ops_lock); | 33 | mutex_unlock(&rtc->ops_lock); |
@@ -36,10 +35,9 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm) | |||
36 | } | 35 | } |
37 | EXPORT_SYMBOL_GPL(rtc_read_time); | 36 | EXPORT_SYMBOL_GPL(rtc_read_time); |
38 | 37 | ||
39 | int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm) | 38 | int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm) |
40 | { | 39 | { |
41 | int err; | 40 | int err; |
42 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
43 | 41 | ||
44 | err = rtc_valid_tm(tm); | 42 | err = rtc_valid_tm(tm); |
45 | if (err != 0) | 43 | if (err != 0) |
@@ -54,17 +52,16 @@ int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm) | |||
54 | else if (!rtc->ops->set_time) | 52 | else if (!rtc->ops->set_time) |
55 | err = -EINVAL; | 53 | err = -EINVAL; |
56 | else | 54 | else |
57 | err = rtc->ops->set_time(class_dev->dev, tm); | 55 | err = rtc->ops->set_time(rtc->class_dev.dev, tm); |
58 | 56 | ||
59 | mutex_unlock(&rtc->ops_lock); | 57 | mutex_unlock(&rtc->ops_lock); |
60 | return err; | 58 | return err; |
61 | } | 59 | } |
62 | EXPORT_SYMBOL_GPL(rtc_set_time); | 60 | EXPORT_SYMBOL_GPL(rtc_set_time); |
63 | 61 | ||
64 | int rtc_set_mmss(struct class_device *class_dev, unsigned long secs) | 62 | int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs) |
65 | { | 63 | { |
66 | int err; | 64 | int err; |
67 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
68 | 65 | ||
69 | err = mutex_lock_interruptible(&rtc->ops_lock); | 66 | err = mutex_lock_interruptible(&rtc->ops_lock); |
70 | if (err) | 67 | if (err) |
@@ -73,11 +70,11 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs) | |||
73 | if (!rtc->ops) | 70 | if (!rtc->ops) |
74 | err = -ENODEV; | 71 | err = -ENODEV; |
75 | else if (rtc->ops->set_mmss) | 72 | else if (rtc->ops->set_mmss) |
76 | err = rtc->ops->set_mmss(class_dev->dev, secs); | 73 | err = rtc->ops->set_mmss(rtc->class_dev.dev, secs); |
77 | else if (rtc->ops->read_time && rtc->ops->set_time) { | 74 | else if (rtc->ops->read_time && rtc->ops->set_time) { |
78 | struct rtc_time new, old; | 75 | struct rtc_time new, old; |
79 | 76 | ||
80 | err = rtc->ops->read_time(class_dev->dev, &old); | 77 | err = rtc->ops->read_time(rtc->class_dev.dev, &old); |
81 | if (err == 0) { | 78 | if (err == 0) { |
82 | rtc_time_to_tm(secs, &new); | 79 | rtc_time_to_tm(secs, &new); |
83 | 80 | ||
@@ -89,7 +86,8 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs) | |||
89 | */ | 86 | */ |
90 | if (!((old.tm_hour == 23 && old.tm_min == 59) || | 87 | if (!((old.tm_hour == 23 && old.tm_min == 59) || |
91 | (new.tm_hour == 23 && new.tm_min == 59))) | 88 | (new.tm_hour == 23 && new.tm_min == 59))) |
92 | err = rtc->ops->set_time(class_dev->dev, &new); | 89 | err = rtc->ops->set_time(rtc->class_dev.dev, |
90 | &new); | ||
93 | } | 91 | } |
94 | } | 92 | } |
95 | else | 93 | else |
@@ -101,10 +99,9 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs) | |||
101 | } | 99 | } |
102 | EXPORT_SYMBOL_GPL(rtc_set_mmss); | 100 | EXPORT_SYMBOL_GPL(rtc_set_mmss); |
103 | 101 | ||
104 | int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) | 102 | int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) |
105 | { | 103 | { |
106 | int err; | 104 | int err; |
107 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
108 | 105 | ||
109 | err = mutex_lock_interruptible(&rtc->ops_lock); | 106 | err = mutex_lock_interruptible(&rtc->ops_lock); |
110 | if (err) | 107 | if (err) |
@@ -116,7 +113,7 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) | |||
116 | err = -EINVAL; | 113 | err = -EINVAL; |
117 | else { | 114 | else { |
118 | memset(alarm, 0, sizeof(struct rtc_wkalrm)); | 115 | memset(alarm, 0, sizeof(struct rtc_wkalrm)); |
119 | err = rtc->ops->read_alarm(class_dev->dev, alarm); | 116 | err = rtc->ops->read_alarm(rtc->class_dev.dev, alarm); |
120 | } | 117 | } |
121 | 118 | ||
122 | mutex_unlock(&rtc->ops_lock); | 119 | mutex_unlock(&rtc->ops_lock); |
@@ -124,10 +121,9 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) | |||
124 | } | 121 | } |
125 | EXPORT_SYMBOL_GPL(rtc_read_alarm); | 122 | EXPORT_SYMBOL_GPL(rtc_read_alarm); |
126 | 123 | ||
127 | int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) | 124 | int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) |
128 | { | 125 | { |
129 | int err; | 126 | int err; |
130 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
131 | 127 | ||
132 | err = mutex_lock_interruptible(&rtc->ops_lock); | 128 | err = mutex_lock_interruptible(&rtc->ops_lock); |
133 | if (err) | 129 | if (err) |
@@ -138,7 +134,7 @@ int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) | |||
138 | else if (!rtc->ops->set_alarm) | 134 | else if (!rtc->ops->set_alarm) |
139 | err = -EINVAL; | 135 | err = -EINVAL; |
140 | else | 136 | else |
141 | err = rtc->ops->set_alarm(class_dev->dev, alarm); | 137 | err = rtc->ops->set_alarm(rtc->class_dev.dev, alarm); |
142 | 138 | ||
143 | mutex_unlock(&rtc->ops_lock); | 139 | mutex_unlock(&rtc->ops_lock); |
144 | return err; | 140 | return err; |
@@ -147,16 +143,14 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm); | |||
147 | 143 | ||
148 | /** | 144 | /** |
149 | * rtc_update_irq - report RTC periodic, alarm, and/or update irqs | 145 | * rtc_update_irq - report RTC periodic, alarm, and/or update irqs |
150 | * @class_dev: the rtc's class device | 146 | * @rtc: the rtc device |
151 | * @num: how many irqs are being reported (usually one) | 147 | * @num: how many irqs are being reported (usually one) |
152 | * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF | 148 | * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF |
153 | * Context: in_interrupt(), irqs blocked | 149 | * Context: in_interrupt(), irqs blocked |
154 | */ | 150 | */ |
155 | void rtc_update_irq(struct class_device *class_dev, | 151 | void rtc_update_irq(struct rtc_device *rtc, |
156 | unsigned long num, unsigned long events) | 152 | unsigned long num, unsigned long events) |
157 | { | 153 | { |
158 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
159 | |||
160 | spin_lock(&rtc->irq_lock); | 154 | spin_lock(&rtc->irq_lock); |
161 | rtc->irq_data = (rtc->irq_data + (num << 8)) | events; | 155 | rtc->irq_data = (rtc->irq_data + (num << 8)) | events; |
162 | spin_unlock(&rtc->irq_lock); | 156 | spin_unlock(&rtc->irq_lock); |
@@ -171,40 +165,43 @@ void rtc_update_irq(struct class_device *class_dev, | |||
171 | } | 165 | } |
172 | EXPORT_SYMBOL_GPL(rtc_update_irq); | 166 | EXPORT_SYMBOL_GPL(rtc_update_irq); |
173 | 167 | ||
174 | struct class_device *rtc_class_open(char *name) | 168 | struct rtc_device *rtc_class_open(char *name) |
175 | { | 169 | { |
176 | struct class_device *class_dev = NULL, | 170 | struct class_device *class_dev_tmp; |
177 | *class_dev_tmp; | 171 | struct rtc_device *rtc = NULL; |
178 | 172 | ||
179 | down(&rtc_class->sem); | 173 | down(&rtc_class->sem); |
180 | list_for_each_entry(class_dev_tmp, &rtc_class->children, node) { | 174 | list_for_each_entry(class_dev_tmp, &rtc_class->children, node) { |
181 | if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) { | 175 | if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) { |
182 | class_dev = class_device_get(class_dev_tmp); | 176 | class_dev_tmp = class_device_get(class_dev_tmp); |
177 | if (class_dev_tmp) | ||
178 | rtc = to_rtc_device(class_dev_tmp); | ||
183 | break; | 179 | break; |
184 | } | 180 | } |
185 | } | 181 | } |
186 | 182 | ||
187 | if (class_dev) { | 183 | if (rtc) { |
188 | if (!try_module_get(to_rtc_device(class_dev)->owner)) | 184 | if (!try_module_get(rtc->owner)) { |
189 | class_dev = NULL; | 185 | class_device_put(class_dev_tmp); |
186 | rtc = NULL; | ||
187 | } | ||
190 | } | 188 | } |
191 | up(&rtc_class->sem); | 189 | up(&rtc_class->sem); |
192 | 190 | ||
193 | return class_dev; | 191 | return rtc; |
194 | } | 192 | } |
195 | EXPORT_SYMBOL_GPL(rtc_class_open); | 193 | EXPORT_SYMBOL_GPL(rtc_class_open); |
196 | 194 | ||
197 | void rtc_class_close(struct class_device *class_dev) | 195 | void rtc_class_close(struct rtc_device *rtc) |
198 | { | 196 | { |
199 | module_put(to_rtc_device(class_dev)->owner); | 197 | module_put(rtc->owner); |
200 | class_device_put(class_dev); | 198 | class_device_put(&rtc->class_dev); |
201 | } | 199 | } |
202 | EXPORT_SYMBOL_GPL(rtc_class_close); | 200 | EXPORT_SYMBOL_GPL(rtc_class_close); |
203 | 201 | ||
204 | int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task) | 202 | int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task) |
205 | { | 203 | { |
206 | int retval = -EBUSY; | 204 | int retval = -EBUSY; |
207 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
208 | 205 | ||
209 | if (task == NULL || task->func == NULL) | 206 | if (task == NULL || task->func == NULL) |
210 | return -EINVAL; | 207 | return -EINVAL; |
@@ -220,9 +217,8 @@ int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task) | |||
220 | } | 217 | } |
221 | EXPORT_SYMBOL_GPL(rtc_irq_register); | 218 | EXPORT_SYMBOL_GPL(rtc_irq_register); |
222 | 219 | ||
223 | void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task) | 220 | void rtc_irq_unregister(struct rtc_device *rtc, struct rtc_task *task) |
224 | { | 221 | { |
225 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
226 | 222 | ||
227 | spin_lock_irq(&rtc->irq_task_lock); | 223 | spin_lock_irq(&rtc->irq_task_lock); |
228 | if (rtc->irq_task == task) | 224 | if (rtc->irq_task == task) |
@@ -231,11 +227,10 @@ void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task) | |||
231 | } | 227 | } |
232 | EXPORT_SYMBOL_GPL(rtc_irq_unregister); | 228 | EXPORT_SYMBOL_GPL(rtc_irq_unregister); |
233 | 229 | ||
234 | int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int enabled) | 230 | int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled) |
235 | { | 231 | { |
236 | int err = 0; | 232 | int err = 0; |
237 | unsigned long flags; | 233 | unsigned long flags; |
238 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
239 | 234 | ||
240 | if (rtc->ops->irq_set_state == NULL) | 235 | if (rtc->ops->irq_set_state == NULL) |
241 | return -ENXIO; | 236 | return -ENXIO; |
@@ -246,17 +241,16 @@ int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int | |||
246 | spin_unlock_irqrestore(&rtc->irq_task_lock, flags); | 241 | spin_unlock_irqrestore(&rtc->irq_task_lock, flags); |
247 | 242 | ||
248 | if (err == 0) | 243 | if (err == 0) |
249 | err = rtc->ops->irq_set_state(class_dev->dev, enabled); | 244 | err = rtc->ops->irq_set_state(rtc->class_dev.dev, enabled); |
250 | 245 | ||
251 | return err; | 246 | return err; |
252 | } | 247 | } |
253 | EXPORT_SYMBOL_GPL(rtc_irq_set_state); | 248 | EXPORT_SYMBOL_GPL(rtc_irq_set_state); |
254 | 249 | ||
255 | int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int freq) | 250 | int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq) |
256 | { | 251 | { |
257 | int err = 0; | 252 | int err = 0; |
258 | unsigned long flags; | 253 | unsigned long flags; |
259 | struct rtc_device *rtc = to_rtc_device(class_dev); | ||
260 | 254 | ||
261 | if (rtc->ops->irq_set_freq == NULL) | 255 | if (rtc->ops->irq_set_freq == NULL) |
262 | return -ENXIO; | 256 | return -ENXIO; |
@@ -267,7 +261,7 @@ int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int | |||
267 | spin_unlock_irqrestore(&rtc->irq_task_lock, flags); | 261 | spin_unlock_irqrestore(&rtc->irq_task_lock, flags); |
268 | 262 | ||
269 | if (err == 0) { | 263 | if (err == 0) { |
270 | err = rtc->ops->irq_set_freq(class_dev->dev, freq); | 264 | err = rtc->ops->irq_set_freq(rtc->class_dev.dev, freq); |
271 | if (err == 0) | 265 | if (err == 0) |
272 | rtc->irq_freq = freq; | 266 | rtc->irq_freq = freq; |
273 | } | 267 | } |