scd.c (106453) | scd.c (106490) |
---|---|
1/*- 2 * Copyright (c) 1995 Mikael Hybsch 3 * All rights reserved. 4 * 5 * Portions of this file are copied from mcd.c 6 * which has the following copyrights: 7 * 8 * Copyright 1993 by Holger Veit (data part) --- 26 unchanged lines hidden (view full) --- 35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 */ 42 | 1/*- 2 * Copyright (c) 1995 Mikael Hybsch 3 * All rights reserved. 4 * 5 * Portions of this file are copied from mcd.c 6 * which has the following copyrights: 7 * 8 * Copyright 1993 by Holger Veit (data part) --- 26 unchanged lines hidden (view full) --- 35 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 39 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 */ 42 |
43/* $FreeBSD: head/sys/dev/scd/scd.c 106453 2002-11-05 10:56:14Z mdodd $ */ | 43/* $FreeBSD: head/sys/dev/scd/scd.c 106490 2002-11-06 08:08:55Z mdodd $ */ |
44 45#undef SCD_DEBUG 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kernel.h> 50#include <sys/conf.h> 51#include <sys/fcntl.h> --- 107 unchanged lines hidden (view full) --- 159 /* dump */ nodump, 160 /* psize */ nopsize, 161 /* flags */ D_DISK, 162}; 163 164int 165scd_attach(struct scd_softc *sc) 166{ | 44 45#undef SCD_DEBUG 46 47#include <sys/param.h> 48#include <sys/systm.h> 49#include <sys/kernel.h> 50#include <sys/conf.h> 51#include <sys/fcntl.h> --- 107 unchanged lines hidden (view full) --- 159 /* dump */ nodump, 160 /* psize */ nopsize, 161 /* flags */ D_DISK, 162}; 163 164int 165scd_attach(struct scd_softc *sc) 166{ |
167 struct scd_data *cd; | |
168 int unit; 169 | 167 int unit; 168 |
170 cd = &sc->data; | |
171 unit = device_get_unit(sc->dev); 172 173 init_drive(sc); 174 | 169 unit = device_get_unit(sc->dev); 170 171 init_drive(sc); 172 |
175 cd->flags = SCDINIT; 176 cd->audio_status = CD_AS_AUDIO_INVALID; 177 bioq_init(&cd->head); | 173 sc->data.flags = SCDINIT; 174 sc->data.audio_status = CD_AS_AUDIO_INVALID; 175 bioq_init(&sc->data.head); |
178 179 sc->scd_dev_t = make_dev(&scd_cdevsw, 8 * unit, 180 UID_ROOT, GID_OPERATOR, 0640, "scd%d", unit); 181 sc->scd_dev_t->si_drv1 = (void *)sc; 182 183 return (0); 184} 185 186static int 187scdopen(dev_t dev, int flags, int fmt, struct thread *td) 188{ 189 struct scd_softc *sc; 190 int rc; | 176 177 sc->scd_dev_t = make_dev(&scd_cdevsw, 8 * unit, 178 UID_ROOT, GID_OPERATOR, 0640, "scd%d", unit); 179 sc->scd_dev_t->si_drv1 = (void *)sc; 180 181 return (0); 182} 183 184static int 185scdopen(dev_t dev, int flags, int fmt, struct thread *td) 186{ 187 struct scd_softc *sc; 188 int rc; |
191 struct scd_data *cd; | |
192 193 sc = (struct scd_softc *)dev->si_drv1; 194 | 189 190 sc = (struct scd_softc *)dev->si_drv1; 191 |
195 cd = &sc->data; 196 | |
197 /* not initialized*/ | 192 /* not initialized*/ |
198 if (!(cd->flags & SCDINIT)) | 193 if (!(sc->data.flags & SCDINIT)) |
199 return (ENXIO); 200 201 /* invalidated in the meantime? mark all open part's invalid */ | 194 return (ENXIO); 195 196 /* invalidated in the meantime? mark all open part's invalid */ |
202 if (cd->openflag) | 197 if (sc->data.openflag) |
203 return (ENXIO); 204 205 XDEBUG(sc, 1, "DEBUG: status = 0x%x\n", SCD_READ(sc, IREG_STATUS)); 206 207 if ((rc = spin_up(sc)) != 0) { 208 print_error(sc, rc); 209 return (EIO); 210 } | 198 return (ENXIO); 199 200 XDEBUG(sc, 1, "DEBUG: status = 0x%x\n", SCD_READ(sc, IREG_STATUS)); 201 202 if ((rc = spin_up(sc)) != 0) { 203 print_error(sc, rc); 204 return (EIO); 205 } |
211 if (!(cd->flags & SCDTOC)) { | 206 if (!(sc->data.flags & SCDTOC)) { |
212 int loop_count = 3; 213 214 while (loop_count-- > 0 && (rc = read_toc(sc)) != 0) { 215 if (rc == ERR_NOT_SPINNING) { 216 rc = spin_up(sc); 217 if (rc) { 218 print_error(sc, rc);\ 219 return (EIO); 220 } 221 continue; 222 } 223 device_printf(sc->dev, "TOC read error 0x%x\n", rc); 224 return (EIO); 225 } 226 } 227 | 207 int loop_count = 3; 208 209 while (loop_count-- > 0 && (rc = read_toc(sc)) != 0) { 210 if (rc == ERR_NOT_SPINNING) { 211 rc = spin_up(sc); 212 if (rc) { 213 print_error(sc, rc);\ 214 return (EIO); 215 } 216 continue; 217 } 218 device_printf(sc->dev, "TOC read error 0x%x\n", rc); 219 return (EIO); 220 } 221 } 222 |
228 dev->si_bsize_phys = cd->blksize; | 223 dev->si_bsize_phys = sc->data.blksize; |
229 | 224 |
230 cd->openflag = 1; 231 cd->flags |= SCDVALID; | 225 sc->data.openflag = 1; 226 sc->data.flags |= SCDVALID; |
232 233 return (0); 234} 235 236static int 237scdclose(dev_t dev, int flags, int fmt, struct thread *td) 238{ 239 struct scd_softc *sc; | 227 228 return (0); 229} 230 231static int 232scdclose(dev_t dev, int flags, int fmt, struct thread *td) 233{ 234 struct scd_softc *sc; |
240 struct scd_data *cd; | |
241 242 sc = (struct scd_softc *)dev->si_drv1; 243 | 235 236 sc = (struct scd_softc *)dev->si_drv1; 237 |
244 cd = &sc->data; 245 246 if (!(cd->flags & SCDINIT) || !cd->openflag) | 238 if (!(sc->data.flags & SCDINIT) || !sc->data.openflag) |
247 return (ENXIO); 248 | 239 return (ENXIO); 240 |
249 if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS) { | 241 if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS) { |
250 (void)send_cmd(sc, CMD_SPIN_DOWN, 0); | 242 (void)send_cmd(sc, CMD_SPIN_DOWN, 0); |
251 cd->flags &= ~SCDSPINNING; | 243 sc->data.flags &= ~SCDSPINNING; |
252 } 253 254 255 /* close channel */ | 244 } 245 246 247 /* close channel */ |
256 cd->openflag = 0; | 248 sc->data.openflag = 0; |
257 258 return (0); 259} 260 261static void 262scdstrategy(struct bio *bp) 263{ | 249 250 return (0); 251} 252 253static void 254scdstrategy(struct bio *bp) 255{ |
264 struct scd_data *cd; | |
265 int s; 266 struct scd_softc *sc; 267 268 sc = (struct scd_softc *)bp->bio_dev->si_drv1; | 256 int s; 257 struct scd_softc *sc; 258 259 sc = (struct scd_softc *)bp->bio_dev->si_drv1; |
269 cd = &sc->data; | |
270 271 XDEBUG(sc, 2, "DEBUG: strategy: block=%ld, bcount=%ld\n", 272 (long)bp->bio_blkno, bp->bio_bcount); 273 274 if (bp->bio_blkno < 0 || (bp->bio_bcount % SCDBLKSIZE)) { 275 device_printf(sc->dev, "strategy failure: blkno = %ld, bcount = %ld\n", 276 (long)bp->bio_blkno, bp->bio_bcount); 277 bp->bio_error = EINVAL; 278 bp->bio_flags |= BIO_ERROR; 279 goto bad; 280 } 281 282 /* if device invalidated (e.g. media change, door open), error */ | 260 261 XDEBUG(sc, 2, "DEBUG: strategy: block=%ld, bcount=%ld\n", 262 (long)bp->bio_blkno, bp->bio_bcount); 263 264 if (bp->bio_blkno < 0 || (bp->bio_bcount % SCDBLKSIZE)) { 265 device_printf(sc->dev, "strategy failure: blkno = %ld, bcount = %ld\n", 266 (long)bp->bio_blkno, bp->bio_bcount); 267 bp->bio_error = EINVAL; 268 bp->bio_flags |= BIO_ERROR; 269 goto bad; 270 } 271 272 /* if device invalidated (e.g. media change, door open), error */ |
283 if (!(cd->flags & SCDVALID)) { | 273 if (!(sc->data.flags & SCDVALID)) { |
284 device_printf(sc->dev, "media changed\n"); 285 bp->bio_error = EIO; 286 goto bad; 287 } 288 289 /* read only */ 290 if (!(bp->bio_cmd == BIO_READ)) { 291 bp->bio_error = EROFS; 292 goto bad; 293 } 294 295 /* no data to read */ 296 if (bp->bio_bcount == 0) 297 goto done; 298 | 274 device_printf(sc->dev, "media changed\n"); 275 bp->bio_error = EIO; 276 goto bad; 277 } 278 279 /* read only */ 280 if (!(bp->bio_cmd == BIO_READ)) { 281 bp->bio_error = EROFS; 282 goto bad; 283 } 284 285 /* no data to read */ 286 if (bp->bio_bcount == 0) 287 goto done; 288 |
299 if (!(cd->flags & SCDTOC)) { | 289 if (!(sc->data.flags & SCDTOC)) { |
300 bp->bio_error = EIO; 301 goto bad; 302 } 303 304 bp->bio_pblkno = bp->bio_blkno; 305 bp->bio_resid = 0; 306 307 /* queue it */ 308 s = splbio(); | 290 bp->bio_error = EIO; 291 goto bad; 292 } 293 294 bp->bio_pblkno = bp->bio_blkno; 295 bp->bio_resid = 0; 296 297 /* queue it */ 298 s = splbio(); |
309 bioqdisksort(&cd->head, bp); | 299 bioqdisksort(&sc->data.head, bp); |
310 splx(s); 311 312 /* now check whether we can perform processing */ 313 scd_start(sc); 314 return; 315 316bad: 317 bp->bio_flags |= BIO_ERROR; 318done: 319 bp->bio_resid = bp->bio_bcount; 320 biodone(bp); 321 return; 322} 323 324static void 325scd_start(struct scd_softc *sc) 326{ | 300 splx(s); 301 302 /* now check whether we can perform processing */ 303 scd_start(sc); 304 return; 305 306bad: 307 bp->bio_flags |= BIO_ERROR; 308done: 309 bp->bio_resid = bp->bio_bcount; 310 biodone(bp); 311 return; 312} 313 314static void 315scd_start(struct scd_softc *sc) 316{ |
327 struct scd_data *cd = &sc->data; | |
328 struct bio *bp; 329 int s = splbio(); 330 | 317 struct bio *bp; 318 int s = splbio(); 319 |
331 if (cd->flags & SCDMBXBSY) { | 320 if (sc->data.flags & SCDMBXBSY) { |
332 splx(s); 333 return; 334 } 335 | 321 splx(s); 322 return; 323 } 324 |
336 bp = bioq_first(&cd->head); | 325 bp = bioq_first(&sc->data.head); |
337 if (bp != 0) { 338 /* block found to process, dequeue */ | 326 if (bp != 0) { 327 /* block found to process, dequeue */ |
339 bioq_remove(&cd->head, bp); 340 cd->flags |= SCDMBXBSY; | 328 bioq_remove(&sc->data.head, bp); 329 sc->data.flags |= SCDMBXBSY; |
341 splx(s); 342 } else { 343 /* nothing to do */ 344 splx(s); 345 return; 346 } 347 | 330 splx(s); 331 } else { 332 /* nothing to do */ 333 splx(s); 334 return; 335 } 336 |
348 cd->mbx.retry = 3; 349 cd->mbx.bp = bp; | 337 sc->data.mbx.retry = 3; 338 sc->data.mbx.bp = bp; |
350 splx(s); 351 | 339 splx(s); 340 |
352 scd_doread(sc, SCD_S_BEGIN, &(cd->mbx)); | 341 scd_doread(sc, SCD_S_BEGIN, &(sc->data.mbx)); |
353 return; 354} 355 356static int 357scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) 358{ | 342 return; 343} 344 345static int 346scdioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) 347{ |
359 struct scd_data *cd; | |
360 struct scd_softc *sc; 361 362 sc = (struct scd_softc *)dev->si_drv1; | 348 struct scd_softc *sc; 349 350 sc = (struct scd_softc *)dev->si_drv1; |
363 cd = &sc->data; | |
364 365 XDEBUG(sc, 1, "ioctl: cmd=0x%lx\n", cmd); 366 | 351 352 XDEBUG(sc, 1, "ioctl: cmd=0x%lx\n", cmd); 353 |
367 if (!(cd->flags & SCDVALID)) | 354 if (!(sc->data.flags & SCDVALID)) |
368 return (EIO); 369 370 switch (cmd) { 371 case DIOCGMEDIASIZE: | 355 return (EIO); 356 357 switch (cmd) { 358 case DIOCGMEDIASIZE: |
372 *(off_t *)addr = (off_t)cd->disksize * cd->blksize; | 359 *(off_t *)addr = (off_t)sc->data.disksize * sc->data.blksize; |
373 return (0); 374 break; 375 case DIOCGSECTORSIZE: | 360 return (0); 361 break; 362 case DIOCGSECTORSIZE: |
376 *(u_int *)addr = cd->blksize; | 363 *(u_int *)addr = sc->data.blksize; |
377 return (0); 378 break; 379 case CDIOCPLAYTRACKS: 380 return scd_playtracks(sc, (struct ioc_play_track *) addr); 381 case CDIOCPLAYBLOCKS: 382 return (EINVAL); 383 case CDIOCPLAYMSF: 384 return scd_playmsf(sc, (struct ioc_play_msf *) addr); --- 45 unchanged lines hidden (view full) --- 430 431/*************************************************************** 432 * lower level of driver starts here 433 **************************************************************/ 434 435static int 436scd_playtracks(struct scd_softc *sc, struct ioc_play_track *pt) 437{ | 364 return (0); 365 break; 366 case CDIOCPLAYTRACKS: 367 return scd_playtracks(sc, (struct ioc_play_track *) addr); 368 case CDIOCPLAYBLOCKS: 369 return (EINVAL); 370 case CDIOCPLAYMSF: 371 return scd_playmsf(sc, (struct ioc_play_msf *) addr); --- 45 unchanged lines hidden (view full) --- 417 418/*************************************************************** 419 * lower level of driver starts here 420 **************************************************************/ 421 422static int 423scd_playtracks(struct scd_softc *sc, struct ioc_play_track *pt) 424{ |
438 struct scd_data *cd = &sc->data; | |
439 struct ioc_play_msf msf; 440 int a = pt->start_track; 441 int z = pt->end_track; 442 int rc; 443 | 425 struct ioc_play_msf msf; 426 int a = pt->start_track; 427 int z = pt->end_track; 428 int rc; 429 |
444 if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { | 430 if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { |
445 if (rc == -ERR_NOT_SPINNING) { 446 if (spin_up(sc) != 0) 447 return (EIO); 448 rc = read_toc(sc); 449 } 450 if (rc != 0) { 451 print_error(sc, rc); 452 return (EIO); 453 } 454 } 455 456 XDEBUG(sc, 1, "playtracks from %d:%d to %d:%d\n", 457 a, pt->start_index, z, pt->end_index); 458 | 431 if (rc == -ERR_NOT_SPINNING) { 432 if (spin_up(sc) != 0) 433 return (EIO); 434 rc = read_toc(sc); 435 } 436 if (rc != 0) { 437 print_error(sc, rc); 438 return (EIO); 439 } 440 } 441 442 XDEBUG(sc, 1, "playtracks from %d:%d to %d:%d\n", 443 a, pt->start_index, z, pt->end_index); 444 |
459 if ( a < cd->first_track 460 || a > cd->last_track | 445 if ( a < sc->data.first_track 446 || a > sc->data.last_track |
461 || a > z | 447 || a > z |
462 || z > cd->last_track) | 448 || z > sc->data.last_track) |
463 return (EINVAL); 464 | 449 return (EINVAL); 450 |
465 bcopy(cd->toc[a].start_msf, &msf.start_m, 3); 466 hsg2msf(msf2hsg(cd->toc[z+1].start_msf)-1, &msf.end_m); | 451 bcopy(sc->data.toc[a].start_msf, &msf.start_m, 3); 452 hsg2msf(msf2hsg(sc->data.toc[z+1].start_msf)-1, &msf.end_m); |
467 468 return scd_play(sc, &msf); 469} 470 471/* The start/end msf is expected to be in bin format */ 472static int 473scd_playmsf(struct scd_softc *sc, struct ioc_play_msf *msfin) 474{ --- 8 unchanged lines hidden (view full) --- 483 484 return scd_play(sc, &msf); 485} 486 487/* The start/end msf is expected to be in bcd format */ 488static int 489scd_play(struct scd_softc *sc, struct ioc_play_msf *msf) 490{ | 453 454 return scd_play(sc, &msf); 455} 456 457/* The start/end msf is expected to be in bin format */ 458static int 459scd_playmsf(struct scd_softc *sc, struct ioc_play_msf *msfin) 460{ --- 8 unchanged lines hidden (view full) --- 469 470 return scd_play(sc, &msf); 471} 472 473/* The start/end msf is expected to be in bcd format */ 474static int 475scd_play(struct scd_softc *sc, struct ioc_play_msf *msf) 476{ |
491 struct scd_data *cd = &sc->data; | |
492 int i, rc; 493 494 XDEBUG(sc, 1, "playing: %02x:%02x:%02x -> %02x:%02x:%02x\n", 495 msf->start_m, msf->start_s, msf->start_f, 496 msf->end_m, msf->end_s, msf->end_f); 497 498 for (i = 0; i < 2; i++) { 499 rc = send_cmd(sc, CMD_PLAY_AUDIO, 7, 500 0x03, 501 msf->start_m, msf->start_s, msf->start_f, 502 msf->end_m, msf->end_s, msf->end_f); 503 if (rc == -ERR_NOT_SPINNING) { | 477 int i, rc; 478 479 XDEBUG(sc, 1, "playing: %02x:%02x:%02x -> %02x:%02x:%02x\n", 480 msf->start_m, msf->start_s, msf->start_f, 481 msf->end_m, msf->end_s, msf->end_f); 482 483 for (i = 0; i < 2; i++) { 484 rc = send_cmd(sc, CMD_PLAY_AUDIO, 7, 485 0x03, 486 msf->start_m, msf->start_s, msf->start_f, 487 msf->end_m, msf->end_s, msf->end_f); 488 if (rc == -ERR_NOT_SPINNING) { |
504 cd->flags &= ~SCDSPINNING; | 489 sc->data.flags &= ~SCDSPINNING; |
505 if (spin_up(sc) != 0) 506 return (EIO); 507 } else if (rc < 0) { 508 print_error(sc, rc); 509 return (EIO); 510 } else { 511 break; 512 } 513 } | 490 if (spin_up(sc) != 0) 491 return (EIO); 492 } else if (rc < 0) { 493 print_error(sc, rc); 494 return (EIO); 495 } else { 496 break; 497 } 498 } |
514 cd->audio_status = CD_AS_PLAY_IN_PROGRESS; 515 bcopy((char *)msf, (char *)&cd->last_play, sizeof(struct ioc_play_msf)); | 499 sc->data.audio_status = CD_AS_PLAY_IN_PROGRESS; 500 bcopy((char *)msf, (char *)&sc->data.last_play, sizeof(struct ioc_play_msf)); |
516 return (0); 517} 518 519static int 520scd_stop(struct scd_softc *sc) 521{ | 501 return (0); 502} 503 504static int 505scd_stop(struct scd_softc *sc) 506{ |
522 struct scd_data *cd = &sc->data; | |
523 524 (void)send_cmd(sc, CMD_STOP_AUDIO, 0); | 507 508 (void)send_cmd(sc, CMD_STOP_AUDIO, 0); |
525 cd->audio_status = CD_AS_PLAY_COMPLETED; | 509 sc->data.audio_status = CD_AS_PLAY_COMPLETED; |
526 return (0); 527} 528 529static int 530scd_pause(struct scd_softc *sc) 531{ | 510 return (0); 511} 512 513static int 514scd_pause(struct scd_softc *sc) 515{ |
532 struct scd_data *cd = &sc->data; | |
533 struct sony_subchannel_position_data subpos; 534 | 516 struct sony_subchannel_position_data subpos; 517 |
535 if (cd->audio_status != CD_AS_PLAY_IN_PROGRESS) | 518 if (sc->data.audio_status != CD_AS_PLAY_IN_PROGRESS) |
536 return (EINVAL); 537 538 if (read_subcode(sc, &subpos) != 0) 539 return (EIO); 540 541 if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0) 542 return (EIO); 543 | 519 return (EINVAL); 520 521 if (read_subcode(sc, &subpos) != 0) 522 return (EIO); 523 524 if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0) 525 return (EIO); 526 |
544 cd->last_play.start_m = subpos.abs_msf[0]; 545 cd->last_play.start_s = subpos.abs_msf[1]; 546 cd->last_play.start_f = subpos.abs_msf[2]; 547 cd->audio_status = CD_AS_PLAY_PAUSED; | 527 sc->data.last_play.start_m = subpos.abs_msf[0]; 528 sc->data.last_play.start_s = subpos.abs_msf[1]; 529 sc->data.last_play.start_f = subpos.abs_msf[2]; 530 sc->data.audio_status = CD_AS_PLAY_PAUSED; |
548 549 XDEBUG(sc, 1, "pause @ %02x:%02x:%02x\n", | 531 532 XDEBUG(sc, 1, "pause @ %02x:%02x:%02x\n", |
550 cd->last_play.start_m, 551 cd->last_play.start_s, 552 cd->last_play.start_f); | 533 sc->data.last_play.start_m, 534 sc->data.last_play.start_s, 535 sc->data.last_play.start_f); |
553 554 return (0); 555} 556 557static int 558scd_resume(struct scd_softc *sc) 559{ 560 561 if (sc->data.audio_status != CD_AS_PLAY_PAUSED) 562 return (EINVAL); 563 return scd_play(sc, &sc->data.last_play); 564} 565 566static int 567scd_eject(struct scd_softc *sc) 568{ | 536 537 return (0); 538} 539 540static int 541scd_resume(struct scd_softc *sc) 542{ 543 544 if (sc->data.audio_status != CD_AS_PLAY_PAUSED) 545 return (EINVAL); 546 return scd_play(sc, &sc->data.last_play); 547} 548 549static int 550scd_eject(struct scd_softc *sc) 551{ |
569 struct scd_data *cd = &sc->data; | |
570 | 552 |
571 cd->audio_status = CD_AS_AUDIO_INVALID; 572 cd->flags &= ~(SCDSPINNING|SCDTOC); | 553 sc->data.audio_status = CD_AS_AUDIO_INVALID; 554 sc->data.flags &= ~(SCDSPINNING|SCDTOC); |
573 574 if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0 || 575 send_cmd(sc, CMD_SPIN_DOWN, 0) != 0 || 576 send_cmd(sc, CMD_EJECT, 0) != 0) 577 { 578 return (EIO); 579 } 580 return (0); 581} 582 583static int 584scd_subchan(struct scd_softc *sc, struct ioc_read_subchannel *sch) 585{ | 555 556 if (send_cmd(sc, CMD_STOP_AUDIO, 0) != 0 || 557 send_cmd(sc, CMD_SPIN_DOWN, 0) != 0 || 558 send_cmd(sc, CMD_EJECT, 0) != 0) 559 { 560 return (EIO); 561 } 562 return (0); 563} 564 565static int 566scd_subchan(struct scd_softc *sc, struct ioc_read_subchannel *sch) 567{ |
586 struct scd_data *cd = &sc->data; | |
587 struct sony_subchannel_position_data q; 588 struct cd_sub_channel_info data; 589 590 XDEBUG(sc, 1, "subchan af=%d, df=%d\n", 591 sch->address_format, sch->data_format); 592 593 if (sch->address_format != CD_MSF_FORMAT) 594 return (EINVAL); 595 596 if (sch->data_format != CD_CURRENT_POSITION) 597 return (EINVAL); 598 599 if (read_subcode(sc, &q) != 0) 600 return (EIO); 601 | 568 struct sony_subchannel_position_data q; 569 struct cd_sub_channel_info data; 570 571 XDEBUG(sc, 1, "subchan af=%d, df=%d\n", 572 sch->address_format, sch->data_format); 573 574 if (sch->address_format != CD_MSF_FORMAT) 575 return (EINVAL); 576 577 if (sch->data_format != CD_CURRENT_POSITION) 578 return (EINVAL); 579 580 if (read_subcode(sc, &q) != 0) 581 return (EIO); 582 |
602 data.header.audio_status = cd->audio_status; | 583 data.header.audio_status = sc->data.audio_status; |
603 data.what.position.data_format = CD_MSF_FORMAT; 604 data.what.position.track_number = bcd2bin(q.track_number); 605 data.what.position.reladdr.msf.unused = 0; 606 data.what.position.reladdr.msf.minute = bcd2bin(q.rel_msf[0]); 607 data.what.position.reladdr.msf.second = bcd2bin(q.rel_msf[1]); 608 data.what.position.reladdr.msf.frame = bcd2bin(q.rel_msf[2]); 609 data.what.position.absaddr.msf.unused = 0; 610 data.what.position.absaddr.msf.minute = bcd2bin(q.abs_msf[0]); --- 4 unchanged lines hidden (view full) --- 615 return (EFAULT); 616 return (0); 617} 618 619int 620scd_probe(struct scd_softc *sc) 621{ 622 struct sony_drive_configuration drive_config; | 584 data.what.position.data_format = CD_MSF_FORMAT; 585 data.what.position.track_number = bcd2bin(q.track_number); 586 data.what.position.reladdr.msf.unused = 0; 587 data.what.position.reladdr.msf.minute = bcd2bin(q.rel_msf[0]); 588 data.what.position.reladdr.msf.second = bcd2bin(q.rel_msf[1]); 589 data.what.position.reladdr.msf.frame = bcd2bin(q.rel_msf[2]); 590 data.what.position.absaddr.msf.unused = 0; 591 data.what.position.absaddr.msf.minute = bcd2bin(q.abs_msf[0]); --- 4 unchanged lines hidden (view full) --- 596 return (EFAULT); 597 return (0); 598} 599 600int 601scd_probe(struct scd_softc *sc) 602{ 603 struct sony_drive_configuration drive_config; |
623 struct scd_data *cd; | |
624 int rc; 625 static char namebuf[8+16+8+3]; 626 char *s = namebuf; 627 int loop_count = 0; 628 | 604 int rc; 605 static char namebuf[8+16+8+3]; 606 char *s = namebuf; 607 int loop_count = 0; 608 |
629 cd = &sc->data; 630 cd->flags = SCDPROBING; | 609 sc->data.flags = SCDPROBING; |
631 632 bzero(&drive_config, sizeof(drive_config)); 633 634again: 635 /* Reset drive */ 636 SCD_WRITE(sc, OREG_CONTROL, CBIT_RESET_DRIVE); 637 638 /* Calm down */ --- 26 unchanged lines hidden (view full) --- 665 s--; 666 *s++ = ' '; 667 bcopy(drive_config.revision, s, 8); 668 s += 8; 669 while (*(s-1) == ' ') 670 s--; 671 *s = 0; 672 | 610 611 bzero(&drive_config, sizeof(drive_config)); 612 613again: 614 /* Reset drive */ 615 SCD_WRITE(sc, OREG_CONTROL, CBIT_RESET_DRIVE); 616 617 /* Calm down */ --- 26 unchanged lines hidden (view full) --- 644 s--; 645 *s++ = ' '; 646 bcopy(drive_config.revision, s, 8); 647 s += 8; 648 while (*(s-1) == ' ') 649 s--; 650 *s = 0; 651 |
673 cd->name = namebuf; | 652 sc->data.name = namebuf; |
674 675 if (drive_config.config & 0x10) | 653 654 if (drive_config.config & 0x10) |
676 cd->double_speed = 1; | 655 sc->data.double_speed = 1; |
677 else | 656 else |
678 cd->double_speed = 0; | 657 sc->data.double_speed = 0; |
679 680 return (0); 681} 682 683static int 684read_subcode(struct scd_softc *sc, struct sony_subchannel_position_data *scp) 685{ 686 int rc; --- 31 unchanged lines hidden (view full) --- 718 scd_doread(sc, sc->ch_state, sc->ch_mbxsave); 719} 720 721static void 722scd_doread(struct scd_softc *sc, int state, struct scd_mbx *mbxin) 723{ 724 struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? sc->ch_mbxsave : mbxin; 725 struct bio *bp = mbx->bp; | 658 659 return (0); 660} 661 662static int 663read_subcode(struct scd_softc *sc, struct sony_subchannel_position_data *scp) 664{ 665 int rc; --- 31 unchanged lines hidden (view full) --- 697 scd_doread(sc, sc->ch_state, sc->ch_mbxsave); 698} 699 700static void 701scd_doread(struct scd_softc *sc, int state, struct scd_mbx *mbxin) 702{ 703 struct scd_mbx *mbx = (state!=SCD_S_BEGIN) ? sc->ch_mbxsave : mbxin; 704 struct bio *bp = mbx->bp; |
726 struct scd_data *cd = &sc->data; | |
727 int i; 728 int blknum; 729 caddr_t addr; 730 static char sdata[3]; /* Must be preserved between calls to this function */ 731 732loop: 733 switch (state) { 734 case SCD_S_BEGIN: --- 19 unchanged lines hidden (view full) --- 754 sc->ch_state = SCD_S_WAITSTAT; 755 sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */ 756 return; 757 } 758 759 process_attention(sc); 760 761 /* reject, if audio active */ | 705 int i; 706 int blknum; 707 caddr_t addr; 708 static char sdata[3]; /* Must be preserved between calls to this function */ 709 710loop: 711 switch (state) { 712 case SCD_S_BEGIN: --- 19 unchanged lines hidden (view full) --- 732 sc->ch_state = SCD_S_WAITSTAT; 733 sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */ 734 return; 735 } 736 737 process_attention(sc); 738 739 /* reject, if audio active */ |
762 if (cd->audio_status & CD_AS_PLAY_IN_PROGRESS) { | 740 if (sc->data.audio_status & CD_AS_PLAY_IN_PROGRESS) { |
763 device_printf(sc->dev, "audio is active\n"); 764 goto harderr; 765 } 766 | 741 device_printf(sc->dev, "audio is active\n"); 742 goto harderr; 743 } 744 |
767 mbx->sz = cd->blksize; | 745 mbx->sz = sc->data.blksize; |
768 769 /* for first block */ 770 mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz; 771 mbx->skip = 0; 772 773nextblock: | 746 747 /* for first block */ 748 mbx->nblk = (bp->bio_bcount + (mbx->sz-1)) / mbx->sz; 749 mbx->skip = 0; 750 751nextblock: |
774 if (!(cd->flags & SCDVALID)) | 752 if (!(sc->data.flags & SCDVALID)) |
775 goto changed; 776 777 blknum = (bp->bio_blkno / (mbx->sz/DEV_BSIZE)) 778 + mbx->skip/mbx->sz; 779 780 XDEBUG(sc, 2, "scd_doread: read blknum=%d\n", blknum); 781 782 /* build parameter block */ --- 26 unchanged lines hidden (view full) --- 809 SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR); 810 switch ((i = SCD_READ(sc, IREG_RESULT)) & 0xf0) { 811 case 0x20: 812 i = SCD_READ(sc, IREG_RESULT); 813 print_error(sc, i); 814 goto harderr; 815 case 0x00: 816 (void)SCD_READ(sc, IREG_RESULT); | 753 goto changed; 754 755 blknum = (bp->bio_blkno / (mbx->sz/DEV_BSIZE)) 756 + mbx->skip/mbx->sz; 757 758 XDEBUG(sc, 2, "scd_doread: read blknum=%d\n", blknum); 759 760 /* build parameter block */ --- 26 unchanged lines hidden (view full) --- 787 SCD_WRITE(sc, OREG_CONTROL, CBIT_RESULT_READY_CLEAR); 788 switch ((i = SCD_READ(sc, IREG_RESULT)) & 0xf0) { 789 case 0x20: 790 i = SCD_READ(sc, IREG_RESULT); 791 print_error(sc, i); 792 goto harderr; 793 case 0x00: 794 (void)SCD_READ(sc, IREG_RESULT); |
817 cd->flags |= SCDSPINNING; | 795 sc->data.flags |= SCDSPINNING; |
818 break; 819 } 820 XDEBUG(sc, 1, "DEBUG: spin up complete\n"); 821 822 state = SCD_S_BEGIN1; 823 goto loop; 824 825 case SCD_S_WAITFIFO: --- 8 unchanged lines hidden (view full) --- 834 sc->ch = timeout(scd_timeout, (caddr_t)sc,hz/100); /* XXX */ 835 return; 836 } 837 XDEBUG(sc, 1, "mbx->count (writeparamwait) = %d(%d)\n", mbx->count, 100); 838 839writeparam: 840 /* The reason this test isn't done 'till now is to make sure */ 841 /* that it is ok to send the SPIN_UP cmd below. */ | 796 break; 797 } 798 XDEBUG(sc, 1, "DEBUG: spin up complete\n"); 799 800 state = SCD_S_BEGIN1; 801 goto loop; 802 803 case SCD_S_WAITFIFO: --- 8 unchanged lines hidden (view full) --- 812 sc->ch = timeout(scd_timeout, (caddr_t)sc,hz/100); /* XXX */ 813 return; 814 } 815 XDEBUG(sc, 1, "mbx->count (writeparamwait) = %d(%d)\n", mbx->count, 100); 816 817writeparam: 818 /* The reason this test isn't done 'till now is to make sure */ 819 /* that it is ok to send the SPIN_UP cmd below. */ |
842 if (!(cd->flags & SCDSPINNING)) { | 820 if (!(sc->data.flags & SCDSPINNING)) { |
843 XDEBUG(sc, 1, "spinning up drive ...\n"); 844 SCD_WRITE(sc, OREG_COMMAND, CMD_SPIN_UP); 845 mbx->count = 300; 846 sc->ch_state = SCD_S_WAITSPIN; 847 sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */ 848 return; 849 } 850 --- 25 unchanged lines hidden (view full) --- 876 if (mbx->count-- <= 0) { 877 if (STATUS_BIT(sc, SBIT_RESULT_READY)) 878 goto got_param; 879 device_printf(sc->dev, "timeout while reading data\n"); 880 goto readerr; 881 } 882 if (!STATUS_BIT(sc, SBIT_DATA_READY)) { 883 process_attention(sc); | 821 XDEBUG(sc, 1, "spinning up drive ...\n"); 822 SCD_WRITE(sc, OREG_COMMAND, CMD_SPIN_UP); 823 mbx->count = 300; 824 sc->ch_state = SCD_S_WAITSPIN; 825 sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */ 826 return; 827 } 828 --- 25 unchanged lines hidden (view full) --- 854 if (mbx->count-- <= 0) { 855 if (STATUS_BIT(sc, SBIT_RESULT_READY)) 856 goto got_param; 857 device_printf(sc->dev, "timeout while reading data\n"); 858 goto readerr; 859 } 860 if (!STATUS_BIT(sc, SBIT_DATA_READY)) { 861 process_attention(sc); |
884 if (!(cd->flags & SCDVALID)) | 862 if (!(sc->data.flags & SCDVALID)) |
885 goto changed; 886 sc->ch_state = SCD_S_WAITREAD; 887 sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */ 888 return; 889 } 890 XDEBUG(sc, 2, "mbx->count (after RDY_BIT) = %d(%d)\n", mbx->count, RDELAY_WAITREAD); 891 892got_data: --- 42 unchanged lines hidden (view full) --- 935 break; 936 case 0x20: 937 i = SCD_READ(sc, IREG_RESULT); 938 switch (i) { 939 case ERR_NOT_SPINNING: 940 XDEBUG(sc, 1, "read error: drive not spinning\n"); 941 if (mbx->retry-- > 0) { 942 state = SCD_S_BEGIN1; | 863 goto changed; 864 sc->ch_state = SCD_S_WAITREAD; 865 sc->ch = timeout(scd_timeout, (caddr_t)sc, hz/100); /* XXX */ 866 return; 867 } 868 XDEBUG(sc, 2, "mbx->count (after RDY_BIT) = %d(%d)\n", mbx->count, RDELAY_WAITREAD); 869 870got_data: --- 42 unchanged lines hidden (view full) --- 913 break; 914 case 0x20: 915 i = SCD_READ(sc, IREG_RESULT); 916 switch (i) { 917 case ERR_NOT_SPINNING: 918 XDEBUG(sc, 1, "read error: drive not spinning\n"); 919 if (mbx->retry-- > 0) { 920 state = SCD_S_BEGIN1; |
943 cd->flags &= ~SCDSPINNING; | 921 sc->data.flags &= ~SCDSPINNING; |
944 goto loop; 945 } 946 goto harderr; 947 default: 948 print_error(sc, i); 949 goto readerr; 950 } 951 case 0x00: --- 5 unchanged lines hidden (view full) --- 957 mbx->skip += mbx->sz; 958 goto nextblock; 959 } 960 961 /* return buffer */ 962 bp->bio_resid = 0; 963 biodone(bp); 964 | 922 goto loop; 923 } 924 goto harderr; 925 default: 926 print_error(sc, i); 927 goto readerr; 928 } 929 case 0x00: --- 5 unchanged lines hidden (view full) --- 935 mbx->skip += mbx->sz; 936 goto nextblock; 937 } 938 939 /* return buffer */ 940 bp->bio_resid = 0; 941 biodone(bp); 942 |
965 cd->flags &= ~SCDMBXBSY; | 943 sc->data.flags &= ~SCDMBXBSY; |
966 scd_start(sc); 967 return; 968 } 969 970readerr: 971 if (mbx->retry-- > 0) { 972 device_printf(sc->dev, "retrying ...\n"); 973 state = SCD_S_BEGIN1; 974 goto loop; 975 } 976harderr: 977 /* invalidate the buffer */ 978 bp->bio_error = EIO; 979 bp->bio_flags |= BIO_ERROR; 980 bp->bio_resid = bp->bio_bcount; 981 biodone(bp); 982 | 944 scd_start(sc); 945 return; 946 } 947 948readerr: 949 if (mbx->retry-- > 0) { 950 device_printf(sc->dev, "retrying ...\n"); 951 state = SCD_S_BEGIN1; 952 goto loop; 953 } 954harderr: 955 /* invalidate the buffer */ 956 bp->bio_error = EIO; 957 bp->bio_flags |= BIO_ERROR; 958 bp->bio_resid = bp->bio_bcount; 959 biodone(bp); 960 |
983 cd->flags &= ~SCDMBXBSY; | 961 sc->data.flags &= ~SCDMBXBSY; |
984 scd_start(sc); 985 return; 986 987changed: 988 device_printf(sc->dev, "media changed\n"); 989 goto harderr; 990} 991 992static void 993hsg2msf(int hsg, bcd_t *msf) 994{ | 962 scd_start(sc); 963 return; 964 965changed: 966 device_printf(sc->dev, "media changed\n"); 967 goto harderr; 968} 969 970static void 971hsg2msf(int hsg, bcd_t *msf) 972{ |
973 |
|
995 hsg += 150; 996 M_msf(msf) = bin2bcd(hsg / 4500); 997 hsg %= 4500; 998 S_msf(msf) = bin2bcd(hsg / 75); 999 F_msf(msf) = bin2bcd(hsg % 75); 1000} 1001 1002static int 1003msf2hsg(bcd_t *msf) 1004{ | 974 hsg += 150; 975 M_msf(msf) = bin2bcd(hsg / 4500); 976 hsg %= 4500; 977 S_msf(msf) = bin2bcd(hsg / 75); 978 F_msf(msf) = bin2bcd(hsg % 75); 979} 980 981static int 982msf2hsg(bcd_t *msf) 983{ |
984 |
|
1005 return (bcd2bin(M_msf(msf)) * 60 + 1006 bcd2bin(S_msf(msf))) * 75 + 1007 bcd2bin(F_msf(msf)) - 150; 1008} 1009 1010static void 1011process_attention(struct scd_softc *sc) 1012{ --- 99 unchanged lines hidden (view full) --- 1112 return (tl); 1113 (char *)tl += 9; 1114 return (tl); 1115} 1116 1117static int 1118read_toc(struct scd_softc *sc) 1119{ | 985 return (bcd2bin(M_msf(msf)) * 60 + 986 bcd2bin(S_msf(msf))) * 75 + 987 bcd2bin(F_msf(msf)) - 150; 988} 989 990static void 991process_attention(struct scd_softc *sc) 992{ --- 99 unchanged lines hidden (view full) --- 1092 return (tl); 1093 (char *)tl += 9; 1094 return (tl); 1095} 1096 1097static int 1098read_toc(struct scd_softc *sc) 1099{ |
1120 struct scd_data *cd; | |
1121 struct sony_toc toc; 1122 struct sony_tracklist *tl; 1123 int rc, i, j; 1124 u_long first, last; 1125 | 1100 struct sony_toc toc; 1101 struct sony_tracklist *tl; 1102 int rc, i, j; 1103 u_long first, last; 1104 |
1126 cd = &sc->data; 1127 | |
1128 rc = send_cmd(sc, CMD_GET_TOC, 1, 1); 1129 if (rc < 0) 1130 return (rc); 1131 if (rc > sizeof(toc)) { 1132 device_printf(sc->dev, "program error: toc too large (%d)\n", rc); 1133 return (EIO); 1134 } 1135 if (get_result(sc, rc, (u_char *)&toc) != 0) 1136 return (EIO); 1137 1138 XDEBUG(sc, 1, "toc read. len = %d, sizeof(toc) = %d\n", rc, sizeof(toc)); 1139 1140 tl = get_tl(&toc, rc); 1141 first = msf2hsg(tl->start_msf); 1142 last = msf2hsg(toc.lead_out_start_msf); | 1105 rc = send_cmd(sc, CMD_GET_TOC, 1, 1); 1106 if (rc < 0) 1107 return (rc); 1108 if (rc > sizeof(toc)) { 1109 device_printf(sc->dev, "program error: toc too large (%d)\n", rc); 1110 return (EIO); 1111 } 1112 if (get_result(sc, rc, (u_char *)&toc) != 0) 1113 return (EIO); 1114 1115 XDEBUG(sc, 1, "toc read. len = %d, sizeof(toc) = %d\n", rc, sizeof(toc)); 1116 1117 tl = get_tl(&toc, rc); 1118 first = msf2hsg(tl->start_msf); 1119 last = msf2hsg(toc.lead_out_start_msf); |
1143 cd->blksize = SCDBLKSIZE; 1144 cd->disksize = last*cd->blksize/DEV_BSIZE; | 1120 sc->data.blksize = SCDBLKSIZE; 1121 sc->data.disksize = last*sc->data.blksize/DEV_BSIZE; |
1145 1146 XDEBUG(sc, 1, "firstsector = %ld, lastsector = %ld", first, last); 1147 | 1122 1123 XDEBUG(sc, 1, "firstsector = %ld, lastsector = %ld", first, last); 1124 |
1148 cd->first_track = bcd2bin(toc.first_track); 1149 cd->last_track = bcd2bin(toc.last_track); 1150 if (cd->last_track > (MAX_TRACKS-2)) 1151 cd->last_track = MAX_TRACKS-2; 1152 for (j = 0, i = cd->first_track; i <= cd->last_track; i++, j++) { 1153 cd->toc[i].adr = tl[j].adr; 1154 cd->toc[i].ctl = tl[j].ctl; /* for xcdplayer */ 1155 bcopy(tl[j].start_msf, cd->toc[i].start_msf, 3); | 1125 sc->data.first_track = bcd2bin(toc.first_track); 1126 sc->data.last_track = bcd2bin(toc.last_track); 1127 if (sc->data.last_track > (MAX_TRACKS-2)) 1128 sc->data.last_track = MAX_TRACKS-2; 1129 for (j = 0, i = sc->data.first_track; i <= sc->data.last_track; i++, j++) { 1130 sc->data.toc[i].adr = tl[j].adr; 1131 sc->data.toc[i].ctl = tl[j].ctl; /* for xcdplayer */ 1132 bcopy(tl[j].start_msf, sc->data.toc[i].start_msf, 3); |
1156#ifdef SCD_DEBUG 1157 if (scd_debuglevel > 0) { 1158 if ((j % 3) == 0) { 1159 printf("\n"); 1160 device_printf(sc->dev, "tracks "); 1161 } 1162 printf("[%03d: %2d %2d %2d] ", i, | 1133#ifdef SCD_DEBUG 1134 if (scd_debuglevel > 0) { 1135 if ((j % 3) == 0) { 1136 printf("\n"); 1137 device_printf(sc->dev, "tracks "); 1138 } 1139 printf("[%03d: %2d %2d %2d] ", i, |
1163 bcd2bin(cd->toc[i].start_msf[0]), 1164 bcd2bin(cd->toc[i].start_msf[1]), 1165 bcd2bin(cd->toc[i].start_msf[2])); | 1140 bcd2bin(sc->data.toc[i].start_msf[0]), 1141 bcd2bin(sc->data.toc[i].start_msf[1]), 1142 bcd2bin(sc->data.toc[i].start_msf[2])); |
1166 } 1167#endif 1168 } | 1143 } 1144#endif 1145 } |
1169 bcopy(toc.lead_out_start_msf, cd->toc[cd->last_track+1].start_msf, 3); | 1146 bcopy(toc.lead_out_start_msf, sc->data.toc[sc->data.last_track+1].start_msf, 3); |
1170#ifdef SCD_DEBUG 1171 if (scd_debuglevel > 0) { | 1147#ifdef SCD_DEBUG 1148 if (scd_debuglevel > 0) { |
1172 i = cd->last_track+1; | 1149 i = sc->data.last_track+1; |
1173 printf("[END: %2d %2d %2d]\n", | 1150 printf("[END: %2d %2d %2d]\n", |
1174 bcd2bin(cd->toc[i].start_msf[0]), 1175 bcd2bin(cd->toc[i].start_msf[1]), 1176 bcd2bin(cd->toc[i].start_msf[2])); | 1151 bcd2bin(sc->data.toc[i].start_msf[0]), 1152 bcd2bin(sc->data.toc[i].start_msf[1]), 1153 bcd2bin(sc->data.toc[i].start_msf[2])); |
1177 } 1178#endif 1179 | 1154 } 1155#endif 1156 |
1180 cd->flags |= SCDTOC; | 1157 sc->data.flags |= SCDTOC; |
1181 1182 return (0); 1183} 1184 1185static void 1186init_drive(struct scd_softc *sc) 1187{ 1188 int rc; --- 83 unchanged lines hidden (view full) --- 1272 XDEBUG(sc, 1, "DEBUG: send_cmd: result_len=%d\n", rc); 1273 return (rc); 1274 } 1275} 1276 1277static void 1278print_error(struct scd_softc *sc, int errcode) 1279{ | 1158 1159 return (0); 1160} 1161 1162static void 1163init_drive(struct scd_softc *sc) 1164{ 1165 int rc; --- 83 unchanged lines hidden (view full) --- 1249 XDEBUG(sc, 1, "DEBUG: send_cmd: result_len=%d\n", rc); 1250 return (rc); 1251 } 1252} 1253 1254static void 1255print_error(struct scd_softc *sc, int errcode) 1256{ |
1257 |
|
1280 switch (errcode) { 1281 case -ERR_CD_NOT_LOADED: 1282 device_printf(sc->dev, "door is open\n"); 1283 break; 1284 case -ERR_NO_CD_INSIDE: 1285 device_printf(sc->dev, "no cd inside\n"); 1286 break; 1287 default: --- 59 unchanged lines hidden (view full) --- 1347 device_printf(sc->dev, "timeout.\n"); 1348 return (EIO); 1349} 1350 1351/* these two routines for xcdplayer - "borrowed" from mcd.c */ 1352static int 1353scd_toc_header (struct scd_softc *sc, struct ioc_toc_header* th) 1354{ | 1258 switch (errcode) { 1259 case -ERR_CD_NOT_LOADED: 1260 device_printf(sc->dev, "door is open\n"); 1261 break; 1262 case -ERR_NO_CD_INSIDE: 1263 device_printf(sc->dev, "no cd inside\n"); 1264 break; 1265 default: --- 59 unchanged lines hidden (view full) --- 1325 device_printf(sc->dev, "timeout.\n"); 1326 return (EIO); 1327} 1328 1329/* these two routines for xcdplayer - "borrowed" from mcd.c */ 1330static int 1331scd_toc_header (struct scd_softc *sc, struct ioc_toc_header* th) 1332{ |
1355 struct scd_data *cd = &sc->data; | |
1356 int rc; 1357 | 1333 int rc; 1334 |
1358 if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { | 1335 if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { |
1359 print_error(sc, rc); 1360 return (EIO); 1361 } 1362 | 1336 print_error(sc, rc); 1337 return (EIO); 1338 } 1339 |
1363 th->starting_track = cd->first_track; 1364 th->ending_track = cd->last_track; | 1340 th->starting_track = sc->data.first_track; 1341 th->ending_track = sc->data.last_track; |
1365 th->len = 0; /* not used */ 1366 1367 return (0); 1368} 1369 1370static int 1371scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te) 1372{ | 1342 th->len = 0; /* not used */ 1343 1344 return (0); 1345} 1346 1347static int 1348scd_toc_entrys (struct scd_softc *sc, struct ioc_read_toc_entry *te) 1349{ |
1373 struct scd_data *cd = &sc->data; | |
1374 struct cd_toc_entry toc_entry; 1375 int rc, i, len = te->data_len; 1376 | 1350 struct cd_toc_entry toc_entry; 1351 int rc, i, len = te->data_len; 1352 |
1377 if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { | 1353 if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { |
1378 print_error(sc, rc); 1379 return (EIO); 1380 } 1381 1382 /* find the toc to copy*/ 1383 i = te->starting_track; 1384 if (i == SCD_LASTPLUS1) | 1354 print_error(sc, rc); 1355 return (EIO); 1356 } 1357 1358 /* find the toc to copy*/ 1359 i = te->starting_track; 1360 if (i == SCD_LASTPLUS1) |
1385 i = cd->last_track + 1; | 1361 i = sc->data.last_track + 1; |
1386 1387 /* verify starting track */ | 1362 1363 /* verify starting track */ |
1388 if (i < cd->first_track || i > cd->last_track+1) | 1364 if (i < sc->data.first_track || i > sc->data.last_track+1) |
1389 return (EINVAL); 1390 1391 /* valid length ? */ 1392 if (len < sizeof(struct cd_toc_entry) 1393 || (len % sizeof(struct cd_toc_entry)) != 0) 1394 return (EINVAL); 1395 1396 /* copy the toc data */ | 1365 return (EINVAL); 1366 1367 /* valid length ? */ 1368 if (len < sizeof(struct cd_toc_entry) 1369 || (len % sizeof(struct cd_toc_entry)) != 0) 1370 return (EINVAL); 1371 1372 /* copy the toc data */ |
1397 toc_entry.control = cd->toc[i].ctl; | 1373 toc_entry.control = sc->data.toc[i].ctl; |
1398 toc_entry.addr_type = te->address_format; 1399 toc_entry.track = i; 1400 if (te->address_format == CD_MSF_FORMAT) { 1401 toc_entry.addr.msf.unused = 0; | 1374 toc_entry.addr_type = te->address_format; 1375 toc_entry.track = i; 1376 if (te->address_format == CD_MSF_FORMAT) { 1377 toc_entry.addr.msf.unused = 0; |
1402 toc_entry.addr.msf.minute = bcd2bin(cd->toc[i].start_msf[0]); 1403 toc_entry.addr.msf.second = bcd2bin(cd->toc[i].start_msf[1]); 1404 toc_entry.addr.msf.frame = bcd2bin(cd->toc[i].start_msf[2]); | 1378 toc_entry.addr.msf.minute = bcd2bin(sc->data.toc[i].start_msf[0]); 1379 toc_entry.addr.msf.second = bcd2bin(sc->data.toc[i].start_msf[1]); 1380 toc_entry.addr.msf.frame = bcd2bin(sc->data.toc[i].start_msf[2]); |
1405 } 1406 1407 /* copy the data back */ 1408 if (copyout(&toc_entry, te->data, sizeof(struct cd_toc_entry)) != 0) 1409 return (EFAULT); 1410 1411 return (0); 1412} 1413 1414 1415static int 1416scd_toc_entry (struct scd_softc *sc, struct ioc_read_toc_single_entry *te) 1417{ | 1381 } 1382 1383 /* copy the data back */ 1384 if (copyout(&toc_entry, te->data, sizeof(struct cd_toc_entry)) != 0) 1385 return (EFAULT); 1386 1387 return (0); 1388} 1389 1390 1391static int 1392scd_toc_entry (struct scd_softc *sc, struct ioc_read_toc_single_entry *te) 1393{ |
1418 struct scd_data *cd = &sc->data; | |
1419 struct cd_toc_entry toc_entry; 1420 int rc, i; 1421 | 1394 struct cd_toc_entry toc_entry; 1395 int rc, i; 1396 |
1422 if (!(cd->flags & SCDTOC) && (rc = read_toc(sc)) != 0) { | 1397 if (!(sc->data.flags & SCDTOC) && (rc = read_toc(sc)) != 0) { |
1423 print_error(sc, rc); 1424 return (EIO); 1425 } 1426 1427 /* find the toc to copy*/ 1428 i = te->track; 1429 if (i == SCD_LASTPLUS1) | 1398 print_error(sc, rc); 1399 return (EIO); 1400 } 1401 1402 /* find the toc to copy*/ 1403 i = te->track; 1404 if (i == SCD_LASTPLUS1) |
1430 i = cd->last_track + 1; | 1405 i = sc->data.last_track + 1; |
1431 1432 /* verify starting track */ | 1406 1407 /* verify starting track */ |
1433 if (i < cd->first_track || i > cd->last_track+1) | 1408 if (i < sc->data.first_track || i > sc->data.last_track+1) |
1434 return (EINVAL); 1435 1436 /* copy the toc data */ | 1409 return (EINVAL); 1410 1411 /* copy the toc data */ |
1437 toc_entry.control = cd->toc[i].ctl; | 1412 toc_entry.control = sc->data.toc[i].ctl; |
1438 toc_entry.addr_type = te->address_format; 1439 toc_entry.track = i; 1440 if (te->address_format == CD_MSF_FORMAT) { 1441 toc_entry.addr.msf.unused = 0; | 1413 toc_entry.addr_type = te->address_format; 1414 toc_entry.track = i; 1415 if (te->address_format == CD_MSF_FORMAT) { 1416 toc_entry.addr.msf.unused = 0; |
1442 toc_entry.addr.msf.minute = bcd2bin(cd->toc[i].start_msf[0]); 1443 toc_entry.addr.msf.second = bcd2bin(cd->toc[i].start_msf[1]); 1444 toc_entry.addr.msf.frame = bcd2bin(cd->toc[i].start_msf[2]); | 1417 toc_entry.addr.msf.minute = bcd2bin(sc->data.toc[i].start_msf[0]); 1418 toc_entry.addr.msf.second = bcd2bin(sc->data.toc[i].start_msf[1]); 1419 toc_entry.addr.msf.frame = bcd2bin(sc->data.toc[i].start_msf[2]); |
1445 } 1446 1447 /* copy the data back */ 1448 bcopy(&toc_entry, &te->entry, sizeof(struct cd_toc_entry)); 1449 1450 return (0); 1451} | 1420 } 1421 1422 /* copy the data back */ 1423 bcopy(&toc_entry, &te->entry, sizeof(struct cd_toc_entry)); 1424 1425 return (0); 1426} |