blob: f68aae035b81cd685ec04a0f1e798227a073d382 [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;
60 rtc->uie_timer.expires = jiffies + HZ - (HZ/10);
61 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}
Kees Cooke99e88a2017-10-16 14:43:17 -070071static void rtc_uie_timer(struct timer_list *t)
John Stultz6e57b1d2011-02-11 17:45:40 -080072{
Kees Cooke99e88a2017-10-16 14:43:17 -070073 struct rtc_device *rtc = from_timer(rtc, t, uie_timer);
John Stultz6e57b1d2011-02-11 17:45:40 -080074 unsigned long flags;
75
76 spin_lock_irqsave(&rtc->irq_lock, flags);
77 rtc->uie_timer_active = 0;
78 rtc->uie_task_active = 1;
79 if ((schedule_work(&rtc->uie_task) == 0))
80 rtc->uie_task_active = 0;
81 spin_unlock_irqrestore(&rtc->irq_lock, flags);
82}
83
84static int clear_uie(struct rtc_device *rtc)
85{
86 spin_lock_irq(&rtc->irq_lock);
87 if (rtc->uie_irq_active) {
88 rtc->stop_uie_polling = 1;
89 if (rtc->uie_timer_active) {
90 spin_unlock_irq(&rtc->irq_lock);
91 del_timer_sync(&rtc->uie_timer);
92 spin_lock_irq(&rtc->irq_lock);
93 rtc->uie_timer_active = 0;
94 }
95 if (rtc->uie_task_active) {
96 spin_unlock_irq(&rtc->irq_lock);
97 flush_scheduled_work();
98 spin_lock_irq(&rtc->irq_lock);
99 }
100 rtc->uie_irq_active = 0;
101 }
102 spin_unlock_irq(&rtc->irq_lock);
103 return 0;
104}
105
106static int set_uie(struct rtc_device *rtc)
107{
108 struct rtc_time tm;
109 int err;
110
111 err = rtc_read_time(rtc, &tm);
112 if (err)
113 return err;
114 spin_lock_irq(&rtc->irq_lock);
115 if (!rtc->uie_irq_active) {
116 rtc->uie_irq_active = 1;
117 rtc->stop_uie_polling = 0;
118 rtc->oldsecs = tm.tm_sec;
119 rtc->uie_task_active = 1;
120 if (schedule_work(&rtc->uie_task) == 0)
121 rtc->uie_task_active = 0;
122 }
123 rtc->irq_data = 0;
124 spin_unlock_irq(&rtc->irq_lock);
125 return 0;
126}
127
128int rtc_dev_update_irq_enable_emul(struct rtc_device *rtc, unsigned int enabled)
129{
130 if (enabled)
131 return set_uie(rtc);
132 else
133 return clear_uie(rtc);
134}
135EXPORT_SYMBOL(rtc_dev_update_irq_enable_emul);
136
137#endif /* CONFIG_RTC_INTF_DEV_UIE_EMUL */
Alessandro Zummoe8242902006-03-27 01:16:41 -0800138
139static ssize_t
140rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
141{
Mark Zhan88efe132007-10-16 01:28:17 -0700142 struct rtc_device *rtc = file->private_data;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800143
144 DECLARE_WAITQUEUE(wait, current);
145 unsigned long data;
146 ssize_t ret;
147
Atsushi Nemoto3418ff72006-05-01 12:16:16 -0700148 if (count != sizeof(unsigned int) && count < sizeof(unsigned long))
Alessandro Zummoe8242902006-03-27 01:16:41 -0800149 return -EINVAL;
150
151 add_wait_queue(&rtc->irq_queue, &wait);
152 do {
153 __set_current_state(TASK_INTERRUPTIBLE);
154
155 spin_lock_irq(&rtc->irq_lock);
156 data = rtc->irq_data;
157 rtc->irq_data = 0;
158 spin_unlock_irq(&rtc->irq_lock);
159
160 if (data != 0) {
161 ret = 0;
162 break;
163 }
164 if (file->f_flags & O_NONBLOCK) {
165 ret = -EAGAIN;
166 break;
167 }
168 if (signal_pending(current)) {
169 ret = -ERESTARTSYS;
170 break;
171 }
172 schedule();
173 } while (1);
174 set_current_state(TASK_RUNNING);
175 remove_wait_queue(&rtc->irq_queue, &wait);
176
177 if (ret == 0) {
Atsushi Nemoto3418ff72006-05-01 12:16:16 -0700178 if (sizeof(int) != sizeof(long) &&
179 count == sizeof(unsigned int))
180 ret = put_user(data, (unsigned int __user *)buf) ?:
181 sizeof(unsigned int);
182 else
183 ret = put_user(data, (unsigned long __user *)buf) ?:
184 sizeof(unsigned long);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800185 }
186 return ret;
187}
188
Al Viroafc9a422017-07-03 06:39:46 -0400189static __poll_t rtc_dev_poll(struct file *file, poll_table *wait)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800190{
Mark Zhan88efe132007-10-16 01:28:17 -0700191 struct rtc_device *rtc = file->private_data;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800192 unsigned long data;
193
194 poll_wait(file, &rtc->irq_queue, wait);
195
196 data = rtc->irq_data;
197
Linus Torvaldsa9a08842018-02-11 14:34:03 -0800198 return (data != 0) ? (EPOLLIN | EPOLLRDNORM) : 0;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800199}
200
David Brownell5ad31a572008-07-23 21:30:33 -0700201static long rtc_dev_ioctl(struct file *file,
Alessandro Zummoe8242902006-03-27 01:16:41 -0800202 unsigned int cmd, unsigned long arg)
203{
204 int err = 0;
David Brownellab6a2d72007-05-08 00:33:30 -0700205 struct rtc_device *rtc = file->private_data;
David Brownellff8371a2006-09-30 23:28:17 -0700206 const struct rtc_class_ops *ops = rtc->ops;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800207 struct rtc_time tm;
208 struct rtc_wkalrm alarm;
209 void __user *uarg = (void __user *) arg;
210
David Brownell5ad31a572008-07-23 21:30:33 -0700211 err = mutex_lock_interruptible(&rtc->ops_lock);
212 if (err)
David Brownellb68bb262008-07-29 22:33:30 -0700213 return err;
David Brownell5ad31a572008-07-23 21:30:33 -0700214
David Brownell2601a462006-11-25 11:09:27 -0800215 /* check that the calling task has appropriate permissions
Alessandro Zummo110d6932006-06-25 05:48:20 -0700216 * for certain ioctls. doing this check here is useful
217 * to avoid duplicate code in each driver.
218 */
219 switch (cmd) {
220 case RTC_EPOCH_SET:
221 case RTC_SET_TIME:
222 if (!capable(CAP_SYS_TIME))
David Brownell5ad31a572008-07-23 21:30:33 -0700223 err = -EACCES;
Alessandro Zummo110d6932006-06-25 05:48:20 -0700224 break;
225
226 case RTC_IRQP_SET:
227 if (arg > rtc->max_user_freq && !capable(CAP_SYS_RESOURCE))
David Brownell5ad31a572008-07-23 21:30:33 -0700228 err = -EACCES;
Alessandro Zummo110d6932006-06-25 05:48:20 -0700229 break;
230
231 case RTC_PIE_ON:
Bryan Kadzban9d013d32007-10-16 01:28:23 -0700232 if (rtc->irq_freq > rtc->max_user_freq &&
233 !capable(CAP_SYS_RESOURCE))
David Brownell5ad31a572008-07-23 21:30:33 -0700234 err = -EACCES;
Alessandro Zummo110d6932006-06-25 05:48:20 -0700235 break;
236 }
237
David Brownell5ad31a572008-07-23 21:30:33 -0700238 if (err)
239 goto done;
240
John Stultzac54cd22011-02-02 16:55:19 -0800241 /*
David Brownell8a0bdfd72008-02-06 01:38:45 -0800242 * Drivers *SHOULD NOT* provide ioctl implementations
243 * for these requests. Instead, provide methods to
244 * support the following code, so that the RTC's main
245 * features are accessible without using ioctls.
246 *
247 * RTC and alarm times will be in UTC, by preference,
248 * but dual-booting with MS-Windows implies RTCs must
249 * use the local wall clock time.
Alessandro Zummoe8242902006-03-27 01:16:41 -0800250 */
251
252 switch (cmd) {
253 case RTC_ALM_READ:
David Brownell5ad31a572008-07-23 21:30:33 -0700254 mutex_unlock(&rtc->ops_lock);
255
David Brownellab6a2d72007-05-08 00:33:30 -0700256 err = rtc_read_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800257 if (err < 0)
258 return err;
259
260 if (copy_to_user(uarg, &alarm.time, sizeof(tm)))
David Brownell5ad31a572008-07-23 21:30:33 -0700261 err = -EFAULT;
262 return err;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800263
264 case RTC_ALM_SET:
David Brownell5ad31a572008-07-23 21:30:33 -0700265 mutex_unlock(&rtc->ops_lock);
266
Alessandro Zummoe8242902006-03-27 01:16:41 -0800267 if (copy_from_user(&alarm.time, uarg, sizeof(tm)))
268 return -EFAULT;
269
270 alarm.enabled = 0;
271 alarm.pending = 0;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800272 alarm.time.tm_wday = -1;
273 alarm.time.tm_yday = -1;
274 alarm.time.tm_isdst = -1;
David Brownellf8245c22007-05-08 00:34:07 -0700275
276 /* RTC_ALM_SET alarms may be up to 24 hours in the future.
277 * Rather than expecting every RTC to implement "don't care"
278 * for day/month/year fields, just force the alarm to have
279 * the right values for those fields.
280 *
281 * RTC_WKALM_SET should be used instead. Not only does it
282 * eliminate the need for a separate RTC_AIE_ON call, it
283 * doesn't have the "alarm 23:59:59 in the future" race.
284 *
285 * NOTE: some legacy code may have used invalid fields as
286 * wildcards, exposing hardware "periodic alarm" capabilities.
287 * Not supported here.
288 */
289 {
Xunlei Pang4ec23642015-01-22 02:31:52 +0000290 time64_t now, then;
David Brownellf8245c22007-05-08 00:34:07 -0700291
292 err = rtc_read_time(rtc, &tm);
293 if (err < 0)
294 return err;
Xunlei Pang4ec23642015-01-22 02:31:52 +0000295 now = rtc_tm_to_time64(&tm);
David Brownellf8245c22007-05-08 00:34:07 -0700296
297 alarm.time.tm_mday = tm.tm_mday;
298 alarm.time.tm_mon = tm.tm_mon;
299 alarm.time.tm_year = tm.tm_year;
300 err = rtc_valid_tm(&alarm.time);
301 if (err < 0)
302 return err;
Xunlei Pang4ec23642015-01-22 02:31:52 +0000303 then = rtc_tm_to_time64(&alarm.time);
David Brownellf8245c22007-05-08 00:34:07 -0700304
305 /* alarm may need to wrap into tomorrow */
306 if (then < now) {
Xunlei Pang4ec23642015-01-22 02:31:52 +0000307 rtc_time64_to_tm(now + 24 * 60 * 60, &tm);
David Brownellf8245c22007-05-08 00:34:07 -0700308 alarm.time.tm_mday = tm.tm_mday;
309 alarm.time.tm_mon = tm.tm_mon;
310 alarm.time.tm_year = tm.tm_year;
311 }
312 }
313
David Brownell5ad31a572008-07-23 21:30:33 -0700314 return rtc_set_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800315
316 case RTC_RD_TIME:
David Brownell5ad31a572008-07-23 21:30:33 -0700317 mutex_unlock(&rtc->ops_lock);
318
David Brownellab6a2d72007-05-08 00:33:30 -0700319 err = rtc_read_time(rtc, &tm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800320 if (err < 0)
321 return err;
322
323 if (copy_to_user(uarg, &tm, sizeof(tm)))
David Brownell5ad31a572008-07-23 21:30:33 -0700324 err = -EFAULT;
325 return err;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800326
327 case RTC_SET_TIME:
David Brownell5ad31a572008-07-23 21:30:33 -0700328 mutex_unlock(&rtc->ops_lock);
329
Alessandro Zummoe8242902006-03-27 01:16:41 -0800330 if (copy_from_user(&tm, uarg, sizeof(tm)))
331 return -EFAULT;
332
David Brownell5ad31a572008-07-23 21:30:33 -0700333 return rtc_set_time(rtc, &tm);
David Brownell2601a462006-11-25 11:09:27 -0800334
Alessandro Zummod691eb92007-10-16 01:28:15 -0700335 case RTC_PIE_ON:
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200336 err = rtc_irq_set_state(rtc, 1);
Alessandro Zummod691eb92007-10-16 01:28:15 -0700337 break;
338
339 case RTC_PIE_OFF:
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200340 err = rtc_irq_set_state(rtc, 0);
David Brownell2601a462006-11-25 11:09:27 -0800341 break;
342
Alessandro Zummo099e6572009-01-04 12:00:54 -0800343 case RTC_AIE_ON:
344 mutex_unlock(&rtc->ops_lock);
345 return rtc_alarm_irq_enable(rtc, 1);
346
347 case RTC_AIE_OFF:
348 mutex_unlock(&rtc->ops_lock);
349 return rtc_alarm_irq_enable(rtc, 0);
350
351 case RTC_UIE_ON:
352 mutex_unlock(&rtc->ops_lock);
353 return rtc_update_irq_enable(rtc, 1);
354
355 case RTC_UIE_OFF:
356 mutex_unlock(&rtc->ops_lock);
357 return rtc_update_irq_enable(rtc, 0);
358
David Brownell2601a462006-11-25 11:09:27 -0800359 case RTC_IRQP_SET:
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200360 err = rtc_irq_set_freq(rtc, arg);
Alessandro Zummod691eb92007-10-16 01:28:15 -0700361 break;
362
363 case RTC_IRQP_READ:
364 err = put_user(rtc->irq_freq, (unsigned long __user *)uarg);
David Brownell2601a462006-11-25 11:09:27 -0800365 break;
366
Alessandro Zummoe8242902006-03-27 01:16:41 -0800367 case RTC_WKALM_SET:
David Brownell5ad31a572008-07-23 21:30:33 -0700368 mutex_unlock(&rtc->ops_lock);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800369 if (copy_from_user(&alarm, uarg, sizeof(alarm)))
370 return -EFAULT;
371
David Brownell5ad31a572008-07-23 21:30:33 -0700372 return rtc_set_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800373
374 case RTC_WKALM_RD:
David Brownell5ad31a572008-07-23 21:30:33 -0700375 mutex_unlock(&rtc->ops_lock);
David Brownellab6a2d72007-05-08 00:33:30 -0700376 err = rtc_read_alarm(rtc, &alarm);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800377 if (err < 0)
378 return err;
379
380 if (copy_to_user(uarg, &alarm, sizeof(alarm)))
David Brownell5ad31a572008-07-23 21:30:33 -0700381 err = -EFAULT;
382 return err;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800383
384 default:
John Stultzac54cd22011-02-02 16:55:19 -0800385 /* Finally try the driver's ioctl interface */
386 if (ops->ioctl) {
387 err = ops->ioctl(rtc->dev.parent, cmd, arg);
388 if (err == -ENOIOCTLCMD)
389 err = -ENOTTY;
John Stultze17fd4ba2011-05-31 23:26:11 -0700390 } else
391 err = -ENOTTY;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800392 break;
393 }
394
David Brownell5ad31a572008-07-23 21:30:33 -0700395done:
396 mutex_unlock(&rtc->ops_lock);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800397 return err;
398}
399
Marcin Slusarz2e4a75c2008-10-03 15:23:36 -0700400static int rtc_dev_fasync(int fd, struct file *file, int on)
401{
402 struct rtc_device *rtc = file->private_data;
403 return fasync_helper(fd, file, on, &rtc->async_queue);
404}
405
Alessandro Zummoe8242902006-03-27 01:16:41 -0800406static int rtc_dev_release(struct inode *inode, struct file *file)
407{
Mark Zhan88efe132007-10-16 01:28:17 -0700408 struct rtc_device *rtc = file->private_data;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800409
David Brownell743e6a52008-10-15 22:03:04 -0700410 /* We shut down the repeating IRQs that userspace enabled,
411 * since nothing is listening to them.
412 * - Update (UIE) ... currently only managed through ioctls
413 * - Periodic (PIE) ... also used through rtc_*() interface calls
414 *
415 * Leave the alarm alone; it may be set to trigger a system wakeup
416 * later, or be used by kernel code, and is a one-shot event anyway.
417 */
Alessandro Zummo099e6572009-01-04 12:00:54 -0800418
419 /* Keep ioctl until all drivers are converted */
David Brownell743e6a52008-10-15 22:03:04 -0700420 rtc_dev_ioctl(file, RTC_UIE_OFF, 0);
Alessandro Zummo099e6572009-01-04 12:00:54 -0800421 rtc_update_irq_enable(rtc, 0);
Alexandre Belloni8719d3c2018-07-25 15:07:09 +0200422 rtc_irq_set_state(rtc, 0);
Tomas Janousek5cdc98b2008-07-29 22:33:51 -0700423
Jiri Kosina372a3022007-12-04 23:45:05 -0800424 clear_bit_unlock(RTC_DEV_BUSY, &rtc->flags);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800425 return 0;
426}
427
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800428static const struct file_operations rtc_dev_fops = {
Alessandro Zummoe8242902006-03-27 01:16:41 -0800429 .owner = THIS_MODULE,
430 .llseek = no_llseek,
431 .read = rtc_dev_read,
432 .poll = rtc_dev_poll,
David Brownell5ad31a572008-07-23 21:30:33 -0700433 .unlocked_ioctl = rtc_dev_ioctl,
Alessandro Zummoe8242902006-03-27 01:16:41 -0800434 .open = rtc_dev_open,
435 .release = rtc_dev_release,
436 .fasync = rtc_dev_fasync,
437};
438
439/* insertion/removal hooks */
440
David Brownellcb3a58d2007-05-08 00:33:46 -0700441void rtc_dev_prepare(struct rtc_device *rtc)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800442{
David Brownell5726fb22007-05-08 00:33:27 -0700443 if (!rtc_devt)
444 return;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800445
446 if (rtc->id >= RTC_DEV_MAX) {
Alexandre Belloni9f860652017-06-02 14:01:37 +0200447 dev_dbg(&rtc->dev, "too many RTC devices\n");
David Brownell5726fb22007-05-08 00:33:27 -0700448 return;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800449 }
450
David Brownellcd966202007-05-08 00:33:40 -0700451 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
David Brownell5726fb22007-05-08 00:33:27 -0700452
John Stultz6e57b1d2011-02-11 17:45:40 -0800453#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL
454 INIT_WORK(&rtc->uie_task, rtc_uie_task);
Kees Cooke99e88a2017-10-16 14:43:17 -0700455 timer_setup(&rtc->uie_timer, rtc_uie_timer, 0);
John Stultz6e57b1d2011-02-11 17:45:40 -0800456#endif
457
Alessandro Zummoe8242902006-03-27 01:16:41 -0800458 cdev_init(&rtc->char_dev, &rtc_dev_fops);
459 rtc->char_dev.owner = rtc->owner;
Alessandro Zummoe8242902006-03-27 01:16:41 -0800460}
461
David Brownell5726fb22007-05-08 00:33:27 -0700462void __init rtc_dev_init(void)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800463{
464 int err;
465
Alessandro Zummoe8242902006-03-27 01:16:41 -0800466 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
David Brownell5726fb22007-05-08 00:33:27 -0700467 if (err < 0)
Jingoo Hanc100a5e2013-02-21 16:45:23 -0800468 pr_err("failed to allocate char dev region\n");
Alessandro Zummoe8242902006-03-27 01:16:41 -0800469}
470
David Brownell5726fb22007-05-08 00:33:27 -0700471void __exit rtc_dev_exit(void)
Alessandro Zummoe8242902006-03-27 01:16:41 -0800472{
David Brownell5726fb22007-05-08 00:33:27 -0700473 if (rtc_devt)
474 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
Alessandro Zummoe8242902006-03-27 01:16:41 -0800475}