init.S 11 KB

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