2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2008-01-30 20:31:09 +08:00
|
|
|
* Real Time Clock interface for Linux
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 1996 Paul Gortmaker
|
|
|
|
*
|
|
|
|
* This driver allows use of the real time clock (built into
|
|
|
|
* nearly all computers) from user space. It exports the /dev/rtc
|
|
|
|
* interface supporting various ioctl() and also the
|
|
|
|
* /proc/driver/rtc pseudo-file for status information.
|
|
|
|
*
|
|
|
|
* The ioctls can be used to set the interrupt behaviour and
|
|
|
|
* generation rate from the RTC via IRQ 8. Then the /dev/rtc
|
|
|
|
* interface can be used to make use of these timer interrupts,
|
|
|
|
* be they interval or alarm based.
|
|
|
|
*
|
|
|
|
* The /dev/rtc interface will block on reads until an interrupt
|
|
|
|
* has been received. If a RTC interrupt has already happened,
|
|
|
|
* it will output an unsigned long and then block. The output value
|
|
|
|
* contains the interrupt status in the low byte and the number of
|
2008-01-30 20:31:09 +08:00
|
|
|
* interrupts since the last read in the remaining high bytes. The
|
2005-04-17 06:20:36 +08:00
|
|
|
* /dev/rtc interface can also be used with the select(2) call.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Based on other minimal char device drivers, like Alan's
|
|
|
|
* watchdog, Ted's random, etc. etc.
|
|
|
|
*
|
|
|
|
* 1.07 Paul Gortmaker.
|
|
|
|
* 1.08 Miquel van Smoorenburg: disallow certain things on the
|
|
|
|
* DEC Alpha as the CMOS clock is also used for other things.
|
|
|
|
* 1.09 Nikita Schmidt: epoch support and some Alpha cleanup.
|
|
|
|
* 1.09a Pete Zaitcev: Sun SPARC
|
|
|
|
* 1.09b Jeff Garzik: Modularize, init cleanup
|
|
|
|
* 1.09c Jeff Garzik: SMP cleanup
|
2006-10-10 06:20:47 +08:00
|
|
|
* 1.10 Paul Barton-Davis: add support for async I/O
|
2005-04-17 06:20:36 +08:00
|
|
|
* 1.10a Andrea Arcangeli: Alpha updates
|
|
|
|
* 1.10b Andrew Morton: SMP lock fix
|
|
|
|
* 1.10c Cesar Barros: SMP locking fixes and cleanup
|
|
|
|
* 1.10d Paul Gortmaker: delete paranoia check in rtc_exit
|
|
|
|
* 1.10e Maciej W. Rozycki: Handle DECstation's year weirdness.
|
2006-10-10 06:20:47 +08:00
|
|
|
* 1.11 Takashi Iwai: Kernel access functions
|
2005-04-17 06:20:36 +08:00
|
|
|
* rtc_register/rtc_unregister/rtc_control
|
|
|
|
* 1.11a Daniele Bellucci: Audit create_proc_read_entry in rtc_init
|
|
|
|
* 1.12 Venkatesh Pallipadi: Hooks for emulating rtc on HPET base-timer
|
|
|
|
* CONFIG_HPET_EMULATE_RTC
|
2006-07-10 19:45:30 +08:00
|
|
|
* 1.12a Maciej W. Rozycki: Handle memory-mapped chips properly.
|
2006-01-12 04:17:32 +08:00
|
|
|
* 1.12ac Alan Cox: Allow read access to the day of week register
|
2008-10-23 16:25:56 +08:00
|
|
|
* 1.12b David John: Remove calls to the BKL.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2008-10-23 16:25:56 +08:00
|
|
|
#define RTC_VERSION "1.12b"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that *all* calls to CMOS_READ and CMOS_WRITE are done with
|
|
|
|
* interrupts disabled. Due to the index-port/data-port (0x70/0x71)
|
|
|
|
* design of the RTC, we don't want two different things trying to
|
2012-01-25 06:48:04 +08:00
|
|
|
* get to it at once. (e.g. the periodic 11 min sync from
|
|
|
|
* kernel/time/ntp.c vs. this driver.)
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/mc146818rtc.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/proc_fs.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/spinlock.h>
|
2017-02-03 02:15:33 +08:00
|
|
|
#include <linux/sched/signal.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/wait.h>
|
|
|
|
#include <linux/bcd.h>
|
2005-06-29 11:44:42 +08:00
|
|
|
#include <linux/delay.h>
|
2008-07-24 12:30:32 +08:00
|
|
|
#include <linux/uaccess.h>
|
2011-06-04 23:36:33 +08:00
|
|
|
#include <linux/ratelimit.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/current.h>
|
|
|
|
|
2007-07-21 23:10:09 +08:00
|
|
|
#ifdef CONFIG_X86
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/hpet.h>
|
|
|
|
#endif
|
|
|
|
|
2007-07-20 04:59:58 +08:00
|
|
|
#ifdef CONFIG_SPARC32
|
2008-08-30 15:23:51 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
|
|
|
#include <asm/io.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static unsigned long rtc_port;
|
2008-08-30 15:23:51 +08:00
|
|
|
static int rtc_irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2008-10-16 13:03:00 +08:00
|
|
|
#ifdef CONFIG_HPET_EMULATE_RTC
|
2005-04-17 06:20:36 +08:00
|
|
|
#undef RTC_IRQ
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
static int rtc_has_irq = 1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_HPET_EMULATE_RTC
|
|
|
|
#define is_hpet_enabled() 0
|
2008-01-30 20:31:09 +08:00
|
|
|
#define hpet_set_alarm_time(hrs, min, sec) 0
|
|
|
|
#define hpet_set_periodic_freq(arg) 0
|
|
|
|
#define hpet_mask_rtc_irq_bit(arg) 0
|
|
|
|
#define hpet_set_rtc_irq_bit(arg) 0
|
|
|
|
#define hpet_rtc_timer_init() do { } while (0)
|
|
|
|
#define hpet_rtc_dropped_irq() 0
|
2008-02-28 21:29:43 +08:00
|
|
|
#define hpet_register_irq_handler(h) ({ 0; })
|
|
|
|
#define hpet_unregister_irq_handler(h) ({ 0; })
|
2006-12-22 17:06:36 +08:00
|
|
|
#ifdef RTC_IRQ
|
|
|
|
static irqreturn_t hpet_rtc_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We sponge a minor off of the misc major. No need slurping
|
|
|
|
* up another valuable major dev number for this. If you add
|
|
|
|
* an ioctl, make sure you don't conflict with SPARC's RTC
|
|
|
|
* ioctls.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct fasync_struct *rtc_async_queue;
|
|
|
|
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(rtc_wait);
|
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
2017-08-29 02:28:21 +08:00
|
|
|
static void rtc_dropped_irq(struct timer_list *unused);
|
2007-02-12 16:52:31 +08:00
|
|
|
|
2017-10-05 07:27:04 +08:00
|
|
|
static DEFINE_TIMER(rtc_irq_timer, rtc_dropped_irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static ssize_t rtc_read(struct file *file, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos);
|
|
|
|
|
2008-07-24 12:30:32 +08:00
|
|
|
static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
|
2008-07-26 10:46:25 +08:00
|
|
|
static void rtc_get_rtc_time(struct rtc_time *rtc_tm);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
2017-07-03 18:39:46 +08:00
|
|
|
static __poll_t rtc_poll(struct file *file, poll_table *wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
static void get_rtc_alm_time(struct rtc_time *alm_tm);
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef RTC_IRQ
|
2005-11-07 18:14:57 +08:00
|
|
|
static void set_rtc_irq_bit_locked(unsigned char bit);
|
|
|
|
static void mask_rtc_irq_bit_locked(unsigned char bit);
|
|
|
|
|
|
|
|
static inline void set_rtc_irq_bit(unsigned char bit)
|
|
|
|
{
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
set_rtc_irq_bit_locked(bit);
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mask_rtc_irq_bit(unsigned char bit)
|
|
|
|
{
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
mask_rtc_irq_bit_locked(bit);
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2006-12-13 16:35:05 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2018-05-15 21:57:23 +08:00
|
|
|
static int rtc_proc_show(struct seq_file *seq, void *v);
|
2006-12-13 16:35:05 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bits in rtc_status. (6 bits of room for future expansion)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define RTC_IS_OPEN 0x01 /* means /dev/rtc is in use */
|
|
|
|
#define RTC_TIMER_ON 0x02 /* missed irq timer active */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* rtc_status is never changed by rtc_interrupt, and ioctl/open/close is
|
2008-10-23 16:25:56 +08:00
|
|
|
* protected by the spin lock rtc_lock. However, ioctl can still disable the
|
|
|
|
* timer in rtc_status and then with del_timer after the interrupt has read
|
2005-04-17 06:20:36 +08:00
|
|
|
* rtc_status but before mod_timer is called, which would then reenable the
|
|
|
|
* timer (but you would need to have an awful timing before you'd trip on it)
|
|
|
|
*/
|
2008-01-30 20:31:09 +08:00
|
|
|
static unsigned long rtc_status; /* bitmapped status byte. */
|
|
|
|
static unsigned long rtc_freq; /* Current periodic IRQ rate */
|
|
|
|
static unsigned long rtc_irq_data; /* our output to the world */
|
2005-04-17 06:20:36 +08:00
|
|
|
static unsigned long rtc_max_user_freq = 64; /* > this, need CAP_SYS_RESOURCE */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this driver ever becomes modularised, it will be really nice
|
|
|
|
* to make the epoch retain its value across module reload...
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned long epoch = 1900; /* year corresponding to 0x00 */
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
static const unsigned char days_in_mo[] =
|
2005-04-17 06:20:36 +08:00
|
|
|
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true if a clock update is in progress
|
|
|
|
*/
|
|
|
|
static inline unsigned char rtc_is_updating(void)
|
|
|
|
{
|
2006-09-26 07:24:23 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char uip;
|
|
|
|
|
2006-09-26 07:24:23 +08:00
|
|
|
spin_lock_irqsave(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
uip = (CMOS_READ(RTC_FREQ_SELECT) & RTC_UIP);
|
2006-09-26 07:24:23 +08:00
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return uip;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
/*
|
2013-10-13 12:14:42 +08:00
|
|
|
* A very tiny interrupt handler. It runs with interrupts disabled,
|
2005-04-17 06:20:36 +08:00
|
|
|
* but there is possibility of conflicting with the set_rtc_mmss()
|
|
|
|
* call (the rtc irq and the timer irq can easily run at the same
|
|
|
|
* time in two different CPUs). So we need to serialize
|
|
|
|
* accesses to the chip with the rtc_lock spinlock that each
|
|
|
|
* architecture should implement in the timer code.
|
|
|
|
* (See ./arch/XXXX/kernel/time.c for the set_rtc_mmss() function.)
|
|
|
|
*/
|
|
|
|
|
2008-07-26 10:46:25 +08:00
|
|
|
static irqreturn_t rtc_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Can be an alarm interrupt, update complete interrupt,
|
|
|
|
* or a periodic interrupt. We store the status in the
|
|
|
|
* low byte and the number of interrupts received since
|
|
|
|
* the last read in the remainder of rtc_irq_data.
|
|
|
|
*/
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_lock(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
rtc_irq_data += 0x100;
|
|
|
|
rtc_irq_data &= ~0xff;
|
|
|
|
if (is_hpet_enabled()) {
|
|
|
|
/*
|
|
|
|
* In this case it is HPET RTC interrupt handler
|
|
|
|
* calling us, with the interrupt information
|
|
|
|
* passed as arg1, instead of irq.
|
|
|
|
*/
|
|
|
|
rtc_irq_data |= (unsigned long)irq & 0xF0;
|
|
|
|
} else {
|
|
|
|
rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rtc_status & RTC_TIMER_ON)
|
|
|
|
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100);
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
wake_up_interruptible(&rtc_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
kill_fasync(&rtc_async_queue, SIGIO, POLL_IN);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sysctl-tuning infrastructure.
|
|
|
|
*/
|
2013-06-14 10:37:35 +08:00
|
|
|
static struct ctl_table rtc_table[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.procname = "max-user-freq",
|
|
|
|
.data = &rtc_max_user_freq,
|
|
|
|
.maxlen = sizeof(int),
|
|
|
|
.mode = 0644,
|
2009-11-16 19:11:48 +08:00
|
|
|
.proc_handler = proc_dointvec,
|
2005-04-17 06:20:36 +08:00
|
|
|
},
|
2009-11-06 06:34:02 +08:00
|
|
|
{ }
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2013-06-14 10:37:35 +08:00
|
|
|
static struct ctl_table rtc_root[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.procname = "rtc",
|
|
|
|
.mode = 0555,
|
|
|
|
.child = rtc_table,
|
|
|
|
},
|
2009-11-06 06:34:02 +08:00
|
|
|
{ }
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2013-06-14 10:37:35 +08:00
|
|
|
static struct ctl_table dev_root[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
.procname = "dev",
|
|
|
|
.mode = 0555,
|
|
|
|
.child = rtc_root,
|
|
|
|
},
|
2009-11-06 06:34:02 +08:00
|
|
|
{ }
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ctl_table_header *sysctl_header;
|
|
|
|
|
|
|
|
static int __init init_sysctl(void)
|
|
|
|
{
|
2007-02-14 16:34:09 +08:00
|
|
|
sysctl_header = register_sysctl_table(dev_root);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cleanup_sysctl(void)
|
|
|
|
{
|
|
|
|
unregister_sysctl_table(sysctl_header);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now all the various file operations that we export.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static ssize_t rtc_read(struct file *file, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
#ifndef RTC_IRQ
|
|
|
|
return -EIO;
|
|
|
|
#else
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
unsigned long data;
|
|
|
|
ssize_t retval;
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rtc_has_irq == 0)
|
|
|
|
return -EIO;
|
|
|
|
|
2006-07-10 19:45:30 +08:00
|
|
|
/*
|
|
|
|
* Historically this function used to assume that sizeof(unsigned long)
|
|
|
|
* is the same in userspace and kernelspace. This lead to problems
|
|
|
|
* for configurations with multiple ABIs such a the MIPS o32 and 64
|
|
|
|
* ABIs supported on the same kernel. So now we support read of both
|
|
|
|
* 4 and 8 bytes and assume that's the sizeof(unsigned long) in the
|
|
|
|
* userspace ABI.
|
|
|
|
*/
|
|
|
|
if (count != sizeof(unsigned int) && count != sizeof(unsigned long))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
add_wait_queue(&rtc_wait, &wait);
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* First make it right. Then make it fast. Putting this whole
|
|
|
|
* block within the parentheses of a while would be too
|
|
|
|
* confusing. And no, xchg() is not the answer. */
|
|
|
|
|
|
|
|
__set_current_state(TASK_INTERRUPTIBLE);
|
2008-01-30 20:31:09 +08:00
|
|
|
|
|
|
|
spin_lock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
data = rtc_irq_data;
|
|
|
|
rtc_irq_data = 0;
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (data != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
|
|
retval = -EAGAIN;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
retval = -ERESTARTSYS;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
schedule();
|
|
|
|
} while (1);
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
if (count == sizeof(unsigned int)) {
|
|
|
|
retval = put_user(data,
|
|
|
|
(unsigned int __user *)buf) ?: sizeof(int);
|
|
|
|
} else {
|
|
|
|
retval = put_user(data,
|
|
|
|
(unsigned long __user *)buf) ?: sizeof(long);
|
|
|
|
}
|
2006-07-10 19:45:30 +08:00
|
|
|
if (!retval)
|
|
|
|
retval = count;
|
2005-04-17 06:20:36 +08:00
|
|
|
out:
|
2007-05-08 15:30:52 +08:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-04-17 06:20:36 +08:00
|
|
|
remove_wait_queue(&rtc_wait, &wait);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
|
|
|
|
{
|
2008-01-30 20:31:09 +08:00
|
|
|
struct rtc_time wtime;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
if (rtc_has_irq == 0) {
|
|
|
|
switch (cmd) {
|
|
|
|
case RTC_AIE_OFF:
|
|
|
|
case RTC_AIE_ON:
|
|
|
|
case RTC_PIE_OFF:
|
|
|
|
case RTC_PIE_ON:
|
|
|
|
case RTC_UIE_OFF:
|
|
|
|
case RTC_UIE_ON:
|
|
|
|
case RTC_IRQP_READ:
|
|
|
|
case RTC_IRQP_SET:
|
|
|
|
return -EINVAL;
|
2012-09-13 01:03:18 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
case RTC_AIE_OFF: /* Mask alarm int. enab. bit */
|
|
|
|
{
|
|
|
|
mask_rtc_irq_bit(RTC_AIE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case RTC_AIE_ON: /* Allow alarm interrupts. */
|
|
|
|
{
|
|
|
|
set_rtc_irq_bit(RTC_AIE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case RTC_PIE_OFF: /* Mask periodic int. enab. bit */
|
|
|
|
{
|
2008-01-30 20:31:09 +08:00
|
|
|
/* can be called from isr via rtc_control() */
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&rtc_lock, flags);
|
2005-11-07 18:14:57 +08:00
|
|
|
mask_rtc_irq_bit_locked(RTC_PIE);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rtc_status & RTC_TIMER_ON) {
|
|
|
|
rtc_status &= ~RTC_TIMER_ON;
|
|
|
|
del_timer(&rtc_irq_timer);
|
|
|
|
}
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case RTC_PIE_ON: /* Allow periodic ints */
|
|
|
|
{
|
2008-01-30 20:31:09 +08:00
|
|
|
/* can be called from isr via rtc_control() */
|
|
|
|
unsigned long flags;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We don't really want Joe User enabling more
|
|
|
|
* than 64Hz of interrupts on a multi-user machine.
|
|
|
|
*/
|
|
|
|
if (!kernel && (rtc_freq > rtc_max_user_freq) &&
|
2008-01-30 20:31:09 +08:00
|
|
|
(!capable(CAP_SYS_RESOURCE)))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EACCES;
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_lock_irqsave(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(rtc_status & RTC_TIMER_ON)) {
|
2007-02-12 16:52:31 +08:00
|
|
|
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq +
|
|
|
|
2*HZ/100);
|
2005-04-17 06:20:36 +08:00
|
|
|
rtc_status |= RTC_TIMER_ON;
|
|
|
|
}
|
2005-11-07 18:14:57 +08:00
|
|
|
set_rtc_irq_bit_locked(RTC_PIE);
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case RTC_UIE_OFF: /* Mask ints from RTC updates. */
|
|
|
|
{
|
|
|
|
mask_rtc_irq_bit(RTC_UIE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case RTC_UIE_ON: /* Allow ints for RTC updates. */
|
|
|
|
{
|
|
|
|
set_rtc_irq_bit(RTC_UIE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case RTC_ALM_READ: /* Read the present alarm time */
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This returns a struct rtc_time. Reading >= 0xc0
|
|
|
|
* means "don't care" or "match all". Only the tm_hour,
|
|
|
|
* tm_min, and tm_sec values are filled in.
|
|
|
|
*/
|
|
|
|
memset(&wtime, 0, sizeof(struct rtc_time));
|
|
|
|
get_rtc_alm_time(&wtime);
|
2008-01-30 20:31:09 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
case RTC_ALM_SET: /* Store a time into the alarm */
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This expects a struct rtc_time. Writing 0xff means
|
|
|
|
* "don't care" or "match all". Only the tm_hour,
|
|
|
|
* tm_min and tm_sec are used.
|
|
|
|
*/
|
|
|
|
unsigned char hrs, min, sec;
|
|
|
|
struct rtc_time alm_tm;
|
|
|
|
|
|
|
|
if (copy_from_user(&alm_tm, (struct rtc_time __user *)arg,
|
|
|
|
sizeof(struct rtc_time)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
hrs = alm_tm.tm_hour;
|
|
|
|
min = alm_tm.tm_min;
|
|
|
|
sec = alm_tm.tm_sec;
|
|
|
|
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
if (hpet_set_alarm_time(hrs, min, sec)) {
|
|
|
|
/*
|
|
|
|
* Fallthru and set alarm time in CMOS too,
|
|
|
|
* so that we will get proper value in RTC_ALM_READ
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) ||
|
2008-01-30 20:31:09 +08:00
|
|
|
RTC_ALWAYS_BCD) {
|
|
|
|
if (sec < 60)
|
2008-10-19 11:28:42 +08:00
|
|
|
sec = bin2bcd(sec);
|
2008-01-30 20:31:09 +08:00
|
|
|
else
|
|
|
|
sec = 0xff;
|
|
|
|
|
|
|
|
if (min < 60)
|
2008-10-19 11:28:42 +08:00
|
|
|
min = bin2bcd(min);
|
2008-01-30 20:31:09 +08:00
|
|
|
else
|
|
|
|
min = 0xff;
|
|
|
|
|
|
|
|
if (hrs < 24)
|
2008-10-19 11:28:42 +08:00
|
|
|
hrs = bin2bcd(hrs);
|
2008-01-30 20:31:09 +08:00
|
|
|
else
|
|
|
|
hrs = 0xff;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
CMOS_WRITE(hrs, RTC_HOURS_ALARM);
|
|
|
|
CMOS_WRITE(min, RTC_MINUTES_ALARM);
|
|
|
|
CMOS_WRITE(sec, RTC_SECONDS_ALARM);
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case RTC_RD_TIME: /* Read the time/date from RTC */
|
|
|
|
{
|
|
|
|
memset(&wtime, 0, sizeof(struct rtc_time));
|
|
|
|
rtc_get_rtc_time(&wtime);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case RTC_SET_TIME: /* Set the RTC */
|
|
|
|
{
|
|
|
|
struct rtc_time rtc_tm;
|
|
|
|
unsigned char mon, day, hrs, min, sec, leap_yr;
|
|
|
|
unsigned char save_control, save_freq_select;
|
|
|
|
unsigned int yrs;
|
|
|
|
#ifdef CONFIG_MACH_DECSTATION
|
|
|
|
unsigned int real_yrs;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_TIME))
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
if (copy_from_user(&rtc_tm, (struct rtc_time __user *)arg,
|
|
|
|
sizeof(struct rtc_time)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
yrs = rtc_tm.tm_year + 1900;
|
|
|
|
mon = rtc_tm.tm_mon + 1; /* tm_mon starts at zero */
|
|
|
|
day = rtc_tm.tm_mday;
|
|
|
|
hrs = rtc_tm.tm_hour;
|
|
|
|
min = rtc_tm.tm_min;
|
|
|
|
sec = rtc_tm.tm_sec;
|
|
|
|
|
|
|
|
if (yrs < 1970)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
leap_yr = ((!(yrs % 4) && (yrs % 100)) || !(yrs % 400));
|
|
|
|
|
|
|
|
if ((mon > 12) || (day == 0))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (day > (days_in_mo[mon] + ((mon == 2) && leap_yr)))
|
|
|
|
return -EINVAL;
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((hrs >= 24) || (min >= 60) || (sec >= 60))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
yrs -= epoch;
|
|
|
|
if (yrs > 255) /* They are unsigned */
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
#ifdef CONFIG_MACH_DECSTATION
|
|
|
|
real_yrs = yrs;
|
|
|
|
yrs = 72;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to keep the year set to 73 until March
|
|
|
|
* for non-leap years, so that Feb, 29th is handled
|
|
|
|
* correctly.
|
|
|
|
*/
|
|
|
|
if (!leap_yr && mon < 3) {
|
|
|
|
real_yrs--;
|
|
|
|
yrs = 73;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/* These limits and adjustments are independent of
|
|
|
|
* whether the chip is in binary mode or not.
|
|
|
|
*/
|
|
|
|
if (yrs > 169) {
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (yrs >= 100)
|
|
|
|
yrs -= 100;
|
|
|
|
|
|
|
|
if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY)
|
|
|
|
|| RTC_ALWAYS_BCD) {
|
2008-10-19 11:28:42 +08:00
|
|
|
sec = bin2bcd(sec);
|
|
|
|
min = bin2bcd(min);
|
|
|
|
hrs = bin2bcd(hrs);
|
|
|
|
day = bin2bcd(day);
|
|
|
|
mon = bin2bcd(mon);
|
|
|
|
yrs = bin2bcd(yrs);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
save_control = CMOS_READ(RTC_CONTROL);
|
|
|
|
CMOS_WRITE((save_control|RTC_SET), RTC_CONTROL);
|
|
|
|
save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
|
|
|
|
CMOS_WRITE((save_freq_select|RTC_DIV_RESET2), RTC_FREQ_SELECT);
|
|
|
|
|
|
|
|
#ifdef CONFIG_MACH_DECSTATION
|
|
|
|
CMOS_WRITE(real_yrs, RTC_DEC_YEAR);
|
|
|
|
#endif
|
|
|
|
CMOS_WRITE(yrs, RTC_YEAR);
|
|
|
|
CMOS_WRITE(mon, RTC_MONTH);
|
|
|
|
CMOS_WRITE(day, RTC_DAY_OF_MONTH);
|
|
|
|
CMOS_WRITE(hrs, RTC_HOURS);
|
|
|
|
CMOS_WRITE(min, RTC_MINUTES);
|
|
|
|
CMOS_WRITE(sec, RTC_SECONDS);
|
|
|
|
|
|
|
|
CMOS_WRITE(save_control, RTC_CONTROL);
|
|
|
|
CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
|
|
|
|
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
case RTC_IRQP_READ: /* Read the periodic IRQ rate. */
|
|
|
|
{
|
|
|
|
return put_user(rtc_freq, (unsigned long __user *)arg);
|
|
|
|
}
|
|
|
|
case RTC_IRQP_SET: /* Set periodic IRQ rate. */
|
|
|
|
{
|
|
|
|
int tmp = 0;
|
|
|
|
unsigned char val;
|
2008-01-30 20:31:09 +08:00
|
|
|
/* can be called from isr via rtc_control() */
|
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* The max we can do is 8192Hz.
|
|
|
|
*/
|
|
|
|
if ((arg < 2) || (arg > 8192))
|
|
|
|
return -EINVAL;
|
|
|
|
/*
|
|
|
|
* We don't really want Joe User generating more
|
|
|
|
* than 64Hz of interrupts on a multi-user machine.
|
|
|
|
*/
|
2008-01-30 20:31:09 +08:00
|
|
|
if (!kernel && (arg > rtc_max_user_freq) &&
|
|
|
|
!capable(CAP_SYS_RESOURCE))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
while (arg > (1<<tmp))
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that the input was really a power of 2.
|
|
|
|
*/
|
|
|
|
if (arg != (1<<tmp))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2008-07-11 08:30:48 +08:00
|
|
|
rtc_freq = arg;
|
|
|
|
|
2005-11-07 18:14:57 +08:00
|
|
|
spin_lock_irqsave(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (hpet_set_periodic_freq(arg)) {
|
2005-11-07 18:14:57 +08:00
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = CMOS_READ(RTC_FREQ_SELECT) & 0xf0;
|
|
|
|
val |= (16 - tmp);
|
|
|
|
CMOS_WRITE(val, RTC_FREQ_SELECT);
|
2005-11-07 18:14:57 +08:00
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
case RTC_EPOCH_READ: /* Read the epoch. */
|
|
|
|
{
|
2008-01-30 20:31:09 +08:00
|
|
|
return put_user(epoch, (unsigned long __user *)arg);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
case RTC_EPOCH_SET: /* Set the epoch. */
|
|
|
|
{
|
2008-01-30 20:31:09 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* There were no RTC clocks before 1900.
|
|
|
|
*/
|
|
|
|
if (arg < 1900)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!capable(CAP_SYS_TIME))
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
epoch = arg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2008-01-30 20:31:09 +08:00
|
|
|
return copy_to_user((void __user *)arg,
|
|
|
|
&wtime, sizeof wtime) ? -EFAULT : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-07-24 12:30:32 +08:00
|
|
|
static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-07-24 12:30:32 +08:00
|
|
|
long ret;
|
|
|
|
ret = rtc_do_ioctl(cmd, arg, 0);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We enforce only one user at a time here with the open/close.
|
|
|
|
* Also clear the previous interrupt data on an open, and clean
|
|
|
|
* up things on a close.
|
|
|
|
*/
|
|
|
|
static int rtc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_lock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
if (rtc_status & RTC_IS_OPEN)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto out_busy;
|
|
|
|
|
|
|
|
rtc_status |= RTC_IS_OPEN;
|
|
|
|
|
|
|
|
rtc_irq_data = 0;
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_busy:
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
static int rtc_fasync(int fd, struct file *filp, int on)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-01-30 20:31:09 +08:00
|
|
|
return fasync_helper(fd, filp, on, &rtc_async_queue);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int rtc_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
unsigned char tmp;
|
|
|
|
|
|
|
|
if (rtc_has_irq == 0)
|
|
|
|
goto no_irq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turn off all interrupts once the device is no longer
|
|
|
|
* in use, and clear the data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
if (!hpet_mask_rtc_irq_bit(RTC_PIE | RTC_AIE | RTC_UIE)) {
|
|
|
|
tmp = CMOS_READ(RTC_CONTROL);
|
|
|
|
tmp &= ~RTC_PIE;
|
|
|
|
tmp &= ~RTC_AIE;
|
|
|
|
tmp &= ~RTC_UIE;
|
|
|
|
CMOS_WRITE(tmp, RTC_CONTROL);
|
|
|
|
CMOS_READ(RTC_INTR_FLAGS);
|
|
|
|
}
|
|
|
|
if (rtc_status & RTC_TIMER_ON) {
|
|
|
|
rtc_status &= ~RTC_TIMER_ON;
|
|
|
|
del_timer(&rtc_irq_timer);
|
|
|
|
}
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
|
|
|
|
no_irq:
|
|
|
|
#endif
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_lock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
rtc_irq_data = 0;
|
|
|
|
rtc_status &= ~RTC_IS_OPEN;
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
2017-07-03 18:39:46 +08:00
|
|
|
static __poll_t rtc_poll(struct file *file, poll_table *wait)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long l;
|
|
|
|
|
|
|
|
if (rtc_has_irq == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
poll_wait(file, &rtc_wait, wait);
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_lock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
l = rtc_irq_data;
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_unlock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (l != 0)
|
2018-02-12 06:34:03 +08:00
|
|
|
return EPOLLIN | EPOLLRDNORM;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The various file operations we support.
|
|
|
|
*/
|
|
|
|
|
2006-07-03 15:24:21 +08:00
|
|
|
static const struct file_operations rtc_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.llseek = no_llseek,
|
|
|
|
.read = rtc_read,
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
.poll = rtc_poll,
|
|
|
|
#endif
|
2008-07-24 12:30:32 +08:00
|
|
|
.unlocked_ioctl = rtc_ioctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = rtc_open,
|
|
|
|
.release = rtc_release,
|
|
|
|
.fasync = rtc_fasync,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct miscdevice rtc_dev = {
|
|
|
|
.minor = RTC_MINOR,
|
|
|
|
.name = "rtc",
|
|
|
|
.fops = &rtc_fops,
|
|
|
|
};
|
|
|
|
|
2007-11-15 08:59:57 +08:00
|
|
|
static resource_size_t rtc_size;
|
|
|
|
|
|
|
|
static struct resource * __init rtc_request_region(resource_size_t size)
|
|
|
|
{
|
|
|
|
struct resource *r;
|
|
|
|
|
|
|
|
if (RTC_IOMAPPED)
|
|
|
|
r = request_region(RTC_PORT(0), size, "rtc");
|
|
|
|
else
|
|
|
|
r = request_mem_region(RTC_PORT(0), size, "rtc");
|
|
|
|
|
|
|
|
if (r)
|
|
|
|
rtc_size = size;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2007-11-15 08:59:56 +08:00
|
|
|
static void rtc_release_region(void)
|
|
|
|
{
|
|
|
|
if (RTC_IOMAPPED)
|
2007-11-15 08:59:57 +08:00
|
|
|
release_region(RTC_PORT(0), rtc_size);
|
2007-11-15 08:59:56 +08:00
|
|
|
else
|
2007-11-15 08:59:57 +08:00
|
|
|
release_mem_region(RTC_PORT(0), rtc_size);
|
2007-11-15 08:59:56 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int __init rtc_init(void)
|
|
|
|
{
|
2006-12-13 16:35:05 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2005-04-17 06:20:36 +08:00
|
|
|
struct proc_dir_entry *ent;
|
2006-12-13 16:35:05 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
#if defined(__alpha__) || defined(__mips__)
|
|
|
|
unsigned int year, ctrl;
|
|
|
|
char *guess = NULL;
|
|
|
|
#endif
|
2007-07-20 04:59:58 +08:00
|
|
|
#ifdef CONFIG_SPARC32
|
2008-08-30 15:23:51 +08:00
|
|
|
struct device_node *ebus_dp;
|
2010-08-06 23:25:50 +08:00
|
|
|
struct platform_device *op;
|
2006-12-13 16:35:05 +08:00
|
|
|
#else
|
2006-07-10 19:45:30 +08:00
|
|
|
void *r;
|
2006-12-13 16:35:05 +08:00
|
|
|
#ifdef RTC_IRQ
|
|
|
|
irq_handler_t rtc_int_handler_ptr;
|
|
|
|
#endif
|
2006-07-10 19:45:30 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-20 04:59:58 +08:00
|
|
|
#ifdef CONFIG_SPARC32
|
2008-08-30 15:23:51 +08:00
|
|
|
for_each_node_by_name(ebus_dp, "ebus") {
|
|
|
|
struct device_node *dp;
|
|
|
|
for (dp = ebus_dp; dp; dp = dp->sibling) {
|
|
|
|
if (!strcmp(dp->name, "rtc")) {
|
|
|
|
op = of_find_device_by_node(dp);
|
|
|
|
if (op) {
|
|
|
|
rtc_port = op->resource[0].start;
|
|
|
|
rtc_irq = op->irqs[0];
|
|
|
|
goto found;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-12-13 16:35:04 +08:00
|
|
|
rtc_has_irq = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "rtc_init: no PC rtc found\n");
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
found:
|
2008-08-30 15:23:51 +08:00
|
|
|
if (!rtc_irq) {
|
2005-04-17 06:20:36 +08:00
|
|
|
rtc_has_irq = 0;
|
|
|
|
goto no_irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX Interrupt pin #7 in Espresso is shared between RTC and
|
2005-09-06 14:33:05 +08:00
|
|
|
* PCI Slot 2 INTA# (and some INTx# in Slot 1).
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2008-01-30 20:31:09 +08:00
|
|
|
if (request_irq(rtc_irq, rtc_interrupt, IRQF_SHARED, "rtc",
|
|
|
|
(void *)&rtc_port)) {
|
2006-12-13 16:35:04 +08:00
|
|
|
rtc_has_irq = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "rtc: cannot register IRQ %d\n", rtc_irq);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
no_irq:
|
|
|
|
#else
|
2007-11-15 08:59:57 +08:00
|
|
|
r = rtc_request_region(RTC_IO_EXTENT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we've already requested a smaller range (for example, because
|
|
|
|
* PNPBIOS or ACPI told us how the device is configured), the request
|
|
|
|
* above might fail because it's too big.
|
|
|
|
*
|
|
|
|
* If so, request just the range we actually use.
|
|
|
|
*/
|
|
|
|
if (!r)
|
|
|
|
r = rtc_request_region(RTC_IO_EXTENT_USED);
|
2006-07-10 19:45:30 +08:00
|
|
|
if (!r) {
|
2006-12-13 16:35:04 +08:00
|
|
|
#ifdef RTC_IRQ
|
|
|
|
rtc_has_irq = 0;
|
|
|
|
#endif
|
2006-07-10 19:45:30 +08:00
|
|
|
printk(KERN_ERR "rtc: I/O resource %lx is not free.\n",
|
|
|
|
(long)(RTC_PORT(0)));
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
if (is_hpet_enabled()) {
|
2008-01-30 20:33:31 +08:00
|
|
|
int err;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rtc_int_handler_ptr = hpet_rtc_interrupt;
|
2008-01-30 20:33:31 +08:00
|
|
|
err = hpet_register_irq_handler(rtc_interrupt);
|
|
|
|
if (err != 0) {
|
|
|
|
printk(KERN_WARNING "hpet_register_irq_handler failed "
|
|
|
|
"in rtc_init().");
|
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
rtc_int_handler_ptr = rtc_interrupt;
|
|
|
|
}
|
|
|
|
|
2013-10-13 12:14:42 +08:00
|
|
|
if (request_irq(RTC_IRQ, rtc_int_handler_ptr, 0, "rtc", NULL)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Yeah right, seeing as irq 8 doesn't even hit the bus. */
|
2006-12-13 16:35:04 +08:00
|
|
|
rtc_has_irq = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ);
|
2007-11-15 08:59:56 +08:00
|
|
|
rtc_release_region();
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
hpet_rtc_timer_init();
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-07-20 04:59:58 +08:00
|
|
|
#endif /* CONFIG_SPARC32 vs. others */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (misc_register(&rtc_dev)) {
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
free_irq(RTC_IRQ, NULL);
|
2008-01-30 20:33:31 +08:00
|
|
|
hpet_unregister_irq_handler(rtc_interrupt);
|
2006-12-13 16:35:04 +08:00
|
|
|
rtc_has_irq = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2007-11-15 08:59:56 +08:00
|
|
|
rtc_release_region();
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2006-12-13 16:35:05 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2018-05-15 21:57:23 +08:00
|
|
|
ent = proc_create_single("driver/rtc", 0, NULL, rtc_proc_show);
|
2008-04-29 16:02:34 +08:00
|
|
|
if (!ent)
|
2006-12-13 16:35:05 +08:00
|
|
|
printk(KERN_WARNING "rtc: Failed to register with procfs.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(__alpha__) || defined(__mips__)
|
|
|
|
rtc_freq = HZ;
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Each operating system on an Alpha uses its own epoch.
|
|
|
|
Let's try to guess which one we are using now. */
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rtc_is_updating() != 0)
|
2005-06-29 11:44:42 +08:00
|
|
|
msleep(20);
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
year = CMOS_READ(RTC_YEAR);
|
|
|
|
ctrl = CMOS_READ(RTC_CONTROL);
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
|
2008-10-19 11:28:42 +08:00
|
|
|
year = bcd2bin(year); /* This should never happen... */
|
2008-01-30 20:31:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (year < 20) {
|
|
|
|
epoch = 2000;
|
|
|
|
guess = "SRM (post-2000)";
|
|
|
|
} else if (year >= 20 && year < 48) {
|
|
|
|
epoch = 1980;
|
|
|
|
guess = "ARC console";
|
|
|
|
} else if (year >= 48 && year < 72) {
|
|
|
|
epoch = 1952;
|
|
|
|
guess = "Digital UNIX";
|
|
|
|
#if defined(__mips__)
|
|
|
|
} else if (year >= 72 && year < 74) {
|
|
|
|
epoch = 2000;
|
|
|
|
guess = "Digital DECstation";
|
|
|
|
#else
|
|
|
|
} else if (year >= 70) {
|
|
|
|
epoch = 1900;
|
|
|
|
guess = "Standard PC (1900)";
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (guess)
|
2008-01-30 20:31:09 +08:00
|
|
|
printk(KERN_INFO "rtc: %s epoch (%lu) detected\n",
|
|
|
|
guess, epoch);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
if (rtc_has_irq == 0)
|
|
|
|
goto no_irq2;
|
|
|
|
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
rtc_freq = 1024;
|
|
|
|
if (!hpet_set_periodic_freq(rtc_freq)) {
|
2008-01-30 20:31:09 +08:00
|
|
|
/*
|
|
|
|
* Initialize periodic frequency to CMOS reset default,
|
|
|
|
* which is 1024Hz
|
|
|
|
*/
|
|
|
|
CMOS_WRITE(((CMOS_READ(RTC_FREQ_SELECT) & 0xF0) | 0x06),
|
|
|
|
RTC_FREQ_SELECT);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
no_irq2:
|
|
|
|
#endif
|
|
|
|
|
|
|
|
(void) init_sysctl();
|
|
|
|
|
|
|
|
printk(KERN_INFO "Real Time Clock Driver v" RTC_VERSION "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
static void __exit rtc_exit(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
cleanup_sysctl();
|
2008-01-30 20:31:09 +08:00
|
|
|
remove_proc_entry("driver/rtc", NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
misc_deregister(&rtc_dev);
|
|
|
|
|
2007-07-20 04:59:58 +08:00
|
|
|
#ifdef CONFIG_SPARC32
|
2005-04-17 06:20:36 +08:00
|
|
|
if (rtc_has_irq)
|
2008-01-30 20:31:09 +08:00
|
|
|
free_irq(rtc_irq, &rtc_port);
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
2007-11-15 08:59:56 +08:00
|
|
|
rtc_release_region();
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef RTC_IRQ
|
2008-01-30 20:33:31 +08:00
|
|
|
if (rtc_has_irq) {
|
2008-01-30 20:31:09 +08:00
|
|
|
free_irq(RTC_IRQ, NULL);
|
2008-01-30 20:33:31 +08:00
|
|
|
hpet_unregister_irq_handler(hpet_rtc_interrupt);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2007-07-20 04:59:58 +08:00
|
|
|
#endif /* CONFIG_SPARC32 */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(rtc_init);
|
|
|
|
module_exit(rtc_exit);
|
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
/*
|
2008-01-30 20:31:09 +08:00
|
|
|
* At IRQ rates >= 4096Hz, an interrupt may get lost altogether.
|
2005-04-17 06:20:36 +08:00
|
|
|
* (usually during an IDE disk interrupt, with IRQ unmasking off)
|
|
|
|
* Since the interrupt handler doesn't get called, the IRQ status
|
|
|
|
* byte doesn't get read, and the RTC stops generating interrupts.
|
|
|
|
* A timer is set, and will call this function if/when that happens.
|
|
|
|
* To get it out of this stalled state, we just read the status.
|
|
|
|
* At least a jiffy of interrupts (rtc_freq/HZ) will have been lost.
|
2008-01-30 20:31:09 +08:00
|
|
|
* (You *really* shouldn't be trying to use a non-realtime system
|
2005-04-17 06:20:36 +08:00
|
|
|
* for something that requires a steady > 1KHz signal anyways.)
|
|
|
|
*/
|
|
|
|
|
2017-08-29 02:28:21 +08:00
|
|
|
static void rtc_dropped_irq(struct timer_list *unused)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long freq;
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
spin_lock_irq(&rtc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (hpet_rtc_dropped_irq()) {
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Just in case someone disabled the timer from behind our back... */
|
|
|
|
if (rtc_status & RTC_TIMER_ON)
|
|
|
|
mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq + 2*HZ/100);
|
|
|
|
|
|
|
|
rtc_irq_data += ((rtc_freq/HZ)<<8);
|
|
|
|
rtc_irq_data &= ~0xff;
|
|
|
|
rtc_irq_data |= (CMOS_READ(RTC_INTR_FLAGS) & 0xF0); /* restart */
|
|
|
|
|
|
|
|
freq = rtc_freq;
|
|
|
|
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
|
2011-06-04 23:36:33 +08:00
|
|
|
printk_ratelimited(KERN_WARNING "rtc: lost some interrupts at %ldHz.\n",
|
|
|
|
freq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Now we have new data */
|
|
|
|
wake_up_interruptible(&rtc_wait);
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
kill_fasync(&rtc_async_queue, SIGIO, POLL_IN);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-12-13 16:35:05 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Info exported via "/proc/driver/rtc".
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int rtc_proc_show(struct seq_file *seq, void *v)
|
|
|
|
{
|
|
|
|
#define YN(bit) ((ctrl & bit) ? "yes" : "no")
|
|
|
|
#define NY(bit) ((ctrl & bit) ? "no" : "yes")
|
|
|
|
struct rtc_time tm;
|
|
|
|
unsigned char batt, ctrl;
|
|
|
|
unsigned long freq;
|
|
|
|
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
batt = CMOS_READ(RTC_VALID) & RTC_VRT;
|
|
|
|
ctrl = CMOS_READ(RTC_CONTROL);
|
|
|
|
freq = rtc_freq;
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
|
|
|
|
|
|
|
|
rtc_get_rtc_time(&tm);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is no way to tell if the luser has the RTC set for local
|
|
|
|
* time or for Universal Standard Time (GMT). Probably local though.
|
|
|
|
*/
|
|
|
|
seq_printf(seq,
|
|
|
|
"rtc_time\t: %02d:%02d:%02d\n"
|
|
|
|
"rtc_date\t: %04d-%02d-%02d\n"
|
|
|
|
"rtc_epoch\t: %04lu\n",
|
|
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec,
|
|
|
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, epoch);
|
|
|
|
|
|
|
|
get_rtc_alm_time(&tm);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We implicitly assume 24hr mode here. Alarm values >= 0xc0 will
|
|
|
|
* match any value for that particular field. Values that are
|
|
|
|
* greater than a valid time, but less than 0xc0 shouldn't appear.
|
|
|
|
*/
|
|
|
|
seq_puts(seq, "alarm\t\t: ");
|
|
|
|
if (tm.tm_hour <= 24)
|
|
|
|
seq_printf(seq, "%02d:", tm.tm_hour);
|
|
|
|
else
|
|
|
|
seq_puts(seq, "**:");
|
|
|
|
|
|
|
|
if (tm.tm_min <= 59)
|
|
|
|
seq_printf(seq, "%02d:", tm.tm_min);
|
|
|
|
else
|
|
|
|
seq_puts(seq, "**:");
|
|
|
|
|
|
|
|
if (tm.tm_sec <= 59)
|
|
|
|
seq_printf(seq, "%02d\n", tm.tm_sec);
|
|
|
|
else
|
|
|
|
seq_puts(seq, "**\n");
|
|
|
|
|
|
|
|
seq_printf(seq,
|
|
|
|
"DST_enable\t: %s\n"
|
|
|
|
"BCD\t\t: %s\n"
|
|
|
|
"24hr\t\t: %s\n"
|
|
|
|
"square_wave\t: %s\n"
|
|
|
|
"alarm_IRQ\t: %s\n"
|
|
|
|
"update_IRQ\t: %s\n"
|
|
|
|
"periodic_IRQ\t: %s\n"
|
|
|
|
"periodic_freq\t: %ld\n"
|
|
|
|
"batt_status\t: %s\n",
|
|
|
|
YN(RTC_DST_EN),
|
|
|
|
NY(RTC_DM_BINARY),
|
|
|
|
YN(RTC_24H),
|
|
|
|
YN(RTC_SQWE),
|
|
|
|
YN(RTC_AIE),
|
|
|
|
YN(RTC_UIE),
|
|
|
|
YN(RTC_PIE),
|
|
|
|
freq,
|
|
|
|
batt ? "okay" : "dead");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
#undef YN
|
|
|
|
#undef NY
|
|
|
|
}
|
2006-12-13 16:35:05 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-26 10:46:25 +08:00
|
|
|
static void rtc_get_rtc_time(struct rtc_time *rtc_tm)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-07-13 00:03:10 +08:00
|
|
|
unsigned long uip_watchdog = jiffies, flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char ctrl;
|
|
|
|
#ifdef CONFIG_MACH_DECSTATION
|
|
|
|
unsigned int real_year;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* read RTC once any update in progress is done. The update
|
2005-06-29 11:44:42 +08:00
|
|
|
* can take just over 2ms. We wait 20ms. There is no need to
|
2005-04-17 06:20:36 +08:00
|
|
|
* to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
|
|
|
|
* If you need to know *exactly* when a second has started, enable
|
2008-01-30 20:31:09 +08:00
|
|
|
* periodic update complete interrupts, (via ioctl) and then
|
2005-04-17 06:20:36 +08:00
|
|
|
* immediately read /dev/rtc which will block until you get the IRQ.
|
|
|
|
* Once the read clears, read the RTC time (again via ioctl). Easy.
|
|
|
|
*/
|
|
|
|
|
2008-04-28 17:11:59 +08:00
|
|
|
while (rtc_is_updating() != 0 &&
|
|
|
|
time_before(jiffies, uip_watchdog + 2*HZ/100))
|
[PATCH] rtc: msleep() cannot be used from interrupt
Since the beginning of July my Opteron box was randomly crashing and
being rebooted by hardware watchdog. Today it finally did it in front
of me, and this patch will hopefully fix it.
The problem is that at the end of June (the 28th, to be exact: commit
47f176fdaf8924bc83fddcf9658f2fd3ef60d573, "[PATCH] Using msleep()
instead of HZ") rtc_get_rtc_time was converted to use msleep() instead
of busy waiting. But rtc_get_rtc_time is used by hpet_rtc_interrupt,
and scheduling is not allowed during interrupt. So I'm reverting this
part of original change, replacing msleep() back with busy loop.
The original code was busy waiting for up to 20ms, but on my hardware in
the worst case update-in-progress bit was asserted for at most 363
passes through loop (on 2GHz dual Opteron), much less than even one
jiffie, not even talking about 20ms. So I changed code to just wait
only as long as necessary. Otherwise when RTC was set to generate
8192Hz timer, it stopped doing anything for 20ms (160 pulses were
skipped!) from time to time, and this is rather suboptimal as far as I
can tell.
Signed-off-by: Petr Vandrovec <vandrove@vc.cvut.cz>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-05 21:50:07 +08:00
|
|
|
cpu_relax();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only the values that we read from the RTC are set. We leave
|
2006-01-12 04:17:32 +08:00
|
|
|
* tm_wday, tm_yday and tm_isdst untouched. Note that while the
|
|
|
|
* RTC has RTC_DAY_OF_WEEK, we should usually ignore it, as it is
|
|
|
|
* only updated by the RTC when initially set to a non-zero value.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2006-07-13 00:03:10 +08:00
|
|
|
spin_lock_irqsave(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS);
|
|
|
|
rtc_tm->tm_min = CMOS_READ(RTC_MINUTES);
|
|
|
|
rtc_tm->tm_hour = CMOS_READ(RTC_HOURS);
|
|
|
|
rtc_tm->tm_mday = CMOS_READ(RTC_DAY_OF_MONTH);
|
|
|
|
rtc_tm->tm_mon = CMOS_READ(RTC_MONTH);
|
|
|
|
rtc_tm->tm_year = CMOS_READ(RTC_YEAR);
|
2006-01-12 04:17:32 +08:00
|
|
|
/* Only set from 2.6.16 onwards */
|
|
|
|
rtc_tm->tm_wday = CMOS_READ(RTC_DAY_OF_WEEK);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_MACH_DECSTATION
|
|
|
|
real_year = CMOS_READ(RTC_DEC_YEAR);
|
|
|
|
#endif
|
|
|
|
ctrl = CMOS_READ(RTC_CONTROL);
|
2006-07-13 00:03:10 +08:00
|
|
|
spin_unlock_irqrestore(&rtc_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
|
2008-10-19 11:28:42 +08:00
|
|
|
rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
|
|
|
|
rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min);
|
|
|
|
rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour);
|
|
|
|
rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday);
|
|
|
|
rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
|
|
|
|
rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
|
|
|
|
rtc_tm->tm_wday = bcd2bin(rtc_tm->tm_wday);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_MACH_DECSTATION
|
|
|
|
rtc_tm->tm_year += real_year - 72;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Account for differences between how the RTC uses the values
|
|
|
|
* and how they are defined in a struct rtc_time;
|
|
|
|
*/
|
2008-01-30 20:31:09 +08:00
|
|
|
rtc_tm->tm_year += epoch - 1900;
|
|
|
|
if (rtc_tm->tm_year <= 69)
|
2005-04-17 06:20:36 +08:00
|
|
|
rtc_tm->tm_year += 100;
|
|
|
|
|
|
|
|
rtc_tm->tm_mon--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_rtc_alm_time(struct rtc_time *alm_tm)
|
|
|
|
{
|
|
|
|
unsigned char ctrl;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only the values that we read from the RTC are set. That
|
|
|
|
* means only tm_hour, tm_min, and tm_sec.
|
|
|
|
*/
|
|
|
|
spin_lock_irq(&rtc_lock);
|
|
|
|
alm_tm->tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
|
|
|
|
alm_tm->tm_min = CMOS_READ(RTC_MINUTES_ALARM);
|
|
|
|
alm_tm->tm_hour = CMOS_READ(RTC_HOURS_ALARM);
|
|
|
|
ctrl = CMOS_READ(RTC_CONTROL);
|
|
|
|
spin_unlock_irq(&rtc_lock);
|
|
|
|
|
2008-01-30 20:31:09 +08:00
|
|
|
if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
|
2008-10-19 11:28:42 +08:00
|
|
|
alm_tm->tm_sec = bcd2bin(alm_tm->tm_sec);
|
|
|
|
alm_tm->tm_min = bcd2bin(alm_tm->tm_min);
|
|
|
|
alm_tm->tm_hour = bcd2bin(alm_tm->tm_hour);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RTC_IRQ
|
|
|
|
/*
|
|
|
|
* Used to disable/enable interrupts for any one of UIE, AIE, PIE.
|
|
|
|
* Rumour has it that if you frob the interrupt enable/disable
|
|
|
|
* bits in RTC_CONTROL, you should read RTC_INTR_FLAGS, to
|
|
|
|
* ensure you actually start getting interrupts. Probably for
|
|
|
|
* compatibility with older/broken chipset RTC implementations.
|
|
|
|
* We also clear out any old irq data after an ioctl() that
|
|
|
|
* meddles with the interrupt enable/disable bits.
|
|
|
|
*/
|
|
|
|
|
2005-11-07 18:14:57 +08:00
|
|
|
static void mask_rtc_irq_bit_locked(unsigned char bit)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
|
2005-11-07 18:14:57 +08:00
|
|
|
if (hpet_mask_rtc_irq_bit(bit))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
val = CMOS_READ(RTC_CONTROL);
|
|
|
|
val &= ~bit;
|
|
|
|
CMOS_WRITE(val, RTC_CONTROL);
|
|
|
|
CMOS_READ(RTC_INTR_FLAGS);
|
|
|
|
|
|
|
|
rtc_irq_data = 0;
|
|
|
|
}
|
|
|
|
|
2005-11-07 18:14:57 +08:00
|
|
|
static void set_rtc_irq_bit_locked(unsigned char bit)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
|
2005-11-07 18:14:57 +08:00
|
|
|
if (hpet_set_rtc_irq_bit(bit))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
val = CMOS_READ(RTC_CONTROL);
|
|
|
|
val |= bit;
|
|
|
|
CMOS_WRITE(val, RTC_CONTROL);
|
|
|
|
CMOS_READ(RTC_INTR_FLAGS);
|
|
|
|
|
|
|
|
rtc_irq_data = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Paul Gortmaker");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_MISCDEV(RTC_MINOR);
|