blob: 944ab9ce7cda6a93571316d3bae8e52ba4bf7070 [file] [log] [blame]
Rob Herring37fc0ed2011-10-24 08:50:20 +00001/*
2 * Copyright 2010-2011 Calxeda, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <common.h>
19#include <ahci.h>
Rob Herringbd0d90e2012-02-21 12:52:26 +000020#include <netdev.h>
Rob Herring37fc0ed2011-10-24 08:50:20 +000021#include <scsi.h>
22
23#include <asm/sizes.h>
Rob Herring877012d2012-02-01 16:57:54 +000024#include <asm/io.h>
Rob Herring37fc0ed2011-10-24 08:50:20 +000025
Rob Herring0c34e692012-02-01 16:57:55 +000026#define HB_SREG_A9_PWR_REQ 0xfff3cf00
Rob Herring4a3ea212012-02-01 16:57:57 +000027#define HB_SREG_A9_BOOT_SRC_STAT 0xfff3cf04
Rob Herringa167f5f2012-09-10 08:28:42 -050028#define HB_SREG_A9_PWRDOM_STAT 0xfff3cf20
Mark Langsdorf1e6d1832012-11-21 13:01:06 -060029#define HB_SYSRAM_OPP_TABLE_BASE 0xfff8f000
30#define HB_OPP_VERSION 0
Rob Herringa167f5f2012-09-10 08:28:42 -050031
Rob Herring0c34e692012-02-01 16:57:55 +000032#define HB_PWR_SUSPEND 0
33#define HB_PWR_SOFT_RESET 1
34#define HB_PWR_HARD_RESET 2
35#define HB_PWR_SHUTDOWN 3
36
Rob Herringa167f5f2012-09-10 08:28:42 -050037#define PWRDOM_STAT_SATA 0x80000000
38#define PWRDOM_STAT_PCI 0x40000000
39#define PWRDOM_STAT_EMMC 0x20000000
40
Rob Herring37fc0ed2011-10-24 08:50:20 +000041DECLARE_GLOBAL_DATA_PTR;
42
43/*
44 * Miscellaneous platform dependent initialisations
45 */
46int board_init(void)
47{
48 icache_enable();
49
50 return 0;
51}
52
Rob Herring9a420982011-12-15 11:15:50 +000053/* We know all the init functions have been run now */
54int board_eth_init(bd_t *bis)
55{
56 int rc = 0;
57
58#ifdef CONFIG_CALXEDA_XGMAC
59 rc += calxedaxgmac_initialize(0, 0xfff50000);
60 rc += calxedaxgmac_initialize(1, 0xfff51000);
61#endif
62 return rc;
63}
64
Rob Herring37fc0ed2011-10-24 08:50:20 +000065int misc_init_r(void)
66{
Rob Herring4a3ea212012-02-01 16:57:57 +000067 char envbuffer[16];
68 u32 boot_choice;
Rob Herringa167f5f2012-09-10 08:28:42 -050069 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
Rob Herring4a3ea212012-02-01 16:57:57 +000070
Rob Herringa167f5f2012-09-10 08:28:42 -050071 if (reg & PWRDOM_STAT_SATA) {
72 ahci_init(0xffe08000);
73 scsi_scan(1);
74 }
Rob Herring4a3ea212012-02-01 16:57:57 +000075
76 boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
77 sprintf(envbuffer, "bootcmd%d", boot_choice);
78 if (getenv(envbuffer)) {
79 sprintf(envbuffer, "run bootcmd%d", boot_choice);
80 setenv("bootcmd", envbuffer);
81 } else
82 setenv("bootcmd", "");
83
Rob Herring37fc0ed2011-10-24 08:50:20 +000084 return 0;
85}
86
87int dram_init(void)
88{
89 gd->ram_size = SZ_512M;
90 return 0;
91}
92
93void dram_init_banksize(void)
94{
95 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
96 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
97}
98
Rob Herringa167f5f2012-09-10 08:28:42 -050099#if defined(CONFIG_OF_BOARD_SETUP)
Mark Langsdorf1e6d1832012-11-21 13:01:06 -0600100struct a9_opp {
101 unsigned int freq_hz;
102 unsigned int volt_mv;
103};
104
105
Rob Herringa167f5f2012-09-10 08:28:42 -0500106void ft_board_setup(void *fdt, bd_t *bd)
107{
108 const char disabled[] = "disabled";
Mark Langsdorf1e6d1832012-11-21 13:01:06 -0600109 u32 *opp_table = HB_SYSRAM_OPP_TABLE_BASE;
Rob Herringa167f5f2012-09-10 08:28:42 -0500110 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
111
112 if (!(reg & PWRDOM_STAT_SATA))
Rob Herringfb293b82012-09-13 14:05:00 -0500113 do_fixup_by_compat(fdt, "calxeda,hb-ahci", "status", disabled, sizeof(disabled), 1);
Rob Herringa167f5f2012-09-10 08:28:42 -0500114
115 if (!(reg & PWRDOM_STAT_EMMC))
116 do_fixup_by_compat(fdt, "calxeda,hb-sdhci", "status", disabled, sizeof(disabled), 1);
Mark Langsdorf1e6d1832012-11-21 13:01:06 -0600117
118 if ((opp_table[0] >> 16) == HB_OPP_VERSION) {
119 u32 dtb_table[2*10];
120 u32 ret;
121 u32 i;
122 u32 num_opps = opp_table[0] & 0xff;
123 for (i = 0; i < num_opps; i++) {
124 dtb_table[2 * i] = cpu_to_be32(opp_table[3 + 3 * i]);
125 dtb_table[2 * i + 1] =
126 cpu_to_be32(opp_table[2 + 3 * i]);
127 }
128 fdt_find_and_setprop(fdt, "/cpus/cpu@0", "operating-points",
129 dtb_table, 8 * num_opps, 1);
130 }
Rob Herringa167f5f2012-09-10 08:28:42 -0500131}
132#endif
133
Rob Herring37fc0ed2011-10-24 08:50:20 +0000134void reset_cpu(ulong addr)
135{
Rob Herring0c34e692012-02-01 16:57:55 +0000136 writel(HB_PWR_HARD_RESET, HB_SREG_A9_PWR_REQ);
Rob Herringf81fbd72012-04-20 14:32:37 -0500137 writeb(0x3, 0xfff10008);
Rob Herring4d82bee2012-05-07 20:50:01 -0500138 /* older compilers don't understand wfi instr, so hardcode it */
139 asm(" .word 0xe320f003");
Rob Herring37fc0ed2011-10-24 08:50:20 +0000140}