pcs440ep.c 24 KB

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