hcu4.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /*
  2. *(C) Copyright 2005-2007 Netstal Maschinen AG
  3. * Niklaus Giger (Niklaus.Giger@netstal.com)
  4. *
  5. * This source code is free software; you can redistribute it
  6. * and/or modify it in source code form under the terms of the GNU
  7. * General Public License as published by the Free Software
  8. * Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  19. */
  20. #include <common.h>
  21. #include <ppc4xx.h>
  22. #include <asm/processor.h>
  23. #include <asm/io.h>
  24. #include <asm-ppc/u-boot.h>
  25. #include "../common/nm_bsp.c"
  26. DECLARE_GLOBAL_DATA_PTR;
  27. #define HCU_MACH_VERSIONS_REGISTER (0x7C000000 + 0xF00000)
  28. #define SDRAM_LEN 32*1024*1024 /* 32 MB -RAM */
  29. #define DO_UGLY_SDRAM_WORKAROUND
  30. enum {
  31. /* HW_GENERATION_HCU wird nicht mehr unterstuetzt */
  32. HW_GENERATION_HCU2 = 0x10,
  33. HW_GENERATION_HCU3 = 0x10,
  34. HW_GENERATION_HCU4 = 0x20,
  35. HW_GENERATION_MCU = 0x08,
  36. HW_GENERATION_MCU20 = 0x0a,
  37. HW_GENERATION_MCU25 = 0x09,
  38. };
  39. void sysLedSet(u32 value);
  40. long int spd_sdram(int(read_spd)(uint addr));
  41. #ifdef CONFIG_SPD_EEPROM
  42. #define DEBUG
  43. #endif
  44. #if defined(DEBUG)
  45. void show_sdram_registers(void);
  46. #endif
  47. /*
  48. * This function is run very early, out of flash, and before devices are
  49. * initialized. It is called by lib_ppc/board.c:board_init_f by virtue
  50. * of being in the init_sequence array.
  51. *
  52. * The SDRAM has been initialized already -- start.S:start called
  53. * init.S:init_sdram early on -- but it is not yet being used for
  54. * anything, not even stack. So be careful.
  55. */
  56. #define CPC0_CR0 0xb1 /* Chip control register 0 */
  57. #define CPC0_CR1 0xb2 /* Chip control register 1 */
  58. /* Attention: If you want 1 microsecs times from the external oscillator
  59. * use 0x00804051. But this causes problems with u-boot and linux!
  60. */
  61. #define CPC0_CR1_VALUE 0x00004051
  62. #define CPC0_ECR 0xaa /* Edge condition register */
  63. #define EBC0_CFG 0x23 /* External Peripheral Control Register */
  64. #define CPC0_EIRR 0xb6 /* External Interrupt Register */
  65. int board_early_init_f (void)
  66. {
  67. /*-------------------------------------------------------------------+
  68. | Interrupt controller setup for the HCU4 board.
  69. | Note: IRQ 0-15 405GP internally generated; high; level sensitive
  70. | IRQ 16 405GP internally generated; low; level sensitive
  71. | IRQ 17-24 RESERVED/UNUSED
  72. | IRQ 31 (EXT IRQ 6) (unused)
  73. +-------------------------------------------------------------------*/
  74. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  75. mtdcr (uicer, 0x00000000); /* disable all ints */
  76. mtdcr (uiccr, 0x00000000); /* set all to be non-critical */
  77. mtdcr (uicpr, 0xFFFFFF87); /* set int polarities */
  78. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  79. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  80. mtdcr(CPC0_CR1, CPC0_CR1_VALUE);
  81. mtdcr(CPC0_ECR, 0x60606000);
  82. mtdcr(CPC0_EIRR, 0x7c000000);
  83. return 0;
  84. }
  85. #ifdef CONFIG_BOARD_PRE_INIT
  86. int board_pre_init (void)
  87. {
  88. return board_early_init_f ();
  89. }
  90. #endif
  91. int checkboard (void)
  92. {
  93. unsigned int j;
  94. u16 *boardVersReg = (u16 *) HCU_MACH_VERSIONS_REGISTER;
  95. u16 generation = *boardVersReg & 0xf0;
  96. u16 index = *boardVersReg & 0x0f;
  97. /* Force /RTS to active. The board it not wired quite
  98. correctly to use cts/rtc flow control, so just force the
  99. /RST active and forget about it. */
  100. writeb (readb (0xef600404) | 0x03, 0xef600404);
  101. printf ("\nNetstal Maschinen AG ");
  102. if (generation == HW_GENERATION_HCU3)
  103. printf ("HCU3: index %d\n\n", index);
  104. else if (generation == HW_GENERATION_HCU4)
  105. printf ("HCU4: index %d\n\n", index);
  106. /* GPIO here noch nicht richtig initialisert !!! */
  107. sysLedSet(0);
  108. for (j = 0; j < 7; j++) {
  109. sysLedSet(1 << j);
  110. udelay(50 * 1000);
  111. }
  112. return 0;
  113. }
  114. u32 sysLedGet(void)
  115. {
  116. return (~((*(u32 *)GPIO0_OR)) >> 23) & 0xff;
  117. }
  118. void sysLedSet(u32 value /* value to place in LEDs */)
  119. {
  120. u32 tmp = ~value;
  121. u32 *ledReg;
  122. tmp = (tmp << 23) | 0x7FFFFF;
  123. ledReg = (u32 *)GPIO0_OR;
  124. *ledReg = tmp;
  125. }
  126. /*
  127. * sdram_init - Dummy implementation for start.S, spd_sdram or initdram
  128. * used for HCUx
  129. */
  130. void sdram_init(void)
  131. {
  132. return;
  133. }
  134. #if defined(DEBUG)
  135. void show_sdram_registers(void)
  136. {
  137. u32 value;
  138. printf ("SDRAM Controller Registers --\n");
  139. mfsdram(mem_mcopt1, value);
  140. printf (" SDRAM0_CFG : 0x%08x\n", value);
  141. mfsdram(mem_status, value);
  142. printf (" SDRAM0_STATUS: 0x%08x\n", value);
  143. mfsdram(mem_mb0cf, value);
  144. printf (" SDRAM0_B0CR : 0x%08x\n", value);
  145. mfsdram(mem_mb1cf, value);
  146. printf (" SDRAM0_B1CR : 0x%08x\n", value);
  147. mfsdram(mem_sdtr1, value);
  148. printf (" SDRAM0_TR : 0x%08x\n", value);
  149. mfsdram(mem_rtr, value);
  150. printf (" SDRAM0_RTR : 0x%08x\n", value);
  151. }
  152. #endif
  153. /*
  154. * this is even after checkboard. It returns the size of the SDRAM
  155. * that we have installed. This function is called by board_init_f
  156. * in lib_ppc/board.c to initialize the memory and return what I
  157. * found. These are default value, which will be overridden later.
  158. */
  159. long int fixed_hcu4_sdram (int board_type)
  160. {
  161. #ifdef DEBUG
  162. printf (__FUNCTION__);
  163. #endif
  164. /* disable memory controller */
  165. mtdcr (memcfga, mem_mcopt1);
  166. mtdcr (memcfgd, 0x00000000);
  167. udelay (500);
  168. /* Clear SDRAM0_BESR0 (Bus Error Syndrome Register) */
  169. mtdcr (memcfga, mem_besra);
  170. mtdcr (memcfgd, 0xffffffff);
  171. /* Clear SDRAM0_BESR1 (Bus Error Syndrome Register) */
  172. mtdcr (memcfga, mem_besrb);
  173. mtdcr (memcfgd, 0xffffffff);
  174. /* Clear SDRAM0_ECCCFG (disable ECC) */
  175. mtdcr (memcfga, mem_ecccf);
  176. mtdcr (memcfgd, 0x00000000);
  177. /* Clear SDRAM0_ECCESR (ECC Error Syndrome Register) */
  178. mtdcr (memcfga, mem_eccerr);
  179. mtdcr (memcfgd, 0xffffffff);
  180. /* Timing register: CASL=2, PTA=2, CTP=2, LDF=1, RFTA=5, RCD=2
  181. * TODO ngngng
  182. */
  183. mtdcr (memcfga, mem_sdtr1);
  184. mtdcr (memcfgd, 0x008a4015);
  185. /* Memory Bank 0 Config == BA=0x00000000, SZ=64M, AM=3, BE=1
  186. * TODO ngngng
  187. */
  188. mtdcr (memcfga, mem_mb0cf);
  189. mtdcr (memcfgd, 0x00062001);
  190. /* refresh timer = 0x400 */
  191. mtdcr (memcfga, mem_rtr);
  192. mtdcr (memcfgd, 0x04000000);
  193. /* Power management idle timer set to the default. */
  194. mtdcr (memcfga, mem_pmit);
  195. mtdcr (memcfgd, 0x07c00000);
  196. udelay (500);
  197. /* Enable banks (DCE=1, BPRF=1, ECCDD=1, EMDUL=1) TODO */
  198. mtdcr (memcfga, mem_mcopt1);
  199. mtdcr (memcfgd, 0x90800000);
  200. #ifdef DEBUG
  201. printf ("%s: done\n", __FUNCTION__);
  202. #endif
  203. return SDRAM_LEN;
  204. }
  205. /*---------------------------------------------------------------------------+
  206. * getSerialNr
  207. *---------------------------------------------------------------------------*/
  208. static u32 getSerialNr(void)
  209. {
  210. u32 *serial = (u32 *)CFG_FLASH_BASE;
  211. if (*serial == 0xffffffff)
  212. return get_ticks();
  213. return *serial;
  214. }
  215. /*---------------------------------------------------------------------------+
  216. * misc_init_r.
  217. *---------------------------------------------------------------------------*/
  218. int misc_init_r(void)
  219. {
  220. char *s = getenv("ethaddr");
  221. char *e;
  222. int i;
  223. u32 serial = getSerialNr();
  224. for (i = 0; i < 6; ++i) {
  225. gd->bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0;
  226. if (s)
  227. s = (*e) ? e + 1 : e;
  228. }
  229. if (gd->bd->bi_enetaddr[3] == 0 &&
  230. gd->bd->bi_enetaddr[4] == 0 &&
  231. gd->bd->bi_enetaddr[5] == 0) {
  232. char ethaddr[22];
  233. /* [0..3] Must be in sync with CONFIG_ETHADDR */
  234. gd->bd->bi_enetaddr[0] = 0x00;
  235. gd->bd->bi_enetaddr[1] = 0x60;
  236. gd->bd->bi_enetaddr[2] = 0x13;
  237. gd->bd->bi_enetaddr[3] = (serial >> 16) & 0xff;
  238. gd->bd->bi_enetaddr[4] = (serial >> 8) & 0xff;
  239. gd->bd->bi_enetaddr[5] = (serial >> 0) & 0xff;
  240. sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X\0",
  241. gd->bd->bi_enetaddr[0], gd->bd->bi_enetaddr[1],
  242. gd->bd->bi_enetaddr[2], gd->bd->bi_enetaddr[3],
  243. gd->bd->bi_enetaddr[4], gd->bd->bi_enetaddr[5]) ;
  244. printf("%s: Setting eth %s serial 0x%x\n", __FUNCTION__,
  245. ethaddr, serial);
  246. setenv ("ethaddr", ethaddr);
  247. }
  248. return 0;
  249. }
  250. #ifdef DO_UGLY_SDRAM_WORKAROUND
  251. #include "i2c.h"
  252. void set_spd_default_value(unsigned int spd_addr,uchar def_val)
  253. {
  254. uchar value;
  255. int res = i2c_read(SPD_EEPROM_ADDRESS, spd_addr, 1, &value, 1) ;
  256. if (res == 0 && value == 0xff) {
  257. res = i2c_write(SPD_EEPROM_ADDRESS,
  258. spd_addr, 1, &def_val, 1) ;
  259. #ifdef DEBUG
  260. printf("%s: Setting spd offset %3d to %3d res %d\n",
  261. __FUNCTION__, spd_addr, def_val, res);
  262. #endif
  263. }
  264. }
  265. #endif
  266. long int initdram(int board_type)
  267. {
  268. long dram_size = 0;
  269. #if !defined(CONFIG_SPD_EEPROM)
  270. dram_size = fixed_hcu4_sdram();
  271. #else
  272. #ifdef DO_UGLY_SDRAM_WORKAROUND
  273. /* Workaround if you have no working I2C-EEPROM-SPD-configuration */
  274. i2c_init(CFG_I2C_SPEED, CFG_I2C_SLAVE);
  275. set_spd_default_value(2, 4); /* SDRAM Type */
  276. set_spd_default_value(7, 0); /* module width, high byte */
  277. set_spd_default_value(12, 1); /* Refresh or 0x81 */
  278. /* Only correct for HCU3 with 32 MB RAM*/
  279. /* Number of bytes used by module manufacturer */
  280. set_spd_default_value( 0, 128);
  281. set_spd_default_value( 1, 11 ); /* Total SPD memory size */
  282. set_spd_default_value( 2, 4 ); /* Memory type */
  283. set_spd_default_value( 3, 12 ); /* Number of row address bits */
  284. set_spd_default_value( 4, 9 ); /* Number of column address bits */
  285. set_spd_default_value( 5, 1 ); /* Number of module rows */
  286. set_spd_default_value( 6, 32 ); /* Module data width, LSB */
  287. set_spd_default_value( 7, 0 ); /* Module data width, MSB */
  288. set_spd_default_value( 8, 1 ); /* Module interface signal levels */
  289. /* SDRAM cycle time for highest CL (Tclk) */
  290. set_spd_default_value( 9, 112);
  291. /* SDRAM access time from clock for highest CL (Tac) */
  292. set_spd_default_value(10, 84 );
  293. set_spd_default_value(11, 2 ); /* Module configuration type */
  294. set_spd_default_value(12, 128); /* Refresh rate/type */
  295. set_spd_default_value(13, 16 ); /* Primary SDRAM width */
  296. set_spd_default_value(14, 8 ); /* Error Checking SDRAM width */
  297. /* SDRAM device attributes, min clock delay for back to back */
  298. /*random column addresses (Tccd) */
  299. set_spd_default_value(15, 1 );
  300. /* SDRAM device attributes, burst lengths supported */
  301. set_spd_default_value(16, 143);
  302. /* SDRAM device attributes, number of banks on SDRAM device */
  303. set_spd_default_value(17, 4 );
  304. /* SDRAM device attributes, CAS latency */
  305. set_spd_default_value(18, 6 );
  306. /* SDRAM device attributes, CS latency */
  307. set_spd_default_value(19, 1 );
  308. /* SDRAM device attributes, WE latency */
  309. set_spd_default_value(20, 1 );
  310. set_spd_default_value(21, 0 ); /* SDRAM module attributes */
  311. /* SDRAM device attributes, general */
  312. set_spd_default_value(22, 14 );
  313. /* SDRAM cycle time for 2nd highest CL (Tclk) */
  314. set_spd_default_value(23, 117);
  315. /* SDRAM access time from clock for2nd highest CL (Tac) */
  316. set_spd_default_value(24, 84 );
  317. /* SDRAM cycle time for 3rd highest CL (Tclk) */
  318. set_spd_default_value(25, 0 );
  319. /* SDRAM access time from clock for3rd highest CL (Tac) */
  320. set_spd_default_value(26, 0 );
  321. set_spd_default_value(27, 15 ); /* Minimum row precharge time (Trp) */
  322. /* Minimum row active to row active delay (Trrd) */
  323. set_spd_default_value(28, 14 );
  324. set_spd_default_value(29, 15 ); /* Minimum CAS to RAS delay (Trcd) */
  325. set_spd_default_value(30, 37 ); /* Minimum RAS pulse width (Tras) */
  326. set_spd_default_value(31, 8 ); /* Module bank density */
  327. /* Command and Address signal input setup time */
  328. set_spd_default_value(32, 21 );
  329. /* Command and Address signal input hold time */
  330. set_spd_default_value(33, 8 );
  331. set_spd_default_value(34, 21 ); /* Data signal input setup time */
  332. set_spd_default_value(35, 8 ); /* Data signal input hold time */
  333. #endif /* DO_UGLY_SDRAM_WORKAROUND */
  334. dram_size = spd_sdram(0);
  335. #endif
  336. #ifdef DEBUG
  337. show_sdram_registers();
  338. #endif
  339. #if defined(CFG_DRAM_TEST)
  340. bcu4_testdram(dram_size);
  341. printf("%s %d MB of SDRAM\n", __FUNCTION__, dram_size/(1024*1024));
  342. #endif
  343. return dram_size;
  344. }