lowlevel_init.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * lowlevel_init.S - basic hardware initialization for the KS8695 CPU
  3. *
  4. * Copyright (c) 2004-2005, Greg Ungerer <greg.ungerer@opengear.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <config.h>
  25. #include <version.h>
  26. #include <asm/arch/platform.h>
  27. #ifndef CONFIG_SKIP_LOWLEVEL_INIT
  28. /*
  29. *************************************************************************
  30. *
  31. * Handy dandy macros
  32. *
  33. *************************************************************************
  34. */
  35. /* Delay a bit */
  36. .macro DELAY_FOR cycles, reg0
  37. ldr \reg0, =\cycles
  38. subs \reg0, \reg0, #1
  39. subne pc, pc, #0xc
  40. .endm
  41. /*
  42. *************************************************************************
  43. *
  44. * Some local storage.
  45. *
  46. *************************************************************************
  47. */
  48. /* Should we boot with an interactive console or not */
  49. .globl serial_console
  50. /*
  51. *************************************************************************
  52. *
  53. * Raw hardware initialization code. The important thing is to get
  54. * SDRAM setup and running. We do some other basic things here too,
  55. * like getting the PLL set for high speed, and init the LEDs.
  56. *
  57. *************************************************************************
  58. */
  59. .globl lowlevel_init
  60. lowlevel_init:
  61. #if DEBUG
  62. /*
  63. * enable UART for early debug trace
  64. */
  65. ldr r1, =(KS8695_IO_BASE+KS8695_UART_DIVISOR)
  66. mov r2, #0xd9
  67. str r2, [r1] /* 115200 baud */
  68. ldr r1, =(KS8695_IO_BASE+KS8695_UART_LINE_CTRL)
  69. mov r2, #0x03
  70. str r2, [r1] /* 8 data bits, no parity, 1 stop */
  71. ldr r1, =(KS8695_IO_BASE+KS8695_UART_TX_HOLDING)
  72. mov r2, #0x41
  73. str r2, [r1] /* write 'A' */
  74. #endif
  75. #if DEBUG
  76. ldr r1, =(KS8695_IO_BASE+KS8695_UART_TX_HOLDING)
  77. mov r2, #0x42
  78. str r2, [r1]
  79. #endif
  80. /*
  81. * remap the memory and flash regions. we want to end up with
  82. * ram from address 0, and flash at 32MB.
  83. */
  84. ldr r1, =(KS8695_IO_BASE+KS8695_MEM_CTRL0)
  85. ldr r2, =0xbfc00040
  86. str r2, [r1] /* large flash map */
  87. ldr pc, =(highflash+0x02000000-0x00f00000) /* jump to high flash address */
  88. highflash:
  89. ldr r2, =0x8fe00040
  90. str r2, [r1] /* remap flash range */
  91. /*
  92. * remap the second select region to the 4MB immediately after
  93. * the first region. This way if you have a larger flash (say 8Mb)
  94. * then you can have it all mapped nicely. Has no effect if you
  95. * only have a 4Mb or smaller flash.
  96. */
  97. ldr r1, =(KS8695_IO_BASE+KS8695_MEM_CTRL1)
  98. ldr r2, =0x9fe40040
  99. str r2, [r1] /* remap flash2 region, contiguous */
  100. ldr r1, =(KS8695_IO_BASE+KS8695_MEM_GENERAL)
  101. ldr r2, =0x30000005
  102. str r2, [r1] /* enable both flash selects */
  103. #ifdef CONFIG_CM41xx
  104. /*
  105. * map the second flash chip, using the external IO lines.
  106. */
  107. ldr r1, =(KS8695_IO_BASE+KS8695_IO_CTRL0)
  108. ldr r2, =0xafe80b6d
  109. str r2, [r1] /* remap io0 region, contiguous */
  110. ldr r1, =(KS8695_IO_BASE+KS8695_IO_CTRL1)
  111. ldr r2, =0xbfec0b6d
  112. str r2, [r1] /* remap io1 region, contiguous */
  113. ldr r1, =(KS8695_IO_BASE+KS8695_MEM_GENERAL)
  114. ldr r2, =0x30050005
  115. str r2, [r1] /* enable second flash */
  116. #endif
  117. /*
  118. * before relocating, we have to setup RAM timing
  119. */
  120. ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_CTRL0)
  121. #if (PHYS_SDRAM_1_SIZE == 0x02000000)
  122. ldr r2, =0x7fc0000e /* 32MB */
  123. #else
  124. ldr r2, =0x3fc0000e /* 16MB */
  125. #endif
  126. str r2, [r1] /* configure sdram bank0 setup */
  127. ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_CTRL1)
  128. mov r2, #0
  129. str r2, [r1] /* configure sdram bank1 setup */
  130. ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_GENERAL)
  131. ldr r2, =0x0000000a
  132. str r2, [r1] /* set RAS/CAS timing */
  133. ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_BUFFER)
  134. ldr r2, =0x00030000
  135. str r2, [r1] /* send NOP command */
  136. DELAY_FOR 0x100, r0
  137. ldr r2, =0x00010000
  138. str r2, [r1] /* send PRECHARGE-ALL */
  139. DELAY_FOR 0x100, r0
  140. ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_REFRESH)
  141. ldr r2, =0x00000020
  142. str r2, [r1] /* set for fast refresh */
  143. DELAY_FOR 0x100, r0
  144. ldr r2, =0x00000190
  145. str r2, [r1] /* set normal refresh timing */
  146. ldr r1, =(KS8695_IO_BASE+KS8695_SDRAM_BUFFER)
  147. ldr r2, =0x00020033
  148. str r2, [r1] /* send mode command */
  149. DELAY_FOR 0x100, r0
  150. ldr r2, =0x01f00000
  151. str r2, [r1] /* enable sdram fifos */
  152. /*
  153. * set pll to top speed
  154. */
  155. ldr r1, =(KS8695_IO_BASE+KS8695_SYSTEN_BUS_CLOCK)
  156. mov r2, #0
  157. str r2, [r1] /* set pll clock to 166MHz */
  158. ldr r1, =(KS8695_IO_BASE+KS8695_SWITCH_CTRL0)
  159. ldr r2, [r1] /* Get switch ctrl0 register */
  160. and r2, r2, #0x0fc00000 /* Mask out LED control bits */
  161. orr r2, r2, #0x01800000 /* Set Link/activity/speed actions */
  162. str r2, [r1]
  163. #ifdef CONFIG_CM4008
  164. ldr r1, =(KS8695_IO_BASE+KS8695_GPIO_MODE)
  165. ldr r2, =0x0000fe30
  166. str r2, [r1] /* enable LED's as outputs */
  167. ldr r1, =(KS8695_IO_BASE+KS8695_GPIO_DATA)
  168. ldr r2, =0x0000fe20
  169. str r2, [r1] /* turn on power LED */
  170. #endif
  171. #if defined(CONFIG_CM4008) || defined(CONFIG_CM41xx)
  172. ldr r2, [r1] /* get current GPIO input data */
  173. tst r2, #0x8 /* check if "erase" depressed */
  174. beq nobutton
  175. mov r2, #0 /* be quiet on boot, no console */
  176. ldr r1, =serial_console
  177. str r2, [r1]
  178. nobutton:
  179. #endif
  180. add lr, lr, #0x02000000 /* flash is now mapped high */
  181. add ip, ip, #0x02000000 /* this is a hack */
  182. mov pc, lr /* all done, return */
  183. #endif /* CONFIG_SKIP_LOWLEVEL_INIT */