1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-26 05:02:28 +02:00

cleanup the copyright

Signed-off-by: Xiangfu Liu <xiangfu.z@gmail.com>
This commit is contained in:
Xiangfu Liu 2009-07-09 23:27:46 +08:00
parent 0ecb32a9bc
commit 603032264a
23 changed files with 148 additions and 187 deletions

View File

@ -6,12 +6,26 @@ It was downloaded from <http://github.com/xiangfu/xburst-tools>
Upstream Author: Xiangfu Liu <xiangfu@qi-hardware.com> Upstream Author: Xiangfu Liu <xiangfu@qi-hardware.com>
The Debian packaging is copyright 2009, xiangfu <xiangfu@qi-hardware.com> and The Debian packaging is copyright 2009,
is licensed under the GPL, see `/usr/share/common-licenses/GPL-3'. Xiangfu Liu<xiangfu@qi-hardware.com> and
Marek Lindner <lindner_marek@yahoo.de>
Wolfgang Spraul <wolfgang@qi-hardware.com>
Ingenic Semiconductor Inc.
Seeger Chin <seeger.chin@gmail.com>
Michael Anburaj <michaelanburaj@hotmail.com>
Ralf Baechle
Silicon Graphics, Inc.
Paul M. Antoine
Kevin D. Kissell <kevink@mips.com>
Carsten Langgaard <carstenl@mips.com>
MIPS Technologies, Inc.
Maciej W. Rozycki
Lucifer at Ingenic Semiconductor Inc.
is licensed under the GPL, see `/usr/share/common-licenses/GPL'.
You are free to distribute this software under the terms of You are free to distribute this software under the terms of
the GNU General Public License either version 3 of the License, the GNU General Public License either version 3 of the License,
or (at your option) any later version. or (at your option) any later version.
On Debian systems, the complete text of the GNU General Public On Debian systems, the complete text of the GNU General Public
License can be found in the file `/usr/share/common-licenses/GPL-3'. License can be found in the file `/usr/share/common-licenses/GPL'.

View File

@ -83,7 +83,7 @@ binary-arch: install
dh_testroot dh_testroot
dh_installchangelogs ChangeLog dh_installchangelogs ChangeLog
dh_installdocs dh_installdocs
dh_installexamples # dh_installexamples
# dh_install # dh_install
# dh_installmenu # dh_installmenu
# dh_installdebconf # dh_installdebconf

View File

