summaryrefslogtreecommitdiffstats
path: root/sys/dev/scd
diff options
context:
space:
mode:
authormdodd <mdodd@FreeBSD.org>2002-11-05 09:37:32 +0000
committermdodd <mdodd@FreeBSD.org>2002-11-05 09:37:32 +0000
commita7a511811501bf4ea163053b4fa97a83173a6d91 (patch)
treebcffe3131f9b6eec894a5aef875b5c2270b5f82c /sys/dev/scd
parent762ce3134537efee15aa7b8d19a43f565535c4ff (diff)
downloadFreeBSD-src-a7a511811501bf4ea163053b4fa97a83173a6d91.zip
FreeBSD-src-a7a511811501bf4ea163053b4fa97a83173a6d91.tar.gz
- Convert to newbus, bus_space etc.
- Move to MI space. Tested on: i386
Diffstat (limited to 'sys/dev/scd')
-rw-r--r--sys/dev/scd/scd.c725
-rw-r--r--sys/dev/scd/scd_isa.c183
-rw-r--r--sys/dev/scd/scdreg.h6
-rw-r--r--sys/dev/scd/scdvar.h68
4 files changed, 589 insertions, 393 deletions
diff --git a/sys/dev/scd/scd.c b/sys/dev/scd/scd.c
index b758035..84e2ce8 100644
--- a/sys/dev/scd/scd.c
+++ b/sys/dev/scd/scd.c
@@ -49,7 +49,6 @@
#define SCD_DEBUG 0
-#include "scd.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -61,9 +60,15 @@
#include <machine/stdarg.h>
-#include <i386/isa/isa_device.h>
-#include <i386/isa/scdreg.h>
+#include <machine/bus_pio.h>
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+#include <isa/isavar.h>
+
+#include <dev/scd/scdreg.h>
+#include <dev/scd/scdvar.h>
#define scd_part(dev) ((minor(dev)) & 7)
#define scd_unit(dev) (((minor(dev)) & 0x38) >> 3)
@@ -94,93 +99,54 @@
#ifdef SCD_DEBUG
static int scd_debuglevel = SCD_DEBUG;
-# define XDEBUG(level, data) {if (scd_debuglevel >= level) printf data;}
+# define XDEBUG(sc, level, fmt, args...) \
+ do { \
+ if (scd_debuglevel >= level) \
+ device_printf(sc->dev, fmt, ## args); \
+ } while (0)
#else
-# define XDEBUG(level, data)
+# define XDEBUG(sc, level, fmt, args...)
#endif
-struct scd_mbx {
- short unit;
- short port;
- short retry;
- short nblk;
- int sz;
- u_long skip;
- struct bio *bp;
- int p_offset;
- short count;
-};
-
-static struct scd_data {
- int iobase;
- char double_speed;
- char *name;
- short flags;
- int blksize;
- u_long disksize;
- struct disklabel dlabel;
- int openflag;
- struct {
- unsigned int adr :4;
- unsigned int ctl :4; /* xcdplayer needs this */
- unsigned char start_msf[3];
- } toc[MAX_TRACKS];
- short first_track;
- short last_track;
- struct ioc_play_msf last_play;
-
- short audio_status;
- struct bio_queue_head head; /* head of bio queue */
- struct scd_mbx mbx;
-} scd_data[NSCD];
+#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)
/* prototypes */
static void hsg2msf(int hsg, bcd_t *msf);
static int msf2hsg(bcd_t *msf);
-static void process_attention(unsigned unit);
-static __inline void write_control(unsigned port, unsigned data);
-static int waitfor_status_bits(int unit, int bits_set, int bits_clear);
-static int send_cmd(u_int unit, u_char cmd, u_int nargs, ...);
-static void init_drive(unsigned unit);
-static int spin_up(unsigned unit);
-static int read_toc(unsigned unit);
-static int get_result(u_int unit, int result_len, u_char *result);
-static void print_error(int unit, int errcode);
-
-static void scd_start(int unit);
+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 *);
static timeout_t scd_timeout;
-static void scd_doread(int state, struct scd_mbx *mbxin);
-
-static int scd_eject(int unit);
-static int scd_stop(int unit);
-static int scd_pause(int unit);
-static int scd_resume(int unit);
-static int scd_playtracks(int unit, struct ioc_play_track *pt);
-static int scd_playmsf(int unit, struct ioc_play_msf *msf);
-static int scd_play(int unit, struct ioc_play_msf *msf);
-static int scd_subchan(int unit, struct ioc_read_subchannel *sc);
-static int read_subcode(int unit, struct sony_subchannel_position_data *sc);
+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);
/* for xcdplayer */
-static int scd_toc_header(int unit, struct ioc_toc_header *th);
-static int scd_toc_entrys(int unit, struct ioc_read_toc_entry *te);
-static int scd_toc_entry(int unit, struct ioc_read_toc_single_entry *te);
+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);
#define SCD_LASTPLUS1 170 /* don't ask, xcdplayer passes this in */
-static int scd_probe(struct isa_device *dev);
-static int scd_attach(struct isa_device *dev);
-struct isa_driver scddriver = {
- INTR_TYPE_BIO,
- scd_probe,
- scd_attach,
- "scd"
-};
-COMPAT_ISA_DRIVER(scd, scddriver);
-
-/* For canceling our timeout */
-static struct callout_handle tohandle = CALLOUT_HANDLE_INITIALIZER(&tohanle);
-
static d_open_t scdopen;
static d_close_t scdclose;
static d_ioctl_t scdioctl;
@@ -205,42 +171,39 @@ static struct cdevsw scd_cdevsw = {
};
-static int
-scd_attach(struct isa_device *dev)
+int
+scd_attach(struct scd_softc *sc)
{
- int unit = dev->id_unit;
- struct scd_data *cd = scd_data + unit;
-
- cd->iobase = dev->id_iobase; /* Already set by probe, but ... */
+ struct scd_data *cd;
+ int unit;
- /* name filled in probe */
- printf("scd%d: <%s>\n", dev->id_unit, scd_data[dev->id_unit].name);
+ cd = &sc->data;
+ unit = device_get_unit(sc->dev);
- init_drive(dev->id_unit);
+ init_drive(sc);
cd->flags = SCDINIT;
cd->audio_status = CD_AS_AUDIO_INVALID;
bioq_init(&cd->head);
- make_dev(&scd_cdevsw, dkmakeminor(unit, 0, 0),
- UID_ROOT, GID_OPERATOR, 0640, "scd%da", unit);
- make_dev(&scd_cdevsw, dkmakeminor(unit, 0, RAW_PART),
- UID_ROOT, GID_OPERATOR, 0640, "scd%dc", unit);
- return 1;
+ 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;
+
+ return 0;
}
static int
scdopen(dev_t dev, int flags, int fmt, struct thread *td)
{
- int unit,part,phys;
+ struct scd_softc *sc;
+ int part,phys;
int rc;
struct scd_data *cd;
- unit = scd_unit(dev);
- if (unit >= NSCD)
- return ENXIO;
+ sc = (struct scd_softc *)dev->si_drv1;
- cd = scd_data + unit;
+ cd = &sc->data;
part = scd_part(dev);
phys = scd_phys(dev);
@@ -252,25 +215,25 @@ scdopen(dev_t dev, int flags, int fmt, struct thread *td)
if (cd->openflag)
return ENXIO;
- XDEBUG(1,("scd%d: DEBUG: status = 0x%x\n", unit, inb(cd->iobase+IREG_STATUS)));
+ XDEBUG(sc, 1, "DEBUG: status = 0x%x\n", SCD_READ(sc, IREG_STATUS));
- if ((rc = spin_up(unit)) != 0) {
- print_error(unit, rc);
+ if ((rc = spin_up(sc)) != 0) {
+ print_error(sc, rc);
return EIO;
}
if (!(cd->flags & SCDTOC)) {
int loop_count = 3;
- while (loop_count-- > 0 && (rc = read_toc(unit)) != 0) {
+ while (loop_count-- > 0 && (rc = read_toc(sc)) != 0) {
if (rc == ERR_NOT_SPINNING) {
- rc = spin_up(unit);
+ rc = spin_up(sc);
if (rc) {
- print_error(unit, rc);\
+ print_error(sc, rc);\
return EIO;
}
continue;
}
- printf("scd%d: TOC read error 0x%x\n", unit, rc);
+ device_printf(sc->dev, "TOC read error 0x%x\n", rc);
return EIO;
}
}
@@ -286,14 +249,13 @@ scdopen(dev_t dev, int flags, int fmt, struct thread *td)
static int
scdclose(dev_t dev, int flags, int fmt, struct thread *td)
{
- int unit,part,phys;
+ struct scd_softc *sc;
+ int part,phys;
struct scd_data *cd;
- unit = scd_unit(dev);
- if (unit >= NSCD)
- return ENXIO;
+ sc = (struct scd_softc *)dev->si_drv1;
- cd = scd_data + unit;
+ cd = &sc->data;
part = scd_part(dev);
phys = scd_phys(dev);
@@ -301,7 +263,7 @@ scdclose(dev_t dev, int flags, int fmt, struct thread *td)
return ENXIO;
if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS) {
- (void)send_cmd(unit, CMD_SPIN_DOWN, 0);
+ (void)send_cmd(sc, CMD_SPIN_DOWN, 0);
cd->flags &= ~SCDSPINNING;
}
@@ -317,16 +279,17 @@ scdstrategy(struct bio *bp)
{
struct scd_data *cd;
int s;
- int unit = scd_unit(bp->bio_dev);
+ struct scd_softc *sc;
- cd = scd_data + unit;
+ sc = (struct scd_softc *)bp->bio_dev->si_drv1;
+ cd = &sc->data;
- XDEBUG(2, ("scd%d: DEBUG: strategy: block=%ld, bcount=%ld\n",
- unit, (long)bp->bio_blkno, bp->bio_bcount));
+ XDEBUG(sc, 2, "DEBUG: strategy: block=%ld, bcount=%ld\n",
+ (long)bp->bio_blkno, bp->bio_bcount);
- if (unit >= NSCD || bp->bio_blkno < 0 || (bp->bio_bcount % SCDBLKSIZE)) {
- printf("scd%d: strategy failure: blkno = %ld, bcount = %ld\n",
- unit, (long)bp->bio_blkno, bp->bio_bcount);
+ 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);
bp->bio_error = EINVAL;
bp->bio_flags |= BIO_ERROR;
goto bad;
@@ -334,7 +297,7 @@ scdstrategy(struct bio *bp)
/* if device invalidated (e.g. media change, door open), error */
if (!(cd->flags & SCDVALID)) {
- printf("scd%d: media changed\n", unit);
+ device_printf(sc->dev, "media changed\n");
bp->bio_error = EIO;
goto bad;
}
@@ -366,7 +329,7 @@ scdstrategy(struct bio *bp)
splx(s);
/* now check whether we can perform processing */
- scd_start(unit);
+ scd_start(sc);
return;
bad:
@@ -378,9 +341,9 @@ done:
}
static void
-scd_start(int unit)
+scd_start(struct scd_softc *sc)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
struct bio *bp;
struct partition *p;
int s = splbio();
@@ -404,14 +367,12 @@ scd_start(int unit)
p = cd->dlabel.d_partitions + scd_part(bp->bio_dev);
- cd->mbx.unit = unit;
- cd->mbx.port = cd->iobase;
cd->mbx.retry = 3;
cd->mbx.bp = bp;
cd->mbx.p_offset = p->p_offset;
splx(s);
- scd_doread(SCD_S_BEGIN,&(cd->mbx));
+ scd_doread(sc, SCD_S_BEGIN, &(cd->mbx));
return;
}
@@ -419,13 +380,14 @@ static int
scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
{
struct scd_data *cd;
- int unit,part;
+ struct scd_softc *sc;
+ int part;
- unit = scd_unit(dev);
+ sc = (struct scd_softc *)dev->si_drv1;
part = scd_part(dev);
- cd = scd_data + unit;
+ cd = &sc->data;
- XDEBUG(1, ("scd%d: ioctl: cmd=0x%lx\n", unit, cmd));
+ XDEBUG(sc, 1, "ioctl: cmd=0x%lx\n", cmd);
if (!(cd->flags & SCDVALID))
return EIO;
@@ -435,19 +397,19 @@ scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
*(struct disklabel *)addr = cd->dlabel;
return 0;
case CDIOCPLAYTRACKS:
- return scd_playtracks(unit, (struct ioc_play_track *) addr);
+ return scd_playtracks(sc, (struct ioc_play_track *) addr);
case CDIOCPLAYBLOCKS:
return EINVAL;
case CDIOCPLAYMSF:
- return scd_playmsf(unit, (struct ioc_play_msf *) addr);
+ return scd_playmsf(sc, (struct ioc_play_msf *) addr);
case CDIOCREADSUBCHANNEL:
- return scd_subchan(unit, (struct ioc_read_subchannel *) addr);
+ return scd_subchan(sc, (struct ioc_read_subchannel *) addr);
case CDIOREADTOCHEADER:
- return scd_toc_header (unit, (struct ioc_toc_header *) addr);
+ return scd_toc_header (sc, (struct ioc_toc_header *) addr);
case CDIOREADTOCENTRYS:
- return scd_toc_entrys (unit, (struct ioc_read_toc_entry*) addr);
+ return scd_toc_entrys (sc, (struct ioc_read_toc_entry*) addr);
case CDIOREADTOCENTRY:
- return scd_toc_entry (unit, (struct ioc_read_toc_single_entry*) addr);
+ return scd_toc_entry (sc, (struct ioc_read_toc_single_entry*) addr);
case CDIOCSETPATCH:
case CDIOCGETVOL:
case CDIOCSETVOL:
@@ -458,15 +420,15 @@ scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
case CDIOCSETRIGHT:
return EINVAL;
case CDIOCRESUME:
- return scd_resume(unit);
+ return scd_resume(sc);
case CDIOCPAUSE:
- return scd_pause(unit);
+ return scd_pause(sc);
case CDIOCSTART:
return EINVAL;
case CDIOCSTOP:
- return scd_stop(unit);
+ return scd_stop(sc);
case CDIOCEJECT:
- return scd_eject(unit);
+ return scd_eject(sc);
case CDIOCALLOW:
return 0;
case CDIOCSETDEBUG:
@@ -481,7 +443,7 @@ scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
#endif
return 0;
default:
- printf("scd%d: unsupported ioctl (cmd=0x%lx)\n", unit, cmd);
+ device_printf(sc->dev, "unsupported ioctl (cmd=0x%lx)\n", cmd);
return ENOTTY;
}
}
@@ -491,28 +453,28 @@ scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
**************************************************************/
static int
-scd_playtracks(int unit, struct ioc_play_track *pt)
+scd_playtracks(struct scd_softc *sc, struct ioc_play_track *pt)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
struct ioc_play_msf msf;
int a = pt->start_track;
int z = pt->end_track;
int rc;
- if (!(cd->flags & SCDTOC) && (rc = read_toc(unit)) != 0) {
+ if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
if (rc == -ERR_NOT_SPINNING) {
- if (spin_up(unit) != 0)
+ if (spin_up(sc) != 0)
return EIO;
- rc = read_toc(unit);
+ rc = read_toc(sc);
}
if (rc != 0) {
- print_error(unit, rc);
+ print_error(sc, rc);
return EIO;
}
}
- XDEBUG(1, ("scd%d: playtracks from %d:%d to %d:%d\n", unit,
- a, pt->start_index, z, pt->end_index));
+ XDEBUG(sc, 1, "playtracks from %d:%d to %d:%d\n",
+ a, pt->start_index, z, pt->end_index);
if ( a < cd->first_track
|| a > cd->last_track
@@ -523,12 +485,12 @@ scd_playtracks(int unit, struct ioc_play_track *pt)
bcopy(cd->toc[a].start_msf, &msf.start_m, 3);
hsg2msf(msf2hsg(cd->toc[z+1].start_msf)-1, &msf.end_m);
- return scd_play(unit, &msf);
+ return scd_play(sc, &msf);
}
/* The start/end msf is expected to be in bin format */
static int
-scd_playmsf(int unit, struct ioc_play_msf *msfin)
+scd_playmsf(struct scd_softc *sc, struct ioc_play_msf *msfin)
{
struct ioc_play_msf msf;
@@ -539,31 +501,31 @@ scd_playmsf(int unit, struct ioc_play_msf *msfin)
msf.end_s = bin2bcd(msfin->end_s);
msf.end_f = bin2bcd(msfin->end_f);
- return scd_play(unit, &msf);
+ return scd_play(sc, &msf);
}
/* The start/end msf is expected to be in bcd format */
static int
-scd_play(int unit, struct ioc_play_msf *msf)
+scd_play(struct scd_softc *sc, struct ioc_play_msf *msf)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
int i, rc;
- XDEBUG(1, ("scd%d: playing: %02x:%02x:%02x -> %02x:%02x:%02x\n", unit,
+ XDEBUG(sc, 1, "playing: %02x:%02x:%02x -> %02x:%02x:%02x\n",
msf->start_m, msf->start_s, msf->start_f,
- msf->end_m, msf->end_s, msf->end_f));
+ msf->end_m, msf->end_s, msf->end_f);
for (i = 0; i < 2; i++) {
- rc = send_cmd(unit, CMD_PLAY_AUDIO, 7,
+ rc = send_cmd(sc, CMD_PLAY_AUDIO, 7,
0x03,
msf->start_m, msf->start_s, msf->start_f,
msf->end_m, msf->end_s, msf->end_f);
if (rc == -ERR_NOT_SPINNING) {
cd->flags &= ~SCDSPINNING;
- if (spin_up(unit) != 0)
+ if (spin_up(sc) != 0)
return EIO;
} else if (rc < 0) {
- print_error(unit, rc);
+ print_error(sc, rc);
return EIO;
} else {
break;
@@ -575,28 +537,28 @@ scd_play(int unit, struct ioc_play_msf *msf)
}
static int
-scd_stop(int unit)
+scd_stop(struct scd_softc *sc)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
- (void)send_cmd(unit, CMD_STOP_AUDIO, 0);
+ (void)send_cmd(sc, CMD_STOP_AUDIO, 0);
cd->audio_status = CD_AS_PLAY_COMPLETED;
return 0;
}
static int
-scd_pause(int unit)
+scd_pause(struct scd_softc *sc)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
struct sony_subchannel_position_data subpos;
if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS)
return EINVAL;
- if (read_subcode(unit, &subpos) != 0)
+ if (read_subcode(sc, &subpos) != 0)
return EIO;
- if (send_cmd(unit, CMD_STOP_AUDIO, 0) != 0)
+ if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0)
return EIO;
cd->last_play.start_m = subpos.abs_msf[0];
@@ -604,33 +566,34 @@ scd_pause(int unit)
cd->last_play.start_f = subpos.abs_msf[2];
cd->audio_status = CD_AS_PLAY_PAUSED;
- XDEBUG(1, ("scd%d: pause @ %02x:%02x:%02x\n", unit,
+ XDEBUG(sc, 1, "pause @ %02x:%02x:%02x\n",
cd->last_play.start_m,
cd->last_play.start_s,
- cd->last_play.start_f));
+ cd->last_play.start_f);
return 0;
}
static int
-scd_resume(int unit)
+scd_resume(struct scd_softc *sc)
{
- if (scd_data[unit].audio_status != CD_AS_PLAY_PAUSED)
+
+ if (sc->data.audio_status != CD_AS_PLAY_PAUSED)
return EINVAL;
- return scd_play(unit, &scd_data[unit].last_play);
+ return scd_play(sc, &sc->data.last_play);
}
static int
-scd_eject(int unit)
+scd_eject(struct scd_softc *sc)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
cd->audio_status = CD_AS_AUDIO_INVALID;
cd->flags &= ~(SCDSPINNING|SCDTOC);
- if (send_cmd(unit, CMD_STOP_AUDIO, 0) != 0 ||
- send_cmd(unit, CMD_SPIN_DOWN, 0) != 0 ||
- send_cmd(unit, CMD_EJECT, 0) != 0)
+ if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0 ||
+ send_cmd(sc, CMD_SPIN_DOWN, 0) != 0 ||
+ send_cmd(sc, CMD_EJECT, 0) != 0)
{
return EIO;
}
@@ -638,23 +601,22 @@ scd_eject(int unit)
}
static int
-scd_subchan(int unit, struct ioc_read_subchannel *sc)
+scd_subchan(struct scd_softc *sc, struct ioc_read_subchannel *sch)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
struct sony_subchannel_position_data q;
struct cd_sub_channel_info data;
- XDEBUG(1, ("scd%d: subchan af=%d, df=%d\n", unit,
- sc->address_format,
- sc->data_format));
+ XDEBUG(sc, 1, "subchan af=%d, df=%d\n",
+ sch->address_format, sch->data_format);
- if (sc->address_format != CD_MSF_FORMAT)
+ if (sch->address_format != CD_MSF_FORMAT)
return EINVAL;
- if (sc->data_format != CD_CURRENT_POSITION)
+ if (sch->data_format != CD_CURRENT_POSITION)
return EINVAL;
- if (read_subcode(unit, &q) != 0)
+ if (read_subcode(sc, &q) != 0)
return EIO;
data.header.audio_status = cd->audio_status;
@@ -669,54 +631,48 @@ scd_subchan(int unit, struct ioc_read_subchannel *sc)
data.what.position.absaddr.msf.second = bcd2bin(q.abs_msf[1]);
data.what.position.absaddr.msf.frame = bcd2bin(q.abs_msf[2]);
- if (copyout(&data, sc->data, min(sizeof(struct cd_sub_channel_info), sc->data_len))!=0)
+ if (copyout(&data, sch->data, min(sizeof(struct cd_sub_channel_info), sch->data_len))!=0)
return EFAULT;
return 0;
}
-static __inline void
-write_control(unsigned port, unsigned data)
-{
- outb(port + OREG_CONTROL, data);
-}
-
-static int
-scd_probe(struct isa_device *dev)
+int
+scd_probe(struct scd_softc *sc)
{
struct sony_drive_configuration drive_config;
- int unit = dev->id_unit;
+ struct scd_data *cd;
int rc;
static char namebuf[8+16+8+3];
char *s = namebuf;
int loop_count = 0;
- scd_data[unit].flags = SCDPROBING;
- scd_data[unit].iobase = dev->id_iobase;
+ cd = &sc->data;
+ cd->flags = SCDPROBING;
bzero(&drive_config, sizeof(drive_config));
again:
/* Reset drive */
- write_control(dev->id_iobase, CBIT_RESET_DRIVE);
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_RESET_DRIVE);
/* Calm down */
DELAY(300000);
/* Only the ATTENTION bit may be set */
- if ((inb(dev->id_iobase+IREG_STATUS) & ~1) != 0) {
- XDEBUG(1, ("scd: too many bits set. probe failed.\n"));
- return 0;
+ if ((SCD_READ(sc, IREG_STATUS) & ~1) != 0) {
+ XDEBUG(sc, 1, "too many bits set. probe failed.\n");
+ return (ENXIO);
}
- rc = send_cmd(unit, CMD_GET_DRIVE_CONFIG, 0);
+ rc = send_cmd(sc, CMD_GET_DRIVE_CONFIG, 0);
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;
- return 0;
+ return (ENXIO);
}
- if (get_result(unit, rc, (u_char *)&drive_config) != 0)
- return 0;
+ if (get_result(sc, rc, (u_char *)&drive_config) != 0)
+ return (ENXIO);
bcopy(drive_config.vendor, namebuf, 8);
s = namebuf+8;
@@ -734,25 +690,25 @@ again:
s--;
*s = 0;
- scd_data[unit].name = namebuf;
+ cd->name = namebuf;
if (drive_config.config & 0x10)
- scd_data[unit].double_speed = 1;
+ cd->double_speed = 1;
else
- scd_data[unit].double_speed = 0;
+ cd->double_speed = 0;
- return 4;
+ return (0);
}
static int
-read_subcode(int unit, struct sony_subchannel_position_data *sc)
+read_subcode(struct scd_softc *sc, struct sony_subchannel_position_data *scp)
{
int rc;
- rc = send_cmd(unit, CMD_GET_SUBCHANNEL_DATA, 0);
- if (rc < 0 || rc < sizeof(*sc))
+ rc = send_cmd(sc, CMD_GET_SUBCHANNEL_DATA, 0);
+ if (rc < 0 || rc < sizeof(*scp))
return EIO;
- if (get_result(unit, rc, (u_char *)sc) != 0)
+ if (get_result(sc, rc, (u_char *)scp) != 0)
return EIO;
return 0;
}
@@ -760,8 +716,8 @@ read_subcode(int unit, struct sony_subchannel_position_data *sc)
/* State machine copied from mcd.c */
/* This (and the code in mcd.c) will not work with more than one drive */
-/* because there is only one mbxsave below. Should fix that some day. */
-/* (mbxsave & state should probably be included in the scd_data struct and */
+/* 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 */
/* the unit number used as first argument to scd_doread().) /Micke */
/* state machine to process read requests
@@ -773,23 +729,22 @@ read_subcode(int unit, struct sony_subchannel_position_data *sc)
* SCD_S_WAITPARAM: wait for command result params, read them, error if bad data read.
*/
-static struct scd_mbx *mbxsave;
-
static void
scd_timeout(void *arg)
{
- scd_doread((int)arg, mbxsave);
+ struct scd_softc *sc;
+ sc = (struct scd_softc *)arg;
+
+ scd_doread(sc, sc->ch_state, sc->ch_mbxsave);
}
static void
-scd_doread(int state, struct scd_mbx *mbxin)
+scd_doread(struct scd_softc *sc, int state, struct scd_mbx *mbxin)
{
- struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? mbxsave : mbxin;
- int unit = mbx->unit;
- int port = mbx->port;
+ struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? sc->ch_mbxsave : mbxin;
struct bio *bp = mbx->bp;
- struct scd_data *cd = scd_data + unit;
- int reg,i;
+ struct scd_data *cd = &sc->data;
+ int i;
int blknum;
caddr_t addr;
static char sdata[3]; /* Must be preserved between calls to this function */
@@ -797,34 +752,35 @@ scd_doread(int state, struct scd_mbx *mbxin)
loop:
switch (state) {
case SCD_S_BEGIN:
- mbx = mbxsave = mbxin;
+ mbx = sc->ch_mbxsave = mbxin;
case SCD_S_BEGIN1:
/* get status */
mbx->count = RDELAY_WAIT;
- process_attention(unit);
+ process_attention(sc);
goto trystat;
case SCD_S_WAITSTAT:
- untimeout(scd_timeout,(caddr_t)SCD_S_WAITSTAT, tohandle);
+ sc->ch_state = SCD_S_WAITSTAT;
+ untimeout(scd_timeout, (caddr_t)sc, sc->ch);
if (mbx->count-- <= 0) {
- printf("scd%d: timeout. drive busy.\n",unit);
+ device_printf(sc->dev, "timeout. drive busy.\n");
goto harderr;
}
trystat:
- if (IS_BUSY(port)) {
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITSTAT,hz/100); /* XXX */
+ if (IS_BUSY(sc)) {
+ sc->ch_state = SCD_S_WAITSTAT;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
return;
}
- process_attention(unit);
+ process_attention(sc);
/* reject, if audio active */
if (cd->audio_status & CD_AS_PLAY_IN_PROGRESS) {
- printf("scd%d: audio is active\n",unit);
+ device_printf(sc->dev, "audio is active\n");
goto harderr;
}
@@ -841,164 +797,167 @@ nextblock:
blknum = (bp->bio_blkno / (mbx->sz/DEV_BSIZE))
+ mbx->p_offset + mbx->skip/mbx->sz;
- XDEBUG(2, ("scd%d: scd_doread: read blknum=%d\n", unit, blknum));
+ XDEBUG(sc, 2, "scd_doread: read blknum=%d\n", blknum);
/* build parameter block */
hsg2msf(blknum, sdata);
- write_control(port, CBIT_RESULT_READY_CLEAR);
- write_control(port, CBIT_RPARAM_CLEAR);
- write_control(port, CBIT_DATA_READY_CLEAR);
+ 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);
- if (FSTATUS_BIT(port, FBIT_WPARAM_READY))
+ if (FSTATUS_BIT(sc, FBIT_WPARAM_READY))
goto writeparam;
mbx->count = 100;
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITFIFO,hz/100); /* XXX */
+ sc->ch_state = SCD_S_WAITFIFO;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
return;
case SCD_S_WAITSPIN:
- untimeout(scd_timeout,(caddr_t)SCD_S_WAITSPIN, tohandle);
+ sc->ch_state = SCD_S_WAITSPIN;
+ untimeout(scd_timeout,(caddr_t)sc, sc->ch);
if (mbx->count-- <= 0) {
- printf("scd%d: timeout waiting for drive to spin up.\n", unit);
+ device_printf(sc->dev, "timeout waiting for drive to spin up.\n");
goto harderr;
}
- if (!STATUS_BIT(port, SBIT_RESULT_READY)) {
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITSPIN,hz/100); /* XXX */
+ if (!STATUS_BIT(sc, SBIT_RESULT_READY)) {
+ sc->ch_state = SCD_S_WAITSPIN;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
return;
}
- write_control(port, CBIT_RESULT_READY_CLEAR);
- switch ((i = inb(port+IREG_RESULT)) & 0xf0) {
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
+ switch ((i = SCD_READ(sc, IREG_RESULT)) & 0xf0) {
case 0x20:
- i = inb(port+IREG_RESULT);
- print_error(unit, i);
+ i = SCD_READ(sc, IREG_RESULT);
+ print_error(sc, i);
goto harderr;
case 0x00:
- (void)inb(port+IREG_RESULT);
+ (void)SCD_READ(sc, IREG_RESULT);
cd->flags |= SCDSPINNING;
break;
}
- XDEBUG(1, ("scd%d: DEBUG: spin up complete\n", unit));
+ XDEBUG(sc, 1, "DEBUG: spin up complete\n");
state = SCD_S_BEGIN1;
goto loop;
case SCD_S_WAITFIFO:
- untimeout(scd_timeout,(caddr_t)SCD_S_WAITFIFO, tohandle);
+ sc->ch_state = SCD_S_WAITFIFO;
+ untimeout(scd_timeout,(caddr_t)sc, sc->ch);
if (mbx->count-- <= 0) {
- printf("scd%d: timeout. write param not ready.\n",unit);
+ device_printf(sc->dev, "timeout. write param not ready.\n");
goto harderr;
}
- if (!FSTATUS_BIT(port, FBIT_WPARAM_READY)) {
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITFIFO,hz/100); /* XXX */
+ if (!FSTATUS_BIT(sc, FBIT_WPARAM_READY)) {
+ sc->ch_state = SCD_S_WAITFIFO;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc,hz/100); /* XXX */
return;
}
- XDEBUG(1, ("scd%d: mbx->count (writeparamwait) = %d(%d)\n", unit, mbx->count, 100));
+ XDEBUG(sc, 1, "mbx->count (writeparamwait) = %d(%d)\n", mbx->count, 100);
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. */
if (!(cd->flags & SCDSPINNING)) {
- XDEBUG(1, ("scd%d: spinning up drive ...\n", unit));
- outb(port+OREG_COMMAND, CMD_SPIN_UP);
+ XDEBUG(sc, 1, "spinning up drive ...\n");
+ SCD_WRITE(sc, OREG_COMMAND, CMD_SPIN_UP);
mbx->count = 300;
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITSPIN,hz/100); /* XXX */
+ sc->ch_state = SCD_S_WAITSPIN;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
return;
}
- reg = port + OREG_WPARAMS;
/* send the read command */
disable_intr();
- outb(reg, sdata[0]);
- outb(reg, sdata[1]);
- outb(reg, sdata[2]);
- outb(reg, 0);
- outb(reg, 0);
- outb(reg, 1);
- outb(port+OREG_COMMAND, CMD_READ);
+ 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);
enable_intr();
mbx->count = RDELAY_WAITREAD;
for (i = 0; i < 50; i++) {
- if (STATUS_BIT(port, SBIT_DATA_READY))
+ if (STATUS_BIT(sc, SBIT_DATA_READY))
goto got_data;
DELAY(100);
}
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITREAD,hz/100); /* XXX */
+ sc->ch_state = SCD_S_WAITREAD;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
return;
case SCD_S_WAITREAD:
- untimeout(scd_timeout,(caddr_t)SCD_S_WAITREAD, tohandle);
+ sc->ch_state = SCD_S_WAITREAD;
+ untimeout(scd_timeout,(caddr_t)sc, sc->ch);
if (mbx->count-- <= 0) {
- if (STATUS_BIT(port, SBIT_RESULT_READY))
+ if (STATUS_BIT(sc, SBIT_RESULT_READY))
goto got_param;
- printf("scd%d: timeout while reading data\n",unit);
+ device_printf(sc->dev, "timeout while reading data\n");
goto readerr;
}
- if (!STATUS_BIT(port, SBIT_DATA_READY)) {
- process_attention(unit);
+ if (!STATUS_BIT(sc, SBIT_DATA_READY)) {
+ process_attention(sc);
if (!(cd->flags & SCDVALID))
goto changed;
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITREAD,hz/100); /* XXX */
+ sc->ch_state = SCD_S_WAITREAD;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
return;
}
- XDEBUG(2, ("scd%d: mbx->count (after RDY_BIT) = %d(%d)\n", unit, mbx->count, RDELAY_WAITREAD));
+ XDEBUG(sc, 2, "mbx->count (after RDY_BIT) = %d(%d)\n", mbx->count, RDELAY_WAITREAD);
got_data:
/* data is ready */
addr = bp->bio_data + mbx->skip;
- write_control(port, CBIT_DATA_READY_CLEAR);
- insb(port+IREG_DATA, addr, mbx->sz);
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_DATA_READY_CLEAR);
+ SCD_READ_MULTI(sc, IREG_DATA, addr, mbx->sz);
mbx->count = 100;
for (i = 0; i < 20; i++) {
- if (STATUS_BIT(port, SBIT_RESULT_READY))
+ if (STATUS_BIT(sc, SBIT_RESULT_READY))
goto waitfor_param;
DELAY(100);
}
goto waitfor_param;
case SCD_S_WAITPARAM:
- untimeout(scd_timeout,(caddr_t)SCD_S_WAITPARAM, tohandle);
+ sc->ch_state = SCD_S_WAITPARAM;
+ untimeout(scd_timeout,(caddr_t)sc, sc->ch);
if (mbx->count-- <= 0) {
- printf("scd%d: timeout waiting for params\n",unit);
+ device_printf(sc->dev, "timeout waiting for params\n");
goto readerr;
}
waitfor_param:
- if (!STATUS_BIT(port, SBIT_RESULT_READY)) {
- tohandle = timeout(scd_timeout,
- (caddr_t)SCD_S_WAITPARAM,hz/100); /* XXX */
+ if (!STATUS_BIT(sc, SBIT_RESULT_READY)) {
+ sc->ch_state = SCD_S_WAITPARAM;
+ sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */
return;
}
#if SCD_DEBUG
if (mbx->count < 100 && scd_debuglevel > 0)
- printf("scd%d: mbx->count (paramwait) = %d(%d)\n", unit, mbx->count, 100);
+ device_printf(sc->dev, "mbx->count (paramwait) = %d(%d)\n", mbx->count, 100);
#endif
got_param:
- write_control(port, CBIT_RESULT_READY_CLEAR);
- switch ((i = inb(port+IREG_RESULT)) & 0xf0) {
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
+ switch ((i = SCD_READ(sc, IREG_RESULT)) & 0xf0) {
case 0x50:
switch (i) {
case ERR_FATAL_READ_ERROR1:
case ERR_FATAL_READ_ERROR2:
- printf("scd%d: unrecoverable read error 0x%x\n", unit, i);
+ device_printf(sc->dev, "unrecoverable read error 0x%x\n", i);
goto harderr;
}
break;
case 0x20:
- i = inb(port+IREG_RESULT);
+ i = SCD_READ(sc, IREG_RESULT);
switch (i) {
case ERR_NOT_SPINNING:
- XDEBUG(1, ("scd%d: read error: drive not spinning\n", unit));
+ XDEBUG(sc, 1, "read error: drive not spinning\n");
if (mbx->retry-- > 0) {
state = SCD_S_BEGIN1;
cd->flags &= ~SCDSPINNING;
@@ -1006,11 +965,11 @@ got_param:
}
goto harderr;
default:
- print_error(unit, i);
+ print_error(sc, i);
goto readerr;
}
case 0x00:
- i = inb(port+IREG_RESULT);
+ i = SCD_READ(sc, IREG_RESULT);
break;
}
@@ -1024,13 +983,13 @@ got_param:
biodone(bp);
cd->flags &= ~SCDMBXBSY;
- scd_start(mbx->unit);
+ scd_start(sc);
return;
}
readerr:
if (mbx->retry-- > 0) {
- printf("scd%d: retrying ...\n",unit);
+ device_printf(sc->dev, "retrying ...\n");
state = SCD_S_BEGIN1;
goto loop;
}
@@ -1042,11 +1001,11 @@ harderr:
biodone(bp);
cd->flags &= ~SCDMBXBSY;
- scd_start(mbx->unit);
+ scd_start(sc);
return;
changed:
- printf("scd%d: media changed\n", unit);
+ device_printf(sc->dev, "media changed\n");
goto harderr;
}
@@ -1069,20 +1028,19 @@ msf2hsg(bcd_t *msf)
}
static void
-process_attention(unsigned unit)
+process_attention(struct scd_softc *sc)
{
- unsigned port = scd_data[unit].iobase;
unsigned char code;
int count = 0;
- while (IS_ATTENTION(port) && count++ < 30) {
- write_control(port, CBIT_ATTENTION_CLEAR);
- code = inb(port+IREG_RESULT);
+ while (IS_ATTENTION(sc) && count++ < 30) {
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_ATTENTION_CLEAR);
+ code = SCD_READ(sc, IREG_RESULT);
#if SCD_DEBUG
if (scd_debuglevel > 0) {
if (count == 1)
- printf("scd%d: DEBUG: ATTENTIONS = 0x%x", unit, code);
+ device_printf(sc->dev, "DEBUG: ATTENTIONS = 0x%x", code);
else
printf(",0x%x", code);
}
@@ -1090,24 +1048,24 @@ process_attention(unsigned unit)
switch (code) {
case ATTEN_SPIN_DOWN:
- scd_data[unit].flags &= ~SCDSPINNING;
+ sc->data.flags &= ~SCDSPINNING;
break;
case ATTEN_SPIN_UP_DONE:
- scd_data[unit].flags |= SCDSPINNING;
+ sc->data.flags |= SCDSPINNING;
break;
case ATTEN_AUDIO_DONE:
- scd_data[unit].audio_status = CD_AS_PLAY_COMPLETED;
+ sc->data.audio_status = CD_AS_PLAY_COMPLETED;
break;
case ATTEN_DRIVE_LOADED:
- scd_data[unit].flags &= ~(SCDTOC|SCDSPINNING|SCDVALID);
- scd_data[unit].audio_status = CD_AS_AUDIO_INVALID;
+ sc->data.flags &= ~(SCDTOC|SCDSPINNING|SCDVALID);
+ sc->data.audio_status = CD_AS_AUDIO_INVALID;
break;
case ATTEN_EJECT_PUSHED:
- scd_data[unit].flags &= ~SCDVALID;
+ sc->data.flags &= ~SCDVALID;
break;
}
DELAY(100);
@@ -1120,7 +1078,7 @@ process_attention(unsigned unit)
/* Returns 0 OR sony error code */
static int
-spin_up(unsigned unit)
+spin_up(struct scd_softc *sc)
{
unsigned char res_reg[12];
unsigned int res_size;
@@ -1128,14 +1086,14 @@ spin_up(unsigned unit)
int loop_count = 0;
again:
- rc = send_cmd(unit, CMD_SPIN_UP, 0, 0, res_reg, &res_size);
+ rc = send_cmd(sc, CMD_SPIN_UP, 0, 0, res_reg, &res_size);
if (rc != 0) {
- XDEBUG(2, ("scd%d: CMD_SPIN_UP error 0x%x\n", unit, rc));
+ XDEBUG(sc, 2, "CMD_SPIN_UP error 0x%x\n", rc);
return rc;
}
- if (!(scd_data[unit].flags & SCDTOC)) {
- rc = send_cmd(unit, CMD_READ_TOC, 0);
+ if (!(sc->data.flags & SCDTOC)) {
+ rc = send_cmd(sc, CMD_READ_TOC, 0);
if (rc == ERR_NOT_SPINNING) {
if (loop_count++ < 3)
goto again;
@@ -1145,7 +1103,7 @@ again:
return rc;
}
- scd_data[unit].flags |= SCDSPINNING;
+ sc->data.flags |= SCDSPINNING;
return 0;
}
@@ -1177,7 +1135,7 @@ get_tl(struct sony_toc *toc, int size)
}
static int
-read_toc(unsigned unit)
+read_toc(struct scd_softc *sc)
{
struct scd_data *cd;
unsigned part = 0; /* For now ... */
@@ -1186,19 +1144,19 @@ read_toc(unsigned unit)
int rc, i, j;
u_long first, last;
- cd = scd_data + unit;
+ cd = &sc->data;
- rc = send_cmd(unit, CMD_GET_TOC, 1, part+1);
+ rc = send_cmd(sc, CMD_GET_TOC, 1, part+1);
if (rc < 0)
return rc;
if (rc > sizeof(toc)) {
- printf("scd%d: program error: toc too large (%d)\n", unit, rc);
+ device_printf(sc->dev, "program error: toc too large (%d)\n", rc);
return EIO;
}
- if (get_result(unit, rc, (u_char *)&toc) != 0)
+ if (get_result(sc, rc, (u_char *)&toc) != 0)
return EIO;
- XDEBUG(1, ("scd%d: toc read. len = %d, sizeof(toc) = %d\n", unit, rc, sizeof(toc)));
+ XDEBUG(sc, 1, "toc read. len = %d, sizeof(toc) = %d\n", rc, sizeof(toc));
tl = get_tl(&toc, rc);
first = msf2hsg(tl->start_msf);
@@ -1206,8 +1164,7 @@ read_toc(unsigned unit)
cd->blksize = SCDBLKSIZE;
cd->disksize = last*cd->blksize/DEV_BSIZE;
- XDEBUG(1, ("scd%d: firstsector = %ld, lastsector = %ld", unit,
- first, last));
+ XDEBUG(sc, 1, "firstsector = %ld, lastsector = %ld", first, last);
cd->first_track = bcd2bin(toc.first_track);
cd->last_track = bcd2bin(toc.last_track);
@@ -1219,8 +1176,10 @@ read_toc(unsigned unit)
bcopy(tl[j].start_msf, cd->toc[i].start_msf, 3);
#ifdef SCD_DEBUG
if (scd_debuglevel > 0) {
- if ((j % 3) == 0)
- printf("\nscd%d: tracks ", unit);
+ if ((j % 3) == 0) {
+ printf("\n");
+ device_printf(sc->dev, "tracks ");
+ }
printf("[%03d: %2d %2d %2d] ", i,
bcd2bin(cd->toc[i].start_msf[0]),
bcd2bin(cd->toc[i].start_msf[1]),
@@ -1270,140 +1229,132 @@ read_toc(unsigned unit)
}
static void
-init_drive(unsigned unit)
+init_drive(struct scd_softc *sc)
{
int rc;
- rc = send_cmd(unit, CMD_SET_DRIVE_PARAM, 2,
- 0x05, 0x03 | ((scd_data[unit].double_speed) ? 0x04: 0));
+ rc = send_cmd(sc, CMD_SET_DRIVE_PARAM, 2,
+ 0x05, 0x03 | ((sc->data.double_speed) ? 0x04: 0));
if (rc != 0)
- printf("scd%d: Unable to set parameters. Errcode = 0x%x\n", unit, rc);
+ device_printf(sc->dev, "Unable to set parameters. Errcode = 0x%x\n", rc);
}
/* Returns 0 or errno */
static int
-get_result(u_int unit, int result_len, u_char *result)
+get_result(struct scd_softc *sc, int result_len, u_char *result)
{
- unsigned int port = scd_data[unit].iobase;
- unsigned int res_reg = port + IREG_RESULT;
int loop_index = 2; /* send_cmd() reads two bytes ... */
- XDEBUG(1, ("scd%d: DEBUG: get_result: bytes=%d\n", unit, result_len));
+ XDEBUG(sc, 1, "DEBUG: get_result: bytes=%d\n", result_len);
while (result_len-- > 0) {
if (loop_index++ >= 10) {
loop_index = 1;
- if (waitfor_status_bits(unit, SBIT_RESULT_READY, 0))
+ if (waitfor_status_bits(sc, SBIT_RESULT_READY, 0))
return EIO;
- write_control(port, CBIT_RESULT_READY_CLEAR);
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
}
if (result)
- *result++ = inb(res_reg);
+ *result++ = SCD_READ(sc, IREG_RESULT);
else
- (void)inb(res_reg);
+ (void)SCD_READ(sc, IREG_RESULT);
}
return 0;
}
/* Returns -0x100 for timeout, -(drive error code) OR number of result bytes */
static int
-send_cmd(u_int unit, u_char cmd, u_int nargs, ...)
+send_cmd(struct scd_softc *sc, u_char cmd, u_int nargs, ...)
{
va_list ap;
- u_int port = scd_data[unit].iobase;
- u_int reg;
u_char c;
int rc;
int i;
- if (waitfor_status_bits(unit, 0, SBIT_BUSY)) {
- printf("scd%d: drive busy\n", unit);
+ if (waitfor_status_bits(sc, 0, SBIT_BUSY)) {
+ device_printf(sc->dev, "drive busy\n");
return -0x100;
}
- XDEBUG(1,("scd%d: DEBUG: send_cmd: cmd=0x%x nargs=%d", unit, cmd, nargs));
+ XDEBUG(sc, 1, "DEBUG: send_cmd: cmd=0x%x nargs=%d", cmd, nargs);
- write_control(port, CBIT_RESULT_READY_CLEAR);
- write_control(port, CBIT_RPARAM_CLEAR);
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_RPARAM_CLEAR);
for (i = 0; i < 100; i++)
- if (FSTATUS_BIT(port, FBIT_WPARAM_READY))
+ if (FSTATUS_BIT(sc, FBIT_WPARAM_READY))
break;
- if (!FSTATUS_BIT(port, FBIT_WPARAM_READY)) {
- XDEBUG(1, ("\nscd%d: wparam timeout\n", unit));
+ if (!FSTATUS_BIT(sc, FBIT_WPARAM_READY)) {
+ XDEBUG(sc, 1, "\nwparam timeout\n");
return -EIO;
}
va_start(ap, nargs);
- reg = port + OREG_WPARAMS;
for (i = 0; i < nargs; i++) {
c = (u_char)va_arg(ap, int);
- outb(reg, c);
- XDEBUG(1, (",{0x%x}", c));
+ SCD_WRITE(sc, OREG_WPARAMS, c);
+ XDEBUG(sc, 1, ",{0x%x}", c);
}
va_end(ap);
- XDEBUG(1, ("\n"));
+ XDEBUG(sc, 1, "\n");
- outb(port+OREG_COMMAND, cmd);
+ SCD_WRITE(sc, OREG_COMMAND, cmd);
- rc = waitfor_status_bits(unit, SBIT_RESULT_READY, SBIT_BUSY);
+ rc = waitfor_status_bits(sc, SBIT_RESULT_READY, SBIT_BUSY);
if (rc)
return -0x100;
- reg = port + IREG_RESULT;
- write_control(port, CBIT_RESULT_READY_CLEAR);
- switch ((rc = inb(reg)) & 0xf0) {
+ SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR);
+ switch ((rc = SCD_READ(sc, IREG_RESULT)) & 0xf0) {
case 0x20:
- rc = inb(reg);
+ rc = SCD_READ(sc, IREG_RESULT);
/* FALLTHROUGH */
case 0x50:
- XDEBUG(1, ("scd%d: DEBUG: send_cmd: drive_error=0x%x\n", unit, rc));
+ XDEBUG(sc, 1, "DEBUG: send_cmd: drive_error=0x%x\n", rc);
return -rc;
case 0x00:
default:
- rc = inb(reg);
- XDEBUG(1, ("scd%d: DEBUG: send_cmd: result_len=%d\n", unit, rc));
+ rc = SCD_READ(sc, IREG_RESULT);
+ XDEBUG(sc, 1, "DEBUG: send_cmd: result_len=%d\n", rc);
return rc;
}
}
static void
-print_error(int unit, int errcode)
+print_error(struct scd_softc *sc, int errcode)
{
switch (errcode) {
case -ERR_CD_NOT_LOADED:
- printf("scd%d: door is open\n", unit);
+ device_printf(sc->dev, "door is open\n");
break;
case -ERR_NO_CD_INSIDE:
- printf("scd%d: no cd inside\n", unit);
+ device_printf(sc->dev, "no cd inside\n");
break;
default:
if (errcode == -0x100 || errcode > 0)
- printf("scd%d: device timeout\n", unit);
+ device_printf(sc->dev, "device timeout\n");
else
- printf("scd%d: unexpected error 0x%x\n", unit, -errcode);
+ device_printf(sc->dev, "unexpected error 0x%x\n", -errcode);
break;
}
}
/* Returns 0 or errno value */
static int
-waitfor_status_bits(int unit, int bits_set, int bits_clear)
+waitfor_status_bits(struct scd_softc *sc, int bits_set, int bits_clear)
{
- u_int port = scd_data[unit].iobase;
- u_int flags = scd_data[unit].flags;
- u_int reg = port + IREG_STATUS;
+ u_int flags = sc->data.flags;
u_int max_loop;
u_char c = 0;
if (flags & SCDPROBING) {
max_loop = 0;
while (max_loop++ < 1000) {
- c = inb(reg);
+ c = SCD_READ(sc, IREG_STATUS);
if (c == 0xff)
return EIO;
if (c & SBIT_ATTENTION) {
- process_attention(unit);
+ process_attention(sc);
continue;
}
if ((c & bits_set) == bits_set &&
@@ -1416,9 +1367,9 @@ waitfor_status_bits(int unit, int bits_set, int bits_clear)
} else {
max_loop = 100;
while (max_loop-- > 0) {
- c = inb(reg);
+ c = SCD_READ(sc, IREG_STATUS);
if (c & SBIT_ATTENTION) {
- process_attention(unit);
+ process_attention(sc);
continue;
}
if ((c & bits_set) == bits_set &&
@@ -1436,22 +1387,22 @@ waitfor_status_bits(int unit, int bits_set, int bits_clear)
}
#ifdef SCD_DEBUG
if (scd_debuglevel > 0)
- printf("scd%d: DEBUG: waitfor: TIMEOUT (0x%x,(0x%x,0x%x))\n", unit, c, bits_set, bits_clear);
+ device_printf(sc->dev, "DEBUG: waitfor: TIMEOUT (0x%x,(0x%x,0x%x))\n", c, bits_set, bits_clear);
else
#endif
- printf("scd%d: timeout.\n", unit);
+ device_printf(sc->dev, "timeout.\n");
return EIO;
}
/* these two routines for xcdplayer - "borrowed" from mcd.c */
static int
-scd_toc_header (int unit, struct ioc_toc_header* th)
+scd_toc_header (struct scd_softc *sc, struct ioc_toc_header* th)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
int rc;
- if (!(cd->flags & SCDTOC) && (rc = read_toc(unit)) != 0) {
- print_error(unit, rc);
+ if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
+ print_error(sc, rc);
return EIO;
}
@@ -1463,14 +1414,14 @@ scd_toc_header (int unit, struct ioc_toc_header* th)
}
static int
-scd_toc_entrys (int unit, struct ioc_read_toc_entry *te)
+scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
struct cd_toc_entry toc_entry;
int rc, i, len = te->data_len;
- if (!(cd->flags & SCDTOC) && (rc = read_toc(unit)) != 0) {
- print_error(unit, rc);
+ if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
+ print_error(sc, rc);
return EIO;
}
@@ -1508,14 +1459,14 @@ scd_toc_entrys (int unit, struct ioc_read_toc_entry *te)
static int
-scd_toc_entry (int unit, struct ioc_read_toc_single_entry *te)
+scd_toc_entry (struct scd_softc *sc, struct ioc_read_toc_single_entry *te)
{
- struct scd_data *cd = scd_data + unit;
+ struct scd_data *cd = &sc->data;
struct cd_toc_entry toc_entry;
int rc, i;
- if (!(cd->flags & SCDTOC) && (rc = read_toc(unit)) != 0) {
- print_error(unit, rc);
+ if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) {
+ print_error(sc, rc);
return EIO;
}
diff --git a/sys/dev/scd/scd_isa.c b/sys/dev/scd/scd_isa.c
new file mode 100644
index 0000000..3df26f2
--- /dev/null
+++ b/sys/dev/scd/scd_isa.c
@@ -0,0 +1,183 @@
+/*
+ * $FreeBSD$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <sys/bio.h>
+#include <sys/cdio.h>
+#include <sys/disklabel.h>
+#include <sys/bus.h>
+
+#include <sys/mutex.h>
+
+#include <machine/bus_pio.h>
+#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/rman.h>
+
+#include <isa/isavar.h>
+
+#include <dev/scd/scdreg.h>
+#include <dev/scd/scdvar.h>
+
+static int scd_isa_probe (device_t);
+static int scd_isa_attach (device_t);
+static int scd_isa_detach (device_t);
+
+static int scd_alloc_resources (device_t);
+static void scd_release_resources (device_t);
+
+static int
+scd_isa_probe (device_t dev)
+{
+ struct scd_softc * sc;
+ int error;
+
+ /* No pnp support */
+ if (isa_get_vendorid(dev))
+ return (ENXIO);
+
+ /* IO port must be configured. */
+ if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0)
+ return (ENXIO);
+
+ sc = device_get_softc(dev);
+ sc->dev = dev;
+ sc->port_rid = 0;
+ sc->port_type = SYS_RES_IOPORT;
+ error = scd_alloc_resources(dev);
+ if (error)
+ goto fail;
+
+ error = scd_probe(sc);
+ if (error) {
+ device_printf(dev, "Probe failed.\n");
+ goto fail;
+ }
+
+ device_set_desc(dev, sc->data.name);
+
+fail:
+ scd_release_resources(dev);
+ return (error);
+}
+
+static int
+scd_isa_attach (device_t dev)
+{
+ struct scd_softc * sc;
+ int error;
+
+ sc = device_get_softc(dev);
+ error = 0;
+
+ sc->dev = dev;
+ sc->port_rid = 0;
+ sc->port_type = SYS_RES_IOPORT;
+ error = scd_alloc_resources(dev);
+ if (error)
+ goto fail;
+
+ error = scd_probe(sc);
+ if (error) {
+ device_printf(dev, "Re-Probe failed.\n");
+ goto fail;
+ }
+
+ error = scd_attach(sc);
+ if (error) {
+ device_printf(dev, "Attach failed.\n");
+ goto fail;
+ }
+
+ return (0);
+fail:
+ scd_release_resources(dev);
+ return (error);
+}
+
+static int
+scd_isa_detach (device_t dev)
+{
+ struct scd_softc * sc;
+ int error;
+
+ sc = device_get_softc(dev);
+ error = 0;
+
+ destroy_dev(sc->scd_dev_t);
+
+ scd_release_resources(dev);
+
+ return (error);
+}
+
+static int
+scd_alloc_resources (device_t dev)
+{
+ struct scd_softc * sc;
+ int error;
+
+ sc = device_get_softc(dev);
+ error = 0;
+
+ if (sc->port_type) {
+ sc->port = bus_alloc_resource(dev, sc->port_type, &sc->port_rid,
+ 0, ~0, 1, RF_ACTIVE);
+ if (sc->port == NULL) {
+ device_printf(dev, "Unable to allocate PORT resource.\n");
+ error = ENOMEM;
+ goto bad;
+ }
+ sc->port_bst = rman_get_bustag(sc->port);
+ sc->port_bsh = rman_get_bushandle(sc->port);
+ }
+
+ mtx_init(&sc->mtx, device_get_nameunit(dev),
+ "Interrupt lock", MTX_DEF | MTX_RECURSE);
+
+bad:
+ return (error);
+}
+
+void
+scd_release_resources (device_t dev)
+{
+ struct scd_softc * sc;
+
+ sc = device_get_softc(dev);
+
+ if (sc->port) {
+ bus_release_resource(dev, sc->port_type, sc->port_rid, sc->port);
+ sc->port_bst = 0;
+ sc->port_bsh = 0;
+ }
+
+ if (mtx_initialized(&sc->mtx) != 0)
+ mtx_destroy(&sc->mtx);
+
+ return;
+}
+
+static device_method_t scd_isa_methods[] = {
+ DEVMETHOD(device_probe, scd_isa_probe),
+ DEVMETHOD(device_attach, scd_isa_attach),
+ DEVMETHOD(device_detach, scd_isa_detach),
+
+ { 0, 0 }
+};
+
+static driver_t scd_isa_driver = {
+ "scd",
+ scd_isa_methods,
+ sizeof(struct scd_softc)
+};
+
+static devclass_t scd_devclass;
+
+DRIVER_MODULE(scd, isa, scd_isa_driver, scd_devclass, NULL, 0);
diff --git a/sys/dev/scd/scdreg.h b/sys/dev/scd/scdreg.h
index e9ce3b1..bbfeefd 100644
--- a/sys/dev/scd/scdreg.h
+++ b/sys/dev/scd/scdreg.h
@@ -43,12 +43,6 @@ typedef unsigned char bcd_t;
#define S_msf(msf) msf[1]
#define F_msf(msf) msf[2]
-#define IS_ATTENTION(port) ((inb(port+IREG_STATUS) & SBIT_ATTENTION) != 0)
-#define IS_BUSY(port) ((inb(port+IREG_STATUS) & SBIT_BUSY) != 0)
-#define IS_DATA_RDY(port) ((inb(port+IREG_STATUS) & SBIT_DATA_READY) != 0)
-#define STATUS_BIT(port, bit) ((inb(port+IREG_STATUS) & (bit)) != 0)
-#define FSTATUS_BIT(port, bit) ((inb(port+IREG_FSTATUS) & (bit)) != 0)
-
#define OREG_COMMAND 0
#define OREG_WPARAMS 1
#define OREG_CONTROL 3
diff --git a/sys/dev/scd/scdvar.h b/sys/dev/scd/scdvar.h
new file mode 100644
index 0000000..d7faa88
--- /dev/null
+++ b/sys/dev/scd/scdvar.h
@@ -0,0 +1,68 @@
+/*
+ * $FreeBSD$
+ */
+
+struct scd_mbx {
+ short retry;
+ short nblk;
+ int sz;
+ u_long skip;
+ struct bio * bp;
+ int p_offset;
+ short count;
+};
+
+struct scd_data {
+ char double_speed;
+ char * name;
+ short flags;
+ int blksize;
+ u_long disksize;
+ struct disklabel dlabel;
+ int openflag;
+ struct {
+ unsigned int adr :4;
+ unsigned int ctl :4; /* xcdplayer needs this */
+ unsigned char start_msf[3];
+ } toc[MAX_TRACKS];
+ short first_track;
+ short last_track;
+ struct ioc_play_msf last_play;
+
+ short audio_status;
+ struct bio_queue_head head; /* head of bio queue */
+ struct scd_mbx mbx;
+};
+
+struct scd_softc {
+ device_t dev;
+ dev_t scd_dev_t;
+ int debug;
+
+ struct resource * port;
+ int port_rid;
+ int port_type;
+ bus_space_tag_t port_bst;
+ bus_space_handle_t port_bsh;
+
+ struct mtx mtx;
+
+ struct callout_handle ch;
+ int ch_state;
+ struct scd_mbx * ch_mbxsave;
+
+ struct scd_data data;
+};
+
+#define SCD_LOCK(_sc) splx(&(_sc)->mtx
+#define SCD_UNLOCK(_sc) splx(&(_sc)->mtx
+
+#define SCD_READ(_sc, _reg) \
+ bus_space_read_1(_sc->port_bst, _sc->port_bsh, _reg)
+#define SCD_READ_MULTI(_sc, _reg, _addr, _count) \
+ bus_space_read_multi_1(_sc->port_bst, _sc->port_bsh, _reg, _addr, _count)
+#define SCD_WRITE(_sc, _reg, _val) \
+ bus_space_write_1(_sc->port_bst, _sc->port_bsh, _reg, _val)
+
+int scd_probe (struct scd_softc *);
+int scd_attach (struct scd_softc *);
OpenPOWER on IntegriCloud