1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright 2010-2011 Calxeda, Inc.
4 */
5
6 #include <common.h>
7 #include <ahci.h>
8 #include <cpu_func.h>
9 #include <env.h>
10 #include <fdt_support.h>
11 #include <init.h>
12 #include <net.h>
13 #include <netdev.h>
14 #include <scsi.h>
15 #include <asm/global_data.h>
16
17 #include <linux/sizes.h>
18 #include <asm/io.h>
19
20 #define HB_AHCI_BASE 0xffe08000
21
22 #define HB_SCU_A9_PWR_STATUS 0xfff10008
23 #define HB_SREG_A9_PWR_REQ 0xfff3cf00
24 #define HB_SREG_A9_BOOT_SRC_STAT 0xfff3cf04
25 #define HB_SREG_A9_PWRDOM_STAT 0xfff3cf20
26 #define HB_SREG_A15_PWR_CTRL 0xfff3c200
27
28 #define HB_PWR_SUSPEND 0
29 #define HB_PWR_SOFT_RESET 1
30 #define HB_PWR_HARD_RESET 2
31 #define HB_PWR_SHUTDOWN 3
32
33 #define PWRDOM_STAT_SATA 0x80000000
34 #define PWRDOM_STAT_PCI 0x40000000
35 #define PWRDOM_STAT_EMMC 0x20000000
36
37 #define HB_SCU_A9_PWR_NORMAL 0
38 #define HB_SCU_A9_PWR_DORMANT 2
39 #define HB_SCU_A9_PWR_OFF 3
40
41 DECLARE_GLOBAL_DATA_PTR;
42
43 void cphy_disable_overrides(void);
44
45 /*
46 * Miscellaneous platform dependent initialisations
47 */
board_init(void)48 int board_init(void)
49 {
50 icache_enable();
51
52 return 0;
53 }
54
55 /* We know all the init functions have been run now */
board_eth_init(struct bd_info * bis)56 int board_eth_init(struct bd_info *bis)
57 {
58 int rc = 0;
59
60 #ifdef CONFIG_CALXEDA_XGMAC
61 rc += calxedaxgmac_initialize(0, 0xfff50000);
62 rc += calxedaxgmac_initialize(1, 0xfff51000);
63 #endif
64 return rc;
65 }
66
67 #ifdef CONFIG_SCSI_AHCI_PLAT
scsi_init(void)68 void scsi_init(void)
69 {
70 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
71
72 cphy_disable_overrides();
73 if (reg & PWRDOM_STAT_SATA) {
74 ahci_init((void __iomem *)HB_AHCI_BASE);
75 scsi_scan(true);
76 }
77 }
78 #endif
79
80 #ifdef CONFIG_MISC_INIT_R
misc_init_r(void)81 int misc_init_r(void)
82 {
83 char envbuffer[16];
84 u32 boot_choice;
85
86 boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
87 sprintf(envbuffer, "bootcmd%d", boot_choice);
88 if (env_get(envbuffer)) {
89 sprintf(envbuffer, "run bootcmd%d", boot_choice);
90 env_set("bootcmd", envbuffer);
91 } else
92 env_set("bootcmd", "");
93
94 return 0;
95 }
96 #endif
97
dram_init(void)98 int dram_init(void)
99 {
100 gd->ram_size = SZ_512M;
101 return 0;
102 }
103
104 #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * fdt,struct bd_info * bd)105 int ft_board_setup(void *fdt, struct bd_info *bd)
106 {
107 static const char disabled[] = "disabled";
108 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
109
110 if (!(reg & PWRDOM_STAT_SATA))
111 do_fixup_by_compat(fdt, "calxeda,hb-ahci", "status",
112 disabled, sizeof(disabled), 1);
113
114 if (!(reg & PWRDOM_STAT_EMMC))
115 do_fixup_by_compat(fdt, "calxeda,hb-sdhci", "status",
116 disabled, sizeof(disabled), 1);
117
118 return 0;
119 }
120 #endif
121
is_highbank(void)122 static int is_highbank(void)
123 {
124 uint32_t midr;
125
126 asm volatile ("mrc p15, 0, %0, c0, c0, 0\n" : "=r"(midr));
127
128 return (midr & 0xfff0) == 0xc090;
129 }
130
reset_cpu(ulong addr)131 void reset_cpu(ulong addr)
132 {
133 writel(HB_PWR_HARD_RESET, HB_SREG_A9_PWR_REQ);
134 if (is_highbank())
135 writeb(HB_SCU_A9_PWR_OFF, HB_SCU_A9_PWR_STATUS);
136 else
137 writel(0x1, HB_SREG_A15_PWR_CTRL);
138
139 wfi();
140 }
141
142 /*
143 * turn off the override before transferring control to Linux, since Linux
144 * may not support spread spectrum.
145 */
arch_preboot_os(void)146 void arch_preboot_os(void)
147 {
148 cphy_disable_overrides();
149 }
150