vcma9.c 7.5 KB

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