bf537-stamp.c 8.5 KB

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