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.
 
 
 
 
 
 

412 lines
14 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. # This should be called for reset init event handler
  33. proc setupTelo {} {
  34. # setup GPIO used as control signals for C100
  35. setupGPIO
  36. # This will allow acces to lower 8MB or NOR
  37. lowGPIO5
  38. # setup NOR size,timing,etc.
  39. setupNOR
  40. # setup internals + PLL + DDR2
  41. initC100
  42. }
  43. proc setupNOR {} {
  44. puts "Setting up NOR: 16MB, 16-bit wide bus, CS0"
  45. # this is taken from u-boot/boards/mindspeed/ooma-darwin/board.c:nor_hw_init()
  46. set EX_CSEN_REG [regs EX_CSEN_REG ]
  47. set EX_CS0_SEG_REG [regs EX_CS0_SEG_REG ]
  48. set EX_CS0_CFG_REG [regs EX_CS0_CFG_REG ]
  49. set EX_CS0_TMG1_REG [regs EX_CS0_TMG1_REG ]
  50. set EX_CS0_TMG2_REG [regs EX_CS0_TMG2_REG ]
  51. set EX_CS0_TMG3_REG [regs EX_CS0_TMG3_REG ]
  52. set EX_CLOCK_DIV_REG [regs EX_CLOCK_DIV_REG ]
  53. set EX_MFSM_REG [regs EX_MFSM_REG ]
  54. set EX_CSFSM_REG [regs EX_CSFSM_REG ]
  55. set EX_WRFSM_REG [regs EX_WRFSM_REG ]
  56. set EX_RDFSM_REG [regs EX_RDFSM_REG ]
  57. # enable Expansion Bus Clock + CS0 (NOR)
  58. mww $EX_CSEN_REG 0x3
  59. # set the address space for CS0=16MB
  60. mww $EX_CS0_SEG_REG 0x7ff
  61. # set the CS0 bus width to 16-bit
  62. mww $EX_CS0_CFG_REG 0x202
  63. # set timings to NOR
  64. mww $EX_CS0_TMG1_REG 0x03034006
  65. mww $EX_CS0_TMG2_REG 0x04040002
  66. #mww $EX_CS0_TMG3_REG
  67. # set EBUS clock 165/5=33MHz
  68. mww $EX_CLOCK_DIV_REG 0x5
  69. # everthing else is OK with default
  70. }
  71. proc bootNOR {} {
  72. set EXP_CS0_BASEADDR [regs EXP_CS0_BASEADDR]
  73. set BLOCK_RESET_REG [regs BLOCK_RESET_REG]
  74. set DDR_RST [regs DDR_RST]
  75. # put DDR controller in reset (so that it comes reset in u-boot)
  76. mmw $BLOCK_RESET_REG 0x0 $DDR_RST
  77. # setup CS0 controller for NOR
  78. setupNOR
  79. # make sure we are accessing the lower part of NOR
  80. lowGPIO5
  81. # set PC to start of NOR (at boot 0x20000000 = 0x0)
  82. reg pc $EXP_CS0_BASEADDR
  83. # run
  84. resume
  85. }
  86. proc setupGPIO {} {
  87. puts "Setting up GPIO block for Telo"
  88. # This is current setup for Telo (see sch. for details):
  89. #GPIO0 reset for FXS-FXO IC, leave as input, the IC has internal pullup
  90. #GPIO1 irq line for FXS-FXO
  91. #GPIO5 addr22 for NOR flash (access to upper 8MB)
  92. #GPIO17 reset for DECT module.
  93. #GPIO29 CS_n for NAND
  94. set GPIO_OUTPUT_REG [regs GPIO_OUTPUT_REG]
  95. set GPIO_OE_REG [regs GPIO_OE_REG]
  96. # set GPIO29=GPIO17=1, GPIO5=0
  97. mww $GPIO_OUTPUT_REG [expr 1<<29 | 1<<17]
  98. # enable [as output] GPIO29,GPIO17,GPIO5
  99. mww $GPIO_OE_REG [expr 1<<29 | 1<<17 | 1<<5]
  100. }
  101. proc highGPIO5 {} {
  102. puts "GPIO5 high"
  103. set GPIO_OUTPUT_REG [regs GPIO_OUTPUT_REG]
  104. # set GPIO5=1
  105. mmw $GPIO_OUTPUT_REG [expr 1 << 5] 0x0
  106. }
  107. proc lowGPIO5 {} {
  108. puts "GPIO5 low"
  109. set GPIO_OUTPUT_REG [regs GPIO_OUTPUT_REG]
  110. # set GPIO5=0
  111. mmw $GPIO_OUTPUT_REG 0x0 [expr 1 << 5]
  112. }
  113. proc boardID {id} {
  114. # so far built:
  115. # 4'b1111
  116. dict set boardID 15 name "EVT1"
  117. dict set boardID 15 ddr2size 128M
  118. # dict set boardID 15 nandsize 1G
  119. # dict set boardID 15 norsize 16M
  120. # 4'b0000
  121. dict set boardID 0 name "EVT2"
  122. dict set boardID 0 ddr2size 128M
  123. # 4'b0001
  124. dict set boardID 1 name "EVT3"
  125. dict set boardID 1 ddr2size 256M
  126. # 4'b1110
  127. dict set boardID 14 name "EVT3_old"
  128. dict set boardID 14 ddr2size 128M
  129. # 4'b0010
  130. dict set boardID 2 name "EVT4"
  131. dict set boardID 2 ddr2size 256M
  132. return $boardID
  133. }
  134. # converted from u-boot/boards/mindspeed/ooma-darwin/board.c:ooma_board_detect()
  135. # figure out what board revision this is, uses BOOTSTRAP register to read stuffed resistors
  136. proc ooma_board_detect {} {
  137. set GPIO_BOOTSTRAP_REG [regs GPIO_BOOTSTRAP_REG]
  138. # read the current value of the BOOTSRAP pins
  139. set tmp [mrw $GPIO_BOOTSTRAP_REG]
  140. puts [format "GPIO_BOOTSTRAP_REG (0x%x): 0x%x" $GPIO_BOOTSTRAP_REG $tmp]
  141. # extract the GPBP bits
  142. set gpbt [expr ($tmp &0x1C00) >> 10 | ($tmp & 0x40) >>3]
  143. # display board ID
  144. puts [format "This is %s (0x%x)" [dict get [boardID $gpbt] $gpbt name] $gpbt]
  145. # show it on serial console
  146. putsUART0 [format "This is %s (0x%x)\n" [dict get [boardID $gpbt] $gpbt name] $gpbt]
  147. # return the ddr2 size, used to configure DDR2 on a given board.
  148. return [dict get [boardID $gpbt] $gpbt ddr2size]
  149. }
  150. proc configureDDR2regs_256M {} {
  151. set DENALI_CTL_00_DATA [regs DENALI_CTL_00_DATA]
  152. set DENALI_CTL_01_DATA [regs DENALI_CTL_01_DATA]
  153. set DENALI_CTL_02_DATA [regs DENALI_CTL_02_DATA]
  154. set DENALI_CTL_03_DATA [regs DENALI_CTL_03_DATA]
  155. set DENALI_CTL_04_DATA [regs DENALI_CTL_04_DATA]
  156. set DENALI_CTL_05_DATA [regs DENALI_CTL_05_DATA]
  157. set DENALI_CTL_06_DATA [regs DENALI_CTL_06_DATA]
  158. set DENALI_CTL_07_DATA [regs DENALI_CTL_07_DATA]
  159. set DENALI_CTL_08_DATA [regs DENALI_CTL_08_DATA]
  160. set DENALI_CTL_09_DATA [regs DENALI_CTL_09_DATA]
  161. set DENALI_CTL_10_DATA [regs DENALI_CTL_10_DATA]
  162. set DENALI_CTL_11_DATA [regs DENALI_CTL_11_DATA]
  163. set DENALI_CTL_12_DATA [regs DENALI_CTL_12_DATA]
  164. set DENALI_CTL_13_DATA [regs DENALI_CTL_13_DATA]
  165. set DENALI_CTL_14_DATA [regs DENALI_CTL_14_DATA]
  166. set DENALI_CTL_15_DATA [regs DENALI_CTL_15_DATA]
  167. set DENALI_CTL_16_DATA [regs DENALI_CTL_16_DATA]
  168. set DENALI_CTL_17_DATA [regs DENALI_CTL_17_DATA]
  169. set DENALI_CTL_18_DATA [regs DENALI_CTL_18_DATA]
  170. set DENALI_CTL_19_DATA [regs DENALI_CTL_19_DATA]
  171. set DENALI_CTL_20_DATA [regs DENALI_CTL_20_DATA]
  172. set DENALI_CTL_02_VAL 0x0100000000010100
  173. set DENALI_CTL_11_VAL 0x433a32164a560a00
  174. mw64bit $DENALI_CTL_00_DATA 0x0100000101010101
  175. # 01_DATA mod [40]=1, enable BA2
  176. mw64bit $DENALI_CTL_01_DATA 0x0100010100000001
  177. mw64bit $DENALI_CTL_02_DATA $DENALI_CTL_02_VAL
  178. mw64bit $DENALI_CTL_03_DATA 0x0102020202020201
  179. mw64bit $DENALI_CTL_04_DATA 0x0000010100000001
  180. mw64bit $DENALI_CTL_05_DATA 0x0203010300010101
  181. mw64bit $DENALI_CTL_06_DATA 0x060a020200020202
  182. mw64bit $DENALI_CTL_07_DATA 0x0000000300000206
  183. mw64bit $DENALI_CTL_08_DATA 0x6400003f3f0a0209
  184. mw64bit $DENALI_CTL_09_DATA 0x1a000000001a1a1a
  185. mw64bit $DENALI_CTL_10_DATA 0x0120202020191a18
  186. # 11_DATA mod [39-32]=16,more refresh
  187. mw64bit $DENALI_CTL_11_DATA $DENALI_CTL_11_VAL
  188. mw64bit $DENALI_CTL_12_DATA 0x0000000000000800
  189. mw64bit $DENALI_CTL_13_DATA 0x0010002000100040
  190. mw64bit $DENALI_CTL_14_DATA 0x0010004000100040
  191. mw64bit $DENALI_CTL_15_DATA 0x04f8000000000000
  192. mw64bit $DENALI_CTL_16_DATA 0x000000002cca0000
  193. mw64bit $DENALI_CTL_17_DATA 0x0000000000000000
  194. mw64bit $DENALI_CTL_18_DATA 0x0302000000000000
  195. mw64bit $DENALI_CTL_19_DATA 0x00001300c8030600
  196. mw64bit $DENALI_CTL_20_DATA 0x0000000081fe00c8
  197. set wr_dqs_shift 0x40
  198. # start DDRC
  199. mw64bit $DENALI_CTL_02_DATA [expr $DENALI_CTL_02_VAL | (1 << 32)]
  200. # wait int_status[2] (DRAM init complete)
  201. puts -nonewline "Waiting for DDR2 controller to init..."
  202. set tmp [mrw [expr $DENALI_CTL_08_DATA + 4]]
  203. while { [expr $tmp & 0x040000] == 0 } {
  204. sleep 1
  205. set tmp [mrw [expr $DENALI_CTL_08_DATA + 4]]
  206. }
  207. puts "done."
  208. # do ddr2 training sequence
  209. # TBD (for now, if you need it, run trainDDR command)
  210. }
  211. # converted from u-boot/cpu/arm1136/comcerto/bsp100.c:config_board99()
  212. # The values are computed based on Mindspeed and Nanya datasheets
  213. proc configureDDR2regs_128M {} {
  214. set DENALI_CTL_00_DATA [regs DENALI_CTL_00_DATA]
  215. set DENALI_CTL_01_DATA [regs DENALI_CTL_01_DATA]
  216. set DENALI_CTL_02_DATA [regs DENALI_CTL_02_DATA]
  217. set DENALI_CTL_03_DATA [regs DENALI_CTL_03_DATA]
  218. set DENALI_CTL_04_DATA [regs DENALI_CTL_04_DATA]
  219. set DENALI_CTL_05_DATA [regs DENALI_CTL_05_DATA]
  220. set DENALI_CTL_06_DATA [regs DENALI_CTL_06_DATA]
  221. set DENALI_CTL_07_DATA [regs DENALI_CTL_07_DATA]
  222. set DENALI_CTL_08_DATA [regs DENALI_CTL_08_DATA]
  223. set DENALI_CTL_09_DATA [regs DENALI_CTL_09_DATA]
  224. set DENALI_CTL_10_DATA [regs DENALI_CTL_10_DATA]
  225. set DENALI_CTL_11_DATA [regs DENALI_CTL_11_DATA]
  226. set DENALI_CTL_12_DATA [regs DENALI_CTL_12_DATA]
  227. set DENALI_CTL_13_DATA [regs DENALI_CTL_13_DATA]
  228. set DENALI_CTL_14_DATA [regs DENALI_CTL_14_DATA]
  229. set DENALI_CTL_15_DATA [regs DENALI_CTL_15_DATA]
  230. set DENALI_CTL_16_DATA [regs DENALI_CTL_16_DATA]
  231. set DENALI_CTL_17_DATA [regs DENALI_CTL_17_DATA]
  232. set DENALI_CTL_18_DATA [regs DENALI_CTL_18_DATA]
  233. set DENALI_CTL_19_DATA [regs DENALI_CTL_19_DATA]
  234. set DENALI_CTL_20_DATA [regs DENALI_CTL_20_DATA]
  235. set DENALI_CTL_02_VAL 0x0100010000010100
  236. set DENALI_CTL_11_VAL 0x433A42124A650A37
  237. # set some default values
  238. mw64bit $DENALI_CTL_00_DATA 0x0100000101010101
  239. mw64bit $DENALI_CTL_01_DATA 0x0100000100000101
  240. mw64bit $DENALI_CTL_02_DATA $DENALI_CTL_02_VAL
  241. mw64bit $DENALI_CTL_03_DATA 0x0102020202020201
  242. mw64bit $DENALI_CTL_04_DATA 0x0201010100000201
  243. mw64bit $DENALI_CTL_05_DATA 0x0203010300010101
  244. mw64bit $DENALI_CTL_06_DATA 0x050A020200020202
  245. mw64bit $DENALI_CTL_07_DATA 0x000000030E0B0205
  246. mw64bit $DENALI_CTL_08_DATA 0x6427003F3F0A0209
  247. mw64bit $DENALI_CTL_09_DATA 0x1A00002F00001A00
  248. mw64bit $DENALI_CTL_10_DATA 0x01202020201A1A1A
  249. mw64bit $DENALI_CTL_11_DATA $DENALI_CTL_11_VAL
  250. mw64bit $DENALI_CTL_12_DATA 0x0000080000000800
  251. mw64bit $DENALI_CTL_13_DATA 0x0010002000100040
  252. mw64bit $DENALI_CTL_14_DATA 0x0010004000100040
  253. mw64bit $DENALI_CTL_15_DATA 0x0508000000000000
  254. mw64bit $DENALI_CTL_16_DATA 0x000020472D200000
  255. mw64bit $DENALI_CTL_17_DATA 0x0000000008000000
  256. mw64bit $DENALI_CTL_18_DATA 0x0302000000000000
  257. mw64bit $DENALI_CTL_19_DATA 0x00001400C8030604
  258. mw64bit $DENALI_CTL_20_DATA 0x00000000823600C8
  259. set wr_dqs_shift 0x40
  260. # start DDRC
  261. mw64bit $DENALI_CTL_02_DATA [expr $DENALI_CTL_02_VAL | (1 << 32)]
  262. # wait int_status[2] (DRAM init complete)
  263. puts -nonewline "Waiting for DDR2 controller to init..."
  264. set tmp [mrw [expr $DENALI_CTL_08_DATA + 4]]
  265. while { [expr $tmp & 0x040000] == 0 } {
  266. sleep 1
  267. set tmp [mrw [expr $DENALI_CTL_08_DATA + 4]]
  268. }
  269. # This is not necessary
  270. #mw64bit $DENALI_CTL_11_DATA [expr ($DENALI_CTL_11_VAL & ~0x00007F0000000000) | ($wr_dqs_shift << 40) ]
  271. puts "done."
  272. # do ddr2 training sequence
  273. # TBD (for now, if you need it, run trainDDR command)
  274. }
  275. proc setupUART0 {} {
  276. # configure UART0 to 115200, 8N1
  277. set GPIO_LOCK_REG [regs GPIO_LOCK_REG]
  278. set GPIO_IOCTRL_REG [regs GPIO_IOCTRL_REG]
  279. set GPIO_IOCTRL_VAL [regs GPIO_IOCTRL_VAL]
  280. set GPIO_IOCTRL_UART0 [regs GPIO_IOCTRL_UART0]
  281. set UART0_LCR [regs UART0_LCR]
  282. set LCR_DLAB [regs LCR_DLAB]
  283. set UART0_DLL [regs UART0_DLL]
  284. set UART0_DLH [regs UART0_DLH]
  285. set UART0_IIR [regs UART0_IIR]
  286. set UART0_IER [regs UART0_IER]
  287. set LCR_ONE_STOP [regs LCR_ONE_STOP]
  288. set LCR_CHAR_LEN_8 [regs LCR_CHAR_LEN_8]
  289. set FCR_XMITRES [regs FCR_XMITRES]
  290. set FCR_RCVRRES [regs FCR_RCVRRES]
  291. set FCR_FIFOEN [regs FCR_FIFOEN]
  292. set IER_UUE [regs IER_UUE]
  293. # unlock writing to IOCTRL register
  294. mww $GPIO_LOCK_REG $GPIO_IOCTRL_VAL
  295. # enable UART0
  296. mmw $GPIO_IOCTRL_REG $GPIO_IOCTRL_UART0 0x0
  297. # baudrate 115200
  298. # This should really be amba_clk/(16*115200) but amba_clk=165MHz
  299. set tmp 89
  300. # Enable Divisor Latch access
  301. mmw $UART0_LCR $LCR_DLAB 0x0
  302. # set the divisor to $tmp
  303. mww $UART0_DLL [expr $tmp & 0xff]
  304. mww $UART0_DLH [expr $tmp >> 8]
  305. # Disable Divisor Latch access
  306. mmw $UART0_LCR 0x0 $LCR_DLAB
  307. # set the UART to 8N1
  308. mmw $UART0_LCR [expr $LCR_ONE_STOP | $LCR_CHAR_LEN_8 ] 0x0
  309. # reset FIFO
  310. mmw $UART0_IIR [expr $FCR_XMITRES | $FCR_RCVRRES | $FCR_FIFOEN ] 0x0
  311. # enable FFUART
  312. mww $UART0_IER $IER_UUE
  313. }
  314. proc putcUART0 {char} {
  315. set UART0_LSR [regs UART0_LSR]
  316. set UART0_THR [regs UART0_THR]
  317. set LSR_TEMT [regs LSR_TEMT]
  318. # convert the 'char' to digit
  319. set tmp [ scan $char %c ]
  320. # /* wait for room in the tx FIFO on FFUART */
  321. while {[expr [mrw $UART0_LSR] & $LSR_TEMT] == 0} { sleep 1 }
  322. mww $UART0_THR $tmp
  323. if { $char == "\n" } { putcUART0 \r }
  324. }
  325. proc putsUART0 {str} {
  326. set index 0
  327. set len [string length $str]
  328. while { $index < $len } {
  329. putcUART0 [string index $str $index]
  330. set index [expr $index + 1]
  331. }
  332. }
  333. proc trainDDR2 {} {
  334. set ARAM_BASEADDR [regs ARAM_BASEADDR]
  335. # you must have run 'reset init' or u-boot
  336. # load the training code to ARAM
  337. load_image ./images/ddr2train.bin $ARAM_BASEADDR bin
  338. # set PC to start of NOR (at boot 0x20000000 = 0x0)
  339. reg pc $ARAM_BASEADDR
  340. # run
  341. resume
  342. }
  343. proc flashUBOOT {file} {
  344. # this will update uboot on NOR partition
  345. set EXP_CS0_BASEADDR [regs EXP_CS0_BASEADDR]
  346. # setup CS0 controller for NOR
  347. setupNOR
  348. # make sure we are accessing the lower part of NOR
  349. lowGPIO5
  350. flash probe 0
  351. puts "Erasing sectors 0-3 for uboot"
  352. putsUART0 "Erasing sectors 0-3 for uboot\n"
  353. flash erase_sector 0 0 3
  354. puts "Programming u-boot"
  355. putsUART0 "Programming u-boot..."
  356. memwrite burst enable
  357. flash write_image $file $EXP_CS0_BASEADDR
  358. memwrite burst disable
  359. putsUART0 "done.\n"
  360. putsUART0 "Rebooting, please wait!\n"
  361. reboot
  362. }