lwmon5.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * (C) Copyright 2007
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #include <common.h>
  21. #include <asm/processor.h>
  22. #include <ppc440.h>
  23. #include <asm/gpio.h>
  24. DECLARE_GLOBAL_DATA_PTR;
  25. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
  26. ulong flash_get_size (ulong base, int banknum);
  27. int board_early_init_f(void)
  28. {
  29. u32 sdr0_pfc1, sdr0_pfc2;
  30. u32 reg;
  31. /* PLB Write pipelining disabled. Denali Core workaround */
  32. mtdcr(plb0_acr, 0xDE000000);
  33. mtdcr(plb1_acr, 0xDE000000);
  34. /*--------------------------------------------------------------------
  35. * Setup the interrupt controller polarities, triggers, etc.
  36. *-------------------------------------------------------------------*/
  37. mtdcr(uic0sr, 0xffffffff); /* clear all. if write with 1 then the status is cleared */
  38. mtdcr(uic0er, 0x00000000); /* disable all */
  39. mtdcr(uic0cr, 0x00000000); /* we have not critical interrupts at the moment */
  40. mtdcr(uic0pr, 0xfffff7ff); /* Adjustment of the polarity */
  41. mtdcr(uic0tr, 0x00000810); /* per ref-board manual */
  42. mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  43. mtdcr(uic0sr, 0xffffffff); /* clear all */
  44. mtdcr(uic1sr, 0xffffffff); /* clear all */
  45. mtdcr(uic1er, 0x00000000); /* disable all */
  46. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  47. mtdcr(uic1pr, 0xFFFFC7AD); /* Adjustment of the polarity */
  48. mtdcr(uic1tr, 0x0600384A); /* per ref-board manual */
  49. mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  50. mtdcr(uic1sr, 0xffffffff); /* clear all */
  51. mtdcr(uic2sr, 0xffffffff); /* clear all */
  52. mtdcr(uic2er, 0x00000000); /* disable all */
  53. mtdcr(uic2cr, 0x00000000); /* all non-critical */
  54. mtdcr(uic2pr, 0x27C00000); /* Adjustment of the polarity */
  55. mtdcr(uic2tr, 0xDFC00000); /* per ref-board manual */
  56. mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 is within DDRAM */
  57. mtdcr(uic2sr, 0xffffffff); /* clear all. Why this??? */
  58. /* Trace Pins are disabled. SDR0_PFC0 Register */
  59. mtsdr(SDR0_PFC0, 0x0);
  60. /* select Ethernet pins */
  61. mfsdr(SDR0_PFC1, sdr0_pfc1);
  62. /* SMII via ZMII */
  63. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  64. SDR0_PFC1_SELECT_CONFIG_6;
  65. mfsdr(SDR0_PFC2, sdr0_pfc2);
  66. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  67. SDR0_PFC2_SELECT_CONFIG_6;
  68. /* enable SPI (SCP) */
  69. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_SCP_SEL;
  70. mtsdr(SDR0_PFC2, sdr0_pfc2);
  71. mtsdr(SDR0_PFC1, sdr0_pfc1);
  72. mtsdr(SDR0_PFC4, 0x80000000);
  73. /* PCI arbiter disabled */
  74. /* PCI Host Configuration disbaled */
  75. mfsdr(sdr_pci0, reg);
  76. reg = 0;
  77. mtsdr(sdr_pci0, 0x00000000 | reg);
  78. gpio_write_bit(CFG_GPIO_FLASH_WP, 1);
  79. return 0;
  80. }
  81. /*---------------------------------------------------------------------------+
  82. | misc_init_r.
  83. +---------------------------------------------------------------------------*/
  84. int misc_init_r(void)
  85. {
  86. u32 pbcr;
  87. int size_val = 0;
  88. u32 reg;
  89. unsigned long usb2d0cr = 0;
  90. unsigned long usb2phy0cr, usb2h0cr = 0;
  91. unsigned long sdr0_pfc1;
  92. /*
  93. * FLASH stuff...
  94. */
  95. /* Re-do sizing to get full correct info */
  96. /* adjust flash start and offset */
  97. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  98. gd->bd->bi_flashoffset = 0;
  99. mfebc(pb0cr, pbcr);
  100. switch (gd->bd->bi_flashsize) {
  101. case 1 << 20:
  102. size_val = 0;
  103. break;
  104. case 2 << 20:
  105. size_val = 1;
  106. break;
  107. case 4 << 20:
  108. size_val = 2;
  109. break;
  110. case 8 << 20:
  111. size_val = 3;
  112. break;
  113. case 16 << 20:
  114. size_val = 4;
  115. break;
  116. case 32 << 20:
  117. size_val = 5;
  118. break;
  119. case 64 << 20:
  120. size_val = 6;
  121. break;
  122. case 128 << 20:
  123. size_val = 7;
  124. break;
  125. }
  126. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  127. mtebc(pb0cr, pbcr);
  128. /*
  129. * Re-check to get correct base address
  130. */
  131. flash_get_size(gd->bd->bi_flashstart, 0);
  132. /* Monitor protection ON by default */
  133. (void)flash_protect(FLAG_PROTECT_SET,
  134. -CFG_MONITOR_LEN,
  135. 0xffffffff,
  136. &flash_info[0]);
  137. /* Env protection ON by default */
  138. (void)flash_protect(FLAG_PROTECT_SET,
  139. CFG_ENV_ADDR_REDUND,
  140. CFG_ENV_ADDR_REDUND + 2*CFG_ENV_SECT_SIZE - 1,
  141. &flash_info[0]);
  142. /*
  143. * USB suff...
  144. */
  145. /* SDR Setting */
  146. mfsdr(SDR0_PFC1, sdr0_pfc1);
  147. mfsdr(SDR0_USB0, usb2d0cr);
  148. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  149. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  150. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  151. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL; /*0*/
  152. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  153. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ; /*1*/
  154. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  155. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS; /*0*/
  156. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  157. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST; /*1*/
  158. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  159. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST; /*1*/
  160. /* An 8-bit/60MHz interface is the only possible alternative
  161. when connecting the Device to the PHY */
  162. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  163. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ; /*1*/
  164. mtsdr(SDR0_PFC1, sdr0_pfc1);
  165. mtsdr(SDR0_USB0, usb2d0cr);
  166. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  167. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  168. /*
  169. * Clear resets
  170. */
  171. udelay (1000);
  172. mtsdr(SDR0_SRST1, 0x00000000);
  173. udelay (1000);
  174. mtsdr(SDR0_SRST0, 0x00000000);
  175. printf("USB: Host(int phy) Device(ext phy)\n");
  176. /*
  177. * Clear PLB4A0_ACR[WRP]
  178. * This fix will make the MAL burst disabling patch for the Linux
  179. * EMAC driver obsolete.
  180. */
  181. reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
  182. mtdcr(plb4_acr, reg);
  183. /*
  184. * Reset Lime controller
  185. */
  186. gpio_write_bit(CFG_GPIO_LIME_S, 1);
  187. udelay(500);
  188. gpio_write_bit(CFG_GPIO_LIME_RST, 1);
  189. /*
  190. * Reset PHY's
  191. */
  192. gpio_write_bit(CFG_GPIO_PHY0_RST, 0);
  193. gpio_write_bit(CFG_GPIO_PHY1_RST, 0);
  194. udelay(100);
  195. gpio_write_bit(CFG_GPIO_PHY0_RST, 1);
  196. gpio_write_bit(CFG_GPIO_PHY1_RST, 1);
  197. /*
  198. * Reset USB hub
  199. */
  200. gpio_write_bit(CFG_GPIO_HUB_RST, 0);
  201. udelay(100);
  202. gpio_write_bit(CFG_GPIO_HUB_RST, 1);
  203. return 0;
  204. }
  205. int checkboard(void)
  206. {
  207. char *s = getenv("serial#");
  208. printf("Board: lwmon5");
  209. if (s != NULL) {
  210. puts(", serial# ");
  211. puts(s);
  212. }
  213. putc('\n');
  214. return (0);
  215. }
  216. #if defined(CFG_DRAM_TEST)
  217. int testdram(void)
  218. {
  219. unsigned long *mem = (unsigned long *)0;
  220. const unsigned long kend = (1024 / sizeof(unsigned long));
  221. unsigned long k, n;
  222. mtmsr(0);
  223. for (k = 0; k < CFG_MBYTES_SDRAM;
  224. ++k, mem += (1024 / sizeof(unsigned long))) {
  225. if ((k & 1023) == 0) {
  226. printf("%3d MB\r", k / 1024);
  227. }
  228. memset(mem, 0xaaaaaaaa, 1024);
  229. for (n = 0; n < kend; ++n) {
  230. if (mem[n] != 0xaaaaaaaa) {
  231. printf("SDRAM test fails at: %08x\n",
  232. (uint) & mem[n]);
  233. return 1;
  234. }
  235. }
  236. memset(mem, 0x55555555, 1024);
  237. for (n = 0; n < kend; ++n) {
  238. if (mem[n] != 0x55555555) {
  239. printf("SDRAM test fails at: %08x\n",
  240. (uint) & mem[n]);
  241. return 1;
  242. }
  243. }
  244. }
  245. printf("SDRAM test passes\n");
  246. return 0;
  247. }
  248. #endif
  249. /*************************************************************************
  250. * pci_pre_init
  251. *
  252. * This routine is called just prior to registering the hose and gives
  253. * the board the opportunity to check things. Returning a value of zero
  254. * indicates that things are bad & PCI initialization should be aborted.
  255. *
  256. * Different boards may wish to customize the pci controller structure
  257. * (add regions, override default access routines, etc) or perform
  258. * certain pre-initialization actions.
  259. *
  260. ************************************************************************/
  261. #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
  262. int pci_pre_init(struct pci_controller *hose)
  263. {
  264. unsigned long addr;
  265. /*-------------------------------------------------------------------------+
  266. | Set priority for all PLB3 devices to 0.
  267. | Set PLB3 arbiter to fair mode.
  268. +-------------------------------------------------------------------------*/
  269. mfsdr(sdr_amp1, addr);
  270. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  271. addr = mfdcr(plb3_acr);
  272. mtdcr(plb3_acr, addr | 0x80000000);
  273. /*-------------------------------------------------------------------------+
  274. | Set priority for all PLB4 devices to 0.
  275. +-------------------------------------------------------------------------*/
  276. mfsdr(sdr_amp0, addr);
  277. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  278. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  279. mtdcr(plb4_acr, addr);
  280. /*-------------------------------------------------------------------------+
  281. | Set Nebula PLB4 arbiter to fair mode.
  282. +-------------------------------------------------------------------------*/
  283. /* Segment0 */
  284. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  285. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  286. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  287. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  288. mtdcr(plb0_acr, addr);
  289. /* Segment1 */
  290. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  291. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  292. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  293. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  294. mtdcr(plb1_acr, addr);
  295. return 1;
  296. }
  297. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
  298. /*************************************************************************
  299. * pci_target_init
  300. *
  301. * The bootstrap configuration provides default settings for the pci
  302. * inbound map (PIM). But the bootstrap config choices are limited and
  303. * may not be sufficient for a given board.
  304. *
  305. ************************************************************************/
  306. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  307. void pci_target_init(struct pci_controller *hose)
  308. {
  309. /*--------------------------------------------------------------------------+
  310. * Set up Direct MMIO registers
  311. *--------------------------------------------------------------------------*/
  312. /*--------------------------------------------------------------------------+
  313. | PowerPC440EPX PCI Master configuration.
  314. | Map one 1Gig range of PLB/processor addresses to PCI memory space.
  315. | PLB address 0xA0000000-0xDFFFFFFF ==> PCI address 0xA0000000-0xDFFFFFFF
  316. | Use byte reversed out routines to handle endianess.
  317. | Make this region non-prefetchable.
  318. +--------------------------------------------------------------------------*/
  319. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  320. out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  321. out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  322. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  323. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  324. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute - disabled b4 setting */
  325. out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  326. out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  327. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  328. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, and enable region */
  329. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  330. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  331. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  332. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  333. /*--------------------------------------------------------------------------+
  334. * Set up Configuration registers
  335. *--------------------------------------------------------------------------*/
  336. /* Program the board's subsystem id/vendor id */
  337. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  338. CFG_PCI_SUBSYS_VENDORID);
  339. pci_write_config_word(0, PCI_SUBSYSTEM_ID, CFG_PCI_SUBSYS_ID);
  340. /* Configure command register as bus master */
  341. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  342. /* 240nS PCI clock */
  343. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  344. /* No error reporting */
  345. pci_write_config_word(0, PCI_ERREN, 0);
  346. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  347. }
  348. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  349. /*************************************************************************
  350. * pci_master_init
  351. *
  352. ************************************************************************/
  353. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  354. void pci_master_init(struct pci_controller *hose)
  355. {
  356. unsigned short temp_short;
  357. /*--------------------------------------------------------------------------+
  358. | Write the PowerPC440 EP PCI Configuration regs.
  359. | Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  360. | Enable PowerPC440 EP to act as a PCI memory target (PTM).
  361. +--------------------------------------------------------------------------*/
  362. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  363. pci_write_config_word(0, PCI_COMMAND,
  364. temp_short | PCI_COMMAND_MASTER |
  365. PCI_COMMAND_MEMORY);
  366. }
  367. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
  368. /*************************************************************************
  369. * is_pci_host
  370. *
  371. * This routine is called to determine if a pci scan should be
  372. * performed. With various hardware environments (especially cPCI and
  373. * PPMC) it's insufficient to depend on the state of the arbiter enable
  374. * bit in the strap register, or generic host/adapter assumptions.
  375. *
  376. * Rather than hard-code a bad assumption in the general 440 code, the
  377. * 440 pci code requires the board to decide at runtime.
  378. *
  379. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  380. *
  381. *
  382. ************************************************************************/
  383. #if defined(CONFIG_PCI)
  384. int is_pci_host(struct pci_controller *hose)
  385. {
  386. /* Cactus is always configured as host. */
  387. return (1);
  388. }
  389. #endif /* defined(CONFIG_PCI) */
  390. void hw_watchdog_reset(void)
  391. {
  392. int val;
  393. /*
  394. * Toggle watchdog output
  395. */
  396. val = gpio_read_out_bit(CFG_GPIO_WATCHDOG) == 0 ? 1 : 0;
  397. gpio_write_bit(CFG_GPIO_WATCHDOG, val);
  398. }