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