Lines Matching full:rtc
3 * RTC subsystem, dev interface
15 #include <linux/rtc.h>
17 #include "rtc-core.h"
25 struct rtc_device *rtc = container_of(inode->i_cdev, in rtc_dev_open() local
28 if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) in rtc_dev_open()
31 file->private_data = rtc; in rtc_dev_open()
33 spin_lock_irq(&rtc->irq_lock); in rtc_dev_open()
34 rtc->irq_data = 0; in rtc_dev_open()
35 spin_unlock_irq(&rtc->irq_lock); in rtc_dev_open()
42 * Routine to poll RTC seconds field for change as often as possible,
47 struct rtc_device *rtc = in rtc_uie_task() local
53 err = rtc_read_time(rtc, &tm); in rtc_uie_task()
55 spin_lock_irq(&rtc->irq_lock); in rtc_uie_task()
56 if (rtc->stop_uie_polling || err) { in rtc_uie_task()
57 rtc->uie_task_active = 0; in rtc_uie_task()
58 } else if (rtc->oldsecs != tm.tm_sec) { in rtc_uie_task()
59 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60; in rtc_uie_task()
60 rtc->oldsecs = tm.tm_sec; in rtc_uie_task()
61 rtc->uie_timer.expires = jiffies + HZ - (HZ / 10); in rtc_uie_task()
62 rtc->uie_timer_active = 1; in rtc_uie_task()
63 rtc->uie_task_active = 0; in rtc_uie_task()
64 add_timer(&rtc->uie_timer); in rtc_uie_task()
65 } else if (schedule_work(&rtc->uie_task) == 0) { in rtc_uie_task()
66 rtc->uie_task_active = 0; in rtc_uie_task()
68 spin_unlock_irq(&rtc->irq_lock); in rtc_uie_task()
70 rtc_handle_legacy_irq(rtc, num, RTC_UF); in rtc_uie_task()
75 struct rtc_device *rtc = from_timer(rtc, t, uie_timer); in rtc_uie_timer() local
78 spin_lock_irqsave(&rtc->irq_lock, flags); in rtc_uie_timer()
79 rtc->uie_timer_active = 0; in rtc_uie_timer()
80 rtc->uie_task_active = 1; in rtc_uie_timer()
81 if ((schedule_work(&rtc->uie_task) == 0)) in rtc_uie_timer()
82 rtc->uie_task_active = 0; in rtc_uie_timer()
83 spin_unlock_irqrestore(&rtc->irq_lock, flags); in rtc_uie_timer()
86 static int clear_uie(struct rtc_device *rtc) in clear_uie() argument
88 spin_lock_irq(&rtc->irq_lock); in clear_uie()
89 if (rtc->uie_irq_active) { in clear_uie()
90 rtc->stop_uie_polling = 1; in clear_uie()
91 if (rtc->uie_timer_active) { in clear_uie()
92 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
93 del_timer_sync(&rtc->uie_timer); in clear_uie()
94 spin_lock_irq(&rtc->irq_lock); in clear_uie()
95 rtc->uie_timer_active = 0; in clear_uie()
97 if (rtc->uie_task_active) { in clear_uie()
98 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
99 flush_work(&rtc->uie_task); in clear_uie()
100 spin_lock_irq(&rtc->irq_lock); in clear_uie()
102 rtc->uie_irq_active = 0; in clear_uie()
104 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
108 static int set_uie(struct rtc_device *rtc) in set_uie() argument
113 err = rtc_read_time(rtc, &tm); in set_uie()
116 spin_lock_irq(&rtc->irq_lock); in set_uie()
117 if (!rtc->uie_irq_active) { in set_uie()
118 rtc->uie_irq_active = 1; in set_uie()
119 rtc->stop_uie_polling = 0; in set_uie()
120 rtc->oldsecs = tm.tm_sec; in set_uie()
121 rtc->uie_task_active = 1; in set_uie()
122 if (schedule_work(&rtc->uie_task) == 0) in set_uie()
123 rtc->uie_task_active = 0; in set_uie()
125 rtc->irq_data = 0; in set_uie()
126 spin_unlock_irq(&rtc->irq_lock); in set_uie()
130 int rtc_dev_update_irq_enable_emul(struct rtc_device *rtc, unsigned int enabled) in rtc_dev_update_irq_enable_emul() argument
133 return set_uie(rtc); in rtc_dev_update_irq_enable_emul()
135 return clear_uie(rtc); in rtc_dev_update_irq_enable_emul()
144 struct rtc_device *rtc = file->private_data; in rtc_dev_read() local
153 add_wait_queue(&rtc->irq_queue, &wait); in rtc_dev_read()
157 spin_lock_irq(&rtc->irq_lock); in rtc_dev_read()
158 data = rtc->irq_data; in rtc_dev_read()
159 rtc->irq_data = 0; in rtc_dev_read()
160 spin_unlock_irq(&rtc->irq_lock); in rtc_dev_read()
177 remove_wait_queue(&rtc->irq_queue, &wait); in rtc_dev_read()
193 struct rtc_device *rtc = file->private_data; in rtc_dev_poll() local
196 poll_wait(file, &rtc->irq_queue, wait); in rtc_dev_poll()
198 data = rtc->irq_data; in rtc_dev_poll()
207 struct rtc_device *rtc = file->private_data; in rtc_dev_ioctl() local
208 const struct rtc_class_ops *ops = rtc->ops; in rtc_dev_ioctl()
214 err = mutex_lock_interruptible(&rtc->ops_lock); in rtc_dev_ioctl()
231 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE)) in rtc_dev_ioctl()
236 if (rtc->irq_freq > rtc->max_user_freq && in rtc_dev_ioctl()
248 * support the following code, so that the RTC's main in rtc_dev_ioctl()
251 * RTC and alarm times will be in UTC, by preference, in rtc_dev_ioctl()
258 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
260 err = rtc_read_alarm(rtc, &alarm); in rtc_dev_ioctl()
269 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
281 * Rather than expecting every RTC to implement "don't care" in rtc_dev_ioctl()
296 err = rtc_read_time(rtc, &tm); in rtc_dev_ioctl()
318 return rtc_set_alarm(rtc, &alarm); in rtc_dev_ioctl()
321 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
323 err = rtc_read_time(rtc, &tm); in rtc_dev_ioctl()
332 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
337 return rtc_set_time(rtc, &tm); in rtc_dev_ioctl()
340 err = rtc_irq_set_state(rtc, 1); in rtc_dev_ioctl()
344 err = rtc_irq_set_state(rtc, 0); in rtc_dev_ioctl()
348 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
349 return rtc_alarm_irq_enable(rtc, 1); in rtc_dev_ioctl()
352 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
353 return rtc_alarm_irq_enable(rtc, 0); in rtc_dev_ioctl()
356 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
357 return rtc_update_irq_enable(rtc, 1); in rtc_dev_ioctl()
360 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
361 return rtc_update_irq_enable(rtc, 0); in rtc_dev_ioctl()
364 err = rtc_irq_set_freq(rtc, arg); in rtc_dev_ioctl()
367 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg); in rtc_dev_ioctl()
371 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
375 return rtc_set_alarm(rtc, &alarm); in rtc_dev_ioctl()
378 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
379 err = rtc_read_alarm(rtc, &alarm); in rtc_dev_ioctl()
389 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
397 param.uvalue = rtc->features[0]; in rtc_dev_ioctl()
402 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
405 err = rtc_read_offset(rtc, &offset); in rtc_dev_ioctl()
406 mutex_lock(&rtc->ops_lock); in rtc_dev_ioctl()
412 if (rtc->ops->param_get) in rtc_dev_ioctl()
413 err = rtc->ops->param_get(rtc->dev.parent, ¶m); in rtc_dev_ioctl()
426 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
436 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
439 return rtc_set_offset(rtc, param.svalue); in rtc_dev_ioctl()
442 if (rtc->ops->param_set) in rtc_dev_ioctl()
443 err = rtc->ops->param_set(rtc->dev.parent, ¶m); in rtc_dev_ioctl()
453 err = ops->ioctl(rtc->dev.parent, cmd, arg); in rtc_dev_ioctl()
463 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
475 struct rtc_device *rtc = file->private_data; in rtc_dev_compat_ioctl() local
480 return put_user(rtc->irq_freq, (__u32 __user *)uarg); in rtc_dev_compat_ioctl()
497 struct rtc_device *rtc = file->private_data; in rtc_dev_fasync() local
499 return fasync_helper(fd, file, on, &rtc->async_queue); in rtc_dev_fasync()
504 struct rtc_device *rtc = file->private_data; in rtc_dev_release() local
517 rtc_update_irq_enable(rtc, 0); in rtc_dev_release()
518 rtc_irq_set_state(rtc, 0); in rtc_dev_release()
520 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); in rtc_dev_release()
539 void rtc_dev_prepare(struct rtc_device *rtc) in rtc_dev_prepare() argument
544 if (rtc->id >= RTC_DEV_MAX) { in rtc_dev_prepare()
545 dev_dbg(&rtc->dev, "too many RTC devices\n"); in rtc_dev_prepare()
549 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id); in rtc_dev_prepare()
552 INIT_WORK(&rtc->uie_task, rtc_uie_task); in rtc_dev_prepare()
553 timer_setup(&rtc->uie_timer, rtc_uie_timer, 0); in rtc_dev_prepare()
556 cdev_init(&rtc->char_dev, &rtc_dev_fops); in rtc_dev_prepare()
557 rtc->char_dev.owner = rtc->owner; in rtc_dev_prepare()
564 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc"); in rtc_dev_init()