]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/char/omap-rtc.c
[PATCH] ARM: OMAP: RTC
[linux-2.6-omap-h63xx.git] / drivers / char / omap-rtc.c
1 /*
2  *      TI OMAP Real Time Clock interface for Linux     
3  *
4  *      Copyright (C) 2003 MontaVista Software, Inc.
5  *      Author: George G. Davis <gdavis@mvista.com> or <source@mvista.com>
6  *
7  *      Initially based on linux-2.4.20/drivers/char/rtc.c
8  *      Copyright (C) 1996 Paul Gortmaker
9  *
10  *      This driver allows use of the real time clock (built into
11  *      nearly all computers) from user space. It exports the /dev/rtc
12  *      interface supporting various ioctl() and also the
13  *      /proc/driver/rtc pseudo-file for status information.
14  *
15  *      The ioctls can be used to set the interrupt behaviour from the
16  *      RTC via IRQs. Then the /dev/rtc interface can be used to make
17  *      use of RTC interrupts, be they time update or alarm based.
18  *
19  *      The /dev/rtc interface will block on reads until an interrupt
20  *      has been received. If a RTC interrupt has already happened,
21  *      it will output an unsigned long and then block. The output value
22  *      contains the interrupt status in the low byte and the number of
23  *      interrupts since the last read in the remaining high bytes. The 
24  *      /dev/rtc interface can also be used with the select(2) call.
25  *
26  *      This program is free software; you can redistribute it and/or
27  *      modify it under the terms of the GNU General Public License
28  *      as published by the Free Software Foundation; either version
29  *      2 of the License, or (at your option) any later version.
30  *
31  *      Based on other minimal char device drivers, like Alan's
32  *      watchdog, Ted's random, etc. etc.
33  *
34  * Change Log :
35  *      v1.0    <gdavis@mvista.com> Initial version based on rtc.c v1.10e
36  *              <ramakrishnan@india.ti.com> Added support for 2.6 kernel, 
37  *                  - changed the return value of the interrupt handler
38  */
39
40 /*
41  *      Note that *all* calls to CMOS_READ and CMOS_WRITE are done with
42  *      interrupts disabled.
43  *      REVISIT: Elaborate on OMAP1510 TRM 15uS BUSY access rule.
44  */
45
46 #include <linux/config.h>
47 #include <linux/module.h>
48 #include <linux/kernel.h>
49 #include <linux/types.h>
50 #include <linux/miscdevice.h>
51 #include <linux/ioport.h>
52 #include <linux/fcntl.h>
53 #include <linux/init.h>
54 #include <linux/poll.h>
55 #include <linux/proc_fs.h>
56 #include <linux/spinlock.h>
57 #include <linux/device.h>
58 #include <linux/interrupt.h>
59 #include <linux/rtc.h>
60 #include <linux/bcd.h>
61
62 #include <asm/io.h>
63 #include <asm/uaccess.h>
64 #include <asm/system.h>
65 #include <asm/hardware.h>
66 #include <asm/irq.h>
67
68 #include "omap-rtc.h"
69
70 extern spinlock_t rtc_lock;
71
72
73 /* OMAP RTC register access macros: */
74
75 #define CMOS_READ(addr)         omap_readb(addr)
76 #define CMOS_WRITE(val, addr)   omap_writeb(val, addr)
77
78 static struct fasync_struct *rtc_async_queue;
79
80 static DECLARE_WAIT_QUEUE_HEAD(rtc_wait);
81
82 static void get_rtc_time (struct rtc_time *rtc_tm);
83 static void get_rtc_alm_time (struct rtc_time *alm_tm);
84
85 static void set_rtc_irq_bit(unsigned char bit);
86 static void mask_rtc_irq_bit(unsigned char bit);
87
88 static int rtc_read_proc(char *page, char **start, off_t off,
89                          int count, int *eof, void *data);
90
91 /*
92  *      Bits in rtc_status. (7 bits of room for future expansion)
93  */
94
95 #define RTC_IS_OPEN             0x01    /* means /dev/rtc is in use     */
96
97 /*
98  * REVISIT: fix this comment:
99  * rtc_status is never changed by rtc_interrupt, and ioctl/open/close is
100  * protected by the big kernel lock.
101  */
102 static unsigned long rtc_status = 0;    /* bitmapped status byte.       */
103 static unsigned long rtc_irq_data = 0;  /* our output to the world      */
104
105 /*
106  *      If this driver ever becomes modularised, it will be really nice
107  *      to make the epoch retain its value across module reload...
108  */
109
110 static unsigned long epoch = 1900;      /* year corresponding to 0x00   */
111
112 static const unsigned char days_in_mo[] = 
113 {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
114
115 /*
116  *      A very tiny interrupt handler. It runs with SA_INTERRUPT set.
117  */
118
119 static irqreturn_t rtc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
120 {
121         /*
122          *      Either an alarm interrupt or update complete interrupt.
123          *      We store the status in the low byte and the number of
124          *      interrupts received since the last read in the remainder
125          *      of rtc_irq_data.
126          */
127
128         spin_lock (&rtc_lock);
129
130         rtc_irq_data += 0x100;
131         rtc_irq_data &= ~0xff;
132         rtc_irq_data |= CMOS_READ(OMAP_RTC_STATUS_REG);
133
134         if (rtc_irq_data & OMAP_RTC_STATUS_ALARM)
135                 CMOS_WRITE(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG);
136
137         spin_unlock (&rtc_lock);
138
139         /* Now do the rest of the actions */
140         wake_up_interruptible(&rtc_wait);       
141
142         kill_fasync (&rtc_async_queue, SIGIO, POLL_IN);
143         return IRQ_HANDLED;
144 }
145
146 /*
147  *      Now all the various file operations that we export.
148  */
149
150 static ssize_t rtc_read(struct file *file, char __user *buf,
151                         size_t count, loff_t *ppos)
152 {
153         DECLARE_WAITQUEUE(wait, current);
154         unsigned long data;
155         ssize_t retval;
156         
157         if (count < sizeof(unsigned long))
158                 return -EINVAL;
159
160         add_wait_queue(&rtc_wait, &wait);
161         set_current_state(TASK_INTERRUPTIBLE);
162
163         for (;;) {
164                 spin_lock_irq (&rtc_lock);
165                 data = rtc_irq_data;
166                 if (data != 0) {
167                         rtc_irq_data = 0;
168                         break;
169                 }
170                 spin_unlock_irq (&rtc_lock);
171
172                 if (file->f_flags & O_NONBLOCK) {
173                         retval = -EAGAIN;
174                         goto out;
175                 }
176                 if (signal_pending(current)) {
177                         retval = -ERESTARTSYS;
178                         goto out;
179                 }
180                 schedule();
181         }
182
183         spin_unlock_irq (&rtc_lock);
184         retval = put_user(data, (unsigned long __user *)buf);
185         if (!retval)
186                 retval = sizeof(unsigned long); 
187  out:
188         set_current_state(TASK_RUNNING);
189         remove_wait_queue(&rtc_wait, &wait);
190
191         return retval;
192 }
193
194 /* convert from userspace struct to hardware BCD-encoded version,
195  * or return error code
196  */
197 static int utm2bcd(struct rtc_time __user *arg, struct rtc_time *tm)
198 {
199         unsigned char leap_yr;
200
201         if (copy_from_user(tm, arg, sizeof(struct rtc_time)))
202                 return -EFAULT;
203
204         tm->tm_year += 1900;
205         tm->tm_mon++;
206
207         if (tm->tm_year < 1970)
208                 return -EINVAL;
209
210         leap_yr = (!(tm->tm_year % 4) && (tm->tm_year % 100))
211                         || !(tm->tm_year % 400);
212
213         if ((tm->tm_mon > 12) || (tm->tm_mday == 0))
214                 return -EINVAL;
215
216         if (tm->tm_mday > (days_in_mo[tm->tm_mon] + ((tm->tm_mon == 2) && leap_yr)))
217                 return -EINVAL;
218
219         if ((tm->tm_hour >= 24) || (tm->tm_min >= 60) || (tm->tm_sec >= 60))
220                 return -EINVAL;
221
222         if ((tm->tm_year -= epoch) > 255)    /* They are unsigned */
223                 return -EINVAL;
224
225         if (tm->tm_year > 169)
226                 return -EINVAL;
227
228         if (tm->tm_year >= 100)
229                 tm->tm_year -= 100;
230
231         BIN_TO_BCD(tm->tm_sec);
232         BIN_TO_BCD(tm->tm_min);
233         BIN_TO_BCD(tm->tm_hour);
234         BIN_TO_BCD(tm->tm_mday);
235         BIN_TO_BCD(tm->tm_mon);
236         BIN_TO_BCD(tm->tm_year);
237
238         return 0;
239 }
240
241 static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
242                      unsigned long arg)
243 {
244         struct rtc_time wtime; 
245         int status = 0;
246         u8 save_control;
247
248         switch (cmd) {
249         case RTC_AIE_OFF:       /* Mask alarm int. enab. bit    */
250                 mask_rtc_irq_bit(OMAP_RTC_INTERRUPTS_IT_ALARM);
251                 break;
252         case RTC_AIE_ON:        /* Allow alarm interrupts.      */
253                 set_rtc_irq_bit(OMAP_RTC_INTERRUPTS_IT_ALARM);
254                 break;
255         case RTC_UIE_OFF:       /* Mask ints from RTC updates.  */
256                 mask_rtc_irq_bit(OMAP_RTC_INTERRUPTS_IT_TIMER);
257                 break;
258         case RTC_UIE_ON:        /* Allow ints for RTC updates.  */
259                 set_rtc_irq_bit(OMAP_RTC_INTERRUPTS_IT_TIMER);
260                 break;
261         case RTC_ALM_READ:      /* Read the present alarm time */
262                 /*
263                  * This returns a struct rtc_time. Reading >= 0xc0
264                  * means "don't care" or "match all". Only the tm_hour,
265                  * tm_min, and tm_sec values are filled in.
266                  */
267                 memset(&wtime, 0, sizeof(struct rtc_time));
268                 get_rtc_alm_time(&wtime);
269                 goto return_wtime;
270         case RTC_ALM_SET:       /* Store a time into the alarm */
271                 status = utm2bcd((void __user *)arg, &wtime);
272                 if (status != 0)
273                         return status;
274
275                 spin_lock_irq(&rtc_lock);
276                 CMOS_WRITE(wtime.tm_year, OMAP_RTC_ALARM_YEARS_REG);
277                 CMOS_WRITE(wtime.tm_mon, OMAP_RTC_ALARM_MONTHS_REG);
278                 CMOS_WRITE(wtime.tm_mday, OMAP_RTC_ALARM_DAYS_REG);
279                 CMOS_WRITE(wtime.tm_hour, OMAP_RTC_ALARM_HOURS_REG);
280                 CMOS_WRITE(wtime.tm_min, OMAP_RTC_ALARM_MINUTES_REG);
281                 CMOS_WRITE(wtime.tm_sec, OMAP_RTC_ALARM_SECONDS_REG);
282                 spin_unlock_irq(&rtc_lock);
283
284                 break;
285         case RTC_RD_TIME:       /* Read the time/date from RTC  */
286                 memset(&wtime, 0, sizeof(struct rtc_time));
287                 get_rtc_time(&wtime);
288                 goto return_wtime;
289         case RTC_SET_TIME:      /* Set the RTC */
290                 if (!capable(CAP_SYS_TIME))
291                         return -EACCES;
292
293                 status = utm2bcd((void __user *)arg, &wtime);
294                 if (status != 0)
295                         return status;
296
297                 spin_lock_irq(&rtc_lock);
298                 save_control = CMOS_READ(OMAP_RTC_CTRL_REG);
299                 CMOS_WRITE((save_control & ~OMAP_RTC_CTRL_STOP),
300                            OMAP_RTC_CTRL_REG);
301                 CMOS_WRITE(wtime.tm_year, OMAP_RTC_YEARS_REG);
302                 CMOS_WRITE(wtime.tm_mon, OMAP_RTC_MONTHS_REG);
303                 CMOS_WRITE(wtime.tm_mday, OMAP_RTC_DAYS_REG);
304                 CMOS_WRITE(wtime.tm_hour, OMAP_RTC_HOURS_REG);
305                 CMOS_WRITE(wtime.tm_min, OMAP_RTC_MINUTES_REG);
306                 CMOS_WRITE(wtime.tm_sec, OMAP_RTC_SECONDS_REG);
307                 CMOS_WRITE((save_control | OMAP_RTC_CTRL_STOP),
308                            OMAP_RTC_CTRL_REG);
309                 spin_unlock_irq(&rtc_lock);
310
311                 break;
312         case RTC_EPOCH_READ:    /* Read the epoch.      */
313                 status = put_user (epoch, (unsigned long  __user *)arg);
314                 break;
315         case RTC_EPOCH_SET:     /* Set the epoch.       */
316                 if (!capable(CAP_SYS_TIME))
317                         return -EACCES;
318
319                 /* 
320                  * There were no RTC clocks before 1900.
321                  */
322                 if (arg < 1900)
323                         status = -EINVAL;
324                 else
325                         epoch = arg;
326                 break;
327         default:
328                 status = -ENOTTY;
329         }
330         return status;
331
332 return_wtime:
333         return copy_to_user((void  __user *)arg, &wtime, sizeof wtime)
334                 ? -EFAULT
335                 : 0;
336 }
337
338 /*
339  *      We enforce only one user at a time here with the open/close.
340  *      Also clear the previous interrupt data on an open, and clean
341  *      up things on a close.
342  */
343
344 /* We use rtc_lock to protect against concurrent opens. So the BKL is not
345  * needed here. Or anywhere else in this driver. */
346 static int rtc_open(struct inode *inode, struct file *file)
347 {
348         spin_lock_irq (&rtc_lock);
349
350         if (rtc_status & RTC_IS_OPEN)
351                 goto out_busy;
352
353         rtc_status |= RTC_IS_OPEN;
354
355         rtc_irq_data = 0;
356         spin_unlock_irq (&rtc_lock);
357         return 0;
358
359 out_busy:
360         spin_unlock_irq (&rtc_lock);
361         return -EBUSY;
362 }
363
364 static int rtc_fasync(int fd, struct file *filp, int on)
365 {
366         return fasync_helper (fd, filp, on, &rtc_async_queue);
367 }
368
369 static int rtc_release(struct inode *inode, struct file *file)
370 {
371         unsigned char tmp;
372
373         /*
374          * Turn off all interrupts once the device is no longer
375          * in use, and clear the data.
376          */
377
378         spin_lock_irq(&rtc_lock);
379         tmp = CMOS_READ(OMAP_RTC_INTERRUPTS_REG);
380         tmp &=  ~OMAP_RTC_INTERRUPTS_IT_ALARM;
381         tmp &=  ~OMAP_RTC_INTERRUPTS_IT_TIMER;
382         CMOS_WRITE(tmp, OMAP_RTC_INTERRUPTS_REG);
383         spin_unlock_irq(&rtc_lock);
384
385         if (file->f_flags & FASYNC) {
386                 rtc_fasync (-1, file, 0);
387         }
388
389         spin_lock_irq (&rtc_lock);
390         rtc_irq_data = 0;
391         spin_unlock_irq (&rtc_lock);
392
393         /* No need for locking -- nobody else can do anything until this rmw
394          * is committed, and we don't implement timer support in omap-rtc.
395          */
396         rtc_status &= ~RTC_IS_OPEN;
397         return 0;
398 }
399
400 /* Called without the kernel lock - fine */
401 static unsigned int rtc_poll(struct file *file, poll_table *wait)
402 {
403         unsigned long l;
404
405         poll_wait(file, &rtc_wait, wait);
406
407         spin_lock_irq (&rtc_lock);
408         l = rtc_irq_data;
409         spin_unlock_irq (&rtc_lock);
410
411         if (l != 0)
412                 return POLLIN | POLLRDNORM;
413         return 0;
414 }
415
416 /*
417  *      The various file operations we support.
418  */
419
420 static struct file_operations rtc_fops = {
421         .owner          = THIS_MODULE,
422         .llseek         = no_llseek,
423         .read           = rtc_read,
424         .poll           = rtc_poll,
425         .ioctl          = rtc_ioctl,
426         .open           = rtc_open,
427         .release        = rtc_release,
428         .fasync         = rtc_fasync,
429 };
430
431 static struct miscdevice rtc_dev = {
432         .minor          = RTC_MINOR,
433         .name           = "rtc",
434         .fops           = &rtc_fops,
435 };
436
437 static int __init omap_rtc_probe(struct device *dev)
438 {
439         struct platform_device  *pdev = to_platform_device(dev);
440         struct resource         *res, *mem;
441
442         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
443         if (res)
444                 mem = request_mem_region(res->start,
445                                 res->end - res->start + 1,
446                                 pdev->name);
447         else
448                 mem = NULL;
449         if (!mem) {
450                 pr_debug("%s: RTC registers at %x are not free.\n",
451                         pdev->name, OMAP_RTC_BASE);
452                 return -EBUSY;
453         }
454         dev_set_drvdata(dev, mem);
455
456         if (CMOS_READ(OMAP_RTC_STATUS_REG) & OMAP_RTC_STATUS_POWER_UP) {
457                 pr_info("%s: RTC power up reset detected.\n",
458                         pdev->name);
459                 /* Clear OMAP_RTC_STATUS_POWER_UP */
460                 CMOS_WRITE(OMAP_RTC_STATUS_POWER_UP, OMAP_RTC_STATUS_REG);
461         }
462
463         if (CMOS_READ(OMAP_RTC_STATUS_REG) & OMAP_RTC_STATUS_ALARM) {
464                 pr_debug("%s: Clearing RTC ALARM interrupt.\n",
465                         pdev->name);
466                 /* Clear OMAP_RTC_STATUS_ALARM */
467                 CMOS_WRITE(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG);
468         }
469
470         if (request_irq(INT_RTC_TIMER, rtc_interrupt, SA_INTERRUPT,
471                         pdev->name, NULL)) {
472                 pr_debug("%s: RTC timer interrupt IRQ%d is not free.\n",
473                         pdev->name, INT_RTC_TIMER);
474                 goto fail;
475         }
476
477         if (request_irq(INT_RTC_ALARM, rtc_interrupt, SA_INTERRUPT,
478                         pdev->name, NULL)) {
479                 pr_debug("%s: RTC alarm interrupt IRQ%d is not free.\n",
480                         pdev->name, INT_RTC_ALARM);
481                 free_irq(INT_RTC_TIMER, NULL);
482                 goto fail;
483         }
484
485         /* On boards with split power, RTC_ON_NOFF resets all but the RTC */
486         if (!(CMOS_READ(OMAP_RTC_CTRL_REG) & OMAP_RTC_CTRL_STOP)) {
487                 pr_info("%s: Enabling RTC.\n", pdev->name);
488                 CMOS_WRITE(OMAP_RTC_CTRL_STOP, OMAP_RTC_CTRL_REG);
489         } else
490                 pr_info("%s: RTC already running.\n", pdev->name);
491
492         spin_lock_init(&rtc_lock);
493         misc_register(&rtc_dev);
494         create_proc_read_entry("driver/rtc", 0, NULL, rtc_read_proc, NULL);
495
496         return 0;
497
498 fail:
499         release_resource(mem);
500         return -EIO;
501 }
502
503 static int __exit omap_rtc_remove(struct device *dev)
504 {
505         free_irq (INT_RTC_TIMER, NULL);
506         free_irq (INT_RTC_ALARM, NULL);
507
508         remove_proc_entry ("driver/rtc", NULL);
509         misc_deregister(&rtc_dev);
510
511         release_resource(dev_get_drvdata(dev));
512         return 0;
513 }
514
515 /*
516  *      Info exported via "/proc/driver/rtc".
517  */
518
519 static int rtc_proc_output (char *buf)
520 {
521 #define YN(value) ((value) ? "yes" : "no")
522         char *p;
523         struct rtc_time tm;
524
525         p = buf;
526
527         get_rtc_time(&tm);
528
529         /*
530          * There is no way to tell if the luser has the RTC set for local
531          * time or for Universal Standard Time (GMT). Probably local though.
532          */
533         p += sprintf(p,
534                      "rtc_time\t: %02d:%02d:%02d\n"
535                      "rtc_date\t: %04d-%02d-%02d\n"
536                      "rtc_epoch\t: %04lu\n",
537                      tm.tm_hour, tm.tm_min, tm.tm_sec,
538                      tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, epoch);
539
540         get_rtc_alm_time(&tm);
541
542         /*
543          * We implicitly assume 24hr mode here. Alarm values >= 0xc0 will
544          * match any value for that particular field. Values that are
545          * greater than a valid time, but less than 0xc0 shouldn't appear.
546          */
547         p += sprintf(p,
548                      "alarm_time\t: %02d:%02d:%02d\n"
549                      "alarm_date\t: %04d-%02d-%02d\n",
550                      tm.tm_hour, tm.tm_min, tm.tm_sec,
551                      tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
552
553         p += sprintf(p,
554                      "BCD\t\t: %s\n"
555                      "24hr\t\t: %s\n"
556                      "alarm_IRQ\t: %s\n"
557                      "update_IRQ\t: %s\n"
558                      "update_rate\t: %ud\n",
559                      YN(1),
560                      YN(1),
561                      YN(CMOS_READ(OMAP_RTC_INTERRUPTS_REG) &
562                         OMAP_RTC_INTERRUPTS_IT_ALARM),
563                      YN(CMOS_READ(OMAP_RTC_INTERRUPTS_REG) &
564                         OMAP_RTC_INTERRUPTS_IT_TIMER),
565                      CMOS_READ(OMAP_RTC_INTERRUPTS_REG) & 3 /* REVISIT */);
566
567         return  p - buf;
568 #undef YN
569 }
570
571 static int rtc_read_proc(char *page, char **start, off_t off,
572                          int count, int *eof, void *data)
573 {
574         int len = rtc_proc_output (page);
575
576         if (len <= off+count)
577                 *eof = 1;
578         *start = page + off;
579         len -= off;
580         if (len > count)
581                 len = count;
582         if (len < 0)
583                 len = 0;
584         return len;
585 }
586
587 /*
588  * Returns true if a clock update is in progress
589  */
590 static inline unsigned char rtc_is_updating(void)
591 {
592         unsigned char uip;
593
594         spin_lock_irq(&rtc_lock);
595         uip = (CMOS_READ(OMAP_RTC_STATUS_REG) & OMAP_RTC_STATUS_BUSY);
596         spin_unlock_irq(&rtc_lock);
597         return uip;
598 }
599
600 static void bcd2tm(struct rtc_time *tm)
601 {
602         BCD_TO_BIN(tm->tm_sec);
603         BCD_TO_BIN(tm->tm_min);
604         BCD_TO_BIN(tm->tm_hour);
605         BCD_TO_BIN(tm->tm_mday);
606         BCD_TO_BIN(tm->tm_mon);
607         BCD_TO_BIN(tm->tm_year);
608
609         /*
610          * Account for differences between how the RTC uses the values
611          * and how they are defined in a struct rtc_time;
612          */
613         if ((tm->tm_year += (epoch - 1900)) <= 69)
614                 tm->tm_year += 100;
615
616         tm->tm_mon--;
617 }
618
619
620 static void get_rtc_time(struct rtc_time *rtc_tm)
621 {
622         unsigned char ctrl;
623
624         /* REVISIT: Fix this comment!!!
625          * read RTC once any update in progress is done. The update
626          * can take just over 2ms. We wait 10 to 20ms. There is no need to
627          * to poll-wait (up to 1s - eeccch) for the falling edge of OMAP_RTC_STATUS_BUSY.
628          * If you need to know *exactly* when a second has started, enable
629          * periodic update complete interrupts, (via ioctl) and then 
630          * immediately read /dev/rtc which will block until you get the IRQ.
631          * Once the read clears, read the RTC time (again via ioctl). Easy.
632          */
633
634 #if     0 /* REVISIT: This need to do as the TRM says. */
635         unsigned long uip_watchdog = jiffies;
636         if (rtc_is_updating() != 0)
637                 while (jiffies - uip_watchdog < 2*HZ/100) {
638                         barrier();
639                         cpu_relax();
640                 }
641 #endif
642
643         /*
644          * Only the values that we read from the RTC are set. We leave
645          * tm_wday, tm_yday and tm_isdst untouched. Even though the
646          * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
647          * by the RTC when initially set to a non-zero value.
648          */
649         spin_lock_irq(&rtc_lock);
650         rtc_tm->tm_sec = CMOS_READ(OMAP_RTC_SECONDS_REG);
651         rtc_tm->tm_min = CMOS_READ(OMAP_RTC_MINUTES_REG);
652         rtc_tm->tm_hour = CMOS_READ(OMAP_RTC_HOURS_REG);
653         rtc_tm->tm_mday = CMOS_READ(OMAP_RTC_DAYS_REG);
654         rtc_tm->tm_mon = CMOS_READ(OMAP_RTC_MONTHS_REG);
655         rtc_tm->tm_year = CMOS_READ(OMAP_RTC_YEARS_REG);
656         ctrl = CMOS_READ(OMAP_RTC_CTRL_REG);
657         spin_unlock_irq(&rtc_lock);
658
659         bcd2tm(rtc_tm);
660 }
661
662 static void get_rtc_alm_time(struct rtc_time *alm_tm)
663 {
664         unsigned char ctrl;
665
666         spin_lock_irq(&rtc_lock);
667         alm_tm->tm_sec = CMOS_READ(OMAP_RTC_ALARM_SECONDS_REG);
668         alm_tm->tm_min = CMOS_READ(OMAP_RTC_ALARM_MINUTES_REG);
669         alm_tm->tm_hour = CMOS_READ(OMAP_RTC_ALARM_HOURS_REG);
670         alm_tm->tm_mday = CMOS_READ(OMAP_RTC_ALARM_DAYS_REG);
671         alm_tm->tm_mon = CMOS_READ(OMAP_RTC_ALARM_MONTHS_REG);
672         alm_tm->tm_year = CMOS_READ(OMAP_RTC_ALARM_YEARS_REG);
673         ctrl = CMOS_READ(OMAP_RTC_CTRL_REG);
674         spin_unlock_irq(&rtc_lock);
675
676         bcd2tm(alm_tm);
677 }
678
679 /*
680  * Used to disable/enable UIE and AIE interrupts.
681  */
682
683 static void mask_rtc_irq_bit(unsigned char bit)
684 {
685         unsigned char val;
686
687         spin_lock_irq(&rtc_lock);
688         val = CMOS_READ(OMAP_RTC_INTERRUPTS_REG);
689         val &=  ~bit;
690         CMOS_WRITE(val, OMAP_RTC_INTERRUPTS_REG);
691         rtc_irq_data = 0;
692         spin_unlock_irq(&rtc_lock);
693 }
694
695 static void set_rtc_irq_bit(unsigned char bit)
696 {
697         unsigned char val;
698
699         spin_lock_irq(&rtc_lock);
700         val = CMOS_READ(OMAP_RTC_INTERRUPTS_REG);
701         val |= bit;
702         CMOS_WRITE(val, OMAP_RTC_INTERRUPTS_REG);
703         rtc_irq_data = 0;
704         spin_unlock_irq(&rtc_lock);
705 }
706
707 static struct device_driver omap_rtc_driver = {
708         .name           = "omap_rtc",
709         .bus            = &platform_bus_type,
710         .probe          = omap_rtc_probe,
711         .remove         = __exit_p(omap_rtc_remove),
712 };
713
714 static int __init rtc_init(void)
715 {
716         return driver_register(&omap_rtc_driver);
717 }
718
719 static void __exit rtc_exit(void)
720 {
721         driver_unregister(&omap_rtc_driver);
722 }
723
724 module_init(rtc_init);
725 module_exit(rtc_exit);
726
727 MODULE_AUTHOR("George G. Davis (and others)");
728 MODULE_LICENSE("GPL");
729 MODULE_ALIAS_MISCDEV(RTC_MINOR);