You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

324 lines
11 KiB

  1. # board(-config) specfic parameters file.
  2. # set CFG_REFCLKFREQ [configC100 CFG_REFCLKFREQ]
  3. proc config {label} {
  4. return [dict get [configC100] $label ]
  5. }
  6. # show the value for the param. with label
  7. proc showconfig {label} {
  8. puts [format "0x%x" [dict get [configC100] $label ]]
  9. }
  10. # Telo board config
  11. # when there are more then one board config
  12. # use soft links to c100board-config.tcl
  13. # so that only the right board-config gets
  14. # included (just like include/configs/board-configs.h
  15. # in u-boot.
  16. proc configC100 {} {
  17. # xtal freq. 24MHz
  18. dict set configC100 CFG_REFCLKFREQ 24000000
  19. # Amba Clk 165MHz
  20. dict set configC100 CONFIG_SYS_HZ_CLOCK 165000000
  21. dict set configC100 w_amba 1
  22. dict set configC100 x_amba 1
  23. # y = amba_clk * (w+1)*(x+1)*2/xtal_clk
  24. dict set configC100 y_amba [expr ([dict get $configC100 CONFIG_SYS_HZ_CLOCK] * ( ([dict get $configC100 w_amba]+1 ) * ([dict get $configC100 x_amba]+1 ) *2 ) / [dict get $configC100 CFG_REFCLKFREQ]) ]
  25. # Arm Clk 450MHz, must be a multiple of 25 MHz
  26. dict set configC100 CFG_ARM_CLOCK 450000000
  27. dict set configC100 w_arm 0
  28. dict set configC100 x_arm 1
  29. # y = arm_clk * (w+1)*(x+1)*2/xtal_clk
  30. dict set configC100 y_arm [expr ([dict get $configC100 CFG_ARM_CLOCK] * ( ([dict get $configC100 w_arm]+1 ) * ([dict get $configC100 x_arm]+1 ) *2 ) / [dict get $configC100 CFG_REFCLKFREQ]) ]
  31. }
  32. proc setupNOR {} {
  33. puts "Setting up NOR: 16MB, 16-bit wide bus, CS0"
  34. # this is taken from u-boot/boards/mindspeed/ooma-darwin/board.c:nor_hw_init()
  35. set EX_CSEN_REG [regs EX_CSEN_REG ]
  36. set EX_CS0_SEG_REG [regs EX_CS0_SEG_REG ]
  37. set EX_CS0_CFG_REG [regs EX_CS0_CFG_REG ]
  38. set EX_CS0_TMG1_REG [regs EX_CS0_TMG1_REG ]
  39. set EX_CS0_TMG2_REG [regs EX_CS0_TMG2_REG ]
  40. set EX_CS0_TMG3_REG [regs EX_CS0_TMG3_REG ]
  41. set EX_CLOCK_DIV_REG [regs EX_CLOCK_DIV_REG ]
  42. set EX_MFSM_REG [regs EX_MFSM_REG ]
  43. set EX_CSFSM_REG [regs EX_CSFSM_REG ]
  44. set EX_WRFSM_REG [regs EX_WRFSM_REG ]
  45. set EX_RDFSM_REG [regs EX_RDFSM_REG ]
  46. # enable Expansion Bus Clock + CS0 (NOR)
  47. mww $EX_CSEN_REG 0x3
  48. # set the address space for CS0=16MB
  49. mww $EX_CS0_SEG_REG 0x7ff
  50. # set the CS0 bus width to 16-bit
  51. mww $EX_CS0_CFG_REG 0x202
  52. # set timings to NOR
  53. mww $EX_CS0_TMG1_REG 0x03034006
  54. mww $EX_CS0_TMG2_REG 0x04040002
  55. #mww $EX_CS0_TMG3_REG
  56. # set EBUS clock 165/5=33MHz
  57. mww $EX_CLOCK_DIV_REG 0x5
  58. # everthing else is OK with default
  59. }
  60. proc bootNOR {} {
  61. set EXP_CS0_BASEADDR [regs EXP_CS0_BASEADDR]
  62. set BLOCK_RESET_REG [regs BLOCK_RESET_REG]
  63. set DDR_RST [regs DDR_RST]
  64. # put DDR controller in reset (so that it comes reset in u-boot)
  65. mmw $BLOCK_RESET_REG 0x0 $DDR_RST
  66. # setup CS0 controller for NOR
  67. setupNOR
  68. # make sure we are accessing the lower part of NOR
  69. lowGPIO5
  70. # set PC to start of NOR (at boot 0x20000000 = 0x0)
  71. reg pc $EXP_CS0_BASEADDR
  72. # run
  73. resume
  74. }
  75. proc setupGPIO {} {
  76. puts "Setting up GPIO block for Telo"
  77. # This is current setup for Telo (see sch. for details):
  78. #GPIO0 reset for FXS-FXO IC, leave as input, the IC has internal pullup
  79. #GPIO1 irq line for FXS-FXO
  80. #GPIO5 addr22 for NOR flash (access to upper 8MB)
  81. #GPIO17 reset for DECT module.
  82. #GPIO29 CS_n for NAND
  83. set GPIO_OUTPUT_REG [regs GPIO_OUTPUT_REG]
  84. set GPIO_OE_REG [regs GPIO_OE_REG]
  85. # set GPIO29=GPIO17=1, GPIO5=0
  86. mww $GPIO_OUTPUT_REG [expr 1<<29 | 1<<17]
  87. # enable [as output] GPIO29,GPIO17,GPIO5
  88. mww $GPIO_OE_REG [expr 1<<29 | 1<<17 | 1<<5]
  89. }
  90. proc highGPIO5 {} {
  91. puts "GPIO5 high"
  92. set GPIO_OUTPUT_REG [regs GPIO_OUTPUT_REG]
  93. # set GPIO5=1
  94. mmw $GPIO_OUTPUT_REG [expr 1 << 5] 0x0
  95. }
  96. proc lowGPIO5 {} {
  97. puts "GPIO5 low"
  98. set GPIO_OUTPUT_REG [regs GPIO_OUTPUT_REG]
  99. # set GPIO5=0
  100. mmw $GPIO_OUTPUT_REG 0x0 [expr 1 << 5]
  101. }
  102. proc boardID {id} {
  103. # so far built:
  104. # 4'b1111
  105. dict set boardID 15 name "EVT1"
  106. dict set boardID 15 ddr2size 128M
  107. # dict set boardID 15 nandsize 1G
  108. # dict set boardID 15 norsize 16M
  109. # 4'b0000
  110. dict set boardID 0 name "EVT2"
  111. dict set boardID 0 ddr2size 128M
  112. # 4'b0001
  113. dict set boardID 1 name "EVT3"
  114. dict set boardID 1 ddr2size 256M
  115. # 4'b1110
  116. dict set boardID 14 name "EVT3_old"
  117. dict set boardID 14 ddr2size 128M
  118. # 4'b0010
  119. dict set boardID 2 name "EVT4"
  120. dict set boardID 2 ddr2size 256M
  121. return $boardID
  122. }
  123. # converted from u-boot/boards/mindspeed/ooma-darwin/board.c:ooma_board_detect()
  124. # figure out what board revision this is, uses BOOTSTRAP register to read stuffed resistors
  125. proc ooma_board_detect {} {
  126. set GPIO_BOOTSTRAP_REG [regs GPIO_BOOTSTRAP_REG]
  127. # read the current value of the BOOTSRAP pins
  128. set tmp [mrw $GPIO_BOOTSTRAP_REG]
  129. puts [format "GPIO_BOOTSTRAP_REG (0x%x): 0x%x" $GPIO_BOOTSTRAP_REG $tmp]
  130. # extract the GPBP bits
  131. set gpbt [expr ($tmp &0x1C00) >> 10 | ($tmp & 0x40) >>3]
  132. # display board ID
  133. puts [format "This is %s (0x%x)" [dict get [boardID $gpbt] $gpbt name] $gpbt]
  134. # return the ddr2 size, used to configure DDR2 on a given board.
  135. return [dict get [boardID $gpbt] $gpbt ddr2size]
  136. }
  137. proc configureDDR2regs_256M {} {
  138. puts "ConfigureDDR2regs_256M TBD"
  139. }
  140. # converted from u-boot/cpu/arm1136/comcerto/bsp100.c:config_board99()
  141. # The values are computed based on Mindspeed and Nanya datasheets
  142. proc configureDDR2regs_128M {} {
  143. set DENALI_CTL_00_DATA [regs DENALI_CTL_00_DATA]
  144. set DENALI_CTL_01_DATA [regs DENALI_CTL_01_DATA]
  145. set DENALI_CTL_02_DATA [regs DENALI_CTL_02_DATA]
  146. set DENALI_CTL_03_DATA [regs DENALI_CTL_03_DATA]
  147. set DENALI_CTL_04_DATA [regs DENALI_CTL_04_DATA]
  148. set DENALI_CTL_05_DATA [regs DENALI_CTL_05_DATA]
  149. set DENALI_CTL_06_DATA [regs DENALI_CTL_06_DATA]
  150. set DENALI_CTL_07_DATA [regs DENALI_CTL_07_DATA]
  151. set DENALI_CTL_08_DATA [regs DENALI_CTL_08_DATA]
  152. set DENALI_CTL_09_DATA [regs DENALI_CTL_09_DATA]
  153. set DENALI_CTL_10_DATA [regs DENALI_CTL_10_DATA]
  154. set DENALI_CTL_11_DATA [regs DENALI_CTL_11_DATA]
  155. set DENALI_CTL_12_DATA [regs DENALI_CTL_12_DATA]
  156. set DENALI_CTL_13_DATA [regs DENALI_CTL_13_DATA]
  157. set DENALI_CTL_14_DATA [regs DENALI_CTL_14_DATA]
  158. set DENALI_CTL_15_DATA [regs DENALI_CTL_15_DATA]
  159. set DENALI_CTL_16_DATA [regs DENALI_CTL_16_DATA]
  160. set DENALI_CTL_17_DATA [regs DENALI_CTL_17_DATA]
  161. set DENALI_CTL_18_DATA [regs DENALI_CTL_18_DATA]
  162. set DENALI_CTL_19_DATA [regs DENALI_CTL_19_DATA]
  163. set DENALI_CTL_20_DATA [regs DENALI_CTL_20_DATA]
  164. set DENALI_CTL_02_VAL 0x0100010000010100
  165. set DENALI_CTL_11_VAL 0x433A42124A650A37
  166. # set some default values
  167. mw64bit $DENALI_CTL_00_DATA 0x0100000101010101
  168. mw64bit $DENALI_CTL_01_DATA 0x0100000100000101
  169. mw64bit $DENALI_CTL_02_DATA $DENALI_CTL_02_VAL
  170. mw64bit $DENALI_CTL_03_DATA 0x0102020202020201
  171. mw64bit $DENALI_CTL_04_DATA 0x0201010100000201
  172. mw64bit $DENALI_CTL_05_DATA 0x0203010300010101
  173. mw64bit $DENALI_CTL_06_DATA 0x050A020200020202
  174. mw64bit $DENALI_CTL_07_DATA 0x000000030E0B0205
  175. mw64bit $DENALI_CTL_08_DATA 0x6427003F3F0A0209
  176. mw64bit $DENALI_CTL_09_DATA 0x1A00002F00001A00
  177. mw64bit $DENALI_CTL_10_DATA 0x01202020201A1A1A
  178. mw64bit $DENALI_CTL_11_DATA $DENALI_CTL_11_VAL
  179. mw64bit $DENALI_CTL_12_DATA 0x0000080000000800
  180. mw64bit $DENALI_CTL_13_DATA 0x0010002000100040
  181. mw64bit $DENALI_CTL_14_DATA 0x0010004000100040
  182. mw64bit $DENALI_CTL_15_DATA 0x0508000000000000
  183. mw64bit $DENALI_CTL_16_DATA 0x000020472D200000
  184. mw64bit $DENALI_CTL_17_DATA 0x0000000008000000
  185. mw64bit $DENALI_CTL_18_DATA 0x0302000000000000
  186. mw64bit $DENALI_CTL_19_DATA 0x00001400C8030604
  187. mw64bit $DENALI_CTL_20_DATA 0x00000000823600C8
  188. set wr_dqs_shift 0x40
  189. # start DDRC
  190. mw64bit $DENALI_CTL_02_DATA [expr $DENALI_CTL_02_VAL | (1 << 32)]
  191. # wait int_status[2] (DRAM init complete)
  192. puts -nonewline "Waiting for DDR2 controller to init..."
  193. set tmp [mrw [expr $DENALI_CTL_08_DATA + 4]]
  194. while { [expr $tmp & 0x040000] == 0 } {
  195. sleep 1
  196. set tmp [mrw [expr $DENALI_CTL_08_DATA + 4]]
  197. }
  198. mw64bit $DENALI_CTL_11_DATA [expr ($DENALI_CTL_11_VAL & ~0x00007F0000000000) | ($wr_dqs_shift << 40) ]
  199. puts "done."
  200. # do ddr2 training sequence
  201. # TBD (for now, if you need it, run trainDDR command)
  202. }
  203. proc setupUART0 {} {
  204. # configure UART0 to 115200, 8N1
  205. set GPIO_LOCK_REG [regs GPIO_LOCK_REG]
  206. set GPIO_IOCTRL_REG [regs GPIO_IOCTRL_REG]
  207. set GPIO_IOCTRL_VAL [regs GPIO_IOCTRL_VAL]
  208. set GPIO_IOCTRL_UART0 [regs GPIO_IOCTRL_UART0]
  209. set UART0_LCR [regs UART0_LCR]
  210. set LCR_DLAB [regs LCR_DLAB]
  211. set UART0_DLL [regs UART0_DLL]
  212. set UART0_DLH [regs UART0_DLH]
  213. set UART0_IIR [regs UART0_IIR]
  214. set UART0_IER [regs UART0_IER]
  215. set LCR_ONE_STOP [regs LCR_ONE_STOP]
  216. set LCR_CHAR_LEN_8 [regs LCR_CHAR_LEN_8]
  217. set FCR_XMITRES [regs FCR_XMITRES]
  218. set FCR_RCVRRES [regs FCR_RCVRRES]
  219. set FCR_FIFOEN [regs FCR_FIFOEN]
  220. set IER_UUE [regs IER_UUE]
  221. # unlock writing to IOCTRL register
  222. mww $GPIO_LOCK_REG $GPIO_IOCTRL_VAL
  223. # enable UART0
  224. mmw $GPIO_IOCTRL_REG $GPIO_IOCTRL_UART0 0x0
  225. # baudrate 115200
  226. # This should really be amba_clk/(16*115200) but amba_clk=165MHz
  227. set tmp 89
  228. # Enable Divisor Latch access
  229. mmw $UART0_LCR $LCR_DLAB 0x0
  230. # set the divisor to $tmp
  231. mww $UART0_DLL [expr $tmp & 0xff]
  232. mww $UART0_DLH [expr $tmp >> 8]
  233. # Disable Divisor Latch access
  234. mmw $UART0_LCR 0x0 $LCR_DLAB
  235. # set the UART to 8N1
  236. mmw $UART0_LCR [expr $LCR_ONE_STOP | $LCR_CHAR_LEN_8 ] 0x0
  237. # reset FIFO
  238. mmw $UART0_IIR [expr $FCR_XMITRES | $FCR_RCVRRES | $FCR_FIFOEN ] 0x0
  239. # enable FFUART
  240. mww $UART0_IER $IER_UUE
  241. }
  242. proc putcUART0 {char} {
  243. set UART0_LSR [regs UART0_LSR]
  244. set UART0_THR [regs UART0_THR]
  245. set LSR_TEMT [regs LSR_TEMT]
  246. # convert the 'char' to digit
  247. set tmp [ scan $char %c ]
  248. # /* wait for room in the tx FIFO on FFUART */
  249. while {[expr [mrw $UART0_LSR] & $LSR_TEMT] == 0} { sleep 1 }
  250. mww $UART0_THR $tmp
  251. if { $char == "\n" } { putcUART0 \r }
  252. }
  253. proc putsUART0 {str} {
  254. set index 0
  255. set len [string length $str]
  256. while { $index < $len } {
  257. putcUART0 [string index $str $index]
  258. set index [expr $index + 1]
  259. }
  260. }
  261. proc trainDDR2 {} {
  262. set ARAM_BASEADDR [regs ARAM_BASEADDR]
  263. # you must have run 'reset init' or u-boot
  264. # load the training code to ARAM
  265. load_image ./images/ddr2train.bin $ARAM_BASEADDR bin
  266. # set PC to start of NOR (at boot 0x20000000 = 0x0)
  267. reg pc $ARAM_BASEADDR
  268. # run
  269. resume
  270. }
  271. proc flashUBOOT {} {
  272. # this will update uboot on NOR partition
  273. set EXP_CS0_BASEADDR [regs EXP_CS0_BASEADDR]
  274. # setup CS0 controller for NOR
  275. setupNOR
  276. # make sure we are accessing the lower part of NOR
  277. lowGPIO5
  278. flash probe 0
  279. puts "Erasing sectors 0-3 for uboot"
  280. flash erase_sector 0 0 3
  281. puts "Programming u-boot, takes about 4-5 min for 256kb"
  282. flash write_image ./images/u-boot.bin $EXP_CS0_BASEADDR
  283. }