Skip to content

Commit c387ce7

Browse files
author
Sebastien Bourdeauducq
committedFeb 17, 2012
Map DDR PHY controls in CSR
1 parent 5d1dad5 commit c387ce7

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed
 

‎milkymist/s6ddrphy/__init__.py

+39-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from migen.fhdl.structure import *
22
from migen.bus import dfi
3+
from migen.bank.description import *
4+
from migen.bank import csrgen
35

46
class S6DDRPHY:
5-
def __init__(self, a, ba, d):
7+
def __init__(self, csr_address, a, ba, d):
68
ins = []
79
outs = []
810
inouts = []
@@ -16,8 +18,7 @@ def __init__(self, a, ba, d):
1618
"clk4x_rd_left",
1719
"clk4x_rd_strb_left",
1820
"clk4x_rd_right",
19-
"clk4x_rd_strb_right",
20-
"reset_n"
21+
"clk4x_rd_strb_right"
2122
]:
2223
s = Signal(name=name)
2324
setattr(self, name, s)
@@ -50,6 +51,8 @@ def __init__(self, a, ba, d):
5051
outs += self.dfi.get_standard_names(False, True)
5152

5253
ins += [
54+
("reset_n", BV(1)),
55+
5356
("cfg_al", BV(3)),
5457
("cfg_cl", BV(3)),
5558
("cfg_bl", BV(2)),
@@ -87,8 +90,23 @@ def __init__(self, a, ba, d):
8790
("DM_IO_LOC", Constant(2**4-1, BV(4)))
8891
],
8992
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)
90104

91105
def get_fragment(self):
106+
pending_r = Signal()
107+
pending_w = Signal()
108+
cpg_busy = Signal()
109+
92110
comb = [
93111
self._inst.ins["cfg_al"].eq(0),
94112
self._inst.ins["cfg_cl"].eq(3),
@@ -99,6 +117,22 @@ def get_fragment(self):
99117
self._inst.ins["diag_io_sel"].eq(0),
100118
self._inst.ins["diag_disable_cal_on_startup"].eq(0),
101119
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))
103136
]
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()

‎software/include/hw/s6ddrphy.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Milkymist SoC (Software)
3+
* Copyright (C) 2012 Sebastien Bourdeauducq
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, version 3 of the License.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef __HW_S6DDRPHY_H
19+
#define __HW_S6DDRPHY_H
20+
21+
#include <hw/common.h>
22+
23+
#define CSR_DDRPHY_STATUS MMPTR(0xe0000800)
24+
25+
#define DDRPHY_STATUS_RESETN (0x1)
26+
#define DDRPHY_STATUS_INIT_DONE (0x2)
27+
#define DDRPHY_STATUS_PHY_CAL_DONE (0x4)
28+
29+
#define CSR_DDRPHY_REQUESTS MMPTR(0xe0000804)
30+
31+
#define DDRPHY_REQUEST_READ (0x1)
32+
#define DDRPHY_REQUEST_WRITE (0x2)
33+
34+
#define CSR_DDRPHY_REQADDR MMPTR(0xe0000808)
35+
36+
#endif /* __HW_S6DDRPHY_H */

‎software/include/hw/uart.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <hw/common.h>
2222

23-
#define CSR_UART_RXTX MMPTR(0xe0000000)
23+
#define CSR_UART_RXTX MMPTR(0xe0000000)
2424
#define CSR_UART_DIVISORH MMPTR(0xe0000004)
2525
#define CSR_UART_DIVISORL MMPTR(0xe0000008)
2626

‎top.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get():
3131
#
3232
# ASMI
3333
#
34-
ddrphy0 = s6ddrphy.S6DDRPHY(13, 2, 128)
34+
ddrphy0 = s6ddrphy.S6DDRPHY(1, 13, 2, 128)
3535
asmihub0 = asmibus.Hub(23, 128, 12) # TODO: get hub from memory controller
3636
asmiport_wb = asmihub0.get_port()
3737
asmihub0.finalize()
@@ -68,7 +68,10 @@ def get():
6868
# CSR
6969
#
7070
uart0 = uart.UART(0, clk_freq, baud=115200)
71-
csrcon0 = csr.Interconnect(wishbone2csr0.csr, [uart0.bank.interface])
71+
csrcon0 = csr.Interconnect(wishbone2csr0.csr, [
72+
uart0.bank.interface,
73+
ddrphy0.bank.interface
74+
])
7275

7376
#
7477
# Interrupts

0 commit comments

Comments
 (0)
Please sign in to comment.