bf537-stamp.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. /*
  53. * the bootldr command loads an address, checks to see if there
  54. * is a Boot stream that the on-chip BOOTROM can understand,
  55. * and loads it via the BOOTROM Callback. It is possible
  56. * to also add booting from SPI, or TWI, but this function does
  57. * not currently support that.
  58. */
  59. int do_bootldr(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  60. {
  61. ulong addr, entry;
  62. ulong *data;
  63. /* Get the address */
  64. if (argc < 2) {
  65. addr = load_addr;
  66. } else {
  67. addr = simple_strtoul(argv[1], NULL, 16);
  68. }
  69. /* Check if it is a LDR file */
  70. data = (ulong *) addr;
  71. if (*data == 0xFF800060 || *data == 0xFF800040 || *data == 0xFF800020) {
  72. /* We want to boot from FLASH or SDRAM */
  73. entry = _BOOTROM_BOOT_DXE_FLASH;
  74. printf("## Booting ldr image at 0x%08lx ...\n", addr);
  75. if (icache_status())
  76. icache_disable();
  77. if (dcache_status())
  78. dcache_disable();
  79. __asm__("R7=%[a];\n" "P0=%[b];\n" "JUMP (P0);\n":
  80. :[a] "d"(addr),[b] "a"(entry)
  81. :"R7", "P0");
  82. } else {
  83. printf("## No ldr image at address 0x%08lx\n", addr);
  84. }
  85. return 0;
  86. }
  87. U_BOOT_CMD(bootldr, 2, 0, do_bootldr,
  88. "bootldr - boot ldr image from memory\n",
  89. "[addr]\n - boot ldr image stored in memory\n");
  90. int checkboard(void)
  91. {
  92. #if (BFIN_CPU == ADSP_BF534)
  93. printf("CPU: ADSP BF534 Rev.: 0.%d\n", *pCHIPID >> 28);
  94. #elif (BFIN_CPU == ADSP_BF536)
  95. printf("CPU: ADSP BF536 Rev.: 0.%d\n", *pCHIPID >> 28);
  96. #else
  97. printf("CPU: ADSP BF537 Rev.: 0.%d\n", *pCHIPID >> 28);
  98. #endif
  99. printf("Board: ADI BF537 stamp board\n");
  100. printf(" Support: http://blackfin.uclinux.org/\n");
  101. return 0;
  102. }
  103. #if defined(CONFIG_BFIN_IDE)
  104. void cf_outb(unsigned char val, volatile unsigned char *addr)
  105. {
  106. *(addr) = val;
  107. SSYNC();
  108. }
  109. unsigned char cf_inb(volatile unsigned char *addr)
  110. {
  111. volatile unsigned char c;
  112. c = *(addr);
  113. SSYNC();
  114. return c;
  115. }
  116. void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
  117. {
  118. int i;
  119. for (i = 0; i < words; i++)
  120. *(sect_buf + i) = *(addr);
  121. SSYNC();
  122. }
  123. void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
  124. {
  125. int i;
  126. for (i = 0; i < words; i++)
  127. *(addr) = *(sect_buf + i);
  128. SSYNC();
  129. }
  130. #endif /* CONFIG_BFIN_IDE */
  131. long int initdram(int board_type)
  132. {
  133. #ifdef DEBUG
  134. int brate;
  135. char *tmp = getenv("baudrate");
  136. brate = simple_strtoul(tmp, NULL, 16);
  137. printf("Serial Port initialized with Baud rate = %x\n", brate);
  138. printf("SDRAM attributes:\n");
  139. printf("tRCD %d SCLK Cycles,tRP %d SCLK Cycles,tRAS %d SCLK Cycles"
  140. "tWR %d SCLK Cycles,CAS Latency %d SCLK cycles \n",
  141. 3, 3, 6, 2, 3);
  142. printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
  143. printf("Bank size = %d MB\n", CFG_MAX_RAM_SIZE >> 20);
  144. #endif
  145. gd->bd->bi_memstart = CFG_SDRAM_BASE;
  146. gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
  147. return CFG_MAX_RAM_SIZE;
  148. }
  149. #if defined(CONFIG_MISC_INIT_R)
  150. /* miscellaneous platform dependent initialisations */
  151. int misc_init_r(void)
  152. {
  153. #if (BFIN_BOOT_MODE == BF537_BYPASS_BOOT)
  154. char nid[32];
  155. unsigned char *pMACaddr = (unsigned char *)0x203F0000;
  156. u8 SrcAddr[6] = { 0x02, 0x80, 0xAD, 0x20, 0x31, 0xB8 };
  157. #if defined(CONFIG_CMD_NET)
  158. /* The 0xFF check here is to make sure we don't use the address
  159. * in flash if it's simply been erased (aka all 0xFF values) */
  160. if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
  161. sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
  162. pMACaddr[0], pMACaddr[1],
  163. pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
  164. setenv("ethaddr", nid);
  165. }
  166. if (getenv("ethaddr")) {
  167. SetupMacAddr(SrcAddr);
  168. }
  169. #endif
  170. #endif /* BFIN_BOOT_MODE == BF537_BYPASS_BOOT */
  171. #if defined(CONFIG_BFIN_IDE)
  172. #if defined(CONFIG_BFIN_TRUE_IDE)
  173. /* Enable ATASEL when in True IDE mode */
  174. printf("Using CF True IDE Mode\n");
  175. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
  176. udelay(1000);
  177. #elif defined(CONFIG_BFIN_CF_IDE)
  178. /* Disable ATASEL when we're in Common Memory Mode */
  179. printf("Using CF Common Memory Mode\n");
  180. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
  181. udelay(1000);
  182. #elif defined(CONFIG_BFIN_HDD_IDE)
  183. printf("Using HDD IDE Mode\n");
  184. #endif
  185. ide_init();
  186. #endif /* CONFIG_BFIN_IDE */
  187. return 0;
  188. }
  189. #endif /* CONFIG_MISC_INIT_R */
  190. #ifdef CONFIG_POST
  191. #if (BFIN_BOOT_MODE != BF537_BYPASS_BOOT)
  192. /* Using sw10-PF5 as the hotkey */
  193. int post_hotkeys_pressed(void)
  194. {
  195. return 0;
  196. }
  197. #else
  198. /* Using sw10-PF5 as the hotkey */
  199. int post_hotkeys_pressed(void)
  200. {
  201. int delay = 3;
  202. int i;
  203. unsigned short value;
  204. *pPORTF_FER &= ~PF5;
  205. *pPORTFIO_DIR &= ~PF5;
  206. *pPORTFIO_INEN |= PF5;
  207. printf("########Press SW10 to enter Memory POST########: %2d ", delay);
  208. while (delay--) {
  209. for (i = 0; i < 100; i++) {
  210. value = *pPORTFIO & PF5;
  211. if (value != 0) {
  212. break;
  213. }
  214. udelay(10000);
  215. }
  216. printf("\b\b\b%2d ", delay);
  217. }
  218. printf("\b\b\b 0");
  219. printf("\n");
  220. if (value == 0)
  221. return 0;
  222. else {
  223. printf("Hotkey has been pressed, Enter POST . . . . . .\n");
  224. return 1;
  225. }
  226. }
  227. #endif
  228. #endif
  229. #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
  230. void post_word_store(ulong a)
  231. {
  232. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  233. *save_addr = a;
  234. }
  235. ulong post_word_load(void)
  236. {
  237. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  238. return *save_addr;
  239. }
  240. #endif
  241. #ifdef CONFIG_POST
  242. int uart_post_test(int flags)
  243. {
  244. return 0;
  245. }
  246. #define BLOCK_SIZE 0x10000
  247. #define VERIFY_ADDR 0x2000000
  248. extern int erase_block_flash(int);
  249. extern int write_data(long lStart, long lCount, uchar * pnData);
  250. int flash_post_test(int flags)
  251. {
  252. unsigned short *pbuf, *temp;
  253. int offset, n, i;
  254. int value = 0;
  255. int result = 0;
  256. printf("\n");
  257. pbuf = (unsigned short *)VERIFY_ADDR;
  258. temp = pbuf;
  259. for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
  260. offset = (n - 7) * BLOCK_SIZE;
  261. printf("--------Erase block:%2d..", n);
  262. erase_block_flash(n);
  263. printf("OK\r");
  264. printf("--------Program block:%2d...", n);
  265. write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
  266. printf("OK\r");
  267. printf("--------Verify block:%2d...", n);
  268. for (i = 0; i < BLOCK_SIZE; i += 2) {
  269. if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
  270. *temp++) {
  271. value = 1;
  272. result = 1;
  273. }
  274. }
  275. if (value)
  276. printf("failed\n");
  277. else
  278. printf("OK %3d%%\r",
  279. (int)(
  280. (n + 1 -
  281. FLASH_START_POST_BLOCK) *
  282. 100 / (FLASH_END_POST_BLOCK -
  283. FLASH_START_POST_BLOCK)));
  284. temp = pbuf;
  285. value = 0;
  286. }
  287. printf("\n");
  288. if (result)
  289. return -1;
  290. else
  291. return 0;
  292. }
  293. /****************************************************
  294. * LED1 ---- PF6 LED2 ---- PF7 *
  295. * LED3 ---- PF8 LED4 ---- PF9 *
  296. * LED5 ---- PF10 LED6 ---- PF11 *
  297. ****************************************************/
  298. int led_post_test(int flags)
  299. {
  300. *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  301. *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
  302. *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  303. *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  304. udelay(1000000);
  305. printf("LED1 on");
  306. *pPORTFIO |= PF6;
  307. udelay(1000000);
  308. printf("\b\b\b\b\b\b\b");
  309. printf("LED2 on");
  310. *pPORTFIO |= PF7;
  311. udelay(1000000);
  312. printf("\b\b\b\b\b\b\b");
  313. printf("LED3 on");
  314. *pPORTFIO |= PF8;
  315. udelay(1000000);
  316. printf("\b\b\b\b\b\b\b");
  317. printf("LED4 on");
  318. *pPORTFIO |= PF9;
  319. udelay(1000000);
  320. printf("\b\b\b\b\b\b\b");
  321. printf("LED5 on");
  322. *pPORTFIO |= PF10;
  323. udelay(1000000);
  324. printf("\b\b\b\b\b\b\b");
  325. printf("lED6 on");
  326. *pPORTFIO |= PF11;
  327. printf("\b\b\b\b\b\b\b ");
  328. return 0;
  329. }
  330. /************************************************
  331. * SW10 ---- PF5 SW11 ---- PF4 *
  332. * SW12 ---- PF3 SW13 ---- PF2 *
  333. ************************************************/
  334. int button_post_test(int flags)
  335. {
  336. int i, delay = 5;
  337. unsigned short value = 0;
  338. int result = 0;
  339. *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
  340. *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
  341. *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
  342. printf("\n--------Press SW10: %2d ", delay);
  343. while (delay--) {
  344. for (i = 0; i < 100; i++) {
  345. value = *pPORTFIO & PF5;
  346. if (value != 0) {
  347. break;
  348. }
  349. udelay(10000);
  350. }
  351. printf("\b\b\b%2d ", delay);
  352. }
  353. if (value != 0)
  354. printf("\b\bOK");
  355. else {
  356. result = -1;
  357. printf("\b\bfailed");
  358. }
  359. delay = 5;
  360. printf("\n--------Press SW11: %2d ", delay);
  361. while (delay--) {
  362. for (i = 0; i < 100; i++) {
  363. value = *pPORTFIO & PF4;
  364. if (value != 0) {
  365. break;
  366. }
  367. udelay(10000);
  368. }
  369. printf("\b\b\b%2d ", delay);
  370. }
  371. if (value != 0)
  372. printf("\b\bOK");
  373. else {
  374. result = -1;
  375. printf("\b\bfailed");
  376. }
  377. delay = 5;
  378. printf("\n--------Press SW12: %2d ", delay);
  379. while (delay--) {
  380. for (i = 0; i < 100; i++) {
  381. value = *pPORTFIO & PF3;
  382. if (value != 0) {
  383. break;
  384. }
  385. udelay(10000);
  386. }
  387. printf("\b\b\b%2d ", delay);
  388. }
  389. if (value != 0)
  390. printf("\b\bOK");
  391. else {
  392. result = -1;
  393. printf("\b\bfailed");
  394. }
  395. delay = 5;
  396. printf("\n--------Press SW13: %2d ", delay);
  397. while (delay--) {
  398. for (i = 0; i < 100; i++) {
  399. value = *pPORTFIO & PF2;
  400. if (value != 0) {
  401. break;
  402. }
  403. udelay(10000);
  404. }
  405. printf("\b\b\b%2d ", delay);
  406. }
  407. if (value != 0)
  408. printf("\b\bOK");
  409. else {
  410. result = -1;
  411. printf("\b\bfailed");
  412. }
  413. printf("\n");
  414. return result;
  415. }
  416. #endif