From: Stefan E. <se...@us...> - 2002-04-24 14:27:24
|
Update of /cvsroot/blob/blob/src/lib In directory usw-pr-cvs1:/tmp/cvs-serv18840 Modified Files: ide.c pcmcia.c Log Message: - first round of bugfixing. Now at last one can read 512 byte sectors of a CF in true-ide mode. See system3.c::pcmciatest(). Still WIP. YMMV, and so on.... Index: ide.c =================================================================== RCS file: /cvsroot/blob/blob/src/lib/ide.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ide.c 18 Apr 2002 19:52:49 -0000 1.1 +++ ide.c 24 Apr 2002 14:27:08 -0000 1.2 @@ -22,6 +22,12 @@ * $Id$ * * $Log$ + * Revision 1.2 2002/04/24 14:27:08 seletz + * - first round of bugfixing. Now at last one can read 512 byte sectors + * of a CF in true-ide mode. See system3.c::pcmciatest(). + * + * Still WIP. YMMV, and so on.... + * * Revision 1.1 2002/04/18 19:52:49 seletz * - Added PCMCIA and IDE framework. Based on Brad Parker's code. * NOTE NOTE NOTE: @@ -93,13 +99,18 @@ * Exported functions */ +void ide_dbg_set( int level ) +{ + dbg = level; +} + /********************************************************************** * ide_init * * - Initialize ide drive struct * - calculatees and sets HD_PORT and HD_REG_RORT from a base address */ -int ide_init( ide_drive_t *drive, u32 *base_addr ) +int ide_init( ide_drive_t *drive, u32 base_addr ) { if ( !base_addr ) return -1; @@ -115,6 +126,9 @@ drive->ide_reg = (u8 *)(base_addr + HD_REG_PORT); drive->last_status = 0; + _DBG( "%s: ide_port=%p\n", __FUNCTION__, drive->ide_port ); + _DBG( "%s: ide_reg=%p\n", __FUNCTION__, drive->ide_reg ); + return 0; } @@ -206,7 +220,7 @@ ide_fixstring (id->model, sizeof(id->model), 1); - printf("ide: model: %s\n", id->model); + printf("ide: model: '%s'\n", id->model); printf("ide: CHS: %d/%d/%d\n", id->cyls, id->heads, id->sectors); if (id->sectors && id->heads) { @@ -389,6 +403,7 @@ } status = port[7]; + _DBG( "%s: status=0x%02x\n", __FUNCTION__, status ); if (status & ERROR) { printf("ide: identify status: %2x\n", status); Index: pcmcia.c =================================================================== RCS file: /cvsroot/blob/blob/src/lib/pcmcia.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pcmcia.c 18 Apr 2002 19:52:49 -0000 1.1 +++ pcmcia.c 24 Apr 2002 14:27:08 -0000 1.2 @@ -23,6 +23,12 @@ * $Id$ * * $Log$ + * Revision 1.2 2002/04/24 14:27:08 seletz + * - first round of bugfixing. Now at last one can read 512 byte sectors + * of a CF in true-ide mode. See system3.c::pcmciatest(). + * + * Still WIP. YMMV, and so on.... + * * Revision 1.1 2002/04/18 19:52:49 seletz * - Added PCMCIA and IDE framework. Based on Brad Parker's code. * NOTE NOTE NOTE: @@ -52,7 +58,8 @@ */ #define WEAK_SYM __attribute__ (( weak )) -#define MEM(adr) (*((u32 *)adr)) +#define MEM(adr) (*((u32 *)(adr))) +#define MEMb(adr) (*((u16 *)(adr))) #define SET(reg,bit) ((reg) |= (1<<(bit))) #define CLR(reg,bit) ((reg) &= ~(1<<(bit))) @@ -67,16 +74,14 @@ /********************************************************************** * Typen */ -typedef unsigned char uchar; - typedef struct { u16 status; int vcc; int vpp; u32 attr_base; u32 base; - volatile uchar *ident; - volatile uchar *feature_p[PCMCIA_MAX_FEATURES]; + volatile u8 *ident; + volatile u8 *feature_p[PCMCIA_MAX_FEATURES]; int n_features; u16 config_base; } pcmcia_slot_t; @@ -116,7 +121,7 @@ /********************************************************************** * Prototypen */ -static int pcmcia_print_fixed(volatile uchar *p); +static int pcmcia_print_fixed(volatile u8 *p); static int pcmcia_print_funcid(int func); /********************************************************************** @@ -317,7 +322,7 @@ } printf("%s\n", id_str); - return (0); /* don't know */ + return (1); /* don't know */ } /* parse cis tuples of card in slot <slot> */ @@ -325,17 +330,17 @@ { int ret = 0; void *cfg_mem_addr = NULL; - volatile uchar *ident = NULL; - volatile uchar *p = NULL; - volatile uchar *start = NULL; + volatile u8 *ident = NULL; + volatile u8 *p = NULL; + volatile u8 *start = NULL; int n_features = 0; - uchar func_id = ~0; - uchar len = 0; - uchar code = 0; + u8 func_id = ~0; + u8 len = 0; + u8 code = 0; u16 config_base = 0; int found = 0; int i = 0; - volatile uchar **feature_p; + volatile u8 **feature_p; /* sanity check */ if ( slot < 0 ) { @@ -363,7 +368,7 @@ if (dbg > 0) printf("PCMCIA MEM: %p\n", cfg_mem_addr); - start = p = (volatile uchar *)cfg_mem_addr; + start = p = (volatile u8 *)cfg_mem_addr; while ((p - start) < PCMCIA_MAX_TUPEL_SZ) { @@ -374,8 +379,8 @@ } len = *p; p += 2; - if (dbg > 1) { - volatile uchar *q = p; + if (dbg > 10) { + volatile u8 *q = p; printf ("\nTuple code %2x length %d\n\tData:", code, len); @@ -388,9 +393,11 @@ switch (code) { case CISTPL_VERS_1: ident = p + 4; + _DBG( "%s: ident=%p\n", __FUNCTION__, ident ); break; case CISTPL_FUNCID: func_id = *p; + _DBG( "%s: func_id=%p\n", __FUNCTION__, func_id ); break; case CISTPL_FUNCE: if (n_features < PCMCIA_MAX_FEATURES) @@ -398,7 +405,8 @@ break; case CISTPL_CONFIG: config_base = (*(p+6) << 8) + (*(p+4)); - printf("\n## Config_base = %x ###\n", config_base); + pcmcia_slots[slot].config_base = config_base; + _DBG( "%s: config_base=%p\n", __FUNCTION__, config_base ); default: break; } @@ -407,7 +415,7 @@ found = pcmcia_identify( ident ); - if (func_id != ((uchar)~0)) { + if (func_id != ((u8)~0)) { pcmcia_print_funcid(func_id); if (func_id == CISTPL_FUNCID_FIXED) @@ -420,13 +428,13 @@ } } -#if 1 +#if 0 /* hmmm, should this happen here? * FIXME: provide extra function? */ #define COR_FUNC_ENA 0x01 /* set configuration option register to enable card */ - *((uchar *)(cfg_mem_addr + config_base)) = COR_FUNC_ENA; + *((u8 *)(cfg_mem_addr + config_base)) = COR_FUNC_ENA; #endif ret = 0; @@ -434,7 +442,7 @@ return ret; } -int pcmcia_slot_address_get( int slot, u32 **base, u32 **attr ) +int pcmcia_slot_address_get( int slot, u32 *base, u32 *attr ) { int ret = 0; @@ -457,8 +465,123 @@ goto DONE; } - if ( base ) *base = (u32 *)pcmcia_slots[slot].base; - if ( attr ) *attr = (u32 *)pcmcia_slots[slot].attr_base; + _DBG( "%s: base=%p\n", __FUNCTION__, pcmcia_slots[slot].base); + _DBG( "%s: attr_base=%p\n", __FUNCTION__, pcmcia_slots[slot].attr_base); + + if ( base ) *base = pcmcia_slots[slot].base; + if ( attr ) *attr = pcmcia_slots[slot].attr_base; + + ret = 0; +DONE: + return ret; +} + +int pcmcia_slot_cfg_reg_get( int slot, u16 *cfg_base ) +{ + int ret = 0; + + /* sanity check */ + if ( slot < 0 ) { + printf( "pcmcia: invalid slot slot %d\n", slot ); + ret = -1; + goto DONE; + } + if ( slot > PCMCIA_MAX_SLOTS ) { + printf( "pcmcia: invalid slot slot %d\n", slot ); + ret = -1; + goto DONE; + } + + if ( !( pcmcia_slots[slot].status & PCMCIA_SS_ENABLED ) || + !( pcmcia_slots[slot].status & PCMCIA_SS_DETECT )) { + printf( "pcmcia: slot %d not detected and enabled\n", slot ); + ret = -1; + goto DONE; + } + + _DBG( "%s: cfg_base=0x%03x\n", __FUNCTION__, pcmcia_slots[slot].config_base); + + if ( cfg_base ) *cfg_base = pcmcia_slots[slot].config_base; + + ret = 0; +DONE: + return ret; +} + +int pcmcia_slot_attr_read( int slot, u16 offset, u8 *value ) +{ + int ret = 0; + u32 attr_base = 0; + + /* sanity check */ + if ( slot < 0 ) { + printf( "pcmcia: invalid slot slot %d\n", slot ); + ret = -1; + goto DONE; + } + if ( slot > PCMCIA_MAX_SLOTS ) { + printf( "pcmcia: invalid slot slot %d\n", slot ); + ret = -1; + goto DONE; + } + if ( !value ) { + printf( "pcmcia: value==NULL\n" ); + ret = -1; + goto DONE; + } + + if ( !( pcmcia_slots[slot].status & PCMCIA_SS_ENABLED ) || + !( pcmcia_slots[slot].status & PCMCIA_SS_DETECT )) { + printf( "pcmcia: slot %d not detected and enabled\n", slot ); + ret = -1; + goto DONE; + } + + *value = MEMb( + pcmcia_slots[slot].attr_base + + pcmcia_slots[slot].config_base + + offset + ); + + _DBG( "%s: ATTR_REG(0x%02x) => 0x%02x\n", __FUNCTION__, + offset, *value ); + + ret = 0; +DONE: + return ret; +} + +int pcmcia_slot_attr_write( int slot, u16 offset, u8 value ) +{ + int ret = 0; + u32 attr_base = 0; + + /* sanity check */ + if ( slot < 0 ) { + printf( "pcmcia: invalid slot slot %d\n", slot ); + ret = -1; + goto DONE; + } + if ( slot > PCMCIA_MAX_SLOTS ) { + printf( "pcmcia: invalid slot slot %d\n", slot ); + ret = -1; + goto DONE; + } + + if ( !( pcmcia_slots[slot].status & PCMCIA_SS_ENABLED ) || + !( pcmcia_slots[slot].status & PCMCIA_SS_DETECT )) { + printf( "pcmcia: slot %d not detected and enabled\n", slot ); + ret = -1; + goto DONE; + } + + _DBG( "%s: ATTR_REG(0x%02x) <= 0x%02x\n", __FUNCTION__, + offset, value ); + + MEMb( pcmcia_slots[slot].attr_base + + pcmcia_slots[slot].config_base + + offset + ) = value; ret = 0; DONE: @@ -511,7 +634,7 @@ } /* print info for FIXED_DISK function type card */ -static int pcmcia_print_fixed(volatile uchar *p) +static int pcmcia_print_fixed(volatile u8 *p) { if (p == NULL) return -1; @@ -520,7 +643,7 @@ switch (*p) { case CISTPL_FUNCE_IDE_IFACE: - { uchar iface = *(p+2); + { u8 iface = *(p+2); printf((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown"); printf(" interface "); @@ -528,8 +651,8 @@ } case CISTPL_FUNCE_IDE_MASTER: case CISTPL_FUNCE_IDE_SLAVE: - { uchar f1 = *(p+2); - uchar f2 = *(p+4); + { u8 f1 = *(p+2); + u8 f2 = *(p+4); printf((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]"); |