PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/ppc/boot/simple/rw4/rw4_init_brd.S

https://bitbucket.org/evzijst/gittest
Assembly | 1125 lines | 1003 code | 122 blank | 0 comment | 22 complexity | 777dea88a1e5adc5113407378f80ea3d MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /*----------------------------------------------------------------------------+
  2. | This source code has been made available to you by IBM on an AS-IS
  3. | basis. Anyone receiving this source is licensed under IBM
  4. | copyrights to use it in any way he or she deems fit, including
  5. | copying it, modifying it, compiling it, and redistributing it either
  6. | with or without modifications. No license under IBM patents or
  7. | patent applications is to be implied by the copyright license.
  8. |
  9. | Any user of this software should understand that IBM cannot provide
  10. | technical support for this software and will not be responsible for
  11. | any consequences resulting from the use of this software.
  12. |
  13. | Any person who transfers this source code or any derivative work
  14. | must include the IBM copyright notice, this paragraph, and the
  15. | preceding two paragraphs in the transferred software.
  16. |
  17. | COPYRIGHT I B M CORPORATION 1997
  18. | LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  19. +----------------------------------------------------------------------------*/
  20. /*----------------------------------------------------------------------------+
  21. | Author: Tony J. Cerreto
  22. | Component: BSPS
  23. | File: init_brd.s
  24. | Purpose: Vesta Evaluation Board initialization subroutines. The following
  25. | routines are available:
  26. | 1. INITB_EBIU0: Initialize EBIU0.
  27. | 2. INITB_CONFIG: Configure board.
  28. | 3. INITB_HSMC0: Initialize HSMC0 (SDRAM).
  29. | 4. INITB_HSMC1: Initialize HSMC1 (SDRAM).
  30. | 5. INITB_CACHE: Initialize Data and Instruction Cache.
  31. | 6. INITB_DCACHE: Initialize Data Cache.
  32. | 7. INITB_ICACHE: Initialize Instruction Cache.
  33. | 8. INITB_GET_CSPD: Get CPU Speed (Bus Speed and Processor Speed)
  34. |
  35. | Changes:
  36. | Date: Author Comment:
  37. | --------- ------ --------
  38. | 01-Mar-00 tjc Created
  39. | 04-Mar-00 jfh Modified CIC_SEL3_VAL to support 1284 (Mux3 & GPIO 21-28)
  40. | 04-Mar-00 jfh Modified XILINIX Reg 0 to support 1284 (Mux3 & GPIO 21-28)
  41. | 04-Mar-00 jfh Modified XILINIX Reg 1 to support 1284 (Mux3 & GPIO 21-28)
  42. | 04-Mar-00 jfh Modified XILINIX Reg 4 to support 1284 (Mux3 & GPIO 21-28)
  43. | 19-May-00 rlb Relcoated HSMC0 to 0x1F000000 to support 32MB of contiguous
  44. | SDRAM space. Changed cache ctl regs to reflect this.
  45. | 22-May-00 tjc Changed initb_get_cspd interface and eliminated
  46. | initb_get_bspd routines.
  47. | 26-May-00 tjc Added two nop instructions after all mtxxx/mfxxx
  48. | instructions due to PPC405 bug.
  49. +----------------------------------------------------------------------------*/
  50. #define VESTA
  51. #include "ppc_40x.h"
  52. #include "stb.h"
  53. /*----------------------------------------------------------------------------+
  54. | BOARD CONFIGURATION DEFINES
  55. +----------------------------------------------------------------------------*/
  56. #define CBS0_CR_VAL 0x00000002 /* CBS control reg value */
  57. #define CIC0_CR_VAL 0xD0800448 /* CIC control reg value */
  58. #define CIC0_SEL3_VAL 0x11500000 /* CIC select 3 reg value */
  59. #define CIC0_VCR_VAL 0x00631700 /* CIC video cntl reg value */
  60. /*----------------------------------------------------------------------------+
  61. | EBIU0 BANK REGISTERS DEFINES
  62. +----------------------------------------------------------------------------*/
  63. #define EBIU0_BRCRH0_VAL 0x00000000 /* BR High 0 (Extension Reg)*/
  64. #define EBIU0_BRCRH1_VAL 0x00000000 /* BR High 1 (Extension Reg)*/
  65. #define EBIU0_BRCRH2_VAL 0x40000000 /* BR High 2 (Extension Reg)*/
  66. #define EBIU0_BRCRH3_VAL 0x40000000 /* BR High 3 (Extension Reg)*/
  67. #define EBIU0_BRCRH4_VAL 0x00000000 /* BR High 4 (Extension Reg)*/
  68. #define EBIU0_BRCRH5_VAL 0x00000000 /* BR High 5 (Extension Reg)*/
  69. #define EBIU0_BRCRH6_VAL 0x00000000 /* BR High 6 (Extension Reg)*/
  70. #define EBIU0_BRCRH7_VAL 0x40000000 /* BR High 7 (Extension Reg)*/
  71. #define EBIU0_BRCR0_VAL 0xFC58BFFE /* BR 0: 16 bit Flash 4 MB */
  72. #define EBIU0_BRCR1_VAL 0xFF00BFFE /* BR 1: Ext Connector 1 MB */
  73. #if 1
  74. #define EBIU0_BRCR2_VAL 0x207CFFBE /* BR 2: Xilinx 8 MB */
  75. /* twt == 0x3f */
  76. #else
  77. #define EBIU0_BRCR2_VAL 0x207CCFBE /* BR 2: Xilinx 8 MB */
  78. /* twt == 0x0f */
  79. #endif
  80. #define EBIU0_BRCR3_VAL 0x407CBFBE /* BR 3: IDE Drive 8 MB */
  81. #define EBIU0_BRCR4_VAL 0xFF00BFFF /* BR 4: Disabled. 0 MB */
  82. #define EBIU0_BRCR5_VAL 0xFF00BFFF /* BR 5: Disabled. 0 MB */
  83. #define EBIU0_BRCR6_VAL 0xFF00BFFF /* BR 6: Disabled. 0 MB */
  84. #define EBIU0_BRCR7_VAL 0xCE3F0003 /* BR 7: Line Mode DMA 2 MB */
  85. /*----------------------------------------------------------------------------+
  86. | GPIO DEFINES
  87. +----------------------------------------------------------------------------*/
  88. #define STB_GPIO0_OUTPUT (STB_GPIO0_BASE_ADDRESS+ 0x00)
  89. #define STB_GPIO0_TC (STB_GPIO0_BASE_ADDRESS+ 0x04)
  90. #define STB_GPIO0_OS_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x08)
  91. #define STB_GPIO0_OS_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x0C)
  92. #define STB_GPIO0_TS_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x10)
  93. #define STB_GPIO0_TS_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x14)
  94. #define STB_GPIO0_OD (STB_GPIO0_BASE_ADDRESS+ 0x18)
  95. #define STB_GPIO0_INPUT (STB_GPIO0_BASE_ADDRESS+ 0x1C)
  96. #define STB_GPIO0_R1 (STB_GPIO0_BASE_ADDRESS+ 0x20)
  97. #define STB_GPIO0_R2 (STB_GPIO0_BASE_ADDRESS+ 0x24)
  98. #define STB_GPIO0_R3 (STB_GPIO0_BASE_ADDRESS+ 0x28)
  99. #define STB_GPIO0_IS_1_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x30)
  100. #define STB_GPIO0_IS_1_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x34)
  101. #define STB_GPIO0_IS_2_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x38)
  102. #define STB_GPIO0_IS_2_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x3C)
  103. #define STB_GPIO0_IS_3_0_31 (STB_GPIO0_BASE_ADDRESS+ 0x40)
  104. #define STB_GPIO0_IS_3_32_63 (STB_GPIO0_BASE_ADDRESS+ 0x44)
  105. #define STB_GPIO0_SS_1 (STB_GPIO0_BASE_ADDRESS+ 0x50)
  106. #define STB_GPIO0_SS_2 (STB_GPIO0_BASE_ADDRESS+ 0x54)
  107. #define STB_GPIO0_SS_3 (STB_GPIO0_BASE_ADDRESS+ 0x58)
  108. #define GPIO0_TC_VAL 0x0C020004 /* three-state control val */
  109. #define GPIO0_OS_0_31_VAL 0x51A00004 /* output select 0-31 val */
  110. #define GPIO0_OS_32_63_VAL 0x0000002F /* output select 32-63 val */
  111. #define GPIO0_TS_0_31_VAL 0x51A00000 /* three-state sel 0-31 val*/
  112. #define GPIO0_TS_32_63_VAL 0x0000000F /* three-state sel 32-63 val*/
  113. #define GPIO0_OD_VAL 0xC0000004 /* open drain val */
  114. #define GPIO0_IS_1_0_31_VAL 0x50000151 /* input select 1 0-31 val */
  115. #define GPIO0_IS_1_32_63_VAL 0x00000000 /* input select 1 32-63 val */
  116. #define GPIO0_IS_2_0_31_VAL 0x00000000 /* input select 2 0-31 val */
  117. #define GPIO0_IS_2_32_63_VAL 0x00000000 /* input select 2 32-63 val */
  118. #define GPIO0_IS_3_0_31_VAL 0x00000440 /* input select 3 0-31 val */
  119. #define GPIO0_IS_3_32_63_VAL 0x00000000 /* input select 3 32-63 val */
  120. #define GPIO0_SS_1_VAL 0x00000000 /* sync select 1 val */
  121. #define GPIO0_SS_2_VAL 0x00000000 /* sync select 2 val */
  122. #define GPIO0_SS_3_VAL 0x00000000 /* sync select 3 val */
  123. /*----------------------------------------------------------------------------+
  124. | XILINX DEFINES
  125. +----------------------------------------------------------------------------*/
  126. #define STB_XILINX_LED (STB_FPGA_BASE_ADDRESS+ 0x0100)
  127. #define STB_XILINX1_REG0 (STB_FPGA_BASE_ADDRESS+ 0x40000)
  128. #define STB_XILINX1_REG1 (STB_FPGA_BASE_ADDRESS+ 0x40002)
  129. #define STB_XILINX1_REG2 (STB_FPGA_BASE_ADDRESS+ 0x40004)
  130. #define STB_XILINX1_REG3 (STB_FPGA_BASE_ADDRESS+ 0x40006)
  131. #define STB_XILINX1_REG4 (STB_FPGA_BASE_ADDRESS+ 0x40008)
  132. #define STB_XILINX1_REG5 (STB_FPGA_BASE_ADDRESS+ 0x4000A)
  133. #define STB_XILINX1_REG6 (STB_FPGA_BASE_ADDRESS+ 0x4000C)
  134. #define STB_XILINX1_ID (STB_FPGA_BASE_ADDRESS+ 0x4000E)
  135. #define STB_XILINX1_FLUSH (STB_FPGA_BASE_ADDRESS+ 0x4000E)
  136. #define STB_XILINX2_REG0 (STB_FPGA_BASE_ADDRESS+ 0x80000)
  137. #define STB_XILINX2_REG1 (STB_FPGA_BASE_ADDRESS+ 0x80002)
  138. #define STB_XILINX2_REG2 (STB_FPGA_BASE_ADDRESS+ 0x80004)
  139. #define XILINX1_R0_VAL 0x2440 /* Xilinx 1 Register 0 Val */
  140. #define XILINX1_R1_VAL 0x0025 /* Xilinx 1 Register 1 Val */
  141. #define XILINX1_R2_VAL 0x0441 /* Xilinx 1 Register 2 Val */
  142. #define XILINX1_R3_VAL 0x0008 /* Xilinx 1 Register 3 Val */
  143. #define XILINX1_R4_VAL 0x0100 /* Xilinx 1 Register 4 Val */
  144. #define XILINX1_R5_VAL 0x6810 /* Xilinx 1 Register 5 Val */
  145. #define XILINX1_R6_VAL 0x0000 /* Xilinx 1 Register 6 Val */
  146. #if 0
  147. #define XILINX2_R0_VAL 0x0008 /* Xilinx 2 Register 0 Val */
  148. #define XILINX2_R1_VAL 0x0000 /* Xilinx 2 Register 1 Val */
  149. #else
  150. #define XILINX2_R0_VAL 0x0018 /* disable IBM IrDA RxD */
  151. #define XILINX2_R1_VAL 0x0008 /* enable SICC MAX chip */
  152. #endif
  153. #define XILINX2_R2_VAL 0x0000 /* Xilinx 2 Register 2 Val */
  154. /*----------------------------------------------------------------------------+
  155. | HSMC BANK REGISTERS DEFINES
  156. +----------------------------------------------------------------------------*/
  157. #ifdef SDRAM16MB
  158. #define HSMC0_BR0_VAL 0x000D2D55 /* 0x1F000000-007FFFFF R/W */
  159. #define HSMC0_BR1_VAL 0x008D2D55 /* 0x1F800000-1FFFFFFF R/W */
  160. #else
  161. #define HSMC0_BR0_VAL 0x1F0D2D55 /* 0x1F000000-007FFFFF R/W */
  162. #define HSMC0_BR1_VAL 0x1F8D2D55 /* 0x1F800000-1FFFFFFF R/W */
  163. #endif
  164. #define HSMC1_BR0_VAL 0xA00D2D55 /* 0xA0000000-A07FFFFF R/W */
  165. #define HSMC1_BR1_VAL 0xA08D2D55 /* 0xA0800000-A0FFFFFF R/W */
  166. /*----------------------------------------------------------------------------+
  167. | CACHE DEFINES
  168. +----------------------------------------------------------------------------*/
  169. #define DCACHE_NLINES 128 /* no. D-cache lines */
  170. #define DCACHE_NBYTES 32 /* no. bytes/ D-cache line */
  171. #define ICACHE_NLINES 256 /* no. I-cache lines */
  172. #define ICACHE_NBYTES 32 /* no. bytes/ I-cache line */
  173. #ifdef SDRAM16MB
  174. #define DCACHE_ENABLE 0x80000000 /* D-cache regions to enable*/
  175. #define ICACHE_ENABLE 0x80000001 /* I-cache regions to enable*/
  176. #else
  177. #define DCACHE_ENABLE 0x18000000 /* D-cache regions to enable*/
  178. #define ICACHE_ENABLE 0x18000001 /* I-cache regions to enable*/
  179. #endif
  180. /*----------------------------------------------------------------------------+
  181. | CPU CORE SPEED CALCULATION DEFINES
  182. +----------------------------------------------------------------------------*/
  183. #define GCS_LCNT 500000 /* CPU speed loop count */
  184. #define GCS_TROW_BYTES 8 /* no. bytes in table row */
  185. #define GCS_CTICK_TOL 100 /* allowable clock tick tol */
  186. #define GCS_NMULT 4 /* no. of core speed mults */
  187. /*--------------------------------------------------------------------+
  188. | No. 13.5Mhz
  189. | Clock Ticks
  190. | based on a
  191. | loop count Bus
  192. | of 100,000 Speed
  193. +--------------------------------------------------------------------*/
  194. gcs_lookup_table:
  195. .int 50000, 54000000 /* 54.0 Mhz */
  196. .int 66667, 40500000 /* 40.5 Mhz */
  197. .int 54545, 49500000 /* 49.5 Mhz */
  198. .int 46154, 58500000 /* 58.5 Mhz */
  199. .int 0, 0 /* end of table flag */
  200. /*****************************************************************************+
  201. | XXXXXXX XXX XXX XXXXXX XXXXXXX XXXXXX XX XX XX XXXX
  202. | XX X XX XX X XX X XX X XX XX XXX XX XXXX XX
  203. | XX X XXX XX XX X XX XX XXXX XX XX XX XX
  204. | XXXX X XX XXXX XXXXX XX XXXX XX XX XX
  205. | XX X XXX XX XX X XX XX XX XXX XXXXXX XX
  206. | XX X XX XX XX XX X XX XX XX XX XX XX XX XX
  207. | XXXXXXX XXX XXX XXXX XXXXXXX XXX XX XX XX XX XX XXXXXXX
  208. +*****************************************************************************/
  209. /******************************************************************************
  210. |
  211. | Routine: INITB_EBIU0.
  212. |
  213. | Purpose: Initialize all the EBIU0 Bank Registers
  214. | Parameters: None.
  215. | Returns: None.
  216. |
  217. ******************************************************************************/
  218. function_prolog(initb_ebiu0)
  219. /*--------------------------------------------------------------------+
  220. | Set EBIU0 Bank 0
  221. +--------------------------------------------------------------------*/
  222. lis r10,EBIU0_BRCR0_VAL@h
  223. ori r10,r10,EBIU0_BRCR0_VAL@l
  224. mtdcr ebiu0_brcr0,r10
  225. lis r10,EBIU0_BRCRH0_VAL@h
  226. ori r10,r10,EBIU0_BRCRH0_VAL@l
  227. mtdcr ebiu0_brcrh0,r10
  228. /*--------------------------------------------------------------------+
  229. | Set EBIU0 Bank 1
  230. +--------------------------------------------------------------------*/
  231. lis r10,EBIU0_BRCR1_VAL@h
  232. ori r10,r10,EBIU0_BRCR1_VAL@l
  233. mtdcr ebiu0_brcr1,r10
  234. lis r10,EBIU0_BRCRH1_VAL@h
  235. ori r10,r10,EBIU0_BRCRH1_VAL@l
  236. mtdcr ebiu0_brcrh1,r10
  237. /*--------------------------------------------------------------------+
  238. | Set EBIU0 Bank 2
  239. +--------------------------------------------------------------------*/
  240. lis r10,EBIU0_BRCR2_VAL@h
  241. ori r10,r10,EBIU0_BRCR2_VAL@l
  242. mtdcr ebiu0_brcr2,r10
  243. lis r10,EBIU0_BRCRH2_VAL@h
  244. ori r10,r10,EBIU0_BRCRH2_VAL@l
  245. mtdcr ebiu0_brcrh2,r10
  246. /*--------------------------------------------------------------------+
  247. | Set EBIU0 Bank 3
  248. +--------------------------------------------------------------------*/
  249. lis r10,EBIU0_BRCR3_VAL@h
  250. ori r10,r10,EBIU0_BRCR3_VAL@l
  251. mtdcr ebiu0_brcr3,r10
  252. lis r10,EBIU0_BRCRH3_VAL@h
  253. ori r10,r10,EBIU0_BRCRH3_VAL@l
  254. mtdcr ebiu0_brcrh3,r10
  255. /*--------------------------------------------------------------------+
  256. | Set EBIU0 Bank 4
  257. +--------------------------------------------------------------------*/
  258. lis r10,EBIU0_BRCR4_VAL@h
  259. ori r10,r10,EBIU0_BRCR4_VAL@l
  260. mtdcr ebiu0_brcr4,r10
  261. lis r10,EBIU0_BRCRH4_VAL@h
  262. ori r10,r10,EBIU0_BRCRH4_VAL@l
  263. mtdcr ebiu0_brcrh4,r10
  264. /*--------------------------------------------------------------------+
  265. | Set EBIU0 Bank 5
  266. +--------------------------------------------------------------------*/
  267. lis r10,EBIU0_BRCR5_VAL@h
  268. ori r10,r10,EBIU0_BRCR5_VAL@l
  269. mtdcr ebiu0_brcr5,r10
  270. lis r10,EBIU0_BRCRH5_VAL@h
  271. ori r10,r10,EBIU0_BRCRH5_VAL@l
  272. mtdcr ebiu0_brcrh5,r10
  273. /*--------------------------------------------------------------------+
  274. | Set EBIU0 Bank 6
  275. +--------------------------------------------------------------------*/
  276. lis r10,EBIU0_BRCR6_VAL@h
  277. ori r10,r10,EBIU0_BRCR6_VAL@l
  278. mtdcr ebiu0_brcr6,r10
  279. lis r10,EBIU0_BRCRH6_VAL@h
  280. ori r10,r10,EBIU0_BRCRH6_VAL@l
  281. mtdcr ebiu0_brcrh6,r10
  282. /*--------------------------------------------------------------------+
  283. | Set EBIU0 Bank 7
  284. +--------------------------------------------------------------------*/
  285. lis r10,EBIU0_BRCR7_VAL@h
  286. ori r10,r10,EBIU0_BRCR7_VAL@l
  287. mtdcr ebiu0_brcr7,r10
  288. lis r10,EBIU0_BRCRH7_VAL@h
  289. ori r10,r10,EBIU0_BRCRH7_VAL@l
  290. mtdcr ebiu0_brcrh7,r10
  291. blr
  292. function_epilog(initb_ebiu0)
  293. /******************************************************************************
  294. |
  295. | Routine: INITB_CONFIG
  296. |
  297. | Purpose: Configure the Vesta Evaluation Board. The following items
  298. | will be configured:
  299. | 1. Cross-Bar Switch.
  300. | 2. Chip Interconnect.
  301. | 3. Clear/reset key PPC registers.
  302. | 4. Xilinx and GPIO Registers.
  303. |
  304. | Returns: None.
  305. |
  306. ******************************************************************************/
  307. function_prolog(initb_config)
  308. /*--------------------------------------------------------------------+
  309. | Init CROSS-BAR SWITCH
  310. +--------------------------------------------------------------------*/
  311. lis r10,CBS0_CR_VAL@h /* r10 <- CBS Cntl Reg val */
  312. ori r10,r10,CBS0_CR_VAL@l
  313. mtdcr cbs0_cr,r10
  314. /*--------------------------------------------------------------------+
  315. | Init Chip-Interconnect (CIC) Registers
  316. +--------------------------------------------------------------------*/
  317. lis r10,CIC0_CR_VAL@h /* r10 <- CIC Cntl Reg val */
  318. ori r10,r10,CIC0_CR_VAL@l
  319. mtdcr cic0_cr,r10
  320. lis r10,CIC0_SEL3_VAL@h /* r10 <- CIC SEL3 Reg val */
  321. ori r10,r10,CIC0_SEL3_VAL@l
  322. mtdcr cic0_sel3,r10
  323. lis r10,CIC0_VCR_VAL@h /* r10 <- CIC Vid C-Reg val */
  324. ori r10,r10,CIC0_VCR_VAL@l
  325. mtdcr cic0_vcr,r10
  326. /*--------------------------------------------------------------------+
  327. | Clear SGR and DCWR
  328. +--------------------------------------------------------------------*/
  329. li r10,0x0000
  330. mtspr sgr,r10
  331. mtspr dcwr,r10
  332. /*--------------------------------------------------------------------+
  333. | Clear/set up some machine state registers.
  334. +--------------------------------------------------------------------*/
  335. li r10,0x0000 /* r10 <- 0 */
  336. mtdcr ebiu0_besr,r10 /* clr Bus Err Syndrome Reg */
  337. mtspr esr,r10 /* clr Exceptn Syndrome Reg */
  338. mttcr r10 /* timer control register */
  339. mtdcr uic0_er,r10 /* disable all interrupts */
  340. /* UIC_IIC0 | UIC_IIC1 | UIC_U0 | UIC_IR_RCV | UIC_IR_XMIT */
  341. lis r10, 0x00600e00@h
  342. ori r10,r10,0x00600e00@l
  343. mtdcr uic0_pr,r10
  344. li r10,0x00000020 /* UIC_EIR1 */
  345. mtdcr uic0_tr,r10
  346. lis r10,0xFFFF /* r10 <- 0xFFFFFFFF */
  347. ori r10,r10,0xFFFF /* */
  348. mtdbsr r10 /* clear/reset the dbsr */
  349. mtdcr uic0_sr,r10 /* clear pending interrupts */
  350. li r10,0x1000 /* set Machine Exception bit*/
  351. oris r10,r10,0x2 /* set Criticl Exception bit*/
  352. mtmsr r10 /* change MSR */
  353. /*--------------------------------------------------------------------+
  354. | Clear XER.
  355. +--------------------------------------------------------------------*/
  356. li r10,0x0000
  357. mtxer r10
  358. /*--------------------------------------------------------------------+
  359. | Init GPIO0 Registers
  360. +--------------------------------------------------------------------*/
  361. lis r10, STB_GPIO0_TC@h /* Three-state control */
  362. ori r10,r10,STB_GPIO0_TC@l
  363. lis r11, GPIO0_TC_VAL@h
  364. ori r11,r11,GPIO0_TC_VAL@l
  365. stw r11,0(r10)
  366. lis r10, STB_GPIO0_OS_0_31@h /* output select 0-31 */
  367. ori r10,r10,STB_GPIO0_OS_0_31@l
  368. lis r11, GPIO0_OS_0_31_VAL@h
  369. ori r11,r11,GPIO0_OS_0_31_VAL@l
  370. stw r11,0(r10)
  371. lis r10, STB_GPIO0_OS_32_63@h /* output select 32-63 */
  372. ori r10,r10,STB_GPIO0_OS_32_63@l
  373. lis r11, GPIO0_OS_32_63_VAL@h
  374. ori r11,r11,GPIO0_OS_32_63_VAL@l
  375. stw r11,0(r10)
  376. lis r10, STB_GPIO0_TS_0_31@h /* three-state select 0-31 */
  377. ori r10,r10,STB_GPIO0_TS_0_31@l
  378. lis r11, GPIO0_TS_0_31_VAL@h
  379. ori r11,r11,GPIO0_TS_0_31_VAL@l
  380. stw r11,0(r10)
  381. lis r10, STB_GPIO0_TS_32_63@h /* three-state select 32-63 */
  382. ori r10,r10,STB_GPIO0_TS_32_63@l
  383. lis r11, GPIO0_TS_32_63_VAL@h
  384. ori r11,r11,GPIO0_TS_32_63_VAL@l
  385. stw r11,0(r10)
  386. lis r10, STB_GPIO0_OD@h /* open drain */
  387. ori r10,r10,STB_GPIO0_OD@l
  388. lis r11, GPIO0_OD_VAL@h
  389. ori r11,r11,GPIO0_OD_VAL@l
  390. stw r11,0(r10)
  391. lis r10, STB_GPIO0_IS_1_0_31@h /* input select 1, 0-31 */
  392. ori r10,r10,STB_GPIO0_IS_1_0_31@l
  393. lis r11, GPIO0_IS_1_0_31_VAL@h
  394. ori r11,r11,GPIO0_IS_1_0_31_VAL@l
  395. stw r11,0(r10)
  396. lis r10, STB_GPIO0_IS_1_32_63@h /* input select 1, 32-63 */
  397. ori r10,r10,STB_GPIO0_IS_1_32_63@l
  398. lis r11, GPIO0_IS_1_32_63_VAL@h
  399. ori r11,r11,GPIO0_IS_1_32_63_VAL@l
  400. stw r11,0(r10)
  401. lis r10, STB_GPIO0_IS_2_0_31@h /* input select 2, 0-31 */
  402. ori r10,r10,STB_GPIO0_IS_2_0_31@l
  403. lis r11, GPIO0_IS_2_0_31_VAL@h
  404. ori r11,r11,GPIO0_IS_2_0_31_VAL@l
  405. stw r11,0(r10)
  406. lis r10, STB_GPIO0_IS_2_32_63@h /* input select 2, 32-63 */
  407. ori r10,r10,STB_GPIO0_IS_2_32_63@l
  408. lis r11, GPIO0_IS_2_32_63_VAL@h
  409. ori r11,r11,GPIO0_IS_2_32_63_VAL@l
  410. stw r11,0(r10)
  411. lis r10, STB_GPIO0_IS_3_0_31@h /* input select 3, 0-31 */
  412. ori r10,r10,STB_GPIO0_IS_3_0_31@l
  413. lis r11, GPIO0_IS_3_0_31_VAL@h
  414. ori r11,r11,GPIO0_IS_3_0_31_VAL@l
  415. stw r11,0(r10)
  416. lis r10, STB_GPIO0_IS_3_32_63@h /* input select 3, 32-63 */
  417. ori r10,r10,STB_GPIO0_IS_3_32_63@l
  418. lis r11, GPIO0_IS_3_32_63_VAL@h
  419. ori r11,r11,GPIO0_IS_3_32_63_VAL@l
  420. stw r11,0(r10)
  421. lis r10, STB_GPIO0_SS_1@h /* sync select 1 */
  422. ori r10,r10,STB_GPIO0_SS_1@l
  423. lis r11, GPIO0_SS_1_VAL@h
  424. ori r11,r11,GPIO0_SS_1_VAL@l
  425. stw r11,0(r10)
  426. lis r10, STB_GPIO0_SS_2@h /* sync select 2 */
  427. ori r10,r10,STB_GPIO0_SS_2@l
  428. lis r11, GPIO0_SS_2_VAL@h
  429. ori r11,r11,GPIO0_SS_2_VAL@l
  430. stw r11,0(r10)
  431. lis r10, STB_GPIO0_SS_3@h /* sync select 3 */
  432. ori r10,r10,STB_GPIO0_SS_3@l
  433. lis r11, GPIO0_SS_3_VAL@h
  434. ori r11,r11,GPIO0_SS_3_VAL@l
  435. stw r11,0(r10)
  436. /*--------------------------------------------------------------------+
  437. | Init Xilinx #1 Registers
  438. +--------------------------------------------------------------------*/
  439. lis r10, STB_XILINX1_REG0@h /* init Xilinx1 Reg 0 */
  440. ori r10,r10,STB_XILINX1_REG0@l
  441. li r11,XILINX1_R0_VAL
  442. sth r11,0(r10)
  443. lis r10, STB_XILINX1_REG1@h /* init Xilinx1 Reg 1 */
  444. ori r10,r10,STB_XILINX1_REG1@l
  445. li r11,XILINX1_R1_VAL
  446. sth r11,0(r10)
  447. lis r10, STB_XILINX1_REG2@h /* init Xilinx1 Reg 2 */
  448. ori r10,r10,STB_XILINX1_REG2@l
  449. li r11,XILINX1_R2_VAL
  450. sth r11,0(r10)
  451. lis r10, STB_XILINX1_REG3@h /* init Xilinx1 Reg 3 */
  452. ori r10,r10,STB_XILINX1_REG3@l
  453. li r11,XILINX1_R3_VAL
  454. sth r11,0(r10)
  455. lis r10, STB_XILINX1_REG4@h /* init Xilinx1 Reg 4 */
  456. ori r10,r10,STB_XILINX1_REG4@l
  457. li r11,XILINX1_R4_VAL
  458. sth r11,0(r10)
  459. lis r10, STB_XILINX1_REG5@h /* init Xilinx1 Reg 5 */
  460. ori r10,r10,STB_XILINX1_REG5@l
  461. li r11,XILINX1_R5_VAL
  462. sth r11,0(r10)
  463. lis r10, STB_XILINX1_REG6@h /* init Xilinx1 Reg 6 */
  464. ori r10,r10,STB_XILINX1_REG6@l
  465. li r11,XILINX1_R6_VAL
  466. sth r11,0(r10)
  467. lis r10, STB_XILINX1_FLUSH@h /* latch registers in Xilinx*/
  468. ori r10,r10,STB_XILINX1_FLUSH@l
  469. li r11,0x0000
  470. sth r11,0(r10)
  471. /*--------------------------------------------------------------------+
  472. | Init Xilinx #2 Registers
  473. +--------------------------------------------------------------------*/
  474. lis r10, STB_XILINX2_REG0@h /* init Xilinx2 Reg 0 */
  475. ori r10,r10,STB_XILINX2_REG0@l
  476. li r11,XILINX2_R0_VAL
  477. sth r11,0(r10)
  478. lis r10, STB_XILINX2_REG1@h /* init Xilinx2 Reg 1 */
  479. ori r10,r10,STB_XILINX2_REG1@l
  480. li r11,XILINX2_R1_VAL
  481. sth r11,0(r10)
  482. lis r10, STB_XILINX2_REG2@h /* init Xilinx2 Reg 2 */
  483. ori r10,r10,STB_XILINX2_REG2@l
  484. li r11,XILINX2_R2_VAL
  485. sth r11,0(r10)
  486. blr
  487. function_epilog(initb_config)
  488. /******************************************************************************
  489. |
  490. | Routine: INITB_HSMC0.
  491. |
  492. | Purpose: Initialize the HSMC0 Registers for SDRAM
  493. | Parameters: None.
  494. | Returns: R3 = 0: Successful
  495. | = -1: Unsuccessful, SDRAM did not reset properly.
  496. |
  497. ******************************************************************************/
  498. function_prolog(initb_hsmc0)
  499. mflr r0 /* Save return addr */
  500. /*--------------------------------------------------------------------+
  501. | Set Global SDRAM Controller to recommended default
  502. +--------------------------------------------------------------------*/
  503. lis r10,0x6C00
  504. ori r10,r10,0x0000
  505. mtdcr hsmc0_gr,r10
  506. /*--------------------------------------------------------------------+
  507. | Set HSMC0 Data Register to recommended default
  508. +--------------------------------------------------------------------*/
  509. lis r10,0x0037
  510. ori r10,r10,0x0000
  511. mtdcr hsmc0_data,r10
  512. /*--------------------------------------------------------------------+
  513. | Init HSMC0 Bank Register 0
  514. +--------------------------------------------------------------------*/
  515. lis r10,HSMC0_BR0_VAL@h
  516. ori r10,r10,HSMC0_BR0_VAL@l
  517. mtdcr hsmc0_br0,r10
  518. /*--------------------------------------------------------------------+
  519. | Init HSMC0 Bank Register 1
  520. +--------------------------------------------------------------------*/
  521. lis r10,HSMC0_BR1_VAL@h
  522. ori r10,r10,HSMC0_BR1_VAL@l
  523. mtdcr hsmc0_br1,r10
  524. /*--------------------------------------------------------------------+
  525. | Set HSMC0 Control Reg 0
  526. +--------------------------------------------------------------------*/
  527. lis r10,0x8077 /* PRECHARGE ALL DEVICE BKS */
  528. ori r10,r10,0x0000
  529. mtdcr hsmc0_cr0,r10
  530. li r3,0x0000
  531. bl hsmc_cr_wait /* wait for op completion */
  532. cmpwi cr0,r3,0x0000
  533. bne cr0,hsmc0_err
  534. lis r10,0x8078 /* AUTO-REFRESH */
  535. ori r10,r10,0x0000
  536. mtdcr hsmc0_cr0,r10
  537. li r3,0x0000
  538. bl hsmc_cr_wait /* wait for op completion */
  539. cmpwi cr0,r3,0x0000
  540. bne cr0,hsmc0_err
  541. lis r10,0x8070 /* PROG MODE W/DATA REG VAL */
  542. ori r10,r10,0x8000
  543. mtdcr hsmc0_cr0,r10
  544. li r3,0x0000
  545. bl hsmc_cr_wait /* wait for op completion */
  546. cmpwi cr0,r3,0x0000
  547. bne hsmc0_err
  548. /*--------------------------------------------------------------------+
  549. | Set HSMC0 Control Reg 1
  550. +--------------------------------------------------------------------*/
  551. lis r10,0x8077 /* PRECHARGE ALL DEVICE BKS */
  552. ori r10,r10,0x0000
  553. mtdcr hsmc0_cr1,r10
  554. li r3,0x0001
  555. bl hsmc_cr_wait /* wait for op completion */
  556. cmpwi cr0,r3,0x0000
  557. bne cr0,hsmc0_err
  558. lis r10,0x8078 /* AUTO-REFRESH */
  559. ori r10,r10,0x0000
  560. mtdcr hsmc0_cr1,r10
  561. li r3,0x0001
  562. bl hsmc_cr_wait /* wait for op completion */
  563. cmpwi cr0,r3,0x0000
  564. bne cr0,hsmc0_err
  565. lis r10,0x8070 /* PROG MODE W/DATA REG VAL */
  566. ori r10,r10,0x8000
  567. mtdcr hsmc0_cr1,r10
  568. li r3,0x0001
  569. bl hsmc_cr_wait /* wait for op completion */
  570. cmpwi cr0,r3,0x0000
  571. bne cr0,hsmc0_err
  572. /*--------------------------------------------------------------------+
  573. | Set HSMC0 Refresh Register
  574. +--------------------------------------------------------------------*/
  575. lis r10,0x0FE1
  576. ori r10,r10,0x0000
  577. mtdcr hsmc0_crr,r10
  578. li r3,0
  579. hsmc0_err:
  580. mtlr r0
  581. blr
  582. function_epilog(initb_hsmc0)
  583. /******************************************************************************
  584. |
  585. | Routine: INITB_HSMC1.
  586. |
  587. | Purpose: Initialize the HSMC1 Registers for SDRAM
  588. | Parameters: None.
  589. | Returns: R3 = 0: Successful
  590. | = -1: Unsuccessful, SDRAM did not reset properly.
  591. |
  592. ******************************************************************************/
  593. function_prolog(initb_hsmc1)
  594. mflr r0 /* Save return addr */
  595. /*--------------------------------------------------------------------+
  596. | Set Global SDRAM Controller to recommended default
  597. +--------------------------------------------------------------------*/
  598. lis r10,0x6C00
  599. ori r10,r10,0x0000
  600. mtdcr hsmc1_gr,r10
  601. /*--------------------------------------------------------------------+
  602. | Set HSMC1 Data Register to recommended default
  603. +--------------------------------------------------------------------*/
  604. lis r10,0x0037
  605. ori r10,r10,0x0000
  606. mtdcr hsmc1_data,r10
  607. /*--------------------------------------------------------------------+
  608. | Init HSMC1 Bank Register 0
  609. +--------------------------------------------------------------------*/
  610. lis r10,HSMC1_BR0_VAL@h
  611. ori r10,r10,HSMC1_BR0_VAL@l
  612. mtdcr hsmc1_br0,r10
  613. /*--------------------------------------------------------------------+
  614. | Init HSMC1 Bank Register 1
  615. +--------------------------------------------------------------------*/
  616. lis r10,HSMC1_BR1_VAL@h
  617. ori r10,r10,HSMC1_BR1_VAL@l
  618. mtdcr hsmc1_br1,r10
  619. /*--------------------------------------------------------------------+
  620. | Set HSMC1 Control Reg 0
  621. +--------------------------------------------------------------------*/
  622. lis r10,0x8077 /* PRECHARGE ALL DEVICE BANKS */
  623. ori r10,r10,0x0000
  624. mtdcr hsmc1_cr0,r10
  625. li r3,0x0002
  626. bl hsmc_cr_wait /* wait for operation completion */
  627. cmpwi cr0,r3,0x0000
  628. bne hsmc1_err
  629. lis r10,0x8078 /* AUTO-REFRESH */
  630. ori r10,r10,0x0000
  631. mtdcr hsmc1_cr0,r10
  632. li r3,0x0002
  633. bl hsmc_cr_wait /* wait for operation completion */
  634. cmpwi cr0,r3,0x0000
  635. bne hsmc1_err
  636. lis r10,0x8070 /* PROGRAM MODE W/DATA REG VALUE */
  637. ori r10,r10,0x8000
  638. mtdcr hsmc1_cr0,r10
  639. li r3,0x0002
  640. bl hsmc_cr_wait /* wait for operation completion */
  641. cmpwi cr0,r3,0x0000
  642. bne hsmc1_err
  643. /*--------------------------------------------------------------------+
  644. | Set HSMC1 Control Reg 1
  645. +--------------------------------------------------------------------*/
  646. lis r10,0x8077 /* PRECHARGE ALL DEVICE BKS */
  647. ori r10,r10,0x0000
  648. mtdcr hsmc1_cr1,r10
  649. li r3,0x0003
  650. bl hsmc_cr_wait /* wait for op completion */
  651. cmpwi cr0,r3,0x0000
  652. bne hsmc1_err
  653. lis r10,0x8078 /* AUTO-REFRESH */
  654. ori r10,r10,0x0000
  655. mtdcr hsmc1_cr1,r10
  656. li r3,0x0003
  657. bl hsmc_cr_wait /* wait for op completion */
  658. cmpwi cr0,r3,0x0000
  659. bne hsmc1_err
  660. lis r10,0x8070 /* PROG MODE W/DATA REG VAL */
  661. ori r10,r10,0x8000
  662. mtdcr hsmc1_cr1,r10
  663. li r3,0x0003
  664. bl hsmc_cr_wait /* wait for op completion */
  665. cmpwi cr0,r3,0x0000
  666. bne hsmc1_err
  667. /*--------------------------------------------------------------------+
  668. | Set HSMC1 Refresh Register
  669. +--------------------------------------------------------------------*/
  670. lis r10,0x0FE1
  671. ori r10,r10,0x0000
  672. mtdcr hsmc1_crr,r10
  673. xor r3,r3,r3
  674. hsmc1_err:
  675. mtlr r0
  676. blr
  677. function_epilog(initb_hsmc1)
  678. /******************************************************************************
  679. |
  680. | Routine: INITB_CACHE
  681. |
  682. | Purpose: This routine will enable Data and Instruction Cache.
  683. | The Data Cache is an 8K two-way set associative and the
  684. | Instruction Cache is an 16K two-way set associative cache.
  685. |
  686. | Parameters: None.
  687. |
  688. | Returns: None.
  689. |
  690. ******************************************************************************/
  691. function_prolog(initb_cache)
  692. mflr r0 /* Save return addr */
  693. bl initb_Dcache /* enable D-Cache */
  694. bl initb_Icache /* enable I-Cache */
  695. mtlr r0
  696. blr
  697. function_epilog(initb_cache)
  698. /******************************************************************************
  699. |
  700. | Routine: INITB_DCACHE
  701. |
  702. | Purpose: This routine will invalidate all data in the Data Cache and
  703. | then enable D-Cache. If cache is enabled already, the D-Cache
  704. | will be flushed before the data is invalidated.
  705. |
  706. | Parameters: None.
  707. |
  708. | Returns: None.
  709. |
  710. ******************************************************************************/
  711. function_prolog(initb_Dcache)
  712. /*--------------------------------------------------------------------+
  713. | Flush Data Cache if enabled
  714. +--------------------------------------------------------------------*/
  715. mfdccr r10 /* r10 <- DCCR */
  716. isync /* ensure prev insts done */
  717. cmpwi r10,0x00
  718. beq ic_dcinv /* D-cache off, invalidate */
  719. /*--------------------------------------------------------------------+
  720. | Data Cache enabled, force known memory addresses to be Cached
  721. +--------------------------------------------------------------------*/
  722. lis r10,HSMC0_BR0_VAL@h /* r10 <- first memory loc */
  723. andis. r10,r10,0xFFF0
  724. li r11,DCACHE_NLINES /* r11 <- # A-way addresses */
  725. addi r11,r11,DCACHE_NLINES /* r11 <- # B-way addresses */
  726. mtctr r11 /* set loop counter */
  727. ic_dcload:
  728. lwz r12,0(r10) /* force cache of address */
  729. addi r10,r10,DCACHE_NBYTES /* r10 <- next memory loc */
  730. bdnz ic_dcload
  731. sync /* ensure prev insts done */
  732. isync
  733. /*--------------------------------------------------------------------+
  734. | Flush the known memory addresses from Cache
  735. +--------------------------------------------------------------------*/
  736. lis r10,HSMC0_BR0_VAL@h /* r10 <- first memory loc */
  737. andis. r10,r10,0xFFF0
  738. mtctr r11 /* set loop counter */
  739. ic_dcflush:
  740. dcbf 0,r10 /* flush D-cache line */
  741. addi r10,r10,DCACHE_NBYTES /* r10 <- next memory loc */
  742. bdnz ic_dcflush
  743. sync /* ensure prev insts done */
  744. isync
  745. /*--------------------------------------------------------------------+
  746. | Disable then invalidate Data Cache
  747. +--------------------------------------------------------------------*/
  748. li r10,0 /* r10 <- 0 */
  749. mtdccr r10 /* disable the D-Cache */
  750. isync /* ensure prev insts done */
  751. ic_dcinv:
  752. li r10,0 /* r10 <- line address */
  753. li r11,DCACHE_NLINES /* r11 <- # lines in cache */
  754. mtctr r11 /* set loop counter */
  755. ic_dcloop:
  756. dccci 0,r10 /* invalidate A/B cache lns */
  757. addi r10,r10,DCACHE_NBYTES /* bump to next line */
  758. bdnz ic_dcloop
  759. sync /* ensure prev insts done */
  760. isync
  761. /*--------------------------------------------------------------------+
  762. | Enable Data Cache
  763. +--------------------------------------------------------------------*/
  764. lis r10,DCACHE_ENABLE@h /* r10 <- D-cache enable msk*/
  765. ori r10,r10,DCACHE_ENABLE@l
  766. mtdccr r10
  767. sync /* ensure prev insts done */
  768. isync
  769. blr
  770. function_epilog(initb_Dcache)
  771. /******************************************************************************
  772. |
  773. | Routine: INITB_ICACHE
  774. |
  775. | Purpose: This routine will invalidate all data in the Instruction
  776. | Cache then enable I-Cache.
  777. |
  778. | Parameters: None.
  779. |
  780. | Returns: None.
  781. |
  782. ******************************************************************************/
  783. function_prolog(initb_Icache)
  784. /*--------------------------------------------------------------------+
  785. | Invalidate Instruction Cache
  786. +--------------------------------------------------------------------*/
  787. li r10,0 /* r10 <- lines address */
  788. iccci 0,r10 /* invalidate all I-cache */
  789. sync /* ensure prev insts done */
  790. isync
  791. /*--------------------------------------------------------------------+
  792. | Enable Instruction Cache
  793. +--------------------------------------------------------------------*/
  794. lis r10,ICACHE_ENABLE@h /* r10 <- I-cache enable msk*/
  795. ori r10,r10,ICACHE_ENABLE@l
  796. mticcr r10
  797. sync /* ensure prev insts done */
  798. isync
  799. blr
  800. function_epilog(initb_Icache)
  801. #if 0
  802. /******************************************************************************
  803. |
  804. | Routine: INITB_GET_CSPD
  805. |
  806. | Purpose: Determine the CPU Core Speed. The 13.5 Mhz Time Base
  807. | Counter (TBC) is used to measure a conditional branch
  808. | instruction.
  809. |
  810. | Parameters: R3 = Address of Bus Speed
  811. | R4 = Address of Core Speed
  812. |
  813. | Returns: (R3) = >0: Bus Speed.
  814. | 0: Bus Speed not found in Look-Up Table.
  815. | (R4) = >0: Core Speed.
  816. | 0: Core Speed not found in Look-Up Table.
  817. |
  818. | Note: 1. This routine assumes the bdnz branch instruction takes
  819. | two instruction cycles to complete.
  820. | 2. This routine must be called before interrupts are enabled.
  821. |
  822. ******************************************************************************/
  823. function_prolog(initb_get_cspd)
  824. mflr r0 /* Save return address */
  825. /*--------------------------------------------------------------------+
  826. | Set-up timed loop
  827. +--------------------------------------------------------------------*/
  828. lis r9,gcs_time_loop@h /* r9 <- addr loop instr */
  829. ori r9,r9,gcs_time_loop@l
  830. lis r10,GCS_LCNT@h /* r10 <- loop count */
  831. ori r10,r10,GCS_LCNT@l
  832. mtctr r10 /* ctr <- loop count */
  833. lis r11,STB_TIMERS_TBC@h /* r11 <- TBC register addr */
  834. ori r11,r11,STB_TIMERS_TBC@l
  835. li r12,0 /* r12 <- 0 */
  836. /*--------------------------------------------------------------------+
  837. | Cache timed-loop instruction
  838. +--------------------------------------------------------------------*/
  839. icbt 0,r9
  840. sync
  841. isync
  842. /*--------------------------------------------------------------------+
  843. | Get number of 13.5 Mhz cycles to execute time-loop
  844. +--------------------------------------------------------------------*/
  845. stw r12,0(r11) /* reset TBC */
  846. gcs_time_loop:
  847. bdnz+ gcs_time_loop /* force branch pred taken */
  848. lwz r5,0(r11) /* r5 <- num 13.5 Mhz ticks */
  849. li r6,5 /* LUT based on 1/5th the...*/
  850. divw r5,r5,r6 /*..loop count used */
  851. sync
  852. isync
  853. /*--------------------------------------------------------------------+
  854. | Look-up core speed based on TBC value
  855. +--------------------------------------------------------------------*/
  856. lis r6,gcs_lookup_table@h /* r6 <- pts at core spd LUT*/
  857. ori r6,r6,gcs_lookup_table@l
  858. bl gcs_cspd_lookup /* find core speed in LUT */
  859. mtlr r0 /* set return address */
  860. blr
  861. function_epilog(initb_get_cspd)
  862. #endif
  863. /*****************************************************************************+
  864. | XXXX XX XX XXXXXX XXXXXXX XXXXXX XX XX XX XXXX
  865. | XX XXX XX X XX X XX X XX XX XXX XX XXXX XX
  866. | XX XXXX XX XX XX X XX XX XXXX XX XX XX XX
  867. | XX XX XXXX XX XXXX XXXXX XX XXXX XX XX XX
  868. | XX XX XXX XX XX X XX XX XX XXX XXXXXX XX
  869. | XX XX XX XX XX X XX XX XX XX XX XX XX XX
  870. | XXXX XX XX XXXX XXXXXXX XXX XX XX XX XX XX XXXXXXX
  871. +*****************************************************************************/
  872. /******************************************************************************
  873. |
  874. | Routine: HSMC_CR_WAIT
  875. |
  876. | Purpose: Wait for the HSMC Control Register (bits 12-16) to be reset
  877. | after an auto-refresh, pre-charge or program mode register
  878. | command execution.
  879. |
  880. | Parameters: R3 = HSMC Control Register ID.
  881. | 0: HSMC0 CR0
  882. | 1: HSMC0 CR1
  883. | 2: HSMC1 CR0
  884. | 3: HSMC1 CR1
  885. |
  886. | Returns: R3 = 0: Successful
  887. | -1: Unsuccessful
  888. |
  889. ******************************************************************************/
  890. hsmc_cr_wait:
  891. li r11,10 /* r11 <- retry counter */
  892. mtctr r11 /* set retry counter */
  893. mr r11,r3 /* r11 <- HSMC CR reg id */
  894. hsmc_cr_rep:
  895. bdz hsmc_cr_err /* branch if max retries hit*/
  896. /*--------------------------------------------------------------------+
  897. | GET HSMCx_CRx value based on HSMC Control Register ID
  898. +--------------------------------------------------------------------*/
  899. try_hsmc0_cr0: /* CHECK IF ID=HSMC0 CR0 REG*/
  900. cmpwi cr0,r11,0x0000
  901. bne cr0,try_hsmc0_cr1
  902. mfdcr r10,hsmc0_cr0 /* r11 <- HSMC0 CR0 value */
  903. b hsmc_cr_read
  904. try_hsmc0_cr1: /* CHECK IF ID=HSMC0 CR1 REG*/
  905. cmpwi cr0,r11,0x0001
  906. bne cr0,try_hsmc1_cr0
  907. mfdcr r10,hsmc0_cr1 /* r10 <- HSMC0 CR1 value */
  908. b hsmc_cr_read
  909. try_hsmc1_cr0: /* CHECK IF ID=HSMC1 CR0 REG*/
  910. cmpwi cr0,r11,0x0002
  911. bne cr0,try_hsmc1_cr1
  912. mfdcr r10,hsmc1_cr0 /* r10 <- HSMC1 CR0 value */
  913. b hsmc_cr_read
  914. try_hsmc1_cr1: /* CHECK IF ID=HSMC1 CR1 REG*/
  915. cmpwi cr0,r11,0x0003
  916. bne cr0,hsmc_cr_err
  917. mfdcr r10,hsmc1_cr1 /* r10 <- HSMC1 CR1 value */
  918. /*--------------------------------------------------------------------+
  919. | Check if HSMC CR register was reset after command execution
  920. +--------------------------------------------------------------------*/
  921. hsmc_cr_read:
  922. lis r12,0x000F /* create "AND" mask */
  923. ori r12,r12,0x8000
  924. and. r10,r10,r12 /* r10 <- HSMC CR bits 12-16*/
  925. bne cr0,hsmc_cr_rep /* wait for bits to reset */
  926. li r3,0 /* set return code = success*/
  927. b hsmc_cr_done
  928. hsmc_cr_err: /* ERROR: SDRAM didn't reset*/
  929. li r3,-1 /* set RC=unsuccessful */
  930. hsmc_cr_done:
  931. blr
  932. #if 0
  933. /******************************************************************************
  934. |
  935. | Routine: GCS_CSPD_LOOKUP
  936. |
  937. | Purpose: Uses the number of 13.5 Mhz clock ticks found after executing
  938. | the branch instruction time loop to look-up the CPU Core Speed
  939. | in the Core Speed Look-up Table.
  940. |
  941. | Parameters: R3 = Address of Bus Speed
  942. | R4 = Address of Core Speed
  943. | R5 = Number of 13.5 Mhz clock ticks found in time loop.
  944. | R6 = Pointer to Core-Speed Look-Up Table
  945. |
  946. | Returns: (R3) = >0: Bus Speed.
  947. | 0: Bus Speed not found in Look-Up Table.
  948. | (R4) = >0: Core Speed.
  949. | 0: Core Speed not found in Look-Up Table.
  950. |
  951. | Note: Core Speed = Bus Speed * Mult Factor (1-4x).
  952. |
  953. ******************************************************************************/
  954. gcs_cspd_lookup:
  955. li r9,1 /* r9 <- core speed mult */
  956. /*--------------------------------------------------------------------+
  957. | Get theoritical number 13.5 Mhz ticks for a given Bus Speed from
  958. | Look-up Table. Check all mult factors to determine if calculated
  959. | value matches theoretical value (within a tolerance).
  960. +--------------------------------------------------------------------*/
  961. gcs_cspd_loop:
  962. lwz r10,0(r6) /* r10 <- no. ticks from LUT*/
  963. divw r10,r10,r9 /* r10 <- div mult (1-4x) */
  964. subi r11,r10,GCS_CTICK_TOL /* r11 <- no. tks low range */
  965. addi r12,r10,GCS_CTICK_TOL /* r12 <- no. tks high range*/
  966. cmpw cr0,r5,r11 /* calc value within range? */
  967. blt gcs_cspd_retry /* less than low range */
  968. cmpw cr0,r5,r12
  969. bgt gcs_cspd_retry /* greater than high range */
  970. b gcs_cspd_fnd /* calc value within range */
  971. /*--------------------------------------------------------------------+
  972. | SO FAR CORE SPEED NOT FOUND: Check next mult factor
  973. +--------------------------------------------------------------------*/
  974. gcs_cspd_retry:
  975. addi r9,r9,1 /* bump mult factor (1-4x) */
  976. cmpwi cr0,r9,GCS_NMULT
  977. ble gcs_cspd_loop
  978. /*--------------------------------------------------------------------+
  979. | SO FAR CORE SPEED NOT FOUND: Point at next Bus Speed in LUT
  980. +--------------------------------------------------------------------*/
  981. li r9,1 /* reset mult factor */
  982. addi r6,r6,GCS_TROW_BYTES /* point at next table entry*/
  983. lwz r10,0(r6)
  984. cmpwi cr0,r10,0 /* check for EOT flag */
  985. bne gcs_cspd_loop
  986. /*--------------------------------------------------------------------+
  987. | COMPUTE CORE SPEED AND GET BUS SPEED FROM LOOK-UP TABLE
  988. +--------------------------------------------------------------------*/
  989. gcs_cspd_fnd:
  990. lwz r5,4(r6) /* r5 <- Bus Speed in LUT */
  991. mullw r6,r5,r9 /* r6 <- Core speed */
  992. stw r5,0(r3) /* (r3) <- Bus Speed */
  993. stw r6,0(r4) /* (r4) <- Core Speed */
  994. blr
  995. #endif