1993-11-04 12:12:30 +03:00
|
|
|
/*
|
1994-02-21 18:23:11 +03:00
|
|
|
* Copyright (c) 1993, 1994 Charles Hannum.
|
1993-11-04 12:12:30 +03:00
|
|
|
* Copyright 1993 by Holger Veit (data part)
|
|
|
|
* Copyright 1993 by Brian Moore (audio part)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This software was developed by Holger Veit and Brian Moore
|
|
|
|
* for use with "386BSD" and similar operating systems.
|
|
|
|
* "Similar operating systems" includes mainly non-profit oriented
|
|
|
|
* systems for research and education, including but not restricted to
|
|
|
|
* "NetBSD", "FreeBSD", "Mach" (by CMU).
|
|
|
|
* 4. Neither the name of the developer(s) nor the name "386BSD"
|
|
|
|
* may be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPER(S) ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE DEVELOPER(S) BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|
|
|
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
1994-05-05 12:26:13 +04:00
|
|
|
* $Id: mcd.c,v 1.14 1994/05/05 08:26:13 mycroft Exp $
|
1993-11-04 12:12:30 +03:00
|
|
|
*/
|
1993-11-17 15:22:50 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/*static char COPYRIGHT[] = "mcd-driver (C)1993 by H.Veit & B.Moore";*/
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
1994-02-21 18:23:11 +03:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/proc.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/cdio.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/dkbad.h>
|
|
|
|
#include <sys/disklabel.h>
|
1994-02-21 18:23:11 +03:00
|
|
|
#include <sys/device.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#include <machine/cpu.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <machine/pio.h>
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
#include <i386/isa/isavar.h>
|
1993-12-20 12:05:17 +03:00
|
|
|
#include <i386/isa/mcdreg.h>
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifndef MCDDEBUG
|
1993-11-04 12:12:30 +03:00
|
|
|
#define MCD_TRACE(fmt,a,b,c,d)
|
|
|
|
#else
|
1994-02-21 18:23:11 +03:00
|
|
|
#define MCD_TRACE(fmt,a,b,c,d) {if (sc->debug) {printf("%s: st=%02x: ", sc->sc_dev.dv_xname, sc->status); printf(fmt,a,b,c,d);}}
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#define MCDPART(dev) (((minor(dev)) & 0x07) )
|
|
|
|
#define MCDUNIT(dev) (((minor(dev)) & 0x78) >> 3)
|
|
|
|
#define MCDPHYS(dev) (((minor(dev)) & 0x80) >> 7)
|
1993-11-04 12:12:30 +03:00
|
|
|
#define RAW_PART 3
|
|
|
|
|
|
|
|
/* flags */
|
|
|
|
#define MCDOPEN 0x0001 /* device opened */
|
|
|
|
#define MCDVALID 0x0002 /* parameters loaded */
|
1994-03-29 08:35:37 +04:00
|
|
|
#define MCDWAIT 0x0004 /* waiting for something */
|
|
|
|
#define MCDLABEL 0x0008 /* label is read */
|
|
|
|
#define MCDREADRAW 0x0010 /* read raw mode (2352 bytes) */
|
|
|
|
#define MCDVOLINFO 0x0020 /* already read volinfo */
|
|
|
|
#define MCDTOC 0x0040 /* already read toc */
|
|
|
|
#define MCDMBXBSY 0x0080 /* local mbx is busy */
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
/* status */
|
|
|
|
#define MCDAUDIOBSY MCD_ST_AUDIOBSY /* playing audio */
|
|
|
|
#define MCDDSKCHNG MCD_ST_DSKCHNG /* sensed change of disk */
|
|
|
|
#define MCDDSKIN MCD_ST_DSKIN /* sensed disk in drive */
|
|
|
|
#define MCDDOOROPEN MCD_ST_DOOROPEN /* sensed door open */
|
|
|
|
|
|
|
|
/* toc */
|
|
|
|
#define MCD_MAXTOCS 104 /* from the Linux driver */
|
|
|
|
#define MCD_LASTPLUS1 170 /* special toc entry */
|
|
|
|
|
|
|
|
struct mcd_mbx {
|
|
|
|
short unit;
|
|
|
|
short retry;
|
|
|
|
short nblk;
|
|
|
|
int sz;
|
|
|
|
u_long skip;
|
|
|
|
struct buf *bp;
|
|
|
|
int p_offset;
|
|
|
|
short count;
|
1994-05-05 12:26:13 +04:00
|
|
|
short state;
|
1993-11-04 12:12:30 +03:00
|
|
|
};
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_softc {
|
|
|
|
struct device sc_dev;
|
1994-04-07 10:48:19 +04:00
|
|
|
struct intrhand sc_ih;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
|
|
|
u_short iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
short config;
|
|
|
|
short flags;
|
|
|
|
short status;
|
|
|
|
int blksize;
|
|
|
|
u_long disksize;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct disklabel dlabel;
|
1993-11-04 12:12:30 +03:00
|
|
|
int partflags[MAXPARTITIONS];
|
|
|
|
int openflags;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_volinfo volinfo;
|
|
|
|
struct mcd_qchninfo toc[MCD_MAXTOCS];
|
1993-11-04 12:12:30 +03:00
|
|
|
short audio_status;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct mcd_read2 lastpb;
|
1993-11-04 12:12:30 +03:00
|
|
|
short debug;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct buf head; /* head of buf queue */
|
|
|
|
struct mcd_mbx mbx;
|
1994-03-29 08:35:37 +04:00
|
|
|
};
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
/* prototypes */
|
1994-02-21 18:23:11 +03:00
|
|
|
int mcdopen __P((dev_t));
|
|
|
|
int mcdclose __P((dev_t));
|
|
|
|
int mcd_start __P((struct mcd_softc *));
|
|
|
|
int mcdioctl __P((dev_t, int, caddr_t, int, struct proc *));
|
|
|
|
int mcd_getdisklabel __P((struct mcd_softc *));
|
|
|
|
int mcdsize __P((dev_t));
|
|
|
|
void mcd_configure __P((struct mcd_softc *));
|
|
|
|
int mcd_waitrdy __P((u_short, int));
|
|
|
|
int mcd_getreply __P((struct mcd_softc *, int));
|
|
|
|
int mcd_getstat __P((struct mcd_softc *, int));
|
|
|
|
void mcd_setflags __P((struct mcd_softc *));
|
|
|
|
int mcd_get __P((struct mcd_softc *, char *, int));
|
|
|
|
int mcd_send __P((struct mcd_softc *, int, int));
|
|
|
|
int bcd2bin __P((bcd_t));
|
|
|
|
bcd_t bin2bcd __P((int));
|
|
|
|
void hsg2msf __P((int, bcd_t *));
|
|
|
|
int msf2hsg __P((bcd_t *));
|
|
|
|
int mcd_volinfo __P((struct mcd_softc *));
|
1994-04-07 10:48:19 +04:00
|
|
|
int mcdintr __P((struct mcd_softc *));
|
1994-02-21 18:23:11 +03:00
|
|
|
int mcd_setmode __P((struct mcd_softc *, int));
|
1994-05-05 12:26:13 +04:00
|
|
|
void mcd_doread __P((void *));
|
1994-02-21 18:23:11 +03:00
|
|
|
int mcd_toc_header __P((struct mcd_softc *, struct ioc_toc_header *));
|
|
|
|
int mcd_read_toc __P((struct mcd_softc *));
|
|
|
|
int mcd_toc_entry __P((struct mcd_softc *, struct ioc_read_toc_entry *));
|
|
|
|
int mcd_stop __P((struct mcd_softc *));
|
|
|
|
int mcd_getqchan __P((struct mcd_softc *, struct mcd_qchninfo *));
|
|
|
|
int mcd_subchan __P((struct mcd_softc *, struct ioc_read_subchannel *));
|
|
|
|
int mcd_playtracks __P((struct mcd_softc *, struct ioc_play_track *));
|
|
|
|
int mcd_play __P((struct mcd_softc *, struct mcd_read2 *));
|
|
|
|
int mcd_pause __P((struct mcd_softc *));
|
|
|
|
int mcd_resume __P((struct mcd_softc *));
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
int mcdprobe();
|
|
|
|
void mcdattach();
|
|
|
|
|
|
|
|
struct cfdriver mcdcd = {
|
|
|
|
NULL, "mcd", mcdprobe, mcdattach, DV_DISK, sizeof(struct mcd_softc)
|
1994-02-21 18:23:11 +03:00
|
|
|
};
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
#define mcd_put(port,byte) outb(port,byte)
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#define MCD_RETRIES 5
|
|
|
|
#define MCD_RDRETRIES 8
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
#define MCDBLK 2048 /* for cooked mode */
|
|
|
|
#define MCDRBLK 2352 /* for raw mode */
|
|
|
|
|
|
|
|
/* several delays */
|
|
|
|
#define RDELAY_WAITSTAT 300
|
|
|
|
#define RDELAY_WAITMODE 300
|
|
|
|
#define RDELAY_WAITREAD 800
|
|
|
|
|
|
|
|
#define DELAY_STATUS 10000l /* 10000 * 1us */
|
|
|
|
#define DELAY_GETREPLY 200000l /* 200000 * 2us */
|
|
|
|
#define DELAY_SEEKREAD 20000l /* 20000 * 1us */
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* reader state machine */
|
|
|
|
#define MCD_S_BEGIN 0
|
1994-05-05 12:26:13 +04:00
|
|
|
#define MCD_S_WAITSTAT 1
|
|
|
|
#define MCD_S_WAITMODE 2
|
|
|
|
#define MCD_S_WAITREAD 3
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
void
|
|
|
|
mcdattach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifdef notyet
|
|
|
|
/* Wire controller for interrupts and DMA. */
|
1994-03-29 08:35:37 +04:00
|
|
|
mcd_configure(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1994-04-08 22:57:24 +04:00
|
|
|
printf("\n");
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
sc->flags = 0;
|
1994-04-07 10:48:19 +04:00
|
|
|
|
|
|
|
sc->sc_ih.ih_fun = mcdintr;
|
|
|
|
sc->sc_ih.ih_arg = sc;
|
|
|
|
sc->sc_ih.ih_level = IPL_BIO;
|
|
|
|
intr_establish(ia->ia_irq, &sc->sc_ih);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcdopen(dev)
|
|
|
|
dev_t dev;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
int unit, part, phys;
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
unit = MCDUNIT(dev);
|
1994-03-29 08:35:37 +04:00
|
|
|
if (unit >= mcdcd.cd_ndevs)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
1994-03-29 08:35:37 +04:00
|
|
|
sc = mcdcd.cd_devs[unit];
|
|
|
|
if (!sc)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
part = MCDPART(dev);
|
|
|
|
phys = MCDPHYS(dev);
|
|
|
|
|
|
|
|
/* Invalidated in the meantime? Mark all open part's invalid. */
|
|
|
|
if (!(sc->flags & MCDVALID) && sc->openflags)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_getstat(sc, 1) < 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* XXX Get a default disklabel. */
|
|
|
|
mcd_getdisklabel(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
if (mcdsize(dev) < 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("%s: failed to get disk size\n", sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
} else
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->flags |= MCDVALID;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("open: partition=%d disksize=%d blksize=%d\n", part,
|
|
|
|
sc->disksize, sc->blksize, 0);
|
|
|
|
|
|
|
|
if (part != RAW_PART &&
|
|
|
|
(part >= sc->dlabel.d_npartitions ||
|
|
|
|
sc->dlabel.d_partitions[part].p_fstype == FS_UNUSED))
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->partflags[part] |= MCDOPEN;
|
|
|
|
sc->openflags |= (1 << part);
|
|
|
|
if (part == RAW_PART && phys != 0)
|
|
|
|
sc->partflags[part] |= MCDREADRAW;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mcdclose(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
|
|
|
int unit, part;
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
unit = MCDUNIT(dev);
|
|
|
|
part = MCDPART(dev);
|
1994-03-29 08:35:37 +04:00
|
|
|
sc = mcdcd.cd_devs[unit];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get status. */
|
|
|
|
mcd_getstat(sc, 1);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Close channel. */
|
|
|
|
sc->partflags[part] &= ~(MCDOPEN | MCDREADRAW);
|
|
|
|
sc->openflags &= ~(1 << part);
|
|
|
|
MCD_TRACE("close: partition=%d\n", part, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
|
|
|
mcdstrategy(bp)
|
|
|
|
struct buf *bp;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = mcdcd.cd_devs[MCDUNIT(bp->b_dev)];
|
1993-11-04 12:12:30 +03:00
|
|
|
struct buf *qp;
|
|
|
|
int s;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Test validity. */
|
|
|
|
MCD_TRACE("strategy: buf=0x%lx blkno=%ld bcount=%ld\n", bp,
|
|
|
|
bp->b_blkno, bp->b_bcount, 0);
|
|
|
|
if (bp->b_blkno < 0) {
|
|
|
|
printf("%s: strategy: blkno=%d bcount=%d\n",
|
|
|
|
sc->sc_dev.dv_xname, bp->b_blkno, bp->b_bcount);
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_error = EINVAL;
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* If device invalidated (e.g. media change, door open), error. */
|
|
|
|
if (!(sc->flags & MCDVALID)) {
|
|
|
|
MCD_TRACE("strategy: drive not valid\n", 0, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Check for read only. */
|
1993-11-04 12:12:30 +03:00
|
|
|
if (!(bp->b_flags & B_READ)) {
|
|
|
|
bp->b_error = EROFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* No data to read. */
|
1993-11-04 12:12:30 +03:00
|
|
|
if (bp->b_bcount == 0)
|
|
|
|
goto done;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* For non raw access, check partition limits. */
|
|
|
|
if (MCDPART(bp->b_dev) != RAW_PART) {
|
|
|
|
if (!(sc->flags & MCDLABEL)) {
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_error = EIO;
|
|
|
|
goto bad;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Adjust transfer if necessary. */
|
|
|
|
if (bounds_check_with_label(bp, &sc->dlabel, 1) <= 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Queue it. */
|
|
|
|
qp = &sc->head;
|
1993-11-04 12:12:30 +03:00
|
|
|
s = splbio();
|
1994-02-21 18:23:11 +03:00
|
|
|
disksort(qp, bp);
|
1993-11-04 12:12:30 +03:00
|
|
|
splx(s);
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Now check whether we can perform processing. */
|
|
|
|
mcd_start(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
done:
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_start(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
struct buf *bp, *qp = &sc->head;
|
1993-11-04 12:12:30 +03:00
|
|
|
struct partition *p;
|
1994-02-21 18:23:11 +03:00
|
|
|
int s = splbio();
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->flags & MCDMBXBSY)
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
if ((bp = qp->b_actf) != 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Block found to process; dequeue. */
|
|
|
|
MCD_TRACE("start: found block bp=0x%x\n", bp, 0, 0, 0);
|
1994-02-06 13:00:30 +03:00
|
|
|
qp->b_actf = bp->b_actf;
|
1993-11-04 12:12:30 +03:00
|
|
|
splx(s);
|
|
|
|
} else {
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Nothing to do; */
|
1993-11-04 12:12:30 +03:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Changed media? */
|
|
|
|
if (!(sc->flags & MCDVALID)) {
|
|
|
|
MCD_TRACE("start: drive not valid\n", 0, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
p = &sc->dlabel.d_partitions[MCDPART(bp->b_dev)];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->flags |= MCDMBXBSY;
|
|
|
|
sc->mbx.unit = sc->sc_dev.dv_unit;
|
|
|
|
sc->mbx.retry = MCD_RETRIES;
|
|
|
|
sc->mbx.bp = bp;
|
|
|
|
sc->mbx.p_offset = p->p_offset;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Calling the read routine. */
|
1994-05-05 12:26:13 +04:00
|
|
|
sc->mbx.state = MCD_S_BEGIN;
|
|
|
|
mcd_doread(&sc->mbx);
|
1994-02-21 18:23:11 +03:00
|
|
|
/* triggers mcd_start, when successful finished. */
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcdioctl(dev, cmd, addr, flags, p)
|
|
|
|
dev_t dev;
|
|
|
|
int cmd;
|
|
|
|
caddr_t addr;
|
|
|
|
int flags;
|
|
|
|
struct proc *p;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = mcdcd.cd_devs[MCDUNIT(dev)];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (!(sc->flags & MCDVALID))
|
1993-11-04 12:12:30 +03:00
|
|
|
return EIO;
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("ioctl: cmd=0x%x\n", cmd, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case DIOCSBAD:
|
|
|
|
return EINVAL;
|
|
|
|
case DIOCGDINFO:
|
|
|
|
case DIOCGPART:
|
|
|
|
case DIOCWDINFO:
|
|
|
|
case DIOCSDINFO:
|
|
|
|
case DIOCWLABEL:
|
|
|
|
return ENOTTY;
|
|
|
|
case CDIOCPLAYTRACKS:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_playtracks(sc, (struct ioc_play_track *) addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCPLAYBLOCKS:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_play(sc, (struct mcd_read2 *) addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCREADSUBCHANNEL:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_subchan(sc, (struct ioc_read_subchannel *) addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOREADTOCHEADER:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_toc_header(sc, (struct ioc_toc_header *) addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOREADTOCENTRYS:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_toc_entry(sc, (struct ioc_read_toc_entry *) addr);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCSETPATCH:
|
|
|
|
case CDIOCGETVOL:
|
|
|
|
case CDIOCSETVOL:
|
|
|
|
case CDIOCSETMONO:
|
|
|
|
case CDIOCSETSTERIO:
|
|
|
|
case CDIOCSETMUTE:
|
|
|
|
case CDIOCSETLEFT:
|
|
|
|
case CDIOCSETRIGHT:
|
|
|
|
return EINVAL;
|
|
|
|
case CDIOCRESUME:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_resume(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCPAUSE:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_pause(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCSTART:
|
|
|
|
return EINVAL;
|
|
|
|
case CDIOCSTOP:
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_stop(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
case CDIOCEJECT:
|
|
|
|
return EINVAL;
|
|
|
|
case CDIOCSETDEBUG:
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->debug = 1;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
case CDIOCCLRDEBUG:
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->debug = 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
case CDIOCRESET:
|
|
|
|
return EINVAL;
|
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("mcdioctl: impossible");
|
|
|
|
#endif
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/*
|
|
|
|
* This could have been taken from scsi/cd.c, but it is not clear
|
|
|
|
* whether the scsi cd driver is linked in.
|
1993-11-04 12:12:30 +03:00
|
|
|
*/
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_getdisklabel(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->flags & MCDLABEL)
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
bzero(&sc->dlabel, sizeof(struct disklabel));
|
|
|
|
strncpy(sc->dlabel.d_typename, "Mitsumi CD ROM ", 16);
|
|
|
|
strncpy(sc->dlabel.d_packname, "unknown ", 16);
|
|
|
|
sc->dlabel.d_secsize = sc->blksize;
|
|
|
|
sc->dlabel.d_nsectors = 100;
|
|
|
|
sc->dlabel.d_ntracks = 1;
|
|
|
|
sc->dlabel.d_ncylinders = (sc->disksize /100) + 1;
|
|
|
|
sc->dlabel.d_secpercyl = 100;
|
|
|
|
sc->dlabel.d_secperunit = sc->disksize;
|
|
|
|
sc->dlabel.d_rpm = 300;
|
|
|
|
sc->dlabel.d_interleave = 1;
|
|
|
|
sc->dlabel.d_flags = D_REMOVABLE;
|
|
|
|
sc->dlabel.d_npartitions= 1;
|
|
|
|
sc->dlabel.d_partitions[0].p_offset = 0;
|
|
|
|
sc->dlabel.d_partitions[0].p_size = sc->disksize;
|
|
|
|
sc->dlabel.d_partitions[0].p_fstype = 9;
|
|
|
|
sc->dlabel.d_magic = DISKMAGIC;
|
|
|
|
sc->dlabel.d_magic2 = DISKMAGIC;
|
|
|
|
sc->dlabel.d_checksum = dkcksum(&sc->dlabel);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->flags |= MCDLABEL;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcdsize(dev)
|
|
|
|
dev_t dev;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
int size;
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = mcdcd.cd_devs[MCDUNIT(dev)];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_volinfo(sc) >= 0) {
|
|
|
|
sc->blksize = MCDBLK;
|
|
|
|
size = msf2hsg(sc->volinfo.vol_msf);
|
|
|
|
sc->disksize = size * (MCDBLK / DEV_BSIZE);
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* lower level of driver starts here
|
|
|
|
**************************************************************/
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifdef notyet
|
1993-11-04 12:12:30 +03:00
|
|
|
static char irqs[] = {
|
1994-02-21 18:23:11 +03:00
|
|
|
0x00, 0x00, 0x10, 0x20, 0x00, 0x30, 0x00, 0x00,
|
|
|
|
0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00
|
1993-11-04 12:12:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static char drqs[] = {
|
1994-02-21 18:23:11 +03:00
|
|
|
0x00, 0x01, 0x00, 0x03, 0x00, 0x05, 0x06, 0x07
|
1993-11-04 12:12:30 +03:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
|
|
|
mcd_configure(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
outb(sc->iobase + mcd_config, sc->config);
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1994-03-29 08:35:37 +04:00
|
|
|
mcdprobe(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = (void *)self;
|
|
|
|
struct isa_attach_args *ia = aux;
|
|
|
|
u_short iobase = ia->ia_iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
int i;
|
1994-02-21 18:23:11 +03:00
|
|
|
int st, check;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifdef notyet
|
|
|
|
/* Get irq/drq configuration word. */
|
1994-03-29 08:35:37 +04:00
|
|
|
sc->config = irqs[ia->ia_irq];
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->iobase = iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Send a reset. */
|
|
|
|
outb(iobase + mcd_reset, 0);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(300000);
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get any pending status and throw away. */
|
|
|
|
for (i = 10; i; i--)
|
|
|
|
inb(iobase + mcd_status);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(1000);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Send get status command. */
|
|
|
|
outb(iobase + mcd_command, MCD_CMDGETSTAT);
|
|
|
|
i = mcd_getreply(sc, DELAY_GETREPLY);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (i < 0) {
|
1993-11-04 12:12:30 +03:00
|
|
|
#ifdef DEBUG
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("Mitsumi drive NOT detected\n");
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
1994-02-21 18:23:11 +03:00
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following code uses the 0xDC command, it returns a M from the
|
1994-02-21 18:23:11 +03:00
|
|
|
* second byte and a number in the third.
|
|
|
|
* (I hope you have the right drive for that, most drives don't do!)
|
|
|
|
* Whole code entirely rewriten by veit@gmd.de, the changes accessed
|
|
|
|
* the drive in an illegal way. Proper way is to use the timeout
|
|
|
|
* driven routines mcd_getreply etc. rather than arbitrary delays.
|
1993-11-04 12:12:30 +03:00
|
|
|
*/
|
|
|
|
|
1994-03-29 08:35:37 +04:00
|
|
|
delay(2000);
|
1994-02-21 18:23:11 +03:00
|
|
|
outb(iobase + mcd_command, MCD_CMDCONTINFO);
|
|
|
|
i = mcd_getreply(sc, DELAY_GETREPLY);
|
|
|
|
|
|
|
|
if (i < 0) {
|
1993-11-04 12:12:30 +03:00
|
|
|
#ifdef DEBUG
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("Mitsumi drive error\n");
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
st = mcd_getreply(sc, DELAY_GETREPLY);
|
|
|
|
if (st < 0)
|
|
|
|
return 0;
|
|
|
|
check = mcd_getreply(sc, DELAY_GETREPLY);
|
|
|
|
if (check < 0)
|
|
|
|
return 0;
|
|
|
|
/* Flush junk. */
|
|
|
|
(void) mcd_getreply(sc, DELAY_GETREPLY);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following is code which is not guaranteed to work for all
|
|
|
|
* drives, because the meaning of the expected 'M' is not clear
|
|
|
|
* (M_itsumi is an obvious assumption, but I don't trust that).
|
|
|
|
* Also, the original hack had a bogus condition that always
|
|
|
|
* returned true.
|
|
|
|
*/
|
|
|
|
#ifdef notdef
|
|
|
|
if (check != 'M') {
|
1993-11-04 12:12:30 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Mitsumi drive NOT detected\n");
|
1994-02-21 18:23:11 +03:00
|
|
|
#endif
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Mitsumi drive detected\n");
|
|
|
|
#endif
|
1994-03-29 08:35:37 +04:00
|
|
|
ia->ia_iosize = 4;
|
|
|
|
ia->ia_msize = 0;
|
|
|
|
return 1;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_waitrdy(iobase, dly)
|
|
|
|
u_short iobase;
|
|
|
|
int dly;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Wait until xfer port senses data ready. */
|
|
|
|
for (i = dly; i; i--) {
|
|
|
|
if ((inb(iobase + mcd_xfer) & MCD_ST_BUSY) == 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(1);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_getreply(sc, dly)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
int dly;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
u_short iobase = sc->iobase;
|
|
|
|
|
|
|
|
/* Wait data to become ready. */
|
|
|
|
if (mcd_waitrdy(iobase, dly) < 0) {
|
|
|
|
printf("%s: timeout in getreply\n", sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get the data. */
|
|
|
|
return inb(iobase + mcd_status);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_getstat(sc, sflg)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
int sflg;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
int i;
|
|
|
|
u_short iobase = sc->iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get the status. */
|
1993-11-04 12:12:30 +03:00
|
|
|
if (sflg)
|
1994-02-21 18:23:11 +03:00
|
|
|
outb(iobase + mcd_command, MCD_CMDGETSTAT);
|
|
|
|
i = mcd_getreply(sc, DELAY_GETREPLY);
|
|
|
|
if (i < 0) {
|
|
|
|
printf("%s: timeout in getstat\n", sc->sc_dev.dv_xname);
|
|
|
|
return -1;
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->status = i;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
mcd_setflags(sc);
|
|
|
|
return sc->status;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
|
|
|
mcd_setflags(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
|
|
|
/* Check flags. */
|
|
|
|
if (sc->status & (MCDDSKCHNG | MCDDOOROPEN)) {
|
|
|
|
MCD_TRACE("getstat: sensed DSKCHNG or DOOROPEN\n", 0, 0, 0, 0);
|
|
|
|
sc->flags &= ~MCDVALID;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->status & MCDAUDIOBSY)
|
|
|
|
sc->audio_status = CD_AS_PLAY_IN_PROGRESS;
|
|
|
|
else if (sc->audio_status == CD_AS_PLAY_IN_PROGRESS)
|
|
|
|
sc->audio_status = CD_AS_PLAY_COMPLETED;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_get(sc, buf, nmax)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
char *buf;
|
|
|
|
int nmax;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
int i, k;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
for (i = 0; i < nmax; i++) {
|
|
|
|
/* Wait for data. */
|
|
|
|
if ((k = mcd_getreply(sc, DELAY_GETREPLY)) < 0) {
|
|
|
|
printf("%s: timeout in get\n", sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
buf[i] = k;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_send(sc, cmd, nretries)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
int cmd, nretries;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
int i, k;
|
|
|
|
u_short iobase = sc->iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("send: cmd=0x%x\n", cmd, 0, 0, 0);
|
|
|
|
|
|
|
|
for (i = nretries; i; i--) {
|
|
|
|
outb(iobase + mcd_command, cmd);
|
|
|
|
if ((k = mcd_getstat(sc, 0)) != -1)
|
1993-11-04 12:12:30 +03:00
|
|
|
break;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
if (!i) {
|
|
|
|
printf("%s: send: retry count exceeded\n", sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
|
|
|
|
MCD_TRACE("send: status=0x%x\n", k, 0, 0, 0);
|
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
bcd2bin(b)
|
|
|
|
bcd_t b;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return (b >> 4) * 10 + (b & 15);
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
bcd_t
|
|
|
|
bin2bcd(b)
|
|
|
|
int b;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return ((b / 10) << 4) | (b % 10);
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
void
|
|
|
|
hsg2msf(hsg, msf)
|
|
|
|
int hsg;
|
|
|
|
bcd_t *msf;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
hsg += 150;
|
|
|
|
M_msf(msf) = bin2bcd(hsg / 4500);
|
|
|
|
hsg %= 4500;
|
|
|
|
S_msf(msf) = bin2bcd(hsg / 75);
|
|
|
|
F_msf(msf) = bin2bcd(hsg % 75);
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
msf2hsg(msf)
|
|
|
|
bcd_t *msf;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
return (bcd2bin(M_msf(msf)) * 60 +
|
|
|
|
bcd2bin(S_msf(msf))) * 75 +
|
|
|
|
bcd2bin(F_msf(msf)) - 150;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_volinfo(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("volinfo: enter\n", 0, 0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get the status, in case the disc has been changed. */
|
|
|
|
if (mcd_getstat(sc, 1) < 0)
|
|
|
|
return EIO;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Just return if we already have it. */
|
|
|
|
if (sc->flags & MCDVOLINFO)
|
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Send volume info command. */
|
|
|
|
if (mcd_send(sc, MCD_CMDGETVOLINFO, MCD_RETRIES) < 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get the data. */
|
|
|
|
if (mcd_get(sc, (char*) &sc->volinfo, sizeof(struct mcd_volinfo)) < 0) {
|
|
|
|
printf("%s: volinfo: error reading data\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->volinfo.trk_low != 0 || sc->volinfo.trk_high != 0) {
|
|
|
|
/* Volinfo is OK. */
|
|
|
|
sc->flags |= MCDVOLINFO;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
1994-04-07 10:48:19 +04:00
|
|
|
mcdintr(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
u_short iobase = sc->iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
MCD_TRACE("stray interrupt xfer=0x%x\n", inb(iobase + mcd_xfer),
|
|
|
|
0, 0, 0);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Just read out status and ignore the rest. */
|
|
|
|
if (inb(iobase + mcd_xfer) != 0xff)
|
|
|
|
(void) inb(iobase + mcd_status);
|
1994-04-08 22:22:15 +04:00
|
|
|
|
|
|
|
return -1;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/*
|
|
|
|
* State machine to process read requests.
|
|
|
|
* Initialize with MCD_S_BEGIN: calculate sizes, and read status
|
1993-11-04 12:12:30 +03:00
|
|
|
* MCD_S_WAITSTAT: wait for status reply, set mode
|
|
|
|
* MCD_S_WAITMODE: waits for status reply from set mode, set read command
|
1994-02-21 18:23:11 +03:00
|
|
|
* MCD_S_WAITREAD: wait for read ready, read data.
|
1993-11-04 12:12:30 +03:00
|
|
|
*/
|
1994-05-05 09:35:42 +04:00
|
|
|
void
|
1994-05-05 12:26:13 +04:00
|
|
|
mcd_doread(arg)
|
1994-05-05 09:35:42 +04:00
|
|
|
void *arg;
|
|
|
|
{
|
1994-05-05 12:26:13 +04:00
|
|
|
struct mcd_mbx *mbx = arg;
|
1994-03-29 08:35:37 +04:00
|
|
|
struct mcd_softc *sc = mcdcd.cd_devs[mbx->unit];
|
1994-05-05 12:26:13 +04:00
|
|
|
u_short iobase = sc->iobase;
|
1994-02-21 18:23:11 +03:00
|
|
|
struct buf *bp = mbx->bp;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int rm, i, k;
|
1993-11-04 12:12:30 +03:00
|
|
|
struct mcd_read2 rbuf;
|
1994-02-21 18:23:11 +03:00
|
|
|
int blkno;
|
1993-11-04 12:12:30 +03:00
|
|
|
caddr_t addr;
|
|
|
|
|
|
|
|
loop:
|
1994-05-05 12:26:13 +04:00
|
|
|
switch (mbx->state) {
|
1993-11-04 12:12:30 +03:00
|
|
|
case MCD_S_BEGIN:
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get status. */
|
|
|
|
outb(iobase + mcd_command, MCD_CMDGETSTAT);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
mbx->count = RDELAY_WAITSTAT;
|
1994-05-05 12:26:13 +04:00
|
|
|
mbx->state = MCD_S_WAITSTAT;
|
|
|
|
timeout(mcd_doread, mbx, hz / 100);
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
case MCD_S_WAITSTAT:
|
1994-05-05 12:26:13 +04:00
|
|
|
untimeout(mcd_doread, mbx);
|
|
|
|
if (mbx->count-- < 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("%s: timeout getting status\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
goto readerr;
|
|
|
|
}
|
1994-05-05 12:26:13 +04:00
|
|
|
if (inb(iobase + mcd_xfer) & MCD_ST_BUSY) {
|
|
|
|
timeout(mcd_doread, mbx, hz / 100);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mcd_setflags(sc);
|
|
|
|
MCD_TRACE("doread: got WAITSTAT delay=%d\n",
|
|
|
|
RDELAY_WAITSTAT - mbx->count, 0, 0, 0);
|
|
|
|
|
|
|
|
/* Reject, if audio active. */
|
|
|
|
if (sc->status & MCDAUDIOBSY) {
|
|
|
|
printf("%s: audio is active\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
goto readerr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for raw/cooked mode. */
|
|
|
|
if (sc->flags & MCDREADRAW) {
|
|
|
|
rm = MCD_MD_RAW;
|
|
|
|
mbx->sz = MCDRBLK;
|
|
|
|
} else {
|
|
|
|
rm = MCD_MD_COOKED;
|
|
|
|
mbx->sz = sc->blksize;
|
|
|
|
}
|
|
|
|
|
|
|
|
mcd_put(iobase + mcd_command, MCD_CMDSETMODE);
|
|
|
|
mcd_put(iobase + mcd_command, rm);
|
|
|
|
|
|
|
|
mbx->count = RDELAY_WAITMODE;
|
|
|
|
mbx->state = MCD_S_WAITMODE;
|
|
|
|
timeout(mcd_doread, mbx, hz / 100);
|
|
|
|
return;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
case MCD_S_WAITMODE:
|
1994-05-05 12:26:13 +04:00
|
|
|
untimeout(mcd_doread, mbx);
|
1993-11-04 12:12:30 +03:00
|
|
|
if (mbx->count-- < 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("%s: timeout setting mode\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
goto readerr;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
if (inb(iobase + mcd_xfer) & MCD_ST_BUSY) {
|
1994-05-05 12:26:13 +04:00
|
|
|
timeout(mcd_doread, mbx, hz / 100);
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
mcd_setflags(sc);
|
|
|
|
MCD_TRACE("doread: got WAITMODE delay=%d\n",
|
|
|
|
RDELAY_WAITMODE - mbx->count, 0, 0, 0);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* For first block. */
|
|
|
|
mbx->nblk = (bp->b_bcount + (mbx->sz - 1)) / mbx->sz;
|
1993-11-04 12:12:30 +03:00
|
|
|
mbx->skip = 0;
|
|
|
|
|
1994-05-05 12:26:13 +04:00
|
|
|
nextblock:
|
1994-02-21 18:23:11 +03:00
|
|
|
blkno = (bp->b_blkno / (mbx->sz / DEV_BSIZE)) + mbx->p_offset +
|
|
|
|
(mbx->skip / mbx->sz);
|
|
|
|
|
|
|
|
MCD_TRACE("doread: read blkno=%d for bp=0x%x\n", blkno, bp, 0,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* Build parameter block. */
|
|
|
|
hsg2msf(blkno, rbuf.start_msf);
|
|
|
|
|
|
|
|
/* Send the read command. */
|
|
|
|
mcd_put(iobase + mcd_command, MCD_CMDREAD2);
|
|
|
|
mcd_put(iobase + mcd_command, rbuf.start_msf[0]);
|
|
|
|
mcd_put(iobase + mcd_command, rbuf.start_msf[1]);
|
|
|
|
mcd_put(iobase + mcd_command, rbuf.start_msf[2]);
|
|
|
|
mcd_put(iobase + mcd_command, 0);
|
|
|
|
mcd_put(iobase + mcd_command, 0);
|
|
|
|
mcd_put(iobase + mcd_command, 1);
|
1994-05-05 12:26:13 +04:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
mbx->count = RDELAY_WAITREAD;
|
1994-05-05 12:26:13 +04:00
|
|
|
mbx->state = MCD_S_WAITREAD;
|
|
|
|
timeout(mcd_doread, mbx, hz / 100);
|
1993-11-04 12:12:30 +03:00
|
|
|
return;
|
1994-02-21 18:23:11 +03:00
|
|
|
|
1993-11-04 12:12:30 +03:00
|
|
|
case MCD_S_WAITREAD:
|
1994-05-05 12:26:13 +04:00
|
|
|
untimeout(mcd_doread, mbx);
|
|
|
|
if (mbx->count-- < 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("%s: timeout reading data\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
goto readerr;
|
|
|
|
}
|
1994-05-05 12:26:13 +04:00
|
|
|
|
|
|
|
k = inb(iobase + mcd_xfer);
|
|
|
|
if ((k & 2) == 0) { /* XXX MCD_ST_AUDIOBSY? */
|
|
|
|
MCD_TRACE("doread: got data delay=%d\n",
|
|
|
|
RDELAY_WAITREAD - mbx->count, 0, 0, 0);
|
|
|
|
/* Data is ready. */
|
|
|
|
addr = bp->b_un.b_addr + mbx->skip;
|
|
|
|
outb(iobase + mcd_ctl2, 0x04); /* XXX */
|
|
|
|
for (i = 0; i < mbx->sz; i++)
|
|
|
|
*addr++ = inb(iobase + mcd_rdata);
|
|
|
|
outb(iobase + mcd_ctl2, 0x0c); /* XXX */
|
|
|
|
|
|
|
|
if (--mbx->nblk > 0) {
|
|
|
|
mbx->skip += mbx->sz;
|
|
|
|
goto nextblock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return buffer. */
|
|
|
|
bp->b_resid = 0;
|
|
|
|
biodone(bp);
|
|
|
|
|
|
|
|
sc->flags &= ~MCDMBXBSY;
|
|
|
|
mcd_start(sc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((k & MCD_ST_BUSY) == 0)
|
|
|
|
mcd_getstat(sc, 0);
|
|
|
|
timeout(mcd_doread, mbx, hz / 100);
|
|
|
|
return;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
readerr:
|
|
|
|
if (mbx->retry-- > 0) {
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("%s: retrying\n", sc->sc_dev.dv_xname);
|
1994-05-05 12:26:13 +04:00
|
|
|
mbx->state = MCD_S_BEGIN;
|
1993-11-04 12:12:30 +03:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Invalidate the buffer. */
|
1993-11-04 12:12:30 +03:00
|
|
|
bp->b_flags |= B_ERROR;
|
|
|
|
bp->b_resid = bp->b_bcount;
|
|
|
|
biodone(bp);
|
1994-02-21 18:23:11 +03:00
|
|
|
mcd_start(sc);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
#ifdef notyet
|
|
|
|
printf("%s: unit timeout; resetting\n", sc->sc_dev.dv_xname);
|
|
|
|
outb(mbx->iobase + mcd_reset, MCD_CMDRESET);
|
1994-03-06 20:18:43 +03:00
|
|
|
delay(300000);
|
1994-02-21 18:23:11 +03:00
|
|
|
(void)mcd_getstat(sc, 1);
|
|
|
|
(void)mcd_getstat(sc, 1);
|
|
|
|
/*sc->status &= ~MCDDSKCHNG; */
|
|
|
|
sc->debug = 1; /* preventive set debug mode */
|
1993-11-04 12:12:30 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_setmode(sc, mode)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
int mode;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
u_short iobase = sc->iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
int retry;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("%s: setting mode to %d\n", sc->sc_dev.dv_xname, mode);
|
|
|
|
for (retry = MCD_RETRIES; retry; retry--) {
|
|
|
|
outb(iobase + mcd_command, MCD_CMDSETMODE);
|
|
|
|
outb(iobase + mcd_command, mode);
|
|
|
|
if (mcd_getstat(sc, 0) != -1)
|
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_toc_header(sc, th)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_toc_header *th;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_volinfo(sc) < 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
th->len = msf2hsg(sc->volinfo.vol_msf);
|
|
|
|
th->starting_track = bcd2bin(sc->volinfo.trk_low);
|
|
|
|
th->ending_track = bcd2bin(sc->volinfo.trk_high);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_read_toc(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
struct ioc_toc_header th;
|
|
|
|
struct mcd_qchninfo q;
|
|
|
|
int rc, trk, idx, retry;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Only read TOC if needed. */
|
|
|
|
if (sc->flags & MCDTOC)
|
|
|
|
return 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: read_toc: reading toc header\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if (mcd_toc_header(sc, &th) != 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: read_toc: stopping play\n", sc->sc_dev.dv_xname);
|
|
|
|
if ((rc = mcd_stop(sc)) != 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return rc;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Try setting the mode twice. */
|
|
|
|
if (mcd_setmode(sc, MCD_MD_TOC) != 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return EIO;
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_setmode(sc, MCD_MD_TOC) != 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return EIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: read_toc: reading qchannel info\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
for (trk = th.starting_track; trk <= th.ending_track; trk++)
|
|
|
|
sc->toc[trk].idx_no = 0;
|
1993-11-04 12:12:30 +03:00
|
|
|
trk = th.ending_track - th.starting_track + 1;
|
1994-02-21 18:23:11 +03:00
|
|
|
for (retry = 300; retry && trk > 0; retry--) {
|
|
|
|
if (mcd_getqchan(sc, &q) < 0)
|
|
|
|
break;
|
1993-11-04 12:12:30 +03:00
|
|
|
idx = bcd2bin(q.idx_no);
|
1994-02-21 18:23:11 +03:00
|
|
|
if (idx > 0 && idx < MCD_MAXTOCS && q.trk_no == 0 &&
|
|
|
|
sc->toc[idx].idx_no == 0) {
|
|
|
|
sc->toc[idx] = q;
|
|
|
|
trk--;
|
|
|
|
}
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_setmode(sc, MCD_MD_COOKED) != 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return EIO;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (trk != 0)
|
|
|
|
return ENXIO;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Add a fake last+1. */
|
1993-11-04 12:12:30 +03:00
|
|
|
idx = th.ending_track + 1;
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->toc[idx].ctrl_adr = sc->toc[idx-1].ctrl_adr;
|
|
|
|
sc->toc[idx].trk_no = 0;
|
|
|
|
sc->toc[idx].idx_no = 0xaa;
|
|
|
|
sc->toc[idx].hd_pos_msf[0] = sc->volinfo.vol_msf[0];
|
|
|
|
sc->toc[idx].hd_pos_msf[1] = sc->volinfo.vol_msf[1];
|
|
|
|
sc->toc[idx].hd_pos_msf[2] = sc->volinfo.vol_msf[2];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->flags |= MCDTOC;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_toc_entry(sc, te)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_read_toc_entry *te;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
struct ret_toc {
|
1993-11-04 12:12:30 +03:00
|
|
|
struct ioc_toc_header th;
|
|
|
|
struct cd_toc_entry rt;
|
|
|
|
} ret_toc;
|
|
|
|
struct ioc_toc_header th;
|
|
|
|
int rc, i;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Make sure we have a valid TOC. */
|
|
|
|
if ((rc = mcd_read_toc(sc)) != 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return rc;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Find the TOC to copy. */
|
1993-11-04 12:12:30 +03:00
|
|
|
i = te->starting_track;
|
|
|
|
if (i == MCD_LASTPLUS1)
|
1994-02-21 18:23:11 +03:00
|
|
|
i = bcd2bin(sc->volinfo.trk_high) + 1;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Verify starting track. */
|
|
|
|
if (i < bcd2bin(sc->volinfo.trk_low) ||
|
|
|
|
i > bcd2bin(sc->volinfo.trk_high) + 1)
|
1993-11-04 12:12:30 +03:00
|
|
|
return EINVAL;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Do we have room? */
|
1993-11-04 12:12:30 +03:00
|
|
|
if (te->data_len < sizeof(struct ioc_toc_header) +
|
1994-02-21 18:23:11 +03:00
|
|
|
sizeof(struct cd_toc_entry))
|
|
|
|
return EINVAL;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Copy the TOC header. */
|
|
|
|
if (mcd_toc_header(sc, &th) < 0)
|
|
|
|
return EIO;
|
1993-11-04 12:12:30 +03:00
|
|
|
ret_toc.th = th;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Copy the TOC data. */
|
|
|
|
ret_toc.rt.control = sc->toc[i].ctrl_adr;
|
1993-11-04 12:12:30 +03:00
|
|
|
ret_toc.rt.addr_type = te->address_format;
|
|
|
|
ret_toc.rt.track = i;
|
1994-02-21 18:23:11 +03:00
|
|
|
if (te->address_format == CD_MSF_FORMAT) {
|
|
|
|
ret_toc.rt.addr[1] = sc->toc[i].hd_pos_msf[0];
|
|
|
|
ret_toc.rt.addr[2] = sc->toc[i].hd_pos_msf[1];
|
|
|
|
ret_toc.rt.addr[3] = sc->toc[i].hd_pos_msf[2];
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Copy the data back. */
|
|
|
|
copyout(&ret_toc, te->data,
|
|
|
|
sizeof(struct cd_toc_entry) + sizeof(struct ioc_toc_header));
|
1993-11-04 12:12:30 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_stop(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_send(sc, MCD_CMDSTOPAUDIO, MCD_RETRIES) < 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return ENXIO;
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->audio_status = CD_AS_PLAY_COMPLETED;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_getqchan(sc, q)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct mcd_qchninfo *q;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_send(sc, MCD_CMDGETQCHN, MCD_RETRIES) < 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
1994-02-21 18:23:11 +03:00
|
|
|
if (mcd_get(sc, (char *) q, sizeof(struct mcd_qchninfo)) < 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return -1;
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: getqchan: ctl=%d t=%d i=%d ttm=%d:%d.%d dtm=%d:%d.%d\n",
|
|
|
|
sc->sc_dev.dv_xname, q->ctrl_adr, q->trk_no, q->idx_no,
|
|
|
|
q->trk_size_msf[0], q->trk_size_msf[1], q->trk_size_msf[2],
|
|
|
|
q->trk_size_msf[0], q->trk_size_msf[1], q->trk_size_msf[2]);
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_subchan(sc, ch)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_read_subchannel *ch;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
struct mcd_qchninfo q;
|
|
|
|
struct cd_sub_channel_info data;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: subchan: af=%d df=%d\n", sc->sc_dev.dv_xname,
|
|
|
|
ch->address_format, ch->data_format);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (ch->address_format != CD_MSF_FORMAT)
|
|
|
|
return EIO;
|
|
|
|
if (ch->data_format != CD_CURRENT_POSITION)
|
|
|
|
return EIO;
|
|
|
|
if (mcd_getqchan(sc, &q) < 0)
|
|
|
|
return EIO;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
data.header.audio_status = sc->audio_status;
|
1993-11-04 12:12:30 +03:00
|
|
|
data.what.position.data_format = CD_MSF_FORMAT;
|
|
|
|
data.what.position.track_number = bcd2bin(q.trk_no);
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (copyout(&data, ch->data, sizeof(struct cd_sub_channel_info)) != 0)
|
1993-11-04 12:12:30 +03:00
|
|
|
return EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_playtracks(sc, pt)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct ioc_play_track *pt;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
struct mcd_read2 pb;
|
|
|
|
int a = pt->start_track;
|
|
|
|
int z = pt->end_track;
|
|
|
|
int rc;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if ((rc = mcd_read_toc(sc)) != 0)
|
|
|
|
return rc;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
printf("%s: playtracks: from %d:%d to %d:%d\n", sc->sc_dev.dv_xname,
|
|
|
|
a, pt->start_index, z, pt->end_index);
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (a < sc->volinfo.trk_low || a > sc->volinfo.trk_high || a > z ||
|
|
|
|
z < sc->volinfo.trk_low || z > sc->volinfo.trk_high)
|
1993-11-04 12:12:30 +03:00
|
|
|
return EINVAL;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
pb.start_msf[0] = sc->toc[a].hd_pos_msf[0];
|
|
|
|
pb.start_msf[1] = sc->toc[a].hd_pos_msf[1];
|
|
|
|
pb.start_msf[2] = sc->toc[a].hd_pos_msf[2];
|
|
|
|
pb.end_msf[0] = sc->toc[z+1].hd_pos_msf[0];
|
|
|
|
pb.end_msf[1] = sc->toc[z+1].hd_pos_msf[1];
|
|
|
|
pb.end_msf[2] = sc->toc[z+1].hd_pos_msf[2];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
return mcd_play(sc, &pb);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_play(sc, pb)
|
|
|
|
struct mcd_softc *sc;
|
|
|
|
struct mcd_read2 *pb;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
1994-02-21 18:23:11 +03:00
|
|
|
u_short iobase = sc->iobase;
|
1993-11-04 12:12:30 +03:00
|
|
|
int retry, st;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->lastpb = *pb;
|
|
|
|
for (retry = MCD_RETRIES; retry; retry--) {
|
|
|
|
outb(iobase + mcd_command, MCD_CMDREAD2);
|
|
|
|
outb(iobase + mcd_command, pb->start_msf[0]);
|
|
|
|
outb(iobase + mcd_command, pb->start_msf[1]);
|
|
|
|
outb(iobase + mcd_command, pb->start_msf[2]);
|
|
|
|
outb(iobase + mcd_command, pb->end_msf[0]);
|
|
|
|
outb(iobase + mcd_command, pb->end_msf[1]);
|
|
|
|
outb(iobase + mcd_command, pb->end_msf[2]);
|
|
|
|
if ((st = mcd_getstat(sc, 0)) != -1)
|
|
|
|
break;
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->debug)
|
|
|
|
printf("%s: play: retry=%d status=%d\n", sc->sc_dev.dv_xname,
|
|
|
|
retry, st);
|
|
|
|
if (!retry)
|
|
|
|
return ENXIO;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
sc->audio_status = CD_AS_PLAY_IN_PROGRESS;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_pause(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
struct mcd_qchninfo q;
|
|
|
|
int rc;
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Verify current status. */
|
|
|
|
if (sc->audio_status != CD_AS_PLAY_IN_PROGRESS) {
|
|
|
|
printf("%s: pause: attempted when not playing\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
1993-11-04 12:12:30 +03:00
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Get the current position. */
|
|
|
|
if (mcd_getqchan(sc, &q) < 0)
|
|
|
|
return EIO;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Copy it into lastpb. */
|
|
|
|
sc->lastpb.start_msf[0] = q.hd_pos_msf[0];
|
|
|
|
sc->lastpb.start_msf[1] = q.hd_pos_msf[1];
|
|
|
|
sc->lastpb.start_msf[2] = q.hd_pos_msf[2];
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Stop playing. */
|
|
|
|
if ((rc = mcd_stop(sc)) != 0)
|
|
|
|
return rc;
|
1993-11-04 12:12:30 +03:00
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
/* Set the proper status and exit. */
|
|
|
|
sc->audio_status = CD_AS_PLAY_PAUSED;
|
1993-11-04 12:12:30 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
int
|
|
|
|
mcd_resume(sc)
|
|
|
|
struct mcd_softc *sc;
|
1993-11-04 12:12:30 +03:00
|
|
|
{
|
|
|
|
|
1994-02-21 18:23:11 +03:00
|
|
|
if (sc->audio_status != CD_AS_PLAY_PAUSED)
|
|
|
|
return EINVAL;
|
|
|
|
return mcd_play(sc, &sc->lastpb);
|
1993-11-04 12:12:30 +03:00
|
|
|
}
|