blob: b31ede5eb948d71abaffbfe19268db66fdcca2c4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roesec6bc1db2012-01-03 16:49:01 +01002/*
3 * (C) Copyright 2000-2009
4 * Viresh Kumar, ST Microelectronics, viresh.kumar@st.com
5 * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com
Stefan Roesec6bc1db2012-01-03 16:49:01 +01006 */
7
8#include <common.h>
9#include <asm/hardware.h>
10#include <asm/io.h>
11#include <asm/arch/spr_misc.h>
12#include <asm/arch/spr_defs.h>
13
Stefan Roese7618ad02015-08-18 09:27:17 +020014void spear_late_init(void)
15{
16 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
17
18 writel(0x80000007, &misc_p->arb_icm_ml1);
19 writel(0x80000007, &misc_p->arb_icm_ml2);
20 writel(0x80000007, &misc_p->arb_icm_ml3);
21 writel(0x80000007, &misc_p->arb_icm_ml4);
22 writel(0x80000007, &misc_p->arb_icm_ml5);
23 writel(0x80000007, &misc_p->arb_icm_ml6);
24 writel(0x80000007, &misc_p->arb_icm_ml7);
25 writel(0x80000007, &misc_p->arb_icm_ml8);
26 writel(0x80000007, &misc_p->arb_icm_ml9);
27}
28
Stefan Roesec6bc1db2012-01-03 16:49:01 +010029static void sel_1v8(void)
30{
31 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
32 u32 ddr1v8, ddr2v5;
33
34 ddr2v5 = readl(&misc_p->ddr_2v5_compensation);
35 ddr2v5 &= 0x8080ffc0;
36 ddr2v5 |= 0x78000003;
37 writel(ddr2v5, &misc_p->ddr_2v5_compensation);
38
39 ddr1v8 = readl(&misc_p->ddr_1v8_compensation);
40 ddr1v8 &= 0x8080ffc0;
41 ddr1v8 |= 0x78000010;
42 writel(ddr1v8, &misc_p->ddr_1v8_compensation);
43
44 while (!(readl(&misc_p->ddr_1v8_compensation) & DDR_COMP_ACCURATE))
45 ;
46}
47
48static void sel_2v5(void)
49{
50 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
51 u32 ddr1v8, ddr2v5;
52
53 ddr1v8 = readl(&misc_p->ddr_1v8_compensation);
54 ddr1v8 &= 0x8080ffc0;
55 ddr1v8 |= 0x78000003;
56 writel(ddr1v8, &misc_p->ddr_1v8_compensation);
57
58 ddr2v5 = readl(&misc_p->ddr_2v5_compensation);
59 ddr2v5 &= 0x8080ffc0;
60 ddr2v5 |= 0x78000010;
61 writel(ddr2v5, &misc_p->ddr_2v5_compensation);
62
63 while (!(readl(&misc_p->ddr_2v5_compensation) & DDR_COMP_ACCURATE))
64 ;
65}
66
67/*
68 * plat_ddr_init:
69 */
70void plat_ddr_init(void)
71{
72 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
73 u32 ddrpad;
74 u32 core3v3, ddr1v8, ddr2v5;
75
76 /* DDR pad register configurations */
77 ddrpad = readl(&misc_p->ddr_pad);
78 ddrpad &= ~DDR_PAD_CNF_MSK;
79
80#if (CONFIG_DDR_HCLK)
81 ddrpad |= 0xEAAB;
82#elif (CONFIG_DDR_2HCLK)
83 ddrpad |= 0xEAAD;
84#elif (CONFIG_DDR_PLL2)
85 ddrpad |= 0xEAAD;
86#endif
87 writel(ddrpad, &misc_p->ddr_pad);
88
89 /* Compensation register configurations */
90 core3v3 = readl(&misc_p->core_3v3_compensation);
91 core3v3 &= 0x8080ffe0;
92 core3v3 |= 0x78000002;
93 writel(core3v3, &misc_p->core_3v3_compensation);
94
95 ddr1v8 = readl(&misc_p->ddr_1v8_compensation);
96 ddr1v8 &= 0x8080ffc0;
97 ddr1v8 |= 0x78000004;
98 writel(ddr1v8, &misc_p->ddr_1v8_compensation);
99
100 ddr2v5 = readl(&misc_p->ddr_2v5_compensation);
101 ddr2v5 &= 0x8080ffc0;
102 ddr2v5 |= 0x78000004;
103 writel(ddr2v5, &misc_p->ddr_2v5_compensation);
104
105 if ((readl(&misc_p->ddr_pad) & DDR_PAD_SW_CONF) == DDR_PAD_SW_CONF) {
106 /* Software memory configuration */
107 if (readl(&misc_p->ddr_pad) & DDR_PAD_SSTL_SEL)
108 sel_1v8();
109 else
110 sel_2v5();
111 } else {
112 /* Hardware memory configuration */
113 if (readl(&misc_p->ddr_pad) & DDR_PAD_DRAM_TYPE)
114 sel_1v8();
115 else
116 sel_2v5();
117 }
118}
119
120/*
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100121 * xxx_boot_selected:
122 *
York Sun4a598092013-04-01 11:29:11 -0700123 * return true if the particular booting option is selected
124 * return false otherwise
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100125 */
126static u32 read_bootstrap(void)
127{
128 return (readl(CONFIG_SPEAR_BOOTSTRAPCFG) >> CONFIG_SPEAR_BOOTSTRAPSHFT)
129 & CONFIG_SPEAR_BOOTSTRAPMASK;
130}
131
132int snor_boot_selected(void)
133{
134 u32 bootstrap = read_bootstrap();
135
136 if (SNOR_BOOT_SUPPORTED) {
137 /* Check whether SNOR boot is selected */
138 if ((bootstrap & CONFIG_SPEAR_ONLYSNORBOOT) ==
139 CONFIG_SPEAR_ONLYSNORBOOT)
York Sun4a598092013-04-01 11:29:11 -0700140 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100141
142 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
143 CONFIG_SPEAR_NORNAND8BOOT)
York Sun4a598092013-04-01 11:29:11 -0700144 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100145
146 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
147 CONFIG_SPEAR_NORNAND16BOOT)
York Sun4a598092013-04-01 11:29:11 -0700148 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100149 }
150
York Sun4a598092013-04-01 11:29:11 -0700151 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100152}
153
154int nand_boot_selected(void)
155{
156 u32 bootstrap = read_bootstrap();
157
158 if (NAND_BOOT_SUPPORTED) {
159 /* Check whether NAND boot is selected */
160 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
161 CONFIG_SPEAR_NORNAND8BOOT)
York Sun4a598092013-04-01 11:29:11 -0700162 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100163
164 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
165 CONFIG_SPEAR_NORNAND16BOOT)
York Sun4a598092013-04-01 11:29:11 -0700166 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100167 }
168
York Sun4a598092013-04-01 11:29:11 -0700169 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100170}
171
172int pnor_boot_selected(void)
173{
174 /* Parallel NOR boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700175 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100176}
177
178int usb_boot_selected(void)
179{
180 u32 bootstrap = read_bootstrap();
181
182 if (USB_BOOT_SUPPORTED) {
183 /* Check whether USB boot is selected */
184 if (!(bootstrap & CONFIG_SPEAR_USBBOOT))
York Sun4a598092013-04-01 11:29:11 -0700185 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100186 }
187
York Sun4a598092013-04-01 11:29:11 -0700188 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100189}
190
191int tftp_boot_selected(void)
192{
193 /* TFTP boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700194 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100195}
196
197int uart_boot_selected(void)
198{
199 /* UART boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700200 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100201}
202
203int spi_boot_selected(void)
204{
205 /* SPI boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700206 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100207}
208
209int i2c_boot_selected(void)
210{
211 /* I2C boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700212 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100213}
214
215int mmc_boot_selected(void)
216{
York Sun4a598092013-04-01 11:29:11 -0700217 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100218}
219
220void plat_late_init(void)
221{
222 spear_late_init();
223}