Browse Source

fixup xhci spi write error

Change-Id: Ib6cdcb66d75698190f4766ac4085407565e61240
master
wuze 7 years ago
parent
commit
891ea68588
  1. 9
      Targets/Bonito3a3000_7a/Bonito/tgt_machdep.c
  2. 178
      Targets/Bonito3a3000_7a/dev/usb_spi.c

9
Targets/Bonito3a3000_7a/Bonito/tgt_machdep.c

@ -218,9 +218,7 @@ void initmips(unsigned int raw_memsz)
CPU_SetSR(0, SR_BOOT_EXC_VEC);
#endif
SBD_DISPLAY("BEV0",0);
#ifndef MULTI_CHIP
usb_spi_init();
#endif
printf("BEV in SR set to zero.\n");
main();
@ -259,6 +257,11 @@ void tgt_devconfig()
#endif
#endif
_pci_devinit(1); /* PCI device initialization */
#ifndef MULTI_CHIP
usb_spi_init();
#endif
#if (NMOD_X86EMU_INT10 > 0)||(NMOD_X86EMU >0)
if(pcie_dev != NULL){
SBD_DISPLAY("VGAI", 0);

178
Targets/Bonito3a3000_7a/dev/usb_spi.c

@ -20,20 +20,20 @@
int usb_spi_erase(void)
{
unsigned int tmp;
tmp = readl(FWDCS);
tmp &= (1 << 31);
if (!tmp) {
unsigned int tmp,times = 100000;
if (!(readl(FWDCS) & (1 << 31))) {
printf("no external rom exists!\n");
return -1;
return 1;
}
readl(DATA0) = 0x5a65726f;
readl(FWDCS) |= (1 << 17);
tmp = readl(FWDCS);
while ((tmp & (1 << 17))) {
tmp = readl(FWDCS);
while ((readl(FWDCS) & (1 << 17)) && times-- );
if (!times){
printf("erase error.\n");
return 1;
}
printf("erase down.\n");
return 0;
}
@ -42,20 +42,17 @@ int usb_spi_prepare(void)
{
unsigned int tmp;
tmp = readl(FWDCS);
tmp &= (1 << 31);
if (!tmp) {
if (!(readl(FWDCS) & (1 << 31))) {
printf("no external rom exists!\n");
return -1;
return 1;
}
readl(DATA0) = 0x53524f4d;
readl(FWDCS) |= (1 << 16);
tmp = readl(FWDCS);
tmp &= (7 << 20);
if (tmp & (2 << 20)) {
printf("result code error %x\n",tmp);
return -1;
if (readl(FWDCS) & (7 << 20) & (2 << 20)) {
printf("result code error %x\n",readl(FWDCS));
return 1;
}
return 0;
}
@ -63,21 +60,18 @@ int usb_spi_prepare(void)
int usb_spi_write(int size,unsigned int *spi_buf)
{
unsigned int *buf = spi_buf;
unsigned int tmp, times = 10000;
unsigned int tmp, times = 100000000;
usb_spi_prepare();
if (usb_spi_prepare())
return 1;
size /= 2;
tmp = readl(FWDCS);
tmp &= (1 << 24);
if (tmp) {
if (readl(FWDCS) & (1 << 24)) {
printf("set data0 status error.\n");
return 1;
}
readl(DATA0) = *buf++;
tmp = readl(FWDCS);
tmp &= (2 << 24);
if (tmp) {
if (readl(FWDCS) & (2 << 24)) {
printf("set data1 status error.\n");
return 1;
}
@ -85,84 +79,81 @@ int usb_spi_write(int size,unsigned int *spi_buf)
readl(FWDCS) |= (3 << 24);
size -= 1;
while(size--) {
tmp = readl(FWDCS);
while ((tmp & (1 << 24)) && times--) {
delay(10);
tmp = readl(FWDCS);
}
if (tmp & (1 << 24)) {
printf(">> set data0 status error. %x\n",tmp);
times = 100000000;
while ((readl(FWDCS) & (1 << 24)) && times--);
if (!times) {
printf(">> set data0 status error. \n");
return 1;
}
readl(DATA0) = *buf++;
readl(FWDCS) |= (1 << 24);
times = 10000;
tmp = readl(FWDCS);
while ((tmp & (2 << 24)) && times--) {
delay(10);
tmp = readl(FWDCS);
}
if (tmp & (2 << 24)) {
printf(">> set data0 status error. %x\n",tmp);
times = 100000000;
while ((readl(FWDCS) & (2 << 24)) && times--);
if (!times) {
printf(">> set data0 status error. \n");
return 1;
}
readl(DATA1) = *buf++;
readl(FWDCS) |= (2 << 24);
}
times = 100000000;
while ((readl(FWDCS) & (3 << 24)) && times--);
if (!times) {
printf("error\n");
return 1;
}
readl(FWDCS) &= ~(1 << 16);
times = 10000;
tmp = readl(FWDCS);
while (!(tmp & (1 << 20)) && times--) {
delay(10);
tmp = readl(FWDCS);
}
if (tmp & (2 << 20)) {
printf("write result code is %x\n",tmp);
times = 100000;
while (!(readl(FWDCS) & (1 << 20)) && times--);
if (!times) {
printf("write result code is %x\n",readl(FWDCS));
return 1;
}
printf("Fw write done.\n");
readl(FWDCS) |= (1 << 18);
times = 100000;
while (readl(FWDCS) & (1<< 18) && times--);
if (!times) {
printf("reload error \n");
return 1;
}
return size;
}
int usb_spi_read(int size,unsigned int *ret_buf)
{
unsigned int tmp, times = 100;
unsigned int tmp, times = 100000000;
unsigned int *buf = ret_buf;
usb_spi_prepare();
if (usb_spi_prepare()) {
return 1;
}
readl(FWDCS) |= (3 << 26);
size /= 2;
while(size--) {
tmp = readl(FWDCS);
while ((tmp & (1 << 26)) && times--) {
tmp = readl(FWDCS);
}
if (tmp & (1 << 26)) {
printf("get data0 now is %x\n",tmp);
return -1;
while ((readl(FWDCS) & (1 << 26)) && times--);
if (!times) {
printf("error get data0 now is %x\n",readl(FWDCS));
return 1;
}
*buf++ = readl(DATA0);
#ifdef USBSPI_DEBUG
tmp = readl(DATA0);
printf("0x%08x ",tmp);
printf("0x%08x ",readl(DATA0));
#endif
readl(FWDCS) |= (1 << 26);
tmp = readl(FWDCS);
times = 100;
while ((tmp & (2 << 26)) && times--) {
tmp = readl(FWDCS);
}
if (tmp & (2 << 26)) {
printf("get data1 now is %x\n",tmp);
return -1;
times = 100000000;
while ((readl(FWDCS) & (2 << 26)) && times--);
if (!times) {
printf("error get data1 now is %x\n",readl(FWDCS));
return 1;
}
*buf++ = readl(DATA1);
#ifdef USBSPI_DEBUG
tmp = readl(DATA1);
printf("0x%08x ",tmp);
printf("0x%08x ",readl(DATA1));
#endif
readl(FWDCS) |= (2 << 26);
#ifdef USBSPI_DEBUG
@ -170,7 +161,14 @@ int usb_spi_read(int size,unsigned int *ret_buf)
printf("\n");
#endif
}
readl(FWDCS) &= ~(1 << 16);
times = 100000000;
while ((readl(FWDCS) & (3 << 26)) && times--);
if (!times) {
printf("error\n");
return 1;
}
readl(FWDCS) &= ~(1 << 16);
return size;
}
@ -178,7 +176,6 @@ int usb_spi_init(void)
{
unsigned int ret_buf[20];
int i, size = 20;
i = usb_spi_read(size,ret_buf);
if (i != -1) {
printf("usb spi read error i = %d.\n",i);
@ -198,11 +195,44 @@ int usb_spi_init(void)
size = 3260;//FW size
usb_spi_write(size,usb_spi_buf);
}
else {
printf("usb firmware no error\n");
}
return 0;
}
int cmd_usb_spi_read(ac, av)
int ac;
char *av[];
{
unsigned int ret_buf[3260];
int i, size = 50;
size = (int) strtoul(av[1],0,0);
printf("size= %x \n",size);
if (size > 3260){
printf("max is 3260\n");
return 1;
}
if ((size % 2)){
printf("it must be even number\n");
return 1;
}
if (usb_spi_read(size,ret_buf) != -1) {
printf("usb spi read error.\n");
return 1;
}
for (i = 0;i < size;i++) {
printf(">> 0x%08x ",ret_buf[i]);
printf("-- 0x%08x ",usb_spi_buf[i]);
printf("\n");
}
}
static const Cmd Cmds[] = {
{"Misc"},
{"usb_spi_read", "", NULL, "read the usb spi data", usb_spi_read, 1, 5, 0},
{"usb_spi_read", "", NULL, "read the usb spi data", cmd_usb_spi_read, 1, 5, 0},
{"usb_spi_write", "", NULL, "read the usb spi data", usb_spi_write, 1, 5, 0},
{"usb_spi_erase", "", NULL, "read the usb spi data", usb_spi_erase, 1, 5, 0},
{"usb_spi_init", "", NULL, "read the usb spi data", usb_spi_init, 1, 5, 0},

Loading…
Cancel
Save