173b4390fb23456964201abda79f1210fe337d01aRalf Baechle/*
273b4390fb23456964201abda79f1210fe337d01aRalf Baechle * Carsten Langgaard, carstenl@mips.com
373b4390fb23456964201abda79f1210fe337d01aRalf Baechle * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
473b4390fb23456964201abda79f1210fe337d01aRalf Baechle *
573b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  This program is free software; you can distribute it and/or modify it
673b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  under the terms of the GNU General Public License (Version 2) as
773b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  published by the Free Software Foundation.
873b4390fb23456964201abda79f1210fe337d01aRalf Baechle *
973b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  This program is distributed in the hope it will be useful, but WITHOUT
1073b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1173b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1273b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  for more details.
1373b4390fb23456964201abda79f1210fe337d01aRalf Baechle *
1473b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  You should have received a copy of the GNU General Public License along
1573b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  with this program; if not, write to the Free Software Foundation, Inc.,
1673b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
1773b4390fb23456964201abda79f1210fe337d01aRalf Baechle *
1873b4390fb23456964201abda79f1210fe337d01aRalf Baechle *  Setting up the clock on the MIPS boards.
1973b4390fb23456964201abda79f1210fe337d01aRalf Baechle */
2073b4390fb23456964201abda79f1210fe337d01aRalf Baechle
2173b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/init.h>
2273b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/kernel_stat.h>
2373b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/ptrace.h>
2473b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/sched.h>
2573b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/spinlock.h>
2673b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/mc146818rtc.h>
2773b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/irq.h>
2873b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <linux/timex.h>
2973b4390fb23456964201abda79f1210fe337d01aRalf Baechle
3073b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <asm/mipsregs.h>
3173b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <asm/time.h>
3273b4390fb23456964201abda79f1210fe337d01aRalf Baechle#include <asm/mach-rc32434/rc32434.h>
3373b4390fb23456964201abda79f1210fe337d01aRalf Baechle
3473b4390fb23456964201abda79f1210fe337d01aRalf Baechleextern unsigned int idt_cpu_freq;
3573b4390fb23456964201abda79f1210fe337d01aRalf Baechle
3673b4390fb23456964201abda79f1210fe337d01aRalf Baechle/*
3773b4390fb23456964201abda79f1210fe337d01aRalf Baechle * Figure out the r4k offset, the amount to increment the compare
3873b4390fb23456964201abda79f1210fe337d01aRalf Baechle * register for each time tick. There is no RTC available.
3973b4390fb23456964201abda79f1210fe337d01aRalf Baechle *
4073b4390fb23456964201abda79f1210fe337d01aRalf Baechle * The RC32434 counts at half the CPU *core* speed.
4173b4390fb23456964201abda79f1210fe337d01aRalf Baechle */
4273b4390fb23456964201abda79f1210fe337d01aRalf Baechlestatic unsigned long __init cal_r4koff(void)
4373b4390fb23456964201abda79f1210fe337d01aRalf Baechle{
4473b4390fb23456964201abda79f1210fe337d01aRalf Baechle	mips_hpt_frequency = idt_cpu_freq * IDT_CLOCK_MULT / 2;
4573b4390fb23456964201abda79f1210fe337d01aRalf Baechle
4673b4390fb23456964201abda79f1210fe337d01aRalf Baechle	return mips_hpt_frequency / HZ;
4773b4390fb23456964201abda79f1210fe337d01aRalf Baechle}
4873b4390fb23456964201abda79f1210fe337d01aRalf Baechle
4973b4390fb23456964201abda79f1210fe337d01aRalf Baechlevoid __init plat_time_init(void)
5073b4390fb23456964201abda79f1210fe337d01aRalf Baechle{
518b32d6d00ca890ebb204da1260247c11bba042b3Adrian Bunk	unsigned int est_freq;
528b32d6d00ca890ebb204da1260247c11bba042b3Adrian Bunk	unsigned long flags, r4k_offset;
5373b4390fb23456964201abda79f1210fe337d01aRalf Baechle
5473b4390fb23456964201abda79f1210fe337d01aRalf Baechle	local_irq_save(flags);
5573b4390fb23456964201abda79f1210fe337d01aRalf Baechle
5673b4390fb23456964201abda79f1210fe337d01aRalf Baechle	printk(KERN_INFO "calculating r4koff... ");
5773b4390fb23456964201abda79f1210fe337d01aRalf Baechle	r4k_offset = cal_r4koff();
5873b4390fb23456964201abda79f1210fe337d01aRalf Baechle	printk("%08lx(%d)\n", r4k_offset, (int) r4k_offset);
5973b4390fb23456964201abda79f1210fe337d01aRalf Baechle
6073b4390fb23456964201abda79f1210fe337d01aRalf Baechle	est_freq = 2 * r4k_offset * HZ;
6173b4390fb23456964201abda79f1210fe337d01aRalf Baechle	est_freq += 5000;	/* round */
6273b4390fb23456964201abda79f1210fe337d01aRalf Baechle	est_freq -= est_freq % 10000;
6373b4390fb23456964201abda79f1210fe337d01aRalf Baechle	printk(KERN_INFO "CPU frequency %d.%02d MHz\n", est_freq / 1000000,
6473b4390fb23456964201abda79f1210fe337d01aRalf Baechle	       (est_freq % 1000000) * 100 / 1000000);
6573b4390fb23456964201abda79f1210fe337d01aRalf Baechle	local_irq_restore(flags);
6673b4390fb23456964201abda79f1210fe337d01aRalf Baechle}
67