blob: 84feb2565abd57cf76e6484d0ad201225d0104fd [file] [log] [blame]
Alexandre Bellonicdf75452019-03-13 23:02:48 +01001// SPDX-License-Identifier: GPL-2.0
Alessandro Zummoe8242902006-03-27 01:16:41 -08002/*
3 * RTC subsystem, dev interface
4 *
5 * Copyright (C) 2005 Tower Technologies
6 * Author: Alessandro Zummo <a.zummo@towertech.it>
7 *
8 * based on arch/arm/common/rtctime.c
Alexandre Bellonicdf75452019-03-13 23:02:48 +01009 */
Alessandro Zummoe8242902006-03-27 01:16:41 -080010
Jingoo Hanc100a5e2013-02-21 16:45:23 -080011#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12
Alessandro Zummoe8242902006-03-27 01:16:41 -080013#include <linux/module.h>
14#include <linux/rtc.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010015#include <linux/sched/signal.h>
David Brownell5726fb22007-05-08 00:33:27 -070016#include "rtc-core.h"
Alessandro Zummoe8242902006-03-27 01:16:41 -080017
Alessandro Zummoe8242902006-03-27 01:16:41 -080018static dev_t rtc_devt;
19
20#define RTC_DEV_MAX 16 /* 16 RTCs should be enough for everyone... */
21
22static int rtc_dev_open(struct inode *inode, struct file *file)
23{
Alessandro Zummoe8242902006-03-27 01:16:41 -080024 struct rtc_device *rtc = container_of(inode->i_cdev,
25 struct rtc_device, char_dev);
Alessandro Zummoe8242902006-03-27 01:16:41 -080026
David Brownellb1c3c892008-08-12 15:08:41 -070027 if (test_and_set_bit_lock(RTC_DEV_BUSY, &rtc->flags))
28 return -EBUSY;
Alessandro Zummoe8242902006-03-27 01:16:41 -080029
David Brownellab6a2d72007-05-08 00:33:30 -070030 file->private_data = rtc;
Alessandro Zummoe8242902006-03-27 01:16:41 -080031
Alexandre Belloniea369ea2017-08-23 02:33:04 +020032 spin_lock_irq(&rtc->irq_lock);
33 rtc->irq_data = 0;
34 spin_unlock_irq(&rtc->irq_lock);
Alessandro Zummoe8242902006-03-27 01:16:41 -080035
Alexandre Belloniea369ea2017-08-23 02:33:04 +020036 return 0;
Alessandro Zummoe8242902006-03-27 01:16:41 -080037}
38
John Stultz6e57b1d2011-02-11 17:45:40 -080039#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
40/*
41 * Routine to poll RTC seconds field for change as often as possible,
42 * after first RTC_UIE use timer to reduce polling
43 */
44static void rtc_uie_task(struct work_struct *work)
45{
46 struct rtc_device *rtc =
47 container_of(work, struct rtc_device, uie_task);
48 struct rtc_time tm;
49 int num = 0;
50 int err;
51
52 err = rtc_read_time(rtc, &tm);
53
54 spin_lock_irq(&rtc->irq_lock);
55 if (rtc->stop_uie_polling || err) {
56 rtc->uie_task_active = 0;
57 } else if (rtc->oldsecs != tm.tm_sec) {
58 num = (tm.tm_sec + 60 - rtc->oldsecs) % 60;
59 rtc->oldsecs = tm.tm_sec;
Alexandre Belloni606cc432019-03-20 12:59:09 +010060 rtc->uie_timer.expires = jiffies + HZ - (HZ / 10);
John Stultz6e57b1d2011-02-11 17:45:40 -080061 rtc->uie_timer_active = 1;
62 rtc->uie_task_active = 0;
63 add_timer(&rtc->uie_timer);
64 } else if (schedule_work(&rtc->uie_task) == 0) {
65 rtc->uie_task_active = 0;
66 }
67 spin_unlock_irq(&rtc->irq_lock);
68 if (num)
John Stultz456d66e2011-02-11 18:15:23 -080069 rtc_handle_legacy_irq(rtc, num, RTC_UF);
John Stultz6e57b1d2011-02-11 17:45:40 -080070}
Alexandre Belloni606cc432019-03-20 12:59:09 +010071
Kees Cooke99e88a2017-10-16 14:43:17 -070072static void rtc_uie_timer(struct timer_list *t)
John Stultz6e57b1d2011-02-11 17:45:40 -080073{
Kees Cooke99e88a2017-10-16 14:43:17 -070074 struct rtc_device *rtc = from_timer(rtc, t, uie_timer);
John Stultz6e57b1d2011-02-11 17:45:40 -080075 unsigned long flags;
76
77 spin_lock_irqsave(&rtc->irq_lock, flags);
78 rtc->uie_timer_active = 0;
79 rtc->uie_task_active = 1;
80 if ((schedule_work(&rtc->uie_task) == 0))
81 rtc->uie_task_active = 0;
82 spin_unlock_irqrestore(&rtc->irq_lock, flags);
83}
84
85static int clear_uie(struct rtc_device *rtc)
86{
87 spin_lock_irq(&rtc->irq_lock);
88 if (rtc->uie_irq_active) {
89 rtc->stop_uie_polling = 1;
90 if (rtc->uie_timer_active) {
91 spin_unlock_irq(&rtc->irq_lock);
92 del_timer_sync(&rtc->uie_timer);
93 spin_lock_irq(&rtc->irq_lock);
94 rtc->uie_timer_active = 0;
95 }
96 if (rtc->uie_task_active) {
97 spin_unlock_irq(&rtc->irq_lock);
98 flush_scheduled_work();
99 spin_lock_irq(&rtc->irq_lock);
100 }
101 rtc->uie_irq_active = 0;
102 }
103 spin_unlock_irq(&rtc->irq_lock);
104 return 0;
105}
106
107static int set_uie(struct rtc_device *rtc)
108{
109 struct rtc_time tm;
110 int err;
111
112 err = rtc_read_time(rtc, &tm);
113 if (err)
114 return err;
115 spin_lock_irq(&rtc->irq_lock);
116 if (!rtc->uie_irq_active) {
117 rtc->uie_irq_active = 1;
118 rtc->stop_uie_polling = 0;
119 rtc->oldsecs = tm.tm_sec;
120 rtc->uie_task_active = 1;
121 if (schedule_work(&rtc->uie_task) == 0)
122 rtc->uie_task_active = 0;
123 }
124 rtc->irq_data = 0;
125 spin_unlock_irq(&rtc->irq_lock);
126 return 0;
127}
128
129int rtc_dev_update_irq_enable_emul(struct rtc_device *rtc, unsigned int enabled)
130{
131 if (enabled)
132 return set_uie(rtc);
133 else
134 return clear_uie(rtc);
135}
136EXPORT_SYMBOL(rtc_dev_update_irq_enable_emul);
137
138#endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */
Alessandro Zummoe8242902006-03-27 01:16:41 -0800139
140static ssize_t
141rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
142{
Mark Zhan88efe132007-10-16 01:28:17 -0700143 struct rtc_device *rtc = file->private_data;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800144
145 DECLARE_WAITQUEUE(wait, current);
146 unsigned long data;
147 ssize_t ret;
148
Atsushi Nemoto3418ff72006-05-01 12:16:16 -0700149 if (count != sizeof(unsigned int) && count < sizeof(unsigned long))
Alessandro Zummoe8242902006-03-27 01:16:41 -0800150 return -EINVAL;
151
152 add_wait_queue(&rtc->irq_queue, &wait);
153 do {
154 __set_current_state(TASK_INTERRUPTIBLE);
155
156 spin_lock_irq(&rtc->irq_lock);
157 data = rtc->irq_data;
158 rtc->irq_data = 0;
159 spin_unlock_irq(&rtc->irq_lock);
160
161 if (data != 0) {
162 ret = 0;
163 break;
164 }
165 if (file->f_flags & O_NONBLOCK) {
166 ret = -EAGAIN;
167 break;
168 }
169 if (signal_pending(current)) {
170 ret = -ERESTARTSYS;
171 break;
172 }
173 schedule();
174 } while (1);
175 set_current_state(TASK_RUNNING);
176 remove_wait_queue(&rtc->irq_queue, &wait);
177
178 if (ret == 0) {
Atsushi Nemoto3418ff72006-05-01 12:16:16 -0700179 if (sizeof(int) != sizeof(long) &&
180 count == sizeof(unsigned int))
181 ret = put_user(data, (unsigned int __user *)buf) ?:
182 sizeof(unsigned int);
183 else
184 ret = put_user(data, (unsigned long __user *)buf) ?:
185 sizeof(unsigned long);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800186 }
187 return ret;
188}
189
Al Viroafc9a422017-07-03 06:39:46 -0400190static __poll_t rtc_dev_poll(struct file *file, poll_table *wait)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800191{
Mark Zhan88efe132007-10-16 01:28:17 -0700192 struct rtc_device *rtc = file->private_data;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800193 unsigned long data;
194
195 poll_wait(file, &rtc->irq_queue, wait);
196
197 data = rtc->irq_data;
198
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800199 return (data != 0) ? (EPOLLIN | EPOLLRDNORM) : 0;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800200}
201
David Brownell5ad31a572008-07-23 21:30:33 -0700202static long rtc_dev_ioctl(struct file *file,
Alexandre Belloni606cc432019-03-20 12:59:09 +0100203 unsigned int cmd, unsigned long arg)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800204{
205 int err = 0;
David Brownellab6a2d72007-05-08 00:33:30 -0700206 struct rtc_device *rtc = file->private_data;
David Brownellff8371a2006-09-30 23:28:17 -0700207 const struct rtc_class_ops *ops = rtc->ops;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800208 struct rtc_time tm;
209 struct rtc_wkalrm alarm;
Alexandre Belloni606cc432019-03-20 12:59:09 +0100210 void __user *uarg = (void __user *)arg;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800211
David Brownell5ad31a572008-07-23 21:30:33 -0700212 err = mutex_lock_interruptible(&rtc->ops_lock);
213 if (err)
David Brownellb68bb262008-07-29 22:33:30 -0700214 return err;
David Brownell5ad31a572008-07-23 21:30:33 -0700215
David Brownell2601a462006-11-25 11:09:27 -0800216 /* check that the calling task has appropriate permissions
Alessandro Zummo110d6932006-06-25 05:48:20 -0700217 * for certain ioctls. doing this check here is useful
218 * to avoid duplicate code in each driver.
219 */
220 switch (cmd) {
221 case RTC_EPOCH_SET:
222 case RTC_SET_TIME:
223 if (!capable(CAP_SYS_TIME))
David Brownell5ad31a572008-07-23 21:30:33 -0700224 err = -EACCES;
Alessandro Zummo110d6932006-06-25 05:48:20 -0700225 break;
226
227 case RTC_IRQP_SET:
228 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE))
David Brownell5ad31a572008-07-23 21:30:33 -0700229 err = -EACCES;
Alessandro Zummo110d6932006-06-25 05:48:20 -0700230 break;
231
232 case RTC_PIE_ON:
Bryan Kadzban9d013d32007-10-16 01:28:23 -0700233 if (rtc->irq_freq > rtc->max_user_freq &&
Alexandre Belloni606cc432019-03-20 12:59:09 +0100234 !capable(CAP_SYS_RESOURCE))
David Brownell5ad31a572008-07-23 21:30:33 -0700235 err = -EACCES;
Alessandro Zummo110d6932006-06-25 05:48:20 -0700236 break;
237 }
238
David Brownell5ad31a572008-07-23 21:30:33 -0700239 if (err)
240 goto done;
241
John Stultzac54cd22011-02-02 16:55:19 -0800242 /*
David Brownell8a0bdfd72008-02-06 01:38:45 -0800243 * Drivers *SHOULD NOT* provide ioctl implementations
244 * for these requests. Instead, provide methods to
245 * support the following code, so that the RTC's main
246 * features are accessible without using ioctls.
247 *
248 * RTC and alarm times will be in UTC, by preference,
249 * but dual-booting with MS-Windows implies RTCs must
250 * use the local wall clock time.
Alessandro Zummoe8242902006-03-27 01:16:41 -0800251 */
252
253 switch (cmd) {
254 case RTC_ALM_READ:
David Brownell5ad31a572008-07-23 21:30:33 -0700255 mutex_unlock(&rtc->ops_lock);
256
David Brownellab6a2d72007-05-08 00:33:30 -0700257 err = rtc_read_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800258 if (err < 0)
259 return err;
260
261 if (copy_to_user(uarg, &alarm.time, sizeof(tm)))
David Brownell5ad31a572008-07-23 21:30:33 -0700262 err = -EFAULT;
263 return err;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800264
265 case RTC_ALM_SET:
David Brownell5ad31a572008-07-23 21:30:33 -0700266 mutex_unlock(&rtc->ops_lock);
267
Alessandro Zummoe8242902006-03-27 01:16:41 -0800268 if (copy_from_user(&alarm.time, uarg, sizeof(tm)))
269 return -EFAULT;
270
271 alarm.enabled = 0;
272 alarm.pending = 0;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800273 alarm.time.tm_wday = -1;
274 alarm.time.tm_yday = -1;
275 alarm.time.tm_isdst = -1;
David Brownellf8245c22007-05-08 00:34:07 -0700276
277 /* RTC_ALM_SET alarms may be up to 24 hours in the future.
278 * Rather than expecting every RTC to implement "don't care"
279 * for day/month/year fields, just force the alarm to have
280 * the right values for those fields.
281 *
282 * RTC_WKALM_SET should be used instead. Not only does it
283 * eliminate the need for a separate RTC_AIE_ON call, it
284 * doesn't have the "alarm 23:59:59 in the future" race.
285 *
286 * NOTE: some legacy code may have used invalid fields as
287 * wildcards, exposing hardware "periodic alarm" capabilities.
288 * Not supported here.
289 */
290 {
Xunlei Pang4ec23642015-01-22 02:31:52 +0000291 time64_t now, then;
David Brownellf8245c22007-05-08 00:34:07 -0700292
293 err = rtc_read_time(rtc, &tm);
294 if (err < 0)
295 return err;
Xunlei Pang4ec23642015-01-22 02:31:52 +0000296 now = rtc_tm_to_time64(&tm);
David Brownellf8245c22007-05-08 00:34:07 -0700297
298 alarm.time.tm_mday = tm.tm_mday;
299 alarm.time.tm_mon = tm.tm_mon;
300 alarm.time.tm_year = tm.tm_year;
301 err = rtc_valid_tm(&alarm.time);
302 if (err < 0)
303 return err;
Xunlei Pang4ec23642015-01-22 02:31:52 +0000304 then = rtc_tm_to_time64(&alarm.time);
David Brownellf8245c22007-05-08 00:34:07 -0700305
306 /* alarm may need to wrap into tomorrow */
307 if (then < now) {
Xunlei Pang4ec23642015-01-22 02:31:52 +0000308 rtc_time64_to_tm(now + 24 * 60 * 60, &tm);
David Brownellf8245c22007-05-08 00:34:07 -0700309 alarm.time.tm_mday = tm.tm_mday;
310 alarm.time.tm_mon = tm.tm_mon;
311 alarm.time.tm_year = tm.tm_year;
312 }
313 }
314
David Brownell5ad31a572008-07-23 21:30:33 -0700315 return rtc_set_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800316
317 case RTC_RD_TIME:
David Brownell5ad31a572008-07-23 21:30:33 -0700318 mutex_unlock(&rtc->ops_lock);
319
David Brownellab6a2d72007-05-08 00:33:30 -0700320 err = rtc_read_time(rtc, &tm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800321 if (err < 0)
322 return err;
323
324 if (copy_to_user(uarg, &tm, sizeof(tm)))
David Brownell5ad31a572008-07-23 21:30:33 -0700325 err = -EFAULT;
326 return err;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800327
328 case RTC_SET_TIME:
David Brownell5ad31a572008-07-23 21:30:33 -0700329 mutex_unlock(&rtc->ops_lock);
330
Alessandro Zummoe8242902006-03-27 01:16:41 -0800331 if (copy_from_user(&tm, uarg, sizeof(tm)))
332 return -EFAULT;
333
David Brownell5ad31a572008-07-23 21:30:33 -0700334 return rtc_set_time(rtc, &tm);
David Brownell2601a462006-11-25 11:09:27 -0800335
Alessandro Zummod691eb92007-10-16 01:28:15 -0700336 case RTC_PIE_ON:
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200337 err = rtc_irq_set_state(rtc, 1);
Alessandro Zummod691eb92007-10-16 01:28:15 -0700338 break;
339
340 case RTC_PIE_OFF:
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200341 err = rtc_irq_set_state(rtc, 0);
David Brownell2601a462006-11-25 11:09:27 -0800342 break;
343
Alessandro Zummo099e6572009-01-04 12:00:54 -0800344 case RTC_AIE_ON:
345 mutex_unlock(&rtc->ops_lock);
346 return rtc_alarm_irq_enable(rtc, 1);
347
348 case RTC_AIE_OFF:
349 mutex_unlock(&rtc->ops_lock);
350 return rtc_alarm_irq_enable(rtc, 0);
351
352 case RTC_UIE_ON:
353 mutex_unlock(&rtc->ops_lock);
354 return rtc_update_irq_enable(rtc, 1);
355
356 case RTC_UIE_OFF:
357 mutex_unlock(&rtc->ops_lock);
358 return rtc_update_irq_enable(rtc, 0);
359
David Brownell2601a462006-11-25 11:09:27 -0800360 case RTC_IRQP_SET:
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200361 err = rtc_irq_set_freq(rtc, arg);
Alessandro Zummod691eb92007-10-16 01:28:15 -0700362 break;
363
364 case RTC_IRQP_READ:
365 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
David Brownell2601a462006-11-25 11:09:27 -0800366 break;
367
Alessandro Zummoe8242902006-03-27 01:16:41 -0800368 case RTC_WKALM_SET:
David Brownell5ad31a572008-07-23 21:30:33 -0700369 mutex_unlock(&rtc->ops_lock);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800370 if (copy_from_user(&alarm, uarg, sizeof(alarm)))
371 return -EFAULT;
372
David Brownell5ad31a572008-07-23 21:30:33 -0700373 return rtc_set_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800374
375 case RTC_WKALM_RD:
David Brownell5ad31a572008-07-23 21:30:33 -0700376 mutex_unlock(&rtc->ops_lock);
David Brownellab6a2d72007-05-08 00:33:30 -0700377 err = rtc_read_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800378 if (err < 0)
379 return err;
380
381 if (copy_to_user(uarg, &alarm, sizeof(alarm)))
David Brownell5ad31a572008-07-23 21:30:33 -0700382 err = -EFAULT;
383 return err;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800384
385 default:
John Stultzac54cd22011-02-02 16:55:19 -0800386 /* Finally try the driver's ioctl interface */
387 if (ops->ioctl) {
388 err = ops->ioctl(rtc->dev.parent, cmd, arg);
389 if (err == -ENOIOCTLCMD)
390 err = -ENOTTY;
Alexandre Belloni606cc432019-03-20 12:59:09 +0100391 } else {
John Stultze17fd4ba2011-05-31 23:26:11 -0700392 err = -ENOTTY;
Alexandre Belloni606cc432019-03-20 12:59:09 +0100393 }
Alessandro Zummoe8242902006-03-27 01:16:41 -0800394 break;
395 }
396
David Brownell5ad31a572008-07-23 21:30:33 -0700397done:
398 mutex_unlock(&rtc->ops_lock);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800399 return err;
400}
401
Marcin Slusarz2e4a75c2008-10-03 15:23:36 -0700402static int rtc_dev_fasync(int fd, struct file *file, int on)
403{
404 struct rtc_device *rtc = file->private_data;
Alexandre Belloni606cc432019-03-20 12:59:09 +0100405
Marcin Slusarz2e4a75c2008-10-03 15:23:36 -0700406 return fasync_helper(fd, file, on, &rtc->async_queue);
407}
408
Alessandro Zummoe8242902006-03-27 01:16:41 -0800409static int rtc_dev_release(struct inode *inode, struct file *file)
410{
Mark Zhan88efe132007-10-16 01:28:17 -0700411 struct rtc_device *rtc = file->private_data;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800412
David Brownell743e6a52008-10-15 22:03:04 -0700413 /* We shut down the repeating IRQs that userspace enabled,
414 * since nothing is listening to them.
415 * - Update (UIE) ... currently only managed through ioctls
416 * - Periodic (PIE) ... also used through rtc_*() interface calls
417 *
418 * Leave the alarm alone; it may be set to trigger a system wakeup
419 * later, or be used by kernel code, and is a one-shot event anyway.
420 */
Alessandro Zummo099e6572009-01-04 12:00:54 -0800421
422 /* Keep ioctl until all drivers are converted */
David Brownell743e6a52008-10-15 22:03:04 -0700423 rtc_dev_ioctl(file, RTC_UIE_OFF, 0);
Alessandro Zummo099e6572009-01-04 12:00:54 -0800424 rtc_update_irq_enable(rtc, 0);
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200425 rtc_irq_set_state(rtc, 0);
Tomas Janousek5cdc98b2008-07-29 22:33:51 -0700426
Jiri Kosina372a3022007-12-04 23:45:05 -0800427 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800428 return 0;
429}
430
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800431static const struct file_operations rtc_dev_fops = {
Alessandro Zummoe8242902006-03-27 01:16:41 -0800432 .owner = THIS_MODULE,
433 .llseek = no_llseek,
434 .read = rtc_dev_read,
435 .poll = rtc_dev_poll,
David Brownell5ad31a572008-07-23 21:30:33 -0700436 .unlocked_ioctl = rtc_dev_ioctl,
Alessandro Zummoe8242902006-03-27 01:16:41 -0800437 .open = rtc_dev_open,
438 .release = rtc_dev_release,
439 .fasync = rtc_dev_fasync,
440};
441
442/* insertion/removal hooks */
443
David Brownellcb3a58d2007-05-08 00:33:46 -0700444void rtc_dev_prepare(struct rtc_device *rtc)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800445{
David Brownell5726fb22007-05-08 00:33:27 -0700446 if (!rtc_devt)
447 return;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800448
449 if (rtc->id >= RTC_DEV_MAX) {
Alexandre Belloni9f860652017-06-02 14:01:37 +0200450 dev_dbg(&rtc->dev, "too many RTC devices\n");
David Brownell5726fb22007-05-08 00:33:27 -0700451 return;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800452 }
453
David Brownellcd966202007-05-08 00:33:40 -0700454 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
David Brownell5726fb22007-05-08 00:33:27 -0700455
John Stultz6e57b1d2011-02-11 17:45:40 -0800456#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
457 INIT_WORK(&rtc->uie_task, rtc_uie_task);
Kees Cooke99e88a2017-10-16 14:43:17 -0700458 timer_setup(&rtc->uie_timer, rtc_uie_timer, 0);
John Stultz6e57b1d2011-02-11 17:45:40 -0800459#endif
460
Alessandro Zummoe8242902006-03-27 01:16:41 -0800461 cdev_init(&rtc->char_dev, &rtc_dev_fops);
462 rtc->char_dev.owner = rtc->owner;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800463}
464
David Brownell5726fb22007-05-08 00:33:27 -0700465void __init rtc_dev_init(void)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800466{
467 int err;
468
Alessandro Zummoe8242902006-03-27 01:16:41 -0800469 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
David Brownell5726fb22007-05-08 00:33:27 -0700470 if (err < 0)
Jingoo Hanc100a5e2013-02-21 16:45:23 -0800471 pr_err("failed to allocate char dev region\n");
Alessandro Zummoe8242902006-03-27 01:16:41 -0800472}
473
David Brownell5726fb22007-05-08 00:33:27 -0700474void __exit rtc_dev_exit(void)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800475{
David Brownell5726fb22007-05-08 00:33:27 -0700476 if (rtc_devt)
477 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800478}