1995-03-24 18:33:02 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1995 Mikael Hybsch
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Portions of this file are copied from mcd.c
|
|
|
|
* which has the following copyrights:
|
|
|
|
*
|
|
|
|
* Copyright 1993 by Holger Veit (data part)
|
|
|
|
* Copyright 1993 by Brian Moore (audio part)
|
|
|
|
* Changes Copyright 1993 by Gary Clark II
|
|
|
|
* Changes Copyright (C) 1994 by Andrew A. Chernov
|
|
|
|
*
|
|
|
|
* Rewrote probe routine to work on newer Mitsumi drives.
|
|
|
|
* Additional changes (C) 1994 by Jordan K. Hubbard
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 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. The name of the author may not be used to endorse or promote products
|
2002-06-02 20:05:59 +00:00
|
|
|
* derived from this software without specific prior written permission
|
1995-03-24 18:33:02 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
#undef SCD_DEBUG
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-05-28 13:40:48 +00:00
|
|
|
#include <sys/kernel.h>
|
1995-03-24 18:33:02 +00:00
|
|
|
#include <sys/conf.h>
|
2002-11-05 09:50:15 +00:00
|
|
|
#include <sys/fcntl.h>
|
2000-05-05 09:59:14 +00:00
|
|
|
#include <sys/bio.h>
|
1995-03-24 18:33:02 +00:00
|
|
|
#include <sys/cdio.h>
|
2002-11-05 09:50:15 +00:00
|
|
|
#include <sys/disk.h>
|
2000-05-28 13:40:48 +00:00
|
|
|
#include <sys/bus.h>
|
1995-03-25 18:14:37 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
#include <machine/bus_pio.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/rman.h>
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
#include <isa/isavar.h>
|
|
|
|
|
|
|
|
#include <dev/scd/scdreg.h>
|
|
|
|
#include <dev/scd/scdvar.h>
|
the second set of changes in a move towards getting devices to be
totally dynamic.
this is only the devices in i386/isa
I'll do more tomorrow.
they're completely masked by #ifdef JREMOD at this stage...
the eventual aim is that every driver will do a SYSINIT
at startup BEFORE the probes, which will effectively
link it into the devsw tables etc.
If I'd thought about it more I'd have put that in in this set (damn)
The ioconf lines generated by config will also end up in the
device's own scope as well, so ioconf.c will eventually be gutted
the SYSINIT call to the driver will include a phase where the
driver links it's ioconf line into a chain of such. when this phase is done
then the user can modify them with the boot: -c
config menu if he wants, just like now..
config will put the config lines out in the .h file
(e.g. in aha.h will be the addresses for the aha driver to look.)
as I said this is a very small first step..
the aim of THIS set of edits is to not have to edit conf.c at all when
adding a new device.. the tabe will be a simple skeleton..
when this is done, it will allow other changes to be made,
all teh time still having a fully working kernel tree,
but the logical outcome is the complete REMOVAL of the devsw tables.
By the end of this, linked in drivers will be exactly the same as
run-time loaded drivers, except they JUST HAPPEN to already be linked
and present at startup..
the SYSINIT calls will be the equivalent of the "init" call
made to a newly loaded driver in every respect.
For this edit,
each of the files has the following code inserted into it:
obviously, tailored to suit..
----------------------somewhere at the top:
#ifdef JREMOD
#include <sys/conf.h>
#define CDEV_MAJOR 13
#define BDEV_MAJOR 4
static void sd_devsw_install();
#endif /*JREMOD */
---------------------somewhere that's run during bootup: EVENTUALLY a SYSINIT
#ifdef JREMOD
sd_devsw_install();
#endif /*JREMOD*/
-----------------------at the bottom:
#ifdef JREMOD
struct bdevsw sd_bdevsw =
{ sdopen, sdclose, sdstrategy, sdioctl, /*4*/
sddump, sdsize, 0 };
struct cdevsw sd_cdevsw =
{ sdopen, sdclose, rawread, rawwrite, /*13*/
sdioctl, nostop, nullreset, nodevtotty,/* sd */
seltrue, nommap, sdstrategy };
static sd_devsw_installed = 0;
static void sd_devsw_install()
{
dev_t descript;
if( ! sd_devsw_installed ) {
descript = makedev(CDEV_MAJOR,0);
cdevsw_add(&descript,&sd_cdevsw,NULL);
#if defined(BDEV_MAJOR)
descript = makedev(BDEV_MAJOR,0);
bdevsw_add(&descript,&sd_bdevsw,NULL);
#endif /*BDEV_MAJOR*/
sd_devsw_installed = 1;
}
}
#endif /* JREMOD */
1995-11-28 09:42:06 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
/* flags */
|
|
|
|
#define SCDOPEN 0x0001 /* device opened */
|
|
|
|
#define SCDVALID 0x0002 /* parameters loaded */
|
|
|
|
#define SCDINIT 0x0004 /* device is init'd */
|
|
|
|
#define SCDPROBING 0x0020 /* probing */
|
|
|
|
#define SCDTOC 0x0100 /* already read toc */
|
|
|
|
#define SCDMBXBSY 0x0200 /* local mbx is busy */
|
|
|
|
#define SCDSPINNING 0x0400 /* drive is spun up */
|
|
|
|
|
|
|
|
#define SCD_S_BEGIN 0
|
|
|
|
#define SCD_S_BEGIN1 1
|
|
|
|
#define SCD_S_WAITSTAT 2
|
|
|
|
#define SCD_S_WAITFIFO 3
|
|
|
|
#define SCD_S_WAITSPIN 4
|
|
|
|
#define SCD_S_WAITREAD 5
|
|
|
|
#define SCD_S_WAITPARAM 6
|
|
|
|
|
|
|
|
#define RDELAY_WAIT 300
|
|
|
|
#define RDELAY_WAITREAD 300
|
|
|
|
|
|
|
|
#define SCDBLKSIZE 2048
|
|
|
|
|
|
|
|
#ifdef SCD_DEBUG
|
1995-10-28 15:39:31 +00:00
|
|
|
static int scd_debuglevel = SCD_DEBUG;
|
2002-11-05 09:37:32 +00:00
|
|
|
# define XDEBUG(sc, level, fmt, args...) \
|
|
|
|
do { \
|
|
|
|
if (scd_debuglevel >= level) \
|
|
|
|
device_printf(sc->dev, fmt, ## args); \
|
|
|
|
} while (0)
|
1995-03-24 18:33:02 +00:00
|
|
|
#else
|
2002-11-05 09:37:32 +00:00
|
|
|
# define XDEBUG(sc, level, fmt, args...)
|
1995-03-24 18:33:02 +00:00
|
|
|
#endif
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
#define IS_ATTENTION(sc) ((SCD_READ(sc, IREG_STATUS) & SBIT_ATTENTION) != 0)
|
|
|
|
#define IS_BUSY(sc) ((SCD_READ(sc, IREG_STATUS) & SBIT_BUSY) != 0)
|
|
|
|
#define IS_DATA_RDY(sc) ((SCD_READ(sc, IREG_STATUS) & SBIT_DATA_READY) != 0)
|
|
|
|
#define STATUS_BIT(sc, bit) ((SCD_READ(sc, IREG_STATUS) & (bit)) != 0)
|
|
|
|
#define FSTATUS_BIT(sc, bit) ((SCD_READ(sc, IREG_FSTATUS) & (bit)) != 0)
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* prototypes */
|
|
|
|
static void hsg2msf(int hsg, bcd_t *msf);
|
|
|
|
static int msf2hsg(bcd_t *msf);
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
static void process_attention(struct scd_softc *);
|
|
|
|
static int waitfor_status_bits(struct scd_softc *, int bits_set, int bits_clear);
|
|
|
|
static int send_cmd(struct scd_softc *, u_char cmd, u_int nargs, ...);
|
|
|
|
static void init_drive(struct scd_softc *);
|
|
|
|
static int spin_up(struct scd_softc *);
|
|
|
|
static int read_toc(struct scd_softc *);
|
|
|
|
static int get_result(struct scd_softc *, int result_len, u_char *result);
|
|
|
|
static void print_error(struct scd_softc *, int errcode);
|
|
|
|
|
|
|
|
static void scd_start(struct scd_softc *);
|
1997-04-20 17:26:55 +00:00
|
|
|
static timeout_t scd_timeout;
|
2002-11-05 09:37:32 +00:00
|
|
|
static void scd_doread(struct scd_softc *, int state, struct scd_mbx *mbxin);
|
|
|
|
|
|
|
|
static int scd_eject(struct scd_softc *);
|
|
|
|
static int scd_stop(struct scd_softc *);
|
|
|
|
static int scd_pause(struct scd_softc *);
|
|
|
|
static int scd_resume(struct scd_softc *);
|
|
|
|
static int scd_playtracks(struct scd_softc *, struct ioc_play_track *pt);
|
|
|
|
static int scd_playmsf(struct scd_softc *, struct ioc_play_msf *msf);
|
|
|
|
static int scd_play(struct scd_softc *, struct ioc_play_msf *msf);
|
|
|
|
static int scd_subchan(struct scd_softc *, struct ioc_read_subchannel *sch);
|
|
|
|
static int read_subcode(struct scd_softc *, struct sony_subchannel_position_data *sch);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* for xcdplayer */
|
2002-11-05 09:37:32 +00:00
|
|
|
static int scd_toc_header(struct scd_softc *, struct ioc_toc_header *th);
|
|
|
|
static int scd_toc_entrys(struct scd_softc *, struct ioc_read_toc_entry *te);
|
|
|
|
static int scd_toc_entry(struct scd_softc *, struct ioc_read_toc_single_entry *te);
|
1995-03-24 18:33:02 +00:00
|
|
|
#define SCD_LASTPLUS1 170 /* don't ask, xcdplayer passes this in */
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static d_open_t scdopen;
|
|
|
|
static d_close_t scdclose;
|
|
|
|
static d_ioctl_t scdioctl;
|
|
|
|
static d_strategy_t scdstrategy;
|
|
|
|
|
|
|
|
#define CDEV_MAJOR 45
|
2001-03-26 12:41:29 +00:00
|
|
|
|
1998-07-04 22:30:26 +00:00
|
|
|
static struct cdevsw scd_cdevsw = {
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = scdopen,
|
|
|
|
.d_close = scdclose,
|
|
|
|
.d_read = physread,
|
|
|
|
.d_ioctl = scdioctl,
|
|
|
|
.d_strategy = scdstrategy,
|
|
|
|
.d_name = "scd",
|
|
|
|
.d_maj = CDEV_MAJOR,
|
|
|
|
.d_flags = D_DISK,
|
1999-05-30 16:53:49 +00:00
|
|
|
};
|
1998-07-04 22:30:26 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
int
|
|
|
|
scd_attach(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
int unit;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
unit = device_get_unit(sc->dev);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
init_drive(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags = SCDINIT;
|
|
|
|
sc->data.audio_status = CD_AS_AUDIO_INVALID;
|
|
|
|
bioq_init(&sc->data.head);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->scd_dev_t = make_dev(&scd_cdevsw, 8 * unit,
|
|
|
|
UID_ROOT, GID_OPERATOR, 0640, "scd%d", unit);
|
|
|
|
sc->scd_dev_t->si_drv1 = (void *)sc;
|
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
scdopen(dev_t dev, int flags, int fmt, struct thread *td)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
struct scd_softc *sc;
|
1995-03-24 18:33:02 +00:00
|
|
|
int rc;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
sc = (struct scd_softc *)dev->si_drv1;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* not initialized*/
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDINIT))
|
2002-11-05 10:12:03 +00:00
|
|
|
return (ENXIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* invalidated in the meantime? mark all open part's invalid */
|
2002-11-06 08:08:55 +00:00
|
|
|
if (sc->data.openflag)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (ENXIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "DEBUG: status = 0x%x\n", SCD_READ(sc, IREG_STATUS));
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if ((rc = spin_up(sc)) != 0) {
|
|
|
|
print_error(sc, rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDTOC)) {
|
1995-03-24 18:33:02 +00:00
|
|
|
int loop_count = 3;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
while (loop_count-- > 0 && (rc = read_toc(sc)) != 0) {
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc == ERR_NOT_SPINNING) {
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = spin_up(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc) {
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(sc, rc);\
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "TOC read error 0x%x\n", rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
dev->si_bsize_phys = sc->data.blksize;
|
1999-09-09 19:08:44 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.openflag = 1;
|
|
|
|
sc->data.flags |= SCDVALID;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
scdclose(dev_t dev, int flags, int fmt, struct thread *td)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
struct scd_softc *sc;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
sc = (struct scd_softc *)dev->si_drv1;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDINIT) || !sc->data.openflag)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (ENXIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS) {
|
2002-11-05 09:37:32 +00:00
|
|
|
(void)send_cmd(sc, CMD_SPIN_DOWN, 0);
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags &= ~SCDSPINNING;
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* close channel */
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.openflag = 0;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static void
|
2000-04-15 05:54:02 +00:00
|
|
|
scdstrategy(struct bio *bp)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
int s;
|
2002-11-05 09:37:32 +00:00
|
|
|
struct scd_softc *sc;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
sc = (struct scd_softc *)bp->bio_dev->si_drv1;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 2, "DEBUG: strategy: block=%ld, bcount=%ld\n",
|
|
|
|
(long)bp->bio_blkno, bp->bio_bcount);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (bp->bio_blkno < 0 || (bp->bio_bcount % SCDBLKSIZE)) {
|
|
|
|
device_printf(sc->dev, "strategy failure: blkno = %ld, bcount = %ld\n",
|
|
|
|
(long)bp->bio_blkno, bp->bio_bcount);
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EINVAL;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1995-03-24 18:33:02 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if device invalidated (e.g. media change, door open), error */
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDVALID)) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "media changed\n");
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EIO;
|
1995-03-24 18:33:02 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read only */
|
2000-04-15 05:54:02 +00:00
|
|
|
if (!(bp->bio_cmd == BIO_READ)) {
|
|
|
|
bp->bio_error = EROFS;
|
1995-03-24 18:33:02 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
/* no data to read */
|
2000-04-15 05:54:02 +00:00
|
|
|
if (bp->bio_bcount == 0)
|
1995-03-24 18:33:02 +00:00
|
|
|
goto done;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDTOC)) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EIO;
|
1995-03-24 18:33:02 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_pblkno = bp->bio_blkno;
|
|
|
|
bp->bio_resid = 0;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
/* queue it */
|
|
|
|
s = splbio();
|
2002-11-06 08:08:55 +00:00
|
|
|
bioqdisksort(&sc->data.head, bp);
|
1995-03-24 18:33:02 +00:00
|
|
|
splx(s);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
/* now check whether we can perform processing */
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_start(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_flags |= BIO_ERROR;
|
1995-03-24 18:33:02 +00:00
|
|
|
done:
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid = bp->bio_bcount;
|
1995-03-24 18:33:02 +00:00
|
|
|
biodone(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_start(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio *bp;
|
1999-05-06 18:54:19 +00:00
|
|
|
int s = splbio();
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (sc->data.flags & SCDMBXBSY) {
|
1995-03-24 18:33:02 +00:00
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
bp = bioq_first(&sc->data.head);
|
1996-05-03 14:57:27 +00:00
|
|
|
if (bp != 0) {
|
1995-03-24 18:33:02 +00:00
|
|
|
/* block found to process, dequeue */
|
2002-11-06 08:08:55 +00:00
|
|
|
bioq_remove(&sc->data.head, bp);
|
|
|
|
sc->data.flags |= SCDMBXBSY;
|
1995-03-24 18:33:02 +00:00
|
|
|
splx(s);
|
|
|
|
} else {
|
|
|
|
/* nothing to do */
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.mbx.retry = 3;
|
|
|
|
sc->data.mbx.bp = bp;
|
1995-03-24 18:33:02 +00:00
|
|
|
splx(s);
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
scd_doread(sc, SCD_S_BEGIN, &(sc->data.mbx));
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1995-12-08 11:19:42 +00:00
|
|
|
static int
|
2001-09-12 08:38:13 +00:00
|
|
|
scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
struct scd_softc *sc;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
sc = (struct scd_softc *)dev->si_drv1;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "ioctl: cmd=0x%lx\n", cmd);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDVALID))
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
switch (cmd) {
|
2002-11-05 09:50:15 +00:00
|
|
|
case DIOCGMEDIASIZE:
|
2002-11-06 08:08:55 +00:00
|
|
|
*(off_t *)addr = (off_t)sc->data.disksize * sc->data.blksize;
|
2002-11-05 09:50:15 +00:00
|
|
|
return (0);
|
|
|
|
break;
|
|
|
|
case DIOCGSECTORSIZE:
|
2002-11-06 08:08:55 +00:00
|
|
|
*(u_int *)addr = sc->data.blksize;
|
2002-11-05 09:50:15 +00:00
|
|
|
return (0);
|
|
|
|
break;
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCPLAYTRACKS:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_playtracks(sc, (struct ioc_play_track *) addr);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCPLAYBLOCKS:
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCPLAYMSF:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_playmsf(sc, (struct ioc_play_msf *) addr);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCREADSUBCHANNEL:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_subchan(sc, (struct ioc_read_subchannel *) addr);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOREADTOCHEADER:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_toc_header (sc, (struct ioc_toc_header *) addr);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOREADTOCENTRYS:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_toc_entrys (sc, (struct ioc_read_toc_entry*) addr);
|
1997-05-04 15:24:23 +00:00
|
|
|
case CDIOREADTOCENTRY:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_toc_entry (sc, (struct ioc_read_toc_single_entry*) addr);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCSETPATCH:
|
|
|
|
case CDIOCGETVOL:
|
|
|
|
case CDIOCSETVOL:
|
|
|
|
case CDIOCSETMONO:
|
|
|
|
case CDIOCSETSTERIO:
|
|
|
|
case CDIOCSETMUTE:
|
|
|
|
case CDIOCSETLEFT:
|
|
|
|
case CDIOCSETRIGHT:
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCRESUME:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_resume(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCPAUSE:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_pause(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCSTART:
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCSTOP:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_stop(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCEJECT:
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_eject(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCALLOW:
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCSETDEBUG:
|
|
|
|
#ifdef SCD_DEBUG
|
|
|
|
scd_debuglevel++;
|
|
|
|
#endif
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
case CDIOCCLRDEBUG:
|
|
|
|
#ifdef SCD_DEBUG
|
|
|
|
scd_debuglevel = 0;
|
|
|
|
|
|
|
|
#endif
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
default:
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "unsupported ioctl (cmd=0x%lx)\n", cmd);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (ENOTTY);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
* lower level of driver starts here
|
|
|
|
**************************************************************/
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_playtracks(struct scd_softc *sc, struct ioc_play_track *pt)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
struct ioc_play_msf msf;
|
|
|
|
int a = pt->start_track;
|
|
|
|
int z = pt->end_track;
|
1995-10-28 15:39:31 +00:00
|
|
|
int rc;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc == -ERR_NOT_SPINNING) {
|
2002-11-05 09:37:32 +00:00
|
|
|
if (spin_up(sc) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = read_toc(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
if (rc != 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(sc, rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "playtracks from %d:%d to %d:%d\n",
|
|
|
|
a, pt->start_index, z, pt->end_index);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if ( a < sc->data.first_track
|
|
|
|
|| a > sc->data.last_track
|
1995-03-24 18:33:02 +00:00
|
|
|
|| a > z
|
2002-11-06 08:08:55 +00:00
|
|
|
|| z > sc->data.last_track)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
bcopy(sc->data.toc[a].start_msf, &msf.start_m, 3);
|
|
|
|
hsg2msf(msf2hsg(sc->data.toc[z+1].start_msf)-1, &msf.end_m);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_play(sc, &msf);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The start/end msf is expected to be in bin format */
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_playmsf(struct scd_softc *sc, struct ioc_play_msf *msfin)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
struct ioc_play_msf msf;
|
|
|
|
|
|
|
|
msf.start_m = bin2bcd(msfin->start_m);
|
|
|
|
msf.start_s = bin2bcd(msfin->start_s);
|
|
|
|
msf.start_f = bin2bcd(msfin->start_f);
|
|
|
|
msf.end_m = bin2bcd(msfin->end_m);
|
|
|
|
msf.end_s = bin2bcd(msfin->end_s);
|
|
|
|
msf.end_f = bin2bcd(msfin->end_f);
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_play(sc, &msf);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The start/end msf is expected to be in bcd format */
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_play(struct scd_softc *sc, struct ioc_play_msf *msf)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
int i, rc;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "playing: %02x:%02x:%02x -> %02x:%02x:%02x\n",
|
1995-03-24 18:33:02 +00:00
|
|
|
msf->start_m, msf->start_s, msf->start_f,
|
2002-11-05 09:37:32 +00:00
|
|
|
msf->end_m, msf->end_s, msf->end_f);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = send_cmd(sc, CMD_PLAY_AUDIO, 7,
|
1995-03-24 18:33:02 +00:00
|
|
|
0x03,
|
|
|
|
msf->start_m, msf->start_s, msf->start_f,
|
|
|
|
msf->end_m, msf->end_s, msf->end_f);
|
|
|
|
if (rc == -ERR_NOT_SPINNING) {
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags &= ~SCDSPINNING;
|
2002-11-05 09:37:32 +00:00
|
|
|
if (spin_up(sc) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
} else if (rc < 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(sc, rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.audio_status = CD_AS_PLAY_IN_PROGRESS;
|
|
|
|
bcopy((char *)msf, (char *)&sc->data.last_play, sizeof(struct ioc_play_msf));
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_stop(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
(void)send_cmd(sc, CMD_STOP_AUDIO, 0);
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.audio_status = CD_AS_PLAY_COMPLETED;
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_pause(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
struct sony_subchannel_position_data subpos;
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (read_subcode(sc, &subpos) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.last_play.start_m = subpos.abs_msf[0];
|
|
|
|
sc->data.last_play.start_s = subpos.abs_msf[1];
|
|
|
|
sc->data.last_play.start_f = subpos.abs_msf[2];
|
|
|
|
sc->data.audio_status = CD_AS_PLAY_PAUSED;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "pause @ %02x:%02x:%02x\n",
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.last_play.start_m,
|
|
|
|
sc->data.last_play.start_s,
|
|
|
|
sc->data.last_play.start_f);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_resume(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
|
|
|
|
if (sc->data.audio_status != CD_AS_PLAY_PAUSED)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
2002-11-05 09:37:32 +00:00
|
|
|
return scd_play(sc, &sc->data.last_play);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_eject(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.audio_status = CD_AS_AUDIO_INVALID;
|
|
|
|
sc->data.flags &= ~(SCDSPINNING|SCDTOC);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0 ||
|
|
|
|
send_cmd(sc, CMD_SPIN_DOWN, 0) != 0 ||
|
|
|
|
send_cmd(sc, CMD_EJECT, 0) != 0)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_subchan(struct scd_softc *sc, struct ioc_read_subchannel *sch)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
struct sony_subchannel_position_data q;
|
|
|
|
struct cd_sub_channel_info data;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "subchan af=%d, df=%d\n",
|
|
|
|
sch->address_format, sch->data_format);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (sch->address_format != CD_MSF_FORMAT)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (sch->data_format != CD_CURRENT_POSITION)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (read_subcode(sc, &q) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
data.header.audio_status = sc->data.audio_status;
|
1995-03-24 18:33:02 +00:00
|
|
|
data.what.position.data_format = CD_MSF_FORMAT;
|
|
|
|
data.what.position.track_number = bcd2bin(q.track_number);
|
|
|
|
data.what.position.reladdr.msf.unused = 0;
|
|
|
|
data.what.position.reladdr.msf.minute = bcd2bin(q.rel_msf[0]);
|
|
|
|
data.what.position.reladdr.msf.second = bcd2bin(q.rel_msf[1]);
|
|
|
|
data.what.position.reladdr.msf.frame = bcd2bin(q.rel_msf[2]);
|
|
|
|
data.what.position.absaddr.msf.unused = 0;
|
|
|
|
data.what.position.absaddr.msf.minute = bcd2bin(q.abs_msf[0]);
|
|
|
|
data.what.position.absaddr.msf.second = bcd2bin(q.abs_msf[1]);
|
|
|
|
data.what.position.absaddr.msf.frame = bcd2bin(q.abs_msf[2]);
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (copyout(&data, sch->data, min(sizeof(struct cd_sub_channel_info), sch->data_len))!=0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EFAULT);
|
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
int
|
|
|
|
scd_probe(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
struct sony_drive_configuration drive_config;
|
|
|
|
int rc;
|
|
|
|
static char namebuf[8+16+8+3];
|
|
|
|
char *s = namebuf;
|
|
|
|
int loop_count = 0;
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags = SCDPROBING;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
bzero(&drive_config, sizeof(drive_config));
|
|
|
|
|
|
|
|
again:
|
|
|
|
/* Reset drive */
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RESET_DRIVE);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* Calm down */
|
|
|
|
DELAY(300000);
|
|
|
|
|
|
|
|
/* Only the ATTENTION bit may be set */
|
2002-11-05 09:37:32 +00:00
|
|
|
if ((SCD_READ(sc, IREG_STATUS) & ~1) != 0) {
|
|
|
|
XDEBUG(sc, 1, "too many bits set. probe failed.\n");
|
|
|
|
return (ENXIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = send_cmd(sc, CMD_GET_DRIVE_CONFIG, 0);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc != sizeof(drive_config)) {
|
|
|
|
/* Sometimes if the drive is playing audio I get */
|
|
|
|
/* the bad result 82. Fix by repeating the reset */
|
|
|
|
if (rc > 0 && loop_count++ == 0)
|
|
|
|
goto again;
|
2002-11-05 09:37:32 +00:00
|
|
|
return (ENXIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
if (get_result(sc, rc, (u_char *)&drive_config) != 0)
|
|
|
|
return (ENXIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
bcopy(drive_config.vendor, namebuf, 8);
|
|
|
|
s = namebuf+8;
|
|
|
|
while (*(s-1) == ' ') /* Strip trailing spaces */
|
|
|
|
s--;
|
|
|
|
*s++ = ' ';
|
|
|
|
bcopy(drive_config.product, s, 16);
|
|
|
|
s += 16;
|
|
|
|
while (*(s-1) == ' ')
|
|
|
|
s--;
|
|
|
|
*s++ = ' ';
|
|
|
|
bcopy(drive_config.revision, s, 8);
|
|
|
|
s += 8;
|
|
|
|
while (*(s-1) == ' ')
|
|
|
|
s--;
|
|
|
|
*s = 0;
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.name = namebuf;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
if (drive_config.config & 0x10)
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.double_speed = 1;
|
1995-03-24 18:33:02 +00:00
|
|
|
else
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.double_speed = 0;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
read_subcode(struct scd_softc *sc, struct sony_subchannel_position_data *scp)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = send_cmd(sc, CMD_GET_SUBCHANNEL_DATA, 0);
|
|
|
|
if (rc < 0 || rc < sizeof(*scp))
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
2002-11-05 09:37:32 +00:00
|
|
|
if (get_result(sc, rc, (u_char *)scp) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* State machine copied from mcd.c */
|
|
|
|
|
|
|
|
/* This (and the code in mcd.c) will not work with more than one drive */
|
2002-11-05 09:37:32 +00:00
|
|
|
/* because there is only one sc->ch_mbxsave below. Should fix that some day. */
|
|
|
|
/* (sc->ch_mbxsave & state should probably be included in the scd_data struct and */
|
1995-03-24 18:33:02 +00:00
|
|
|
/* the unit number used as first argument to scd_doread().) /Micke */
|
|
|
|
|
|
|
|
/* state machine to process read requests
|
|
|
|
* initialize with SCD_S_BEGIN: reset state machine
|
|
|
|
* SCD_S_WAITSTAT: wait for ready (!busy)
|
|
|
|
* SCD_S_WAITSPIN: wait for drive to spin up (if not spinning)
|
|
|
|
* SCD_S_WAITFIFO: wait for param fifo to get ready, them exec. command.
|
|
|
|
* SCD_S_WAITREAD: wait for data ready, read data
|
|
|
|
* SCD_S_WAITPARAM: wait for command result params, read them, error if bad data read.
|
|
|
|
*/
|
|
|
|
|
1997-04-20 17:26:55 +00:00
|
|
|
static void
|
|
|
|
scd_timeout(void *arg)
|
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
struct scd_softc *sc;
|
|
|
|
sc = (struct scd_softc *)arg;
|
|
|
|
|
|
|
|
scd_doread(sc, sc->ch_state, sc->ch_mbxsave);
|
1997-04-20 17:26:55 +00:00
|
|
|
}
|
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
static void
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_doread(struct scd_softc *sc, int state, struct scd_mbx *mbxin)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? sc->ch_mbxsave : mbxin;
|
2000-04-15 05:54:02 +00:00
|
|
|
struct bio *bp = mbx->bp;
|
2002-11-05 09:37:32 +00:00
|
|
|
int i;
|
1995-03-24 18:33:02 +00:00
|
|
|
int blknum;
|
|
|
|
caddr_t addr;
|
|
|
|
static char sdata[3]; /* Must be preserved between calls to this function */
|
|
|
|
|
|
|
|
loop:
|
|
|
|
switch (state) {
|
|
|
|
case SCD_S_BEGIN:
|
2002-11-05 09:37:32 +00:00
|
|
|
mbx = sc->ch_mbxsave = mbxin;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
case SCD_S_BEGIN1:
|
|
|
|
/* get status */
|
|
|
|
mbx->count = RDELAY_WAIT;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
process_attention(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
goto trystat;
|
|
|
|
|
|
|
|
case SCD_S_WAITSTAT:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITSTAT;
|
|
|
|
untimeout(scd_timeout, (caddr_t)sc, sc->ch);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (mbx->count-- <= 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "timeout. drive busy.\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
goto harderr;
|
|
|
|
}
|
|
|
|
|
|
|
|
trystat:
|
2002-11-05 09:37:32 +00:00
|
|
|
if (IS_BUSY(sc)) {
|
|
|
|
sc->ch_state = SCD_S_WAITSTAT;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
process_attention(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* reject, if audio active */
|
2002-11-06 08:08:55 +00:00
|
|
|
if (sc->data.audio_status & CD_AS_PLAY_IN_PROGRESS) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "audio is active\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
goto harderr;
|
|
|
|
}
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
mbx->sz = sc->data.blksize;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* for first block */
|
2000-04-15 05:54:02 +00:00
|
|
|
mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz;
|
1995-03-24 18:33:02 +00:00
|
|
|
mbx->skip = 0;
|
|
|
|
|
|
|
|
nextblock:
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDVALID))
|
1995-03-24 18:33:02 +00:00
|
|
|
goto changed;
|
|
|
|
|
2000-04-15 05:54:02 +00:00
|
|
|
blknum = (bp->bio_blkno / (mbx->sz/DEV_BSIZE))
|
2002-11-05 09:50:15 +00:00
|
|
|
+ mbx->skip/mbx->sz;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 2, "scd_doread: read blknum=%d\n", blknum);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* build parameter block */
|
|
|
|
hsg2msf(blknum, sdata);
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
|
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RPARAM_CLEAR);
|
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_DATA_READY_CLEAR);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (FSTATUS_BIT(sc, FBIT_WPARAM_READY))
|
1995-03-24 18:33:02 +00:00
|
|
|
goto writeparam;
|
|
|
|
|
|
|
|
mbx->count = 100;
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITFIFO;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case SCD_S_WAITSPIN:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITSPIN;
|
|
|
|
untimeout(scd_timeout,(caddr_t)sc, sc->ch);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (mbx->count-- <= 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "timeout waiting for drive to spin up.\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
goto harderr;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
if (!STATUS_BIT(sc, SBIT_RESULT_READY)) {
|
|
|
|
sc->ch_state = SCD_S_WAITSPIN;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
|
|
|
|
switch ((i = SCD_READ(sc, IREG_RESULT)) & 0xf0) {
|
1995-03-24 18:33:02 +00:00
|
|
|
case 0x20:
|
2002-11-05 09:37:32 +00:00
|
|
|
i = SCD_READ(sc, IREG_RESULT);
|
|
|
|
print_error(sc, i);
|
1995-03-24 18:33:02 +00:00
|
|
|
goto harderr;
|
|
|
|
case 0x00:
|
2002-11-05 09:37:32 +00:00
|
|
|
(void)SCD_READ(sc, IREG_RESULT);
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags |= SCDSPINNING;
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "DEBUG: spin up complete\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
state = SCD_S_BEGIN1;
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
case SCD_S_WAITFIFO:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITFIFO;
|
|
|
|
untimeout(scd_timeout,(caddr_t)sc, sc->ch);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (mbx->count-- <= 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "timeout. write param not ready.\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
goto harderr;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
if (!FSTATUS_BIT(sc, FBIT_WPARAM_READY)) {
|
|
|
|
sc->ch_state = SCD_S_WAITFIFO;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc,hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "mbx->count (writeparamwait) = %d(%d)\n", mbx->count, 100);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
writeparam:
|
|
|
|
/* The reason this test isn't done 'till now is to make sure */
|
|
|
|
/* that it is ok to send the SPIN_UP cmd below. */
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDSPINNING)) {
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "spinning up drive ...\n");
|
|
|
|
SCD_WRITE(sc, OREG_COMMAND, CMD_SPIN_UP);
|
1995-03-24 18:33:02 +00:00
|
|
|
mbx->count = 300;
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITSPIN;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send the read command */
|
2002-11-10 03:45:49 +00:00
|
|
|
critical_enter();
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_WPARAMS, sdata[0]);
|
|
|
|
SCD_WRITE(sc, OREG_WPARAMS, sdata[1]);
|
|
|
|
SCD_WRITE(sc, OREG_WPARAMS, sdata[2]);
|
|
|
|
SCD_WRITE(sc, OREG_WPARAMS, 0);
|
|
|
|
SCD_WRITE(sc, OREG_WPARAMS, 0);
|
|
|
|
SCD_WRITE(sc, OREG_WPARAMS, 1);
|
|
|
|
SCD_WRITE(sc, OREG_COMMAND, CMD_READ);
|
2002-11-10 03:45:49 +00:00
|
|
|
critical_exit();
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
mbx->count = RDELAY_WAITREAD;
|
|
|
|
for (i = 0; i < 50; i++) {
|
2002-11-05 09:37:32 +00:00
|
|
|
if (STATUS_BIT(sc, SBIT_DATA_READY))
|
1995-03-24 18:33:02 +00:00
|
|
|
goto got_data;
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITREAD;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
case SCD_S_WAITREAD:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITREAD;
|
|
|
|
untimeout(scd_timeout,(caddr_t)sc, sc->ch);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (mbx->count-- <= 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
if (STATUS_BIT(sc, SBIT_RESULT_READY))
|
1995-03-24 18:33:02 +00:00
|
|
|
goto got_param;
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "timeout while reading data\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
goto readerr;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
if (!STATUS_BIT(sc, SBIT_DATA_READY)) {
|
|
|
|
process_attention(sc);
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDVALID))
|
1995-03-24 18:33:02 +00:00
|
|
|
goto changed;
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITREAD;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 2, "mbx->count (after RDY_BIT) = %d(%d)\n", mbx->count, RDELAY_WAITREAD);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
got_data:
|
|
|
|
/* data is ready */
|
2000-04-15 05:54:02 +00:00
|
|
|
addr = bp->bio_data + mbx->skip;
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_DATA_READY_CLEAR);
|
|
|
|
SCD_READ_MULTI(sc, IREG_DATA, addr, mbx->sz);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
mbx->count = 100;
|
|
|
|
for (i = 0; i < 20; i++) {
|
2002-11-05 09:37:32 +00:00
|
|
|
if (STATUS_BIT(sc, SBIT_RESULT_READY))
|
1995-03-24 18:33:02 +00:00
|
|
|
goto waitfor_param;
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
goto waitfor_param;
|
|
|
|
|
|
|
|
case SCD_S_WAITPARAM:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->ch_state = SCD_S_WAITPARAM;
|
|
|
|
untimeout(scd_timeout,(caddr_t)sc, sc->ch);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (mbx->count-- <= 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "timeout waiting for params\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
goto readerr;
|
|
|
|
}
|
|
|
|
|
|
|
|
waitfor_param:
|
2002-11-05 09:37:32 +00:00
|
|
|
if (!STATUS_BIT(sc, SBIT_RESULT_READY)) {
|
|
|
|
sc->ch_state = SCD_S_WAITPARAM;
|
|
|
|
sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-11-05 10:12:03 +00:00
|
|
|
#ifdef SCD_DEBUG
|
1995-03-24 18:33:02 +00:00
|
|
|
if (mbx->count < 100 && scd_debuglevel > 0)
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "mbx->count (paramwait) = %d(%d)\n", mbx->count, 100);
|
1995-03-24 18:33:02 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
got_param:
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
|
|
|
|
switch ((i = SCD_READ(sc, IREG_RESULT)) & 0xf0) {
|
1995-03-24 18:33:02 +00:00
|
|
|
case 0x50:
|
|
|
|
switch (i) {
|
|
|
|
case ERR_FATAL_READ_ERROR1:
|
|
|
|
case ERR_FATAL_READ_ERROR2:
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "unrecoverable read error 0x%x\n", i);
|
1995-03-24 18:33:02 +00:00
|
|
|
goto harderr;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x20:
|
2002-11-05 09:37:32 +00:00
|
|
|
i = SCD_READ(sc, IREG_RESULT);
|
1995-03-24 18:33:02 +00:00
|
|
|
switch (i) {
|
|
|
|
case ERR_NOT_SPINNING:
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "read error: drive not spinning\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
if (mbx->retry-- > 0) {
|
|
|
|
state = SCD_S_BEGIN1;
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags &= ~SCDSPINNING;
|
1995-03-24 18:33:02 +00:00
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
goto harderr;
|
|
|
|
default:
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(sc, i);
|
1995-03-24 18:33:02 +00:00
|
|
|
goto readerr;
|
|
|
|
}
|
|
|
|
case 0x00:
|
2002-11-05 09:37:32 +00:00
|
|
|
i = SCD_READ(sc, IREG_RESULT);
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (--mbx->nblk > 0) {
|
|
|
|
mbx->skip += mbx->sz;
|
|
|
|
goto nextblock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return buffer */
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_resid = 0;
|
1995-03-24 18:33:02 +00:00
|
|
|
biodone(bp);
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags &= ~SCDMBXBSY;
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_start(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
readerr:
|
|
|
|
if (mbx->retry-- > 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "retrying ...\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
state = SCD_S_BEGIN1;
|
|
|
|
goto loop;
|
|
|
|
}
|
|
|
|
harderr:
|
|
|
|
/* invalidate the buffer */
|
2000-04-15 05:54:02 +00:00
|
|
|
bp->bio_error = EIO;
|
|
|
|
bp->bio_flags |= BIO_ERROR;
|
|
|
|
bp->bio_resid = bp->bio_bcount;
|
1995-03-24 18:33:02 +00:00
|
|
|
biodone(bp);
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags &= ~SCDMBXBSY;
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_start(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
changed:
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "media changed\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
goto harderr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hsg2msf(int hsg, bcd_t *msf)
|
|
|
|
{
|
2002-11-06 08:08:55 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
hsg += 150;
|
|
|
|
M_msf(msf) = bin2bcd(hsg / 4500);
|
|
|
|
hsg %= 4500;
|
|
|
|
S_msf(msf) = bin2bcd(hsg / 75);
|
|
|
|
F_msf(msf) = bin2bcd(hsg % 75);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
msf2hsg(bcd_t *msf)
|
|
|
|
{
|
2002-11-06 08:08:55 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
return (bcd2bin(M_msf(msf)) * 60 +
|
|
|
|
bcd2bin(S_msf(msf))) * 75 +
|
|
|
|
bcd2bin(F_msf(msf)) - 150;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-05 09:37:32 +00:00
|
|
|
process_attention(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
unsigned char code;
|
|
|
|
int count = 0;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
while (IS_ATTENTION(sc) && count++ < 30) {
|
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_ATTENTION_CLEAR);
|
|
|
|
code = SCD_READ(sc, IREG_RESULT);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
#ifdef SCD_DEBUG
|
1995-03-24 18:33:02 +00:00
|
|
|
if (scd_debuglevel > 0) {
|
|
|
|
if (count == 1)
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "DEBUG: ATTENTIONS = 0x%x", code);
|
1995-03-24 18:33:02 +00:00
|
|
|
else
|
|
|
|
printf(",0x%x", code);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case ATTEN_SPIN_DOWN:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->data.flags &= ~SCDSPINNING;
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ATTEN_SPIN_UP_DONE:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->data.flags |= SCDSPINNING;
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ATTEN_AUDIO_DONE:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->data.audio_status = CD_AS_PLAY_COMPLETED;
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ATTEN_DRIVE_LOADED:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->data.flags &= ~(SCDTOC|SCDSPINNING|SCDVALID);
|
|
|
|
sc->data.audio_status = CD_AS_AUDIO_INVALID;
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ATTEN_EJECT_PUSHED:
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->data.flags &= ~SCDVALID;
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
DELAY(100);
|
|
|
|
}
|
2002-11-05 10:12:03 +00:00
|
|
|
#ifdef SCD_DEBUG
|
1995-03-24 18:33:02 +00:00
|
|
|
if (scd_debuglevel > 0 && count > 0)
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 OR sony error code */
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
spin_up(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
unsigned char res_reg[12];
|
|
|
|
unsigned int res_size;
|
|
|
|
int rc;
|
|
|
|
int loop_count = 0;
|
|
|
|
|
|
|
|
again:
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = send_cmd(sc, CMD_SPIN_UP, 0, 0, res_reg, &res_size);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc != 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 2, "CMD_SPIN_UP error 0x%x\n", rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (rc);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (!(sc->data.flags & SCDTOC)) {
|
|
|
|
rc = send_cmd(sc, CMD_READ_TOC, 0);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc == ERR_NOT_SPINNING) {
|
|
|
|
if (loop_count++ < 3)
|
|
|
|
goto again;
|
2002-11-05 10:12:03 +00:00
|
|
|
return (rc);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
if (rc != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (rc);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
sc->data.flags |= SCDSPINNING;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct sony_tracklist *
|
|
|
|
get_tl(struct sony_toc *toc, int size)
|
|
|
|
{
|
|
|
|
struct sony_tracklist *tl = &toc->tracks[0];
|
|
|
|
|
|
|
|
if (tl->track != 0xb0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (tl);
|
1995-03-24 18:33:02 +00:00
|
|
|
(char *)tl += 9;
|
1995-05-30 08:16:23 +00:00
|
|
|
if (tl->track != 0xb1)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (tl);
|
1995-03-24 18:33:02 +00:00
|
|
|
(char *)tl += 9;
|
1995-05-30 08:16:23 +00:00
|
|
|
if (tl->track != 0xb2)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (tl);
|
1995-03-24 18:33:02 +00:00
|
|
|
(char *)tl += 9;
|
1995-05-30 08:16:23 +00:00
|
|
|
if (tl->track != 0xb3)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (tl);
|
1995-03-24 18:33:02 +00:00
|
|
|
(char *)tl += 9;
|
1995-05-30 08:16:23 +00:00
|
|
|
if (tl->track != 0xb4)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (tl);
|
1995-03-24 18:33:02 +00:00
|
|
|
(char *)tl += 9;
|
1995-05-30 08:16:23 +00:00
|
|
|
if (tl->track != 0xc0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (tl);
|
1995-03-24 18:33:02 +00:00
|
|
|
(char *)tl += 9;
|
2002-11-05 10:12:03 +00:00
|
|
|
return (tl);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
read_toc(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
struct sony_toc toc;
|
|
|
|
struct sony_tracklist *tl;
|
|
|
|
int rc, i, j;
|
|
|
|
u_long first, last;
|
|
|
|
|
2002-11-05 10:56:14 +00:00
|
|
|
rc = send_cmd(sc, CMD_GET_TOC, 1, 1);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc < 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (rc);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc > sizeof(toc)) {
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "program error: toc too large (%d)\n", rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
2002-11-05 09:37:32 +00:00
|
|
|
if (get_result(sc, rc, (u_char *)&toc) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "toc read. len = %d, sizeof(toc) = %d\n", rc, sizeof(toc));
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
tl = get_tl(&toc, rc);
|
|
|
|
first = msf2hsg(tl->start_msf);
|
|
|
|
last = msf2hsg(toc.lead_out_start_msf);
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.blksize = SCDBLKSIZE;
|
|
|
|
sc->data.disksize = last*sc->data.blksize/DEV_BSIZE;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "firstsector = %ld, lastsector = %ld", first, last);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.first_track = bcd2bin(toc.first_track);
|
|
|
|
sc->data.last_track = bcd2bin(toc.last_track);
|
|
|
|
if (sc->data.last_track > (MAX_TRACKS-2))
|
|
|
|
sc->data.last_track = MAX_TRACKS-2;
|
|
|
|
for (j = 0, i = sc->data.first_track; i <= sc->data.last_track; i++, j++) {
|
|
|
|
sc->data.toc[i].adr = tl[j].adr;
|
|
|
|
sc->data.toc[i].ctl = tl[j].ctl; /* for xcdplayer */
|
|
|
|
bcopy(tl[j].start_msf, sc->data.toc[i].start_msf, 3);
|
1995-03-24 18:33:02 +00:00
|
|
|
#ifdef SCD_DEBUG
|
|
|
|
if (scd_debuglevel > 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
if ((j % 3) == 0) {
|
|
|
|
printf("\n");
|
|
|
|
device_printf(sc->dev, "tracks ");
|
|
|
|
}
|
1995-03-24 18:33:02 +00:00
|
|
|
printf("[%03d: %2d %2d %2d] ", i,
|
2002-11-06 08:08:55 +00:00
|
|
|
bcd2bin(sc->data.toc[i].start_msf[0]),
|
|
|
|
bcd2bin(sc->data.toc[i].start_msf[1]),
|
|
|
|
bcd2bin(sc->data.toc[i].start_msf[2]));
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2002-11-06 08:08:55 +00:00
|
|
|
bcopy(toc.lead_out_start_msf, sc->data.toc[sc->data.last_track+1].start_msf, 3);
|
1995-03-24 18:33:02 +00:00
|
|
|
#ifdef SCD_DEBUG
|
|
|
|
if (scd_debuglevel > 0) {
|
2002-11-06 08:08:55 +00:00
|
|
|
i = sc->data.last_track+1;
|
1995-03-24 18:33:02 +00:00
|
|
|
printf("[END: %2d %2d %2d]\n",
|
2002-11-06 08:08:55 +00:00
|
|
|
bcd2bin(sc->data.toc[i].start_msf[0]),
|
|
|
|
bcd2bin(sc->data.toc[i].start_msf[1]),
|
|
|
|
bcd2bin(sc->data.toc[i].start_msf[2]));
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
sc->data.flags |= SCDTOC;
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-05 09:37:32 +00:00
|
|
|
init_drive(struct scd_softc *sc)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = send_cmd(sc, CMD_SET_DRIVE_PARAM, 2,
|
|
|
|
0x05, 0x03 | ((sc->data.double_speed) ? 0x04: 0));
|
1995-03-24 18:33:02 +00:00
|
|
|
if (rc != 0)
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "Unable to set parameters. Errcode = 0x%x\n", rc);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 or errno */
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
get_result(struct scd_softc *sc, int result_len, u_char *result)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
int loop_index = 2; /* send_cmd() reads two bytes ... */
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "DEBUG: get_result: bytes=%d\n", result_len);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
while (result_len-- > 0) {
|
|
|
|
if (loop_index++ >= 10) {
|
|
|
|
loop_index = 1;
|
2002-11-05 09:37:32 +00:00
|
|
|
if (waitfor_status_bits(sc, SBIT_RESULT_READY, 0))
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
if (result)
|
2002-11-05 09:37:32 +00:00
|
|
|
*result++ = SCD_READ(sc, IREG_RESULT);
|
1995-03-24 18:33:02 +00:00
|
|
|
else
|
2002-11-05 09:37:32 +00:00
|
|
|
(void)SCD_READ(sc, IREG_RESULT);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns -0x100 for timeout, -(drive error code) OR number of result bytes */
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
send_cmd(struct scd_softc *sc, u_char cmd, u_int nargs, ...)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
u_char c;
|
|
|
|
int rc;
|
|
|
|
int i;
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
if (waitfor_status_bits(sc, 0, SBIT_BUSY)) {
|
|
|
|
device_printf(sc->dev, "drive busy\n");
|
2002-11-05 10:12:03 +00:00
|
|
|
return (-0x100);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "DEBUG: send_cmd: cmd=0x%x nargs=%d", cmd, nargs);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
|
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RPARAM_CLEAR);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 100; i++)
|
2002-11-05 09:37:32 +00:00
|
|
|
if (FSTATUS_BIT(sc, FBIT_WPARAM_READY))
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
2002-11-05 09:37:32 +00:00
|
|
|
if (!FSTATUS_BIT(sc, FBIT_WPARAM_READY)) {
|
|
|
|
XDEBUG(sc, 1, "\nwparam timeout\n");
|
2002-11-05 10:12:03 +00:00
|
|
|
return (-EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
va_start(ap, nargs);
|
|
|
|
for (i = 0; i < nargs; i++) {
|
|
|
|
c = (u_char)va_arg(ap, int);
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_WPARAMS, c);
|
|
|
|
XDEBUG(sc, 1, ",{0x%x}", c);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
va_end(ap);
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_COMMAND, cmd);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = waitfor_status_bits(sc, SBIT_RESULT_READY, SBIT_BUSY);
|
1995-10-28 15:39:31 +00:00
|
|
|
if (rc)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (-0x100);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 09:37:32 +00:00
|
|
|
SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
|
|
|
|
switch ((rc = SCD_READ(sc, IREG_RESULT)) & 0xf0) {
|
1995-03-24 18:33:02 +00:00
|
|
|
case 0x20:
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = SCD_READ(sc, IREG_RESULT);
|
2002-08-25 13:23:09 +00:00
|
|
|
/* FALLTHROUGH */
|
1995-03-24 18:33:02 +00:00
|
|
|
case 0x50:
|
2002-11-05 09:37:32 +00:00
|
|
|
XDEBUG(sc, 1, "DEBUG: send_cmd: drive_error=0x%x\n", rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (-rc);
|
1995-03-24 18:33:02 +00:00
|
|
|
case 0x00:
|
|
|
|
default:
|
2002-11-05 09:37:32 +00:00
|
|
|
rc = SCD_READ(sc, IREG_RESULT);
|
|
|
|
XDEBUG(sc, 1, "DEBUG: send_cmd: result_len=%d\n", rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (rc);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(struct scd_softc *sc, int errcode)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-06 08:08:55 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
switch (errcode) {
|
|
|
|
case -ERR_CD_NOT_LOADED:
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "door is open\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
case -ERR_NO_CD_INSIDE:
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "no cd inside\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (errcode == -0x100 || errcode > 0)
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "device timeout\n");
|
1995-03-24 18:33:02 +00:00
|
|
|
else
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "unexpected error 0x%x\n", -errcode);
|
1995-03-24 18:33:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns 0 or errno value */
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
waitfor_status_bits(struct scd_softc *sc, int bits_set, int bits_clear)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
2002-11-05 09:37:32 +00:00
|
|
|
u_int flags = sc->data.flags;
|
1995-03-24 18:33:02 +00:00
|
|
|
u_int max_loop;
|
|
|
|
u_char c = 0;
|
|
|
|
|
|
|
|
if (flags & SCDPROBING) {
|
|
|
|
max_loop = 0;
|
|
|
|
while (max_loop++ < 1000) {
|
2002-11-05 09:37:32 +00:00
|
|
|
c = SCD_READ(sc, IREG_STATUS);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (c == 0xff)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (c & SBIT_ATTENTION) {
|
2002-11-05 09:37:32 +00:00
|
|
|
process_attention(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((c & bits_set) == bits_set &&
|
|
|
|
(c & bits_clear) == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
DELAY(10000);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
max_loop = 100;
|
|
|
|
while (max_loop-- > 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
c = SCD_READ(sc, IREG_STATUS);
|
1995-03-24 18:33:02 +00:00
|
|
|
if (c & SBIT_ATTENTION) {
|
2002-11-05 09:37:32 +00:00
|
|
|
process_attention(sc);
|
1995-03-24 18:33:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((c & bits_set) == bits_set &&
|
|
|
|
(c & bits_clear) == 0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tsleep(waitfor_status_bits, PZERO - 1, "waitfor", hz/10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((c & bits_set) == bits_set &&
|
|
|
|
(c & bits_clear) == 0)
|
|
|
|
{
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
#ifdef SCD_DEBUG
|
|
|
|
if (scd_debuglevel > 0)
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "DEBUG: waitfor: TIMEOUT (0x%x,(0x%x,0x%x))\n", c, bits_set, bits_clear);
|
1995-03-24 18:33:02 +00:00
|
|
|
else
|
|
|
|
#endif
|
2002-11-05 09:37:32 +00:00
|
|
|
device_printf(sc->dev, "timeout.\n");
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* these two routines for xcdplayer - "borrowed" from mcd.c */
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_toc_header (struct scd_softc *sc, struct ioc_toc_header* th)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(sc, rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
th->starting_track = sc->data.first_track;
|
|
|
|
th->ending_track = sc->data.last_track;
|
1995-03-24 18:33:02 +00:00
|
|
|
th->len = 0; /* not used */
|
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te)
|
1995-03-24 18:33:02 +00:00
|
|
|
{
|
|
|
|
struct cd_toc_entry toc_entry;
|
|
|
|
int rc, i, len = te->data_len;
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(sc, rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find the toc to copy*/
|
|
|
|
i = te->starting_track;
|
|
|
|
if (i == SCD_LASTPLUS1)
|
2002-11-06 08:08:55 +00:00
|
|
|
i = sc->data.last_track + 1;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1995-03-24 18:33:02 +00:00
|
|
|
/* verify starting track */
|
2002-11-06 08:08:55 +00:00
|
|
|
if (i < sc->data.first_track || i > sc->data.last_track+1)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* valid length ? */
|
|
|
|
if (len < sizeof(struct cd_toc_entry)
|
|
|
|
|| (len % sizeof(struct cd_toc_entry)) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
|
|
|
/* copy the toc data */
|
2002-11-06 08:08:55 +00:00
|
|
|
toc_entry.control = sc->data.toc[i].ctl;
|
1995-03-24 18:33:02 +00:00
|
|
|
toc_entry.addr_type = te->address_format;
|
|
|
|
toc_entry.track = i;
|
|
|
|
if (te->address_format == CD_MSF_FORMAT) {
|
|
|
|
toc_entry.addr.msf.unused = 0;
|
2002-11-06 08:08:55 +00:00
|
|
|
toc_entry.addr.msf.minute = bcd2bin(sc->data.toc[i].start_msf[0]);
|
|
|
|
toc_entry.addr.msf.second = bcd2bin(sc->data.toc[i].start_msf[1]);
|
|
|
|
toc_entry.addr.msf.frame = bcd2bin(sc->data.toc[i].start_msf[2]);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the data back */
|
|
|
|
if (copyout(&toc_entry, te->data, sizeof(struct cd_toc_entry)) != 0)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EFAULT);
|
1995-03-24 18:33:02 +00:00
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1995-03-24 18:33:02 +00:00
|
|
|
}
|
|
|
|
|
1995-11-29 10:49:16 +00:00
|
|
|
|
1997-05-04 15:24:23 +00:00
|
|
|
static int
|
2002-11-05 09:37:32 +00:00
|
|
|
scd_toc_entry (struct scd_softc *sc, struct ioc_read_toc_single_entry *te)
|
1997-05-04 15:24:23 +00:00
|
|
|
{
|
|
|
|
struct cd_toc_entry toc_entry;
|
|
|
|
int rc, i;
|
|
|
|
|
2002-11-06 08:08:55 +00:00
|
|
|
if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
|
2002-11-05 09:37:32 +00:00
|
|
|
print_error(sc, rc);
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EIO);
|
1997-05-04 15:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find the toc to copy*/
|
|
|
|
i = te->track;
|
|
|
|
if (i == SCD_LASTPLUS1)
|
2002-11-06 08:08:55 +00:00
|
|
|
i = sc->data.last_track + 1;
|
1997-05-04 15:24:23 +00:00
|
|
|
|
|
|
|
/* verify starting track */
|
2002-11-06 08:08:55 +00:00
|
|
|
if (i < sc->data.first_track || i > sc->data.last_track+1)
|
2002-11-05 10:12:03 +00:00
|
|
|
return (EINVAL);
|
1997-05-04 15:24:23 +00:00
|
|
|
|
|
|
|
/* copy the toc data */
|
2002-11-06 08:08:55 +00:00
|
|
|
toc_entry.control = sc->data.toc[i].ctl;
|
1997-05-04 15:24:23 +00:00
|
|
|
toc_entry.addr_type = te->address_format;
|
|
|
|
toc_entry.track = i;
|
|
|
|
if (te->address_format == CD_MSF_FORMAT) {
|
|
|
|
toc_entry.addr.msf.unused = 0;
|
2002-11-06 08:08:55 +00:00
|
|
|
toc_entry.addr.msf.minute = bcd2bin(sc->data.toc[i].start_msf[0]);
|
|
|
|
toc_entry.addr.msf.second = bcd2bin(sc->data.toc[i].start_msf[1]);
|
|
|
|
toc_entry.addr.msf.frame = bcd2bin(sc->data.toc[i].start_msf[2]);
|
1997-05-04 15:24:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy the data back */
|
|
|
|
bcopy(&toc_entry, &te->entry, sizeof(struct cd_toc_entry));
|
|
|
|
|
2002-11-05 10:12:03 +00:00
|
|
|
return (0);
|
1997-05-04 15:24:23 +00:00
|
|
|
}
|