cpu_init.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*
  2. * (C) Copyright 2000-2007
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <watchdog.h>
  25. #include <asm/ppc4xx-emac.h>
  26. #include <asm/processor.h>
  27. #include <asm/ppc4xx-gpio.h>
  28. #include <asm/ppc4xx.h>
  29. #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
  30. DECLARE_GLOBAL_DATA_PTR;
  31. #endif
  32. #ifndef CONFIG_SYS_PLL_RECONFIG
  33. #define CONFIG_SYS_PLL_RECONFIG 0
  34. #endif
  35. #if defined(CONFIG_440EPX) || \
  36. defined(CONFIG_460EX) || defined(CONFIG_460GT)
  37. static void reset_with_rli(void)
  38. {
  39. u32 reg;
  40. /*
  41. * Set reload inhibit so configuration will persist across
  42. * processor resets
  43. */
  44. mfcpr(CPR0_ICFG, reg);
  45. reg |= CPR0_ICFG_RLI_MASK;
  46. mtcpr(CPR0_ICFG, reg);
  47. /* Reset processor if configuration changed */
  48. __asm__ __volatile__ ("sync; isync");
  49. mtspr(SPRN_DBCR0, 0x20000000);
  50. }
  51. #endif
  52. void reconfigure_pll(u32 new_cpu_freq)
  53. {
  54. #if defined(CONFIG_440EPX)
  55. int reset_needed = 0;
  56. u32 reg, temp;
  57. u32 prbdv0, target_prbdv0, /* CLK_PRIMBD */
  58. fwdva, target_fwdva, fwdvb, target_fwdvb, /* CLK_PLLD */
  59. fbdv, target_fbdv, lfbdv, target_lfbdv,
  60. perdv0, target_perdv0, /* CLK_PERD */
  61. spcid0, target_spcid0; /* CLK_SPCID */
  62. /* Reconfigure clocks if necessary.
  63. * See PPC440EPx User's Manual, sections 8.2 and 14 */
  64. if (new_cpu_freq == 667) {
  65. target_prbdv0 = 2;
  66. target_fwdva = 2;
  67. target_fwdvb = 4;
  68. target_fbdv = 20;
  69. target_lfbdv = 1;
  70. target_perdv0 = 4;
  71. target_spcid0 = 4;
  72. mfcpr(CPR0_PRIMBD0, reg);
  73. temp = (reg & PRBDV_MASK) >> 24;
  74. prbdv0 = temp ? temp : 8;
  75. if (prbdv0 != target_prbdv0) {
  76. reg &= ~PRBDV_MASK;
  77. reg |= ((target_prbdv0 == 8 ? 0 : target_prbdv0) << 24);
  78. mtcpr(CPR0_PRIMBD0, reg);
  79. reset_needed = 1;
  80. }
  81. mfcpr(CPR0_PLLD, reg);
  82. temp = (reg & PLLD_FWDVA_MASK) >> 16;
  83. fwdva = temp ? temp : 16;
  84. temp = (reg & PLLD_FWDVB_MASK) >> 8;
  85. fwdvb = temp ? temp : 8;
  86. temp = (reg & PLLD_FBDV_MASK) >> 24;
  87. fbdv = temp ? temp : 32;
  88. temp = (reg & PLLD_LFBDV_MASK);
  89. lfbdv = temp ? temp : 64;
  90. if (fwdva != target_fwdva || fbdv != target_fbdv || lfbdv != target_lfbdv) {
  91. reg &= ~(PLLD_FWDVA_MASK | PLLD_FWDVB_MASK |
  92. PLLD_FBDV_MASK | PLLD_LFBDV_MASK);
  93. reg |= ((target_fwdva == 16 ? 0 : target_fwdva) << 16) |
  94. ((target_fwdvb == 8 ? 0 : target_fwdvb) << 8) |
  95. ((target_fbdv == 32 ? 0 : target_fbdv) << 24) |
  96. (target_lfbdv == 64 ? 0 : target_lfbdv);
  97. mtcpr(CPR0_PLLD, reg);
  98. reset_needed = 1;
  99. }
  100. mfcpr(CPR0_PERD, reg);
  101. perdv0 = (reg & CPR0_PERD_PERDV0_MASK) >> 24;
  102. if (perdv0 != target_perdv0) {
  103. reg &= ~CPR0_PERD_PERDV0_MASK;
  104. reg |= (target_perdv0 << 24);
  105. mtcpr(CPR0_PERD, reg);
  106. reset_needed = 1;
  107. }
  108. mfcpr(CPR0_SPCID, reg);
  109. temp = (reg & CPR0_SPCID_SPCIDV0_MASK) >> 24;
  110. spcid0 = temp ? temp : 4;
  111. if (spcid0 != target_spcid0) {
  112. reg &= ~CPR0_SPCID_SPCIDV0_MASK;
  113. reg |= ((target_spcid0 == 4 ? 0 : target_spcid0) << 24);
  114. mtcpr(CPR0_SPCID, reg);
  115. reset_needed = 1;
  116. }
  117. }
  118. /* Get current value of FWDVA.*/
  119. mfcpr(CPR0_PLLD, reg);
  120. temp = (reg & PLLD_FWDVA_MASK) >> 16;
  121. /*
  122. * Check to see if FWDVA has been set to value of 1. if it has we must
  123. * modify it.
  124. */
  125. if (temp == 1) {
  126. /*
  127. * Load register that contains current boot strapping option.
  128. */
  129. mfcpr(CPR0_ICFG, reg);
  130. /*
  131. * Strapping option bits (ICS) are already in correct position,
  132. * only masking needed.
  133. */
  134. reg &= CPR0_ICFG_ICS_MASK;
  135. if ((reg == BOOT_STRAP_OPTION_A) || (reg == BOOT_STRAP_OPTION_B) ||
  136. (reg == BOOT_STRAP_OPTION_D) || (reg == BOOT_STRAP_OPTION_E)) {
  137. mfcpr(CPR0_PLLD, reg);
  138. /* Get current value of fbdv. */
  139. temp = (reg & PLLD_FBDV_MASK) >> 24;
  140. fbdv = temp ? temp : 32;
  141. /* Get current value of lfbdv. */
  142. temp = (reg & PLLD_LFBDV_MASK);
  143. lfbdv = temp ? temp : 64;
  144. /*
  145. * Get current value of FWDVA. Assign current FWDVA to
  146. * new FWDVB.
  147. */
  148. mfcpr(CPR0_PLLD, reg);
  149. target_fwdvb = (reg & PLLD_FWDVA_MASK) >> 16;
  150. fwdvb = target_fwdvb ? target_fwdvb : 8;
  151. /*
  152. * Get current value of FWDVB. Assign current FWDVB to
  153. * new FWDVA.
  154. */
  155. target_fwdva = (reg & PLLD_FWDVB_MASK) >> 8;
  156. fwdva = target_fwdva ? target_fwdva : 16;
  157. /*
  158. * Update CPR0_PLLD with switched FWDVA and FWDVB.
  159. */
  160. reg &= ~(PLLD_FWDVA_MASK | PLLD_FWDVB_MASK |
  161. PLLD_FBDV_MASK | PLLD_LFBDV_MASK);
  162. reg |= ((fwdva == 16 ? 0 : fwdva) << 16) |
  163. ((fwdvb == 8 ? 0 : fwdvb) << 8) |
  164. ((fbdv == 32 ? 0 : fbdv) << 24) |
  165. (lfbdv == 64 ? 0 : lfbdv);
  166. mtcpr(CPR0_PLLD, reg);
  167. /* Acknowledge that a reset is required. */
  168. reset_needed = 1;
  169. }
  170. }
  171. /* Now reset the CPU if needed */
  172. if (reset_needed)
  173. reset_with_rli();
  174. #endif
  175. #if defined(CONFIG_460EX) || defined(CONFIG_460GT)
  176. u32 reg;
  177. /*
  178. * See "9.2.1.1 Booting with Option E" in the 460EX/GT
  179. * users manual
  180. */
  181. mfcpr(CPR0_PLLC, reg);
  182. if ((reg & (CPR0_PLLC_RST | CPR0_PLLC_ENG)) == CPR0_PLLC_RST) {
  183. /*
  184. * Set engage bit
  185. */
  186. reg = (reg & ~CPR0_PLLC_RST) | CPR0_PLLC_ENG;
  187. mtcpr(CPR0_PLLC, reg);
  188. /* Now reset the CPU */
  189. reset_with_rli();
  190. }
  191. #endif
  192. }
  193. #ifdef CONFIG_SYS_4xx_CHIP_21_ERRATA
  194. void
  195. chip_21_errata(void)
  196. {
  197. /*
  198. * See rev 1.09 of the 405EX/405EXr errata. CHIP_21 says that
  199. * sometimes reading the PVR and/or SDR0_ECID results in incorrect
  200. * values. Since the rev-D chip uses the SDR0_ECID bits to control
  201. * internal features, that means the second PCIe or ethernet of an EX
  202. * variant could fail to work. Also, security features of both EX and
  203. * EXr might be incorrectly disabled.
  204. *
  205. * The suggested workaround is as follows (covering rev-C and rev-D):
  206. *
  207. * 1.Read the PVR and SDR0_ECID3.
  208. *
  209. * 2.If the PVR matches an expected Revision C PVR value AND if
  210. * SDR0_ECID3[12:15] is different from PVR[28:31], then processor is
  211. * Revision C: continue executing the initialization code (no reset
  212. * required). else go to step 3.
  213. *
  214. * 3.If the PVR matches an expected Revision D PVR value AND if
  215. * SDR0_ECID3[10:11] matches its expected value, then continue
  216. * executing initialization code, no reset required. else write
  217. * DBCR0[RST] = 0b11 to generate a SysReset.
  218. */
  219. u32 pvr;
  220. u32 pvr_28_31;
  221. u32 ecid3;
  222. u32 ecid3_10_11;
  223. u32 ecid3_12_15;
  224. /* Step 1: */
  225. pvr = get_pvr();
  226. mfsdr(SDR0_ECID3, ecid3);
  227. /* Step 2: */
  228. pvr_28_31 = pvr & 0xf;
  229. ecid3_10_11 = (ecid3 >> 20) & 0x3;
  230. ecid3_12_15 = (ecid3 >> 16) & 0xf;
  231. if ((pvr == CONFIG_405EX_CHIP21_PVR_REV_C) &&
  232. (pvr_28_31 != ecid3_12_15)) {
  233. /* No reset required. */
  234. return;
  235. }
  236. /* Step 3: */
  237. if ((pvr == CONFIG_405EX_CHIP21_PVR_REV_D) &&
  238. (ecid3_10_11 == CONFIG_405EX_CHIP21_ECID3_REV_D)) {
  239. /* No reset required. */
  240. return;
  241. }
  242. /* Reset required. */
  243. __asm__ __volatile__ ("sync; isync");
  244. mtspr(SPRN_DBCR0, 0x30000000);
  245. }
  246. #endif
  247. /*
  248. * Breath some life into the CPU...
  249. *
  250. * Reconfigure PLL if necessary,
  251. * set up the memory map,
  252. * initialize a bunch of registers
  253. */
  254. void
  255. cpu_init_f (void)
  256. {
  257. #if defined(CONFIG_WATCHDOG) || defined(CONFIG_440GX) || defined(CONFIG_460EX)
  258. u32 val;
  259. #endif
  260. #ifdef CONFIG_SYS_4xx_CHIP_21_ERRATA
  261. chip_21_errata();
  262. #endif
  263. reconfigure_pll(CONFIG_SYS_PLL_RECONFIG);
  264. #if (defined(CONFIG_405EP) || defined (CONFIG_405EX)) && \
  265. !defined(CONFIG_APM821XX) &&!defined(CONFIG_SYS_4xx_GPIO_TABLE)
  266. /*
  267. * GPIO0 setup (select GPIO or alternate function)
  268. */
  269. #if defined(CONFIG_SYS_GPIO0_OR)
  270. out32(GPIO0_OR, CONFIG_SYS_GPIO0_OR); /* set initial state of output pins */
  271. #endif
  272. #if defined(CONFIG_SYS_GPIO0_ODR)
  273. out32(GPIO0_ODR, CONFIG_SYS_GPIO0_ODR); /* open-drain select */
  274. #endif
  275. out32(GPIO0_OSRH, CONFIG_SYS_GPIO0_OSRH); /* output select */
  276. out32(GPIO0_OSRL, CONFIG_SYS_GPIO0_OSRL);
  277. out32(GPIO0_ISR1H, CONFIG_SYS_GPIO0_ISR1H); /* input select */
  278. out32(GPIO0_ISR1L, CONFIG_SYS_GPIO0_ISR1L);
  279. out32(GPIO0_TSRH, CONFIG_SYS_GPIO0_TSRH); /* three-state select */
  280. out32(GPIO0_TSRL, CONFIG_SYS_GPIO0_TSRL);
  281. #if defined(CONFIG_SYS_GPIO0_ISR2H)
  282. out32(GPIO0_ISR2H, CONFIG_SYS_GPIO0_ISR2H);
  283. out32(GPIO0_ISR2L, CONFIG_SYS_GPIO0_ISR2L);
  284. #endif
  285. #if defined (CONFIG_SYS_GPIO0_TCR)
  286. out32(GPIO0_TCR, CONFIG_SYS_GPIO0_TCR); /* enable output driver for outputs */
  287. #endif
  288. #endif /* CONFIG_405EP ... && !CONFIG_SYS_4xx_GPIO_TABLE */
  289. #if defined (CONFIG_405EP)
  290. /*
  291. * Set EMAC noise filter bits
  292. */
  293. mtdcr(CPC0_EPCTL, CPC0_EPCTL_E0NFE | CPC0_EPCTL_E1NFE);
  294. #endif /* CONFIG_405EP */
  295. #if defined(CONFIG_SYS_4xx_GPIO_TABLE)
  296. gpio_set_chip_configuration();
  297. #endif /* CONFIG_SYS_4xx_GPIO_TABLE */
  298. /*
  299. * External Bus Controller (EBC) Setup
  300. */
  301. #if (defined(CONFIG_SYS_EBC_PB0AP) && defined(CONFIG_SYS_EBC_PB0CR))
  302. #if (defined(CONFIG_405GP) || defined(CONFIG_405CR) || \
  303. defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \
  304. defined(CONFIG_405EX) || defined(CONFIG_405))
  305. /*
  306. * Move the next instructions into icache, since these modify the flash
  307. * we are running from!
  308. */
  309. asm volatile(" bl 0f" ::: "lr");
  310. asm volatile("0: mflr 3" ::: "r3");
  311. asm volatile(" addi 4, 0, 14" ::: "r4");
  312. asm volatile(" mtctr 4" ::: "ctr");
  313. asm volatile("1: icbt 0, 3");
  314. asm volatile(" addi 3, 3, 32" ::: "r3");
  315. asm volatile(" bdnz 1b" ::: "ctr", "cr0");
  316. asm volatile(" addis 3, 0, 0x0" ::: "r3");
  317. asm volatile(" ori 3, 3, 0xA000" ::: "r3");
  318. asm volatile(" mtctr 3" ::: "ctr");
  319. asm volatile("2: bdnz 2b" ::: "ctr", "cr0");
  320. #endif
  321. mtebc(PB0AP, CONFIG_SYS_EBC_PB0AP);
  322. mtebc(PB0CR, CONFIG_SYS_EBC_PB0CR);
  323. #endif
  324. #if (defined(CONFIG_SYS_EBC_PB1AP) && defined(CONFIG_SYS_EBC_PB1CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 1))
  325. mtebc(PB1AP, CONFIG_SYS_EBC_PB1AP);
  326. mtebc(PB1CR, CONFIG_SYS_EBC_PB1CR);
  327. #endif
  328. #if (defined(CONFIG_SYS_EBC_PB2AP) && defined(CONFIG_SYS_EBC_PB2CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 2))
  329. mtebc(PB2AP, CONFIG_SYS_EBC_PB2AP);
  330. mtebc(PB2CR, CONFIG_SYS_EBC_PB2CR);
  331. #endif
  332. #if (defined(CONFIG_SYS_EBC_PB3AP) && defined(CONFIG_SYS_EBC_PB3CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 3))
  333. mtebc(PB3AP, CONFIG_SYS_EBC_PB3AP);
  334. mtebc(PB3CR, CONFIG_SYS_EBC_PB3CR);
  335. #endif
  336. #if (defined(CONFIG_SYS_EBC_PB4AP) && defined(CONFIG_SYS_EBC_PB4CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 4))
  337. mtebc(PB4AP, CONFIG_SYS_EBC_PB4AP);
  338. mtebc(PB4CR, CONFIG_SYS_EBC_PB4CR);
  339. #endif
  340. #if (defined(CONFIG_SYS_EBC_PB5AP) && defined(CONFIG_SYS_EBC_PB5CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 5))
  341. mtebc(PB5AP, CONFIG_SYS_EBC_PB5AP);
  342. mtebc(PB5CR, CONFIG_SYS_EBC_PB5CR);
  343. #endif
  344. #if (defined(CONFIG_SYS_EBC_PB6AP) && defined(CONFIG_SYS_EBC_PB6CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 6))
  345. mtebc(PB6AP, CONFIG_SYS_EBC_PB6AP);
  346. mtebc(PB6CR, CONFIG_SYS_EBC_PB6CR);
  347. #endif
  348. #if (defined(CONFIG_SYS_EBC_PB7AP) && defined(CONFIG_SYS_EBC_PB7CR) && !(CONFIG_SYS_INIT_DCACHE_CS == 7))
  349. mtebc(PB7AP, CONFIG_SYS_EBC_PB7AP);
  350. mtebc(PB7CR, CONFIG_SYS_EBC_PB7CR);
  351. #endif
  352. #if defined (CONFIG_SYS_EBC_CFG)
  353. mtebc(EBC0_CFG, CONFIG_SYS_EBC_CFG);
  354. #endif
  355. #if defined(CONFIG_WATCHDOG)
  356. val = mfspr(SPRN_TCR);
  357. #if defined(CONFIG_440EP) || defined(CONFIG_440GR)
  358. val |= 0xb8000000; /* generate system reset after 1.34 seconds */
  359. #elif defined(CONFIG_440EPX)
  360. val |= 0xb0000000; /* generate system reset after 1.34 seconds */
  361. #else
  362. val |= 0xf0000000; /* generate system reset after 2.684 seconds */
  363. #endif
  364. #if defined(CONFIG_SYS_4xx_RESET_TYPE)
  365. val &= ~0x30000000; /* clear WRC bits */
  366. val |= CONFIG_SYS_4xx_RESET_TYPE << 28; /* set board specific WRC type */
  367. #endif
  368. mtspr(SPRN_TCR, val);
  369. val = mfspr(SPRN_TSR);
  370. val |= 0x80000000; /* enable watchdog timer */
  371. mtspr(SPRN_TSR, val);
  372. reset_4xx_watchdog();
  373. #endif /* CONFIG_WATCHDOG */
  374. #if defined(CONFIG_440GX)
  375. /* Take the GX out of compatibility mode
  376. * Travis Sawyer, 9 Mar 2004
  377. * NOTE: 440gx user manual inconsistency here
  378. * Compatibility mode and Ethernet Clock select are not
  379. * correct in the manual
  380. */
  381. mfsdr(SDR0_MFR, val);
  382. val &= ~0x10000000;
  383. mtsdr(SDR0_MFR,val);
  384. #endif /* CONFIG_440GX */
  385. #if defined(CONFIG_460EX)
  386. /*
  387. * Set SDR0_AHB_CFG[A2P_INCR4] (bit 24) and
  388. * clear SDR0_AHB_CFG[A2P_PROT2] (bit 25) for a new 460EX errata
  389. * regarding concurrent use of AHB USB OTG, USB 2.0 host and SATA
  390. */
  391. mfsdr(SDR0_AHB_CFG, val);
  392. val |= 0x80;
  393. val &= ~0x40;
  394. mtsdr(SDR0_AHB_CFG, val);
  395. mfsdr(SDR0_USB2HOST_CFG, val);
  396. val &= ~0xf00;
  397. val |= 0x400;
  398. mtsdr(SDR0_USB2HOST_CFG, val);
  399. #endif /* CONFIG_460EX */
  400. #if defined(CONFIG_405EX) || \
  401. defined(CONFIG_440SP) || defined(CONFIG_440SPE) || \
  402. defined(CONFIG_460EX) || defined(CONFIG_460GT) || \
  403. defined(CONFIG_460SX) || defined(CONFIG_APM821XX)
  404. /*
  405. * Set PLB4 arbiter (Segment 0 and 1) to 4 deep pipeline read
  406. */
  407. mtdcr(PLB4A0_ACR, (mfdcr(PLB4A0_ACR) & ~PLB4Ax_ACR_RDP_MASK) |
  408. PLB4Ax_ACR_RDP_4DEEP);
  409. mtdcr(PLB4A1_ACR, (mfdcr(PLB4A1_ACR) & ~PLB4Ax_ACR_RDP_MASK) |
  410. PLB4Ax_ACR_RDP_4DEEP);
  411. #endif /* CONFIG_440SP/SPE || CONFIG_460EX/GT || CONFIG_405EX */
  412. }
  413. /*
  414. * initialize higher level parts of CPU like time base and timers
  415. */
  416. int cpu_init_r (void)
  417. {
  418. #if defined(CONFIG_405GP)
  419. uint pvr = get_pvr();
  420. /*
  421. * Set edge conditioning circuitry on PPC405GPr
  422. * for compatibility to existing PPC405GP designs.
  423. */
  424. if ((pvr & 0xfffffff0) == (PVR_405GPR_RB & 0xfffffff0)) {
  425. mtdcr(CPC0_ECR, 0x60606000);
  426. }
  427. #endif /* defined(CONFIG_405GP) */
  428. return 0;
  429. }
  430. #if defined(CONFIG_PCI) && \
  431. (defined(CONFIG_440EP) || defined(CONFIG_440EPX) || \
  432. defined(CONFIG_440GR) || defined(CONFIG_440GRX))
  433. /*
  434. * 440EP(x)/GR(x) PCI async/sync clocking restriction:
  435. *
  436. * In asynchronous PCI mode, the synchronous PCI clock must meet
  437. * certain requirements. The following equation describes the
  438. * relationship that must be maintained between the asynchronous PCI
  439. * clock and synchronous PCI clock. Select an appropriate PCI:PLB
  440. * ratio to maintain the relationship:
  441. *
  442. * AsyncPCIClk - 1MHz <= SyncPCIclock <= (2 * AsyncPCIClk) - 1MHz
  443. */
  444. static int ppc4xx_pci_sync_clock_ok(u32 sync, u32 async)
  445. {
  446. if (((async - 1000000) > sync) || (sync > ((2 * async) - 1000000)))
  447. return 0;
  448. else
  449. return 1;
  450. }
  451. int ppc4xx_pci_sync_clock_config(u32 async)
  452. {
  453. sys_info_t sys_info;
  454. u32 sync;
  455. int div;
  456. u32 reg;
  457. u32 spcid_val[] = {
  458. CPR0_SPCID_SPCIDV0_DIV1, CPR0_SPCID_SPCIDV0_DIV2,
  459. CPR0_SPCID_SPCIDV0_DIV3, CPR0_SPCID_SPCIDV0_DIV4 };
  460. get_sys_info(&sys_info);
  461. sync = sys_info.freqPCI;
  462. /*
  463. * First check if the equation above is met
  464. */
  465. if (!ppc4xx_pci_sync_clock_ok(sync, async)) {
  466. /*
  467. * Reconfigure PCI sync clock to meet the equation.
  468. * Start with highest possible PCI sync frequency
  469. * (divider 1).
  470. */
  471. for (div = 1; div <= 4; div++) {
  472. sync = sys_info.freqPLB / div;
  473. if (ppc4xx_pci_sync_clock_ok(sync, async))
  474. break;
  475. }
  476. if (div <= 4) {
  477. mtcpr(CPR0_SPCID, spcid_val[div]);
  478. mfcpr(CPR0_ICFG, reg);
  479. reg |= CPR0_ICFG_RLI_MASK;
  480. mtcpr(CPR0_ICFG, reg);
  481. /* do chip reset */
  482. mtspr(SPRN_DBCR0, 0x20000000);
  483. } else {
  484. /* Impossible to configure the PCI sync clock */
  485. return -1;
  486. }
  487. }
  488. return 0;
  489. }
  490. #endif