Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - stamp.c STAMP board specific routines |
| 3 | * |
Aubrey Li | 155fd76 | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 4 | * Copyright (c) 2005-2007 Analog Devices Inc. |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 5 | * |
| 6 | * (C) Copyright 2000-2004 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
Aubrey Li | 155fd76 | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 24 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 25 | * MA 02110-1301 USA |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <asm/mem_init.h> |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 30 | #include <asm/io.h> |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 31 | #include "bf533-stamp.h" |
| 32 | |
Wolfgang Denk | 1218abf | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 35 | #define STATUS_LED_OFF 0 |
| 36 | #define STATUS_LED_ON 1 |
| 37 | |
| 38 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 39 | # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) |
| 40 | #else |
| 41 | # define SHOW_BOOT_PROGRESS(arg) |
| 42 | #endif |
| 43 | |
| 44 | int checkboard(void) |
| 45 | { |
| 46 | #if (BFIN_CPU == ADSP_BF531) |
| 47 | printf("CPU: ADSP BF531 Rev.: 0.%d\n", *pCHIPID >> 28); |
| 48 | #elif (BFIN_CPU == ADSP_BF532) |
| 49 | printf("CPU: ADSP BF532 Rev.: 0.%d\n", *pCHIPID >> 28); |
| 50 | #else |
| 51 | printf("CPU: ADSP BF533 Rev.: 0.%d\n", *pCHIPID >> 28); |
| 52 | #endif |
| 53 | printf("Board: ADI BF533 Stamp board\n"); |
| 54 | printf(" Support: http://blackfin.uclinux.org/\n"); |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | long int initdram(int board_type) |
| 59 | { |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 60 | #ifdef DEBUG |
| 61 | printf("SDRAM attributes:\n"); |
| 62 | printf |
| 63 | (" tRCD:%d Cycles; tRP:%d Cycles; tRAS:%d Cycles; tWR:%d Cycles; " |
| 64 | "CAS Latency:%d cycles\n", (SDRAM_tRCD >> 15), (SDRAM_tRP >> 11), |
| 65 | (SDRAM_tRAS >> 6), (SDRAM_tWR >> 19), (SDRAM_CL >> 2)); |
| 66 | printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE); |
| 67 | printf("Bank size = %d MB\n", 128); |
| 68 | #endif |
| 69 | gd->bd->bi_memstart = CFG_SDRAM_BASE; |
| 70 | gd->bd->bi_memsize = CFG_MAX_RAM_SIZE; |
| 71 | return (gd->bd->bi_memsize); |
| 72 | } |
| 73 | |
| 74 | void swap_to(int device_id) |
| 75 | { |
| 76 | |
| 77 | if (device_id == ETHERNET) { |
| 78 | *pFIO_DIR = PF0; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 79 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 80 | *pFIO_FLAG_S = PF0; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 81 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 82 | } else if (device_id == FLASH) { |
| 83 | *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0); |
| 84 | *pFIO_FLAG_S = (PF4 | PF3 | PF2); |
| 85 | *pFIO_MASKA_D = (PF8 | PF6 | PF5); |
| 86 | *pFIO_MASKB_D = (PF7); |
| 87 | *pFIO_POLAR = (PF8 | PF6 | PF5); |
| 88 | *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5); |
| 89 | *pFIO_INEN = (PF8 | PF7 | PF6 | PF5); |
| 90 | *pFIO_FLAG_D = (PF4 | PF3 | PF2); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 91 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 92 | } else { |
| 93 | printf("Unknown bank to switch\n"); |
| 94 | } |
| 95 | |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | #if defined(CONFIG_MISC_INIT_R) |
| 100 | /* miscellaneous platform dependent initialisations */ |
| 101 | int misc_init_r(void) |
| 102 | { |
| 103 | int i; |
| 104 | int cf_stat = 0; |
| 105 | |
| 106 | /* Check whether CF card is inserted */ |
| 107 | *pFIO_EDGE = FIO_EDGE_CF_BITS; |
| 108 | *pFIO_POLAR = FIO_POLAR_CF_BITS; |
| 109 | for (i = 0; i < 0x300; i++) |
| 110 | asm("nop;"); |
| 111 | |
| 112 | if ((*pFIO_FLAG_S) & CF_STAT_BITS) { |
| 113 | cf_stat = 0; |
| 114 | } else { |
| 115 | cf_stat = 1; |
| 116 | } |
| 117 | |
| 118 | *pFIO_EDGE = FIO_EDGE_BITS; |
| 119 | *pFIO_POLAR = FIO_POLAR_BITS; |
| 120 | |
| 121 | if (cf_stat) { |
| 122 | printf("Booting from COMPACT flash\n"); |
| 123 | |
| 124 | /* Set cycle time for CF */ |
| 125 | *(volatile unsigned long *)ambctl1 = CF_AMBCTL1VAL; |
| 126 | |
| 127 | for (i = 0; i < 0x1000; i++) |
| 128 | asm("nop;"); |
| 129 | for (i = 0; i < 0x1000; i++) |
| 130 | asm("nop;"); |
| 131 | for (i = 0; i < 0x1000; i++) |
| 132 | asm("nop;"); |
| 133 | |
| 134 | serial_setbrg(); |
| 135 | ide_init(); |
| 136 | |
| 137 | setenv("bootargs", ""); |
| 138 | setenv("bootcmd", |
| 139 | "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000"); |
| 140 | } else { |
| 141 | printf("Booting from FLASH\n"); |
| 142 | } |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | #endif |
| 147 | |
| 148 | #ifdef CONFIG_STAMP_CF |
| 149 | |
| 150 | void cf_outb(unsigned char val, volatile unsigned char *addr) |
| 151 | { |
| 152 | /* |
| 153 | * Set PF1 PF0 respectively to 0 1 to divert address |
| 154 | * to the expansion memory banks |
| 155 | */ |
| 156 | *pFIO_FLAG_S = CF_PF0; |
| 157 | *pFIO_FLAG_C = CF_PF1; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 158 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 159 | |
| 160 | *(addr) = val; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 161 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 162 | |
| 163 | /* Setback PF1 PF0 to 0 0 to address external |
| 164 | * memory banks */ |
| 165 | *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 166 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | unsigned char cf_inb(volatile unsigned char *addr) |
| 170 | { |
| 171 | volatile unsigned char c; |
| 172 | |
| 173 | *pFIO_FLAG_S = CF_PF0; |
| 174 | *pFIO_FLAG_C = CF_PF1; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 175 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 176 | |
| 177 | c = *(addr); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 178 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 179 | |
| 180 | *pFIO_FLAG_C = CF_PF1_PF0; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 181 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 182 | |
| 183 | return c; |
| 184 | } |
| 185 | |
| 186 | void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words) |
| 187 | { |
| 188 | int i; |
| 189 | |
| 190 | *pFIO_FLAG_S = CF_PF0; |
| 191 | *pFIO_FLAG_C = CF_PF1; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 192 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 193 | |
| 194 | for (i = 0; i < words; i++) { |
| 195 | *(sect_buf + i) = *(addr); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 196 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | *pFIO_FLAG_C = CF_PF1_PF0; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 200 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words) |
| 204 | { |
| 205 | int i; |
| 206 | |
| 207 | *pFIO_FLAG_S = CF_PF0; |
| 208 | *pFIO_FLAG_C = CF_PF1; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 209 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 210 | |
| 211 | for (i = 0; i < words; i++) { |
| 212 | *(addr) = *(sect_buf + i); |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 213 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | *pFIO_FLAG_C = CF_PF1_PF0; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 217 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 218 | } |
| 219 | #endif |
| 220 | |
| 221 | void stamp_led_set(int LED1, int LED2, int LED3) |
| 222 | { |
| 223 | *pFIO_INEN &= ~(PF2 | PF3 | PF4); |
| 224 | *pFIO_DIR |= (PF2 | PF3 | PF4); |
| 225 | |
| 226 | if (LED1 == STATUS_LED_OFF) |
| 227 | *pFIO_FLAG_S = PF2; |
| 228 | else |
| 229 | *pFIO_FLAG_C = PF2; |
| 230 | if (LED2 == STATUS_LED_OFF) |
| 231 | *pFIO_FLAG_S = PF3; |
| 232 | else |
| 233 | *pFIO_FLAG_C = PF3; |
| 234 | if (LED3 == STATUS_LED_OFF) |
| 235 | *pFIO_FLAG_S = PF4; |
| 236 | else |
| 237 | *pFIO_FLAG_C = PF4; |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 238 | sync(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | void show_boot_progress(int status) |
| 242 | { |
| 243 | switch (status) { |
| 244 | case 1: |
| 245 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON); |
| 246 | break; |
| 247 | case 2: |
| 248 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF); |
| 249 | break; |
| 250 | case 3: |
| 251 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON); |
| 252 | break; |
| 253 | case 4: |
| 254 | stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF); |
| 255 | break; |
| 256 | case 5: |
| 257 | case 6: |
| 258 | stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON); |
| 259 | break; |
| 260 | case 7: |
| 261 | case 8: |
| 262 | stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF); |
| 263 | break; |
| 264 | case 9: |
| 265 | case 10: |
| 266 | case 11: |
| 267 | case 12: |
| 268 | case 13: |
| 269 | case 14: |
| 270 | case 15: |
| 271 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF); |
| 272 | break; |
| 273 | default: |
| 274 | stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON); |
| 275 | break; |
| 276 | } |
| 277 | } |