Skip to content

Commit c38de34

Browse files
author
Sebastien Bourdeauducq
committedFeb 17, 2012
bios: DDR initialization skeleton
1 parent e5927e2 commit c38de34

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed
 

‎software/bios/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
M2DIR=../..
22
include $(M2DIR)/software/include.mak
33

4-
OBJECTS=crt0.o isr.o main.o
4+
OBJECTS=crt0.o isr.o ddrinit.o main.o
55

66
all: bios.bin
77

‎software/bios/ddrinit.c

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
#include <stdio.h>
19+
20+
#include <hw/s6ddrphy.h>
21+
22+
#include "ddrinit.h"
23+
24+
static void init_sequence(void)
25+
{
26+
printf("Sending initialization sequence...\n");
27+
// TODO
28+
}
29+
30+
static void calibrate_phy(void)
31+
{
32+
int requests;
33+
int addr;
34+
35+
printf("Calibrating PHY...\n");
36+
while(!(CSR_DDRPHY_STATUS & DDRPHY_STATUS_PHY_CAL_DONE)) {
37+
requests = CSR_DDRPHY_REQUESTS;
38+
addr = CSR_DDRPHY_REQADDR;
39+
40+
if(requests & DDRPHY_REQUEST_READ) {
41+
printf("R %d\n", addr);
42+
// TODO
43+
}
44+
if(requests & DDRPHY_REQUEST_WRITE) {
45+
printf("W %d\n", addr);
46+
// TODO
47+
}
48+
49+
CSR_DDRPHY_REQUESTS = requests;
50+
}
51+
}
52+
53+
int ddrinit(void)
54+
{
55+
printf("Initializing DDR SDRAM...\n");
56+
57+
CSR_DDRPHY_STATUS = DDRPHY_STATUS_RESETN;
58+
init_sequence();
59+
CSR_DDRPHY_STATUS = DDRPHY_STATUS_RESETN|DDRPHY_STATUS_INIT_DONE;
60+
calibrate_phy();
61+
62+
return 1;
63+
}

‎software/bios/ddrinit.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 __DDRINIT_H
19+
#define __DDRINIT_H
20+
21+
int ddrinit(void);
22+
23+
#endif /* __DDRINIT_H */

‎software/bios/main.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include <hw/flash.h>
2929

30+
#include "ddrinit.h"
31+
3032
enum {
3133
CSR_IE = 1, CSR_IM, CSR_IP, CSR_ICC, CSR_DCC, CSR_CC, CSR_CFG, CSR_EBA,
3234
CSR_DC, CSR_DEBA, CSR_JTX, CSR_JRX, CSR_BP0, CSR_BP1, CSR_BP2, CSR_BP3,
@@ -440,11 +442,12 @@ int main(int i, char **c)
440442
uart_init();
441443
printf(banner);
442444
crcbios();
443-
445+
print_mac();
446+
ddrinit();
447+
444448
if(rescue)
445449
printf("I: Booting in rescue mode\n");
446-
447-
print_mac();
450+
448451
while(1) {
449452
putsnonl("\e[1mBIOS>\e[0m ");
450453
readstr(buffer, 64);

0 commit comments

Comments
 (0)