init.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. /* 0000 1000 0xxx 0000 0000 0010 100x xxxx = 0x03800280 */
  70. ori r25,r25,0x0280
  71. /*
  72. * Second, create a fast timing:
  73. * 90ns first cycle - 3 clock access
  74. * and 90ns burst cycle, plus 1 clock after the last access
  75. * This is used for the internal access
  76. */
  77. lis r26,0x8900
  78. /* 1000 1001 0xxx 0000 0000 0010 100x xxxx */
  79. ori r26,r26,0x0280
  80. /*
  81. * We can't change settings on CS# if we currently use them.
  82. * -> load a few instructions into cache and run this code from cache
  83. */
  84. mflr r4 /* save link register */
  85. bl ..getAddr
  86. ..getAddr:
  87. mflr r3 /* get address of ..getAddr */
  88. mtlr r4 /* restore link register */
  89. addi r4,0,14 /* set ctr to 10; used to prefetch */
  90. mtctr r4 /* 10 cache lines to fit this function
  91. in cache (gives us 8x10=80 instructions) */
  92. ..ebcloop:
  93. icbt r0,r3 /* prefetch cache line for addr in r3 */
  94. addi r3,r3,32 /* move to next cache line */
  95. bdnz ..ebcloop /* continue for 10 cache lines */
  96. /*
  97. * Delay to ensure all accesses to ROM are complete before changing
  98. * bank 0 timings. 200usec should be enough.
  99. * 200,000,000 (cycles/sec) X .000200 (sec) = 0x9C40 cycles
  100. */
  101. lis r3,0x0
  102. ori r3,r3,0xA000 /* ensure 200usec have passed since reset */
  103. mtctr r3
  104. ..spinlp:
  105. bdnz ..spinlp /* spin loop */
  106. /*-----------------------------------------------------------------------
  107. * Memory Bank 0 (BOOT-ROM) initialization
  108. * 0xFFEF00000....0xFFFFFFF
  109. * We only have to change the timing. Mapping is ok by boot-strapping
  110. *----------------------------------------------------------------------- */
  111. li r4,PB1AP /* PB0AP=Peripheral Bank 0 Access Parameters */
  112. mtdcr EBC0_CFGADDR,r4
  113. mr r4,r26 /* assume internal fast flash is boot flash */
  114. cmpwi r24,0x2000 /* assumption true? ... */
  115. beq 1f /* ...yes! */
  116. mr r4,r25 /* ...no, use the slow variant */
  117. mr r25,r26 /* use this for the other flash */
  118. 1:
  119. mtdcr EBC0_CFGDATA,r4 /* change timing now */
  120. li r4,PB0CR /* PB0CR=Peripheral Bank 0 Control Register */
  121. mtdcr EBC0_CFGADDR,r4
  122. mfdcr r4,EBC0_CFGDATA
  123. lis r3,0x0001
  124. ori r3,r3,0x8000 /* allow reads and writes */
  125. or r4,r4,r3
  126. mtdcr EBC0_CFGDATA,r4
  127. /*-----------------------------------------------------------------------
  128. * Memory Bank 3 (Second-Flash) initialization
  129. * 0xF0000000...0xF01FFFFF -> 2MB
  130. *----------------------------------------------------------------------- */
  131. li r4,PB3AP /* Peripheral Bank 1 Access Parameter */
  132. mtdcr EBC0_CFGADDR,r4
  133. mtdcr EBC0_CFGDATA,r2 /* change timing */
  134. li r4,PB3CR /* Peripheral Bank 1 Configuration Registers */
  135. mtdcr EBC0_CFGADDR,r4
  136. lis r4,0xF003
  137. ori r4,r4,0x8000
  138. /*
  139. * Consider boot configuration
  140. */
  141. xori r24,r24,0x2000 /* invert current bus width */
  142. or r4,r4,r24
  143. mtdcr EBC0_CFGDATA,r4
  144. /*-----------------------------------------------------------------------
  145. * Memory Bank 1 (NAND-Flash) initialization
  146. * 0x77D00000...0x77DFFFFF -> 1MB
  147. * - the write/read pulse to the NAND can be as short as 25ns, bus the cycle time is always 50ns
  148. * - the setup time is 0ns
  149. * - the hold time is 15ns
  150. * ->
  151. * - TWT = 0
  152. * - CSN = 0
  153. * - OEN = 0
  154. * - WBN = 0
  155. * - WBF = 0
  156. * - TH = 1
  157. * ----> 2 clocks per cycle = 60ns cycle (30ns active, 30ns hold)
  158. *----------------------------------------------------------------------- */
  159. li r4,PB1AP /* Peripheral Bank 1 Access Parameter */
  160. mtdcr EBC0_CFGADDR,r4
  161. lis r4,0x0000
  162. ori r4,r4,0x0200
  163. mtdcr EBC0_CFGDATA,r4
  164. li r4,PB1CR /* Peripheral Bank 1 Configuration Registers */
  165. mtdcr EBC0_CFGADDR,r4
  166. lis r4,0x77D1
  167. ori r4,r4,0x8000
  168. mtdcr EBC0_CFGDATA,r4
  169. /* USB init (without acceleration) */
  170. #ifndef CONFIG_ISP1161_PRESENT
  171. li r4,PB4AP /* PB4AP=Peripheral Bank 4 Access Parameters */
  172. mtdcr EBC0_CFGADDR,r4
  173. lis r4,0x0180
  174. ori r4,r4,0x5940
  175. mtdcr EBC0_CFGDATA,r4
  176. #endif
  177. /*-----------------------------------------------------------------------
  178. * Memory Bank 2 (ISA Access) initialization (plus memory bank 6 and 7)
  179. * 0x78000000...0x7BFFFFFF -> 64 MB
  180. * Wir arbeiten bei 33 MHz -> 30ns
  181. *-----------------------------------------------------------------------
  182. A7 (ppc notation) or A24 (standard notation) decides about
  183. the type of access:
  184. A7/A24=0 -> memory cycle
  185. A7/ /A24=1 -> I/O cycle
  186. */
  187. li r4,PB2AP /* PB2AP=Peripheral Bank 2 Access Parameters */
  188. mtdcr EBC0_CFGADDR,r4
  189. /*
  190. We emulate an ISA access
  191. 1. Address active
  192. 2. wait 0 EBC clocks -> CSN=0
  193. 3. set CS#
  194. 4. wait 0 EBC clock -> OEN/WBN=0
  195. 5. set OE#/WE#
  196. 6. wait 4 clocks (ca. 90ns) and for Ready signal
  197. 7. hold for 4 clocks -> TH=4
  198. */
  199. #if 1
  200. /* faster access to isa-bus */
  201. lis r4,0x0180
  202. ori r4,r4,0x5940
  203. #else
  204. lis r4,0x0100
  205. ori r4,r4,0x0340
  206. #endif
  207. mtdcr EBC0_CFGDATA,r4
  208. #ifdef IDE_USES_ISA_EMULATION
  209. li r25,PB5AP /* PB5AP=Peripheral Bank 5 Access Parameters */
  210. mtdcr EBC0_CFGADDR,r25
  211. mtdcr EBC0_CFGDATA,r4
  212. #endif
  213. li r25,PB6AP /* PB6AP=Peripheral Bank 6 Access Parameters */
  214. mtdcr EBC0_CFGADDR,r25
  215. mtdcr EBC0_CFGDATA,r4
  216. li r25,PB7AP /* PB7AP=Peripheral Bank 7 Access Parameters */
  217. mtdcr EBC0_CFGADDR,r25
  218. mtdcr EBC0_CFGDATA,r4
  219. li r25,PB2CR /* PB2CR=Peripheral Bank 2 Configuration Register */
  220. mtdcr EBC0_CFGADDR,r25
  221. lis r4,0x780B
  222. ori r4,r4,0xA000
  223. mtdcr EBC0_CFGDATA,r4
  224. /*
  225. * the other areas are only 1MiB in size
  226. */
  227. lis r4,0x7401
  228. ori r4,r4,0xA000
  229. li r25,PB6CR /* PB6CR=Peripheral Bank 6 Configuration Register */
  230. mtdcr EBC0_CFGADDR,r25
  231. lis r4,0x7401
  232. ori r4,r4,0xA000
  233. mtdcr EBC0_CFGDATA,r4
  234. li r25,PB7CR /* PB7CR=Peripheral Bank 7 Configuration Register */
  235. mtdcr EBC0_CFGADDR,r25
  236. lis r4,0x7411
  237. ori r4,r4,0xA000
  238. mtdcr EBC0_CFGDATA,r4
  239. #ifndef CONFIG_ISP1161_PRESENT
  240. li r25,PB4CR /* PB4CR=Peripheral Bank 4 Configuration Register */
  241. mtdcr EBC0_CFGADDR,r25
  242. lis r4,0x7421
  243. ori r4,r4,0xA000
  244. mtdcr EBC0_CFGDATA,r4
  245. #endif
  246. #ifdef IDE_USES_ISA_EMULATION
  247. li r25,PB5CR /* PB5CR=Peripheral Bank 5 Configuration Register */
  248. mtdcr EBC0_CFGADDR,r25
  249. lis r4,0x0000
  250. ori r4,r4,0x0000
  251. mtdcr EBC0_CFGDATA,r4
  252. #endif
  253. /*-----------------------------------------------------------------------
  254. * Memory bank 4: USB controller Philips ISP6111
  255. * 0x77C00000 ... 0x77CFFFFF
  256. *
  257. * The chip is connected to:
  258. * - CPU CS#4
  259. * - CPU IRQ#2
  260. * - CPU DMA 3
  261. *
  262. * Timing:
  263. * - command to first data: 300ns. Software must ensure this timing!
  264. * - Write pulse: 26ns
  265. * - Read pulse: 33ns
  266. * - read cycle time: 150ns
  267. * - write cycle time: 140ns
  268. *
  269. * Note: All calculations are based on 33MHz EBC clock. One '#' or '_' is 30ns
  270. *
  271. * |- 300ns --|
  272. * |---- 420ns ---|---- 420ns ---| cycle
  273. * CS ############:###____#######:###____#######
  274. * OE ############:####___#######:####___#######
  275. * WE ############:####__########:####__########
  276. *
  277. * ----> 2 clocks RD/WR pulses: 60ns
  278. * ----> CSN: 3 clock, 90ns
  279. * ----> OEN: 1 clocks (read cycle)
  280. * ----> WBN: 1 clocks (write cycle)
  281. * ----> WBE: 2 clocks
  282. * ----> TH: 7 clock, 210ns
  283. * ----> TWT: 7 clocks
  284. *----------------------------------------------------------------------- */
  285. #ifdef CONFIG_ISP1161_PRESENT
  286. li r4,PB4AP /* PB4AP=Peripheral Bank 4 Access Parameters */
  287. mtdcr EBC0_CFGADDR,r4
  288. lis r4,0x030D
  289. ori r4,r4,0x5E80
  290. mtdcr EBC0_CFGDATA,r4
  291. li r4,PB4CR /* PB2CR=Peripheral Bank 4 Configuration Register */
  292. mtdcr EBC0_CFGADDR,r4
  293. lis r4,0x77C1
  294. ori r4,r4,0xA000
  295. mtdcr EBC0_CFGDATA,r4
  296. #endif
  297. #ifndef IDE_USES_ISA_EMULATION
  298. /*-----------------------------------------------------------------------
  299. * Memory Bank 5 used for IDE access
  300. *
  301. * Timings for IDE Interface
  302. *
  303. * SETUP / LENGTH / HOLD - cycles valid for 33.3 MHz clk -> 30ns cycle time
  304. * 70 165 30 PIO-Mode 0, [ns]
  305. * 3 6 1 [Cycles] ----> AP=0x040C0200
  306. * 50 125 20 PIO-Mode 1, [ns]
  307. * 2 5 1 [Cycles] ----> AP=0x03080200
  308. * 30 100 15 PIO-Mode 2, [ns]
  309. * 1 4 1 [Cycles] ----> AP=0x02040200
  310. * 30 80 10 PIO-Mode 3, [ns]
  311. * 1 3 1 [Cycles] ----> AP=0x01840200
  312. * 25 70 10 PIO-Mode 4, [ns]
  313. * 1 3 1 [Cycles] ----> AP=0x01840200
  314. *
  315. *----------------------------------------------------------------------- */
  316. li r4,PB5AP
  317. mtdcr EBC0_CFGADDR,r4
  318. lis r4,0x040C
  319. ori r4,r4,0x0200
  320. mtdcr EBC0_CFGDATA,r4
  321. li r4,PB5CR /* PB2CR=Peripheral Bank 2 Configuration Register */
  322. mtdcr EBC0_CFGADDR,r4
  323. lis r4,0x7A01
  324. ori r4,r4,0xA000
  325. mtdcr EBC0_CFGDATA,r4
  326. #endif
  327. /*
  328. * External Peripheral Control Register
  329. */
  330. li r4,EBC0_CFG
  331. mtdcr EBC0_CFGADDR,r4
  332. lis r4,0xB84E
  333. ori r4,r4,0xF000
  334. mtdcr EBC0_CFGDATA,r4
  335. /*
  336. * drive POST code
  337. */
  338. lis r4,0x7900
  339. ori r4,r4,0x0080
  340. li r3,0x0001
  341. stb r3,0(r4) /* 01 -> external bus controller is initialized */
  342. nop /* pass2 DCR errata #8 */
  343. blr