1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
237fc0ed2SRob Herring /*
337fc0ed2SRob Herring * Copyright 2010-2011 Calxeda, Inc.
437fc0ed2SRob Herring */
537fc0ed2SRob Herring
637fc0ed2SRob Herring #include <common.h>
737fc0ed2SRob Herring #include <ahci.h>
8bd0d90efSRob Herring #include <netdev.h>
937fc0ed2SRob Herring #include <scsi.h>
1037fc0ed2SRob Herring
111ace4022SAlexey Brodkin #include <linux/sizes.h>
12877012dfSRob Herring #include <asm/io.h>
1337fc0ed2SRob Herring
1476c3999dSRob Herring #define HB_AHCI_BASE 0xffe08000
1576c3999dSRob Herring
16083ffd65SRob Herring #define HB_SCU_A9_PWR_STATUS 0xfff10008
170c34e69fSRob Herring #define HB_SREG_A9_PWR_REQ 0xfff3cf00
184a3ea216SRob Herring #define HB_SREG_A9_BOOT_SRC_STAT 0xfff3cf04
1976c3999dSRob Herring #define HB_SREG_A9_PWRDOM_STAT 0xfff3cf20
20f8973325SMark Langsdorf #define HB_SREG_A15_PWR_CTRL 0xfff3c200
2176c3999dSRob Herring
220c34e69fSRob Herring #define HB_PWR_SUSPEND 0
230c34e69fSRob Herring #define HB_PWR_SOFT_RESET 1
240c34e69fSRob Herring #define HB_PWR_HARD_RESET 2
250c34e69fSRob Herring #define HB_PWR_SHUTDOWN 3
260c34e69fSRob Herring
2776c3999dSRob Herring #define PWRDOM_STAT_SATA 0x80000000
2876c3999dSRob Herring #define PWRDOM_STAT_PCI 0x40000000
2976c3999dSRob Herring #define PWRDOM_STAT_EMMC 0x20000000
3076c3999dSRob Herring
31083ffd65SRob Herring #define HB_SCU_A9_PWR_NORMAL 0
32083ffd65SRob Herring #define HB_SCU_A9_PWR_DORMANT 2
33083ffd65SRob Herring #define HB_SCU_A9_PWR_OFF 3
34083ffd65SRob Herring
3537fc0ed2SRob Herring DECLARE_GLOBAL_DATA_PTR;
3637fc0ed2SRob Herring
37ef51c416SMark Langsdorf void cphy_disable_overrides(void);
38ef51c416SMark Langsdorf
3937fc0ed2SRob Herring /*
4037fc0ed2SRob Herring * Miscellaneous platform dependent initialisations
4137fc0ed2SRob Herring */
board_init(void)4237fc0ed2SRob Herring int board_init(void)
4337fc0ed2SRob Herring {
4437fc0ed2SRob Herring icache_enable();
4537fc0ed2SRob Herring
4637fc0ed2SRob Herring return 0;
4737fc0ed2SRob Herring }
4837fc0ed2SRob Herring
499a420986SRob Herring /* We know all the init functions have been run now */
board_eth_init(bd_t * bis)509a420986SRob Herring int board_eth_init(bd_t *bis)
519a420986SRob Herring {
529a420986SRob Herring int rc = 0;
539a420986SRob Herring
549a420986SRob Herring #ifdef CONFIG_CALXEDA_XGMAC
559a420986SRob Herring rc += calxedaxgmac_initialize(0, 0xfff50000);
569a420986SRob Herring rc += calxedaxgmac_initialize(1, 0xfff51000);
579a420986SRob Herring #endif
589a420986SRob Herring return rc;
599a420986SRob Herring }
609a420986SRob Herring
61b9463226SIan Campbell #ifdef CONFIG_SCSI_AHCI_PLAT
scsi_init(void)62b9463226SIan Campbell void scsi_init(void)
6337fc0ed2SRob Herring {
6476c3999dSRob Herring u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
654a3ea216SRob Herring
66ef51c416SMark Langsdorf cphy_disable_overrides();
6776c3999dSRob Herring if (reg & PWRDOM_STAT_SATA) {
689efaca3eSScott Wood ahci_init((void __iomem *)HB_AHCI_BASE);
698eab1a58SSimon Glass scsi_scan(true);
7076c3999dSRob Herring }
71b9463226SIan Campbell }
72b9463226SIan Campbell #endif
73b9463226SIan Campbell
74b9463226SIan Campbell #ifdef CONFIG_MISC_INIT_R
misc_init_r(void)75b9463226SIan Campbell int misc_init_r(void)
76b9463226SIan Campbell {
77b9463226SIan Campbell char envbuffer[16];
78b9463226SIan Campbell u32 boot_choice;
794a3ea216SRob Herring
804a3ea216SRob Herring boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
814a3ea216SRob Herring sprintf(envbuffer, "bootcmd%d", boot_choice);
8200caae6dSSimon Glass if (env_get(envbuffer)) {
834a3ea216SRob Herring sprintf(envbuffer, "run bootcmd%d", boot_choice);
84382bee57SSimon Glass env_set("bootcmd", envbuffer);
854a3ea216SRob Herring } else
86382bee57SSimon Glass env_set("bootcmd", "");
874a3ea216SRob Herring
8837fc0ed2SRob Herring return 0;
8937fc0ed2SRob Herring }
9095395023SRob Herring #endif
9137fc0ed2SRob Herring
dram_init(void)9237fc0ed2SRob Herring int dram_init(void)
9337fc0ed2SRob Herring {
9437fc0ed2SRob Herring gd->ram_size = SZ_512M;
9537fc0ed2SRob Herring return 0;
9637fc0ed2SRob Herring }
9737fc0ed2SRob Herring
9876c3999dSRob Herring #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * fdt,bd_t * bd)99e895a4b0SSimon Glass int ft_board_setup(void *fdt, bd_t *bd)
10076c3999dSRob Herring {
10176c3999dSRob Herring static const char disabled[] = "disabled";
10276c3999dSRob Herring u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
10376c3999dSRob Herring
10476c3999dSRob Herring if (!(reg & PWRDOM_STAT_SATA))
10576c3999dSRob Herring do_fixup_by_compat(fdt, "calxeda,hb-ahci", "status",
10676c3999dSRob Herring disabled, sizeof(disabled), 1);
10776c3999dSRob Herring
10876c3999dSRob Herring if (!(reg & PWRDOM_STAT_EMMC))
10976c3999dSRob Herring do_fixup_by_compat(fdt, "calxeda,hb-sdhci", "status",
11076c3999dSRob Herring disabled, sizeof(disabled), 1);
111e895a4b0SSimon Glass
112e895a4b0SSimon Glass return 0;
11376c3999dSRob Herring }
11476c3999dSRob Herring #endif
11576c3999dSRob Herring
is_highbank(void)116f8973325SMark Langsdorf static int is_highbank(void)
117f8973325SMark Langsdorf {
118f8973325SMark Langsdorf uint32_t midr;
119f8973325SMark Langsdorf
120f8973325SMark Langsdorf asm volatile ("mrc p15, 0, %0, c0, c0, 0\n" : "=r"(midr));
121f8973325SMark Langsdorf
122f8973325SMark Langsdorf return (midr & 0xfff0) == 0xc090;
123f8973325SMark Langsdorf }
124f8973325SMark Langsdorf
reset_cpu(ulong addr)12537fc0ed2SRob Herring void reset_cpu(ulong addr)
12637fc0ed2SRob Herring {
1270c34e69fSRob Herring writel(HB_PWR_HARD_RESET, HB_SREG_A9_PWR_REQ);
128f8973325SMark Langsdorf if (is_highbank())
129083ffd65SRob Herring writeb(HB_SCU_A9_PWR_OFF, HB_SCU_A9_PWR_STATUS);
130f8973325SMark Langsdorf else
131f8973325SMark Langsdorf writel(0x1, HB_SREG_A15_PWR_CTRL);
1325bedf884SRob Herring
1335bedf884SRob Herring wfi();
13437fc0ed2SRob Herring }
135ef51c416SMark Langsdorf
136ef51c416SMark Langsdorf /*
137ef51c416SMark Langsdorf * turn off the override before transferring control to Linux, since Linux
138ef51c416SMark Langsdorf * may not support spread spectrum.
139ef51c416SMark Langsdorf */
arch_preboot_os(void)140ef51c416SMark Langsdorf void arch_preboot_os(void)
141ef51c416SMark Langsdorf {
142ef51c416SMark Langsdorf cphy_disable_overrides();
143ef51c416SMark Langsdorf }
144