pcs440ep.c 23 KB

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