Diff markup
1 /* 1 /*
2 * RTC subsystem, dev interface 2 * RTC subsystem, dev interface
3 * 3 *
4 * Copyright (C) 2005 Tower Technologies 4 * Copyright (C) 2005 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech 5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 * 6 *
7 * based on arch/arm/common/rtctime.c 7 * based on arch/arm/common/rtctime.c
8 * 8 *
9 * This program is free software; you can redi 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Publi 10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. 11 * published by the Free Software Foundation.
12 */ 12 */
13 13
14 #include <linux/module.h> 14 #include <linux/module.h>
15 #include <linux/rtc.h> 15 #include <linux/rtc.h>
16 #include "rtc-core.h" 16 #include "rtc-core.h"
17 17
18 static dev_t rtc_devt; 18 static dev_t rtc_devt;
19 19
20 #define RTC_DEV_MAX 16 /* 16 RTCs should be en 20 #define RTC_DEV_MAX 16 /* 16 RTCs should be enough for everyone... */
21 21
22 static int rtc_dev_open(struct inode *inode, s 22 static int rtc_dev_open(struct inode *inode, struct file *file)
23 { 23 {
24 int err; 24 int err;
25 struct rtc_device *rtc = container_of( 25 struct rtc_device *rtc = container_of(inode->i_cdev,
26 struct 26 struct rtc_device, char_dev);
27 const struct rtc_class_ops *ops = rtc- 27 const struct rtc_class_ops *ops = rtc->ops;
28 28
29 if (test_and_set_bit_lock(RTC_DEV_BUSY 29 if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
30 return -EBUSY; 30 return -EBUSY;
31 31
32 file->private_data = rtc; 32 file->private_data = rtc;
33 33
34 err = ops->open ? ops->open(rtc->dev.p 34 err = ops->open ? ops->open(rtc->dev.parent) : 0;
35 if (err == 0) { 35 if (err == 0) {
36 spin_lock_irq(&rtc->irq_lock); 36 spin_lock_irq(&rtc->irq_lock);
37 rtc->irq_data = 0; 37 rtc->irq_data = 0;
38 spin_unlock_irq(&rtc->irq_lock 38 spin_unlock_irq(&rtc->irq_lock);
39 39
40 return 0; 40 return 0;
41 } 41 }
42 42
43 /* something has gone wrong */ 43 /* something has gone wrong */
44 clear_bit_unlock(RTC_DEV_BUSY, &rtc->f 44 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
45 return err; 45 return err;
46 } 46 }
47 47
48 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 48 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
49 /* 49 /*
50 * Routine to poll RTC seconds field for chang 50 * Routine to poll RTC seconds field for change as often as possible,
51 * after first RTC_UIE use timer to reduce pol 51 * after first RTC_UIE use timer to reduce polling
52 */ 52 */
53 static void rtc_uie_task(struct work_struct *w 53 static void rtc_uie_task(struct work_struct *work)
54 { 54 {
55 struct rtc_device *rtc = 55 struct rtc_device *rtc =
56 container_of(work, struct rtc_ 56 container_of(work, struct rtc_device, uie_task);
57 struct rtc_time tm; 57 struct rtc_time tm;
58 int num = 0; 58 int num = 0;
59 int err; 59 int err;
60 60
61 err = rtc_read_time(rtc, &tm); 61 err = rtc_read_time(rtc, &tm);
62 62
63 spin_lock_irq(&rtc->irq_lock); !! 63 local_irq_disable();
>> 64 spin_lock(&rtc->irq_lock);
64 if (rtc->stop_uie_polling || err) { 65 if (rtc->stop_uie_polling || err) {
65 rtc->uie_task_active = 0; 66 rtc->uie_task_active = 0;
66 } else if (rtc->oldsecs != tm.tm_sec) 67 } else if (rtc->oldsecs != tm.tm_sec) {
67 num = (tm.tm_sec + 60 - rtc->o 68 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60;
68 rtc->oldsecs = tm.tm_sec; 69 rtc->oldsecs = tm.tm_sec;
69 rtc->uie_timer.expires = jiffi 70 rtc->uie_timer.expires = jiffies + HZ - (HZ/10);
70 rtc->uie_timer_active = 1; 71 rtc->uie_timer_active = 1;
71 rtc->uie_task_active = 0; 72 rtc->uie_task_active = 0;
72 add_timer(&rtc->uie_timer); 73 add_timer(&rtc->uie_timer);
73 } else if (schedule_work(&rtc->uie_tas 74 } else if (schedule_work(&rtc->uie_task) == 0) {
74 rtc->uie_task_active = 0; 75 rtc->uie_task_active = 0;
75 } 76 }
76 spin_unlock_irq(&rtc->irq_lock); !! 77 spin_unlock(&rtc->irq_lock);
77 if (num) 78 if (num)
78 rtc_update_irq(rtc, num, RTC_U 79 rtc_update_irq(rtc, num, RTC_UF | RTC_IRQF);
>> 80 local_irq_enable();
79 } 81 }
80 static void rtc_uie_timer(unsigned long data) 82 static void rtc_uie_timer(unsigned long data)
81 { 83 {
82 struct rtc_device *rtc = (struct rtc_d 84 struct rtc_device *rtc = (struct rtc_device *)data;
83 unsigned long flags; 85 unsigned long flags;
84 86
85 spin_lock_irqsave(&rtc->irq_lock, flag 87 spin_lock_irqsave(&rtc->irq_lock, flags);
86 rtc->uie_timer_active = 0; 88 rtc->uie_timer_active = 0;
87 rtc->uie_task_active = 1; 89 rtc->uie_task_active = 1;
88 if ((schedule_work(&rtc->uie_task) == 90 if ((schedule_work(&rtc->uie_task) == 0))
89 rtc->uie_task_active = 0; 91 rtc->uie_task_active = 0;
90 spin_unlock_irqrestore(&rtc->irq_lock, 92 spin_unlock_irqrestore(&rtc->irq_lock, flags);
91 } 93 }
92 94
93 static int clear_uie(struct rtc_device *rtc) !! 95 static void clear_uie(struct rtc_device *rtc)
94 { 96 {
95 spin_lock_irq(&rtc->irq_lock); 97 spin_lock_irq(&rtc->irq_lock);
96 if (rtc->uie_irq_active) { !! 98 if (rtc->irq_active) {
97 rtc->stop_uie_polling = 1; 99 rtc->stop_uie_polling = 1;
98 if (rtc->uie_timer_active) { 100 if (rtc->uie_timer_active) {
99 spin_unlock_irq(&rtc-> 101 spin_unlock_irq(&rtc->irq_lock);
100 del_timer_sync(&rtc->u 102 del_timer_sync(&rtc->uie_timer);
101 spin_lock_irq(&rtc->ir 103 spin_lock_irq(&rtc->irq_lock);
102 rtc->uie_timer_active 104 rtc->uie_timer_active = 0;
103 } 105 }
104 if (rtc->uie_task_active) { 106 if (rtc->uie_task_active) {
105 spin_unlock_irq(&rtc-> 107 spin_unlock_irq(&rtc->irq_lock);
106 flush_scheduled_work() 108 flush_scheduled_work();
107 spin_lock_irq(&rtc->ir 109 spin_lock_irq(&rtc->irq_lock);
108 } 110 }
109 rtc->uie_irq_active = 0; !! 111 rtc->irq_active = 0;
110 } 112 }
111 spin_unlock_irq(&rtc->irq_lock); 113 spin_unlock_irq(&rtc->irq_lock);
112 return 0; <<
113 } 114 }
114 115
115 static int set_uie(struct rtc_device *rtc) 116 static int set_uie(struct rtc_device *rtc)
116 { 117 {
117 struct rtc_time tm; 118 struct rtc_time tm;
118 int err; 119 int err;
119 120
120 err = rtc_read_time(rtc, &tm); 121 err = rtc_read_time(rtc, &tm);
121 if (err) 122 if (err)
122 return err; 123 return err;
123 spin_lock_irq(&rtc->irq_lock); 124 spin_lock_irq(&rtc->irq_lock);
124 if (!rtc->uie_irq_active) { !! 125 if (!rtc->irq_active) {
125 rtc->uie_irq_active = 1; !! 126 rtc->irq_active = 1;
126 rtc->stop_uie_polling = 0; 127 rtc->stop_uie_polling = 0;
127 rtc->oldsecs = tm.tm_sec; 128 rtc->oldsecs = tm.tm_sec;
128 rtc->uie_task_active = 1; 129 rtc->uie_task_active = 1;
129 if (schedule_work(&rtc->uie_ta 130 if (schedule_work(&rtc->uie_task) == 0)
130 rtc->uie_task_active = 131 rtc->uie_task_active = 0;
131 } 132 }
132 rtc->irq_data = 0; 133 rtc->irq_data = 0;
133 spin_unlock_irq(&rtc->irq_lock); 134 spin_unlock_irq(&rtc->irq_lock);
134 return 0; 135 return 0;
135 } 136 }
136 <<
137 int rtc_dev_update_irq_enable_emul(struct rtc_ <<
138 { <<
139 if (enabled) <<
140 return set_uie(rtc); <<
141 else <<
142 return clear_uie(rtc); <<
143 } <<
144 EXPORT_SYMBOL(rtc_dev_update_irq_enable_emul); <<
145 <<
146 #endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */ 137 #endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */
147 138
148 static ssize_t 139 static ssize_t
149 rtc_dev_read(struct file *file, char __user *b 140 rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
150 { 141 {
151 struct rtc_device *rtc = file->private 142 struct rtc_device *rtc = file->private_data;
152 143
153 DECLARE_WAITQUEUE(wait, current); 144 DECLARE_WAITQUEUE(wait, current);
154 unsigned long data; 145 unsigned long data;
155 ssize_t ret; 146 ssize_t ret;
156 147
157 if (count != sizeof(unsigned int) && c 148 if (count != sizeof(unsigned int) && count < sizeof(unsigned long))
158 return -EINVAL; 149 return -EINVAL;
159 150
160 add_wait_queue(&rtc->irq_queue, &wait) 151 add_wait_queue(&rtc->irq_queue, &wait);
161 do { 152 do {
162 __set_current_state(TASK_INTER 153 __set_current_state(TASK_INTERRUPTIBLE);
163 154
164 spin_lock_irq(&rtc->irq_lock); 155 spin_lock_irq(&rtc->irq_lock);
165 data = rtc->irq_data; 156 data = rtc->irq_data;
166 rtc->irq_data = 0; 157 rtc->irq_data = 0;
167 spin_unlock_irq(&rtc->irq_lock 158 spin_unlock_irq(&rtc->irq_lock);
168 159
169 if (data != 0) { 160 if (data != 0) {
170 ret = 0; 161 ret = 0;
171 break; 162 break;
172 } 163 }
173 if (file->f_flags & O_NONBLOCK 164 if (file->f_flags & O_NONBLOCK) {
174 ret = -EAGAIN; 165 ret = -EAGAIN;
175 break; 166 break;
176 } 167 }
177 if (signal_pending(current)) { 168 if (signal_pending(current)) {
178 ret = -ERESTARTSYS; 169 ret = -ERESTARTSYS;
179 break; 170 break;
180 } 171 }
181 schedule(); 172 schedule();
182 } while (1); 173 } while (1);
183 set_current_state(TASK_RUNNING); 174 set_current_state(TASK_RUNNING);
184 remove_wait_queue(&rtc->irq_queue, &wa 175 remove_wait_queue(&rtc->irq_queue, &wait);
185 176
186 if (ret == 0) { 177 if (ret == 0) {
187 /* Check for any data updates 178 /* Check for any data updates */
188 if (rtc->ops->read_callback) 179 if (rtc->ops->read_callback)
189 data = rtc->ops->read_ 180 data = rtc->ops->read_callback(rtc->dev.parent,
190 181 data);
191 182
192 if (sizeof(int) != sizeof(long 183 if (sizeof(int) != sizeof(long) &&
193 count == sizeof(unsigned i 184 count == sizeof(unsigned int))
194 ret = put_user(data, ( 185 ret = put_user(data, (unsigned int __user *)buf) ?:
195 sizeof(unsigne 186 sizeof(unsigned int);
196 else 187 else
197 ret = put_user(data, ( 188 ret = put_user(data, (unsigned long __user *)buf) ?:
198 sizeof(unsigne 189 sizeof(unsigned long);
199 } 190 }
200 return ret; 191 return ret;
201 } 192 }
202 193
203 static unsigned int rtc_dev_poll(struct file * 194 static unsigned int rtc_dev_poll(struct file *file, poll_table *wait)
204 { 195 {
205 struct rtc_device *rtc = file->private 196 struct rtc_device *rtc = file->private_data;
206 unsigned long data; 197 unsigned long data;
207 198
208 poll_wait(file, &rtc->irq_queue, wait) 199 poll_wait(file, &rtc->irq_queue, wait);
209 200
210 data = rtc->irq_data; 201 data = rtc->irq_data;
211 202
212 return (data != 0) ? (POLLIN | POLLRDN 203 return (data != 0) ? (POLLIN | POLLRDNORM) : 0;
213 } 204 }
214 205
215 static long rtc_dev_ioctl(struct file *file, !! 206 static int rtc_dev_ioctl(struct inode *inode, struct file *file,
216 unsigned int cmd, unsigned lon 207 unsigned int cmd, unsigned long arg)
217 { 208 {
218 int err = 0; 209 int err = 0;
219 struct rtc_device *rtc = file->private 210 struct rtc_device *rtc = file->private_data;
220 const struct rtc_class_ops *ops = rtc- 211 const struct rtc_class_ops *ops = rtc->ops;
221 struct rtc_time tm; 212 struct rtc_time tm;
222 struct rtc_wkalrm alarm; 213 struct rtc_wkalrm alarm;
223 void __user *uarg = (void __user *) ar 214 void __user *uarg = (void __user *) arg;
224 215
225 err = mutex_lock_interruptible(&rtc->o <<
226 if (err) <<
227 return err; <<
228 <<
229 /* check that the calling task has app 216 /* check that the calling task has appropriate permissions
230 * for certain ioctls. doing this chec 217 * for certain ioctls. doing this check here is useful
231 * to avoid duplicate code in each dri 218 * to avoid duplicate code in each driver.
232 */ 219 */
233 switch (cmd) { 220 switch (cmd) {
234 case RTC_EPOCH_SET: 221 case RTC_EPOCH_SET:
235 case RTC_SET_TIME: 222 case RTC_SET_TIME:
236 if (!capable(CAP_SYS_TIME)) 223 if (!capable(CAP_SYS_TIME))
237 err = -EACCES; !! 224 return -EACCES;
238 break; 225 break;
239 226
240 case RTC_IRQP_SET: 227 case RTC_IRQP_SET:
241 if (arg > rtc->max_user_freq & 228 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE))
242 err = -EACCES; !! 229 return -EACCES;
243 break; 230 break;
244 231
245 case RTC_PIE_ON: 232 case RTC_PIE_ON:
246 if (rtc->irq_freq > rtc->max_u 233 if (rtc->irq_freq > rtc->max_user_freq &&
247 !capable(CAP_S 234 !capable(CAP_SYS_RESOURCE))
248 err = -EACCES; !! 235 return -EACCES;
249 break; 236 break;
250 } 237 }
251 238
252 if (err) <<
253 goto done; <<
254 <<
255 /* try the driver's ioctl interface */ 239 /* try the driver's ioctl interface */
256 if (ops->ioctl) { 240 if (ops->ioctl) {
257 err = ops->ioctl(rtc->dev.pare 241 err = ops->ioctl(rtc->dev.parent, cmd, arg);
258 if (err != -ENOIOCTLCMD) { !! 242 if (err != -ENOIOCTLCMD)
259 mutex_unlock(&rtc->ops <<
260 return err; 243 return err;
261 } <<
262 } 244 }
263 245
264 /* if the driver does not provide the 246 /* if the driver does not provide the ioctl interface
265 * or if that particular ioctl was not 247 * or if that particular ioctl was not implemented
266 * (-ENOIOCTLCMD), we will try to emul 248 * (-ENOIOCTLCMD), we will try to emulate here.
267 * 249 *
268 * Drivers *SHOULD NOT* provide ioctl 250 * Drivers *SHOULD NOT* provide ioctl implementations
269 * for these requests. Instead, provi 251 * for these requests. Instead, provide methods to
270 * support the following code, so that 252 * support the following code, so that the RTC's main
271 * features are accessible without usi 253 * features are accessible without using ioctls.
272 * 254 *
273 * RTC and alarm times will be in UTC, 255 * RTC and alarm times will be in UTC, by preference,
274 * but dual-booting with MS-Windows im 256 * but dual-booting with MS-Windows implies RTCs must
275 * use the local wall clock time. 257 * use the local wall clock time.
276 */ 258 */
277 259
278 switch (cmd) { 260 switch (cmd) {
279 case RTC_ALM_READ: 261 case RTC_ALM_READ:
280 mutex_unlock(&rtc->ops_lock); <<
281 <<
282 err = rtc_read_alarm(rtc, &ala 262 err = rtc_read_alarm(rtc, &alarm);
283 if (err < 0) 263 if (err < 0)
284 return err; 264 return err;
285 265
286 if (copy_to_user(uarg, &alarm. 266 if (copy_to_user(uarg, &alarm.time, sizeof(tm)))
287 err = -EFAULT; !! 267 return -EFAULT;
288 return err; !! 268 break;
289 269
290 case RTC_ALM_SET: 270 case RTC_ALM_SET:
291 mutex_unlock(&rtc->ops_lock); <<
292 <<
293 if (copy_from_user(&alarm.time 271 if (copy_from_user(&alarm.time, uarg, sizeof(tm)))
294 return -EFAULT; 272 return -EFAULT;
295 273
296 alarm.enabled = 0; 274 alarm.enabled = 0;
297 alarm.pending = 0; 275 alarm.pending = 0;
298 alarm.time.tm_wday = -1; 276 alarm.time.tm_wday = -1;
299 alarm.time.tm_yday = -1; 277 alarm.time.tm_yday = -1;
300 alarm.time.tm_isdst = -1; 278 alarm.time.tm_isdst = -1;
301 279
302 /* RTC_ALM_SET alarms may be u 280 /* RTC_ALM_SET alarms may be up to 24 hours in the future.
303 * Rather than expecting every 281 * Rather than expecting every RTC to implement "don't care"
304 * for day/month/year fields, 282 * for day/month/year fields, just force the alarm to have
305 * the right values for those 283 * the right values for those fields.
306 * 284 *
307 * RTC_WKALM_SET should be use 285 * RTC_WKALM_SET should be used instead. Not only does it
308 * eliminate the need for a se 286 * eliminate the need for a separate RTC_AIE_ON call, it
309 * doesn't have the "alarm 23: 287 * doesn't have the "alarm 23:59:59 in the future" race.
310 * 288 *
311 * NOTE: some legacy code may 289 * NOTE: some legacy code may have used invalid fields as
312 * wildcards, exposing hardwar 290 * wildcards, exposing hardware "periodic alarm" capabilities.
313 * Not supported here. 291 * Not supported here.
314 */ 292 */
315 { 293 {
316 unsigned long now, the 294 unsigned long now, then;
317 295
318 err = rtc_read_time(rt 296 err = rtc_read_time(rtc, &tm);
319 if (err < 0) 297 if (err < 0)
320 return err; 298 return err;
321 rtc_tm_to_time(&tm, &n 299 rtc_tm_to_time(&tm, &now);
322 300
323 alarm.time.tm_mday = t 301 alarm.time.tm_mday = tm.tm_mday;
324 alarm.time.tm_mon = tm 302 alarm.time.tm_mon = tm.tm_mon;
325 alarm.time.tm_year = t 303 alarm.time.tm_year = tm.tm_year;
326 err = rtc_valid_tm(&a 304 err = rtc_valid_tm(&alarm.time);
327 if (err < 0) 305 if (err < 0)
328 return err; 306 return err;
329 rtc_tm_to_time(&alarm. 307 rtc_tm_to_time(&alarm.time, &then);
330 308
331 /* alarm may need to w 309 /* alarm may need to wrap into tomorrow */
332 if (then < now) { 310 if (then < now) {
333 rtc_time_to_tm 311 rtc_time_to_tm(now + 24 * 60 * 60, &tm);
334 alarm.time.tm_ 312 alarm.time.tm_mday = tm.tm_mday;
335 alarm.time.tm_ 313 alarm.time.tm_mon = tm.tm_mon;
336 alarm.time.tm_ 314 alarm.time.tm_year = tm.tm_year;
337 } 315 }
338 } 316 }
339 317
340 return rtc_set_alarm(rtc, &ala !! 318 err = rtc_set_alarm(rtc, &alarm);
>> 319 break;
341 320
342 case RTC_RD_TIME: 321 case RTC_RD_TIME:
343 mutex_unlock(&rtc->ops_lock); <<
344 <<
345 err = rtc_read_time(rtc, &tm); 322 err = rtc_read_time(rtc, &tm);
346 if (err < 0) 323 if (err < 0)
347 return err; 324 return err;
348 325
349 if (copy_to_user(uarg, &tm, si 326 if (copy_to_user(uarg, &tm, sizeof(tm)))
350 err = -EFAULT; !! 327 return -EFAULT;
351 return err; !! 328 break;
352 329
353 case RTC_SET_TIME: 330 case RTC_SET_TIME:
354 mutex_unlock(&rtc->ops_lock); <<
355 <<
356 if (copy_from_user(&tm, uarg, 331 if (copy_from_user(&tm, uarg, sizeof(tm)))
357 return -EFAULT; 332 return -EFAULT;
358 333
359 return rtc_set_time(rtc, &tm); !! 334 err = rtc_set_time(rtc, &tm);
>> 335 break;
360 336
361 case RTC_PIE_ON: 337 case RTC_PIE_ON:
362 err = rtc_irq_set_state(rtc, N 338 err = rtc_irq_set_state(rtc, NULL, 1);
363 break; 339 break;
364 340
365 case RTC_PIE_OFF: 341 case RTC_PIE_OFF:
366 err = rtc_irq_set_state(rtc, N 342 err = rtc_irq_set_state(rtc, NULL, 0);
367 break; 343 break;
368 344
369 case RTC_AIE_ON: <<
370 mutex_unlock(&rtc->ops_lock); <<
371 return rtc_alarm_irq_enable(rt <<
372 <<
373 case RTC_AIE_OFF: <<
374 mutex_unlock(&rtc->ops_lock); <<
375 return rtc_alarm_irq_enable(rt <<
376 <<
377 case RTC_UIE_ON: <<
378 mutex_unlock(&rtc->ops_lock); <<
379 return rtc_update_irq_enable(r <<
380 <<
381 case RTC_UIE_OFF: <<
382 mutex_unlock(&rtc->ops_lock); <<
383 return rtc_update_irq_enable(r <<
384 <<
385 case RTC_IRQP_SET: 345 case RTC_IRQP_SET:
386 err = rtc_irq_set_freq(rtc, NU 346 err = rtc_irq_set_freq(rtc, NULL, arg);
387 break; 347 break;
388 348
389 case RTC_IRQP_READ: 349 case RTC_IRQP_READ:
390 err = put_user(rtc->irq_freq, 350 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
391 break; 351 break;
392 352
393 #if 0 353 #if 0
394 case RTC_EPOCH_SET: 354 case RTC_EPOCH_SET:
395 #ifndef rtc_epoch 355 #ifndef rtc_epoch
396 /* 356 /*
397 * There were no RTC clocks be 357 * There were no RTC clocks before 1900.
398 */ 358 */
399 if (arg < 1900) { 359 if (arg < 1900) {
400 err = -EINVAL; 360 err = -EINVAL;
401 break; 361 break;
402 } 362 }
403 rtc_epoch = arg; 363 rtc_epoch = arg;
404 err = 0; 364 err = 0;
405 #endif 365 #endif
406 break; 366 break;
407 367
408 case RTC_EPOCH_READ: 368 case RTC_EPOCH_READ:
409 err = put_user(rtc_epoch, (uns 369 err = put_user(rtc_epoch, (unsigned long __user *)uarg);
410 break; 370 break;
411 #endif 371 #endif
412 case RTC_WKALM_SET: 372 case RTC_WKALM_SET:
413 mutex_unlock(&rtc->ops_lock); <<
414 if (copy_from_user(&alarm, uar 373 if (copy_from_user(&alarm, uarg, sizeof(alarm)))
415 return -EFAULT; 374 return -EFAULT;
416 375
417 return rtc_set_alarm(rtc, &ala !! 376 err = rtc_set_alarm(rtc, &alarm);
>> 377 break;
418 378
419 case RTC_WKALM_RD: 379 case RTC_WKALM_RD:
420 mutex_unlock(&rtc->ops_lock); <<
421 err = rtc_read_alarm(rtc, &ala 380 err = rtc_read_alarm(rtc, &alarm);
422 if (err < 0) 381 if (err < 0)
423 return err; 382 return err;
424 383
425 if (copy_to_user(uarg, &alarm, 384 if (copy_to_user(uarg, &alarm, sizeof(alarm)))
426 err = -EFAULT; !! 385 return -EFAULT;
427 return err; !! 386 break;
428 387
>> 388 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
>> 389 case RTC_UIE_OFF:
>> 390 clear_uie(rtc);
>> 391 return 0;
>> 392
>> 393 case RTC_UIE_ON:
>> 394 return set_uie(rtc);
>> 395 #endif
429 default: 396 default:
430 err = -ENOTTY; 397 err = -ENOTTY;
431 break; 398 break;
432 } 399 }
433 400
434 done: <<
435 mutex_unlock(&rtc->ops_lock); <<
436 return err; 401 return err;
437 } 402 }
438 403
439 static int rtc_dev_fasync(int fd, struct file <<
440 { <<
441 struct rtc_device *rtc = file->private <<
442 return fasync_helper(fd, file, on, &rt <<
443 } <<
444 <<
445 static int rtc_dev_release(struct inode *inode 404 static int rtc_dev_release(struct inode *inode, struct file *file)
446 { 405 {
447 struct rtc_device *rtc = file->private 406 struct rtc_device *rtc = file->private_data;
448 407
449 /* We shut down the repeating IRQs tha !! 408 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
450 * since nothing is listening to them. !! 409 clear_uie(rtc);
451 * - Update (UIE) ... currently only !! 410 #endif
452 * - Periodic (PIE) ... also used thr <<
453 * <<
454 * Leave the alarm alone; it may be se <<
455 * later, or be used by kernel code, a <<
456 */ <<
457 <<
458 /* Keep ioctl until all drivers are co <<
459 rtc_dev_ioctl(file, RTC_UIE_OFF, 0); <<
460 rtc_update_irq_enable(rtc, 0); <<
461 rtc_irq_set_state(rtc, NULL, 0); <<
462 <<
463 if (rtc->ops->release) 411 if (rtc->ops->release)
464 rtc->ops->release(rtc->dev.par 412 rtc->ops->release(rtc->dev.parent);
465 413
466 clear_bit_unlock(RTC_DEV_BUSY, &rtc->f 414 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
467 return 0; 415 return 0;
468 } 416 }
469 417
>> 418 static int rtc_dev_fasync(int fd, struct file *file, int on)
>> 419 {
>> 420 struct rtc_device *rtc = file->private_data;
>> 421 return fasync_helper(fd, file, on, &rtc->async_queue);
>> 422 }
>> 423
470 static const struct file_operations rtc_dev_fo 424 static const struct file_operations rtc_dev_fops = {
471 .owner = THIS_MODULE, 425 .owner = THIS_MODULE,
472 .llseek = no_llseek, 426 .llseek = no_llseek,
473 .read = rtc_dev_read, 427 .read = rtc_dev_read,
474 .poll = rtc_dev_poll, 428 .poll = rtc_dev_poll,
475 .unlocked_ioctl = rtc_dev_ioctl, !! 429 .ioctl = rtc_dev_ioctl,
476 .open = rtc_dev_open, 430 .open = rtc_dev_open,
477 .release = rtc_dev_release, 431 .release = rtc_dev_release,
478 .fasync = rtc_dev_fasync, 432 .fasync = rtc_dev_fasync,
479 }; 433 };
480 434
481 /* insertion/removal hooks */ 435 /* insertion/removal hooks */
482 436
483 void rtc_dev_prepare(struct rtc_device *rtc) 437 void rtc_dev_prepare(struct rtc_device *rtc)
484 { 438 {
485 if (!rtc_devt) 439 if (!rtc_devt)
486 return; 440 return;
487 441
488 if (rtc->id >= RTC_DEV_MAX) { 442 if (rtc->id >= RTC_DEV_MAX) {
489 pr_debug("%s: too many RTC dev 443 pr_debug("%s: too many RTC devices\n", rtc->name);
490 return; 444 return;
491 } 445 }
492 446
493 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), 447 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
494 448
495 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 449 #ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
496 INIT_WORK(&rtc->uie_task, rtc_uie_task 450 INIT_WORK(&rtc->uie_task, rtc_uie_task);
497 setup_timer(&rtc->uie_timer, rtc_uie_t 451 setup_timer(&rtc->uie_timer, rtc_uie_timer, (unsigned long)rtc);
498 #endif 452 #endif
499 453
500 cdev_init(&rtc->char_dev, &rtc_dev_fop 454 cdev_init(&rtc->char_dev, &rtc_dev_fops);
501 rtc->char_dev.owner = rtc->owner; 455 rtc->char_dev.owner = rtc->owner;
502 } 456 }
503 457
504 void rtc_dev_add_device(struct rtc_device *rtc 458 void rtc_dev_add_device(struct rtc_device *rtc)
505 { 459 {
506 if (cdev_add(&rtc->char_dev, rtc->dev. 460 if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1))
507 printk(KERN_WARNING "%s: faile 461 printk(KERN_WARNING "%s: failed to add char device %d:%d\n",
508 rtc->name, MAJOR(rtc_d 462 rtc->name, MAJOR(rtc_devt), rtc->id);
509 else 463 else
510 pr_debug("%s: dev (%d:%d)\n", 464 pr_debug("%s: dev (%d:%d)\n", rtc->name,
511 MAJOR(rtc_devt), rtc-> 465 MAJOR(rtc_devt), rtc->id);
512 } 466 }
513 467
514 void rtc_dev_del_device(struct rtc_device *rtc 468 void rtc_dev_del_device(struct rtc_device *rtc)
515 { 469 {
516 if (rtc->dev.devt) 470 if (rtc->dev.devt)
517 cdev_del(&rtc->char_dev); 471 cdev_del(&rtc->char_dev);
518 } 472 }
519 473
520 void __init rtc_dev_init(void) 474 void __init rtc_dev_init(void)
521 { 475 {
522 int err; 476 int err;
523 477
524 err = alloc_chrdev_region(&rtc_devt, 0 478 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
525 if (err < 0) 479 if (err < 0)
526 printk(KERN_ERR "%s: failed to 480 printk(KERN_ERR "%s: failed to allocate char dev region\n",
527 __FILE__); 481 __FILE__);
528 } 482 }
529 483
530 void __exit rtc_dev_exit(void) 484 void __exit rtc_dev_exit(void)
531 { 485 {
532 if (rtc_devt) 486 if (rtc_devt)
533 unregister_chrdev_region(rtc_d 487 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
534 } 488 }
535 489
|
This page was automatically generated by the
LXR engine.
|