hcu4.c 12 KB

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