c100config.tcl 15 KB

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