bf537-stamp.c 9.4 KB

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