Deleted Added
full compact
mcd.c (6028) mcd.c (6604)
1/*
2 * Copyright 1993 by Holger Veit (data part)
3 * Copyright 1993 by Brian Moore (audio part)
4 * Changes Copyright 1993 by Gary Clark II
1/*
2 * Copyright 1993 by Holger Veit (data part)
3 * Copyright 1993 by Brian Moore (audio part)
4 * Changes Copyright 1993 by Gary Clark II
5 * Changes Copyright (C) 1994 by Andrew A. Chernov
5 * Changes Copyright (C) 1994-1995 by Andrey A. Chernov, Moscow, Russia
6 *
7 * Rewrote probe routine to work on newer Mitsumi drives.
8 * Additional changes (C) 1994 by Jordan K. Hubbard
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions

--- 168 unchanged lines hidden (view full) ---

182static int mcd_toc_entrys(int unit, struct ioc_read_toc_entry *te);
183static int mcd_stop(int unit);
184static int mcd_eject(int unit);
185static int mcd_playtracks(int unit, struct ioc_play_track *pt);
186static int mcd_play(int unit, struct mcd_read2 *pb);
187static int mcd_playmsf(int unit, struct ioc_play_msf *pt);
188static int mcd_pause(int unit);
189static int mcd_resume(int unit);
6 *
7 * Rewrote probe routine to work on newer Mitsumi drives.
8 * Additional changes (C) 1994 by Jordan K. Hubbard
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions

--- 168 unchanged lines hidden (view full) ---

182static int mcd_toc_entrys(int unit, struct ioc_read_toc_entry *te);
183static int mcd_stop(int unit);
184static int mcd_eject(int unit);
185static int mcd_playtracks(int unit, struct ioc_play_track *pt);
186static int mcd_play(int unit, struct mcd_read2 *pb);
187static int mcd_playmsf(int unit, struct ioc_play_msf *pt);
188static int mcd_pause(int unit);
189static int mcd_resume(int unit);
190static int mcd_lock_door(int unit, int lock);
191static int mcd_close_tray(int unit);
190
191extern int hz;
192extern int mcd_probe(struct isa_device *dev);
193extern int mcd_attach(struct isa_device *dev);
194struct isa_driver mcddriver = { mcd_probe, mcd_attach, "mcd" };
195
196#define mcd_put(port,byte) outb(port,byte)
197
198#define MCD_RETRYS 5
199#define MCD_RDRETRYS 8
200
192
193extern int hz;
194extern int mcd_probe(struct isa_device *dev);
195extern int mcd_attach(struct isa_device *dev);
196struct isa_driver mcddriver = { mcd_probe, mcd_attach, "mcd" };
197
198#define mcd_put(port,byte) outb(port,byte)
199
200#define MCD_RETRYS 5
201#define MCD_RDRETRYS 8
202
203#define CLOSE_TRAY_SECS 8
204#define DISK_SENSE_SECS 3
205#define WAIT_FRAC 4
206
201/* several delays */
202#define RDELAY_WAITSTAT 300
203#define RDELAY_WAITMODE 300
204#define RDELAY_WAITREAD 800
205
206#define MIN_DELAY 15
207/* several delays */
208#define RDELAY_WAITSTAT 300
209#define RDELAY_WAITMODE 300
210#define RDELAY_WAITREAD 800
211
212#define MIN_DELAY 15
207#define DELAY_GETREPLY 1300000
213#define DELAY_GETREPLY 1400000
208
209static struct kern_devconf kdc_mcd[NMCD] = { {
210 0, 0, 0, /* filled in by dev_attach */
211 "mcd", 0, { MDDT_ISA, 0, "bio" },
212 isa_generic_externalize, 0, 0, ISA_EXTERNALLEN,
213 &kdc_isa0, /* parent */
214 0, /* parentdata */
215 DC_IDLE, /* status */

--- 5 unchanged lines hidden (view full) ---

221{
222 if(id->id_unit)
223 kdc_mcd[id->id_unit] = kdc_mcd[0];
224 kdc_mcd[id->id_unit].kdc_unit = id->id_unit;
225 kdc_mcd[id->id_unit].kdc_isa = id;
226 dev_attach(&kdc_mcd[id->id_unit]);
227}
228
214
215static struct kern_devconf kdc_mcd[NMCD] = { {
216 0, 0, 0, /* filled in by dev_attach */
217 "mcd", 0, { MDDT_ISA, 0, "bio" },
218 isa_generic_externalize, 0, 0, ISA_EXTERNALLEN,
219 &kdc_isa0, /* parent */
220 0, /* parentdata */
221 DC_IDLE, /* status */

--- 5 unchanged lines hidden (view full) ---

227{
228 if(id->id_unit)
229 kdc_mcd[id->id_unit] = kdc_mcd[0];
230 kdc_mcd[id->id_unit].kdc_unit = id->id_unit;
231 kdc_mcd[id->id_unit].kdc_isa = id;
232 dev_attach(&kdc_mcd[id->id_unit]);
233}
234
229
230int mcd_attach(struct isa_device *dev)
231{
232 struct mcd_data *cd = mcd_data + dev->id_unit;
233 int i;
234
235 cd->iobase = dev->id_iobase;
236 cd->flags |= MCDINIT;
237 mcd_soft_reset(dev->id_unit);

--- 6 unchanged lines hidden (view full) ---

244 /* name filled in probe */
245 kdc_mcd[dev->id_unit].kdc_description = mcd_data[dev->id_unit].name;
246
247 return 1;
248}
249
250int mcdopen(dev_t dev)
251{
235int mcd_attach(struct isa_device *dev)
236{
237 struct mcd_data *cd = mcd_data + dev->id_unit;
238 int i;
239
240 cd->iobase = dev->id_iobase;
241 cd->flags |= MCDINIT;
242 mcd_soft_reset(dev->id_unit);

--- 6 unchanged lines hidden (view full) ---

249 /* name filled in probe */
250 kdc_mcd[dev->id_unit].kdc_description = mcd_data[dev->id_unit].name;
251
252 return 1;
253}
254
255int mcdopen(dev_t dev)
256{
252 int unit,part,phys;
257 int unit,part,phys,r,retry;
253 struct mcd_data *cd;
254
255 unit = mcd_unit(dev);
256 if (unit >= NMCD)
257 return ENXIO;
258
259 cd = mcd_data + unit;
260 part = mcd_part(dev);
261 phys = mcd_phys(dev);
262
263 /* not initialized*/
264 if (!(cd->flags & MCDINIT))
265 return ENXIO;
266
267 /* invalidated in the meantime? mark all open part's invalid */
268 if (!(cd->flags & MCDVALID) && cd->openflags)
269 return ENXIO;
270
258 struct mcd_data *cd;
259
260 unit = mcd_unit(dev);
261 if (unit >= NMCD)
262 return ENXIO;
263
264 cd = mcd_data + unit;
265 part = mcd_part(dev);
266 phys = mcd_phys(dev);
267
268 /* not initialized*/
269 if (!(cd->flags & MCDINIT))
270 return ENXIO;
271
272 /* invalidated in the meantime? mark all open part's invalid */
273 if (!(cd->flags & MCDVALID) && cd->openflags)
274 return ENXIO;
275
271 if (mcd_getstat(unit,1) == -1) /* detect disk change too */
272 return ENXIO;
276 if (mcd_close_tray(unit) == EIO) /* detect disk change too */
277 return EIO;
273
278
279 if ( (cd->status & (MCDDSKCHNG|MCDDOOROPEN))
280 || !(cd->status & MCDDSKIN))
281 for (retry = 0; retry < DISK_SENSE_SECS * WAIT_FRAC; retry++) {
282 (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdsns", hz/WAIT_FRAC);
283 if ((r = mcd_getstat(unit,1)) == -1)
284 return EIO;
285 if (r != -2)
286 break;
287 }
288
274 if (cd->status & MCDDOOROPEN) {
275 printf("mcd%d: door is open\n");
276 return ENXIO;
277 }
278 if (!(cd->status & MCDDSKIN)) {
279 printf("mcd%d: no CD inside\n");
280 return ENXIO;
281 }
289 if (cd->status & MCDDOOROPEN) {
290 printf("mcd%d: door is open\n");
291 return ENXIO;
292 }
293 if (!(cd->status & MCDDSKIN)) {
294 printf("mcd%d: no CD inside\n");
295 return ENXIO;
296 }
297 if (cd->status & MCDDSKCHNG) {
298 printf("mcd%d: CD not sensed\n");
299 return ENXIO;
300 }
282
283 if (mcdsize(dev) < 0) {
284 printf("mcd%d: failed to get disk size\n",unit);
285 return ENXIO;
286 } else
287 cd->flags |= MCDVALID;
288
289 /* XXX get a default disklabel */

--- 5 unchanged lines hidden (view full) ---

295 if (part == RAW_PART ||
296 (part < cd->dlabel.d_npartitions &&
297 cd->dlabel.d_partitions[part].p_fstype != FS_UNUSED)) {
298 cd->partflags[part] |= MCDOPEN;
299 cd->openflags |= (1<<part);
300 if (part == RAW_PART && phys != 0)
301 cd->partflags[part] |= MCDREADRAW;
302 kdc_mcd[unit].kdc_state = DC_BUSY;
301
302 if (mcdsize(dev) < 0) {
303 printf("mcd%d: failed to get disk size\n",unit);
304 return ENXIO;
305 } else
306 cd->flags |= MCDVALID;
307
308 /* XXX get a default disklabel */

--- 5 unchanged lines hidden (view full) ---

314 if (part == RAW_PART ||
315 (part < cd->dlabel.d_npartitions &&
316 cd->dlabel.d_partitions[part].p_fstype != FS_UNUSED)) {
317 cd->partflags[part] |= MCDOPEN;
318 cd->openflags |= (1<<part);
319 if (part == RAW_PART && phys != 0)
320 cd->partflags[part] |= MCDREADRAW;
321 kdc_mcd[unit].kdc_state = DC_BUSY;
322 (void) mcd_lock_door(unit, MCD_LK_LOCK);
323 if (!(cd->flags & MCDVALID))
324 return ENXIO;
303 return 0;
304 }
305
306 return ENXIO;
307}
308
309int mcdclose(dev_t dev)
310{

--- 7 unchanged lines hidden (view full) ---

318 cd = mcd_data + unit;
319 part = mcd_part(dev);
320 phys = mcd_phys(dev);
321
322 if (!(cd->flags & MCDINIT))
323 return ENXIO;
324
325 kdc_mcd[unit].kdc_state = DC_IDLE;
325 return 0;
326 }
327
328 return ENXIO;
329}
330
331int mcdclose(dev_t dev)
332{

--- 7 unchanged lines hidden (view full) ---

340 cd = mcd_data + unit;
341 part = mcd_part(dev);
342 phys = mcd_phys(dev);
343
344 if (!(cd->flags & MCDINIT))
345 return ENXIO;
346
347 kdc_mcd[unit].kdc_state = DC_IDLE;
326 if (mcd_getstat(unit,1) == -2)
348 (void) mcd_lock_door(unit, MCD_LK_UNLOCK);
349
350 if (!(cd->flags & MCDVALID))
327 return 0;
328
329 /* close channel */
330 cd->partflags[part] &= ~(MCDOPEN|MCDREADRAW);
331 cd->openflags &= ~(1<<part);
332 MCD_TRACE("close: partition=%d\n",part,0,0,0);
333
334 return 0;

--- 123 unchanged lines hidden (view full) ---

458{
459 struct mcd_data *cd;
460 int unit,part;
461
462 unit = mcd_unit(dev);
463 part = mcd_part(dev);
464 cd = mcd_data + unit;
465
351 return 0;
352
353 /* close channel */
354 cd->partflags[part] &= ~(MCDOPEN|MCDREADRAW);
355 cd->openflags &= ~(1<<part);
356 MCD_TRACE("close: partition=%d\n",part,0,0,0);
357
358 return 0;

--- 123 unchanged lines hidden (view full) ---

482{
483 struct mcd_data *cd;
484 int unit,part;
485
486 unit = mcd_unit(dev);
487 part = mcd_part(dev);
488 cd = mcd_data + unit;
489
466 if (mcd_getstat(unit, 1) < 0) /* detect disk change too */
490 if (mcd_getstat(unit, 1) == -1) /* detect disk change too */
467 return EIO;
491 return EIO;
468 if (!(cd->flags & MCDVALID))
469 return EIO;
470MCD_TRACE("ioctl called 0x%x\n",cmd,0,0,0);
471
472 switch (cmd) {
473 case DIOCSBAD:
492MCD_TRACE("ioctl called 0x%x\n",cmd,0,0,0);
493
494 switch (cmd) {
495 case DIOCSBAD:
496 if (!(cd->flags & MCDVALID))
497 return ENXIO;
474 return EINVAL;
475 case DIOCGDINFO:
498 return EINVAL;
499 case DIOCGDINFO:
500 if (!(cd->flags & MCDVALID))
501 return ENXIO;
476 *(struct disklabel *) addr = cd->dlabel;
477 return 0;
478 case DIOCGPART:
502 *(struct disklabel *) addr = cd->dlabel;
503 return 0;
504 case DIOCGPART:
505 if (!(cd->flags & MCDVALID))
506 return ENXIO;
479 ((struct partinfo *) addr)->disklab = &cd->dlabel;
480 ((struct partinfo *) addr)->part =
481 &cd->dlabel.d_partitions[mcd_part(dev)];
482 return 0;
483
484 /*
485 * a bit silly, but someone might want to test something on a
486 * section of cdrom.
487 */
488 case DIOCWDINFO:
489 case DIOCSDINFO:
507 ((struct partinfo *) addr)->disklab = &cd->dlabel;
508 ((struct partinfo *) addr)->part =
509 &cd->dlabel.d_partitions[mcd_part(dev)];
510 return 0;
511
512 /*
513 * a bit silly, but someone might want to test something on a
514 * section of cdrom.
515 */
516 case DIOCWDINFO:
517 case DIOCSDINFO:
518 if (!(cd->flags & MCDVALID))
519 return ENXIO;
490 if ((flags & FWRITE) == 0)
491 return EBADF;
492 else {
493 return setdisklabel(&cd->dlabel,
494 (struct disklabel *) addr,
495 0);
496 }
497 case DIOCWLABEL:
520 if ((flags & FWRITE) == 0)
521 return EBADF;
522 else {
523 return setdisklabel(&cd->dlabel,
524 (struct disklabel *) addr,
525 0);
526 }
527 case DIOCWLABEL:
528 if (!(cd->flags & MCDVALID))
529 return ENXIO;
498 return EBADF;
499 case CDIOCPLAYTRACKS:
530 return EBADF;
531 case CDIOCPLAYTRACKS:
532 if (!(cd->flags & MCDVALID))
533 return ENXIO;
500 return mcd_playtracks(unit, (struct ioc_play_track *) addr);
501 case CDIOCPLAYBLOCKS:
534 return mcd_playtracks(unit, (struct ioc_play_track *) addr);
535 case CDIOCPLAYBLOCKS:
536 if (!(cd->flags & MCDVALID))
537 return ENXIO;
502 return EINVAL;
503 case CDIOCPLAYMSF:
538 return EINVAL;
539 case CDIOCPLAYMSF:
540 if (!(cd->flags & MCDVALID))
541 return ENXIO;
504 return mcd_playmsf(unit, (struct ioc_play_msf *) addr);
505 case CDIOCREADSUBCHANNEL:
542 return mcd_playmsf(unit, (struct ioc_play_msf *) addr);
543 case CDIOCREADSUBCHANNEL:
544 if (!(cd->flags & MCDVALID))
545 return ENXIO;
506 return mcd_subchan(unit, (struct ioc_read_subchannel *) addr);
507 case CDIOREADTOCHEADER:
546 return mcd_subchan(unit, (struct ioc_read_subchannel *) addr);
547 case CDIOREADTOCHEADER:
548 if (!(cd->flags & MCDVALID))
549 return ENXIO;
508 return mcd_toc_header(unit, (struct ioc_toc_header *) addr);
509 case CDIOREADTOCENTRYS:
550 return mcd_toc_header(unit, (struct ioc_toc_header *) addr);
551 case CDIOREADTOCENTRYS:
552 if (!(cd->flags & MCDVALID))
553 return ENXIO;
510 return mcd_toc_entrys(unit, (struct ioc_read_toc_entry *) addr);
511 case CDIOCSETPATCH:
512 case CDIOCGETVOL:
513 case CDIOCSETVOL:
514 case CDIOCSETMONO:
515 case CDIOCSETSTERIO:
516 case CDIOCSETMUTE:
517 case CDIOCSETLEFT:
518 case CDIOCSETRIGHT:
519 return EINVAL;
520 case CDIOCRESUME:
554 return mcd_toc_entrys(unit, (struct ioc_read_toc_entry *) addr);
555 case CDIOCSETPATCH:
556 case CDIOCGETVOL:
557 case CDIOCSETVOL:
558 case CDIOCSETMONO:
559 case CDIOCSETSTERIO:
560 case CDIOCSETMUTE:
561 case CDIOCSETLEFT:
562 case CDIOCSETRIGHT:
563 return EINVAL;
564 case CDIOCRESUME:
565 if (!(cd->flags & MCDVALID))
566 return ENXIO;
521 return mcd_resume(unit);
522 case CDIOCPAUSE:
567 return mcd_resume(unit);
568 case CDIOCPAUSE:
569 if (!(cd->flags & MCDVALID))
570 return ENXIO;
523 return mcd_pause(unit);
524 case CDIOCSTART:
571 return mcd_pause(unit);
572 case CDIOCSTART:
573 if (!(cd->flags & MCDVALID))
574 return ENXIO;
525 return EINVAL;
526 case CDIOCSTOP:
575 return EINVAL;
576 case CDIOCSTOP:
577 if (!(cd->flags & MCDVALID))
578 return ENXIO;
527 return mcd_stop(unit);
528 case CDIOCEJECT:
529 return mcd_eject(unit);
530 case CDIOCSETDEBUG:
531 cd->debug = 1;
532 return 0;
533 case CDIOCCLRDEBUG:
534 cd->debug = 0;
535 return 0;
536 case CDIOCRESET:
537 return mcd_hard_reset(unit);
538 case CDIOCALLOW:
579 return mcd_stop(unit);
580 case CDIOCEJECT:
581 return mcd_eject(unit);
582 case CDIOCSETDEBUG:
583 cd->debug = 1;
584 return 0;
585 case CDIOCCLRDEBUG:
586 cd->debug = 0;
587 return 0;
588 case CDIOCRESET:
589 return mcd_hard_reset(unit);
590 case CDIOCALLOW:
539 return 0;
591 return mcd_lock_door(unit, MCD_LK_UNLOCK);
540 default:
541 return ENOTTY;
542 }
543 /*NOTREACHED*/
544}
545
546/* this could have been taken from scsi/cd.c, but it is not clear
547 * whether the scsi cd driver is linked in

--- 202 unchanged lines hidden (view full) ---

750 int i;
751 struct mcd_data *cd = mcd_data + unit;
752 int port = cd->iobase;
753
754 /* get the status */
755 if (sflg)
756 outb(port+mcd_command, MCD_CMDGETSTAT);
757 i = mcd_getreply(unit,DELAY_GETREPLY);
592 default:
593 return ENOTTY;
594 }
595 /*NOTREACHED*/
596}
597
598/* this could have been taken from scsi/cd.c, but it is not clear
599 * whether the scsi cd driver is linked in

--- 202 unchanged lines hidden (view full) ---

802 int i;
803 struct mcd_data *cd = mcd_data + unit;
804 int port = cd->iobase;
805
806 /* get the status */
807 if (sflg)
808 outb(port+mcd_command, MCD_CMDGETSTAT);
809 i = mcd_getreply(unit,DELAY_GETREPLY);
758 if (i<0 || (i & MCD_ST_CMDCHECK)) return -1;
810 if (i<0 || (i & MCD_ST_CMDCHECK)) {
811 cd->curr_mode = MCD_MD_UNKNOWN;
812 return -1;
813 }
759
760 cd->status = i;
761
762 if (mcd_setflags(unit,cd) < 0)
763 return -2;
764 return cd->status;
765}
766

--- 102 unchanged lines hidden (view full) ---

869 return EIO;
870
871 /* get data */
872 if (mcd_get(unit,(char*) &cd->volinfo,sizeof(struct mcd_volinfo)) < 0) {
873 printf("mcd%d: mcd_volinfo: error read data\n",unit);
874 return EIO;
875 }
876
814
815 cd->status = i;
816
817 if (mcd_setflags(unit,cd) < 0)
818 return -2;
819 return cd->status;
820}
821

--- 102 unchanged lines hidden (view full) ---

924 return EIO;
925
926 /* get data */
927 if (mcd_get(unit,(char*) &cd->volinfo,sizeof(struct mcd_volinfo)) < 0) {
928 printf("mcd%d: mcd_volinfo: error read data\n",unit);
929 return EIO;
930 }
931
877 if (cd->volinfo.trk_low != 0 || cd->volinfo.trk_high != 0) {
932 if (cd->volinfo.trk_low > 0 &&
933 cd->volinfo.trk_high >= cd->volinfo.trk_low
934 ) {
878 cd->flags |= MCDVOLINFO; /* volinfo is OK */
879 return 0;
880 }
881
882 return EINVAL;
883}
884
885void

--- 28 unchanged lines hidden (view full) ---

914 caddr_t addr;
915
916loop:
917 switch (state) {
918 case MCD_S_BEGIN:
919 mbx = mbxsave = mbxin;
920
921 case MCD_S_BEGIN1:
935 cd->flags |= MCDVOLINFO; /* volinfo is OK */
936 return 0;
937 }
938
939 return EINVAL;
940}
941
942void

--- 28 unchanged lines hidden (view full) ---

971 caddr_t addr;
972
973loop:
974 switch (state) {
975 case MCD_S_BEGIN:
976 mbx = mbxsave = mbxin;
977
978 case MCD_S_BEGIN1:
922 /* get status */
923retry_status:
979retry_status:
980 /* get status */
924 outb(com_port, MCD_CMDGETSTAT);
925 mbx->count = RDELAY_WAITSTAT;
926 timeout((timeout_func_t)mcd_doread,
927 (caddr_t)MCD_S_WAITSTAT,hz/100); /* XXX */
928 return;
929 case MCD_S_WAITSTAT:
930 untimeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITSTAT);
931 if (mbx->count-- >= 0) {

--- 9 unchanged lines hidden (view full) ---

941 goto changed;
942 MCD_TRACE("got WAITSTAT delay=%d\n",
943 RDELAY_WAITSTAT-mbx->count,0,0,0);
944 /* reject, if audio active */
945 if (cd->status & MCDAUDIOBSY) {
946 printf("mcd%d: audio is active\n",unit);
947 goto readerr;
948 }
981 outb(com_port, MCD_CMDGETSTAT);
982 mbx->count = RDELAY_WAITSTAT;
983 timeout((timeout_func_t)mcd_doread,
984 (caddr_t)MCD_S_WAITSTAT,hz/100); /* XXX */
985 return;
986 case MCD_S_WAITSTAT:
987 untimeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITSTAT);
988 if (mbx->count-- >= 0) {

--- 9 unchanged lines hidden (view full) ---

998 goto changed;
999 MCD_TRACE("got WAITSTAT delay=%d\n",
1000 RDELAY_WAITSTAT-mbx->count,0,0,0);
1001 /* reject, if audio active */
1002 if (cd->status & MCDAUDIOBSY) {
1003 printf("mcd%d: audio is active\n",unit);
1004 goto readerr;
1005 }
1006
949retry_mode:
950 /* to check for raw/cooked mode */
951 if (cd->flags & MCDREADRAW) {
952 rm = MCD_MD_RAW;
953 mbx->sz = MCDRBLK;
954 } else {
955 rm = MCD_MD_COOKED;
956 mbx->sz = cd->blksize;

--- 24 unchanged lines hidden (view full) ---

981 goto readerr;
982 }
983 if (inb(port+MCD_FLAGS) & MFL_STATUS_NOT_AVAIL) {
984 timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITMODE,hz/100);
985 return;
986 }
987 cd->status = inb(port+mcd_status) & 0xFF;
988 if (cd->status & MCD_ST_CMDCHECK) {
1007retry_mode:
1008 /* to check for raw/cooked mode */
1009 if (cd->flags & MCDREADRAW) {
1010 rm = MCD_MD_RAW;
1011 mbx->sz = MCDRBLK;
1012 } else {
1013 rm = MCD_MD_COOKED;
1014 mbx->sz = cd->blksize;

--- 24 unchanged lines hidden (view full) ---

1039 goto readerr;
1040 }
1041 if (inb(port+MCD_FLAGS) & MFL_STATUS_NOT_AVAIL) {
1042 timeout((timeout_func_t)mcd_doread,(caddr_t)MCD_S_WAITMODE,hz/100);
1043 return;
1044 }
1045 cd->status = inb(port+mcd_status) & 0xFF;
1046 if (cd->status & MCD_ST_CMDCHECK) {
989 cd->curr_mode = MCD_MD_UNKNOWN;
1047 cd->curr_mode = MCD_MD_UNKNOWN;
990 goto retry_mode;
991 }
992 if (mcd_setflags(unit,cd) < 0)
993 goto changed;
994 cd->curr_mode = mbx->mode;
995 MCD_TRACE("got WAITMODE delay=%d\n",
996 RDELAY_WAITMODE-mbx->count,0,0,0);
997modedone:

--- 117 unchanged lines hidden (view full) ---

1115 /*cd->status &= ~MCDDSKCHNG; */
1116 cd->debug = 1; /* preventive set debug mode */
1117
1118#endif
1119
1120}
1121
1122static int
1048 goto retry_mode;
1049 }
1050 if (mcd_setflags(unit,cd) < 0)
1051 goto changed;
1052 cd->curr_mode = mbx->mode;
1053 MCD_TRACE("got WAITMODE delay=%d\n",
1054 RDELAY_WAITMODE-mbx->count,0,0,0);
1055modedone:

--- 117 unchanged lines hidden (view full) ---

1173 /*cd->status &= ~MCDDSKCHNG; */
1174 cd->debug = 1; /* preventive set debug mode */
1175
1176#endif
1177
1178}
1179
1180static int
1123mcd_eject(int unit)
1181mcd_lock_door(int unit, int lock)
1124{
1125 struct mcd_data *cd = mcd_data + unit;
1126 int port = cd->iobase;
1127
1182{
1183 struct mcd_data *cd = mcd_data + unit;
1184 int port = cd->iobase;
1185
1186 outb(port+mcd_command, MCD_CMDLOCKDRV);
1187 outb(port+mcd_command, lock);
1188 if (mcd_getstat(unit,0) == -1)
1189 return EIO;
1190 return 0;
1191}
1192
1193static int
1194mcd_close_tray(int unit)
1195{
1196 struct mcd_data *cd = mcd_data + unit;
1197 int port = cd->iobase;
1198 int retry, r;
1199
1200 if (mcd_getstat(unit,1) == -1)
1201 return EIO;
1202 if (cd->status & MCDDOOROPEN) {
1203 outb(port+mcd_command, MCD_CMDCLOSETRAY);
1204 for (retry = 0; retry < CLOSE_TRAY_SECS * WAIT_FRAC; retry++) {
1205 if (inb(port+MCD_FLAGS) & MFL_STATUS_NOT_AVAIL)
1206 (void) tsleep((caddr_t)cd, PSOCK | PCATCH, "mcdcls", hz/WAIT_FRAC);
1207 else {
1208 if ((r = mcd_getstat(unit,0)) == -1)
1209 return EIO;
1210 return 0;
1211 }
1212 }
1213 return ENXIO;
1214 }
1215 return 0;
1216}
1217
1218static int
1219mcd_eject(int unit)
1220{
1221 struct mcd_data *cd = mcd_data + unit;
1222 int port = cd->iobase, r;
1223
1224 if (mcd_getstat(unit,1) == -1) /* detect disk change too */
1225 return EIO;
1226 if (cd->status & MCDDOOROPEN)
1227 return mcd_close_tray(unit);
1228 if ((r = mcd_stop(unit)) == EIO)
1229 return r;
1128 outb(port+mcd_command, MCD_CMDEJECTDISK);
1230 outb(port+mcd_command, MCD_CMDEJECTDISK);
1129 if (mcd_getstat(unit,0) == -1) return EIO;
1231 if (mcd_getstat(unit,0) == -1)
1232 return EIO;
1130 return 0;
1131}
1132
1133static int
1134mcd_hard_reset(int unit)
1135{
1136 struct mcd_data *cd = mcd_data + unit;
1137 int port = cd->iobase;

--- 189 unchanged lines hidden (view full) ---

1327 return 0;
1328}
1329
1330static int
1331mcd_stop(int unit)
1332{
1333 struct mcd_data *cd = mcd_data + unit;
1334
1233 return 0;
1234}
1235
1236static int
1237mcd_hard_reset(int unit)
1238{
1239 struct mcd_data *cd = mcd_data + unit;
1240 int port = cd->iobase;

--- 189 unchanged lines hidden (view full) ---

1430 return 0;
1431}
1432
1433static int
1434mcd_stop(int unit)
1435{
1436 struct mcd_data *cd = mcd_data + unit;
1437
1335 if (mcd_send(unit, MCD_CMDSTOPAUDIO, MCD_RETRYS) < 0)
1336 return ENXIO;
1438 /* Verify current status */
1439 if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS &&
1440 cd->audio_status != CD_AS_PLAY_PAUSED) {
1441 if (cd->debug)
1442 printf("mcd%d: stop attempted when not playing\n", unit);
1443 return EINVAL;
1444 }
1445 if (cd->audio_status == CD_AS_PLAY_IN_PROGRESS)
1446 if (mcd_send(unit, MCD_CMDSTOPAUDIO, MCD_RETRYS) < 0)
1447 return EIO;
1337 cd->audio_status = CD_AS_PLAY_COMPLETED;
1338 return 0;
1339}
1340
1341static int
1342mcd_getqchan(int unit, struct mcd_qchninfo *q)
1343{
1344 struct mcd_data *cd = mcd_data + unit;

--- 189 unchanged lines hidden ---
1448 cd->audio_status = CD_AS_PLAY_COMPLETED;
1449 return 0;
1450}
1451
1452static int
1453mcd_getqchan(int unit, struct mcd_qchninfo *q)
1454{
1455 struct mcd_data *cd = mcd_data + unit;

--- 189 unchanged lines hidden ---