vcma9.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * (C) Copyright 2002
  3. * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
  4. * Marius Groeger <mgroeger@sysgo.de>
  5. *
  6. * (C) Copyright 2002
  7. * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
  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., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <s3c2410.h>
  29. #include <i2c.h>
  30. #include "vcma9.h"
  31. #include "../common/common_util.h"
  32. /* ------------------------------------------------------------------------- */
  33. #define FCLK_SPEED 1
  34. #if FCLK_SPEED==0 /* Fout = 203MHz, Fin = 12MHz for Audio */
  35. #define M_MDIV 0xC3
  36. #define M_PDIV 0x4
  37. #define M_SDIV 0x1
  38. #elif FCLK_SPEED==1 /* Fout = 202.8MHz */
  39. #define M_MDIV 0xA1
  40. #define M_PDIV 0x3
  41. #define M_SDIV 0x1
  42. #endif
  43. #define USB_CLOCK 1
  44. #if USB_CLOCK==0
  45. #define U_M_MDIV 0xA1
  46. #define U_M_PDIV 0x3
  47. #define U_M_SDIV 0x1
  48. #elif USB_CLOCK==1
  49. #define U_M_MDIV 0x48
  50. #define U_M_PDIV 0x3
  51. #define U_M_SDIV 0x2
  52. #endif
  53. static inline void delay(unsigned long loops)
  54. {
  55. __asm__ volatile ("1:\n"
  56. "subs %0, %1, #1\n"
  57. "bne 1b":"=r" (loops):"0" (loops));
  58. }
  59. /*
  60. * Miscellaneous platform dependent initialisations
  61. */
  62. int board_init(void)
  63. {
  64. DECLARE_GLOBAL_DATA_PTR;
  65. S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
  66. S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
  67. /* to reduce PLL lock time, adjust the LOCKTIME register */
  68. clk_power->LOCKTIME = 0xFFFFFF;
  69. /* configure MPLL */
  70. clk_power->MPLLCON = ((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV);
  71. /* some delay between MPLL and UPLL */
  72. delay (4000);
  73. /* configure UPLL */
  74. clk_power->UPLLCON = ((U_M_MDIV << 12) + (U_M_PDIV << 4) + U_M_SDIV);
  75. /* some delay between MPLL and UPLL */
  76. delay (8000);
  77. /* set up the I/O ports */
  78. gpio->GPACON = 0x007FFFFF;
  79. gpio->GPBCON = 0x002AAAAA;
  80. gpio->GPBUP = 0x000002BF;
  81. gpio->GPCCON = 0xAAAAAAAA;
  82. gpio->GPCUP = 0x0000FFFF;
  83. gpio->GPDCON = 0xAAAAAAAA;
  84. gpio->GPDUP = 0x0000FFFF;
  85. gpio->GPECON = 0xAAAAAAAA;
  86. gpio->GPEUP = 0x000037F7;
  87. gpio->GPFCON = 0x00000000;
  88. gpio->GPFUP = 0x00000000;
  89. gpio->GPGCON = 0xFFEAFF5A;
  90. gpio->GPGUP = 0x0000F0DC;
  91. gpio->GPHCON = 0x0028AAAA;
  92. gpio->GPHUP = 0x00000656;
  93. /* setup correct IRQ modes for NIC */
  94. gpio->EXTINT2 = (gpio->EXTINT2 & ~(7<<8)) | (4<<8); /* rising edge mode */
  95. /* select USB port 2 to be host or device (fix to host for now) */
  96. gpio->MISCCR |= 0x08;
  97. /* init serial */
  98. gd->baudrate = CONFIG_BAUDRATE;
  99. gd->have_console = 1;
  100. serial_init();
  101. /* arch number of VCMA9-Board */
  102. gd->bd->bi_arch_number = 227;
  103. /* adress of boot parameters */
  104. gd->bd->bi_boot_params = 0x30000100;
  105. icache_enable();
  106. dcache_enable();
  107. return 0;
  108. }
  109. /*
  110. * NAND flash initialization.
  111. */
  112. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  113. extern ulong
  114. nand_probe(ulong physadr);
  115. static inline void NF_Reset(void)
  116. {
  117. int i;
  118. NF_SetCE(NFCE_LOW);
  119. NF_Cmd(0xFF); /* reset command */
  120. for(i = 0; i < 10; i++); /* tWB = 100ns. */
  121. NF_WaitRB(); /* wait 200~500us; */
  122. NF_SetCE(NFCE_HIGH);
  123. }
  124. static inline void NF_Init(void)
  125. {
  126. #if 0 /* a little bit too optimistic */
  127. #define TACLS 0
  128. #define TWRPH0 3
  129. #define TWRPH1 0
  130. #else
  131. #define TACLS 0
  132. #define TWRPH0 4
  133. #define TWRPH1 2
  134. #endif
  135. NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));
  136. /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */
  137. /* 1 1 1 1, 1 xxx, r xxx, r xxx */
  138. /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */
  139. NF_Reset();
  140. }
  141. void
  142. nand_init(void)
  143. {
  144. S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
  145. NF_Init();
  146. #ifdef DEBUG
  147. printf("NAND flash probing at 0x%.8lX\n", (ulong)nand);
  148. #endif
  149. printf ("%4lu MB\n", nand_probe((ulong)nand) >> 20);
  150. }
  151. #endif
  152. /*
  153. * Get some Board/PLD Info
  154. */
  155. static u8 Get_PLD_ID(void)
  156. {
  157. VCMA9_PLD * const pld = VCMA9_GetBase_PLD();
  158. return(pld->ID);
  159. }
  160. static u8 Get_PLD_BOARD(void)
  161. {
  162. VCMA9_PLD * const pld = VCMA9_GetBase_PLD();
  163. return(pld->BOARD);
  164. }
  165. static u8 Get_PLD_SDRAM(void)
  166. {
  167. VCMA9_PLD * const pld = VCMA9_GetBase_PLD();
  168. return(pld->SDRAM);
  169. }
  170. static u8 Get_PLD_Version(void)
  171. {
  172. return((Get_PLD_ID() >> 4) & 0x0F);
  173. }
  174. static u8 Get_PLD_Revision(void)
  175. {
  176. return(Get_PLD_ID() & 0x0F);
  177. }
  178. static int Get_Board_Config(void)
  179. {
  180. u8 config = Get_PLD_BOARD() & 0x03;
  181. if (config == 3)
  182. return 1;
  183. else
  184. return 0;
  185. }
  186. static uchar Get_Board_PCB(void)
  187. {
  188. return(((Get_PLD_BOARD() >> 4) & 0x03) + 'A');
  189. }
  190. static u8 Get_SDRAM_ChipNr(void)
  191. {
  192. switch ((Get_PLD_SDRAM() >> 4) & 0x0F) {
  193. case 0: return 4;
  194. case 1: return 1;
  195. case 2: return 2;
  196. default: return 0;
  197. }
  198. }
  199. static ulong Get_SDRAM_ChipSize(void)
  200. {
  201. switch (Get_PLD_SDRAM() & 0x0F) {
  202. case 0: return 16 * (1024*1024);
  203. case 1: return 32 * (1024*1024);
  204. case 2: return 8 * (1024*1024);
  205. case 3: return 8 * (1024*1024);
  206. default: return 0;
  207. }
  208. }
  209. static const char * Get_SDRAM_ChipGeom(void)
  210. {
  211. switch (Get_PLD_SDRAM() & 0x0F) {
  212. case 0: return "4Mx8x4";
  213. case 1: return "8Mx8x4";
  214. case 2: return "2Mx8x4";
  215. case 3: return "4Mx8x2";
  216. default: return "unknown";
  217. }
  218. }
  219. static void Show_VCMA9_Info(char *board_name, char *serial)
  220. {
  221. printf("Board: %s SN: %s PCB Rev: %c PLD(%d,%d)\n",
  222. board_name, serial, Get_Board_PCB(), Get_PLD_Version(), Get_PLD_Revision());
  223. printf("SDRAM: %d chips %s\n", Get_SDRAM_ChipNr(), Get_SDRAM_ChipGeom());
  224. }
  225. int dram_init(void)
  226. {
  227. DECLARE_GLOBAL_DATA_PTR;
  228. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  229. gd->bd->bi_dram[0].size = Get_SDRAM_ChipSize() * Get_SDRAM_ChipNr();
  230. return 0;
  231. }
  232. /* ------------------------------------------------------------------------- */
  233. /*
  234. * Check Board Identity:
  235. */
  236. int checkboard(void)
  237. {
  238. unsigned char s[50];
  239. int i;
  240. backup_t *b = (backup_t *) s;
  241. i = getenv_r("serial#", s, 32);
  242. if ((i < 0) || strncmp (s, "VCMA9", 5)) {
  243. get_backup_values (b);
  244. if (strncmp (b->signature, "MPL\0", 4) != 0) {
  245. puts ("### No HW ID - assuming VCMA9");
  246. } else {
  247. b->serial_name[5] = 0;
  248. Show_VCMA9_Info(b->serial_name, &b->serial_name[6]);
  249. }
  250. } else {
  251. s[5] = 0;
  252. Show_VCMA9_Info(s, &s[6]);
  253. }
  254. /*printf("\n");*/
  255. return(0);
  256. }
  257. extern void mem_test_reloc(void);
  258. int last_stage_init(void)
  259. {
  260. mem_test_reloc();
  261. checkboard();
  262. show_stdio_dev();
  263. check_env();
  264. return 0;
  265. }
  266. /***************************************************************************
  267. * some helping routines
  268. */
  269. int overwrite_console(void)
  270. {
  271. /* return TRUE if console should be overwritten */
  272. return 0;
  273. }
  274. /************************************************************************
  275. * Print VCMA9 Info
  276. ************************************************************************/
  277. void print_vcma9_info(void)
  278. {
  279. unsigned char s[50];
  280. int i;
  281. if ((i = getenv_r("serial#", s, 32)) < 0) {
  282. puts ("### No HW ID - assuming VCMA9");
  283. printf("i %d", i*24);
  284. } else {
  285. s[5] = 0;
  286. Show_VCMA9_Info(s, &s[6]);
  287. }
  288. }