bios: DDR initialization skeleton
authorSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 17 Feb 2012 17:47:04 +0000 (18:47 +0100)
committerSebastien Bourdeauducq <sebastien@milkymist.org>
Fri, 17 Feb 2012 17:47:04 +0000 (18:47 +0100)
software/bios/Makefile
software/bios/ddrinit.c [new file with mode: 0644]
software/bios/ddrinit.h [new file with mode: 0644]
software/bios/main.c

index ad4eec7381f869acda972a6469b7c94bffc60b10..e7f001544cbf6d2b4bb5300349f66e1563120aa2 100644 (file)
@@ -1,7 +1,7 @@
 M2DIR=../..
 include $(M2DIR)/software/include.mak
 
-OBJECTS=crt0.o isr.o main.o
+OBJECTS=crt0.o isr.o ddrinit.o main.o
 
 all: bios.bin
 
diff --git a/software/bios/ddrinit.c b/software/bios/ddrinit.c
new file mode 100644 (file)
index 0000000..24352a7
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Milkymist SoC (Software)
+ * Copyright (C) 2012 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include <hw/s6ddrphy.h>
+
+#include "ddrinit.h"
+
+static void init_sequence(void)
+{
+       printf("Sending initialization sequence...\n");
+       // TODO
+}
+
+static void calibrate_phy(void)
+{
+       int requests;
+       int addr;
+       
+       printf("Calibrating PHY...\n");
+       while(!(CSR_DDRPHY_STATUS & DDRPHY_STATUS_PHY_CAL_DONE)) {
+               requests = CSR_DDRPHY_REQUESTS;
+               addr = CSR_DDRPHY_REQADDR;
+               
+               if(requests & DDRPHY_REQUEST_READ) {
+                       printf("R %d\n", addr);
+                       // TODO
+               }
+               if(requests & DDRPHY_REQUEST_WRITE) {
+                       printf("W %d\n", addr);
+                       // TODO
+               }
+               
+               CSR_DDRPHY_REQUESTS = requests;
+       }
+}
+
+int ddrinit(void)
+{
+       printf("Initializing DDR SDRAM...\n");
+       
+       CSR_DDRPHY_STATUS = DDRPHY_STATUS_RESETN;
+       init_sequence();
+       CSR_DDRPHY_STATUS = DDRPHY_STATUS_RESETN|DDRPHY_STATUS_INIT_DONE;
+       calibrate_phy();
+       
+       return 1;
+}
diff --git a/software/bios/ddrinit.h b/software/bios/ddrinit.h
new file mode 100644 (file)
index 0000000..7ef4a21
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Milkymist SoC (Software)
+ * Copyright (C) 2012 Sebastien Bourdeauducq
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __DDRINIT_H
+#define __DDRINIT_H
+
+int ddrinit(void);
+
+#endif /* __DDRINIT_H */
index c408b8e3fe75312b606b91d3db8bbdf39cee9775..4b700b54e2e1d0bf60e7ebe84f275632c006a50f 100644 (file)
@@ -27,6 +27,8 @@
 
 #include <hw/flash.h>
 
+#include "ddrinit.h"
+
 enum {
        CSR_IE = 1, CSR_IM, CSR_IP, CSR_ICC, CSR_DCC, CSR_CC, CSR_CFG, CSR_EBA,
        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)
        uart_init();
        printf(banner);
        crcbios();
-
+       print_mac();
+       ddrinit();
+       
        if(rescue)
                printf("I: Booting in rescue mode\n");
-
-       print_mac();
+       
        while(1) {
                putsnonl("\e[1mBIOS>\e[0m ");
                readstr(buffer, 64);