bf537-stamp.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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 defined(CONFIG_CMD_NET)
  108. char nid[32];
  109. unsigned char *pMACaddr = (unsigned char *)0x203F0000;
  110. /* The 0xFF check here is to make sure we don't use the address
  111. * in flash if it's simply been erased (aka all 0xFF values) */
  112. if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
  113. sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
  114. pMACaddr[0], pMACaddr[1],
  115. pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
  116. setenv("ethaddr", nid);
  117. }
  118. #endif
  119. #if defined(CONFIG_BFIN_IDE)
  120. #if defined(CONFIG_BFIN_TRUE_IDE)
  121. /* Enable ATASEL when in True IDE mode */
  122. printf("Using CF True IDE Mode\n");
  123. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
  124. udelay(1000);
  125. #elif defined(CONFIG_BFIN_CF_IDE)
  126. /* Disable ATASEL when we're in Common Memory Mode */
  127. printf("Using CF Common Memory Mode\n");
  128. cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
  129. udelay(1000);
  130. #elif defined(CONFIG_BFIN_HDD_IDE)
  131. printf("Using HDD IDE Mode\n");
  132. #endif
  133. ide_init();
  134. #endif /* CONFIG_BFIN_IDE */
  135. return 0;
  136. }
  137. #endif /* CONFIG_MISC_INIT_R */
  138. #ifdef CONFIG_POST
  139. /* Using sw10-PF5 as the hotkey */
  140. int post_hotkeys_pressed(void)
  141. {
  142. int delay = 3;
  143. int i;
  144. unsigned short value;
  145. *pPORTF_FER &= ~PF5;
  146. *pPORTFIO_DIR &= ~PF5;
  147. *pPORTFIO_INEN |= PF5;
  148. printf("########Press SW10 to enter Memory POST########: %2d ", delay);
  149. while (delay--) {
  150. for (i = 0; i < 100; i++) {
  151. value = *pPORTFIO & PF5;
  152. if (value != 0) {
  153. break;
  154. }
  155. udelay(10000);
  156. }
  157. printf("\b\b\b%2d ", delay);
  158. }
  159. printf("\b\b\b 0");
  160. printf("\n");
  161. if (value == 0)
  162. return 0;
  163. else {
  164. printf("Hotkey has been pressed, Enter POST . . . . . .\n");
  165. return 1;
  166. }
  167. }
  168. #endif
  169. #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
  170. void post_word_store(ulong a)
  171. {
  172. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  173. *save_addr = a;
  174. }
  175. ulong post_word_load(void)
  176. {
  177. volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
  178. return *save_addr;
  179. }
  180. #endif
  181. #ifdef CONFIG_POST
  182. int uart_post_test(int flags)
  183. {
  184. return 0;
  185. }
  186. #define BLOCK_SIZE 0x10000
  187. #define VERIFY_ADDR 0x2000000
  188. extern int erase_block_flash(int);
  189. extern int write_data(long lStart, long lCount, uchar * pnData);
  190. int flash_post_test(int flags)
  191. {
  192. unsigned short *pbuf, *temp;
  193. int offset, n, i;
  194. int value = 0;
  195. int result = 0;
  196. printf("\n");
  197. pbuf = (unsigned short *)VERIFY_ADDR;
  198. temp = pbuf;
  199. for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
  200. offset = (n - 7) * BLOCK_SIZE;
  201. printf("--------Erase block:%2d..", n);
  202. erase_block_flash(n);
  203. printf("OK\r");
  204. printf("--------Program block:%2d...", n);
  205. write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
  206. printf("OK\r");
  207. printf("--------Verify block:%2d...", n);
  208. for (i = 0; i < BLOCK_SIZE; i += 2) {
  209. if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
  210. *temp++) {
  211. value = 1;
  212. result = 1;
  213. }
  214. }
  215. if (value)
  216. printf("failed\n");
  217. else
  218. printf("OK %3d%%\r",
  219. (int)(
  220. (n + 1 -
  221. FLASH_START_POST_BLOCK) *
  222. 100 / (FLASH_END_POST_BLOCK -
  223. FLASH_START_POST_BLOCK)));
  224. temp = pbuf;
  225. value = 0;
  226. }
  227. printf("\n");
  228. if (result)
  229. return -1;
  230. else
  231. return 0;
  232. }
  233. /****************************************************
  234. * LED1 ---- PF6 LED2 ---- PF7 *
  235. * LED3 ---- PF8 LED4 ---- PF9 *
  236. * LED5 ---- PF10 LED6 ---- PF11 *
  237. ****************************************************/
  238. int led_post_test(int flags)
  239. {
  240. *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  241. *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
  242. *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  243. *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
  244. udelay(1000000);
  245. printf("LED1 on");
  246. *pPORTFIO |= PF6;
  247. udelay(1000000);
  248. printf("\b\b\b\b\b\b\b");
  249. printf("LED2 on");
  250. *pPORTFIO |= PF7;
  251. udelay(1000000);
  252. printf("\b\b\b\b\b\b\b");
  253. printf("LED3 on");
  254. *pPORTFIO |= PF8;
  255. udelay(1000000);
  256. printf("\b\b\b\b\b\b\b");
  257. printf("LED4 on");
  258. *pPORTFIO |= PF9;
  259. udelay(1000000);
  260. printf("\b\b\b\b\b\b\b");
  261. printf("LED5 on");
  262. *pPORTFIO |= PF10;
  263. udelay(1000000);
  264. printf("\b\b\b\b\b\b\b");
  265. printf("lED6 on");
  266. *pPORTFIO |= PF11;
  267. printf("\b\b\b\b\b\b\b ");
  268. return 0;
  269. }
  270. /************************************************
  271. * SW10 ---- PF5 SW11 ---- PF4 *
  272. * SW12 ---- PF3 SW13 ---- PF2 *
  273. ************************************************/
  274. int button_post_test(int flags)
  275. {
  276. int i, delay = 5;
  277. unsigned short value = 0;
  278. int result = 0;
  279. *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
  280. *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
  281. *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
  282. printf("\n--------Press SW10: %2d ", delay);
  283. while (delay--) {
  284. for (i = 0; i < 100; i++) {
  285. value = *pPORTFIO & PF5;
  286. if (value != 0) {
  287. break;
  288. }
  289. udelay(10000);
  290. }
  291. printf("\b\b\b%2d ", delay);
  292. }
  293. if (value != 0)
  294. printf("\b\bOK");
  295. else {
  296. result = -1;
  297. printf("\b\bfailed");
  298. }
  299. delay = 5;
  300. printf("\n--------Press SW11: %2d ", delay);
  301. while (delay--) {
  302. for (i = 0; i < 100; i++) {
  303. value = *pPORTFIO & PF4;
  304. if (value != 0) {
  305. break;
  306. }
  307. udelay(10000);
  308. }
  309. printf("\b\b\b%2d ", delay);
  310. }
  311. if (value != 0)
  312. printf("\b\bOK");
  313. else {
  314. result = -1;
  315. printf("\b\bfailed");
  316. }
  317. delay = 5;
  318. printf("\n--------Press SW12: %2d ", delay);
  319. while (delay--) {
  320. for (i = 0; i < 100; i++) {
  321. value = *pPORTFIO & PF3;
  322. if (value != 0) {
  323. break;
  324. }
  325. udelay(10000);
  326. }
  327. printf("\b\b\b%2d ", delay);
  328. }
  329. if (value != 0)
  330. printf("\b\bOK");
  331. else {
  332. result = -1;
  333. printf("\b\bfailed");
  334. }
  335. delay = 5;
  336. printf("\n--------Press SW13: %2d ", delay);
  337. while (delay--) {
  338. for (i = 0; i < 100; i++) {
  339. value = *pPORTFIO & PF2;
  340. if (value != 0) {
  341. break;
  342. }
  343. udelay(10000);
  344. }
  345. printf("\b\b\b%2d ", delay);
  346. }
  347. if (value != 0)
  348. printf("\b\bOK");
  349. else {
  350. result = -1;
  351. printf("\b\bfailed");
  352. }
  353. printf("\n");
  354. return result;
  355. }
  356. #endif