Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 1 | /* |
| 2 | * U-boot - stamp.c STAMP board specific routines |
| 3 | * |
| 4 | * Copyright (c) 2005 blackfin.uclinux.org |
| 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 |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <asm/mem_init.h> |
| 30 | #include "stamp.h" |
| 31 | |
| 32 | #define STATUS_LED_OFF 0 |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 33 | #define STATUS_LED_ON 1 |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 34 | |
| 35 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 36 | # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) |
| 37 | #else |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 38 | # define SHOW_BOOT_PROGRESS(arg) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 39 | #endif |
| 40 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 41 | int checkboard (void) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 42 | { |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 43 | printf ("CPU: ADSP BF533 Rev.: 0.%d\n", *pCHIPID >> 28); |
| 44 | printf ("Board: ADI BF533 Stamp board\n"); |
| 45 | printf (" Support: http://blackfin.uclinux.org/\n"); |
| 46 | printf (" Richard Klingler <richard@uclinux.net>\n"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 47 | return 0; |
| 48 | } |
| 49 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 50 | long int initdram (int board_type) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 51 | { |
| 52 | DECLARE_GLOBAL_DATA_PTR; |
| 53 | #ifdef DEBUG |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 54 | printf ("SDRAM attributes:\n"); |
| 55 | printf (" tRCD:%d Cycles; tRP:%d Cycles; tRAS:%d Cycles; tWR:%d Cycles; " |
| 56 | "CAS Latency:%d cycles\n", |
| 57 | (SDRAM_tRCD >> 15), |
| 58 | (SDRAM_tRP >> 11), |
| 59 | (SDRAM_tRAS >> 6), |
| 60 | (SDRAM_tWR >> 19), |
| 61 | (SDRAM_CL >> 2)); |
| 62 | printf ("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE); |
| 63 | printf ("Bank size = %d MB\n", 128); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 64 | #endif |
| 65 | gd->bd->bi_memstart = CFG_SDRAM_BASE; |
| 66 | gd->bd->bi_memsize = CFG_MAX_RAM_SIZE; |
| 67 | return (gd->bd->bi_memsize); |
| 68 | } |
| 69 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 70 | void swap_to (int device_id) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 71 | { |
| 72 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 73 | if (device_id == ETHERNET) { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 74 | *pFIO_DIR = PF0; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 75 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 76 | *pFIO_FLAG_S = PF0; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 77 | asm ("ssync;"); |
| 78 | } else if (device_id == FLASH) { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 79 | *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 80 | *pFIO_FLAG_S = (PF4 | PF3 | PF2); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 81 | *pFIO_MASKA_D = (PF8 | PF6 | PF5); |
| 82 | *pFIO_MASKB_D = (PF7); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 83 | *pFIO_POLAR = (PF8 | PF6 | PF5); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 84 | *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5); |
| 85 | *pFIO_INEN = (PF8 | PF7 | PF6 | PF5); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 86 | *pFIO_FLAG_D = (PF4 | PF3 | PF2); |
| 87 | asm ("ssync;"); |
| 88 | } else { |
| 89 | printf ("Unknown bank to switch\n"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 90 | } |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 91 | |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 92 | return; |
| 93 | } |
| 94 | |
| 95 | #if defined(CONFIG_MISC_INIT_R) |
| 96 | /* miscellaneous platform dependent initialisations */ |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 97 | int misc_init_r (void) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 98 | { |
| 99 | int i; |
| 100 | int cf_stat = 0; |
| 101 | |
| 102 | /* Check whether CF card is inserted */ |
| 103 | *pFIO_EDGE = FIO_EDGE_CF_BITS; |
| 104 | *pFIO_POLAR = FIO_POLAR_CF_BITS; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 105 | for (i = 0; i < 0x300; i++) |
| 106 | asm ("nop;"); |
| 107 | |
| 108 | if ((*pFIO_FLAG_S) & CF_STAT_BITS) { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 109 | cf_stat = 0; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 110 | } else { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 111 | cf_stat = 1; |
| 112 | } |
| 113 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 114 | *pFIO_EDGE = FIO_EDGE_BITS; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 115 | *pFIO_POLAR = FIO_POLAR_BITS; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 116 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 117 | |
| 118 | if (cf_stat) { |
| 119 | printf ("Booting from COMPACT flash\n"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 120 | |
| 121 | /* Set cycle time for CF */ |
| 122 | *(volatile unsigned long *) ambctl1 = CF_AMBCTL1VAL; |
| 123 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 124 | for (i = 0; i < 0x1000; i++) |
| 125 | asm ("nop;"); |
| 126 | for (i = 0; i < 0x1000; i++) |
| 127 | asm ("nop;"); |
| 128 | for (i = 0; i < 0x1000; i++) |
| 129 | asm ("nop;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 130 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 131 | serial_setbrg (); |
| 132 | ide_init (); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 133 | |
| 134 | setenv ("bootargs", ""); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 135 | setenv ("bootcmd", |
| 136 | "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000"); |
| 137 | } else { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 138 | printf ("Booting from FLASH\n"); |
| 139 | } |
| 140 | |
| 141 | return 1; |
| 142 | } |
| 143 | #endif |
| 144 | |
| 145 | #ifdef CONFIG_STAMP_CF |
| 146 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 147 | void cf_outb (unsigned char val, volatile unsigned char *addr) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 148 | { |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 149 | /* |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 150 | * Set PF1 PF0 respectively to 0 1 to divert address |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 151 | * to the expansion memory banks |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 152 | */ |
| 153 | *pFIO_FLAG_S = CF_PF0; |
| 154 | *pFIO_FLAG_C = CF_PF1; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 155 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 156 | |
| 157 | *(addr) = val; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 158 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 159 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 160 | /* Setback PF1 PF0 to 0 0 to address external |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 161 | * memory banks */ |
| 162 | *(volatile unsigned short *) pFIO_FLAG_C = CF_PF1_PF0; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 163 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 166 | unsigned char cf_inb (volatile unsigned char *addr) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 167 | { |
| 168 | volatile unsigned char c; |
| 169 | |
| 170 | *pFIO_FLAG_S = CF_PF0; |
| 171 | *pFIO_FLAG_C = CF_PF1; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 172 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 173 | |
| 174 | c = *(addr); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 175 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 176 | |
| 177 | *pFIO_FLAG_C = CF_PF1_PF0; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 178 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 179 | |
| 180 | return c; |
| 181 | } |
| 182 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 183 | void cf_insw (unsigned short *sect_buf, unsigned short *addr, int words) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 184 | { |
| 185 | int i; |
| 186 | |
| 187 | *pFIO_FLAG_S = CF_PF0; |
| 188 | *pFIO_FLAG_C = CF_PF1; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 189 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 190 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 191 | for (i = 0; i < words; i++) { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 192 | *(sect_buf + i) = *(addr); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 193 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | *pFIO_FLAG_C = CF_PF1_PF0; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 197 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 200 | void cf_outsw (unsigned short *addr, unsigned short *sect_buf, int words) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 201 | { |
| 202 | int i; |
| 203 | |
| 204 | *pFIO_FLAG_S = CF_PF0; |
| 205 | *pFIO_FLAG_C = CF_PF1; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 206 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 207 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 208 | for (i = 0; i < words; i++) { |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 209 | *(addr) = *(sect_buf + i); |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 210 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | *pFIO_FLAG_C = CF_PF1_PF0; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 214 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 215 | } |
| 216 | #endif |
| 217 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 218 | void stamp_led_set (int LED1, int LED2, int LED3) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 219 | { |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 220 | *pFIO_INEN &= ~(PF2 | PF3 | PF4); |
| 221 | *pFIO_DIR |= (PF2 | PF3 | PF4); |
| 222 | |
| 223 | if (LED1 == STATUS_LED_OFF) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 224 | *pFIO_FLAG_S = PF2; |
| 225 | else |
| 226 | *pFIO_FLAG_C = PF2; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 227 | if (LED2 == STATUS_LED_OFF) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 228 | *pFIO_FLAG_S = PF3; |
| 229 | else |
| 230 | *pFIO_FLAG_C = PF3; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 231 | if (LED3 == STATUS_LED_OFF) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 232 | *pFIO_FLAG_S = PF4; |
| 233 | else |
| 234 | *pFIO_FLAG_C = PF4; |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 235 | asm ("ssync;"); |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 238 | void show_boot_progress (int status) |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 239 | { |
Wolfgang Denk | 8e7b703 | 2006-03-12 02:55:22 +0100 | [diff] [blame] | 240 | switch (status) { |
| 241 | case 1: |
| 242 | stamp_led_set (STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON); |
| 243 | break; |
| 244 | case 2: |
| 245 | stamp_led_set (STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF); |
| 246 | break; |
| 247 | case 3: |
| 248 | stamp_led_set (STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON); |
| 249 | break; |
| 250 | case 4: |
| 251 | stamp_led_set (STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF); |
| 252 | break; |
| 253 | case 5: |
| 254 | case 6: |
| 255 | stamp_led_set (STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON); |
| 256 | break; |
| 257 | case 7: |
| 258 | case 8: |
| 259 | stamp_led_set (STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF); |
| 260 | break; |
| 261 | case 9: |
| 262 | case 10: |
| 263 | case 11: |
| 264 | case 12: |
| 265 | case 13: |
| 266 | case 14: |
| 267 | case 15: |
| 268 | stamp_led_set (STATUS_LED_OFF, STATUS_LED_OFF, |
| 269 | STATUS_LED_OFF); |
| 270 | break; |
| 271 | default: |
| 272 | stamp_led_set (STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON); |
| 273 | break; |
Wolfgang Denk | 6cb142f | 2006-03-12 02:12:27 +0100 | [diff] [blame] | 274 | } |
| 275 | } |