Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 1 | /* |
| 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 Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 7 | */ |
| 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 Roese | 7618ad0 | 2015-08-18 09:27:17 +0200 | [diff] [blame^] | 15 | void 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 Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 30 | static 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 | |
| 49 | static 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 | */ |
| 71 | void 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 Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 122 | * xxx_boot_selected: |
| 123 | * |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 124 | * return true if the particular booting option is selected |
| 125 | * return false otherwise |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 126 | */ |
| 127 | static u32 read_bootstrap(void) |
| 128 | { |
| 129 | return (readl(CONFIG_SPEAR_BOOTSTRAPCFG) >> CONFIG_SPEAR_BOOTSTRAPSHFT) |
| 130 | & CONFIG_SPEAR_BOOTSTRAPMASK; |
| 131 | } |
| 132 | |
| 133 | int 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 Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 141 | return true; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 142 | |
| 143 | if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) == |
| 144 | CONFIG_SPEAR_NORNAND8BOOT) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 145 | return true; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 146 | |
| 147 | if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) == |
| 148 | CONFIG_SPEAR_NORNAND16BOOT) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 149 | return true; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 150 | } |
| 151 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 152 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | int 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 Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 163 | return true; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 164 | |
| 165 | if ((bootstrap & CONFIG_SPEAR_NORNANDBOOT) == |
| 166 | CONFIG_SPEAR_NORNAND16BOOT) |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 167 | return true; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 168 | } |
| 169 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 170 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | int pnor_boot_selected(void) |
| 174 | { |
| 175 | /* Parallel NOR boot is not selected in any SPEAr600 revision */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 176 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | int 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 Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 186 | return true; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 187 | } |
| 188 | |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 189 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | int tftp_boot_selected(void) |
| 193 | { |
| 194 | /* TFTP boot is not selected in any SPEAr600 revision */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 195 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | int uart_boot_selected(void) |
| 199 | { |
| 200 | /* UART boot is not selected in any SPEAr600 revision */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 201 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | int spi_boot_selected(void) |
| 205 | { |
| 206 | /* SPI boot is not selected in any SPEAr600 revision */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 207 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | int i2c_boot_selected(void) |
| 211 | { |
| 212 | /* I2C boot is not selected in any SPEAr600 revision */ |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 213 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | int mmc_boot_selected(void) |
| 217 | { |
York Sun | 4a59809 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 218 | return false; |
Stefan Roese | c6bc1db | 2012-01-03 16:49:01 +0100 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void plat_late_init(void) |
| 222 | { |
| 223 | spear_late_init(); |
| 224 | } |