Lines Matching refs:rtc
28 struct rtc_device *rtc = container_of(inode->i_cdev, in rtc_dev_open() local
30 const struct rtc_class_ops *ops = rtc->ops; in rtc_dev_open()
32 if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags)) in rtc_dev_open()
35 file->private_data = rtc; in rtc_dev_open()
37 err = ops->open ? ops->open(rtc->dev.parent) : 0; in rtc_dev_open()
39 spin_lock_irq(&rtc->irq_lock); in rtc_dev_open()
40 rtc->irq_data = 0; in rtc_dev_open()
41 spin_unlock_irq(&rtc->irq_lock); in rtc_dev_open()
47 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); in rtc_dev_open()
58 struct rtc_device *rtc = in rtc_uie_task() local
64 err = rtc_read_time(rtc, &tm); in rtc_uie_task()
66 spin_lock_irq(&rtc->irq_lock); in rtc_uie_task()
67 if (rtc->stop_uie_polling || err) { in rtc_uie_task()
68 rtc->uie_task_active = 0; in rtc_uie_task()
69 } else if (rtc->oldsecs != tm.tm_sec) { in rtc_uie_task()
70 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60; in rtc_uie_task()
71 rtc->oldsecs = tm.tm_sec; in rtc_uie_task()
72 rtc->uie_timer.expires = jiffies + HZ - (HZ/10); in rtc_uie_task()
73 rtc->uie_timer_active = 1; in rtc_uie_task()
74 rtc->uie_task_active = 0; in rtc_uie_task()
75 add_timer(&rtc->uie_timer); in rtc_uie_task()
76 } else if (schedule_work(&rtc->uie_task) == 0) { in rtc_uie_task()
77 rtc->uie_task_active = 0; in rtc_uie_task()
79 spin_unlock_irq(&rtc->irq_lock); in rtc_uie_task()
81 rtc_handle_legacy_irq(rtc, num, RTC_UF); in rtc_uie_task()
85 struct rtc_device *rtc = (struct rtc_device *)data; in rtc_uie_timer() local
88 spin_lock_irqsave(&rtc->irq_lock, flags); in rtc_uie_timer()
89 rtc->uie_timer_active = 0; in rtc_uie_timer()
90 rtc->uie_task_active = 1; in rtc_uie_timer()
91 if ((schedule_work(&rtc->uie_task) == 0)) in rtc_uie_timer()
92 rtc->uie_task_active = 0; in rtc_uie_timer()
93 spin_unlock_irqrestore(&rtc->irq_lock, flags); in rtc_uie_timer()
96 static int clear_uie(struct rtc_device *rtc) in clear_uie() argument
98 spin_lock_irq(&rtc->irq_lock); in clear_uie()
99 if (rtc->uie_irq_active) { in clear_uie()
100 rtc->stop_uie_polling = 1; in clear_uie()
101 if (rtc->uie_timer_active) { in clear_uie()
102 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
103 del_timer_sync(&rtc->uie_timer); in clear_uie()
104 spin_lock_irq(&rtc->irq_lock); in clear_uie()
105 rtc->uie_timer_active = 0; in clear_uie()
107 if (rtc->uie_task_active) { in clear_uie()
108 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
110 spin_lock_irq(&rtc->irq_lock); in clear_uie()
112 rtc->uie_irq_active = 0; in clear_uie()
114 spin_unlock_irq(&rtc->irq_lock); in clear_uie()
118 static int set_uie(struct rtc_device *rtc) in set_uie() argument
123 err = rtc_read_time(rtc, &tm); in set_uie()
126 spin_lock_irq(&rtc->irq_lock); in set_uie()
127 if (!rtc->uie_irq_active) { in set_uie()
128 rtc->uie_irq_active = 1; in set_uie()
129 rtc->stop_uie_polling = 0; in set_uie()
130 rtc->oldsecs = tm.tm_sec; in set_uie()
131 rtc->uie_task_active = 1; in set_uie()
132 if (schedule_work(&rtc->uie_task) == 0) in set_uie()
133 rtc->uie_task_active = 0; in set_uie()
135 rtc->irq_data = 0; in set_uie()
136 spin_unlock_irq(&rtc->irq_lock); in set_uie()
140 int rtc_dev_update_irq_enable_emul(struct rtc_device *rtc, unsigned int enabled) in rtc_dev_update_irq_enable_emul() argument
143 return set_uie(rtc); in rtc_dev_update_irq_enable_emul()
145 return clear_uie(rtc); in rtc_dev_update_irq_enable_emul()
154 struct rtc_device *rtc = file->private_data; in rtc_dev_read() local
163 add_wait_queue(&rtc->irq_queue, &wait); in rtc_dev_read()
167 spin_lock_irq(&rtc->irq_lock); in rtc_dev_read()
168 data = rtc->irq_data; in rtc_dev_read()
169 rtc->irq_data = 0; in rtc_dev_read()
170 spin_unlock_irq(&rtc->irq_lock); in rtc_dev_read()
187 remove_wait_queue(&rtc->irq_queue, &wait); in rtc_dev_read()
191 if (rtc->ops->read_callback) in rtc_dev_read()
192 data = rtc->ops->read_callback(rtc->dev.parent, in rtc_dev_read()
208 struct rtc_device *rtc = file->private_data; in rtc_dev_poll() local
211 poll_wait(file, &rtc->irq_queue, wait); in rtc_dev_poll()
213 data = rtc->irq_data; in rtc_dev_poll()
222 struct rtc_device *rtc = file->private_data; in rtc_dev_ioctl() local
223 const struct rtc_class_ops *ops = rtc->ops; in rtc_dev_ioctl()
228 err = mutex_lock_interruptible(&rtc->ops_lock); in rtc_dev_ioctl()
244 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE)) in rtc_dev_ioctl()
249 if (rtc->irq_freq > rtc->max_user_freq && in rtc_dev_ioctl()
271 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
273 err = rtc_read_alarm(rtc, &alarm); in rtc_dev_ioctl()
282 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
309 err = rtc_read_time(rtc, &tm); in rtc_dev_ioctl()
331 return rtc_set_alarm(rtc, &alarm); in rtc_dev_ioctl()
334 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
336 err = rtc_read_time(rtc, &tm); in rtc_dev_ioctl()
345 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
350 return rtc_set_time(rtc, &tm); in rtc_dev_ioctl()
353 err = rtc_irq_set_state(rtc, NULL, 1); in rtc_dev_ioctl()
357 err = rtc_irq_set_state(rtc, NULL, 0); in rtc_dev_ioctl()
361 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
362 return rtc_alarm_irq_enable(rtc, 1); in rtc_dev_ioctl()
365 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
366 return rtc_alarm_irq_enable(rtc, 0); in rtc_dev_ioctl()
369 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
370 return rtc_update_irq_enable(rtc, 1); in rtc_dev_ioctl()
373 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
374 return rtc_update_irq_enable(rtc, 0); in rtc_dev_ioctl()
377 err = rtc_irq_set_freq(rtc, NULL, arg); in rtc_dev_ioctl()
381 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg); in rtc_dev_ioctl()
385 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
389 return rtc_set_alarm(rtc, &alarm); in rtc_dev_ioctl()
392 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
393 err = rtc_read_alarm(rtc, &alarm); in rtc_dev_ioctl()
404 err = ops->ioctl(rtc->dev.parent, cmd, arg); in rtc_dev_ioctl()
413 mutex_unlock(&rtc->ops_lock); in rtc_dev_ioctl()
419 struct rtc_device *rtc = file->private_data; in rtc_dev_fasync() local
420 return fasync_helper(fd, file, on, &rtc->async_queue); in rtc_dev_fasync()
425 struct rtc_device *rtc = file->private_data; in rtc_dev_release() local
438 rtc_update_irq_enable(rtc, 0); in rtc_dev_release()
439 rtc_irq_set_state(rtc, NULL, 0); in rtc_dev_release()
441 if (rtc->ops->release) in rtc_dev_release()
442 rtc->ops->release(rtc->dev.parent); in rtc_dev_release()
444 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags); in rtc_dev_release()
461 void rtc_dev_prepare(struct rtc_device *rtc) in rtc_dev_prepare() argument
466 if (rtc->id >= RTC_DEV_MAX) { in rtc_dev_prepare()
467 dev_dbg(&rtc->dev, "%s: too many RTC devices\n", rtc->name); in rtc_dev_prepare()
471 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id); in rtc_dev_prepare()
474 INIT_WORK(&rtc->uie_task, rtc_uie_task); in rtc_dev_prepare()
475 setup_timer(&rtc->uie_timer, rtc_uie_timer, (unsigned long)rtc); in rtc_dev_prepare()
478 cdev_init(&rtc->char_dev, &rtc_dev_fops); in rtc_dev_prepare()
479 rtc->char_dev.owner = rtc->owner; in rtc_dev_prepare()
480 rtc->char_dev.kobj.parent = &rtc->dev.kobj; in rtc_dev_prepare()
483 void rtc_dev_add_device(struct rtc_device *rtc) in rtc_dev_add_device() argument
485 if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1)) in rtc_dev_add_device()
486 dev_warn(&rtc->dev, "%s: failed to add char device %d:%d\n", in rtc_dev_add_device()
487 rtc->name, MAJOR(rtc_devt), rtc->id); in rtc_dev_add_device()
489 dev_dbg(&rtc->dev, "%s: dev (%d:%d)\n", rtc->name, in rtc_dev_add_device()
490 MAJOR(rtc_devt), rtc->id); in rtc_dev_add_device()
493 void rtc_dev_del_device(struct rtc_device *rtc) in rtc_dev_del_device() argument
495 if (rtc->dev.devt) in rtc_dev_del_device()
496 cdev_del(&rtc->char_dev); in rtc_dev_del_device()