blob: b5fa5101e881aa7a885d47ced1871f989c67bb32 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rob Herring73089ad2011-10-24 08:50:20 +00002/*
3 * Copyright 2010-2011 Calxeda, Inc.
Rob Herring73089ad2011-10-24 08:50:20 +00004 */
5
6#include <common.h>
7#include <ahci.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Simon Glass5e6201b2019-08-01 09:46:51 -06009#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060010#include <fdt_support.h>
Andre Przywara126d9a62021-04-12 01:04:54 +010011#include <fdtdec.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Rob Herring73089ad2011-10-24 08:50:20 +000014#include <scsi.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Rob Herring73089ad2011-10-24 08:50:20 +000016
Alexey Brodkin267d8e22014-02-26 17:47:58 +040017#include <linux/sizes.h>
Rob Herring02fe7852012-02-01 16:57:54 +000018#include <asm/io.h>
Rob Herring73089ad2011-10-24 08:50:20 +000019
Rob Herringfd7ec6e2013-06-12 22:24:52 -050020#define HB_AHCI_BASE 0xffe08000
21
Rob Herring37057562015-06-05 00:58:42 +010022#define HB_SCU_A9_PWR_STATUS 0xfff10008
Rob Herringf9904ce2012-02-01 16:57:55 +000023#define HB_SREG_A9_PWR_REQ 0xfff3cf00
Rob Herring06d00742012-02-01 16:57:57 +000024#define HB_SREG_A9_BOOT_SRC_STAT 0xfff3cf04
Rob Herringfd7ec6e2013-06-12 22:24:52 -050025#define HB_SREG_A9_PWRDOM_STAT 0xfff3cf20
Mark Langsdorf1a707a22015-06-05 00:58:43 +010026#define HB_SREG_A15_PWR_CTRL 0xfff3c200
Rob Herringfd7ec6e2013-06-12 22:24:52 -050027
Rob Herringf9904ce2012-02-01 16:57:55 +000028#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
Rob Herringfd7ec6e2013-06-12 22:24:52 -050033#define PWRDOM_STAT_SATA 0x80000000
34#define PWRDOM_STAT_PCI 0x40000000
35#define PWRDOM_STAT_EMMC 0x20000000
36
Rob Herring37057562015-06-05 00:58:42 +010037#define HB_SCU_A9_PWR_NORMAL 0
38#define HB_SCU_A9_PWR_DORMANT 2
39#define HB_SCU_A9_PWR_OFF 3
40
Rob Herring73089ad2011-10-24 08:50:20 +000041DECLARE_GLOBAL_DATA_PTR;
42
Mark Langsdorff913ff52015-06-05 00:58:49 +010043void cphy_disable_overrides(void);
44
Rob Herring73089ad2011-10-24 08:50:20 +000045/*
46 * Miscellaneous platform dependent initialisations
47 */
48int board_init(void)
49{
50 icache_enable();
51
52 return 0;
53}
54
Ian Campbell5af74b62014-03-07 01:20:57 +000055#ifdef CONFIG_SCSI_AHCI_PLAT
56void scsi_init(void)
Rob Herring73089ad2011-10-24 08:50:20 +000057{
Rob Herringfd7ec6e2013-06-12 22:24:52 -050058 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
Rob Herring06d00742012-02-01 16:57:57 +000059
Mark Langsdorff913ff52015-06-05 00:58:49 +010060 cphy_disable_overrides();
Rob Herringfd7ec6e2013-06-12 22:24:52 -050061 if (reg & PWRDOM_STAT_SATA) {
Scott Wood16519a32015-04-17 09:19:01 -050062 ahci_init((void __iomem *)HB_AHCI_BASE);
Simon Glass48228732017-06-14 21:28:41 -060063 scsi_scan(true);
Rob Herringfd7ec6e2013-06-12 22:24:52 -050064 }
Ian Campbell5af74b62014-03-07 01:20:57 +000065}
66#endif
67
68#ifdef CONFIG_MISC_INIT_R
69int misc_init_r(void)
70{
71 char envbuffer[16];
72 u32 boot_choice;
Rob Herring06d00742012-02-01 16:57:57 +000073
74 boot_choice = readl(HB_SREG_A9_BOOT_SRC_STAT) & 0xff;
75 sprintf(envbuffer, "bootcmd%d", boot_choice);
Simon Glass64b723f2017-08-03 12:22:12 -060076 if (env_get(envbuffer)) {
Rob Herring06d00742012-02-01 16:57:57 +000077 sprintf(envbuffer, "run bootcmd%d", boot_choice);
Simon Glass6a38e412017-08-03 12:22:09 -060078 env_set("bootcmd", envbuffer);
Rob Herring06d00742012-02-01 16:57:57 +000079 } else
Simon Glass6a38e412017-08-03 12:22:09 -060080 env_set("bootcmd", "");
Rob Herring06d00742012-02-01 16:57:57 +000081
Rob Herring73089ad2011-10-24 08:50:20 +000082 return 0;
83}
Rob Herring13b17c32013-06-12 22:24:53 -050084#endif
Rob Herring73089ad2011-10-24 08:50:20 +000085
86int dram_init(void)
87{
Andre Przywara126d9a62021-04-12 01:04:54 +010088 return fdtdec_setup_mem_size_base();
89}
90
91int dram_init_banksize(void)
92{
93 return fdtdec_setup_memory_banksize();
Rob Herring73089ad2011-10-24 08:50:20 +000094}
95
Rob Herringfd7ec6e2013-06-12 22:24:52 -050096#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090097int ft_board_setup(void *fdt, struct bd_info *bd)
Rob Herringfd7ec6e2013-06-12 22:24:52 -050098{
99 static const char disabled[] = "disabled";
100 u32 reg = readl(HB_SREG_A9_PWRDOM_STAT);
101
102 if (!(reg & PWRDOM_STAT_SATA))
103 do_fixup_by_compat(fdt, "calxeda,hb-ahci", "status",
104 disabled, sizeof(disabled), 1);
105
106 if (!(reg & PWRDOM_STAT_EMMC))
107 do_fixup_by_compat(fdt, "calxeda,hb-sdhci", "status",
108 disabled, sizeof(disabled), 1);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600109
110 return 0;
Rob Herringfd7ec6e2013-06-12 22:24:52 -0500111}
112#endif
113
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300114void *board_fdt_blob_setup(int *err)
Andre Przywara8d1069f2021-04-12 01:04:51 +0100115{
Ilias Apalodimasab5348a2021-10-26 09:12:33 +0300116 *err = 0;
Andre Przywara8d1069f2021-04-12 01:04:51 +0100117 /*
118 * The ECME management processor loads the DTB from NOR flash
119 * into DRAM (at 4KB), where it gets patched to contain the
120 * detected memory size.
121 */
122 return (void *)0x1000;
123}
124
Mark Langsdorf1a707a22015-06-05 00:58:43 +0100125static int is_highbank(void)
126{
127 uint32_t midr;
128
129 asm volatile ("mrc p15, 0, %0, c0, c0, 0\n" : "=r"(midr));
130
131 return (midr & 0xfff0) == 0xc090;
132}
133
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100134void reset_cpu(void)
Rob Herring73089ad2011-10-24 08:50:20 +0000135{
Rob Herringf9904ce2012-02-01 16:57:55 +0000136 writel(HB_PWR_HARD_RESET, HB_SREG_A9_PWR_REQ);
Mark Langsdorf1a707a22015-06-05 00:58:43 +0100137 if (is_highbank())
138 writeb(HB_SCU_A9_PWR_OFF, HB_SCU_A9_PWR_STATUS);
139 else
140 writel(0x1, HB_SREG_A15_PWR_CTRL);
Rob Herring35139602012-12-02 17:06:22 +0000141
142 wfi();
Rob Herring73089ad2011-10-24 08:50:20 +0000143}
Mark Langsdorff913ff52015-06-05 00:58:49 +0100144
145/*
146 * turn off the override before transferring control to Linux, since Linux
147 * may not support spread spectrum.
148 */
149void arch_preboot_os(void)
150{
151 cphy_disable_overrides();
152}