bf533-stamp.c 5.6 KB

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