bf533-stamp.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * U-boot - stamp.c STAMP board specific routines
  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 <asm/mem_init.h>
  29. #include <asm/io.h>
  30. #include "bf533-stamp.h"
  31. #define STATUS_LED_OFF 0
  32. #define STATUS_LED_ON 1
  33. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  34. # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
  35. #else
  36. # define SHOW_BOOT_PROGRESS(arg)
  37. #endif
  38. int checkboard(void)
  39. {
  40. #if (BFIN_CPU == ADSP_BF531)
  41. printf("CPU: ADSP BF531 Rev.: 0.%d\n", *pCHIPID >> 28);
  42. #elif (BFIN_CPU == ADSP_BF532)
  43. printf("CPU: ADSP BF532 Rev.: 0.%d\n", *pCHIPID >> 28);
  44. #else
  45. printf("CPU: ADSP BF533 Rev.: 0.%d\n", *pCHIPID >> 28);
  46. #endif
  47. printf("Board: ADI BF533 Stamp board\n");
  48. printf(" Support: http://blackfin.uclinux.org/\n");
  49. return 0;
  50. }
  51. long int initdram(int board_type)
  52. {
  53. DECLARE_GLOBAL_DATA_PTR;
  54. #ifdef DEBUG
  55. printf("SDRAM attributes:\n");
  56. printf
  57. (" tRCD:%d Cycles; tRP:%d Cycles; tRAS:%d Cycles; tWR:%d Cycles; "
  58. "CAS Latency:%d cycles\n", (SDRAM_tRCD >> 15), (SDRAM_tRP >> 11),
  59. (SDRAM_tRAS >> 6), (SDRAM_tWR >> 19), (SDRAM_CL >> 2));
  60. printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
  61. printf("Bank size = %d MB\n", 128);
  62. #endif
  63. gd->bd->bi_memstart = CFG_SDRAM_BASE;
  64. gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
  65. return (gd->bd->bi_memsize);
  66. }
  67. void swap_to(int device_id)
  68. {
  69. if (device_id == ETHERNET) {
  70. *pFIO_DIR = PF0;
  71. sync();
  72. *pFIO_FLAG_S = PF0;
  73. sync();
  74. } else if (device_id == FLASH) {
  75. *pFIO_DIR = (PF4 | PF3 | PF2 | PF1 | PF0);
  76. *pFIO_FLAG_S = (PF4 | PF3 | PF2);
  77. *pFIO_MASKA_D = (PF8 | PF6 | PF5);
  78. *pFIO_MASKB_D = (PF7);
  79. *pFIO_POLAR = (PF8 | PF6 | PF5);
  80. *pFIO_EDGE = (PF8 | PF7 | PF6 | PF5);
  81. *pFIO_INEN = (PF8 | PF7 | PF6 | PF5);
  82. *pFIO_FLAG_D = (PF4 | PF3 | PF2);
  83. sync();
  84. } else {
  85. printf("Unknown bank to switch\n");
  86. }
  87. return;
  88. }
  89. #if defined(CONFIG_MISC_INIT_R)
  90. /* miscellaneous platform dependent initialisations */
  91. int misc_init_r(void)
  92. {
  93. int i;
  94. int cf_stat = 0;
  95. /* Check whether CF card is inserted */
  96. *pFIO_EDGE = FIO_EDGE_CF_BITS;
  97. *pFIO_POLAR = FIO_POLAR_CF_BITS;
  98. for (i = 0; i < 0x300; i++)
  99. asm("nop;");
  100. if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
  101. cf_stat = 0;
  102. } else {
  103. cf_stat = 1;
  104. }
  105. *pFIO_EDGE = FIO_EDGE_BITS;
  106. *pFIO_POLAR = FIO_POLAR_BITS;
  107. if (cf_stat) {
  108. printf("Booting from COMPACT flash\n");
  109. /* Set cycle time for CF */
  110. *(volatile unsigned long *)ambctl1 = CF_AMBCTL1VAL;
  111. for (i = 0; i < 0x1000; i++)
  112. asm("nop;");
  113. for (i = 0; i < 0x1000; i++)
  114. asm("nop;");
  115. for (i = 0; i < 0x1000; i++)
  116. asm("nop;");
  117. serial_setbrg();
  118. ide_init();
  119. setenv("bootargs", "");
  120. setenv("bootcmd",
  121. "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
  122. } else {
  123. printf("Booting from FLASH\n");
  124. }
  125. return 0;
  126. }
  127. #endif
  128. #ifdef CONFIG_STAMP_CF
  129. void cf_outb(unsigned char val, volatile unsigned char *addr)
  130. {
  131. /*
  132. * Set PF1 PF0 respectively to 0 1 to divert address
  133. * to the expansion memory banks
  134. */
  135. *pFIO_FLAG_S = CF_PF0;
  136. *pFIO_FLAG_C = CF_PF1;
  137. sync();
  138. *(addr) = val;
  139. sync();
  140. /* Setback PF1 PF0 to 0 0 to address external
  141. * memory banks */
  142. *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
  143. sync();
  144. }
  145. unsigned char cf_inb(volatile unsigned char *addr)
  146. {
  147. volatile unsigned char c;
  148. *pFIO_FLAG_S = CF_PF0;
  149. *pFIO_FLAG_C = CF_PF1;
  150. sync();
  151. c = *(addr);
  152. sync();
  153. *pFIO_FLAG_C = CF_PF1_PF0;
  154. sync();
  155. return c;
  156. }
  157. void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
  158. {
  159. int i;
  160. *pFIO_FLAG_S = CF_PF0;
  161. *pFIO_FLAG_C = CF_PF1;
  162. sync();
  163. for (i = 0; i < words; i++) {
  164. *(sect_buf + i) = *(addr);
  165. sync();
  166. }
  167. *pFIO_FLAG_C = CF_PF1_PF0;
  168. sync();
  169. }
  170. void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
  171. {
  172. int i;
  173. *pFIO_FLAG_S = CF_PF0;
  174. *pFIO_FLAG_C = CF_PF1;
  175. sync();
  176. for (i = 0; i < words; i++) {
  177. *(addr) = *(sect_buf + i);
  178. sync();
  179. }
  180. *pFIO_FLAG_C = CF_PF1_PF0;
  181. sync();
  182. }
  183. #endif
  184. void stamp_led_set(int LED1, int LED2, int LED3)
  185. {
  186. *pFIO_INEN &= ~(PF2 | PF3 | PF4);
  187. *pFIO_DIR |= (PF2 | PF3 | PF4);
  188. if (LED1 == STATUS_LED_OFF)
  189. *pFIO_FLAG_S = PF2;
  190. else
  191. *pFIO_FLAG_C = PF2;
  192. if (LED2 == STATUS_LED_OFF)
  193. *pFIO_FLAG_S = PF3;
  194. else
  195. *pFIO_FLAG_C = PF3;
  196. if (LED3 == STATUS_LED_OFF)
  197. *pFIO_FLAG_S = PF4;
  198. else
  199. *pFIO_FLAG_C = PF4;
  200. sync();
  201. }
  202. void show_boot_progress(int status)
  203. {
  204. switch (status) {
  205. case 1:
  206. stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
  207. break;
  208. case 2:
  209. stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
  210. break;
  211. case 3:
  212. stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
  213. break;
  214. case 4:
  215. stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
  216. break;
  217. case 5:
  218. case 6:
  219. stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
  220. break;
  221. case 7:
  222. case 8:
  223. stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
  224. break;
  225. case 9:
  226. case 10:
  227. case 11:
  228. case 12:
  229. case 13:
  230. case 14:
  231. case 15:
  232. stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
  233. break;
  234. default:
  235. stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
  236. break;
  237. }
  238. }