early_init.S 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. #include <ppc_asm.tmpl>
  2. #include <mpc824x.h>
  3. #include <ppc_defs.h>
  4. #include <asm/cache.h>
  5. #include <asm/mmu.h>
  6. #define USE_V2_INIT 1 /* Jimmy Blair's initialization. */
  7. /*
  8. * Initialize the MMU using BAT entries and hardwired TLB
  9. * This obviates the need for any code in cpu_init_f which
  10. * configures the BAT registers.
  11. */
  12. #define MEMORY_MGMT_MSR_BITS (MSR_DR | MSR_IR) /* Data and Inst Relocate */
  13. .global iommu_setup
  14. /* Initialize IO/MMU mappings via BAT method Ch. 7,
  15. * PPC Programming Reference
  16. */
  17. iommu_setup:
  18. /* initialize the BAT registers (SPRs 528 - 543 */
  19. #define mtibat0u(x) mtspr 528,(x) /* SPR 528 (IBAT0U) */
  20. #define mtibat0l(x) mtspr 529,(x) /* SPR 529 (IBAT0L) */
  21. #define mtibat1u(x) mtspr 530,(x) /* SPR 530 (IBAT1U) */
  22. #define mtibat1l(x) mtspr 531,(x) /* SPR 531 (IBAT1L) */
  23. #define mtibat2u(x) mtspr 532,(x) /* SPR 532 (IBAT2U) */
  24. #define mtibat2l(x) mtspr 533,(x) /* SPR 533 (IBAT2L) */
  25. #define mtibat3u(x) mtspr 534,(x) /* SPR 534 (IBAT3U) */
  26. #define mtibat3l(x) mtspr 535,(x) /* SPR 535 (IBAT3L) */
  27. #define mtdbat0u(x) mtspr 536,(x) /* SPR 536 (DBAT0U) */
  28. #define mtdbat0l(x) mtspr 537,(x) /* SPR 537 (DBAT0L) */
  29. #define mtdbat1u(x) mtspr 538,(x) /* SPR 538 (DBAT1U) */
  30. #define mtdbat1l(x) mtspr 539,(x) /* SPR 539 (DBAT1L) */
  31. #define mtdbat2u(x) mtspr 540,(x) /* SPR 540 (DBAT2U) */
  32. #define mtdbat2l(x) mtspr 541,(x) /* SPR 541 (DBAT2L) */
  33. #define mtdbat3u(x) mtspr 542,(x) /* SPR 542 (DBAT3U) */
  34. #define mtdbat3l(x) mtspr 543,(x) /* SPR 543 (DBAT3L) */
  35. /* PowerPC processors do not necessarily initialize the BAT
  36. registers on power-up or reset. So they are in an unknown
  37. state. Before programming the BATs for the first time, all
  38. BAT registers MUST have their Vs and Vp bits cleared in the
  39. upper BAT half in order to avoid possibly having 2 BATs
  40. valid and mapping the same memory region.
  41. The reason for this is that, even with address translation
  42. disabled, multiple BAT hits for an address are treated as
  43. programming errors and can cause unpredictable results.
  44. It is up to the software to make sure it never has 2 IBAT
  45. mappings or 2 DBAT mappings that are valid for the same
  46. addresses. It is not necessary to perform this code
  47. sequence every time the BATs are programmed, only when
  48. there is a possibility that there may be overlapping BAT
  49. entries.
  50. When programming the BATs in non-reset scenarios, even if
  51. you are sure that your new mapping will not temporarily
  52. create overlapping regions, it is still a wise idea to
  53. invalidate a BAT entry by setting its upper BAT register to
  54. all 0's before programming it. This will avoid having a
  55. BAT marked valid that is in an unknown or transient state
  56. */
  57. addis r5,0,0x0000
  58. mtibat0u(r5)
  59. mtibat0l(r5)
  60. mtibat1u(r5)
  61. mtibat1l(r5)
  62. mtibat2u(r5)
  63. mtibat2l(r5)
  64. mtibat3u(r5)
  65. mtibat3l(r5)
  66. mtdbat0u(r5)
  67. mtdbat0l(r5)
  68. mtdbat1u(r5)
  69. mtdbat1l(r5)
  70. mtdbat2u(r5)
  71. mtdbat2l(r5)
  72. mtdbat3u(r5)
  73. mtdbat3l(r5)
  74. isync
  75. /*
  76. * Set up I/D BAT0
  77. */
  78. lis r4, CFG_DBAT0L@h
  79. ori r4, r4, CFG_DBAT0L@l
  80. lis r3, CFG_DBAT0U@h
  81. ori r3, r3, CFG_DBAT0U@l
  82. mtdbat0l(r4)
  83. isync
  84. mtdbat0u(r3)
  85. isync
  86. sync
  87. lis r4, CFG_IBAT0L@h
  88. ori r4, r4, CFG_IBAT0L@l
  89. lis r3, CFG_IBAT0U@h
  90. ori r3, r3, CFG_IBAT0U@l
  91. isync
  92. mtibat0l(r4)
  93. isync
  94. mtibat0u(r3)
  95. isync
  96. /*
  97. * Set up I/D BAT1
  98. */
  99. lis r4, CFG_IBAT1L@h
  100. ori r4, r4, CFG_IBAT1L@l
  101. lis r3, CFG_IBAT1U@h
  102. ori r3, r3, CFG_IBAT1U@l
  103. isync
  104. mtibat1l(r4)
  105. isync
  106. mtibat1u(r3)
  107. isync
  108. mtdbat1l(r4)
  109. isync
  110. mtdbat1u(r3)
  111. isync
  112. sync
  113. /*
  114. * Set up I/D BAT2
  115. */
  116. lis r4, CFG_IBAT2L@h
  117. ori r4, r4, CFG_IBAT2L@l
  118. lis r3, CFG_IBAT2U@h
  119. ori r3, r3, CFG_IBAT2U@l
  120. isync
  121. mtibat2l(r4)
  122. isync
  123. mtibat2u(r3)
  124. isync
  125. mtdbat2l(r4)
  126. isync
  127. mtdbat2u(r3)
  128. isync
  129. sync
  130. /*
  131. * Setup I/D BAT3
  132. */
  133. lis r4, CFG_IBAT3L@h
  134. ori r4, r4, CFG_IBAT3L@l
  135. lis r3, CFG_IBAT3U@h
  136. ori r3, r3, CFG_IBAT3U@l
  137. isync
  138. mtibat3l(r4)
  139. isync
  140. mtibat3u(r3)
  141. isync
  142. mtdbat3l(r4)
  143. isync
  144. mtdbat3u(r3)
  145. isync
  146. sync
  147. /*
  148. * Invalidate all 64 TLB's
  149. */
  150. lis r3, 0
  151. mtctr r3
  152. lis r5, 4
  153. tlblp:
  154. tlbie r3
  155. sync
  156. addi r3, r3, 0x1000
  157. cmplw r3, r5
  158. blt tlblp
  159. sync
  160. /*
  161. * Enable Data Translation
  162. */
  163. lis r4, MEMORY_MGMT_MSR_BITS@h
  164. ori r4, r4, MEMORY_MGMT_MSR_BITS@l
  165. mfmsr r3
  166. or r3, r4, r3
  167. mtmsr r3
  168. isync
  169. sync
  170. blr
  171. #ifdef USE_V2_INIT
  172. /* #define USER_I_CACHE_ENABLE 1*/ /* Fast rom boots */
  173. /* Macro for hiadjust and lo */
  174. #define HIADJ(arg) arg@ha
  175. #define HI(arg) arg@h
  176. #define LO(arg) arg@l
  177. #undef LOADPTR
  178. #define LOADPTR(reg,const32) \
  179. addis reg,r0,HIADJ(const32); addi reg,reg,LO(const32)
  180. .globl early_init_f
  181. early_init_f:
  182. /* MPC8245/BMW CPCI System Init
  183. * Jimmy Blair, Broadcom Corp, 2002.
  184. */
  185. mflr r11
  186. /* Zero-out registers */
  187. addis r0,r0,0
  188. mtspr SPRG0,r0
  189. mtspr SPRG1,r0
  190. mtspr SPRG2,r0
  191. mtspr SPRG3,r0
  192. /* Set MPU/MSR to a known state. Turn on FP */
  193. LOADPTR (r3, MSR_FP)
  194. sync
  195. mtmsr r3
  196. isync
  197. /* Init the floating point control/status register */
  198. mtfsfi 7,0x0
  199. mtfsfi 6,0x0
  200. mtfsfi 5,0x0
  201. mtfsfi 4,0x0
  202. mtfsfi 3,0x0
  203. mtfsfi 2,0x0
  204. mtfsfi 1,0x0
  205. mtfsfi 0,0x0
  206. isync
  207. /* Set MPU/MSR to a known state. Turn off FP */
  208. #if 1 /* Turn off floating point (remove to keep FP on) */
  209. andi. r3, r3, 0
  210. sync
  211. mtmsr r3
  212. isync
  213. #endif
  214. /* Init the Segment registers */
  215. andi. r3, r3, 0
  216. isync
  217. mtsr 0,r3
  218. isync
  219. mtsr 1,r3
  220. isync
  221. mtsr 2,r3
  222. isync
  223. mtsr 3,r3
  224. isync
  225. mtsr 4,r3
  226. isync
  227. mtsr 5,r3
  228. isync
  229. mtsr 6,r3
  230. isync
  231. mtsr 7,r3
  232. isync
  233. mtsr 8,r3
  234. isync
  235. mtsr 9,r3
  236. isync
  237. mtsr 10,r3
  238. isync
  239. mtsr 11,r3
  240. isync
  241. mtsr 12,r3
  242. isync
  243. mtsr 13,r3
  244. isync
  245. mtsr 14,r3
  246. isync
  247. mtsr 15,r3
  248. isync
  249. /* Turn off data and instruction cache control bits */
  250. mfspr r3, HID0
  251. isync
  252. rlwinm r4, r3, 0, 18, 15 /* r4 has ICE and DCE bits cleared */
  253. sync
  254. isync
  255. mtspr HID0, r4 /* HID0 = r4 */
  256. isync
  257. /* Get cpu type */
  258. mfspr r28, PVR
  259. rlwinm r28, r28, 16, 16, 31
  260. /* invalidate the MPU's data/instruction caches */
  261. lis r3, 0x0
  262. cmpli 0, 0, r28, CPU_TYPE_603
  263. beq cpuIs603
  264. cmpli 0, 0, r28, CPU_TYPE_603E
  265. beq cpuIs603
  266. cmpli 0, 0, r28, CPU_TYPE_603P
  267. beq cpuIs603
  268. cmpli 0, 0, r28, CPU_TYPE_604R
  269. bne cpuNot604R
  270. cpuIs604R:
  271. lis r3, 0x0
  272. mtspr HID0, r3 /* disable the caches */
  273. isync
  274. ori r4, r4, 0x0002 /* disable BTAC by setting bit 30 */
  275. cpuNot604R:
  276. ori r3, r3, (HID0_ICFI |HID0_DCI)
  277. cpuIs603:
  278. ori r3, r3, (HID0_ICE | HID0_DCE)
  279. or r4, r4, r3 /* set bits */
  280. sync
  281. isync
  282. mtspr HID0, r4 /* HID0 = r4 */
  283. andc r4, r4, r3 /* clear bits */
  284. isync
  285. cmpli 0, 0, r28, CPU_TYPE_604
  286. beq cpuIs604
  287. cmpli 0, 0, r28, CPU_TYPE_604E
  288. beq cpuIs604
  289. cmpli 0, 0, r28, CPU_TYPE_604R
  290. beq cpuIs604
  291. mtspr HID0, r4
  292. isync
  293. #ifdef USER_I_CACHE_ENABLE
  294. b instCacheOn603
  295. #else
  296. b cacheEnableDone
  297. #endif
  298. cpuIs604:
  299. LOADPTR (r5, 0x1000) /* loop count, 0x1000 */
  300. mtspr CTR, r5
  301. loopDelay:
  302. nop
  303. bdnz loopDelay
  304. isync
  305. mtspr HID0, r4
  306. isync
  307. /* turn the Instruction cache ON for faster FLASH ROM boots */
  308. #ifdef USER_I_CACHE_ENABLE
  309. ori r4, r4, (HID0_ICE | HID0_ICFI)
  310. isync /* Synchronize for ICE enable */
  311. b writeReg4
  312. instCacheOn603:
  313. ori r4, r4, (HID0_ICE | HID0_ICFI)
  314. rlwinm r3, r4, 0, 21, 19 /* clear the ICFI bit */
  315. /*
  316. * The setting of the instruction cache enable (ICE) bit must be
  317. * preceded by an isync instruction to prevent the cache from being
  318. * enabled or disabled while an instruction access is in progress.
  319. */
  320. isync
  321. writeReg4:
  322. mtspr HID0, r4 /* Enable Instr Cache & Inval cache */
  323. cmpli 0, 0, r28, CPU_TYPE_604
  324. beq cacheEnableDone
  325. cmpli 0, 0, r28, CPU_TYPE_604E
  326. beq cacheEnableDone
  327. mtspr HID0, r3 /* using 2 consec instructions */
  328. /* PPC603 recommendation */
  329. #endif
  330. cacheEnableDone:
  331. /* Detect map A or B */
  332. addis r5,r0, HI(CHRP_REG_ADDR)
  333. addis r6,r0, HI(CHRP_REG_DATA)
  334. LOADPTR (r7, KAHLUA_ID) /* Kahlua PCI controller ID */
  335. LOADPTR (r8, BMC_BASE)
  336. stwbrx r8,0,(r5)
  337. lwbrx r3,0,(r6) /* Store read value to r3 */
  338. cmp 0,0,r3,r7
  339. beq cr0, X4_KAHLUA_START
  340. /* It's not an 8240, is it an 8245? */
  341. LOADPTR (r7, KAHLUA2_ID) /* Kahlua PCI controller ID */
  342. cmp 0,0,r3,r7
  343. beq cr0, X4_KAHLUA_START
  344. /* Save the PCI controller type in r7 */
  345. mr r7, r3
  346. LOADPTR (r5, PREP_REG_ADDR)
  347. LOADPTR (r6, PREP_REG_DATA)
  348. X4_KAHLUA_START:
  349. /* MPC8245 changes begin here */
  350. LOADPTR (r3, MPC107_PCI_CMD) /* PCI command reg */
  351. stwbrx r3,0,r5
  352. li r4, 6 /* Command register value */
  353. sthbrx r4, 0, r6
  354. LOADPTR (r3, MPC107_PCI_STAT) /* PCI status reg */
  355. stwbrx r3,0,r5
  356. li r4, -1 /* Write-to-clear all bits */
  357. li r3, 2 /* PCI_STATUS is at +2 offset */
  358. sthbrx r4, r3, r6
  359. /*-------PROC_INT1_ADR */
  360. LOADPTR (r3, PROC_INT1_ADR) /* Processor I/F Config 1 reg. */
  361. stwbrx r3,0,r5
  362. LOADPTR (r4, 0xff141b98)
  363. stwbrx r4,0,r6
  364. /*-------PROC_INT2_ADR */
  365. LOADPTR (r3, PROC_INT2_ADR) /* Processor I/F Config 2 reg. */
  366. stwbrx r3,0,r5
  367. lis r4, 0x2000 /* Flush PCI config writes */
  368. stwbrx r4,0,r6
  369. LOADPTR (r9, KAHLUA2_ID)
  370. cmpl 0, 0, r7, r9
  371. bne L1not8245
  372. /* MIOCR1 -- turn on bit for DLL delay */
  373. LOADPTR (r3, MIOCR1_ADR_X)
  374. stwbrx r3,0,r5
  375. li r4, 0x04
  376. stb r4, MIOCR1_SHIFT(r6)
  377. /* For the MPC8245, set register 77 to %00100000 (see Errata #15) */
  378. /* SDRAM_CLK_DEL (0x77)*/
  379. LOADPTR (r3, MIOCR2_ADR_X)
  380. stwbrx r3,0,r5
  381. li r4, 0x10
  382. stb r4, MIOCR2_SHIFT(r6)
  383. /* PMCR2 -- set PCI hold delay to <10>b for 33 MHz */
  384. LOADPTR (r3, PMCR2_ADR_X)
  385. stwbrx r3,0,r5
  386. li r4, 0x20
  387. stb r4, PMCR2_SHIFT(r6)
  388. /* Initialize EUMBBAR early since 8245 has internal UART in EUMB */
  389. LOADPTR (r3, EUMBBAR)
  390. stwbrx r3,0,r5
  391. LOADPTR (r4, CFG_EUMB_ADDR)
  392. stwbrx r4,0,r6
  393. L1not8245:
  394. /* Toggle the DLL reset bit in AMBOR */
  395. LOADPTR (r3, AMBOR)
  396. stwbrx r3,0,r5
  397. lbz r4, 0(r6)
  398. andi. r4, r4, 0xdf
  399. stb r4, 0(r6) /* Clear DLL_RESET */
  400. sync
  401. ori r4, r4, 0x20 /* Set DLL_RESET */
  402. stb r4, 0(r6)
  403. sync
  404. andi. r4, r4, 0xdf
  405. stb r4, 0(r6) /* Clear DLL_RESET */
  406. /* Enable RCS2, use supplied timings */
  407. LOADPTR (r3, ERCR1)
  408. stwbrx r3,0,r5
  409. LOADPTR (r4, 0x80408000)
  410. stwbrx r4,0,r6
  411. /* Disable RCS3 parameters */
  412. LOADPTR (r3, ERCR2)
  413. stwbrx r3,0,r5
  414. LOADPTR (r4, 0x00000000)
  415. stwbrx r4,0,r6
  416. /* RCS3 at 0x70000000, 64KBytes */
  417. LOADPTR (r3, ERCR2)
  418. stwbrx r3,0,r5
  419. LOADPTR (r4, 0x00000004)
  420. stwbrx r4,0,r6
  421. /*-------MCCR1 */
  422. #ifdef INCLUDE_ECC
  423. #define MC_ECC 1
  424. #else /* INCLUDE_ECC */
  425. #define MC_ECC 0
  426. #endif /* INCLUDE_ECC */
  427. #define MC1_ROMNAL 8 /* 0-15 */
  428. #define MC1_ROMFAL 11 /* 0-31 */
  429. #define MC1_DBUS_SIZE 0 /* 0-3, read only */
  430. #define MC1_BURST 0 /* 0-1 */
  431. #define MC1_MEMGO 0 /* 0-1 */
  432. #define MC1_SREN 1 /* 0-1 */
  433. #define MC1_RAM_TYPE 0 /* 0-1 */
  434. #define MC1_PCKEN MC_ECC /* 0-1 */
  435. #define MC1_BANKBITS 0x5555 /* 2 bits/bank 7-0 */
  436. LOADPTR (r3, MEM_CONT1_ADR) /* Set MCCR1 (F0) */
  437. stwbrx r3,0,r5
  438. LOADPTR(r4, \
  439. MC1_ROMNAL << 28 | MC1_ROMFAL << 23 | \
  440. MC1_DBUS_SIZE << 21 | MC1_BURST << 20 | \
  441. MC1_MEMGO << 19 | MC1_SREN << 18 | \
  442. MC1_RAM_TYPE << 17 | MC1_PCKEN << 16 )
  443. li r3, MC1_BANKBITS
  444. cmpl 0, 0, r7, r9 /* Check for Kahlua2 */
  445. bne BankBitsAdd
  446. cmpli 0, 0, r3, 0x5555
  447. beq K2BankBitsHack /* On 8245, 5555 ==> 0 */
  448. BankBitsAdd:
  449. ori r4, r3, 0
  450. K2BankBitsHack:
  451. stwbrx r4, 0, r6
  452. /*------- MCCR2 */
  453. #define MC2_TS_WAIT_TIMER 0 /* 0-7 */
  454. #define MC2_ASRISE 8 /* 0-15 */
  455. #define MC2_ASFALL 4 /* 0-15 */
  456. #define MC2_INLINE_PAR_NOT_ECC 0 /* 0-1 */
  457. #define MC2_WRITE_PARITY_CHK_EN MC_ECC /* 0-1 */
  458. #define MC2_INLRD_PARECC_CHK_EN MC_ECC /* 0-1 */
  459. #define MC2_ECC_EN 0 /* 0-1 */
  460. #define MC2_EDO 0 /* 0-1 */
  461. /*
  462. * N.B. This refresh interval looks good up to 85 MHz with Hynix SDRAM.
  463. * May need to be decreased for 100 MHz
  464. */
  465. #define MC2_REFINT 0x3a5 /* 0-0x3fff */
  466. #define MC2_RSV_PG 0 /* 0-1 */
  467. #define MC2_RMW_PAR MC_ECC /* 0-1 */
  468. LOADPTR (r3, MEM_CONT2_ADR) /* Set MCCR2 (F4) */
  469. stwbrx r3,0,r5
  470. LOADPTR(r4, \
  471. MC2_TS_WAIT_TIMER << 29 | MC2_ASRISE << 25 | \
  472. MC2_ASFALL << 21 | MC2_INLINE_PAR_NOT_ECC << 20 | \
  473. MC2_WRITE_PARITY_CHK_EN << 19 | \
  474. MC2_INLRD_PARECC_CHK_EN << 18 | \
  475. MC2_ECC_EN << 17 | MC2_EDO << 16 | \
  476. MC2_REFINT << 2 | MC2_RSV_PG << 1 | MC2_RMW_PAR)
  477. cmpl 0, 0, r7, r9 /* Check for Kahlua2 */
  478. bne notK2
  479. /* clear Kahlua2 reserved bits */
  480. LOADPTR (r3, 0xfffcffff)
  481. and r4, r4, r3
  482. notK2:
  483. stwbrx r4,0,r6
  484. /*------- MCCR3 */
  485. #define MC_BSTOPRE 0x079 /* 0-0x7ff */
  486. #define MC3_BSTOPRE_U (MC_BSTOPRE >> 4 & 0xf)
  487. #define MC3_REFREC 8 /* 0-15 */
  488. #define MC3_RDLAT (4+MC_ECC) /* 0-15 */
  489. #define MC3_CPX 0 /* 0-1 */
  490. #define MC3_RAS6P 0 /* 0-15 */
  491. #define MC3_CAS5 0 /* 0-7 */
  492. #define MC3_CP4 0 /* 0-7 */
  493. #define MC3_CAS3 0 /* 0-7 */
  494. #define MC3_RCD2 0 /* 0-7 */
  495. #define MC3_RP1 0 /* 0-7 */
  496. LOADPTR (r3, MEM_CONT3_ADR) /* Set MCCR3 (F8) */
  497. stwbrx r3,0,r5
  498. LOADPTR(r4, \
  499. MC3_BSTOPRE_U << 28 | MC3_REFREC << 24 | \
  500. MC3_RDLAT << 20 | MC3_CPX << 19 | \
  501. MC3_RAS6P << 15 | MC3_CAS5 << 12 | MC3_CP4 << 9 | \
  502. MC3_CAS3 << 6 | MC3_RCD2 << 3 | MC3_RP1)
  503. cmpl 0, 0, r7, r9 /* Check for Kahlua2 */
  504. bne notK2b
  505. /* clear Kahlua2 reserved bits */
  506. LOADPTR (r3, 0xff000000)
  507. and r4, r4, r3
  508. notK2b:
  509. stwbrx r4,0,r6
  510. /*------- MCCR4 */
  511. #define MC4_PRETOACT 3 /* 0-15 */
  512. #define MC4_ACTOPRE 5 /* 0-15 */
  513. #define MC4_WMODE 0 /* 0-1 */
  514. #define MC4_INLINE MC_ECC /* 0-1 */
  515. #define MC4_REGISTERED (1-MC_ECC) /* 0-1 */
  516. #define MC4_BSTOPRE_UU (MC_BSTOPRE >> 8 & 3)
  517. #define MC4_REGDIMM 0 /* 0-1 */
  518. #define MC4_SDMODE_CAS 2 /* 0-7 */
  519. #define MC4_DBUS_RCS1 1 /* 0-1, 8-bit */
  520. #define MC4_SDMODE_WRAP 0 /* 0-1 */
  521. #define MC4_SDMODE_BURST 2 /* 0-7 */
  522. #define MC4_ACTORW 3 /* 0-15 */
  523. #define MC4_BSTOPRE_L (MC_BSTOPRE & 0xf)
  524. LOADPTR (r3, MEM_CONT4_ADR) /* Set MCCR4 (FC) */
  525. stwbrx r3,0,r5
  526. LOADPTR(r4, \
  527. MC4_PRETOACT << 28 | MC4_ACTOPRE << 24 | \
  528. MC4_WMODE << 23 | MC4_INLINE << 22 | \
  529. MC4_REGISTERED << 20 | MC4_BSTOPRE_UU << 18 | \
  530. MC4_DBUS_RCS1 << 17 | \
  531. MC4_REGDIMM << 15 | MC4_SDMODE_CAS << 12 | \
  532. MC4_SDMODE_WRAP << 11 | MC4_SDMODE_BURST << 8 | \
  533. MC4_ACTORW << 4 | MC4_BSTOPRE_L)
  534. cmpl 0, 0, r7, r9 /* Check for Kahlua 2 */
  535. bne notK2c
  536. /* Turn on Kahlua2 extended ROM space */
  537. LOADPTR (r3, 0x00200000)
  538. or r4, r4, r3
  539. notK2c:
  540. stwbrx r4,0,r6
  541. #ifdef INCLUDE_ECC
  542. /*------- MEM_ERREN1 */
  543. LOADPTR (r3, MEM_ERREN1_ADR) /* Set MEM_ERREN1 (c0) */
  544. stwbrx r3,0,r5
  545. lwbrx r4,0,r6
  546. ori r4,r4,4 /* Set MEM_PERR_EN */
  547. stwbrx r4,0,r6
  548. #endif /* INCLUDE_ECC */
  549. /*------- MSAR/MEAR */
  550. LOADPTR (r3, MEM_START1_ADR) /* Set MSAR1 (80) */
  551. stwbrx r3,0,r5
  552. LOADPTR (r4, 0xc0804000)
  553. stwbrx r4,0,r6
  554. LOADPTR (r3, MEM_START2_ADR) /* Set MSAR2 (84) */
  555. stwbrx r3,0,r5
  556. LOADPTR (r4, 0xc0804000)
  557. stwbrx r4,0,r6
  558. LOADPTR (r3, XMEM_START1_ADR) /* Set MESAR1 (88) */
  559. stwbrx r3,0,r5
  560. LOADPTR (r4, 0x00000000)
  561. stwbrx r4,0,r6
  562. LOADPTR (r3, XMEM_START2_ADR) /* Set MESAR2 (8c) */
  563. stwbrx r3,0,r5
  564. LOADPTR (r4, 0x01010101)
  565. stwbrx r4,0,r6
  566. LOADPTR (r3, MEM_END1_ADR) /* Set MEAR1 (90) */
  567. stwbrx r3,0,r5
  568. LOADPTR (r4, 0xffbf7f3f)
  569. stwbrx r4,0,r6
  570. LOADPTR (r3, MEM_END2_ADR) /* Set MEAR2 (94) */
  571. stwbrx r3,0,r5
  572. LOADPTR (r4, 0xffbf7f3f)
  573. stwbrx r4,0,r6
  574. LOADPTR (r3, XMEM_END1_ADR) /* MEEAR1 (98) */
  575. stwbrx r3,0,r5
  576. LOADPTR (r4, 0x00000000)
  577. stwbrx r4,0,r6
  578. LOADPTR (r3, XMEM_END2_ADR) /* MEEAR2 (9c) */
  579. stwbrx r3,0,r5
  580. LOADPTR (r4, 0x01010101)
  581. stwbrx r4,0,r6
  582. /*-------ODCR */
  583. LOADPTR (r3, ODCR_ADR_X) /* Set ODCR */
  584. stwbrx r3,0,r5
  585. li r4, 0x7f
  586. stb r4, ODCR_SHIFT(r6) /* ODCR is at +3 offset */
  587. /*-------MBEN */
  588. LOADPTR (r3, MEM_EN_ADR) /* Set MBEN (a0) */
  589. stwbrx r3,0,r5
  590. li r4, 0x01 /* Enable bank 0 */
  591. stb r4, 0(r6) /* MBEN is at +0 offset */
  592. #if 0 /* Jimmy: I think page made is broken */
  593. /*-------PGMAX */
  594. LOADPTR (r3, MPM_ADR_X)
  595. stwbrx r3,0,r5
  596. li r4, 0x32
  597. stb r4, MPM_SHIFT(r6) /* PAGE_MODE is at +3 offset */
  598. #endif
  599. /* Wait before initializing other registers */
  600. lis r4,0x0001
  601. mtctr r4
  602. KahluaX4wait200us:
  603. bdnz KahluaX4wait200us
  604. /* Set MEMGO bit */
  605. LOADPTR (r3, MEM_CONT1_ADR) /* MCCR1 (F0) |= PGMAX */
  606. stwbrx r3,0,r5
  607. lwbrx r4,0,r6 /* old MCCR1 */
  608. oris r4,r4,0x0008 /* MEMGO=1 */
  609. stwbrx r4, 0, r6
  610. /* Wait again */
  611. addis r4,r0,0x0002
  612. ori r4,r4,0xffff
  613. mtctr r4
  614. KahluaX4wait8ref:
  615. bdnz KahluaX4wait8ref
  616. sync
  617. eieio
  618. mtlr r11
  619. blr
  620. #else /* USE_V2_INIT */
  621. /* U-Boot works, but memory will not run reliably for all address ranges.
  622. * Early U-Boot Working init, but 2.4.19 kernel will crash since memory is not
  623. * initialized correctly. Could work if debugged.
  624. */
  625. /* PCI Support routines */
  626. .globl __pci_config_read_32
  627. __pci_config_read_32:
  628. lis r4, 0xfec0
  629. stwbrx r3, r0, r4
  630. sync
  631. lis r4, 0xfee0
  632. lwbrx r3, 0, r4
  633. blr
  634. .globl __pci_config_read_16
  635. __pci_config_read_16:
  636. lis r4, 0xfec0
  637. andi. r5, r3, 2
  638. stwbrx r3, r0, r4
  639. sync
  640. oris r4, r5, 0xfee0
  641. lhbrx r3, r0, r4
  642. blr
  643. .globl __pci_config_read_8
  644. __pci_config_read_8:
  645. lis r4, 0xfec0
  646. andi. r5, r3, 3
  647. stwbrx r3, r0, r4
  648. sync
  649. oris r4, r5, 0xfee0
  650. lbz r3, 0(4)
  651. blr
  652. .globl __pci_config_write_32
  653. __pci_config_write_32:
  654. lis r5, 0xfec0
  655. stwbrx r3, r0, r5
  656. sync
  657. lis r5, 0xfee0
  658. stwbrx r4, r0, r5
  659. sync
  660. blr
  661. .globl __pci_config_write_16
  662. __pci_config_write_16:
  663. lis r5, 0xfec0
  664. andi. r6, r3, 2
  665. stwbrx r3, r0, 5
  666. sync
  667. oris r5, r6, 0xfee0
  668. sthbrx r4, r0, r5
  669. sync
  670. blr
  671. .globl __pci_config_write_8
  672. __pci_config_write_8:
  673. lis r5, 0xfec0
  674. andi. r6, r3, 3
  675. stwbrx r3, r0, r5
  676. sync
  677. oris r5, r6, 0xfee0
  678. stb r4, 0(r5)
  679. sync
  680. blr
  681. .globl in_8
  682. in_8:
  683. oris r3, r3, 0xfe00
  684. lbz r3,0(r3)
  685. blr
  686. .globl in_16
  687. in_16:
  688. oris r3, r3, 0xfe00
  689. lhbrx r3, 0, r3
  690. blr
  691. .globl in_16_ne
  692. in_16_ne:
  693. oris r3, r3, 0xfe00
  694. lhzx r3, 0, r3
  695. blr
  696. .globl in_32
  697. in_32:
  698. oris r3, r3, 0xfe00
  699. lwbrx r3, 0, r3
  700. blr
  701. .globl out_8
  702. out_8:
  703. oris r3, r3, 0xfe00
  704. stb r4, 0(r3)
  705. eieio
  706. blr
  707. .globl out_16
  708. out_16:
  709. oris r3, r3, 0xfe00
  710. sthbrx r4, 0, r3
  711. eieio
  712. blr
  713. .globl out_16_ne
  714. out_16_ne:
  715. oris r3, r3, 0xfe00
  716. sth r4, 0(r3)
  717. eieio
  718. blr
  719. .globl out_32
  720. out_32:
  721. oris r3, r3, 0xfe00
  722. stwbrx r4, 0, r3
  723. eieio
  724. blr
  725. .globl read_8
  726. read_8:
  727. lbz r3,0(r3)
  728. blr
  729. .globl read_16
  730. read_16:
  731. lhbrx r3, 0, r3
  732. blr
  733. .globl read_32
  734. read_32:
  735. lwbrx r3, 0, r3
  736. blr
  737. .globl read_32_ne
  738. read_32_ne:
  739. lwz r3, 0(r3)
  740. blr
  741. .globl write_8
  742. write_8:
  743. stb r4, 0(r3)
  744. eieio
  745. blr
  746. .globl write_16
  747. write_16:
  748. sthbrx r4, 0, r3
  749. eieio
  750. blr
  751. .globl write_32
  752. write_32:
  753. stwbrx r4, 0, r3
  754. eieio
  755. blr
  756. .globl write_32_ne
  757. write_32_ne:
  758. stw r4, 0(r3)
  759. eieio
  760. blr
  761. .globl early_init_f
  762. early_init_f:
  763. mflr r11
  764. lis r10, 0x8000
  765. /* PCI Latency Timer */
  766. li r4, 0x0d
  767. ori r3, r10, PLTR@l
  768. bl __pci_config_write_8
  769. /* Cache Line Size */
  770. li r4, 0x08
  771. ori r3, r10, PCLSR@l
  772. bl __pci_config_write_8
  773. /* PCI Cmd */
  774. li r4, 6
  775. ori r3, r10, PCICR@l
  776. bl __pci_config_write_16
  777. #if 1
  778. /* PCI Stat */
  779. ori r3, r10, PCISR@l
  780. bl __pci_config_read_16
  781. ori r4, r4, 0xffff
  782. ori r3, r10, PCISR@l
  783. bl __pci_config_write_16
  784. #endif
  785. /* PICR1 */
  786. lis r4, 0xff14
  787. ori r4, r4, 0x1b98
  788. ori r3, r10, PICR1@l
  789. bl __pci_config_write_32
  790. /* PICR2 */
  791. lis r4, 0x0404
  792. ori r4, r4, 0x0004
  793. ori r3, r10, PICR2@l
  794. bl __pci_config_write_32
  795. /* MIOCR1 */
  796. li r4, 0x04
  797. ori r3, r10, MIOCR1@l
  798. bl __pci_config_write_8
  799. /* For the MPC8245, set register 77 to %00100000 (see Errata #15) */
  800. /* SDRAM_CLK_DEL (0x77)*/
  801. li r4, 0x10
  802. ori r3, r10, MIOCR2@l
  803. bl __pci_config_write_8
  804. /* EUMBBAR */
  805. lis r4, 0xfc00
  806. ori r3, r10, EUMBBAR@l
  807. bl __pci_config_write_32
  808. /* AMBOR */
  809. /* Even if Address Map B is not being used (though it should),
  810. * the memory DLL needs to be cleared/set/cleared before using memory.
  811. */
  812. ori r3, r10, AMBOR@l
  813. bl __pci_config_read_8 /* get Current bits */
  814. andi. r4, r4, 0xffdf
  815. ori r3, r10, AMBOR@l
  816. bl __pci_config_write_16 /* Clear DLL_RESET */
  817. ori r4, r4, 0x0020
  818. ori r3, r10, AMBOR@l
  819. bl __pci_config_write_16 /* Set DLL_RESET */
  820. andi. r4, r4, 0xffdf
  821. ori r3, r10, AMBOR@l
  822. bl __pci_config_write_16 /* Clear DLL_RESET */
  823. /* ERCR1 */
  824. lis r4, 0x8040 /* Enable RCS2, use supplied timings */
  825. ori r4, r4, 0x8000
  826. ori r3, r10, ERCR1@l
  827. bl __pci_config_write_32
  828. /* ERCR2 */
  829. lis r4, 0x0000 /* Disable RCS3 parms */
  830. ori r4, r4, 0x0000
  831. ori r3, r10, ERCR2@l
  832. bl __pci_config_write_32
  833. /* ERCR3 */
  834. lis r4, 0x0000 /* RCS3 at 0x70000000, 64K bytes */
  835. ori r4, r4, 0x0004
  836. ori r3, r10, ERCR2@l
  837. bl __pci_config_write_32
  838. /* Preserve memgo bit */
  839. /* MCCR1 */
  840. /* lis r4, 0x75a8 / Safe Local ROM = 11+3 clocks */
  841. lis r4, 0x75a0 /* Safe Local ROM = 11+3 clocks */
  842. /* lis r4, 0x73a0 / Fast Local ROM = 7+3 clocks */
  843. /* oris r4, r4, 0x0010 / Burst ROM/Flash enable */
  844. /* oris r4, r4, 0x0004 / Self-refresh enable */
  845. /* ori r4,r4,0xFFFF / 16Mbit 2bank SDRAM */
  846. /* ori r4,r4,0xAAAA / 256Mbit 4bank SDRAM (8245 only) */
  847. /* ori r4,r4,0x5555 / 64Mbit 2bank SDRAM */
  848. ori r4,r4,0x0000 /* 64Mbit 4bank SDRAM */
  849. ori r3, r10, MCCR1@l
  850. bl __pci_config_write_32
  851. /* MCCR2 */
  852. lis r4,0x0000
  853. /* oris r4,r4,0x4000 / TS_WAIT_TIMER = 3 clocks */
  854. oris r4,r4,0x1000 /* ASRISE = 8 clocks */
  855. oris r4,r4,0x0080 /* ASFALL = 8 clocks */
  856. /* oris r4,r4,0x0010 / SDRAM Parity (else ECC) */
  857. /* oris r4,r4,0x0008 / Write parity check */
  858. /* oris r4,r4,0x0004 / SDRAM inline reads */
  859. /* Select a refresh rate; it needs to match the bus speed; if too */
  860. /* slow, data may be lost; if too fast, performance is lost. We */
  861. /* use the fastest value so we run at all speeds. */
  862. /* Refresh = (15600ns/busclk) - (213 (see UM)). */
  863. /* ori r4,r4,0x1d2c / 133 MHz mem bus = 1867 */
  864. /* ori r4,r4,0x150c / 100 MHz mem bus = 1347 */
  865. /* ori r4,r4,0x10fc / 83 MHz mem bus = 1087 */
  866. /* ori r4,r4,0x0cc4 / 66 MHz mem bus = 817 */
  867. ori r4,r4,0x04cc /* 33 MHz mem bus (SAFE) = 307 */
  868. /* ori r4,r4,0x0002 / Reserve a page */
  869. /* ori r4,r4,0x0001 / RWM parity */
  870. ori r3, r10, MCCR2@l
  871. bl __pci_config_write_32
  872. /* MCCR3 */
  873. lis r4,0x0000 /* BSTOPRE_M = 7 (see A/N) */
  874. oris r4,r4,0x0500 /* REFREC = 8 clocks */
  875. ori r3, r10, MCCR3@l
  876. bl __pci_config_write_32
  877. /* MCCR4 */ /* Turn on registered buffer mode */
  878. lis r4, 0x2000 /* PRETOACT = 3 clocks */
  879. oris r4,r4,0x0400 /* ACTOPRE = 5 clocks */
  880. /* oris r4,r4,0x0080 / Enable 8-beat burst (32-bit bus) */
  881. /* oris r4,r4,0x0040 / Enable Inline ECC/Parity */
  882. oris r4,r4,0x0020 /* EXTROM enabled */
  883. oris r4,r4,0x0010 /* Registered buffers */
  884. /* oris r4,r4,0x0000 / BSTOPRE_U = 0 (see A/N) */
  885. oris r4,r4,0x0002 /* DBUS_SIZ[2] (8 bit on RCS1) */
  886. /* ori r4,r4,0x8000 / Registered DIMMs */
  887. ori r4,r4,0x2000 /*CAS Latency (CL=3) (see RDLAT) */
  888. /* ori r4,r4,0x2000 / CAS Latency (CL=2) (see RDLAT) */
  889. /* ori r4,r4,0x0300 / Sequential wrap/8-beat burst */
  890. ori r4,r4,0x0200 /* Sequential wrap/4-beat burst */
  891. ori r4,r4,0x0030 /* ACTORW = 3 clocks */
  892. ori r4,r4,0x0009 /* BSTOPRE_L = 9 (see A/N) */
  893. ori r3, r10, MCCR4@l
  894. bl __pci_config_write_32
  895. /* MSAR1 */
  896. lis r4, 0xc0804000@h
  897. ori r4, r4, 0xc0804000@l
  898. ori r3, r10, MSAR1@l
  899. bl __pci_config_write_32
  900. /* MSAR2 */
  901. lis r4, 0xc0804000@h
  902. ori r4, r4, 0xc0804000@l
  903. ori r3, r10, MSAR2@l
  904. bl __pci_config_write_32
  905. /* MESAR1 */
  906. lis r4, 0x00000000@h
  907. ori r4, r4, 0x00000000@l
  908. ori r3, r10, EMSAR1@l
  909. bl __pci_config_write_32
  910. /* MESAR2 */
  911. lis r4, 0x01010101@h
  912. ori r4, r4, 0x01010101@l
  913. ori r3, r10, EMSAR2@l
  914. bl __pci_config_write_32
  915. /* MEAR1 */
  916. lis r4, 0xffbf7f3f@h
  917. ori r4, r4, 0xffbf7f3f@l
  918. ori r3, r10, MEAR1@l
  919. bl __pci_config_write_32
  920. /* MEAR2 */
  921. lis r4, 0xffbf7f3f@h
  922. ori r4, r4, 0xffbf7f3f@l
  923. ori r3, r10, MEAR2@l
  924. bl __pci_config_write_32
  925. /* MEEAR1 */
  926. lis r4, 0x00000000@h
  927. ori r4, r4, 0x00000000@l
  928. ori r3, r10, EMEAR1@l
  929. bl __pci_config_write_32
  930. /* MEEAR2 */
  931. lis r4, 0x01010101@h
  932. ori r4, r4, 0x01010101@l
  933. ori r3, r10, EMEAR2@l
  934. bl __pci_config_write_32
  935. /* ODCR */
  936. li r4, 0x7f
  937. ori r3, r10, ODCR@l
  938. bl __pci_config_write_8
  939. /* MBER */
  940. li r4, 0x01
  941. ori r3, r10, MBER@l
  942. bl __pci_config_write_8
  943. /* Page CTR aka PGMAX */
  944. li r4, 0x32
  945. ori r3, r10, 0x70
  946. bl __pci_config_write_8
  947. #if 0
  948. /* CLK Drive */
  949. ori r4, r10, 0xfc01 /* Top bit will be ignored */
  950. ori r3, r10, 0x74
  951. bl __pci_config_write_16
  952. #endif
  953. /* delay */
  954. lis r7, 1
  955. mtctr r7
  956. label1: bdnz label1
  957. /* Set memgo bit */
  958. /* MCCR1 */
  959. ori r3, r10, MCCR1@l
  960. bl __pci_config_read_32
  961. lis r7, 0x0008
  962. or r4, r3, r7
  963. ori r3, r10, MCCR1@l
  964. bl __pci_config_write_32
  965. /* delay again */
  966. lis r7, 1
  967. mtctr r7
  968. label2: bdnz label2
  969. #if 0
  970. /* DEBUG: Infinite loop, write then read */
  971. loop:
  972. lis r7, 0xffff
  973. mtctr r7
  974. li r3, 0x5004
  975. lis r4, 0xa0a0
  976. ori r4, r4, 0x5050
  977. bl write_32_ne
  978. li r3, 0x5004
  979. bl read_32_ne
  980. bdnz loop
  981. #endif
  982. mtlr r11
  983. blr
  984. #endif