bf533-stamp.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * U-boot - main board file
  3. *
  4. * Copyright (c) 2005-2008 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. int checkboard(void)
  32. {
  33. printf("Board: ADI BF533 Stamp board\n");
  34. printf(" Support: http://blackfin.uclinux.org/\n");
  35. return 0;
  36. }
  37. phys_size_t initdram(int board_type)
  38. {
  39. gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
  40. gd->bd->bi_memsize = CONFIG_SYS_MAX_RAM_SIZE;
  41. return gd->bd->bi_memsize;
  42. }
  43. /* PF0 and PF1 are used to switch between the ethernet and flash:
  44. * PF0 PF1
  45. * flash: 0 0
  46. * ether: 1 0
  47. */
  48. void swap_to(int device_id)
  49. {
  50. bfin_write_FIO_DIR(bfin_read_FIO_DIR() | PF1 | PF0);
  51. SSYNC();
  52. bfin_write_FIO_FLAG_C(PF1);
  53. if (device_id == ETHERNET)
  54. bfin_write_FIO_FLAG_S(PF0);
  55. else if (device_id == FLASH)
  56. bfin_write_FIO_FLAG_C(PF0);
  57. else
  58. printf("Unknown device to switch\n");
  59. SSYNC();
  60. }
  61. #if defined(CONFIG_MISC_INIT_R)
  62. /* miscellaneous platform dependent initialisations */
  63. int misc_init_r(void)
  64. {
  65. int i;
  66. int cf_stat = 0;
  67. /* Check whether CF card is inserted */
  68. *pFIO_EDGE = FIO_EDGE_CF_BITS;
  69. *pFIO_POLAR = FIO_POLAR_CF_BITS;
  70. for (i = 0; i < 0x300; i++)
  71. asm("nop;");
  72. if ((*pFIO_FLAG_S) & CF_STAT_BITS) {
  73. cf_stat = 0;
  74. } else {
  75. cf_stat = 1;
  76. }
  77. *pFIO_EDGE = FIO_EDGE_BITS;
  78. *pFIO_POLAR = FIO_POLAR_BITS;
  79. if (cf_stat) {
  80. printf("Booting from COMPACT flash\n");
  81. for (i = 0; i < 0x1000; i++)
  82. asm("nop;");
  83. for (i = 0; i < 0x1000; i++)
  84. asm("nop;");
  85. for (i = 0; i < 0x1000; i++)
  86. asm("nop;");
  87. serial_setbrg();
  88. ide_init();
  89. setenv("bootargs", "");
  90. setenv("bootcmd",
  91. "fatload ide 0:1 0x1000000 uImage-stamp;bootm 0x1000000;bootm 0x20100000");
  92. } else {
  93. printf("Booting from FLASH\n");
  94. }
  95. return 0;
  96. }
  97. #endif
  98. #ifdef CONFIG_STAMP_CF
  99. void cf_outb(unsigned char val, volatile unsigned char *addr)
  100. {
  101. /*
  102. * Set PF1 PF0 respectively to 0 1 to divert address
  103. * to the expansion memory banks
  104. */
  105. *pFIO_FLAG_S = CF_PF0;
  106. *pFIO_FLAG_C = CF_PF1;
  107. SSYNC();
  108. *(addr) = val;
  109. SSYNC();
  110. /* Setback PF1 PF0 to 0 0 to address external
  111. * memory banks */
  112. *(volatile unsigned short *)pFIO_FLAG_C = CF_PF1_PF0;
  113. SSYNC();
  114. }
  115. unsigned char cf_inb(volatile unsigned char *addr)
  116. {
  117. volatile unsigned char c;
  118. *pFIO_FLAG_S = CF_PF0;
  119. *pFIO_FLAG_C = CF_PF1;
  120. SSYNC();
  121. c = *(addr);
  122. SSYNC();
  123. *pFIO_FLAG_C = CF_PF1_PF0;
  124. SSYNC();
  125. return c;
  126. }
  127. void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
  128. {
  129. int i;
  130. *pFIO_FLAG_S = CF_PF0;
  131. *pFIO_FLAG_C = CF_PF1;
  132. SSYNC();
  133. for (i = 0; i < words; i++) {
  134. *(sect_buf + i) = *(addr);
  135. SSYNC();
  136. }
  137. *pFIO_FLAG_C = CF_PF1_PF0;
  138. SSYNC();
  139. }
  140. void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
  141. {
  142. int i;
  143. *pFIO_FLAG_S = CF_PF0;
  144. *pFIO_FLAG_C = CF_PF1;
  145. SSYNC();
  146. for (i = 0; i < words; i++) {
  147. *(addr) = *(sect_buf + i);
  148. SSYNC();
  149. }
  150. *pFIO_FLAG_C = CF_PF1_PF0;
  151. SSYNC();
  152. }
  153. #endif
  154. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  155. #define STATUS_LED_OFF 0
  156. #define STATUS_LED_ON 1
  157. static void stamp_led_set(int LED1, int LED2, int LED3)
  158. {
  159. bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
  160. bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
  161. if (LED1 == STATUS_LED_OFF)
  162. *pFIO_FLAG_S = PF2;
  163. else
  164. *pFIO_FLAG_C = PF2;
  165. if (LED2 == STATUS_LED_OFF)
  166. *pFIO_FLAG_S = PF3;
  167. else
  168. *pFIO_FLAG_C = PF3;
  169. if (LED3 == STATUS_LED_OFF)
  170. *pFIO_FLAG_S = PF4;
  171. else
  172. *pFIO_FLAG_C = PF4;
  173. SSYNC();
  174. }
  175. void show_boot_progress(int status)
  176. {
  177. switch (status) {
  178. case 1:
  179. stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_ON);
  180. break;
  181. case 2:
  182. stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_OFF);
  183. break;
  184. case 3:
  185. stamp_led_set(STATUS_LED_OFF, STATUS_LED_ON, STATUS_LED_ON);
  186. break;
  187. case 4:
  188. stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_OFF);
  189. break;
  190. case 5:
  191. case 6:
  192. stamp_led_set(STATUS_LED_ON, STATUS_LED_OFF, STATUS_LED_ON);
  193. break;
  194. case 7:
  195. case 8:
  196. stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_OFF);
  197. break;
  198. case 9:
  199. case 10:
  200. case 11:
  201. case 12:
  202. case 13:
  203. case 14:
  204. case 15:
  205. stamp_led_set(STATUS_LED_OFF, STATUS_LED_OFF, STATUS_LED_OFF);
  206. break;
  207. default:
  208. stamp_led_set(STATUS_LED_ON, STATUS_LED_ON, STATUS_LED_ON);
  209. break;
  210. }
  211. }
  212. #endif
  213. #ifdef CONFIG_STATUS_LED
  214. #include <status_led.h>
  215. static void set_led(int pf, int state)
  216. {
  217. switch (state) {
  218. case STATUS_LED_OFF: bfin_write_FIO_FLAG_S(pf); break;
  219. case STATUS_LED_BLINKING: bfin_write_FIO_FLAG_T(pf); break;
  220. case STATUS_LED_ON: bfin_write_FIO_FLAG_C(pf); break;
  221. }
  222. }
  223. static void set_leds(led_id_t mask, int state)
  224. {
  225. if (mask & 0x1) set_led(PF2, state);
  226. if (mask & 0x2) set_led(PF3, state);
  227. if (mask & 0x4) set_led(PF4, state);
  228. }
  229. void __led_init(led_id_t mask, int state)
  230. {
  231. bfin_write_FIO_INEN(bfin_read_FIO_INEN() & ~(PF2 | PF3 | PF4));
  232. bfin_write_FIO_DIR(bfin_read_FIO_DIR() | (PF2 | PF3 | PF4));
  233. }
  234. void __led_set(led_id_t mask, int state)
  235. {
  236. set_leds(mask, state);
  237. }
  238. void __led_toggle(led_id_t mask)
  239. {
  240. set_leds(mask, STATUS_LED_BLINKING);
  241. }
  242. #endif