Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

bios: DDR initialization skeleton

  • Loading branch information...
commit c38de34a211cf210fd4c7d651e53af756e439fb4 1 parent e5927e2
Sébastien Bourdeauducq authored February 17, 2012
2  software/bios/Makefile
... ...
@@ -1,7 +1,7 @@
1 1
 M2DIR=../..
2 2
 include $(M2DIR)/software/include.mak
3 3
 
4  
-OBJECTS=crt0.o isr.o main.o
  4
+OBJECTS=crt0.o isr.o ddrinit.o main.o
5 5
 
6 6
 all: bios.bin
7 7
 
63  software/bios/ddrinit.c
... ...
@@ -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
+}
23  software/bios/ddrinit.h
... ...
@@ -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 */
9  software/bios/main.c
@@ -27,6 +27,8 @@
27 27
 
28 28
 #include <hw/flash.h>
29 29
 
  30
+#include "ddrinit.h"
  31
+
30 32
 enum {
31 33
 	CSR_IE = 1, CSR_IM, CSR_IP, CSR_ICC, CSR_DCC, CSR_CC, CSR_CFG, CSR_EBA,
32 34
 	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)
440 442
 	uart_init();
441 443
 	printf(banner);
442 444
 	crcbios();
443  
-
  445
+	print_mac();
  446
+	ddrinit();
  447
+	
444 448
 	if(rescue)
445 449
 		printf("I: Booting in rescue mode\n");
446  
-
447  
-	print_mac();
  450
+	
448 451
 	while(1) {
449 452
 		putsnonl("\e[1mBIOS>\e[0m ");
450 453
 		readstr(buffer, 64);

0 notes on commit c38de34

Please sign in to comment.
Something went wrong with that request. Please try again.