Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 1 | /* |
Mike Frysinger | 23fd959 | 2008-10-11 22:40:22 -0400 | [diff] [blame] | 2 | * U-boot - main board file |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 3 | * |
Mike Frysinger | 23fd959 | 2008-10-11 22:40:22 -0400 | [diff] [blame] | 4 | * Copyright (c) 2005-2008 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> |
Aubrey Li | 8440bb1 | 2007-03-12 00:25:14 +0800 | [diff] [blame] | 29 | #include <asm/io.h> |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 30 | #include "bf533-stamp.h" |
| 31 | |
Wolfgang Denk | 1218abf | 2007-09-15 20:48:41 +0200 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 34 | int checkboard(void) |
| 35 | { |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 36 | printf("Board: ADI BF533 Stamp board\n"); |
| 37 | printf(" Support: http://blackfin.uclinux.org/\n"); |
| 38 | return 0; |
| 39 | } |
| 40 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 41 | phys_size_t initdram(int board_type) |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 42 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 43 | gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE; |
| 44 | gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE; |
Mike Frysinger | 41f3325 | 2008-10-11 20:31:17 -0400 | [diff] [blame] | 45 | return gd->bd->bi_memsize; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 46 | } |
| 47 | |
Mike Frysinger | 1f75d6f | 2008-10-11 22:38:37 -0400 | [diff] [blame] | 48 | /* PF0 and PF1 are used to switch between the ethernet and flash: |
| 49 | * PF0 PF1 |
| 50 | * flash: 0 0 |
| 51 | * ether: 1 0 |
| 52 | */ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 53 | void swap_to(int device_id) |
| 54 | { |
Mike Frysinger | 1f75d6f | 2008-10-11 22:38:37 -0400 | [diff] [blame] | 55 | bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF1 | PF0); |
| 56 | SSYNC(); |
| 57 | bfin_write_FIO_FLAG_C(PF1); |
| 58 | if (device_id == ETHERNET) |
| 59 | bfin_write_FIO_FLAG_S(PF0); |
| 60 | else if (device_id == FLASH) |
| 61 | bfin_write_FIO_FLAG_C(PF0); |
| 62 | else |
| 63 | printf("Unknown device to switch\n"); |
| 64 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | #if defined(CONFIG_MISC_INIT_R) |
| 68 | /* miscellaneous platform dependent initialisations */ |
| 69 | int misc_init_r(void) |
| 70 | { |
| 71 | int i; |
| 72 | int cf_stat = 0; |
| 73 | |
| 74 | /* Check whether CF card is inserted */ |
| 75 | *pFIO_EDGE = FIO_EDGE_CF_BITS; |
| 76 | *pFIO_POLAR = FIO_POLAR_CF_BITS; |
| 77 | for (i = 0; i < 0x300; i++) |
| 78 | asm("nop;"); |
| 79 | |
| 80 | if ((*pFIO_FLAG_S) & CF_STAT_BITS) { |
| 81 | cf_stat = 0; |
| 82 | } else { |
| 83 | cf_stat = 1; |
| 84 | } |
| 85 | |
| 86 | *pFIO_EDGE = FIO_EDGE_BITS; |
| 87 | *pFIO_POLAR = FIO_POLAR_BITS; |
| 88 | |
| 89 | if (cf_stat) { |
| 90 | printf("Booting from COMPACT flash\n"); |
| 91 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 92 | for (i = 0; i < 0x1000; i++) |
| 93 | asm("nop;"); |
| 94 | for (i = 0; i < 0x1000; i++) |
| 95 | asm("nop;"); |
| 96 | for (i = 0; i < 0x1000; i++) |
| 97 | asm("nop;"); |
| 98 | |
| 99 | serial_setbrg(); |
| 100 | ide_init(); |
| 101 | |
| 102 | setenv("bootargs", ""); |
| 103 | setenv("bootcmd", |
| 104 | "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000"); |
| 105 | } else { |
| 106 | printf("Booting from FLASH\n"); |
| 107 | } |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | #endif |
| 112 | |
| 113 | #ifdef CONFIG_STAMP_CF |
| 114 | |
| 115 | void cf_outb(unsigned char val, volatile unsigned char *addr) |
| 116 | { |
| 117 | /* |
| 118 | * Set PF1 PF0 respectively to 0 1 to divert address |
| 119 | * to the expansion memory banks |
| 120 | */ |
| 121 | *pFIO_FLAG_S = CF_PF0; |
| 122 | *pFIO_FLAG_C = CF_PF1; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 123 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 124 | |
| 125 | *(addr) = val; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 126 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 127 | |
| 128 | /* Setback PF1 PF0 to 0 0 to address external |
| 129 | * memory banks */ |
| 130 | *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 131 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | unsigned char cf_inb(volatile unsigned char *addr) |
| 135 | { |
| 136 | volatile unsigned char c; |
| 137 | |
| 138 | *pFIO_FLAG_S = CF_PF0; |
| 139 | *pFIO_FLAG_C = CF_PF1; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 140 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 141 | |
| 142 | c = *(addr); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 143 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 144 | |
| 145 | *pFIO_FLAG_C = CF_PF1_PF0; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 146 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 147 | |
| 148 | return c; |
| 149 | } |
| 150 | |
| 151 | void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words) |
| 152 | { |
| 153 | int i; |
| 154 | |
| 155 | *pFIO_FLAG_S = CF_PF0; |
| 156 | *pFIO_FLAG_C = CF_PF1; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 157 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 158 | |
| 159 | for (i = 0; i < words; i++) { |
| 160 | *(sect_buf + i) = *(addr); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 161 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | *pFIO_FLAG_C = CF_PF1_PF0; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 165 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words) |
| 169 | { |
| 170 | int i; |
| 171 | |
| 172 | *pFIO_FLAG_S = CF_PF0; |
| 173 | *pFIO_FLAG_C = CF_PF1; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 174 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 175 | |
| 176 | for (i = 0; i < words; i++) { |
| 177 | *(addr) = *(sect_buf + i); |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 178 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | *pFIO_FLAG_C = CF_PF1_PF0; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 182 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 183 | } |
| 184 | #endif |
| 185 | |
Mike Frysinger | 23fd959 | 2008-10-11 22:40:22 -0400 | [diff] [blame] | 186 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 187 | |
| 188 | #define STATUS_LED_OFF 0 |
| 189 | #define STATUS_LED_ON 1 |
| 190 | |
| 191 | static void stamp_led_set(int LED1, int LED2, int LED3) |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 192 | { |
Mike Frysinger | 23fd959 | 2008-10-11 22:40:22 -0400 | [diff] [blame] | 193 | bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4)); |
| 194 | bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4)); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 195 | |
| 196 | if (LED1 == STATUS_LED_OFF) |
| 197 | *pFIO_FLAG_S = PF2; |
| 198 | else |
| 199 | *pFIO_FLAG_C = PF2; |
| 200 | if (LED2 == STATUS_LED_OFF) |
| 201 | *pFIO_FLAG_S = PF3; |
| 202 | else |
| 203 | *pFIO_FLAG_C = PF3; |
| 204 | if (LED3 == STATUS_LED_OFF) |
| 205 | *pFIO_FLAG_S = PF4; |
| 206 | else |
| 207 | *pFIO_FLAG_C = PF4; |
Mike Frysinger | d4d7730 | 2008-02-04 19:26:55 -0500 | [diff] [blame] | 208 | SSYNC(); |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | void show_boot_progress(int status) |
| 212 | { |
| 213 | switch (status) { |
| 214 | case 1: |
| 215 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON); |
| 216 | break; |
| 217 | case 2: |
| 218 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF); |
| 219 | break; |
| 220 | case 3: |
| 221 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON); |
| 222 | break; |
| 223 | case 4: |
| 224 | stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF); |
| 225 | break; |
| 226 | case 5: |
| 227 | case 6: |
| 228 | stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON); |
| 229 | break; |
| 230 | case 7: |
| 231 | case 8: |
| 232 | stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF); |
| 233 | break; |
| 234 | case 9: |
| 235 | case 10: |
| 236 | case 11: |
| 237 | case 12: |
| 238 | case 13: |
| 239 | case 14: |
| 240 | case 15: |
| 241 | stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF); |
| 242 | break; |
| 243 | default: |
| 244 | stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON); |
| 245 | break; |
| 246 | } |
| 247 | } |
Mike Frysinger | 23fd959 | 2008-10-11 22:40:22 -0400 | [diff] [blame] | 248 | #endif |
| 249 | |
| 250 | #ifdef CONFIG_STATUS_LED |
| 251 | #include <status_led.h> |
| 252 | |
| 253 | static void set_led(int pf, int state) |
| 254 | { |
| 255 | switch (state) { |
| 256 | case STATUS_LED_OFF: bfin_write_FIO_FLAG_S(pf); break; |
| 257 | case STATUS_LED_BLINKING: bfin_write_FIO_FLAG_T(pf); break; |
| 258 | case STATUS_LED_ON: bfin_write_FIO_FLAG_C(pf); break; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | static void set_leds(led_id_t mask, int state) |
| 263 | { |
| 264 | if (mask & 0x1) set_led(PF2, state); |
| 265 | if (mask & 0x2) set_led(PF3, state); |
| 266 | if (mask & 0x4) set_led(PF4, state); |
| 267 | } |
| 268 | |
| 269 | void __led_init(led_id_t mask, int state) |
| 270 | { |
| 271 | bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4)); |
| 272 | bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4)); |
| 273 | } |
| 274 | |
| 275 | void __led_set(led_id_t mask, int state) |
| 276 | { |
| 277 | set_leds(mask, state); |
| 278 | } |
| 279 | |
| 280 | void __led_toggle(led_id_t mask) |
| 281 | { |
| 282 | set_leds(mask, STATUS_LED_BLINKING); |
| 283 | } |
| 284 | |
| 285 | #endif |