bf537-stamp.c 9.0 KB

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