From: Stefan E. <se...@us...> - 2004-02-19 13:48:20
|
Update of /cvsroot/blob/blob/src/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26940 Modified Files: cf.c Log Message: fixes to use new PCMCIA module Index: cf.c =================================================================== RCS file: /cvsroot/blob/blob/src/lib/cf.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- cf.c 10 May 2002 15:41:16 -0000 1.5 +++ cf.c 19 Feb 2004 13:37:53 -0000 1.6 @@ -43,32 +43,32 @@ /********************************************************************** * defines */ -#define CF_DEBUG 1 +#undef CF_DEBUG /* define this to activate module test cmd */ -#define CF_TEST_MODULE 0 +#define CF_TEST_MODULE -#if CF_DEBUG -# define DBG( x, args... ) if ( cf_dbg>x ) printf( args ); +#ifdef CF_DEBUG +# define _DBG( x, fmt, args... ) do { if ( dbg>=x ) printf( "%s: " fmt "\n", __FUNCTION__, ## args ); }while(0) +# define _DBGERR( x, code ) do { if ( dbg>=x ) printf( "%s(%d): ERROR %d.\n", __FUNCTION__, __LINE__, code ); ret = code; goto DONE; } while(0) #else -# define DBG( x, args... ) +# define _DBG( x, fmt, args... ) do { } while(0) +# define _DBGERR( x, code ) do { ret = code; goto DONE; } while(0) #endif /********************************************************************** * module globals */ #if CF_DEBUG -static int cf_dbg = 1; +static int dbg = 1; #else -static int cf_dbg = 0; +static int dbg = 0; #endif static char module_version[] = "$Id$"; /* static atm. Do we need more than one CF card? */ -static int cf_slot = 1; -static u32 cf_slot_base = 0L; -static u32 cf_slot_attr = 0L; +static int cf_slot = 1; static ide_drive_t drive; /********************************************************************** @@ -85,104 +85,77 @@ /* set debug level */ void cf_dbg_set( int lvl ) { - cf_dbg = lvl; + dbg = lvl; } /***************************************************************** - * cf_init - initialize CF card plugged in slot <slot> + * cf_init - initialize CF card plugged in socket <sock> */ int cf_init( int slot ) { int ret = 0; - u16 cfg_reg; + struct pcmcia_sock *sock = NULL; + u16 cfg_reg; u8 cfgvalue; u8 value; - DBG( 1, "%s: %s\n", __FUNCTION__, module_version ); - - ret = pcmcia_init(); - if ( ret != 0 ) - return -EINVAL; - - if ( cf_dbg > 10 ) { - pcmcia_dbg_set( 5 ); - ide_dbg_set( 5 ); - } - - ret = pcmcia_slot_detect( slot ); - if ( !ret ) - return -EINVAL; - - printf( "cf: slot %d detected\n", slot ); - - ret = pcmcia_slot_enable( slot ); - if ( ret ) - return -EINVAL; - - ret = pcmcia_slot_address_get( slot, &cf_slot_base, &cf_slot_attr ); - if ( ret ) - return -EINVAL; + _DBG( 1, "%s: %s\n", __FUNCTION__, module_version ); - ret = pcmcia_slot_reset( slot ); - if ( ret ) - return -EINVAL; + ret = pcmcia_sock_get( slot, &sock ); + if ( ret ) _DBGERR( dbg, ret ); - ret = pcmcia_cis_parse( slot ); - if ( ret ) - return -EINVAL; + ret = pcmcia_sock_reset( sock ); + if ( ret ) _DBGERR( dbg, ret ); - ret = pcmcia_slot_cfg_reg_get( slot, &cfg_reg ); - if ( ret ) - return -EINVAL; - DBG( 2, "cf: slot %d config register: 0x%03x\n", slot, cfg_reg ); + cfg_reg = sock->config_base; + _DBG( 2, "sock %d config register: 0x%03x", slot, cfg_reg ); - pcmcia_slot_attr_read( slot, CF_REG_CFG, &cfgvalue ); - DBG( 2, "slot %d config register: 0x%02x = 0x%02x\n", slot, CF_REG_CFG, cfgvalue ); + pcmcia_sock_attr_read( slot, cfg_reg + CF_REG_CFG, &cfgvalue ); + _DBG( 2, "sock %d config register: 0x%02x = 0x%02x", slot, CF_REG_CFG, cfgvalue ); - pcmcia_slot_attr_read( slot, CF_REG_CFGSTAT, &value ); - DBG( 2, "slot %d config status register: 0x%02x = 0x%02x\n", slot, CF_REG_CFGSTAT, value ); + pcmcia_sock_attr_read( slot, cfg_reg + CF_REG_CFGSTAT, &value ); + _DBG( 2, "sock %d config status register: 0x%02x = 0x%02x", slot, CF_REG_CFGSTAT, value ); /* reset CF card */ - pcmcia_slot_attr_write( slot, CF_REG_CFG, cfgvalue | CF_CFG_SRST ); + pcmcia_sock_attr_write( slot, cfg_reg + 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 ); - DBG( 2, "slot %d config register: 0x%02x = 0x%02x\n", slot, CF_REG_CFG, cfgvalue ); + pcmcia_sock_attr_write( slot, cfg_reg + CF_REG_CFG, cfgvalue & (~CF_CFG_SRST) ); + pcmcia_sock_attr_read( slot, cfg_reg + CF_REG_CFG, &cfgvalue ); + _DBG( 2, "sock %d config register: 0x%02x = 0x%02x", 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 ); - DBG( 2, "slot %d config register: 0x%02x = 0x%02x\n", slot, CF_REG_CFG, cfgvalue ); + pcmcia_sock_attr_write( slot, cfg_reg + CF_REG_CFG, cfgvalue | CF_CFG_IO_IDE0 ); + pcmcia_sock_attr_read( slot, cfg_reg + CF_REG_CFG, &cfgvalue ); + _DBG( 2, "sock %d config register: 0x%02x = 0x%02x", slot, CF_REG_CFG, cfgvalue ); - pcmcia_slot_attr_read( slot, CF_REG_CFGSTAT, &value ); - DBG( 2, "slot %d config status register: 0x%02x = 0x%02x\n", slot, CF_REG_CFGSTAT, value ); + pcmcia_sock_attr_read( slot, cfg_reg + CF_REG_CFGSTAT, &value ); + _DBG( 2, "sock %d config status register: 0x%02x = 0x%02x", slot, CF_REG_CFGSTAT, value ); - DBG( 2, "slot %d enabled\n", slot ); + _DBG( 2, "sock %d enabled", slot ); - ret = ide_init( &drive, (u32)cf_slot_base ); - if ( ret ) - return -EINVAL; + /* FIXME the code below should be moved away */ + ret = ide_init( &drive, (u32)sock->io_base ); + if ( ret ) _DBGERR( dbg, ret ); ret = ide_reset( &drive ); + if ( ret ) _DBGERR( dbg, ret ); ret = ide_identify_drive( &drive ); - if ( ret ) - return -EINVAL; + if ( ret ) _DBGERR( dbg, ret ); ret = ide_setfeature( &drive, IDE_FEAT_8BITON, 0 ); - if ( ret ) - return -EINVAL; + if ( ret ) _DBGERR( dbg, ret ); ret = ide_setfeature( &drive, IDE_FEAT_IOMODE, IDE_IOM_PIO ); - if ( ret ) - return -EINVAL; + if ( ret ) _DBGERR( dbg, ret ); ret = ide_status_dump( &drive ); - if ( ret ) - return -EINVAL; + if ( ret ) _DBGERR( dbg, ret ); - return 0; + ret = 0; +DONE: + return ret; } /********************************************************************** @@ -209,8 +182,9 @@ int cf_io_init( io_driver_t *io ) { - DBG( 5, "%s: io=%p\n", __FUNCTION__, io ); + _DBG( 5, "%s: io=%p\n", __FUNCTION__, io ); + io->flags = GIO_FLAG_R; io->conf = cf_io_conf; io->read = cf_io_read; io->write = cf_io_write; @@ -229,14 +203,14 @@ { int ret; - DBG( 5, "%s: io=%p, conf=%p\n", __FUNCTION__, + _DBG( 5, "%s: io=%p, conf=%p\n", __FUNCTION__, io, conf ); if ( !io || !conf ) return -EINVAL; cf_slot = (int)conf; - DBG( 5, "%s: cf_slot=%d\n", __FUNCTION__, cf_slot ); + _DBG( 5, "%s: cf_slot=%d\n", __FUNCTION__, cf_slot ); ret = cf_init( cf_slot ); if ( ret ) @@ -246,7 +220,7 @@ /* FIXME: is this ok? How to calculate the correct size? */ io->io_size = (drive.driveid.vendor1 | (drive.driveid.vendor0 << 16)) * IDE_BLOCK_SIZE; - DBG( 1, "%s: io_size=%d\n", __FUNCTION__, io_get_size( io ) ); + _DBG( 1, "%s: io_size=%d\n", __FUNCTION__, io_get_size( io ) ); return 0; } @@ -268,7 +242,7 @@ /* start offset (in-block-offset)*/ start_off = (u32)src - start_block*IDE_BLOCK_SIZE; - DBG( 1, "%s: start_block=%d, start_off=%d, src=%p, dest=%p, amount=%d\n", + _DBG( 1, "%s: start_block=%d, start_off=%d, src=%p, dest=%p, amount=%d\n", __FUNCTION__, start_block, start_off, src, dest, amount ); block = start_block; @@ -279,7 +253,7 @@ if ( ret != 0 ) return -EINVAL; - if ( cf_dbg>5 ) { + if ( dbg>5 ) { ret = ide_status_dump( &drive ); if ( ret ) return -EINVAL; @@ -296,7 +270,7 @@ to_copy = amount; } - DBG( 15, "%s: block=%d, to_copy=%d, amount=%d\n", + _DBG( 15, "%s: block=%d, to_copy=%d, amount=%d\n", __FUNCTION__, block, to_copy, amount ); /* copy data */ @@ -319,46 +293,34 @@ return -EINVAL; } - /********************************************************************** * Module test */ -#if defined(CF_TEST_MODULE) -int cf_test_module( int argc, char *argv[] ) +#ifdef CF_TEST_MODULE +int test_cf_cmd( int argc, char *argv[] ) { int ret; - static io_driver_t cf_def_io; - char buffer[1024]; + int slot = 1; /* this is a debug command. be verbose. */ cf_dbg_set( 100 ); - - /* init default cf drv */ - ret = cf_io_init( &cf_def_io ); - if ( ret ) { - DBG( 1, "%s: cf_io_init: %d\n", __FUNCTION__, ret ); - return ret; - } - - ret = io_register( &cf_def_io, "CF" ); - if ( ret ) { - DBG( 1, "%s: cf_io_register: %d\n", __FUNCTION__, ret ); - return ret; - } + ide_dbg_set( 100 ); + pcmcia_dbg_set( 100 ); - ret = io_configure( "CF", (void *)1 ); - if ( ret ) { - DBG( 1, "%s: cf_io_configure: %d\n", __FUNCTION__, ret ); - return ret; - } + if ( argc > 1 ) + strtou32( argv[1], &slot ); - ret = io_read( buffer, (unsigned char *)256, 512, &cf_def_io ); - if ( ret ) { - DBG( 1, "%s: io_read: %d\n", __FUNCTION__, ret ); - return ret; - } + printf( "CF Test\n" ); + printf( "-------\n" ); + printf( "\n" ); + printf( "Slot: %d\n", slot ); - return 0; + ret = cf_init( slot ); + if ( ret ) _DBGERR( dbg, ret ); + +DONE: + return ret; } char cf_help[] = "cf test function\n"; +__commandlist(test_cf_cmd, "cf_test", cf_help ); #endif |