From 26e25527db48296582a93bd0c3ecfb364bacd931 Mon Sep 17 00:00:00 2001 From: "Jordan K. Hubbard" Date: Sun, 16 Jan 1994 23:34:17 +0000 Subject: [PATCH] From Gary Clark II: 1. Fixed probe to work with FX mitsumi's. 2. Added some defines in prep for adding interupts and dma --- sys/dev/mcd/mcd.c | 104 ++++++++++++++---------------------------- sys/dev/mcd/mcdreg.h | 16 +++++-- sys/i386/isa/mcd.c | 104 ++++++++++++++---------------------------- sys/i386/isa/mcdreg.h | 16 +++++-- 4 files changed, 94 insertions(+), 146 deletions(-) diff --git a/sys/dev/mcd/mcd.c b/sys/dev/mcd/mcd.c index f4802bcc4439..2a690cb1e5b5 100644 --- a/sys/dev/mcd/mcd.c +++ b/sys/dev/mcd/mcd.c @@ -1,6 +1,7 @@ /* * Copyright 1993 by Holger Veit (data part) * Copyright 1993 by Brian Moore (audio part) + * Changes Copyright 1993 by Gary Clark II * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -68,7 +69,7 @@ static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore"; #undef MCD_TO_WARNING_ON #endif #else -#define MCD_TRACE(fmt,a,b,c,xd) {if (mcd_data[unit].debug) {printf("mcd%d st=%02x: ",unit,mcd_data[unit].status); printf(fmt,a,b,c,xd);}} +#define MCD_TRACE(fmt,a,b,c,d) {if (mcd_data[unit].debug) {printf("mcd%d st=%02x: ",unit,mcd_data[unit].status); printf(fmt,a,b,c,d);}} #endif #define mcd_part(dev) ((minor(dev)) & 7) @@ -158,7 +159,7 @@ static void hsg2msf(int hsg, bcd_t *msf); static int msf2hsg(bcd_t *msf); static int mcd_volinfo(int unit); static int mcd_waitrdy(int port,int dly); -static void mcd_doread(caddr_t, int); +static void mcd_doread(int state, struct mcd_mbx *mbxin); #ifndef MCDMINI static int mcd_setmode(int unit, int mode); static int mcd_getqchan(int unit, struct mcd_qchninfo *q); @@ -397,7 +398,7 @@ static void mcd_start(int unit) cd->mbx.p_offset = p->p_offset; /* calling the read routine */ - mcd_doread((caddr_t)MCD_S_BEGIN, (int)&(cd->mbx)); + mcd_doread(MCD_S_BEGIN,&(cd->mbx)); /* triggers mcd_start, when successful finished */ return; } @@ -540,14 +541,13 @@ static void mcd_configure(struct mcd_data *cd) outb(cd->iobase+mcd_config,cd->config); } -/* check if there is a cdrom */ -/* Heavly hacked by gclarkii@sugar.neosoft.com */ +/* check to see if a Mitsumi CD-ROM is attached to the ISA bus */ int mcd_probe(struct isa_device *dev) { int port = dev->id_iobase; int unit = dev->id_unit; - int i; + int i,j; int st; int check; int junk; @@ -562,72 +562,43 @@ int mcd_probe(struct isa_device *dev) #endif /* send a reset */ - outb(port+MCD_FLAGS,0); - DELAY(100000); - /* get any pending status and throw away...*/ - for (i=10; i != 0; i--) { + outb(port+MCD_FLAGS,M_RESET); + DELAY(30000); + + for (j=3; j != 0; j--) { + + /* get any pending garbage (old data) and throw away...*/ + for (i=10; i != 0; i--) { inb(port+MCD_DATA); - } - DELAY(1000); - - outb(port+MCD_DATA,MCD_CMDGETSTAT); /* Send get status command */ - - /* Loop looking for avail of status */ - /* XXX May have to increase for fast machinces */ - for (i = 1000; i != 0; i--) { - if ((inb(port+MCD_FLAGS) & 0xF ) == STATUS_AVAIL) { - break; - } - DELAY(10); - } - /* get status */ - - if (i == 0) { -#ifdef DEBUG - printf ("Mitsumi drive NOT detected\n"); -#endif - return 0; - } - -/* - * The following code uses the 0xDC command, it returns a M from the - * second byte and a number in the third. Does anyone know what the - * number is for? Better yet, how about someone thats REAL good in - * i80x86 asm looking at the Dos driver... Most of this info came - * from a friend of mine spending a whole weekend..... - */ + } DELAY (2000); outb(port+MCD_DATA,MCD_CMDCONTINFO); - for (i = 0; i < 100000; i++) { - if ((inb(port+MCD_FLAGS) & 0xF) == STATUS_AVAIL) - break; - } - if (i > 100000) { -#ifdef DEBUG - printf ("Mitsumi drive error\n"); -#endif - return 0; - } - DELAY (40000); - st = inb(port+MCD_DATA); - DELAY (500); - check = inb(port+MCD_DATA); - DELAY (500); - junk = inb(port+MCD_DATA); /* What is byte used for?!?!? */ - - if (check = 'M') { + for (i = 0; i < 300000; i++) { + if ((inb(port+MCD_FLAGS) & M_STATUS_AVAIL) == M_STATUS_AVAIL) + { + DELAY (4000); + st = inb(port+MCD_DATA); + DELAY (500); + check = inb(port+MCD_DATA); + DELAY (500); + junk = inb(port+MCD_DATA); /* What is byte used for?!?!? */ + + if (check = 'M') { #ifdef DEBUG printf("Mitsumi drive detected\n"); #endif return 4; - } else { + } else { printf("Mitsumi drive NOT detected\n"); - printf("Mitsumi drive error\n"); return 0; - } + } + } + } + } } + static int mcd_waitrdy(int port,int dly) { int i; @@ -811,13 +782,8 @@ mcdintr(unit) */ static struct mcd_mbx *mbxsave; -/* - * Good thing Alphas come with real CD players... - */ -static void mcd_doread(caddr_t xstate, int xmbxin) +static void mcd_doread(int state, struct mcd_mbx *mbxin) { - int state = (int)xstate; - struct mcd_mbx *mbxin = (struct mcd_mbx *)xmbxin; struct mcd_mbx *mbx = (state!=MCD_S_BEGIN) ? mbxsave : mbxin; int unit = mbx->unit; int port = mbx->port; @@ -841,7 +807,7 @@ static void mcd_doread(caddr_t xstate, int xmbxin) timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITSTAT,hz/100); /* XXX */ return; case MCD_S_WAITSTAT: - untimeout(mcd_doread, (caddr_t)MCD_S_WAITSTAT); + untimeout(mcd_doread,MCD_S_WAITSTAT); if (mbx->count-- >= 0) { if (inb(port+mcd_xfer) & MCD_ST_BUSY) { timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITSTAT,hz/100); /* XXX */ @@ -878,7 +844,7 @@ static void mcd_doread(caddr_t xstate, int xmbxin) } case MCD_S_WAITMODE: - untimeout(mcd_doread, (caddr_t)MCD_S_WAITMODE); + untimeout(mcd_doread,MCD_S_WAITMODE); if (mbx->count-- < 0) { #ifdef MCD_TO_WARNING_ON printf("mcd%d: timeout set mode\n",unit); @@ -916,7 +882,7 @@ static void mcd_doread(caddr_t xstate, int xmbxin) timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITREAD,hz/100); /* XXX */ return; case MCD_S_WAITREAD: - untimeout(mcd_doread,(caddr_t)MCD_S_WAITREAD); + untimeout(mcd_doread,MCD_S_WAITREAD); if (mbx->count-- > 0) { k = inb(port+mcd_xfer); if ((k & 2)==0) { diff --git a/sys/dev/mcd/mcdreg.h b/sys/dev/mcd/mcdreg.h index 83664a7674a0..c5c95d8c85e2 100644 --- a/sys/dev/mcd/mcdreg.h +++ b/sys/dev/mcd/mcdreg.h @@ -1,6 +1,7 @@ /* * Copyright 1993 by Holger Veit (data part) * Copyright 1993 by Brian Moore (audio part) + * Changes Copyright 1993 by Gary Clark II * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +41,7 @@ * the manufacturer or anyone else might provide better documentation, * so this file (and the driver) will then have a better quality. * - * $Id$ + * $Id: mcdreg.h,v 1.1 1993/10/12 06:08:31 rgrimes Exp $ */ #ifndef MCD_H @@ -67,8 +68,8 @@ typedef unsigned char bcd_t; #define mcd_reset 1 #define mcd_xfer 1 #define mcd_ctl2 2 /* XXX Is this right? */ - #define mcd_config 3 + #define MCD_MASK_DMA 0x07 /* bits 2-0 = DMA channel */ #define MCD_MASK_IRQ 0x70 /* bits 6-4 = INT number */ /* 001 = int 2,9 */ @@ -77,8 +78,15 @@ typedef unsigned char bcd_t; /* 100 = int 10 */ /* 101 = int 11 */ /* flags */ -#define STATUS_AVAIL 0xb -#define DATA_AVAIL 0xf +#define STATUS_AVAIL 0xB +#define DATA_AVAIL 0xF + +/* New Flags */ +#define M_STATUS_AVAIL 0xFB +#define M_DATA_AVAIL 0xFD + +/* New Commands */ +#define M_RESET 0x00 /* ports */ #define MCD_DATA 0 diff --git a/sys/i386/isa/mcd.c b/sys/i386/isa/mcd.c index f4802bcc4439..2a690cb1e5b5 100644 --- a/sys/i386/isa/mcd.c +++ b/sys/i386/isa/mcd.c @@ -1,6 +1,7 @@ /* * Copyright 1993 by Holger Veit (data part) * Copyright 1993 by Brian Moore (audio part) + * Changes Copyright 1993 by Gary Clark II * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -68,7 +69,7 @@ static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore"; #undef MCD_TO_WARNING_ON #endif #else -#define MCD_TRACE(fmt,a,b,c,xd) {if (mcd_data[unit].debug) {printf("mcd%d st=%02x: ",unit,mcd_data[unit].status); printf(fmt,a,b,c,xd);}} +#define MCD_TRACE(fmt,a,b,c,d) {if (mcd_data[unit].debug) {printf("mcd%d st=%02x: ",unit,mcd_data[unit].status); printf(fmt,a,b,c,d);}} #endif #define mcd_part(dev) ((minor(dev)) & 7) @@ -158,7 +159,7 @@ static void hsg2msf(int hsg, bcd_t *msf); static int msf2hsg(bcd_t *msf); static int mcd_volinfo(int unit); static int mcd_waitrdy(int port,int dly); -static void mcd_doread(caddr_t, int); +static void mcd_doread(int state, struct mcd_mbx *mbxin); #ifndef MCDMINI static int mcd_setmode(int unit, int mode); static int mcd_getqchan(int unit, struct mcd_qchninfo *q); @@ -397,7 +398,7 @@ static void mcd_start(int unit) cd->mbx.p_offset = p->p_offset; /* calling the read routine */ - mcd_doread((caddr_t)MCD_S_BEGIN, (int)&(cd->mbx)); + mcd_doread(MCD_S_BEGIN,&(cd->mbx)); /* triggers mcd_start, when successful finished */ return; } @@ -540,14 +541,13 @@ static void mcd_configure(struct mcd_data *cd) outb(cd->iobase+mcd_config,cd->config); } -/* check if there is a cdrom */ -/* Heavly hacked by gclarkii@sugar.neosoft.com */ +/* check to see if a Mitsumi CD-ROM is attached to the ISA bus */ int mcd_probe(struct isa_device *dev) { int port = dev->id_iobase; int unit = dev->id_unit; - int i; + int i,j; int st; int check; int junk; @@ -562,72 +562,43 @@ int mcd_probe(struct isa_device *dev) #endif /* send a reset */ - outb(port+MCD_FLAGS,0); - DELAY(100000); - /* get any pending status and throw away...*/ - for (i=10; i != 0; i--) { + outb(port+MCD_FLAGS,M_RESET); + DELAY(30000); + + for (j=3; j != 0; j--) { + + /* get any pending garbage (old data) and throw away...*/ + for (i=10; i != 0; i--) { inb(port+MCD_DATA); - } - DELAY(1000); - - outb(port+MCD_DATA,MCD_CMDGETSTAT); /* Send get status command */ - - /* Loop looking for avail of status */ - /* XXX May have to increase for fast machinces */ - for (i = 1000; i != 0; i--) { - if ((inb(port+MCD_FLAGS) & 0xF ) == STATUS_AVAIL) { - break; - } - DELAY(10); - } - /* get status */ - - if (i == 0) { -#ifdef DEBUG - printf ("Mitsumi drive NOT detected\n"); -#endif - return 0; - } - -/* - * The following code uses the 0xDC command, it returns a M from the - * second byte and a number in the third. Does anyone know what the - * number is for? Better yet, how about someone thats REAL good in - * i80x86 asm looking at the Dos driver... Most of this info came - * from a friend of mine spending a whole weekend..... - */ + } DELAY (2000); outb(port+MCD_DATA,MCD_CMDCONTINFO); - for (i = 0; i < 100000; i++) { - if ((inb(port+MCD_FLAGS) & 0xF) == STATUS_AVAIL) - break; - } - if (i > 100000) { -#ifdef DEBUG - printf ("Mitsumi drive error\n"); -#endif - return 0; - } - DELAY (40000); - st = inb(port+MCD_DATA); - DELAY (500); - check = inb(port+MCD_DATA); - DELAY (500); - junk = inb(port+MCD_DATA); /* What is byte used for?!?!? */ - - if (check = 'M') { + for (i = 0; i < 300000; i++) { + if ((inb(port+MCD_FLAGS) & M_STATUS_AVAIL) == M_STATUS_AVAIL) + { + DELAY (4000); + st = inb(port+MCD_DATA); + DELAY (500); + check = inb(port+MCD_DATA); + DELAY (500); + junk = inb(port+MCD_DATA); /* What is byte used for?!?!? */ + + if (check = 'M') { #ifdef DEBUG printf("Mitsumi drive detected\n"); #endif return 4; - } else { + } else { printf("Mitsumi drive NOT detected\n"); - printf("Mitsumi drive error\n"); return 0; - } + } + } + } + } } + static int mcd_waitrdy(int port,int dly) { int i; @@ -811,13 +782,8 @@ mcdintr(unit) */ static struct mcd_mbx *mbxsave; -/* - * Good thing Alphas come with real CD players... - */ -static void mcd_doread(caddr_t xstate, int xmbxin) +static void mcd_doread(int state, struct mcd_mbx *mbxin) { - int state = (int)xstate; - struct mcd_mbx *mbxin = (struct mcd_mbx *)xmbxin; struct mcd_mbx *mbx = (state!=MCD_S_BEGIN) ? mbxsave : mbxin; int unit = mbx->unit; int port = mbx->port; @@ -841,7 +807,7 @@ static void mcd_doread(caddr_t xstate, int xmbxin) timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITSTAT,hz/100); /* XXX */ return; case MCD_S_WAITSTAT: - untimeout(mcd_doread, (caddr_t)MCD_S_WAITSTAT); + untimeout(mcd_doread,MCD_S_WAITSTAT); if (mbx->count-- >= 0) { if (inb(port+mcd_xfer) & MCD_ST_BUSY) { timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITSTAT,hz/100); /* XXX */ @@ -878,7 +844,7 @@ static void mcd_doread(caddr_t xstate, int xmbxin) } case MCD_S_WAITMODE: - untimeout(mcd_doread, (caddr_t)MCD_S_WAITMODE); + untimeout(mcd_doread,MCD_S_WAITMODE); if (mbx->count-- < 0) { #ifdef MCD_TO_WARNING_ON printf("mcd%d: timeout set mode\n",unit); @@ -916,7 +882,7 @@ static void mcd_doread(caddr_t xstate, int xmbxin) timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITREAD,hz/100); /* XXX */ return; case MCD_S_WAITREAD: - untimeout(mcd_doread,(caddr_t)MCD_S_WAITREAD); + untimeout(mcd_doread,MCD_S_WAITREAD); if (mbx->count-- > 0) { k = inb(port+mcd_xfer); if ((k & 2)==0) { diff --git a/sys/i386/isa/mcdreg.h b/sys/i386/isa/mcdreg.h index 83664a7674a0..c5c95d8c85e2 100644 --- a/sys/i386/isa/mcdreg.h +++ b/sys/i386/isa/mcdreg.h @@ -1,6 +1,7 @@ /* * Copyright 1993 by Holger Veit (data part) * Copyright 1993 by Brian Moore (audio part) + * Changes Copyright 1993 by Gary Clark II * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,7 +41,7 @@ * the manufacturer or anyone else might provide better documentation, * so this file (and the driver) will then have a better quality. * - * $Id$ + * $Id: mcdreg.h,v 1.1 1993/10/12 06:08:31 rgrimes Exp $ */ #ifndef MCD_H @@ -67,8 +68,8 @@ typedef unsigned char bcd_t; #define mcd_reset 1 #define mcd_xfer 1 #define mcd_ctl2 2 /* XXX Is this right? */ - #define mcd_config 3 + #define MCD_MASK_DMA 0x07 /* bits 2-0 = DMA channel */ #define MCD_MASK_IRQ 0x70 /* bits 6-4 = INT number */ /* 001 = int 2,9 */ @@ -77,8 +78,15 @@ typedef unsigned char bcd_t; /* 100 = int 10 */ /* 101 = int 11 */ /* flags */ -#define STATUS_AVAIL 0xb -#define DATA_AVAIL 0xf +#define STATUS_AVAIL 0xB +#define DATA_AVAIL 0xF + +/* New Flags */ +#define M_STATUS_AVAIL 0xFB +#define M_DATA_AVAIL 0xFD + +/* New Commands */ +#define M_RESET 0x00 /* ports */ #define MCD_DATA 0