bf537-stamp.c 10 KB

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