blk: rq_data_dir() should not return a boolean
[cris-mirror.git] / arch / mips / mti-sead3 / sead3-time.c
bloba120b7a5a8fe4e9af03ccb40fc9e7e123f88d633
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7 */
8 #include <linux/init.h>
9 #include <linux/irqchip/mips-gic.h>
11 #include <asm/cpu.h>
12 #include <asm/setup.h>
13 #include <asm/time.h>
14 #include <asm/irq.h>
15 #include <asm/mips-boards/generic.h>
17 static void __iomem *status_reg = (void __iomem *)0xbf000410;
20 * Estimate CPU frequency. Sets mips_hpt_frequency as a side-effect.
22 static unsigned int __init estimate_cpu_frequency(void)
24 unsigned int prid = read_c0_prid() & (PRID_COMP_MASK | PRID_IMP_MASK);
25 unsigned int tick = 0;
26 unsigned int freq;
27 unsigned int orig;
28 unsigned long flags;
30 local_irq_save(flags);
32 orig = readl(status_reg) & 0x2; /* get original sample */
33 /* wait for transition */
34 while ((readl(status_reg) & 0x2) == orig)
36 orig = orig ^ 0x2; /* flip the bit */
38 write_c0_count(0);
40 /* wait 1 second (the sampling clock transitions every 10ms) */
41 while (tick < 100) {
42 /* wait for transition */
43 while ((readl(status_reg) & 0x2) == orig)
45 orig = orig ^ 0x2; /* flip the bit */
46 tick++;
49 freq = read_c0_count();
51 local_irq_restore(flags);
53 mips_hpt_frequency = freq;
55 /* Adjust for processor */
56 if ((prid != (PRID_COMP_MIPS | PRID_IMP_20KC)) &&
57 (prid != (PRID_COMP_MIPS | PRID_IMP_25KF)))
58 freq *= 2;
60 freq += 5000; /* rounding */
61 freq -= freq%10000;
63 return freq ;
66 void read_persistent_clock(struct timespec *ts)
68 ts->tv_sec = 0;
69 ts->tv_nsec = 0;
72 int get_c0_perfcount_int(void)
74 if (gic_present)
75 return gic_get_c0_perfcount_int();
76 if (cp0_perfcount_irq >= 0)
77 return MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
78 return -1;
80 EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
82 unsigned int get_c0_compare_int(void)
84 if (gic_present)
85 return gic_get_c0_compare_int();
86 return MIPS_CPU_IRQ_BASE + cp0_compare_irq;
89 void __init plat_time_init(void)
91 unsigned int est_freq;
93 est_freq = estimate_cpu_frequency();
95 pr_debug("CPU frequency %d.%02d MHz\n", (est_freq / 1000000),
96 (est_freq % 1000000) * 100 / 1000000);
98 mips_scroll_message();