bf537-stamp.c 8.0 KB

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