/*
* sbpcd.c CD-ROM device driver for the whole family of traditional,
* non-ATAPI IDE-style Matsushita/Panasonic CR-5xx drives.
* Works with SoundBlaster compatible cards and with "no-sound"
* interface cards like Lasermate, Panasonic CI-101P, Teac, ...
* Also for the Longshine LCS-7260 drive.
* Also for the IBM "External ISA CD-Rom" drive.
* Also for the CreativeLabs CD200 drive.
* Also for the TEAC CD-55A drive.
* Also for the ECS-AT "Vertos 100" drive.
* Not for Sanyo drives (but for the H94A, sjcd is there...).
* Not for any other Funai drives than the CD200 types (sometimes
* labelled E2550UA or MK4015 or 2800F).
*/
#define VERSION "v4.61 Eberhard Moenkeberg <emoenke@gwdg.de>"
/* Copyright (C) 1993, 1994, 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* You should have received a copy of the GNU General Public License
* (for example /usr/src/linux/COPYING); if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* If you change this software, you should mail a .diff file with some
* description lines to emoenke@gwdg.de. I want to know about it.
*
* If you are the editor of a Linux CD, you should enable sbpcd.c within
* your boot floppy kernel and send me one of your CDs for free.
*
* If you would like to port the driver to an other operating system (f.e.
* FreeBSD or NetBSD) or use it as an information source, you shall not be
* restricted by the GPL under the following conditions:
* a) the source code of your work is freely available
* b) my part of the work gets mentioned at all places where your
* authorship gets mentioned
* c) I receive a copy of your code together with a full installation
* package of your operating system for free.
*
*
* VERSION HISTORY
*
* 0.1 initial release, April/May 93, after mcd.c (Martin Harriss)
*
* 0.2 the "repeat:"-loop in do_sbpcd_request did not check for
* end-of-request_queue (resulting in kernel panic).
* Flow control seems stable, but throughput is not better.
*
* 0.3 interrupt locking totally eliminated (maybe "inb" and "outb"
* are still locking) - 0.2 made keyboard-type-ahead losses.
* check_sbpcd_media_change added (to use by isofs/inode.c)
* - but it detects almost nothing.
*
* 0.4 use MAJOR 25 definitely.
* Almost total re-design to support double-speed drives and
* "naked" (no sound) interface cards ("LaserMate" interface type).
* Flow control should be exact now.
* Don't occupy the SbPro IRQ line (not needed either); will
* live together with Hannu Savolainen's sndkit now.
* Speeded up data transfer to 150 kB/sec, with help from Kai
* Makisara, the "provider" of the "mt" tape utility.
* Give "SpinUp" command if necessary.
* First steps to support up to 4 drives (but currently only one).
* Implemented audio capabilities - workman should work, xcdplayer
* gives some problems.
* This version is still consuming too much CPU time, and
* sleeping still has to be worked on.
* During "long" implied seeks, it seems possible that a
* ReadStatus command gets ignored. That gives the message
* "ResponseStatus timed out" (happens about 6 times here during
* a "ls -alR" of the YGGDRASIL LGX-Beta CD). Such a case is
* handled without data error, but it should get done better.
*
* 0.5 Free CPU during waits (again with help from Kai Makisara).
* Made it work together with the LILO/kernel setup standard.
* Included auto-probing code, as suggested by YGGDRASIL.
* Formal redesign to add DDI debugging.
* There are still flaws in IOCTL (workman with double speed drive).
*
* 1.0 Added support for all drive IDs (0...3, no longer only 0)
* and up to 4 drives on one controller.
* Added "#define MANY_SESSION" for "old" multi session CDs.
*
* 1.1 Do SpinUp for new drives, too.
* Revised for clean compile under "old" kernels (0.99pl9).
*
* 1.2 Found the "workman with double-speed drive" bug: use the driver's
* audio_state, not what the drive is reporting with ReadSubQ.
*
* 1.3 Minor cleanups.
* Refinements regarding Workman.
*
* 1.4 Read XA disks (PhotoCDs) with "old" drives, too (but only the first
* session - no chance to fully access a "multi-session" CD).
* This currently still is too slow (50 kB/sec) - but possibly
* the old drives won't do it faster.
* Implemented "door (un)lock" for new drives (still does not work
* as wanted - no lock possible after an unlock).
* Added some debugging printout for the UPC/EAN code - but my drives
* return only zeroes. Is there no UPC/EAN code written?
*
* 1.5 Laborate with UPC/EAN code (not better yet).
* Adapt to kernel 1.1.8 change (have to explicitly include
* <linux/string.h> now).
*
* 1.6 Trying to read audio frames as data. Impossible with the current
* drive firmware levels, as it seems. Awaiting any hint. ;-)
* Changed "door unlock": repeat it until success.
* Changed CDROMSTOP routine (stop somewhat "softer" so that Workman
* won't get confused).
* Added a third interface type: Sequoia S-1000, as used with the SPEA
* Media FX sound card. This interface (usable for Sony and Mitsumi
* drives, too) needs a special configuration setup and behaves like a
* LaserMate type after that. Still experimental - I do not have such
* an interface.
* Use the "variable BLOCK_SIZE" feature (2048). But it does only work
* if you give the mount option "block=2048".
* The media_check routine is currently disabled; now that it gets
* called as it should I fear it must get synchronized for not to
* disturb the normal driver's activity.
*
* 2.0 Version number bumped - two reasons:
* - reading audio tracks as data works now with CR-562 and CR-563. We
* currently do it by an IOCTL (yet has to get standardized), one frame
* at a time; that is pretty slow. But it works.
* - we are maintaining now up to 4 interfaces (each up to 4 drives):
* did it the easy way - a different MAJOR (25, 26, ...) and a different
* copy of the driver (sbpcd.c, sbpcd2.c, sbpcd3.c, sbpcd4.c - only
* distinguished by the value of SBPCD_ISSUE and the driver's name),
* and a common sbpcd.h file.
* Bettered the "ReadCapacity error" problem with old CR-52x drives (the
* drives sometimes need a manual "eject/insert" before work): just
* reset the drive and do again. Needs lots of resets here and sometimes
* that does not cure, so this can't be the solution.
*
* 2.1 Found bug with multisession CDs (accessing frame 16).
* "read audio" works now with address type CDROM_MSF, too.
* Bigger audio frame buffer: allows reading max. 4 frames at time; this
* gives a significant speedup, but reading more than one frame at once
* gives missing chunks at each single frame boundary.
*
* 2.2 Kernel interface cleanups: timers, init, setup, media check.
*
* 2.3 Let "door lock" and "eject" live together.
* Implemented "close tray" (done automatically during open).
*
* 2.4 Use different names for device registering.
*
* 2.5 Added "#if EJECT" code (default: enabled) to automatically eject
* the tray during last call to "sbpcd_release".
* Added "#if JUKEBOX" code (default: disable