1 /*
2  * Copyright (C) 2014 Broadcom Corporation
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation version 2.
7  *
8  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9  * kind, whether express or implied; without even the implied warranty
10  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13 
14 #include <linux/of_address.h>
15 #include <linux/io.h>
16 
17 #include <asm/mach/arch.h>
18 
19 #include "kona_l2_cache.h"
20 
21 #define RSTMGR_DT_STRING		"brcm,bcm21664-resetmgr"
22 
23 #define RSTMGR_REG_WR_ACCESS_OFFSET	0
24 #define RSTMGR_REG_CHIP_SOFT_RST_OFFSET	4
25 
26 #define RSTMGR_WR_PASSWORD		0xa5a5
27 #define RSTMGR_WR_PASSWORD_SHIFT	8
28 #define RSTMGR_WR_ACCESS_ENABLE		1
29 
30 static void bcm21664_restart(enum reboot_mode mode, const char *cmd)
31 {
32 	void __iomem *base;
33 	struct device_node *resetmgr;
34 
35 	resetmgr = of_find_compatible_node(NULL, NULL, RSTMGR_DT_STRING);
36 	if (!resetmgr) {
37 		pr_emerg("Couldn't find " RSTMGR_DT_STRING "\n");
38 		return;
39 	}
40 	base = of_iomap(resetmgr, 0);
41 	if (!base) {
42 		pr_emerg("Couldn't map " RSTMGR_DT_STRING "\n");
43 		return;
44 	}
45 
46 	/*
47 	 * A soft reset is triggered by writing a 0 to bit 0 of the soft reset
48 	 * register. To write to that register we must first write the password
49 	 * and the enable bit in the write access enable register.
50 	 */
51 	writel((RSTMGR_WR_PASSWORD << RSTMGR_WR_PASSWORD_SHIFT) |
52 		RSTMGR_WR_ACCESS_ENABLE,
53 		base + RSTMGR_REG_WR_ACCESS_OFFSET);
54 	writel(0, base + RSTMGR_REG_CHIP_SOFT_RST_OFFSET);
55 
56 	/* Wait for reset */
57 	while (1);
58 }
59 
60 static void __init bcm21664_init(void)
61 {
62 	kona_l2_cache_init();
63 }
64 
65 static const char * const bcm21664_dt_compat[] = {
66 	"brcm,bcm21664",
67 	NULL,
68 };
69 
70 DT_MACHINE_START(BCM21664_DT, "BCM21664 Broadcom Application Processor")
71 	.init_machine = bcm21664_init,
72 	.restart = bcm21664_restart,
73 	.dt_compat = bcm21664_dt_compat,
74 MACHINE_END
75