aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAtsushi Nemoto <anemo@mba.ocn.ne.jp>2006-06-25 08:48:17 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-06-25 13:01:13 -0400
commit655066c3835e7b51794c4d56f042eb78b5a79f53 (patch)
tree25d2a104d5c77c58994f3c96aa08bf83bd1f8116 /drivers/rtc
parent1abb0dc92d706e8c73c7a62ca813738fe2259a7f (diff)
[PATCH] RTC: rtc-dev UIE emulation
Import genrtc's RTC UIE emulation (CONFIG_GEN_RTC_X) to rtc-dev driver with slight adjustments/refinements. This makes UIE-less rtc drivers work better with programs doing read/poll on /dev/rtc, such as hwclock. This emulation should not harm rtc drivers with UIE support, since rtc_dev_ioctl() calls underlaying rtc driver's ioctl() first. Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp> Acked-by: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/Kconfig7
-rw-r--r--drivers/rtc/rtc-dev.c102
2 files changed, 109 insertions, 0 deletions
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 9e249650baf0..725d6b696792 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -73,6 +73,13 @@ config RTC_INTF_DEV
73 This driver can also be built as a module. If so, the module 73 This driver can also be built as a module. If so, the module
74 will be called rtc-dev. 74 will be called rtc-dev.
75 75
76config RTC_INTF_DEV_UIE_EMUL
77 bool "RTC UIE emulation on dev interface"
78 depends on RTC_INTF_DEV
79 help
80 Provides an emulation for RTC_UIE if the underlaying rtc chip
81 driver did not provide RTC_UIE ioctls.
82
76comment "RTC drivers" 83comment "RTC drivers"
77 depends on RTC_CLASS 84 depends on RTC_CLASS
78 85
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 2011567005f9..07387c99df0d 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -48,6 +48,93 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
48 return err; 48 return err;
49} 49}
50 50
51#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
52/*
53 * Routine to poll RTC seconds field for change as often as possible,
54 * after first RTC_UIE use timer to reduce polling
55 */
56static void rtc_uie_task(void *data)
57{
58 struct rtc_device *rtc = data;
59 struct rtc_time tm;
60 int num = 0;
61 int err;
62
63 err = rtc_read_time(&rtc->class_dev, &tm);
64 spin_lock_irq(&rtc->irq_lock);
65 if (rtc->stop_uie_polling || err) {
66 rtc->uie_task_active = 0;
67 } else if (rtc->oldsecs != tm.tm_sec) {
68 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60;
69 rtc->oldsecs = tm.tm_sec;
70 rtc->uie_timer.expires = jiffies + HZ - (HZ/10);
71 rtc->uie_timer_active = 1;
72 rtc->uie_task_active = 0;
73 add_timer(&rtc->uie_timer);
74 } else if (schedule_work(&rtc->uie_task) == 0) {
75 rtc->uie_task_active = 0;
76 }
77 spin_unlock_irq(&rtc->irq_lock);
78 if (num)
79 rtc_update_irq(&rtc->class_dev, num, RTC_UF | RTC_IRQF);
80}
81
82static void rtc_uie_timer(unsigned long data)
83{
84 struct rtc_device *rtc = (struct rtc_device *)data;
85 unsigned long flags;
86
87 spin_lock_irqsave(&rtc->irq_lock, flags);
88 rtc->uie_timer_active = 0;
89 rtc->uie_task_active = 1;
90 if ((schedule_work(&rtc->uie_task) == 0))
91 rtc->uie_task_active = 0;
92 spin_unlock_irqrestore(&rtc->irq_lock, flags);
93}
94
95static void clear_uie(struct rtc_device *rtc)
96{
97 spin_lock_irq(&rtc->irq_lock);
98 if (rtc->irq_active) {
99 rtc->stop_uie_polling = 1;
100 if (rtc->uie_timer_active) {
101 spin_unlock_irq(&rtc->irq_lock);
102 del_timer_sync(&rtc->uie_timer);
103 spin_lock_irq(&rtc->irq_lock);
104 rtc->uie_timer_active = 0;
105 }
106 if (rtc->uie_task_active) {
107 spin_unlock_irq(&rtc->irq_lock);
108 flush_scheduled_work();
109 spin_lock_irq(&rtc->irq_lock);
110 }
111 rtc->irq_active = 0;
112 }
113 spin_unlock_irq(&rtc->irq_lock);
114}
115
116static int set_uie(struct rtc_device *rtc)
117{
118 struct rtc_time tm;
119 int err;
120
121 err = rtc_read_time(&rtc->class_dev, &tm);
122 if (err)
123 return err;
124 spin_lock_irq(&rtc->irq_lock);
125 if (!rtc->irq_active) {
126 rtc->irq_active = 1;
127 rtc->stop_uie_polling = 0;
128 rtc->oldsecs = tm.tm_sec;
129 rtc->uie_task_active = 1;
130 if (schedule_work(&rtc->uie_task) == 0)
131 rtc->uie_task_active = 0;
132 }
133 rtc->irq_data = 0;
134 spin_unlock_irq(&rtc->irq_lock);
135 return 0;
136}
137#endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */
51 138
52static ssize_t 139static ssize_t
53rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) 140rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
@@ -232,6 +319,14 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
232 return -EFAULT; 319 return -EFAULT;
233 break; 320 break;
234 321
322#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
323 case RTC_UIE_OFF:
324 clear_uie(rtc);
325 return 0;
326
327 case RTC_UIE_ON:
328 return set_uie(rtc);
329#endif
235 default: 330 default:
236 err = -ENOTTY; 331 err = -ENOTTY;
237 break; 332 break;
@@ -244,6 +339,9 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
244{ 339{
245 struct rtc_device *rtc = to_rtc_device(file->private_data); 340 struct rtc_device *rtc = to_rtc_device(file->private_data);
246 341
342#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
343 clear_uie(rtc);
344#endif
247 if (rtc->ops->release) 345 if (rtc->ops->release)
248 rtc->ops->release(rtc->class_dev.dev); 346 rtc->ops->release(rtc->class_dev.dev);
249 347
@@ -284,6 +382,10 @@ static int rtc_dev_add_device(struct class_device *class_dev,
284 mutex_init(&rtc->char_lock); 382 mutex_init(&rtc->char_lock);
285 spin_lock_init(&rtc->irq_lock); 383 spin_lock_init(&rtc->irq_lock);
286 init_waitqueue_head(&rtc->irq_queue); 384 init_waitqueue_head(&rtc->irq_queue);
385#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
386 INIT_WORK(&rtc->uie_task, rtc_uie_task, rtc);
387 setup_timer(&rtc->uie_timer, rtc_uie_timer, (unsigned long)rtc);
388#endif
287 389
288 cdev_init(&rtc->char_dev, &rtc_dev_fops); 390 cdev_init(&rtc->char_dev, &rtc_dev_fops);
289 rtc->char_dev.owner = rtc->owner; 391 rtc->char_dev.owner = rtc->owner;