mip405.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /*
  2. * (C) Copyright 2001
  3. * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. *
  24. * TODO: clean-up
  25. */
  26. /*
  27. * How do I program the SDRAM Timing Register (SDRAM0_TR) for a specific SDRAM or DIMM?
  28. *
  29. * As an example, consider a case where PC133 memory with CAS Latency equal to 2 is being
  30. * used with a 200MHz 405GP. For a typical 128Mb, PC133 SDRAM, the relevant minimum
  31. * parameters from the datasheet are:
  32. * Tclk = 7.5ns (CL = 2)
  33. * Trp = 15ns
  34. * Trc = 60ns
  35. * Trcd = 15ns
  36. * Trfc = 66ns
  37. *
  38. * If we are operating the 405GP with the MemClk output frequency set to 100 MHZ, the clock
  39. * period is 10ns and the parameters needed for the Timing Register are:
  40. * CASL = CL = 2 clock cycles
  41. * PTA = Trp = 15ns / 10ns = 2 clock cycles
  42. * CTP = Trc - Trcd - Trp = (60ns - 15ns - 15ns) / 10ns= 3 clock cycles
  43. * LDF = 2 clock cycles (but can be extended to meet board-level timing)
  44. * RFTA = Trfc = 66ns / 10ns= 7 clock cycles
  45. * RCD = Trcd = 15ns / 10ns= 2 clock cycles
  46. *
  47. * The actual bit settings in the register would be:
  48. *
  49. * CASL = 0b01
  50. * PTA = 0b01
  51. * CTP = 0b10
  52. * LDF = 0b01
  53. * RFTA = 0b011
  54. * RCD = 0b01
  55. *
  56. * If Trfc is not specified in the datasheet for PC100 or PC133 memory, set RFTA = Trc
  57. * instead. Figure 24 in the PC SDRAM Specification Rev. 1.7 shows refresh to active delay
  58. * defined as Trc rather than Trfc.
  59. * When using DIMM modules, most but not all of the required timing parameters can be read
  60. * from the Serial Presence Detect (SPD) EEPROM on the module. Specifically, Trc and Trfc
  61. * are not available from the EEPROM
  62. */
  63. #include <common.h>
  64. #include "mip405.h"
  65. #include <asm/processor.h>
  66. #include <asm/ppc4xx.h>
  67. #include <asm/ppc4xx-i2c.h>
  68. #include <miiphy.h>
  69. #include "../common/common_util.h"
  70. #include <stdio_dev.h>
  71. #include <i2c.h>
  72. #include <rtc.h>
  73. DECLARE_GLOBAL_DATA_PTR;
  74. #undef SDRAM_DEBUG
  75. #define ENABLE_ECC /* for ecc boards */
  76. #define FALSE 0
  77. #define TRUE 1
  78. /* stdlib.h causes some compatibility problems; should fixe these! -- wd */
  79. #ifndef __ldiv_t_defined
  80. typedef struct {
  81. long int quot; /* Quotient */
  82. long int rem; /* Remainder */
  83. } ldiv_t;
  84. extern ldiv_t ldiv (long int __numer, long int __denom);
  85. # define __ldiv_t_defined 1
  86. #endif
  87. #define PLD_PART_REG PER_PLD_ADDR + 0
  88. #define PLD_VERS_REG PER_PLD_ADDR + 1
  89. #define PLD_BOARD_CFG_REG PER_PLD_ADDR + 2
  90. #define PLD_IRQ_REG PER_PLD_ADDR + 3
  91. #define PLD_COM_MODE_REG PER_PLD_ADDR + 4
  92. #define PLD_EXT_CONF_REG PER_PLD_ADDR + 5
  93. #define MEGA_BYTE (1024*1024)
  94. typedef struct {
  95. unsigned char boardtype; /* Board revision and Population Options */
  96. unsigned char cal; /* cas Latency (will be programmend as cal-1) */
  97. unsigned char trp; /* datain27 in clocks */
  98. unsigned char trcd; /* datain29 in clocks */
  99. unsigned char tras; /* datain30 in clocks */
  100. unsigned char tctp; /* tras - trcd in clocks */
  101. unsigned char am; /* Address Mod (will be programmed as am-1) */
  102. unsigned char sz; /* log binary => Size = (4MByte<<sz) 5 = 128, 4 = 64, 3 = 32, 2 = 16, 1=8 */
  103. unsigned char ecc; /* if true, ecc is enabled */
  104. } sdram_t;
  105. #if defined(CONFIG_MIP405T)
  106. const sdram_t sdram_table[] = {
  107. { 0x0F, /* MIP405T Rev A, 64MByte -1 Board */
  108. 3, /* Case Latenty = 3 */
  109. 3, /* trp 20ns / 7.5 ns datain[27] */
  110. 3, /* trcd 20ns /7.5 ns (datain[29]) */
  111. 6, /* tras 44ns /7.5 ns (datain[30]) */
  112. 4, /* tcpt 44 - 20ns = 24ns */
  113. 2, /* Address Mode = 2 (12x9x4) */
  114. 3, /* size value (32MByte) */
  115. 0}, /* ECC disabled */
  116. { 0xff, /* terminator */
  117. 0xff,
  118. 0xff,
  119. 0xff,
  120. 0xff,
  121. 0xff,
  122. 0xff,
  123. 0xff }
  124. };
  125. #else
  126. const sdram_t sdram_table[] = {
  127. { 0x0f, /* Rev A, 128MByte -1 Board */
  128. 3, /* Case Latenty = 3 */
  129. 3, /* trp 20ns / 7.5 ns datain[27] */
  130. 3, /* trcd 20ns /7.5 ns (datain[29]) */
  131. 6, /* tras 44ns /7.5 ns (datain[30]) */
  132. 4, /* tcpt 44 - 20ns = 24ns */
  133. 3, /* Address Mode = 3 */
  134. 5, /* size value */
  135. 1}, /* ECC enabled */
  136. { 0x07, /* Rev A, 64MByte -2 Board */
  137. 3, /* Case Latenty = 3 */
  138. 3, /* trp 20ns / 7.5 ns datain[27] */
  139. 3, /* trcd 20ns /7.5 ns (datain[29]) */
  140. 6, /* tras 44ns /7.5 ns (datain[30]) */
  141. 4, /* tcpt 44 - 20ns = 24ns */
  142. 2, /* Address Mode = 2 */
  143. 4, /* size value */
  144. 1}, /* ECC enabled */
  145. { 0x03, /* Rev A, 128MByte -4 Board */
  146. 3, /* Case Latenty = 3 */
  147. 3, /* trp 20ns / 7.5 ns datain[27] */
  148. 3, /* trcd 20ns /7.5 ns (datain[29]) */
  149. 6, /* tras 44ns /7.5 ns (datain[30]) */
  150. 4, /* tcpt 44 - 20ns = 24ns */
  151. 3, /* Address Mode = 3 */
  152. 5, /* size value */
  153. 1}, /* ECC enabled */
  154. { 0x1f, /* Rev B, 128MByte -3 Board */
  155. 3, /* Case Latenty = 3 */
  156. 3, /* trp 20ns / 7.5 ns datain[27] */
  157. 3, /* trcd 20ns /7.5 ns (datain[29]) */
  158. 6, /* tras 44ns /7.5 ns (datain[30]) */
  159. 4, /* tcpt 44 - 20ns = 24ns */
  160. 3, /* Address Mode = 3 */
  161. 5, /* size value */
  162. 1}, /* ECC enabled */
  163. { 0x2f, /* Rev C, 128MByte -3 Board */
  164. 3, /* Case Latenty = 3 */
  165. 3, /* trp 20ns / 7.5 ns datain[27] */
  166. 3, /* trcd 20ns /7.5 ns (datain[29]) */
  167. 6, /* tras 44ns /7.5 ns (datain[30]) */
  168. 4, /* tcpt 44 - 20ns = 24ns */
  169. 3, /* Address Mode = 3 */
  170. 5, /* size value */
  171. 1}, /* ECC enabled */
  172. { 0xff, /* terminator */
  173. 0xff,
  174. 0xff,
  175. 0xff,
  176. 0xff,
  177. 0xff,
  178. 0xff,
  179. 0xff }
  180. };
  181. #endif /*CONFIG_MIP405T */
  182. void SDRAM_err (const char *s)
  183. {
  184. #ifndef SDRAM_DEBUG
  185. (void) get_clocks ();
  186. gd->baudrate = 9600;
  187. serial_init ();
  188. #endif
  189. serial_puts ("\n");
  190. serial_puts (s);
  191. serial_puts ("\n enable SDRAM_DEBUG for more info\n");
  192. for (;;);
  193. }
  194. unsigned char get_board_revcfg (void)
  195. {
  196. out8 (PER_BOARD_ADDR, 0);
  197. return (in8 (PER_BOARD_ADDR));
  198. }
  199. #ifdef SDRAM_DEBUG
  200. void write_hex (unsigned char i)
  201. {
  202. char cc;
  203. cc = i >> 4;
  204. cc &= 0xf;
  205. if (cc > 9)
  206. serial_putc (cc + 55);
  207. else
  208. serial_putc (cc + 48);
  209. cc = i & 0xf;
  210. if (cc > 9)
  211. serial_putc (cc + 55);
  212. else
  213. serial_putc (cc + 48);
  214. }
  215. void write_4hex (unsigned long val)
  216. {
  217. write_hex ((unsigned char) (val >> 24));
  218. write_hex ((unsigned char) (val >> 16));
  219. write_hex ((unsigned char) (val >> 8));
  220. write_hex ((unsigned char) val);
  221. }
  222. #endif
  223. int init_sdram (void)
  224. {
  225. unsigned long tmp, baseaddr;
  226. unsigned short i;
  227. unsigned char trp_clocks,
  228. trcd_clocks,
  229. tras_clocks,
  230. trc_clocks;
  231. unsigned char cal_val;
  232. unsigned char bc;
  233. unsigned long sdram_tim, sdram_bank;
  234. /*i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);*/
  235. (void) get_clocks ();
  236. gd->baudrate = 9600;
  237. serial_init ();
  238. /* set up the pld */
  239. mtdcr (EBC0_CFGADDR, PB7AP);
  240. mtdcr (EBC0_CFGDATA, PLD_AP);
  241. mtdcr (EBC0_CFGADDR, PB7CR);
  242. mtdcr (EBC0_CFGDATA, PLD_CR);
  243. /* THIS IS OBSOLETE */
  244. /* set up the board rev reg*/
  245. mtdcr (EBC0_CFGADDR, PB5AP);
  246. mtdcr (EBC0_CFGDATA, BOARD_AP);
  247. mtdcr (EBC0_CFGADDR, PB5CR);
  248. mtdcr (EBC0_CFGDATA, BOARD_CR);
  249. #ifdef SDRAM_DEBUG
  250. /* get all informations from PLD */
  251. serial_puts ("\nPLD Part 0x");
  252. bc = in8 (PLD_PART_REG);
  253. write_hex (bc);
  254. serial_puts ("\nPLD Vers 0x");
  255. bc = in8 (PLD_VERS_REG);
  256. write_hex (bc);
  257. serial_puts ("\nBoard Rev 0x");
  258. bc = in8 (PLD_BOARD_CFG_REG);
  259. write_hex (bc);
  260. serial_puts ("\n");
  261. #endif
  262. /* check board */
  263. bc = in8 (PLD_PART_REG);
  264. #if defined(CONFIG_MIP405T)
  265. if((bc & 0x80)==0)
  266. SDRAM_err ("U-Boot configured for a MIP405T not for a MIP405!!!\n");
  267. #else
  268. if((bc & 0x80)==0x80)
  269. SDRAM_err ("U-Boot configured for a MIP405 not for a MIP405T!!!\n");
  270. #endif
  271. /* set-up the chipselect machine */
  272. mtdcr (EBC0_CFGADDR, PB0CR); /* get cs0 config reg */
  273. tmp = mfdcr (EBC0_CFGDATA);
  274. if ((tmp & 0x00002000) == 0) {
  275. /* MPS Boot, set up the flash */
  276. mtdcr (EBC0_CFGADDR, PB1AP);
  277. mtdcr (EBC0_CFGDATA, FLASH_AP);
  278. mtdcr (EBC0_CFGADDR, PB1CR);
  279. mtdcr (EBC0_CFGDATA, FLASH_CR);
  280. } else {
  281. /* Flash boot, set up the MPS */
  282. mtdcr (EBC0_CFGADDR, PB1AP);
  283. mtdcr (EBC0_CFGDATA, MPS_AP);
  284. mtdcr (EBC0_CFGADDR, PB1CR);
  285. mtdcr (EBC0_CFGDATA, MPS_CR);
  286. }
  287. /* set up UART0 (CS2) and UART1 (CS3) */
  288. mtdcr (EBC0_CFGADDR, PB2AP);
  289. mtdcr (EBC0_CFGDATA, UART0_AP);
  290. mtdcr (EBC0_CFGADDR, PB2CR);
  291. mtdcr (EBC0_CFGDATA, UART0_CR);
  292. mtdcr (EBC0_CFGADDR, PB3AP);
  293. mtdcr (EBC0_CFGDATA, UART1_AP);
  294. mtdcr (EBC0_CFGADDR, PB3CR);
  295. mtdcr (EBC0_CFGDATA, UART1_CR);
  296. bc = in8 (PLD_BOARD_CFG_REG);
  297. #ifdef SDRAM_DEBUG
  298. serial_puts ("\nstart SDRAM Setup\n");
  299. serial_puts ("\nBoard Rev: ");
  300. write_hex (bc);
  301. serial_puts ("\n");
  302. #endif
  303. i = 0;
  304. baseaddr = CONFIG_SYS_SDRAM_BASE;
  305. while (sdram_table[i].sz != 0xff) {
  306. if (sdram_table[i].boardtype == bc)
  307. break;
  308. i++;
  309. }
  310. if (sdram_table[i].boardtype != bc)
  311. SDRAM_err ("No SDRAM table found for this board!!!\n");
  312. #ifdef SDRAM_DEBUG
  313. serial_puts (" found table ");
  314. write_hex (i);
  315. serial_puts (" \n");
  316. #endif
  317. /* since the ECC initialisation needs some time,
  318. * we show that we're alive
  319. */
  320. if (sdram_table[i].ecc)
  321. serial_puts ("\nInitializing SDRAM, Please stand by");
  322. cal_val = sdram_table[i].cal - 1; /* Cas Latency */
  323. trp_clocks = sdram_table[i].trp; /* 20ns / 7.5 ns datain[27] */
  324. trcd_clocks = sdram_table[i].trcd; /* 20ns /7.5 ns (datain[29]) */
  325. tras_clocks = sdram_table[i].tras; /* 44ns /7.5 ns (datain[30]) */
  326. /* ctp = ((trp + tras) - trp - trcd) => tras - trcd */
  327. /* trc_clocks is sum of trp_clocks + tras_clocks */
  328. trc_clocks = trp_clocks + tras_clocks;
  329. /* get SDRAM timing register */
  330. mtdcr (SDRAM0_CFGADDR, SDRAM0_TR);
  331. sdram_tim = mfdcr (SDRAM0_CFGDATA) & ~0x018FC01F;
  332. /* insert CASL value */
  333. sdram_tim |= ((unsigned long) (cal_val)) << 23;
  334. /* insert PTA value */
  335. sdram_tim |= ((unsigned long) (trp_clocks - 1)) << 18;
  336. /* insert CTP value */
  337. sdram_tim |=
  338. ((unsigned long) (trc_clocks - trp_clocks -
  339. trcd_clocks)) << 16;
  340. /* insert LDF (always 01) */
  341. sdram_tim |= ((unsigned long) 0x01) << 14;
  342. /* insert RFTA value */
  343. sdram_tim |= ((unsigned long) (trc_clocks - 4)) << 2;
  344. /* insert RCD value */
  345. sdram_tim |= ((unsigned long) (trcd_clocks - 1)) << 0;
  346. tmp = ((unsigned long) (sdram_table[i].am - 1) << 13); /* AM = 3 */
  347. /* insert SZ value; */
  348. tmp |= ((unsigned long) sdram_table[i].sz << 17);
  349. /* get SDRAM bank 0 register */
  350. mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
  351. sdram_bank = mfdcr (SDRAM0_CFGDATA) & ~0xFFCEE001;
  352. sdram_bank |= (baseaddr | tmp | 0x01);
  353. #ifdef SDRAM_DEBUG
  354. serial_puts ("sdtr: ");
  355. write_4hex (sdram_tim);
  356. serial_puts ("\n");
  357. #endif
  358. /* write SDRAM timing register */
  359. mtdcr (SDRAM0_CFGADDR, SDRAM0_TR);
  360. mtdcr (SDRAM0_CFGDATA, sdram_tim);
  361. #ifdef SDRAM_DEBUG
  362. serial_puts ("mb0cf: ");
  363. write_4hex (sdram_bank);
  364. serial_puts ("\n");
  365. #endif
  366. /* write SDRAM bank 0 register */
  367. mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
  368. mtdcr (SDRAM0_CFGDATA, sdram_bank);
  369. if (get_bus_freq (tmp) > 110000000) { /* > 110MHz */
  370. /* get SDRAM refresh interval register */
  371. mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
  372. tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000;
  373. tmp |= 0x07F00000;
  374. } else {
  375. /* get SDRAM refresh interval register */
  376. mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
  377. tmp = mfdcr (SDRAM0_CFGDATA) & ~0x3FF80000;
  378. tmp |= 0x05F00000;
  379. }
  380. /* write SDRAM refresh interval register */
  381. mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
  382. mtdcr (SDRAM0_CFGDATA, tmp);
  383. /* enable ECC if used */
  384. #if defined(ENABLE_ECC) && !defined(CONFIG_BOOT_PCI)
  385. if (sdram_table[i].ecc) {
  386. /* disable checking for all banks */
  387. unsigned long *p;
  388. #ifdef SDRAM_DEBUG
  389. serial_puts ("disable ECC.. ");
  390. #endif
  391. mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
  392. tmp = mfdcr (SDRAM0_CFGDATA);
  393. tmp &= 0xff0fffff; /* disable all banks */
  394. mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
  395. /* set up SDRAM Controller with ECC enabled */
  396. #ifdef SDRAM_DEBUG
  397. serial_puts ("setup SDRAM Controller.. ");
  398. #endif
  399. mtdcr (SDRAM0_CFGDATA, tmp);
  400. mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
  401. tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x90800000;
  402. mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
  403. mtdcr (SDRAM0_CFGDATA, tmp);
  404. udelay (600);
  405. #ifdef SDRAM_DEBUG
  406. serial_puts ("fill the memory..\n");
  407. #endif
  408. serial_puts (".");
  409. /* now, fill all the memory */
  410. tmp = ((4 * MEGA_BYTE) << sdram_table[i].sz);
  411. p = (unsigned long) 0;
  412. while ((unsigned long) p < tmp) {
  413. *p++ = 0L;
  414. if (!((unsigned long) p % 0x00800000)) /* every 8MByte */
  415. serial_puts (".");
  416. }
  417. /* enable bank 0 */
  418. serial_puts (".");
  419. #ifdef SDRAM_DEBUG
  420. serial_puts ("enable ECC\n");
  421. #endif
  422. udelay (400);
  423. mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
  424. tmp = mfdcr (SDRAM0_CFGDATA);
  425. tmp |= 0x00800000; /* enable bank 0 */
  426. mtdcr (SDRAM0_CFGDATA, tmp);
  427. udelay (400);
  428. } else
  429. #endif
  430. {
  431. /* enable SDRAM controller with no ECC, 32-bit SDRAM width, 16 byte burst */
  432. mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
  433. tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x80C00000;
  434. mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
  435. mtdcr (SDRAM0_CFGDATA, tmp);
  436. udelay (400);
  437. }
  438. serial_puts ("\n");
  439. return (0);
  440. }
  441. int board_early_init_f (void)
  442. {
  443. init_sdram ();
  444. /*-------------------------------------------------------------------------+
  445. | Interrupt controller setup for the PIP405 board.
  446. | Note: IRQ 0-15 405GP internally generated; active high; level sensitive
  447. | IRQ 16 405GP internally generated; active low; level sensitive
  448. | IRQ 17-24 RESERVED
  449. | IRQ 25 (EXT IRQ 0) SouthBridge; active low; level sensitive
  450. | IRQ 26 (EXT IRQ 1) NMI: active low; level sensitive
  451. | IRQ 27 (EXT IRQ 2) SMI: active Low; level sensitive
  452. | IRQ 28 (EXT IRQ 3) PCI SLOT 3; active low; level sensitive
  453. | IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  454. | IRQ 30 (EXT IRQ 5) PCI SLOT 1; active low; level sensitive
  455. | IRQ 31 (EXT IRQ 6) PCI SLOT 0; active low; level sensitive
  456. | Note for MIP405 board:
  457. | An interrupt taken for the SouthBridge (IRQ 25) indicates that
  458. | the Interrupt Controller in the South Bridge has caused the
  459. | interrupt. The IC must be read to determine which device
  460. | caused the interrupt.
  461. |
  462. +-------------------------------------------------------------------------*/
  463. mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
  464. mtdcr (UIC0ER, 0x00000000); /* disable all ints */
  465. mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical (for now) */
  466. mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */
  467. mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
  468. mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */
  469. mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
  470. return 0;
  471. }
  472. int board_early_init_r(void)
  473. {
  474. int mode;
  475. /*
  476. * since we are relocated, we can finally enable i-cache
  477. * and set up the flash CS correctly
  478. */
  479. icache_enable();
  480. setup_cs_reloc();
  481. /* get and display boot mode */
  482. mode = get_boot_mode();
  483. if (mode & BOOT_PCI)
  484. printf("PCI Boot %s Map\n", (mode & BOOT_MPS) ?
  485. "MPS" : "Flash");
  486. else
  487. printf("%s Boot\n", (mode & BOOT_MPS) ?
  488. "MPS" : "Flash");
  489. return 0;
  490. }
  491. /*
  492. * Get some PLD Registers
  493. */
  494. unsigned short get_pld_parvers (void)
  495. {
  496. unsigned short result;
  497. unsigned char rc;
  498. rc = in8 (PLD_PART_REG);
  499. result = (unsigned short) rc << 8;
  500. rc = in8 (PLD_VERS_REG);
  501. result |= rc;
  502. return result;
  503. }
  504. void user_led0 (unsigned char on)
  505. {
  506. if (on)
  507. out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x4));
  508. else
  509. out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfb));
  510. }
  511. void ide_set_reset (int idereset)
  512. {
  513. /* if reset = 1 IDE reset will be asserted */
  514. if (idereset)
  515. out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) | 0x1));
  516. else {
  517. udelay (10000);
  518. out8 (PLD_COM_MODE_REG, (in8 (PLD_COM_MODE_REG) & 0xfe));
  519. }
  520. }
  521. /* ------------------------------------------------------------------------- */
  522. void get_pcbrev_var(unsigned char *pcbrev, unsigned char *var)
  523. {
  524. #if !defined(CONFIG_MIP405T)
  525. unsigned char bc,rc,tmp;
  526. int i;
  527. bc = in8 (PLD_BOARD_CFG_REG);
  528. tmp = ~bc;
  529. tmp &= 0xf;
  530. rc = 0;
  531. for (i = 0; i < 4; i++) {
  532. rc <<= 1;
  533. rc += (tmp & 0x1);
  534. tmp >>= 1;
  535. }
  536. rc++;
  537. if(( (((bc>>4) & 0xf)==0x2) /* Rev C PCB or */
  538. || (((bc>>4) & 0xf)==0x1)) /* Rev B PCB with */
  539. && (rc==0x1)) /* Population Option 1 is a -3 */
  540. rc=3;
  541. *pcbrev=(bc >> 4) & 0xf;
  542. *var=rc;
  543. #else
  544. unsigned char bc;
  545. bc = in8 (PLD_BOARD_CFG_REG);
  546. *pcbrev=(bc >> 4) & 0xf;
  547. *var=16-(bc & 0xf);
  548. #endif
  549. }
  550. /*
  551. * Check Board Identity:
  552. */
  553. /* serial String: "MIP405_1000" OR "MIP405T_1000" */
  554. #if !defined(CONFIG_MIP405T)
  555. #define BOARD_NAME "MIP405"
  556. #else
  557. #define BOARD_NAME "MIP405T"
  558. #endif
  559. int checkboard (void)
  560. {
  561. char s[50];
  562. unsigned char bc, var;
  563. int i;
  564. backup_t *b = (backup_t *) s;
  565. puts ("Board: ");
  566. get_pcbrev_var(&bc,&var);
  567. i = getenv_f("serial#", (char *)s, 32);
  568. if ((i == 0) || strncmp ((char *)s, BOARD_NAME,sizeof(BOARD_NAME))) {
  569. get_backup_values (b);
  570. if (strncmp (b->signature, "MPL\0", 4) != 0) {
  571. puts ("### No HW ID - assuming " BOARD_NAME);
  572. printf ("-%d Rev %c", var, 'A' + bc);
  573. } else {
  574. b->serial_name[sizeof(BOARD_NAME)-1] = 0;
  575. printf ("%s-%d Rev %c SN: %s", b->serial_name, var,
  576. 'A' + bc, &b->serial_name[sizeof(BOARD_NAME)]);
  577. }
  578. } else {
  579. s[sizeof(BOARD_NAME)-1] = 0;
  580. printf ("%s-%d Rev %c SN: %s", s, var,'A' + bc,
  581. &s[sizeof(BOARD_NAME)]);
  582. }
  583. bc = in8 (PLD_EXT_CONF_REG);
  584. printf (" Boot Config: 0x%x\n", bc);
  585. return (0);
  586. }
  587. /* ------------------------------------------------------------------------- */
  588. /* ------------------------------------------------------------------------- */
  589. /*
  590. initdram(int board_type) reads EEPROM via I2c. EEPROM contains all of
  591. the necessary info for SDRAM controller configuration
  592. */
  593. /* ------------------------------------------------------------------------- */
  594. /* ------------------------------------------------------------------------- */
  595. static int test_dram (unsigned long ramsize);
  596. phys_size_t initdram (int board_type)
  597. {
  598. unsigned long bank_reg[4], tmp, bank_size;
  599. int i;
  600. unsigned long TotalSize;
  601. /* since the DRAM controller is allready set up, calculate the size with the
  602. bank registers */
  603. mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
  604. bank_reg[0] = mfdcr (SDRAM0_CFGDATA);
  605. mtdcr (SDRAM0_CFGADDR, SDRAM0_B1CR);
  606. bank_reg[1] = mfdcr (SDRAM0_CFGDATA);
  607. mtdcr (SDRAM0_CFGADDR, SDRAM0_B2CR);
  608. bank_reg[2] = mfdcr (SDRAM0_CFGDATA);
  609. mtdcr (SDRAM0_CFGADDR, SDRAM0_B3CR);
  610. bank_reg[3] = mfdcr (SDRAM0_CFGDATA);
  611. TotalSize = 0;
  612. for (i = 0; i < 4; i++) {
  613. if ((bank_reg[i] & 0x1) == 0x1) {
  614. tmp = (bank_reg[i] >> 17) & 0x7;
  615. bank_size = 4 << tmp;
  616. TotalSize += bank_size;
  617. }
  618. }
  619. mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
  620. tmp = mfdcr (SDRAM0_CFGDATA);
  621. if (!tmp)
  622. printf ("No ");
  623. printf ("ECC ");
  624. test_dram (TotalSize * MEGA_BYTE);
  625. return (TotalSize * MEGA_BYTE);
  626. }
  627. /* ------------------------------------------------------------------------- */
  628. static int test_dram (unsigned long ramsize)
  629. {
  630. #ifdef SDRAM_DEBUG
  631. mem_test (0L, ramsize, 1);
  632. #endif
  633. /* not yet implemented */
  634. return (1);
  635. }
  636. /* used to check if the time in RTC is valid */
  637. static unsigned long start;
  638. static struct rtc_time tm;
  639. int misc_init_r (void)
  640. {
  641. /* adjust flash start and size as well as the offset */
  642. gd->bd->bi_flashstart=0-flash_info[0].size;
  643. gd->bd->bi_flashsize=flash_info[0].size-CONFIG_SYS_MONITOR_LEN;
  644. gd->bd->bi_flashoffset=0;
  645. /* check, if RTC is running */
  646. rtc_get (&tm);
  647. start=get_timer(0);
  648. /* if MIP405 has booted from PCI, reset CCR0[24] as described in errata PCI_18 */
  649. if (mfdcr(CPC0_PSR) & PSR_ROM_LOC)
  650. mtspr(SPRN_CCR0, (mfspr(SPRN_CCR0) & ~0x80));
  651. return (0);
  652. }
  653. void print_mip405_rev (void)
  654. {
  655. unsigned char part, vers, pcbrev, var;
  656. get_pcbrev_var(&pcbrev,&var);
  657. part = in8 (PLD_PART_REG);
  658. vers = in8 (PLD_VERS_REG);
  659. printf ("Rev: " BOARD_NAME "-%d Rev %c PLD %d Vers %d\n",
  660. var, pcbrev + 'A', part & 0x7F, vers);
  661. }
  662. extern int mk_date (char *, struct rtc_time *);
  663. int last_stage_init (void)
  664. {
  665. unsigned long stop;
  666. struct rtc_time newtm;
  667. char *s;
  668. /* write correct LED configuration */
  669. if (miiphy_write("ppc_4xx_eth0", 0x1, 0x14, 0x2402) != 0) {
  670. printf ("Error writing to the PHY\n");
  671. }
  672. /* since LED/CFG2 is not connected on the -2,
  673. * write to correct capability information */
  674. if (miiphy_write("ppc_4xx_eth0", 0x1, 0x4, 0x01E1) != 0) {
  675. printf ("Error writing to the PHY\n");
  676. }
  677. print_mip405_rev ();
  678. stdio_print_current_devices ();
  679. check_env ();
  680. /* check if RTC time is valid */
  681. stop=get_timer(start);
  682. while(stop<1200) { /* we wait 1.2 sec to check if the RTC is running */
  683. udelay(1000);
  684. stop=get_timer(start);
  685. }
  686. rtc_get (&newtm);
  687. if(tm.tm_sec==newtm.tm_sec) {
  688. s=getenv("defaultdate");
  689. if(!s)
  690. mk_date ("010112001970", &newtm);
  691. else
  692. if(mk_date (s, &newtm)!=0) {
  693. printf("RTC: Bad date format in defaultdate\n");
  694. return 0;
  695. }
  696. rtc_reset ();
  697. rtc_set(&newtm);
  698. }
  699. return 0;
  700. }
  701. /***************************************************************************
  702. * some helping routines
  703. */
  704. int overwrite_console (void)
  705. {
  706. return ((in8 (PLD_EXT_CONF_REG) & 0x1)==0); /* return TRUE if console should be overwritten */
  707. }
  708. /************************************************************************
  709. * Print MIP405 Info
  710. ************************************************************************/
  711. void print_mip405_info (void)
  712. {
  713. unsigned char part, vers, cfg, irq_reg, com_mode, ext;
  714. part = in8 (PLD_PART_REG);
  715. vers = in8 (PLD_VERS_REG);
  716. cfg = in8 (PLD_BOARD_CFG_REG);
  717. irq_reg = in8 (PLD_IRQ_REG);
  718. com_mode = in8 (PLD_COM_MODE_REG);
  719. ext = in8 (PLD_EXT_CONF_REG);
  720. printf ("PLD Part %d version %d\n", part & 0x7F, vers);
  721. printf ("Board Revision %c\n", ((cfg >> 4) & 0xf) + 'A');
  722. printf ("Population Options %d %d %d %d\n", (cfg) & 0x1,
  723. (cfg >> 1) & 0x1, (cfg >> 2) & 0x1, (cfg >> 3) & 0x1);
  724. printf ("User LED %s\n", (com_mode & 0x4) ? "on" : "off");
  725. printf ("UART Clocks %d\n", (com_mode >> 4) & 0x3);
  726. #if !defined(CONFIG_MIP405T)
  727. printf ("User Config Switch %d %d %d %d %d %d %d %d\n",
  728. (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1,
  729. (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1,
  730. (ext >> 6) & 0x1, (ext >> 7) & 0x1);
  731. printf ("SER1 uses handshakes %s\n",
  732. (ext & 0x80) ? "DTR/DSR" : "RTS/CTS");
  733. #else
  734. printf ("User Config Switch %d %d %d %d %d %d %d %d\n",
  735. (ext) & 0x1, (ext >> 1) & 0x1, (ext >> 2) & 0x1,
  736. (ext >> 3) & 0x1, (ext >> 4) & 0x1, (ext >> 5) & 0x1,
  737. (ext >> 6) & 0x1,(ext >> 7) & 0x1);
  738. #endif
  739. printf ("IDE Reset %s\n", (ext & 0x01) ? "asserted" : "not asserted");
  740. printf ("IRQs:\n");
  741. printf (" PIIX INTR: %s\n", (irq_reg & 0x80) ? "inactive" : "active");
  742. #if !defined(CONFIG_MIP405T)
  743. printf (" UART0 IRQ: %s\n", (irq_reg & 0x40) ? "inactive" : "active");
  744. printf (" UART1 IRQ: %s\n", (irq_reg & 0x20) ? "inactive" : "active");
  745. #endif
  746. printf (" PIIX SMI: %s\n", (irq_reg & 0x10) ? "inactive" : "active");
  747. printf (" PIIX INIT: %s\n", (irq_reg & 0x8) ? "inactive" : "active");
  748. printf (" PIIX NMI: %s\n", (irq_reg & 0x4) ? "inactive" : "active");
  749. }