86f2a1d2459a736ebe682965b9ab9e279bc77d46
[fw/openocd] / tcl / chip / st / spear / spear3xx.tcl
1 # Generic init scripts for all ST SPEAr3xx family
2 # http://www.st.com/spear
3 #
4 # Date:      2010-09-23
5 # Author:    Antonio Borneo <borneo.antonio@gmail.com>
6
7
8 # Initialize internal clock
9 # Default:
10 # - Crystal =  24 MHz
11 # - PLL1    = 332 MHz
12 # - PLL2    = 332 MHz
13 # - CPU_CLK = 332 MHz
14 # - DDR_CLK = 332 MHz async
15 # - HCLK    = 166 MHz
16 # - PCLK    =  83 MHz
17 proc sp3xx_clock_default {} {
18         mww 0xfca00000 0x00000002       ;# set sysclk slow
19         mww 0xfca00014 0x0ffffff8       ;# set pll timeout to minimum (100us ?!?)
20
21         # DDRCORE disable to change frequency
22         set val [expr {([mrw 0xfca8002c] & ~0x20000000) | 0x40000000}]
23         mww 0xfca8002c $val
24         mww 0xfca8002c $val ;# Yes, write twice!
25
26         # programming PLL1
27         mww 0xfca8000c 0xa600010c       ;# M=166 P=1 N=12
28         mww 0xfca80008 0x00001c0a       ;# power down
29         mww 0xfca80008 0x00001c0e       ;# enable
30         mww 0xfca80008 0x00001c06       ;# strobe
31         mww 0xfca80008 0x00001c0e
32         while { [expr {[mrw 0xfca80008] & 0x01}] == 0x00 } { sleep 1 }
33
34         # programming PLL2
35         mww 0xfca80018 0xa600010c       ;# M=166, P=1, N=12
36         mww 0xfca80014 0x00001c0a       ;# power down
37         mww 0xfca80014 0x00001c0e       ;# enable
38         mww 0xfca80014 0x00001c06       ;# strobe
39         mww 0xfca80014 0x00001c0e
40         while { [expr {[mrw 0xfca80014] & 0x01}] == 0x00 } { sleep 1 }
41
42         mww 0xfca80028 0x00000082       ;# enable plltimeen
43         mww 0xfca80024 0x00000511       ;# set hclkdiv="/2" & pclkdiv="/2"
44
45         mww 0xfca00000 0x00000004       ;# setting SYSCTL to NORMAL mode
46         while { [expr {[mrw 0xfca00000] & 0x20}] != 0x20 } { sleep 1 }
47
48         # Select source of DDR clock
49         #mmw 0xfca80020 0x10000000 0x70000000 ;# PLL1
50         mmw 0xfca80020 0x30000000 0x70000000 ;# PLL2
51
52         # DDRCORE enable after change frequency
53         mmw 0xfca8002c 0x20000000 0x00000000
54 }
55
56 proc sp3xx_common_init {} {
57         mww 0xfca8002c 0xfffffff8       ;# enable clock of all peripherals
58         mww 0xfca80038 0x00000000       ;# remove reset of all peripherals
59
60         mww 0xfca80034 0x0000ffff       ;# enable all RAS clocks
61         mww 0xfca80040 0x00000000       ;# remove all RAS resets
62
63         mww 0xfca800e4 0x78000008       ;# COMP1V8_REG
64         mww 0xfca800ec 0x78000008       ;# COMP3V3_REG
65
66         mww 0xfc000000 0x10000f5f       ;# init SMI and set HW mode
67         mww 0xfc000000 0x00000f5f
68
69         # Initialize Bus Interconnection Matrix
70         # All ports Round-Robin and lowest priority
71         mww 0xfca8007c 0x80000007
72         mww 0xfca80080 0x80000007
73         mww 0xfca80084 0x80000007
74         mww 0xfca80088 0x80000007
75         mww 0xfca8008c 0x80000007
76         mww 0xfca80090 0x80000007
77         mww 0xfca80094 0x80000007
78         mww 0xfca80098 0x80000007
79         mww 0xfca8009c 0x80000007
80 }
81
82
83 # Specific init scripts for ST SPEAr300
84 proc sp300_init {} {
85         mww 0x99000000 0x00003fff       ;# RAS function enable
86 }
87
88
89 # Specific init scripts for ST SPEAr310
90 proc sp310_init {} {
91         mww 0xb4000008 0x00002ff4       ;# RAS function enable
92
93         mww 0xfca80050 0x00000001       ;# Enable clk mem port 1
94
95         mww 0xfca8013c 0x2f7bc210       ;# plgpio_pad_drv
96         mww 0xfca80140 0x017bdef6
97 }
98
99 proc sp310_emi_init {} {
100         # set EMI pad strength
101         mmw 0xfca80134 0x0e000000 0x00000000
102         mmw 0xfca80138 0x0e739ce7 0x00000000
103         mmw 0xfca8013c 0x00039ce7 0x00000000
104
105         # set safe EMI timing as in BootROM
106         #mww 0x4f000000 0x0000000f      ;# tAP_0_reg
107         #mww 0x4f000004 0x00000000      ;# tSDP_0_reg
108         #mww 0x4f000008 0x000000ff      ;# tDPw_0_reg
109         #mww 0x4f00000c 0x00000111      ;# tDPr_0_reg
110         #mww 0x4f000010 0x00000002      ;# tDCS_0_reg
111
112         # set fast EMI timing as in Linux
113         mww 0x4f000000 0x00000010       ;# tAP_0_reg
114         mww 0x4f000004 0x00000005       ;# tSDP_0_reg
115         mww 0x4f000008 0x0000000a       ;# tDPw_0_reg
116         mww 0x4f00000c 0x0000000a       ;# tDPr_0_reg
117         mww 0x4f000010 0x00000005       ;# tDCS_0_re
118
119         # 32bit wide, 8/16/32bit access
120         mww 0x4f000014 0x0000000e       ;# control_0_reg
121         mww 0x4f000094 0x0000003f       ;# ack_reg
122 }
123
124
125 # Specific init scripts for ST SPEAr320
126 proc sp320_init {} {
127         mww 0xb300000c 0xffffac04       ;# RAS function enable
128         mww 0xb3000010 0x00000001       ;# RAS mode select
129 }