From: Stefan E. <se...@us...> - 2002-05-08 13:55:33
|
Update of /cvsroot/blob/blob/src/lib In directory usw-pr-cvs1:/tmp/cvs-serv16398 Modified Files: ide.c Log Message: - added ide_setfeature() to set ide features Index: ide.c =================================================================== RCS file: /cvsroot/blob/blob/src/lib/ide.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- ide.c 27 Apr 2002 04:59:59 -0000 1.4 +++ ide.c 8 May 2002 13:55:28 -0000 1.5 @@ -23,6 +23,9 @@ * $Id$ * * $Log$ + * Revision 1.5 2002/05/08 13:55:28 seletz + * - added ide_setfeature() to set ide features + * * Revision 1.4 2002/04/27 04:59:59 timriker * turn on ide and pcmcia again, fix pcmcia compiles (but not features) for non sa1111 systems * @@ -67,9 +70,9 @@ #define IDE_DEBUG 1 #ifdef IDE_DEBUG -# define _DBG( args... ) printf( args ) +# define DBG( x, args... ) if ( ide_dbg>x ) printf( args ); #else -# define _DBG( args... ) +# define DBG( x, args... ) #endif #define IDE_DELAY 10 @@ -88,9 +91,9 @@ static char *version = "$Id$"; #ifdef IDE_DEBUG -static int dbg = 1; +static int ide_dbg = 1; #else -static int dbg = 0; +static int ide_dbg = 0; #endif @@ -108,7 +111,7 @@ void ide_dbg_set( int level ) { - dbg = level; + ide_dbg = level; } /********************************************************************** @@ -125,16 +128,14 @@ if ( !drive ) return -1; - if ( dbg > 0 ) { - printf( "ide: %s\n", version ); - } + DBG( 1, "ide: %s\n", version ); drive->ide_port = (u8 *)(base_addr + HD_PORT); 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 ); + DBG( 1, "%s: ide_port=%p\n", __FUNCTION__, drive->ide_port ); + DBG( 1, "%s: ide_reg=%p\n", __FUNCTION__, drive->ide_reg ); return 0; } @@ -147,15 +148,22 @@ int ide_status_dump( ide_drive_t *drive ) { u8 status; - int i; if ( !drive || !drive->ide_port ) return -1; - for (i = 0; i < 8; i++) { - status = drive->ide_port[i]; - printf("port[ %d ] %x\n", i, status); - } + + status = drive->ide_port[7]; + printf( "ide: status[%s %s %s %s %s %s %s %s]\n", + status&BUSY ?"BSY":" ", + status&READY ?"RDY":" ", + status&WRITE_FAULT ?"DF ":" ", + status&SEEKOK ?"DSC":" ", + status&DATA_REQ ?"DRQ":" ", + status&CORRECTED ?"COR":" ", + status&REV_INDEX ?"IDX":" ", + status&ERROR ?"ERR":" " + ); return 0; } @@ -180,9 +188,11 @@ #if 1 /* reset hd controller */ - reg[0] = 0x04; + reg[0] = 0x06; + barrier(); msleep(IDE_DELAY); - reg[0] = 0x00; + reg[0] = 0x02; + barrier(); msleep(IDE_DELAY); #else msleep(5*IDE_DELAY); @@ -194,6 +204,7 @@ port[4] = 0; port[5] = 0; port[6] = 0xa0; + barrier(); msleep(IDE_DELAY); return 0; @@ -244,6 +255,39 @@ } /********************************************************************** + * ide_setfeature + * + * - set features + * + */ +int ide_setfeature( ide_drive_t *drive, unsigned char opcode, unsigned char param ) +{ + volatile u8 *port = NULL; + volatile u8 *reg = NULL; + + if ( !drive || !drive->ide_port ) + return -1; + + port = drive->ide_port; + reg = drive->ide_reg; + + DBG( 1, "%s: HDC_SETFEATURE( 0x%02x, 0x%02x )\n", __FUNCTION__, + opcode, param ); + + port[1] = opcode; + port[2] = param; + port[3] = 0; + port[4] = 0; + port[5] = 0; + port[6] = 0; + port[7] = HDC_SETFEATURE; + + hd_busy_wait(port); + + return 0; +} + +/********************************************************************** * hd_read * * - read head/sector/cyl of drive to a buffer. Reads 1 block (512 bytes) of @@ -274,8 +318,8 @@ hd_cmd[5] = (cyl >> 8) & 0xff; /* cylinder hi byte */ hd_cmd[6] = (hd_drive << 4) | (hd_head & 0x0f) | 0xa0; - if (dbg > 2) - printf("hd_read() h=%d s=%d c=%d\n", hd_head, hd_sector, hd_cyl); + DBG( 2, "%s: h=%d s=%d c=%d\n", __FUNCTION__, hd_head, hd_sector, + hd_cyl); #if 0 if (hd_head > 7) { @@ -290,16 +334,18 @@ hd_busy_wait(port); for (i = 1; i < 7; i++) { - hd_busy_wait(port); port[i] = hd_cmd[i]; + barrier(); } port[7] = HDC_READ; + barrier(); hd_busy_wait(port); for (i = 0; i < 512; i++) { buffer[i] = port[0]; + barrier(); } drive->last_status = status = port[7]; @@ -332,9 +378,8 @@ if ( !drive || !drive->ide_port ) return -1; - if (dbg > 2) - printf("hd_read_mapped(sector_num=%d, buffer=%x)\n", - sector_num, (u32)buffer); + DBG( 2, "%s: sector_num=%d, buffer=%p\n", __FUNCTION__, + sector_num, buffer); #if 0 sector = (sector_num % disk_sectors_per_track) + 1; @@ -371,7 +416,7 @@ _cyl = sector; - _DBG( "%s: => (h:%d, s:%d, c:%d)\n", __FUNCTION__, _head, _sec, _cyl ); + DBG( 1, "%s: => (h:%d, s:%d, c:%d)\n", __FUNCTION__, _head, _sec, _cyl ); if ( head ) *head = _head; if ( sec ) *sec = _sec; @@ -402,15 +447,17 @@ port[5] = 0; port[6] = 0xa0; port[7] = HDC_IDENTIFY; + barrier(); hd_busy_wait(port); for (i = 0; i < 512; i++) { + barrier(); buffer[i] = port[0]; } status = port[7]; - _DBG( "%s: status=0x%02x\n", __FUNCTION__, status ); + DBG( 1, "%s: status=0x%02x\n", __FUNCTION__, status ); if (status & ERROR) { printf("ide: identify status: %2x\n", status); @@ -441,9 +488,11 @@ for (i = 1; i < 7; i++) { hd_busy_wait(port); port[i] = hd_cmd[i]; + barrier(); } port[7] = HDC_RECAL; + barrier(); if (hd_busy_wait(port)) return -1; @@ -459,16 +508,18 @@ count = 0; while (count++ < 2500) { status = port[7]; + barrier(); if ((status & BUSY) == 0) break; msleep(1); } - _DBG( "ide: %s: port=%x, count=%d, status=%x\n", __FUNCTION__, - *port, count, status ); + DBG( 1, "%s: port=%p, count=%d, status=%02x\n", __FUNCTION__, + port, count, status ); - if (status & 0x01) { + if ( (status & ERROR) || (status & WRITE_FAULT) ) { err = port[1]; + barrier(); printf( "ide: busy_wait: err = %2x\n", err ); return -1; } |