blob: 3e0edd48f51d534c407f53ca981b9ac747417eb0 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rob Herring37fc0ed2011-10-24 08:50:20 +00002/*
3 * Copyright 2010-2011 Calxeda, Inc.
Rob Herring37fc0ed2011-10-24 08:50:20 +00004 */
5
6#include <common.h>
7#include <ahci.h>
Simon Glass9edefc22019-11-14 12:57:37 -07008#include <cpu_func.h>
Simon Glass9fb625c2019-08-01 09:46:51 -06009#include <env.h>
Rob Herringbd0d90e2012-02-21 12:52:26 +000010#include <netdev.h>
Rob Herring37fc0ed2011-10-24 08:50:20 +000011#include <scsi.h>
12
Alexey Brodkin1ace4022014-02-26 17:47:58 +040013#include <linux/sizes.h>
Rob Herring877012d2012-02-01 16:57:54 +000014#include <asm/io.h>
Rob Herring37fc0ed2011-10-24 08:50:20 +000015
Rob Herring76c39992013-06-12 22:24:52 -050016#define HB_AHCI_BASE 0xffe08000
17
Rob Herring083ffd62015-06-05 00:58:42 +010018#define HB_SCU_A9_PWR_STATUS 0xfff10008
Rob Herring0c34e692012-02-01 16:57:55 +000019#define HB_SREG_A9_PWR_REQ 0xfff3cf00
Rob Herring4a3ea212012-02-01 16:57:57 +000020#define HB_SREG_A9_BOOT_SRC_STAT 0xfff3cf04
Rob Herring76c39992013-06-12 22:24:52 -050021#define HB_SREG_A9_PWRDOM_STAT 0xfff3cf20
Mark Langsdorff8973322015-06-05 00:58:43 +010022#define HB_SREG_A15_PWR_CTRL 0xfff3c200
Rob Herring76c39992013-06-12 22:24:52 -050023
Rob Herring0c34e692012-02-01 16:57:55 +000024#define HB_PWR_SUSPEND 0
25#define HB_PWR_SOFT_RESET 1
26#define HB_PWR_HARD_RESET 2
27#define HB_PWR_SHUTDOWN 3
28
Rob Herring76c39992013-06-12 22:24:52 -050029#define PWRDOM_STAT_SATA 0x80000000
30#define PWRDOM_STAT_PCI 0x40000000
31#define PWRDOM_STAT_EMMC 0x20000000
32
Rob Herring083ffd62015-06-05 00:58:42 +010033#define HB_SCU_A9_PWR_NORMAL 0
34#define HB_SCU_A9_PWR_DORMANT 2
35#define HB_SCU_A9_PWR_OFF 3
36
Rob Herring37fc0ed2011-10-24 08:50:20 +000037DECLARE_GLOBAL_DATA_PTR;
38
Mark Langsdorfef51c412015-06-05 00:58:49 +010039void cphy_disable_overrides(void);
40
Rob Herring37fc0ed2011-10-24 08:50:20 +000041/*
42 * Miscellaneous platform dependent initialisations
43 */
44int board_init(void)
45{
46 icache_enable();
47
48 return 0;
49}
50
Rob Herring9a420982011-12-15 11:15:50 +000051/* We know all the init functions have been run now */
52int board_eth_init(bd_t *bis)
53{
54 int rc = 0;
55
56#ifdef CONFIG_CALXEDA_XGMAC
57 rc += calxedaxgmac_initialize(0, 0xfff50000);
58 rc += calxedaxgmac_initialize(1, 0xfff51000);
59#endif
60 return rc;
61}
62
Ian Campbellb9463222014-03-07 01:20:57 +000063#ifdef CONFIG_SCSI_AHCI_PLAT
64void scsi_init(void)
Rob Herring37fc0ed2011-10-24 08:50:20 +000065{
Rob Herring76c39992013-06-12 22:24:52 -050066 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
Rob Herring4a3ea212012-02-01 16:57:57 +000067
Mark Langsdorfef51c412015-06-05 00:58:49 +010068 cphy_disable_overrides();
Rob Herring76c39992013-06-12 22:24:52 -050069 if (reg & PWRDOM_STAT_SATA) {
Scott Wood9efaca32015-04-17 09:19:01 -050070 ahci_init((void __iomem *)HB_AHCI_BASE);
Simon Glass8eab1a52017-06-14 21:28:41 -060071 scsi_scan(true);
Rob Herring76c39992013-06-12 22:24:52 -050072 }
Ian Campbellb9463222014-03-07 01:20:57 +000073}
74#endif
75
76#ifdef CONFIG_MISC_INIT_R
77int misc_init_r(void)
78{
79 char envbuffer[16];
80 u32 boot_choice;
Rob Herring4a3ea212012-02-01 16:57:57 +000081
82 boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
83 sprintf(envbuffer, "bootcmd%d", boot_choice);
Simon Glass00caae62017-08-03 12:22:12 -060084 if (env_get(envbuffer)) {
Rob Herring4a3ea212012-02-01 16:57:57 +000085 sprintf(envbuffer, "run bootcmd%d", boot_choice);
Simon Glass382bee52017-08-03 12:22:09 -060086 env_set("bootcmd", envbuffer);
Rob Herring4a3ea212012-02-01 16:57:57 +000087 } else
Simon Glass382bee52017-08-03 12:22:09 -060088 env_set("bootcmd", "");
Rob Herring4a3ea212012-02-01 16:57:57 +000089
Rob Herring37fc0ed2011-10-24 08:50:20 +000090 return 0;
91}
Rob Herring95395022013-06-12 22:24:53 -050092#endif
Rob Herring37fc0ed2011-10-24 08:50:20 +000093
94int dram_init(void)
95{
96 gd->ram_size = SZ_512M;
97 return 0;
98}
99
Rob Herring76c39992013-06-12 22:24:52 -0500100#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600101int ft_board_setup(void *fdt, bd_t *bd)
Rob Herring76c39992013-06-12 22:24:52 -0500102{
103 static const char disabled[] = "disabled";
104 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
105
106 if (!(reg & PWRDOM_STAT_SATA))
107 do_fixup_by_compat(fdt, "calxeda,hb-ahci", "status",
108 disabled, sizeof(disabled), 1);
109
110 if (!(reg & PWRDOM_STAT_EMMC))
111 do_fixup_by_compat(fdt, "calxeda,hb-sdhci", "status",
112 disabled, sizeof(disabled), 1);
Simon Glasse895a4b2014-10-23 18:58:47 -0600113
114 return 0;
Rob Herring76c39992013-06-12 22:24:52 -0500115}
116#endif
117
Mark Langsdorff8973322015-06-05 00:58:43 +0100118static int is_highbank(void)
119{
120 uint32_t midr;
121
122 asm volatile ("mrc p15, 0, %0, c0, c0, 0\n" : "=r"(midr));
123
124 return (midr & 0xfff0) == 0xc090;
125}
126
Rob Herring37fc0ed2011-10-24 08:50:20 +0000127void reset_cpu(ulong addr)
128{
Rob Herring0c34e692012-02-01 16:57:55 +0000129 writel(HB_PWR_HARD_RESET, HB_SREG_A9_PWR_REQ);
Mark Langsdorff8973322015-06-05 00:58:43 +0100130 if (is_highbank())
131 writeb(HB_SCU_A9_PWR_OFF, HB_SCU_A9_PWR_STATUS);
132 else
133 writel(0x1, HB_SREG_A15_PWR_CTRL);
Rob Herring5bedf882012-12-02 17:06:22 +0000134
135 wfi();
Rob Herring37fc0ed2011-10-24 08:50:20 +0000136}
Mark Langsdorfef51c412015-06-05 00:58:49 +0100137
138/*
139 * turn off the override before transferring control to Linux, since Linux
140 * may not support spread spectrum.
141 */
142void arch_preboot_os(void)
143{
144 cphy_disable_overrides();
145}