pcs440ep.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. /*
  2. * (C) Copyright 2006
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  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. #include <common.h>
  24. #include <ppc4xx.h>
  25. #include <malloc.h>
  26. #include <command.h>
  27. #include <crc.h>
  28. #include <asm/processor.h>
  29. #include <spd_sdram.h>
  30. #include <status_led.h>
  31. #include <sha1.h>
  32. DECLARE_GLOBAL_DATA_PTR;
  33. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  34. unsigned char sha1_checksum[SHA1_SUM_LEN];
  35. /* swap 4 Bits (Bit0 = Bit3, Bit1 = Bit2, Bit2 = Bit1 and Bit3 = Bit0) */
  36. unsigned char swapbits[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
  37. 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
  38. static void set_leds (int val)
  39. {
  40. out32(GPIO0_OR, (in32 (GPIO0_OR) & ~0x78000000) | (val << 27));
  41. }
  42. #define GET_LEDS ((in32 (GPIO0_OR) & 0x78000000) >> 27)
  43. void __led_init (led_id_t mask, int state)
  44. {
  45. int val = GET_LEDS;
  46. if (state == STATUS_LED_ON)
  47. val |= mask;
  48. else
  49. val &= ~mask;
  50. set_leds (val);
  51. }
  52. void __led_set (led_id_t mask, int state)
  53. {
  54. int val = GET_LEDS;
  55. if (state == STATUS_LED_ON)
  56. val |= mask;
  57. else if (state == STATUS_LED_OFF)
  58. val &= ~mask;
  59. set_leds (val);
  60. }
  61. void __led_toggle (led_id_t mask)
  62. {
  63. int val = GET_LEDS;
  64. val ^= mask;
  65. set_leds (val);
  66. }
  67. static void status_led_blink (void)
  68. {
  69. int i;
  70. int val = GET_LEDS;
  71. /* set all LED which are on, to state BLINKING */
  72. for (i = 0; i < 4; i++) {
  73. if (val & 0x08) status_led_set (i, STATUS_LED_BLINKING);
  74. val = val << 1;
  75. }
  76. }
  77. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  78. void show_boot_progress (int val)
  79. {
  80. /* find all valid Codes for val in README */
  81. if (val == -30) return;
  82. if (val < 0) {
  83. /* smthing goes wrong */
  84. status_led_blink ();
  85. return;
  86. }
  87. switch (val) {
  88. case 1:
  89. /* validating Image */
  90. status_led_set (0, STATUS_LED_OFF);
  91. status_led_set (1, STATUS_LED_ON);
  92. status_led_set (2, STATUS_LED_ON);
  93. break;
  94. case 15:
  95. /* booting */
  96. status_led_set (0, STATUS_LED_ON);
  97. status_led_set (1, STATUS_LED_ON);
  98. status_led_set (2, STATUS_LED_ON);
  99. break;
  100. case 64:
  101. /* starting Ethernet configuration */
  102. status_led_set (0, STATUS_LED_OFF);
  103. status_led_set (1, STATUS_LED_OFF);
  104. status_led_set (2, STATUS_LED_ON);
  105. break;
  106. case 80:
  107. /* loading Image */
  108. status_led_set (0, STATUS_LED_ON);
  109. status_led_set (1, STATUS_LED_OFF);
  110. status_led_set (2, STATUS_LED_ON);
  111. break;
  112. }
  113. }
  114. #endif
  115. int board_early_init_f(void)
  116. {
  117. register uint reg;
  118. set_leds(0); /* display boot info counter */
  119. /*--------------------------------------------------------------------
  120. * Setup the external bus controller/chip selects
  121. *-------------------------------------------------------------------*/
  122. mtdcr(ebccfga, xbcfg);
  123. reg = mfdcr(ebccfgd);
  124. mtdcr(ebccfgd, reg | 0x04000000); /* Set ATC */
  125. /*--------------------------------------------------------------------
  126. * GPIO's are alreay setup in cpu/ppc4xx/cpu_init.c
  127. * via define from board config file.
  128. *-------------------------------------------------------------------*/
  129. /*--------------------------------------------------------------------
  130. * Setup the interrupt controller polarities, triggers, etc.
  131. *-------------------------------------------------------------------*/
  132. mtdcr(uic0sr, 0xffffffff); /* clear all */
  133. mtdcr(uic0er, 0x00000000); /* disable all */
  134. mtdcr(uic0cr, 0x00000001); /* UIC1 crit is critical */
  135. mtdcr(uic0pr, 0xfffffe1f); /* per ref-board manual */
  136. mtdcr(uic0tr, 0x01c00000); /* per ref-board manual */
  137. mtdcr(uic0vr, 0x00000001); /* int31 highest, base=0x000 */
  138. mtdcr(uic0sr, 0xffffffff); /* clear all */
  139. mtdcr(uic1sr, 0xffffffff); /* clear all */
  140. mtdcr(uic1er, 0x00000000); /* disable all */
  141. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  142. mtdcr(uic1pr, 0xffffe0ff); /* per ref-board manual */
  143. mtdcr(uic1tr, 0x00ffc000); /* per ref-board manual */
  144. mtdcr(uic1vr, 0x00000001); /* int31 highest, base=0x000 */
  145. mtdcr(uic1sr, 0xffffffff); /* clear all */
  146. /*--------------------------------------------------------------------
  147. * Setup other serial configuration
  148. *-------------------------------------------------------------------*/
  149. mfsdr(sdr_pci0, reg);
  150. mtsdr(sdr_pci0, 0x80000000 | reg); /* PCI arbiter enabled */
  151. mtsdr(sdr_pfc0, 0x00000100); /* Pin function: enable GPIO49-63 */
  152. mtsdr(sdr_pfc1, 0x00048000); /* Pin function: UART0 has 4 pins, select IRQ5 */
  153. return 0;
  154. }
  155. #define EEPROM_LEN 256
  156. void load_sernum_ethaddr (void)
  157. {
  158. int ret;
  159. char buf[EEPROM_LEN];
  160. char mac[32];
  161. char *use_eeprom;
  162. u16 checksumcrc16 = 0;
  163. /* read the MACs from EEprom */
  164. status_led_set (0, STATUS_LED_ON);
  165. status_led_set (1, STATUS_LED_ON);
  166. ret = eeprom_read (CFG_I2C_EEPROM_ADDR, 0, (uchar *)buf, EEPROM_LEN);
  167. if (ret == 0) {
  168. checksumcrc16 = cyg_crc16 ((uchar *)buf, EEPROM_LEN - 2);
  169. /* check, if the EEprom is programmed:
  170. * - The Prefix(Byte 0,1,2) is equal to "ATR"
  171. * - The checksum, stored in the last 2 Bytes, is correct
  172. */
  173. if ((strncmp (buf,"ATR",3) != 0) ||
  174. ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) ||
  175. ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1]))
  176. {
  177. /* EEprom is not programmed */
  178. printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
  179. } else {
  180. /* get the MACs */
  181. sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x",
  182. buf[3],
  183. buf[4],
  184. buf[5],
  185. buf[6],
  186. buf[7],
  187. buf[8]);
  188. setenv ("ethaddr", (char *) mac);
  189. sprintf (mac, "%02x:%02x:%02x:%02x:%02x:%02x",
  190. buf[9],
  191. buf[10],
  192. buf[11],
  193. buf[12],
  194. buf[13],
  195. buf[14]);
  196. setenv ("eth1addr", (char *) mac);
  197. return;
  198. }
  199. }
  200. /* some error reading the EEprom */
  201. if ((use_eeprom = getenv ("use_eeprom_ethaddr")) == NULL) {
  202. /* dont use bootcmd */
  203. setenv("bootdelay", "-1");
  204. return;
  205. }
  206. /* == default ? use standard */
  207. if (strncmp (use_eeprom, "default", 7) == 0) {
  208. return;
  209. }
  210. /* Env doesnt exist -> hang */
  211. status_led_blink ();
  212. hang ();
  213. return;
  214. }
  215. #ifdef CONFIG_PREBOOT
  216. static uchar kbd_magic_prefix[] = "key_magic";
  217. static uchar kbd_command_prefix[] = "key_cmd";
  218. struct kbd_data_t {
  219. char s1;
  220. char s2;
  221. };
  222. struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
  223. {
  224. char *val;
  225. unsigned long tmp;
  226. /* use the DIPs for some bootoptions */
  227. val = getenv (ENV_NAME_DIP);
  228. tmp = simple_strtoul (val, NULL, 16);
  229. kbd_data->s2 = (tmp & 0x0f);
  230. kbd_data->s1 = (tmp & 0xf0) >> 4;
  231. return kbd_data;
  232. }
  233. static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
  234. {
  235. char s1 = str[0];
  236. if (s1 >= '0' && s1 <= '9')
  237. s1 -= '0';
  238. else if (s1 >= 'a' && s1 <= 'f')
  239. s1 = s1 - 'a' + 10;
  240. else if (s1 >= 'A' && s1 <= 'F')
  241. s1 = s1 - 'A' + 10;
  242. else
  243. return -1;
  244. if (s1 != kbd_data->s1) return -1;
  245. s1 = str[1];
  246. if (s1 >= '0' && s1 <= '9')
  247. s1 -= '0';
  248. else if (s1 >= 'a' && s1 <= 'f')
  249. s1 = s1 - 'a' + 10;
  250. else if (s1 >= 'A' && s1 <= 'F')
  251. s1 = s1 - 'A' + 10;
  252. else
  253. return -1;
  254. if (s1 != kbd_data->s2) return -1;
  255. return 0;
  256. }
  257. static char *key_match (const struct kbd_data_t *kbd_data)
  258. {
  259. char magic[sizeof (kbd_magic_prefix) + 1];
  260. char *suffix;
  261. char *kbd_magic_keys;
  262. /*
  263. * The following string defines the characters that can be appended
  264. * to "key_magic" to form the names of environment variables that
  265. * hold "magic" key codes, i. e. such key codes that can cause
  266. * pre-boot actions. If the string is empty (""), then only
  267. * "key_magic" is checked (old behaviour); the string "125" causes
  268. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  269. */
  270. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  271. kbd_magic_keys = "";
  272. /* loop over all magic keys;
  273. * use '\0' suffix in case of empty string
  274. */
  275. for (suffix = kbd_magic_keys; *suffix ||
  276. suffix == kbd_magic_keys; ++suffix) {
  277. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  278. if (compare_magic (kbd_data, getenv (magic)) == 0) {
  279. char cmd_name[sizeof (kbd_command_prefix) + 1];
  280. char *cmd;
  281. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  282. cmd = getenv (cmd_name);
  283. return (cmd);
  284. }
  285. }
  286. return (NULL);
  287. }
  288. #endif /* CONFIG_PREBOOT */
  289. static int pcs440ep_readinputs (void)
  290. {
  291. int i;
  292. char value[20];
  293. /* read the inputs and set the Envvars */
  294. /* Revision Level Bit 26 - 29 */
  295. i = ((in32 (GPIO0_IR) & 0x0000003c) >> 2);
  296. i = swapbits[i];
  297. sprintf (value, "%02x", i);
  298. setenv (ENV_NAME_REVLEV, value);
  299. /* Solder Switch Bit 30 - 33 */
  300. i = (in32 (GPIO0_IR) & 0x00000003) << 2;
  301. i += (in32 (GPIO1_IR) & 0xc0000000) >> 30;
  302. i = swapbits[i];
  303. sprintf (value, "%02x", i);
  304. setenv (ENV_NAME_SOLDER, value);
  305. /* DIP Switch Bit 49 - 56 */
  306. i = ((in32 (GPIO1_IR) & 0x00007f80) >> 7);
  307. i = (swapbits[i & 0x0f] << 4) + swapbits[(i & 0xf0) >> 4];
  308. sprintf (value, "%02x", i);
  309. setenv (ENV_NAME_DIP, value);
  310. return 0;
  311. }
  312. #if defined(CONFIG_SHA1_CHECK_UB_IMG)
  313. /*************************************************************************
  314. * calculate a SHA1 sum for the U-Boot image in Flash.
  315. *
  316. ************************************************************************/
  317. static int pcs440ep_sha1 (int docheck)
  318. {
  319. unsigned char *data;
  320. unsigned char *ptroff;
  321. unsigned char output[20];
  322. unsigned char org[20];
  323. int i, len = CONFIG_SHA1_LEN;
  324. memcpy ((char *)CFG_LOAD_ADDR, (char *)CONFIG_SHA1_START, len);
  325. data = (unsigned char *)CFG_LOAD_ADDR;
  326. ptroff = &data[len + SHA1_SUM_POS];
  327. for (i = 0; i < SHA1_SUM_LEN; i++) {
  328. org[i] = ptroff[i];
  329. ptroff[i] = 0;
  330. }
  331. sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
  332. if (docheck == 2) {
  333. for (i = 0; i < 20 ; i++) {
  334. printf("%02X ", output[i]);
  335. }
  336. printf("\n");
  337. }
  338. if (docheck == 1) {
  339. for (i = 0; i < 20 ; i++) {
  340. if (org[i] != output[i]) return 1;
  341. }
  342. }
  343. return 0;
  344. }
  345. /*************************************************************************
  346. * do some checks after the SHA1 checksum from the U-Boot Image was
  347. * calculated.
  348. *
  349. ************************************************************************/
  350. static void pcs440ep_checksha1 (void)
  351. {
  352. int ret;
  353. char *cs_test;
  354. ret = pcs440ep_sha1 (1);
  355. if (ret == 0) return;
  356. if ((cs_test = getenv ("cs_test")) == NULL) {
  357. /* Env doesnt exist -> hang */
  358. status_led_blink ();
  359. hang ();
  360. }
  361. if (strncmp (cs_test, "off", 3) == 0) {
  362. printf ("SHA1 U-Boot sum NOT ok!\n");
  363. setenv ("bootdelay", "-1");
  364. }
  365. }
  366. #else
  367. static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);}
  368. #endif
  369. int misc_init_r (void)
  370. {
  371. uint pbcr;
  372. int size_val = 0;
  373. /* Re-do sizing to get full correct info */
  374. mtdcr(ebccfga, pb0cr);
  375. pbcr = mfdcr(ebccfgd);
  376. switch (gd->bd->bi_flashsize) {
  377. case 1 << 20:
  378. size_val = 0;
  379. break;
  380. case 2 << 20:
  381. size_val = 1;
  382. break;
  383. case 4 << 20:
  384. size_val = 2;
  385. break;
  386. case 8 << 20:
  387. size_val = 3;
  388. break;
  389. case 16 << 20:
  390. size_val = 4;
  391. break;
  392. case 32 << 20:
  393. size_val = 5;
  394. break;
  395. case 64 << 20:
  396. size_val = 6;
  397. break;
  398. case 128 << 20:
  399. size_val = 7;
  400. break;
  401. }
  402. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  403. mtdcr(ebccfga, pb0cr);
  404. mtdcr(ebccfgd, pbcr);
  405. /* adjust flash start and offset */
  406. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  407. gd->bd->bi_flashoffset = 0;
  408. /* Monitor protection ON by default */
  409. (void)flash_protect(FLAG_PROTECT_SET,
  410. -CFG_MONITOR_LEN,
  411. 0xffffffff,
  412. &flash_info[1]);
  413. /* Env protection ON by default */
  414. (void)flash_protect(FLAG_PROTECT_SET,
  415. CFG_ENV_ADDR_REDUND,
  416. CFG_ENV_ADDR_REDUND + 2*CFG_ENV_SECT_SIZE - 1,
  417. &flash_info[1]);
  418. pcs440ep_readinputs ();
  419. pcs440ep_checksha1 ();
  420. #ifdef CONFIG_PREBOOT
  421. {
  422. struct kbd_data_t kbd_data;
  423. /* Decode keys */
  424. char *str = strdup (key_match (get_keys (&kbd_data)));
  425. /* Set or delete definition */
  426. setenv ("preboot", str);
  427. free (str);
  428. }
  429. #endif /* CONFIG_PREBOOT */
  430. return 0;
  431. }
  432. int checkboard(void)
  433. {
  434. char *s = getenv("serial#");
  435. printf("Board: PCS440EP");
  436. if (s != NULL) {
  437. puts(", serial# ");
  438. puts(s);
  439. }
  440. putc('\n');
  441. return (0);
  442. }
  443. #if defined(CONFIG_PPC4xx_USE_SPD_DDR_INIT_HANG)
  444. void spd_ddr_init_hang (void)
  445. {
  446. status_led_set (0, STATUS_LED_OFF);
  447. status_led_set (1, STATUS_LED_ON);
  448. /* we cannot use hang() because we are still running from
  449. Flash, and so the status_led driver is not initialized */
  450. puts ("### ERROR ### Please RESET the board ###\n");
  451. for (;;) {
  452. __led_toggle (4);
  453. udelay (100000);
  454. }
  455. }
  456. #endif
  457. long int initdram (int board_type)
  458. {
  459. long dram_size = 0;
  460. status_led_set (0, STATUS_LED_ON);
  461. status_led_set (1, STATUS_LED_OFF);
  462. dram_size = spd_sdram();
  463. status_led_set (0, STATUS_LED_OFF);
  464. status_led_set (1, STATUS_LED_ON);
  465. if (dram_size == 0) {
  466. hang();
  467. }
  468. return dram_size;
  469. }
  470. #if defined(CFG_DRAM_TEST)
  471. int testdram(void)
  472. {
  473. unsigned long *mem = (unsigned long *)0;
  474. const unsigned long kend = (1024 / sizeof(unsigned long));
  475. unsigned long k, n;
  476. mtmsr(0);
  477. for (k = 0; k < CFG_KBYTES_SDRAM;
  478. ++k, mem += (1024 / sizeof(unsigned long))) {
  479. if ((k & 1023) == 0) {
  480. printf("%3d MB\r", k / 1024);
  481. }
  482. memset(mem, 0xaaaaaaaa, 1024);
  483. for (n = 0; n < kend; ++n) {
  484. if (mem[n] != 0xaaaaaaaa) {
  485. printf("SDRAM test fails at: %08x\n",
  486. (uint) & mem[n]);
  487. return 1;
  488. }
  489. }
  490. memset(mem, 0x55555555, 1024);
  491. for (n = 0; n < kend; ++n) {
  492. if (mem[n] != 0x55555555) {
  493. printf("SDRAM test fails at: %08x\n",
  494. (uint) & mem[n]);
  495. return 1;
  496. }
  497. }
  498. }
  499. printf("SDRAM test passes\n");
  500. return 0;
  501. }
  502. #endif
  503. /*************************************************************************
  504. * pci_pre_init
  505. *
  506. * This routine is called just prior to registering the hose and gives
  507. * the board the opportunity to check things. Returning a value of zero
  508. * indicates that things are bad & PCI initialization should be aborted.
  509. *
  510. * Different boards may wish to customize the pci controller structure
  511. * (add regions, override default access routines, etc) or perform
  512. * certain pre-initialization actions.
  513. *
  514. ************************************************************************/
  515. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  516. int pci_pre_init(struct pci_controller *hose)
  517. {
  518. unsigned long addr;
  519. /*-------------------------------------------------------------------------+
  520. | Set priority for all PLB3 devices to 0.
  521. | Set PLB3 arbiter to fair mode.
  522. +-------------------------------------------------------------------------*/
  523. mfsdr(sdr_amp1, addr);
  524. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  525. addr = mfdcr(plb3_acr);
  526. mtdcr(plb3_acr, addr | 0x80000000);
  527. /*-------------------------------------------------------------------------+
  528. | Set priority for all PLB4 devices to 0.
  529. +-------------------------------------------------------------------------*/
  530. mfsdr(sdr_amp0, addr);
  531. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  532. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  533. mtdcr(plb4_acr, addr);
  534. /*-------------------------------------------------------------------------+
  535. | Set Nebula PLB4 arbiter to fair mode.
  536. +-------------------------------------------------------------------------*/
  537. /* Segment0 */
  538. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  539. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  540. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  541. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  542. mtdcr(plb0_acr, addr);
  543. /* Segment1 */
  544. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  545. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  546. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  547. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  548. mtdcr(plb1_acr, addr);
  549. return 1;
  550. }
  551. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  552. /*************************************************************************
  553. * pci_target_init
  554. *
  555. * The bootstrap configuration provides default settings for the pci
  556. * inbound map (PIM). But the bootstrap config choices are limited and
  557. * may not be sufficient for a given board.
  558. *
  559. ************************************************************************/
  560. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  561. void pci_target_init(struct pci_controller *hose)
  562. {
  563. /*--------------------------------------------------------------------------+
  564. * Set up Direct MMIO registers
  565. *--------------------------------------------------------------------------*/
  566. /*--------------------------------------------------------------------------+
  567. | PowerPC440 EP PCI Master configuration.
  568. | Map one 1Gig range of PLB/processor addresses to PCI memory space.
  569. | PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
  570. | Use byte reversed out routines to handle endianess.
  571. | Make this region non-prefetchable.
  572. +--------------------------------------------------------------------------*/
  573. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  574. out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  575. out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  576. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  577. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  578. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  579. out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  580. out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  581. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  582. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  583. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  584. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  585. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  586. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  587. /*--------------------------------------------------------------------------+
  588. * Set up Configuration registers
  589. *--------------------------------------------------------------------------*/
  590. /* Program the board's subsystem id/vendor id */
  591. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  592. CFG_PCI_SUBSYS_VENDORID);
  593. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
  594. /* Configure command register as bus master */
  595. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  596. /* 240nS PCI clock */
  597. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  598. /* No error reporting */
  599. pci_write_config_word(0, PCI_ERREN, 0);
  600. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  601. }
  602. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  603. /*************************************************************************
  604. * pci_master_init
  605. *
  606. ************************************************************************/
  607. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  608. void pci_master_init(struct pci_controller *hose)
  609. {
  610. unsigned short temp_short;
  611. /*--------------------------------------------------------------------------+
  612. | Write the PowerPC440 EP PCI Configuration regs.
  613. | Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  614. | Enable PowerPC440 EP to act as a PCI memory target (PTM).
  615. +--------------------------------------------------------------------------*/
  616. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  617. pci_write_config_word(0, PCI_COMMAND,
  618. temp_short | PCI_COMMAND_MASTER |
  619. PCI_COMMAND_MEMORY);
  620. }
  621. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
  622. /*************************************************************************
  623. * is_pci_host
  624. *
  625. * This routine is called to determine if a pci scan should be
  626. * performed. With various hardware environments (especially cPCI and
  627. * PPMC) it's insufficient to depend on the state of the arbiter enable
  628. * bit in the strap register, or generic host/adapter assumptions.
  629. *
  630. * Rather than hard-code a bad assumption in the general 440 code, the
  631. * 440 pci code requires the board to decide at runtime.
  632. *
  633. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  634. *
  635. *
  636. ************************************************************************/
  637. #if defined(CONFIG_PCI)
  638. int is_pci_host(struct pci_controller *hose)
  639. {
  640. /* PCS440EP is always configured as host. */
  641. return (1);
  642. }
  643. #endif /* defined(CONFIG_PCI) */
  644. /*************************************************************************
  645. * hw_watchdog_reset
  646. *
  647. * This routine is called to reset (keep alive) the watchdog timer
  648. *
  649. ************************************************************************/
  650. #if defined(CONFIG_HW_WATCHDOG)
  651. void hw_watchdog_reset(void)
  652. {
  653. }
  654. #endif
  655. /*************************************************************************
  656. * "led" Commando for the U-Boot shell
  657. *
  658. ************************************************************************/
  659. int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  660. {
  661. int rcode = 0;
  662. ulong pattern = 0;
  663. pattern = simple_strtoul (argv[1], NULL, 10);
  664. if (pattern > 200) {
  665. status_led_blink ();
  666. hang ();
  667. return rcode;
  668. }
  669. if (pattern > 100) {
  670. status_led_blink ();
  671. return rcode;
  672. }
  673. pattern &= 0x0f;
  674. set_leds (pattern);
  675. return rcode;
  676. }
  677. U_BOOT_CMD(
  678. led, 2, 1, do_led,
  679. "led - set the led\n",
  680. NULL
  681. );
  682. #if defined(CONFIG_SHA1_CHECK_UB_IMG)
  683. /*************************************************************************
  684. * "sha1" Commando for the U-Boot shell
  685. *
  686. ************************************************************************/
  687. int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  688. {
  689. int rcode = -1;
  690. if (argc < 2) {
  691. usage:
  692. printf ("Usage:\n%s\n", cmdtp->usage);
  693. return 1;
  694. }
  695. if (argc >= 3) {
  696. unsigned char *data;
  697. unsigned char output[20];
  698. int len;
  699. int i;
  700. data = (unsigned char *)simple_strtoul (argv[1], NULL, 16);
  701. len = simple_strtoul (argv[2], NULL, 16);
  702. sha1_csum (data, len, (unsigned char *)output);
  703. printf ("U-Boot sum:\n");
  704. for (i = 0; i < 20 ; i++) {
  705. printf ("%02X ", output[i]);
  706. }
  707. printf ("\n");
  708. if (argc == 4) {
  709. data = (unsigned char *)simple_strtoul (argv[3], NULL, 16);
  710. memcpy (data, output, 20);
  711. }
  712. return 0;
  713. }
  714. if (argc == 2) {
  715. char *ptr = argv[1];
  716. if (*ptr != '-') goto usage;
  717. ptr++;
  718. if ((*ptr == 'c') || (*ptr == 'C')) {
  719. rcode = pcs440ep_sha1 (1);
  720. printf ("SHA1 U-Boot sum %sok!\n", (rcode != 0) ? "not " : "");
  721. } else if ((*ptr == 'p') || (*ptr == 'P')) {
  722. rcode = pcs440ep_sha1 (2);
  723. } else {
  724. rcode = pcs440ep_sha1 (0);
  725. }
  726. return rcode;
  727. }
  728. return rcode;
  729. }
  730. U_BOOT_CMD(
  731. sha1, 4, 1, do_sha1,
  732. "sha1 - calculate the SHA1 Sum\n",
  733. "address len [addr] calculate the SHA1 sum [save at addr]\n"
  734. " -p calculate the SHA1 sum from the U-Boot image in flash and print\n"
  735. " -c check the U-Boot image in flash\n"
  736. );
  737. #endif
  738. #ifdef CONFIG_IDE_PREINIT
  739. int ide_preinit (void)
  740. {
  741. /* Set True IDE Mode */
  742. out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00100000));
  743. out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
  744. out32 (GPIO1_OR, (in32 (GPIO1_OR) & ~0x00008040));
  745. udelay (100000);
  746. return 0;
  747. }
  748. #endif
  749. #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
  750. void ide_set_reset (int idereset)
  751. {
  752. debug ("ide_reset(%d)\n", idereset);
  753. if (idereset == 0) {
  754. out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
  755. } else {
  756. out32 (GPIO0_OR, (in32 (GPIO0_OR) & ~0x00200000));
  757. }
  758. udelay (10000);
  759. }
  760. #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */