pcs440ep.c 24 KB

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