Commit 09e81263 authored by Arnd Bergmann's avatar Arnd Bergmann

sh: sh03: rtc: push down rtc class ops into driver

The SH RTC support has an extra level of indirection to provide
either the old read_persistent_clock/update_persistent_clock
interface or the rtc-generic device for hctosys/systohc.

By removing the indirection and always using the RTC_CLASS interface,
we can avoid the lossy double conversion between rtc_time and timespec,
so we end up supporting the entire range of 'year' values, and clarifying
the rtc_set_time callback.

I did not change the behavior of sh03_rtc_settimeofday(), which keeps
just updating the seconds/minutes by calling set_rtc_mmss(), this
could be improved if anyone cares. Also, the file should ideally be
moved into drivers/rtc and not use rtc-generic.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
parent b0495e4b
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
# Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel # Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel
# #
obj-y := setup.o rtc.o obj-y := setup.o
obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o
...@@ -13,8 +13,9 @@ ...@@ -13,8 +13,9 @@
#include <linux/bcd.h> #include <linux/bcd.h>
#include <linux/rtc.h> #include <linux/rtc.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <asm/io.h> #include <linux/io.h>
#include <asm/rtc.h> #include <linux/rtc.h>
#include <linux/platform_device.h>
#define RTC_BASE 0xb0000000 #define RTC_BASE 0xb0000000
#define RTC_SEC1 (RTC_BASE + 0) #define RTC_SEC1 (RTC_BASE + 0)
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
static DEFINE_SPINLOCK(sh03_rtc_lock); static DEFINE_SPINLOCK(sh03_rtc_lock);
unsigned long get_cmos_time(void) static int sh03_rtc_gettimeofday(struct device *dev, struct rtc_time *tm)
{ {
unsigned int year, mon, day, hour, min, sec; unsigned int year, mon, day, hour, min, sec;
...@@ -75,17 +76,18 @@ unsigned long get_cmos_time(void) ...@@ -75,17 +76,18 @@ unsigned long get_cmos_time(void)
} }
spin_unlock(&sh03_rtc_lock); spin_unlock(&sh03_rtc_lock);
return mktime(year, mon, day, hour, min, sec);
}
void sh03_rtc_gettimeofday(struct timespec *tv) tm->tm_sec = sec;
{ tm->tm_min = min;
tm->tm_hour = hour;
tm->tm_mday = day;
tm->tm_mon = mon;
tm->tm_year = year - 1900;
tv->tv_sec = get_cmos_time(); return 0;
tv->tv_nsec = 0;
} }
static int set_rtc_mmss(unsigned long nowtime) static int set_rtc_mmss(struct rtc_time *tm)
{ {
int retval = 0; int retval = 0;
int real_seconds, real_minutes, cmos_minutes; int real_seconds, real_minutes, cmos_minutes;
...@@ -97,8 +99,8 @@ static int set_rtc_mmss(unsigned long nowtime) ...@@ -97,8 +99,8 @@ static int set_rtc_mmss(unsigned long nowtime)
if (!(__raw_readb(RTC_CTL) & RTC_BUSY)) if (!(__raw_readb(RTC_CTL) & RTC_BUSY))
break; break;
cmos_minutes = (__raw_readb(RTC_MIN1) & 0xf) + (__raw_readb(RTC_MIN10) & 0xf) * 10; cmos_minutes = (__raw_readb(RTC_MIN1) & 0xf) + (__raw_readb(RTC_MIN10) & 0xf) * 10;
real_seconds = nowtime % 60; real_seconds = tm->tm_sec;
real_minutes = nowtime / 60; real_minutes = tm->tm_min;
if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1) if (((abs(real_minutes - cmos_minutes) + 15)/30) & 1)
real_minutes += 30; /* correct for half hour time zone */ real_minutes += 30; /* correct for half hour time zone */
real_minutes %= 60; real_minutes %= 60;
...@@ -112,22 +114,31 @@ static int set_rtc_mmss(unsigned long nowtime) ...@@ -112,22 +114,31 @@ static int set_rtc_mmss(unsigned long nowtime)
printk_once(KERN_NOTICE printk_once(KERN_NOTICE
"set_rtc_mmss: can't update from %d to %d\n", "set_rtc_mmss: can't update from %d to %d\n",
cmos_minutes, real_minutes); cmos_minutes, real_minutes);
retval = -1; retval = -EINVAL;
} }
spin_unlock(&sh03_rtc_lock); spin_unlock(&sh03_rtc_lock);
return retval; return retval;
} }
int sh03_rtc_settimeofday(const time_t secs) int sh03_rtc_settimeofday(struct device *dev, struct rtc_time *tm)
{ {
unsigned long nowtime = secs; return set_rtc_mmss(tm);
return set_rtc_mmss(nowtime);
} }
void sh03_time_init(void) static const struct rtc_class_ops rtc_generic_ops = {
.read_time = sh03_rtc_gettimeofday,
.set_time = sh03_rtc_settimeofday,
};
static int __init sh03_time_init(void)
{ {
rtc_sh_get_time = sh03_rtc_gettimeofday; struct platform_device *pdev;
rtc_sh_set_time = sh03_rtc_settimeofday;
pdev = platform_device_register_data(NULL, "rtc-generic", -1,
&rtc_generic_ops,
sizeof(rtc_generic_ops));
return PTR_ERR_OR_ZERO(pdev);
} }
arch_initcall(sh03_time_init);
...@@ -22,14 +22,6 @@ static void __init init_sh03_IRQ(void) ...@@ -22,14 +22,6 @@ static void __init init_sh03_IRQ(void)
plat_irq_setup_pins(IRQ_MODE_IRQ); plat_irq_setup_pins(IRQ_MODE_IRQ);
} }
/* arch/sh/boards/sh03/rtc.c */
void sh03_time_init(void);
static void __init sh03_setup(char **cmdline_p)
{
board_time_init = sh03_time_init;
}
static struct resource cf_ide_resources[] = { static struct resource cf_ide_resources[] = {
[0] = { [0] = {
.start = 0x1f0, .start = 0x1f0,
...@@ -101,6 +93,5 @@ device_initcall(sh03_devices_setup); ...@@ -101,6 +93,5 @@ device_initcall(sh03_devices_setup);
static struct sh_machine_vector mv_sh03 __initmv = { static struct sh_machine_vector mv_sh03 __initmv = {
.mv_name = "Interface (CTP/PCI-SH03)", .mv_name = "Interface (CTP/PCI-SH03)",
.mv_setup = sh03_setup,
.mv_init_irq = init_sh03_IRQ, .mv_init_irq = init_sh03_IRQ,
}; };
...@@ -130,3 +130,5 @@ CONFIG_CRYPTO_SHA1=y ...@@ -130,3 +130,5 @@ CONFIG_CRYPTO_SHA1=y
CONFIG_CRYPTO_DEFLATE=y CONFIG_CRYPTO_DEFLATE=y
# CONFIG_CRYPTO_ANSI_CPRNG is not set # CONFIG_CRYPTO_ANSI_CPRNG is not set
CONFIG_CRC_CCITT=y CONFIG_CRC_CCITT=y
CONFIG_RTC_CLASS=y
CONFIG_RTC_DRV_GENERIC=y
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment