Busify the driver (from perry).
This commit is contained in:
parent
be3e57de4a
commit
ef8d40a999
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: mcd.c,v 1.52 1996/11/05 07:17:25 mikel Exp $ */
|
/* $NetBSD: mcd.c,v 1.53 1997/04/04 18:59:35 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved.
|
* Copyright (c) 1993, 1994, 1995 Charles M. Hannum. All rights reserved.
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
|
|
||||||
#include <machine/cpu.h>
|
#include <machine/cpu.h>
|
||||||
#include <machine/intr.h>
|
#include <machine/intr.h>
|
||||||
#include <machine/pio.h>
|
#include <machine/bus.h>
|
||||||
|
|
||||||
#include <dev/isa/isavar.h>
|
#include <dev/isa/isavar.h>
|
||||||
#include <dev/isa/mcdreg.h>
|
#include <dev/isa/mcdreg.h>
|
||||||
|
@ -111,11 +111,12 @@ struct mcd_softc {
|
||||||
struct disk sc_dk;
|
struct disk sc_dk;
|
||||||
void *sc_ih;
|
void *sc_ih;
|
||||||
|
|
||||||
int iobase;
|
bus_space_tag_t sc_iot;
|
||||||
|
bus_space_handle_t sc_ioh;
|
||||||
|
|
||||||
int irq, drq;
|
int irq, drq;
|
||||||
|
|
||||||
char *type;
|
char *type;
|
||||||
u_char readcmd;
|
|
||||||
int flags;
|
int flags;
|
||||||
#define MCDF_LOCKED 0x01
|
#define MCDF_LOCKED 0x01
|
||||||
#define MCDF_WANTED 0x02
|
#define MCDF_WANTED 0x02
|
||||||
|
@ -134,8 +135,10 @@ struct mcd_softc {
|
||||||
#define MCD_MD_UNKNOWN -1
|
#define MCD_MD_UNKNOWN -1
|
||||||
int lastupc;
|
int lastupc;
|
||||||
#define MCD_UPC_UNKNOWN -1
|
#define MCD_UPC_UNKNOWN -1
|
||||||
int debug;
|
|
||||||
struct buf buf_queue;
|
struct buf buf_queue;
|
||||||
|
u_char readcmd;
|
||||||
|
u_char debug;
|
||||||
|
u_char probe;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
|
@ -174,6 +177,7 @@ int mcd_read_toc __P((struct mcd_softc *));
|
||||||
int mcd_getqchan __P((struct mcd_softc *, union mcd_qchninfo *, int));
|
int mcd_getqchan __P((struct mcd_softc *, union mcd_qchninfo *, int));
|
||||||
int mcd_setlock __P((struct mcd_softc *, int));
|
int mcd_setlock __P((struct mcd_softc *, int));
|
||||||
|
|
||||||
|
int mcd_find __P((bus_space_tag_t, bus_space_handle_t, struct mcd_softc *));
|
||||||
int mcdprobe __P((struct device *, void *, void *));
|
int mcdprobe __P((struct device *, void *, void *));
|
||||||
void mcdattach __P((struct device *, struct device *, void *));
|
void mcdattach __P((struct device *, struct device *, void *));
|
||||||
|
|
||||||
|
@ -212,8 +216,23 @@ mcdattach(parent, self, aux)
|
||||||
{
|
{
|
||||||
struct mcd_softc *sc = (void *)self;
|
struct mcd_softc *sc = (void *)self;
|
||||||
struct isa_attach_args *ia = aux;
|
struct isa_attach_args *ia = aux;
|
||||||
|
bus_space_tag_t iot = ia->ia_iot;
|
||||||
|
bus_space_handle_t ioh;
|
||||||
struct mcd_mbox mbx;
|
struct mcd_mbox mbx;
|
||||||
|
|
||||||
|
/* Map i/o space */
|
||||||
|
if (bus_space_map(iot, ia->ia_iobase, MCD_NPORT, 0, &ioh))
|
||||||
|
panic("mcdattach: bus_space_map failed!");
|
||||||
|
|
||||||
|
sc->sc_iot = iot;
|
||||||
|
sc->sc_ioh = ioh;
|
||||||
|
|
||||||
|
sc->probe = 0;
|
||||||
|
sc->debug = 0;
|
||||||
|
|
||||||
|
if (!mcd_find(iot, ioh, sc))
|
||||||
|
panic("mcdattach: mcd_find failed!");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize and attach the disk structure.
|
* Initialize and attach the disk structure.
|
||||||
*/
|
*/
|
||||||
|
@ -745,25 +764,27 @@ mcddump(dev, blkno, va, size)
|
||||||
return ENXIO;
|
return ENXIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the board and fill in the softc.
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
mcdprobe(parent, match, aux)
|
mcd_find(iot, ioh, sc)
|
||||||
struct device *parent;
|
bus_space_tag_t iot;
|
||||||
void *match, *aux;
|
bus_space_handle_t ioh;
|
||||||
|
struct mcd_softc *sc;
|
||||||
{
|
{
|
||||||
struct mcd_softc *sc = match;
|
|
||||||
struct isa_attach_args *ia = aux;
|
|
||||||
int iobase = ia->ia_iobase;
|
|
||||||
int i;
|
int i;
|
||||||
struct mcd_mbox mbx;
|
struct mcd_mbox mbx;
|
||||||
|
|
||||||
sc->iobase = iobase;
|
sc->sc_iot = iot;
|
||||||
|
sc->sc_ioh = ioh;
|
||||||
|
|
||||||
/* Send a reset. */
|
/* Send a reset. */
|
||||||
outb(iobase + MCD_RESET, 0);
|
bus_space_write_1(iot, ioh, MCD_RESET, 0);
|
||||||
delay(1000000);
|
delay(1000000);
|
||||||
/* Get any pending status and throw away. */
|
/* Get any pending status and throw away. */
|
||||||
for (i = 10; i; i--)
|
for (i = 10; i; i--)
|
||||||
inb(iobase + MCD_STATUS);
|
bus_space_read_1(iot, ioh, MCD_STATUS);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
|
||||||
/* Send get status command. */
|
/* Send get status command. */
|
||||||
|
@ -816,21 +837,52 @@ mcdprobe(parent, match, aux)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ia->ia_iosize = 4;
|
|
||||||
ia->ia_msize = 0;
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
mcdprobe(parent, match, aux)
|
||||||
|
struct device *parent;
|
||||||
|
void *match, *aux;
|
||||||
|
{
|
||||||
|
struct isa_attach_args *ia = aux;
|
||||||
|
struct mcd_softc sc;
|
||||||
|
bus_space_tag_t iot = ia->ia_iot;
|
||||||
|
bus_space_handle_t ioh;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
/* Map i/o space */
|
||||||
|
if (bus_space_map(iot, ia->ia_iobase, MCD_NPORT, 0, &ioh))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
sc.debug = 0;
|
||||||
|
sc.probe = 1;
|
||||||
|
|
||||||
|
rv = mcd_find(iot, ioh, &sc);
|
||||||
|
|
||||||
|
bus_space_unmap(iot, ioh, MCD_NPORT);
|
||||||
|
|
||||||
|
if (rv) {
|
||||||
|
ia->ia_iosize = MCD_NPORT;
|
||||||
|
ia->ia_msize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
mcd_getreply(sc)
|
mcd_getreply(sc)
|
||||||
struct mcd_softc *sc;
|
struct mcd_softc *sc;
|
||||||
{
|
{
|
||||||
int iobase = sc->iobase;
|
bus_space_tag_t iot = sc->sc_iot;
|
||||||
|
bus_space_handle_t ioh = sc->sc_ioh;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Wait until xfer port senses data ready. */
|
/* Wait until xfer port senses data ready. */
|
||||||
for (i = DELAY_GETREPLY; i; i--) {
|
for (i = DELAY_GETREPLY; i; i--) {
|
||||||
if ((inb(iobase + MCD_XFER) & MCD_XF_STATUSUNAVAIL) == 0)
|
if ((bus_space_read_1(iot, ioh, MCD_XFER) &
|
||||||
|
MCD_XF_STATUSUNAVAIL) == 0)
|
||||||
break;
|
break;
|
||||||
delay(DELAY_GRANULARITY);
|
delay(DELAY_GRANULARITY);
|
||||||
}
|
}
|
||||||
|
@ -838,7 +890,7 @@ mcd_getreply(sc)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Get the data. */
|
/* Get the data. */
|
||||||
return inb(iobase + MCD_STATUS);
|
return bus_space_read_1(iot, ioh, MCD_STATUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -867,7 +919,7 @@ mcd_getresult(sc, res)
|
||||||
if ((x = mcd_getreply(sc)) < 0) {
|
if ((x = mcd_getreply(sc)) < 0) {
|
||||||
if (sc->debug)
|
if (sc->debug)
|
||||||
printf(" timeout\n");
|
printf(" timeout\n");
|
||||||
else
|
else if (!sc->probe)
|
||||||
printf("%s: timeout in getresult\n", sc->sc_dev.dv_xname);
|
printf("%s: timeout in getresult\n", sc->sc_dev.dv_xname);
|
||||||
return EIO;
|
return EIO;
|
||||||
}
|
}
|
||||||
|
@ -897,8 +949,9 @@ mcd_getresult(sc, res)
|
||||||
|
|
||||||
#ifdef MCDDEBUG
|
#ifdef MCDDEBUG
|
||||||
delay(10);
|
delay(10);
|
||||||
while ((inb(sc->iobase + MCD_XFER) & MCD_XF_STATUSUNAVAIL) == 0) {
|
while ((bus_space_read_1(sc->sc_iot, sc->sc_ioh, MCD_XFER) &
|
||||||
x = inb(sc->iobase + MCD_STATUS);
|
MCD_XF_STATUSUNAVAIL) == 0) {
|
||||||
|
x = bus_space_read_1(sc->sc_iot, sc->sc_ioh, MCD_STATUS);
|
||||||
printf("%s: got extra byte %02x during getstatus\n",
|
printf("%s: got extra byte %02x during getstatus\n",
|
||||||
sc->sc_dev.dv_xname, (u_int)x);
|
sc->sc_dev.dv_xname, (u_int)x);
|
||||||
delay(10);
|
delay(10);
|
||||||
|
@ -939,8 +992,9 @@ mcd_send(sc, mbx, diskin)
|
||||||
struct mcd_mbox *mbx;
|
struct mcd_mbox *mbx;
|
||||||
int diskin;
|
int diskin;
|
||||||
{
|
{
|
||||||
int iobase = sc->iobase;
|
|
||||||
int retry, i, error;
|
int retry, i, error;
|
||||||
|
bus_space_tag_t iot = sc->sc_iot;
|
||||||
|
bus_space_handle_t ioh = sc->sc_ioh;
|
||||||
|
|
||||||
if (sc->debug) {
|
if (sc->debug) {
|
||||||
printf("%s: mcd_send: %d %02x", sc->sc_dev.dv_xname,
|
printf("%s: mcd_send: %d %02x", sc->sc_dev.dv_xname,
|
||||||
|
@ -951,9 +1005,9 @@ mcd_send(sc, mbx, diskin)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (retry = MCD_RETRIES; retry; retry--) {
|
for (retry = MCD_RETRIES; retry; retry--) {
|
||||||
outb(iobase + MCD_COMMAND, mbx->cmd.opcode);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->cmd.opcode);
|
||||||
for (i = 0; i < mbx->cmd.length; i++)
|
for (i = 0; i < mbx->cmd.length; i++)
|
||||||
outb(iobase + MCD_COMMAND, mbx->cmd.data.raw.data[i]);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->cmd.data.raw.data[i]);
|
||||||
if ((error = mcd_getresult(sc, &mbx->res)) == 0)
|
if ((error = mcd_getresult(sc, &mbx->res)) == 0)
|
||||||
break;
|
break;
|
||||||
if (error == EINVAL)
|
if (error == EINVAL)
|
||||||
|
@ -1036,8 +1090,9 @@ mcdintr(arg)
|
||||||
{
|
{
|
||||||
struct mcd_softc *sc = arg;
|
struct mcd_softc *sc = arg;
|
||||||
struct mcd_mbx *mbx = &sc->mbx;
|
struct mcd_mbx *mbx = &sc->mbx;
|
||||||
int iobase = sc->iobase;
|
|
||||||
struct buf *bp = mbx->bp;
|
struct buf *bp = mbx->bp;
|
||||||
|
bus_space_tag_t iot = sc->sc_iot;
|
||||||
|
bus_space_handle_t ioh = sc->sc_ioh;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
u_char x;
|
u_char x;
|
||||||
|
@ -1053,8 +1108,8 @@ mcdintr(arg)
|
||||||
goto firstblock;
|
goto firstblock;
|
||||||
|
|
||||||
sc->lastmode = MCD_MD_UNKNOWN;
|
sc->lastmode = MCD_MD_UNKNOWN;
|
||||||
outb(iobase + MCD_COMMAND, MCD_CMDSETMODE);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, MCD_CMDSETMODE);
|
||||||
outb(iobase + MCD_COMMAND, mbx->mode);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->mode);
|
||||||
|
|
||||||
mbx->count = RDELAY_WAITMODE;
|
mbx->count = RDELAY_WAITMODE;
|
||||||
mbx->state = MCD_S_WAITMODE;
|
mbx->state = MCD_S_WAITMODE;
|
||||||
|
@ -1062,14 +1117,14 @@ mcdintr(arg)
|
||||||
case MCD_S_WAITMODE:
|
case MCD_S_WAITMODE:
|
||||||
untimeout(mcd_pseudointr, sc);
|
untimeout(mcd_pseudointr, sc);
|
||||||
for (i = 20; i; i--) {
|
for (i = 20; i; i--) {
|
||||||
x = inb(iobase + MCD_XFER);
|
x = bus_space_read_1(iot, ioh, MCD_XFER);
|
||||||
if ((x & MCD_XF_STATUSUNAVAIL) == 0)
|
if ((x & MCD_XF_STATUSUNAVAIL) == 0)
|
||||||
break;
|
break;
|
||||||
delay(50);
|
delay(50);
|
||||||
}
|
}
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
goto hold;
|
goto hold;
|
||||||
sc->status = inb(iobase + MCD_STATUS);
|
sc->status = bus_space_read_1(iot, ioh, MCD_STATUS);
|
||||||
mcd_setflags(sc);
|
mcd_setflags(sc);
|
||||||
if ((sc->flags & MCDF_LOADED) == 0)
|
if ((sc->flags & MCDF_LOADED) == 0)
|
||||||
goto changed;
|
goto changed;
|
||||||
|
@ -1086,13 +1141,13 @@ mcdintr(arg)
|
||||||
hsg2msf(mbx->blkno, msf);
|
hsg2msf(mbx->blkno, msf);
|
||||||
|
|
||||||
/* Send the read command. */
|
/* Send the read command. */
|
||||||
outb(iobase + MCD_COMMAND, sc->readcmd);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, sc->readcmd);
|
||||||
outb(iobase + MCD_COMMAND, msf[0]);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, msf[0]);
|
||||||
outb(iobase + MCD_COMMAND, msf[1]);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, msf[1]);
|
||||||
outb(iobase + MCD_COMMAND, msf[2]);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, msf[2]);
|
||||||
outb(iobase + MCD_COMMAND, 0);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, 0);
|
||||||
outb(iobase + MCD_COMMAND, 0);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, 0);
|
||||||
outb(iobase + MCD_COMMAND, mbx->nblk);
|
bus_space_write_1(iot, ioh, MCD_COMMAND, mbx->nblk);
|
||||||
|
|
||||||
mbx->count = RDELAY_WAITREAD;
|
mbx->count = RDELAY_WAITREAD;
|
||||||
mbx->state = MCD_S_WAITREAD;
|
mbx->state = MCD_S_WAITREAD;
|
||||||
|
@ -1102,7 +1157,7 @@ mcdintr(arg)
|
||||||
nextblock:
|
nextblock:
|
||||||
loop:
|
loop:
|
||||||
for (i = 20; i; i--) {
|
for (i = 20; i; i--) {
|
||||||
x = inb(iobase + MCD_XFER);
|
x = bus_space_read_1(iot, ioh, MCD_XFER);
|
||||||
if ((x & MCD_XF_DATAUNAVAIL) == 0)
|
if ((x & MCD_XF_DATAUNAVAIL) == 0)
|
||||||
goto gotblock;
|
goto gotblock;
|
||||||
if ((x & MCD_XF_STATUSUNAVAIL) == 0)
|
if ((x & MCD_XF_STATUSUNAVAIL) == 0)
|
||||||
|
@ -1111,7 +1166,7 @@ mcdintr(arg)
|
||||||
}
|
}
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
goto hold;
|
goto hold;
|
||||||
sc->status = inb(iobase + MCD_STATUS);
|
sc->status = bus_space_read_1(iot, ioh, MCD_STATUS);
|
||||||
mcd_setflags(sc);
|
mcd_setflags(sc);
|
||||||
if ((sc->flags & MCDF_LOADED) == 0)
|
if ((sc->flags & MCDF_LOADED) == 0)
|
||||||
goto changed;
|
goto changed;
|
||||||
|
@ -1126,9 +1181,10 @@ mcdintr(arg)
|
||||||
RDELAY_WAITREAD - mbx->count, 0, 0, 0);
|
RDELAY_WAITREAD - mbx->count, 0, 0, 0);
|
||||||
|
|
||||||
/* Data is ready. */
|
/* Data is ready. */
|
||||||
outb(iobase + MCD_CTL2, 0x04); /* XXX */
|
bus_space_write_1(iot, ioh, MCD_CTL2, 0x04); /* XXX */
|
||||||
insb(iobase + MCD_RDATA, bp->b_data + mbx->skip, mbx->sz);
|
bus_space_read_multi_1(iot, ioh, MCD_RDATA,
|
||||||
outb(iobase + MCD_CTL2, 0x0c); /* XXX */
|
bp->b_data + mbx->skip, mbx->sz);
|
||||||
|
bus_space_write_1(iot, ioh, MCD_CTL2, 0x0c); /* XXX */
|
||||||
mbx->blkno += 1;
|
mbx->blkno += 1;
|
||||||
mbx->skip += mbx->sz;
|
mbx->skip += mbx->sz;
|
||||||
if (--mbx->nblk > 0)
|
if (--mbx->nblk > 0)
|
||||||
|
@ -1178,7 +1234,7 @@ changed:
|
||||||
|
|
||||||
#ifdef notyet
|
#ifdef notyet
|
||||||
printf("%s: unit timeout; resetting\n", sc->sc_dev.dv_xname);
|
printf("%s: unit timeout; resetting\n", sc->sc_dev.dv_xname);
|
||||||
outb(mbx->iobase + MCD_RESET, MCD_CMDRESET);
|
bus_space_write_1(iot, ioh, MCD_RESET, MCD_CMDRESET);
|
||||||
delay(300000);
|
delay(300000);
|
||||||
(void) mcd_getstat(sc, 1);
|
(void) mcd_getstat(sc, 1);
|
||||||
(void) mcd_getstat(sc, 1);
|
(void) mcd_getstat(sc, 1);
|
||||||
|
@ -1197,7 +1253,7 @@ mcd_soft_reset(sc)
|
||||||
sc->lastmode = MCD_MD_UNKNOWN;
|
sc->lastmode = MCD_MD_UNKNOWN;
|
||||||
sc->lastupc = MCD_UPC_UNKNOWN;
|
sc->lastupc = MCD_UPC_UNKNOWN;
|
||||||
sc->audio_status = CD_AS_AUDIO_INVALID;
|
sc->audio_status = CD_AS_AUDIO_INVALID;
|
||||||
outb(sc->iobase + MCD_CTL2, 0x0c); /* XXX */
|
bus_space_write_1(sc->sc_iot, sc->sc_ioh, MCD_CTL2, 0x0c); /* XXX */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $NetBSD: mcdreg.h,v 1.7 1995/07/10 01:27:27 cgd Exp $ */
|
/* $NetBSD: mcdreg.h,v 1.8 1997/04/04 18:59:37 christos Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 1993 by Holger Veit (data part)
|
* Copyright 1993 by Holger Veit (data part)
|
||||||
|
@ -59,6 +59,7 @@ typedef unsigned char bcd_t;
|
||||||
#define MCD_XFER 1
|
#define MCD_XFER 1
|
||||||
#define MCD_CTL2 2 /* XXX Is this right? */
|
#define MCD_CTL2 2 /* XXX Is this right? */
|
||||||
#define MCD_CONFIG 3
|
#define MCD_CONFIG 3
|
||||||
|
#define MCD_NPORT 4
|
||||||
|
|
||||||
#define MCD_MASK_DMA 0x07 /* bits 2-0 = DMA channel */
|
#define MCD_MASK_DMA 0x07 /* bits 2-0 = DMA channel */
|
||||||
#define MCD_MASK_IRQ 0x70 /* bits 6-4 = INT number */
|
#define MCD_MASK_IRQ 0x70 /* bits 6-4 = INT number */
|
||||||
|
|
Loading…
Reference in New Issue