1 /* linux/arch/sparc/kernel/time.c
3 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
4 * Copyright (C) 1996 Thomas K. Dyas (tdyas@eden.rutgers.edu)
6 * Chris Davis (cdavis@cois.on.ca) 03/27/1998
7 * Added support for the intersil on the sun4/4200
9 * Gleb Raiko (rajko@mech.math.msu.su) 08/18/1998
10 * Support for MicroSPARC-IIep, PCI CPU.
12 * This file handles the Sparc specific time handling details.
14 * 1997-09-10 Updated NTP code according to technical memorandum Jan '96
15 * "A Kernel Model for Precision Timekeeping" by Dave Mills
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>
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>
34 #include <linux/of_device.h>
35 #include <linux/platform_device.h>
37 #include <asm/oplib.h>
38 #include <asm/timex.h>
39 #include <asm/timer.h>
42 #include <asm/idprom.h>
43 #include <asm/machines.h>
46 #include <asm/irq_regs.h>
50 DEFINE_SPINLOCK(rtc_lock
);
51 EXPORT_SYMBOL(rtc_lock
);
53 static int set_rtc_mmss(unsigned long);
55 unsigned long profile_pc(struct pt_regs
*regs
)
57 extern char __copy_user_begin
[], __copy_user_end
[];
58 extern char __atomic_begin
[], __atomic_end
[];
59 extern char __bzero_begin
[], __bzero_end
[];
61 unsigned long pc
= regs
->pc
;
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
];
74 EXPORT_SYMBOL(profile_pc
);
76 __volatile__
unsigned int *master_l10_counter
;
78 u32 (*do_arch_gettimeoffset
)(void);
80 int update_persistent_clock(struct timespec now
)
82 return set_rtc_mmss(now
.tv_sec
);
86 * timer_interrupt() needs to keep up the real-time clock,
87 * as well as call the "xtime_update()" routine every clocktick
90 #define TICK_SIZE (tick_nsec / 1000)
92 static irqreturn_t
timer_interrupt(int dummy
, void *dev_id
)
95 profile_tick(CPU_PROFILING
);
103 update_process_times(user_mode(get_irq_regs()));
108 static unsigned char mostek_read_byte(struct device
*dev
, u32 ofs
)
110 struct platform_device
*pdev
= to_platform_device(dev
);
111 struct m48t59_plat_data
*pdata
= pdev
->dev
.platform_data
;
113 return readb(pdata
->ioaddr
+ ofs
);
116 static void mostek_write_byte(struct device
*dev
, u32 ofs
, u8 val
)
118 struct platform_device
*pdev
= to_platform_device(dev
);
119 struct m48t59_plat_data
*pdata
= pdev
->dev
.platform_data
;
121 writeb(val
, pdata
->ioaddr
+ ofs
);
124 static struct m48t59_plat_data m48t59_data
= {
125 .read_byte
= mostek_read_byte
,
126 .write_byte
= mostek_write_byte
,
129 /* resource is set at runtime */
130 static struct platform_device m48t59_rtc
= {
131 .name
= "rtc-m48t59",
135 .platform_data
= &m48t59_data
,
139 static int __devinit
clock_probe(struct platform_device
*op
)
141 struct device_node
*dp
= op
->dev
.of_node
;
142 const char *model
= of_get_property(dp
, "model", NULL
);
147 /* Only the primary RTC has an address property */
148 if (!of_find_property(dp
, "address", NULL
))
151 m48t59_rtc
.resource
= &op
->resource
[0];
152 if (!strcmp(model
, "mk48t02")) {
153 /* Map the clock register io area read-only */
154 m48t59_data
.ioaddr
= of_ioremap(&op
->resource
[0], 0,
156 m48t59_data
.type
= M48T59RTC_TYPE_M48T02
;
157 } else if (!strcmp(model
, "mk48t08")) {
158 m48t59_data
.ioaddr
= of_ioremap(&op
->resource
[0], 0,
160 m48t59_data
.type
= M48T59RTC_TYPE_M48T08
;
164 if (platform_device_register(&m48t59_rtc
) < 0)
165 printk(KERN_ERR
"Registering RTC device failed\n");
170 static struct of_device_id clock_match
[] = {
177 static struct platform_driver clock_driver
= {
178 .probe
= clock_probe
,
181 .owner
= THIS_MODULE
,
182 .of_match_table
= clock_match
,
187 /* Probe for the mostek real time clock chip. */
188 static int __init
clock_init(void)
190 return platform_driver_register(&clock_driver
);
192 /* Must be after subsys_initcall() so that busses are probed. Must
193 * be before device_initcall() because things like the RTC driver
194 * need to see the clock registers.
196 fs_initcall(clock_init
);
199 u32
sbus_do_gettimeoffset(void)
201 unsigned long val
= *master_l10_counter
;
202 unsigned long usec
= (val
>> 10) & 0x1fffff;
205 if (val
& 0x80000000)
206 usec
+= 1000000 / HZ
;
212 u32
arch_gettimeoffset(void)
214 if (unlikely(!do_arch_gettimeoffset
))
216 return do_arch_gettimeoffset();
219 static void __init
sbus_time_init(void)
221 do_arch_gettimeoffset
= sbus_do_gettimeoffset
;
225 sparc_irq_config
.init_timers(timer_interrupt
);
228 void __init
time_init(void)
237 static int set_rtc_mmss(unsigned long secs
)
239 struct rtc_device
*rtc
= rtc_class_open("rtc0");
243 err
= rtc_set_mmss(rtc
, secs
);
244 rtc_class_close(rtc
);