bf537-stamp.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*
  2. * U-boot - main board file
  3. *
  4. * Copyright (c) 2005-2008 Analog Devices Inc.
  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., 51 Franklin St, Fifth Floor, Boston,
  25. * MA 02110-1301 USA
  26. */
  27. #include <common.h>
  28. #include <config.h>
  29. #include <command.h>
  30. #include <asm/blackfin.h>
  31. #include <asm/net.h>
  32. #include <net.h>
  33. #include <asm/mach-common/bits/bootrom.h>
  34. #include <netdev.h>
  35. DECLARE_GLOBAL_DATA_PTR;
  36. #define POST_WORD_ADDR 0xFF903FFC
  37. int checkboard(void)
  38. {
  39. printf("Board: ADI BF537 stamp board\n");
  40. printf(" Support: http://blackfin.uclinux.org/\n");
  41. return 0;
  42. }
  43. #if defined(CONFIG_BFIN_IDE)
  44. void cf_outb(unsigned char val, volatile unsigned char *addr)
  45. {
  46. *(addr) = val;
  47. SSYNC();
  48. }
  49. unsigned char cf_inb(volatile unsigned char *addr)
  50. {
  51. volatile unsigned char c;
  52. c = *(addr);
  53. SSYNC();
  54. return c;
  55. }
  56. void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
  57. {
  58. int i;
  59. for (i = 0; i < words; i++)
  60. *(sect_buf + i) = *(addr);
  61. SSYNC();
  62. }
  63. void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
  64. {
  65. int i;
  66. for (i = 0; i < words; i++)
  67. *(addr) = *(sect_buf + i);
  68. SSYNC();
  69. }
  70. #endif /* CONFIG_BFIN_IDE */
  71. phys_size_t initdram(int board_type)
  72. {
  73. gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  74. gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
  75. return gd->bd->bi_memsize;
  76. }
  77. void board_reset(void)
  78. {
  79. /* workaround for weak pull ups on ssel */
  80. if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_SPI_MASTER) {
  81. bfin_write_PORTF_FER(bfin_read_PORTF_FER() & ~PF10);
  82. bfin_write_PORTFIO_SET(PF10);
  83. udelay(1);
  84. }
  85. }
  86. #ifdef CONFIG_BFIN_MAC
  87. static void board_init_enetaddr(uchar *mac_addr)
  88. {
  89. #ifdef CONFIG_SYS_NO_FLASH
  90. # define USE_MAC_IN_FLASH 0
  91. #else
  92. # define USE_MAC_IN_FLASH 1
  93. #endif
  94. bool valid_mac = false;
  95. if (USE_MAC_IN_FLASH) {
  96. /* we cram the MAC in the last flash sector */
  97. uchar *board_mac_addr = (uchar *)0x203F0000;
  98. if (is_valid_ether_addr(board_mac_addr)) {
  99. memcpy(mac_addr, board_mac_addr, 6);
  100. valid_mac = true;
  101. }
  102. }
  103. if (!valid_mac) {
  104. puts("Warning: Generating 'random' MAC address\n");
  105. bfin_gen_rand_mac(mac_addr);
  106. }
  107. eth_setenv_enetaddr("ethaddr", mac_addr);
  108. }
  109. int board_eth_init(bd_t *bis)
  110. {
  111. return bfin_EMAC_initialize(bis);
  112. }
  113. #endif
  114. #if defined(CONFIG_MISC_INIT_R)
  115. /* miscellaneous platform dependent initialisations */
  116. int misc_init_r(void)
  117. {
  118. #ifdef CONFIG_BFIN_MAC
  119. uchar enetaddr[6];
  120. if (!eth_getenv_enetaddr("ethaddr", enetaddr))
  121. board_init_enetaddr(enetaddr);
  122. #endif
  123. #ifndef CONFIG_SYS_NO_FLASH
  124. /* we use the last sector for the MAC address / POST LDR */
  125. extern flash_info_t flash_info[];
  126. flash_protect(FLAG_PROTECT_SET, 0x203F0000, 0x203FFFFF, &flash_info[0]);
  127. #endif
  128. #if defined(CONFIG_BFIN_IDE)
  129. #if defined(CONFIG_BFIN_TRUE_IDE)
  130. /* Enable ATASEL when in True IDE mode */
  131. printf("Using CF True IDE Mode\n");
  132. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
  133. udelay(1000);
  134. #elif defined(CONFIG_BFIN_CF_IDE)
  135. /* Disable ATASEL when we're in Common Memory Mode */
  136. printf("Using CF Common Memory Mode\n");
  137. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
  138. udelay(1000);
  139. #elif defined(CONFIG_BFIN_HDD_IDE)
  140. printf("Using HDD IDE Mode\n");
  141. #endif
  142. ide_init();
  143. #endif /* CONFIG_BFIN_IDE */
  144. return 0;
  145. }
  146. #endif /* CONFIG_MISC_INIT_R */
  147. #ifdef CONFIG_POST
  148. /* Using sw10-PF5 as the hotkey */
  149. int post_hotkeys_pressed(void)
  150. {
  151. int delay = 3;
  152. int i;
  153. unsigned short value;
  154. *pPORTF_FER &= ~PF5;
  155. *pPORTFIO_DIR &= ~PF5;
  156. *pPORTFIO_INEN |= PF5;
  157. printf("########Press SW10 to enter Memory POST########: %2d ", delay);
  158. while (delay--) {
  159. for (i = 0; i < 100; i++) {
  160. value = *pPORTFIO & PF5;
  161. if (value != 0) {
  162. break;
  163. }
  164. udelay(10000);
  165. }
  166. printf("\b\b\b%2d ", delay);
  167. }
  168. printf("\b\b\b 0");
  169. printf("\n");
  170. if (value == 0)
  171. return 0;
  172. else {
  173. printf("Hotkey has been pressed, Enter POST . . . . . .\n");
  174. return 1;
  175. }
  176. }
  177. #endif
  178. #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
  179. void post_word_store(ulong a)
  180. {
  181. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  182. *save_addr = a;
  183. }
  184. ulong post_word_load(void)
  185. {
  186. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  187. return *save_addr;
  188. }
  189. #endif
  190. #ifdef CONFIG_POST
  191. int uart_post_test(int flags)
  192. {
  193. return 0;
  194. }
  195. #define BLOCK_SIZE 0x10000
  196. #define VERIFY_ADDR 0x2000000
  197. extern int erase_block_flash(int);
  198. extern int write_data(long lStart, long lCount, uchar * pnData);
  199. int flash_post_test(int flags)
  200. {
  201. unsigned short *pbuf, *temp;
  202. int offset, n, i;
  203. int value = 0;
  204. int result = 0;
  205. printf("\n");
  206. pbuf = (unsigned short *)VERIFY_ADDR;
  207. temp = pbuf;
  208. for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
  209. offset = (n - 7) * BLOCK_SIZE;
  210. printf("--------Erase block:%2d..", n);
  211. erase_block_flash(n);
  212. printf("OK\r");
  213. printf("--------Program block:%2d...", n);
  214. write_data(CONFIG_SYS_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
  215. printf("OK\r");
  216. printf("--------Verify block:%2d...", n);
  217. for (i = 0; i < BLOCK_SIZE; i += 2) {
  218. if (*(unsigned short *)(CONFIG_SYS_FLASH_BASE + offset + i) !=
  219. *temp++) {
  220. value = 1;
  221. result = 1;
  222. }
  223. }
  224. if (value)
  225. printf("failed\n");
  226. else
  227. printf("OK %3d%%\r",
  228. (int)(
  229. (n + 1 -
  230. FLASH_START_POST_BLOCK) *
  231. 100 / (FLASH_END_POST_BLOCK -
  232. FLASH_START_POST_BLOCK)));
  233. temp = pbuf;
  234. value = 0;
  235. }
  236. printf("\n");
  237. if (result)
  238. return -1;
  239. else
  240. return 0;
  241. }
  242. /****************************************************
  243. * LED1 ---- PF6 LED2 ---- PF7 *
  244. * LED3 ---- PF8 LED4 ---- PF9 *
  245. * LED5 ---- PF10 LED6 ---- PF11 *
  246. ****************************************************/
  247. int led_post_test(int flags)
  248. {
  249. *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  250. *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
  251. *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  252. *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  253. udelay(1000000);
  254. printf("LED1 on");
  255. *pPORTFIO |= PF6;
  256. udelay(1000000);
  257. printf("\b\b\b\b\b\b\b");
  258. printf("LED2 on");
  259. *pPORTFIO |= PF7;
  260. udelay(1000000);
  261. printf("\b\b\b\b\b\b\b");
  262. printf("LED3 on");
  263. *pPORTFIO |= PF8;
  264. udelay(1000000);
  265. printf("\b\b\b\b\b\b\b");
  266. printf("LED4 on");
  267. *pPORTFIO |= PF9;
  268. udelay(1000000);
  269. printf("\b\b\b\b\b\b\b");
  270. printf("LED5 on");
  271. *pPORTFIO |= PF10;
  272. udelay(1000000);
  273. printf("\b\b\b\b\b\b\b");
  274. printf("lED6 on");
  275. *pPORTFIO |= PF11;
  276. printf("\b\b\b\b\b\b\b ");
  277. return 0;
  278. }
  279. /************************************************
  280. * SW10 ---- PF5 SW11 ---- PF4 *
  281. * SW12 ---- PF3 SW13 ---- PF2 *
  282. ************************************************/
  283. int button_post_test(int flags)
  284. {
  285. int i, delay = 5;
  286. unsigned short value = 0;
  287. int result = 0;
  288. *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
  289. *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
  290. *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
  291. printf("\n--------Press SW10: %2d ", delay);
  292. while (delay--) {
  293. for (i = 0; i < 100; i++) {
  294. value = *pPORTFIO & PF5;
  295. if (value != 0) {
  296. break;
  297. }
  298. udelay(10000);
  299. }
  300. printf("\b\b\b%2d ", delay);
  301. }
  302. if (value != 0)
  303. printf("\b\bOK");
  304. else {
  305. result = -1;
  306. printf("\b\bfailed");
  307. }
  308. delay = 5;
  309. printf("\n--------Press SW11: %2d ", delay);
  310. while (delay--) {
  311. for (i = 0; i < 100; i++) {
  312. value = *pPORTFIO & PF4;
  313. if (value != 0) {
  314. break;
  315. }
  316. udelay(10000);
  317. }
  318. printf("\b\b\b%2d ", delay);
  319. }
  320. if (value != 0)
  321. printf("\b\bOK");
  322. else {
  323. result = -1;
  324. printf("\b\bfailed");
  325. }
  326. delay = 5;
  327. printf("\n--------Press SW12: %2d ", delay);
  328. while (delay--) {
  329. for (i = 0; i < 100; i++) {
  330. value = *pPORTFIO & PF3;
  331. if (value != 0) {
  332. break;
  333. }
  334. udelay(10000);
  335. }
  336. printf("\b\b\b%2d ", delay);
  337. }
  338. if (value != 0)
  339. printf("\b\bOK");
  340. else {
  341. result = -1;
  342. printf("\b\bfailed");
  343. }
  344. delay = 5;
  345. printf("\n--------Press SW13: %2d ", delay);
  346. while (delay--) {
  347. for (i = 0; i < 100; i++) {
  348. value = *pPORTFIO & PF2;
  349. if (value != 0) {
  350. break;
  351. }
  352. udelay(10000);
  353. }
  354. printf("\b\b\b%2d ", delay);
  355. }
  356. if (value != 0)
  357. printf("\b\bOK");
  358. else {
  359. result = -1;
  360. printf("\b\bfailed");
  361. }
  362. printf("\n");
  363. return result;
  364. }
  365. #endif