2012-02-17 12:47:04 -05:00
|
|
|
#include <stdio.h>
|
2012-02-23 15:21:07 -05:00
|
|
|
#include <stdlib.h>
|
2012-02-17 12:47:04 -05:00
|
|
|
|
2012-02-18 12:12:14 -05:00
|
|
|
#include <hw/dfii.h>
|
2012-05-15 13:29:26 -04:00
|
|
|
#include <hw/mem.h>
|
2012-02-17 12:47:04 -05:00
|
|
|
|
|
|
|
#include "ddrinit.h"
|
|
|
|
|
2012-02-18 12:12:14 -05:00
|
|
|
static void cdelay(int i)
|
|
|
|
{
|
|
|
|
while(i > 0) {
|
|
|
|
__asm__ volatile("nop");
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setaddr(int a)
|
|
|
|
{
|
2012-05-21 16:55:45 -04:00
|
|
|
CSR_DFII_AH_P0 = (a & 0xff00) >> 8;
|
|
|
|
CSR_DFII_AL_P0 = a & 0x00ff;
|
|
|
|
CSR_DFII_AH_P1 = (a & 0xff00) >> 8;
|
|
|
|
CSR_DFII_AL_P1 = a & 0x00ff;
|
2012-02-18 12:12:14 -05:00
|
|
|
}
|
|
|
|
|
2012-02-17 12:47:04 -05:00
|
|
|
static void init_sequence(void)
|
|
|
|
{
|
2012-02-18 12:12:14 -05:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Bring CKE high */
|
|
|
|
setaddr(0x0000);
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_BA_P0 = 0;
|
2012-02-18 12:12:14 -05:00
|
|
|
CSR_DFII_CONTROL = DFII_CONTROL_CKE;
|
|
|
|
|
|
|
|
/* Precharge All */
|
|
|
|
setaddr(0x0400);
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_WE|DFII_COMMAND_CS;
|
2012-02-18 12:12:14 -05:00
|
|
|
|
|
|
|
/* Load Extended Mode Register */
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_BA_P0 = 1;
|
2012-02-18 12:12:14 -05:00
|
|
|
setaddr(0x0000);
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS;
|
|
|
|
CSR_DFII_BA_P0 = 0;
|
2012-02-18 12:12:14 -05:00
|
|
|
|
|
|
|
/* Load Mode Register */
|
2012-02-24 09:05:52 -05:00
|
|
|
setaddr(0x0132); /* Reset DLL, CL=3, BL=4 */
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS;
|
2012-02-18 12:12:14 -05:00
|
|
|
cdelay(200);
|
|
|
|
|
|
|
|
/* Precharge All */
|
|
|
|
setaddr(0x0400);
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_WE|DFII_COMMAND_CS;
|
2012-02-18 12:12:14 -05:00
|
|
|
|
|
|
|
/* 2x Auto Refresh */
|
|
|
|
for(i=0;i<2;i++) {
|
|
|
|
setaddr(0);
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_CS;
|
2012-02-18 12:12:14 -05:00
|
|
|
cdelay(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load Mode Register */
|
2012-02-24 09:05:52 -05:00
|
|
|
setaddr(0x0032); /* CL=3, BL=4 */
|
2012-02-23 15:21:07 -05:00
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS;
|
2012-02-18 12:12:14 -05:00
|
|
|
cdelay(200);
|
2012-02-17 12:47:04 -05:00
|
|
|
}
|
|
|
|
|
2012-05-14 14:07:57 -04:00
|
|
|
void ddrsw(void)
|
|
|
|
{
|
|
|
|
CSR_DFII_CONTROL = DFII_CONTROL_CKE;
|
|
|
|
printf("DDR now under software control\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ddrhw(void)
|
|
|
|
{
|
|
|
|
CSR_DFII_CONTROL = DFII_CONTROL_SEL|DFII_CONTROL_CKE;
|
|
|
|
printf("DDR now under hardware control\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ddrrow(char *_row)
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
unsigned int row;
|
|
|
|
|
|
|
|
if(*_row == 0) {
|
|
|
|
setaddr(0x0000);
|
|
|
|
CSR_DFII_BA_P0 = 0;
|
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_WE|DFII_COMMAND_CS;
|
|
|
|
cdelay(15);
|
|
|
|
printf("Precharged\n");
|
|
|
|
} else {
|
|
|
|
row = strtoul(_row, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect row\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setaddr(row);
|
|
|
|
CSR_DFII_BA_P0 = 0;
|
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_RAS|DFII_COMMAND_CS;
|
|
|
|
cdelay(15);
|
|
|
|
printf("Activated row %d\n", row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-23 15:21:07 -05:00
|
|
|
void ddrrd(char *startaddr)
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
unsigned int addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(*startaddr == 0) {
|
|
|
|
printf("ddrrd <address>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr = strtoul(startaddr, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect address\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setaddr(addr);
|
|
|
|
CSR_DFII_BA_P0 = 0;
|
|
|
|
CSR_DFII_COMMAND_P0 = DFII_COMMAND_CAS|DFII_COMMAND_CS|DFII_COMMAND_RDDATA;
|
|
|
|
cdelay(15);
|
|
|
|
|
|
|
|
for(i=0;i<8;i++)
|
2012-02-24 07:54:10 -05:00
|
|
|
printf("%02x", MMPTR(0xe0000834+4*i));
|
2012-02-23 15:21:07 -05:00
|
|
|
for(i=0;i<8;i++)
|
2012-02-24 07:54:10 -05:00
|
|
|
printf("%02x", MMPTR(0xe0000884+4*i));
|
2012-02-23 15:21:07 -05:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ddrwr(char *startaddr)
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
unsigned int addr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(*startaddr == 0) {
|
|
|
|
printf("ddrrd <address>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr = strtoul(startaddr, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect address\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0;i<8;i++) {
|
|
|
|
MMPTR(0xe0000814+4*i) = i;
|
2012-02-24 07:54:10 -05:00
|
|
|
MMPTR(0xe0000864+4*i) = 0xf0 + i;
|
2012-02-23 15:21:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
setaddr(addr);
|
|
|
|
CSR_DFII_BA_P1 = 0;
|
|
|
|
CSR_DFII_COMMAND_P1 = DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS|DFII_COMMAND_WRDATA;
|
|
|
|
}
|
|
|
|
|
2012-05-15 13:29:26 -04:00
|
|
|
#define TEST_SIZE (4*1024*1024)
|
|
|
|
|
|
|
|
int memtest_silent(void)
|
|
|
|
{
|
|
|
|
volatile unsigned int *array = (unsigned int *)SDRAM_BASE;
|
|
|
|
int i;
|
|
|
|
unsigned int prv;
|
|
|
|
|
|
|
|
prv = 0;
|
|
|
|
for(i=0;i<TEST_SIZE/4;i++) {
|
|
|
|
prv = 1664525*prv + 1013904223;
|
|
|
|
array[i] = prv;
|
|
|
|
}
|
|
|
|
|
|
|
|
prv = 0;
|
|
|
|
for(i=0;i<TEST_SIZE/4;i++) {
|
|
|
|
prv = 1664525*prv + 1013904223;
|
|
|
|
if(array[i] != prv)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void memtest(void)
|
|
|
|
{
|
|
|
|
if(memtest_silent())
|
|
|
|
printf("OK\n");
|
|
|
|
else
|
|
|
|
printf("Failed\n");
|
|
|
|
}
|
|
|
|
|
2012-02-17 12:47:04 -05:00
|
|
|
int ddrinit(void)
|
|
|
|
{
|
2012-05-16 04:20:04 -04:00
|
|
|
printf("Initializing DDR SDRAM...\n");
|
2012-02-17 12:47:04 -05:00
|
|
|
|
|
|
|
init_sequence();
|
2012-05-15 13:29:26 -04:00
|
|
|
CSR_DFII_CONTROL = DFII_CONTROL_SEL|DFII_CONTROL_CKE;
|
|
|
|
if(!memtest_silent())
|
|
|
|
return 0;
|
2012-02-17 12:47:04 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|