du440.c 25 KB

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