du440.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  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(EBC0_CFGADDR, EBC0_CFG);
  42. mtdcr(EBC0_CFGDATA, 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(SDR0_PCI0, reg);
  132. mtsdr(SDR0_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(EBC0_CFGADDR, PB0CR);
  158. pbcr = mfdcr(EBC0_CFGDATA);
  159. size_val = ffs(gd->bd->bi_flashsize) - 21;
  160. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  161. mtdcr(EBC0_CFGADDR, PB0CR);
  162. mtdcr(EBC0_CFGDATA, 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(SD0_AMP1, addr);
  327. mtsdr(SD0_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(SD0_AMP0, addr);
  334. mtsdr(SD0_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. #if defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT)
  356. void pci_master_init(struct pci_controller *hose)
  357. {
  358. unsigned short temp_short;
  359. /*
  360. * Write the PowerPC440 EP PCI Configuration regs.
  361. * Enable PowerPC440 EP to be a master on the PCI bus (PMM).
  362. * Enable PowerPC440 EP to act as a PCI memory target (PTM).
  363. */
  364. pci_read_config_word(0, PCI_COMMAND, &temp_short);
  365. pci_write_config_word(0, PCI_COMMAND,
  366. temp_short | PCI_COMMAND_MASTER |
  367. PCI_COMMAND_MEMORY);
  368. }
  369. #endif /* defined(CONFIG_PCI) && defined(CONFIG_SYS_PCI_MASTER_INIT) */
  370. int last_stage_init(void)
  371. {
  372. int e, i;
  373. /* everyting is ok: turn on POST-LED */
  374. out_be32((void*)GPIO1_OR, in_be32((void*)GPIO1_OR) | CONFIG_SYS_GPIO1_LEDPOST);
  375. /* slowly blink on errors and finally keep LED off */
  376. for (e = 0; e < du440_post_errors; e++) {
  377. out_be32((void*)GPIO1_OR,
  378. in_be32((void*)GPIO1_OR) | CONFIG_SYS_GPIO1_LEDPOST);
  379. for (i = 0; i < 500; i++)
  380. udelay(1000);
  381. out_be32((void*)GPIO1_OR,
  382. in_be32((void*)GPIO1_OR) & ~CONFIG_SYS_GPIO1_LEDPOST);
  383. for (i = 0; i < 500; i++)
  384. udelay(1000);
  385. }
  386. return 0;
  387. }
  388. #if defined(CONFIG_I2C_MULTI_BUS)
  389. /*
  390. * read field strength from I2C ADC
  391. */
  392. int dcf77_status(void)
  393. {
  394. unsigned int oldbus;
  395. uchar u[2];
  396. int mv;
  397. oldbus = I2C_GET_BUS();
  398. I2C_SET_BUS(1);
  399. if (i2c_read (IIC1_MCP3021_ADDR, 0, 0, u, 2)) {
  400. I2C_SET_BUS(oldbus);
  401. return -1;
  402. }
  403. mv = (int)(((u[0] << 8) | u[1]) >> 2) * 3300 / 1024;
  404. I2C_SET_BUS(oldbus);
  405. return mv;
  406. }
  407. int do_dcf77(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  408. {
  409. int mv;
  410. u32 pin, pinold;
  411. unsigned long long t1, t2;
  412. bd_t *bd = gd->bd;
  413. printf("DCF77: ");
  414. mv = dcf77_status();
  415. if (mv > 0)
  416. printf("signal=%d mV\n", mv);
  417. else
  418. printf("ERROR - no signal\n");
  419. t1 = t2 = 0;
  420. pinold = in_be32((void*)GPIO1_IR) & CONFIG_SYS_GPIO1_DCF77;
  421. while (!ctrlc()) {
  422. pin = in_be32((void*)GPIO1_IR) & CONFIG_SYS_GPIO1_DCF77;
  423. if (pin && !pinold) { /* bit start */
  424. t1 = get_ticks();
  425. if (t2 && ((unsigned int)(t1 - t2) /
  426. (bd->bi_procfreq / 1000) >= 1800))
  427. printf("Start of minute\n");
  428. t2 = t1;
  429. }
  430. if (t1 && !pin && pinold) { /* bit end */
  431. printf("%5d\n", (unsigned int)(get_ticks() - t1) /
  432. (bd->bi_procfreq / 1000));
  433. }
  434. pinold = pin;
  435. }
  436. printf("Abort\n");
  437. return 0;
  438. }
  439. U_BOOT_CMD(
  440. dcf77, 1, 1, do_dcf77,
  441. "Check DCF77 receiver",
  442. ""
  443. );
  444. /*
  445. * initialize USB hub via I2C1
  446. */
  447. int usbhub_init(void)
  448. {
  449. int reg;
  450. int ret = 0;
  451. unsigned int oldbus;
  452. uchar u[] = {0x04, 0x24, 0x04, 0x07, 0x25, 0x00, 0x00, 0xd3,
  453. 0x18, 0xe0, 0x00, 0x00, 0x01, 0x64, 0x01, 0x64,
  454. 0x32};
  455. uchar stcd;
  456. printf("Hub: ");
  457. oldbus = I2C_GET_BUS();
  458. I2C_SET_BUS(1);
  459. for (reg = 0; reg < sizeof(u); reg++)
  460. if (i2c_write (IIC1_USB2507_ADDR, reg, 1, &u[reg], 1)) {
  461. ret = -1;
  462. break;
  463. }
  464. if (ret == 0) {
  465. stcd = 0x03;
  466. if (i2c_write (IIC1_USB2507_ADDR, 0, 1, &stcd, 1))
  467. ret = -1;
  468. }
  469. if (ret == 0)
  470. printf("initialized\n");
  471. else
  472. printf("failed - cannot initialize USB hub\n");
  473. I2C_SET_BUS(oldbus);
  474. return ret;
  475. }
  476. int do_hubinit(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  477. {
  478. usbhub_init();
  479. return 0;
  480. }
  481. U_BOOT_CMD(
  482. hubinit, 1, 1, do_hubinit,
  483. "Initialize USB hub",
  484. ""
  485. );
  486. #endif /* CONFIG_I2C_MULTI_BUS */
  487. #define CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS 3
  488. int boot_eeprom_write (unsigned dev_addr,
  489. unsigned offset,
  490. uchar *buffer,
  491. unsigned cnt)
  492. {
  493. unsigned end = offset + cnt;
  494. unsigned blk_off;
  495. int rcode = 0;
  496. #if defined(CONFIG_SYS_EEPROM_WREN)
  497. eeprom_write_enable(dev_addr, 1);
  498. #endif
  499. /*
  500. * Write data until done or would cross a write page boundary.
  501. * We must write the address again when changing pages
  502. * because the address counter only increments within a page.
  503. */
  504. while (offset < end) {
  505. unsigned alen, len;
  506. unsigned maxlen;
  507. uchar addr[2];
  508. blk_off = offset & 0xFF; /* block offset */
  509. addr[0] = offset >> 8; /* block number */
  510. addr[1] = blk_off; /* block offset */
  511. alen = 2;
  512. addr[0] |= dev_addr; /* insert device address */
  513. len = end - offset;
  514. /*
  515. * For a FRAM device there is no limit on the number of the
  516. * bytes that can be ccessed with the single read or write
  517. * operation.
  518. */
  519. #if defined(CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS)
  520. #define BOOT_EEPROM_PAGE_SIZE (1 << CONFIG_SYS_BOOT_EEPROM_PAGE_WRITE_BITS)
  521. #define BOOT_EEPROM_PAGE_OFFSET(x) ((x) & (BOOT_EEPROM_PAGE_SIZE - 1))
  522. maxlen = BOOT_EEPROM_PAGE_SIZE -
  523. BOOT_EEPROM_PAGE_OFFSET(blk_off);
  524. #else
  525. maxlen = 0x100 - blk_off;
  526. #endif
  527. if (maxlen > I2C_RXTX_LEN)
  528. maxlen = I2C_RXTX_LEN;
  529. if (len > maxlen)
  530. len = maxlen;
  531. if (i2c_write (addr[0], offset, alen - 1, buffer, len) != 0)
  532. rcode = 1;
  533. buffer += len;
  534. offset += len;
  535. #if defined(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS)
  536. udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
  537. #endif
  538. }
  539. #if defined(CONFIG_SYS_EEPROM_WREN)
  540. eeprom_write_enable(dev_addr, 0);
  541. #endif
  542. return rcode;
  543. }
  544. int do_setup_boot_eeprom(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  545. {
  546. ulong sdsdp[4];
  547. if (argc > 1) {
  548. if (!strcmp(argv[1], "533")) {
  549. printf("Bootstrapping for 533MHz\n");
  550. sdsdp[0] = 0x87788252;
  551. /* PLB-PCI-divider = 3 : sync PCI clock=44MHz */
  552. sdsdp[1] = 0x095fa030;
  553. sdsdp[2] = 0x40082350;
  554. sdsdp[3] = 0x0d050000;
  555. } else if (!strcmp(argv[1], "533-66")) {
  556. printf("Bootstrapping for 533MHz (66MHz PCI)\n");
  557. sdsdp[0] = 0x87788252;
  558. /* PLB-PCI-divider = 2 : sync PCI clock=66MHz */
  559. sdsdp[1] = 0x0957a030;
  560. sdsdp[2] = 0x40082350;
  561. sdsdp[3] = 0x0d050000;
  562. } else if (!strcmp(argv[1], "667")) {
  563. printf("Bootstrapping for 667MHz\n");
  564. sdsdp[0] = 0x8778a256;
  565. /* PLB-PCI-divider = 4 : sync PCI clock=33MHz */
  566. sdsdp[1] = 0x0947a030;
  567. /* PLB-PCI-divider = 3 : sync PCI clock=44MHz
  568. * -> not working when overclocking 533MHz chips
  569. * -> untested on 667MHz chips */
  570. /* sdsdp[1]=0x095fa030; */
  571. sdsdp[2] = 0x40082350;
  572. sdsdp[3] = 0x0d050000;
  573. } else if (!strcmp(argv[1], "667-166")) {
  574. printf("Bootstrapping for 667-166MHz\n");
  575. sdsdp[0] = 0x8778a252;
  576. sdsdp[1] = 0x09d7a030;
  577. sdsdp[2] = 0x40082350;
  578. sdsdp[3] = 0x0d050000;
  579. }
  580. } else {
  581. printf("Bootstrapping for 533MHz (default)\n");
  582. sdsdp[0] = 0x87788252;
  583. /* PLB-PCI-divider = 3 : sync PCI clock=44MHz */
  584. sdsdp[1] = 0x095fa030;
  585. sdsdp[2] = 0x40082350;
  586. sdsdp[3] = 0x0d050000;
  587. }
  588. printf("Writing boot EEPROM ...\n");
  589. if (boot_eeprom_write(CONFIG_SYS_I2C_BOOT_EEPROM_ADDR,
  590. 0, (uchar*)sdsdp, 16) != 0)
  591. printf("boot_eeprom_write failed\n");
  592. else
  593. printf("done (dump via 'i2c md 52 0.1 10')\n");
  594. return 0;
  595. }
  596. U_BOOT_CMD(
  597. sbe, 2, 0, do_setup_boot_eeprom,
  598. "setup boot eeprom",
  599. ""
  600. );
  601. #if defined(CONFIG_SYS_EEPROM_WREN)
  602. /*
  603. * Input: <dev_addr> I2C address of EEPROM device to enable.
  604. * <state> -1: deliver current state
  605. * 0: disable write
  606. * 1: enable write
  607. * Returns: -1: wrong device address
  608. * 0: dis-/en- able done
  609. * 0/1: current state if <state> was -1.
  610. */
  611. int eeprom_write_enable (unsigned dev_addr, int state)
  612. {
  613. if ((CONFIG_SYS_I2C_EEPROM_ADDR != dev_addr) &&
  614. (CONFIG_SYS_I2C_BOOT_EEPROM_ADDR != dev_addr))
  615. return -1;
  616. else {
  617. switch (state) {
  618. case 1:
  619. /* Enable write access, clear bit GPIO_SINT2. */
  620. out_be32((void*)GPIO0_OR,
  621. in_be32((void*)GPIO0_OR) & ~CONFIG_SYS_GPIO0_EP_EEP);
  622. state = 0;
  623. break;
  624. case 0:
  625. /* Disable write access, set bit GPIO_SINT2. */
  626. out_be32((void*)GPIO0_OR,
  627. in_be32((void*)GPIO0_OR) | CONFIG_SYS_GPIO0_EP_EEP);
  628. state = 0;
  629. break;
  630. default:
  631. /* Read current status back. */
  632. state = (0 == (in_be32((void*)GPIO0_OR) &
  633. CONFIG_SYS_GPIO0_EP_EEP));
  634. break;
  635. }
  636. }
  637. return state;
  638. }
  639. int do_eep_wren (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  640. {
  641. int query = argc == 1;
  642. int state = 0;
  643. if (query) {
  644. /* Query write access state. */
  645. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, -1);
  646. if (state < 0)
  647. puts ("Query of write access state failed.\n");
  648. else {
  649. printf ("Write access for device 0x%0x is %sabled.\n",
  650. CONFIG_SYS_I2C_EEPROM_ADDR, state ? "en" : "dis");
  651. state = 0;
  652. }
  653. } else {
  654. if ('0' == argv[1][0]) {
  655. /* Disable write access. */
  656. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 0);
  657. } else {
  658. /* Enable write access. */
  659. state = eeprom_write_enable(CONFIG_SYS_I2C_EEPROM_ADDR, 1);
  660. }
  661. if (state < 0)
  662. puts ("Setup of write access state failed.\n");
  663. }
  664. return state;
  665. }
  666. U_BOOT_CMD(eepwren, 2, 0, do_eep_wren,
  667. "Enable / disable / query EEPROM write access",
  668. ""
  669. );
  670. #endif /* #if defined(CONFIG_SYS_EEPROM_WREN) */
  671. static int got_pldirq;
  672. static int pld_interrupt(u32 arg)
  673. {
  674. int rc = -1; /* not for us */
  675. u8 status = in_8((void *)CONFIG_SYS_CPLD_BASE);
  676. /* check for PLD interrupt */
  677. if (status & PWR_INT_FLAG) {
  678. /* reset this int */
  679. out_8((void *)CONFIG_SYS_CPLD_BASE, 0);
  680. rc = 0;
  681. got_pldirq = 1; /* trigger backend */
  682. }
  683. return rc;
  684. }
  685. int do_waitpwrirq(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  686. {
  687. got_pldirq = 0;
  688. /* clear any pending interrupt */
  689. out_8((void *)CONFIG_SYS_CPLD_BASE, 0);
  690. irq_install_handler(CPLD_IRQ,
  691. (interrupt_handler_t *)pld_interrupt, 0);
  692. printf("Waiting ...\n");
  693. while(!got_pldirq) {
  694. /* Abort if ctrl-c was pressed */
  695. if (ctrlc()) {
  696. puts("\nAbort\n");
  697. break;
  698. }
  699. }
  700. if (got_pldirq) {
  701. printf("Got interrupt!\n");
  702. printf("Power %sready!\n",
  703. in_8((void *)CONFIG_SYS_CPLD_BASE) &
  704. PWR_RDY ? "":"NOT ");
  705. }
  706. irq_free_handler(CPLD_IRQ);
  707. return 0;
  708. }
  709. U_BOOT_CMD(
  710. wpi, 1, 1, do_waitpwrirq,
  711. "Wait for power change interrupt",
  712. ""
  713. );
  714. /*
  715. * initialize DVI panellink transmitter
  716. */
  717. int dvi_init(void)
  718. {
  719. int i;
  720. int ret = 0;
  721. unsigned int oldbus;
  722. uchar u[] = {0x08, 0x34,
  723. 0x09, 0x20,
  724. 0x0a, 0x90,
  725. 0x0c, 0x89,
  726. 0x08, 0x35};
  727. printf("DVI: ");
  728. oldbus = I2C_GET_BUS();
  729. I2C_SET_BUS(0);
  730. for (i = 0; i < sizeof(u); i += 2)
  731. if (i2c_write (0x38, u[i], 1, &u[i + 1], 1)) {
  732. ret = -1;
  733. break;
  734. }
  735. if (ret == 0)
  736. printf("initialized\n");
  737. else
  738. printf("failed - cannot initialize DVI transmitter\n");
  739. I2C_SET_BUS(oldbus);
  740. return ret;
  741. }
  742. int do_dviinit(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  743. {
  744. dvi_init();
  745. return 0;
  746. }
  747. U_BOOT_CMD(
  748. dviinit, 1, 1, do_dviinit,
  749. "Initialize DVI Panellink transmitter",
  750. ""
  751. );
  752. /*
  753. * TODO: 'time' command might be useful for others as well.
  754. * Move to 'common' directory.
  755. */
  756. int do_time(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  757. {
  758. unsigned long long start, end;
  759. char c, cmd[CONFIG_SYS_CBSIZE];
  760. char *p, *d = cmd;
  761. int ret, i;
  762. ulong us;
  763. for (i = 1; i < argc; i++) {
  764. p = argv[i];
  765. if (i > 1)
  766. *d++ = ' ';
  767. while ((c = *p++) != '\0') {
  768. *d++ = c;
  769. }
  770. }
  771. *d = '\0';
  772. start = get_ticks();
  773. ret = run_command (cmd, 0);
  774. end = get_ticks();
  775. printf("ticks=%ld\n", (ulong)(end - start));
  776. us = (ulong)((1000L * (end - start)) / (get_tbclk() / 1000));
  777. printf("usec=%ld\n", us);
  778. return ret;
  779. }
  780. U_BOOT_CMD(
  781. time, CONFIG_SYS_MAXARGS, 1, do_time,
  782. "run command and output execution time",
  783. ""
  784. );
  785. extern void video_hw_rectfill (
  786. unsigned int bpp, /* bytes per pixel */
  787. unsigned int dst_x, /* dest pos x */
  788. unsigned int dst_y, /* dest pos y */
  789. unsigned int dim_x, /* frame width */
  790. unsigned int dim_y, /* frame height */
  791. unsigned int color /* fill color */
  792. );
  793. /*
  794. * graphics demo
  795. * draw rectangles using pseudorandom number generator
  796. * (see http://www.embedded.com/columns/technicalinsights/20900500)
  797. */
  798. unsigned int rprime = 9972;
  799. static unsigned int r;
  800. static unsigned int Y;
  801. unsigned int prng(unsigned int max)
  802. {
  803. if (r == 0 || r == 1 || r == -1)
  804. r = rprime; /* keep from getting stuck */
  805. r = (9973 * ~r) + ((Y) % 701); /* the actual algorithm */
  806. Y = (r >> 16) % max; /* choose upper bits and reduce */
  807. return Y;
  808. }
  809. int do_gfxdemo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  810. {
  811. unsigned int color;
  812. unsigned int x, y, dx, dy;
  813. while (!ctrlc()) {
  814. x = prng(1280 - 1);
  815. y = prng(1024 - 1);
  816. dx = prng(1280- x - 1);
  817. dy = prng(1024 - y - 1);
  818. color = prng(0x10000);
  819. video_hw_rectfill(2, x, y, dx, dy, color);
  820. }
  821. return 0;
  822. }
  823. U_BOOT_CMD(
  824. gfxdemo, CONFIG_SYS_MAXARGS, 1, do_gfxdemo,
  825. "demo",
  826. ""
  827. );