bf533-stamp.c 5.6 KB

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