x86: clean up drivers/char/rtc.c

tons of style cleanup in drivers/char/rtc.c - no code changed:

   text    data     bss     dec     hex filename
   6400     384      32    6816    1aa0 rtc.o.before
   6400     384      32    6816    1aa0 rtc.o.after

since we seem to have a number of open breakages in this code we might
as well start with making the code more readable and maintainable.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
Ingo Molnar 2008-01-30 13:31:09 +01:00
parent 6b4b05bd79
commit 5fd1fe9c58

View File

@ -185,9 +185,9 @@ static int rtc_proc_open(struct inode *inode, struct file *file);
* rtc_status but before mod_timer is called, which would then reenable the * 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) * timer (but you would need to have an awful timing before you'd trip on it)
*/ */
static unsigned long rtc_status = 0; /* bitmapped status byte. */ static unsigned long rtc_status; /* bitmapped status byte. */
static unsigned long rtc_freq = 0; /* Current periodic IRQ rate */ static unsigned long rtc_freq; /* Current periodic IRQ rate */
static unsigned long rtc_irq_data = 0; /* our output to the world */ static unsigned long rtc_irq_data; /* our output to the world */
static unsigned long rtc_max_user_freq = 64; /* > this, need CAP_SYS_RESOURCE */ static unsigned long rtc_max_user_freq = 64; /* > this, need CAP_SYS_RESOURCE */
#ifdef RTC_IRQ #ifdef RTC_IRQ
@ -195,7 +195,7 @@ static unsigned long rtc_max_user_freq = 64; /* > this, need CAP_SYS_RESOURCE */
* rtc_task_lock nests inside rtc_lock. * rtc_task_lock nests inside rtc_lock.
*/ */
static DEFINE_SPINLOCK(rtc_task_lock); static DEFINE_SPINLOCK(rtc_task_lock);
static rtc_task_t *rtc_callback = NULL; static rtc_task_t *rtc_callback;
#endif #endif
/* /*
@ -378,10 +378,13 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
schedule(); schedule();
} while (1); } while (1);
if (count == sizeof(unsigned int)) if (count == sizeof(unsigned int)) {
retval = put_user(data, (unsigned int __user *)buf) ?: sizeof(int); retval = put_user(data,
else (unsigned int __user *)buf) ?: sizeof(int);
retval = put_user(data, (unsigned long __user *)buf) ?: sizeof(long); } else {
retval = put_user(data,
(unsigned long __user *)buf) ?: sizeof(long);
}
if (!retval) if (!retval)
retval = count; retval = count;
out: out:
@ -426,7 +429,9 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
} }
case RTC_PIE_OFF: /* Mask periodic int. enab. bit */ case RTC_PIE_OFF: /* Mask periodic int. enab. bit */
{ {
unsigned long flags; /* can be called from isr via rtc_control() */ /* can be called from isr via rtc_control() */
unsigned long flags;
spin_lock_irqsave(&rtc_lock, flags); spin_lock_irqsave(&rtc_lock, flags);
mask_rtc_irq_bit_locked(RTC_PIE); mask_rtc_irq_bit_locked(RTC_PIE);
if (rtc_status & RTC_TIMER_ON) { if (rtc_status & RTC_TIMER_ON) {
@ -434,11 +439,14 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
del_timer(&rtc_irq_timer); del_timer(&rtc_irq_timer);
} }
spin_unlock_irqrestore(&rtc_lock, flags); spin_unlock_irqrestore(&rtc_lock, flags);
return 0; return 0;
} }
case RTC_PIE_ON: /* Allow periodic ints */ case RTC_PIE_ON: /* Allow periodic ints */
{ {
unsigned long flags; /* can be called from isr via rtc_control() */ /* can be called from isr via rtc_control() */
unsigned long flags;
/* /*
* We don't really want Joe User enabling more * We don't really want Joe User enabling more
* than 64Hz of interrupts on a multi-user machine. * than 64Hz of interrupts on a multi-user machine.
@ -455,6 +463,7 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
} }
set_rtc_irq_bit_locked(RTC_PIE); set_rtc_irq_bit_locked(RTC_PIE);
spin_unlock_irqrestore(&rtc_lock, flags); spin_unlock_irqrestore(&rtc_lock, flags);
return 0; return 0;
} }
case RTC_UIE_OFF: /* Mask ints from RTC updates. */ case RTC_UIE_OFF: /* Mask ints from RTC updates. */
@ -505,16 +514,21 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
*/ */
} }
if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) || if (!(CMOS_READ(RTC_CONTROL) & RTC_DM_BINARY) ||
RTC_ALWAYS_BCD) RTC_ALWAYS_BCD) {
{ if (sec < 60)
if (sec < 60) BIN_TO_BCD(sec); BIN_TO_BCD(sec);
else sec = 0xff; else
sec = 0xff;
if (min < 60) BIN_TO_BCD(min); if (min < 60)
else min = 0xff; BIN_TO_BCD(min);
else
min = 0xff;
if (hrs < 24) BIN_TO_BCD(hrs); if (hrs < 24)
else hrs = 0xff; BIN_TO_BCD(hrs);
else
hrs = 0xff;
} }
CMOS_WRITE(hrs, RTC_HOURS_ALARM); CMOS_WRITE(hrs, RTC_HOURS_ALARM);
CMOS_WRITE(min, RTC_MINUTES_ALARM); CMOS_WRITE(min, RTC_MINUTES_ALARM);
@ -567,7 +581,8 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
if ((hrs >= 24) || (min >= 60) || (sec >= 60)) if ((hrs >= 24) || (min >= 60) || (sec >= 60))
return -EINVAL; return -EINVAL;
if ((yrs -= epoch) > 255) /* They are unsigned */ yrs -= epoch;
if (yrs > 255) /* They are unsigned */
return -EINVAL; return -EINVAL;
spin_lock_irq(&rtc_lock); spin_lock_irq(&rtc_lock);
@ -635,7 +650,8 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
{ {
int tmp = 0; int tmp = 0;
unsigned char val; unsigned char val;
unsigned long flags; /* can be called from isr via rtc_control() */ /* can be called from isr via rtc_control() */
unsigned long flags;
/* /*
* The max we can do is 8192Hz. * The max we can do is 8192Hz.
@ -646,7 +662,8 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
* We don't really want Joe User generating more * We don't really want Joe User generating more
* than 64Hz of interrupts on a multi-user machine. * than 64Hz of interrupts on a multi-user machine.
*/ */
if (!kernel && (arg > rtc_max_user_freq) && (!capable(CAP_SYS_RESOURCE))) if (!kernel && (arg > rtc_max_user_freq) &&
!capable(CAP_SYS_RESOURCE))
return -EACCES; return -EACCES;
while (arg > (1<<tmp)) while (arg > (1<<tmp))
@ -693,7 +710,8 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
default: default:
return -ENOTTY; return -ENOTTY;
} }
return copy_to_user((void __user *)arg, &wtime, sizeof wtime) ? -EFAULT : 0; return copy_to_user((void __user *)arg,
&wtime, sizeof wtime) ? -EFAULT : 0;
} }
static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
@ -729,7 +747,6 @@ out_busy:
} }
static int rtc_fasync(int fd, struct file *filp, int on) static int rtc_fasync(int fd, struct file *filp, int on)
{ {
return fasync_helper(fd, filp, on, &rtc_async_queue); return fasync_helper(fd, filp, on, &rtc_async_queue);
} }
@ -762,9 +779,8 @@ static int rtc_release(struct inode *inode, struct file *file)
} }
spin_unlock_irq(&rtc_lock); spin_unlock_irq(&rtc_lock);
if (file->f_flags & FASYNC) { if (file->f_flags & FASYNC)
rtc_fasync(-1, file, 0); rtc_fasync(-1, file, 0);
}
no_irq: no_irq:
#endif #endif
@ -772,6 +788,7 @@ no_irq:
rtc_irq_data = 0; rtc_irq_data = 0;
rtc_status &= ~RTC_IS_OPEN; rtc_status &= ~RTC_IS_OPEN;
spin_unlock_irq(&rtc_lock); spin_unlock_irq(&rtc_lock);
return 0; return 0;
} }
@ -796,14 +813,6 @@ static unsigned int rtc_poll(struct file *file, poll_table *wait)
} }
#endif #endif
/*
* exported stuffs
*/
EXPORT_SYMBOL(rtc_register);
EXPORT_SYMBOL(rtc_unregister);
EXPORT_SYMBOL(rtc_control);
int rtc_register(rtc_task_t *task) int rtc_register(rtc_task_t *task)
{ {
#ifndef RTC_IRQ #ifndef RTC_IRQ
@ -829,6 +838,7 @@ int rtc_register(rtc_task_t *task)
return 0; return 0;
#endif #endif
} }
EXPORT_SYMBOL(rtc_register);
int rtc_unregister(rtc_task_t *task) int rtc_unregister(rtc_task_t *task)
{ {
@ -865,6 +875,7 @@ int rtc_unregister(rtc_task_t *task)
return 0; return 0;
#endif #endif
} }
EXPORT_SYMBOL(rtc_unregister);
int rtc_control(rtc_task_t *task, unsigned int cmd, unsigned long arg) int rtc_control(rtc_task_t *task, unsigned int cmd, unsigned long arg)
{ {
@ -883,7 +894,7 @@ int rtc_control(rtc_task_t *task, unsigned int cmd, unsigned long arg)
return rtc_do_ioctl(cmd, arg, 1); return rtc_do_ioctl(cmd, arg, 1);
#endif #endif
} }
EXPORT_SYMBOL(rtc_control);
/* /*
* The various file operations we support. * The various file operations we support.
@ -986,7 +997,8 @@ found:
* XXX Interrupt pin #7 in Espresso is shared between RTC and * XXX Interrupt pin #7 in Espresso is shared between RTC and
* PCI Slot 2 INTA# (and some INTx# in Slot 1). * PCI Slot 2 INTA# (and some INTx# in Slot 1).
*/ */
if (request_irq(rtc_irq, rtc_interrupt, IRQF_SHARED, "rtc", (void *)&rtc_port)) { if (request_irq(rtc_irq, rtc_interrupt, IRQF_SHARED, "rtc",
(void *)&rtc_port)) {
rtc_has_irq = 0; rtc_has_irq = 0;
printk(KERN_ERR "rtc: cannot register IRQ %d\n", rtc_irq); printk(KERN_ERR "rtc: cannot register IRQ %d\n", rtc_irq);
return -EIO; return -EIO;
@ -1020,11 +1032,13 @@ no_irq:
rtc_int_handler_ptr = rtc_interrupt; rtc_int_handler_ptr = rtc_interrupt;
} }
if(request_irq(RTC_IRQ, rtc_int_handler_ptr, IRQF_DISABLED, "rtc", NULL)) { if (request_irq(RTC_IRQ, rtc_int_handler_ptr, IRQF_DISABLED,
"rtc", NULL)) {
/* Yeah right, seeing as irq 8 doesn't even hit the bus. */ /* Yeah right, seeing as irq 8 doesn't even hit the bus. */
rtc_has_irq = 0; rtc_has_irq = 0;
printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ); printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ);
rtc_release_region(); rtc_release_region();
return -EIO; return -EIO;
} }
hpet_rtc_timer_init(); hpet_rtc_timer_init();
@ -1087,7 +1101,8 @@ no_irq:
#endif #endif
} }
if (guess) if (guess)
printk(KERN_INFO "rtc: %s epoch (%lu) detected\n", guess, epoch); printk(KERN_INFO "rtc: %s epoch (%lu) detected\n",
guess, epoch);
#endif #endif
#ifdef RTC_IRQ #ifdef RTC_IRQ
if (rtc_has_irq == 0) if (rtc_has_irq == 0)
@ -1096,8 +1111,12 @@ no_irq:
spin_lock_irq(&rtc_lock); spin_lock_irq(&rtc_lock);
rtc_freq = 1024; rtc_freq = 1024;
if (!hpet_set_periodic_freq(rtc_freq)) { if (!hpet_set_periodic_freq(rtc_freq)) {
/* Initialize periodic freq. to CMOS reset default, which is 1024Hz */ /*
CMOS_WRITE(((CMOS_READ(RTC_FREQ_SELECT) & 0xF0) | 0x06), RTC_FREQ_SELECT); * Initialize periodic frequency to CMOS reset default,
* which is 1024Hz
*/
CMOS_WRITE(((CMOS_READ(RTC_FREQ_SELECT) & 0xF0) | 0x06),
RTC_FREQ_SELECT);
} }
spin_unlock_irq(&rtc_lock); spin_unlock_irq(&rtc_lock);
no_irq2: no_irq2:
@ -1167,8 +1186,10 @@ static void rtc_dropped_irq(unsigned long data)
spin_unlock_irq(&rtc_lock); spin_unlock_irq(&rtc_lock);
if (printk_ratelimit()) if (printk_ratelimit()) {
printk(KERN_WARNING "rtc: lost some interrupts at %ldHz.\n", freq); printk(KERN_WARNING "rtc: lost some interrupts at %ldHz.\n",
freq);
}
/* Now we have new data */ /* Now we have new data */
wake_up_interruptible(&rtc_wait); wake_up_interruptible(&rtc_wait);
@ -1307,8 +1328,7 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
ctrl = CMOS_READ(RTC_CONTROL); ctrl = CMOS_READ(RTC_CONTROL);
spin_unlock_irqrestore(&rtc_lock, flags); spin_unlock_irqrestore(&rtc_lock, flags);
if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
{
BCD_TO_BIN(rtc_tm->tm_sec); BCD_TO_BIN(rtc_tm->tm_sec);
BCD_TO_BIN(rtc_tm->tm_min); BCD_TO_BIN(rtc_tm->tm_min);
BCD_TO_BIN(rtc_tm->tm_hour); BCD_TO_BIN(rtc_tm->tm_hour);
@ -1326,7 +1346,8 @@ void rtc_get_rtc_time(struct rtc_time *rtc_tm)
* Account for differences between how the RTC uses the values * Account for differences between how the RTC uses the values
* and how they are defined in a struct rtc_time; * and how they are defined in a struct rtc_time;
*/ */
if ((rtc_tm->tm_year += (epoch - 1900)) <= 69) rtc_tm->tm_year += epoch - 1900;
if (rtc_tm->tm_year <= 69)
rtc_tm->tm_year += 100; rtc_tm->tm_year += 100;
rtc_tm->tm_mon--; rtc_tm->tm_mon--;
@ -1347,8 +1368,7 @@ static void get_rtc_alm_time(struct rtc_time *alm_tm)
ctrl = CMOS_READ(RTC_CONTROL); ctrl = CMOS_READ(RTC_CONTROL);
spin_unlock_irq(&rtc_lock); spin_unlock_irq(&rtc_lock);
if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) if (!(ctrl & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
{
BCD_TO_BIN(alm_tm->tm_sec); BCD_TO_BIN(alm_tm->tm_sec);
BCD_TO_BIN(alm_tm->tm_min); BCD_TO_BIN(alm_tm->tm_min);
BCD_TO_BIN(alm_tm->tm_hour); BCD_TO_BIN(alm_tm->tm_hour);