sead3-time.c 2.2 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 2012 MIPS Technologies, Inc.  All rights reserved.
 */
#include <linux/init.h>
9
#include <linux/irqchip/mips-gic.h>
10

11
#include <asm/cpu.h>
12 13 14 15 16 17 18 19 20 21 22 23
#include <asm/setup.h>
#include <asm/time.h>
#include <asm/irq.h>
#include <asm/mips-boards/generic.h>

static void __iomem *status_reg = (void __iomem *)0xbf000410;

/*
 * Estimate CPU frequency.  Sets mips_hpt_frequency as a side-effect.
 */
static unsigned int __init estimate_cpu_frequency(void)
{
24
	unsigned int prid = read_c0_prid() & (PRID_COMP_MASK | PRID_IMP_MASK);
25 26 27 28 29 30 31
	unsigned int tick = 0;
	unsigned int freq;
	unsigned int orig;
	unsigned long flags;

	local_irq_save(flags);

R
Ralf Baechle 已提交
32
	orig = readl(status_reg) & 0x2;		      /* get original sample */
33 34 35
	/* wait for transition */
	while ((readl(status_reg) & 0x2) == orig)
		;
R
Ralf Baechle 已提交
36
	orig = orig ^ 0x2;			      /* flip the bit */
37 38 39 40 41 42 43 44

	write_c0_count(0);

	/* wait 1 second (the sampling clock transitions every 10ms) */
	while (tick < 100) {
		/* wait for transition */
		while ((readl(status_reg) & 0x2) == orig)
			;
R
Ralf Baechle 已提交
45
		orig = orig ^ 0x2;			      /* flip the bit */
46 47 48 49 50 51 52 53 54 55 56 57 58 59
		tick++;
	}

	freq = read_c0_count();

	local_irq_restore(flags);

	mips_hpt_frequency = freq;

	/* Adjust for processor */
	if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
		(prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
		freq *= 2;

R
Ralf Baechle 已提交
60
	freq += 5000;	     /* rounding */
61 62 63 64 65 66 67 68 69 70 71
	freq -= freq%10000;

	return freq ;
}

void read_persistent_clock(struct timespec *ts)
{
	ts->tv_sec = 0;
	ts->tv_nsec = 0;
}

72
int get_c0_perfcount_int(void)
73
{
74
	if (gic_present)
75
		return gic_get_c0_perfcount_int();
76 77 78
	if (cp0_perfcount_irq >= 0)
		return MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
	return -1;
79
}
80
EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
81

82
unsigned int get_c0_compare_int(void)
83
{
84 85 86
	if (gic_present)
		return gic_get_c0_compare_int();
	return MIPS_CPU_IRQ_BASE + cp0_compare_irq;
87 88 89 90 91 92 93 94 95 96 97 98 99
}

void __init plat_time_init(void)
{
	unsigned int est_freq;

	est_freq = estimate_cpu_frequency();

	pr_debug("CPU frequency %d.%02d MHz\n", (est_freq / 1000000),
		(est_freq % 1000000) * 100 / 1000000);

	mips_scroll_message();
}