init.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. /*------------------------------------------------------------------------------+
  2. *
  3. * This souce code has been made available to you by EuroDesign
  4. * (www.eurodsn.de). It's based on the original IBM source code, so
  5. * this follows:
  6. *
  7. * This source code is dual-licensed. You may use it under the terms of the
  8. * GNU General Public License version 2, or under the license below.
  9. *
  10. * This source code has been made available to you by IBM on an AS-IS
  11. * basis. Anyone receiving this source is licensed under IBM
  12. * copyrights to use it in any way he or she deems fit, including
  13. * copying it, modifying it, compiling it, and redistributing it either
  14. * with or without modifications. No license under IBM patents or
  15. * patent applications is to be implied by the copyright license.
  16. *
  17. * Any user of this software should understand that IBM cannot provide
  18. * technical support for this software and will not be responsible for
  19. * any consequences resulting from the use of this software.
  20. *
  21. * Any person who transfers this source code or any derivative work
  22. * must include the IBM copyright notice, this paragraph, and the
  23. * preceding two paragraphs in the transferred software.
  24. *
  25. * COPYRIGHT I B M CORPORATION 1995
  26. * LICENSED MATERIAL - PROGRAM PROPERTY OF I B M
  27. *------------------------------------------------------------------------------- */
  28. #include <config.h>
  29. #include <asm/ppc4xx.h>
  30. #define _LINUX_CONFIG_H 1 /* avoid reading Linux autoconf.h file */
  31. #include <ppc_asm.tmpl>
  32. #include <ppc_defs.h>
  33. #include <asm/cache.h>
  34. #include <asm/mmu.h>
  35. /**
  36. * ext_bus_cntlr_init - Initializes the External Bus Controller for the external peripherals
  37. *
  38. * IMPORTANT: For pass1 this code must run from cache since you can not
  39. * reliably change a peripheral banks timing register (pbxap) while running
  40. * code from that bank. For ex., since we are running from ROM on bank 0, we
  41. * can NOT execute the code that modifies bank 0 timings from ROM, so
  42. * we run it from cache.
  43. *
  44. * Bank 0 - Boot-Flash
  45. * Bank 1 - NAND-Flash
  46. * Bank 2 - ISA bus
  47. * Bank 3 - Second Flash
  48. * Bank 4 - USB controller
  49. */
  50. .globl ext_bus_cntlr_init
  51. ext_bus_cntlr_init:
  52. /*
  53. * We need the current boot up configuration to set correct
  54. * timings into internal flash and external flash
  55. */
  56. mfdcr r24,CPC0_PSR /* xxxx xxxx xxxx xxx? ?xxx xxxx xxxx xxxx
  57. 0 0 -> 8 bit external ROM
  58. 0 1 -> 16 bit internal ROM */
  59. addi r4,0,2
  60. srw r24,r24,r4 /* shift right r24 two positions */
  61. andi. r24,r24,0x06000
  62. /*
  63. * All calculations are based on 33MHz EBC clock.
  64. *
  65. * First, create a "very slow" timing (~250ns) with burst mode enabled
  66. * This is need for the external flash access
  67. */
  68. lis r25,0x0800
  69. ori r25,r25,0x0280 /* 0000 1000 0xxx 0000 0000 0010 100x xxxx = 0x03800280
  70. /*
  71. * Second, create a fast timing:
  72. * 90ns first cycle - 3 clock access
  73. * and 90ns burst cycle, plus 1 clock after the last access
  74. * This is used for the internal access
  75. */
  76. lis r26,0x8900
  77. ori r26,r26,0x0280 /* 1000 1001 0xxx 0000 0000 0010 100x xxxx
  78. /*
  79. * We can't change settings on CS# if we currently use them.
  80. * -> load a few instructions into cache and run this code from cache
  81. */
  82. mflr r4 /* save link register */
  83. bl ..getAddr
  84. ..getAddr:
  85. mflr r3 /* get address of ..getAddr */
  86. mtlr r4 /* restore link register */
  87. addi r4,0,14 /* set ctr to 10; used to prefetch */
  88. mtctr r4 /* 10 cache lines to fit this function
  89. in cache (gives us 8x10=80 instructions) */
  90. ..ebcloop:
  91. icbt r0,r3 /* prefetch cache line for addr in r3 */
  92. addi r3,r3,32 /* move to next cache line */
  93. bdnz ..ebcloop /* continue for 10 cache lines */
  94. /*
  95. * Delay to ensure all accesses to ROM are complete before changing
  96. * bank 0 timings. 200usec should be enough.
  97. * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles
  98. */
  99. lis r3,0x0
  100. ori r3,r3,0xA000 /* ensure 200usec have passed since reset */
  101. mtctr r3
  102. ..spinlp:
  103. bdnz ..spinlp /* spin loop */
  104. /*-----------------------------------------------------------------------
  105. * Memory Bank 0 (BOOT-ROM) initialization
  106. * 0xFFEF00000....0xFFFFFFF
  107. * We only have to change the timing. Mapping is ok by boot-strapping
  108. *----------------------------------------------------------------------- */
  109. li r4,PB1AP /* PB0AP=Peripheral Bank 0 Access Parameters */
  110. mtdcr EBC0_CFGADDR,r4
  111. mr r4,r26 /* assume internal fast flash is boot flash */
  112. cmpwi r24,0x2000 /* assumption true? ... */
  113. beq 1f /* ...yes! */
  114. mr r4,r25 /* ...no, use the slow variant */
  115. mr r25,r26 /* use this for the other flash */
  116. 1:
  117. mtdcr EBC0_CFGDATA,r4 /* change timing now */
  118. li r4,PB0CR /* PB0CR=Peripheral Bank 0 Control Register */
  119. mtdcr EBC0_CFGADDR,r4
  120. mfdcr r4,EBC0_CFGDATA
  121. lis r3,0x0001
  122. ori r3,r3,0x8000 /* allow reads and writes */
  123. or r4,r4,r3
  124. mtdcr EBC0_CFGDATA,r4
  125. /*-----------------------------------------------------------------------
  126. * Memory Bank 3 (Second-Flash) initialization
  127. * 0xF0000000...0xF01FFFFF -> 2MB
  128. *----------------------------------------------------------------------- */
  129. li r4,PB3AP /* Peripheral Bank 1 Access Parameter */
  130. mtdcr EBC0_CFGADDR,r4
  131. mtdcr EBC0_CFGDATA,r2 /* change timing */
  132. li r4,PB3CR /* Peripheral Bank 1 Configuration Registers */
  133. mtdcr EBC0_CFGADDR,r4
  134. lis r4,0xF003
  135. ori r4,r4,0x8000
  136. /*
  137. * Consider boot configuration
  138. */
  139. xori r24,r24,0x2000 /* invert current bus width */
  140. or r4,r4,r24
  141. mtdcr EBC0_CFGDATA,r4
  142. /*-----------------------------------------------------------------------
  143. * Memory Bank 1 (NAND-Flash) initialization
  144. * 0x77D00000...0x77DFFFFF -> 1MB
  145. * - the write/read pulse to the NAND can be as short as 25ns, bus the cycle time is always 50ns
  146. * - the setup time is 0ns
  147. * - the hold time is 15ns
  148. * ->
  149. * - TWT = 0
  150. * - CSN = 0
  151. * - OEN = 0
  152. * - WBN = 0
  153. * - WBF = 0
  154. * - TH = 1
  155. * ----> 2 clocks per cycle = 60ns cycle (30ns active, 30ns hold)
  156. *----------------------------------------------------------------------- */
  157. li r4,PB1AP /* Peripheral Bank 1 Access Parameter */
  158. mtdcr EBC0_CFGADDR,r4
  159. lis r4,0x0000
  160. ori r4,r4,0x0200
  161. mtdcr EBC0_CFGDATA,r4
  162. li r4,PB1CR /* Peripheral Bank 1 Configuration Registers */
  163. mtdcr EBC0_CFGADDR,r4
  164. lis r4,0x77D1
  165. ori r4,r4,0x8000
  166. mtdcr EBC0_CFGDATA,r4
  167. /* USB init (without acceleration) */
  168. #ifndef CONFIG_ISP1161_PRESENT
  169. li r4,PB4AP /* PB4AP=Peripheral Bank 4 Access Parameters */
  170. mtdcr EBC0_CFGADDR,r4
  171. lis r4,0x0180
  172. ori r4,r4,0x5940
  173. mtdcr EBC0_CFGDATA,r4
  174. #endif
  175. /*-----------------------------------------------------------------------
  176. * Memory Bank 2 (ISA Access) initialization (plus memory bank 6 and 7)
  177. * 0x78000000...0x7BFFFFFF -> 64 MB
  178. * Wir arbeiten bei 33 MHz -> 30ns
  179. *-----------------------------------------------------------------------
  180. A7 (ppc notation) or A24 (standard notation) decides about
  181. the type of access:
  182. A7/A24=0 -> memory cycle
  183. A7/ /A24=1 -> I/O cycle
  184. */
  185. li r4,PB2AP /* PB2AP=Peripheral Bank 2 Access Parameters */
  186. mtdcr EBC0_CFGADDR,r4
  187. /*
  188. We emulate an ISA access
  189. 1. Address active
  190. 2. wait 0 EBC clocks -> CSN=0
  191. 3. set CS#
  192. 4. wait 0 EBC clock -> OEN/WBN=0
  193. 5. set OE#/WE#
  194. 6. wait 4 clocks (ca. 90ns) and for Ready signal
  195. 7. hold for 4 clocks -> TH=4
  196. */
  197. #if 1
  198. /* faster access to isa-bus */
  199. lis r4,0x0180
  200. ori r4,r4,0x5940
  201. #else
  202. lis r4,0x0100
  203. ori r4,r4,0x0340
  204. #endif
  205. mtdcr EBC0_CFGDATA,r4
  206. #ifdef IDE_USES_ISA_EMULATION
  207. li r25,PB5AP /* PB5AP=Peripheral Bank 5 Access Parameters */
  208. mtdcr EBC0_CFGADDR,r25
  209. mtdcr EBC0_CFGDATA,r4
  210. #endif
  211. li r25,PB6AP /* PB6AP=Peripheral Bank 6 Access Parameters */
  212. mtdcr EBC0_CFGADDR,r25
  213. mtdcr EBC0_CFGDATA,r4
  214. li r25,PB7AP /* PB7AP=Peripheral Bank 7 Access Parameters */
  215. mtdcr EBC0_CFGADDR,r25
  216. mtdcr EBC0_CFGDATA,r4
  217. li r25,PB2CR /* PB2CR=Peripheral Bank 2 Configuration Register */
  218. mtdcr EBC0_CFGADDR,r25
  219. lis r4,0x780B
  220. ori r4,r4,0xA000
  221. mtdcr EBC0_CFGDATA,r4
  222. /*
  223. * the other areas are only 1MiB in size
  224. */
  225. lis r4,0x7401
  226. ori r4,r4,0xA000
  227. li r25,PB6CR /* PB6CR=Peripheral Bank 6 Configuration Register */
  228. mtdcr EBC0_CFGADDR,r25
  229. lis r4,0x7401
  230. ori r4,r4,0xA000
  231. mtdcr EBC0_CFGDATA,r4
  232. li r25,PB7CR /* PB7CR=Peripheral Bank 7 Configuration Register */
  233. mtdcr EBC0_CFGADDR,r25
  234. lis r4,0x7411
  235. ori r4,r4,0xA000
  236. mtdcr EBC0_CFGDATA,r4
  237. #ifndef CONFIG_ISP1161_PRESENT
  238. li r25,PB4CR /* PB4CR=Peripheral Bank 4 Configuration Register */
  239. mtdcr EBC0_CFGADDR,r25
  240. lis r4,0x7421
  241. ori r4,r4,0xA000
  242. mtdcr EBC0_CFGDATA,r4
  243. #endif
  244. #ifdef IDE_USES_ISA_EMULATION
  245. li r25,PB5CR /* PB5CR=Peripheral Bank 5 Configuration Register */
  246. mtdcr EBC0_CFGADDR,r25
  247. lis r4,0x0000
  248. ori r4,r4,0x0000
  249. mtdcr EBC0_CFGDATA,r4
  250. #endif
  251. /*-----------------------------------------------------------------------
  252. * Memory bank 4: USB controller Philips ISP6111
  253. * 0x77C00000 ... 0x77CFFFFF
  254. *
  255. * The chip is connected to:
  256. * - CPU CS#4
  257. * - CPU IRQ#2
  258. * - CPU DMA 3
  259. *
  260. * Timing:
  261. * - command to first data: 300ns. Software must ensure this timing!
  262. * - Write pulse: 26ns
  263. * - Read pulse: 33ns
  264. * - read cycle time: 150ns
  265. * - write cycle time: 140ns
  266. *
  267. * Note: All calculations are based on 33MHz EBC clock. One '#' or '_' is 30ns
  268. *
  269. * |- 300ns --|
  270. * |---- 420ns ---|---- 420ns ---| cycle
  271. * CS ############:###____#######:###____#######
  272. * OE ############:####___#######:####___#######
  273. * WE ############:####__########:####__########
  274. *
  275. * ----> 2 clocks RD/WR pulses: 60ns
  276. * ----> CSN: 3 clock, 90ns
  277. * ----> OEN: 1 clocks (read cycle)
  278. * ----> WBN: 1 clocks (write cycle)
  279. * ----> WBE: 2 clocks
  280. * ----> TH: 7 clock, 210ns
  281. * ----> TWT: 7 clocks
  282. *----------------------------------------------------------------------- */
  283. #ifdef CONFIG_ISP1161_PRESENT
  284. li r4,PB4AP /* PB4AP=Peripheral Bank 4 Access Parameters */
  285. mtdcr EBC0_CFGADDR,r4
  286. lis r4,0x030D
  287. ori r4,r4,0x5E80
  288. mtdcr EBC0_CFGDATA,r4
  289. li r4,PB4CR /* PB2CR=Peripheral Bank 4 Configuration Register */
  290. mtdcr EBC0_CFGADDR,r4
  291. lis r4,0x77C1
  292. ori r4,r4,0xA000
  293. mtdcr EBC0_CFGDATA,r4
  294. #endif
  295. #ifndef IDE_USES_ISA_EMULATION
  296. /*-----------------------------------------------------------------------
  297. * Memory Bank 5 used for IDE access
  298. *
  299. * Timings for IDE Interface
  300. *
  301. * SETUP / LENGTH / HOLD - cycles valid for 33.3 MHz clk -> 30ns cycle time
  302. * 70 165 30 PIO-Mode 0, [ns]
  303. * 3 6 1 [Cycles] ----> AP=0x040C0200
  304. * 50 125 20 PIO-Mode 1, [ns]
  305. * 2 5 1 [Cycles] ----> AP=0x03080200
  306. * 30 100 15 PIO-Mode 2, [ns]
  307. * 1 4 1 [Cycles] ----> AP=0x02040200
  308. * 30 80 10 PIO-Mode 3, [ns]
  309. * 1 3 1 [Cycles] ----> AP=0x01840200
  310. * 25 70 10 PIO-Mode 4, [ns]
  311. * 1 3 1 [Cycles] ----> AP=0x01840200
  312. *
  313. *----------------------------------------------------------------------- */
  314. li r4,PB5AP
  315. mtdcr EBC0_CFGADDR,r4
  316. lis r4,0x040C
  317. ori r4,r4,0x0200
  318. mtdcr EBC0_CFGDATA,r4
  319. li r4,PB5CR /* PB2CR=Peripheral Bank 2 Configuration Register */
  320. mtdcr EBC0_CFGADDR,r4
  321. lis r4,0x7A01
  322. ori r4,r4,0xA000
  323. mtdcr EBC0_CFGDATA,r4
  324. #endif
  325. /*
  326. * External Peripheral Control Register
  327. */
  328. li r4,EBC0_CFG
  329. mtdcr EBC0_CFGADDR,r4
  330. lis r4,0xB84E
  331. ori r4,r4,0xF000
  332. mtdcr EBC0_CFGDATA,r4
  333. /*
  334. * drive POST code
  335. */
  336. lis r4,0x7900
  337. ori r4,r4,0x0080
  338. li r3,0x0001
  339. stb r3,0(r4) /* 01 -> external bus controller is initialized */
  340. nop /* pass2 DCR errata #8 */
  341. blr