@ -1,7 +1,7 @@
/* /*
* device board * device board
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* Include file for Ingenic Semiconductor's JZ4740 CPU. * Include file for Ingenic Semiconductor's JZ4740 CPU.
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* Include file for Ingenic Semiconductor's JZ4750 CPU. * Include file for Ingenic Semiconductor's JZ4750 CPU.
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* "Ingenic flash tool" - flash the Ingenic CPU via USB * "Ingenic flash tool" - flash the Ingenic CPU via USB
* *
* Copyright (C) 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* device board * device board
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* Board init routines. * Board init routines.
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* device board * device board
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* device board * device board
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -4,7 +4,7 @@
* Entry point of the firmware. * Entry point of the firmware.
* The firmware code are executed in the ICache. * The firmware code are executed in the ICache.
* *
* (C) Copyright 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* Main routine of the firmware. * Main routine of the firmware.
* *
* Copyright (C) 2009 * Copyright 2009 (C) Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,7 +1,7 @@
/* /*
* USB_BOOT Handle routines * USB_BOOT Handle routines
* *
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -26,11 +26,9 @@ _start:
.word 0x0 .word 0x0
real_start: real_start:
//---------------------------------------------------- /* setup stack, jump to C code */
// setup stack, jump to C code add $29, $20, 0x3ffff0 // sp locate at start address offset 0x2ffff0
//---------------------------------------------------- add $25, $20, 0x40 // t9 = usb_main()
add $29, $20, 0x3ffff0 // sp locate at start address offset 0x2ffff0
add $25, $20, 0x40 // t9 = usb_main()
j $25 j $25
nop nop

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 QI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, * Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA * Boston, MA 02110-1301, USA
*/ */
#include "nandflash.h" #include "nandflash.h"
#include "jz4740.h" #include "jz4740.h"
#include "usb_boot.h" #include "usb_boot.h"
@ -68,7 +69,6 @@ static volatile unsigned char *cmdport = (volatile unsigned char *)0xb8008000;
static int bus = 8, row = 2, pagesize = 2048, oobsize = 64, ppb = 128; static int bus = 8, row = 2, pagesize = 2048, oobsize = 64, ppb = 128;
static int bad_block_pos,bad_block_page,force_erase,ecc_pos,wp_pin; static int bad_block_pos,bad_block_page,force_erase,ecc_pos,wp_pin;
extern struct hand Hand; extern struct hand Hand;
//static u8 data_buf[2048] = {0};
static u8 oob_buf[256] = {0}; static u8 oob_buf[256] = {0};
extern u16 handshake_PKT[4]; extern u16 handshake_PKT[4];
@ -92,7 +92,8 @@ static inline void __nand_sync(void)
static void select_chip(int block) static void select_chip(int block)
{ {
int t; int t;
if (!Hand.nand_bpc) return; if (!Hand.nand_bpc)
return;
t = (block / Hand.nand_bpc) % 4; t = (block / Hand.nand_bpc) % 4;
addrport = (volatile unsigned char *)(EMC_CSN[t] + 0x10000); addrport = (volatile unsigned char *)(EMC_CSN[t] + 0x10000);
dataport = (volatile unsigned char *)EMC_CSN[t]; dataport = (volatile unsigned char *)EMC_CSN[t];
@ -109,27 +110,28 @@ static int (*read_proc)(char *, int) = NULL;
static nand_init_gpio(void) static nand_init_gpio(void)
{ {
//modify this fun to a specifical borad /* modify this fun to a specifical borad
//this fun init those gpio use by all flash chip * this fun init those gpio use by all flash chip
//select the gpio function related to flash chip * select the gpio function related to flash chip
*/
__gpio_as_nand(); __gpio_as_nand();
} }
inline void nand_enable_4740(unsigned int csn) inline void nand_enable_4740(unsigned int csn)
{ {
//modify this fun to a specifical borad /* modify this fun to a specifical borad
//this fun to enable the chip select pin csn * this fun to enable the chip select pin csn
//the choosn chip can work after this fun * the choosn chip can work after this fun
//dprintf("\n Enable chip select :%d",csn); */
__nand_enable(); __nand_enable();
} }
inline void nand_disable_4740(unsigned int csn) inline void nand_disable_4740(unsigned int csn)
{ {
//modify this fun to a specifical borad /* modify this fun to a specifical borad
//this fun to enable the chip select pin csn * this fun to enable the chip select pin csn
//the choosn chip can not work after this fun * the choosn chip can not work after this fun
//dprintf("\n Disable chip select :%d",csn); */
__nand_disable(); __nand_disable();
} }
@ -162,7 +164,6 @@ int nand_init_4740(int bus_width, int row_cycle, int page_size, int page_per_blo
ecc_pos = ep; ecc_pos = ep;
wp_pin = Hand.nand_wppin; wp_pin = Hand.nand_wppin;
// nand_enable(0);
/* Initialize NAND Flash Pins */ /* Initialize NAND Flash Pins */
if (wp_pin) if (wp_pin)
{ {
@ -218,47 +219,42 @@ u32 nand_read_oob_4740(void *buf, u32 startpage, u32 pagenum)
static int nand_check_block(u32 block) static int nand_check_block(u32 block)
{ {
u32 pg,i; u32 pg,i;
if ( bad_block_page >= ppb ) {
if ( bad_block_page >= ppb ) //do absolute bad block detect! /* do absolute bad block detect! */
{
pg = block * ppb + 0; pg = block * ppb + 0;
read_oob(oob_buf, oobsize, pg); read_oob(oob_buf, oobsize, pg);
if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff ) { if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff )
serial_puts("Absolute skip a bad block\n"); goto bad;
return 1;
}
pg = block * ppb + 1; pg = block * ppb + 1;
read_oob(oob_buf, oobsize, pg); read_oob(oob_buf, oobsize, pg);
if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff ) { if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff )
serial_puts("Absolute skip a bad block\n"); goto bad;
return 1;
}
pg = block * ppb + ppb - 2 ; pg = block * ppb + ppb - 2 ;
read_oob(oob_buf, oobsize, pg); read_oob(oob_buf, oobsize, pg);
if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff ) { if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff )
serial_puts("Absolute skip a bad block\n"); goto bad;
return 1;
}
pg = block * ppb + ppb - 1 ; pg = block * ppb + ppb - 1 ;
read_oob(oob_buf, oobsize, pg); read_oob(oob_buf, oobsize, pg);
if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff ) { if ( oob_buf[0] != 0xff || oob_buf[1] != 0xff )
serial_puts("Absolute skip a bad block\n"); goto bad;
return 1;
}
} else { } else {
pg = block * ppb + bad_block_page; pg = block * ppb + bad_block_page;
read_oob(oob_buf, oobsize, pg); read_oob(oob_buf, oobsize, pg);
if (oob_buf[bad_block_pos] != 0xff) { if (oob_buf[bad_block_pos] != 0xff)
serial_puts("Skip a bad block\n"); goto bad;
return 1;
}
} }
return 0; return 0;
bad:
serial_puts("Absolute skip a bad block\n");
return 1;
} }
/* /*
@ -280,7 +276,7 @@ u32 nand_read_raw_4740(void *buf, u32 startpage, u32 pagecount, int option)
select_chip(cnt / ppb); select_chip(cnt / ppb);
if ((cur_page % ppb) == 0) { if ((cur_page % ppb) == 0) {
if (nand_check_block(cur_page / ppb)) { if (nand_check_block(cur_page / ppb)) {
cur_page += ppb; // Bad block, set to next block cur_page += ppb; //Bad block, set to next block
continue; continue;
} }
} }
@ -327,10 +323,8 @@ u32 nand_erase_4740(int blk_num, int sblk, int force)
for (i = 0; i < blk_num; ) { for (i = 0; i < blk_num; ) {
rowaddr = cur; rowaddr = cur;
select_chip(cur / ppb); select_chip(cur / ppb);
if ( !force ) if ( !force ) {
{ if (nand_check_block(cur/ppb)) {
if (nand_check_block(cur/ppb))
{
cur += ppb; cur += ppb;
blk_num += Hand.nand_plane; blk_num += Hand.nand_plane;
continue; continue;
@ -347,8 +341,7 @@ u32 nand_erase_4740(int blk_num, int sblk, int force)
__nand_sync(); __nand_sync();
__nand_cmd(CMD_READ_STATUS); __nand_cmd(CMD_READ_STATUS);
if (__nand_data8() & 0x01) if (__nand_data8() & 0x01) {
{
serial_puts("Erase fail at "); serial_puts("Erase fail at ");
serial_put_hex(cur / ppb); serial_put_hex(cur / ppb);
nand_mark_bad_4740(cur/ppb); nand_mark_bad_4740(cur/ppb);
@ -452,7 +445,7 @@ u32 nand_read_4740(void *buf, u32 startpage, u32 pagecount, int option)
if ((cur_page % ppb) == 0) { if ((cur_page % ppb) == 0) {
cur_blk = cur_page / ppb; cur_blk = cur_page / ppb;
if (nand_check_block(cur_blk)) { if (nand_check_block(cur_blk)) {
cur_page += ppb; // Bad block, set to next block cur_page += ppb; //Bad block, set to next block
continue; continue;
} }
} }
@ -524,19 +517,19 @@ u32 nand_read_4740(void *buf, u32 startpage, u32 pagecount, int option)
} }
switch (option) { switch (option) {
case OOB_ECC: case OOB_ECC:
for (j = 0; j < oobsize; j++) for (j = 0; j < oobsize; j++)
tmpbuf[j] = oob_buf[j]; tmpbuf[j] = oob_buf[j];
tmpbuf += oobsize; tmpbuf += oobsize;
break; break;
case OOB_NO_ECC: case OOB_NO_ECC:
for (j = 0; j < ecccnt * PAR_SIZE; j++) for (j = 0; j < ecccnt * PAR_SIZE; j++)
oob_buf[ecc_pos + j] = 0xff; oob_buf[ecc_pos + j] = 0xff;
for (j = 0; j < oobsize; j++) for (j = 0; j < oobsize; j++)
tmpbuf[j] = oob_buf[j]; tmpbuf[j] = oob_buf[j];
tmpbuf += oobsize; tmpbuf += oobsize;
break; break;
case NO_OOB: case NO_OOB:
break; break;
} }
@ -811,4 +804,3 @@ static int nand_data_read16(char *buf, int count)
*p++ = __nand_data16(); *p++ = __nand_data16();
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2009 PI * Copyright (C) 2009 Qi Hardware Inc.,
* Author: Xiangfu Liu <xiangfu@qi-hardware.com> * Author: Xiangfu Liu <xiangfu@qi-hardware.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -26,14 +26,14 @@
u32 Bulk_in_buf[BULK_IN_BUF_SIZE]; u32 Bulk_in_buf[BULK_IN_BUF_SIZE];
u32 Bulk_out_buf[BULK_OUT_BUF_SIZE]; u32 Bulk_out_buf[BULK_OUT_BUF_SIZE];
u32 Bulk_in_size,Bulk_in_finish,Bulk_out_size; u32 Bulk_in_size, Bulk_in_finish, Bulk_out_size;
u16 handshake_PKT[4]={0,0,0,0}; u16 handshake_PKT[4] = {0, 0, 0, 0};
u8 udc_state; u8 udc_state;
static u32 rx_buf[32]; static u32 rx_buf[32];
static u32 tx_buf[32]; static u32 tx_buf[32];
static u32 tx_size, rx_size, finished,fifo; static u32 tx_size, rx_size, finished, fifo;
static u8 ep0state,USB_Version; static u8 ep0state, USB_Version;
static u32 fifoaddr[] = static u32 fifoaddr[] =
{ {
@ -93,30 +93,24 @@ static void udcWriteFifo(u8 *ptr, int size)
void HW_SendPKT(int ep, const u8 *buf, int size) void HW_SendPKT(int ep, const u8 *buf, int size)
{ {
// dprintf("EP%d send pkt :%d\n", ep, size);
fifo = fifoaddr[ep]; fifo = fifoaddr[ep];
if (ep!=0) if (ep!=0) {
{
Bulk_in_size = size; Bulk_in_size = size;
Bulk_in_finish = 0; Bulk_in_finish = 0;
jz_writeb(USB_REG_INDEX, ep); jz_writeb(USB_REG_INDEX, ep);
if (Bulk_in_size - Bulk_in_finish <= fifosize[ep]) if (Bulk_in_size - Bulk_in_finish <= fifosize[ep]) {
{
udcWriteFifo((u8 *)((u32)buf+Bulk_in_finish), udcWriteFifo((u8 *)((u32)buf+Bulk_in_finish),
Bulk_in_size - Bulk_in_finish); Bulk_in_size - Bulk_in_finish);
usb_setb(USB_REG_INCSR, USB_INCSR_INPKTRDY); usb_setb(USB_REG_INCSR, USB_INCSR_INPKTRDY);
Bulk_in_finish = Bulk_in_size; Bulk_in_finish = Bulk_in_size;
} else } else {
{
udcWriteFifo((u8 *)((u32)buf+Bulk_in_finish), udcWriteFifo((u8 *)((u32)buf+Bulk_in_finish),
fifosize[ep]); fifosize[ep]);
usb_setb(USB_REG_INCSR, USB_INCSR_INPKTRDY); usb_setb(USB_REG_INCSR, USB_INCSR_INPKTRDY);
Bulk_in_finish += fifosize[ep]; Bulk_in_finish += fifosize[ep];
} }
} } else {
else //EP0
{
tx_size = size; tx_size = size;
finished = 0; finished = 0;
memcpy((void *)tx_buf, buf, size); memcpy((void *)tx_buf, buf, size);
@ -126,7 +120,6 @@ void HW_SendPKT(int ep, const u8 *buf, int size)
void HW_GetPKT(int ep, const u8 *buf, int size) void HW_GetPKT(int ep, const u8 *buf, int size)
{ {
// dprintf("EP%d read pkt :%d\n", ep, size);
memcpy((void *)buf, (u8 *)rx_buf, size); memcpy((void *)buf, (u8 *)rx_buf, size);
fifo = fifoaddr[ep]; fifo = fifoaddr[ep];
if (rx_size > size) if (rx_size > size)
@ -209,21 +202,20 @@ static struct {
void sendDevDescString(int size) void sendDevDescString(int size)
{ {
u16 str_ret[13] = { u16 str_ret[13] = {
0x031a,//0x1a=26 byte 0x031a,//0x1a=26 byte
0x0041, 0x0041,
0x0030, 0x0030,
0x0030, 0x0030,
0x0041, 0x0041,
0x0030, 0x0030,
0x0030, 0x0030,
0x0041, 0x0041,
0x0030, 0x0030,
0x0030, 0x0030,
0x0041, 0x0041,
0x0030, 0x0030,
0x0030 0x0030
}; };
// dprintf("sendDevDescString size = %d\r\n",size);
if(size >= 26) if(size >= 26)
size = 26; size = 26;
str_ret[0] = (0x0300 | size); str_ret[0] = (0x0300 | size);
@ -269,7 +261,6 @@ void EP0_init(u32 out, u32 out_size, u32 in, u32 in_size)
static void udc_reset(void) static void udc_reset(void)
{ {
u8 byte; u8 byte;
//data init
ep0state = USB_EP0_IDLE; ep0state = USB_EP0_IDLE;
Bulk_in_size = 0; Bulk_in_size = 0;
Bulk_in_finish = 0; Bulk_in_finish = 0;
@ -282,7 +273,6 @@ static void udc_reset(void)
// REG_CPM_SCR |= CPM_SCR_USBPHY_ENABLE; // REG_CPM_SCR |= CPM_SCR_USBPHY_ENABLE;
/* Disable interrupts */ /* Disable interrupts */
byte=jz_readb(USB_REG_POWER); byte=jz_readb(USB_REG_POWER);
// dprintf("\nREG_POWER: %02x",byte);
jz_writew(USB_REG_INTRINE, 0); jz_writew(USB_REG_INTRINE, 0);
jz_writew(USB_REG_INTROUTE, 0); jz_writew(USB_REG_INTROUTE, 0);
jz_writeb(USB_REG_INTRUSBE, 0); jz_writeb(USB_REG_INTRUSBE, 0);
@ -301,9 +291,7 @@ static void udc_reset(void)
jz_writeb(USB_REG_INTRUSBE,0x4); jz_writeb(USB_REG_INTRUSBE,0x4);
byte=jz_readb(USB_REG_POWER); byte=jz_readb(USB_REG_POWER);
// dprintf("\nREG_POWER: %02x",byte); if ((byte&0x10)==0) {
if ((byte&0x10)==0)
{
jz_writeb(USB_REG_INDEX,1); jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_INMAXP,64); jz_writew(USB_REG_INMAXP,64);
jz_writew(USB_REG_INCSR,0x2048); jz_writew(USB_REG_INCSR,0x2048);
@ -313,9 +301,7 @@ static void udc_reset(void)
USB_Version=USB_FS; USB_Version=USB_FS;
fifosize[1]=64; fifosize[1]=64;
EP0_init(1,64,1,64); EP0_init(1,64,1,64);
} } else {
else
{
jz_writeb(USB_REG_INDEX,1); jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_INMAXP,512); jz_writew(USB_REG_INMAXP,512);
jz_writew(USB_REG_INCSR,0x2048); jz_writew(USB_REG_INCSR,0x2048);
@ -336,8 +322,7 @@ void usbHandleStandDevReq(u8 *buf)
switch (dreq->bRequest) { switch (dreq->bRequest) {
case GET_DESCRIPTOR: case GET_DESCRIPTOR:
if (dreq->bmRequestType == 0x80) /* Dev2Host */ if (dreq->bmRequestType == 0x80) /* Dev2Host */
switch(dreq->wValue >> 8) switch(dreq->wValue >> 8) {
{
case DEVICE_DESCRIPTOR: case DEVICE_DESCRIPTOR:
dprintf("get device\n"); dprintf("get device\n");
sendDevDesc(dreq->wLength); sendDevDesc(dreq->wLength);
@ -351,7 +336,6 @@ void usbHandleStandDevReq(u8 *buf)
HW_SendPKT(0, "\x04\x03", 2); HW_SendPKT(0, "\x04\x03", 2);
else else
sendDevDescString(dreq->wLength); sendDevDescString(dreq->wLength);
//HW_SendPKT(0, "\x04\x03\x09\x04", 2);
break; break;
} }
dprintf("\nSet ep0state=TX!"); dprintf("\nSet ep0state=TX!");
@ -408,28 +392,22 @@ void usbHandleVendorReq(u8 *buf)
case VR_NOR_OPS: case VR_NOR_OPS:
ret_state=NOR_OPS_Handle(buf); ret_state=NOR_OPS_Handle(buf);
Bulk_out_size = 0; Bulk_out_size = 0;
//Bulk_in_size = 0;
break; break;
case VR_NAND_OPS: case VR_NAND_OPS:
NAND_OPS_Handle(buf); NAND_OPS_Handle(buf);
Bulk_out_size = 0; Bulk_out_size = 0;
//Bulk_in_size = 0;
//handshake_PKT[3]=(u16)ret_state;
//HW_SendPKT(0,handshake_PKT,sizeof(handshake_PKT));
break; break;
case VR_CONFIGRATION: case VR_CONFIGRATION:
ret_state=CONFIGRATION_Handle(buf); ret_state=CONFIGRATION_Handle(buf);
handshake_PKT[3]=(u16)ret_state; handshake_PKT[3]=(u16)ret_state;
HW_SendPKT(1,(u8 *)handshake_PKT,sizeof(handshake_PKT)); HW_SendPKT(1,(u8 *)handshake_PKT,sizeof(handshake_PKT));
Bulk_out_size = 0; Bulk_out_size = 0;
//Bulk_in_size = 0;
break; break;
case VR_SDRAM_OPS: case VR_SDRAM_OPS:
SDRAM_OPS_Handle(buf); SDRAM_OPS_Handle(buf);
Bulk_out_size = 0; Bulk_out_size = 0;
break; break;
} }
// serial_puts("get here! \n");
} }
void Handshake_PKT() void Handshake_PKT()
@ -445,7 +423,6 @@ void Handshake_PKT()
void usbHandleDevReq(u8 *buf) void usbHandleDevReq(u8 *buf)
{ {
// dprintf("dev req:%d\n", (buf[0] & (3 << 5)) >> 5);
switch ((buf[0] & (3 << 5)) >> 5) { switch ((buf[0] & (3 << 5)) >> 5) {
case 0: /* Standard request */ case 0: /* Standard request */
usbHandleStandDevReq(buf); usbHandleStandDevReq(buf);
@ -460,16 +437,15 @@ void usbHandleDevReq(u8 *buf)
void EP0_Handler () void EP0_Handler ()
{ {
u8 byCSR0; u8 byCSR0;
/* Read CSR0 */ /* Read CSR0 */
jz_writeb(USB_REG_INDEX, 0); jz_writeb(USB_REG_INDEX, 0);
byCSR0 = jz_readb(USB_REG_CSR0); byCSR0 = jz_readb(USB_REG_CSR0);
/* Check for SentStall /* Check for SentStall
if sendtall is set ,clear the sendstall bit*/ * if sendtall is set ,clear the sendstall bit */
if (byCSR0 & USB_CSR0_SENTSTALL) if (byCSR0 & USB_CSR0_SENTSTALL) {
{
jz_writeb(USB_REG_CSR0, (byCSR0 & ~USB_CSR0_SENDSTALL)); jz_writeb(USB_REG_CSR0, (byCSR0 & ~USB_CSR0_SENDSTALL));
ep0state = USB_EP0_IDLE; ep0state = USB_EP0_IDLE;
dprintf("\nSentstall!"); dprintf("\nSentstall!");
@ -477,18 +453,15 @@ void EP0_Handler ()
} }
/* Check for SetupEnd */ /* Check for SetupEnd */
if (byCSR0 & USB_CSR0_SETUPEND) if (byCSR0 & USB_CSR0_SETUPEND) {
{
jz_writeb(USB_REG_CSR0, (byCSR0 | USB_CSR0_SVDSETUPEND)); jz_writeb(USB_REG_CSR0, (byCSR0 | USB_CSR0_SVDSETUPEND));
ep0state = USB_EP0_IDLE; ep0state = USB_EP0_IDLE;
dprintf("\nSetupend!"); dprintf("\nSetupend!");
return; return;
} }
/* Call relevant routines for endpoint 0 state */ /* Call relevant routines for endpoint 0 state */
if (ep0state == USB_EP0_IDLE) if (ep0state == USB_EP0_IDLE) {
{ if (byCSR0 & USB_CSR0_OUTPKTRDY) { //There are datas in fifo
if (byCSR0 & USB_CSR0_OUTPKTRDY) //There are datas in fifo
{
USB_DeviceRequest *dreq; USB_DeviceRequest *dreq;
fifo=fifoaddr[0]; fifo=fifoaddr[0];
udcReadFifo((u8 *)rx_buf, sizeof(USB_DeviceRequest)); udcReadFifo((u8 *)rx_buf, sizeof(USB_DeviceRequest));
@ -505,26 +478,22 @@ void EP0_Handler ()
dreq->wLength); dreq->wLength);
#endif #endif
usbHandleDevReq((u8 *)rx_buf); usbHandleDevReq((u8 *)rx_buf);
} else } else {
{
dprintf("0:R DATA\n"); dprintf("0:R DATA\n");
} }
rx_size = 0; rx_size = 0;
} }
if (ep0state == USB_EP0_TX) if (ep0state == USB_EP0_TX) {
{
fifo=fifoaddr[0]; fifo=fifoaddr[0];
if (tx_size - finished <= 64) if (tx_size - finished <= 64) {
{
udcWriteFifo((u8 *)((u32)tx_buf+finished), udcWriteFifo((u8 *)((u32)tx_buf+finished),
tx_size - finished); tx_size - finished);
finished = tx_size; finished = tx_size;
usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY); usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY);
usb_setb(USB_REG_CSR0, USB_CSR0_DATAEND); //Set dataend! usb_setb(USB_REG_CSR0, USB_CSR0_DATAEND); //Set dataend!
ep0state=USB_EP0_IDLE; ep0state=USB_EP0_IDLE;
} else } else {
{
udcWriteFifo((u8 *)((u32)tx_buf+finished), 64); udcWriteFifo((u8 *)((u32)tx_buf+finished), 64);
usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY); usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY);
finished += 64; finished += 64;
@ -538,20 +507,17 @@ void EPIN_Handler(u8 EP)
jz_writeb(USB_REG_INDEX, EP); jz_writeb(USB_REG_INDEX, EP);
fifo = fifoaddr[EP]; fifo = fifoaddr[EP];
if (Bulk_in_size-Bulk_in_finish==0) if (Bulk_in_size-Bulk_in_finish==0) {
{
Handshake_PKT(); Handshake_PKT();
return; return;
} }
if (Bulk_in_size - Bulk_in_finish <= fifosize[EP]) if (Bulk_in_size - Bulk_in_finish <= fifosize[EP]) {
{
udcWriteFifo((u8 *)((u32)Bulk_in_buf+Bulk_in_finish), udcWriteFifo((u8 *)((u32)Bulk_in_buf+Bulk_in_finish),
Bulk_in_size - Bulk_in_finish); Bulk_in_size - Bulk_in_finish);
usb_setw(USB_REG_INCSR, USB_INCSR_INPKTRDY); usb_setw(USB_REG_INCSR, USB_INCSR_INPKTRDY);
Bulk_in_finish = Bulk_in_size; Bulk_in_finish = Bulk_in_size;
} else } else {
{
udcWriteFifo((u8 *)((u32)Bulk_in_buf+Bulk_in_finish), udcWriteFifo((u8 *)((u32)Bulk_in_buf+Bulk_in_finish),
fifosize[EP]); fifosize[EP]);
usb_setw(USB_REG_INCSR, USB_INCSR_INPKTRDY); usb_setw(USB_REG_INCSR, USB_INCSR_INPKTRDY);
@ -577,45 +543,39 @@ void udc4740Proc ()
volatile u16 IntrIn; volatile u16 IntrIn;
volatile u16 IntrOut; volatile u16 IntrOut;
/* Read interrupt registers */ /* Read interrupt registers */
// while(1) IntrUSB = jz_readb(USB_REG_INTRUSB);
// { IntrIn = jz_readw(USB_REG_INTRIN);
IntrUSB = jz_readb(USB_REG_INTRUSB); IntrOut = jz_readw(USB_REG_INTROUT);
IntrIn = jz_readw(USB_REG_INTRIN);
IntrOut = jz_readw(USB_REG_INTROUT);
if ( IntrUSB == 0 && IntrIn == 0 && IntrOut == 0) if ( IntrUSB == 0 && IntrIn == 0 && IntrOut == 0)
return; return;
if (IntrIn & 2) if (IntrIn & 2) {
{ dprintf("\nUDC EP1 IN operation!");
dprintf("\nUDC EP1 IN operation!"); EPIN_Handler(1);
EPIN_Handler(1); }
}
if (IntrOut & 2) if (IntrOut & 2) {
{ dprintf("\nUDC EP1 OUT operation!");
dprintf("\nUDC EP1 OUT operation!"); EPOUT_Handler(1);
EPOUT_Handler(1); }
}
if (IntrUSB & USB_INTR_RESET) if (IntrUSB & USB_INTR_RESET) {
{ dprintf("\nUDC reset intrupt!");
dprintf("\nUDC reset intrupt!"); udc_reset();
udc_reset(); }
}
/* Check for endpoint 0 interrupt */ /* Check for endpoint 0 interrupt */
if (IntrIn & USB_INTR_EP0) if (IntrIn & USB_INTR_EP0) {
{ dprintf("\nUDC EP0 operations!");
dprintf("\nUDC EP0 operations!"); EP0_Handler();
EP0_Handler(); }
}
if (USB_Version == USB_FS) if (USB_Version == USB_FS)
IntrIn = jz_readw(USB_REG_INTRIN); IntrIn = jz_readw(USB_REG_INTRIN);
// }
return; return;
} }
//unsigned int g_stack[2049];
void usb_main() void usb_main()
{ {
u8 byte; u8 byte;
@ -633,14 +593,11 @@ void usb_main()
finished = 0; finished = 0;
byte=jz_readb(USB_REG_POWER); byte=jz_readb(USB_REG_POWER);
if ((byte&0x10)==0) if ((byte&0x10)==0) {
{
USB_Version=USB_FS; USB_Version=USB_FS;
fifosize[1]=64; fifosize[1]=64;
EP0_init(1,64,1,64); EP0_init(1,64,1,64);
} } else {
else
{
USB_Version=USB_HS; USB_Version=USB_HS;
fifosize[1]=512; fifosize[1]=512;
EP0_init(1,512,1,512); EP0_init(1,512,1,512);