import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / Documentation / cdrom / aztcd
1 $Id: README.aztcd,v 2.60 1997/11/29 09:51:25 root Exp root $
2           Readme-File /usr/src/Documentation/cdrom/aztcd
3                                 for 
4              AZTECH CD-ROM CDA268-01A, ORCHID CD-3110,
5       OKANO/WEARNES CDD110, CONRAD TXC, CyCDROM CR520, CR540
6                            CD-ROM Drives 
7                        Version 2.6 and newer
8                    (for other drives see 6.-8.)
9
10 NOTE: THIS DRIVER WILL WORK WITH THE CD-ROM DRIVES LISTED, WHICH HAVE
11       A PROPRIETARY INTERFACE (implemented on a sound card or on an
12       ISA-AT-bus card). 
13       IT WILL DEFINITELY NOT WORK WITH CD-ROM DRIVES WITH *IDE*-INTERFACE,
14       such as the Aztech CDA269-031SE !!! (The only known exceptions are
15       'faked' IDE drives like the CyCDROM CR520ie which work with aztcd
16       under certain conditions, see 7.). IF YOU'RE USING A CD-ROM DRIVE
17       WITH IDE-INTERFACE, SOMETIMES ALSO CALLED ATAPI-COMPATIBLE, PLEASE 
18       USE THE ide-cd.c DRIVER, WRITTEN BY MARK LORD AND SCOTT SNYDER !
19       THE STANDARD-KERNEL 1.2.x NOW ALSO SUPPORTS IDE-CDROM-DRIVES, SEE THE
20       HARDDISK (!) SECTION OF make config, WHEN COMPILING A NEW KERNEL!!!
21 ----------------------------------------------------------------------------
22
23 Contents of this file:
24                          1.  NOTE
25                          2.  INSTALLATION
26                          3.  CONFIGURING YOUR KERNEL
27                          4.  RECOMPILING YOUR KERNEL
28                          4.1   AZTCD AS A RUN-TIME LOADABLE MODULE
29                          4.2   CDROM CONNECTED TO A SOUNDCARD
30                          5.  KNOWN PROBLEMS, FUTURE DEVELOPMENTS
31                          5.1   MULTISESSION SUPPORT
32                          5.2   STATUS RECOGNITION
33                          5.3   DOSEMU's CDROM SUPPORT
34                          6.  BUG REPORTS
35                          7.  OTHER DRIVES
36                          8.  IF YOU DON'T SUCCEED ... DEBUGGING  
37                          9.  TECHNICAL HISTORY OF THE DRIVER
38                         10.  ACKNOWLEDGMENTS
39                         11.  PROGRAMMING ADD ONS: CDPLAY.C
40                         APPENDIX: Source code of cdplay.c
41 ----------------------------------------------------------------------------
42
43 1. NOTE 
44 This software has been successfully in alpha and beta test and is part of
45 the standard kernel since kernel 1.1.8x since December 1994. It works with
46 AZTECH CDA268-01A, ORCHID CDS-3110, ORCHID/WEARNES CDD110 and CONRAD TXC 
47 (Nr.99 31 23 -series 04) and has proven to be stable with kernel 
48 versions 1.0.9 and newer. But with any software there still may be bugs in it. 
49 So if you encounter problems, you are invited to help us improve this software. 
50 Please send me a detailed bug report (see chapter BUG REPORTS). You are also 
51 invited in helping us to increase the number of drives, which are supported.
52
53 Please read the README-files carefully and always keep a backup copy of your 
54 old kernel, in order to reboot if something goes wrong!
55
56 2. INSTALLATION
57 The driver consists of a header file 'aztcd.h', which normally should reside 
58 in /usr/src/linux/drivers/cdrom and the source code 'aztcd.c', which normally 
59 resides in the same place. It uses /dev/aztcd (/dev/aztcd0 in some distri-
60 butions), which must be a valid block device with major number 29 and reside 
61 in directory /dev. To mount a CD-ROM, your kernel needs to have the ISO9660-
62 filesystem support included.
63
64 PLEASE NOTE: aztcd.c has been developed in parallel to the linux kernel,
65 which had and is having many major and minor changes which are not backward
66 compatible. Quite definitely aztcd.c version 1.80 and newer will NOT work
67 in kernels older than 1.3.33. So please always use the most recent version
68 of aztcd.c with the appropriate linux-kernel.
69
70 3.  CONFIGURING YOUR KERNEL
71 If your kernel is already configured for using the AZTECH driver you will
72 see the following message while Linux boots:
73     Aztech CD-ROM Init: DriverVersion=<version number> BaseAddress=<baseaddress>
74     Aztech CD-ROM Init: FirmwareVersion=<firmware version id of your I/O-card>>>
75     Aztech CD-ROM Init: <drive type> detected
76     Aztech CD-ROM Init: End
77 If the message looks different and you are sure to have a supported drive,
78 it may have a different base address. The Aztech driver does look for the 
79 CD-ROM drive at the base address specified in aztcd.h at compile time. This 
80 address can be overwritten by boot parameter aztcd=....You should reboot and 
81 start Linux with boot parameter aztcd=<base address>, e.g. aztcd=0x320. If 
82 you do not know the base address, start your PC with DOS and look at the boot 
83 message of your CD-ROM's DOS driver. If that still does not help, use boot
84 parameter aztcd=<base address>,0x79 , this tells aztcd to try a little harder.
85 aztcd may be configured to use autoprobing the base address by recompiling
86 it (see chapter 4.).
87
88 If the message looks correct, as user 'root' you should be able to mount the 
89 drive by
90           mount -t iso9660 -r /dev/aztcd0 /mnt
91 and use it as any other filesystem. (If this does not work, check if
92 /dev/aztcd0 and /mnt do exist and create them, if necessary by doing
93       mknod /dev/aztcd0 b 29 0
94       mkdir /mnt                       
95
96 If you still get a different message while Linux boots or when you get the 
97 message, that the ISO9660-filesystem is not supported by your kernel, when
98 you try to mount the CD-ROM drive, you have to recompile your kernel.
99
100 If you do *not* have an Aztech/Orchid/Okano/Wearnes/TXC drive and want to 
101 bypass drive detection during Linux boot up, start with boot parameter aztcd=0.
102
103 Most distributions nowadays do contain a boot disk image containing aztcd.
104 Please note, that this driver will not work with IDE/ATAPI drives! With these 
105 you must use ide-cd.c instead.
106
107 4. RECOMPILING YOUR KERNEL
108 If your kernel is not yet configured for the AZTECH driver and the ISO9660-
109 filesystem, you have to recompile your kernel: 
110
111 - Edit aztcd.h to set the I/O-address to your I/O-Base address (AZT_BASE_ADDR), 
112   the driver does not use interrupts or DMA, so if you are using an AZTECH
113   CD268, an ORCHID CD-3110 or ORCHID/WEARNES CDD110 that's the only item you 
114   have to set up. If you have a soundcard, read chapter 4.2.
115   Users of other drives should read chapter OTHER DRIVES of this file.
116   You also can configure that address by kernel boot parameter aztcd=... 
117 - aztcd may be configured to use autoprobing the base address by setting
118   AZT_BASE_ADDR to '-1'. In that case aztcd probes the addresses listed 
119   under AZT_BASE_AUTO. But please remember, that autoprobing always may 
120   incorrectly influence other hardware components too!
121 - There are some other points, which may be configured, e.g. auto-eject the
122   CD when unmounting a drive, tray locking etc., see aztcd.h for details.
123 - If you're using a linux kernel version prior to 2.1.0, in aztcd.h
124   uncomment the line '#define AZT_KERNEL_PRIOR_2_1'
125 - Build a new kernel, configure it for 'Aztech/Orchid/Okano/Wearnes support' 
126   (if you want aztcd to be part of the kernel). Do not configure it for
127   'Aztech... support', if you want to use aztcd as a run time loadable module. 
128   But in any case you must have the ISO9660-filesystem included in your
129   kernel.
130 - Activate the new kernel, normally this is done by running LILO (don't for-
131   get to configure it before and to keep a copy of your old kernel in case
132   something goes wrong!).
133 - Reboot
134 - If you've included aztcd in your kernel, you now should see during boot 
135   some messages like
136     Aztech CD-ROM Init: DriverVersion=<version number> BaseAddress=<baseaddress>
137     Aztech CD-ROM Init: FirmwareVersion=<firmware version id of your I/O-card>
138     Aztech CD-ROM Init: <drive type> detected
139     Aztech CD-ROM Init: End
140 - If you have not included aztcd in your kernel, but want to load aztcd as a 
141   run time loadable module see 4.1. 
142 - If the message looks correct, as user 'root' you should be able to mount 
143   the drive by
144           mount -t iso9660 -r /dev/aztcd0 /mnt
145   and use it as any other filesystem. (If this does not work, check if
146   /dev/aztcd0 and /mnt do exist and create them, if necessary by doing
147       mknod /dev/aztcd0 b 29 0
148       mkdir /mnt                       
149 - If this still does not help, see chapters OTHER DRIVES and DEBUGGING.
150
151 4.1 AZTCD AS A RUN-TIME LOADABLE MODULE
152 If you do not need aztcd permanently, you can also load and remove the driver
153 during runtime via insmod and rmmod. To build aztcd as a loadable module you 
154 must configure your kernel for AZTECH module support (answer 'm' when con-
155 figuring the kernel). Anyhow, you may run into problems, if the version of 
156 your boot kernel is not the same than the source kernel version, from which 
157 you create the modules. So rebuild your kernel, if necessary. 
158
159 Now edit the base address of your AZTECH interface card in
160 /usr/src/linux/drivers/cdrom/aztcd.h to the appropriate value. 
161 aztcd may be configured to use autoprobing the base address by setting
162 AZT_BASE_ADDR to '-1'. In that case aztcd probes the addresses listed 
163 under AZT_BASE_AUTO. But please remember, that autoprobing always may 
164 incorrectly influence other hardware components too!
165 There are also some special features which may be configured, e.g. 
166 auto-eject a CD when unmounting the drive etc; see aztcd.h for details. 
167 Then change to /usr/src/linux and do a 
168                     make modules  
169                     make modules_install
170 After that you can run-time load the driver via
171                     insmod /lib/modules/X.X.X/misc/aztcd.o
172 and remove it via   rmmod  aztcd.
173 If you did not set the correct base address in aztcd.h, you can also supply the
174 base address when loading the driver via
175                     insmod /lib/modules/X.X.X/misc/aztcd.o aztcd=<base address>
176 Again specifying aztcd=-1 will cause autoprobing.
177 If you do not have the iso9660-filesystem in your boot kernel, you also have
178 to load it before you can mount the CDROM:
179                     insmod /lib/modules/X.X.X/fs/isofs.o
180 The mount procedure works as described in 4. above.
181 (In all commands 'X.X.X' is the current linux kernel version number. For details
182 see file modules.txt in /usr/src/linux/Documentation)
183
184 4.2 CDROM CONNECTED TO A SOUNDCARD
185 Most soundcards do have a bus interface to the CDROM-drive. In many cases
186 this soundcard needs to be configured, before the CDROM can be used. This
187 configuration procedure consists of writing some kind of initialization
188 data to the soundcard registers. The AZTECH-CDROM driver in the moment does
189 only support one type of soundcard (SoundWave32). Users of other soundcards
190 should try to boot DOS first and let their DOS drivers initialize the
191 soundcard and CDROM, then warm boot (or use loadlin) their PC to start
192 Linux.
193 Support for the CDROM-interface of SoundWave32-soundcards is directly
194 implemented in the AZTECH driver. Please edit linux/drivers/cdrom/aztdc.h,
195 uncomment line '#define AZT_SW32' and set the appropriate value for
196 AZT_BASE_ADDR and AZT_SW32_BASE_ADDR. This support was tested with an Orchid
197 CDS-3110 connected to a SoundWave32.
198 If you want your soundcard to be supported, find out, how it needs to be
199 configured and mail me (see 6.) the appropriate information. 
200
201 5. KNOWN PROBLEMS, FUTURE DEVELOPMENTS
202 5.1 MULTISESSION SUPPORT
203 Multisession support for CD's still is a myth. I implemented and tested a basic
204 support for multisession and XA CDs, but I still have not enough CDs and appli-
205 cations to test it rigorously. So if you'd like to help me, please contact me
206 (Email address see below). As of version 1.4 and newer you can enable the 
207 multisession support in aztcd.h by setting AZT_MULTISESSION to 1. Doing so 
208 will cause the ISO9660-filesystem to deal with multisession CDs, ie. redirect 
209 requests to the Table of Contents (TOC) information from the last session, 
210 which contains the info of all previous sessions etc.. If you do set 
211 AZT_MULTISESSION to 0, you can use multisession CDs anyway. In that case the 
212 drive's firmware will do automatic redirection. For the ISO9660-filesystem any 
213 multisession CD  will then look like a 'normal' single session CD. But never-
214 theless the data of all sessions are viewable and accessible. So with practical-
215 ly all real world applications you won't notice the difference. But as future
216 applications may make use of advanced multisession features, I've started to
217 implement the interface for the ISO9660 multisession interface via ioctl
218 CDROMMULTISESSION.
219
220 5.2 STATUS RECOGNITION
221 The drive status recognition does not work correctly in all cases. Changing
222 a disk or having the door open, when a drive is already mounted, is detected 
223 by the Aztech driver itself, but nevertheless causes multiple read attempts
224 by the different layers of the ISO9660-filesystem driver, which finally timeout,
225 so you have to wait quite a little... But isn't it bad style to change a disk 
226 in a mounted drive, anyhow ?!
227
228 The driver uses busy wait in most cases for the drive handshake (macros
229 STEN_LOW and DTEN_LOW). I tested with a 486/DX2 at 66MHz and a Pentium at
230 60MHz and 90MHz. Whenever you use a much faster machine you are likely to get 
231 timeout messages. In that case edit aztcd.h and increase the timeout value 
232 AZT_TIMEOUT. 
233
234 For some 'slow' drive commands I implemented waiting with a timer waitqueue
235 (macro STEN_LOW_WAIT). If you get this timeout message, you may also edit
236 aztcd.h and increase the timeout value AZT_STATUS_DELAY. The waitqueue has
237 shown to be a little critical. If you get kernel panic messages, edit aztcd.c
238 and substitute STEN_LOW_WAIT by STEN_LOW. Busy waiting with STEN_LOW is more
239 stable, but also causes CPU overhead.
240
241 5.3 DOSEMU's CD-ROM SUPPORT
242 With release 1.20 aztcd was modified to allow access to CD-ROMS when running
243 under dosemu-0.60.0 aztcd-versions before 1.20 are most likely to crash
244 Linux, when a CD-ROM is accessed under dosemu. This problem has partly been
245 fixed, but still when accessing a directory for the first time the system
246 might hang for some 30sec. So be patient, when using dosemu's CD-ROM support
247 in combination with aztcd :-) ! 
248 This problem has now (July 1995) been fixed by a modification to dosemu's
249 CD-ROM driver. The new version came with dosemu-0.60.2, see dosemu's
250 README.CDROM.
251
252 6. BUG REPORTS
253 Please send detailed bug reports and bug fixes via EMail to
254
255         Werner.Zimmermann@fht-esslingen.de
256
257 Please include a description of your CD-ROM drive type and interface card, 
258 the exact firmware message during Linux bootup, the version number of the 
259 AZTECH-CDROM-driver and the Linux kernel version. Also a description of your 
260 system's other hardware could be of interest, especially microprocessor type, 
261 clock frequency, other interface cards such as soundcards, ethernet adapter, 
262 game cards etc..
263
264 I will try to collect the reports and make the necessary modifications from 
265 time to time. I may also come back to you directly with some bug fixes and 
266 ask you to do further testing and debugging.
267
268 Editors of CD-ROMs are invited to send a 'cooperation' copy of their
269 CD-ROMs to the volunteers, who provided the CD-ROM support for Linux. My
270 snail mail address for such 'stuff' is
271            Prof. Dr. W. Zimmermann
272            Fachhochschule fuer Technik Esslingen
273            Fachbereich IT
274            Flandernstrasse 101
275            D-73732 Esslingen
276            Germany
277
278
279 7. OTHER DRIVES
280 The following drives ORCHID CDS3110, OKANO CDD110, WEARNES CDD110 and Conrad
281 TXC Nr. 993123-series 04 nearly look the same as AZTECH CDA268-01A, especially 
282 they seem to use the same command codes. So it was quite simple to make the 
283 AZTECH driver work with these drives. 
284
285 Unfortunately I do not have any of these drives available, so I couldn't test
286 it myself. In some installations, it seems necessary to initialize the drive 
287 with the DOS driver before (especially if combined with a sound card) and then 
288 do a warm boot (CTRL-ALT-RESET) or start Linux from DOS, e.g. with 'loadlin'.
289
290 If you do not succeed, read chapter DEBUGGING. Thanks in advance!
291
292 Sorry for the inconvenience, but it is difficult to develop for hardware, 
293 which you don't have available for testing. So if you like, please help us.
294
295 If you do have a CyCDROM CR520ie thanks to Hilmar Berger's help your chances
296 are good, that it will work with aztcd. The CR520ie is sold as an IDE-drive
297 and really is connected to the IDE interface (primary at 0x1F0 or secondary
298 at 0x170, configured as slave, not as master). Nevertheless it is not ATAPI
299 compatible but still uses Aztech's command codes.
300
301
302 8. DEBUGGING : IF YOU DON'T SUCCEED, TRY THE FOLLOWING
303 -reread the complete README file
304 -make sure, that your drive is hardware configured for 
305     transfer mode: polled
306     IRQ:           not used
307     DMA:           not used
308     Base Address:  something like 300, 320 ...
309  You can check this, when you start the DOS driver, which came with your
310  drive. By appropriately configuring the drive and the DOS driver you can
311  check, whether your drive does operate in this mode correctly under DOS. If
312  it does not operate under DOS, it won't under Linux.
313  If your drive's base address is something like 0x170 or 0x1F0 (and it is
314  not a CyCDROM CR520ie or CR 940ie) you most likely are having an IDE/ATAPI-
315  compatible drive, which is not supported by aztcd.c, use ide-cd.c instead.
316  Make sure the Base Address is configured correctly in aztcd.h, also make
317  sure, that /dev/aztcd0 exists with the correct major number (compare it with
318  the entry in file /usr/include/linux/major.h for the Aztech drive). 
319 -insert a CD-ROM and close the tray
320 -cold boot your PC (i.e. via the power on switch or the reset button)
321 -if you start Linux via DOS, e.g. using loadlin, make sure, that the DOS
322  driver for the CD-ROM drive is not loaded (comment out the calling lines 
323  in DOS' config.sys!)
324 -look for the aztcd: init message during Linux init and note them exactly
325 -log in as root and do a mount -t iso9660 /dev/aztcd0 /mnt
326 -if you don't succeed in the first time, try several times. Try also to open
327  and close the tray, then mount again. Please note carefully all commands
328  you typed in and the aztcd-messages, which you get.
329 -if you get an 'Aztech CD-ROM init: aborted' message, read the remarks about
330  the version string below.
331
332 If this does not help, do the same with the following differences 
333 -start DOS before; make now sure, that the DOS driver for the CD-ROM is 
334  loaded under DOS (i.e. uncomment it again in config.sys)
335 -warm boot your PC (i.e. via CTRL-ALT-DEL)
336  if you have it, you can also start via loadlin (try both).
337  ...
338  Again note all commands and the aztcd-messages.
339
340 If you see STEN_LOW or STEN_LOW_WAIT error messages, increase the timeout
341 values.
342
343 If this still does not help, 
344 -look in aztcd.c for the lines  #if 0
345                                 #define AZT_TEST1
346                                 ...
347                                 #endif
348  and substitute '#if 0' by '#if 1'.
349 -recompile your kernel and repeat the above two procedures. You will now get 
350  a bundle of debugging messages from the driver. Again note your commands
351  and the appropriate messages. If you have syslogd running, these messages
352  may also be found in syslogd's kernel log file. Nevertheless in some
353  installations syslogd does not yet run, when init() is called, thus look for
354  the aztcd-messages during init, before the login-prompt appears.
355  Then look in aztcd.c, to find out, what happened. The normal calling sequence 
356  is: aztcd_init() during Linux bootup procedure init()
357  after doing a 'mount -t iso9660 /dev/aztcd0 /mnt' the normal calling sequence is
358      aztcd_open()    -> Status 2c after cold reboot with CDROM or audio CD inserted
359                      -> Status 8  after warm reboot with CDROM inserted          
360                      -> Status 2e after cold reboot with no disk, closed tray
361                      -> Status 6e after cold reboot, mount with door open
362      aztUpdateToc()
363      aztGetDiskInfo()
364      aztGetQChannelInfo()   repeated several times
365      aztGetToc()
366      aztGetQChannelInfo()   repeated several times
367      a list of track information
368      do_aztcd_request()  }  
369      azt_transfer()    } repeated several times
370      azt_poll          }
371  Check, if there is a difference in the calling sequence or the status flags!
372  
373  There are a lot of other messages, eg. the ACMD-command code (defined in
374  aztcd.h), status info from the getAztStatus-command and the state sequence of
375  the finite state machine in azt_poll(). The most important are the status
376  messages, look how they are defined and try to understand, if they make
377  sense in the context where they appear. With a CD-ROM inserted the status 
378  should always be 8, except in aztcd_open(). Try to open the tray, insert an
379  audio disk, insert no disk or reinsert the CD-ROM and check, if the status
380  bits change accordingly. The status bits are the most likely point, where 
381  the drive manufacturers may implement changes.
382             
383 If you still don't succeed, a good point to start is to look in aztcd.c in 
384 function aztcd_init, where the drive should be detected during init. Do the
385 following:
386 -reboot the system with boot parameter 'aztcd=<your base address>,0x79'. With
387  parameter 0x79 most of the drive version detection is bypassed. After that 
388  you should see the complete version string including leading and trailing 
389  blanks during init. 
390  Now adapt the statement
391       if ((result[1]=='A')&&(result[2]=='Z' ...)
392  in aztcd_init() to exactly match the first 3 or 4 letters you have seen.
393 -Another point is the 'smart' card detection feature in aztcd_init(). Normally
394  the CD-ROM drive is ready, when aztcd_init is trying to read the version
395  string and a time consuming ACMD_SOFT_RESET command can be avoided. This is
396  detected by looking, if AFL_OP_OK can be read correctly. If the CD-ROM drive 
397  hangs in some unknown state, e.g. because of an error before a warm start or 
398  because you first operated under DOS, even the version string may be correct, 
399  but the following commands will not. Then change the code in such a way, 
400  that the ACMD_SOFT_RESET is issued in any case, by substituting the
401  if-statement 'if ( ...=AFL_OP_OK)' by 'if (1)'.
402
403 If you succeed, please mail me the exact version string of your drive and
404 the code modifications, you have made together with a short explanation.
405 If you don't succeed, you may mail me the output of the debugging messages.
406 But remember, they are only useful, if they are exact and complete and you
407 describe in detail your hardware setup and what you did (cold/warm reboot,
408 with/without DOS, DOS-driver started/not started, which Linux-commands etc.)
409
410
411 9. TECHNICAL HISTORY OF THE DRIVER
412 The AZTECH-Driver is a rework of the Mitsumi-Driver. Four major items had to
413 be reworked:
414
415 a) The Mitsumi drive does issue complete status information acknowledging
416 each command, the Aztech drive does only signal that the command was
417 processed. So whenever the complete status information is needed, an extra
418 ACMD_GET_STATUS command is issued. The handshake procedure for the drive
419 can be found in the functions aztSendCmd(), sendAztCmd() and getAztStatus().
420
421 b) The Aztech Drive does not have a ACMD_GET_DISK_INFO command, so the
422 necessary info about the number of tracks (firstTrack, lastTrack), disk
423 length etc. has to be read from the TOC in the lead in track (see function
424 aztGetDiskInfo()).
425
426 c) Whenever data is read from the drive, the Mitsumi drive is started with a
427 command to read an indefinite (0xffffff) number of sectors. When the appropriate 
428 number of sectors is read, the drive is stopped by a ACDM_STOP command. This
429 does not work with the Aztech drive. I did not find a way to stop it. The
430 stop and pause commands do only work in AUDIO mode but not in DATA mode.
431 Therefore I had to modify the 'finite state machine' in function azt_poll to
432 only read a certain number of sectors and then start a new read on demand. As I 
433 have not completely understood, how the buffer/caching scheme of the Mitsumi 
434 driver was implemented, I am not sure, if I have covered all cases correctly, 
435 whenever you get timeout messages, the bug is most likely to be in that
436 function azt_poll() around switch(cmd) .... case ACD_S_DATA. 
437
438 d) I did not get information about changing drive mode. So I doubt, that the
439 code around function azt_poll() case AZT_S_MODE does work. In my test I have
440 not been able to switch to reading in raw mode. For reading raw mode, Aztech
441 uses a different command than for cooked mode, which I only have implemen-
442 ted in the ioctl-section but not in the section which is used by the ISO9660. 
443
444 The driver was developed on an AST PC with Intel 486/DX2, 8MB RAM, 340MB IDE 
445 hard disk and on an AST PC with Intel Pentium 60MHz, 16MB RAM, 520MB IDE 
446 running Linux kernel version 1.0.9 from the LST 1.8 Distribution. The kernel 
447 was compiled with gcc.2.5.8. My CD-ROM drive is an Aztech CDA268-01A. My
448 drive says, that it has Firmware Version AZT26801A1.3. It came with an ISA-bus
449 interface card and works with polled I/O without DMA and without interrupts.
450 The code for all other drives was 'remote' tested and debugged by a number of 
451 volunteers on the Internet.
452
453 Points, where I feel that possible problems might be and all points where I 
454 did not completely understand the drive's behaviour or trust my own code are 
455 marked with /*???*/ in the source code. There are also some parts in the 
456 Mitsumi driver, where I did not completely understand their code.
457
458
459 10. ACKNOWLEDGMENTS
460 Without the help of P.Bush, Aztech, who delivered technical information
461 about the Aztech Drive and without the help of E.Moenkeberg, GWDG, who did a
462 great job in analyzing the command structure of various CD-ROM drives, this
463 work would not have been possible. E.Moenkeberg was also a great help in 
464 making the software 'kernel ready' and in answering many of the CDROM-related 
465 questions in the newsgroups. He really is *the* Linux CD-ROM guru. Thanks 
466 also to all the guys on the Internet, who collected valuable technical 
467 information about CDROMs. 
468
469 Joe Nardone (joe@access.digex.net) was a patient tester even for my first
470 trial, which was more than slow, and made suggestions for code improvement.
471 Especially the 'finite state machine' azt_poll() was rewritten by Joe to get
472 clean C code and avoid the ugly 'gotos', which I copied from mcd.c.
473
474 Robby Schirmer (schirmer@fmi.uni-passau.de) tested the audio stuff (ioctls) 
475 and suggested a lot of patches for them.
476
477 Joseph Piskor and Peter Nugent were the first users with the ORCHID CD3110
478 and also were very patient with the problems which occurred.
479
480 Reinhard Max delivered the information for the CDROM-interface of the
481 SoundWave32 soundcards.
482
483 Jochen Kunz and Olaf Kaluza delivered the information for supporting Conrad's 
484 TXC drive.
485
486 Hilmar Berger delivered the patches for supporting CyCDROM CR520ie.
487
488 Anybody, who is interested in these items should have a look at 'ftp.gwdg.de',
489 directory 'pub/linux/cdrom' and at 'ftp.cdrom.com', directory 'pub/cdrom'.
490
491 11. PROGRAMMING ADD ONs: cdplay.c
492 You can use the ioctl-functions included in aztcd.c in your own programs. As
493 an example on how to do this, you will find a tiny CD Player for audio CDs 
494 named 'cdplay.c'. It allows you to play audio CDs. You can play a specified 
495 track, pause and resume or skip tracks forward and backwards. If you quit the 
496 program without stopping the  drive, playing is continued. You can also 
497 (mis)use cdplay to read and hexdump data disks. You can find the code in the 
498 APPENDIX of this file, which you should cut out with an editor and store in a 
499 separate file 'cdplay.c'. To compile it and make it executable, do
500   gcc -s -Wall -O2 -L/usr/lib cdplay.c -o /usr/local/bin/cdplay # compiles it
501   chmod +755 /usr/local/bin/cdplay                              # makes it executable
502   ln -s /dev/aztcd0 /dev/cdrom                                  # creates a link
503    (for /usr/lib substitute the top level directory, where your include files 
504     reside,  and for /usr/local/bin the directory, where you want the executable 
505     binary to reside )
506
507 You have to set the correct permissions for cdplay *and* for /dev/mcd0 or
508 /dev/aztcd0 in order to use it. Remember, that you should not have /dev/cdrom 
509 mounted, when you're playing audio CDs. 
510
511 This program is just a hack for testing the ioctl-functions in aztcd.c. I will 
512 not maintain it, so if you run into problems, discard it or have a look into 
513 the source code 'cdplay.c'. The program does only contain a minimum of user 
514 protection and input error detection. If you use the commands in the wrong 
515 order or if you try to read a CD at wrong addresses, you may get error messages
516 or even hang your machine. If you get STEN_LOW, STEN_LOW_WAIT or segment violation 
517 error messages when using cdplay, after that, the system might not be stable 
518 any more, so you'd better reboot. As the ioctl-functions run in kernel mode,
519 most normal Linux-multitasking protection features do not work. By using
520 uninitialized 'wild' pointers etc., it is easy to write to other users' data 
521 and program areas, destroy kernel tables etc.. So if you experiment with ioctls
522 as always when you are doing systems programming and kernel hacking, you
523 should have a backup copy of your system in a safe place (and you also
524 should try restoring from a backup copy first)!
525
526 A reworked and improved version called 'cdtester.c', which has yet more
527 features for testing CDROM-drives can be found in
528 /usr/src/linux/Documentation/cdrom/sbpcd, written by E.Moenkeberg.
529
530 Werner Zimmermann
531 Fachhochschule fuer Technik Esslingen
532 (EMail: Werner.Zimmermann@fht-esslingen.de)
533 October, 1997
534
535 ---------------------------------------------------------------------------
536 APPENDIX: Source code of cdplay.c
537
538 /* Tiny Audio CD Player
539
540    Copyright 1994, 1995, 1996 Werner Zimmermann (Werner.Zimmermann@fht-esslingen.de)
541
542 This program originally was written to test the audio functions of the
543 AZTECH.CDROM-driver, but it should work with every CD-ROM drive. Before 
544 using it, you should set a symlink from /dev/cdrom to your real CDROM
545 device.
546
547 The GNU General Public License applies to this program.
548
549 History:  V0.1  W.Zimmermann: First release. Nov. 8, 1994
550           V0.2  W.Zimmermann: Enhanced functionality. Nov. 9, 1994
551           V0.3  W.Zimmermann: Additional functions. Nov. 28, 1994          
552           V0.4  W.Zimmermann: fixed some bugs. Dec. 17, 1994
553           V0.5  W.Zimmermann: clean 'scanf' commands without compiler warnings
554                               Jan. 6, 1995
555           V0.6  W.Zimmermann: volume control (still experimental). Jan. 24, 1995
556           V0.7  W.Zimmermann: read raw modified. July 26, 95
557 */
558
559 #include <stdio.h>
560 #include <ctype.h>
561 #include <sys/ioctl.h>
562 #include <sys/types.h>
563 #include <fcntl.h>
564 #include <unistd.h>
565 #include <linux/cdrom.h>
566 #include <linux/../../drivers/cdrom/aztcd.h>
567
568 void help(void)
569 { printf("Available Commands:  STOP         s      EJECT/CLOSE  e       QUIT         q\n");
570   printf("                     PLAY TRACK   t      PAUSE        p       RESUME       r\n");
571   printf("                     NEXT TRACK   n      REPEAT LAST  l       HELP         h\n");
572   printf("                     SUB CHANNEL  c      TRACK INFO   i       PLAY AT      a\n");
573   printf("                     READ         d      READ RAW     w       VOLUME       v\n");
574 }
575
576 int main(void)
577 { int handle;
578   unsigned char command=' ', ini=0, first=1, last=1;
579   unsigned int cmd, i,j,k, arg1,arg2,arg3;
580   struct cdrom_ti       ti;
581   struct cdrom_tochdr   tocHdr;
582   struct cdrom_subchnl  subchnl;
583   struct cdrom_tocentry entry;
584   struct cdrom_msf      msf;
585   union  { struct cdrom_msf msf;
586            unsigned char buf[CD_FRAMESIZE_RAW];
587          } azt;
588   struct cdrom_volctrl  volctrl;
589
590   printf("\nMini-Audio CD-Player V0.72   (C) 1994,1995,1996  W.Zimmermann\n");
591   handle=open("/dev/cdrom",O_RDWR);
592   ioctl(handle,CDROMRESUME);
593   
594   if (handle<=0) 
595     { printf("Drive Error: already playing, no audio disk, door open\n");
596       printf("             or no permission (you must be ROOT in order to use this program)\n");
597     }
598   else
599     { help();
600       while (1)
601         { printf("Type command (h = help):  ");
602           scanf("%s",&command); 
603           switch (command)
604             { case 'e':   cmd=CDROMEJECT;
605                           ioctl(handle,cmd);
606                           break;  
607               case 'p':   if (!ini)
608                              { printf("Command not allowed - play track first\n");
609                              }
610                           else
611                              { cmd=CDROMPAUSE;
612                                if (ioctl(handle,cmd)) printf("Drive Error\n");
613                              }
614                           break;
615               case 'r':   if (!ini)
616                              { printf("Command not allowed - play track first\n");
617                              }
618                           else
619                              { cmd=CDROMRESUME;
620                                if (ioctl(handle,cmd)) printf("Drive Error\n");
621                              }
622                           break;
623               case 's':   cmd=CDROMPAUSE;
624                           if (ioctl(handle,cmd)) printf("Drive error or already stopped\n");
625                           cmd=CDROMSTOP;
626                           if (ioctl(handle,cmd)) printf("Drive error\n");
627                           break;
628               case 't':   cmd=CDROMREADTOCHDR;
629                           if (ioctl(handle,cmd,&tocHdr)) printf("Drive Error\n");
630                           first=tocHdr.cdth_trk0;
631                           last= tocHdr.cdth_trk1;
632                           if ((first==0)||(first>last))
633                             { printf ("--could not read TOC\n");
634                             }
635                           else
636                             { printf("--first track: %d   --last track: %d   --enter track number: ",first,last);
637                               cmd=CDROMPLAYTRKIND;
638                               scanf("%i",&arg1);
639                               ti.cdti_trk0=arg1;
640                               if (ti.cdti_trk0<first) ti.cdti_trk0=first;
641                               if (ti.cdti_trk0>last)  ti.cdti_trk0=last;
642                               ti.cdti_ind0=0;
643                               ti.cdti_trk1=last;
644                               ti.cdti_ind1=0;
645                               if (ioctl(handle,cmd,&ti)) printf("Drive Error\n");
646                               ini=1;
647                             } 
648                           break;
649               case 'n':   if (!ini++) 
650                             { if (ioctl(handle,CDROMREADTOCHDR,&tocHdr)) printf("Drive Error\n");
651                               first=tocHdr.cdth_trk0;
652                               last= tocHdr.cdth_trk1;
653                               ti.cdti_trk0=first-1;
654                             }
655                           if ((first==0)||(first>last))
656                             { printf ("--could not read TOC\n");
657                             }
658                           else
659                             { cmd=CDROMPLAYTRKIND;
660                               if (++ti.cdti_trk0 > last)  ti.cdti_trk0=last;
661                               ti.cdti_ind0=0;
662                               ti.cdti_trk1=last;
663                               ti.cdti_ind1=0;
664                               if (ioctl(handle,cmd,&ti)) printf("Drive Error\n");
665                               ini=1;
666                             }
667                           break;
668               case 'l':   if (!ini++)
669                             { if (ioctl(handle,CDROMREADTOCHDR,&tocHdr)) printf("Drive Error\n");
670                               first=tocHdr.cdth_trk0;
671                               last= tocHdr.cdth_trk1;
672                               ti.cdti_trk0=first+1;
673                             }
674                           if ((first==0)||(first>last))
675                             { printf ("--could not read TOC\n");
676                             }
677                           else
678                             { cmd=CDROMPLAYTRKIND;
679                               if (--ti.cdti_trk0 < first) ti.cdti_trk0=first;
680                               ti.cdti_ind0=0;
681                               ti.cdti_trk1=last;
682                               ti.cdti_ind1=0;
683                               if (ioctl(handle,cmd,&ti)) printf("Drive Error\n");
684                               ini=1;
685                             }  
686                           break;
687               case 'c':   subchnl.cdsc_format=CDROM_MSF;
688                           if (ioctl(handle,CDROMSUBCHNL,&subchnl)) 
689                             printf("Drive Error\n");
690                           else
691                             { printf("AudioStatus:%s   Track:%d  Mode:%d   MSF=%d:%d:%d\n", \
692                               subchnl.cdsc_audiostatus==CDROM_AUDIO_PLAY ? "PLAYING":"NOT PLAYING",\
693                               subchnl.cdsc_trk,subchnl.cdsc_adr, \
694                               subchnl.cdsc_absaddr.msf.minute, subchnl.cdsc_absaddr.msf.second, \
695                               subchnl.cdsc_absaddr.msf.frame);
696                             }
697                           break;              
698               case 'i':   if (!ini)
699                             { printf("Command not allowed - play track first\n");
700                             }
701                           else
702                             { cmd=CDROMREADTOCENTRY;
703                               printf("Track No.: ");
704                               scanf("%d",&arg1);
705                               entry.cdte_track=arg1;
706                               if (entry.cdte_track<first) entry.cdte_track=first;
707                               if (entry.cdte_track>last)  entry.cdte_track=last;
708                               entry.cdte_format=CDROM_MSF;
709                               if (ioctl(handle,cmd,&entry)) 
710                                { printf("Drive error or invalid track no.\n");
711                                }
712                               else
713                                { printf("Mode %d Track, starts at %d:%d:%d\n", \
714                                entry.cdte_adr,entry.cdte_addr.msf.minute, \
715                                entry.cdte_addr.msf.second,entry.cdte_addr.msf.frame);
716                                }
717                             }
718                           break;
719               case 'a':   cmd=CDROMPLAYMSF;
720                           printf("Address (min:sec:frame)  ");
721                           scanf("%d:%d:%d",&arg1,&arg2,&arg3);
722                           msf.cdmsf_min0  =arg1;
723                           msf.cdmsf_sec0  =arg2;
724                           msf.cdmsf_frame0=arg3;
725                           if (msf.cdmsf_sec0  > 59) msf.cdmsf_sec0  =59;
726                           if (msf.cdmsf_frame0> 74) msf.cdmsf_frame0=74;
727                           msf.cdmsf_min1=60;
728                           msf.cdmsf_sec1=00;
729                           msf.cdmsf_frame1=00;
730                           if (ioctl(handle,cmd,&msf)) 
731                            { printf("Drive error or invalid address\n");
732                            }
733                           break;
734 #ifdef AZT_PRIVATE_IOCTLS /*not supported by every CDROM driver*/
735               case 'd':   cmd=CDROMREADCOOKED;
736                           printf("Address (min:sec:frame)  ");
737                           scanf("%d:%d:%d",&arg1,&arg2,&arg3);
738                           azt.msf.cdmsf_min0  =arg1;
739                           azt.msf.cdmsf_sec0  =arg2;
740                           azt.msf.cdmsf_frame0=arg3;
741                           if (azt.msf.cdmsf_sec0  > 59) azt.msf.cdmsf_sec0  =59;
742                           if (azt.msf.cdmsf_frame0> 74) azt.msf.cdmsf_frame0=74;
743                           if (ioctl(handle,cmd,&azt.msf)) 
744                            { printf("Drive error, invalid address or unsupported command\n");
745                            }
746                           k=0;
747                           getchar();
748                           for (i=0;i<128;i++)
749                            { printf("%4d:",i*16);
750                              for (j=0;j<16;j++)
751                                { printf("%2x ",azt.buf[i*16+j]);
752                                }
753                              for (j=0;j<16;j++)
754                                { if (isalnum(azt.buf[i*16+j])) 
755                                    printf("%c",azt.buf[i*16+j]);
756                                  else
757                                    printf(".");
758                                }
759                              printf("\n"); 
760                              k++;
761                              if (k>=20)
762                               { printf("press ENTER to continue\n");
763                                 getchar();
764                                 k=0;
765                               }
766                            } 
767                           break;
768               case 'w':   cmd=CDROMREADRAW;
769                           printf("Address (min:sec:frame)  ");
770                           scanf("%d:%d:%d",&arg1,&arg2,&arg3);
771                           azt.msf.cdmsf_min0  =arg1;
772                           azt.msf.cdmsf_sec0  =arg2;
773                           azt.msf.cdmsf_frame0=arg3;                          
774                           if (azt.msf.cdmsf_sec0  > 59) azt.msf.cdmsf_sec0  =59;
775                           if (azt.msf.cdmsf_frame0> 74) azt.msf.cdmsf_frame0=74;
776                           if (ioctl(handle,cmd,&azt)) 
777                            { printf("Drive error, invalid address or unsupported command\n");
778                            }
779                           k=0;
780                           for (i=0;i<147;i++)
781                            { printf("%4d:",i*16);
782                              for (j=0;j<16;j++)
783                                { printf("%2x ",azt.buf[i*16+j]);
784                                }
785                              for (j=0;j<16;j++)
786                                { if (isalnum(azt.buf[i*16+j])) 
787                                    printf("%c",azt.buf[i*16+j]);
788                                  else
789                                    printf(".");
790                                }
791                              printf("\n"); 
792                              k++;
793                              if (k>=20)
794                               { getchar();
795                                 k=0;
796                               }
797                            } 
798                           break;
799 #endif
800               case 'v':   cmd=CDROMVOLCTRL;
801                           printf("--Channel 0 Left  (0-255): ");
802                           scanf("%d",&arg1);
803                           printf("--Channel 1 Right (0-255): ");
804                           scanf("%d",&arg2);
805                           volctrl.channel0=arg1;
806                           volctrl.channel1=arg2;
807                           volctrl.channel2=0;
808                           volctrl.channel3=0;
809                           if (ioctl(handle,cmd,&volctrl)) 
810                            { printf("Drive error or unsupported command\n");
811                            }
812                           break;  
813               case 'q':   if (close(handle)) printf("Drive Error: CLOSE\n");
814                           exit(0);
815               case 'h':   help();
816                           break;
817               default:    printf("unknown command\n");
818                           break;
819             }
820        }
821     }
822   return 0;
823 }