bf537-stamp.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*
  2. * U-boot - BF537.c
  3. *
  4. * Copyright (c) 2005-2007 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/io.h>
  32. #include <net.h>
  33. #include <asm/mach-common/bits/bootrom.h>
  34. /**
  35. * is_valid_ether_addr - Determine if the given Ethernet address is valid
  36. * @addr: Pointer to a six-byte array containing the Ethernet address
  37. *
  38. * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not
  39. * a multicast address, and is not FF:FF:FF:FF:FF:FF.
  40. *
  41. * Return true if the address is valid.
  42. */
  43. static inline int is_valid_ether_addr(const u8 * addr)
  44. {
  45. /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to
  46. * explicitly check for it here. */
  47. return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr);
  48. }
  49. DECLARE_GLOBAL_DATA_PTR;
  50. #define POST_WORD_ADDR 0xFF903FFC
  51. int checkboard(void)
  52. {
  53. printf("Board: ADI BF537 stamp board\n");
  54. printf(" Support: http://blackfin.uclinux.org/\n");
  55. return 0;
  56. }
  57. #if defined(CONFIG_BFIN_IDE)
  58. void cf_outb(unsigned char val, volatile unsigned char *addr)
  59. {
  60. *(addr) = val;
  61. SSYNC();
  62. }
  63. unsigned char cf_inb(volatile unsigned char *addr)
  64. {
  65. volatile unsigned char c;
  66. c = *(addr);
  67. SSYNC();
  68. return c;
  69. }
  70. void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
  71. {
  72. int i;
  73. for (i = 0; i < words; i++)
  74. *(sect_buf + i) = *(addr);
  75. SSYNC();
  76. }
  77. void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
  78. {
  79. int i;
  80. for (i = 0; i < words; i++)
  81. *(addr) = *(sect_buf + i);
  82. SSYNC();
  83. }
  84. #endif /* CONFIG_BFIN_IDE */
  85. long int initdram(int board_type)
  86. {
  87. #ifdef DEBUG
  88. int brate;
  89. char *tmp = getenv("baudrate");
  90. brate = simple_strtoul(tmp, NULL, 16);
  91. printf("Serial Port initialized with Baud rate = %x\n", brate);
  92. printf("SDRAM attributes:\n");
  93. printf("tRCD %d SCLK Cycles,tRP %d SCLK Cycles,tRAS %d SCLK Cycles"
  94. "tWR %d SCLK Cycles,CAS Latency %d SCLK cycles \n",
  95. 3, 3, 6, 2, 3);
  96. printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
  97. printf("Bank size = %d MB\n", CFG_MAX_RAM_SIZE >> 20);
  98. #endif
  99. gd->bd->bi_memstart = CFG_SDRAM_BASE;
  100. gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
  101. return CFG_MAX_RAM_SIZE;
  102. }
  103. #if defined(CONFIG_MISC_INIT_R)
  104. /* miscellaneous platform dependent initialisations */
  105. int misc_init_r(void)
  106. {
  107. #if (BFIN_BOOT_MODE == BF537_BYPASS_BOOT)
  108. char nid[32];
  109. unsigned char *pMACaddr = (unsigned char *)0x203F0000;
  110. u8 SrcAddr[6] = { 0x02, 0x80, 0xAD, 0x20, 0x31, 0xB8 };
  111. #if defined(CONFIG_CMD_NET)
  112. /* The 0xFF check here is to make sure we don't use the address
  113. * in flash if it's simply been erased (aka all 0xFF values) */
  114. if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
  115. sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
  116. pMACaddr[0], pMACaddr[1],
  117. pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
  118. setenv("ethaddr", nid);
  119. }
  120. #endif
  121. #endif /* BFIN_BOOT_MODE == BF537_BYPASS_BOOT */
  122. #if defined(CONFIG_BFIN_IDE)
  123. #if defined(CONFIG_BFIN_TRUE_IDE)
  124. /* Enable ATASEL when in True IDE mode */
  125. printf("Using CF True IDE Mode\n");
  126. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
  127. udelay(1000);
  128. #elif defined(CONFIG_BFIN_CF_IDE)
  129. /* Disable ATASEL when we're in Common Memory Mode */
  130. printf("Using CF Common Memory Mode\n");
  131. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
  132. udelay(1000);
  133. #elif defined(CONFIG_BFIN_HDD_IDE)
  134. printf("Using HDD IDE Mode\n");
  135. #endif
  136. ide_init();
  137. #endif /* CONFIG_BFIN_IDE */
  138. return 0;
  139. }
  140. #endif /* CONFIG_MISC_INIT_R */
  141. #ifdef CONFIG_POST
  142. #if (BFIN_BOOT_MODE != BF537_BYPASS_BOOT)
  143. /* Using sw10-PF5 as the hotkey */
  144. int post_hotkeys_pressed(void)
  145. {
  146. return 0;
  147. }
  148. #else
  149. /* Using sw10-PF5 as the hotkey */
  150. int post_hotkeys_pressed(void)
  151. {
  152. int delay = 3;
  153. int i;
  154. unsigned short value;
  155. *pPORTF_FER &= ~PF5;
  156. *pPORTFIO_DIR &= ~PF5;
  157. *pPORTFIO_INEN |= PF5;
  158. printf("########Press SW10 to enter Memory POST########: %2d ", delay);
  159. while (delay--) {
  160. for (i = 0; i < 100; i++) {
  161. value = *pPORTFIO & PF5;
  162. if (value != 0) {
  163. break;
  164. }
  165. udelay(10000);
  166. }
  167. printf("\b\b\b%2d ", delay);
  168. }
  169. printf("\b\b\b 0");
  170. printf("\n");
  171. if (value == 0)
  172. return 0;
  173. else {
  174. printf("Hotkey has been pressed, Enter POST . . . . . .\n");
  175. return 1;
  176. }
  177. }
  178. #endif
  179. #endif
  180. #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
  181. void post_word_store(ulong a)
  182. {
  183. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  184. *save_addr = a;
  185. }
  186. ulong post_word_load(void)
  187. {
  188. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  189. return *save_addr;
  190. }
  191. #endif
  192. #ifdef CONFIG_POST
  193. int uart_post_test(int flags)
  194. {
  195. return 0;
  196. }
  197. #define BLOCK_SIZE 0x10000
  198. #define VERIFY_ADDR 0x2000000
  199. extern int erase_block_flash(int);
  200. extern int write_data(long lStart, long lCount, uchar * pnData);
  201. int flash_post_test(int flags)
  202. {
  203. unsigned short *pbuf, *temp;
  204. int offset, n, i;
  205. int value = 0;
  206. int result = 0;
  207. printf("\n");
  208. pbuf = (unsigned short *)VERIFY_ADDR;
  209. temp = pbuf;
  210. for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
  211. offset = (n - 7) * BLOCK_SIZE;
  212. printf("--------Erase block:%2d..", n);
  213. erase_block_flash(n);
  214. printf("OK\r");
  215. printf("--------Program block:%2d...", n);
  216. write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
  217. printf("OK\r");
  218. printf("--------Verify block:%2d...", n);
  219. for (i = 0; i < BLOCK_SIZE; i += 2) {
  220. if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
  221. *temp++) {
  222. value = 1;
  223. result = 1;
  224. }
  225. }
  226. if (value)
  227. printf("failed\n");
  228. else
  229. printf("OK %3d%%\r",
  230. (int)(
  231. (n + 1 -
  232. FLASH_START_POST_BLOCK) *
  233. 100 / (FLASH_END_POST_BLOCK -
  234. FLASH_START_POST_BLOCK)));
  235. temp = pbuf;
  236. value = 0;
  237. }
  238. printf("\n");
  239. if (result)
  240. return -1;
  241. else
  242. return 0;
  243. }
  244. /****************************************************
  245. * LED1 ---- PF6 LED2 ---- PF7 *
  246. * LED3 ---- PF8 LED4 ---- PF9 *
  247. * LED5 ---- PF10 LED6 ---- PF11 *
  248. ****************************************************/
  249. int led_post_test(int flags)
  250. {
  251. *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  252. *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
  253. *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  254. *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  255. udelay(1000000);
  256. printf("LED1 on");
  257. *pPORTFIO |= PF6;
  258. udelay(1000000);
  259. printf("\b\b\b\b\b\b\b");
  260. printf("LED2 on");
  261. *pPORTFIO |= PF7;
  262. udelay(1000000);
  263. printf("\b\b\b\b\b\b\b");
  264. printf("LED3 on");
  265. *pPORTFIO |= PF8;
  266. udelay(1000000);
  267. printf("\b\b\b\b\b\b\b");
  268. printf("LED4 on");
  269. *pPORTFIO |= PF9;
  270. udelay(1000000);
  271. printf("\b\b\b\b\b\b\b");
  272. printf("LED5 on");
  273. *pPORTFIO |= PF10;
  274. udelay(1000000);
  275. printf("\b\b\b\b\b\b\b");
  276. printf("lED6 on");
  277. *pPORTFIO |= PF11;
  278. printf("\b\b\b\b\b\b\b ");
  279. return 0;
  280. }
  281. /************************************************
  282. * SW10 ---- PF5 SW11 ---- PF4 *
  283. * SW12 ---- PF3 SW13 ---- PF2 *
  284. ************************************************/
  285. int button_post_test(int flags)
  286. {
  287. int i, delay = 5;
  288. unsigned short value = 0;
  289. int result = 0;
  290. *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
  291. *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
  292. *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
  293. printf("\n--------Press SW10: %2d ", delay);
  294. while (delay--) {
  295. for (i = 0; i < 100; i++) {
  296. value = *pPORTFIO & PF5;
  297. if (value != 0) {
  298. break;
  299. }
  300. udelay(10000);
  301. }
  302. printf("\b\b\b%2d ", delay);
  303. }
  304. if (value != 0)
  305. printf("\b\bOK");
  306. else {
  307. result = -1;
  308. printf("\b\bfailed");
  309. }
  310. delay = 5;
  311. printf("\n--------Press SW11: %2d ", delay);
  312. while (delay--) {
  313. for (i = 0; i < 100; i++) {
  314. value = *pPORTFIO & PF4;
  315. if (value != 0) {
  316. break;
  317. }
  318. udelay(10000);
  319. }
  320. printf("\b\b\b%2d ", delay);
  321. }
  322. if (value != 0)
  323. printf("\b\bOK");
  324. else {
  325. result = -1;
  326. printf("\b\bfailed");
  327. }
  328. delay = 5;
  329. printf("\n--------Press SW12: %2d ", delay);
  330. while (delay--) {
  331. for (i = 0; i < 100; i++) {
  332. value = *pPORTFIO & PF3;
  333. if (value != 0) {
  334. break;
  335. }
  336. udelay(10000);
  337. }
  338. printf("\b\b\b%2d ", delay);
  339. }
  340. if (value != 0)
  341. printf("\b\bOK");
  342. else {
  343. result = -1;
  344. printf("\b\bfailed");
  345. }
  346. delay = 5;
  347. printf("\n--------Press SW13: %2d ", delay);
  348. while (delay--) {
  349. for (i = 0; i < 100; i++) {
  350. value = *pPORTFIO & PF2;
  351. if (value != 0) {
  352. break;
  353. }
  354. udelay(10000);
  355. }
  356. printf("\b\b\b%2d ", delay);
  357. }
  358. if (value != 0)
  359. printf("\b\bOK");
  360. else {
  361. result = -1;
  362. printf("\b\bfailed");
  363. }
  364. printf("\n");
  365. return result;
  366. }
  367. #endif