pip405.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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. #include <common.h>
  27. #include "pip405.h"
  28. #include <asm/processor.h>
  29. #include <i2c.h>
  30. #include "../common/isa.h"
  31. #include "../common/common_util.h"
  32. #undef SDRAM_DEBUG
  33. #define FALSE 0
  34. #define TRUE 1
  35. /* stdlib.h causes some compatibility problems; should fixe these! -- wd */
  36. #ifndef __ldiv_t_defined
  37. typedef struct {
  38. long int quot; /* Quotient */
  39. long int rem; /* Remainder */
  40. } ldiv_t;
  41. extern ldiv_t ldiv (long int __numer, long int __denom);
  42. # define __ldiv_t_defined 1
  43. #endif
  44. typedef enum {
  45. SDRAM_NO_ERR,
  46. SDRAM_SPD_COMM_ERR,
  47. SDRAM_SPD_CHKSUM_ERR,
  48. SDRAM_UNSUPPORTED_ERR,
  49. SDRAM_UNKNOWN_ERR
  50. } SDRAM_ERR;
  51. typedef struct {
  52. const unsigned char mode;
  53. const unsigned char row;
  54. const unsigned char col;
  55. const unsigned char bank;
  56. } SDRAM_SETUP;
  57. static const SDRAM_SETUP sdram_setup_table[] = {
  58. {1, 11, 9, 2},
  59. {1, 11, 10, 2},
  60. {2, 12, 9, 4},
  61. {2, 12, 10, 4},
  62. {3, 13, 9, 4},
  63. {3, 13, 10, 4},
  64. {3, 13, 11, 4},
  65. {4, 12, 8, 2},
  66. {4, 12, 8, 4},
  67. {5, 11, 8, 2},
  68. {5, 11, 8, 4},
  69. {6, 13, 8, 2},
  70. {6, 13, 8, 4},
  71. {7, 13, 9, 2},
  72. {7, 13, 10, 2},
  73. {0, 0, 0, 0}
  74. };
  75. static const unsigned char cal_indextable[] = {
  76. 9, 23, 25
  77. };
  78. /*
  79. * translate ns.ns/10 coding of SPD timing values
  80. * into 10 ps unit values
  81. */
  82. unsigned short NS10to10PS (unsigned char spd_byte, unsigned char spd_version)
  83. {
  84. unsigned short ns, ns10;
  85. /* isolate upper nibble */
  86. ns = (spd_byte >> 4) & 0x0F;
  87. /* isolate lower nibble */
  88. ns10 = (spd_byte & 0x0F);
  89. return (ns * 100 + ns10 * 10);
  90. }
  91. /*
  92. * translate ns.ns/4 coding of SPD timing values
  93. * into 10 ps unit values
  94. */
  95. unsigned short NS4to10PS (unsigned char spd_byte, unsigned char spd_version)
  96. {
  97. unsigned short ns, ns4;
  98. /* isolate upper 6 bits */
  99. ns = (spd_byte >> 2) & 0x3F;
  100. /* isloate lower 2 bits */
  101. ns4 = (spd_byte & 0x03);
  102. return (ns * 100 + ns4 * 25);
  103. }
  104. /*
  105. * translate ns coding of SPD timing values
  106. * into 10 ps unit values
  107. */
  108. unsigned short NSto10PS (unsigned char spd_byte)
  109. {
  110. return (spd_byte * 100);
  111. }
  112. void SDRAM_err (const char *s)
  113. {
  114. #ifndef SDRAM_DEBUG
  115. DECLARE_GLOBAL_DATA_PTR;
  116. (void) get_clocks ();
  117. gd->baudrate = 9600;
  118. serial_init ();
  119. #endif
  120. serial_puts ("\n");
  121. serial_puts (s);
  122. serial_puts ("\n enable SDRAM_DEBUG for more info\n");
  123. for (;;);
  124. }
  125. #ifdef SDRAM_DEBUG
  126. void write_hex (unsigned char i)
  127. {
  128. char cc;
  129. cc = i >> 4;
  130. cc &= 0xf;
  131. if (cc > 9)
  132. serial_putc (cc + 55);
  133. else
  134. serial_putc (cc + 48);
  135. cc = i & 0xf;
  136. if (cc > 9)
  137. serial_putc (cc + 55);
  138. else
  139. serial_putc (cc + 48);
  140. }
  141. void write_4hex (unsigned long val)
  142. {
  143. write_hex ((unsigned char) (val >> 24));
  144. write_hex ((unsigned char) (val >> 16));
  145. write_hex ((unsigned char) (val >> 8));
  146. write_hex ((unsigned char) val);
  147. }
  148. #endif
  149. int board_early_init_f (void)
  150. {
  151. unsigned char dataout[1];
  152. unsigned char datain[128];
  153. unsigned long sdram_size = 0;
  154. SDRAM_SETUP *t = (SDRAM_SETUP *) sdram_setup_table;
  155. unsigned long memclk;
  156. unsigned long tmemclk = 0;
  157. unsigned long tmp, bank, baseaddr, bank_size;
  158. unsigned short i;
  159. unsigned char rows, cols, banks, sdram_banks, density;
  160. unsigned char supported_cal, trp_clocks, trcd_clocks, tras_clocks,
  161. trc_clocks, tctp_clocks;
  162. unsigned char cal_index, cal_val, spd_version, spd_chksum;
  163. unsigned char buf[8];
  164. #ifdef SDRAM_DEBUG
  165. DECLARE_GLOBAL_DATA_PTR;
  166. #endif
  167. /* set up the config port */
  168. mtdcr (ebccfga, pb7ap);
  169. mtdcr (ebccfgd, CONFIG_PORT_AP);
  170. mtdcr (ebccfga, pb7cr);
  171. mtdcr (ebccfgd, CONFIG_PORT_CR);
  172. memclk = get_bus_freq (tmemclk);
  173. tmemclk = 1000000000 / (memclk / 100); /* in 10 ps units */
  174. #ifdef SDRAM_DEBUG
  175. (void) get_clocks ();
  176. gd->baudrate = 9600;
  177. serial_init ();
  178. serial_puts ("\nstart SDRAM Setup\n");
  179. #endif
  180. /* Read Serial Presence Detect Information */
  181. i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
  182. dataout[0] = 0;
  183. for (i = 0; i < 128; i++)
  184. datain[i] = 127;
  185. i2c_read(SPD_EEPROM_ADDRESS,0,1,datain,128);
  186. #ifdef SDRAM_DEBUG
  187. serial_puts ("\ni2c_read returns ");
  188. write_hex (i);
  189. serial_puts ("\n");
  190. #endif
  191. #ifdef SDRAM_DEBUG
  192. for (i = 0; i < 128; i++) {
  193. write_hex (datain[i]);
  194. serial_puts (" ");
  195. if (((i + 1) % 16) == 0)
  196. serial_puts ("\n");
  197. }
  198. serial_puts ("\n");
  199. #endif
  200. spd_chksum = 0;
  201. for (i = 0; i < 63; i++) {
  202. spd_chksum += datain[i];
  203. } /* endfor */
  204. if (datain[63] != spd_chksum) {
  205. #ifdef SDRAM_DEBUG
  206. serial_puts ("SPD chksum: 0x");
  207. write_hex (datain[63]);
  208. serial_puts (" != calc. chksum: 0x");
  209. write_hex (spd_chksum);
  210. serial_puts ("\n");
  211. #endif
  212. SDRAM_err ("SPD checksum Error");
  213. }
  214. /* SPD seems to be ok, use it */
  215. /* get SPD version */
  216. spd_version = datain[62];
  217. /* do some sanity checks on the kind of RAM */
  218. if ((datain[0] < 0x80) || /* less than 128 valid bytes in SPD */
  219. (datain[2] != 0x04) || /* if not SDRAM */
  220. (!((datain[6] == 0x40) || (datain[6] == 0x48))) || /* or not (64 Bit or 72 Bit) */
  221. (datain[7] != 0x00) || (datain[8] != 0x01) || /* or not LVTTL signal levels */
  222. (datain[126] == 0x66)) /* or a 66Mhz modules */
  223. SDRAM_err ("unsupported SDRAM");
  224. #ifdef SDRAM_DEBUG
  225. serial_puts ("SDRAM sanity ok\n");
  226. #endif
  227. /* get number of rows/cols/banks out of byte 3+4+5 */
  228. rows = datain[3];
  229. cols = datain[4];
  230. banks = datain[5];
  231. /* get number of SDRAM banks out of byte 17 and
  232. supported CAS latencies out of byte 18 */
  233. sdram_banks = datain[17];
  234. supported_cal = datain[18] & ~0x81;
  235. while (t->mode != 0) {
  236. if ((t->row == rows) && (t->col == cols)
  237. && (t->bank == sdram_banks))
  238. break;
  239. t++;
  240. } /* endwhile */
  241. #ifdef SDRAM_DEBUG
  242. serial_puts ("rows: ");
  243. write_hex (rows);
  244. serial_puts (" cols: ");
  245. write_hex (cols);
  246. serial_puts (" banks: ");
  247. write_hex (banks);
  248. serial_puts (" mode: ");
  249. write_hex (t->mode);
  250. serial_puts ("\n");
  251. #endif
  252. if (t->mode == 0)
  253. SDRAM_err ("unsupported SDRAM");
  254. /* get tRP, tRCD, tRAS and density from byte 27+29+30+31 */
  255. #ifdef SDRAM_DEBUG
  256. serial_puts ("tRP: ");
  257. write_hex (datain[27]);
  258. serial_puts ("\ntRCD: ");
  259. write_hex (datain[29]);
  260. serial_puts ("\ntRAS: ");
  261. write_hex (datain[30]);
  262. serial_puts ("\n");
  263. #endif
  264. trp_clocks = (NSto10PS (datain[27]) + (tmemclk - 1)) / tmemclk;
  265. trcd_clocks = (NSto10PS (datain[29]) + (tmemclk - 1)) / tmemclk;
  266. tras_clocks = (NSto10PS (datain[30]) + (tmemclk - 1)) / tmemclk;
  267. density = datain[31];
  268. /* trc_clocks is sum of trp_clocks + tras_clocks */
  269. trc_clocks = trp_clocks + tras_clocks;
  270. /* ctp = ((trp + tras) - trp - trcd) => tras - trcd */
  271. tctp_clocks =
  272. ((NSto10PS (datain[30]) - NSto10PS (datain[29])) +
  273. (tmemclk - 1)) / tmemclk;
  274. #ifdef SDRAM_DEBUG
  275. serial_puts ("c_RP: ");
  276. write_hex (trp_clocks);
  277. serial_puts ("\nc_RCD: ");
  278. write_hex (trcd_clocks);
  279. serial_puts ("\nc_RAS: ");
  280. write_hex (tras_clocks);
  281. serial_puts ("\nc_RC: (RP+RAS): ");
  282. write_hex (trc_clocks);
  283. serial_puts ("\nc_CTP: ((RP+RAS)-RP-RCD): ");
  284. write_hex (tctp_clocks);
  285. serial_puts ("\nt_CTP: RAS - RCD: ");
  286. write_hex ((unsigned
  287. char) ((NSto10PS (datain[30]) -
  288. NSto10PS (datain[29])) >> 8));
  289. write_hex ((unsigned char) (NSto10PS (datain[30]) - NSto10PS (datain[29])));
  290. serial_puts ("\ntmemclk: ");
  291. write_hex ((unsigned char) (tmemclk >> 8));
  292. write_hex ((unsigned char) (tmemclk));
  293. serial_puts ("\n");
  294. #endif
  295. cal_val = 255;
  296. for (i = 6, cal_index = 0; (i > 0) && (cal_index < 3); i--) {
  297. /* is this CAS latency supported ? */
  298. if ((supported_cal >> i) & 0x01) {
  299. buf[0] = datain[cal_indextable[cal_index]];
  300. if (cal_index < 2) {
  301. if (NS10to10PS (buf[0], spd_version) <= tmemclk)
  302. cal_val = i;
  303. } else {
  304. /* SPD bytes 25+26 have another format */
  305. if (NS4to10PS (buf[0], spd_version) <= tmemclk)
  306. cal_val = i;
  307. } /* endif */
  308. cal_index++;
  309. } /* endif */
  310. } /* endfor */
  311. #ifdef SDRAM_DEBUG
  312. serial_puts ("CAL: ");
  313. write_hex (cal_val + 1);
  314. serial_puts ("\n");
  315. #endif
  316. if (cal_val == 255)
  317. SDRAM_err ("unsupported SDRAM");
  318. /* get SDRAM timing register */
  319. mtdcr (memcfga, mem_sdtr1);
  320. tmp = mfdcr (memcfgd) & ~0x018FC01F;
  321. /* insert CASL value */
  322. /* tmp |= ((unsigned long)cal_val) << 23; */
  323. tmp |= ((unsigned long) cal_val) << 23;
  324. /* insert PTA value */
  325. tmp |= ((unsigned long) (trp_clocks - 1)) << 18;
  326. /* insert CTP value */
  327. /* tmp |= ((unsigned long)(trc_clocks - trp_clocks - trcd_clocks - 1)) << 16; */
  328. tmp |= ((unsigned long) (trc_clocks - trp_clocks - trcd_clocks)) << 16;
  329. /* insert LDF (always 01) */
  330. tmp |= ((unsigned long) 0x01) << 14;
  331. /* insert RFTA value */
  332. tmp |= ((unsigned long) (trc_clocks - 4)) << 2;
  333. /* insert RCD value */
  334. tmp |= ((unsigned long) (trcd_clocks - 1)) << 0;
  335. #ifdef SDRAM_DEBUG
  336. serial_puts ("sdtr: ");
  337. write_4hex (tmp);
  338. serial_puts ("\n");
  339. #endif
  340. /* write SDRAM timing register */
  341. mtdcr (memcfga, mem_sdtr1);
  342. mtdcr (memcfgd, tmp);
  343. baseaddr = CFG_SDRAM_BASE;
  344. bank_size = (((unsigned long) density) << 22) / 2;
  345. /* insert AM value */
  346. tmp = ((unsigned long) t->mode - 1) << 13;
  347. /* insert SZ value; */
  348. switch (bank_size) {
  349. case 0x00400000:
  350. tmp |= ((unsigned long) 0x00) << 17;
  351. break;
  352. case 0x00800000:
  353. tmp |= ((unsigned long) 0x01) << 17;
  354. break;
  355. case 0x01000000:
  356. tmp |= ((unsigned long) 0x02) << 17;
  357. break;
  358. case 0x02000000:
  359. tmp |= ((unsigned long) 0x03) << 17;
  360. break;
  361. case 0x04000000:
  362. tmp |= ((unsigned long) 0x04) << 17;
  363. break;
  364. case 0x08000000:
  365. tmp |= ((unsigned long) 0x05) << 17;
  366. break;
  367. case 0x10000000:
  368. tmp |= ((unsigned long) 0x06) << 17;
  369. break;
  370. default:
  371. SDRAM_err ("unsupported SDRAM");
  372. } /* endswitch */
  373. /* get SDRAM bank 0 register */
  374. mtdcr (memcfga, mem_mb0cf);
  375. bank = mfdcr (memcfgd) & ~0xFFCEE001;
  376. bank |= (baseaddr | tmp | 0x01);
  377. #ifdef SDRAM_DEBUG
  378. serial_puts ("bank0: baseaddr: ");
  379. write_4hex (baseaddr);
  380. serial_puts (" banksize: ");
  381. write_4hex (bank_size);
  382. serial_puts (" mb0cf: ");
  383. write_4hex (bank);
  384. serial_puts ("\n");
  385. #endif
  386. baseaddr += bank_size;
  387. sdram_size += bank_size;
  388. /* write SDRAM bank 0 register */
  389. mtdcr (memcfga, mem_mb0cf);
  390. mtdcr (memcfgd, bank);
  391. /* get SDRAM bank 1 register */
  392. mtdcr (memcfga, mem_mb1cf);
  393. bank = mfdcr (memcfgd) & ~0xFFCEE001;
  394. sdram_size = 0;
  395. #ifdef SDRAM_DEBUG
  396. serial_puts ("bank1: baseaddr: ");
  397. write_4hex (baseaddr);
  398. serial_puts (" banksize: ");
  399. write_4hex (bank_size);
  400. #endif
  401. if (banks == 2) {
  402. bank |= (baseaddr | tmp | 0x01);
  403. baseaddr += bank_size;
  404. sdram_size += bank_size;
  405. } /* endif */
  406. #ifdef SDRAM_DEBUG
  407. serial_puts (" mb1cf: ");
  408. write_4hex (bank);
  409. serial_puts ("\n");
  410. #endif
  411. /* write SDRAM bank 1 register */
  412. mtdcr (memcfga, mem_mb1cf);
  413. mtdcr (memcfgd, bank);
  414. /* get SDRAM bank 2 register */
  415. mtdcr (memcfga, mem_mb2cf);
  416. bank = mfdcr (memcfgd) & ~0xFFCEE001;
  417. bank |= (baseaddr | tmp | 0x01);
  418. #ifdef SDRAM_DEBUG
  419. serial_puts ("bank2: baseaddr: ");
  420. write_4hex (baseaddr);
  421. serial_puts (" banksize: ");
  422. write_4hex (bank_size);
  423. serial_puts (" mb2cf: ");
  424. write_4hex (bank);
  425. serial_puts ("\n");
  426. #endif
  427. baseaddr += bank_size;
  428. sdram_size += bank_size;
  429. /* write SDRAM bank 2 register */
  430. mtdcr (memcfga, mem_mb2cf);
  431. mtdcr (memcfgd, bank);
  432. /* get SDRAM bank 3 register */
  433. mtdcr (memcfga, mem_mb3cf);
  434. bank = mfdcr (memcfgd) & ~0xFFCEE001;
  435. #ifdef SDRAM_DEBUG
  436. serial_puts ("bank3: baseaddr: ");
  437. write_4hex (baseaddr);
  438. serial_puts (" banksize: ");
  439. write_4hex (bank_size);
  440. #endif
  441. if (banks == 2) {
  442. bank |= (baseaddr | tmp | 0x01);
  443. baseaddr += bank_size;
  444. sdram_size += bank_size;
  445. }
  446. /* endif */
  447. #ifdef SDRAM_DEBUG
  448. serial_puts (" mb3cf: ");
  449. write_4hex (bank);
  450. serial_puts ("\n");
  451. #endif
  452. /* write SDRAM bank 3 register */
  453. mtdcr (memcfga, mem_mb3cf);
  454. mtdcr (memcfgd, bank);
  455. /* get SDRAM refresh interval register */
  456. mtdcr (memcfga, mem_rtr);
  457. tmp = mfdcr (memcfgd) & ~0x3FF80000;
  458. if (tmemclk < NSto10PS (16))
  459. tmp |= 0x05F00000;
  460. else
  461. tmp |= 0x03F80000;
  462. /* write SDRAM refresh interval register */
  463. mtdcr (memcfga, mem_rtr);
  464. mtdcr (memcfgd, tmp);
  465. /* enable SDRAM controller with no ECC, 32-bit SDRAM width, 16 byte burst */
  466. mtdcr (memcfga, mem_mcopt1);
  467. tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x80E00000;
  468. mtdcr (memcfga, mem_mcopt1);
  469. mtdcr (memcfgd, tmp);
  470. /*-------------------------------------------------------------------------+
  471. | Interrupt controller setup for the PIP405 board.
  472. | Note: IRQ 0-15 405GP internally generated; active high; level sensitive
  473. | IRQ 16 405GP internally generated; active low; level sensitive
  474. | IRQ 17-24 RESERVED
  475. | IRQ 25 (EXT IRQ 0) SouthBridg; active low; level sensitive
  476. | IRQ 26 (EXT IRQ 1) NMI: active low; level sensitive
  477. | IRQ 27 (EXT IRQ 2) SMI: active Low; level sensitive
  478. | IRQ 28 (EXT IRQ 3) PCI SLOT 3; active low; level sensitive
  479. | IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
  480. | IRQ 30 (EXT IRQ 5) PCI SLOT 1; active low; level sensitive
  481. | IRQ 31 (EXT IRQ 6) PCI SLOT 0; active low; level sensitive
  482. | Note for PIP405 board:
  483. | An interrupt taken for the SouthBridge (IRQ 25) indicates that
  484. | the Interrupt Controller in the South Bridge has caused the
  485. | interrupt. The IC must be read to determine which device
  486. | caused the interrupt.
  487. |
  488. +-------------------------------------------------------------------------*/
  489. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  490. mtdcr (uicer, 0x00000000); /* disable all ints */
  491. mtdcr (uiccr, 0x00000000); /* set all to be non-critical (for now) */
  492. mtdcr (uicpr, 0xFFFFFF80); /* set int polarities */
  493. mtdcr (uictr, 0x10000000); /* set int trigger levels */
  494. mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
  495. mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
  496. return 0;
  497. }
  498. /* ------------------------------------------------------------------------- */
  499. /*
  500. * Check Board Identity:
  501. */
  502. int checkboard (void)
  503. {
  504. char s[50];
  505. unsigned char bc;
  506. int i;
  507. backup_t *b = (backup_t *) s;
  508. puts ("Board: ");
  509. i = getenv_r ("serial#", (char *)s, 32);
  510. if ((i == 0) || strncmp ((char *)s, "PIP405", 6)) {
  511. get_backup_values (b);
  512. if (strncmp (b->signature, "MPL\0", 4) != 0) {
  513. puts ("### No HW ID - assuming PIP405");
  514. } else {
  515. b->serial_name[6] = 0;
  516. printf ("%s SN: %s", b->serial_name,
  517. &b->serial_name[7]);
  518. }
  519. } else {
  520. s[6] = 0;
  521. printf ("%s SN: %s", s, &s[7]);
  522. }
  523. bc = in8 (CONFIG_PORT_ADDR);
  524. printf (" Boot Config: 0x%x\n", bc);
  525. return (0);
  526. }
  527. /* ------------------------------------------------------------------------- */
  528. /* ------------------------------------------------------------------------- */
  529. /*
  530. initdram(int board_type) reads EEPROM via I2c. EEPROM contains all of
  531. the necessary info for SDRAM controller configuration
  532. */
  533. /* ------------------------------------------------------------------------- */
  534. /* ------------------------------------------------------------------------- */
  535. static int test_dram (unsigned long ramsize);
  536. long int initdram (int board_type)
  537. {
  538. DECLARE_GLOBAL_DATA_PTR;
  539. unsigned long bank_reg[4], tmp, bank_size;
  540. int i, ds;
  541. unsigned long TotalSize;
  542. ds = 0;
  543. /* since the DRAM controller is allready set up,
  544. * calculate the size with the bank registers
  545. */
  546. mtdcr (memcfga, mem_mb0cf);
  547. bank_reg[0] = mfdcr (memcfgd);
  548. mtdcr (memcfga, mem_mb1cf);
  549. bank_reg[1] = mfdcr (memcfgd);
  550. mtdcr (memcfga, mem_mb2cf);
  551. bank_reg[2] = mfdcr (memcfgd);
  552. mtdcr (memcfga, mem_mb3cf);
  553. bank_reg[3] = mfdcr (memcfgd);
  554. TotalSize = 0;
  555. for (i = 0; i < 4; i++) {
  556. if ((bank_reg[i] & 0x1) == 0x1) {
  557. tmp = (bank_reg[i] >> 17) & 0x7;
  558. bank_size = 4 << tmp;
  559. TotalSize += bank_size;
  560. } else
  561. ds = 1;
  562. }
  563. if (ds == 1)
  564. printf ("single-sided DIMM ");
  565. else
  566. printf ("double-sided DIMM ");
  567. test_dram (TotalSize * 1024 * 1024);
  568. /* bank 2 (SDRAM Clock 2) is not usable if 133MHz SDRAM IF */
  569. (void) get_clocks();
  570. if (gd->cpu_clk > 220000000)
  571. TotalSize /= 2;
  572. return (TotalSize * 1024 * 1024);
  573. }
  574. /* ------------------------------------------------------------------------- */
  575. static int test_dram (unsigned long ramsize)
  576. {
  577. /* not yet implemented */
  578. return (1);
  579. }
  580. extern flash_info_t flash_info[]; /* info for FLASH chips */
  581. int misc_init_r (void)
  582. {
  583. DECLARE_GLOBAL_DATA_PTR;
  584. /* adjust flash start and size as well as the offset */
  585. gd->bd->bi_flashstart=0-flash_info[0].size;
  586. gd->bd->bi_flashsize=flash_info[0].size-CFG_MONITOR_LEN;
  587. gd->bd->bi_flashoffset=0;
  588. /* if PIP405 has booted from PCI, reset CCR0[24] as described in errata PCI_18 */
  589. if (mfdcr(strap) & PSR_ROM_LOC)
  590. mtspr(ccr0, (mfspr(ccr0) & ~0x80));
  591. return (0);
  592. }
  593. /***************************************************************************
  594. * some helping routines
  595. */
  596. int overwrite_console (void)
  597. {
  598. return (in8 (CONFIG_PORT_ADDR) & 0x1); /* return TRUE if console should be overwritten */
  599. }
  600. extern int isa_init (void);
  601. void print_pip405_rev (void)
  602. {
  603. unsigned char part, vers, cfg;
  604. part = in8 (PLD_PART_REG);
  605. vers = in8 (PLD_VERS_REG);
  606. cfg = in8 (PLD_BOARD_CFG_REG);
  607. printf ("Rev: PIP405-%d Rev %c PLD%d %d PLD%d %d\n",
  608. 16 - ((cfg >> 4) & 0xf), (cfg & 0xf) + 'A', part & 0xf,
  609. vers & 0xf, (part >> 4) & 0xf, (vers >> 4) & 0xf);
  610. }
  611. extern void check_env(void);
  612. int last_stage_init (void)
  613. {
  614. print_pip405_rev ();
  615. isa_init ();
  616. show_stdio_dev ();
  617. check_env();
  618. return 0;
  619. }
  620. /************************************************************************
  621. * Print PIP405 Info
  622. ************************************************************************/
  623. void print_pip405_info (void)
  624. {
  625. unsigned char part, vers, cfg, ledu, sysman, flashcom, can, serpwr,
  626. compwr, nicvga, scsirst;
  627. part = in8 (PLD_PART_REG);
  628. vers = in8 (PLD_VERS_REG);
  629. cfg = in8 (PLD_BOARD_CFG_REG);
  630. ledu = in8 (PLD_LED_USER_REG);
  631. sysman = in8 (PLD_SYS_MAN_REG);
  632. flashcom = in8 (PLD_FLASH_COM_REG);
  633. can = in8 (PLD_CAN_REG);
  634. serpwr = in8 (PLD_SER_PWR_REG);
  635. compwr = in8 (PLD_COM_PWR_REG);
  636. nicvga = in8 (PLD_NIC_VGA_REG);
  637. scsirst = in8 (PLD_SCSI_RST_REG);
  638. printf ("PLD Part %d version %d\n",
  639. part & 0xf, vers & 0xf);
  640. printf ("PLD Part %d version %d\n",
  641. (part >> 4) & 0xf, (vers >> 4) & 0xf);
  642. printf ("Board Revision %c\n", (cfg & 0xf) + 'A');
  643. printf ("Population Options %d %d %d %d\n",
  644. (cfg >> 4) & 0x1, (cfg >> 5) & 0x1,
  645. (cfg >> 6) & 0x1, (cfg >> 7) & 0x1);
  646. printf ("User LED0 %s User LED1 %s\n",
  647. ((ledu & 0x1) == 0x1) ? "on" : "off",
  648. ((ledu & 0x2) == 0x2) ? "on" : "off");
  649. printf ("Additionally Options %d %d\n",
  650. (ledu >> 2) & 0x1, (ledu >> 3) & 0x1);
  651. printf ("User Config Switch %d %d %d %d\n",
  652. (ledu >> 4) & 0x1, (ledu >> 5) & 0x1,
  653. (ledu >> 6) & 0x1, (ledu >> 7) & 0x1);
  654. switch (sysman & 0x3) {
  655. case 0:
  656. printf ("PCI Clocks are running\n");
  657. break;
  658. case 1:
  659. printf ("PCI Clocks are stopped in POS State\n");
  660. break;
  661. case 2:
  662. printf ("PCI Clocks are stopped when PCI_STP# is asserted\n");
  663. break;
  664. case 3:
  665. printf ("PCI Clocks are stopped\n");
  666. break;
  667. }
  668. switch ((sysman >> 2) & 0x3) {
  669. case 0:
  670. printf ("Main Clocks are running\n");
  671. break;
  672. case 1:
  673. printf ("Main Clocks are stopped in POS State\n");
  674. break;
  675. case 2:
  676. case 3:
  677. printf ("PCI Clocks are stopped\n");
  678. break;
  679. }
  680. printf ("INIT asserts %sINT2# (SMI)\n",
  681. ((sysman & 0x10) == 0x10) ? "" : "not ");
  682. printf ("INIT asserts %sINT1# (NMI)\n",
  683. ((sysman & 0x20) == 0x20) ? "" : "not ");
  684. printf ("INIT occured %d\n", (sysman >> 6) & 0x1);
  685. printf ("SER1 is routed to %s\n",
  686. ((flashcom & 0x1) == 0x1) ? "RS485" : "RS232");
  687. printf ("COM2 is routed to %s\n",
  688. ((flashcom & 0x2) == 0x2) ? "RS485" : "RS232");
  689. printf ("RS485 is configured as %s duplex\n",
  690. ((flashcom & 0x4) == 0x4) ? "full" : "half");
  691. printf ("RS485 is connected to %s\n",
  692. ((flashcom & 0x8) == 0x8) ? "COM1" : "COM2");
  693. printf ("SER1 uses handshakes %s\n",
  694. ((flashcom & 0x10) == 0x10) ? "DTR/DSR" : "RTS/CTS");
  695. printf ("Bootflash is %swriteprotected\n",
  696. ((flashcom & 0x20) == 0x20) ? "not " : "");
  697. printf ("Bootflash VPP is %s\n",
  698. ((flashcom & 0x40) == 0x40) ? "on" : "off");
  699. printf ("Bootsector is %swriteprotected\n",
  700. ((flashcom & 0x80) == 0x80) ? "not " : "");
  701. switch ((can) & 0x3) {
  702. case 0:
  703. printf ("CAN Controller is on address 0x1000..0x10FF\n");
  704. break;
  705. case 1:
  706. printf ("CAN Controller is on address 0x8000..0x80FF\n");
  707. break;
  708. case 2:
  709. printf ("CAN Controller is on address 0xE000..0xE0FF\n");
  710. break;
  711. case 3:
  712. printf ("CAN Controller is disabled\n");
  713. break;
  714. }
  715. switch ((can >> 2) & 0x3) {
  716. case 0:
  717. printf ("CAN Controller Reset is ISA Reset\n");
  718. break;
  719. case 1:
  720. printf ("CAN Controller Reset is ISA Reset and POS State\n");
  721. break;
  722. case 2:
  723. case 3:
  724. printf ("CAN Controller is in reset\n");
  725. break;
  726. }
  727. if (((can >> 4) < 3) || ((can >> 4) == 8) || ((can >> 4) == 13))
  728. printf ("CAN Interrupt is disabled\n");
  729. else
  730. printf ("CAN Interrupt is ISA INT%d\n", (can >> 4) & 0xf);
  731. switch (serpwr & 0x3) {
  732. case 0:
  733. printf ("SER0 Drivers are enabled\n");
  734. break;
  735. case 1:
  736. printf ("SER0 Drivers are disabled in the POS state\n");
  737. break;
  738. case 2:
  739. case 3:
  740. printf ("SER0 Drivers are disabled\n");
  741. break;
  742. }
  743. switch ((serpwr >> 2) & 0x3) {
  744. case 0:
  745. printf ("SER1 Drivers are enabled\n");
  746. break;
  747. case 1:
  748. printf ("SER1 Drivers are disabled in the POS state\n");
  749. break;
  750. case 2:
  751. case 3:
  752. printf ("SER1 Drivers are disabled\n");
  753. break;
  754. }
  755. switch (compwr & 0x3) {
  756. case 0:
  757. printf ("COM1 Drivers are enabled\n");
  758. break;
  759. case 1:
  760. printf ("COM1 Drivers are disabled in the POS state\n");
  761. break;
  762. case 2:
  763. case 3:
  764. printf ("COM1 Drivers are disabled\n");
  765. break;
  766. }
  767. switch ((compwr >> 2) & 0x3) {
  768. case 0:
  769. printf ("COM2 Drivers are enabled\n");
  770. break;
  771. case 1:
  772. printf ("COM2 Drivers are disabled in the POS state\n");
  773. break;
  774. case 2:
  775. case 3:
  776. printf ("COM2 Drivers are disabled\n");
  777. break;
  778. }
  779. switch ((nicvga) & 0x3) {
  780. case 0:
  781. printf ("PHY is running\n");
  782. break;
  783. case 1:
  784. printf ("PHY is in Power save mode in POS state\n");
  785. break;
  786. case 2:
  787. case 3:
  788. printf ("PHY is in Power save mode\n");
  789. break;
  790. }
  791. switch ((nicvga >> 2) & 0x3) {
  792. case 0:
  793. printf ("VGA is running\n");
  794. break;
  795. case 1:
  796. printf ("VGA is in Power save mode in POS state\n");
  797. break;
  798. case 2:
  799. case 3:
  800. printf ("VGA is in Power save mode\n");
  801. break;
  802. }
  803. printf ("PHY is %sreseted\n", ((nicvga & 0x10) == 0x10) ? "" : "not ");
  804. printf ("VGA is %sreseted\n", ((nicvga & 0x20) == 0x20) ? "" : "not ");
  805. printf ("Reserved Configuration is %d %d\n", (nicvga >> 6) & 0x1,
  806. (nicvga >> 7) & 0x1);
  807. switch ((scsirst) & 0x3) {
  808. case 0:
  809. printf ("SCSI Controller is running\n");
  810. break;
  811. case 1:
  812. printf ("SCSI Controller is in Power save mode in POS state\n");
  813. break;
  814. case 2:
  815. case 3:
  816. printf ("SCSI Controller is in Power save mode\n");
  817. break;
  818. }
  819. printf ("SCSI termination is %s\n",
  820. ((scsirst & 0x4) == 0x4) ? "disabled" : "enabled");
  821. printf ("SCSI Controller is %sreseted\n",
  822. ((scsirst & 0x10) == 0x10) ? "" : "not ");
  823. printf ("IDE disks are %sreseted\n",
  824. ((scsirst & 0x20) == 0x20) ? "" : "not ");
  825. printf ("ISA Bus is %sreseted\n",
  826. ((scsirst & 0x40) == 0x40) ? "" : "not ");
  827. printf ("Super IO is %sreseted\n",
  828. ((scsirst & 0x80) == 0x80) ? "" : "not ");
  829. }
  830. void user_led0 (unsigned char on)
  831. {
  832. if (on == TRUE)
  833. out8 (PLD_LED_USER_REG, (in8 (PLD_LED_USER_REG) | 0x1));
  834. else
  835. out8 (PLD_LED_USER_REG, (in8 (PLD_LED_USER_REG) & 0xfe));
  836. }
  837. void user_led1 (unsigned char on)
  838. {
  839. if (on == TRUE)
  840. out8 (PLD_LED_USER_REG, (in8 (PLD_LED_USER_REG) | 0x2));
  841. else
  842. out8 (PLD_LED_USER_REG, (in8 (PLD_LED_USER_REG) & 0xfd));
  843. }
  844. void ide_set_reset (int idereset)
  845. {
  846. /* if reset = 1 IDE reset will be asserted */
  847. unsigned char resreg;
  848. resreg = in8 (PLD_SCSI_RST_REG);
  849. if (idereset == 1)
  850. resreg |= 0x20;
  851. else {
  852. udelay(10000);
  853. resreg &= 0xdf;
  854. }
  855. out8 (PLD_SCSI_RST_REG, resreg);
  856. }