Lines Matching refs:rtc
27 struct rtc_device *rtc = container_of(inode->i_cdev, in rtc_dev_open() local
30 if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) in rtc_dev_open()
33 file->private_data = rtc; in rtc_dev_open()
35 spin_lock_irq(&rtc->irq_lock); in rtc_dev_open()
36 rtc->irq_data = 0; in rtc_dev_open()
37 spin_unlock_irq(&rtc->irq_lock); in rtc_dev_open()
49 struct rtc_device *rtc = in rtc_uie_task() local
55 err = rtc_read_time(rtc, &tm); in rtc_uie_task()
57 spin_lock_irq(&rtc->irq_lock); in rtc_uie_task()
58 if (rtc->stop_uie_polling || err) { in rtc_uie_task()
59 rtc->uie_task_active = 0; in rtc_uie_task()
60 } else if (rtc->oldsecs != tm.tm_sec) { in rtc_uie_task()
61 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60; in rtc_uie_task()
62 rtc->oldsecs = tm.tm_sec; in rtc_uie_task()
63 rtc->uie_timer.expires = jiffies + HZ - (HZ/10); in rtc_uie_task()
64 rtc->uie_timer_active = 1; in rtc_uie_task()
65 rtc->uie_task_active = 0; in rtc_uie_task()
66 add_timer(&rtc->uie_timer); in rtc_uie_task()
67 } else if (schedule_work(&rtc->uie_task) == 0) { in rtc_uie_task()
68 rtc->uie_task_active = 0; in rtc_uie_task()
70 spin_unlock_irq(&rtc->irq_lock); in rtc_uie_task()
72 rtc_handle_legacy_irq(rtc, num, RTC_UF); in rtc_uie_task()
76 struct rtc_device *rtc = from_timer(rtc, t, uie_timer); in rtc_uie_timer() local
79 spin_lock_irqsave(&rtc->irq_lock, flags); in rtc_uie_timer()
80 rtc->uie_timer_active = 0; in rtc_uie_timer()
81 rtc->uie_task_active = 1; in rtc_uie_timer()
82 if ((schedule_work(&rtc->uie_task) == 0)) in rtc_uie_timer()
83 rtc->uie_task_active = 0; in rtc_uie_timer()
84 spin_unlock_irqrestore(&rtc->irq_lock, flags); in rtc_uie_timer()
87 static int clear_uie(struct rtc_device *rtc) in clear_uie() argument
89 spin_lock_irq(&rtc->irq_lock); in clear_uie()
90 if (rtc->uie_irq_active) { in clear_uie()
91 rtc->stop_uie_polling = 1; in clear_uie()
92 if (rtc->uie_timer_active) { in clear_uie()
93 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
94 del_timer_sync(&rtc->uie_timer); in clear_uie()
95 spin_lock_irq(&rtc->irq_lock); in clear_uie()
96 rtc->uie_timer_active = 0; in clear_uie()
98 if (rtc->uie_task_active) { in clear_uie()
99 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
101 spin_lock_irq(&rtc->irq_lock); in clear_uie()
103 rtc->uie_irq_active = 0; in clear_uie()
105 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
109 static int set_uie(struct rtc_device *rtc) in set_uie() argument
114 err = rtc_read_time(rtc, &tm); in set_uie()
117 spin_lock_irq(&rtc->irq_lock); in set_uie()
118 if (!rtc->uie_irq_active) { in set_uie()
119 rtc->uie_irq_active = 1; in set_uie()
120 rtc->stop_uie_polling = 0; in set_uie()
121 rtc->oldsecs = tm.tm_sec; in set_uie()
122 rtc->uie_task_active = 1; in set_uie()
123 if (schedule_work(&rtc->uie_task) == 0) in set_uie()
124 rtc->uie_task_active = 0; in set_uie()
126 rtc->irq_data = 0; in set_uie()
127 spin_unlock_irq(&rtc->irq_lock); in set_uie()
131 int rtc_dev_update_irq_enable_emul(struct rtc_device *rtc, unsigned int enabled) in rtc_dev_update_irq_enable_emul() argument
134 return set_uie(rtc); in rtc_dev_update_irq_enable_emul()
136 return clear_uie(rtc); in rtc_dev_update_irq_enable_emul()
145 struct rtc_device *rtc = file->private_data; in rtc_dev_read() local
154 add_wait_queue(&rtc->irq_queue, &wait); in rtc_dev_read()
158 spin_lock_irq(&rtc->irq_lock); in rtc_dev_read()
159 data = rtc->irq_data; in rtc_dev_read()
160 rtc->irq_data = 0; in rtc_dev_read()
161 spin_unlock_irq(&rtc->irq_lock); in rtc_dev_read()
178 remove_wait_queue(&rtc->irq_queue, &wait); in rtc_dev_read()
182 if (rtc->ops->read_callback) in rtc_dev_read()
183 data = rtc->ops->read_callback(rtc->dev.parent, in rtc_dev_read()
199 struct rtc_device *rtc = file->private_data; in rtc_dev_poll() local
202 poll_wait(file, &rtc->irq_queue, wait); in rtc_dev_poll()
204 data = rtc->irq_data; in rtc_dev_poll()
213 struct rtc_device *rtc = file->private_data; in rtc_dev_ioctl() local
214 const struct rtc_class_ops *ops = rtc->ops; in rtc_dev_ioctl()
219 err = mutex_lock_interruptible(&rtc->ops_lock); in rtc_dev_ioctl()
235 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE)) in rtc_dev_ioctl()
240 if (rtc->irq_freq > rtc->max_user_freq && in rtc_dev_ioctl()
262 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
264 err = rtc_read_alarm(rtc, &alarm); in rtc_dev_ioctl()
273 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
300 err = rtc_read_time(rtc, &tm); in rtc_dev_ioctl()
322 return rtc_set_alarm(rtc, &alarm); in rtc_dev_ioctl()
325 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
327 err = rtc_read_time(rtc, &tm); in rtc_dev_ioctl()
336 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
341 return rtc_set_time(rtc, &tm); in rtc_dev_ioctl()
344 err = rtc_irq_set_state(rtc, 1); in rtc_dev_ioctl()
348 err = rtc_irq_set_state(rtc, 0); in rtc_dev_ioctl()
352 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
353 return rtc_alarm_irq_enable(rtc, 1); in rtc_dev_ioctl()
356 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
357 return rtc_alarm_irq_enable(rtc, 0); in rtc_dev_ioctl()
360 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
361 return rtc_update_irq_enable(rtc, 1); in rtc_dev_ioctl()
364 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
365 return rtc_update_irq_enable(rtc, 0); in rtc_dev_ioctl()
368 err = rtc_irq_set_freq(rtc, arg); in rtc_dev_ioctl()
372 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg); in rtc_dev_ioctl()
376 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
380 return rtc_set_alarm(rtc, &alarm); in rtc_dev_ioctl()
383 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
384 err = rtc_read_alarm(rtc, &alarm); in rtc_dev_ioctl()
395 err = ops->ioctl(rtc->dev.parent, cmd, arg); in rtc_dev_ioctl()
404 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
410 struct rtc_device *rtc = file->private_data; in rtc_dev_fasync() local
411 return fasync_helper(fd, file, on, &rtc->async_queue); in rtc_dev_fasync()
416 struct rtc_device *rtc = file->private_data; in rtc_dev_release() local
429 rtc_update_irq_enable(rtc, 0); in rtc_dev_release()
430 rtc_irq_set_state(rtc, 0); in rtc_dev_release()
432 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); in rtc_dev_release()
449 void rtc_dev_prepare(struct rtc_device *rtc) in rtc_dev_prepare() argument
454 if (rtc->id >= RTC_DEV_MAX) { in rtc_dev_prepare()
455 dev_dbg(&rtc->dev, "too many RTC devices\n"); in rtc_dev_prepare()
459 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id); in rtc_dev_prepare()
462 INIT_WORK(&rtc->uie_task, rtc_uie_task); in rtc_dev_prepare()
463 timer_setup(&rtc->uie_timer, rtc_uie_timer, 0); in rtc_dev_prepare()
466 cdev_init(&rtc->char_dev, &rtc_dev_fops); in rtc_dev_prepare()
467 rtc->char_dev.owner = rtc->owner; in rtc_dev_prepare()