162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
362306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
462306a36Sopenharmony_ci * for more details.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <linux/init.h>
1062306a36Sopenharmony_ci#include <linux/memblock.h>
1162306a36Sopenharmony_ci#include <linux/smp.h>
1262306a36Sopenharmony_ci#include <asm/bootinfo.h>
1362306a36Sopenharmony_ci#include <asm/bmips.h>
1462306a36Sopenharmony_ci#include <asm/smp-ops.h>
1562306a36Sopenharmony_ci#include <asm/mipsregs.h>
1662306a36Sopenharmony_ci#include <bcm63xx_board.h>
1762306a36Sopenharmony_ci#include <bcm63xx_cpu.h>
1862306a36Sopenharmony_ci#include <bcm63xx_io.h>
1962306a36Sopenharmony_ci#include <bcm63xx_regs.h>
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_civoid __init prom_init(void)
2262306a36Sopenharmony_ci{
2362306a36Sopenharmony_ci	u32 reg, mask;
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci	bcm63xx_cpu_init();
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci	/* stop any running watchdog */
2862306a36Sopenharmony_ci	bcm_wdt_writel(WDT_STOP_1, WDT_CTL_REG);
2962306a36Sopenharmony_ci	bcm_wdt_writel(WDT_STOP_2, WDT_CTL_REG);
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci	/* disable all hardware blocks clock for now */
3262306a36Sopenharmony_ci	if (BCMCPU_IS_3368())
3362306a36Sopenharmony_ci		mask = CKCTL_3368_ALL_SAFE_EN;
3462306a36Sopenharmony_ci	else if (BCMCPU_IS_6328())
3562306a36Sopenharmony_ci		mask = CKCTL_6328_ALL_SAFE_EN;
3662306a36Sopenharmony_ci	else if (BCMCPU_IS_6338())
3762306a36Sopenharmony_ci		mask = CKCTL_6338_ALL_SAFE_EN;
3862306a36Sopenharmony_ci	else if (BCMCPU_IS_6345())
3962306a36Sopenharmony_ci		mask = CKCTL_6345_ALL_SAFE_EN;
4062306a36Sopenharmony_ci	else if (BCMCPU_IS_6348())
4162306a36Sopenharmony_ci		mask = CKCTL_6348_ALL_SAFE_EN;
4262306a36Sopenharmony_ci	else if (BCMCPU_IS_6358())
4362306a36Sopenharmony_ci		mask = CKCTL_6358_ALL_SAFE_EN;
4462306a36Sopenharmony_ci	else if (BCMCPU_IS_6362())
4562306a36Sopenharmony_ci		mask = CKCTL_6362_ALL_SAFE_EN;
4662306a36Sopenharmony_ci	else if (BCMCPU_IS_6368())
4762306a36Sopenharmony_ci		mask = CKCTL_6368_ALL_SAFE_EN;
4862306a36Sopenharmony_ci	else
4962306a36Sopenharmony_ci		mask = 0;
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	reg = bcm_perf_readl(PERF_CKCTL_REG);
5262306a36Sopenharmony_ci	reg &= ~mask;
5362306a36Sopenharmony_ci	bcm_perf_writel(reg, PERF_CKCTL_REG);
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci	/* do low level board init */
5662306a36Sopenharmony_ci	board_prom_init();
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci	/* set up SMP */
5962306a36Sopenharmony_ci	if (!register_bmips_smp_ops()) {
6062306a36Sopenharmony_ci		/*
6162306a36Sopenharmony_ci		 * BCM6328 might not have its second CPU enabled, while BCM3368
6262306a36Sopenharmony_ci		 * and BCM6358 need special handling for their shared TLB, so
6362306a36Sopenharmony_ci		 * disable SMP for now.
6462306a36Sopenharmony_ci		 */
6562306a36Sopenharmony_ci		if (BCMCPU_IS_6328()) {
6662306a36Sopenharmony_ci			reg = bcm_readl(BCM_6328_OTP_BASE +
6762306a36Sopenharmony_ci					OTP_USER_BITS_6328_REG(3));
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci			if (reg & OTP_6328_REG3_TP1_DISABLED)
7062306a36Sopenharmony_ci				bmips_smp_enabled = 0;
7162306a36Sopenharmony_ci		} else if (BCMCPU_IS_3368() || BCMCPU_IS_6358()) {
7262306a36Sopenharmony_ci			bmips_smp_enabled = 0;
7362306a36Sopenharmony_ci		}
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci		if (!bmips_smp_enabled)
7662306a36Sopenharmony_ci			return;
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci		/*
7962306a36Sopenharmony_ci		 * The bootloader has set up the CPU1 reset vector at
8062306a36Sopenharmony_ci		 * 0xa000_0200.
8162306a36Sopenharmony_ci		 * This conflicts with the special interrupt vector (IV).
8262306a36Sopenharmony_ci		 * The bootloader has also set up CPU1 to respond to the wrong
8362306a36Sopenharmony_ci		 * IPI interrupt.
8462306a36Sopenharmony_ci		 * Here we will start up CPU1 in the background and ask it to
8562306a36Sopenharmony_ci		 * reconfigure itself then go back to sleep.
8662306a36Sopenharmony_ci		 */
8762306a36Sopenharmony_ci		memcpy((void *)0xa0000200, bmips_smp_movevec, 0x20);
8862306a36Sopenharmony_ci		__sync();
8962306a36Sopenharmony_ci		set_c0_cause(C_SW0);
9062306a36Sopenharmony_ci		cpumask_set_cpu(1, &bmips_booted_mask);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci		/*
9362306a36Sopenharmony_ci		 * FIXME: we really should have some sort of hazard barrier here
9462306a36Sopenharmony_ci		 */
9562306a36Sopenharmony_ci	}
9662306a36Sopenharmony_ci}
97