blob: 1fdf715da45ba8eafd864b9d4e6033b1cf8c4967 [file] [log] [blame]
Stefan Roesec6bc1db2012-01-03 16:49:01 +01001/*
2 * (C) Copyright 2000-2009
3 * Viresh Kumar, ST Microelectronics, viresh.kumar@st.com
4 * Vipin Kumar, ST Microelectronics, vipin.kumar@st.com
5 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02006 * SPDX-License-Identifier: GPL-2.0+
Stefan Roesec6bc1db2012-01-03 16:49:01 +01007 */
8
9#include <common.h>
10#include <asm/hardware.h>
11#include <asm/io.h>
12#include <asm/arch/spr_misc.h>
13#include <asm/arch/spr_defs.h>
14
Stefan Roese7618ad02015-08-18 09:27:17 +020015void spear_late_init(void)
16{
17 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
18
19 writel(0x80000007, &misc_p->arb_icm_ml1);
20 writel(0x80000007, &misc_p->arb_icm_ml2);
21 writel(0x80000007, &misc_p->arb_icm_ml3);
22 writel(0x80000007, &misc_p->arb_icm_ml4);
23 writel(0x80000007, &misc_p->arb_icm_ml5);
24 writel(0x80000007, &misc_p->arb_icm_ml6);
25 writel(0x80000007, &misc_p->arb_icm_ml7);
26 writel(0x80000007, &misc_p->arb_icm_ml8);
27 writel(0x80000007, &misc_p->arb_icm_ml9);
28}
29
Stefan Roesec6bc1db2012-01-03 16:49:01 +010030static void sel_1v8(void)
31{
32 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
33 u32 ddr1v8, ddr2v5;
34
35 ddr2v5 = readl(&misc_p->ddr_2v5_compensation);
36 ddr2v5 &= 0x8080ffc0;
37 ddr2v5 |= 0x78000003;
38 writel(ddr2v5, &misc_p->ddr_2v5_compensation);
39
40 ddr1v8 = readl(&misc_p->ddr_1v8_compensation);
41 ddr1v8 &= 0x8080ffc0;
42 ddr1v8 |= 0x78000010;
43 writel(ddr1v8, &misc_p->ddr_1v8_compensation);
44
45 while (!(readl(&misc_p->ddr_1v8_compensation) & DDR_COMP_ACCURATE))
46 ;
47}
48
49static void sel_2v5(void)
50{
51 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
52 u32 ddr1v8, ddr2v5;
53
54 ddr1v8 = readl(&misc_p->ddr_1v8_compensation);
55 ddr1v8 &= 0x8080ffc0;
56 ddr1v8 |= 0x78000003;
57 writel(ddr1v8, &misc_p->ddr_1v8_compensation);
58
59 ddr2v5 = readl(&misc_p->ddr_2v5_compensation);
60 ddr2v5 &= 0x8080ffc0;
61 ddr2v5 |= 0x78000010;
62 writel(ddr2v5, &misc_p->ddr_2v5_compensation);
63
64 while (!(readl(&misc_p->ddr_2v5_compensation) & DDR_COMP_ACCURATE))
65 ;
66}
67
68/*
69 * plat_ddr_init:
70 */
71void plat_ddr_init(void)
72{
73 struct misc_regs *misc_p = (struct misc_regs *)CONFIG_SPEAR_MISCBASE;
74 u32 ddrpad;
75 u32 core3v3, ddr1v8, ddr2v5;
76
77 /* DDR pad register configurations */
78 ddrpad = readl(&misc_p->ddr_pad);
79 ddrpad &= ~DDR_PAD_CNF_MSK;
80
81#if (CONFIG_DDR_HCLK)
82 ddrpad |= 0xEAAB;
83#elif (CONFIG_DDR_2HCLK)
84 ddrpad |= 0xEAAD;
85#elif (CONFIG_DDR_PLL2)
86 ddrpad |= 0xEAAD;
87#endif
88 writel(ddrpad, &misc_p->ddr_pad);
89
90 /* Compensation register configurations */
91 core3v3 = readl(&misc_p->core_3v3_compensation);
92 core3v3 &= 0x8080ffe0;
93 core3v3 |= 0x78000002;
94 writel(core3v3, &misc_p->core_3v3_compensation);
95
96 ddr1v8 = readl(&misc_p->ddr_1v8_compensation);
97 ddr1v8 &= 0x8080ffc0;
98 ddr1v8 |= 0x78000004;
99 writel(ddr1v8, &misc_p->ddr_1v8_compensation);
100
101 ddr2v5 = readl(&misc_p->ddr_2v5_compensation);
102 ddr2v5 &= 0x8080ffc0;
103 ddr2v5 |= 0x78000004;
104 writel(ddr2v5, &misc_p->ddr_2v5_compensation);
105
106 if ((readl(&misc_p->ddr_pad) & DDR_PAD_SW_CONF) == DDR_PAD_SW_CONF) {
107 /* Software memory configuration */
108 if (readl(&misc_p->ddr_pad) & DDR_PAD_SSTL_SEL)
109 sel_1v8();
110 else
111 sel_2v5();
112 } else {
113 /* Hardware memory configuration */
114 if (readl(&misc_p->ddr_pad) & DDR_PAD_DRAM_TYPE)
115 sel_1v8();
116 else
117 sel_2v5();
118 }
119}
120
121/*
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100122 * xxx_boot_selected:
123 *
York Sun4a598092013-04-01 11:29:11 -0700124 * return true if the particular booting option is selected
125 * return false otherwise
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100126 */
127static u32 read_bootstrap(void)
128{
129 return (readl(CONFIG_SPEAR_BOOTSTRAPCFG) >> CONFIG_SPEAR_BOOTSTRAPSHFT)
130 & CONFIG_SPEAR_BOOTSTRAPMASK;
131}
132
133int snor_boot_selected(void)
134{
135 u32 bootstrap = read_bootstrap();
136
137 if (SNOR_BOOT_SUPPORTED) {
138 /* Check whether SNOR boot is selected */
139 if ((bootstrap & CONFIG_SPEAR_ONLYSNORBOOT) ==
140 CONFIG_SPEAR_ONLYSNORBOOT)
York Sun4a598092013-04-01 11:29:11 -0700141 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100142
143 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
144 CONFIG_SPEAR_NORNAND8BOOT)
York Sun4a598092013-04-01 11:29:11 -0700145 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100146
147 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
148 CONFIG_SPEAR_NORNAND16BOOT)
York Sun4a598092013-04-01 11:29:11 -0700149 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100150 }
151
York Sun4a598092013-04-01 11:29:11 -0700152 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100153}
154
155int nand_boot_selected(void)
156{
157 u32 bootstrap = read_bootstrap();
158
159 if (NAND_BOOT_SUPPORTED) {
160 /* Check whether NAND boot is selected */
161 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
162 CONFIG_SPEAR_NORNAND8BOOT)
York Sun4a598092013-04-01 11:29:11 -0700163 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100164
165 if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) ==
166 CONFIG_SPEAR_NORNAND16BOOT)
York Sun4a598092013-04-01 11:29:11 -0700167 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100168 }
169
York Sun4a598092013-04-01 11:29:11 -0700170 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100171}
172
173int pnor_boot_selected(void)
174{
175 /* Parallel NOR boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700176 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100177}
178
179int usb_boot_selected(void)
180{
181 u32 bootstrap = read_bootstrap();
182
183 if (USB_BOOT_SUPPORTED) {
184 /* Check whether USB boot is selected */
185 if (!(bootstrap & CONFIG_SPEAR_USBBOOT))
York Sun4a598092013-04-01 11:29:11 -0700186 return true;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100187 }
188
York Sun4a598092013-04-01 11:29:11 -0700189 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100190}
191
192int tftp_boot_selected(void)
193{
194 /* TFTP boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700195 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100196}
197
198int uart_boot_selected(void)
199{
200 /* UART boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700201 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100202}
203
204int spi_boot_selected(void)
205{
206 /* SPI boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700207 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100208}
209
210int i2c_boot_selected(void)
211{
212 /* I2C boot is not selected in any SPEAr600 revision */
York Sun4a598092013-04-01 11:29:11 -0700213 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100214}
215
216int mmc_boot_selected(void)
217{
York Sun4a598092013-04-01 11:29:11 -0700218 return false;
Stefan Roesec6bc1db2012-01-03 16:49:01 +0100219}
220
221void plat_late_init(void)
222{
223 spear_late_init();
224}