2012-05-31 05:02:49 +08:00
|
|
|
/*
|
|
|
|
* 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>
|
2014-10-21 03:03:53 +08:00
|
|
|
#include <linux/irqchip/mips-gic.h>
|
2012-05-31 05:02:49 +08:00
|
|
|
|
2013-09-17 23:58:10 +08:00
|
|
|
#include <asm/cpu.h>
|
2012-05-31 05:02:49 +08:00
|
|
|
#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)
|
|
|
|
{
|
2013-09-17 23:58:10 +08:00
|
|
|
unsigned int prid = read_c0_prid() & (PRID_COMP_MASK | PRID_IMP_MASK);
|
2012-05-31 05:02:49 +08:00
|
|
|
unsigned int tick = 0;
|
|
|
|
unsigned int freq;
|
|
|
|
unsigned int orig;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
2013-01-22 19:59:30 +08:00
|
|
|
orig = readl(status_reg) & 0x2; /* get original sample */
|
2012-05-31 05:02:49 +08:00
|
|
|
/* wait for transition */
|
|
|
|
while ((readl(status_reg) & 0x2) == orig)
|
|
|
|
;
|
2013-01-22 19:59:30 +08:00
|
|
|
orig = orig ^ 0x2; /* flip the bit */
|
2012-05-31 05:02:49 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
;
|
2013-01-22 19:59:30 +08:00
|
|
|
orig = orig ^ 0x2; /* flip the bit */
|
2012-05-31 05:02:49 +08:00
|
|
|
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;
|
|
|
|
|
2013-01-22 19:59:30 +08:00
|
|
|
freq += 5000; /* rounding */
|
2012-05-31 05:02:49 +08:00
|
|
|
freq -= freq%10000;
|
|
|
|
|
|
|
|
return freq ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void read_persistent_clock(struct timespec *ts)
|
|
|
|
{
|
|
|
|
ts->tv_sec = 0;
|
|
|
|
ts->tv_nsec = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-19 05:47:12 +08:00
|
|
|
int get_c0_perfcount_int(void)
|
2012-05-31 05:02:49 +08:00
|
|
|
{
|
2014-09-19 05:47:27 +08:00
|
|
|
if (gic_present)
|
2015-02-07 00:18:29 +08:00
|
|
|
return gic_get_c0_perfcount_int();
|
2014-09-19 05:47:27 +08:00
|
|
|
if (cp0_perfcount_irq >= 0)
|
|
|
|
return MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
|
|
|
|
return -1;
|
2012-05-31 05:02:49 +08:00
|
|
|
}
|
2015-07-24 00:59:52 +08:00
|
|
|
EXPORT_SYMBOL_GPL(get_c0_perfcount_int);
|
2012-05-31 05:02:49 +08:00
|
|
|
|
MIPS: Delete __cpuinit/__CPUINIT usage from MIPS code
commit 3747069b25e419f6b51395f48127e9812abc3596 upstream.
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
and are flagged as __cpuinit -- so if we remove the __cpuinit from
the arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
related content into no-ops as early as possible, since that will get
rid of these warnings. In any case, they are temporary and harmless.
Here, we remove all the MIPS __cpuinit from C code and __CPUINIT
from asm files. MIPS is interesting in this respect, because there
are also uasm users hiding behind their own renamed versions of the
__cpuinit macros.
[1] https://lkml.org/lkml/2013/5/20/589
[ralf@linux-mips.org: Folded in Paul's followup fix.]
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/5494/
Patchwork: https://patchwork.linux-mips.org/patch/5495/
Patchwork: https://patchwork.linux-mips.org/patch/5509/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
2013-06-18 21:38:59 +08:00
|
|
|
unsigned int get_c0_compare_int(void)
|
2012-05-31 05:02:49 +08:00
|
|
|
{
|
2014-09-19 05:47:27 +08:00
|
|
|
if (gic_present)
|
|
|
|
return gic_get_c0_compare_int();
|
|
|
|
return MIPS_CPU_IRQ_BASE + cp0_compare_irq;
|
2012-05-31 05:02:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|