From: Stefan E. <se...@us...> - 2002-04-24 14:34:31
|
Update of /cvsroot/blob/blob/src/blob In directory usw-pr-cvs1:/tmp/cvs-serv20791 Modified Files: system3.c Log Message: - pcmcia test funtion. reads first 10 sectors of an CF card. Yeah! - sysver command prints out system3 build id string - manually reference ferase/fwrite/dlfile commands - changed sa1111_init() to match recent kernels. - removed silly bug in MEM(). Index: system3.c =================================================================== RCS file: /cvsroot/blob/blob/src/blob/system3.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- system3.c 18 Apr 2002 19:55:34 -0000 1.11 +++ system3.c 24 Apr 2002 14:34:26 -0000 1.12 @@ -58,23 +58,15 @@ #define ERR( x ) { ret = x; goto DONE; } /* more readable IMHO */ -#define MEM( x ) (*((u32 *)x)) +#define MEM( x ) (*((u32 *)(x))) #define SET(reg,bit) ((reg) |= (1<<(bit))) #define RST(reg,bit) ((reg) &= ~(1<<(bit))) -#define mem_b(adr) ( ((volatile unsigned char*)0)[adr] ) -#define mem_w(adr) ( ((volatile unsigned short int*)0)[(adr)/2] ) -#define mem_dw(adr) ( ((volatile unsigned long*)(0)) [(adr)/4] ) - -#if 0 -#define GPDR (0x90040004) -#define GPSR (0x90040008) -#define GPCR (0x9004000c) -#define GAFR (0x9004001c) -#define TUCR (0x90030008) /* Test Unit Control Reg. */ -#endif - -#define CF_REG_CFG (0x200) +/***************************************************************** + * CF Flash register definitions + */ +/* config register - offset 0 */ +#define CF_REG_CFG (0x00) #define CF_CFG_SRST (0x80) #define CF_CFG_LVLREQ (0x40) #define CF_CFG_MMAP (0x00) @@ -82,7 +74,8 @@ #define CF_CFG_IO_IDE0 (0x02) #define CF_CFG_IO_IDE1 (0x03) -#define CF_REG_CFGSTAT (0x202) +/* config status register - offset 2 */ +#define CF_REG_CFGSTAT (0x02) #define SYSTEM3_DEBUG 1 @@ -96,7 +89,6 @@ */ extern blob_status_t blob_status; -static void sa1111_init(); /********************************************************************** * module globals @@ -119,15 +111,13 @@ /********************************************************************** * static functions */ +static char module_version[] = "$Id$"; +static void dumpmem(char *ptr, int len); +static char tohex(char b); +static void sa1111_init(); /********************************************************************* - * init_system3_flash - * - * AUTOR: SELETZ - * REVISED: - * - * inits system 3 flash driver - * + * init_system3_flash - inits system 3 flash driver */ static void init_system3_flash_driver(void) { @@ -136,6 +126,9 @@ } __initlist(init_system3_flash_driver, INIT_LEVEL_DRIVER_SELECTION); +/********************************************************************* + * system3_init_hardware - inits system 3 LL hardware stuff + */ static void system3_init_hardware(void) { /* init on-board CPLD */ @@ -143,18 +136,15 @@ MEM(SYSTEM3_CTRL_1) = 0x00; MEM(SYSTEM3_CTRL_2) = 0x00; -#if 0 /* activate SYSCLCK for keyboard controller */ - SET( MEM(GAFR), 27 ); - SET( MEM(GPDR), 27 ); + RST( MEM(TUCR), 31 ); + GAFR |= GPIO_32_768kHz; + GPDR |= GPIO_32_768kHz; /* 3.6864 MHz SYSCLK */ - SET( MEM(TUCR), 29 ); - RST( MEM(TUCR), 30 ); - RST( MEM(TUCR), 31 ); + TUCR = TUCR_3_6864MHz; msleep( 1 ); -#endif //sa1111_init(); @@ -170,72 +160,103 @@ } __initlist(system3_init_hardware, INIT_LEVEL_DRIVER_SELECTION); +/***************************************************************** + * sysver - print system version + */ +static int sysver_cmd( int argc, char *argv[] ) +{ + printf( "version: '%s'\n", module_version ); + return 0; +} +static char sysver_help[] = "print BLOB and system3 version number\n"; +__commandlist(sysver_cmd, "sysver", sysver_help); + +/***************************************************************** + * sa1111_init - initialize companion chip + */ static void sa1111_init() { _DBG( "%s", "START\n" ); - _DBG( "%s", "Switch on SYSCLCK 3.6864 MHz\n" ); - /* switch on clock for sa1111 */ + /* + * First, set up the 3.6864MHz clock on GPIO 27 for the SA-1111: + * (SA-1110 Developer's Manual, section 9.1.2.1) + */ GAFR |= GPIO_32_768kHz; GPDR |= GPIO_32_768kHz; TUCR = TUCR_3_6864MHz; - /* Now, set up the PLL and RCLK in the SA-1111: */ - SBI_SKCR = SKCR_PLL_BYPASS | SKCR_RDYEN | SKCR_OE_EN; - msleep(100); - SBI_SKCR = SKCR_PLL_BYPASS | SKCR_RCLKEN | SKCR_RDYEN | SKCR_OE_EN; + /* + * Turn VCO on, and disable PLL Bypass. + */ + SBI_SKCR &= ~SKCR_VCO_OFF; + SBI_SKCR |= SKCR_PLL_BYPASS | SKCR_OE_EN; - printf( "SA1111 ID: %08x\n", SBI_SKID ); + /* + * Wait lock time. SA1111 manual _doesn't_ + * specify a figure for this! We choose 100us. + */ + msleep(1); /* - * SA-1111 Register Access Bus should now be available. Clocks for - * any other SA-1111 functional blocks must be enabled separately - * using the SKPCR. + * Enable RCLK. We also ensure that RDYEN is set. */ - SKPCR |= SKPCR_DCLKEN | SKPCR_PWMCLKEN; + SBI_SKCR |= SKCR_RCLKEN | SKCR_RDYEN; /* - * If the system is going to use the SA-1111 DMA engines, set up - * the memory bus request/grant pins. Also configure the shared - * memory controller on the SA-1111 (SA-1111 Developer's Manual, - * section 3.2.3) and power up the DMA bus clock: + * Wait 14 RCLK cycles for the chip to finish coming out + * of reset. (RCLK=24MHz). This is 590ns. */ - GAFR |= (GPIO_MBGNT | GPIO_MBREQ); - GPDR |= GPIO_MBGNT; - GPDR &= ~GPIO_MBREQ; - TUCR |= TUCR_MR; + msleep(1); + + /* + * Ensure all clocks are initially off. + */ + SKPCR = 0; + + printf( "SA1111 ID: %08x\n", SBI_SKID ); - SBI_SMCR = (SMCR_DTIM | SMCR_MBGE | - FInsrt(FExtr(MDCNFG, MDCNFG_SA1110_DRAC0), SMCR_DRAC) | - ((FExtr(MDCNFG, MDCNFG_SA1110_TDL0)==3) ? SMCR_CLAT : 0)); _DBG( "%s", "DONE\n" ); } #if defined(CONFIG_PCMCIA_SUPPORT) +/***************************************************************** + * pcmcia_init - initialize PCMCIA + */ int pcmcia_init() { printf( "PT Digital Board PCMCIA init\n" ); - /* nothing to do ATM */ sa1111_init(); +#if SYSTEM3_DEBUG printf( "MECR=0x%08x\n", MECR ); printf( "MSC0=0x%08x\n", MSC0 ); printf( "MSC1=0x%08x\n", MSC1 ); printf( "MSC2=0x%08x\n", MSC2 ); + printf( "SA1111_BASE=0x%08x\n", SA1111_VBASE ); + printf( "SBI_SMCR=0x%08x\n", SBI_SMCR ); + printf( "SBI_SKID=0x%08x\n", SBI_SKID ); +#endif return 0; } + +/***************************************************************** + * pcmcia_test - test PCMCIA, CF and IDE + */ static int pcmcia_test( int argc, char *argv[] ) { int ret = 0; - int slot = 0; - u32 *slot_base; - u32 *slot_attr; + int slot = 1; /* default CF */ + u32 slot_base; + u32 slot_attr; u16 cfg_reg; ide_drive_t drive; int numDev; int sec; + u8 cfgvalue; + u8 value; unsigned char * devTypeStr[] = { "no device found", "unknown type", "ATA", "ATAPI" }; @@ -259,7 +280,7 @@ } pcmcia_dbg_set( 5 ); - //ide_dbg_set( 5 ); + ide_dbg_set( 5 ); ret = pcmcia_slot_detect( slot ); if ( !ret ) ERR( -EINVAL ); @@ -275,18 +296,39 @@ ret = pcmcia_slot_reset( slot ); if ( ret != 0 ) ERR( -EINVAL ); - mem_b( (u32)slot_attr + CF_REG_CFG ) = ( mem_b( (u32)slot_attr + CF_REG_CFG ) & 0xC0 ) | CF_CFG_IO_IDE0; - - printf( "CF CFG REG = 0x%x\n", mem_b( (u32)slot_attr + CF_REG_CFG ) ); - - printf( "slot %d enabled\n", slot ); - ret = pcmcia_cis_parse( slot ); if ( ret != 0 ) ERR( -EINVAL ); -#if 0 ret = pcmcia_slot_cfg_reg_get( slot, &cfg_reg ); if ( ret != 0 ) ERR( -EINVAL ); + printf( "slot %d config register: 0x%03x\n", slot, cfg_reg ); + + pcmcia_slot_attr_read( slot, CF_REG_CFG, &cfgvalue ); + printf( "slot %d config register: 0x%02x = 0x%02x\n", slot, CF_REG_CFG, cfgvalue ); + + pcmcia_slot_attr_read( slot, CF_REG_CFGSTAT, &value ); + printf( "slot %d config status register: 0x%02x = 0x%02x\n", slot, CF_REG_CFGSTAT, value ); + + /* reset CF card */ + pcmcia_slot_attr_write( slot, CF_REG_CFG, cfgvalue | CF_CFG_SRST ); + msleep(1); + pcmcia_slot_attr_write( slot, CF_REG_CFG, cfgvalue & (~CF_CFG_SRST) ); + pcmcia_slot_attr_read( slot, CF_REG_CFG, &cfgvalue ); + printf( "slot %d config register: 0x%02x = 0x%02x\n", slot, CF_REG_CFG, cfgvalue ); + + + /* configure for true ide mode */ + pcmcia_slot_attr_write( slot, CF_REG_CFG, cfgvalue | CF_CFG_IO_IDE0 ); + pcmcia_slot_attr_read( slot, CF_REG_CFG, &cfgvalue ); + printf( "slot %d config register: 0x%02x = 0x%02x\n", slot, CF_REG_CFG, cfgvalue ); + + pcmcia_slot_attr_read( slot, CF_REG_CFGSTAT, &value ); + printf( "slot %d config status register: 0x%02x = 0x%02x\n", slot, CF_REG_CFGSTAT, value ); + + printf( "slot %d enabled\n", slot ); + + //ret = pcmcia_slot_cfg_reg_get( slot, &cfg_reg ); + //if ( ret != 0 ) ERR( -EINVAL ); ret = ide_init( &drive, (u32)slot_base ); if ( ret != 0 ) ERR( -EINVAL ); @@ -299,6 +341,7 @@ ret = ide_status_dump( &drive ); if ( ret != 0 ) ERR( -EINVAL ); +#if 1 for ( sec=0; sec<10; sec++ ) { ret = hd_read_mapped( &drive, sec, buffer ); if ( ret != 0 ) ERR( -EINVAL ); @@ -356,153 +399,55 @@ __commandlist(pcmcia_test, "pcmciatest", pcmciahelp); #endif - -#if 0 -/********************************************************************* - * cmd_download_file - * - * AUTOR: SELETZ - * REVISED: - * - * Download a file to arbitary memory location - * +/***************************************************************** + * misc utility funcs */ -int cmd_download_file( int argc, char *argv[] ) +static char tohex(char b) { - int ret = 0; - u32 dest = 0L; - u32 len = 0L; - - if ( argc < 3 ) ERR( -EINVAL ); - - ret = strtou32( argv[1], &dest ); - if ( ret < 0 ) ERR( -EINVAL ); - - ret = strtou32( argv[2], &len ); - if ( ret < 0 ) ERR( -EINVAL ); - -#if defined(CONFIG_XMODEM_SUPPORT) - printf( "XMODEM download\n" ); -#else - printf( "UUENCODE download\n" ); -#endif - - if (blob_status.terminalSpeed != blob_status.downloadSpeed) { - SerialOutputString("Switching to download speed\n"); - SerialOutputString("You have 60 seconds to switch your terminal emulator to the same speed and\n"); - SerialOutputString("start downloading. After that " PACKAGE " will switch back to term speed.\n"); - - serial_init(blob_status.downloadSpeed); - } else { - SerialOutputString("You have 60 seconds to start downloading.\n"); - } -#if defined(CONFIG_XMODEM_SUPPORT) - ret = XModemReceive( (char *)dest, len ); -#else - ret = UUDecode((char *)dest, len); -#endif - if ( ret == len ) { - SerialOutputString("Received "); - SerialOutputDec(ret); - SerialOutputString(" (0x"); - SerialOutputHex(ret); - SerialOutputString(") bytes.\n"); - ret = 0; - } else { - SerialOutputString("error during download\n"); - } - - if (blob_status.terminalSpeed != blob_status.downloadSpeed) { - SerialOutputString("\n(Please switch your terminal emulator back to terminal speed\n"); - serial_init(blob_status.terminalSpeed); - } - -DONE: - return ret; + b = b & 0xf; + if (b < 10) return '0' + b; + return 'a' + (b - 10); } -static char downloadhelp[] = "dlfile destadr filelength\n" -"download file to memory\n"; -__commandlist( cmd_download_file, "dlfile", downloadhelp ); -/********************************************************************* - * cmd_flash_write - * - * AUTOR: SELETZ - * REVISED: - * - * Command wrapper for low-level flash write access - * - */ -static int cmd_flash_write( int argc, char *argv[] ) +static void dumpmem(char *ptr, int len) { - int ret = 0; - u32 src = 0L; - u32 dest = 0L; - u32 len = 0L; - - if ( argc < 4 ) ERR( -EINVAL ); - - ret = strtou32( argv[1], &src ); - if ( ret < 0 ) ERR( -EINVAL ); - - ret = strtou32( argv[2], &dest ); - if ( ret < 0 ) ERR( -EINVAL ); + char line[80], chars[80], *p, b, *c, *end; + int i, j; - ret = strtou32( argv[3], &len ); - if ( ret < 0 ) ERR( -EINVAL ); + end = ptr + len; + while (ptr < end) { + SerialOutputHex((int)ptr); + p = line; + c = chars; - if ( len & (0x3) ) { - len = (len>>2) + 1; - } else { - len = len>>2; + *p++ = ' '; + for (j = 0; j < 16; j++) { + b = *ptr++; + *p++ = tohex(b >> 4); + *p++ = tohex(b); + *p++ = ' '; + *c++ = ' ' <= b && b <= '~' ? b : '.'; } - - _DBGU32( src ); - _DBGU32( dest ); - _DBGU32( len ); - - ret = flash_write_region( (u32 *)dest, (u32*)src, len ); -DONE: - return ret; + *p = 0; + SerialOutputString(line); + *c = 0; + SerialOutputString(chars); + serial_write('\n'); + } } -static char flashwritehelp[] = "fwrite srcadr destadr size(bytes)\n" -"flash a memory region\n"; -__commandlist( cmd_flash_write, "fwrite", flashwritehelp ); -/********************************************************************* - * cmd_flash_erase - * - * AUTOR: SELETZ - * REVISED: - * - * Command wrapper for low-level flash erasing - * +/***************************************************************** + * manually reference flash and download commands until they + * are in libblob. */ -static int cmd_flash_erase( int argc, char *argv[] ) -{ - int ret = 0; - u32 dest = 0L; - u32 len = 0L; - - if ( argc < 3 ) ERR( -EINVAL ); - - ret = strtou32( argv[1], &dest ); - if ( ret < 0 ) ERR( -EINVAL ); - - ret = strtou32( argv[2], &len ); - if ( ret < 0 ) ERR( -EINVAL ); +extern int fwrite_cmd(int argc, char *argv[]); +extern char fwrite_help[]; +__commandlist(fwrite_cmd, "fwrite", fwrite_help); - if ( len & (0x3) ) { - len = (len>>2) + 1; - } else { - len = len>>2; - } +extern int ferase_cmd(int argc, char *argv[]); +extern char ferase_help[]; +__commandlist(ferase_cmd, "ferase", ferase_help); - ret = flash_erase_region( (u32 *)dest, len ); -DONE: - return ret; -} -static char flasherasehelp[] = "ferase adr size(bytes)\n" -"erase a flash region\n"; -__commandlist( cmd_flash_erase, "ferase", flasherasehelp ); -#endif +extern int dlfile_cmd(int argc, char *argv[]); +extern char dlfile_help[]; +__commandlist(dlfile_cmd, "dlfile", dlfile_help); |