1
1
from migen .fhdl .structure import *
2
2
from migen .bus import dfi
3
+ from migen .bank .description import *
4
+ from migen .bank import csrgen
3
5
4
6
class S6DDRPHY :
5
- def __init__ (self , a , ba , d ):
7
+ def __init__ (self , csr_address , a , ba , d ):
6
8
ins = []
7
9
outs = []
8
10
inouts = []
@@ -16,8 +18,7 @@ def __init__(self, a, ba, d):
16
18
"clk4x_rd_left" ,
17
19
"clk4x_rd_strb_left" ,
18
20
"clk4x_rd_right" ,
19
- "clk4x_rd_strb_right" ,
20
- "reset_n"
21
+ "clk4x_rd_strb_right"
21
22
]:
22
23
s = Signal (name = name )
23
24
setattr (self , name , s )
@@ -50,6 +51,8 @@ def __init__(self, a, ba, d):
50
51
outs += self .dfi .get_standard_names (False , True )
51
52
52
53
ins += [
54
+ ("reset_n" , BV (1 )),
55
+
53
56
("cfg_al" , BV (3 )),
54
57
("cfg_cl" , BV (3 )),
55
58
("cfg_bl" , BV (2 )),
@@ -87,8 +90,23 @@ def __init__(self, a, ba, d):
87
90
("DM_IO_LOC" , Constant (2 ** 4 - 1 , BV (4 )))
88
91
],
89
92
clkport = "clk" )
93
+
94
+ self ._reset_n = Field ("reset_n" )
95
+ self ._init_done = Field ("init_done" )
96
+ self ._phy_cal_done = Field ("phy_cal_done" , 1 , READ_ONLY , WRITE_ONLY )
97
+ self ._status = RegisterFields ("status" ,
98
+ [self ._reset_n , self ._init_done , self ._phy_cal_done ])
99
+ self ._req = RegisterRaw ("req" , 2 )
100
+ self ._req_addr = RegisterField ("req_addr" , 8 , READ_ONLY , WRITE_ONLY )
101
+
102
+ self .bank = csrgen .Bank ([self ._status , self ._req , self ._req_addr ],
103
+ address = csr_address )
90
104
91
105
def get_fragment (self ):
106
+ pending_r = Signal ()
107
+ pending_w = Signal ()
108
+ cpg_busy = Signal ()
109
+
92
110
comb = [
93
111
self ._inst .ins ["cfg_al" ].eq (0 ),
94
112
self ._inst .ins ["cfg_cl" ].eq (3 ),
@@ -99,6 +117,22 @@ def get_fragment(self):
99
117
self ._inst .ins ["diag_io_sel" ].eq (0 ),
100
118
self ._inst .ins ["diag_disable_cal_on_startup" ].eq (0 ),
101
119
self ._inst .ins ["diag_cal_bits" ].eq (0 ),
102
- self ._inst .ins ["diag_short_cal" ].eq (0 )
120
+ self ._inst .ins ["diag_short_cal" ].eq (0 ),
121
+
122
+ self ._inst .ins ["reset_n" ].eq (self ._reset_n .r ),
123
+ self ._inst .ins ["init_done" ].eq (self ._init_done .r ),
124
+ self ._phy_cal_done .w .eq (self ._inst .outs ["phy_cal_done" ]),
125
+ self ._req_addr .field .w .eq (self ._inst .outs ["cpg_addr" ][2 :10 ]),
126
+
127
+ self ._req .w .eq (Cat (pending_r , pending_w )),
128
+ cpg_busy .eq (pending_r | pending_w ),
129
+ self ._inst .ins ["cpg_busy" ].eq (cpg_busy )
130
+ ]
131
+ sync = [
132
+ If (self ._inst .outs ["cpg_r_req" ], pending_r .eq (1 )),
133
+ If (self ._inst .outs ["cpg_w_req" ], pending_w .eq (1 )),
134
+ If (self ._req .re & self ._req .r [0 ], pending_r .eq (0 )),
135
+ If (self ._req .re & self ._req .r [1 ], pending_w .eq (0 ))
103
136
]
104
- return Fragment (comb , instances = [self ._inst ], pads = set (self ._sd_pins ))
137
+ return Fragment (comb , sync , instances = [self ._inst ], pads = set (self ._sd_pins )) \
138
+ + self .bank .get_fragment ()
0 commit comments