du440.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. * (C) Copyright 2008
  3. * Matthias Fuchs, esd gmbh, matthias.fuchs@esd-electronics.com
  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 <asm/io.h>
  23. #include <asm/bitops.h>
  24. #include <command.h>
  25. #include <i2c.h>
  26. #include <ppc440.h>
  27. #include "du440.h"
  28. DECLARE_GLOBAL_DATA_PTR;
  29. extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS];
  30. extern ulong flash_get_size (ulong base, int banknum);
  31. int usbhub_init(void);
  32. int dvi_init(void);
  33. int eeprom_write_enable (unsigned dev_addr, int state);
  34. int board_revision(void);
  35. static int du440_post_errors;
  36. int board_early_init_f(void)
  37. {
  38. u32 sdr0_cust0;
  39. u32 sdr0_pfc1, sdr0_pfc2;
  40. u32 reg;
  41. mtdcr(ebccfga, xbcfg);
  42. mtdcr(ebccfgd, 0xb8400000);
  43. /*
  44. * Setup the GPIO pins
  45. */
  46. out_be32((void*)GPIO0_OR, 0x00000000 | CFG_GPIO0_EP_EEP);
  47. out_be32((void*)GPIO0_TCR, 0x0000000f | CFG_GPIO0_EP_EEP);
  48. out_be32((void*)GPIO0_OSRL, 0x50055400);
  49. out_be32((void*)GPIO0_OSRH, 0x550050aa);
  50. out_be32((void*)GPIO0_TSRL, 0x50055400);
  51. out_be32((void*)GPIO0_TSRH, 0x55005000);
  52. out_be32((void*)GPIO0_ISR1L, 0x50000000);
  53. out_be32((void*)GPIO0_ISR1H, 0x00000000);
  54. out_be32((void*)GPIO0_ISR2L, 0x00000000);
  55. out_be32((void*)GPIO0_ISR2H, 0x00000100);
  56. out_be32((void*)GPIO0_ISR3L, 0x00000000);
  57. out_be32((void*)GPIO0_ISR3H, 0x00000000);
  58. out_be32((void*)GPIO1_OR, 0x00000000);
  59. out_be32((void*)GPIO1_TCR, 0xc2000000 |
  60. CFG_GPIO1_IORSTN |
  61. CFG_GPIO1_LEDUSR1 |
  62. CFG_GPIO1_LEDUSR2 |
  63. CFG_GPIO1_LEDPOST |
  64. CFG_GPIO1_LEDDU);
  65. out_be32((void*)GPIO1_ODR, CFG_GPIO1_LEDDU);
  66. out_be32((void*)GPIO1_OSRL, 0x5c280000);
  67. out_be32((void*)GPIO1_OSRH, 0x00000000);
  68. out_be32((void*)GPIO1_TSRL, 0x0c000000);
  69. out_be32((void*)GPIO1_TSRH, 0x00000000);
  70. out_be32((void*)GPIO1_ISR1L, 0x00005550);
  71. out_be32((void*)GPIO1_ISR1H, 0x00000000);
  72. out_be32((void*)GPIO1_ISR2L, 0x00050000);
  73. out_be32((void*)GPIO1_ISR2H, 0x00000000);
  74. out_be32((void*)GPIO1_ISR3L, 0x01400000);
  75. out_be32((void*)GPIO1_ISR3H, 0x00000000);
  76. /*
  77. * Setup the interrupt controller polarities, triggers, etc.
  78. */
  79. mtdcr(uic0sr, 0xffffffff); /* clear all */
  80. mtdcr(uic0er, 0x00000000); /* disable all */
  81. mtdcr(uic0cr, 0x00000005); /* ATI & UIC1 crit are critical */
  82. mtdcr(uic0pr, 0xfffff7ff); /* per ref-board manual */
  83. mtdcr(uic0tr, 0x00000000); /* per ref-board manual */
  84. mtdcr(uic0vr, 0x00000000); /* int31 highest, base=0x000 */
  85. mtdcr(uic0sr, 0xffffffff); /* clear all */
  86. /*
  87. * UIC1:
  88. * bit30: ext. Irq 1: PLD : int 32+30
  89. */
  90. mtdcr(uic1sr, 0xffffffff); /* clear all */
  91. mtdcr(uic1er, 0x00000000); /* disable all */
  92. mtdcr(uic1cr, 0x00000000); /* all non-critical */
  93. mtdcr(uic1pr, 0xfffffffd);
  94. mtdcr(uic1tr, 0x00000000);
  95. mtdcr(uic1vr, 0x00000000); /* int31 highest, base=0x000 */
  96. mtdcr(uic1sr, 0xffffffff); /* clear all */
  97. /*
  98. * UIC2
  99. * bit3: ext. Irq 2: DCF77 : int 64+3
  100. */
  101. mtdcr(uic2sr, 0xffffffff); /* clear all */
  102. mtdcr(uic2er, 0x00000000); /* disable all */
  103. mtdcr(uic2cr, 0x00000000); /* all non-critical */
  104. mtdcr(uic2pr, 0xffffffff); /* per ref-board manual */
  105. mtdcr(uic2tr, 0x00000000); /* per ref-board manual */
  106. mtdcr(uic2vr, 0x00000000); /* int31 highest, base=0x000 */
  107. mtdcr(uic2sr, 0xffffffff); /* clear all */
  108. /* select Ethernet pins */
  109. mfsdr(SDR0_PFC1, sdr0_pfc1);
  110. mfsdr(SDR0_PFC2, sdr0_pfc2);
  111. /* setup EMAC bridge interface */
  112. if (board_revision() == 0) {
  113. /* 1 x MII */
  114. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  115. SDR0_PFC1_SELECT_CONFIG_1_2;
  116. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  117. SDR0_PFC2_SELECT_CONFIG_1_2;
  118. } else {
  119. /* 2 x SMII */
  120. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SELECT_MASK) |
  121. SDR0_PFC1_SELECT_CONFIG_6;
  122. sdr0_pfc2 = (sdr0_pfc2 & ~SDR0_PFC2_SELECT_MASK) |
  123. SDR0_PFC2_SELECT_CONFIG_6;
  124. }
  125. /* enable 2nd IIC */
  126. sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_SIS_MASK) | SDR0_PFC1_SIS_IIC1_SEL;
  127. mtsdr(SDR0_PFC2, sdr0_pfc2);
  128. mtsdr(SDR0_PFC1, sdr0_pfc1);
  129. /* PCI arbiter enabled */
  130. mfsdr(sdr_pci0, reg);
  131. mtsdr(sdr_pci0, 0x80000000 | reg);
  132. /* setup NAND FLASH */
  133. mfsdr(SDR0_CUST0, sdr0_cust0);
  134. sdr0_cust0 = SDR0_CUST0_MUX_NDFC_SEL |
  135. SDR0_CUST0_NDFC_ENABLE |
  136. SDR0_CUST0_NDFC_BW_8_BIT |
  137. SDR0_CUST0_NDFC_ARE_MASK |
  138. (0x80000000 >> (28 + CFG_NAND0_CS)) |
  139. (0x80000000 >> (28 + CFG_NAND1_CS));
  140. mtsdr(SDR0_CUST0, sdr0_cust0);
  141. return 0;
  142. }
  143. int misc_init_r(void)
  144. {
  145. uint pbcr;
  146. int size_val = 0;
  147. u32 reg;
  148. unsigned long usb2d0cr = 0;
  149. unsigned long usb2phy0cr, usb2h0cr = 0;
  150. unsigned long sdr0_pfc1;
  151. int i, j;
  152. /* adjust flash start and offset */
  153. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  154. gd->bd->bi_flashoffset = 0;
  155. mtdcr(ebccfga, pb0cr);
  156. pbcr = mfdcr(ebccfgd);
  157. size_val = ffs(gd->bd->bi_flashsize) - 21;
  158. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  159. mtdcr(ebccfga, pb0cr);
  160. mtdcr(ebccfgd, pbcr);
  161. /*
  162. * Re-check to get correct base address
  163. */
  164. flash_get_size(gd->bd->bi_flashstart, 0);
  165. /*
  166. * USB suff...
  167. */
  168. /* SDR Setting */
  169. mfsdr(SDR0_PFC1, sdr0_pfc1);
  170. mfsdr(SDR0_USB0, usb2d0cr);
  171. mfsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  172. mfsdr(SDR0_USB2H0CR, usb2h0cr);
  173. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_XOCLK_MASK;
  174. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_XOCLK_EXTERNAL;
  175. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_WDINT_MASK;
  176. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_WDINT_16BIT_30MHZ;
  177. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DVBUS_MASK;
  178. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DVBUS_PURDIS;
  179. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_DWNSTR_MASK;
  180. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_DWNSTR_HOST;
  181. usb2phy0cr = usb2phy0cr &~SDR0_USB2PHY0CR_UTMICN_MASK;
  182. usb2phy0cr = usb2phy0cr | SDR0_USB2PHY0CR_UTMICN_HOST;
  183. /* An 8-bit/60MHz interface is the only possible alternative
  184. when connecting the Device to the PHY */
  185. usb2h0cr = usb2h0cr &~SDR0_USB2H0CR_WDINT_MASK;
  186. usb2h0cr = usb2h0cr | SDR0_USB2H0CR_WDINT_16BIT_30MHZ;
  187. /* To enable the USB 2.0 Device function through the UTMI interface */
  188. usb2d0cr = usb2d0cr &~SDR0_USB2D0CR_USB2DEV_EBC_SEL_MASK;
  189. sdr0_pfc1 = sdr0_pfc1 &~SDR0_PFC1_UES_MASK;
  190. sdr0_pfc1 = sdr0_pfc1 | SDR0_PFC1_UES_EBCHR_SEL;
  191. mtsdr(SDR0_PFC1, sdr0_pfc1);
  192. mtsdr(SDR0_USB0, usb2d0cr);
  193. mtsdr(SDR0_USB2PHY0CR, usb2phy0cr);
  194. mtsdr(SDR0_USB2H0CR, usb2h0cr);
  195. /* clear resets */
  196. udelay (1000);
  197. mtsdr(SDR0_SRST1, 0x00000000);
  198. udelay (1000);
  199. mtsdr(SDR0_SRST0, 0x00000000);
  200. printf("USB: Host(int phy)\n");
  201. /*
  202. * Clear PLB4A0_ACR[WRP]
  203. * This fix will make the MAL burst disabling patch for the Linux
  204. * EMAC driver obsolete.
  205. */
  206. reg = mfdcr(plb4_acr) & ~PLB4_ACR_WRP;
  207. mtdcr(plb4_acr, reg);
  208. /*
  209. * release IO-RST#
  210. * We have to wait at least 560ms until we may call usbhub_init
  211. */
  212. out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | CFG_GPIO1_IORSTN);
  213. /*
  214. * flash USR1/2 LEDs (600ms)
  215. * This results in the necessary delay from IORST# until
  216. * calling usbhub_init will succeed
  217. */
  218. for (j = 0; j < 3; j++) {
  219. out_be32((void*)GPIO1_OR,
  220. (in_be32((void*)GPIO1_OR) & ~CFG_GPIO1_LEDUSR2) |
  221. CFG_GPIO1_LEDUSR1);
  222. for (i = 0; i < 100; i++)
  223. udelay(1000);
  224. out_be32((void*)GPIO1_OR,
  225. (in_be32((void*)GPIO1_OR) & ~CFG_GPIO1_LEDUSR1) |
  226. CFG_GPIO1_LEDUSR2);
  227. for (i = 0; i < 100; i++)
  228. udelay(1000);
  229. }
  230. out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) &
  231. ~(CFG_GPIO1_LEDUSR1 | CFG_GPIO1_LEDUSR2));
  232. if (usbhub_init())
  233. du440_post_errors++;
  234. if (dvi_init())
  235. du440_post_errors++;
  236. return 0;
  237. }
  238. int pld_revision(void)
  239. {
  240. out8(CFG_CPLD_BASE, 0x00);
  241. return (int)(in8(CFG_CPLD_BASE) & CPLD_VERSION_MASK);
  242. }
  243. int board_revision(void)
  244. {
  245. int rpins = (int)((in_be32((void*)GPIO1_IR) & CFG_GPIO1_HWVER_MASK)
  246. >> CFG_GPIO1_HWVER_SHIFT);
  247. return ((rpins & 1) << 3) | ((rpins & 2) << 1) |
  248. ((rpins & 4) >> 1) | ((rpins & 8) >> 3);
  249. }
  250. #if defined(CONFIG_SHOW_ACTIVITY)
  251. void board_show_activity (ulong timestamp)
  252. {
  253. if ((timestamp % 100) == 0)
  254. out_be32((void*)GPIO1_OR,
  255. in_be32((void*)GPIO1_OR) ^ CFG_GPIO1_LEDUSR1);
  256. }
  257. void show_activity(int arg)
  258. {
  259. }
  260. #endif /* CONFIG_SHOW_ACTIVITY */
  261. int du440_phy_addr(int devnum)
  262. {
  263. if (board_revision() == 0)
  264. return devnum;
  265. return devnum + 1;
  266. }
  267. int checkboard(void)
  268. {
  269. char serno[32];
  270. puts("Board: DU440");
  271. if (getenv_r("serial#", serno, sizeof(serno)) > 0) {
  272. puts(", serial# ");
  273. puts(serno);
  274. }
  275. printf(", HW-Rev. 1.%d, CPLD-Rev. 1.%d\n",
  276. board_revision(), pld_revision());
  277. return (0);
  278. }
  279. /*
  280. * pci_pre_init
  281. *
  282. * This routine is called just prior to registering the hose and gives
  283. * the board the opportunity to check things. Returning a value of zero
  284. * indicates that things are bad & PCI initialization should be aborted.
  285. *
  286. * Different boards may wish to customize the pci controller structure
  287. * (add regions, override default access routines, etc) or perform
  288. * certain pre-initialization actions.
  289. */
  290. #if defined(CONFIG_PCI)
  291. int pci_pre_init(struct pci_controller *hose)
  292. {
  293. unsigned long addr;
  294. /*
  295. * Set priority for all PLB3 devices to 0.
  296. * Set PLB3 arbiter to fair mode.
  297. */
  298. mfsdr(sdr_amp1, addr);
  299. mtsdr(sdr_amp1, (addr & 0x000000FF) | 0x0000FF00);
  300. addr = mfdcr(plb3_acr);
  301. mtdcr(plb3_acr, addr | 0x80000000);
  302. /*
  303. * Set priority for all PLB4 devices to 0.
  304. */
  305. mfsdr(sdr_amp0, addr);
  306. mtsdr(sdr_amp0, (addr & 0x000000FF) | 0x0000FF00);
  307. addr = mfdcr(plb4_acr) | 0xa0000000; /* Was 0x8---- */
  308. mtdcr(plb4_acr, addr);
  309. /*
  310. * Set Nebula PLB4 arbiter to fair mode.
  311. */
  312. /* Segment0 */
  313. addr = (mfdcr(plb0_acr) & ~plb0_acr_ppm_mask) | plb0_acr_ppm_fair;
  314. addr = (addr & ~plb0_acr_hbu_mask) | plb0_acr_hbu_enabled;
  315. addr = (addr & ~plb0_acr_rdp_mask) | plb0_acr_rdp_4deep;
  316. addr = (addr & ~plb0_acr_wrp_mask) | plb0_acr_wrp_2deep;
  317. mtdcr(plb0_acr, addr);
  318. /* Segment1 */
  319. addr = (mfdcr(plb1_acr) & ~plb1_acr_ppm_mask) | plb1_acr_ppm_fair;
  320. addr = (addr & ~plb1_acr_hbu_mask) | plb1_acr_hbu_enabled;
  321. addr = (addr & ~plb1_acr_rdp_mask) | plb1_acr_rdp_4deep;
  322. addr = (addr & ~plb1_acr_wrp_mask) | plb1_acr_wrp_2deep;
  323. mtdcr(plb1_acr, addr);
  324. return 1;
  325. }
  326. #endif /* defined(CONFIG_PCI) */
  327. /*
  328. * pci_target_init
  329. *
  330. * The bootstrap configuration provides default settings for the pci
  331. * inbound map (PIM). But the bootstrap config choices are limited and
  332. * may not be sufficient for a given board.
  333. */
  334. #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
  335. void pci_target_init(struct pci_controller *hose)
  336. {
  337. /*
  338. * Set up Direct MMIO registers
  339. */
  340. /*
  341. * PowerPC440EPX PCI Master configuration.
  342. * Map one 1Gig range of PLB/processor addresses to PCI memory space.
  343. * PLB address 0xA0000000-0xDFFFFFFF
  344. * ==> PCI address 0xA0000000-0xDFFFFFFF
  345. * Use byte reversed out routines to handle endianess.
  346. * Make this region non-prefetchable.
  347. */
  348. out32r(PCIX0_PMM0MA, 0x00000000); /* PMM0 Mask/Attribute */
  349. /* - disabled b4 setting */
  350. out32r(PCIX0_PMM0LA, CFG_PCI_MEMBASE); /* PMM0 Local Address */
  351. out32r(PCIX0_PMM0PCILA, CFG_PCI_MEMBASE); /* PMM0 PCI Low Address */
  352. out32r(PCIX0_PMM0PCIHA, 0x00000000); /* PMM0 PCI High Address */
  353. out32r(PCIX0_PMM0MA, 0xE0000001); /* 512M + No prefetching, */
  354. /* and enable region */
  355. out32r(PCIX0_PMM1MA, 0x00000000); /* PMM0 Mask/Attribute */
  356. /* - disabled b4 setting */
  357. out32r(PCIX0_PMM1LA, CFG_PCI_MEMBASE2); /* PMM0 Local Address */
  358. out32r(PCIX0_PMM1PCILA, CFG_PCI_MEMBASE2); /* PMM0 PCI Low Address */
  359. out32r(PCIX0_PMM1PCIHA, 0x00000000); /* PMM0 PCI High Address */
  360. out32r(PCIX0_PMM1MA, 0xE0000001); /* 512M + No prefetching, */
  361. /* and enable region */
  362. out32r(PCIX0_PTM1MS, 0x00000001); /* Memory Size/Attribute */
  363. out32r(PCIX0_PTM1LA, 0); /* Local Addr. Reg */
  364. out32r(PCIX0_PTM2MS, 0); /* Memory Size/Attribute */
  365. out32r(PCIX0_PTM2LA, 0); /* Local Addr. Reg */
  366. /*
  367. * Set up Configuration registers
  368. */
  369. /* Program the board's subsystem id/vendor id */
  370. pci_write_config_word(0, PCI_SUBSYSTEM_VENDOR_ID,
  371. PCI_VENDOR_ID_ESDGMBH);
  372. pci_write_config_word(0, PCI_SUBSYSTEM_ID, PCI_DEVICE_ID_DU440);
  373. pci_write_config_word(0, PCI_CLASS_SUB_CODE, PCI_CLASS_BRIDGE_HOST);
  374. /* Configure command register as bus master */
  375. pci_write_config_word(0, PCI_COMMAND, PCI_COMMAND_MASTER);
  376. /* 240nS PCI clock */
  377. pci_write_config_word(0, PCI_LATENCY_TIMER, 1);
  378. /* No error reporting */
  379. pci_write_config_word(0, PCI_ERREN, 0);
  380. pci_write_config_dword(0, PCI_BRDGOPT2, 0x00000101);
  381. }
  382. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
  383. #if defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT)
  384. void pci_master_init(struct pci_controller *hose)
  385. {
  386. unsigned short temp_short;
  387. /*
  388. * Write the PowerPC440 EP PCI Configuration regs.
  389. * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  390. * Enable PowerPC440 EP to act as a PCI memory target (PTM).
  391. */
  392. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  393. pci_write_config_word(0, PCI_COMMAND,
  394. temp_short | PCI_COMMAND_MASTER |
  395. PCI_COMMAND_MEMORY);
  396. }
  397. #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_MASTER_INIT) */
  398. /*
  399. * is_pci_host
  400. *
  401. * This routine is called to determine if a pci scan should be
  402. * performed. With various hardware environments (especially cPCI and
  403. * PPMC) it's insufficient to depend on the state of the arbiter enable
  404. * bit in the strap register, or generic host/adapter assumptions.
  405. *
  406. * Rather than hard-code a bad assumption in the general 440 code, the
  407. * 440 pci code requires the board to decide at runtime.
  408. *
  409. * Return 0 for adapter mode, non-zero for host (monarch) mode.
  410. */
  411. #if defined(CONFIG_PCI)
  412. int is_pci_host(struct pci_controller *hose)
  413. {
  414. /* always configured as host. */
  415. return (1);
  416. }
  417. #endif /* defined(CONFIG_PCI) */
  418. int last_stage_init(void)
  419. {
  420. int e, i;
  421. /* everyting is ok: turn on POST-LED */
  422. out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | CFG_GPIO1_LEDPOST);
  423. /* slowly blink on errors and finally keep LED off */
  424. for (e = 0; e < du440_post_errors; e++) {
  425. out_be32((void*)GPIO1_OR,
  426. in_be32((void*)GPIO1_OR) | CFG_GPIO1_LEDPOST);
  427. for (i = 0; i < 500; i++)
  428. udelay(1000);
  429. out_be32((void*)GPIO1_OR,
  430. in_be32((void*)GPIO1_OR) & ~CFG_GPIO1_LEDPOST);
  431. for (i = 0; i < 500; i++)
  432. udelay(1000);
  433. }
  434. return 0;
  435. }
  436. #if defined(CONFIG_I2C_MULTI_BUS)
  437. /*
  438. * read field strength from I2C ADC
  439. */
  440. int dcf77_status(void)
  441. {
  442. unsigned int oldbus;
  443. uchar u[2];
  444. int mv;
  445. oldbus = I2C_GET_BUS();
  446. I2C_SET_BUS(1);
  447. if (i2c_read (IIC1_MCP3021_ADDR, 0, 0, u, 2)) {
  448. I2C_SET_BUS(oldbus);
  449. return -1;
  450. }
  451. mv = (int)(((u[0] << 8) | u[1]) >> 2) * 3300 / 1024;
  452. I2C_SET_BUS(oldbus);
  453. return mv;
  454. }
  455. int do_dcf77(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  456. {
  457. int mv;
  458. u32 pin, pinold;
  459. unsigned long long t1, t2;
  460. bd_t *bd = gd->bd;
  461. printf("DCF77: ");
  462. mv = dcf77_status();
  463. if (mv > 0)
  464. printf("signal=%d mV\n", mv);
  465. else
  466. printf("ERROR - no signal\n");
  467. t1 = t2 = 0;
  468. pinold = in_be32((void*)GPIO1_IR) & CFG_GPIO1_DCF77;
  469. while (!ctrlc()) {
  470. pin = in_be32((void*)GPIO1_IR) & CFG_GPIO1_DCF77;
  471. if (pin && !pinold) { /* bit start */
  472. t1 = get_ticks();
  473. if (t2 && ((unsigned int)(t1 - t2) /
  474. (bd->bi_procfreq / 1000) >= 1800))
  475. printf("Start of minute\n");
  476. t2 = t1;
  477. }
  478. if (t1 && !pin && pinold) { /* bit end */
  479. printf("%5d\n", (unsigned int)(get_ticks() - t1) /
  480. (bd->bi_procfreq / 1000));
  481. }
  482. pinold = pin;
  483. }
  484. printf("Abort\n");
  485. return 0;
  486. }
  487. U_BOOT_CMD(
  488. dcf77, 1, 1, do_dcf77,
  489. "dcf77 - Check DCF77 receiver\n",
  490. NULL
  491. );
  492. /*
  493. * initialize USB hub via I2C1
  494. */
  495. int usbhub_init(void)
  496. {
  497. int reg;
  498. int ret = 0;
  499. unsigned int oldbus;
  500. uchar u[] = {0x04, 0x24, 0x04, 0x07, 0x25, 0x00, 0x00, 0xd3,
  501. 0x18, 0xe0, 0x00, 0x00, 0x01, 0x64, 0x01, 0x64,
  502. 0x32};
  503. uchar stcd;
  504. printf("Hub: ");
  505. oldbus = I2C_GET_BUS();
  506. I2C_SET_BUS(1);
  507. for (reg = 0; reg < sizeof(u); reg++)
  508. if (i2c_write (IIC1_USB2507_ADDR, reg, 1, &u[reg], 1)) {
  509. ret = -1;
  510. break;
  511. }
  512. if (ret == 0) {
  513. stcd = 0x03;
  514. if (i2c_write (IIC1_USB2507_ADDR, 0, 1, &stcd, 1))
  515. ret = -1;
  516. }
  517. if (ret == 0)
  518. printf("initialized\n");
  519. else
  520. printf("failed - cannot initialize USB hub\n");
  521. I2C_SET_BUS(oldbus);
  522. return ret;
  523. }
  524. int do_hubinit(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  525. {
  526. usbhub_init();
  527. return 0;
  528. }
  529. U_BOOT_CMD(
  530. hubinit, 1, 1, do_hubinit,
  531. "hubinit - Initialize USB hub\n",
  532. NULL
  533. );
  534. #endif /* CONFIG_I2C_MULTI_BUS */
  535. #define CFG_BOOT_EEPROM_PAGE_WRITE_BITS 3
  536. int boot_eeprom_write (unsigned dev_addr,
  537. unsigned offset,
  538. uchar *buffer,
  539. unsigned cnt)
  540. {
  541. unsigned end = offset + cnt;
  542. unsigned blk_off;
  543. int rcode = 0;
  544. #if defined(CFG_EEPROM_WREN)
  545. eeprom_write_enable(dev_addr, 1);
  546. #endif
  547. /*
  548. * Write data until done or would cross a write page boundary.
  549. * We must write the address again when changing pages
  550. * because the address counter only increments within a page.
  551. */
  552. while (offset < end) {
  553. unsigned alen, len;
  554. unsigned maxlen;
  555. uchar addr[2];
  556. blk_off = offset & 0xFF; /* block offset */
  557. addr[0] = offset >> 8; /* block number */
  558. addr[1] = blk_off; /* block offset */
  559. alen = 2;
  560. addr[0] |= dev_addr; /* insert device address */
  561. len = end - offset;
  562. /*
  563. * For a FRAM device there is no limit on the number of the
  564. * bytes that can be ccessed with the single read or write
  565. * operation.
  566. */
  567. #if defined(CFG_BOOT_EEPROM_PAGE_WRITE_BITS)
  568. #define BOOT_EEPROM_PAGE_SIZE (1 << CFG_BOOT_EEPROM_PAGE_WRITE_BITS)
  569. #define BOOT_EEPROM_PAGE_OFFSET(x) ((x) & (BOOT_EEPROM_PAGE_SIZE - 1))
  570. maxlen = BOOT_EEPROM_PAGE_SIZE -
  571. BOOT_EEPROM_PAGE_OFFSET(blk_off);
  572. #else
  573. maxlen = 0x100 - blk_off;
  574. #endif
  575. if (maxlen > I2C_RXTX_LEN)
  576. maxlen = I2C_RXTX_LEN;
  577. if (len > maxlen)
  578. len = maxlen;
  579. if (i2c_write (addr[0], offset, alen - 1, buffer, len) != 0)
  580. rcode = 1;
  581. buffer += len;
  582. offset += len;
  583. #if defined(CFG_EEPROM_PAGE_WRITE_DELAY_MS)
  584. udelay(CFG_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  585. #endif
  586. }
  587. #if defined(CFG_EEPROM_WREN)
  588. eeprom_write_enable(dev_addr, 0);
  589. #endif
  590. return rcode;
  591. }
  592. int do_setup_boot_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  593. {
  594. ulong sdsdp[4];
  595. if (argc > 1) {
  596. if (!strcmp(argv[1], "533")) {
  597. printf("Bootstrapping for 533MHz\n");
  598. sdsdp[0] = 0x87788252;
  599. /* PLB-PCI-divider = 3 : sync PCI clock=44MHz */
  600. sdsdp[1] = 0x095fa030;
  601. sdsdp[2] = 0x40082350;
  602. sdsdp[3] = 0x0d050000;
  603. } else if (!strcmp(argv[1], "533-66")) {
  604. printf("Bootstrapping for 533MHz (66MHz PCI)\n");
  605. sdsdp[0] = 0x87788252;
  606. /* PLB-PCI-divider = 2 : sync PCI clock=66MHz */
  607. sdsdp[1] = 0x0957a030;
  608. sdsdp[2] = 0x40082350;
  609. sdsdp[3] = 0x0d050000;
  610. } else if (!strcmp(argv[1], "667")) {
  611. printf("Bootstrapping for 667MHz\n");
  612. sdsdp[0] = 0x8778a256;
  613. /* PLB-PCI-divider = 4 : sync PCI clock=33MHz */
  614. sdsdp[1] = 0x0947a030;
  615. /* PLB-PCI-divider = 3 : sync PCI clock=44MHz
  616. * -> not working when overclocking 533MHz chips
  617. * -> untested on 667MHz chips */
  618. /* sdsdp[1]=0x095fa030; */
  619. sdsdp[2] = 0x40082350;
  620. sdsdp[3] = 0x0d050000;
  621. }
  622. } else {
  623. printf("Bootstrapping for 533MHz (default)\n");
  624. sdsdp[0] = 0x87788252;
  625. /* PLB-PCI-divider = 3 : sync PCI clock=44MHz */
  626. sdsdp[1] = 0x095fa030;
  627. sdsdp[2] = 0x40082350;
  628. sdsdp[3] = 0x0d050000;
  629. }
  630. printf("Writing boot EEPROM ...\n");
  631. if (boot_eeprom_write(CFG_I2C_BOOT_EEPROM_ADDR,
  632. 0, (uchar*)sdsdp, 16) != 0)
  633. printf("boot_eeprom_write failed\n");
  634. else
  635. printf("done (dump via 'i2c md 52 0.1 10')\n");
  636. return 0;
  637. }
  638. U_BOOT_CMD(
  639. sbe, 2, 0, do_setup_boot_eeprom,
  640. "sbe - setup boot eeprom\n",
  641. NULL
  642. );
  643. #if defined(CFG_EEPROM_WREN)
  644. /*
  645. * Input: <dev_addr> I2C address of EEPROM device to enable.
  646. * <state> -1: deliver current state
  647. * 0: disable write
  648. * 1: enable write
  649. * Returns: -1: wrong device address
  650. * 0: dis-/en- able done
  651. * 0/1: current state if <state> was -1.
  652. */
  653. int eeprom_write_enable (unsigned dev_addr, int state)
  654. {
  655. if ((CFG_I2C_EEPROM_ADDR != dev_addr) &&
  656. (CFG_I2C_BOOT_EEPROM_ADDR != dev_addr))
  657. return -1;
  658. else {
  659. switch (state) {
  660. case 1:
  661. /* Enable write access, clear bit GPIO_SINT2. */
  662. out_be32((void*)GPIO0_OR,
  663. in_be32((void*)GPIO0_OR) & ~CFG_GPIO0_EP_EEP);
  664. state = 0;
  665. break;
  666. case 0:
  667. /* Disable write access, set bit GPIO_SINT2. */
  668. out_be32((void*)GPIO0_OR,
  669. in_be32((void*)GPIO0_OR) | CFG_GPIO0_EP_EEP);
  670. state = 0;
  671. break;
  672. default:
  673. /* Read current status back. */
  674. state = (0 == (in_be32((void*)GPIO0_OR) &
  675. CFG_GPIO0_EP_EEP));
  676. break;
  677. }
  678. }
  679. return state;
  680. }
  681. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  682. {
  683. int query = argc == 1;
  684. int state = 0;
  685. if (query) {
  686. /* Query write access state. */
  687. state = eeprom_write_enable(CFG_I2C_EEPROM_ADDR, -1);
  688. if (state < 0)
  689. puts ("Query of write access state failed.\n");
  690. else {
  691. printf ("Write access for device 0x%0x is %sabled.\n",
  692. CFG_I2C_EEPROM_ADDR, state ? "en" : "dis");
  693. state = 0;
  694. }
  695. } else {
  696. if ('0' == argv[1][0]) {
  697. /* Disable write access. */
  698. state = eeprom_write_enable(CFG_I2C_EEPROM_ADDR, 0);
  699. } else {
  700. /* Enable write access. */
  701. state = eeprom_write_enable(CFG_I2C_EEPROM_ADDR, 1);
  702. }
  703. if (state < 0)
  704. puts ("Setup of write access state failed.\n");
  705. }
  706. return state;
  707. }
  708. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  709. "eepwren - Enable / disable / query EEPROM write access\n",
  710. NULL);
  711. #endif /* #if defined(CFG_EEPROM_WREN) */
  712. static int got_pldirq;
  713. static int pld_interrupt(u32 arg)
  714. {
  715. int rc = -1; /* not for us */
  716. u8 status = in8(CFG_CPLD_BASE);
  717. /* check for PLD interrupt */
  718. if (status & PWR_INT_FLAG) {
  719. /* reset this int */
  720. out8(CFG_CPLD_BASE, 0);
  721. rc = 0;
  722. got_pldirq = 1; /* trigger backend */
  723. }
  724. return rc;
  725. }
  726. int do_waitpwrirq(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  727. {
  728. got_pldirq = 0;
  729. /* clear any pending interrupt */
  730. out8(CFG_CPLD_BASE, 0);
  731. irq_install_handler(CPLD_IRQ,
  732. (interrupt_handler_t *)pld_interrupt, 0);
  733. printf("Waiting ...\n");
  734. while(!got_pldirq) {
  735. /* Abort if ctrl-c was pressed */
  736. if (ctrlc()) {
  737. puts("\nAbort\n");
  738. break;
  739. }
  740. }
  741. if (got_pldirq) {
  742. printf("Got interrupt!\n");
  743. printf("Power %sready!\n",
  744. in8(CFG_CPLD_BASE) & PWR_RDY ? "":"NOT ");
  745. }
  746. irq_free_handler(CPLD_IRQ);
  747. return 0;
  748. }
  749. U_BOOT_CMD(
  750. wpi, 1, 1, do_waitpwrirq,
  751. "wpi - Wait for power change interrupt\n",
  752. NULL
  753. );
  754. /*
  755. * initialize DVI panellink transmitter
  756. */
  757. int dvi_init(void)
  758. {
  759. int i;
  760. int ret = 0;
  761. unsigned int oldbus;
  762. uchar u[] = {0x08, 0x34,
  763. 0x09, 0x20,
  764. 0x0a, 0x90,
  765. 0x0c, 0x89,
  766. 0x08, 0x35};
  767. printf("DVI: ");
  768. oldbus = I2C_GET_BUS();
  769. I2C_SET_BUS(0);
  770. for (i = 0; i < sizeof(u); i += 2)
  771. if (i2c_write (0x38, u[i], 1, &u[i + 1], 1)) {
  772. ret = -1;
  773. break;
  774. }
  775. if (ret == 0)
  776. printf("initialized\n");
  777. else
  778. printf("failed - cannot initialize DVI transmitter\n");
  779. I2C_SET_BUS(oldbus);
  780. return ret;
  781. }
  782. int do_dviinit(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  783. {
  784. dvi_init();
  785. return 0;
  786. }
  787. U_BOOT_CMD(
  788. dviinit, 1, 1, do_dviinit,
  789. "dviinit - Initialize DVI Panellink transmitter\n",
  790. NULL
  791. );
  792. /*
  793. * TODO: 'time' command might be useful for others as well.
  794. * Move to 'common' directory.
  795. */
  796. int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  797. {
  798. unsigned long long start, end;
  799. char c, cmd[CFG_CBSIZE];
  800. char *p, *d = cmd;
  801. int ret, i;
  802. ulong us;
  803. for (i = 1; i < argc; i++) {
  804. p = argv[i];
  805. if (i > 1)
  806. *d++ = ' ';
  807. while ((c = *p++) != '\0') {
  808. *d++ = c;
  809. }
  810. }
  811. *d = '\0';
  812. start = get_ticks();
  813. ret = run_command (cmd, 0);
  814. end = get_ticks();
  815. printf("ticks=%d\n", (ulong)(end - start));
  816. us = (ulong)((1000L * (end - start)) / (get_tbclk() / 1000));
  817. printf("usec=%d\n", us);
  818. return ret;
  819. }
  820. U_BOOT_CMD(
  821. time, CFG_MAXARGS, 1, do_time,
  822. "time - run command and output execution time\n",
  823. NULL
  824. );
  825. extern void video_hw_rectfill (
  826. unsigned int bpp, /* bytes per pixel */
  827. unsigned int dst_x, /* dest pos x */
  828. unsigned int dst_y, /* dest pos y */
  829. unsigned int dim_x, /* frame width */
  830. unsigned int dim_y, /* frame height */
  831. unsigned int color /* fill color */
  832. );
  833. /*
  834. * graphics demo
  835. * draw rectangles using pseudorandom number generator
  836. * (see http://www.embedded.com/columns/technicalinsights/20900500)
  837. */
  838. unsigned int rprime = 9972;
  839. static unsigned int r;
  840. static unsigned int Y;
  841. unsigned int prng(unsigned int max)
  842. {
  843. if (r == 0 || r == 1 || r == -1)
  844. r = rprime; /* keep from getting stuck */
  845. r = (9973 * ~r) + ((Y) % 701); /* the actual algorithm */
  846. Y = (r >> 16) % max; /* choose upper bits and reduce */
  847. return Y;
  848. }
  849. int do_gfxdemo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  850. {
  851. unsigned int color;
  852. unsigned int x, y, dx, dy;
  853. while (!ctrlc()) {
  854. x = prng(1280 - 1);
  855. y = prng(1024 - 1);
  856. dx = prng(1280- x - 1);
  857. dy = prng(1024 - y - 1);
  858. color = prng(0x10000);
  859. video_hw_rectfill(2, x, y, dx, dy, color);
  860. }
  861. return 0;
  862. }
  863. U_BOOT_CMD(
  864. gfxdemo, CFG_MAXARGS, 1, do_gfxdemo,
  865. "gfxdemo - demo\n",
  866. NULL
  867. );