2019-05-27 09:55:05 +03:00
// SPDX-License-Identifier: GPL-2.0-or-later
2005-04-17 02:20:36 +04:00
/*
2006-04-11 09:54:47 +04:00
* Driver for NEC VR4100 series Real Time Clock unit .
2005-04-17 02:20:36 +04:00
*
2009-07-02 19:39:38 +04:00
* Copyright ( C ) 2003 - 2008 Yoichi Yuasa < yuasa @ linux - mips . org >
2005-04-17 02:20:36 +04:00
*/
compat_ioctl: move rtc handling into drivers/rtc/dev.c
We no longer need the rtc compat handling to be in common code, now that
all drivers are either moved to the rtc-class framework, or (rarely)
exist in drivers/char for architectures without compat mode (m68k,
alpha and ia64, respectively).
I checked the list of ioctl commands in drivers, and the ones that are
not already handled are all compatible, again with the one exception of
m68k driver, which implements RTC_PLL_GET and RTC_PLL_SET, but has no
compat mode.
Unlike earlier versions of this patch, I'm now adding a separate
compat_ioctl handler that takes care of RTC_IRQP_READ32/RTC_IRQP_SET32
and treats all other commands as compatible, leaving the native
behavior unchanged.
The old conversion handler also deals with RTC_EPOCH_READ and
RTC_EPOCH_SET, which are not handled in rtc-dev.c but only in a single
device driver (rtc-vr41xx), so I'm adding the compat version in the same
place. I don't expect other drivers to need those commands in the future.
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Reviewed-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v4: handle RTC_EPOCH_SET32 in rtc_dev_compat_ioctl
v3: handle RTC_IRQP_READ32/RTC_IRQP_SET32 in rtc_dev_compat_ioctl
v2: merge compat handler into ioctl function to avoid the
compat_alloc_user_space() roundtrip, based on feedback
from Al Viro.
2018-08-24 01:11:19 +03:00
# include <linux/compat.h>
2007-05-11 16:18:48 +04:00
# include <linux/err.h>
2005-04-17 02:20:36 +04:00
# include <linux/fs.h>
# include <linux/init.h>
2013-11-13 03:10:34 +04:00
# include <linux/io.h>
2005-04-17 02:20:36 +04:00
# include <linux/ioport.h>
2007-05-11 16:18:48 +04:00
# include <linux/interrupt.h>
2005-04-17 02:20:36 +04:00
# include <linux/module.h>
2006-04-11 09:54:47 +04:00
# include <linux/platform_device.h>
2005-04-17 02:20:36 +04:00
# include <linux/rtc.h>
# include <linux/spinlock.h>
# include <linux/types.h>
2013-11-13 03:10:34 +04:00
# include <linux/uaccess.h>
2009-01-07 01:42:12 +03:00
# include <linux/log2.h>
2005-04-17 02:20:36 +04:00
# include <asm/div64.h>
2009-07-02 19:39:38 +04:00
MODULE_AUTHOR ( " Yoichi Yuasa <yuasa@linux-mips.org> " ) ;
2005-04-17 02:20:36 +04:00
MODULE_DESCRIPTION ( " NEC VR4100 series RTC driver " ) ;
2008-07-24 08:30:48 +04:00
MODULE_LICENSE ( " GPL v2 " ) ;
2005-04-17 02:20:36 +04:00
/* RTC 1 registers */
# define ETIMELREG 0x00
# define ETIMEMREG 0x02
# define ETIMEHREG 0x04
/* RFU */
# define ECMPLREG 0x08
# define ECMPMREG 0x0a
# define ECMPHREG 0x0c
/* RFU */
# define RTCL1LREG 0x10
# define RTCL1HREG 0x12
# define RTCL1CNTLREG 0x14
# define RTCL1CNTHREG 0x16
# define RTCL2LREG 0x18
# define RTCL2HREG 0x1a
# define RTCL2CNTLREG 0x1c
# define RTCL2CNTHREG 0x1e
/* RTC 2 registers */
# define TCLKLREG 0x00
# define TCLKHREG 0x02
# define TCLKCNTLREG 0x04
# define TCLKCNTHREG 0x06
/* RFU */
# define RTCINTREG 0x1e
# define TCLOCK_INT 0x08
# define RTCLONG2_INT 0x04
# define RTCLONG1_INT 0x02
# define ELAPSEDTIME_INT 0x01
# define RTC_FREQUENCY 32768
# define MAX_PERIODIC_RATE 6553
static void __iomem * rtc1_base ;
static void __iomem * rtc2_base ;
# define rtc1_read(offset) readw(rtc1_base + (offset))
# define rtc1_write(offset, value) writew((value), rtc1_base + (offset))
# define rtc2_read(offset) readw(rtc2_base + (offset))
# define rtc2_write(offset, value) writew((value), rtc2_base + (offset))
compat_ioctl: move rtc handling into drivers/rtc/dev.c
We no longer need the rtc compat handling to be in common code, now that
all drivers are either moved to the rtc-class framework, or (rarely)
exist in drivers/char for architectures without compat mode (m68k,
alpha and ia64, respectively).
I checked the list of ioctl commands in drivers, and the ones that are
not already handled are all compatible, again with the one exception of
m68k driver, which implements RTC_PLL_GET and RTC_PLL_SET, but has no
compat mode.
Unlike earlier versions of this patch, I'm now adding a separate
compat_ioctl handler that takes care of RTC_IRQP_READ32/RTC_IRQP_SET32
and treats all other commands as compatible, leaving the native
behavior unchanged.
The old conversion handler also deals with RTC_EPOCH_READ and
RTC_EPOCH_SET, which are not handled in rtc-dev.c but only in a single
device driver (rtc-vr41xx), so I'm adding the compat version in the same
place. I don't expect other drivers to need those commands in the future.
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Reviewed-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v4: handle RTC_EPOCH_SET32 in rtc_dev_compat_ioctl
v3: handle RTC_IRQP_READ32/RTC_IRQP_SET32 in rtc_dev_compat_ioctl
v2: merge compat handler into ioctl function to avoid the
compat_alloc_user_space() roundtrip, based on feedback
from Al Viro.
2018-08-24 01:11:19 +03:00
/* 32-bit compat for ioctls that nobody else uses */
# define RTC_EPOCH_READ32 _IOR('p', 0x0d, __u32)
2005-04-17 02:20:36 +04:00
static unsigned long epoch = 1970 ; /* Jan 1 1970 00:00:00 */
2006-06-27 13:53:55 +04:00
static DEFINE_SPINLOCK ( rtc_lock ) ;
2005-04-17 02:20:36 +04:00
static char rtc_name [ ] = " RTC " ;
static unsigned long periodic_count ;
2007-05-08 11:33:50 +04:00
static unsigned int alarm_enabled ;
2009-01-07 01:42:11 +03:00
static int aie_irq ;
static int pie_irq ;
2005-04-17 02:20:36 +04:00
2018-04-20 19:14:24 +03:00
static inline time64_t read_elapsed_second ( void )
2005-04-17 02:20:36 +04:00
{
2006-04-11 09:54:47 +04:00
2005-04-17 02:20:36 +04:00
unsigned long first_low , first_mid , first_high ;
2006-04-11 09:54:47 +04:00
2005-04-17 02:20:36 +04:00
unsigned long second_low , second_mid , second_high ;
do {
first_low = rtc1_read ( ETIMELREG ) ;
first_mid = rtc1_read ( ETIMEMREG ) ;
first_high = rtc1_read ( ETIMEHREG ) ;
second_low = rtc1_read ( ETIMELREG ) ;
second_mid = rtc1_read ( ETIMEMREG ) ;
second_high = rtc1_read ( ETIMEHREG ) ;
} while ( first_low ! = second_low | | first_mid ! = second_mid | |
2013-07-04 02:06:06 +04:00
first_high ! = second_high ) ;
2005-04-17 02:20:36 +04:00
2018-04-20 19:14:24 +03:00
return ( ( u64 ) first_high < < 17 ) | ( first_mid < < 1 ) | ( first_low > > 15 ) ;
2005-04-17 02:20:36 +04:00
}
2018-04-20 19:14:24 +03:00
static inline void write_elapsed_second ( time64_t sec )
2005-04-17 02:20:36 +04:00
{
spin_lock_irq ( & rtc_lock ) ;
rtc1_write ( ETIMELREG , ( uint16_t ) ( sec < < 15 ) ) ;
rtc1_write ( ETIMEMREG , ( uint16_t ) ( sec > > 1 ) ) ;
rtc1_write ( ETIMEHREG , ( uint16_t ) ( sec > > 17 ) ) ;
spin_unlock_irq ( & rtc_lock ) ;
}
2006-04-11 09:54:47 +04:00
static int vr41xx_rtc_read_time ( struct device * dev , struct rtc_time * time )
2005-04-17 02:20:36 +04:00
{
2018-04-20 19:14:24 +03:00
time64_t epoch_sec , elapsed_sec ;
2005-04-17 02:20:36 +04:00
2018-04-20 19:14:24 +03:00
epoch_sec = mktime64 ( epoch , 1 , 1 , 0 , 0 , 0 ) ;
2005-04-17 02:20:36 +04:00
elapsed_sec = read_elapsed_second ( ) ;
2018-04-20 19:14:24 +03:00
rtc_time64_to_tm ( epoch_sec + elapsed_sec , time ) ;
2006-04-11 09:54:47 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2006-04-11 09:54:47 +04:00
static int vr41xx_rtc_set_time ( struct device * dev , struct rtc_time * time )
2005-04-17 02:20:36 +04:00
{
2018-04-20 19:14:24 +03:00
time64_t epoch_sec , current_sec ;
2005-04-17 02:20:36 +04:00
2018-04-20 19:14:24 +03:00
epoch_sec = mktime64 ( epoch , 1 , 1 , 0 , 0 , 0 ) ;
2018-10-02 00:51:35 +03:00
current_sec = rtc_tm_to_time64 ( time ) ;
2005-04-17 02:20:36 +04:00
write_elapsed_second ( current_sec - epoch_sec ) ;
2006-04-11 09:54:47 +04:00
return 0 ;
2005-04-17 02:20:36 +04:00
}
2006-04-11 09:54:47 +04:00
static int vr41xx_rtc_read_alarm ( struct device * dev , struct rtc_wkalrm * wkalrm )
2005-04-17 02:20:36 +04:00
{
2006-04-11 09:54:47 +04:00
unsigned long low , mid , high ;
struct rtc_time * time = & wkalrm - > time ;
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
spin_lock_irq ( & rtc_lock ) ;
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
low = rtc1_read ( ECMPLREG ) ;
mid = rtc1_read ( ECMPMREG ) ;
high = rtc1_read ( ECMPHREG ) ;
2007-05-08 11:33:50 +04:00
wkalrm - > enabled = alarm_enabled ;
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
spin_unlock_irq ( & rtc_lock ) ;
2005-04-17 02:20:36 +04:00
2018-10-02 00:51:35 +03:00
rtc_time64_to_tm ( ( high < < 17 ) | ( mid < < 1 ) | ( low > > 15 ) , time ) ;
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
return 0 ;
}
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
static int vr41xx_rtc_set_alarm ( struct device * dev , struct rtc_wkalrm * wkalrm )
{
2018-04-20 19:14:24 +03:00
time64_t alarm_sec ;
2005-04-17 02:20:36 +04:00
2018-10-02 00:51:35 +03:00
alarm_sec = rtc_tm_to_time64 ( & wkalrm - > time ) ;
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
spin_lock_irq ( & rtc_lock ) ;
2005-04-17 02:20:36 +04:00
2007-05-08 11:33:50 +04:00
if ( alarm_enabled )
2007-05-11 16:18:48 +04:00
disable_irq ( aie_irq ) ;
2007-05-08 11:33:50 +04:00
2006-04-11 09:54:47 +04:00
rtc1_write ( ECMPLREG , ( uint16_t ) ( alarm_sec < < 15 ) ) ;
rtc1_write ( ECMPMREG , ( uint16_t ) ( alarm_sec > > 1 ) ) ;
rtc1_write ( ECMPHREG , ( uint16_t ) ( alarm_sec > > 17 ) ) ;
2005-04-17 02:20:36 +04:00
2007-05-08 11:33:50 +04:00
if ( wkalrm - > enabled )
2007-05-11 16:18:48 +04:00
enable_irq ( aie_irq ) ;
2007-05-08 11:33:50 +04:00
alarm_enabled = wkalrm - > enabled ;
2006-04-11 09:54:47 +04:00
spin_unlock_irq ( & rtc_lock ) ;
2005-04-17 02:20:36 +04:00
return 0 ;
}
2008-07-24 08:30:48 +04:00
static int vr41xx_rtc_ioctl ( struct device * dev , unsigned int cmd , unsigned long arg )
{
2005-04-17 02:20:36 +04:00
switch ( cmd ) {
case RTC_EPOCH_READ :
return put_user ( epoch , ( unsigned long __user * ) arg ) ;
compat_ioctl: move rtc handling into drivers/rtc/dev.c
We no longer need the rtc compat handling to be in common code, now that
all drivers are either moved to the rtc-class framework, or (rarely)
exist in drivers/char for architectures without compat mode (m68k,
alpha and ia64, respectively).
I checked the list of ioctl commands in drivers, and the ones that are
not already handled are all compatible, again with the one exception of
m68k driver, which implements RTC_PLL_GET and RTC_PLL_SET, but has no
compat mode.
Unlike earlier versions of this patch, I'm now adding a separate
compat_ioctl handler that takes care of RTC_IRQP_READ32/RTC_IRQP_SET32
and treats all other commands as compatible, leaving the native
behavior unchanged.
The old conversion handler also deals with RTC_EPOCH_READ and
RTC_EPOCH_SET, which are not handled in rtc-dev.c but only in a single
device driver (rtc-vr41xx), so I'm adding the compat version in the same
place. I don't expect other drivers to need those commands in the future.
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Reviewed-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
v4: handle RTC_EPOCH_SET32 in rtc_dev_compat_ioctl
v3: handle RTC_IRQP_READ32/RTC_IRQP_SET32 in rtc_dev_compat_ioctl
v2: merge compat handler into ioctl function to avoid the
compat_alloc_user_space() roundtrip, based on feedback
from Al Viro.
2018-08-24 01:11:19 +03:00
# ifdef CONFIG_64BIT
case RTC_EPOCH_READ32 :
return put_user ( epoch , ( unsigned int __user * ) arg ) ;
# endif
2005-04-17 02:20:36 +04:00
case RTC_EPOCH_SET :
/* Doesn't support before 1900 */
if ( arg < 1900 )
return - EINVAL ;
epoch = arg ;
break ;
default :
2006-05-21 02:00:29 +04:00
return - ENOIOCTLCMD ;
2005-04-17 02:20:36 +04:00
}
return 0 ;
}
2011-02-03 04:02:41 +03:00
static int vr41xx_rtc_alarm_irq_enable ( struct device * dev , unsigned int enabled )
{
spin_lock_irq ( & rtc_lock ) ;
if ( enabled ) {
if ( ! alarm_enabled ) {
enable_irq ( aie_irq ) ;
alarm_enabled = 1 ;
}
} else {
if ( alarm_enabled ) {
disable_irq ( aie_irq ) ;
alarm_enabled = 0 ;
}
}
spin_unlock_irq ( & rtc_lock ) ;
return 0 ;
}
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
static irqreturn_t elapsedtime_interrupt ( int irq , void * dev_id )
2005-04-17 02:20:36 +04:00
{
2006-04-11 09:54:47 +04:00
struct platform_device * pdev = ( struct platform_device * ) dev_id ;
struct rtc_device * rtc = platform_get_drvdata ( pdev ) ;
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
rtc2_write ( RTCINTREG , ELAPSEDTIME_INT ) ;
2005-04-17 02:20:36 +04:00
2007-05-08 11:33:30 +04:00
rtc_update_irq ( rtc , 1 , RTC_AF ) ;
2005-04-17 02:20:36 +04:00
return IRQ_HANDLED ;
}
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
static irqreturn_t rtclong1_interrupt ( int irq , void * dev_id )
2005-04-17 02:20:36 +04:00
{
2006-04-11 09:54:47 +04:00
struct platform_device * pdev = ( struct platform_device * ) dev_id ;
struct rtc_device * rtc = platform_get_drvdata ( pdev ) ;
2005-04-17 02:20:36 +04:00
unsigned long count = periodic_count ;
rtc2_write ( RTCINTREG , RTCLONG1_INT ) ;
rtc1_write ( RTCL1LREG , count ) ;
rtc1_write ( RTCL1HREG , count > > 16 ) ;
2007-05-08 11:33:30 +04:00
rtc_update_irq ( rtc , 1 , RTC_PF ) ;
2005-04-17 02:20:36 +04:00
return IRQ_HANDLED ;
}
2006-10-01 10:28:17 +04:00
static const struct rtc_class_ops vr41xx_rtc_ops = {
2016-03-01 11:50:01 +03:00
. ioctl = vr41xx_rtc_ioctl ,
. read_time = vr41xx_rtc_read_time ,
. set_time = vr41xx_rtc_set_time ,
. read_alarm = vr41xx_rtc_read_alarm ,
. set_alarm = vr41xx_rtc_set_alarm ,
. alarm_irq_enable = vr41xx_rtc_alarm_irq_enable ,
2005-04-17 02:20:36 +04:00
} ;
2012-12-22 01:09:38 +04:00
static int rtc_probe ( struct platform_device * pdev )
2005-04-17 02:20:36 +04:00
{
2007-05-11 16:18:48 +04:00
struct resource * res ;
2006-04-11 09:54:47 +04:00
struct rtc_device * rtc ;
2005-04-17 02:20:36 +04:00
int retval ;
2007-05-11 16:18:48 +04:00
if ( pdev - > num_resources ! = 4 )
2005-04-17 02:20:36 +04:00
return - EBUSY ;
2007-05-11 16:18:48 +04:00
res = platform_get_resource ( pdev , IORESOURCE_MEM , 0 ) ;
if ( ! res )
2005-04-17 02:20:36 +04:00
return - EBUSY ;
2014-01-24 03:55:07 +04:00
rtc1_base = devm_ioremap ( & pdev - > dev , res - > start , resource_size ( res ) ) ;
2007-05-11 16:18:48 +04:00
if ( ! rtc1_base )
2005-04-17 02:20:36 +04:00
return - EBUSY ;
2007-05-11 16:18:48 +04:00
res = platform_get_resource ( pdev , IORESOURCE_MEM , 1 ) ;
if ( ! res ) {
retval = - EBUSY ;
goto err_rtc1_iounmap ;
}
2014-01-24 03:55:07 +04:00
rtc2_base = devm_ioremap ( & pdev - > dev , res - > start , resource_size ( res ) ) ;
2007-05-11 16:18:48 +04:00
if ( ! rtc2_base ) {
retval = - EBUSY ;
goto err_rtc1_iounmap ;
2005-04-17 02:20:36 +04:00
}
2018-05-17 23:47:05 +03:00
rtc = devm_rtc_allocate_device ( & pdev - > dev ) ;
2006-04-11 09:54:47 +04:00
if ( IS_ERR ( rtc ) ) {
2007-05-11 16:18:48 +04:00
retval = PTR_ERR ( rtc ) ;
goto err_iounmap_all ;
2005-04-17 02:20:36 +04:00
}
2018-05-17 23:47:05 +03:00
rtc - > ops = & vr41xx_rtc_ops ;
2018-05-17 23:47:06 +03:00
/* 48-bit counter at 32.768 kHz */
rtc - > range_max = ( 1ULL < < 33 ) - 1 ;
2008-07-24 08:30:48 +04:00
rtc - > max_user_freq = MAX_PERIODIC_RATE ;
2005-04-17 02:20:36 +04:00
spin_lock_irq ( & rtc_lock ) ;
rtc1_write ( ECMPLREG , 0 ) ;
rtc1_write ( ECMPMREG , 0 ) ;
rtc1_write ( ECMPHREG , 0 ) ;
rtc1_write ( RTCL1LREG , 0 ) ;
rtc1_write ( RTCL1HREG , 0 ) ;
spin_unlock_irq ( & rtc_lock ) ;
2007-05-11 16:18:48 +04:00
aie_irq = platform_get_irq ( pdev , 0 ) ;
2009-01-07 01:42:11 +03:00
if ( aie_irq < = 0 ) {
2007-05-11 16:18:48 +04:00
retval = - EBUSY ;
2014-01-24 03:55:07 +04:00
goto err_iounmap_all ;
2005-04-17 02:20:36 +04:00
}
2014-01-24 03:55:07 +04:00
retval = devm_request_irq ( & pdev - > dev , aie_irq , elapsedtime_interrupt , 0 ,
" elapsed_time " , pdev ) ;
2007-05-11 16:18:48 +04:00
if ( retval < 0 )
2014-01-24 03:55:07 +04:00
goto err_iounmap_all ;
2007-05-11 16:18:48 +04:00
pie_irq = platform_get_irq ( pdev , 1 ) ;
2013-07-04 02:07:04 +04:00
if ( pie_irq < = 0 ) {
retval = - EBUSY ;
2014-01-24 03:55:07 +04:00
goto err_iounmap_all ;
2013-07-04 02:07:04 +04:00
}
2007-05-11 16:18:48 +04:00
2014-01-24 03:55:07 +04:00
retval = devm_request_irq ( & pdev - > dev , pie_irq , rtclong1_interrupt , 0 ,
" rtclong1 " , pdev ) ;
2007-05-11 16:18:48 +04:00
if ( retval < 0 )
2014-01-24 03:55:07 +04:00
goto err_iounmap_all ;
2005-04-17 02:20:36 +04:00
2006-04-11 09:54:47 +04:00
platform_set_drvdata ( pdev , rtc ) ;
2007-05-11 16:18:48 +04:00
disable_irq ( aie_irq ) ;
disable_irq ( pie_irq ) ;
2005-04-17 02:20:36 +04:00
2013-02-22 04:45:30 +04:00
dev_info ( & pdev - > dev , " Real Time Clock of NEC VR4100 series \n " ) ;
2005-04-17 02:20:36 +04:00
2018-05-17 23:47:05 +03:00
retval = rtc_register_device ( rtc ) ;
if ( retval )
goto err_iounmap_all ;
2005-04-17 02:20:36 +04:00
return 0 ;
2007-05-11 16:18:48 +04:00
err_iounmap_all :
rtc2_base = NULL ;
err_rtc1_iounmap :
rtc1_base = NULL ;
return retval ;
2005-04-17 02:20:36 +04:00
}
2008-04-11 08:29:25 +04:00
/* work with hotplug and coldplug */
MODULE_ALIAS ( " platform:RTC " ) ;
2006-04-11 09:54:47 +04:00
static struct platform_driver rtc_platform_driver = {
2005-04-17 02:20:36 +04:00
. probe = rtc_probe ,
2005-11-10 01:32:44 +03:00
. driver = {
. name = rtc_name ,
} ,
2005-04-17 02:20:36 +04:00
} ;
2012-01-11 03:10:48 +04:00
module_platform_driver ( rtc_platform_driver ) ;