1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include <linux/errno.h>
18#include <linux/module.h>
19#include <linux/sched.h>
20#include <linux/kernel.h>
21#include <linux/param.h>
22#include <linux/string.h>
23#include <linux/mm.h>
24#include <linux/interrupt.h>
25#include <linux/time.h>
26#include <linux/rtc.h>
27#include <linux/rtc/m48t59.h>
28#include <linux/timex.h>
29#include <linux/init.h>
30#include <linux/pci.h>
31#include <linux/ioport.h>
32#include <linux/profile.h>
33#include <linux/of.h>
34#include <linux/of_device.h>
35#include <linux/platform_device.h>
36
37#include <asm/oplib.h>
38#include <asm/timex.h>
39#include <asm/timer.h>
40#include <asm/irq.h>
41#include <asm/io.h>
42#include <asm/idprom.h>
43#include <asm/machines.h>
44#include <asm/page.h>
45#include <asm/pcic.h>
46#include <asm/irq_regs.h>
47
48#include "irq.h"
49
50DEFINE_SPINLOCK(rtc_lock);
51EXPORT_SYMBOL(rtc_lock);
52
53static int set_rtc_mmss(unsigned long);
54
55unsigned long profile_pc(struct pt_regs *regs)
56{
57 extern char __copy_user_begin[], __copy_user_end[];
58 extern char __atomic_begin[], __atomic_end[];
59 extern char __bzero_begin[], __bzero_end[];
60
61 unsigned long pc = regs->pc;
62
63 if (in_lock_functions(pc) ||
64 (pc >= (unsigned long) __copy_user_begin &&
65 pc < (unsigned long) __copy_user_end) ||
66 (pc >= (unsigned long) __atomic_begin &&
67 pc < (unsigned long) __atomic_end) ||
68 (pc >= (unsigned long) __bzero_begin &&
69 pc < (unsigned long) __bzero_end))
70 pc = regs->u_regs[UREG_RETPC];
71 return pc;
72}
73
74EXPORT_SYMBOL(profile_pc);
75
76__volatile__ unsigned int *master_l10_counter;
77
78u32 (*do_arch_gettimeoffset)(void);
79
80int update_persistent_clock(struct timespec now)
81{
82 return set_rtc_mmss(now.tv_sec);
83}
84
85
86
87
88
89
90#define TICK_SIZE (tick_nsec / 1000)
91
92static irqreturn_t timer_interrupt(int dummy, void *dev_id)
93{
94#ifndef CONFIG_SMP
95 profile_tick(CPU_PROFILING);
96#endif
97
98 clear_clock_irq();
99
100 xtime_update(1);
101
102#ifndef CONFIG_SMP
103 update_process_times(user_mode(get_irq_regs()));
104#endif
105 return IRQ_HANDLED;
106}
107
108static unsigned char mostek_read_byte(struct device *dev, u32 ofs)
109{
110 struct platform_device *pdev = to_platform_device(dev);
111 struct m48t59_plat_data *pdata = pdev->dev.platform_data;
112
113 return readb(pdata->ioaddr + ofs);
114}
115
116static void mostek_write_byte(struct device *dev, u32 ofs, u8 val)
117{
118 struct platform_device *pdev = to_platform_device(dev);
119 struct m48t59_plat_data *pdata = pdev->dev.platform_data;
120
121 writeb(val, pdata->ioaddr + ofs);
122}
123
124static struct m48t59_plat_data m48t59_data = {
125 .read_byte = mostek_read_byte,
126 .write_byte = mostek_write_byte,
127};
128
129
130static struct platform_device m48t59_rtc = {
131 .name = "rtc-m48t59",
132 .id = 0,
133 .num_resources = 1,
134 .dev = {
135 .platform_data = &m48t59_data,
136 },
137};
138
139static int __devinit clock_probe(struct platform_device *op)
140{
141 struct device_node *dp = op->dev.of_node;
142 const char *model = of_get_property(dp, "model", NULL);
143
144 if (!model)
145 return -ENODEV;
146
147
148 if (!of_find_property(dp, "address", NULL))
149 return -ENODEV;
150
151 m48t59_rtc.resource = &op->resource[0];
152 if (!strcmp(model, "mk48t02")) {
153
154 m48t59_data.ioaddr = of_ioremap(&op->resource[0], 0,
155 2048, "rtc-m48t59");
156 m48t59_data.type = M48T59RTC_TYPE_M48T02;
157 } else if (!strcmp(model, "mk48t08")) {
158 m48t59_data.ioaddr = of_ioremap(&op->resource[0], 0,
159 8192, "rtc-m48t59");
160 m48t59_data.type = M48T59RTC_TYPE_M48T08;
161 } else
162 return -ENODEV;
163
164 if (platform_device_register(&m48t59_rtc) < 0)
165 printk(KERN_ERR "Registering RTC device failed\n");
166
167 return 0;
168}
169
170static struct of_device_id clock_match[] = {
171 {
172 .name = "eeprom",
173 },
174 {},
175};
176
177static struct platform_driver clock_driver = {
178 .probe = clock_probe,
179 .driver = {
180 .name = "rtc",
181 .owner = THIS_MODULE,
182 .of_match_table = clock_match,
183 },
184};
185
186
187
188static int __init clock_init(void)
189{
190 return platform_driver_register(&clock_driver);
191}
192
193
194
195
196fs_initcall(clock_init);
197
198
199u32 sbus_do_gettimeoffset(void)
200{
201 unsigned long val = *master_l10_counter;
202 unsigned long usec = (val >> 10) & 0x1fffff;
203
204
205 if (val & 0x80000000)
206 usec += 1000000 / HZ;
207
208 return usec * 1000;
209}
210
211
212u32 arch_gettimeoffset(void)
213{
214 if (unlikely(!do_arch_gettimeoffset))
215 return 0;
216 return do_arch_gettimeoffset();
217}
218
219static void __init sbus_time_init(void)
220{
221 do_arch_gettimeoffset = sbus_do_gettimeoffset;
222
223 btfixup();
224
225 sparc_irq_config.init_timers(timer_interrupt);
226}
227
228void __init time_init(void)
229{
230 if (pcic_present())
231 pci_time_init();
232 else
233 sbus_time_init();
234}
235
236
237static int set_rtc_mmss(unsigned long secs)
238{
239 struct rtc_device *rtc = rtc_class_open("rtc0");
240 int err = -1;
241
242 if (rtc) {
243 err = rtc_set_mmss(rtc, secs);
244 rtc_class_close(rtc);
245 }
246
247 return err;
248}
249