Import 2.1.118
[davej-history.git] / drivers / cdrom / sbpcd.c
blob11b99e645aacea75ac6cd0dba2ea04cef7b1049d
1 /*
2 * sbpcd.c CD-ROM device driver for the whole family of traditional,
3 * non-ATAPI IDE-style Matsushita/Panasonic CR-5xx drives.
4 * Works with SoundBlaster compatible cards and with "no-sound"
5 * interface cards like Lasermate, Panasonic CI-101P, Teac, ...
6 * Also for the Longshine LCS-7260 drive.
7 * Also for the IBM "External ISA CD-Rom" drive.
8 * Also for the CreativeLabs CD200 drive.
9 * Also for the TEAC CD-55A drive.
10 * Also for the ECS-AT "Vertos 100" drive.
11 * Not for Sanyo drives (but for the H94A, sjcd is there...).
12 * Not for any other Funai drives than the CD200 types (sometimes
13 * labelled E2550UA or MK4015 or 2800F).
16 #define VERSION "v4.61 Eberhard Moenkeberg <emoenke@gwdg.de>"
18 /* Copyright (C) 1993, 1994, 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2, or (at your option)
23 * any later version.
25 * You should have received a copy of the GNU General Public License
26 * (for example /usr/src/linux/COPYING); if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * If you change this software, you should mail a .diff file with some
30 * description lines to emoenke@gwdg.de. I want to know about it.
32 * If you are the editor of a Linux CD, you should enable sbpcd.c within
33 * your boot floppy kernel and send me one of your CDs for free.
35 * If you would like to port the driver to an other operating system (f.e.
36 * FreeBSD or NetBSD) or use it as an information source, you shall not be
37 * restricted by the GPL under the following conditions:
38 * a) the source code of your work is freely available
39 * b) my part of the work gets mentioned at all places where your
40 * authorship gets mentioned
41 * c) I receive a copy of your code together with a full installation
42 * package of your operating system for free.
45 * VERSION HISTORY
47 * 0.1 initial release, April/May 93, after mcd.c (Martin Harriss)
49 * 0.2 the "repeat:"-loop in do_sbpcd_request did not check for
50 * end-of-request_queue (resulting in kernel panic).
51 * Flow control seems stable, but throughput is not better.
53 * 0.3 interrupt locking totally eliminated (maybe "inb" and "outb"
54 * are still locking) - 0.2 made keyboard-type-ahead losses.
55 * check_sbpcd_media_change added (to use by isofs/inode.c)
56 * - but it detects almost nothing.
58 * 0.4 use MAJOR 25 definitely.
59 * Almost total re-design to support double-speed drives and
60 * "naked" (no sound) interface cards ("LaserMate" interface type).
61 * Flow control should be exact now.
62 * Don't occupy the SbPro IRQ line (not needed either); will
63 * live together with Hannu Savolainen's sndkit now.
64 * Speeded up data transfer to 150 kB/sec, with help from Kai
65 * Makisara, the "provider" of the "mt" tape utility.
66 * Give "SpinUp" command if necessary.
67 * First steps to support up to 4 drives (but currently only one).
68 * Implemented audio capabilities - workman should work, xcdplayer
69 * gives some problems.
70 * This version is still consuming too much CPU time, and
71 * sleeping still has to be worked on.
72 * During "long" implied seeks, it seems possible that a
73 * ReadStatus command gets ignored. That gives the message
74 * "ResponseStatus timed out" (happens about 6 times here during
75 * a "ls -alR" of the YGGDRASIL LGX-Beta CD). Such a case is
76 * handled without data error, but it should get done better.
78 * 0.5 Free CPU during waits (again with help from Kai Makisara).
79 * Made it work together with the LILO/kernel setup standard.
80 * Included auto-probing code, as suggested by YGGDRASIL.
81 * Formal redesign to add DDI debugging.
82 * There are still flaws in IOCTL (workman with double speed drive).
84 * 1.0 Added support for all drive IDs (0...3, no longer only 0)
85 * and up to 4 drives on one controller.
86 * Added "#define MANY_SESSION" for "old" multi session CDs.
88 * 1.1 Do SpinUp for new drives, too.
89 * Revised for clean compile under "old" kernels (0.99pl9).
91 * 1.2 Found the "workman with double-speed drive" bug: use the driver's
92 * audio_state, not what the drive is reporting with ReadSubQ.
94 * 1.3 Minor cleanups.
95 * Refinements regarding Workman.
97 * 1.4 Read XA disks (PhotoCDs) with "old" drives, too (but only the first
98 * session - no chance to fully access a "multi-session" CD).
99 * This currently still is too slow (50 kB/sec) - but possibly
100 * the old drives won't do it faster.
101 * Implemented "door (un)lock" for new drives (still does not work
102 * as wanted - no lock possible after an unlock).
103 * Added some debugging printout for the UPC/EAN code - but my drives
104 * return only zeroes. Is there no UPC/EAN code written?
106 * 1.5 Laborate with UPC/EAN code (not better yet).
107 * Adapt to kernel 1.1.8 change (have to explicitly include
108 * <linux/string.h> now).
110 * 1.6 Trying to read audio frames as data. Impossible with the current
111 * drive firmware levels, as it seems. Awaiting any hint. ;-)
112 * Changed "door unlock": repeat it until success.
113 * Changed CDROMSTOP routine (stop somewhat "softer" so that Workman
114 * won't get confused).
115 * Added a third interface type: Sequoia S-1000, as used with the SPEA
116 * Media FX sound card. This interface (usable for Sony and Mitsumi
117 * drives, too) needs a special configuration setup and behaves like a
118 * LaserMate type after that. Still experimental - I do not have such
119 * an interface.
120 * Use the "variable BLOCK_SIZE" feature (2048). But it does only work
121 * if you give the mount option "block=2048".
122 * The media_check routine is currently disabled; now that it gets
123 * called as it should I fear it must get synchronized for not to
124 * disturb the normal driver's activity.
126 * 2.0 Version number bumped - two reasons:
127 * - reading audio tracks as data works now with CR-562 and CR-563. We
128 * currently do it by an IOCTL (yet has to get standardized), one frame
129 * at a time; that is pretty slow. But it works.
130 * - we are maintaining now up to 4 interfaces (each up to 4 drives):
131 * did it the easy way - a different MAJOR (25, 26, ...) and a different
132 * copy of the driver (sbpcd.c, sbpcd2.c, sbpcd3.c, sbpcd4.c - only
133 * distinguished by the value of SBPCD_ISSUE and the driver's name),
134 * and a common sbpcd.h file.
135 * Bettered the "ReadCapacity error" problem with old CR-52x drives (the
136 * drives sometimes need a manual "eject/insert" before work): just
137 * reset the drive and do again. Needs lots of resets here and sometimes
138 * that does not cure, so this can't be the solution.
140 * 2.1 Found bug with multisession CDs (accessing frame 16).
141 * "read audio" works now with address type CDROM_MSF, too.
142 * Bigger audio frame buffer: allows reading max. 4 frames at time; this
143 * gives a significant speedup, but reading more than one frame at once
144 * gives missing chunks at each single frame boundary.
146 * 2.2 Kernel interface cleanups: timers, init, setup, media check.
148 * 2.3 Let "door lock" and "eject" live together.
149 * Implemented "close tray" (done automatically during open).
151 * 2.4 Use different names for device registering.
153 * 2.5 Added "#if EJECT" code (default: enabled) to automatically eject
154 * the tray during last call to "sbpcd_release".
155 * Added "#if JUKEBOX" code (default: disabled) to automatically eject
156 * the tray during call to "sbpcd_open" if no disk is in.
157 * Turn on the CD volume of "compatible" sound cards, too; just define
158 * SOUND_BASE (in sbpcd.h) accordingly (default: disabled).
160 * 2.6 Nothing new.
162 * 2.7 Added CDROMEJECT_SW ioctl to set the "EJECT" behavior on the fly:
163 * 0 disables, 1 enables auto-ejecting. Useful to keep the tray in
164 * during shutdown.
166 * 2.8 Added first support (still BETA, I need feedback or a drive) for
167 * the Longshine LCS-7260 drives. They appear as double-speed drives
168 * using the "old" command scheme, extended by tray control and door
169 * lock functions.
170 * Found (and fixed preliminary) a flaw with some multisession CDs: we
171 * have to re-direct not only the accesses to frame 16 (the isofs
172 * routines drive it up to max. 100), but also those to the continuation
173 * (repetition) frames (as far as they exist - currently set fix as
174 * 16..20).
175 * Changed default of the "JUKEBOX" define. If you use this default,
176 * your tray will eject if you try to mount without a disk in. Next
177 * mount command will insert the tray - so, just fill in a disk. ;-)
179 * 2.9 Fulfilled the Longshine LCS-7260 support; with great help and
180 * experiments by Serge Robyns.
181 * First attempts to support the TEAC CD-55A drives; but still not
182 * usable yet.
183 * Implemented the CDROMMULTISESSION ioctl; this is an attempt to handle
184 * multi session CDs more "transparent" (redirection handling has to be
185 * done within the isofs routines, and only for the special purpose of
186 * obtaining the "right" volume descriptor; accesses to the raw device
187 * should not get redirected).
189 * 3.0 Just a "normal" increment, with some provisions to do it better. ;-)
190 * Introduced "#define READ_AUDIO" to specify the maximum number of
191 * audio frames to grab with one request. This defines a buffer size
192 * within kernel space; a value of 0 will reserve no such space and
193 * disable the CDROMREADAUDIO ioctl. A value of 75 enables the reading
194 * of a whole second with one command, but will use a buffer of more
195 * than 172 kB.
196 * Started CD200 support. Drive detection should work, but nothing
197 * more.
199 * 3.1 Working to support the CD200 and the Teac CD-55A drives.
200 * AT-BUS style device numbering no longer used: use SCSI style now.
201 * So, the first "found" device has MINOR 0, regardless of the
202 * jumpered drive ID. This implies modifications to the /dev/sbpcd*
203 * entries for some people, but will help the DAU (german TLA, english:
204 * "newbie", maybe ;-) to install his "first" system from a CD.
206 * 3.2 Still testing with CD200 and CD-55A drives.
208 * 3.3 Working with CD200 support.
210 * 3.4 Auto-probing stops if an address of 0 is seen (to be entered with
211 * the kernel command line).
212 * Made the driver "loadable". If used as a module, "audio copy" is
213 * disabled, and the internal read ahead data buffer has a reduced size
214 * of 4 kB; so, throughput may be reduced a little bit with slow CPUs.
216 * 3.5 Provisions to handle weird photoCDs which have an interrupted
217 * "formatting" immediately after the last frames of some files: simply
218 * never "read ahead" with MultiSession CDs. By this, CPU usage may be
219 * increased with those CDs, and there may be a loss in speed.
220 * Re-structured the messaging system.
221 * The "loadable" version no longer has a limited READ_AUDIO buffer
222 * size.
223 * Removed "MANY_SESSION" handling for "old" multi session CDs.
224 * Added "private" IOCTLs CDROMRESET and CDROMVOLREAD.
225 * Started again to support the TEAC CD-55A drives, now that I found
226 * the money for "my own" drive. ;-)
227 * The TEAC CD-55A support is fairly working now.
228 * I have measured that the drive "delivers" at 600 kB/sec (even with
229 * bigger requests than the drive's 64 kB buffer can satisfy), but
230 * the "real" rate does not exceed 520 kB/sec at the moment.
231 * Caused by the various changes to build in TEAC support, the timed
232 * loops are de-optimized at the moment (less throughput with CR-52x
233 * drives, and the TEAC will give speed only with SBP_BUFFER_FRAMES 64).
235 * 3.6 Fixed TEAC data read problems with SbPro interfaces.
236 * Initial size of the READ_AUDIO buffer is 0. Can get set to any size
237 * during runtime.
239 * 3.7 Introduced MAX_DRIVES for some poor interface cards (seen with TEAC
240 * drives) which allow only one drive (ID 0); this avoids repetitive
241 * detection under IDs 1..3.
242 * Elongated cmd_out_T response waiting; necessary for photo CDs with
243 * a lot of sessions.
244 * Bettered the sbpcd_open() behavior with TEAC drives.
246 * 3.8 Elongated max_latency for CR-56x drives.
248 * 3.9 Finally fixed the long-known SoundScape/SPEA/Sequoia S-1000 interface
249 * configuration bug.
250 * Now Corey, Heiko, Ken, Leo, Vadim/Eric & Werner are invited to copy
251 * the config_spea() routine into their drivers. ;-)
253 * 4.0 No "big step" - normal version increment.
254 * Adapted the benefits from 1.3.33.
255 * Fiddled with CDROMREADAUDIO flaws.
256 * Avoid ReadCapacity command with CD200 drives (the MKE 1.01 version
257 * seems not to support it).
258 * Fulfilled "read audio" for CD200 drives, with help of Pete Heist
259 * (heistp@rpi.edu).
261 * 4.1 Use loglevel KERN_INFO with printk().
262 * Added support for "Vertos 100" drive ("ECS-AT") - it is very similar
263 * to the Longshine LCS-7260. Give feedback if you can - I never saw
264 * such a drive, and I have no specs.
266 * 4.2 Support for Teac 16-bit interface cards. Can't get auto-detected,
267 * so you have to jumper your card to 0x2C0. Still not 100% - come
268 * in contact if you can give qualified feedback.
269 * Use loglevel KERN_NOTICE with printk(). If you get annoyed by a
270 * flood of unwanted messages and the accompanied delay, try to read
271 * my documentation. Especially the Linux CDROM drivers have to do an
272 * important job for the newcomers, so the "distributed" version has
273 * to fit some special needs. Since generations, the flood of messages
274 * is user-configurable (even at runtime), but to get aware of this, one
275 * needs a special mental quality: the ability to read.
277 * 4.3 CD200F does not like to receive a command while the drive is
278 * reading the ToC; still trying to solve it.
279 * Removed some redundant verify_area calls (yes, Heiko Eissfeldt
280 * is visiting all the Linux CDROM drivers ;-).
282 * 4.4 Adapted one idea from tiensivu@pilot.msu.edu's "stripping-down"
283 * experiments: "KLOGD_PAUSE".
284 * Inhibited "play audio" attempts with data CDs. Provisions for a
285 * "data-safe" handling of "mixed" (data plus audio) Cds.
287 * 4.5 Meanwhile Gonzalo Tornaria <tornaria@cmat.edu.uy> (GTL) built a
288 * special end_request routine: we seem to have to take care for not
289 * to have two processes working at the request list. My understanding
290 * was and is that ll_rw_blk should not call do_sbpcd_request as long
291 * as there is still one call active (the first call will care for all
292 * outstanding I/Os, and if a second call happens, that is a bug in
293 * ll_rw_blk.c).
294 * "Check media change" without touching any drive.
296 * 4.6 Use a semaphore to synchronize multi-activity; elaborated by Rob
297 * Riggs <rriggs@tesser.com>. At the moment, we simply block "read"
298 * against "ioctl" and vice versa. This could be refined further, but
299 * I guess with almost no performance increase.
300 * Experiments to speed up the CD-55A; again with help of Rob Riggs
301 * (to be true, he gave both, idea & code. ;-)
303 * 4.61 Ported to Uniform CD-ROM driver by
304 * Heiko Eissfeldt <heiko@colossus.escape.de> with additional
305 * changes by Erik Andersen <andersee@debian.org>
307 * 4.62 Fix a bug where playing audio left the drive in an unusable state.
308 * Heiko Eissfeldt <heiko@colossus.escape.de>
311 * TODO
312 * implement "read all subchannel data" (96 bytes per frame)
314 * special thanks to Kai Makisara (kai.makisara@vtt.fi) for his fine
315 * elaborated speed-up experiments (and the fabulous results!), for
316 * the "push" towards load-free wait loops, and for the extensive mail
317 * thread which brought additional hints and bug fixes.
321 #ifndef SBPCD_ISSUE
322 #define SBPCD_ISSUE 1
323 #endif SBPCD_ISSUE
325 #include <linux/module.h>
327 #include <linux/errno.h>
328 #include <linux/sched.h>
329 #include <linux/mm.h>
330 #include <linux/timer.h>
331 #include <linux/fs.h>
332 #include <linux/kernel.h>
333 #include <linux/cdrom.h>
334 #include <linux/ioport.h>
335 #include <linux/major.h>
336 #include <linux/string.h>
337 #include <linux/vmalloc.h>
338 #include <linux/init.h>
340 #include <asm/system.h>
341 #include <asm/io.h>
342 #include <asm/uaccess.h>
343 #include <stdarg.h>
344 #include <linux/config.h>
345 #include "sbpcd.h"
347 #if !(SBPCD_ISSUE-1)
348 #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
349 #endif
350 #if !(SBPCD_ISSUE-2)
351 #define MAJOR_NR MATSUSHITA_CDROM2_MAJOR /* second driver issue */
352 #endif
353 #if !(SBPCD_ISSUE-3)
354 #define MAJOR_NR MATSUSHITA_CDROM3_MAJOR /* third driver issue */
355 #endif
356 #if !(SBPCD_ISSUE-4)
357 #define MAJOR_NR MATSUSHITA_CDROM4_MAJOR /* fourth driver issue */
358 #endif
360 #include <linux/blk.h>
362 /*==========================================================================*/
364 * provisions for more than 1 driver issues
365 * currently up to 4 drivers, expandable
367 #if !(SBPCD_ISSUE-1)
368 #define DO_SBPCD_REQUEST(a) do_sbpcd_request(a)
369 #define SBPCD_INIT(a) sbpcd_init(a)
370 #endif
371 #if !(SBPCD_ISSUE-2)
372 #define DO_SBPCD_REQUEST(a) do_sbpcd2_request(a)
373 #define SBPCD_INIT(a) sbpcd2_init(a)
374 #endif
375 #if !(SBPCD_ISSUE-3)
376 #define DO_SBPCD_REQUEST(a) do_sbpcd3_request(a)
377 #define SBPCD_INIT(a) sbpcd3_init(a)
378 #endif
379 #if !(SBPCD_ISSUE-4)
380 #define DO_SBPCD_REQUEST(a) do_sbpcd4_request(a)
381 #define SBPCD_INIT(a) sbpcd4_init(a)
382 #endif
383 /*==========================================================================*/
384 #if SBPCD_DIS_IRQ
385 #define SBPCD_CLI cli()
386 #define SBPCD_STI sti()
387 #else
388 #define SBPCD_CLI
389 #define SBPCD_STI
390 #endif SBPCD_DIS_IRQ
391 /*==========================================================================*/
393 * auto-probing address list
394 * inspired by Adam J. Richter from Yggdrasil
396 * still not good enough - can cause a hang.
397 * example: a NE 2000 ethernet card at 300 will cause a hang probing 310.
398 * if that happens, reboot and use the LILO (kernel) command line.
399 * The possibly conflicting ethernet card addresses get NOT probed
400 * by default - to minimize the hang possibilities.
402 * The SB Pro addresses get "mirrored" at 0x6xx and some more locations - to
403 * avoid a type error, the 0x2xx-addresses must get checked before 0x6xx.
405 * send mail to emoenke@gwdg.de if your interface card is not FULLY
406 * represented here.
408 #if !(SBPCD_ISSUE-1)
409 static int sbpcd[] =
411 CDROM_PORT, SBPRO, /* probe with user's setup first */
412 #if DISTRIBUTION
413 0x230, 1, /* Soundblaster Pro and 16 (default) */
414 #if 0
415 0x300, 0, /* CI-101P (default), WDH-7001C (default),
416 Galaxy (default), Reveal (one default) */
417 0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
418 0x2C0, 3, /* Teac 16-bit cards */
419 0x260, 1, /* OmniCD */
420 0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
421 Longshine LCS-6853 (default) */
422 0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
423 0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
424 0x360, 0, /* Lasermate, CI-101P */
425 0x270, 1, /* Soundblaster 16 */
426 0x670, 0, /* "sound card #9" */
427 0x690, 0, /* "sound card #9" */
428 0x338, 2, /* SPEA Media FX, Ensonic SoundScape (default) */
429 0x328, 2, /* SPEA Media FX */
430 0x348, 2, /* SPEA Media FX */
431 0x634, 0, /* some newer sound cards */
432 0x638, 0, /* some newer sound cards */
433 0x230, 1, /* some newer sound cards */
434 /* due to incomplete address decoding of the SbPro card, these must be last */
435 0x630, 0, /* "sound card #9" (default) */
436 0x650, 0, /* "sound card #9" */
437 #ifdef MODULE
439 * some "hazardous" locations (no harm with the loadable version)
440 * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
442 0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
443 0x350, 0, /* Lasermate, CI-101P */
444 0x358, 2, /* SPEA Media FX */
445 0x370, 0, /* Lasermate, CI-101P */
446 0x290, 1, /* Soundblaster 16 */
447 0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
448 #endif MODULE
449 #endif
450 #endif DISTRIBUTION
452 #else
453 static int sbpcd[] = {CDROM_PORT, SBPRO}; /* probe with user's setup only */
454 #endif
455 MODULE_PARM(sbpcd, "2i");
457 #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
459 /*==========================================================================*/
461 * the external references:
463 #if !(SBPCD_ISSUE-1)
464 #ifdef CONFIG_SBPCD2
465 extern int sbpcd2_init(void);
466 #endif
467 #ifdef CONFIG_SBPCD3
468 extern int sbpcd3_init(void);
469 #endif
470 #ifdef CONFIG_SBPCD4
471 extern int sbpcd4_init(void);
472 #endif
473 #endif
475 /*==========================================================================*/
477 #define INLINE inline
479 /*==========================================================================*/
481 * the forward references:
483 static void sbp_sleep(u_int);
484 static void mark_timeout_delay(u_long);
485 static void mark_timeout_data(u_long);
486 #if 0
487 static void mark_timeout_audio(u_long);
488 #endif
489 static void sbp_read_cmd(struct request *req);
490 static int sbp_data(struct request *req);
491 static int cmd_out(void);
492 static int DiskInfo(void);
493 static int sbpcd_chk_disk_change(kdev_t);
495 /*==========================================================================*/
498 * pattern for printk selection:
500 * (1<<DBG_INF) necessary information
501 * (1<<DBG_BSZ) BLOCK_SIZE trace
502 * (1<<DBG_REA) "read" status trace
503 * (1<<DBG_CHK) "media check" trace
504 * (1<<DBG_TIM) datarate timer test
505 * (1<<DBG_INI) initialization trace
506 * (1<<DBG_TOC) tell TocEntry values
507 * (1<<DBG_IOC) ioctl trace
508 * (1<<DBG_STA) "ResponseStatus" trace
509 * (1<<DBG_ERR) "cc_ReadError" trace
510 * (1<<DBG_CMD) "cmd_out" trace
511 * (1<<DBG_WRN) give explanation before auto-probing
512 * (1<<DBG_MUL) multi session code test
513 * (1<<DBG_IDX) "drive_id != 0" test code
514 * (1<<DBG_IOX) some special information
515 * (1<<DBG_DID) drive ID test
516 * (1<<DBG_RES) drive reset info
517 * (1<<DBG_SPI) SpinUp test info
518 * (1<<DBG_IOS) ioctl trace: "subchannel"
519 * (1<<DBG_IO2) ioctl trace: general
520 * (1<<DBG_UPC) show UPC info
521 * (1<<DBG_XA1) XA mode debugging
522 * (1<<DBG_LCK) door (un)lock info
523 * (1<<DBG_SQ1) dump SubQ frame
524 * (1<<DBG_AUD) "read audio" debugging
525 * (1<<DBG_SEQ) Sequoia interface configuration trace
526 * (1<<DBG_LCS) Longshine LCS-7260 debugging trace
527 * (1<<DBG_CD2) MKE/Funai CD200 debugging trace
528 * (1<<DBG_TEA) TEAC CD-55A debugging trace
529 * (1<<DBG_ECS) ECS-AT (Vertos-100) debugging trace
530 * (1<<DBG_000) unnecessary information
532 #if DISTRIBUTION
533 static int sbpcd_debug = (1<<DBG_INF);
534 #else
535 static int sbpcd_debug = 0 & ((1<<DBG_INF) |
536 (1<<DBG_TOC) |
537 (1<<DBG_MUL) |
538 (1<<DBG_UPC));
539 #endif DISTRIBUTION
541 static int sbpcd_ioaddr = CDROM_PORT; /* default I/O base address */
542 static int sbpro_type = SBPRO;
543 static unsigned char setup_done = 0;
544 static unsigned char f_16bit = 0;
545 static unsigned char do_16bit = 0;
546 static int CDo_command, CDo_reset;
547 static int CDo_sel_i_d, CDo_enable;
548 static int CDi_info, CDi_status, CDi_data;
549 static struct cdrom_msf msf;
550 static struct cdrom_ti ti;
551 static struct cdrom_tochdr tochdr;
552 static struct cdrom_tocentry tocentry;
553 static struct cdrom_subchnl SC;
554 static struct cdrom_volctrl volctrl;
555 static struct cdrom_read_audio read_audio;
557 static unsigned char msgnum=0;
558 static char msgbuf[80];
560 static const char *str_sb = "SoundBlaster";
561 static const char *str_sb_l = "soundblaster";
562 static const char *str_lm = "LaserMate";
563 static const char *str_sp = "SPEA";
564 static const char *str_sp_l = "spea";
565 static const char *str_ss = "SoundScape";
566 static const char *str_ss_l = "soundscape";
567 static const char *str_t16 = "Teac16bit";
568 static const char *str_t16_l = "teac16bit";
569 static const char *type;
571 #if !(SBPCD_ISSUE-1)
572 static const char *major_name="sbpcd";
573 #endif
574 #if !(SBPCD_ISSUE-2)
575 static const char *major_name="sbpcd2";
576 #endif
577 #if !(SBPCD_ISSUE-3)
578 static const char *major_name="sbpcd3";
579 #endif
580 #if !(SBPCD_ISSUE-4)
581 static const char *major_name="sbpcd4";
582 #endif
584 /*==========================================================================*/
586 #if FUTURE
587 static struct wait_queue *sbp_waitq = NULL;
588 #endif FUTURE
590 static int teac=SBP_TEAC_SPEED;
591 static int buffers=SBP_BUFFER_FRAMES;
593 static u_char family0[]="MATSHITA"; /* MKE CR-521, CR-522, CR-523 */
594 static u_char family1[]="CR-56"; /* MKE CR-562, CR-563 */
595 static u_char family2[]="CD200"; /* MKE CD200, Funai CD200F */
596 static u_char familyL[]="LCS-7260"; /* Longshine LCS-7260 */
597 static u_char familyT[]="CD-55"; /* TEAC CD-55A */
598 static u_char familyV[]="ECS-AT"; /* ECS Vertos 100 */
600 static u_int recursion=0; /* internal testing only */
601 static u_int fatal_err=0; /* internal testing only */
602 static u_int response_count=0;
603 static u_int flags_cmd_out;
604 static u_char cmd_type=0;
605 static u_char drvcmd[10];
606 static u_char infobuf[20];
607 static u_char xa_head_buf[CD_XA_HEAD];
608 static u_char xa_tail_buf[CD_XA_TAIL];
610 #if OLD_BUSY
611 static volatile u_char busy_data=0;
612 static volatile u_char busy_audio=0; /* true semaphores would be safer */
613 #endif OLD_BUSY
614 static struct semaphore ioctl_read_sem = MUTEX;
615 static u_long timeout;
616 static volatile u_char timed_out_delay=0;
617 static volatile u_char timed_out_data=0;
618 #if 0
619 static volatile u_char timed_out_audio=0;
620 #endif
621 static u_int datarate= 1000000;
622 static u_int maxtim16=16000000;
623 static u_int maxtim04= 4000000;
624 static u_int maxtim02= 2000000;
625 static u_int maxtim_8= 30000;
626 #if LONG_TIMING
627 static u_int maxtim_data= 9000;
628 #else
629 static u_int maxtim_data= 3000;
630 #endif LONG_TIMING
631 #if DISTRIBUTION
632 static int n_retries=3;
633 #else
634 static int n_retries=1;
635 #endif
636 /*==========================================================================*/
638 static int ndrives=0;
639 static u_char drv_pattern[NR_SBPCD]={speed_auto,speed_auto,speed_auto,speed_auto};
640 static int sbpcd_blocksizes[NR_SBPCD] = {0, };
642 /*==========================================================================*/
644 * drive space begins here (needed separate for each unit)
646 static int d=0; /* DriveStruct index: drive number */
648 static struct {
649 char drv_id; /* "jumpered" drive ID or -1 */
650 char drv_sel; /* drive select lines bits */
652 char drive_model[9];
653 u_char firmware_version[4];
654 char f_eject; /* auto-eject flag: 0 or 1 */
655 u_char *sbp_buf; /* Pointer to internal data buffer,
656 space allocated during sbpcd_init() */
657 u_int sbp_bufsiz; /* size of sbp_buf (# of frames) */
658 int sbp_first_frame; /* First frame in buffer */
659 int sbp_last_frame; /* Last frame in buffer */
660 int sbp_read_frames; /* Number of frames being read to buffer */
661 int sbp_current; /* Frame being currently read */
663 u_char mode; /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
664 u_char *aud_buf; /* Pointer to audio data buffer,
665 space allocated during sbpcd_init() */
666 u_int sbp_audsiz; /* size of aud_buf (# of raw frames) */
667 u_int drv_type;
668 u_char drv_options;
669 int status_bits;
670 u_char diskstate_flags;
671 u_char sense_byte;
673 u_char CD_changed;
674 char open_count;
675 u_char error_byte;
677 u_char f_multisession;
678 u_int lba_multi;
679 int first_session;
680 int last_session;
681 int track_of_last_session;
683 u_char audio_state;
684 u_int pos_audio_start;
685 u_int pos_audio_end;
686 char vol_chan0;
687 u_char vol_ctrl0;
688 char vol_chan1;
689 u_char vol_ctrl1;
690 #if 000 /* no supported drive has it */
691 char vol_chan2;
692 u_char vol_ctrl2;
693 char vol_chan3;
694 u_char vol_ctrl3;
695 #endif 000
696 u_char volume_control; /* TEAC on/off bits */
698 u_char SubQ_ctl_adr;
699 u_char SubQ_trk;
700 u_char SubQ_pnt_idx;
701 u_int SubQ_run_tot;
702 u_int SubQ_run_trk;
703 u_char SubQ_whatisthis;
705 u_char UPC_ctl_adr;
706 u_char UPC_buf[7];
708 int frame_size;
709 int CDsize_frm;
711 u_char xa_byte; /* 0x20: XA capabilities */
712 u_char n_first_track; /* binary */
713 u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
714 u_int size_msf; /* time of whole CD, position of LeadOut track */
715 u_int size_blk;
717 u_char TocEnt_nixbyte; /* em */
718 u_char TocEnt_ctl_adr;
719 u_char TocEnt_number;
720 u_char TocEnt_format; /* em */
721 u_int TocEnt_address;
722 #if SAFE_MIXED
723 char has_data;
724 #endif SAFE_MIXED
725 u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
727 struct {
728 u_char nixbyte; /* em */
729 u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
730 u_char number;
731 u_char format; /* em */ /* 0x00: lba, 0x01: msf */
732 u_int address;
733 } TocBuffer[MAX_TRACKS+1]; /* last entry faked */
735 int in_SpinUp; /* CR-52x test flag */
736 int n_bytes; /* TEAC awaited response count */
737 u_char error_state, b3, b4; /* TEAC command error state */
738 u_char f_drv_error; /* TEAC command error flag */
739 u_char speed_byte;
740 int frmsiz;
741 u_char f_XA; /* 1: XA */
742 u_char type_byte; /* 0, 1, 3 */
743 u_char mode_xb_6;
744 u_char mode_yb_7;
745 u_char mode_xb_8;
746 u_char delay;
747 struct cdrom_device_info *sbpcd_infop;
749 } D_S[NR_SBPCD];
752 * drive space ends here (needed separate for each unit)
754 /*==========================================================================*/
755 #if 0
756 unsigned long cli_sti; /* for saving the processor flags */
757 #endif
758 /*==========================================================================*/
759 static struct timer_list delay_timer = { NULL, NULL, 0, 0, mark_timeout_delay};
760 static struct timer_list data_timer = { NULL, NULL, 0, 0, mark_timeout_data};
761 #if 0
762 static struct timer_list audio_timer = { NULL, NULL, 0, 0, mark_timeout_audio};
763 #endif
764 /*==========================================================================*/
766 * DDI interface
768 static void msg(int level, const char *fmt, ...)
770 #if DISTRIBUTION
771 #define MSG_LEVEL KERN_NOTICE
772 #else
773 #define MSG_LEVEL KERN_INFO
774 #endif DISTRIBUTION
776 char buf[256];
777 va_list args;
779 if (!(sbpcd_debug&(1<<level))) return;
781 msgnum++;
782 if (msgnum>99) msgnum=0;
783 sprintf(buf, MSG_LEVEL "%s-%d [%02d]: ", major_name, d, msgnum);
784 va_start(args, fmt);
785 vsprintf(&buf[18], fmt, args);
786 va_end(args);
787 printk(buf);
788 #if KLOGD_PAUSE
789 sbp_sleep(KLOGD_PAUSE); /* else messages get lost */
790 #endif KLOGD_PAUSE
791 return;
793 /*==========================================================================*/
795 * DDI interface: runtime trace bit pattern maintenance
797 static int sbpcd_dbg_ioctl(unsigned long arg, int level)
799 switch(arg)
801 case 0: /* OFF */
802 sbpcd_debug = DBG_INF;
803 break;
805 default:
806 if (arg>=128) sbpcd_debug &= ~(1<<(arg-128));
807 else sbpcd_debug |= (1<<arg);
809 return (arg);
811 /*==========================================================================*/
812 static void mark_timeout_delay(u_long i)
814 timed_out_delay=1;
815 #if 0
816 msg(DBG_TIM,"delay timer expired.\n");
817 #endif
819 /*==========================================================================*/
820 static void mark_timeout_data(u_long i)
822 timed_out_data=1;
823 #if 0
824 msg(DBG_TIM,"data timer expired.\n");
825 #endif
827 /*==========================================================================*/
828 #if 0
829 static void mark_timeout_audio(u_long i)
831 timed_out_audio=1;
832 #if 0
833 msg(DBG_TIM,"audio timer expired.\n");
834 #endif
836 #endif
837 /*==========================================================================*/
839 * Wait a little while (used for polling the drive).
841 static void sbp_sleep(u_int time)
843 sti();
844 current->state = TASK_INTERRUPTIBLE;
845 current->timeout = jiffies + time;
846 schedule();
847 sti();
849 /*==========================================================================*/
850 #define RETURN_UP(rc) {up(&ioctl_read_sem); return(rc);}
851 /*==========================================================================*/
853 * convert logical_block_address to m-s-f_number (3 bytes only)
855 static INLINE void lba2msf(int lba, u_char *msf)
857 lba += CD_MSF_OFFSET;
858 msf[0] = lba / (CD_SECS*CD_FRAMES);
859 lba %= CD_SECS*CD_FRAMES;
860 msf[1] = lba / CD_FRAMES;
861 msf[2] = lba % CD_FRAMES;
863 /*==========================================================================*/
864 /*==========================================================================*/
866 * convert msf-bin to msf-bcd
868 static INLINE void bin2bcdx(u_char *p) /* must work only up to 75 or 99 */
870 *p=((*p/10)<<4)|(*p%10);
872 /*==========================================================================*/
873 static INLINE u_int blk2msf(u_int blk)
875 MSF msf;
876 u_int mm;
878 msf.c[3] = 0;
879 msf.c[2] = (blk + CD_MSF_OFFSET) / (CD_SECS * CD_FRAMES);
880 mm = (blk + CD_MSF_OFFSET) % (CD_SECS * CD_FRAMES);
881 msf.c[1] = mm / CD_FRAMES;
882 msf.c[0] = mm % CD_FRAMES;
883 return (msf.n);
885 /*==========================================================================*/
886 static INLINE u_int make16(u_char rh, u_char rl)
888 return ((rh<<8)|rl);
890 /*==========================================================================*/
891 static INLINE u_int make32(u_int rh, u_int rl)
893 return ((rh<<16)|rl);
895 /*==========================================================================*/
896 static INLINE u_char swap_nibbles(u_char i)
898 return ((i<<4)|(i>>4));
900 /*==========================================================================*/
901 static INLINE u_char byt2bcd(u_char i)
903 return (((i/10)<<4)+i%10);
905 /*==========================================================================*/
906 static INLINE u_char bcd2bin(u_char bcd)
908 return ((bcd>>4)*10+(bcd&0x0F));
910 /*==========================================================================*/
911 static INLINE int msf2blk(int msfx)
913 MSF msf;
914 int i;
916 msf.n=msfx;
917 i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_MSF_OFFSET;
918 if (i<0) return (0);
919 return (i);
921 /*==========================================================================*/
923 * convert m-s-f_number (3 bytes only) to logical_block_address
925 static INLINE int msf2lba(u_char *msf)
927 int i;
929 i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_MSF_OFFSET;
930 if (i<0) return (0);
931 return (i);
933 /*==========================================================================*/
934 /* evaluate cc_ReadError code */
935 static int sta2err(int sta)
937 if (famT_drive)
939 if (sta==0x00) return (0);
940 if (sta==0x01) return (-604); /* CRC error */
941 if (sta==0x02) return (-602); /* drive not ready */
942 if (sta==0x03) return (-607); /* unknown media */
943 if (sta==0x04) return (-612); /* general failure */
944 if (sta==0x05) return (0);
945 if (sta==0x06) return (-ERR_DISKCHANGE); /* disk change */
946 if (sta==0x0b) return (-612); /* general failure */
947 if (sta==0xff) return (-612); /* general failure */
948 return (0);
950 else
952 if (sta<=2) return (sta);
953 if (sta==0x05) return (-604); /* CRC error */
954 if (sta==0x06) return (-606); /* seek error */
955 if (sta==0x0d) return (-606); /* seek error */
956 if (sta==0x0e) return (-603); /* unknown command */
957 if (sta==0x14) return (-603); /* unknown command */
958 if (sta==0x0c) return (-611); /* read fault */
959 if (sta==0x0f) return (-611); /* read fault */
960 if (sta==0x10) return (-611); /* read fault */
961 if (sta>=0x16) return (-612); /* general failure */
962 if (sta==0x11) return (-ERR_DISKCHANGE); /* disk change (LCS: removed) */
963 if (famL_drive)
964 if (sta==0x12) return (-ERR_DISKCHANGE); /* disk change (inserted) */
965 return (-602); /* drive not ready */
968 /*==========================================================================*/
969 static INLINE void clr_cmdbuf(void)
971 int i;
973 for (i=0;i<10;i++) drvcmd[i]=0;
974 cmd_type=0;
976 /*==========================================================================*/
977 static void flush_status(void)
979 int i;
981 sbp_sleep(15*HZ/10);
982 for (i=maxtim_data;i!=0;i--) inb(CDi_status);
984 /*====================================================================*/
986 * CDi status loop for Teac CD-55A (Rob Riggs)
988 * This is needed because for some strange reason
989 * the CD-55A can take a real long time to give a
990 * status response. This seems to happen after we
991 * issue a READ command where a long seek is involved.
993 * I tried to ensure that we get max throughput with
994 * minimal busy waiting. We busy wait at first, then
995 * "switch gears" and start sleeping. We sleep for
996 * longer periods of time the longer we wait.
999 static int CDi_stat_loop_T(void)
1001 int i, gear=1;
1002 u_long timeout_1, timeout_2, timeout_3, timeout_4;
1004 timeout_1 = jiffies + HZ / 50; /* sbp_sleep(0) for a short period */
1005 timeout_2 = jiffies + HZ / 5; /* nap for no more than 200ms */
1006 timeout_3 = jiffies + 5 * HZ; /* sleep for up to 5s */
1007 timeout_4 = jiffies + 45 * HZ; /* long sleep for up to 45s. */
1010 i = inb(CDi_status);
1011 if (!(i&s_not_data_ready)) return (i);
1012 if (!(i&s_not_result_ready)) return (i);
1013 switch(gear)
1015 case 4:
1016 sbp_sleep(HZ);
1017 if (jiffies > timeout_4) gear++;
1018 msg(DBG_TEA, "CDi_stat_loop_T: long sleep active.\n");
1019 break;
1020 case 3:
1021 sbp_sleep(HZ/10);
1022 if (jiffies > timeout_3) gear++;
1023 break;
1024 case 2:
1025 sbp_sleep(HZ/100);
1026 if (jiffies > timeout_2) gear++;
1027 break;
1028 case 1:
1029 sbp_sleep(0);
1030 if (jiffies > timeout_1) gear++;
1032 } while (gear < 5);
1033 return -1;
1035 /*==========================================================================*/
1036 static int CDi_stat_loop(void)
1038 int i,j;
1040 for(timeout = jiffies + 10*HZ, i=maxtim_data; timeout > jiffies; )
1042 for ( ;i!=0;i--)
1044 j=inb(CDi_status);
1045 if (!(j&s_not_data_ready)) return (j);
1046 if (!(j&s_not_result_ready)) return (j);
1047 if (fam0L_drive) if (j&s_attention) return (j);
1049 sbp_sleep(1);
1050 i = 1;
1052 msg(DBG_LCS,"CDi_stat_loop failed in line %d\n", __LINE__);
1053 return (-1);
1055 /*==========================================================================*/
1056 #if 00000
1057 /*==========================================================================*/
1058 static int tst_DataReady(void)
1060 int i;
1062 i=inb(CDi_status);
1063 if (i&s_not_data_ready) return (0);
1064 return (1);
1066 /*==========================================================================*/
1067 static int tst_ResultReady(void)
1069 int i;
1071 i=inb(CDi_status);
1072 if (i&s_not_result_ready) return (0);
1073 return (1);
1075 /*==========================================================================*/
1076 static int tst_Attention(void)
1078 int i;
1080 i=inb(CDi_status);
1081 if (i&s_attention) return (1);
1082 return (0);
1084 /*==========================================================================*/
1085 #endif 00000
1086 /*==========================================================================*/
1087 static int ResponseInfo(void)
1089 int i,j,st=0;
1090 u_long timeout;
1092 for (i=0,timeout=jiffies+HZ;i<response_count;i++)
1094 for (j=maxtim_data; ; )
1096 for ( ;j!=0;j-- )
1098 st=inb(CDi_status);
1099 if (!(st&s_not_result_ready)) break;
1101 if ((j!=0)||(timeout<=jiffies)) break;
1102 sbp_sleep(1);
1103 j = 1;
1105 if (timeout<=jiffies) break;
1106 infobuf[i]=inb(CDi_info);
1108 #if 000
1109 while (!(inb(CDi_status)&s_not_result_ready))
1111 infobuf[i++]=inb(CDi_info);
1113 j=i-response_count;
1114 if (j>0) msg(DBG_INF,"ResponseInfo: got %d trailing bytes.\n",j);
1115 #endif 000
1116 for (j=0;j<i;j++)
1117 sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1118 msgbuf[j*3]=0;
1119 msg(DBG_CMD,"ResponseInfo:%s (%d,%d)\n",msgbuf,response_count,i);
1120 j=response_count-i;
1121 if (j>0) return (-j);
1122 else return (i);
1124 /*==========================================================================*/
1125 static void EvaluateStatus(int st)
1127 D_S[d].status_bits=0;
1128 if (fam1_drive) D_S[d].status_bits=st|p_success;
1129 else if (fam0_drive)
1131 if (st&p_caddin_old) D_S[d].status_bits |= p_door_closed|p_caddy_in;
1132 if (st&p_spinning) D_S[d].status_bits |= p_spinning;
1133 if (st&p_check) D_S[d].status_bits |= p_check;
1134 if (st&p_success_old) D_S[d].status_bits |= p_success;
1135 if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
1136 if (st&p_disk_ok) D_S[d].status_bits |= p_disk_ok;
1138 else if (famLV_drive)
1140 D_S[d].status_bits |= p_success;
1141 if (st&p_caddin_old) D_S[d].status_bits |= p_disk_ok|p_caddy_in;
1142 if (st&p_spinning) D_S[d].status_bits |= p_spinning;
1143 if (st&p_check) D_S[d].status_bits |= p_check;
1144 if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
1145 if (st&p_lcs_door_closed) D_S[d].status_bits |= p_door_closed;
1146 if (st&p_lcs_door_locked) D_S[d].status_bits |= p_door_locked;
1148 else if (fam2_drive)
1150 D_S[d].status_bits |= p_success;
1151 if (st&p2_check) D_S[d].status_bits |= p1_check;
1152 if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
1153 if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
1154 if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
1155 if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
1156 if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
1157 if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
1158 if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
1160 else if (famT_drive)
1162 return; /* still needs to get coded */
1163 D_S[d].status_bits |= p_success;
1164 if (st&p2_check) D_S[d].status_bits |= p1_check;
1165 if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
1166 if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
1167 if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
1168 if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
1169 if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
1170 if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
1171 if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
1173 return;
1175 /*==========================================================================*/
1176 static int get_state_T(void)
1178 int i;
1180 static int cmd_out_T(void);
1182 clr_cmdbuf();
1183 D_S[d].n_bytes=1;
1184 drvcmd[0]=CMDT_STATUS;
1185 i=cmd_out_T();
1186 if (i>=0) i=infobuf[0];
1187 else
1189 msg(DBG_TEA,"get_state_T error %d\n", i);
1190 return (i);
1192 if (i>=0)
1193 /* 2: closed, disk in */
1194 D_S[d].status_bits=p1_door_closed|p1_disk_in|p1_spinning|p1_disk_ok;
1195 else if (D_S[d].error_state==6)
1197 /* 3: closed, disk in, changed ("06 xx xx") */
1198 D_S[d].status_bits=p1_door_closed|p1_disk_in;
1199 D_S[d].CD_changed=0xFF;
1200 D_S[d].diskstate_flags &= ~toc_bit;
1202 else if ((D_S[d].error_state!=2)||(D_S[d].b3!=0x3A)||(D_S[d].b4==0x00))
1204 /* 1: closed, no disk ("xx yy zz"or "02 3A 00") */
1205 D_S[d].status_bits=p1_door_closed;
1206 D_S[d].open_count=0;
1208 else if (D_S[d].b4==0x01)
1210 /* 0: open ("02 3A 01") */
1211 D_S[d].status_bits=0;
1212 D_S[d].open_count=0;
1214 else
1216 /* 1: closed, no disk ("02 3A xx") */
1217 D_S[d].status_bits=p1_door_closed;
1218 D_S[d].open_count=0;
1220 return (D_S[d].status_bits);
1222 /*==========================================================================*/
1223 static int ResponseStatus(void)
1225 int i,j;
1226 u_long timeout;
1228 msg(DBG_STA,"doing ResponseStatus...\n");
1229 if (famT_drive) return (get_state_T());
1230 if (flags_cmd_out & f_respo3) timeout = jiffies;
1231 else if (flags_cmd_out & f_respo2) timeout = jiffies + 16*HZ;
1232 else timeout = jiffies + 4*HZ;
1233 j=maxtim_8;
1236 for ( ;j!=0;j--)
1238 i=inb(CDi_status);
1239 if (!(i&s_not_result_ready)) break;
1241 if ((j!=0)||(timeout<jiffies)) break;
1242 sbp_sleep(1);
1243 j = 1;
1245 while (1);
1246 if (j==0)
1248 if ((flags_cmd_out & f_respo3) == 0)
1249 msg(DBG_STA,"ResponseStatus: timeout.\n");
1250 D_S[d].status_bits=0;
1251 return (-401);
1253 i=inb(CDi_info);
1254 msg(DBG_STA,"ResponseStatus: response %02X.\n", i);
1255 EvaluateStatus(i);
1256 msg(DBG_STA,"status_bits=%02X, i=%02X\n",D_S[d].status_bits,i);
1257 return (D_S[d].status_bits);
1259 /*==========================================================================*/
1260 static void cc_ReadStatus(void)
1262 int i;
1264 msg(DBG_STA,"giving cc_ReadStatus command\n");
1265 if (famT_drive) return;
1266 SBPCD_CLI;
1267 if (fam0LV_drive) OUT(CDo_command,CMD0_STATUS);
1268 else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
1269 else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
1270 if (!fam0LV_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
1271 SBPCD_STI;
1273 /*==========================================================================*/
1274 static int cc_ReadError(void)
1276 int i;
1278 clr_cmdbuf();
1279 msg(DBG_ERR,"giving cc_ReadError command.\n");
1280 if (fam1_drive)
1282 drvcmd[0]=CMD1_READ_ERR;
1283 response_count=8;
1284 flags_cmd_out=f_putcmd|f_ResponseStatus;
1286 else if (fam0LV_drive)
1288 drvcmd[0]=CMD0_READ_ERR;
1289 response_count=6;
1290 if (famLV_drive)
1291 flags_cmd_out=f_putcmd;
1292 else
1293 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
1295 else if (fam2_drive)
1297 drvcmd[0]=CMD2_READ_ERR;
1298 response_count=6;
1299 flags_cmd_out=f_putcmd;
1301 else if (famT_drive)
1303 response_count=5;
1304 drvcmd[0]=CMDT_READ_ERR;
1306 i=cmd_out();
1307 D_S[d].error_byte=0;
1308 msg(DBG_ERR,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i,i);
1309 if (i<0) return (i);
1310 if (fam0V_drive) i=1;
1311 else i=2;
1312 D_S[d].error_byte=infobuf[i];
1313 msg(DBG_ERR,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i,D_S[d].error_byte,D_S[d].error_byte);
1314 i=sta2err(infobuf[i]);
1315 if (i==-ERR_DISKCHANGE)
1317 D_S[d].CD_changed=0xFF;
1318 D_S[d].diskstate_flags &= ~toc_bit;
1320 return (i);
1322 /*==========================================================================*/
1323 static int cmd_out_T(void)
1325 #undef CMDT_TRIES
1326 #define CMDT_TRIES 1000
1327 #define TEST_FALSE_FF 1
1329 static int cc_DriveReset(void);
1330 int i, j, l=0, m, ntries;
1331 long flags;
1333 D_S[d].error_state=0;
1334 D_S[d].b3=0;
1335 D_S[d].b4=0;
1336 D_S[d].f_drv_error=0;
1337 for (i=0;i<10;i++) sprintf(&msgbuf[i*3]," %02X",drvcmd[i]);
1338 msgbuf[i*3]=0;
1339 msg(DBG_CMD,"cmd_out_T:%s\n",msgbuf);
1341 OUT(CDo_sel_i_d,0);
1342 OUT(CDo_enable,D_S[d].drv_sel);
1343 i=inb(CDi_status);
1344 do_16bit=0;
1345 if ((f_16bit)&&(!(i&0x80)))
1347 do_16bit=1;
1348 msg(DBG_TEA,"cmd_out_T: do_16bit set.\n");
1350 if (!(i&s_not_result_ready))
1353 j=inb(CDi_info);
1354 i=inb(CDi_status);
1355 sbp_sleep(0);
1356 msg(DBG_TEA,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j);
1358 while (!(i&s_not_result_ready));
1359 save_flags(flags); cli();
1360 for (i=0;i<10;i++) OUT(CDo_command,drvcmd[i]);
1361 restore_flags(flags);
1362 for (ntries=CMDT_TRIES;ntries>0;ntries--)
1364 if (drvcmd[0]==CMDT_READ_VER) sbp_sleep(HZ); /* fixme */
1365 #if 01
1366 OUT(CDo_sel_i_d,1);
1367 #endif 01
1368 if (teac==2)
1370 if ((i=CDi_stat_loop_T()) == -1) break;
1372 else
1374 #if 0
1375 OUT(CDo_sel_i_d,1);
1376 #endif 0
1377 i=inb(CDi_status);
1379 if (!(i&s_not_data_ready)) /* f.e. CMDT_DISKINFO */
1381 OUT(CDo_sel_i_d,1);
1382 if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
1383 if (drvcmd[0]==CMDT_DISKINFO)
1385 l=0;
1388 if (do_16bit)
1390 i=inw(CDi_data);
1391 infobuf[l++]=i&0x0ff;
1392 infobuf[l++]=i>>8;
1393 #if TEST_FALSE_FF
1394 if ((l==2)&&(infobuf[0]==0x0ff))
1396 infobuf[0]=infobuf[1];
1397 l=1;
1398 msg(DBG_TEA,"cmd_out_T: do_16bit: false first byte!\n");
1400 #endif TEST_FALSE_FF
1402 else infobuf[l++]=inb(CDi_data);
1403 i=inb(CDi_status);
1405 while (!(i&s_not_data_ready));
1406 for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1407 msgbuf[j*3]=0;
1408 msg(DBG_CMD,"cmd_out_T data response:%s\n", msgbuf);
1410 else
1412 msg(DBG_TEA,"cmd_out_T: data response with cmd_%02X!\n",
1413 drvcmd[0]);
1414 j=0;
1417 if (do_16bit) i=inw(CDi_data);
1418 else i=inb(CDi_data);
1419 j++;
1420 i=inb(CDi_status);
1422 while (!(i&s_not_data_ready));
1423 msg(DBG_TEA,"cmd_out_T: data response: discarded %d bytes/words.\n", j);
1424 fatal_err++;
1427 i=inb(CDi_status);
1428 if (!(i&s_not_result_ready))
1430 OUT(CDo_sel_i_d,0);
1431 if (drvcmd[0]==CMDT_DISKINFO) m=l;
1432 else m=0;
1435 infobuf[m++]=inb(CDi_info);
1436 i=inb(CDi_status);
1438 while (!(i&s_not_result_ready));
1439 for (j=0;j<m;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1440 msgbuf[j*3]=0;
1441 msg(DBG_CMD,"cmd_out_T info response:%s\n", msgbuf);
1442 if (drvcmd[0]==CMDT_DISKINFO)
1444 infobuf[0]=infobuf[l];
1445 if (infobuf[0]!=0x02) return (l); /* data length */
1447 else if (infobuf[0]!=0x02) return (m); /* info length */
1450 ++recursion;
1451 if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd[0], recursion);
1452 clr_cmdbuf();
1453 drvcmd[0]=CMDT_READ_ERR;
1454 j=cmd_out_T(); /* !!! recursive here !!! */
1455 --recursion;
1456 sbp_sleep(1);
1458 while (j<0);
1459 D_S[d].error_state=infobuf[2];
1460 D_S[d].b3=infobuf[3];
1461 D_S[d].b4=infobuf[4];
1462 if (D_S[d].f_drv_error)
1464 D_S[d].f_drv_error=0;
1465 cc_DriveReset();
1466 D_S[d].error_state=2;
1468 return (-D_S[d].error_state-400);
1470 if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
1471 if ((teac==0)||(ntries<(CMDT_TRIES-5))) sbp_sleep(HZ/10);
1472 else sbp_sleep(HZ/100);
1473 if (ntries>(CMDT_TRIES-50)) continue;
1474 msg(DBG_TEA,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd[0], ntries-1);
1476 D_S[d].f_drv_error=1;
1477 cc_DriveReset();
1478 D_S[d].error_state=2;
1479 return (-99);
1481 /*==========================================================================*/
1482 static int cmd_out(void)
1484 int i=0;
1486 if (famT_drive) return(cmd_out_T());
1488 if (flags_cmd_out&f_putcmd)
1490 for (i=0;i<7;i++)
1491 sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
1492 msgbuf[i*3]=0;
1493 msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
1494 cli();
1495 for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
1496 sti();
1498 if (response_count!=0)
1500 if (cmd_type!=0)
1502 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
1503 msg(DBG_INF,"misleaded to try ResponseData.\n");
1504 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
1505 return (-22);
1507 else i=ResponseInfo();
1508 if (i<0) return (i);
1510 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
1511 if (flags_cmd_out&f_lopsta)
1513 i=CDi_stat_loop();
1514 if ((i<0)||!(i&s_attention)) return (-8);
1516 if (!(flags_cmd_out&f_getsta)) goto LOC_229;
1518 LOC_228:
1519 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
1520 cc_ReadStatus();
1522 LOC_229:
1523 if (flags_cmd_out&f_ResponseStatus)
1525 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
1526 i=ResponseStatus();
1527 /* builds status_bits, returns orig. status or p_busy_new */
1528 if (i<0) return (i);
1529 if (flags_cmd_out&(f_bit1|f_wait_if_busy))
1531 if (!st_check)
1533 if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
1534 if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
1538 LOC_232:
1539 if (!(flags_cmd_out&f_obey_p_check)) return (0);
1540 if (!st_check) return (0);
1541 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
1542 i=cc_ReadError();
1543 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
1544 msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
1545 return (i);
1547 /*==========================================================================*/
1548 static int cc_Seek(u_int pos, char f_blk_msf)
1550 int i;
1552 clr_cmdbuf();
1553 if (f_blk_msf>1) return (-3);
1554 if (fam0V_drive)
1556 drvcmd[0]=CMD0_SEEK;
1557 if (f_blk_msf==1) pos=msf2blk(pos);
1558 drvcmd[2]=(pos>>16)&0x00FF;
1559 drvcmd[3]=(pos>>8)&0x00FF;
1560 drvcmd[4]=pos&0x00FF;
1561 if (fam0_drive)
1562 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
1563 f_ResponseStatus | f_obey_p_check | f_bit1;
1564 else
1565 flags_cmd_out = f_putcmd;
1567 else if (fam1L_drive)
1569 drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
1570 if (f_blk_msf==0) pos=blk2msf(pos);
1571 drvcmd[1]=(pos>>16)&0x00FF;
1572 drvcmd[2]=(pos>>8)&0x00FF;
1573 drvcmd[3]=pos&0x00FF;
1574 if (famL_drive)
1575 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1576 else
1577 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1579 else if (fam2_drive)
1581 drvcmd[0]=CMD2_SEEK;
1582 if (f_blk_msf==0) pos=blk2msf(pos);
1583 drvcmd[2]=(pos>>24)&0x00FF;
1584 drvcmd[3]=(pos>>16)&0x00FF;
1585 drvcmd[4]=(pos>>8)&0x00FF;
1586 drvcmd[5]=pos&0x00FF;
1587 flags_cmd_out=f_putcmd|f_ResponseStatus;
1589 else if (famT_drive)
1591 drvcmd[0]=CMDT_SEEK;
1592 if (f_blk_msf==1) pos=msf2blk(pos);
1593 drvcmd[2]=(pos>>24)&0x00FF;
1594 drvcmd[3]=(pos>>16)&0x00FF;
1595 drvcmd[4]=(pos>>8)&0x00FF;
1596 drvcmd[5]=pos&0x00FF;
1597 D_S[d].n_bytes=1;
1599 response_count=0;
1600 i=cmd_out();
1601 return (i);
1603 /*==========================================================================*/
1604 static int cc_SpinUp(void)
1606 int i;
1608 msg(DBG_SPI,"SpinUp.\n");
1609 D_S[d].in_SpinUp = 1;
1610 clr_cmdbuf();
1611 if (fam0LV_drive)
1613 drvcmd[0]=CMD0_SPINUP;
1614 if (fam0L_drive)
1615 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
1616 f_ResponseStatus|f_obey_p_check|f_bit1;
1617 else
1618 flags_cmd_out=f_putcmd;
1620 else if (fam1_drive)
1622 drvcmd[0]=CMD1_SPINUP;
1623 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1625 else if (fam2_drive)
1627 drvcmd[0]=CMD2_TRAY_CTL;
1628 drvcmd[4]=0x01; /* "spinup" */
1629 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1631 else if (famT_drive)
1633 drvcmd[0]=CMDT_TRAY_CTL;
1634 drvcmd[4]=0x03; /* "insert", it hopefully spins the drive up */
1636 response_count=0;
1637 i=cmd_out();
1638 D_S[d].in_SpinUp = 0;
1639 return (i);
1641 /*==========================================================================*/
1642 static int cc_SpinDown(void)
1644 int i;
1646 if (fam0_drive) return (0);
1647 clr_cmdbuf();
1648 response_count=0;
1649 if (fam1_drive)
1651 drvcmd[0]=CMD1_SPINDOWN;
1652 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1654 else if (fam2_drive)
1656 drvcmd[0]=CMD2_TRAY_CTL;
1657 drvcmd[4]=0x02; /* "eject" */
1658 flags_cmd_out=f_putcmd|f_ResponseStatus;
1660 else if (famL_drive)
1662 drvcmd[0]=CMDL_SPINDOWN;
1663 drvcmd[1]=1;
1664 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1666 else if (famV_drive)
1668 drvcmd[0]=CMDV_SPINDOWN;
1669 flags_cmd_out=f_putcmd;
1671 else if (famT_drive)
1673 drvcmd[0]=CMDT_TRAY_CTL;
1674 drvcmd[4]=0x02; /* "eject" */
1676 i=cmd_out();
1677 return (i);
1679 /*==========================================================================*/
1680 static int cc_get_mode_T(void)
1682 int i;
1684 clr_cmdbuf();
1685 response_count=10;
1686 drvcmd[0]=CMDT_GETMODE;
1687 drvcmd[4]=response_count;
1688 i=cmd_out_T();
1689 return (i);
1691 /*==========================================================================*/
1692 static int cc_set_mode_T(void)
1694 int i;
1696 clr_cmdbuf();
1697 response_count=1;
1698 drvcmd[0]=CMDT_SETMODE;
1699 drvcmd[1]=D_S[d].speed_byte;
1700 drvcmd[2]=D_S[d].frmsiz>>8;
1701 drvcmd[3]=D_S[d].frmsiz&0x0FF;
1702 drvcmd[4]=D_S[d].f_XA; /* 1: XA */
1703 drvcmd[5]=D_S[d].type_byte; /* 0, 1, 3 */
1704 drvcmd[6]=D_S[d].mode_xb_6;
1705 drvcmd[7]=D_S[d].mode_yb_7|D_S[d].volume_control;
1706 drvcmd[8]=D_S[d].mode_xb_8;
1707 drvcmd[9]=D_S[d].delay;
1708 i=cmd_out_T();
1709 return (i);
1711 /*==========================================================================*/
1712 static int cc_prep_mode_T(void)
1714 int i, j;
1716 i=cc_get_mode_T();
1717 if (i<0) return (i);
1718 for (i=0;i<10;i++)
1719 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1720 msgbuf[i*3]=0;
1721 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1722 D_S[d].speed_byte=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
1723 D_S[d].frmsiz=make16(infobuf[2],infobuf[3]);
1724 D_S[d].f_XA=infobuf[4];
1725 if (D_S[d].f_XA==0) D_S[d].type_byte=0;
1726 else D_S[d].type_byte=1;
1727 D_S[d].mode_xb_6=infobuf[6];
1728 D_S[d].mode_yb_7=1;
1729 D_S[d].mode_xb_8=infobuf[8];
1730 D_S[d].delay=0; /* 0, 1, 2, 3 */
1731 j=cc_set_mode_T();
1732 i=cc_get_mode_T();
1733 for (i=0;i<10;i++)
1734 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1735 msgbuf[i*3]=0;
1736 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1737 return (j);
1739 /*==========================================================================*/
1740 static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
1742 int i;
1744 if (fam0LV_drive) return (0);
1745 clr_cmdbuf();
1746 response_count=0;
1747 if (fam1_drive)
1749 drvcmd[0]=CMD1_SETMODE;
1750 drvcmd[1]=0x03;
1751 drvcmd[2]=speed;
1752 drvcmd[3]=x1;
1753 drvcmd[4]=x2;
1754 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1756 else if (fam2_drive)
1758 drvcmd[0]=CMD2_SETSPEED;
1759 if (speed&speed_auto)
1761 drvcmd[2]=0xFF;
1762 drvcmd[3]=0xFF;
1764 else
1766 drvcmd[2]=0;
1767 drvcmd[3]=150;
1769 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1771 else if (famT_drive)
1773 return (0);
1775 i=cmd_out();
1776 return (i);
1778 /*==========================================================================*/
1779 static int cc_SetVolume(void)
1781 int i;
1782 u_char channel0,channel1,volume0,volume1;
1783 u_char control0,value0,control1,value1;
1785 D_S[d].diskstate_flags &= ~volume_bit;
1786 clr_cmdbuf();
1787 channel0=D_S[d].vol_chan0;
1788 volume0=D_S[d].vol_ctrl0;
1789 channel1=control1=D_S[d].vol_chan1;
1790 volume1=value1=D_S[d].vol_ctrl1;
1791 control0=value0=0;
1793 if (famV_drive) return (0);
1795 if (((D_S[d].drv_options&audio_mono)!=0)&&(D_S[d].drv_type>=drv_211))
1797 if ((volume0!=0)&&(volume1==0))
1799 volume1=volume0;
1800 channel1=channel0;
1802 else if ((volume0==0)&&(volume1!=0))
1804 volume0=volume1;
1805 channel0=channel1;
1808 if (channel0>1)
1810 channel0=0;
1811 volume0=0;
1813 if (channel1>1)
1815 channel1=1;
1816 volume1=0;
1819 if (fam1_drive)
1821 control0=channel0+1;
1822 control1=channel1+1;
1823 value0=(volume0>volume1)?volume0:volume1;
1824 value1=value0;
1825 if (volume0==0) control0=0;
1826 if (volume1==0) control1=0;
1827 drvcmd[0]=CMD1_SETMODE;
1828 drvcmd[1]=0x05;
1829 drvcmd[3]=control0;
1830 drvcmd[4]=value0;
1831 drvcmd[5]=control1;
1832 drvcmd[6]=value1;
1833 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1835 else if (fam2_drive)
1837 control0=channel0+1;
1838 control1=channel1+1;
1839 value0=(volume0>volume1)?volume0:volume1;
1840 value1=value0;
1841 if (volume0==0) control0=0;
1842 if (volume1==0) control1=0;
1843 drvcmd[0]=CMD2_SETMODE;
1844 drvcmd[1]=0x0E;
1845 drvcmd[3]=control0;
1846 drvcmd[4]=value0;
1847 drvcmd[5]=control1;
1848 drvcmd[6]=value1;
1849 flags_cmd_out=f_putcmd|f_ResponseStatus;
1851 else if (famL_drive)
1853 if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
1854 if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
1855 if (volume0|volume1) value0=0x80;
1856 drvcmd[0]=CMDL_SETMODE;
1857 drvcmd[1]=0x03;
1858 drvcmd[4]=control0;
1859 drvcmd[5]=value0;
1860 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1862 else if (fam0_drive) /* different firmware levels */
1864 if (D_S[d].drv_type>=drv_300)
1866 control0=volume0&0xFC;
1867 value0=volume1&0xFC;
1868 if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
1869 if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
1870 if (channel0!=0) control0 |= 0x01;
1871 if (channel1==1) value0 |= 0x01;
1873 else
1875 value0=(volume0>volume1)?volume0:volume1;
1876 if (D_S[d].drv_type<drv_211)
1878 if (channel0!=0)
1880 i=channel1;
1881 channel1=channel0;
1882 channel0=i;
1883 i=volume1;
1884 volume1=volume0;
1885 volume0=i;
1887 if (channel0==channel1)
1889 if (channel0==0)
1891 channel1=1;
1892 volume1=0;
1893 volume0=value0;
1895 else
1897 channel0=0;
1898 volume0=0;
1899 volume1=value0;
1904 if ((volume0!=0)&&(volume1!=0))
1906 if (volume0==0xFF) volume1=0xFF;
1907 else if (volume1==0xFF) volume0=0xFF;
1909 else if (D_S[d].drv_type<drv_201) volume0=volume1=value0;
1911 if (D_S[d].drv_type>=drv_201)
1913 if (volume0==0) control0 |= 0x80;
1914 if (volume1==0) control0 |= 0x40;
1916 if (D_S[d].drv_type>=drv_211)
1918 if (channel0!=0) control0 |= 0x20;
1919 if (channel1!=1) control0 |= 0x10;
1922 drvcmd[0]=CMD0_SETMODE;
1923 drvcmd[1]=0x83;
1924 drvcmd[4]=control0;
1925 drvcmd[5]=value0;
1926 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
1928 else if (famT_drive)
1930 D_S[d].volume_control=0;
1931 if (!volume0) D_S[d].volume_control|=0x10;
1932 if (!volume1) D_S[d].volume_control|=0x20;
1933 i=cc_prep_mode_T();
1934 if (i<0) return (i);
1936 if (!famT_drive)
1938 response_count=0;
1939 i=cmd_out();
1940 if (i<0) return (i);
1942 D_S[d].diskstate_flags |= volume_bit;
1943 return (0);
1945 /*==========================================================================*/
1946 static int GetStatus(void)
1948 int i;
1950 if (famT_drive) return (0);
1951 flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
1952 response_count=0;
1953 cmd_type=0;
1954 i=cmd_out();
1955 return (i);
1957 /*==========================================================================*/
1958 static int cc_DriveReset(void)
1960 int i;
1962 msg(DBG_RES,"cc_DriveReset called.\n");
1963 clr_cmdbuf();
1964 response_count=0;
1965 if (fam0LV_drive) OUT(CDo_reset,0x00);
1966 else if (fam1_drive)
1968 drvcmd[0]=CMD1_RESET;
1969 flags_cmd_out=f_putcmd;
1970 i=cmd_out();
1972 else if (fam2_drive)
1974 drvcmd[0]=CMD2_RESET;
1975 flags_cmd_out=f_putcmd;
1976 i=cmd_out();
1977 OUT(CDo_reset,0x00);
1979 else if (famT_drive)
1981 OUT(CDo_sel_i_d,0);
1982 OUT(CDo_enable,D_S[d].drv_sel);
1983 OUT(CDo_command,CMDT_RESET);
1984 for (i=1;i<10;i++) OUT(CDo_command,0);
1986 if (fam0LV_drive) sbp_sleep(5*HZ); /* wait 5 seconds */
1987 else sbp_sleep(1*HZ); /* wait a second */
1988 #if 1
1989 if (famT_drive)
1991 msg(DBG_TEA, "================CMDT_RESET given=================.\n");
1992 sbp_sleep(3*HZ);
1994 #endif 1
1995 flush_status();
1996 i=GetStatus();
1997 if (i<0) return i;
1998 if (!famT_drive)
1999 if (D_S[d].error_byte!=aud_12) return -501;
2000 return (0);
2003 /*==========================================================================*/
2004 static int SetSpeed(void)
2006 int i, speed;
2008 if (!(D_S[d].drv_options&(speed_auto|speed_300|speed_150))) return (0);
2009 speed=speed_auto;
2010 if (!(D_S[d].drv_options&speed_auto))
2012 speed |= speed_300;
2013 if (!(D_S[d].drv_options&speed_300)) speed=0;
2015 i=cc_SetSpeed(speed,0,0);
2016 return (i);
2019 static void switch_drive(int i);
2021 static int sbpcd_select_speed(struct cdrom_device_info *cdi, int speed)
2023 int i = MINOR(cdi->dev);
2025 if (i != d)
2026 switch_drive(i);
2028 return cc_SetSpeed(speed == 2 ? speed_300 : speed_150, 0, 0);
2031 /*==========================================================================*/
2032 static int DriveReset(void)
2034 int i;
2036 i=cc_DriveReset();
2037 if (i<0) return (-22);
2040 i=GetStatus();
2041 if ((i<0)&&(i!=-ERR_DISKCHANGE)) return (-2); /* from sta2err */
2042 if (!st_caddy_in) break;
2043 sbp_sleep(1);
2045 while (!st_diskok);
2046 #if 000
2047 D_S[d].CD_changed=1;
2048 #endif
2049 if ((st_door_closed) && (st_caddy_in))
2051 i=DiskInfo();
2052 if (i<0) return (-23);
2054 return (0);
2057 static int sbpcd_reset(struct cdrom_device_info *cdi)
2059 int i = MINOR(cdi->dev);
2061 if (i != d)
2062 switch_drive(i);
2064 return DriveReset();
2067 /*==========================================================================*/
2068 static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
2070 int i, j, n;
2072 if (D_S[d].audio_state==audio_playing) return (-EINVAL);
2073 clr_cmdbuf();
2074 response_count=0;
2075 if (famLV_drive)
2077 drvcmd[0]=CMDL_PLAY;
2078 i=msf2blk(pos_audio_start);
2079 n=msf2blk(pos_audio_end)+1-i;
2080 drvcmd[1]=(i>>16)&0x00FF;
2081 drvcmd[2]=(i>>8)&0x00FF;
2082 drvcmd[3]=i&0x00FF;
2083 drvcmd[4]=(n>>16)&0x00FF;
2084 drvcmd[5]=(n>>8)&0x00FF;
2085 drvcmd[6]=n&0x00FF;
2086 if (famL_drive)
2087 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
2088 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
2089 else
2090 flags_cmd_out = f_putcmd;
2092 else
2094 j=1;
2095 if (fam1_drive)
2097 drvcmd[0]=CMD1_PLAY_MSF;
2098 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
2099 f_obey_p_check | f_wait_if_busy;
2101 else if (fam2_drive)
2103 drvcmd[0]=CMD2_PLAY_MSF;
2104 flags_cmd_out = f_putcmd | f_ResponseStatus | f_obey_p_check;
2106 else if (famT_drive)
2108 drvcmd[0]=CMDT_PLAY_MSF;
2109 j=3;
2110 response_count=1;
2112 else if (fam0_drive)
2114 drvcmd[0]=CMD0_PLAY_MSF;
2115 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
2116 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
2118 drvcmd[j]=(pos_audio_start>>16)&0x00FF;
2119 drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
2120 drvcmd[j+2]=pos_audio_start&0x00FF;
2121 drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
2122 drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
2123 drvcmd[j+5]=pos_audio_end&0x00FF;
2125 i=cmd_out();
2126 return (i);
2128 /*==========================================================================*/
2129 static int cc_Pause_Resume(int pau_res)
2131 int i;
2133 clr_cmdbuf();
2134 response_count=0;
2135 if (fam1_drive)
2137 drvcmd[0]=CMD1_PAU_RES;
2138 if (pau_res!=1) drvcmd[1]=0x80;
2139 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2141 else if (fam2_drive)
2143 drvcmd[0]=CMD2_PAU_RES;
2144 if (pau_res!=1) drvcmd[2]=0x01;
2145 flags_cmd_out=f_putcmd|f_ResponseStatus;
2147 else if (fam0LV_drive)
2149 drvcmd[0]=CMD0_PAU_RES;
2150 if (pau_res!=1) drvcmd[1]=0x80;
2151 if (famL_drive)
2152 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2153 f_obey_p_check|f_bit1;
2154 else if (famV_drive)
2155 flags_cmd_out=f_putcmd;
2156 else
2157 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2158 f_obey_p_check;
2160 else if (famT_drive)
2162 if (pau_res==3) return (cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end));
2163 else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
2164 else return (-56);
2166 i=cmd_out();
2167 return (i);
2169 /*==========================================================================*/
2170 static int cc_LockDoor(char lock)
2172 int i;
2174 if (fam0_drive) return (0);
2175 msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, d);
2176 msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
2177 clr_cmdbuf();
2178 response_count=0;
2179 if (fam1_drive)
2181 drvcmd[0]=CMD1_LOCK_CTL;
2182 if (lock==1) drvcmd[1]=0x01;
2183 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2185 else if (fam2_drive)
2187 drvcmd[0]=CMD2_LOCK_CTL;
2188 if (lock==1) drvcmd[4]=0x01;
2189 flags_cmd_out=f_putcmd|f_ResponseStatus;
2191 else if (famLV_drive)
2193 drvcmd[0]=CMDL_LOCK_CTL;
2194 if (lock==1) drvcmd[1]=0x01;
2195 if (famL_drive)
2196 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
2197 else
2198 flags_cmd_out=f_putcmd;
2200 else if (famT_drive)
2202 drvcmd[0]=CMDT_LOCK_CTL;
2203 if (lock==1) drvcmd[4]=0x01;
2205 i=cmd_out();
2206 msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
2207 return (i);
2209 /*==========================================================================*/
2210 /*==========================================================================*/
2211 static int UnLockDoor(void)
2213 int i,j;
2215 j=20;
2218 i=cc_LockDoor(0);
2219 --j;
2220 sbp_sleep(1);
2222 while ((i<0)&&(j));
2223 if (i<0)
2225 cc_DriveReset();
2226 return -84;
2228 return (0);
2230 /*==========================================================================*/
2231 static int LockDoor(void)
2233 int i,j;
2235 j=20;
2238 i=cc_LockDoor(1);
2239 --j;
2240 sbp_sleep(1);
2242 while ((i<0)&&(j));
2243 if (j==0)
2245 cc_DriveReset();
2246 j=20;
2249 i=cc_LockDoor(1);
2250 --j;
2251 sbp_sleep(1);
2253 while ((i<0)&&(j));
2255 return (i);
2258 static int sbpcd_lock_door(struct cdrom_device_info *cdi, int lock)
2260 return lock ? LockDoor() : UnLockDoor();
2263 /*==========================================================================*/
2264 static int cc_CloseTray(void)
2266 int i;
2268 if (fam0_drive) return (0);
2269 msg(DBG_LCK,"cc_CloseTray (drive %d)\n", d);
2270 msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
2272 clr_cmdbuf();
2273 response_count=0;
2274 if (fam1_drive)
2276 drvcmd[0]=CMD1_TRAY_CTL;
2277 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2279 else if (fam2_drive)
2281 drvcmd[0]=CMD2_TRAY_CTL;
2282 drvcmd[1]=0x01;
2283 drvcmd[4]=0x03; /* "insert" */
2284 flags_cmd_out=f_putcmd|f_ResponseStatus;
2286 else if (famLV_drive)
2288 drvcmd[0]=CMDL_TRAY_CTL;
2289 if (famLV_drive)
2290 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
2291 f_ResponseStatus|f_obey_p_check|f_bit1;
2292 else
2293 flags_cmd_out=f_putcmd;
2295 else if (famT_drive)
2297 drvcmd[0]=CMDT_TRAY_CTL;
2298 drvcmd[4]=0x03; /* "insert" */
2300 i=cmd_out();
2301 msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
2303 i=cc_ReadError();
2304 flags_cmd_out |= f_respo2;
2305 cc_ReadStatus(); /* command: give 1-byte status */
2306 i=ResponseStatus();
2307 if (famT_drive&&(i<0))
2309 cc_DriveReset();
2310 i=ResponseStatus();
2311 #if 0
2312 sbp_sleep(HZ);
2313 #endif 0
2314 i=ResponseStatus();
2316 if (i<0)
2318 msg(DBG_INF,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i);
2320 if (!(famT_drive))
2322 if (!st_spinning)
2324 cc_SpinUp();
2325 if (st_check) i=cc_ReadError();
2326 flags_cmd_out |= f_respo2;
2327 cc_ReadStatus();
2328 i=ResponseStatus();
2329 } else {
2332 i=DiskInfo();
2333 return (i);
2336 static int sbpcd_tray_move(struct cdrom_device_info *cdi, int position)
2338 int i;
2339 i = MINOR(cdi->dev);
2341 switch_drive(i);
2342 if (position == 1) {
2343 cc_SpinDown();
2344 } else {
2345 return cc_CloseTray();
2347 return 0;
2350 /*==========================================================================*/
2351 static int cc_ReadSubQ(void)
2353 int i,j;
2355 D_S[d].diskstate_flags &= ~subq_bit;
2356 for (j=255;j>0;j--)
2358 clr_cmdbuf();
2359 if (fam1_drive)
2361 drvcmd[0]=CMD1_READSUBQ;
2362 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2363 response_count=11;
2365 else if (fam2_drive)
2367 drvcmd[0]=CMD2_READSUBQ;
2368 drvcmd[1]=0x02;
2369 drvcmd[3]=0x01;
2370 flags_cmd_out=f_putcmd;
2371 response_count=10;
2373 else if (fam0LV_drive)
2375 drvcmd[0]=CMD0_READSUBQ;
2376 drvcmd[1]=0x02;
2377 if (famLV_drive)
2378 flags_cmd_out=f_putcmd;
2379 else
2380 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2381 response_count=13;
2383 else if (famT_drive)
2385 response_count=12;
2386 drvcmd[0]=CMDT_READSUBQ;
2387 drvcmd[1]=0x02;
2388 drvcmd[2]=0x40;
2389 drvcmd[3]=0x01;
2390 drvcmd[8]=response_count;
2392 i=cmd_out();
2393 if (i<0) return (i);
2394 for (i=0;i<response_count;i++)
2396 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2397 msgbuf[i*3]=0;
2398 msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
2400 if (famT_drive) break;
2401 if (infobuf[0]!=0) break;
2402 if ((!st_spinning) || (j==1))
2404 D_S[d].SubQ_ctl_adr=D_S[d].SubQ_trk=D_S[d].SubQ_pnt_idx=D_S[d].SubQ_whatisthis=0;
2405 D_S[d].SubQ_run_tot=D_S[d].SubQ_run_trk=0;
2406 return (0);
2409 if (famT_drive) D_S[d].SubQ_ctl_adr=infobuf[1];
2410 else D_S[d].SubQ_ctl_adr=swap_nibbles(infobuf[1]);
2411 D_S[d].SubQ_trk=byt2bcd(infobuf[2]);
2412 D_S[d].SubQ_pnt_idx=byt2bcd(infobuf[3]);
2413 if (fam0LV_drive) i=5;
2414 else if (fam12_drive) i=4;
2415 else if (famT_drive) i=8;
2416 D_S[d].SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
2417 i=7;
2418 if (fam0LV_drive) i=9;
2419 else if (fam12_drive) i=7;
2420 else if (famT_drive) i=4;
2421 D_S[d].SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
2422 D_S[d].SubQ_whatisthis=infobuf[i+3];
2423 D_S[d].diskstate_flags |= subq_bit;
2424 return (0);
2426 /*==========================================================================*/
2427 static int cc_ModeSense(void)
2429 int i;
2431 if (fam2_drive) return (0);
2432 if (famV_drive) return (0);
2433 D_S[d].diskstate_flags &= ~frame_size_bit;
2434 clr_cmdbuf();
2435 if (fam1_drive)
2437 response_count=5;
2438 drvcmd[0]=CMD1_GETMODE;
2439 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2441 else if (fam0L_drive)
2443 response_count=2;
2444 drvcmd[0]=CMD0_GETMODE;
2445 if (famL_drive) flags_cmd_out=f_putcmd;
2446 else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2448 else if (famT_drive)
2450 response_count=10;
2451 drvcmd[0]=CMDT_GETMODE;
2452 drvcmd[4]=response_count;
2454 i=cmd_out();
2455 if (i<0) return (i);
2456 i=0;
2457 D_S[d].sense_byte=0;
2458 if (fam1_drive) D_S[d].sense_byte=infobuf[i++];
2459 else if (famT_drive)
2461 if (infobuf[4]==0x01) D_S[d].xa_byte=0x20;
2462 else D_S[d].xa_byte=0;
2463 i=2;
2465 D_S[d].frame_size=make16(infobuf[i],infobuf[i+1]);
2466 for (i=0;i<response_count;i++)
2467 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2468 msgbuf[i*3]=0;
2469 msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
2471 D_S[d].diskstate_flags |= frame_size_bit;
2472 return (0);
2474 /*==========================================================================*/
2475 /*==========================================================================*/
2476 static int cc_ModeSelect(int framesize)
2478 int i;
2480 if (fam2_drive) return (0);
2481 if (famV_drive) return (0);
2482 D_S[d].diskstate_flags &= ~frame_size_bit;
2483 clr_cmdbuf();
2484 D_S[d].frame_size=framesize;
2485 if (framesize==CD_FRAMESIZE_RAW) D_S[d].sense_byte=0x82;
2486 else D_S[d].sense_byte=0x00;
2488 msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
2489 D_S[d].sense_byte, D_S[d].frame_size);
2491 if (fam1_drive)
2493 drvcmd[0]=CMD1_SETMODE;
2494 drvcmd[1]=0x00;
2495 drvcmd[2]=D_S[d].sense_byte;
2496 drvcmd[3]=(D_S[d].frame_size>>8)&0xFF;
2497 drvcmd[4]=D_S[d].frame_size&0xFF;
2498 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2500 else if (fam0L_drive)
2502 drvcmd[0]=CMD0_SETMODE;
2503 drvcmd[1]=0x00;
2504 drvcmd[2]=(D_S[d].frame_size>>8)&0xFF;
2505 drvcmd[3]=D_S[d].frame_size&0xFF;
2506 drvcmd[4]=0x00;
2507 if(famL_drive)
2508 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
2509 else
2510 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2512 else if (famT_drive)
2514 return (-1);
2516 response_count=0;
2517 i=cmd_out();
2518 if (i<0) return (i);
2519 D_S[d].diskstate_flags |= frame_size_bit;
2520 return (0);
2522 /*==========================================================================*/
2523 static int cc_GetVolume(void)
2525 int i;
2526 u_char switches;
2527 u_char chan0=0;
2528 u_char vol0=0;
2529 u_char chan1=1;
2530 u_char vol1=0;
2532 if (famV_drive) return (0);
2533 D_S[d].diskstate_flags &= ~volume_bit;
2534 clr_cmdbuf();
2535 if (fam1_drive)
2537 drvcmd[0]=CMD1_GETMODE;
2538 drvcmd[1]=0x05;
2539 response_count=5;
2540 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2542 else if (fam2_drive)
2544 drvcmd[0]=CMD2_GETMODE;
2545 drvcmd[1]=0x0E;
2546 response_count=5;
2547 flags_cmd_out=f_putcmd;
2549 else if (fam0L_drive)
2551 drvcmd[0]=CMD0_GETMODE;
2552 drvcmd[1]=0x03;
2553 response_count=2;
2554 if(famL_drive)
2555 flags_cmd_out=f_putcmd;
2556 else
2557 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2559 else if (famT_drive)
2561 i=cc_get_mode_T();
2562 if (i<0) return (i);
2564 if (!famT_drive)
2566 i=cmd_out();
2567 if (i<0) return (i);
2569 if (fam1_drive)
2571 chan0=infobuf[1]&0x0F;
2572 vol0=infobuf[2];
2573 chan1=infobuf[3]&0x0F;
2574 vol1=infobuf[4];
2575 if (chan0==0)
2577 chan0=1;
2578 vol0=0;
2580 if (chan1==0)
2582 chan1=2;
2583 vol1=0;
2585 chan0 >>= 1;
2586 chan1 >>= 1;
2588 else if (fam2_drive)
2590 chan0=infobuf[1];
2591 vol0=infobuf[2];
2592 chan1=infobuf[3];
2593 vol1=infobuf[4];
2595 else if (famL_drive)
2597 chan0=0;
2598 chan1=1;
2599 vol0=vol1=infobuf[1];
2600 switches=infobuf[0];
2601 if ((switches&0x80)!=0) chan0=1;
2602 if ((switches&0x40)!=0) chan1=0;
2604 else if (fam0_drive) /* different firmware levels */
2606 chan0=0;
2607 chan1=1;
2608 vol0=vol1=infobuf[1];
2609 if (D_S[d].drv_type>=drv_201)
2611 if (D_S[d].drv_type<drv_300)
2613 switches=infobuf[0];
2614 if ((switches&0x80)!=0) vol0=0;
2615 if ((switches&0x40)!=0) vol1=0;
2616 if (D_S[d].drv_type>=drv_211)
2618 if ((switches&0x20)!=0) chan0=1;
2619 if ((switches&0x10)!=0) chan1=0;
2622 else
2624 vol0=infobuf[0];
2625 if ((vol0&0x01)!=0) chan0=1;
2626 if ((vol1&0x01)==0) chan1=0;
2627 vol0 &= 0xFC;
2628 vol1 &= 0xFC;
2629 if (vol0!=0) vol0 += 3;
2630 if (vol1!=0) vol1 += 3;
2634 else if (famT_drive)
2636 D_S[d].volume_control=infobuf[7];
2637 chan0=0;
2638 chan1=1;
2639 if (D_S[d].volume_control&0x10) vol0=0;
2640 else vol0=0xff;
2641 if (D_S[d].volume_control&0x20) vol1=0;
2642 else vol1=0xff;
2644 D_S[d].vol_chan0=chan0;
2645 D_S[d].vol_ctrl0=vol0;
2646 D_S[d].vol_chan1=chan1;
2647 D_S[d].vol_ctrl1=vol1;
2648 #if 000
2649 D_S[d].vol_chan2=2;
2650 D_S[d].vol_ctrl2=0xFF;
2651 D_S[d].vol_chan3=3;
2652 D_S[d].vol_ctrl3=0xFF;
2653 #endif 000
2654 D_S[d].diskstate_flags |= volume_bit;
2655 return (0);
2657 /*==========================================================================*/
2658 static int cc_ReadCapacity(void)
2660 int i, j;
2662 if (fam2_drive) return (0); /* some firmware lacks this command */
2663 if (famLV_drive) return (0); /* some firmware lacks this command */
2664 if (famT_drive) return (0); /* done with cc_ReadTocDescr() */
2665 D_S[d].diskstate_flags &= ~cd_size_bit;
2666 for (j=3;j>0;j--)
2668 clr_cmdbuf();
2669 if (fam1_drive)
2671 drvcmd[0]=CMD1_CAPACITY;
2672 response_count=5;
2673 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2675 #if 00
2676 else if (fam2_drive)
2678 drvcmd[0]=CMD2_CAPACITY;
2679 response_count=8;
2680 flags_cmd_out=f_putcmd;
2682 #endif
2683 else if (fam0_drive)
2685 drvcmd[0]=CMD0_CAPACITY;
2686 response_count=5;
2687 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2689 i=cmd_out();
2690 if (i>=0) break;
2691 msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
2692 cc_ReadError();
2694 if (j==0) return (i);
2695 if (fam1_drive) D_S[d].CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_MSF_OFFSET;
2696 else if (fam0_drive) D_S[d].CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
2697 #if 00
2698 else if (fam2_drive) D_S[d].CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
2699 #endif
2700 D_S[d].diskstate_flags |= cd_size_bit;
2701 msg(DBG_000,"cc_ReadCapacity: %d frames.\n", D_S[d].CDsize_frm);
2702 return (0);
2704 /*==========================================================================*/
2705 static int cc_ReadTocDescr(void)
2707 int i;
2709 D_S[d].diskstate_flags &= ~toc_bit;
2710 clr_cmdbuf();
2711 if (fam1_drive)
2713 drvcmd[0]=CMD1_DISKINFO;
2714 response_count=6;
2715 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2717 else if (fam0LV_drive)
2719 drvcmd[0]=CMD0_DISKINFO;
2720 response_count=6;
2721 if(famLV_drive)
2722 flags_cmd_out=f_putcmd;
2723 else
2724 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2726 else if (fam2_drive)
2728 /* possibly longer timeout periods necessary */
2729 D_S[d].f_multisession=0;
2730 drvcmd[0]=CMD2_DISKINFO;
2731 drvcmd[1]=0x02;
2732 drvcmd[2]=0xAB;
2733 drvcmd[3]=0xFF; /* session */
2734 response_count=8;
2735 flags_cmd_out=f_putcmd;
2737 else if (famT_drive)
2739 D_S[d].f_multisession=0;
2740 response_count=12;
2741 drvcmd[0]=CMDT_DISKINFO;
2742 drvcmd[1]=0x02;
2743 drvcmd[6]=CDROM_LEADOUT;
2744 drvcmd[8]=response_count;
2745 drvcmd[9]=0x00;
2747 i=cmd_out();
2748 if (i<0) return (i);
2749 if ((famT_drive)&&(i<response_count)) return (-100-i);
2750 if ((fam1_drive)||(fam2_drive)||(fam0LV_drive))
2751 D_S[d].xa_byte=infobuf[0];
2752 if (fam2_drive)
2754 D_S[d].first_session=infobuf[1];
2755 D_S[d].last_session=infobuf[2];
2756 D_S[d].n_first_track=infobuf[3];
2757 D_S[d].n_last_track=infobuf[4];
2758 if (D_S[d].first_session!=D_S[d].last_session)
2760 D_S[d].f_multisession=1;
2761 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
2763 #if 0
2764 if (D_S[d].first_session!=D_S[d].last_session)
2766 if (D_S[d].last_session<=20)
2767 zwanzig=D_S[d].last_session+1;
2768 else zwanzig=20;
2769 for (count=D_S[d].first_session;count<zwanzig;count++)
2771 drvcmd[0]=CMD2_DISKINFO;
2772 drvcmd[1]=0x02;
2773 drvcmd[2]=0xAB;
2774 drvcmd[3]=count;
2775 response_count=8;
2776 flags_cmd_out=f_putcmd;
2777 i=cmd_out();
2778 if (i<0) return (i);
2779 D_S[d].msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
2781 D_S[d].diskstate_flags |= multisession_bit;
2783 #endif
2784 drvcmd[0]=CMD2_DISKINFO;
2785 drvcmd[1]=0x02;
2786 drvcmd[2]=0xAA;
2787 drvcmd[3]=0xFF;
2788 response_count=5;
2789 flags_cmd_out=f_putcmd;
2790 i=cmd_out();
2791 if (i<0) return (i);
2792 D_S[d].size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
2793 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2794 D_S[d].CDsize_frm=D_S[d].size_blk+1;
2796 else if (famT_drive)
2798 D_S[d].size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
2799 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2800 D_S[d].CDsize_frm=D_S[d].size_blk+1;
2801 D_S[d].n_first_track=infobuf[2];
2802 D_S[d].n_last_track=infobuf[3];
2804 else
2806 D_S[d].n_first_track=infobuf[1];
2807 D_S[d].n_last_track=infobuf[2];
2808 D_S[d].size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
2809 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2810 if (famLV_drive) D_S[d].CDsize_frm=D_S[d].size_blk+1;
2812 D_S[d].diskstate_flags |= toc_bit;
2813 msg(DBG_TOC,"TocDesc: xa %02X firstt %02X lastt %02X size %08X firstses %02X lastsess %02X\n",
2814 D_S[d].xa_byte,
2815 D_S[d].n_first_track,
2816 D_S[d].n_last_track,
2817 D_S[d].size_msf,
2818 D_S[d].first_session,
2819 D_S[d].last_session);
2820 return (0);
2822 /*==========================================================================*/
2823 static int cc_ReadTocEntry(int num)
2825 int i;
2827 clr_cmdbuf();
2828 if (fam1_drive)
2830 drvcmd[0]=CMD1_READTOC;
2831 drvcmd[2]=num;
2832 response_count=8;
2833 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2835 else if (fam2_drive)
2837 /* possibly longer timeout periods necessary */
2838 drvcmd[0]=CMD2_DISKINFO;
2839 drvcmd[1]=0x02;
2840 drvcmd[2]=num;
2841 response_count=5;
2842 flags_cmd_out=f_putcmd;
2844 else if (fam0LV_drive)
2846 drvcmd[0]=CMD0_READTOC;
2847 drvcmd[1]=0x02;
2848 drvcmd[2]=num;
2849 response_count=8;
2850 if (famLV_drive)
2851 flags_cmd_out=f_putcmd;
2852 else
2853 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2855 else if (famT_drive)
2857 response_count=12;
2858 drvcmd[0]=CMDT_DISKINFO;
2859 drvcmd[1]=0x02;
2860 drvcmd[6]=num;
2861 drvcmd[8]=response_count;
2862 drvcmd[9]=0x00;
2864 i=cmd_out();
2865 if (i<0) return (i);
2866 if ((famT_drive)&&(i<response_count)) return (-100-i);
2867 if ((fam1_drive)||(fam0LV_drive))
2869 D_S[d].TocEnt_nixbyte=infobuf[0];
2870 i=1;
2872 else if (fam2_drive) i=0;
2873 else if (famT_drive) i=5;
2874 D_S[d].TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
2875 if ((fam1_drive)||(fam0L_drive))
2877 D_S[d].TocEnt_number=infobuf[i++];
2878 D_S[d].TocEnt_format=infobuf[i];
2880 else
2882 D_S[d].TocEnt_number=num;
2883 D_S[d].TocEnt_format=0;
2885 if (fam1_drive) i=4;
2886 else if (fam0LV_drive) i=5;
2887 else if (fam2_drive) i=2;
2888 else if (famT_drive) i=9;
2889 D_S[d].TocEnt_address=make32(make16(0,infobuf[i]),
2890 make16(infobuf[i+1],infobuf[i+2]));
2891 for (i=0;i<response_count;i++)
2892 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2893 msgbuf[i*3]=0;
2894 msg(DBG_ECS,"TocEntry:%s\n", msgbuf);
2895 msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
2896 D_S[d].TocEnt_nixbyte, D_S[d].TocEnt_ctl_adr,
2897 D_S[d].TocEnt_number, D_S[d].TocEnt_format,
2898 D_S[d].TocEnt_address);
2899 return (0);
2901 /*==========================================================================*/
2902 static int cc_ReadPacket(void)
2904 int i;
2906 clr_cmdbuf();
2907 drvcmd[0]=CMD0_PACKET;
2908 drvcmd[1]=response_count;
2909 if(famL_drive) flags_cmd_out=f_putcmd;
2910 else if (fam01_drive)
2911 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2912 else if (fam2_drive) return (-1); /* not implemented yet */
2913 else if (famT_drive)
2915 return (-1);
2917 i=cmd_out();
2918 return (i);
2920 /*==========================================================================*/
2921 static int convert_UPC(u_char *p)
2923 int i;
2925 p++;
2926 if (fam0L_drive) p[13]=0;
2927 for (i=0;i<7;i++)
2929 if (fam1_drive) D_S[d].UPC_buf[i]=swap_nibbles(*p++);
2930 else if (fam0L_drive)
2932 D_S[d].UPC_buf[i]=((*p++)<<4)&0xFF;
2933 D_S[d].UPC_buf[i] |= *p++;
2935 else if (famT_drive)
2937 return (-1);
2939 else /* CD200 */
2941 return (-1);
2944 D_S[d].UPC_buf[6] &= 0xF0;
2945 return (0);
2947 /*==========================================================================*/
2948 static int cc_ReadUPC(void)
2950 int i;
2951 #if TEST_UPC
2952 int block, checksum;
2953 #endif TEST_UPC
2955 if (fam2_drive) return (0); /* not implemented yet */
2956 if (famT_drive) return (0); /* not implemented yet */
2957 if (famV_drive) return (0); /* not implemented yet */
2958 #if 1
2959 if (fam0_drive) return (0); /* but it should work */
2960 #endif 1
2962 D_S[d].diskstate_flags &= ~upc_bit;
2963 #if TEST_UPC
2964 for (block=CD_MSF_OFFSET+1;block<CD_MSF_OFFSET+200;block++)
2966 #endif TEST_UPC
2967 clr_cmdbuf();
2968 if (fam1_drive)
2970 drvcmd[0]=CMD1_READ_UPC;
2971 #if TEST_UPC
2972 drvcmd[1]=(block>>16)&0xFF;
2973 drvcmd[2]=(block>>8)&0xFF;
2974 drvcmd[3]=block&0xFF;
2975 #endif TEST_UPC
2976 response_count=8;
2977 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2979 else if (fam0L_drive)
2981 drvcmd[0]=CMD0_READ_UPC;
2982 #if TEST_UPC
2983 drvcmd[2]=(block>>16)&0xFF;
2984 drvcmd[3]=(block>>8)&0xFF;
2985 drvcmd[4]=block&0xFF;
2986 #endif TEST_UPC
2987 response_count=0;
2988 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
2990 else if (fam2_drive)
2992 return (-1);
2994 else if (famT_drive)
2996 return (-1);
2998 i=cmd_out();
2999 if (i<0)
3001 msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
3002 return (i);
3004 if (fam0L_drive)
3006 response_count=16;
3007 if (famL_drive) flags_cmd_out=f_putcmd;
3008 i=cc_ReadPacket();
3009 if (i<0)
3011 msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
3012 return (i);
3015 #if TEST_UPC
3016 checksum=0;
3017 #endif TEST_UPC
3018 for (i=0;i<(fam1_drive?8:16);i++)
3020 #if TEST_UPC
3021 checksum |= infobuf[i];
3022 #endif TEST_UPC
3023 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3025 msgbuf[i*3]=0;
3026 msg(DBG_UPC,"UPC info:%s\n", msgbuf);
3027 #if TEST_UPC
3028 if ((checksum&0x7F)!=0) break;
3030 #endif TEST_UPC
3031 D_S[d].UPC_ctl_adr=0;
3032 if (fam1_drive) i=0;
3033 else i=2;
3034 if ((infobuf[i]&0x80)!=0)
3036 convert_UPC(&infobuf[i]);
3037 D_S[d].UPC_ctl_adr = (D_S[d].TocEnt_ctl_adr & 0xF0) | 0x02;
3039 for (i=0;i<7;i++)
3040 sprintf(&msgbuf[i*3], " %02X", D_S[d].UPC_buf[i]);
3041 sprintf(&msgbuf[i*3], " (%02X)", D_S[d].UPC_ctl_adr);
3042 msgbuf[i*3+5]=0;
3043 msg(DBG_UPC,"UPC code:%s\n", msgbuf);
3044 D_S[d].diskstate_flags |= upc_bit;
3045 return (0);
3048 static int sbpcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
3050 int i;
3051 unsigned char *mcnp = mcn->medium_catalog_number;
3052 unsigned char *resp;
3054 D_S[d].diskstate_flags &= ~upc_bit;
3055 clr_cmdbuf();
3056 if (fam1_drive)
3058 drvcmd[0]=CMD1_READ_UPC;
3059 response_count=8;
3060 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
3062 else if (fam0L_drive)
3064 drvcmd[0]=CMD0_READ_UPC;
3065 response_count=0;
3066 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
3068 else if (fam2_drive)
3070 return (-1);
3072 else if (famT_drive)
3074 return (-1);
3076 i=cmd_out();
3077 if (i<0)
3079 msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
3080 return (i);
3082 if (fam0L_drive)
3084 response_count=16;
3085 if (famL_drive) flags_cmd_out=f_putcmd;
3086 i=cc_ReadPacket();
3087 if (i<0)
3089 msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
3090 return (i);
3093 D_S[d].UPC_ctl_adr=0;
3094 if (fam1_drive) i=0;
3095 else i=2;
3097 resp = infobuf + i;
3098 if (*resp++ == 0x80) {
3099 /* packed bcd to single ASCII digits */
3100 *mcnp++ = (*resp >> 4) + '0';
3101 *mcnp++ = (*resp++ & 0x0f) + '0';
3102 *mcnp++ = (*resp >> 4) + '0';
3103 *mcnp++ = (*resp++ & 0x0f) + '0';
3104 *mcnp++ = (*resp >> 4) + '0';
3105 *mcnp++ = (*resp++ & 0x0f) + '0';
3106 *mcnp++ = (*resp >> 4) + '0';
3107 *mcnp++ = (*resp++ & 0x0f) + '0';
3108 *mcnp++ = (*resp >> 4) + '0';
3109 *mcnp++ = (*resp++ & 0x0f) + '0';
3110 *mcnp++ = (*resp >> 4) + '0';
3111 *mcnp++ = (*resp++ & 0x0f) + '0';
3112 *mcnp++ = (*resp >> 4) + '0';
3114 *mcnp = '\0';
3116 D_S[d].diskstate_flags |= upc_bit;
3117 return (0);
3120 /*==========================================================================*/
3121 static int cc_CheckMultiSession(void)
3123 int i;
3125 if (fam2_drive) return (0);
3126 D_S[d].f_multisession=0;
3127 D_S[d].lba_multi=0;
3128 if (fam0_drive) return (0);
3129 clr_cmdbuf();
3130 if (fam1_drive)
3132 drvcmd[0]=CMD1_MULTISESS;
3133 response_count=6;
3134 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
3135 i=cmd_out();
3136 if (i<0) return (i);
3137 if ((infobuf[0]&0x80)!=0)
3139 D_S[d].f_multisession=1;
3140 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[1]),
3141 make16(infobuf[2],infobuf[3])));
3144 else if (famLV_drive)
3146 drvcmd[0]=CMDL_MULTISESS;
3147 drvcmd[1]=3;
3148 drvcmd[2]=1;
3149 response_count=8;
3150 flags_cmd_out=f_putcmd;
3151 i=cmd_out();
3152 if (i<0) return (i);
3153 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),
3154 make16(infobuf[6],infobuf[7])));
3156 else if (famT_drive)
3158 response_count=12;
3159 drvcmd[0]=CMDT_DISKINFO;
3160 drvcmd[1]=0x02;
3161 drvcmd[6]=0;
3162 drvcmd[8]=response_count;
3163 drvcmd[9]=0x40;
3164 i=cmd_out();
3165 if (i<0) return (i);
3166 if (i<response_count) return (-100-i);
3167 D_S[d].first_session=infobuf[2];
3168 D_S[d].last_session=infobuf[3];
3169 D_S[d].track_of_last_session=infobuf[6];
3170 if (D_S[d].first_session!=D_S[d].last_session)
3172 D_S[d].f_multisession=1;
3173 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
3176 for (i=0;i<response_count;i++)
3177 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3178 msgbuf[i*3]=0;
3179 msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, D_S[d].lba_multi);
3180 if (D_S[d].lba_multi>200)
3182 D_S[d].f_multisession=1;
3183 msg(DBG_MUL,"MultiSession base: %06X\n", D_S[d].lba_multi);
3185 return (0);
3187 /*==========================================================================*/
3188 #if FUTURE
3189 static int cc_SubChanInfo(int frame, int count, u_char *buffer)
3190 /* "frame" is a RED BOOK (msf-bin) address */
3192 int i;
3194 if (fam0LV_drive) return (-ENOSYS); /* drive firmware lacks it */
3195 if (famT_drive)
3197 return (-1);
3199 #if 0
3200 if (D_S[d].audio_state!=audio_playing) return (-ENODATA);
3201 #endif
3202 clr_cmdbuf();
3203 drvcmd[0]=CMD1_SUBCHANINF;
3204 drvcmd[1]=(frame>>16)&0xFF;
3205 drvcmd[2]=(frame>>8)&0xFF;
3206 drvcmd[3]=frame&0xFF;
3207 drvcmd[5]=(count>>8)&0xFF;
3208 drvcmd[6]=count&0xFF;
3209 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
3210 cmd_type=READ_SC;
3211 D_S[d].frame_size=CD_FRAMESIZE_SUB;
3212 i=cmd_out(); /* which buffer to use? */
3213 return (i);
3215 #endif FUTURE
3216 /*==========================================================================*/
3217 __initfunc(static void check_datarate(void))
3219 int i=0;
3221 msg(DBG_IOX,"check_datarate entered.\n");
3222 datarate=0;
3223 #if TEST_STI
3224 for (i=0;i<=1000;i++) printk(".");
3225 #endif
3226 /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
3227 #if 1
3228 del_timer(&delay_timer);
3229 #endif
3230 delay_timer.expires=jiffies+11*HZ/10;
3231 timed_out_delay=0;
3232 add_timer(&delay_timer);
3233 #if 0
3234 msg(DBG_TIM,"delay timer started (11*HZ/10).\n");
3235 #endif
3238 i=inb(CDi_status);
3239 datarate++;
3240 #if 1
3241 if (datarate>0x6FFFFFFF) break;
3242 #endif 00000
3244 while (!timed_out_delay);
3245 del_timer(&delay_timer);
3246 #if 0
3247 msg(DBG_TIM,"datarate: %04X\n", datarate);
3248 #endif
3249 if (datarate<65536) datarate=65536;
3250 maxtim16=datarate*16;
3251 maxtim04=datarate*4;
3252 maxtim02=datarate*2;
3253 maxtim_8=datarate/32;
3254 #if LONG_TIMING
3255 maxtim_data=datarate/100;
3256 #else
3257 maxtim_data=datarate/300;
3258 #endif LONG_TIMING
3259 #if 0
3260 msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8, maxtim_data);
3261 #endif
3263 /*==========================================================================*/
3264 #if 0
3265 static int c2_ReadError(int fam)
3267 int i;
3269 clr_cmdbuf();
3270 response_count=9;
3271 clr_respo_buf(9);
3272 if (fam==1)
3274 drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
3275 i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
3277 else if (fam==2)
3279 drvcmd[0]=CMD2_READ_ERR;
3280 i=do_cmd(f_putcmd);
3282 else return (-1);
3283 return (i);
3285 #endif
3286 /*==========================================================================*/
3287 __initfunc(static void ask_mail(void))
3289 int i;
3291 msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de\n");
3292 msg(DBG_INF, "(don't mail if you are not using the actual kernel):\n");
3293 msg(DBG_INF, "%s\n", VERSION);
3294 msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
3295 CDo_command, type, D_S[d].drive_model, D_S[d].drv_id);
3296 for (i=0;i<12;i++)
3297 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3298 msgbuf[i*3]=0;
3299 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3300 for (i=0;i<12;i++)
3301 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3302 msgbuf[i*3]=0;
3303 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3305 /*==========================================================================*/
3306 __initfunc(static int check_version(void))
3308 int i, j, l;
3309 int teac_possible=0;
3311 msg(DBG_INI,"check_version: id=%d, d=%d.\n", D_S[d].drv_id, d);
3312 D_S[d].drv_type=0;
3314 /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
3315 /* clear any pending error state */
3316 clr_cmdbuf();
3317 drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
3318 response_count=9;
3319 flags_cmd_out=f_putcmd;
3320 i=cmd_out();
3321 if (i<0) msg(DBG_INI,"CMD0_READ_ERR returns %d (ok anyway).\n",i);
3322 /* read drive version */
3323 clr_cmdbuf();
3324 for (i=0;i<12;i++) infobuf[i]=0;
3325 drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
3326 response_count=12; /* fam1: only 11 */
3327 flags_cmd_out=f_putcmd;
3328 i=cmd_out();
3329 if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
3330 if (i==-11) teac_possible++;
3331 j=0;
3332 for (i=0;i<12;i++) j+=infobuf[i];
3333 if (j)
3335 for (i=0;i<12;i++)
3336 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3337 msgbuf[i*3]=0;
3338 msg(DBG_ECS,"infobuf =%s\n", msgbuf);
3339 for (i=0;i<12;i++)
3340 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3341 msgbuf[i*3]=0;
3342 msg(DBG_ECS,"infobuf =%s\n", msgbuf);
3344 for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
3345 if (i==4)
3347 D_S[d].drive_model[0]='C';
3348 D_S[d].drive_model[1]='R';
3349 D_S[d].drive_model[2]='-';
3350 D_S[d].drive_model[3]='5';
3351 D_S[d].drive_model[4]=infobuf[i++];
3352 D_S[d].drive_model[5]=infobuf[i++];
3353 D_S[d].drive_model[6]=0;
3354 D_S[d].drv_type=drv_fam1;
3356 if (!D_S[d].drv_type)
3358 for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
3359 if (i==8)
3361 D_S[d].drive_model[0]='C';
3362 D_S[d].drive_model[1]='R';
3363 D_S[d].drive_model[2]='-';
3364 D_S[d].drive_model[3]='5';
3365 D_S[d].drive_model[4]='2';
3366 D_S[d].drive_model[5]='x';
3367 D_S[d].drive_model[6]=0;
3368 D_S[d].drv_type=drv_fam0;
3371 if (!D_S[d].drv_type)
3373 for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
3374 if (i==8)
3376 for (j=0;j<8;j++)
3377 D_S[d].drive_model[j]=infobuf[j];
3378 D_S[d].drive_model[8]=0;
3379 D_S[d].drv_type=drv_famL;
3382 if (!D_S[d].drv_type)
3384 for (i=0;i<6;i++) if (infobuf[i]!=familyV[i]) break;
3385 if (i==6)
3387 for (j=0;j<6;j++)
3388 D_S[d].drive_model[j]=infobuf[j];
3389 D_S[d].drive_model[6]=0;
3390 D_S[d].drv_type=drv_famV;
3391 i+=2; /* 2 blanks before version */
3394 if (!D_S[d].drv_type)
3396 /* check for CD200 */
3397 clr_cmdbuf();
3398 drvcmd[0]=CMD2_READ_ERR;
3399 response_count=9;
3400 flags_cmd_out=f_putcmd;
3401 i=cmd_out();
3402 if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
3403 if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
3404 /* read drive version */
3405 clr_cmdbuf();
3406 for (i=0;i<12;i++) infobuf[i]=0;
3407 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
3408 #if 0
3409 OUT(CDo_reset,0);
3410 sbp_sleep(6*HZ);
3411 OUT(CDo_enable,D_S[d].drv_sel);
3412 #endif 0
3413 drvcmd[0]=CMD2_READ_VER;
3414 response_count=12;
3415 flags_cmd_out=f_putcmd;
3416 i=cmd_out();
3417 if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
3418 if (i==-7) teac_possible++;
3419 j=0;
3420 for (i=0;i<12;i++) j+=infobuf[i];
3421 if (j)
3423 for (i=0;i<12;i++)
3424 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3425 msgbuf[i*3]=0;
3426 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3427 for (i=0;i<12;i++)
3428 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3429 msgbuf[i*3]=0;
3430 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3432 if (i>=0)
3434 for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
3435 if (i==5)
3437 D_S[d].drive_model[0]='C';
3438 D_S[d].drive_model[1]='D';
3439 D_S[d].drive_model[2]='2';
3440 D_S[d].drive_model[3]='0';
3441 D_S[d].drive_model[4]='0';
3442 D_S[d].drive_model[5]=infobuf[i++];
3443 D_S[d].drive_model[6]=infobuf[i++];
3444 D_S[d].drive_model[7]=0;
3445 D_S[d].drv_type=drv_fam2;
3449 if (!D_S[d].drv_type)
3451 /* check for TEAC CD-55A */
3452 msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
3453 for (j=1;j<=((D_S[d].drv_id==0)?3:1);j++)
3455 for (l=1;l<=((D_S[d].drv_id==0)?10:1);l++)
3457 msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
3458 if (sbpro_type==1) OUT(CDo_reset,0);
3459 else
3461 OUT(CDo_enable,D_S[d].drv_sel);
3462 OUT(CDo_sel_i_d,0);
3463 OUT(CDo_command,CMDT_RESET);
3464 for (i=0;i<9;i++) OUT(CDo_command,0);
3466 sbp_sleep(5*HZ/10);
3467 OUT(CDo_enable,D_S[d].drv_sel);
3468 OUT(CDo_sel_i_d,0);
3469 i=inb(CDi_status);
3470 msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
3471 #if 0
3472 if (i&s_not_result_ready) continue; /* drive not present or ready */
3473 #endif
3474 i=inb(CDi_info);
3475 msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
3476 if (i==0x55) break; /* drive found */
3478 if (i==0x55) break; /* drive found */
3480 if (i==0x55) /* drive found */
3482 msg(DBG_TEA,"TEAC drive found.\n");
3483 clr_cmdbuf();
3484 flags_cmd_out=f_putcmd;
3485 response_count=12;
3486 drvcmd[0]=CMDT_READ_VER;
3487 drvcmd[4]=response_count;
3488 for (i=0;i<12;i++) infobuf[i]=0;
3489 i=cmd_out_T();
3490 if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
3491 for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
3492 if (i==6)
3494 D_S[d].drive_model[0]='C';
3495 D_S[d].drive_model[1]='D';
3496 D_S[d].drive_model[2]='-';
3497 D_S[d].drive_model[3]='5';
3498 D_S[d].drive_model[4]='5';
3499 D_S[d].drive_model[5]=0;
3500 D_S[d].drv_type=drv_famT;
3504 if (!D_S[d].drv_type)
3506 msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,D_S[d].drv_id);
3507 return (-522);
3509 for (j=0;j<4;j++) D_S[d].firmware_version[j]=infobuf[i+j];
3510 if (famL_drive)
3512 u_char lcs_firm_e1[]="A E1";
3513 u_char lcs_firm_f4[]="A4F4";
3515 for (j=0;j<4;j++)
3516 if (D_S[d].firmware_version[j]!=lcs_firm_e1[j]) break;
3517 if (j==4) D_S[d].drv_type=drv_e1;
3519 for (j=0;j<4;j++)
3520 if (D_S[d].firmware_version[j]!=lcs_firm_f4[j]) break;
3521 if (j==4) D_S[d].drv_type=drv_f4;
3523 if (D_S[d].drv_type==drv_famL) ask_mail();
3525 else if (famT_drive)
3527 j=infobuf[4]; /* one-byte version??? - here: 0x15 */
3528 if (j=='5')
3530 D_S[d].firmware_version[0]=infobuf[7];
3531 D_S[d].firmware_version[1]=infobuf[8];
3532 D_S[d].firmware_version[2]=infobuf[10];
3533 D_S[d].firmware_version[3]=infobuf[11];
3535 else
3537 if (j!=0x15) ask_mail();
3538 D_S[d].firmware_version[0]='0';
3539 D_S[d].firmware_version[1]='.';
3540 D_S[d].firmware_version[2]='0'+(j>>4);
3541 D_S[d].firmware_version[3]='0'+(j&0x0f);
3544 else /* CR-52x, CR-56x, CD200, ECS-AT */
3546 j = (D_S[d].firmware_version[0] & 0x0F) * 100 +
3547 (D_S[d].firmware_version[2] & 0x0F) *10 +
3548 (D_S[d].firmware_version[3] & 0x0F);
3549 if (fam0_drive)
3551 if (j<200) D_S[d].drv_type=drv_199;
3552 else if (j<201) D_S[d].drv_type=drv_200;
3553 else if (j<210) D_S[d].drv_type=drv_201;
3554 else if (j<211) D_S[d].drv_type=drv_210;
3555 else if (j<300) D_S[d].drv_type=drv_211;
3556 else if (j>=300) D_S[d].drv_type=drv_300;
3558 else if (fam1_drive)
3560 if (j<100) D_S[d].drv_type=drv_099;
3561 else
3563 D_S[d].drv_type=drv_100;
3564 if ((j!=500)&&(j!=102)) ask_mail();
3567 else if (fam2_drive)
3569 if (D_S[d].drive_model[5]=='F')
3571 if ((j!=1)&&(j!=35)&&(j!=200)&&(j!=210))
3572 ask_mail(); /* unknown version at time */
3574 else
3576 msg(DBG_INF,"this CD200 drive is not fully supported yet - only audio will work.\n");
3577 if ((j!=101)&&(j!=35))
3578 ask_mail(); /* unknown version at time */
3581 else if (famV_drive)
3583 if ((j==100)||(j==150)) D_S[d].drv_type=drv_at;
3584 ask_mail(); /* hopefully we get some feedback by this */
3587 msg(DBG_LCS,"drive type %02X\n",D_S[d].drv_type);
3588 msg(DBG_INI,"check_version done.\n");
3589 return (0);
3591 /*==========================================================================*/
3592 static void switch_drive(int i)
3594 d=i;
3595 OUT(CDo_enable,D_S[d].drv_sel);
3596 msg(DBG_DID,"drive %d (ID=%d) activated.\n", i, D_S[d].drv_id);
3597 return;
3599 /*==========================================================================*/
3600 #ifdef PATH_CHECK
3602 * probe for the presence of an interface card
3604 __initfunc(static int check_card(int port))
3606 #undef N_RESPO
3607 #define N_RESPO 20
3608 int i, j, k;
3609 u_char response[N_RESPO];
3610 u_char save_port0;
3611 u_char save_port3;
3613 msg(DBG_INI,"check_card entered.\n");
3614 save_port0=inb(port+0);
3615 save_port3=inb(port+3);
3617 for (j=0;j<NR_SBPCD;j++)
3619 OUT(port+3,j) ; /* enable drive #j */
3620 OUT(port+0,CMD0_PATH_CHECK);
3621 for (i=10;i>0;i--) OUT(port+0,0);
3622 for (k=0;k<N_RESPO;k++) response[k]=0;
3623 for (k=0;k<N_RESPO;k++)
3625 for (i=10000;i>0;i--)
3627 if (inb(port+1)&s_not_result_ready) continue;
3628 response[k]=inb(port+0);
3629 break;
3632 for (i=0;i<N_RESPO;i++)
3633 sprintf(&msgbuf[i*3], " %02X", response[i]);
3634 msgbuf[i*3]=0;
3635 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3636 OUT(port+0,CMD0_PATH_CHECK);
3637 for (i=10;i>0;i--) OUT(port+0,0);
3638 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3639 for (k=0;k<N_RESPO;k++)
3641 for (i=10000;i>0;i--)
3643 if (inb(port+1)&s_not_result_ready) continue;
3644 response[k]=inb(port+0);
3645 break;
3648 for (i=0;i<N_RESPO;i++)
3649 sprintf(&msgbuf[i*3], " %02X", response[i]);
3650 msgbuf[i*3]=0;
3651 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3653 if (response[0]==0xAA)
3654 if (response[1]==0x55)
3655 return (0);
3657 for (j=0;j<NR_SBPCD;j++)
3659 OUT(port+3,j) ; /* enable drive #j */
3660 OUT(port+0,CMD2_READ_VER);
3661 for (i=10;i>0;i--) OUT(port+0,0);
3662 for (k=0;k<N_RESPO;k++) response[k]=0;
3663 for (k=0;k<N_RESPO;k++)
3665 for (i=1000000;i>0;i--)
3667 if (inb(port+1)&s_not_result_ready) continue;
3668 response[k]=inb(port+0);
3669 break;
3672 for (i=0;i<N_RESPO;i++)
3673 sprintf(&msgbuf[i*3], " %02X", response[i]);
3674 msgbuf[i*3]=0;
3675 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3677 OUT(port+0,CMD2_READ_VER);
3678 for (i=10;i>0;i--) OUT(port+0,0);
3679 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3680 for (k=0;k<N_RESPO;k++)
3682 for (i=1000000;i>0;i--)
3684 if (inb(port+1)&s_not_result_ready) continue;
3685 response[k]=inb(port+0);
3686 break;
3689 for (i=0;i<N_RESPO;i++)
3690 sprintf(&msgbuf[i*3], " %02X", response[i]);
3691 msgbuf[i*3]=0;
3692 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3694 if (response[0]==0xAA)
3695 if (response[1]==0x55)
3696 return (0);
3698 OUT(port+0,save_port0);
3699 OUT(port+3,save_port3);
3700 return (0); /* in any case - no real "function" at time */
3702 #endif PATH_CHECK
3703 /*==========================================================================*/
3704 /*==========================================================================*/
3706 * probe for the presence of drives on the selected controller
3708 __initfunc(static int check_drives(void))
3710 int i, j;
3712 msg(DBG_INI,"check_drives entered.\n");
3713 ndrives=0;
3714 for (j=0;j<MAX_DRIVES;j++)
3716 D_S[ndrives].drv_id=j;
3717 if (sbpro_type==1) D_S[ndrives].drv_sel=(j&0x01)<<1|(j&0x02)>>1;
3718 else D_S[ndrives].drv_sel=j;
3719 switch_drive(ndrives);
3720 msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3721 msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3722 i=check_version();
3723 if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
3724 else
3726 D_S[d].drv_options=drv_pattern[j];
3727 if (fam0L_drive) D_S[d].drv_options&=~(speed_auto|speed_300|speed_150);
3728 msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
3730 D_S[d].drv_id,
3731 D_S[d].drive_model,
3732 D_S[d].firmware_version,
3733 CDo_command,
3734 sbpro_type);
3735 ndrives++;
3738 for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
3739 if (ndrives==0) return (-1);
3740 return (0);
3742 /*==========================================================================*/
3743 #if FUTURE
3745 * obtain if requested service disturbs current audio state
3747 static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
3749 switch (audio_state) /* audio status from controller */
3751 case aud_11: /* "audio play in progress" */
3752 case audx11:
3753 switch (func) /* DOS command code */
3755 case cmd_07: /* input flush */
3756 case cmd_0d: /* open device */
3757 case cmd_0e: /* close device */
3758 case cmd_0c: /* ioctl output */
3759 return (1);
3760 case cmd_03: /* ioctl input */
3761 switch (subfunc)
3762 /* DOS ioctl input subfunction */
3764 case cxi_00:
3765 case cxi_06:
3766 case cxi_09:
3767 return (1);
3768 default:
3769 return (ERROR15);
3771 return (1);
3772 default:
3773 return (ERROR15);
3775 return (1);
3776 case aud_12: /* "audio play paused" */
3777 case audx12:
3778 return (1);
3779 default:
3780 return (2);
3783 /*==========================================================================*/
3784 /* allowed is only
3785 * ioctl_o, flush_input, open_device, close_device,
3786 * tell_address, tell_volume, tell_capabiliti,
3787 * tell_framesize, tell_CD_changed, tell_audio_posi
3789 static int check_allowed1(u_char func1, u_char func2)
3791 #if 000
3792 if (func1==ioctl_o) return (0);
3793 if (func1==read_long) return (-1);
3794 if (func1==read_long_prefetch) return (-1);
3795 if (func1==seek) return (-1);
3796 if (func1==audio_play) return (-1);
3797 if (func1==audio_pause) return (-1);
3798 if (func1==audio_resume) return (-1);
3799 if (func1!=ioctl_i) return (0);
3800 if (func2==tell_SubQ_run_tot) return (-1);
3801 if (func2==tell_cdsize) return (-1);
3802 if (func2==tell_TocDescrip) return (-1);
3803 if (func2==tell_TocEntry) return (-1);
3804 if (func2==tell_subQ_info) return (-1);
3805 if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
3806 if (func2==tell_UPC) return (-1);
3807 #else
3808 return (0);
3809 #endif 000
3811 /*==========================================================================*/
3812 static int check_allowed2(u_char func1, u_char func2)
3814 #if 000
3815 if (func1==read_long) return (-1);
3816 if (func1==read_long_prefetch) return (-1);
3817 if (func1==seek) return (-1);
3818 if (func1==audio_play) return (-1);
3819 if (func1!=ioctl_o) return (0);
3820 if (fam1_drive)
3822 if (func2==EjectDisk) return (-1);
3823 if (func2==CloseTray) return (-1);
3825 #else
3826 return (0);
3827 #endif 000
3829 /*==========================================================================*/
3830 static int check_allowed3(u_char func1, u_char func2)
3832 #if 000
3833 if (func1==ioctl_i)
3835 if (func2==tell_address) return (0);
3836 if (func2==tell_capabiliti) return (0);
3837 if (func2==tell_CD_changed) return (0);
3838 if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
3839 return (-1);
3841 if (func1==ioctl_o)
3843 if (func2==DriveReset) return (0);
3844 if (fam0L_drive)
3846 if (func2==EjectDisk) return (0);
3847 if (func2==LockDoor) return (0);
3848 if (func2==CloseTray) return (0);
3850 return (-1);
3852 if (func1==flush_input) return (-1);
3853 if (func1==read_long) return (-1);
3854 if (func1==read_long_prefetch) return (-1);
3855 if (func1==seek) return (-1);
3856 if (func1==audio_play) return (-1);
3857 if (func1==audio_pause) return (-1);
3858 if (func1==audio_resume) return (-1);
3859 #else
3860 return (0);
3861 #endif 000
3863 /*==========================================================================*/
3864 static int seek_pos_audio_end(void)
3866 int i;
3868 i=msf2blk(D_S[d].pos_audio_end)-1;
3869 if (i<0) return (-1);
3870 i=cc_Seek(i,0);
3871 return (i);
3873 #endif FUTURE
3874 /*==========================================================================*/
3875 static int ReadToC(void)
3877 int i, j;
3878 D_S[d].diskstate_flags &= ~toc_bit;
3879 D_S[d].ored_ctl_adr=0;
3880 /* special handling of CD-I HE */
3881 if ((D_S[d].n_first_track == 2 && D_S[d].n_last_track == 2) ||
3882 D_S[d].xa_byte == 0x10)
3884 D_S[d].TocBuffer[1].nixbyte=0;
3885 D_S[d].TocBuffer[1].ctl_adr=0x40;
3886 D_S[d].TocBuffer[1].number=1;
3887 D_S[d].TocBuffer[1].format=0;
3888 D_S[d].TocBuffer[1].address=blk2msf(0);
3889 D_S[d].ored_ctl_adr |= 0x40;
3890 D_S[d].n_first_track = 1;
3891 D_S[d].n_last_track = 1;
3892 D_S[d].xa_byte = 0x10;
3893 j = 2;
3894 } else
3895 for (j=D_S[d].n_first_track;j<=D_S[d].n_last_track;j++)
3897 i=cc_ReadTocEntry(j);
3898 if (i<0)
3900 msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
3901 return (i);
3903 D_S[d].TocBuffer[j].nixbyte=D_S[d].TocEnt_nixbyte;
3904 D_S[d].TocBuffer[j].ctl_adr=D_S[d].TocEnt_ctl_adr;
3905 D_S[d].TocBuffer[j].number=D_S[d].TocEnt_number;
3906 D_S[d].TocBuffer[j].format=D_S[d].TocEnt_format;
3907 D_S[d].TocBuffer[j].address=D_S[d].TocEnt_address;
3908 D_S[d].ored_ctl_adr |= D_S[d].TocEnt_ctl_adr;
3910 /* fake entry for LeadOut Track */
3911 D_S[d].TocBuffer[j].nixbyte=0;
3912 D_S[d].TocBuffer[j].ctl_adr=0;
3913 D_S[d].TocBuffer[j].number=CDROM_LEADOUT;
3914 D_S[d].TocBuffer[j].format=0;
3915 D_S[d].TocBuffer[j].address=D_S[d].size_msf;
3917 D_S[d].diskstate_flags |= toc_bit;
3918 return (0);
3920 /*==========================================================================*/
3921 static int DiskInfo(void)
3923 int i, j;
3925 D_S[d].mode=READ_M1;
3927 #undef LOOP_COUNT
3928 #define LOOP_COUNT 10 /* needed for some "old" drives */
3930 msg(DBG_000,"DiskInfo entered.\n");
3931 for (j=1;j<LOOP_COUNT;j++)
3933 #if 0
3934 i=SetSpeed();
3935 if (i<0)
3937 msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
3938 continue;
3940 i=cc_ModeSense();
3941 if (i<0)
3943 msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
3944 continue;
3946 #endif
3947 i=cc_ReadCapacity();
3948 if (i>=0) break;
3949 msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
3950 #if 0
3951 i=cc_DriveReset();
3952 #endif
3953 if (!fam0_drive && j == 2) break;
3955 if (j==LOOP_COUNT) return (-33); /* give up */
3957 i=cc_ReadTocDescr();
3958 if (i<0)
3960 msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
3961 return (i);
3963 i=ReadToC();
3964 if (i<0)
3966 msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
3967 return (i);
3969 i=cc_CheckMultiSession();
3970 if (i<0)
3972 msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
3973 return (i);
3975 if (D_S[d].f_multisession) D_S[d].sbp_bufsiz=1; /* possibly a weird PhotoCD */
3976 else D_S[d].sbp_bufsiz=buffers;
3977 i=cc_ReadTocEntry(D_S[d].n_first_track);
3978 if (i<0)
3980 msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
3981 return (i);
3983 i=cc_ReadUPC();
3984 if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
3985 if ((fam0L_drive) && (D_S[d].xa_byte==0x20 || D_S[d].xa_byte == 0x10))
3987 /* XA disk with old drive */
3988 cc_ModeSelect(CD_FRAMESIZE_RAW1);
3989 cc_ModeSense();
3991 if (famT_drive) cc_prep_mode_T();
3992 msg(DBG_000,"DiskInfo done.\n");
3993 return (0);
3996 static int sbpcd_drive_status(struct cdrom_device_info *cdi, int slot_nr)
3998 int st;
4000 if (CDSL_CURRENT != slot_nr) {
4001 /* we have no changer support */
4002 return -EINVAL;
4005 cc_ReadStatus();
4006 st=ResponseStatus();
4007 if (st<0)
4009 msg(DBG_INF,"sbpcd_drive_status: timeout.\n");
4010 return (0);
4012 msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
4013 msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
4014 msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
4015 msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
4016 msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
4017 msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
4018 #if 0
4019 if (!(D_S[MINOR(cdi->dev)].status_bits & p_door_closed)) return CDS_TRAY_OPEN;
4020 if (D_S[MINOR(cdi->dev)].status_bits & p_disk_ok) return CDS_DISC_OK;
4021 if (D_S[MINOR(cdi->dev)].status_bits & p_disk_in) return CDS_DRIVE_NOT_READY;
4023 return CDS_NO_DISC;
4024 #else
4025 if (D_S[MINOR(cdi->dev)].status_bits & p_spinning) return CDS_DISC_OK;
4026 return CDS_TRAY_OPEN;
4027 #endif
4031 /*==========================================================================*/
4032 #if FUTURE
4034 * called always if driver gets entered
4035 * returns 0 or ERROR2 or ERROR15
4037 static int prepare(u_char func, u_char subfunc)
4039 int i;
4041 if (fam0L_drive)
4043 i=inb(CDi_status);
4044 if (i&s_attention) GetStatus();
4046 else if (fam1_drive) GetStatus();
4047 else if (fam2_drive) GetStatus();
4048 else if (famT_drive) GetStatus();
4049 if (D_S[d].CD_changed==0xFF)
4051 D_S[d].diskstate_flags=0;
4052 D_S[d].audio_state=0;
4053 if (!st_diskok)
4055 i=check_allowed1(func,subfunc);
4056 if (i<0) return (-2);
4058 else
4060 i=check_allowed3(func,subfunc);
4061 if (i<0)
4063 D_S[d].CD_changed=1;
4064 return (-15);
4068 else
4070 if (!st_diskok)
4072 D_S[d].diskstate_flags=0;
4073 D_S[d].audio_state=0;
4074 i=check_allowed1(func,subfunc);
4075 if (i<0) return (-2);
4077 else
4079 if (st_busy)
4081 if (D_S[d].audio_state!=audio_pausing)
4083 i=check_allowed2(func,subfunc);
4084 if (i<0) return (-2);
4087 else
4089 if (D_S[d].audio_state==audio_playing) seek_pos_audio_end();
4090 D_S[d].audio_state=0;
4092 if (!frame_size_valid)
4094 i=DiskInfo();
4095 if (i<0)
4097 D_S[d].diskstate_flags=0;
4098 D_S[d].audio_state=0;
4099 i=check_allowed1(func,subfunc);
4100 if (i<0) return (-2);
4105 return (0);
4107 #endif FUTURE
4108 /*==========================================================================*/
4109 /*==========================================================================*/
4111 * Check the results of the "get status" command.
4113 static int sbp_status(void)
4115 int st;
4117 st=ResponseStatus();
4118 if (st<0)
4120 msg(DBG_INF,"sbp_status: timeout.\n");
4121 return (0);
4124 if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
4126 if (st_check)
4128 msg(DBG_INF,"st_check detected - retrying.\n");
4129 return (0);
4131 if (!st_door_closed)
4133 msg(DBG_INF,"door is open - retrying.\n");
4134 return (0);
4136 if (!st_caddy_in)
4138 msg(DBG_INF,"disk removed - retrying.\n");
4139 return (0);
4141 if (!st_diskok)
4143 msg(DBG_INF,"!st_diskok detected - retrying.\n");
4144 return (0);
4146 if (st_busy)
4148 msg(DBG_INF,"st_busy detected - retrying.\n");
4149 return (0);
4151 return (1);
4153 /*==========================================================================*/
4155 static int sbpcd_get_last_session(struct cdrom_device_info *cdi, struct cdrom_multisession *ms_infp)
4157 ms_infp->addr_format = CDROM_LBA;
4158 ms_infp->addr.lba = D_S[MINOR(cdi->dev)].lba_multi;
4159 if (D_S[MINOR(cdi->dev)].f_multisession)
4160 ms_infp->xa_flag=1; /* valid redirection address */
4161 else
4162 ms_infp->xa_flag=0; /* invalid redirection address */
4164 return 0;
4167 /*==========================================================================*/
4168 /*==========================================================================*/
4170 * ioctl support
4172 static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4173 u_long arg)
4175 int i;
4177 msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08lX)\n",
4178 MINOR(cdi->dev), cmd, arg);
4179 i=MINOR(cdi->dev);
4180 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4182 msg(DBG_INF, "ioctl: bad device: %04X\n", cdi->dev);
4183 return (-ENXIO); /* no such drive */
4185 down(&ioctl_read_sem);
4186 if (d!=i) switch_drive(i);
4188 msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
4189 switch (cmd) /* Sun-compatible */
4191 case DDIOCSDBG: /* DDI Debug */
4192 if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
4193 i=sbpcd_dbg_ioctl(arg,1);
4194 RETURN_UP(i);
4195 case CDROMRESET: /* hard reset the drive */
4196 msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
4197 i=DriveReset();
4198 D_S[d].audio_state=0;
4199 RETURN_UP(i);
4201 case CDROMREADMODE1:
4202 msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
4203 #if SAFE_MIXED
4204 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4205 #endif SAFE_MIXED
4206 cc_ModeSelect(CD_FRAMESIZE);
4207 cc_ModeSense();
4208 D_S[d].mode=READ_M1;
4209 RETURN_UP(0);
4211 case CDROMREADMODE2: /* not usable at the moment */
4212 msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
4213 #if SAFE_MIXED
4214 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4215 #endif SAFE_MIXED
4216 cc_ModeSelect(CD_FRAMESIZE_RAW1);
4217 cc_ModeSense();
4218 D_S[d].mode=READ_M2;
4219 RETURN_UP(0);
4221 case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
4222 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
4223 if (D_S[d].sbp_audsiz>0) vfree(D_S[d].aud_buf);
4224 D_S[d].aud_buf=NULL;
4225 D_S[d].sbp_audsiz=arg;
4227 if (D_S[d].sbp_audsiz>0)
4229 D_S[d].aud_buf=(u_char *) vmalloc(D_S[d].sbp_audsiz*CD_FRAMESIZE_RAW);
4230 if (D_S[d].aud_buf==NULL)
4232 msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[d].sbp_audsiz);
4233 D_S[d].sbp_audsiz=0;
4235 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[d].sbp_audsiz);
4237 RETURN_UP(D_S[d].sbp_audsiz);
4239 case CDROMREADAUDIO:
4240 { /* start of CDROMREADAUDIO */
4241 int i=0, j=0, frame, block=0;
4242 u_int try=0;
4243 u_long timeout;
4244 u_char *p;
4245 u_int data_tries = 0;
4246 u_int data_waits = 0;
4247 u_int data_retrying = 0;
4248 int status_tries;
4249 int error_flag;
4251 msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
4252 if (fam0_drive) RETURN_UP(-EINVAL);
4253 if (famL_drive) RETURN_UP(-EINVAL);
4254 if (famV_drive) RETURN_UP(-EINVAL);
4255 if (famT_drive) RETURN_UP(-EINVAL);
4256 #if SAFE_MIXED
4257 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4258 #endif SAFE_MIXED
4259 if (D_S[d].aud_buf==NULL) RETURN_UP(-EINVAL);
4260 i=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_read_audio));
4261 if (i) RETURN_UP(i);
4262 copy_from_user(&read_audio, (void *) arg, sizeof(struct cdrom_read_audio));
4263 if (read_audio.nframes>D_S[d].sbp_audsiz) RETURN_UP(-EINVAL);
4264 i=verify_area(VERIFY_WRITE, read_audio.buf,
4265 read_audio.nframes*CD_FRAMESIZE_RAW);
4266 if (i) RETURN_UP(i);
4268 if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
4269 block=msf2lba(&read_audio.addr.msf.minute);
4270 else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
4271 block=read_audio.addr.lba;
4272 else RETURN_UP(-EINVAL);
4273 #if 000
4274 i=cc_SetSpeed(speed_150,0,0);
4275 if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
4276 #endif
4277 msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
4278 block, blk2msf(block));
4279 msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
4280 #if OLD_BUSY
4281 while (busy_data) sbp_sleep(HZ/10); /* wait a bit */
4282 busy_audio=1;
4283 #endif OLD_BUSY
4284 error_flag=0;
4285 for (data_tries=5; data_tries>0; data_tries--)
4287 msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
4288 D_S[d].mode=READ_AU;
4289 cc_ModeSelect(CD_FRAMESIZE_RAW);
4290 cc_ModeSense();
4291 for (status_tries=3; status_tries > 0; status_tries--)
4293 flags_cmd_out |= f_respo3;
4294 cc_ReadStatus();
4295 if (sbp_status() != 0) break;
4296 if (st_check) cc_ReadError();
4297 sbp_sleep(1); /* wait a bit, try again */
4299 if (status_tries == 0)
4301 msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__);
4302 continue;
4304 msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
4306 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4307 if (fam0L_drive)
4309 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4310 cmd_type=READ_M2;
4311 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
4312 drvcmd[1]=(block>>16)&0x000000ff;
4313 drvcmd[2]=(block>>8)&0x000000ff;
4314 drvcmd[3]=block&0x000000ff;
4315 drvcmd[4]=0;
4316 drvcmd[5]=read_audio.nframes; /* # of frames */
4317 drvcmd[6]=0;
4319 else if (fam1_drive)
4321 drvcmd[0]=CMD1_READ; /* "read frames", new drives */
4322 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4323 drvcmd[4]=0;
4324 drvcmd[5]=0;
4325 drvcmd[6]=read_audio.nframes; /* # of frames */
4327 else if (fam2_drive)
4329 drvcmd[0]=CMD2_READ_XA2;
4330 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4331 drvcmd[4]=0;
4332 drvcmd[5]=read_audio.nframes; /* # of frames */
4333 drvcmd[6]=0x11; /* raw mode */
4335 else if (famT_drive) /* CD-55A: not tested yet */
4338 msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
4339 flags_cmd_out=f_putcmd;
4340 response_count=0;
4341 i=cmd_out();
4342 if (i<0) msg(DBG_INF,"error giving READ AUDIO command: %0d\n", i);
4343 sbp_sleep(0);
4344 msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
4345 for (frame=1;frame<2 && !error_flag; frame++)
4347 try=maxtim_data;
4348 for (timeout=jiffies+9*HZ; ; )
4350 for ( ; try!=0;try--)
4352 j=inb(CDi_status);
4353 if (!(j&s_not_data_ready)) break;
4354 if (!(j&s_not_result_ready)) break;
4355 if (fam0L_drive) if (j&s_attention) break;
4357 if (try != 0 || timeout <= jiffies) break;
4358 if (data_retrying == 0) data_waits++;
4359 data_retrying = 1;
4360 sbp_sleep(1);
4361 try = 1;
4363 if (try==0)
4365 msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
4366 error_flag++;
4367 break;
4369 msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
4370 if (j&s_not_data_ready)
4372 msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
4373 error_flag++;
4374 break;
4376 msg(DBG_AUD,"read_audio: before reading data.\n");
4377 error_flag=0;
4378 p = D_S[d].aud_buf;
4379 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
4380 if (do_16bit)
4382 u_short *p2 = (u_short *) p;
4384 for (; (u_char *) p2 < D_S[d].aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4386 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4388 /* get one sample */
4389 *p2++ = inw_p(CDi_data);
4390 *p2++ = inw_p(CDi_data);
4392 } else {
4393 for (; p < D_S[d].aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4395 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4397 /* get one sample */
4398 *p++ = inb_p(CDi_data);
4399 *p++ = inb_p(CDi_data);
4400 *p++ = inb_p(CDi_data);
4401 *p++ = inb_p(CDi_data);
4404 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
4405 data_retrying = 0;
4407 msg(DBG_AUD,"read_audio: after reading data.\n");
4408 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
4410 msg(DBG_AUD,"read_audio: read aborted by drive\n");
4411 #if 0000
4412 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4413 #else
4414 i=cc_ReadError();
4415 #endif 0000
4416 continue;
4418 if (fam0L_drive)
4420 i=maxtim_data;
4421 for (timeout=jiffies+9*HZ; timeout > jiffies; timeout--)
4423 for ( ;i!=0;i--)
4425 j=inb(CDi_status);
4426 if (!(j&s_not_data_ready)) break;
4427 if (!(j&s_not_result_ready)) break;
4428 if (j&s_attention) break;
4430 if (i != 0 || timeout <= jiffies) break;
4431 sbp_sleep(0);
4432 i = 1;
4434 if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
4435 if (!(j&s_attention))
4437 msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
4438 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4439 continue;
4444 if (fam0L_drive) cc_ReadStatus();
4445 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
4446 if (i<0) { msg(DBG_AUD,
4447 "read_audio: cc_ReadStatus error after read: %02X\n",
4448 D_S[d].status_bits);
4449 continue; /* FIXME */
4452 while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
4453 if (st_check)
4455 i=cc_ReadError();
4456 msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
4457 continue;
4459 copy_to_user((u_char *) read_audio.buf,
4460 (u_char *) D_S[d].aud_buf,
4461 read_audio.nframes*CD_FRAMESIZE_RAW);
4462 msg(DBG_AUD,"read_audio: copy_to_user done.\n");
4463 break;
4465 cc_ModeSelect(CD_FRAMESIZE);
4466 cc_ModeSense();
4467 D_S[d].mode=READ_M1;
4468 #if OLD_BUSY
4469 busy_audio=0;
4470 #endif OLD_BUSY
4471 if (data_tries == 0)
4473 msg(DBG_AUD,"read_audio: failed after 5 tries in line %d.\n", __LINE__);
4474 RETURN_UP(-EIO);
4476 msg(DBG_AUD,"read_audio: successful return.\n");
4477 RETURN_UP(0);
4478 } /* end of CDROMREADAUDIO */
4480 case BLKRASET:
4481 if(!capable(CAP_SYS_ADMIN)) RETURN_UP(-EACCES);
4482 if(!(cdi->dev)) RETURN_UP(-EINVAL);
4483 if(arg > 0xff) RETURN_UP(-EINVAL);
4484 read_ahead[MAJOR(cdi->dev)] = arg;
4485 RETURN_UP(0);
4486 default:
4487 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4488 RETURN_UP(-EINVAL);
4489 } /* end switch(cmd) */
4492 static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4493 void * arg)
4495 int i, st;
4497 msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08p)\n",
4498 MINOR(cdi->dev), cmd, arg);
4499 i=MINOR(cdi->dev);
4500 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4502 msg(DBG_INF, "ioctl: bad device: %04X\n", cdi->dev);
4503 return (-ENXIO); /* no such drive */
4505 down(&ioctl_read_sem);
4506 if (d!=i) switch_drive(i);
4508 msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
4509 switch (cmd) /* Sun-compatible */
4512 case CDROMPAUSE: /* Pause the drive */
4513 msg(DBG_IOC,"ioctl: CDROMPAUSE entered.\n");
4514 /* pause the drive unit when it is currently in PLAY mode, */
4515 /* or reset the starting and ending locations when in PAUSED mode. */
4516 /* If applicable, at the next stopping point it reaches */
4517 /* the drive will discontinue playing. */
4518 switch (D_S[d].audio_state)
4520 case audio_playing:
4521 if (famL_drive) i=cc_ReadSubQ();
4522 else i=cc_Pause_Resume(1);
4523 if (i<0) RETURN_UP(-EIO);
4524 if (famL_drive) i=cc_Pause_Resume(1);
4525 else i=cc_ReadSubQ();
4526 if (i<0) RETURN_UP(-EIO);
4527 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
4528 D_S[d].audio_state=audio_pausing;
4529 RETURN_UP(0);
4530 case audio_pausing:
4531 i=cc_Seek(D_S[d].pos_audio_start,1);
4532 if (i<0) RETURN_UP(-EIO);
4533 RETURN_UP(0);
4534 default:
4535 RETURN_UP(-EINVAL);
4538 case CDROMRESUME: /* resume paused audio play */
4539 msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
4540 /* resume playing audio tracks when a previous PLAY AUDIO call has */
4541 /* been paused with a PAUSE command. */
4542 /* It will resume playing from the location saved in SubQ_run_tot. */
4543 if (D_S[d].audio_state!=audio_pausing) RETURN_UP(-EINVAL);
4544 if (famL_drive)
4545 i=cc_PlayAudio(D_S[d].pos_audio_start,
4546 D_S[d].pos_audio_end);
4547 else i=cc_Pause_Resume(3);
4548 if (i<0) RETURN_UP(-EIO);
4549 D_S[d].audio_state=audio_playing;
4550 RETURN_UP(0);
4552 case CDROMPLAYMSF:
4553 msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
4554 #if SAFE_MIXED
4555 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4556 #endif SAFE_MIXED
4557 if (D_S[d].audio_state==audio_playing)
4559 i=cc_Pause_Resume(1);
4560 if (i<0) RETURN_UP(-EIO);
4561 i=cc_ReadSubQ();
4562 if (i<0) RETURN_UP(-EIO);
4563 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
4564 i=cc_Seek(D_S[d].pos_audio_start,1);
4566 memcpy(&msf, (void *) arg, sizeof(struct cdrom_msf));
4567 /* values come as msf-bin */
4568 D_S[d].pos_audio_start = (msf.cdmsf_min0<<16) |
4569 (msf.cdmsf_sec0<<8) |
4570 msf.cdmsf_frame0;
4571 D_S[d].pos_audio_end = (msf.cdmsf_min1<<16) |
4572 (msf.cdmsf_sec1<<8) |
4573 msf.cdmsf_frame1;
4574 msg(DBG_IOX,"ioctl: CDROMPLAYMSF %08X %08X\n",
4575 D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4576 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4577 if (i<0)
4579 msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
4580 DriveReset();
4581 D_S[d].audio_state=0;
4582 RETURN_UP(-EIO);
4584 D_S[d].audio_state=audio_playing;
4585 RETURN_UP(0);
4587 case CDROMPLAYTRKIND: /* Play a track. This currently ignores index. */
4588 msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
4589 #if SAFE_MIXED
4590 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4591 #endif SAFE_MIXED
4592 if (D_S[d].audio_state==audio_playing)
4594 msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
4595 #if 1
4596 RETURN_UP(0); /* just let us play on */
4597 #else
4598 RETURN_UP(-EINVAL); /* play on, but say "error" */
4599 #endif
4601 memcpy(&ti,(void *) arg,sizeof(struct cdrom_ti));
4602 msg(DBG_IOX,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
4603 ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1);
4604 if (ti.cdti_trk0<D_S[d].n_first_track) RETURN_UP(-EINVAL);
4605 if (ti.cdti_trk0>D_S[d].n_last_track) RETURN_UP(-EINVAL);
4606 if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
4607 if (ti.cdti_trk1>D_S[d].n_last_track) ti.cdti_trk1=D_S[d].n_last_track;
4608 D_S[d].pos_audio_start=D_S[d].TocBuffer[ti.cdti_trk0].address;
4609 D_S[d].pos_audio_end=D_S[d].TocBuffer[ti.cdti_trk1+1].address;
4610 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4611 if (i<0)
4613 msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
4614 DriveReset();
4615 D_S[d].audio_state=0;
4616 RETURN_UP(-EIO);
4618 D_S[d].audio_state=audio_playing;
4619 RETURN_UP(0);
4621 case CDROMREADTOCHDR: /* Read the table of contents header */
4622 msg(DBG_IOC,"ioctl: CDROMREADTOCHDR entered.\n");
4623 tochdr.cdth_trk0=D_S[d].n_first_track;
4624 tochdr.cdth_trk1=D_S[d].n_last_track;
4625 memcpy((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
4626 RETURN_UP(0);
4628 case CDROMREADTOCENTRY: /* Read an entry in the table of contents */
4629 msg(DBG_IOC,"ioctl: CDROMREADTOCENTRY entered.\n");
4630 memcpy(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
4631 i=tocentry.cdte_track;
4632 if (i==CDROM_LEADOUT) i=D_S[d].n_last_track+1;
4633 else if (i<D_S[d].n_first_track||i>D_S[d].n_last_track)
4634 RETURN_UP(-EINVAL);
4635 tocentry.cdte_adr=D_S[d].TocBuffer[i].ctl_adr&0x0F;
4636 tocentry.cdte_ctrl=(D_S[d].TocBuffer[i].ctl_adr>>4)&0x0F;
4637 tocentry.cdte_datamode=D_S[d].TocBuffer[i].format;
4638 if (tocentry.cdte_format==CDROM_MSF) /* MSF-bin required */
4640 tocentry.cdte_addr.msf.minute=(D_S[d].TocBuffer[i].address>>16)&0x00FF;
4641 tocentry.cdte_addr.msf.second=(D_S[d].TocBuffer[i].address>>8)&0x00FF;
4642 tocentry.cdte_addr.msf.frame=D_S[d].TocBuffer[i].address&0x00FF;
4644 else if (tocentry.cdte_format==CDROM_LBA) /* blk required */
4645 tocentry.cdte_addr.lba=msf2blk(D_S[d].TocBuffer[i].address);
4646 else RETURN_UP(-EINVAL);
4647 memcpy((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
4648 RETURN_UP(0);
4650 case CDROMSTOP: /* Spin down the drive */
4651 msg(DBG_IOC,"ioctl: CDROMSTOP entered.\n");
4652 #if SAFE_MIXED
4653 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4654 #endif SAFE_MIXED
4655 i=cc_Pause_Resume(1);
4656 D_S[d].audio_state=0;
4657 #if 0
4658 cc_DriveReset();
4659 #endif
4660 RETURN_UP(i);
4662 case CDROMSTART: /* Spin up the drive */
4663 msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
4664 cc_SpinUp();
4665 D_S[d].audio_state=0;
4666 RETURN_UP(0);
4668 case CDROMVOLCTRL: /* Volume control */
4669 msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
4670 memcpy(&volctrl,(char *) arg,sizeof(volctrl));
4671 D_S[d].vol_chan0=0;
4672 D_S[d].vol_ctrl0=volctrl.channel0;
4673 D_S[d].vol_chan1=1;
4674 D_S[d].vol_ctrl1=volctrl.channel1;
4675 i=cc_SetVolume();
4676 RETURN_UP(0);
4678 case CDROMVOLREAD: /* read Volume settings from drive */
4679 msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
4680 st=cc_GetVolume();
4681 if (st<0) RETURN_UP(st);
4682 volctrl.channel0=D_S[d].vol_ctrl0;
4683 volctrl.channel1=D_S[d].vol_ctrl1;
4684 volctrl.channel2=0;
4685 volctrl.channel2=0;
4686 memcpy((void *)arg,&volctrl,sizeof(volctrl));
4687 RETURN_UP(0);
4689 case CDROMSUBCHNL: /* Get subchannel info */
4690 msg(DBG_IOS,"ioctl: CDROMSUBCHNL entered.\n");
4691 if ((st_spinning)||(!subq_valid)) {
4692 i=cc_ReadSubQ();
4693 if (i<0) RETURN_UP(-EIO);
4695 memcpy(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
4696 switch (D_S[d].audio_state)
4698 case audio_playing:
4699 SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
4700 break;
4701 case audio_pausing:
4702 SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
4703 break;
4704 default:
4705 SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
4706 break;
4708 SC.cdsc_adr=D_S[d].SubQ_ctl_adr;
4709 SC.cdsc_ctrl=D_S[d].SubQ_ctl_adr>>4;
4710 SC.cdsc_trk=bcd2bin(D_S[d].SubQ_trk);
4711 SC.cdsc_ind=bcd2bin(D_S[d].SubQ_pnt_idx);
4712 if (SC.cdsc_format==CDROM_LBA)
4714 SC.cdsc_absaddr.lba=msf2blk(D_S[d].SubQ_run_tot);
4715 SC.cdsc_reladdr.lba=msf2blk(D_S[d].SubQ_run_trk);
4717 else /* not only if (SC.cdsc_format==CDROM_MSF) */
4719 SC.cdsc_absaddr.msf.minute=(D_S[d].SubQ_run_tot>>16)&0x00FF;
4720 SC.cdsc_absaddr.msf.second=(D_S[d].SubQ_run_tot>>8)&0x00FF;
4721 SC.cdsc_absaddr.msf.frame=D_S[d].SubQ_run_tot&0x00FF;
4722 SC.cdsc_reladdr.msf.minute=(D_S[d].SubQ_run_trk>>16)&0x00FF;
4723 SC.cdsc_reladdr.msf.second=(D_S[d].SubQ_run_trk>>8)&0x00FF;
4724 SC.cdsc_reladdr.msf.frame=D_S[d].SubQ_run_trk&0x00FF;
4726 memcpy((void *) arg, &SC, sizeof(struct cdrom_subchnl));
4727 msg(DBG_IOS,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
4728 SC.cdsc_format,SC.cdsc_audiostatus,
4729 SC.cdsc_adr,SC.cdsc_ctrl,
4730 SC.cdsc_trk,SC.cdsc_ind,
4731 SC.cdsc_absaddr,SC.cdsc_reladdr);
4732 RETURN_UP(0);
4734 default:
4735 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4736 RETURN_UP(-EINVAL);
4737 } /* end switch(cmd) */
4739 /*==========================================================================*/
4741 * Take care of the different block sizes between cdrom and Linux.
4743 static void sbp_transfer(struct request *req)
4745 long offs;
4747 while ( (req->nr_sectors > 0) &&
4748 (req->sector/4 >= D_S[d].sbp_first_frame) &&
4749 (req->sector/4 <= D_S[d].sbp_last_frame) )
4751 offs = (req->sector - D_S[d].sbp_first_frame * 4) * 512;
4752 memcpy(req->buffer, D_S[d].sbp_buf + offs, 512);
4753 req->nr_sectors--;
4754 req->sector++;
4755 req->buffer += 512;
4758 /*==========================================================================*/
4760 * special end_request for sbpcd to solve CURRENT==NULL bug. (GTL)
4761 * GTL = Gonzalo Tornaria <tornaria@cmat.edu.uy>
4763 * This is a kludge so we don't need to modify end_request.
4764 * We put the req we take out after INIT_REQUEST in the requests list,
4765 * so that end_request will discard it.
4767 * The bug could be present in other block devices, perhaps we
4768 * should modify INIT_REQUEST and end_request instead, and
4769 * change every block device..
4771 * Could be a race here?? Could e.g. a timer interrupt schedule() us?
4772 * If so, we should copy end_request here, and do it right.. (or
4773 * modify end_request and the block devices).
4775 * In any case, the race here would be much small than it was, and
4776 * I couldn't reproduce..
4778 * The race could be: suppose CURRENT==NULL. We put our req in the list,
4779 * and we are scheduled. Other process takes over, and gets into
4780 * do_sbpcd_request. It sees CURRENT!=NULL (it is == to our req), so
4781 * proceeds. It ends, so CURRENT is now NULL.. Now we awake somewhere in
4782 * end_request, but now CURRENT==NULL... oops!
4785 #undef DEBUG_GTL
4786 static inline void sbpcd_end_request(struct request *req, int uptodate) {
4787 req->next=CURRENT;
4788 CURRENT=req;
4789 up(&ioctl_read_sem);
4790 end_request(uptodate);
4792 /*==========================================================================*/
4794 * I/O request routine, called from Linux kernel.
4796 static void DO_SBPCD_REQUEST(void)
4798 u_int block;
4799 u_int nsect;
4800 int i, status_tries, data_tries;
4801 struct request *req;
4802 #ifdef DEBUG_GTL
4803 static int xx_nr=0;
4804 int xnr;
4805 #endif
4807 request_loop:
4808 #ifdef DEBUG_GTL
4809 xnr=++xx_nr;
4811 if(!CURRENT)
4813 printk( "do_sbpcd_request[%di](NULL), Pid:%d, Time:%li\n",
4814 xnr, current->pid, jiffies);
4815 printk( "do_sbpcd_request[%do](NULL) end 0 (null), Time:%li\n",
4816 xnr, jiffies);
4817 CLEAR_INTR;
4818 return;
4821 printk(" do_sbpcd_request[%di](%p:%ld+%ld), Pid:%d, Time:%li\n",
4822 xnr, CURRENT, CURRENT->sector, CURRENT->nr_sectors, current->pid, jiffies);
4823 #endif
4824 INIT_REQUEST;
4825 req=CURRENT; /* take out our request so no other */
4826 CURRENT=req->next; /* task can fuck it up GTL */
4827 sti();
4829 down(&ioctl_read_sem);
4830 if (req->rq_status == RQ_INACTIVE)
4831 sbpcd_end_request(req, 0);
4832 if (req -> sector == -1)
4833 sbpcd_end_request(req, 0);
4835 if (req->cmd != READ)
4837 msg(DBG_INF, "bad cmd %d\n", req->cmd);
4838 goto err_done;
4840 i = MINOR(req->rq_dev);
4841 if ( (i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4843 msg(DBG_INF, "do_request: bad device: %s\n",
4844 kdevname(req->rq_dev));
4845 goto err_done;
4847 #if OLD_BUSY
4848 while (busy_audio) sbp_sleep(HZ); /* wait a bit */
4849 busy_data=1;
4850 #endif OLD_BUSY
4852 if (D_S[i].audio_state==audio_playing) goto err_done;
4853 if (d!=i) switch_drive(i);
4855 block = req->sector; /* always numbered as 512-byte-pieces */
4856 nsect = req->nr_sectors; /* always counted as 512-byte-pieces */
4858 msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
4859 #if 0
4860 msg(DBG_MUL,"read LBA %d\n", block/4);
4861 #endif
4863 sbp_transfer(req);
4864 /* if we satisfied the request from the buffer, we're done. */
4865 if (req->nr_sectors == 0)
4867 #ifdef DEBUG_GTL
4868 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 2, Time:%li\n",
4869 xnr, req, req->sector, req->nr_sectors, jiffies);
4870 #endif
4871 sbpcd_end_request(req, 1);
4872 goto request_loop;
4875 #if FUTURE
4876 i=prepare(0,0); /* at moment not really a hassle check, but ... */
4877 if (i!=0)
4878 msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
4879 #endif FUTURE
4881 if (!st_spinning) cc_SpinUp();
4883 for (data_tries=n_retries; data_tries > 0; data_tries--)
4885 for (status_tries=3; status_tries > 0; status_tries--)
4887 flags_cmd_out |= f_respo3;
4888 cc_ReadStatus();
4889 if (sbp_status() != 0) break;
4890 if (st_check) cc_ReadError();
4891 sbp_sleep(1); /* wait a bit, try again */
4893 if (status_tries == 0)
4895 msg(DBG_INF,"sbp_status: failed after 3 tries in line %d\n", __LINE__);
4896 break;
4899 sbp_read_cmd(req);
4900 sbp_sleep(0);
4901 if (sbp_data(req) != 0)
4903 #if SAFE_MIXED
4904 D_S[d].has_data=2; /* is really a data disk */
4905 #endif SAFE_MIXED
4906 #ifdef DEBUG_GTL
4907 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
4908 xnr, req, req->sector, req->nr_sectors, jiffies);
4909 #endif
4910 sbpcd_end_request(req, 1);
4911 goto request_loop;
4915 err_done:
4916 #if OLD_BUSY
4917 busy_data=0;
4918 #endif OLD_BUSY
4919 #ifdef DEBUG_GTL
4920 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 4 (error), Time:%li\n",
4921 xnr, req, req->sector, req->nr_sectors, jiffies);
4922 #endif
4923 sbpcd_end_request(req, 0);
4924 sbp_sleep(0); /* wait a bit, try again */
4925 goto request_loop;
4927 /*==========================================================================*/
4929 * build and send the READ command.
4931 static void sbp_read_cmd(struct request *req)
4933 #undef OLD
4935 int i;
4936 int block;
4938 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1; /* purge buffer */
4939 D_S[d].sbp_current = 0;
4940 block=req->sector/4;
4941 if (block+D_S[d].sbp_bufsiz <= D_S[d].CDsize_frm)
4942 D_S[d].sbp_read_frames = D_S[d].sbp_bufsiz;
4943 else
4945 D_S[d].sbp_read_frames=D_S[d].CDsize_frm-block;
4946 /* avoid reading past end of data */
4947 if (D_S[d].sbp_read_frames < 1)
4949 msg(DBG_INF,"requested frame %d, CD size %d ???\n",
4950 block, D_S[d].CDsize_frm);
4951 D_S[d].sbp_read_frames=1;
4955 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4956 clr_cmdbuf();
4957 if (famV_drive)
4959 drvcmd[0]=CMDV_READ;
4960 lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
4961 bin2bcdx(&drvcmd[1]);
4962 bin2bcdx(&drvcmd[2]);
4963 bin2bcdx(&drvcmd[3]);
4964 drvcmd[4]=D_S[d].sbp_read_frames>>8;
4965 drvcmd[5]=D_S[d].sbp_read_frames&0xff;
4966 drvcmd[6]=0x02; /* flag "msf-bcd" */
4968 else if (fam0L_drive)
4970 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4971 if (D_S[d].xa_byte==0x20)
4973 cmd_type=READ_M2;
4974 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
4975 drvcmd[1]=(block>>16)&0x0ff;
4976 drvcmd[2]=(block>>8)&0x0ff;
4977 drvcmd[3]=block&0x0ff;
4978 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
4979 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
4981 else
4983 drvcmd[0]=CMD0_READ; /* "read frames", old drives */
4984 if (D_S[d].drv_type>=drv_201)
4986 lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
4987 bin2bcdx(&drvcmd[1]);
4988 bin2bcdx(&drvcmd[2]);
4989 bin2bcdx(&drvcmd[3]);
4991 else
4993 drvcmd[1]=(block>>16)&0x0ff;
4994 drvcmd[2]=(block>>8)&0x0ff;
4995 drvcmd[3]=block&0x0ff;
4997 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
4998 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
4999 drvcmd[6]=(D_S[d].drv_type<drv_201)?0:2; /* flag "lba or msf-bcd format" */
5002 else if (fam1_drive)
5004 drvcmd[0]=CMD1_READ;
5005 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5006 drvcmd[5]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5007 drvcmd[6]=D_S[d].sbp_read_frames&0x0ff;
5009 else if (fam2_drive)
5011 drvcmd[0]=CMD2_READ;
5012 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5013 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5014 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
5015 drvcmd[6]=0x02;
5017 else if (famT_drive)
5019 drvcmd[0]=CMDT_READ;
5020 drvcmd[2]=(block>>24)&0x0ff;
5021 drvcmd[3]=(block>>16)&0x0ff;
5022 drvcmd[4]=(block>>8)&0x0ff;
5023 drvcmd[5]=block&0x0ff;
5024 drvcmd[7]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5025 drvcmd[8]=D_S[d].sbp_read_frames&0x0ff;
5027 flags_cmd_out=f_putcmd;
5028 response_count=0;
5029 i=cmd_out();
5030 if (i<0) msg(DBG_INF,"error giving READ command: %0d\n", i);
5031 return;
5033 /*==========================================================================*/
5035 * Check the completion of the read-data command. On success, read
5036 * the D_S[d].sbp_bufsiz * 2048 bytes of data from the disk into buffer.
5038 static int sbp_data(struct request *req)
5040 int i=0, j=0, l, frame;
5041 u_int try=0;
5042 u_long timeout;
5043 u_char *p;
5044 u_int data_tries = 0;
5045 u_int data_waits = 0;
5046 u_int data_retrying = 0;
5047 int error_flag;
5048 int xa_count;
5049 int max_latency;
5050 int success;
5051 int wait;
5052 int duration;
5054 error_flag=0;
5055 success=0;
5056 #if LONG_TIMING
5057 max_latency=9*HZ;
5058 #else
5059 if (D_S[d].f_multisession) max_latency=15*HZ;
5060 else max_latency=5*HZ;
5061 #endif
5062 duration=jiffies;
5063 for (frame=0;frame<D_S[d].sbp_read_frames&&!error_flag; frame++)
5065 SBPCD_CLI;
5067 del_timer(&data_timer);
5068 data_timer.expires=jiffies+max_latency;
5069 timed_out_data=0;
5070 add_timer(&data_timer);
5071 while (!timed_out_data)
5073 if (D_S[d].f_multisession) try=maxtim_data*4;
5074 else try=maxtim_data;
5075 msg(DBG_000,"sbp_data: CDi_status loop: try=%d.\n",try);
5076 for ( ; try!=0;try--)
5078 j=inb(CDi_status);
5079 if (!(j&s_not_data_ready)) break;;
5080 if (!(j&s_not_result_ready)) break;
5081 if (fam0LV_drive) if (j&s_attention) break;
5083 if (!(j&s_not_data_ready)) goto data_ready;
5084 if (try==0)
5086 if (data_retrying == 0) data_waits++;
5087 data_retrying = 1;
5088 msg(DBG_000,"sbp_data: CDi_status loop: sleeping.\n");
5089 sbp_sleep(1);
5090 try = 1;
5093 msg(DBG_INF,"sbp_data: CDi_status loop expired.\n");
5094 data_ready:
5095 del_timer(&data_timer);
5097 if (timed_out_data)
5099 msg(DBG_INF,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j);
5100 error_flag++;
5101 break;
5103 if (try==0)
5105 msg(DBG_INF,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j);
5106 error_flag++;
5107 break;
5109 if (!(j&s_not_result_ready))
5111 msg(DBG_INF, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j);
5112 response_count=20;
5113 j=ResponseInfo();
5114 j=inb(CDi_status);
5116 if (j&s_not_data_ready)
5118 if ((D_S[d].ored_ctl_adr&0x40)==0)
5119 msg(DBG_INF, "CD contains no data tracks.\n");
5120 else msg(DBG_INF, "sbp_data: DATA_READY timeout (%02X).\n", j);
5121 error_flag++;
5122 break;
5124 SBPCD_STI;
5125 error_flag=0;
5126 msg(DBG_000, "sbp_data: beginning to read.\n");
5127 p = D_S[d].sbp_buf + frame * CD_FRAMESIZE;
5128 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
5129 if (cmd_type==READ_M2) {
5130 if (do_16bit) insw(CDi_data, xa_head_buf, CD_XA_HEAD>>1);
5131 else insb(CDi_data, xa_head_buf, CD_XA_HEAD);
5133 if (do_16bit) insw(CDi_data, p, CD_FRAMESIZE>>1);
5134 else insb(CDi_data, p, CD_FRAMESIZE);
5135 if (cmd_type==READ_M2) {
5136 if (do_16bit) insw(CDi_data, xa_tail_buf, CD_XA_TAIL>>1);
5137 else insb(CDi_data, xa_tail_buf, CD_XA_TAIL);
5139 D_S[d].sbp_current++;
5140 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
5141 if (cmd_type==READ_M2)
5143 for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
5144 sprintf(&msgbuf[xa_count*3], " %02X", xa_head_buf[xa_count]);
5145 msgbuf[xa_count*3]=0;
5146 msg(DBG_XA1,"xa head:%s\n", msgbuf);
5148 data_retrying = 0;
5149 data_tries++;
5150 if (data_tries >= 1000)
5152 msg(DBG_INF,"sbp_data() statistics: %d waits in %d frames.\n", data_waits, data_tries);
5153 data_waits = data_tries = 0;
5156 duration=jiffies-duration;
5157 msg(DBG_TEA,"time to read %d frames: %d jiffies .\n",frame,duration);
5158 if (famT_drive)
5160 wait=8;
5163 if (teac==2)
5165 if ((i=CDi_stat_loop_T()) == -1) break;
5167 else
5169 sbp_sleep(1);
5170 OUT(CDo_sel_i_d,0);
5171 i=inb(CDi_status);
5173 if (!(i&s_not_data_ready))
5175 OUT(CDo_sel_i_d,1);
5176 j=0;
5179 if (do_16bit) i=inw(CDi_data);
5180 else i=inb(CDi_data);
5181 j++;
5182 i=inb(CDi_status);
5184 while (!(i&s_not_data_ready));
5185 msg(DBG_TEA, "==========too much data (%d bytes/words)==============.\n", j);
5187 if (!(i&s_not_result_ready))
5189 OUT(CDo_sel_i_d,0);
5190 l=0;
5193 infobuf[l++]=inb(CDi_info);
5194 i=inb(CDi_status);
5196 while (!(i&s_not_result_ready));
5197 if (infobuf[0]==0x00) success=1;
5198 #if 1
5199 for (j=0;j<l;j++) sprintf(&msgbuf[j*3], " %02X", infobuf[j]);
5200 msgbuf[j*3]=0;
5201 msg(DBG_TEA,"sbp_data info response:%s\n", msgbuf);
5202 #endif
5203 if (infobuf[0]==0x02)
5205 error_flag++;
5208 ++recursion;
5209 if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion);
5210 else msg(DBG_TEA,"sbp_data: CMDT_READ_ERR necessary.\n");
5211 clr_cmdbuf();
5212 drvcmd[0]=CMDT_READ_ERR;
5213 j=cmd_out_T(); /* !!! recursive here !!! */
5214 --recursion;
5215 sbp_sleep(1);
5217 while (j<0);
5218 D_S[d].error_state=infobuf[2];
5219 D_S[d].b3=infobuf[3];
5220 D_S[d].b4=infobuf[4];
5222 break;
5224 else
5226 #if 0
5227 msg(DBG_TEA, "============= waiting for result=================.\n");
5228 sbp_sleep(1);
5229 #endif
5232 while (wait--);
5235 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
5237 msg(DBG_TEA, "================error flag: %d=================.\n", error_flag);
5238 msg(DBG_INF,"sbp_data: read aborted by drive.\n");
5239 #if 1
5240 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5241 #else
5242 i=cc_ReadError();
5243 #endif
5244 return (0);
5247 if (fam0LV_drive)
5249 SBPCD_CLI;
5250 i=maxtim_data;
5251 for (timeout=jiffies+HZ; timeout > jiffies; timeout--)
5253 for ( ;i!=0;i--)
5255 j=inb(CDi_status);
5256 if (!(j&s_not_data_ready)) break;
5257 if (!(j&s_not_result_ready)) break;
5258 if (j&s_attention) break;
5260 if (i != 0 || timeout <= jiffies) break;
5261 sbp_sleep(0);
5262 i = 1;
5264 if (i==0) msg(DBG_INF,"status timeout after READ.\n");
5265 if (!(j&s_attention))
5267 msg(DBG_INF,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
5268 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5269 SBPCD_STI;
5270 return (0);
5272 SBPCD_STI;
5275 #if 0
5276 if (!success)
5277 #endif 0
5280 if (fam0LV_drive) cc_ReadStatus();
5281 #if 1
5282 if (famT_drive) msg(DBG_TEA, "================before ResponseStatus=================.\n", i);
5283 #endif 1
5284 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
5285 #if 1
5286 if (famT_drive) msg(DBG_TEA, "================ResponseStatus: %d=================.\n", i);
5287 #endif 1
5288 if (i<0)
5290 msg(DBG_INF,"bad cc_ReadStatus after read: %02X\n", D_S[d].status_bits);
5291 return (0);
5294 while ((fam0LV_drive)&&(!st_check)&&(!(i&p_success)));
5295 if (st_check)
5297 i=cc_ReadError();
5298 msg(DBG_INF,"cc_ReadError was necessary after read: %d\n",i);
5299 return (0);
5301 if (fatal_err)
5303 fatal_err=0;
5304 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1; /* purge buffer */
5305 D_S[d].sbp_current = 0;
5306 msg(DBG_INF,"sbp_data: fatal_err - retrying.\n");
5307 return (0);
5310 D_S[d].sbp_first_frame = req -> sector / 4;
5311 D_S[d].sbp_last_frame = D_S[d].sbp_first_frame + D_S[d].sbp_read_frames - 1;
5312 sbp_transfer(req);
5313 return (1);
5315 /*==========================================================================*/
5316 /*==========================================================================*/
5318 * Open the device special file. Check that a disk is in. Read TOC.
5320 static int sbpcd_open(struct cdrom_device_info *cdi, int purpose)
5322 int i;
5324 i = MINOR(cdi->dev);
5326 MOD_INC_USE_COUNT;
5327 down(&ioctl_read_sem);
5328 switch_drive(i);
5331 * try to keep an "open" counter here and lock the door if 0->1.
5333 msg(DBG_LCK,"open_count: %d -> %d\n",
5334 D_S[d].open_count,D_S[d].open_count+1);
5335 if (++D_S[d].open_count<=1)
5337 i=LockDoor();
5338 D_S[d].open_count=1;
5339 if (famT_drive) msg(DBG_TEA,"sbpcd_open: before i=DiskInfo();.\n");
5340 i=DiskInfo();
5341 if (famT_drive) msg(DBG_TEA,"sbpcd_open: after i=DiskInfo();.\n");
5342 if ((D_S[d].ored_ctl_adr&0x40)==0)
5344 msg(DBG_INF,"CD contains no data tracks.\n");
5345 #if SAFE_MIXED
5346 D_S[d].has_data=0;
5347 #endif SAFE_MIXED
5349 #if SAFE_MIXED
5350 else if (D_S[d].has_data<1) D_S[d].has_data=1;
5351 #endif SAFE_MIXED
5353 if (!st_spinning) cc_SpinUp();
5354 RETURN_UP(0);
5356 /*==========================================================================*/
5358 * On close, we flush all sbp blocks from the buffer cache.
5360 static void sbpcd_release(struct cdrom_device_info * cdi)
5362 int i;
5364 i = MINOR(cdi->dev);
5365 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
5367 msg(DBG_INF, "release: bad device: %04X\n", cdi->dev);
5368 return ;
5370 down(&ioctl_read_sem);
5371 switch_drive(i);
5373 * try to keep an "open" counter here and unlock the door if 1->0.
5375 msg(DBG_LCK,"open_count: %d -> %d\n",
5376 D_S[d].open_count,D_S[d].open_count-1);
5377 if (D_S[d].open_count>-2) /* CDROMEJECT may have been done */
5379 if (--D_S[d].open_count<=0)
5381 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;
5382 invalidate_buffers(cdi->dev);
5383 if (D_S[d].audio_state!=audio_playing)
5384 if (D_S[d].f_eject) cc_SpinDown();
5385 D_S[d].diskstate_flags &= ~cd_size_bit;
5386 D_S[d].open_count=0;
5387 #if SAFE_MIXED
5388 D_S[d].has_data=0;
5389 #endif SAFE_MIXED
5392 up(&ioctl_read_sem);
5393 MOD_DEC_USE_COUNT;
5394 return ;
5396 /*==========================================================================*/
5400 static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr);
5401 static struct cdrom_device_ops sbpcd_dops = {
5402 sbpcd_open, /* open */
5403 sbpcd_release, /* release */
5404 sbpcd_drive_status, /* drive status */
5405 sbpcd_media_changed, /* media changed */
5406 sbpcd_tray_move, /* tray move */
5407 sbpcd_lock_door, /* lock door */
5408 sbpcd_select_speed, /* select speed */
5409 NULL, /* select disc */
5410 sbpcd_get_last_session, /* get last session */
5411 sbpcd_get_mcn, /* get universal product code */
5412 sbpcd_reset, /* hard reset */
5413 sbpcd_audio_ioctl, /* audio ioctl */
5414 sbpcd_dev_ioctl, /* device-specific ioctl */
5415 CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_MULTI_SESSION |
5416 CDC_MEDIA_CHANGED | CDC_MCN | CDC_PLAY_AUDIO | CDC_IOCTLS, /* capability */
5417 1, /* number of minor devices */
5420 static struct cdrom_device_info sbpcd_info = {
5421 &sbpcd_dops, /* device operations */
5422 NULL, /* link */
5423 NULL, /* handle */
5424 0, /* dev */
5425 0, /* mask */
5426 2, /* maximum speed */
5427 1, /* number of discs */
5428 0, /* options, not owned */
5429 0, /* mc_flags, not owned */
5430 0 /* use count, not owned */
5432 /*==========================================================================*/
5434 * accept "kernel command line" parameters
5435 * (suggested by Peter MacDonald with SLS 1.03)
5437 * This is only implemented for the first controller. Should be enough to
5438 * allow installing with a "strange" distribution kernel.
5440 * use: tell LILO:
5441 * sbpcd=0x230,SoundBlaster
5442 * or
5443 * sbpcd=0x300,LaserMate
5444 * or
5445 * sbpcd=0x338,SoundScape
5446 * or
5447 * sbpcd=0x2C0,Teac16bit
5449 * (upper/lower case sensitive here - but all-lowercase is ok!!!).
5451 * the address value has to be the CDROM PORT ADDRESS -
5452 * not the soundcard base address.
5453 * For the SPEA/SoundScape setup, DO NOT specify the "configuration port"
5454 * address, but the address which is really used for the CDROM (usually 8
5455 * bytes above).
5458 #if (SBPCD_ISSUE-1)
5459 __initfunc(static void sbpcd_setup(const char *s, int *p))
5460 #else
5461 __initfunc(void sbpcd_setup(const char *s, int *p))
5462 #endif
5464 setup_done++;
5465 msg(DBG_INI,"sbpcd_setup called with %04X,%s\n",p[1], s);
5466 sbpro_type=0; /* default: "LaserMate" */
5467 if (p[0]>1) sbpro_type=p[2];
5468 else if (!strcmp(s,str_sb)) sbpro_type=1;
5469 else if (!strcmp(s,str_sb_l)) sbpro_type=1;
5470 else if (!strcmp(s,str_sp)) sbpro_type=2;
5471 else if (!strcmp(s,str_sp_l)) sbpro_type=2;
5472 else if (!strcmp(s,str_ss)) sbpro_type=2;
5473 else if (!strcmp(s,str_ss_l)) sbpro_type=2;
5474 else if (!strcmp(s,str_t16)) sbpro_type=3;
5475 else if (!strcmp(s,str_t16_l)) sbpro_type=3;
5476 if (p[0]>0) sbpcd_ioaddr=p[1];
5478 CDo_command=sbpcd_ioaddr;
5479 CDi_info=sbpcd_ioaddr;
5480 CDi_status=sbpcd_ioaddr+1;
5481 CDo_sel_i_d=sbpcd_ioaddr+1;
5482 CDo_reset=sbpcd_ioaddr+2;
5483 CDo_enable=sbpcd_ioaddr+3;
5484 f_16bit=0;
5485 if ((sbpro_type==1)||(sbpro_type==3))
5487 CDi_data=sbpcd_ioaddr;
5488 if (sbpro_type==3)
5490 f_16bit=1;
5491 sbpro_type=1;
5494 else CDi_data=sbpcd_ioaddr+2;
5496 /*==========================================================================*/
5498 * Sequoia S-1000 CD-ROM Interface Configuration
5499 * as used within SPEA Media FX, Ensonic SoundScape and some Reveal cards
5500 * The soundcard has to get jumpered for the interface type "Panasonic"
5501 * (not Sony or Mitsumi) and to get soft-configured for
5502 * -> configuration port address
5503 * -> CDROM port offset (num_ports): has to be 8 here. Possibly this
5504 * offset value determines the interface type (none, Panasonic,
5505 * Mitsumi, Sony).
5506 * The interface uses a configuration port (0x320, 0x330, 0x340, 0x350)
5507 * some bytes below the real CDROM address.
5509 * For the Panasonic style (LaserMate) interface and the configuration
5510 * port 0x330, we have to use an offset of 8; so, the real CDROM port
5511 * address is 0x338.
5513 __initfunc(static int config_spea(void))
5516 * base address offset between configuration port and CDROM port,
5517 * this probably defines the interface type
5518 * 2 (type=??): 0x00
5519 * 8 (type=LaserMate):0x10
5520 * 16 (type=??):0x20
5521 * 32 (type=??):0x30
5523 int n_ports=0x10;
5525 int irq_number=0; /* off:0x00, 2/9:0x01, 7:0x03, 12:0x05, 15:0x07 */
5526 int dma_channel=0; /* off: 0x00, 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68 */
5527 int dack_polarity=0; /* L:0x00, H:0x80 */
5528 int drq_polarity=0x40; /* L:0x00, H:0x40 */
5529 int i;
5531 #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
5532 #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
5534 OUT(SPEA_REG_1,0xFF);
5535 i=inb(SPEA_REG_1);
5536 if (i!=0x0F)
5538 msg(DBG_SEQ,"no SPEA interface at %04X present.\n", sbpcd_ioaddr);
5539 return (-1); /* no interface found */
5541 OUT(SPEA_REG_1,0x04);
5542 OUT(SPEA_REG_2,0xC0);
5544 OUT(SPEA_REG_1,0x05);
5545 OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
5547 #if 1
5548 #define SPEA_PATTERN 0x80
5549 #else
5550 #define SPEA_PATTERN 0x00
5551 #endif
5552 OUT(SPEA_REG_1,0x06);
5553 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5554 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5556 OUT(SPEA_REG_1,0x09);
5557 i=(inb(SPEA_REG_2)&0xCF)|n_ports;
5558 OUT(SPEA_REG_2,i);
5560 sbpro_type = 0; /* acts like a LaserMate interface now */
5561 msg(DBG_SEQ,"found SoundScape interface at %04X.\n", sbpcd_ioaddr);
5562 return (0);
5564 /*==========================================================================*/
5566 * Test for presence of drive and initialize it.
5567 * Called once at boot or load time.
5569 #ifdef MODULE
5570 int init_module(void)
5571 #else
5572 __initfunc(int SBPCD_INIT(void))
5573 #endif MODULE
5575 int i=0, j=0;
5576 int addr[2]={1, CDROM_PORT};
5577 int port_index;
5579 sti();
5581 msg(DBG_INF,"sbpcd.c %s\n", VERSION);
5582 #ifndef MODULE
5583 #if DISTRIBUTION
5584 if (!setup_done)
5586 msg(DBG_INF,"Looking for Matsushita/Panasonic, CreativeLabs, Longshine, TEAC CD-ROM drives\n");
5587 msg(DBG_INF,"= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
5588 msg(DBG_INF,"Auto-Probing can cause a hang (f.e. touching an NE2000 card).\n");
5589 msg(DBG_INF,"If that happens, you have to reboot and use the\n");
5590 msg(DBG_INF,"LILO (kernel) command line feature like:\n");
5591 msg(DBG_INF," LILO boot: ... sbpcd=0x230,SoundBlaster\n");
5592 msg(DBG_INF,"or like:\n");
5593 msg(DBG_INF," LILO boot: ... sbpcd=0x300,LaserMate\n");
5594 msg(DBG_INF,"or like:\n");
5595 msg(DBG_INF," LILO boot: ... sbpcd=0x338,SoundScape\n");
5596 msg(DBG_INF,"with your REAL address.\n");
5597 msg(DBG_INF,"= = = = = = = = = = END of WARNING = = = = = == = = =\n");
5599 #endif DISTRIBUTION
5600 sbpcd[0]=sbpcd_ioaddr; /* possibly changed by kernel command line */
5601 sbpcd[1]=sbpro_type; /* possibly changed by kernel command line */
5602 #endif MODULE
5604 for (port_index=0;port_index<NUM_PROBE;port_index+=2)
5606 addr[1]=sbpcd[port_index];
5607 if (addr[1]==0) break;
5608 if (check_region(addr[1],4))
5610 msg(DBG_INF,"check_region: %03X is not free.\n",addr[1]);
5611 continue;
5613 if (sbpcd[port_index+1]==2) type=str_sp;
5614 else if (sbpcd[port_index+1]==1) type=str_sb;
5615 else if (sbpcd[port_index+1]==3) type=str_t16;
5616 else type=str_lm;
5617 sbpcd_setup(type, addr);
5618 #if DISTRIBUTION
5619 msg(DBG_INF,"Scanning 0x%X (%s)...\n", CDo_command, type);
5620 #endif DISTRIBUTION
5621 if (sbpcd[port_index+1]==2)
5623 i=config_spea();
5624 if (i<0) continue;
5626 #ifdef PATH_CHECK
5627 if (check_card(addr[1])) continue;
5628 #endif PATH_CHECK
5629 i=check_drives();
5630 msg(DBG_INI,"check_drives done.\n");
5631 if (i>=0) break; /* drive found */
5632 } /* end of cycling through the set of possible I/O port addresses */
5634 if (ndrives==0)
5636 msg(DBG_INF, "No drive found.\n");
5637 #ifdef MODULE
5638 return -EIO;
5639 #else
5640 goto init_done;
5641 #endif MODULE
5644 if (port_index>0)
5646 msg(DBG_INF, "You should read linux/Documentation/cdrom/sbpcd\n");
5647 msg(DBG_INF, "and then configure sbpcd.h for your hardware.\n");
5649 check_datarate();
5650 msg(DBG_INI,"check_datarate done.\n");
5652 for (j=0;j<NR_SBPCD;j++)
5654 if (D_S[j].drv_id==-1) continue;
5655 switch_drive(j);
5656 #if 1
5657 if (!famL_drive) cc_DriveReset();
5658 #endif 0
5659 if (!st_spinning) cc_SpinUp();
5660 D_S[j].sbp_first_frame = -1; /* First frame in buffer */
5661 D_S[j].sbp_last_frame = -1; /* Last frame in buffer */
5662 D_S[j].sbp_read_frames = 0; /* Number of frames being read to buffer */
5663 D_S[j].sbp_current = 0; /* Frame being currently read */
5664 D_S[j].CD_changed=1;
5665 D_S[j].frame_size=CD_FRAMESIZE;
5666 D_S[j].f_eject=0;
5667 #if EJECT
5668 if (!fam0_drive) D_S[j].f_eject=1;
5669 #endif EJECT
5670 cc_ReadStatus();
5671 i=ResponseStatus(); /* returns orig. status or p_busy_new */
5672 if (famT_drive) i=ResponseStatus(); /* returns orig. status or p_busy_new */
5673 if (i<0)
5675 if (i!=-402)
5676 msg(DBG_INF,"init: ResponseStatus returns %d.\n",i);
5678 else
5680 if (st_check)
5682 i=cc_ReadError();
5683 msg(DBG_INI,"init: cc_ReadError returns %d\n",i);
5686 msg(DBG_INI,"init: first GetStatus: %d\n",i);
5687 msg(DBG_LCS,"init: first GetStatus: error_byte=%d\n",
5688 D_S[j].error_byte);
5689 if (D_S[j].error_byte==aud_12)
5691 timeout=jiffies+2*HZ;
5694 i=GetStatus();
5695 msg(DBG_INI,"init: second GetStatus: %02X\n",i);
5696 msg(DBG_LCS,
5697 "init: second GetStatus: error_byte=%d\n",
5698 D_S[j].error_byte);
5699 if (i<0) break;
5700 if (!st_caddy_in) break;
5702 while ((!st_diskok)||(timeout<jiffies));
5704 i=SetSpeed();
5705 if (i>=0) D_S[j].CD_changed=1;
5709 * Turn on the CD audio channels.
5710 * The addresses are obtained from SOUND_BASE (see sbpcd.h).
5712 #if SOUND_BASE
5713 OUT(MIXER_addr,MIXER_CD_Volume); /* select SB Pro mixer register */
5714 OUT(MIXER_data,0xCC); /* one nibble per channel, max. value: 0xFF */
5715 #endif SOUND_BASE
5717 if (register_blkdev(MAJOR_NR, major_name, &cdrom_fops) != 0)
5719 msg(DBG_INF, "Can't get MAJOR %d for Matsushita CDROM\n", MAJOR_NR);
5720 #ifdef MODULE
5721 return -EIO;
5722 #else
5723 goto init_done;
5724 #endif MODULE
5726 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
5727 read_ahead[MAJOR_NR] = buffers * (CD_FRAMESIZE / 512);
5729 request_region(CDo_command,4,major_name);
5731 for (j=0;j<NR_SBPCD;j++)
5733 struct cdrom_device_info * sbpcd_infop;
5735 if (D_S[j].drv_id==-1) continue;
5736 switch_drive(j);
5737 #if SAFE_MIXED
5738 D_S[j].has_data=0;
5739 #endif SAFE_MIXED
5741 * allocate memory for the frame buffers
5743 D_S[j].aud_buf=NULL;
5744 D_S[j].sbp_audsiz=0;
5745 D_S[j].sbp_bufsiz=buffers;
5746 if (D_S[j].drv_type&drv_fam1)
5747 if (READ_AUDIO>0) D_S[j].sbp_audsiz=READ_AUDIO;
5748 D_S[j].sbp_buf=(u_char *) vmalloc(D_S[j].sbp_bufsiz*CD_FRAMESIZE);
5749 if (D_S[j].sbp_buf==NULL)
5751 msg(DBG_INF,"data buffer (%d frames) not available.\n",D_S[j].sbp_bufsiz);
5752 if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
5754 printk("Can't unregister %s\n", major_name);
5756 release_region(CDo_command,4);
5757 return -EIO;
5759 #ifdef MODULE
5760 msg(DBG_INF,"data buffer size: %d frames.\n",buffers);
5761 #endif MODULE
5762 if (D_S[j].sbp_audsiz>0)
5764 D_S[j].aud_buf=(u_char *) vmalloc(D_S[j].sbp_audsiz*CD_FRAMESIZE_RAW);
5765 if (D_S[j].aud_buf==NULL) msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[j].sbp_audsiz);
5766 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[j].sbp_audsiz);
5768 sbpcd_infop = vmalloc(sizeof (struct cdrom_device_info));
5769 if (sbpcd_infop == NULL)
5771 release_region(CDo_command,4);
5772 return -ENOMEM;
5774 D_S[j].sbpcd_infop = sbpcd_infop;
5775 memcpy (sbpcd_infop, &sbpcd_info, sizeof(struct cdrom_device_info));
5776 sbpcd_infop->dev = MKDEV(MAJOR_NR, j);
5777 strncpy(sbpcd_infop->name,major_name, sizeof(sbpcd_infop->name));
5779 if (register_cdrom(sbpcd_infop))
5781 printk(" sbpcd: Unable to register with Uniform CD-ROm driver\n");
5785 * set the block size
5787 sbpcd_blocksizes[j]=CD_FRAMESIZE;
5789 blksize_size[MAJOR_NR]=sbpcd_blocksizes;
5791 #ifndef MODULE
5792 init_done:
5793 #if !(SBPCD_ISSUE-1)
5794 #ifdef CONFIG_SBPCD2
5795 sbpcd2_init();
5796 #endif CONFIG_SBPCD2
5797 #ifdef CONFIG_SBPCD3
5798 sbpcd3_init();
5799 #endif CONFIG_SBPCD3
5800 #ifdef CONFIG_SBPCD4
5801 sbpcd4_init();
5802 #endif CONFIG_SBPCD4
5803 #endif !(SBPCD_ISSUE-1)
5804 #endif MODULE
5805 return 0;
5807 /*==========================================================================*/
5808 #ifdef MODULE
5809 void cleanup_module(void)
5811 int j;
5813 if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
5815 msg(DBG_INF, "What's that: can't unregister %s.\n", major_name);
5816 return;
5818 release_region(CDo_command,4);
5820 for (j=0;j<NR_SBPCD;j++)
5822 if (D_S[j].drv_id==-1) continue;
5823 vfree(D_S[j].sbp_buf);
5824 if (D_S[j].sbp_audsiz>0) vfree(D_S[j].aud_buf);
5825 if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
5827 msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
5828 return;
5830 vfree(D_S[j].sbpcd_infop);
5832 msg(DBG_INF, "%s module released.\n", major_name);
5834 #endif MODULE
5835 /*==========================================================================*/
5837 * Check if the media has changed in the CD-ROM drive.
5838 * used externally (isofs/inode.c, fs/buffer.c)
5840 static int sbpcd_chk_disk_change(kdev_t full_dev)
5842 int i;
5844 msg(DBG_CHK,"media_check (%d) called\n", MINOR(full_dev));
5845 i=MINOR(full_dev);
5847 if (D_S[i].CD_changed==0xFF)
5849 D_S[i].CD_changed=0;
5850 msg(DBG_CHK,"medium changed (drive %d)\n", i);
5851 return (1);
5853 else
5854 return (0);
5857 static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr)
5859 return sbpcd_chk_disk_change(cdi->dev);
5861 /*==========================================================================*/
5863 * Overrides for Emacs so that we follow Linus's tabbing style.
5864 * Emacs will notice this stuff at the end of the file and automatically
5865 * adjust the settings for this buffer only. This must remain at the end
5866 * of the file.
5867 * ---------------------------------------------------------------------------
5868 * Local variables:
5869 * c-indent-level: 8
5870 * c-brace-imaginary-offset: 0
5871 * c-brace-offset: -8
5872 * c-argdecl-indent: 8
5873 * c-label-offset: -8
5874 * c-continued-statement-offset: 8
5875 * c-continued-brace-offset: 0
5876 * End: