2013-11-24 17:50:09 -05:00
|
|
|
#include <generated/csr.h>
|
|
|
|
#ifdef DFII_BASE
|
|
|
|
|
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
|
|
|
|
2013-11-24 13:50:17 -05:00
|
|
|
#include <generated/sdram_phy.h>
|
2014-02-21 11:55:05 -05:00
|
|
|
#include <generated/mem.h>
|
2013-03-25 09:42:48 -04:00
|
|
|
#include <hw/flags.h>
|
2012-02-17 12:47:04 -05:00
|
|
|
|
2012-08-04 10:32:15 -04:00
|
|
|
#include "sdram.h"
|
2012-02-17 12:47:04 -05:00
|
|
|
|
2013-07-10 14:39:53 -04:00
|
|
|
static void cdelay(int i)
|
2012-02-18 12:12:14 -05:00
|
|
|
{
|
|
|
|
while(i > 0) {
|
2014-05-14 04:24:56 -04:00
|
|
|
#if defined (__lm32__)
|
2012-02-18 12:12:14 -05:00
|
|
|
__asm__ volatile("nop");
|
2014-05-14 04:24:56 -04:00
|
|
|
#elif defined (__or1k__)
|
|
|
|
__asm__ volatile("l.nop");
|
|
|
|
#else
|
|
|
|
#error Unsupported architecture
|
|
|
|
#endif
|
2012-02-18 12:12:14 -05:00
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:31:26 -04:00
|
|
|
void sdrsw(void)
|
2012-05-14 14:07:57 -04:00
|
|
|
{
|
2014-08-08 09:57:42 -04:00
|
|
|
dfii_control_write(DFII_CONTROL_CKE|DFII_CONTROL_ODT|DFII_CONTROL_RESET_N);
|
2014-05-23 15:31:26 -04:00
|
|
|
printf("SDRAM now under software control\n");
|
2012-05-14 14:07:57 -04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:31:26 -04:00
|
|
|
void sdrhw(void)
|
2012-05-14 14:07:57 -04:00
|
|
|
{
|
2014-08-08 09:57:42 -04:00
|
|
|
dfii_control_write(DFII_CONTROL_SEL);
|
2014-05-23 15:31:26 -04:00
|
|
|
printf("SDRAM now under hardware control\n");
|
2012-05-14 14:07:57 -04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:31:26 -04:00
|
|
|
void sdrrow(char *_row)
|
2012-05-14 14:07:57 -04:00
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
unsigned int row;
|
|
|
|
|
|
|
|
if(*_row == 0) {
|
2013-03-25 09:42:48 -04:00
|
|
|
dfii_pi0_address_write(0x0000);
|
|
|
|
dfii_pi0_baddress_write(0);
|
2012-10-09 13:08:37 -04:00
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_WE|DFII_COMMAND_CS);
|
2012-05-14 14:07:57 -04:00
|
|
|
cdelay(15);
|
|
|
|
printf("Precharged\n");
|
|
|
|
} else {
|
|
|
|
row = strtoul(_row, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect row\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-03-25 09:42:48 -04:00
|
|
|
dfii_pi0_address_write(row);
|
|
|
|
dfii_pi0_baddress_write(0);
|
2012-10-09 13:08:37 -04:00
|
|
|
command_p0(DFII_COMMAND_RAS|DFII_COMMAND_CS);
|
2012-05-14 14:07:57 -04:00
|
|
|
cdelay(15);
|
|
|
|
printf("Activated row %d\n", row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-01 02:58:58 -04:00
|
|
|
void sdrrdbuf(int dq)
|
|
|
|
{
|
|
|
|
int i, p;
|
|
|
|
int first_byte, step;
|
|
|
|
|
|
|
|
if(dq < 0) {
|
|
|
|
first_byte = 0;
|
|
|
|
step = 1;
|
|
|
|
} else {
|
|
|
|
first_byte = DFII_PIX_RDDATA_SIZE/2 - 1 - dq;
|
|
|
|
step = DFII_PIX_RDDATA_SIZE/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(p=0;p<DFII_NPHASES;p++)
|
|
|
|
for(i=first_byte;i<DFII_PIX_RDDATA_SIZE;i+=step)
|
|
|
|
printf("%02x", MMPTR(dfii_pix_rddata_addr[p]+4*i));
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void sdrrd(char *startaddr, char *dq)
|
2012-02-23 15:21:07 -05:00
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
unsigned int addr;
|
2014-09-01 02:58:58 -04:00
|
|
|
int _dq;
|
2012-02-23 15:21:07 -05:00
|
|
|
|
|
|
|
if(*startaddr == 0) {
|
2014-05-23 15:31:26 -04:00
|
|
|
printf("sdrrd <address>\n");
|
2012-02-23 15:21:07 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr = strtoul(startaddr, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect address\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-09-01 02:58:58 -04:00
|
|
|
if(*dq == 0)
|
|
|
|
_dq = -1;
|
|
|
|
else {
|
|
|
|
_dq = strtoul(dq, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect DQ\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-02-23 15:21:07 -05:00
|
|
|
|
2013-07-09 13:41:28 -04:00
|
|
|
dfii_pird_address_write(addr);
|
|
|
|
dfii_pird_baddress_write(0);
|
|
|
|
command_prd(DFII_COMMAND_CAS|DFII_COMMAND_CS|DFII_COMMAND_RDDATA);
|
2012-02-23 15:21:07 -05:00
|
|
|
cdelay(15);
|
2014-09-01 02:58:58 -04:00
|
|
|
sdrrdbuf(_dq);
|
2012-02-23 15:21:07 -05:00
|
|
|
}
|
|
|
|
|
2014-09-01 03:23:37 -04:00
|
|
|
void sdrrderr(char *count)
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
int _count;
|
|
|
|
int i, j, p;
|
|
|
|
unsigned char prev_data[DFII_NPHASES*DFII_PIX_RDDATA_SIZE];
|
|
|
|
unsigned char errs[DFII_PIX_RDDATA_SIZE/2];
|
|
|
|
|
|
|
|
if(*count == 0) {
|
|
|
|
printf("sdrrderr <count>\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_count = strtoul(count, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect count\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dfii_pird_address_write(0);
|
|
|
|
dfii_pird_baddress_write(0);
|
|
|
|
command_prd(DFII_COMMAND_CAS|DFII_COMMAND_CS|DFII_COMMAND_RDDATA);
|
|
|
|
cdelay(15);
|
|
|
|
for(p=0;p<DFII_NPHASES;p++)
|
|
|
|
for(i=0;i<DFII_PIX_RDDATA_SIZE;i++)
|
|
|
|
prev_data[p*DFII_PIX_RDDATA_SIZE+i] = MMPTR(dfii_pix_rddata_addr[p]+4*i);
|
|
|
|
for(i=0;i<DFII_PIX_RDDATA_SIZE/2;i++)
|
|
|
|
errs[i] = 0;
|
|
|
|
|
|
|
|
for(j=0;j<_count;j++) {
|
|
|
|
command_prd(DFII_COMMAND_CAS|DFII_COMMAND_CS|DFII_COMMAND_RDDATA);
|
|
|
|
cdelay(15);
|
|
|
|
for(p=0;p<DFII_NPHASES;p++)
|
|
|
|
for(i=0;i<DFII_PIX_RDDATA_SIZE;i++) {
|
|
|
|
unsigned char new_data;
|
|
|
|
|
|
|
|
new_data = MMPTR(dfii_pix_rddata_addr[p]+4*i);
|
|
|
|
errs[i%(DFII_PIX_RDDATA_SIZE/2)] |= prev_data[p*DFII_PIX_RDDATA_SIZE+i] ^ new_data;
|
|
|
|
prev_data[p*DFII_PIX_RDDATA_SIZE+i] = new_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=0;i<DFII_PIX_RDDATA_SIZE/2;i++)
|
|
|
|
printf("%02x ", errs[i]);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2014-05-23 15:31:26 -04:00
|
|
|
void sdrwr(char *startaddr)
|
2012-02-23 15:21:07 -05:00
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
unsigned int addr;
|
|
|
|
int i;
|
2014-08-08 07:23:57 -04:00
|
|
|
int p;
|
2012-02-23 15:21:07 -05:00
|
|
|
|
|
|
|
if(*startaddr == 0) {
|
2014-05-23 15:31:26 -04:00
|
|
|
printf("sdrrd <address>\n");
|
2012-02-23 15:21:07 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr = strtoul(startaddr, &c, 0);
|
|
|
|
if(*c != 0) {
|
|
|
|
printf("incorrect address\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-08-08 07:23:57 -04:00
|
|
|
|
2014-08-08 09:57:58 -04:00
|
|
|
for(p=0;p<DFII_NPHASES;p++)
|
|
|
|
for(i=0;i<DFII_PIX_WRDATA_SIZE;i++)
|
2014-08-08 07:23:57 -04:00
|
|
|
MMPTR(dfii_pix_wrdata_addr[p]+4*i) = 0x10*p + i;
|
2012-02-23 15:21:07 -05:00
|
|
|
|
2013-07-09 13:41:28 -04:00
|
|
|
dfii_piwr_address_write(addr);
|
|
|
|
dfii_piwr_baddress_write(0);
|
|
|
|
command_pwr(DFII_COMMAND_CAS|DFII_COMMAND_WE|DFII_COMMAND_CS|DFII_COMMAND_WRDATA);
|
2012-02-23 15:21:07 -05:00
|
|
|
}
|
|
|
|
|
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;
|
2013-02-24 10:51:03 -05:00
|
|
|
unsigned int error_cnt;
|
2012-05-15 13:29:26 -04:00
|
|
|
|
|
|
|
prv = 0;
|
|
|
|
for(i=0;i<TEST_SIZE/4;i++) {
|
|
|
|
prv = 1664525*prv + 1013904223;
|
|
|
|
array[i] = prv;
|
|
|
|
}
|
|
|
|
|
|
|
|
prv = 0;
|
2013-02-24 10:51:03 -05:00
|
|
|
error_cnt = 0;
|
2012-05-15 13:29:26 -04:00
|
|
|
for(i=0;i<TEST_SIZE/4;i++) {
|
|
|
|
prv = 1664525*prv + 1013904223;
|
|
|
|
if(array[i] != prv)
|
2013-02-24 10:51:03 -05:00
|
|
|
error_cnt++;
|
2012-05-15 13:29:26 -04:00
|
|
|
}
|
2013-02-24 10:51:03 -05:00
|
|
|
return error_cnt;
|
2012-05-15 13:29:26 -04:00
|
|
|
}
|
|
|
|
|
2013-02-24 10:51:03 -05:00
|
|
|
int memtest(void)
|
2012-05-15 13:29:26 -04:00
|
|
|
{
|
2013-02-24 10:51:03 -05:00
|
|
|
unsigned int e;
|
|
|
|
|
|
|
|
e = memtest_silent();
|
|
|
|
if(e != 0) {
|
|
|
|
printf("Memtest failed: %d/%d words incorrect\n", e, TEST_SIZE/4);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
printf("Memtest OK\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2012-05-15 13:29:26 -04:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:31:26 -04:00
|
|
|
int sdrinit(void)
|
2012-02-17 12:47:04 -05:00
|
|
|
{
|
2014-05-23 15:31:26 -04:00
|
|
|
printf("Initializing SDRAM...\n");
|
2012-02-17 12:47:04 -05:00
|
|
|
|
|
|
|
init_sequence();
|
2014-08-08 09:57:42 -04:00
|
|
|
dfii_control_write(DFII_CONTROL_SEL);
|
2013-02-24 10:51:03 -05:00
|
|
|
if(!memtest())
|
2012-05-15 13:29:26 -04:00
|
|
|
return 0;
|
2012-02-17 12:47:04 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2013-11-24 17:50:09 -05:00
|
|
|
|
|
|
|
#endif
|