du440.c 26 KB

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