aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/platform/mrst/vrtc.c
diff options
context:
space:
mode:
authorFeng Tang <feng.tang@intel.com>2010-11-10 12:29:00 -0500
committerThomas Gleixner <tglx@linutronix.de>2010-11-11 05:34:27 -0500
commit7309282c90d251cde77fe3b520a8276e25315c49 (patch)
treeda33c8a838d0ee779c1b8a70e13002bf29cd4527 /arch/x86/platform/mrst/vrtc.c
parentcfb505a7ebd4c84206b4cc7d9f966d864a2ac05a (diff)
x86: mrst: Add vrtc driver which serves as a wall clock device
Moorestown platform doesn't have a m146818 RTC device like traditional x86 PC, but a firmware emulated virtual RTC device(vrtc), which provides some basic RTC functions like get/set time. vrtc serves as the only wall clock device on Moorestown platform. [ tglx: Changed the exports to _GPL ] Signed-off-by: Feng Tang <feng.tang@intel.com> Signed-off-by: Jacob Pan <jacob.jun.pan@linux.intel.com> Signed-off-by: Alan Cox <alan@linux.intel.com> LKML-Reference: <20101110172837.3311.40483.stgit@localhost.localdomain> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/platform/mrst/vrtc.c')
-rw-r--r--arch/x86/platform/mrst/vrtc.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
new file mode 100644
index 00000000000..4944bd521d2
--- /dev/null
+++ b/arch/x86/platform/mrst/vrtc.c
@@ -0,0 +1,120 @@
1/*
2 * vrtc.c: Driver for virtual RTC device on Intel MID platform
3 *
4 * (C) Copyright 2009 Intel Corporation
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; version 2
9 * of the License.
10 *
11 * Note:
12 * VRTC is emulated by system controller firmware, the real HW
13 * RTC is located in the PMIC device. SCU FW shadows PMIC RTC
14 * in a memory mapped IO space that is visible to the host IA
15 * processor.
16 *
17 * This driver is based on RTC CMOS driver.
18 */
19
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/sfi.h>
23
24#include <asm/mrst.h>
25#include <asm/mrst-vrtc.h>
26#include <asm/time.h>
27#include <asm/fixmap.h>
28
29static unsigned char __iomem *vrtc_virt_base;
30
31unsigned char vrtc_cmos_read(unsigned char reg)
32{
33 unsigned char retval;
34
35 /* vRTC's registers range from 0x0 to 0xD */
36 if (reg > 0xd || !vrtc_virt_base)
37 return 0xff;
38
39 lock_cmos_prefix(reg);
40 retval = __raw_readb(vrtc_virt_base + (reg << 2));
41 lock_cmos_suffix(reg);
42 return retval;
43}
44EXPORT_SYMBOL_GPL(vrtc_cmos_read);
45
46void vrtc_cmos_write(unsigned char val, unsigned char reg)
47{
48 if (reg > 0xd || !vrtc_virt_base)
49 return;
50
51 lock_cmos_prefix(reg);
52 __raw_writeb(val, vrtc_virt_base + (reg << 2));
53 lock_cmos_suffix(reg);
54}
55EXPORT_SYMBOL_GPL(vrtc_cmos_write);
56
57unsigned long vrtc_get_time(void)
58{
59 u8 sec, min, hour, mday, mon;
60 u32 year;
61
62 while ((vrtc_cmos_read(RTC_FREQ_SELECT) & RTC_UIP))
63 cpu_relax();
64
65 sec = vrtc_cmos_read(RTC_SECONDS);
66 min = vrtc_cmos_read(RTC_MINUTES);
67 hour = vrtc_cmos_read(RTC_HOURS);
68 mday = vrtc_cmos_read(RTC_DAY_OF_MONTH);
69 mon = vrtc_cmos_read(RTC_MONTH);
70 year = vrtc_cmos_read(RTC_YEAR);
71
72 /* vRTC YEAR reg contains the offset to 1960 */
73 year += 1960;
74
75 printk(KERN_INFO "vRTC: sec: %d min: %d hour: %d day: %d "
76 "mon: %d year: %d\n", sec, min, hour, mday, mon, year);
77
78 return mktime(year, mon, mday, hour, min, sec);
79}
80
81/* Only care about the minutes and seconds */
82int vrtc_set_mmss(unsigned long nowtime)
83{
84 int real_sec, real_min;
85 int vrtc_min;
86
87 vrtc_min = vrtc_cmos_read(RTC_MINUTES);
88
89 real_sec = nowtime % 60;
90 real_min = nowtime / 60;
91 if (((abs(real_min - vrtc_min) + 15)/30) & 1)
92 real_min += 30;
93 real_min %= 60;
94
95 vrtc_cmos_write(real_sec, RTC_SECONDS);
96 vrtc_cmos_write(real_min, RTC_MINUTES);
97 return 0;
98}
99
100void __init mrst_rtc_init(void)
101{
102 unsigned long rtc_paddr;
103 void __iomem *virt_base;
104
105 sfi_table_parse(SFI_SIG_MRTC, NULL, NULL, sfi_parse_mrtc);
106 if (!sfi_mrtc_num)
107 return;
108
109 rtc_paddr = sfi_mrtc_array[0].phys_addr;
110
111 /* vRTC's register address may not be page aligned */
112 set_fixmap_nocache(FIX_LNW_VRTC, rtc_paddr);
113
114 virt_base = (void __iomem *)__fix_to_virt(FIX_LNW_VRTC);
115 virt_base += rtc_paddr & ~PAGE_MASK;
116 vrtc_virt_base = virt_base;
117
118 x86_platform.get_wallclock = vrtc_get_time;
119 x86_platform.set_wallclock = vrtc_set_mmss;
120}