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