pip405.c 24 KB

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