cpu_init.c 14 KB

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