Import 2.3.4pre3
[davej-history.git] / drivers / cdrom / sbpcd.c
blobd19b940d69e087a8e36ff8f7b68526d5c26bc761
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>
339 #include <linux/interrupt.h>
341 #include <asm/system.h>
342 #include <asm/io.h>
343 #include <asm/uaccess.h>
344 #include <stdarg.h>
345 #include <linux/config.h>
346 #include "sbpcd.h"
348 #if !(SBPCD_ISSUE-1)
349 #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
350 #endif
351 #if !(SBPCD_ISSUE-2)
352 #define MAJOR_NR MATSUSHITA_CDROM2_MAJOR /* second driver issue */
353 #endif
354 #if !(SBPCD_ISSUE-3)
355 #define MAJOR_NR MATSUSHITA_CDROM3_MAJOR /* third driver issue */
356 #endif
357 #if !(SBPCD_ISSUE-4)
358 #define MAJOR_NR MATSUSHITA_CDROM4_MAJOR /* fourth driver issue */
359 #endif
361 #include <linux/blk.h>
363 /*==========================================================================*/
365 * provisions for more than 1 driver issues
366 * currently up to 4 drivers, expandable
368 #if !(SBPCD_ISSUE-1)
369 #define DO_SBPCD_REQUEST(a) do_sbpcd_request(a)
370 #define SBPCD_INIT(a) sbpcd_init(a)
371 #endif
372 #if !(SBPCD_ISSUE-2)
373 #define DO_SBPCD_REQUEST(a) do_sbpcd2_request(a)
374 #define SBPCD_INIT(a) sbpcd2_init(a)
375 #endif
376 #if !(SBPCD_ISSUE-3)
377 #define DO_SBPCD_REQUEST(a) do_sbpcd3_request(a)
378 #define SBPCD_INIT(a) sbpcd3_init(a)
379 #endif
380 #if !(SBPCD_ISSUE-4)
381 #define DO_SBPCD_REQUEST(a) do_sbpcd4_request(a)
382 #define SBPCD_INIT(a) sbpcd4_init(a)
383 #endif
384 /*==========================================================================*/
385 #if SBPCD_DIS_IRQ
386 #define SBPCD_CLI cli()
387 #define SBPCD_STI sti()
388 #else
389 #define SBPCD_CLI
390 #define SBPCD_STI
391 #endif SBPCD_DIS_IRQ
392 /*==========================================================================*/
394 * auto-probing address list
395 * inspired by Adam J. Richter from Yggdrasil
397 * still not good enough - can cause a hang.
398 * example: a NE 2000 ethernet card at 300 will cause a hang probing 310.
399 * if that happens, reboot and use the LILO (kernel) command line.
400 * The possibly conflicting ethernet card addresses get NOT probed
401 * by default - to minimize the hang possibilities.
403 * The SB Pro addresses get "mirrored" at 0x6xx and some more locations - to
404 * avoid a type error, the 0x2xx-addresses must get checked before 0x6xx.
406 * send mail to emoenke@gwdg.de if your interface card is not FULLY
407 * represented here.
409 #if !(SBPCD_ISSUE-1)
410 static int sbpcd[] =
412 CDROM_PORT, SBPRO, /* probe with user's setup first */
413 #if DISTRIBUTION
414 0x230, 1, /* Soundblaster Pro and 16 (default) */
415 #if 0
416 0x300, 0, /* CI-101P (default), WDH-7001C (default),
417 Galaxy (default), Reveal (one default) */
418 0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
419 0x2C0, 3, /* Teac 16-bit cards */
420 0x260, 1, /* OmniCD */
421 0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
422 Longshine LCS-6853 (default) */
423 0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
424 0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
425 0x360, 0, /* Lasermate, CI-101P */
426 0x270, 1, /* Soundblaster 16 */
427 0x670, 0, /* "sound card #9" */
428 0x690, 0, /* "sound card #9" */
429 0x338, 2, /* SPEA Media FX, Ensonic SoundScape (default) */
430 0x328, 2, /* SPEA Media FX */
431 0x348, 2, /* SPEA Media FX */
432 0x634, 0, /* some newer sound cards */
433 0x638, 0, /* some newer sound cards */
434 0x230, 1, /* some newer sound cards */
435 /* due to incomplete address decoding of the SbPro card, these must be last */
436 0x630, 0, /* "sound card #9" (default) */
437 0x650, 0, /* "sound card #9" */
438 #ifdef MODULE
440 * some "hazardous" locations (no harm with the loadable version)
441 * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
443 0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
444 0x350, 0, /* Lasermate, CI-101P */
445 0x358, 2, /* SPEA Media FX */
446 0x370, 0, /* Lasermate, CI-101P */
447 0x290, 1, /* Soundblaster 16 */
448 0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
449 #endif MODULE
450 #endif
451 #endif DISTRIBUTION
453 #else
454 static int sbpcd[] = {CDROM_PORT, SBPRO}; /* probe with user's setup only */
455 #endif
456 MODULE_PARM(sbpcd, "2i");
458 #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
460 /*==========================================================================*/
462 * the external references:
464 #if !(SBPCD_ISSUE-1)
465 #ifdef CONFIG_SBPCD2
466 extern int sbpcd2_init(void);
467 #endif
468 #ifdef CONFIG_SBPCD3
469 extern int sbpcd3_init(void);
470 #endif
471 #ifdef CONFIG_SBPCD4
472 extern int sbpcd4_init(void);
473 #endif
474 #endif
476 /*==========================================================================*/
478 #define INLINE inline
480 /*==========================================================================*/
482 * the forward references:
484 static void sbp_sleep(u_int);
485 static void mark_timeout_delay(u_long);
486 static void mark_timeout_data(u_long);
487 #if 0
488 static void mark_timeout_audio(u_long);
489 #endif
490 static void sbp_read_cmd(struct request *req);
491 static int sbp_data(struct request *req);
492 static int cmd_out(void);
493 static int DiskInfo(void);
494 static int sbpcd_chk_disk_change(kdev_t);
496 /*==========================================================================*/
499 * pattern for printk selection:
501 * (1<<DBG_INF) necessary information
502 * (1<<DBG_BSZ) BLOCK_SIZE trace
503 * (1<<DBG_REA) "read" status trace
504 * (1<<DBG_CHK) "media check" trace
505 * (1<<DBG_TIM) datarate timer test
506 * (1<<DBG_INI) initialization trace
507 * (1<<DBG_TOC) tell TocEntry values
508 * (1<<DBG_IOC) ioctl trace
509 * (1<<DBG_STA) "ResponseStatus" trace
510 * (1<<DBG_ERR) "cc_ReadError" trace
511 * (1<<DBG_CMD) "cmd_out" trace
512 * (1<<DBG_WRN) give explanation before auto-probing
513 * (1<<DBG_MUL) multi session code test
514 * (1<<DBG_IDX) "drive_id != 0" test code
515 * (1<<DBG_IOX) some special information
516 * (1<<DBG_DID) drive ID test
517 * (1<<DBG_RES) drive reset info
518 * (1<<DBG_SPI) SpinUp test info
519 * (1<<DBG_IOS) ioctl trace: "subchannel"
520 * (1<<DBG_IO2) ioctl trace: general
521 * (1<<DBG_UPC) show UPC info
522 * (1<<DBG_XA1) XA mode debugging
523 * (1<<DBG_LCK) door (un)lock info
524 * (1<<DBG_SQ1) dump SubQ frame
525 * (1<<DBG_AUD) "read audio" debugging
526 * (1<<DBG_SEQ) Sequoia interface configuration trace
527 * (1<<DBG_LCS) Longshine LCS-7260 debugging trace
528 * (1<<DBG_CD2) MKE/Funai CD200 debugging trace
529 * (1<<DBG_TEA) TEAC CD-55A debugging trace
530 * (1<<DBG_ECS) ECS-AT (Vertos-100) debugging trace
531 * (1<<DBG_000) unnecessary information
533 #if DISTRIBUTION
534 static int sbpcd_debug = (1<<DBG_INF);
535 #else
536 static int sbpcd_debug = 0 & ((1<<DBG_INF) |
537 (1<<DBG_TOC) |
538 (1<<DBG_MUL) |
539 (1<<DBG_UPC));
540 #endif DISTRIBUTION
542 static int sbpcd_ioaddr = CDROM_PORT; /* default I/O base address */
543 static int sbpro_type = SBPRO;
544 static unsigned char setup_done = 0;
545 static unsigned char f_16bit = 0;
546 static unsigned char do_16bit = 0;
547 static int CDo_command, CDo_reset;
548 static int CDo_sel_i_d, CDo_enable;
549 static int CDi_info, CDi_status, CDi_data;
550 static struct cdrom_msf msf;
551 static struct cdrom_ti ti;
552 static struct cdrom_tochdr tochdr;
553 static struct cdrom_tocentry tocentry;
554 static struct cdrom_subchnl SC;
555 static struct cdrom_volctrl volctrl;
556 static struct cdrom_read_audio read_audio;
558 static unsigned char msgnum=0;
559 static char msgbuf[80];
561 static const char *str_sb = "SoundBlaster";
562 static const char *str_sb_l = "soundblaster";
563 static const char *str_lm = "LaserMate";
564 static const char *str_sp = "SPEA";
565 static const char *str_sp_l = "spea";
566 static const char *str_ss = "SoundScape";
567 static const char *str_ss_l = "soundscape";
568 static const char *str_t16 = "Teac16bit";
569 static const char *str_t16_l = "teac16bit";
570 static const char *type;
572 #if !(SBPCD_ISSUE-1)
573 static const char *major_name="sbpcd";
574 #endif
575 #if !(SBPCD_ISSUE-2)
576 static const char *major_name="sbpcd2";
577 #endif
578 #if !(SBPCD_ISSUE-3)
579 static const char *major_name="sbpcd3";
580 #endif
581 #if !(SBPCD_ISSUE-4)
582 static const char *major_name="sbpcd4";
583 #endif
585 /*==========================================================================*/
587 #if FUTURE
588 static DECLARE_WAIT_QUEUE_HEAD(sbp_waitq);
589 #endif FUTURE
591 static int teac=SBP_TEAC_SPEED;
592 static int buffers=SBP_BUFFER_FRAMES;
594 static u_char family0[]="MATSHITA"; /* MKE CR-521, CR-522, CR-523 */
595 static u_char family1[]="CR-56"; /* MKE CR-562, CR-563 */
596 static u_char family2[]="CD200"; /* MKE CD200, Funai CD200F */
597 static u_char familyL[]="LCS-7260"; /* Longshine LCS-7260 */
598 static u_char familyT[]="CD-55"; /* TEAC CD-55A */
599 static u_char familyV[]="ECS-AT"; /* ECS Vertos 100 */
601 static u_int recursion=0; /* internal testing only */
602 static u_int fatal_err=0; /* internal testing only */
603 static u_int response_count=0;
604 static u_int flags_cmd_out;
605 static u_char cmd_type=0;
606 static u_char drvcmd[10];
607 static u_char infobuf[20];
608 static u_char xa_head_buf[CD_XA_HEAD];
609 static u_char xa_tail_buf[CD_XA_TAIL];
611 #if OLD_BUSY
612 static volatile u_char busy_data=0;
613 static volatile u_char busy_audio=0; /* true semaphores would be safer */
614 #endif OLD_BUSY
615 static DECLARE_MUTEX(ioctl_read_sem);
616 static u_long timeout;
617 static volatile u_char timed_out_delay=0;
618 static volatile u_char timed_out_data=0;
619 #if 0
620 static volatile u_char timed_out_audio=0;
621 #endif
622 static u_int datarate= 1000000;
623 static u_int maxtim16=16000000;
624 static u_int maxtim04= 4000000;
625 static u_int maxtim02= 2000000;
626 static u_int maxtim_8= 30000;
627 #if LONG_TIMING
628 static u_int maxtim_data= 9000;
629 #else
630 static u_int maxtim_data= 3000;
631 #endif LONG_TIMING
632 #if DISTRIBUTION
633 static int n_retries=3;
634 #else
635 static int n_retries=1;
636 #endif
637 /*==========================================================================*/
639 static int ndrives=0;
640 static u_char drv_pattern[NR_SBPCD]={speed_auto,speed_auto,speed_auto,speed_auto};
641 static int sbpcd_blocksizes[NR_SBPCD] = {0, };
643 /*==========================================================================*/
645 * drive space begins here (needed separate for each unit)
647 static int d=0; /* DriveStruct index: drive number */
649 static struct {
650 char drv_id; /* "jumpered" drive ID or -1 */
651 char drv_sel; /* drive select lines bits */
653 char drive_model[9];
654 u_char firmware_version[4];
655 char f_eject; /* auto-eject flag: 0 or 1 */
656 u_char *sbp_buf; /* Pointer to internal data buffer,
657 space allocated during sbpcd_init() */
658 u_int sbp_bufsiz; /* size of sbp_buf (# of frames) */
659 int sbp_first_frame; /* First frame in buffer */
660 int sbp_last_frame; /* Last frame in buffer */
661 int sbp_read_frames; /* Number of frames being read to buffer */
662 int sbp_current; /* Frame being currently read */
664 u_char mode; /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
665 u_char *aud_buf; /* Pointer to audio data buffer,
666 space allocated during sbpcd_init() */
667 u_int sbp_audsiz; /* size of aud_buf (# of raw frames) */
668 u_int drv_type;
669 u_char drv_options;
670 int status_bits;
671 u_char diskstate_flags;
672 u_char sense_byte;
674 u_char CD_changed;
675 char open_count;
676 u_char error_byte;
678 u_char f_multisession;
679 u_int lba_multi;
680 int first_session;
681 int last_session;
682 int track_of_last_session;
684 u_char audio_state;
685 u_int pos_audio_start;
686 u_int pos_audio_end;
687 char vol_chan0;
688 u_char vol_ctrl0;
689 char vol_chan1;
690 u_char vol_ctrl1;
691 #if 000 /* no supported drive has it */
692 char vol_chan2;
693 u_char vol_ctrl2;
694 char vol_chan3;
695 u_char vol_ctrl3;
696 #endif 000
697 u_char volume_control; /* TEAC on/off bits */
699 u_char SubQ_ctl_adr;
700 u_char SubQ_trk;
701 u_char SubQ_pnt_idx;
702 u_int SubQ_run_tot;
703 u_int SubQ_run_trk;
704 u_char SubQ_whatisthis;
706 u_char UPC_ctl_adr;
707 u_char UPC_buf[7];
709 int frame_size;
710 int CDsize_frm;
712 u_char xa_byte; /* 0x20: XA capabilities */
713 u_char n_first_track; /* binary */
714 u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
715 u_int size_msf; /* time of whole CD, position of LeadOut track */
716 u_int size_blk;
718 u_char TocEnt_nixbyte; /* em */
719 u_char TocEnt_ctl_adr;
720 u_char TocEnt_number;
721 u_char TocEnt_format; /* em */
722 u_int TocEnt_address;
723 #if SAFE_MIXED
724 char has_data;
725 #endif SAFE_MIXED
726 u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
728 struct {
729 u_char nixbyte; /* em */
730 u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
731 u_char number;
732 u_char format; /* em */ /* 0x00: lba, 0x01: msf */
733 u_int address;
734 } TocBuffer[MAX_TRACKS+1]; /* last entry faked */
736 int in_SpinUp; /* CR-52x test flag */
737 int n_bytes; /* TEAC awaited response count */
738 u_char error_state, b3, b4; /* TEAC command error state */
739 u_char f_drv_error; /* TEAC command error flag */
740 u_char speed_byte;
741 int frmsiz;
742 u_char f_XA; /* 1: XA */
743 u_char type_byte; /* 0, 1, 3 */
744 u_char mode_xb_6;
745 u_char mode_yb_7;
746 u_char mode_xb_8;
747 u_char delay;
748 struct cdrom_device_info *sbpcd_infop;
750 } D_S[NR_SBPCD];
753 * drive space ends here (needed separate for each unit)
755 /*==========================================================================*/
756 #if 0
757 unsigned long cli_sti; /* for saving the processor flags */
758 #endif
759 /*==========================================================================*/
760 static struct timer_list delay_timer = { NULL, NULL, 0, 0, mark_timeout_delay};
761 static struct timer_list data_timer = { NULL, NULL, 0, 0, mark_timeout_data};
762 #if 0
763 static struct timer_list audio_timer = { NULL, NULL, 0, 0, mark_timeout_audio};
764 #endif
765 /*==========================================================================*/
767 * DDI interface
769 static void msg(int level, const char *fmt, ...)
771 #if DISTRIBUTION
772 #define MSG_LEVEL KERN_NOTICE
773 #else
774 #define MSG_LEVEL KERN_INFO
775 #endif DISTRIBUTION
777 char buf[256];
778 va_list args;
780 if (!(sbpcd_debug&(1<<level))) return;
782 msgnum++;
783 if (msgnum>99) msgnum=0;
784 sprintf(buf, MSG_LEVEL "%s-%d [%02d]: ", major_name, d, msgnum);
785 va_start(args, fmt);
786 vsprintf(&buf[18], fmt, args);
787 va_end(args);
788 printk(buf);
789 #if KLOGD_PAUSE
790 sbp_sleep(KLOGD_PAUSE); /* else messages get lost */
791 #endif KLOGD_PAUSE
792 return;
794 /*==========================================================================*/
796 * DDI interface: runtime trace bit pattern maintenance
798 static int sbpcd_dbg_ioctl(unsigned long arg, int level)
800 switch(arg)
802 case 0: /* OFF */
803 sbpcd_debug = DBG_INF;
804 break;
806 default:
807 if (arg>=128) sbpcd_debug &= ~(1<<(arg-128));
808 else sbpcd_debug |= (1<<arg);
810 return (arg);
812 /*==========================================================================*/
813 static void mark_timeout_delay(u_long i)
815 timed_out_delay=1;
816 #if 0
817 msg(DBG_TIM,"delay timer expired.\n");
818 #endif
820 /*==========================================================================*/
821 static void mark_timeout_data(u_long i)
823 timed_out_data=1;
824 #if 0
825 msg(DBG_TIM,"data timer expired.\n");
826 #endif
828 /*==========================================================================*/
829 #if 0
830 static void mark_timeout_audio(u_long i)
832 timed_out_audio=1;
833 #if 0
834 msg(DBG_TIM,"audio timer expired.\n");
835 #endif
837 #endif
838 /*==========================================================================*/
840 * Wait a little while (used for polling the drive).
842 static void sbp_sleep(u_int time)
844 sti();
845 current->state = TASK_INTERRUPTIBLE;
846 schedule_timeout(time);
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 (time_after(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 (time_after(jiffies, timeout_3)) gear++;
1023 break;
1024 case 2:
1025 sbp_sleep(HZ/100);
1026 if (time_after(jiffies, timeout_2)) gear++;
1027 break;
1028 case 1:
1029 sbp_sleep(0);
1030 if (time_after(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; time_before(jiffies, timeout); )
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)||time_after_eq(jiffies, timeout)) break;
1102 sbp_sleep(1);
1103 j = 1;
1105 if (time_after_eq(jiffies, timeout)) 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)||time_after(jiffies, timeout)) 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 unsigned long flags;
1491 for (i=0;i<7;i++)
1492 sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
1493 msgbuf[i*3]=0;
1494 msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
1495 save_flags(flags); cli();
1496 for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
1497 restore_flags(flags);
1499 if (response_count!=0)
1501 if (cmd_type!=0)
1503 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
1504 msg(DBG_INF,"misleaded to try ResponseData.\n");
1505 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
1506 return (-22);
1508 else i=ResponseInfo();
1509 if (i<0) return (i);
1511 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
1512 if (flags_cmd_out&f_lopsta)
1514 i=CDi_stat_loop();
1515 if ((i<0)||!(i&s_attention)) return (-8);
1517 if (!(flags_cmd_out&f_getsta)) goto LOC_229;
1519 LOC_228:
1520 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
1521 cc_ReadStatus();
1523 LOC_229:
1524 if (flags_cmd_out&f_ResponseStatus)
1526 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
1527 i=ResponseStatus();
1528 /* builds status_bits, returns orig. status or p_busy_new */
1529 if (i<0) return (i);
1530 if (flags_cmd_out&(f_bit1|f_wait_if_busy))
1532 if (!st_check)
1534 if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
1535 if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
1539 LOC_232:
1540 if (!(flags_cmd_out&f_obey_p_check)) return (0);
1541 if (!st_check) return (0);
1542 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
1543 i=cc_ReadError();
1544 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
1545 msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
1546 return (i);
1548 /*==========================================================================*/
1549 static int cc_Seek(u_int pos, char f_blk_msf)
1551 int i;
1553 clr_cmdbuf();
1554 if (f_blk_msf>1) return (-3);
1555 if (fam0V_drive)
1557 drvcmd[0]=CMD0_SEEK;
1558 if (f_blk_msf==1) pos=msf2blk(pos);
1559 drvcmd[2]=(pos>>16)&0x00FF;
1560 drvcmd[3]=(pos>>8)&0x00FF;
1561 drvcmd[4]=pos&0x00FF;
1562 if (fam0_drive)
1563 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
1564 f_ResponseStatus | f_obey_p_check | f_bit1;
1565 else
1566 flags_cmd_out = f_putcmd;
1568 else if (fam1L_drive)
1570 drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
1571 if (f_blk_msf==0) pos=blk2msf(pos);
1572 drvcmd[1]=(pos>>16)&0x00FF;
1573 drvcmd[2]=(pos>>8)&0x00FF;
1574 drvcmd[3]=pos&0x00FF;
1575 if (famL_drive)
1576 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1577 else
1578 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1580 else if (fam2_drive)
1582 drvcmd[0]=CMD2_SEEK;
1583 if (f_blk_msf==0) pos=blk2msf(pos);
1584 drvcmd[2]=(pos>>24)&0x00FF;
1585 drvcmd[3]=(pos>>16)&0x00FF;
1586 drvcmd[4]=(pos>>8)&0x00FF;
1587 drvcmd[5]=pos&0x00FF;
1588 flags_cmd_out=f_putcmd|f_ResponseStatus;
1590 else if (famT_drive)
1592 drvcmd[0]=CMDT_SEEK;
1593 if (f_blk_msf==1) pos=msf2blk(pos);
1594 drvcmd[2]=(pos>>24)&0x00FF;
1595 drvcmd[3]=(pos>>16)&0x00FF;
1596 drvcmd[4]=(pos>>8)&0x00FF;
1597 drvcmd[5]=pos&0x00FF;
1598 D_S[d].n_bytes=1;
1600 response_count=0;
1601 i=cmd_out();
1602 return (i);
1604 /*==========================================================================*/
1605 static int cc_SpinUp(void)
1607 int i;
1609 msg(DBG_SPI,"SpinUp.\n");
1610 D_S[d].in_SpinUp = 1;
1611 clr_cmdbuf();
1612 if (fam0LV_drive)
1614 drvcmd[0]=CMD0_SPINUP;
1615 if (fam0L_drive)
1616 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
1617 f_ResponseStatus|f_obey_p_check|f_bit1;
1618 else
1619 flags_cmd_out=f_putcmd;
1621 else if (fam1_drive)
1623 drvcmd[0]=CMD1_SPINUP;
1624 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1626 else if (fam2_drive)
1628 drvcmd[0]=CMD2_TRAY_CTL;
1629 drvcmd[4]=0x01; /* "spinup" */
1630 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1632 else if (famT_drive)
1634 drvcmd[0]=CMDT_TRAY_CTL;
1635 drvcmd[4]=0x03; /* "insert", it hopefully spins the drive up */
1637 response_count=0;
1638 i=cmd_out();
1639 D_S[d].in_SpinUp = 0;
1640 return (i);
1642 /*==========================================================================*/
1643 static int cc_SpinDown(void)
1645 int i;
1647 if (fam0_drive) return (0);
1648 clr_cmdbuf();
1649 response_count=0;
1650 if (fam1_drive)
1652 drvcmd[0]=CMD1_SPINDOWN;
1653 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1655 else if (fam2_drive)
1657 drvcmd[0]=CMD2_TRAY_CTL;
1658 drvcmd[4]=0x02; /* "eject" */
1659 flags_cmd_out=f_putcmd|f_ResponseStatus;
1661 else if (famL_drive)
1663 drvcmd[0]=CMDL_SPINDOWN;
1664 drvcmd[1]=1;
1665 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1667 else if (famV_drive)
1669 drvcmd[0]=CMDV_SPINDOWN;
1670 flags_cmd_out=f_putcmd;
1672 else if (famT_drive)
1674 drvcmd[0]=CMDT_TRAY_CTL;
1675 drvcmd[4]=0x02; /* "eject" */
1677 i=cmd_out();
1678 return (i);
1680 /*==========================================================================*/
1681 static int cc_get_mode_T(void)
1683 int i;
1685 clr_cmdbuf();
1686 response_count=10;
1687 drvcmd[0]=CMDT_GETMODE;
1688 drvcmd[4]=response_count;
1689 i=cmd_out_T();
1690 return (i);
1692 /*==========================================================================*/
1693 static int cc_set_mode_T(void)
1695 int i;
1697 clr_cmdbuf();
1698 response_count=1;
1699 drvcmd[0]=CMDT_SETMODE;
1700 drvcmd[1]=D_S[d].speed_byte;
1701 drvcmd[2]=D_S[d].frmsiz>>8;
1702 drvcmd[3]=D_S[d].frmsiz&0x0FF;
1703 drvcmd[4]=D_S[d].f_XA; /* 1: XA */
1704 drvcmd[5]=D_S[d].type_byte; /* 0, 1, 3 */
1705 drvcmd[6]=D_S[d].mode_xb_6;
1706 drvcmd[7]=D_S[d].mode_yb_7|D_S[d].volume_control;
1707 drvcmd[8]=D_S[d].mode_xb_8;
1708 drvcmd[9]=D_S[d].delay;
1709 i=cmd_out_T();
1710 return (i);
1712 /*==========================================================================*/
1713 static int cc_prep_mode_T(void)
1715 int i, j;
1717 i=cc_get_mode_T();
1718 if (i<0) return (i);
1719 for (i=0;i<10;i++)
1720 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1721 msgbuf[i*3]=0;
1722 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1723 D_S[d].speed_byte=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
1724 D_S[d].frmsiz=make16(infobuf[2],infobuf[3]);
1725 D_S[d].f_XA=infobuf[4];
1726 if (D_S[d].f_XA==0) D_S[d].type_byte=0;
1727 else D_S[d].type_byte=1;
1728 D_S[d].mode_xb_6=infobuf[6];
1729 D_S[d].mode_yb_7=1;
1730 D_S[d].mode_xb_8=infobuf[8];
1731 D_S[d].delay=0; /* 0, 1, 2, 3 */
1732 j=cc_set_mode_T();
1733 i=cc_get_mode_T();
1734 for (i=0;i<10;i++)
1735 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1736 msgbuf[i*3]=0;
1737 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1738 return (j);
1740 /*==========================================================================*/
1741 static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
1743 int i;
1745 if (fam0LV_drive) return (0);
1746 clr_cmdbuf();
1747 response_count=0;
1748 if (fam1_drive)
1750 drvcmd[0]=CMD1_SETMODE;
1751 drvcmd[1]=0x03;
1752 drvcmd[2]=speed;
1753 drvcmd[3]=x1;
1754 drvcmd[4]=x2;
1755 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1757 else if (fam2_drive)
1759 drvcmd[0]=CMD2_SETSPEED;
1760 if (speed&speed_auto)
1762 drvcmd[2]=0xFF;
1763 drvcmd[3]=0xFF;
1765 else
1767 drvcmd[2]=0;
1768 drvcmd[3]=150;
1770 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1772 else if (famT_drive)
1774 return (0);
1776 i=cmd_out();
1777 return (i);
1779 /*==========================================================================*/
1780 static int cc_SetVolume(void)
1782 int i;
1783 u_char channel0,channel1,volume0,volume1;
1784 u_char control0,value0,control1,value1;
1786 D_S[d].diskstate_flags &= ~volume_bit;
1787 clr_cmdbuf();
1788 channel0=D_S[d].vol_chan0;
1789 volume0=D_S[d].vol_ctrl0;
1790 channel1=control1=D_S[d].vol_chan1;
1791 volume1=value1=D_S[d].vol_ctrl1;
1792 control0=value0=0;
1794 if (famV_drive) return (0);
1796 if (((D_S[d].drv_options&audio_mono)!=0)&&(D_S[d].drv_type>=drv_211))
1798 if ((volume0!=0)&&(volume1==0))
1800 volume1=volume0;
1801 channel1=channel0;
1803 else if ((volume0==0)&&(volume1!=0))
1805 volume0=volume1;
1806 channel0=channel1;
1809 if (channel0>1)
1811 channel0=0;
1812 volume0=0;
1814 if (channel1>1)
1816 channel1=1;
1817 volume1=0;
1820 if (fam1_drive)
1822 control0=channel0+1;
1823 control1=channel1+1;
1824 value0=(volume0>volume1)?volume0:volume1;
1825 value1=value0;
1826 if (volume0==0) control0=0;
1827 if (volume1==0) control1=0;
1828 drvcmd[0]=CMD1_SETMODE;
1829 drvcmd[1]=0x05;
1830 drvcmd[3]=control0;
1831 drvcmd[4]=value0;
1832 drvcmd[5]=control1;
1833 drvcmd[6]=value1;
1834 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1836 else if (fam2_drive)
1838 control0=channel0+1;
1839 control1=channel1+1;
1840 value0=(volume0>volume1)?volume0:volume1;
1841 value1=value0;
1842 if (volume0==0) control0=0;
1843 if (volume1==0) control1=0;
1844 drvcmd[0]=CMD2_SETMODE;
1845 drvcmd[1]=0x0E;
1846 drvcmd[3]=control0;
1847 drvcmd[4]=value0;
1848 drvcmd[5]=control1;
1849 drvcmd[6]=value1;
1850 flags_cmd_out=f_putcmd|f_ResponseStatus;
1852 else if (famL_drive)
1854 if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
1855 if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
1856 if (volume0|volume1) value0=0x80;
1857 drvcmd[0]=CMDL_SETMODE;
1858 drvcmd[1]=0x03;
1859 drvcmd[4]=control0;
1860 drvcmd[5]=value0;
1861 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1863 else if (fam0_drive) /* different firmware levels */
1865 if (D_S[d].drv_type>=drv_300)
1867 control0=volume0&0xFC;
1868 value0=volume1&0xFC;
1869 if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
1870 if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
1871 if (channel0!=0) control0 |= 0x01;
1872 if (channel1==1) value0 |= 0x01;
1874 else
1876 value0=(volume0>volume1)?volume0:volume1;
1877 if (D_S[d].drv_type<drv_211)
1879 if (channel0!=0)
1881 i=channel1;
1882 channel1=channel0;
1883 channel0=i;
1884 i=volume1;
1885 volume1=volume0;
1886 volume0=i;
1888 if (channel0==channel1)
1890 if (channel0==0)
1892 channel1=1;
1893 volume1=0;
1894 volume0=value0;
1896 else
1898 channel0=0;
1899 volume0=0;
1900 volume1=value0;
1905 if ((volume0!=0)&&(volume1!=0))
1907 if (volume0==0xFF) volume1=0xFF;
1908 else if (volume1==0xFF) volume0=0xFF;
1910 else if (D_S[d].drv_type<drv_201) volume0=volume1=value0;
1912 if (D_S[d].drv_type>=drv_201)
1914 if (volume0==0) control0 |= 0x80;
1915 if (volume1==0) control0 |= 0x40;
1917 if (D_S[d].drv_type>=drv_211)
1919 if (channel0!=0) control0 |= 0x20;
1920 if (channel1!=1) control0 |= 0x10;
1923 drvcmd[0]=CMD0_SETMODE;
1924 drvcmd[1]=0x83;
1925 drvcmd[4]=control0;
1926 drvcmd[5]=value0;
1927 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
1929 else if (famT_drive)
1931 D_S[d].volume_control=0;
1932 if (!volume0) D_S[d].volume_control|=0x10;
1933 if (!volume1) D_S[d].volume_control|=0x20;
1934 i=cc_prep_mode_T();
1935 if (i<0) return (i);
1937 if (!famT_drive)
1939 response_count=0;
1940 i=cmd_out();
1941 if (i<0) return (i);
1943 D_S[d].diskstate_flags |= volume_bit;
1944 return (0);
1946 /*==========================================================================*/
1947 static int GetStatus(void)
1949 int i;
1951 if (famT_drive) return (0);
1952 flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
1953 response_count=0;
1954 cmd_type=0;
1955 i=cmd_out();
1956 return (i);
1958 /*==========================================================================*/
1959 static int cc_DriveReset(void)
1961 int i;
1963 msg(DBG_RES,"cc_DriveReset called.\n");
1964 clr_cmdbuf();
1965 response_count=0;
1966 if (fam0LV_drive) OUT(CDo_reset,0x00);
1967 else if (fam1_drive)
1969 drvcmd[0]=CMD1_RESET;
1970 flags_cmd_out=f_putcmd;
1971 i=cmd_out();
1973 else if (fam2_drive)
1975 drvcmd[0]=CMD2_RESET;
1976 flags_cmd_out=f_putcmd;
1977 i=cmd_out();
1978 OUT(CDo_reset,0x00);
1980 else if (famT_drive)
1982 OUT(CDo_sel_i_d,0);
1983 OUT(CDo_enable,D_S[d].drv_sel);
1984 OUT(CDo_command,CMDT_RESET);
1985 for (i=1;i<10;i++) OUT(CDo_command,0);
1987 if (fam0LV_drive) sbp_sleep(5*HZ); /* wait 5 seconds */
1988 else sbp_sleep(1*HZ); /* wait a second */
1989 #if 1
1990 if (famT_drive)
1992 msg(DBG_TEA, "================CMDT_RESET given=================.\n");
1993 sbp_sleep(3*HZ);
1995 #endif 1
1996 flush_status();
1997 i=GetStatus();
1998 if (i<0) return i;
1999 if (!famT_drive)
2000 if (D_S[d].error_byte!=aud_12) return -501;
2001 return (0);
2004 /*==========================================================================*/
2005 static int SetSpeed(void)
2007 int i, speed;
2009 if (!(D_S[d].drv_options&(speed_auto|speed_300|speed_150))) return (0);
2010 speed=speed_auto;
2011 if (!(D_S[d].drv_options&speed_auto))
2013 speed |= speed_300;
2014 if (!(D_S[d].drv_options&speed_300)) speed=0;
2016 i=cc_SetSpeed(speed,0,0);
2017 return (i);
2020 static void switch_drive(int i);
2022 static int sbpcd_select_speed(struct cdrom_device_info *cdi, int speed)
2024 int i = MINOR(cdi->dev);
2026 if (i != d)
2027 switch_drive(i);
2029 return cc_SetSpeed(speed == 2 ? speed_300 : speed_150, 0, 0);
2032 /*==========================================================================*/
2033 static int DriveReset(void)
2035 int i;
2037 i=cc_DriveReset();
2038 if (i<0) return (-22);
2041 i=GetStatus();
2042 if ((i<0)&&(i!=-ERR_DISKCHANGE)) return (-2); /* from sta2err */
2043 if (!st_caddy_in) break;
2044 sbp_sleep(1);
2046 while (!st_diskok);
2047 #if 000
2048 D_S[d].CD_changed=1;
2049 #endif
2050 if ((st_door_closed) && (st_caddy_in))
2052 i=DiskInfo();
2053 if (i<0) return (-23);
2055 return (0);
2058 static int sbpcd_reset(struct cdrom_device_info *cdi)
2060 int i = MINOR(cdi->dev);
2062 if (i != d)
2063 switch_drive(i);
2065 return DriveReset();
2068 /*==========================================================================*/
2069 static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
2071 int i, j, n;
2073 if (D_S[d].audio_state==audio_playing) return (-EINVAL);
2074 clr_cmdbuf();
2075 response_count=0;
2076 if (famLV_drive)
2078 drvcmd[0]=CMDL_PLAY;
2079 i=msf2blk(pos_audio_start);
2080 n=msf2blk(pos_audio_end)+1-i;
2081 drvcmd[1]=(i>>16)&0x00FF;
2082 drvcmd[2]=(i>>8)&0x00FF;
2083 drvcmd[3]=i&0x00FF;
2084 drvcmd[4]=(n>>16)&0x00FF;
2085 drvcmd[5]=(n>>8)&0x00FF;
2086 drvcmd[6]=n&0x00FF;
2087 if (famL_drive)
2088 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
2089 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
2090 else
2091 flags_cmd_out = f_putcmd;
2093 else
2095 j=1;
2096 if (fam1_drive)
2098 drvcmd[0]=CMD1_PLAY_MSF;
2099 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
2100 f_obey_p_check | f_wait_if_busy;
2102 else if (fam2_drive)
2104 drvcmd[0]=CMD2_PLAY_MSF;
2105 flags_cmd_out = f_putcmd | f_ResponseStatus | f_obey_p_check;
2107 else if (famT_drive)
2109 drvcmd[0]=CMDT_PLAY_MSF;
2110 j=3;
2111 response_count=1;
2113 else if (fam0_drive)
2115 drvcmd[0]=CMD0_PLAY_MSF;
2116 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
2117 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
2119 drvcmd[j]=(pos_audio_start>>16)&0x00FF;
2120 drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
2121 drvcmd[j+2]=pos_audio_start&0x00FF;
2122 drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
2123 drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
2124 drvcmd[j+5]=pos_audio_end&0x00FF;
2126 i=cmd_out();
2127 return (i);
2129 /*==========================================================================*/
2130 static int cc_Pause_Resume(int pau_res)
2132 int i;
2134 clr_cmdbuf();
2135 response_count=0;
2136 if (fam1_drive)
2138 drvcmd[0]=CMD1_PAU_RES;
2139 if (pau_res!=1) drvcmd[1]=0x80;
2140 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2142 else if (fam2_drive)
2144 drvcmd[0]=CMD2_PAU_RES;
2145 if (pau_res!=1) drvcmd[2]=0x01;
2146 flags_cmd_out=f_putcmd|f_ResponseStatus;
2148 else if (fam0LV_drive)
2150 drvcmd[0]=CMD0_PAU_RES;
2151 if (pau_res!=1) drvcmd[1]=0x80;
2152 if (famL_drive)
2153 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2154 f_obey_p_check|f_bit1;
2155 else if (famV_drive)
2156 flags_cmd_out=f_putcmd;
2157 else
2158 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2159 f_obey_p_check;
2161 else if (famT_drive)
2163 if (pau_res==3) return (cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end));
2164 else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
2165 else return (-56);
2167 i=cmd_out();
2168 return (i);
2170 /*==========================================================================*/
2171 static int cc_LockDoor(char lock)
2173 int i;
2175 if (fam0_drive) return (0);
2176 msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, d);
2177 msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
2178 clr_cmdbuf();
2179 response_count=0;
2180 if (fam1_drive)
2182 drvcmd[0]=CMD1_LOCK_CTL;
2183 if (lock==1) drvcmd[1]=0x01;
2184 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2186 else if (fam2_drive)
2188 drvcmd[0]=CMD2_LOCK_CTL;
2189 if (lock==1) drvcmd[4]=0x01;
2190 flags_cmd_out=f_putcmd|f_ResponseStatus;
2192 else if (famLV_drive)
2194 drvcmd[0]=CMDL_LOCK_CTL;
2195 if (lock==1) drvcmd[1]=0x01;
2196 if (famL_drive)
2197 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
2198 else
2199 flags_cmd_out=f_putcmd;
2201 else if (famT_drive)
2203 drvcmd[0]=CMDT_LOCK_CTL;
2204 if (lock==1) drvcmd[4]=0x01;
2206 i=cmd_out();
2207 msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
2208 return (i);
2210 /*==========================================================================*/
2211 /*==========================================================================*/
2212 static int UnLockDoor(void)
2214 int i,j;
2216 j=20;
2219 i=cc_LockDoor(0);
2220 --j;
2221 sbp_sleep(1);
2223 while ((i<0)&&(j));
2224 if (i<0)
2226 cc_DriveReset();
2227 return -84;
2229 return (0);
2231 /*==========================================================================*/
2232 static int LockDoor(void)
2234 int i,j;
2236 j=20;
2239 i=cc_LockDoor(1);
2240 --j;
2241 sbp_sleep(1);
2243 while ((i<0)&&(j));
2244 if (j==0)
2246 cc_DriveReset();
2247 j=20;
2250 i=cc_LockDoor(1);
2251 --j;
2252 sbp_sleep(1);
2254 while ((i<0)&&(j));
2256 return (i);
2259 static int sbpcd_lock_door(struct cdrom_device_info *cdi, int lock)
2261 return lock ? LockDoor() : UnLockDoor();
2264 /*==========================================================================*/
2265 static int cc_CloseTray(void)
2267 int i;
2269 if (fam0_drive) return (0);
2270 msg(DBG_LCK,"cc_CloseTray (drive %d)\n", d);
2271 msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
2273 clr_cmdbuf();
2274 response_count=0;
2275 if (fam1_drive)
2277 drvcmd[0]=CMD1_TRAY_CTL;
2278 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2280 else if (fam2_drive)
2282 drvcmd[0]=CMD2_TRAY_CTL;
2283 drvcmd[1]=0x01;
2284 drvcmd[4]=0x03; /* "insert" */
2285 flags_cmd_out=f_putcmd|f_ResponseStatus;
2287 else if (famLV_drive)
2289 drvcmd[0]=CMDL_TRAY_CTL;
2290 if (famLV_drive)
2291 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
2292 f_ResponseStatus|f_obey_p_check|f_bit1;
2293 else
2294 flags_cmd_out=f_putcmd;
2296 else if (famT_drive)
2298 drvcmd[0]=CMDT_TRAY_CTL;
2299 drvcmd[4]=0x03; /* "insert" */
2301 i=cmd_out();
2302 msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
2304 i=cc_ReadError();
2305 flags_cmd_out |= f_respo2;
2306 cc_ReadStatus(); /* command: give 1-byte status */
2307 i=ResponseStatus();
2308 if (famT_drive&&(i<0))
2310 cc_DriveReset();
2311 i=ResponseStatus();
2312 #if 0
2313 sbp_sleep(HZ);
2314 #endif 0
2315 i=ResponseStatus();
2317 if (i<0)
2319 msg(DBG_INF,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i);
2321 if (!(famT_drive))
2323 if (!st_spinning)
2325 cc_SpinUp();
2326 if (st_check) i=cc_ReadError();
2327 flags_cmd_out |= f_respo2;
2328 cc_ReadStatus();
2329 i=ResponseStatus();
2330 } else {
2333 i=DiskInfo();
2334 return (i);
2337 static int sbpcd_tray_move(struct cdrom_device_info *cdi, int position)
2339 int i;
2340 i = MINOR(cdi->dev);
2342 switch_drive(i);
2343 if (position == 1) {
2344 cc_SpinDown();
2345 } else {
2346 return cc_CloseTray();
2348 return 0;
2351 /*==========================================================================*/
2352 static int cc_ReadSubQ(void)
2354 int i,j;
2356 D_S[d].diskstate_flags &= ~subq_bit;
2357 for (j=255;j>0;j--)
2359 clr_cmdbuf();
2360 if (fam1_drive)
2362 drvcmd[0]=CMD1_READSUBQ;
2363 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2364 response_count=11;
2366 else if (fam2_drive)
2368 drvcmd[0]=CMD2_READSUBQ;
2369 drvcmd[1]=0x02;
2370 drvcmd[3]=0x01;
2371 flags_cmd_out=f_putcmd;
2372 response_count=10;
2374 else if (fam0LV_drive)
2376 drvcmd[0]=CMD0_READSUBQ;
2377 drvcmd[1]=0x02;
2378 if (famLV_drive)
2379 flags_cmd_out=f_putcmd;
2380 else
2381 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2382 response_count=13;
2384 else if (famT_drive)
2386 response_count=12;
2387 drvcmd[0]=CMDT_READSUBQ;
2388 drvcmd[1]=0x02;
2389 drvcmd[2]=0x40;
2390 drvcmd[3]=0x01;
2391 drvcmd[8]=response_count;
2393 i=cmd_out();
2394 if (i<0) return (i);
2395 for (i=0;i<response_count;i++)
2397 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2398 msgbuf[i*3]=0;
2399 msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
2401 if (famT_drive) break;
2402 if (infobuf[0]!=0) break;
2403 if ((!st_spinning) || (j==1))
2405 D_S[d].SubQ_ctl_adr=D_S[d].SubQ_trk=D_S[d].SubQ_pnt_idx=D_S[d].SubQ_whatisthis=0;
2406 D_S[d].SubQ_run_tot=D_S[d].SubQ_run_trk=0;
2407 return (0);
2410 if (famT_drive) D_S[d].SubQ_ctl_adr=infobuf[1];
2411 else D_S[d].SubQ_ctl_adr=swap_nibbles(infobuf[1]);
2412 D_S[d].SubQ_trk=byt2bcd(infobuf[2]);
2413 D_S[d].SubQ_pnt_idx=byt2bcd(infobuf[3]);
2414 if (fam0LV_drive) i=5;
2415 else if (fam12_drive) i=4;
2416 else if (famT_drive) i=8;
2417 D_S[d].SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
2418 i=7;
2419 if (fam0LV_drive) i=9;
2420 else if (fam12_drive) i=7;
2421 else if (famT_drive) i=4;
2422 D_S[d].SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
2423 D_S[d].SubQ_whatisthis=infobuf[i+3];
2424 D_S[d].diskstate_flags |= subq_bit;
2425 return (0);
2427 /*==========================================================================*/
2428 static int cc_ModeSense(void)
2430 int i;
2432 if (fam2_drive) return (0);
2433 if (famV_drive) return (0);
2434 D_S[d].diskstate_flags &= ~frame_size_bit;
2435 clr_cmdbuf();
2436 if (fam1_drive)
2438 response_count=5;
2439 drvcmd[0]=CMD1_GETMODE;
2440 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2442 else if (fam0L_drive)
2444 response_count=2;
2445 drvcmd[0]=CMD0_GETMODE;
2446 if (famL_drive) flags_cmd_out=f_putcmd;
2447 else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2449 else if (famT_drive)
2451 response_count=10;
2452 drvcmd[0]=CMDT_GETMODE;
2453 drvcmd[4]=response_count;
2455 i=cmd_out();
2456 if (i<0) return (i);
2457 i=0;
2458 D_S[d].sense_byte=0;
2459 if (fam1_drive) D_S[d].sense_byte=infobuf[i++];
2460 else if (famT_drive)
2462 if (infobuf[4]==0x01) D_S[d].xa_byte=0x20;
2463 else D_S[d].xa_byte=0;
2464 i=2;
2466 D_S[d].frame_size=make16(infobuf[i],infobuf[i+1]);
2467 for (i=0;i<response_count;i++)
2468 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2469 msgbuf[i*3]=0;
2470 msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
2472 D_S[d].diskstate_flags |= frame_size_bit;
2473 return (0);
2475 /*==========================================================================*/
2476 /*==========================================================================*/
2477 static int cc_ModeSelect(int framesize)
2479 int i;
2481 if (fam2_drive) return (0);
2482 if (famV_drive) return (0);
2483 D_S[d].diskstate_flags &= ~frame_size_bit;
2484 clr_cmdbuf();
2485 D_S[d].frame_size=framesize;
2486 if (framesize==CD_FRAMESIZE_RAW) D_S[d].sense_byte=0x82;
2487 else D_S[d].sense_byte=0x00;
2489 msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
2490 D_S[d].sense_byte, D_S[d].frame_size);
2492 if (fam1_drive)
2494 drvcmd[0]=CMD1_SETMODE;
2495 drvcmd[1]=0x00;
2496 drvcmd[2]=D_S[d].sense_byte;
2497 drvcmd[3]=(D_S[d].frame_size>>8)&0xFF;
2498 drvcmd[4]=D_S[d].frame_size&0xFF;
2499 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2501 else if (fam0L_drive)
2503 drvcmd[0]=CMD0_SETMODE;
2504 drvcmd[1]=0x00;
2505 drvcmd[2]=(D_S[d].frame_size>>8)&0xFF;
2506 drvcmd[3]=D_S[d].frame_size&0xFF;
2507 drvcmd[4]=0x00;
2508 if(famL_drive)
2509 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
2510 else
2511 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2513 else if (famT_drive)
2515 return (-1);
2517 response_count=0;
2518 i=cmd_out();
2519 if (i<0) return (i);
2520 D_S[d].diskstate_flags |= frame_size_bit;
2521 return (0);
2523 /*==========================================================================*/
2524 static int cc_GetVolume(void)
2526 int i;
2527 u_char switches;
2528 u_char chan0=0;
2529 u_char vol0=0;
2530 u_char chan1=1;
2531 u_char vol1=0;
2533 if (famV_drive) return (0);
2534 D_S[d].diskstate_flags &= ~volume_bit;
2535 clr_cmdbuf();
2536 if (fam1_drive)
2538 drvcmd[0]=CMD1_GETMODE;
2539 drvcmd[1]=0x05;
2540 response_count=5;
2541 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2543 else if (fam2_drive)
2545 drvcmd[0]=CMD2_GETMODE;
2546 drvcmd[1]=0x0E;
2547 response_count=5;
2548 flags_cmd_out=f_putcmd;
2550 else if (fam0L_drive)
2552 drvcmd[0]=CMD0_GETMODE;
2553 drvcmd[1]=0x03;
2554 response_count=2;
2555 if(famL_drive)
2556 flags_cmd_out=f_putcmd;
2557 else
2558 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2560 else if (famT_drive)
2562 i=cc_get_mode_T();
2563 if (i<0) return (i);
2565 if (!famT_drive)
2567 i=cmd_out();
2568 if (i<0) return (i);
2570 if (fam1_drive)
2572 chan0=infobuf[1]&0x0F;
2573 vol0=infobuf[2];
2574 chan1=infobuf[3]&0x0F;
2575 vol1=infobuf[4];
2576 if (chan0==0)
2578 chan0=1;
2579 vol0=0;
2581 if (chan1==0)
2583 chan1=2;
2584 vol1=0;
2586 chan0 >>= 1;
2587 chan1 >>= 1;
2589 else if (fam2_drive)
2591 chan0=infobuf[1];
2592 vol0=infobuf[2];
2593 chan1=infobuf[3];
2594 vol1=infobuf[4];
2596 else if (famL_drive)
2598 chan0=0;
2599 chan1=1;
2600 vol0=vol1=infobuf[1];
2601 switches=infobuf[0];
2602 if ((switches&0x80)!=0) chan0=1;
2603 if ((switches&0x40)!=0) chan1=0;
2605 else if (fam0_drive) /* different firmware levels */
2607 chan0=0;
2608 chan1=1;
2609 vol0=vol1=infobuf[1];
2610 if (D_S[d].drv_type>=drv_201)
2612 if (D_S[d].drv_type<drv_300)
2614 switches=infobuf[0];
2615 if ((switches&0x80)!=0) vol0=0;
2616 if ((switches&0x40)!=0) vol1=0;
2617 if (D_S[d].drv_type>=drv_211)
2619 if ((switches&0x20)!=0) chan0=1;
2620 if ((switches&0x10)!=0) chan1=0;
2623 else
2625 vol0=infobuf[0];
2626 if ((vol0&0x01)!=0) chan0=1;
2627 if ((vol1&0x01)==0) chan1=0;
2628 vol0 &= 0xFC;
2629 vol1 &= 0xFC;
2630 if (vol0!=0) vol0 += 3;
2631 if (vol1!=0) vol1 += 3;
2635 else if (famT_drive)
2637 D_S[d].volume_control=infobuf[7];
2638 chan0=0;
2639 chan1=1;
2640 if (D_S[d].volume_control&0x10) vol0=0;
2641 else vol0=0xff;
2642 if (D_S[d].volume_control&0x20) vol1=0;
2643 else vol1=0xff;
2645 D_S[d].vol_chan0=chan0;
2646 D_S[d].vol_ctrl0=vol0;
2647 D_S[d].vol_chan1=chan1;
2648 D_S[d].vol_ctrl1=vol1;
2649 #if 000
2650 D_S[d].vol_chan2=2;
2651 D_S[d].vol_ctrl2=0xFF;
2652 D_S[d].vol_chan3=3;
2653 D_S[d].vol_ctrl3=0xFF;
2654 #endif 000
2655 D_S[d].diskstate_flags |= volume_bit;
2656 return (0);
2658 /*==========================================================================*/
2659 static int cc_ReadCapacity(void)
2661 int i, j;
2663 if (fam2_drive) return (0); /* some firmware lacks this command */
2664 if (famLV_drive) return (0); /* some firmware lacks this command */
2665 if (famT_drive) return (0); /* done with cc_ReadTocDescr() */
2666 D_S[d].diskstate_flags &= ~cd_size_bit;
2667 for (j=3;j>0;j--)
2669 clr_cmdbuf();
2670 if (fam1_drive)
2672 drvcmd[0]=CMD1_CAPACITY;
2673 response_count=5;
2674 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2676 #if 00
2677 else if (fam2_drive)
2679 drvcmd[0]=CMD2_CAPACITY;
2680 response_count=8;
2681 flags_cmd_out=f_putcmd;
2683 #endif
2684 else if (fam0_drive)
2686 drvcmd[0]=CMD0_CAPACITY;
2687 response_count=5;
2688 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2690 i=cmd_out();
2691 if (i>=0) break;
2692 msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
2693 cc_ReadError();
2695 if (j==0) return (i);
2696 if (fam1_drive) D_S[d].CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_MSF_OFFSET;
2697 else if (fam0_drive) D_S[d].CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
2698 #if 00
2699 else if (fam2_drive) D_S[d].CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
2700 #endif
2701 D_S[d].diskstate_flags |= cd_size_bit;
2702 msg(DBG_000,"cc_ReadCapacity: %d frames.\n", D_S[d].CDsize_frm);
2703 return (0);
2705 /*==========================================================================*/
2706 static int cc_ReadTocDescr(void)
2708 int i;
2710 D_S[d].diskstate_flags &= ~toc_bit;
2711 clr_cmdbuf();
2712 if (fam1_drive)
2714 drvcmd[0]=CMD1_DISKINFO;
2715 response_count=6;
2716 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2718 else if (fam0LV_drive)
2720 drvcmd[0]=CMD0_DISKINFO;
2721 response_count=6;
2722 if(famLV_drive)
2723 flags_cmd_out=f_putcmd;
2724 else
2725 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2727 else if (fam2_drive)
2729 /* possibly longer timeout periods necessary */
2730 D_S[d].f_multisession=0;
2731 drvcmd[0]=CMD2_DISKINFO;
2732 drvcmd[1]=0x02;
2733 drvcmd[2]=0xAB;
2734 drvcmd[3]=0xFF; /* session */
2735 response_count=8;
2736 flags_cmd_out=f_putcmd;
2738 else if (famT_drive)
2740 D_S[d].f_multisession=0;
2741 response_count=12;
2742 drvcmd[0]=CMDT_DISKINFO;
2743 drvcmd[1]=0x02;
2744 drvcmd[6]=CDROM_LEADOUT;
2745 drvcmd[8]=response_count;
2746 drvcmd[9]=0x00;
2748 i=cmd_out();
2749 if (i<0) return (i);
2750 if ((famT_drive)&&(i<response_count)) return (-100-i);
2751 if ((fam1_drive)||(fam2_drive)||(fam0LV_drive))
2752 D_S[d].xa_byte=infobuf[0];
2753 if (fam2_drive)
2755 D_S[d].first_session=infobuf[1];
2756 D_S[d].last_session=infobuf[2];
2757 D_S[d].n_first_track=infobuf[3];
2758 D_S[d].n_last_track=infobuf[4];
2759 if (D_S[d].first_session!=D_S[d].last_session)
2761 D_S[d].f_multisession=1;
2762 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
2764 #if 0
2765 if (D_S[d].first_session!=D_S[d].last_session)
2767 if (D_S[d].last_session<=20)
2768 zwanzig=D_S[d].last_session+1;
2769 else zwanzig=20;
2770 for (count=D_S[d].first_session;count<zwanzig;count++)
2772 drvcmd[0]=CMD2_DISKINFO;
2773 drvcmd[1]=0x02;
2774 drvcmd[2]=0xAB;
2775 drvcmd[3]=count;
2776 response_count=8;
2777 flags_cmd_out=f_putcmd;
2778 i=cmd_out();
2779 if (i<0) return (i);
2780 D_S[d].msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
2782 D_S[d].diskstate_flags |= multisession_bit;
2784 #endif
2785 drvcmd[0]=CMD2_DISKINFO;
2786 drvcmd[1]=0x02;
2787 drvcmd[2]=0xAA;
2788 drvcmd[3]=0xFF;
2789 response_count=5;
2790 flags_cmd_out=f_putcmd;
2791 i=cmd_out();
2792 if (i<0) return (i);
2793 D_S[d].size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
2794 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2795 D_S[d].CDsize_frm=D_S[d].size_blk+1;
2797 else if (famT_drive)
2799 D_S[d].size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
2800 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2801 D_S[d].CDsize_frm=D_S[d].size_blk+1;
2802 D_S[d].n_first_track=infobuf[2];
2803 D_S[d].n_last_track=infobuf[3];
2805 else
2807 D_S[d].n_first_track=infobuf[1];
2808 D_S[d].n_last_track=infobuf[2];
2809 D_S[d].size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
2810 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2811 if (famLV_drive) D_S[d].CDsize_frm=D_S[d].size_blk+1;
2813 D_S[d].diskstate_flags |= toc_bit;
2814 msg(DBG_TOC,"TocDesc: xa %02X firstt %02X lastt %02X size %08X firstses %02X lastsess %02X\n",
2815 D_S[d].xa_byte,
2816 D_S[d].n_first_track,
2817 D_S[d].n_last_track,
2818 D_S[d].size_msf,
2819 D_S[d].first_session,
2820 D_S[d].last_session);
2821 return (0);
2823 /*==========================================================================*/
2824 static int cc_ReadTocEntry(int num)
2826 int i;
2828 clr_cmdbuf();
2829 if (fam1_drive)
2831 drvcmd[0]=CMD1_READTOC;
2832 drvcmd[2]=num;
2833 response_count=8;
2834 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2836 else if (fam2_drive)
2838 /* possibly longer timeout periods necessary */
2839 drvcmd[0]=CMD2_DISKINFO;
2840 drvcmd[1]=0x02;
2841 drvcmd[2]=num;
2842 response_count=5;
2843 flags_cmd_out=f_putcmd;
2845 else if (fam0LV_drive)
2847 drvcmd[0]=CMD0_READTOC;
2848 drvcmd[1]=0x02;
2849 drvcmd[2]=num;
2850 response_count=8;
2851 if (famLV_drive)
2852 flags_cmd_out=f_putcmd;
2853 else
2854 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2856 else if (famT_drive)
2858 response_count=12;
2859 drvcmd[0]=CMDT_DISKINFO;
2860 drvcmd[1]=0x02;
2861 drvcmd[6]=num;
2862 drvcmd[8]=response_count;
2863 drvcmd[9]=0x00;
2865 i=cmd_out();
2866 if (i<0) return (i);
2867 if ((famT_drive)&&(i<response_count)) return (-100-i);
2868 if ((fam1_drive)||(fam0LV_drive))
2870 D_S[d].TocEnt_nixbyte=infobuf[0];
2871 i=1;
2873 else if (fam2_drive) i=0;
2874 else if (famT_drive) i=5;
2875 D_S[d].TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
2876 if ((fam1_drive)||(fam0L_drive))
2878 D_S[d].TocEnt_number=infobuf[i++];
2879 D_S[d].TocEnt_format=infobuf[i];
2881 else
2883 D_S[d].TocEnt_number=num;
2884 D_S[d].TocEnt_format=0;
2886 if (fam1_drive) i=4;
2887 else if (fam0LV_drive) i=5;
2888 else if (fam2_drive) i=2;
2889 else if (famT_drive) i=9;
2890 D_S[d].TocEnt_address=make32(make16(0,infobuf[i]),
2891 make16(infobuf[i+1],infobuf[i+2]));
2892 for (i=0;i<response_count;i++)
2893 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2894 msgbuf[i*3]=0;
2895 msg(DBG_ECS,"TocEntry:%s\n", msgbuf);
2896 msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
2897 D_S[d].TocEnt_nixbyte, D_S[d].TocEnt_ctl_adr,
2898 D_S[d].TocEnt_number, D_S[d].TocEnt_format,
2899 D_S[d].TocEnt_address);
2900 return (0);
2902 /*==========================================================================*/
2903 static int cc_ReadPacket(void)
2905 int i;
2907 clr_cmdbuf();
2908 drvcmd[0]=CMD0_PACKET;
2909 drvcmd[1]=response_count;
2910 if(famL_drive) flags_cmd_out=f_putcmd;
2911 else if (fam01_drive)
2912 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2913 else if (fam2_drive) return (-1); /* not implemented yet */
2914 else if (famT_drive)
2916 return (-1);
2918 i=cmd_out();
2919 return (i);
2921 /*==========================================================================*/
2922 static int convert_UPC(u_char *p)
2924 int i;
2926 p++;
2927 if (fam0L_drive) p[13]=0;
2928 for (i=0;i<7;i++)
2930 if (fam1_drive) D_S[d].UPC_buf[i]=swap_nibbles(*p++);
2931 else if (fam0L_drive)
2933 D_S[d].UPC_buf[i]=((*p++)<<4)&0xFF;
2934 D_S[d].UPC_buf[i] |= *p++;
2936 else if (famT_drive)
2938 return (-1);
2940 else /* CD200 */
2942 return (-1);
2945 D_S[d].UPC_buf[6] &= 0xF0;
2946 return (0);
2948 /*==========================================================================*/
2949 static int cc_ReadUPC(void)
2951 int i;
2952 #if TEST_UPC
2953 int block, checksum;
2954 #endif TEST_UPC
2956 if (fam2_drive) return (0); /* not implemented yet */
2957 if (famT_drive) return (0); /* not implemented yet */
2958 if (famV_drive) return (0); /* not implemented yet */
2959 #if 1
2960 if (fam0_drive) return (0); /* but it should work */
2961 #endif 1
2963 D_S[d].diskstate_flags &= ~upc_bit;
2964 #if TEST_UPC
2965 for (block=CD_MSF_OFFSET+1;block<CD_MSF_OFFSET+200;block++)
2967 #endif TEST_UPC
2968 clr_cmdbuf();
2969 if (fam1_drive)
2971 drvcmd[0]=CMD1_READ_UPC;
2972 #if TEST_UPC
2973 drvcmd[1]=(block>>16)&0xFF;
2974 drvcmd[2]=(block>>8)&0xFF;
2975 drvcmd[3]=block&0xFF;
2976 #endif TEST_UPC
2977 response_count=8;
2978 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2980 else if (fam0L_drive)
2982 drvcmd[0]=CMD0_READ_UPC;
2983 #if TEST_UPC
2984 drvcmd[2]=(block>>16)&0xFF;
2985 drvcmd[3]=(block>>8)&0xFF;
2986 drvcmd[4]=block&0xFF;
2987 #endif TEST_UPC
2988 response_count=0;
2989 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
2991 else if (fam2_drive)
2993 return (-1);
2995 else if (famT_drive)
2997 return (-1);
2999 i=cmd_out();
3000 if (i<0)
3002 msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
3003 return (i);
3005 if (fam0L_drive)
3007 response_count=16;
3008 if (famL_drive) flags_cmd_out=f_putcmd;
3009 i=cc_ReadPacket();
3010 if (i<0)
3012 msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
3013 return (i);
3016 #if TEST_UPC
3017 checksum=0;
3018 #endif TEST_UPC
3019 for (i=0;i<(fam1_drive?8:16);i++)
3021 #if TEST_UPC
3022 checksum |= infobuf[i];
3023 #endif TEST_UPC
3024 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3026 msgbuf[i*3]=0;
3027 msg(DBG_UPC,"UPC info:%s\n", msgbuf);
3028 #if TEST_UPC
3029 if ((checksum&0x7F)!=0) break;
3031 #endif TEST_UPC
3032 D_S[d].UPC_ctl_adr=0;
3033 if (fam1_drive) i=0;
3034 else i=2;
3035 if ((infobuf[i]&0x80)!=0)
3037 convert_UPC(&infobuf[i]);
3038 D_S[d].UPC_ctl_adr = (D_S[d].TocEnt_ctl_adr & 0xF0) | 0x02;
3040 for (i=0;i<7;i++)
3041 sprintf(&msgbuf[i*3], " %02X", D_S[d].UPC_buf[i]);
3042 sprintf(&msgbuf[i*3], " (%02X)", D_S[d].UPC_ctl_adr);
3043 msgbuf[i*3+5]=0;
3044 msg(DBG_UPC,"UPC code:%s\n", msgbuf);
3045 D_S[d].diskstate_flags |= upc_bit;
3046 return (0);
3049 static int sbpcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
3051 int i;
3052 unsigned char *mcnp = mcn->medium_catalog_number;
3053 unsigned char *resp;
3055 D_S[d].diskstate_flags &= ~upc_bit;
3056 clr_cmdbuf();
3057 if (fam1_drive)
3059 drvcmd[0]=CMD1_READ_UPC;
3060 response_count=8;
3061 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
3063 else if (fam0L_drive)
3065 drvcmd[0]=CMD0_READ_UPC;
3066 response_count=0;
3067 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
3069 else if (fam2_drive)
3071 return (-1);
3073 else if (famT_drive)
3075 return (-1);
3077 i=cmd_out();
3078 if (i<0)
3080 msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
3081 return (i);
3083 if (fam0L_drive)
3085 response_count=16;
3086 if (famL_drive) flags_cmd_out=f_putcmd;
3087 i=cc_ReadPacket();
3088 if (i<0)
3090 msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
3091 return (i);
3094 D_S[d].UPC_ctl_adr=0;
3095 if (fam1_drive) i=0;
3096 else i=2;
3098 resp = infobuf + i;
3099 if (*resp++ == 0x80) {
3100 /* packed bcd to single ASCII digits */
3101 *mcnp++ = (*resp >> 4) + '0';
3102 *mcnp++ = (*resp++ & 0x0f) + '0';
3103 *mcnp++ = (*resp >> 4) + '0';
3104 *mcnp++ = (*resp++ & 0x0f) + '0';
3105 *mcnp++ = (*resp >> 4) + '0';
3106 *mcnp++ = (*resp++ & 0x0f) + '0';
3107 *mcnp++ = (*resp >> 4) + '0';
3108 *mcnp++ = (*resp++ & 0x0f) + '0';
3109 *mcnp++ = (*resp >> 4) + '0';
3110 *mcnp++ = (*resp++ & 0x0f) + '0';
3111 *mcnp++ = (*resp >> 4) + '0';
3112 *mcnp++ = (*resp++ & 0x0f) + '0';
3113 *mcnp++ = (*resp >> 4) + '0';
3115 *mcnp = '\0';
3117 D_S[d].diskstate_flags |= upc_bit;
3118 return (0);
3121 /*==========================================================================*/
3122 static int cc_CheckMultiSession(void)
3124 int i;
3126 if (fam2_drive) return (0);
3127 D_S[d].f_multisession=0;
3128 D_S[d].lba_multi=0;
3129 if (fam0_drive) return (0);
3130 clr_cmdbuf();
3131 if (fam1_drive)
3133 drvcmd[0]=CMD1_MULTISESS;
3134 response_count=6;
3135 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
3136 i=cmd_out();
3137 if (i<0) return (i);
3138 if ((infobuf[0]&0x80)!=0)
3140 D_S[d].f_multisession=1;
3141 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[1]),
3142 make16(infobuf[2],infobuf[3])));
3145 else if (famLV_drive)
3147 drvcmd[0]=CMDL_MULTISESS;
3148 drvcmd[1]=3;
3149 drvcmd[2]=1;
3150 response_count=8;
3151 flags_cmd_out=f_putcmd;
3152 i=cmd_out();
3153 if (i<0) return (i);
3154 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),
3155 make16(infobuf[6],infobuf[7])));
3157 else if (famT_drive)
3159 response_count=12;
3160 drvcmd[0]=CMDT_DISKINFO;
3161 drvcmd[1]=0x02;
3162 drvcmd[6]=0;
3163 drvcmd[8]=response_count;
3164 drvcmd[9]=0x40;
3165 i=cmd_out();
3166 if (i<0) return (i);
3167 if (i<response_count) return (-100-i);
3168 D_S[d].first_session=infobuf[2];
3169 D_S[d].last_session=infobuf[3];
3170 D_S[d].track_of_last_session=infobuf[6];
3171 if (D_S[d].first_session!=D_S[d].last_session)
3173 D_S[d].f_multisession=1;
3174 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
3177 for (i=0;i<response_count;i++)
3178 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3179 msgbuf[i*3]=0;
3180 msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, D_S[d].lba_multi);
3181 if (D_S[d].lba_multi>200)
3183 D_S[d].f_multisession=1;
3184 msg(DBG_MUL,"MultiSession base: %06X\n", D_S[d].lba_multi);
3186 return (0);
3188 /*==========================================================================*/
3189 #if FUTURE
3190 static int cc_SubChanInfo(int frame, int count, u_char *buffer)
3191 /* "frame" is a RED BOOK (msf-bin) address */
3193 int i;
3195 if (fam0LV_drive) return (-ENOSYS); /* drive firmware lacks it */
3196 if (famT_drive)
3198 return (-1);
3200 #if 0
3201 if (D_S[d].audio_state!=audio_playing) return (-ENODATA);
3202 #endif
3203 clr_cmdbuf();
3204 drvcmd[0]=CMD1_SUBCHANINF;
3205 drvcmd[1]=(frame>>16)&0xFF;
3206 drvcmd[2]=(frame>>8)&0xFF;
3207 drvcmd[3]=frame&0xFF;
3208 drvcmd[5]=(count>>8)&0xFF;
3209 drvcmd[6]=count&0xFF;
3210 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
3211 cmd_type=READ_SC;
3212 D_S[d].frame_size=CD_FRAMESIZE_SUB;
3213 i=cmd_out(); /* which buffer to use? */
3214 return (i);
3216 #endif FUTURE
3217 /*==========================================================================*/
3218 __initfunc(static void check_datarate(void))
3220 int i=0;
3222 msg(DBG_IOX,"check_datarate entered.\n");
3223 datarate=0;
3224 #if TEST_STI
3225 for (i=0;i<=1000;i++) printk(".");
3226 #endif
3227 /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
3228 #if 1
3229 del_timer(&delay_timer);
3230 #endif
3231 delay_timer.expires=jiffies+11*HZ/10;
3232 timed_out_delay=0;
3233 add_timer(&delay_timer);
3234 #if 0
3235 msg(DBG_TIM,"delay timer started (11*HZ/10).\n");
3236 #endif
3239 i=inb(CDi_status);
3240 datarate++;
3241 #if 1
3242 if (datarate>0x6FFFFFFF) break;
3243 #endif 00000
3245 while (!timed_out_delay);
3246 del_timer(&delay_timer);
3247 #if 0
3248 msg(DBG_TIM,"datarate: %04X\n", datarate);
3249 #endif
3250 if (datarate<65536) datarate=65536;
3251 maxtim16=datarate*16;
3252 maxtim04=datarate*4;
3253 maxtim02=datarate*2;
3254 maxtim_8=datarate/32;
3255 #if LONG_TIMING
3256 maxtim_data=datarate/100;
3257 #else
3258 maxtim_data=datarate/300;
3259 #endif LONG_TIMING
3260 #if 0
3261 msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8, maxtim_data);
3262 #endif
3264 /*==========================================================================*/
3265 #if 0
3266 static int c2_ReadError(int fam)
3268 int i;
3270 clr_cmdbuf();
3271 response_count=9;
3272 clr_respo_buf(9);
3273 if (fam==1)
3275 drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
3276 i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
3278 else if (fam==2)
3280 drvcmd[0]=CMD2_READ_ERR;
3281 i=do_cmd(f_putcmd);
3283 else return (-1);
3284 return (i);
3286 #endif
3287 /*==========================================================================*/
3288 __initfunc(static void ask_mail(void))
3290 int i;
3292 msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de\n");
3293 msg(DBG_INF, "(don't mail if you are not using the actual kernel):\n");
3294 msg(DBG_INF, "%s\n", VERSION);
3295 msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
3296 CDo_command, type, D_S[d].drive_model, D_S[d].drv_id);
3297 for (i=0;i<12;i++)
3298 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3299 msgbuf[i*3]=0;
3300 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3301 for (i=0;i<12;i++)
3302 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3303 msgbuf[i*3]=0;
3304 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3306 /*==========================================================================*/
3307 __initfunc(static int check_version(void))
3309 int i, j, l;
3310 int teac_possible=0;
3312 msg(DBG_INI,"check_version: id=%d, d=%d.\n", D_S[d].drv_id, d);
3313 D_S[d].drv_type=0;
3315 /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
3316 /* clear any pending error state */
3317 clr_cmdbuf();
3318 drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
3319 response_count=9;
3320 flags_cmd_out=f_putcmd;
3321 i=cmd_out();
3322 if (i<0) msg(DBG_INI,"CMD0_READ_ERR returns %d (ok anyway).\n",i);
3323 /* read drive version */
3324 clr_cmdbuf();
3325 for (i=0;i<12;i++) infobuf[i]=0;
3326 drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
3327 response_count=12; /* fam1: only 11 */
3328 flags_cmd_out=f_putcmd;
3329 i=cmd_out();
3330 if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
3331 if (i==-11) teac_possible++;
3332 j=0;
3333 for (i=0;i<12;i++) j+=infobuf[i];
3334 if (j)
3336 for (i=0;i<12;i++)
3337 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3338 msgbuf[i*3]=0;
3339 msg(DBG_ECS,"infobuf =%s\n", msgbuf);
3340 for (i=0;i<12;i++)
3341 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3342 msgbuf[i*3]=0;
3343 msg(DBG_ECS,"infobuf =%s\n", msgbuf);
3345 for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
3346 if (i==4)
3348 D_S[d].drive_model[0]='C';
3349 D_S[d].drive_model[1]='R';
3350 D_S[d].drive_model[2]='-';
3351 D_S[d].drive_model[3]='5';
3352 D_S[d].drive_model[4]=infobuf[i++];
3353 D_S[d].drive_model[5]=infobuf[i++];
3354 D_S[d].drive_model[6]=0;
3355 D_S[d].drv_type=drv_fam1;
3357 if (!D_S[d].drv_type)
3359 for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
3360 if (i==8)
3362 D_S[d].drive_model[0]='C';
3363 D_S[d].drive_model[1]='R';
3364 D_S[d].drive_model[2]='-';
3365 D_S[d].drive_model[3]='5';
3366 D_S[d].drive_model[4]='2';
3367 D_S[d].drive_model[5]='x';
3368 D_S[d].drive_model[6]=0;
3369 D_S[d].drv_type=drv_fam0;
3372 if (!D_S[d].drv_type)
3374 for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
3375 if (i==8)
3377 for (j=0;j<8;j++)
3378 D_S[d].drive_model[j]=infobuf[j];
3379 D_S[d].drive_model[8]=0;
3380 D_S[d].drv_type=drv_famL;
3383 if (!D_S[d].drv_type)
3385 for (i=0;i<6;i++) if (infobuf[i]!=familyV[i]) break;
3386 if (i==6)
3388 for (j=0;j<6;j++)
3389 D_S[d].drive_model[j]=infobuf[j];
3390 D_S[d].drive_model[6]=0;
3391 D_S[d].drv_type=drv_famV;
3392 i+=2; /* 2 blanks before version */
3395 if (!D_S[d].drv_type)
3397 /* check for CD200 */
3398 clr_cmdbuf();
3399 drvcmd[0]=CMD2_READ_ERR;
3400 response_count=9;
3401 flags_cmd_out=f_putcmd;
3402 i=cmd_out();
3403 if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
3404 if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
3405 /* read drive version */
3406 clr_cmdbuf();
3407 for (i=0;i<12;i++) infobuf[i]=0;
3408 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
3409 #if 0
3410 OUT(CDo_reset,0);
3411 sbp_sleep(6*HZ);
3412 OUT(CDo_enable,D_S[d].drv_sel);
3413 #endif 0
3414 drvcmd[0]=CMD2_READ_VER;
3415 response_count=12;
3416 flags_cmd_out=f_putcmd;
3417 i=cmd_out();
3418 if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
3419 if (i==-7) teac_possible++;
3420 j=0;
3421 for (i=0;i<12;i++) j+=infobuf[i];
3422 if (j)
3424 for (i=0;i<12;i++)
3425 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3426 msgbuf[i*3]=0;
3427 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3428 for (i=0;i<12;i++)
3429 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3430 msgbuf[i*3]=0;
3431 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3433 if (i>=0)
3435 for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
3436 if (i==5)
3438 D_S[d].drive_model[0]='C';
3439 D_S[d].drive_model[1]='D';
3440 D_S[d].drive_model[2]='2';
3441 D_S[d].drive_model[3]='0';
3442 D_S[d].drive_model[4]='0';
3443 D_S[d].drive_model[5]=infobuf[i++];
3444 D_S[d].drive_model[6]=infobuf[i++];
3445 D_S[d].drive_model[7]=0;
3446 D_S[d].drv_type=drv_fam2;
3450 if (!D_S[d].drv_type)
3452 /* check for TEAC CD-55A */
3453 msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
3454 for (j=1;j<=((D_S[d].drv_id==0)?3:1);j++)
3456 for (l=1;l<=((D_S[d].drv_id==0)?10:1);l++)
3458 msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
3459 if (sbpro_type==1) OUT(CDo_reset,0);
3460 else
3462 OUT(CDo_enable,D_S[d].drv_sel);
3463 OUT(CDo_sel_i_d,0);
3464 OUT(CDo_command,CMDT_RESET);
3465 for (i=0;i<9;i++) OUT(CDo_command,0);
3467 sbp_sleep(5*HZ/10);
3468 OUT(CDo_enable,D_S[d].drv_sel);
3469 OUT(CDo_sel_i_d,0);
3470 i=inb(CDi_status);
3471 msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
3472 #if 0
3473 if (i&s_not_result_ready) continue; /* drive not present or ready */
3474 #endif
3475 i=inb(CDi_info);
3476 msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
3477 if (i==0x55) break; /* drive found */
3479 if (i==0x55) break; /* drive found */
3481 if (i==0x55) /* drive found */
3483 msg(DBG_TEA,"TEAC drive found.\n");
3484 clr_cmdbuf();
3485 flags_cmd_out=f_putcmd;
3486 response_count=12;
3487 drvcmd[0]=CMDT_READ_VER;
3488 drvcmd[4]=response_count;
3489 for (i=0;i<12;i++) infobuf[i]=0;
3490 i=cmd_out_T();
3491 if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
3492 for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
3493 if (i==6)
3495 D_S[d].drive_model[0]='C';
3496 D_S[d].drive_model[1]='D';
3497 D_S[d].drive_model[2]='-';
3498 D_S[d].drive_model[3]='5';
3499 D_S[d].drive_model[4]='5';
3500 D_S[d].drive_model[5]=0;
3501 D_S[d].drv_type=drv_famT;
3505 if (!D_S[d].drv_type)
3507 msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,D_S[d].drv_id);
3508 return (-522);
3510 for (j=0;j<4;j++) D_S[d].firmware_version[j]=infobuf[i+j];
3511 if (famL_drive)
3513 u_char lcs_firm_e1[]="A E1";
3514 u_char lcs_firm_f4[]="A4F4";
3516 for (j=0;j<4;j++)
3517 if (D_S[d].firmware_version[j]!=lcs_firm_e1[j]) break;
3518 if (j==4) D_S[d].drv_type=drv_e1;
3520 for (j=0;j<4;j++)
3521 if (D_S[d].firmware_version[j]!=lcs_firm_f4[j]) break;
3522 if (j==4) D_S[d].drv_type=drv_f4;
3524 if (D_S[d].drv_type==drv_famL) ask_mail();
3526 else if (famT_drive)
3528 j=infobuf[4]; /* one-byte version??? - here: 0x15 */
3529 if (j=='5')
3531 D_S[d].firmware_version[0]=infobuf[7];
3532 D_S[d].firmware_version[1]=infobuf[8];
3533 D_S[d].firmware_version[2]=infobuf[10];
3534 D_S[d].firmware_version[3]=infobuf[11];
3536 else
3538 if (j!=0x15) ask_mail();
3539 D_S[d].firmware_version[0]='0';
3540 D_S[d].firmware_version[1]='.';
3541 D_S[d].firmware_version[2]='0'+(j>>4);
3542 D_S[d].firmware_version[3]='0'+(j&0x0f);
3545 else /* CR-52x, CR-56x, CD200, ECS-AT */
3547 j = (D_S[d].firmware_version[0] & 0x0F) * 100 +
3548 (D_S[d].firmware_version[2] & 0x0F) *10 +
3549 (D_S[d].firmware_version[3] & 0x0F);
3550 if (fam0_drive)
3552 if (j<200) D_S[d].drv_type=drv_199;
3553 else if (j<201) D_S[d].drv_type=drv_200;
3554 else if (j<210) D_S[d].drv_type=drv_201;
3555 else if (j<211) D_S[d].drv_type=drv_210;
3556 else if (j<300) D_S[d].drv_type=drv_211;
3557 else if (j>=300) D_S[d].drv_type=drv_300;
3559 else if (fam1_drive)
3561 if (j<100) D_S[d].drv_type=drv_099;
3562 else
3564 D_S[d].drv_type=drv_100;
3565 if ((j!=500)&&(j!=102)) ask_mail();
3568 else if (fam2_drive)
3570 if (D_S[d].drive_model[5]=='F')
3572 if ((j!=1)&&(j!=35)&&(j!=200)&&(j!=210))
3573 ask_mail(); /* unknown version at time */
3575 else
3577 msg(DBG_INF,"this CD200 drive is not fully supported yet - only audio will work.\n");
3578 if ((j!=101)&&(j!=35))
3579 ask_mail(); /* unknown version at time */
3582 else if (famV_drive)
3584 if ((j==100)||(j==150)) D_S[d].drv_type=drv_at;
3585 ask_mail(); /* hopefully we get some feedback by this */
3588 msg(DBG_LCS,"drive type %02X\n",D_S[d].drv_type);
3589 msg(DBG_INI,"check_version done.\n");
3590 return (0);
3592 /*==========================================================================*/
3593 static void switch_drive(int i)
3595 d=i;
3596 OUT(CDo_enable,D_S[d].drv_sel);
3597 msg(DBG_DID,"drive %d (ID=%d) activated.\n", i, D_S[d].drv_id);
3598 return;
3600 /*==========================================================================*/
3601 #ifdef PATH_CHECK
3603 * probe for the presence of an interface card
3605 __initfunc(static int check_card(int port))
3607 #undef N_RESPO
3608 #define N_RESPO 20
3609 int i, j, k;
3610 u_char response[N_RESPO];
3611 u_char save_port0;
3612 u_char save_port3;
3614 msg(DBG_INI,"check_card entered.\n");
3615 save_port0=inb(port+0);
3616 save_port3=inb(port+3);
3618 for (j=0;j<NR_SBPCD;j++)
3620 OUT(port+3,j) ; /* enable drive #j */
3621 OUT(port+0,CMD0_PATH_CHECK);
3622 for (i=10;i>0;i--) OUT(port+0,0);
3623 for (k=0;k<N_RESPO;k++) response[k]=0;
3624 for (k=0;k<N_RESPO;k++)
3626 for (i=10000;i>0;i--)
3628 if (inb(port+1)&s_not_result_ready) continue;
3629 response[k]=inb(port+0);
3630 break;
3633 for (i=0;i<N_RESPO;i++)
3634 sprintf(&msgbuf[i*3], " %02X", response[i]);
3635 msgbuf[i*3]=0;
3636 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3637 OUT(port+0,CMD0_PATH_CHECK);
3638 for (i=10;i>0;i--) OUT(port+0,0);
3639 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3640 for (k=0;k<N_RESPO;k++)
3642 for (i=10000;i>0;i--)
3644 if (inb(port+1)&s_not_result_ready) continue;
3645 response[k]=inb(port+0);
3646 break;
3649 for (i=0;i<N_RESPO;i++)
3650 sprintf(&msgbuf[i*3], " %02X", response[i]);
3651 msgbuf[i*3]=0;
3652 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3654 if (response[0]==0xAA)
3655 if (response[1]==0x55)
3656 return (0);
3658 for (j=0;j<NR_SBPCD;j++)
3660 OUT(port+3,j) ; /* enable drive #j */
3661 OUT(port+0,CMD2_READ_VER);
3662 for (i=10;i>0;i--) OUT(port+0,0);
3663 for (k=0;k<N_RESPO;k++) response[k]=0;
3664 for (k=0;k<N_RESPO;k++)
3666 for (i=1000000;i>0;i--)
3668 if (inb(port+1)&s_not_result_ready) continue;
3669 response[k]=inb(port+0);
3670 break;
3673 for (i=0;i<N_RESPO;i++)
3674 sprintf(&msgbuf[i*3], " %02X", response[i]);
3675 msgbuf[i*3]=0;
3676 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3678 OUT(port+0,CMD2_READ_VER);
3679 for (i=10;i>0;i--) OUT(port+0,0);
3680 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3681 for (k=0;k<N_RESPO;k++)
3683 for (i=1000000;i>0;i--)
3685 if (inb(port+1)&s_not_result_ready) continue;
3686 response[k]=inb(port+0);
3687 break;
3690 for (i=0;i<N_RESPO;i++)
3691 sprintf(&msgbuf[i*3], " %02X", response[i]);
3692 msgbuf[i*3]=0;
3693 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3695 if (response[0]==0xAA)
3696 if (response[1]==0x55)
3697 return (0);
3699 OUT(port+0,save_port0);
3700 OUT(port+3,save_port3);
3701 return (0); /* in any case - no real "function" at time */
3703 #endif PATH_CHECK
3704 /*==========================================================================*/
3705 /*==========================================================================*/
3707 * probe for the presence of drives on the selected controller
3709 __initfunc(static int check_drives(void))
3711 int i, j;
3713 msg(DBG_INI,"check_drives entered.\n");
3714 ndrives=0;
3715 for (j=0;j<MAX_DRIVES;j++)
3717 D_S[ndrives].drv_id=j;
3718 if (sbpro_type==1) D_S[ndrives].drv_sel=(j&0x01)<<1|(j&0x02)>>1;
3719 else D_S[ndrives].drv_sel=j;
3720 switch_drive(ndrives);
3721 msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3722 msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3723 i=check_version();
3724 if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
3725 else
3727 D_S[d].drv_options=drv_pattern[j];
3728 if (fam0L_drive) D_S[d].drv_options&=~(speed_auto|speed_300|speed_150);
3729 msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
3731 D_S[d].drv_id,
3732 D_S[d].drive_model,
3733 D_S[d].firmware_version,
3734 CDo_command,
3735 sbpro_type);
3736 ndrives++;
3739 for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
3740 if (ndrives==0) return (-1);
3741 return (0);
3743 /*==========================================================================*/
3744 #if FUTURE
3746 * obtain if requested service disturbs current audio state
3748 static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
3750 switch (audio_state) /* audio status from controller */
3752 case aud_11: /* "audio play in progress" */
3753 case audx11:
3754 switch (func) /* DOS command code */
3756 case cmd_07: /* input flush */
3757 case cmd_0d: /* open device */
3758 case cmd_0e: /* close device */
3759 case cmd_0c: /* ioctl output */
3760 return (1);
3761 case cmd_03: /* ioctl input */
3762 switch (subfunc)
3763 /* DOS ioctl input subfunction */
3765 case cxi_00:
3766 case cxi_06:
3767 case cxi_09:
3768 return (1);
3769 default:
3770 return (ERROR15);
3772 return (1);
3773 default:
3774 return (ERROR15);
3776 return (1);
3777 case aud_12: /* "audio play paused" */
3778 case audx12:
3779 return (1);
3780 default:
3781 return (2);
3784 /*==========================================================================*/
3785 /* allowed is only
3786 * ioctl_o, flush_input, open_device, close_device,
3787 * tell_address, tell_volume, tell_capabiliti,
3788 * tell_framesize, tell_CD_changed, tell_audio_posi
3790 static int check_allowed1(u_char func1, u_char func2)
3792 #if 000
3793 if (func1==ioctl_o) return (0);
3794 if (func1==read_long) return (-1);
3795 if (func1==read_long_prefetch) return (-1);
3796 if (func1==seek) return (-1);
3797 if (func1==audio_play) return (-1);
3798 if (func1==audio_pause) return (-1);
3799 if (func1==audio_resume) return (-1);
3800 if (func1!=ioctl_i) return (0);
3801 if (func2==tell_SubQ_run_tot) return (-1);
3802 if (func2==tell_cdsize) return (-1);
3803 if (func2==tell_TocDescrip) return (-1);
3804 if (func2==tell_TocEntry) return (-1);
3805 if (func2==tell_subQ_info) return (-1);
3806 if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
3807 if (func2==tell_UPC) return (-1);
3808 #else
3809 return (0);
3810 #endif 000
3812 /*==========================================================================*/
3813 static int check_allowed2(u_char func1, u_char func2)
3815 #if 000
3816 if (func1==read_long) return (-1);
3817 if (func1==read_long_prefetch) return (-1);
3818 if (func1==seek) return (-1);
3819 if (func1==audio_play) return (-1);
3820 if (func1!=ioctl_o) return (0);
3821 if (fam1_drive)
3823 if (func2==EjectDisk) return (-1);
3824 if (func2==CloseTray) return (-1);
3826 #else
3827 return (0);
3828 #endif 000
3830 /*==========================================================================*/
3831 static int check_allowed3(u_char func1, u_char func2)
3833 #if 000
3834 if (func1==ioctl_i)
3836 if (func2==tell_address) return (0);
3837 if (func2==tell_capabiliti) return (0);
3838 if (func2==tell_CD_changed) return (0);
3839 if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
3840 return (-1);
3842 if (func1==ioctl_o)
3844 if (func2==DriveReset) return (0);
3845 if (fam0L_drive)
3847 if (func2==EjectDisk) return (0);
3848 if (func2==LockDoor) return (0);
3849 if (func2==CloseTray) return (0);
3851 return (-1);
3853 if (func1==flush_input) return (-1);
3854 if (func1==read_long) return (-1);
3855 if (func1==read_long_prefetch) return (-1);
3856 if (func1==seek) return (-1);
3857 if (func1==audio_play) return (-1);
3858 if (func1==audio_pause) return (-1);
3859 if (func1==audio_resume) return (-1);
3860 #else
3861 return (0);
3862 #endif 000
3864 /*==========================================================================*/
3865 static int seek_pos_audio_end(void)
3867 int i;
3869 i=msf2blk(D_S[d].pos_audio_end)-1;
3870 if (i<0) return (-1);
3871 i=cc_Seek(i,0);
3872 return (i);
3874 #endif FUTURE
3875 /*==========================================================================*/
3876 static int ReadToC(void)
3878 int i, j;
3879 D_S[d].diskstate_flags &= ~toc_bit;
3880 D_S[d].ored_ctl_adr=0;
3881 /* special handling of CD-I HE */
3882 if ((D_S[d].n_first_track == 2 && D_S[d].n_last_track == 2) ||
3883 D_S[d].xa_byte == 0x10)
3885 D_S[d].TocBuffer[1].nixbyte=0;
3886 D_S[d].TocBuffer[1].ctl_adr=0x40;
3887 D_S[d].TocBuffer[1].number=1;
3888 D_S[d].TocBuffer[1].format=0;
3889 D_S[d].TocBuffer[1].address=blk2msf(0);
3890 D_S[d].ored_ctl_adr |= 0x40;
3891 D_S[d].n_first_track = 1;
3892 D_S[d].n_last_track = 1;
3893 D_S[d].xa_byte = 0x10;
3894 j = 2;
3895 } else
3896 for (j=D_S[d].n_first_track;j<=D_S[d].n_last_track;j++)
3898 i=cc_ReadTocEntry(j);
3899 if (i<0)
3901 msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
3902 return (i);
3904 D_S[d].TocBuffer[j].nixbyte=D_S[d].TocEnt_nixbyte;
3905 D_S[d].TocBuffer[j].ctl_adr=D_S[d].TocEnt_ctl_adr;
3906 D_S[d].TocBuffer[j].number=D_S[d].TocEnt_number;
3907 D_S[d].TocBuffer[j].format=D_S[d].TocEnt_format;
3908 D_S[d].TocBuffer[j].address=D_S[d].TocEnt_address;
3909 D_S[d].ored_ctl_adr |= D_S[d].TocEnt_ctl_adr;
3911 /* fake entry for LeadOut Track */
3912 D_S[d].TocBuffer[j].nixbyte=0;
3913 D_S[d].TocBuffer[j].ctl_adr=0;
3914 D_S[d].TocBuffer[j].number=CDROM_LEADOUT;
3915 D_S[d].TocBuffer[j].format=0;
3916 D_S[d].TocBuffer[j].address=D_S[d].size_msf;
3918 D_S[d].diskstate_flags |= toc_bit;
3919 return (0);
3921 /*==========================================================================*/
3922 static int DiskInfo(void)
3924 int i, j;
3926 D_S[d].mode=READ_M1;
3928 #undef LOOP_COUNT
3929 #define LOOP_COUNT 10 /* needed for some "old" drives */
3931 msg(DBG_000,"DiskInfo entered.\n");
3932 for (j=1;j<LOOP_COUNT;j++)
3934 #if 0
3935 i=SetSpeed();
3936 if (i<0)
3938 msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
3939 continue;
3941 i=cc_ModeSense();
3942 if (i<0)
3944 msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
3945 continue;
3947 #endif
3948 i=cc_ReadCapacity();
3949 if (i>=0) break;
3950 msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
3951 #if 0
3952 i=cc_DriveReset();
3953 #endif
3954 if (!fam0_drive && j == 2) break;
3956 if (j==LOOP_COUNT) return (-33); /* give up */
3958 i=cc_ReadTocDescr();
3959 if (i<0)
3961 msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
3962 return (i);
3964 i=ReadToC();
3965 if (i<0)
3967 msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
3968 return (i);
3970 i=cc_CheckMultiSession();
3971 if (i<0)
3973 msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
3974 return (i);
3976 if (D_S[d].f_multisession) D_S[d].sbp_bufsiz=1; /* possibly a weird PhotoCD */
3977 else D_S[d].sbp_bufsiz=buffers;
3978 i=cc_ReadTocEntry(D_S[d].n_first_track);
3979 if (i<0)
3981 msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
3982 return (i);
3984 i=cc_ReadUPC();
3985 if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
3986 if ((fam0L_drive) && (D_S[d].xa_byte==0x20 || D_S[d].xa_byte == 0x10))
3988 /* XA disk with old drive */
3989 cc_ModeSelect(CD_FRAMESIZE_RAW1);
3990 cc_ModeSense();
3992 if (famT_drive) cc_prep_mode_T();
3993 msg(DBG_000,"DiskInfo done.\n");
3994 return (0);
3997 static int sbpcd_drive_status(struct cdrom_device_info *cdi, int slot_nr)
3999 int st;
4001 if (CDSL_CURRENT != slot_nr) {
4002 /* we have no changer support */
4003 return -EINVAL;
4006 cc_ReadStatus();
4007 st=ResponseStatus();
4008 if (st<0)
4010 msg(DBG_INF,"sbpcd_drive_status: timeout.\n");
4011 return (0);
4013 msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
4014 msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
4015 msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
4016 msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
4017 msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
4018 msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
4019 #if 0
4020 if (!(D_S[MINOR(cdi->dev)].status_bits & p_door_closed)) return CDS_TRAY_OPEN;
4021 if (D_S[MINOR(cdi->dev)].status_bits & p_disk_ok) return CDS_DISC_OK;
4022 if (D_S[MINOR(cdi->dev)].status_bits & p_disk_in) return CDS_DRIVE_NOT_READY;
4024 return CDS_NO_DISC;
4025 #else
4026 if (D_S[MINOR(cdi->dev)].status_bits & p_spinning) return CDS_DISC_OK;
4027 return CDS_TRAY_OPEN;
4028 #endif
4032 /*==========================================================================*/
4033 #if FUTURE
4035 * called always if driver gets entered
4036 * returns 0 or ERROR2 or ERROR15
4038 static int prepare(u_char func, u_char subfunc)
4040 int i;
4042 if (fam0L_drive)
4044 i=inb(CDi_status);
4045 if (i&s_attention) GetStatus();
4047 else if (fam1_drive) GetStatus();
4048 else if (fam2_drive) GetStatus();
4049 else if (famT_drive) GetStatus();
4050 if (D_S[d].CD_changed==0xFF)
4052 D_S[d].diskstate_flags=0;
4053 D_S[d].audio_state=0;
4054 if (!st_diskok)
4056 i=check_allowed1(func,subfunc);
4057 if (i<0) return (-2);
4059 else
4061 i=check_allowed3(func,subfunc);
4062 if (i<0)
4064 D_S[d].CD_changed=1;
4065 return (-15);
4069 else
4071 if (!st_diskok)
4073 D_S[d].diskstate_flags=0;
4074 D_S[d].audio_state=0;
4075 i=check_allowed1(func,subfunc);
4076 if (i<0) return (-2);
4078 else
4080 if (st_busy)
4082 if (D_S[d].audio_state!=audio_pausing)
4084 i=check_allowed2(func,subfunc);
4085 if (i<0) return (-2);
4088 else
4090 if (D_S[d].audio_state==audio_playing) seek_pos_audio_end();
4091 D_S[d].audio_state=0;
4093 if (!frame_size_valid)
4095 i=DiskInfo();
4096 if (i<0)
4098 D_S[d].diskstate_flags=0;
4099 D_S[d].audio_state=0;
4100 i=check_allowed1(func,subfunc);
4101 if (i<0) return (-2);
4106 return (0);
4108 #endif FUTURE
4109 /*==========================================================================*/
4110 /*==========================================================================*/
4112 * Check the results of the "get status" command.
4114 static int sbp_status(void)
4116 int st;
4118 st=ResponseStatus();
4119 if (st<0)
4121 msg(DBG_INF,"sbp_status: timeout.\n");
4122 return (0);
4125 if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
4127 if (st_check)
4129 msg(DBG_INF,"st_check detected - retrying.\n");
4130 return (0);
4132 if (!st_door_closed)
4134 msg(DBG_INF,"door is open - retrying.\n");
4135 return (0);
4137 if (!st_caddy_in)
4139 msg(DBG_INF,"disk removed - retrying.\n");
4140 return (0);
4142 if (!st_diskok)
4144 msg(DBG_INF,"!st_diskok detected - retrying.\n");
4145 return (0);
4147 if (st_busy)
4149 msg(DBG_INF,"st_busy detected - retrying.\n");
4150 return (0);
4152 return (1);
4154 /*==========================================================================*/
4156 static int sbpcd_get_last_session(struct cdrom_device_info *cdi, struct cdrom_multisession *ms_infp)
4158 ms_infp->addr_format = CDROM_LBA;
4159 ms_infp->addr.lba = D_S[MINOR(cdi->dev)].lba_multi;
4160 if (D_S[MINOR(cdi->dev)].f_multisession)
4161 ms_infp->xa_flag=1; /* valid redirection address */
4162 else
4163 ms_infp->xa_flag=0; /* invalid redirection address */
4165 return 0;
4168 /*==========================================================================*/
4169 /*==========================================================================*/
4171 * ioctl support
4173 static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4174 u_long arg)
4176 int i;
4178 msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08lX)\n",
4179 MINOR(cdi->dev), cmd, arg);
4180 i=MINOR(cdi->dev);
4181 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4183 msg(DBG_INF, "ioctl: bad device: %04X\n", cdi->dev);
4184 return (-ENXIO); /* no such drive */
4186 down(&ioctl_read_sem);
4187 if (d!=i) switch_drive(i);
4189 msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
4190 switch (cmd) /* Sun-compatible */
4192 case DDIOCSDBG: /* DDI Debug */
4193 if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
4194 i=sbpcd_dbg_ioctl(arg,1);
4195 RETURN_UP(i);
4196 case CDROMRESET: /* hard reset the drive */
4197 msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
4198 i=DriveReset();
4199 D_S[d].audio_state=0;
4200 RETURN_UP(i);
4202 case CDROMREADMODE1:
4203 msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
4204 #if SAFE_MIXED
4205 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4206 #endif SAFE_MIXED
4207 cc_ModeSelect(CD_FRAMESIZE);
4208 cc_ModeSense();
4209 D_S[d].mode=READ_M1;
4210 RETURN_UP(0);
4212 case CDROMREADMODE2: /* not usable at the moment */
4213 msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
4214 #if SAFE_MIXED
4215 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4216 #endif SAFE_MIXED
4217 cc_ModeSelect(CD_FRAMESIZE_RAW1);
4218 cc_ModeSense();
4219 D_S[d].mode=READ_M2;
4220 RETURN_UP(0);
4222 case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
4223 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
4224 if (D_S[d].sbp_audsiz>0) vfree(D_S[d].aud_buf);
4225 D_S[d].aud_buf=NULL;
4226 D_S[d].sbp_audsiz=arg;
4228 if (D_S[d].sbp_audsiz>0)
4230 D_S[d].aud_buf=(u_char *) vmalloc(D_S[d].sbp_audsiz*CD_FRAMESIZE_RAW);
4231 if (D_S[d].aud_buf==NULL)
4233 msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[d].sbp_audsiz);
4234 D_S[d].sbp_audsiz=0;
4236 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[d].sbp_audsiz);
4238 RETURN_UP(D_S[d].sbp_audsiz);
4240 case CDROMREADAUDIO:
4241 { /* start of CDROMREADAUDIO */
4242 int i=0, j=0, frame, block=0;
4243 u_int try=0;
4244 u_long timeout;
4245 u_char *p;
4246 u_int data_tries = 0;
4247 u_int data_waits = 0;
4248 u_int data_retrying = 0;
4249 int status_tries;
4250 int error_flag;
4252 msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
4253 if (fam0_drive) RETURN_UP(-EINVAL);
4254 if (famL_drive) RETURN_UP(-EINVAL);
4255 if (famV_drive) RETURN_UP(-EINVAL);
4256 if (famT_drive) RETURN_UP(-EINVAL);
4257 #if SAFE_MIXED
4258 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4259 #endif SAFE_MIXED
4260 if (D_S[d].aud_buf==NULL) RETURN_UP(-EINVAL);
4261 i=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_read_audio));
4262 if (i) RETURN_UP(i);
4263 copy_from_user(&read_audio, (void *) arg, sizeof(struct cdrom_read_audio));
4264 if (read_audio.nframes>D_S[d].sbp_audsiz) RETURN_UP(-EINVAL);
4265 i=verify_area(VERIFY_WRITE, read_audio.buf,
4266 read_audio.nframes*CD_FRAMESIZE_RAW);
4267 if (i) RETURN_UP(i);
4269 if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
4270 block=msf2lba(&read_audio.addr.msf.minute);
4271 else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
4272 block=read_audio.addr.lba;
4273 else RETURN_UP(-EINVAL);
4274 #if 000
4275 i=cc_SetSpeed(speed_150,0,0);
4276 if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
4277 #endif
4278 msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
4279 block, blk2msf(block));
4280 msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
4281 #if OLD_BUSY
4282 while (busy_data) sbp_sleep(HZ/10); /* wait a bit */
4283 busy_audio=1;
4284 #endif OLD_BUSY
4285 error_flag=0;
4286 for (data_tries=5; data_tries>0; data_tries--)
4288 msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
4289 D_S[d].mode=READ_AU;
4290 cc_ModeSelect(CD_FRAMESIZE_RAW);
4291 cc_ModeSense();
4292 for (status_tries=3; status_tries > 0; status_tries--)
4294 flags_cmd_out |= f_respo3;
4295 cc_ReadStatus();
4296 if (sbp_status() != 0) break;
4297 if (st_check) cc_ReadError();
4298 sbp_sleep(1); /* wait a bit, try again */
4300 if (status_tries == 0)
4302 msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__);
4303 continue;
4305 msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
4307 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4308 if (fam0L_drive)
4310 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4311 cmd_type=READ_M2;
4312 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
4313 drvcmd[1]=(block>>16)&0x000000ff;
4314 drvcmd[2]=(block>>8)&0x000000ff;
4315 drvcmd[3]=block&0x000000ff;
4316 drvcmd[4]=0;
4317 drvcmd[5]=read_audio.nframes; /* # of frames */
4318 drvcmd[6]=0;
4320 else if (fam1_drive)
4322 drvcmd[0]=CMD1_READ; /* "read frames", new drives */
4323 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4324 drvcmd[4]=0;
4325 drvcmd[5]=0;
4326 drvcmd[6]=read_audio.nframes; /* # of frames */
4328 else if (fam2_drive)
4330 drvcmd[0]=CMD2_READ_XA2;
4331 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4332 drvcmd[4]=0;
4333 drvcmd[5]=read_audio.nframes; /* # of frames */
4334 drvcmd[6]=0x11; /* raw mode */
4336 else if (famT_drive) /* CD-55A: not tested yet */
4339 msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
4340 flags_cmd_out=f_putcmd;
4341 response_count=0;
4342 i=cmd_out();
4343 if (i<0) msg(DBG_INF,"error giving READ AUDIO command: %0d\n", i);
4344 sbp_sleep(0);
4345 msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
4346 for (frame=1;frame<2 && !error_flag; frame++)
4348 try=maxtim_data;
4349 for (timeout=jiffies+9*HZ; ; )
4351 for ( ; try!=0;try--)
4353 j=inb(CDi_status);
4354 if (!(j&s_not_data_ready)) break;
4355 if (!(j&s_not_result_ready)) break;
4356 if (fam0L_drive) if (j&s_attention) break;
4358 if (try != 0 || time_after_eq(jiffies, timeout)) break;
4359 if (data_retrying == 0) data_waits++;
4360 data_retrying = 1;
4361 sbp_sleep(1);
4362 try = 1;
4364 if (try==0)
4366 msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
4367 error_flag++;
4368 break;
4370 msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
4371 if (j&s_not_data_ready)
4373 msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
4374 error_flag++;
4375 break;
4377 msg(DBG_AUD,"read_audio: before reading data.\n");
4378 error_flag=0;
4379 p = D_S[d].aud_buf;
4380 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
4381 if (do_16bit)
4383 u_short *p2 = (u_short *) p;
4385 for (; (u_char *) p2 < D_S[d].aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4387 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4389 /* get one sample */
4390 *p2++ = inw_p(CDi_data);
4391 *p2++ = inw_p(CDi_data);
4393 } else {
4394 for (; p < D_S[d].aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4396 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4398 /* get one sample */
4399 *p++ = inb_p(CDi_data);
4400 *p++ = inb_p(CDi_data);
4401 *p++ = inb_p(CDi_data);
4402 *p++ = inb_p(CDi_data);
4405 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
4406 data_retrying = 0;
4408 msg(DBG_AUD,"read_audio: after reading data.\n");
4409 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
4411 msg(DBG_AUD,"read_audio: read aborted by drive\n");
4412 #if 0000
4413 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4414 #else
4415 i=cc_ReadError();
4416 #endif 0000
4417 continue;
4419 if (fam0L_drive)
4421 i=maxtim_data;
4422 for (timeout=jiffies+9*HZ; time_before(jiffies, timeout); timeout--)
4424 for ( ;i!=0;i--)
4426 j=inb(CDi_status);
4427 if (!(j&s_not_data_ready)) break;
4428 if (!(j&s_not_result_ready)) break;
4429 if (j&s_attention) break;
4431 if (i != 0 || time_after_eq(jiffies, timeout)) break;
4432 sbp_sleep(0);
4433 i = 1;
4435 if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
4436 if (!(j&s_attention))
4438 msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
4439 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4440 continue;
4445 if (fam0L_drive) cc_ReadStatus();
4446 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
4447 if (i<0) { msg(DBG_AUD,
4448 "read_audio: cc_ReadStatus error after read: %02X\n",
4449 D_S[d].status_bits);
4450 continue; /* FIXME */
4453 while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
4454 if (st_check)
4456 i=cc_ReadError();
4457 msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
4458 continue;
4460 copy_to_user((u_char *) read_audio.buf,
4461 (u_char *) D_S[d].aud_buf,
4462 read_audio.nframes*CD_FRAMESIZE_RAW);
4463 msg(DBG_AUD,"read_audio: copy_to_user done.\n");
4464 break;
4466 cc_ModeSelect(CD_FRAMESIZE);
4467 cc_ModeSense();
4468 D_S[d].mode=READ_M1;
4469 #if OLD_BUSY
4470 busy_audio=0;
4471 #endif OLD_BUSY
4472 if (data_tries == 0)
4474 msg(DBG_AUD,"read_audio: failed after 5 tries in line %d.\n", __LINE__);
4475 RETURN_UP(-EIO);
4477 msg(DBG_AUD,"read_audio: successful return.\n");
4478 RETURN_UP(0);
4479 } /* end of CDROMREADAUDIO */
4481 case BLKRASET:
4482 if(!capable(CAP_SYS_ADMIN)) RETURN_UP(-EACCES);
4483 if(!(cdi->dev)) RETURN_UP(-EINVAL);
4484 if(arg > 0xff) RETURN_UP(-EINVAL);
4485 read_ahead[MAJOR(cdi->dev)] = arg;
4486 RETURN_UP(0);
4487 default:
4488 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4489 RETURN_UP(-EINVAL);
4490 } /* end switch(cmd) */
4493 static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4494 void * arg)
4496 int i, st;
4498 msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08p)\n",
4499 MINOR(cdi->dev), cmd, arg);
4500 i=MINOR(cdi->dev);
4501 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4503 msg(DBG_INF, "ioctl: bad device: %04X\n", cdi->dev);
4504 return (-ENXIO); /* no such drive */
4506 down(&ioctl_read_sem);
4507 if (d!=i) switch_drive(i);
4509 msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
4510 switch (cmd) /* Sun-compatible */
4513 case CDROMPAUSE: /* Pause the drive */
4514 msg(DBG_IOC,"ioctl: CDROMPAUSE entered.\n");
4515 /* pause the drive unit when it is currently in PLAY mode, */
4516 /* or reset the starting and ending locations when in PAUSED mode. */
4517 /* If applicable, at the next stopping point it reaches */
4518 /* the drive will discontinue playing. */
4519 switch (D_S[d].audio_state)
4521 case audio_playing:
4522 if (famL_drive) i=cc_ReadSubQ();
4523 else i=cc_Pause_Resume(1);
4524 if (i<0) RETURN_UP(-EIO);
4525 if (famL_drive) i=cc_Pause_Resume(1);
4526 else i=cc_ReadSubQ();
4527 if (i<0) RETURN_UP(-EIO);
4528 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
4529 D_S[d].audio_state=audio_pausing;
4530 RETURN_UP(0);
4531 case audio_pausing:
4532 i=cc_Seek(D_S[d].pos_audio_start,1);
4533 if (i<0) RETURN_UP(-EIO);
4534 RETURN_UP(0);
4535 default:
4536 RETURN_UP(-EINVAL);
4539 case CDROMRESUME: /* resume paused audio play */
4540 msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
4541 /* resume playing audio tracks when a previous PLAY AUDIO call has */
4542 /* been paused with a PAUSE command. */
4543 /* It will resume playing from the location saved in SubQ_run_tot. */
4544 if (D_S[d].audio_state!=audio_pausing) RETURN_UP(-EINVAL);
4545 if (famL_drive)
4546 i=cc_PlayAudio(D_S[d].pos_audio_start,
4547 D_S[d].pos_audio_end);
4548 else i=cc_Pause_Resume(3);
4549 if (i<0) RETURN_UP(-EIO);
4550 D_S[d].audio_state=audio_playing;
4551 RETURN_UP(0);
4553 case CDROMPLAYMSF:
4554 msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
4555 #if SAFE_MIXED
4556 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4557 #endif SAFE_MIXED
4558 if (D_S[d].audio_state==audio_playing)
4560 i=cc_Pause_Resume(1);
4561 if (i<0) RETURN_UP(-EIO);
4562 i=cc_ReadSubQ();
4563 if (i<0) RETURN_UP(-EIO);
4564 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
4565 i=cc_Seek(D_S[d].pos_audio_start,1);
4567 memcpy(&msf, (void *) arg, sizeof(struct cdrom_msf));
4568 /* values come as msf-bin */
4569 D_S[d].pos_audio_start = (msf.cdmsf_min0<<16) |
4570 (msf.cdmsf_sec0<<8) |
4571 msf.cdmsf_frame0;
4572 D_S[d].pos_audio_end = (msf.cdmsf_min1<<16) |
4573 (msf.cdmsf_sec1<<8) |
4574 msf.cdmsf_frame1;
4575 msg(DBG_IOX,"ioctl: CDROMPLAYMSF %08X %08X\n",
4576 D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4577 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4578 if (i<0)
4580 msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
4581 DriveReset();
4582 D_S[d].audio_state=0;
4583 RETURN_UP(-EIO);
4585 D_S[d].audio_state=audio_playing;
4586 RETURN_UP(0);
4588 case CDROMPLAYTRKIND: /* Play a track. This currently ignores index. */
4589 msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
4590 #if SAFE_MIXED
4591 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4592 #endif SAFE_MIXED
4593 if (D_S[d].audio_state==audio_playing)
4595 msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
4596 #if 1
4597 RETURN_UP(0); /* just let us play on */
4598 #else
4599 RETURN_UP(-EINVAL); /* play on, but say "error" */
4600 #endif
4602 memcpy(&ti,(void *) arg,sizeof(struct cdrom_ti));
4603 msg(DBG_IOX,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
4604 ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1);
4605 if (ti.cdti_trk0<D_S[d].n_first_track) RETURN_UP(-EINVAL);
4606 if (ti.cdti_trk0>D_S[d].n_last_track) RETURN_UP(-EINVAL);
4607 if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
4608 if (ti.cdti_trk1>D_S[d].n_last_track) ti.cdti_trk1=D_S[d].n_last_track;
4609 D_S[d].pos_audio_start=D_S[d].TocBuffer[ti.cdti_trk0].address;
4610 D_S[d].pos_audio_end=D_S[d].TocBuffer[ti.cdti_trk1+1].address;
4611 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4612 if (i<0)
4614 msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
4615 DriveReset();
4616 D_S[d].audio_state=0;
4617 RETURN_UP(-EIO);
4619 D_S[d].audio_state=audio_playing;
4620 RETURN_UP(0);
4622 case CDROMREADTOCHDR: /* Read the table of contents header */
4623 msg(DBG_IOC,"ioctl: CDROMREADTOCHDR entered.\n");
4624 tochdr.cdth_trk0=D_S[d].n_first_track;
4625 tochdr.cdth_trk1=D_S[d].n_last_track;
4626 memcpy((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
4627 RETURN_UP(0);
4629 case CDROMREADTOCENTRY: /* Read an entry in the table of contents */
4630 msg(DBG_IOC,"ioctl: CDROMREADTOCENTRY entered.\n");
4631 memcpy(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
4632 i=tocentry.cdte_track;
4633 if (i==CDROM_LEADOUT) i=D_S[d].n_last_track+1;
4634 else if (i<D_S[d].n_first_track||i>D_S[d].n_last_track)
4635 RETURN_UP(-EINVAL);
4636 tocentry.cdte_adr=D_S[d].TocBuffer[i].ctl_adr&0x0F;
4637 tocentry.cdte_ctrl=(D_S[d].TocBuffer[i].ctl_adr>>4)&0x0F;
4638 tocentry.cdte_datamode=D_S[d].TocBuffer[i].format;
4639 if (tocentry.cdte_format==CDROM_MSF) /* MSF-bin required */
4641 tocentry.cdte_addr.msf.minute=(D_S[d].TocBuffer[i].address>>16)&0x00FF;
4642 tocentry.cdte_addr.msf.second=(D_S[d].TocBuffer[i].address>>8)&0x00FF;
4643 tocentry.cdte_addr.msf.frame=D_S[d].TocBuffer[i].address&0x00FF;
4645 else if (tocentry.cdte_format==CDROM_LBA) /* blk required */
4646 tocentry.cdte_addr.lba=msf2blk(D_S[d].TocBuffer[i].address);
4647 else RETURN_UP(-EINVAL);
4648 memcpy((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
4649 RETURN_UP(0);
4651 case CDROMSTOP: /* Spin down the drive */
4652 msg(DBG_IOC,"ioctl: CDROMSTOP entered.\n");
4653 #if SAFE_MIXED
4654 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4655 #endif SAFE_MIXED
4656 i=cc_Pause_Resume(1);
4657 D_S[d].audio_state=0;
4658 #if 0
4659 cc_DriveReset();
4660 #endif
4661 RETURN_UP(i);
4663 case CDROMSTART: /* Spin up the drive */
4664 msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
4665 cc_SpinUp();
4666 D_S[d].audio_state=0;
4667 RETURN_UP(0);
4669 case CDROMVOLCTRL: /* Volume control */
4670 msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
4671 memcpy(&volctrl,(char *) arg,sizeof(volctrl));
4672 D_S[d].vol_chan0=0;
4673 D_S[d].vol_ctrl0=volctrl.channel0;
4674 D_S[d].vol_chan1=1;
4675 D_S[d].vol_ctrl1=volctrl.channel1;
4676 i=cc_SetVolume();
4677 RETURN_UP(0);
4679 case CDROMVOLREAD: /* read Volume settings from drive */
4680 msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
4681 st=cc_GetVolume();
4682 if (st<0) RETURN_UP(st);
4683 volctrl.channel0=D_S[d].vol_ctrl0;
4684 volctrl.channel1=D_S[d].vol_ctrl1;
4685 volctrl.channel2=0;
4686 volctrl.channel2=0;
4687 memcpy((void *)arg,&volctrl,sizeof(volctrl));
4688 RETURN_UP(0);
4690 case CDROMSUBCHNL: /* Get subchannel info */
4691 msg(DBG_IOS,"ioctl: CDROMSUBCHNL entered.\n");
4692 if ((st_spinning)||(!subq_valid)) {
4693 i=cc_ReadSubQ();
4694 if (i<0) RETURN_UP(-EIO);
4696 memcpy(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
4697 switch (D_S[d].audio_state)
4699 case audio_playing:
4700 SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
4701 break;
4702 case audio_pausing:
4703 SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
4704 break;
4705 default:
4706 SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
4707 break;
4709 SC.cdsc_adr=D_S[d].SubQ_ctl_adr;
4710 SC.cdsc_ctrl=D_S[d].SubQ_ctl_adr>>4;
4711 SC.cdsc_trk=bcd2bin(D_S[d].SubQ_trk);
4712 SC.cdsc_ind=bcd2bin(D_S[d].SubQ_pnt_idx);
4713 if (SC.cdsc_format==CDROM_LBA)
4715 SC.cdsc_absaddr.lba=msf2blk(D_S[d].SubQ_run_tot);
4716 SC.cdsc_reladdr.lba=msf2blk(D_S[d].SubQ_run_trk);
4718 else /* not only if (SC.cdsc_format==CDROM_MSF) */
4720 SC.cdsc_absaddr.msf.minute=(D_S[d].SubQ_run_tot>>16)&0x00FF;
4721 SC.cdsc_absaddr.msf.second=(D_S[d].SubQ_run_tot>>8)&0x00FF;
4722 SC.cdsc_absaddr.msf.frame=D_S[d].SubQ_run_tot&0x00FF;
4723 SC.cdsc_reladdr.msf.minute=(D_S[d].SubQ_run_trk>>16)&0x00FF;
4724 SC.cdsc_reladdr.msf.second=(D_S[d].SubQ_run_trk>>8)&0x00FF;
4725 SC.cdsc_reladdr.msf.frame=D_S[d].SubQ_run_trk&0x00FF;
4727 memcpy((void *) arg, &SC, sizeof(struct cdrom_subchnl));
4728 msg(DBG_IOS,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
4729 SC.cdsc_format,SC.cdsc_audiostatus,
4730 SC.cdsc_adr,SC.cdsc_ctrl,
4731 SC.cdsc_trk,SC.cdsc_ind,
4732 SC.cdsc_absaddr,SC.cdsc_reladdr);
4733 RETURN_UP(0);
4735 default:
4736 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4737 RETURN_UP(-EINVAL);
4738 } /* end switch(cmd) */
4740 /*==========================================================================*/
4742 * Take care of the different block sizes between cdrom and Linux.
4744 static void sbp_transfer(struct request *req)
4746 long offs;
4748 while ( (req->nr_sectors > 0) &&
4749 (req->sector/4 >= D_S[d].sbp_first_frame) &&
4750 (req->sector/4 <= D_S[d].sbp_last_frame) )
4752 offs = (req->sector - D_S[d].sbp_first_frame * 4) * 512;
4753 memcpy(req->buffer, D_S[d].sbp_buf + offs, 512);
4754 req->nr_sectors--;
4755 req->sector++;
4756 req->buffer += 512;
4759 /*==========================================================================*/
4761 * special end_request for sbpcd to solve CURRENT==NULL bug. (GTL)
4762 * GTL = Gonzalo Tornaria <tornaria@cmat.edu.uy>
4764 * This is a kludge so we don't need to modify end_request.
4765 * We put the req we take out after INIT_REQUEST in the requests list,
4766 * so that end_request will discard it.
4768 * The bug could be present in other block devices, perhaps we
4769 * should modify INIT_REQUEST and end_request instead, and
4770 * change every block device..
4772 * Could be a race here?? Could e.g. a timer interrupt schedule() us?
4773 * If so, we should copy end_request here, and do it right.. (or
4774 * modify end_request and the block devices).
4776 * In any case, the race here would be much small than it was, and
4777 * I couldn't reproduce..
4779 * The race could be: suppose CURRENT==NULL. We put our req in the list,
4780 * and we are scheduled. Other process takes over, and gets into
4781 * do_sbpcd_request. It sees CURRENT!=NULL (it is == to our req), so
4782 * proceeds. It ends, so CURRENT is now NULL.. Now we awake somewhere in
4783 * end_request, but now CURRENT==NULL... oops!
4786 #undef DEBUG_GTL
4787 static inline void sbpcd_end_request(struct request *req, int uptodate) {
4788 req->next=CURRENT;
4789 CURRENT=req;
4790 up(&ioctl_read_sem);
4791 end_request(uptodate);
4793 /*==========================================================================*/
4795 * I/O request routine, called from Linux kernel.
4797 static void DO_SBPCD_REQUEST(void)
4799 u_int block;
4800 u_int nsect;
4801 int i, status_tries, data_tries;
4802 struct request *req;
4803 #ifdef DEBUG_GTL
4804 static int xx_nr=0;
4805 int xnr;
4806 #endif
4808 request_loop:
4809 #ifdef DEBUG_GTL
4810 xnr=++xx_nr;
4812 if(!CURRENT)
4814 printk( "do_sbpcd_request[%di](NULL), Pid:%d, Time:%li\n",
4815 xnr, current->pid, jiffies);
4816 printk( "do_sbpcd_request[%do](NULL) end 0 (null), Time:%li\n",
4817 xnr, jiffies);
4818 CLEAR_INTR;
4819 return;
4822 printk(" do_sbpcd_request[%di](%p:%ld+%ld), Pid:%d, Time:%li\n",
4823 xnr, CURRENT, CURRENT->sector, CURRENT->nr_sectors, current->pid, jiffies);
4824 #endif
4825 INIT_REQUEST;
4826 req=CURRENT; /* take out our request so no other */
4827 CURRENT=req->next; /* task can fuck it up GTL */
4828 spin_unlock_irq(&io_request_lock); /* FIXME!!!! */
4830 down(&ioctl_read_sem);
4831 if (req->rq_status == RQ_INACTIVE)
4832 sbpcd_end_request(req, 0);
4833 if (req -> sector == -1)
4834 sbpcd_end_request(req, 0);
4836 if (req->cmd != READ)
4838 msg(DBG_INF, "bad cmd %d\n", req->cmd);
4839 goto err_done;
4841 i = MINOR(req->rq_dev);
4842 if ( (i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4844 msg(DBG_INF, "do_request: bad device: %s\n",
4845 kdevname(req->rq_dev));
4846 goto err_done;
4848 #if OLD_BUSY
4849 while (busy_audio) sbp_sleep(HZ); /* wait a bit */
4850 busy_data=1;
4851 #endif OLD_BUSY
4853 if (D_S[i].audio_state==audio_playing) goto err_done;
4854 if (d!=i) switch_drive(i);
4856 block = req->sector; /* always numbered as 512-byte-pieces */
4857 nsect = req->nr_sectors; /* always counted as 512-byte-pieces */
4859 msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
4860 #if 0
4861 msg(DBG_MUL,"read LBA %d\n", block/4);
4862 #endif
4864 sbp_transfer(req);
4865 /* if we satisfied the request from the buffer, we're done. */
4866 if (req->nr_sectors == 0)
4868 #ifdef DEBUG_GTL
4869 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 2, Time:%li\n",
4870 xnr, req, req->sector, req->nr_sectors, jiffies);
4871 #endif
4872 sbpcd_end_request(req, 1);
4873 spin_lock_irq(&io_request_lock); /* FIXME!!!! */
4874 goto request_loop;
4877 #if FUTURE
4878 i=prepare(0,0); /* at moment not really a hassle check, but ... */
4879 if (i!=0)
4880 msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
4881 #endif FUTURE
4883 if (!st_spinning) cc_SpinUp();
4885 for (data_tries=n_retries; data_tries > 0; data_tries--)
4887 for (status_tries=3; status_tries > 0; status_tries--)
4889 flags_cmd_out |= f_respo3;
4890 cc_ReadStatus();
4891 if (sbp_status() != 0) break;
4892 if (st_check) cc_ReadError();
4893 sbp_sleep(1); /* wait a bit, try again */
4895 if (status_tries == 0)
4897 msg(DBG_INF,"sbp_status: failed after 3 tries in line %d\n", __LINE__);
4898 break;
4901 sbp_read_cmd(req);
4902 sbp_sleep(0);
4903 if (sbp_data(req) != 0)
4905 #if SAFE_MIXED
4906 D_S[d].has_data=2; /* is really a data disk */
4907 #endif SAFE_MIXED
4908 #ifdef DEBUG_GTL
4909 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
4910 xnr, req, req->sector, req->nr_sectors, jiffies);
4911 #endif
4912 sbpcd_end_request(req, 1);
4913 spin_lock_irq(&io_request_lock); /* FIXME!!!! */
4914 goto request_loop;
4918 err_done:
4919 #if OLD_BUSY
4920 busy_data=0;
4921 #endif OLD_BUSY
4922 #ifdef DEBUG_GTL
4923 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 4 (error), Time:%li\n",
4924 xnr, req, req->sector, req->nr_sectors, jiffies);
4925 #endif
4926 sbpcd_end_request(req, 0);
4927 sbp_sleep(0); /* wait a bit, try again */
4928 spin_lock_irq(&io_request_lock); /* FIXME!!!! */
4929 goto request_loop;
4931 /*==========================================================================*/
4933 * build and send the READ command.
4935 static void sbp_read_cmd(struct request *req)
4937 #undef OLD
4939 int i;
4940 int block;
4942 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1; /* purge buffer */
4943 D_S[d].sbp_current = 0;
4944 block=req->sector/4;
4945 if (block+D_S[d].sbp_bufsiz <= D_S[d].CDsize_frm)
4946 D_S[d].sbp_read_frames = D_S[d].sbp_bufsiz;
4947 else
4949 D_S[d].sbp_read_frames=D_S[d].CDsize_frm-block;
4950 /* avoid reading past end of data */
4951 if (D_S[d].sbp_read_frames < 1)
4953 msg(DBG_INF,"requested frame %d, CD size %d ???\n",
4954 block, D_S[d].CDsize_frm);
4955 D_S[d].sbp_read_frames=1;
4959 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4960 clr_cmdbuf();
4961 if (famV_drive)
4963 drvcmd[0]=CMDV_READ;
4964 lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
4965 bin2bcdx(&drvcmd[1]);
4966 bin2bcdx(&drvcmd[2]);
4967 bin2bcdx(&drvcmd[3]);
4968 drvcmd[4]=D_S[d].sbp_read_frames>>8;
4969 drvcmd[5]=D_S[d].sbp_read_frames&0xff;
4970 drvcmd[6]=0x02; /* flag "msf-bcd" */
4972 else if (fam0L_drive)
4974 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4975 if (D_S[d].xa_byte==0x20)
4977 cmd_type=READ_M2;
4978 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
4979 drvcmd[1]=(block>>16)&0x0ff;
4980 drvcmd[2]=(block>>8)&0x0ff;
4981 drvcmd[3]=block&0x0ff;
4982 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
4983 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
4985 else
4987 drvcmd[0]=CMD0_READ; /* "read frames", old drives */
4988 if (D_S[d].drv_type>=drv_201)
4990 lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
4991 bin2bcdx(&drvcmd[1]);
4992 bin2bcdx(&drvcmd[2]);
4993 bin2bcdx(&drvcmd[3]);
4995 else
4997 drvcmd[1]=(block>>16)&0x0ff;
4998 drvcmd[2]=(block>>8)&0x0ff;
4999 drvcmd[3]=block&0x0ff;
5001 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5002 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
5003 drvcmd[6]=(D_S[d].drv_type<drv_201)?0:2; /* flag "lba or msf-bcd format" */
5006 else if (fam1_drive)
5008 drvcmd[0]=CMD1_READ;
5009 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5010 drvcmd[5]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5011 drvcmd[6]=D_S[d].sbp_read_frames&0x0ff;
5013 else if (fam2_drive)
5015 drvcmd[0]=CMD2_READ;
5016 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5017 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5018 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
5019 drvcmd[6]=0x02;
5021 else if (famT_drive)
5023 drvcmd[0]=CMDT_READ;
5024 drvcmd[2]=(block>>24)&0x0ff;
5025 drvcmd[3]=(block>>16)&0x0ff;
5026 drvcmd[4]=(block>>8)&0x0ff;
5027 drvcmd[5]=block&0x0ff;
5028 drvcmd[7]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5029 drvcmd[8]=D_S[d].sbp_read_frames&0x0ff;
5031 flags_cmd_out=f_putcmd;
5032 response_count=0;
5033 i=cmd_out();
5034 if (i<0) msg(DBG_INF,"error giving READ command: %0d\n", i);
5035 return;
5037 /*==========================================================================*/
5039 * Check the completion of the read-data command. On success, read
5040 * the D_S[d].sbp_bufsiz * 2048 bytes of data from the disk into buffer.
5042 static int sbp_data(struct request *req)
5044 int i=0, j=0, l, frame;
5045 u_int try=0;
5046 u_long timeout;
5047 u_char *p;
5048 u_int data_tries = 0;
5049 u_int data_waits = 0;
5050 u_int data_retrying = 0;
5051 int error_flag;
5052 int xa_count;
5053 int max_latency;
5054 int success;
5055 int wait;
5056 int duration;
5058 error_flag=0;
5059 success=0;
5060 #if LONG_TIMING
5061 max_latency=9*HZ;
5062 #else
5063 if (D_S[d].f_multisession) max_latency=15*HZ;
5064 else max_latency=5*HZ;
5065 #endif
5066 duration=jiffies;
5067 for (frame=0;frame<D_S[d].sbp_read_frames&&!error_flag; frame++)
5069 SBPCD_CLI;
5071 del_timer(&data_timer);
5072 data_timer.expires=jiffies+max_latency;
5073 timed_out_data=0;
5074 add_timer(&data_timer);
5075 while (!timed_out_data)
5077 if (D_S[d].f_multisession) try=maxtim_data*4;
5078 else try=maxtim_data;
5079 msg(DBG_000,"sbp_data: CDi_status loop: try=%d.\n",try);
5080 for ( ; try!=0;try--)
5082 j=inb(CDi_status);
5083 if (!(j&s_not_data_ready)) break;;
5084 if (!(j&s_not_result_ready)) break;
5085 if (fam0LV_drive) if (j&s_attention) break;
5087 if (!(j&s_not_data_ready)) goto data_ready;
5088 if (try==0)
5090 if (data_retrying == 0) data_waits++;
5091 data_retrying = 1;
5092 msg(DBG_000,"sbp_data: CDi_status loop: sleeping.\n");
5093 sbp_sleep(1);
5094 try = 1;
5097 msg(DBG_INF,"sbp_data: CDi_status loop expired.\n");
5098 data_ready:
5099 del_timer(&data_timer);
5101 if (timed_out_data)
5103 msg(DBG_INF,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j);
5104 error_flag++;
5106 if (try==0)
5108 msg(DBG_INF,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j);
5109 error_flag++;
5111 if (!(j&s_not_result_ready))
5113 msg(DBG_INF, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j);
5114 response_count=20;
5115 j=ResponseInfo();
5116 j=inb(CDi_status);
5118 if (j&s_not_data_ready)
5120 if ((D_S[d].ored_ctl_adr&0x40)==0)
5121 msg(DBG_INF, "CD contains no data tracks.\n");
5122 else msg(DBG_INF, "sbp_data: DATA_READY timeout (%02X).\n", j);
5123 error_flag++;
5125 SBPCD_STI;
5126 if (error_flag) break;
5128 msg(DBG_000, "sbp_data: beginning to read.\n");
5129 p = D_S[d].sbp_buf + frame * CD_FRAMESIZE;
5130 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
5131 if (cmd_type==READ_M2) {
5132 if (do_16bit) insw(CDi_data, xa_head_buf, CD_XA_HEAD>>1);
5133 else insb(CDi_data, xa_head_buf, CD_XA_HEAD);
5135 if (do_16bit) insw(CDi_data, p, CD_FRAMESIZE>>1);
5136 else insb(CDi_data, p, CD_FRAMESIZE);
5137 if (cmd_type==READ_M2) {
5138 if (do_16bit) insw(CDi_data, xa_tail_buf, CD_XA_TAIL>>1);
5139 else insb(CDi_data, xa_tail_buf, CD_XA_TAIL);
5141 D_S[d].sbp_current++;
5142 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
5143 if (cmd_type==READ_M2)
5145 for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
5146 sprintf(&msgbuf[xa_count*3], " %02X", xa_head_buf[xa_count]);
5147 msgbuf[xa_count*3]=0;
5148 msg(DBG_XA1,"xa head:%s\n", msgbuf);
5150 data_retrying = 0;
5151 data_tries++;
5152 if (data_tries >= 1000)
5154 msg(DBG_INF,"sbp_data() statistics: %d waits in %d frames.\n", data_waits, data_tries);
5155 data_waits = data_tries = 0;
5158 duration=jiffies-duration;
5159 msg(DBG_TEA,"time to read %d frames: %d jiffies .\n",frame,duration);
5160 if (famT_drive)
5162 wait=8;
5165 if (teac==2)
5167 if ((i=CDi_stat_loop_T()) == -1) break;
5169 else
5171 sbp_sleep(1);
5172 OUT(CDo_sel_i_d,0);
5173 i=inb(CDi_status);
5175 if (!(i&s_not_data_ready))
5177 OUT(CDo_sel_i_d,1);
5178 j=0;
5181 if (do_16bit) i=inw(CDi_data);
5182 else i=inb(CDi_data);
5183 j++;
5184 i=inb(CDi_status);
5186 while (!(i&s_not_data_ready));
5187 msg(DBG_TEA, "==========too much data (%d bytes/words)==============.\n", j);
5189 if (!(i&s_not_result_ready))
5191 OUT(CDo_sel_i_d,0);
5192 l=0;
5195 infobuf[l++]=inb(CDi_info);
5196 i=inb(CDi_status);
5198 while (!(i&s_not_result_ready));
5199 if (infobuf[0]==0x00) success=1;
5200 #if 1
5201 for (j=0;j<l;j++) sprintf(&msgbuf[j*3], " %02X", infobuf[j]);
5202 msgbuf[j*3]=0;
5203 msg(DBG_TEA,"sbp_data info response:%s\n", msgbuf);
5204 #endif
5205 if (infobuf[0]==0x02)
5207 error_flag++;
5210 ++recursion;
5211 if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion);
5212 else msg(DBG_TEA,"sbp_data: CMDT_READ_ERR necessary.\n");
5213 clr_cmdbuf();
5214 drvcmd[0]=CMDT_READ_ERR;
5215 j=cmd_out_T(); /* !!! recursive here !!! */
5216 --recursion;
5217 sbp_sleep(1);
5219 while (j<0);
5220 D_S[d].error_state=infobuf[2];
5221 D_S[d].b3=infobuf[3];
5222 D_S[d].b4=infobuf[4];
5224 break;
5226 else
5228 #if 0
5229 msg(DBG_TEA, "============= waiting for result=================.\n");
5230 sbp_sleep(1);
5231 #endif
5234 while (wait--);
5237 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
5239 msg(DBG_TEA, "================error flag: %d=================.\n", error_flag);
5240 msg(DBG_INF,"sbp_data: read aborted by drive.\n");
5241 #if 1
5242 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5243 #else
5244 i=cc_ReadError();
5245 #endif
5246 return (0);
5249 if (fam0LV_drive)
5251 SBPCD_CLI;
5252 i=maxtim_data;
5253 for (timeout=jiffies+HZ; time_before(jiffies, timeout); timeout--)
5255 for ( ;i!=0;i--)
5257 j=inb(CDi_status);
5258 if (!(j&s_not_data_ready)) break;
5259 if (!(j&s_not_result_ready)) break;
5260 if (j&s_attention) break;
5262 if (i != 0 || time_after_eq(jiffies, timeout)) break;
5263 sbp_sleep(0);
5264 i = 1;
5266 if (i==0) msg(DBG_INF,"status timeout after READ.\n");
5267 if (!(j&s_attention))
5269 msg(DBG_INF,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
5270 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5271 SBPCD_STI;
5272 return (0);
5274 SBPCD_STI;
5277 #if 0
5278 if (!success)
5279 #endif 0
5282 if (fam0LV_drive) cc_ReadStatus();
5283 #if 1
5284 if (famT_drive) msg(DBG_TEA, "================before ResponseStatus=================.\n", i);
5285 #endif 1
5286 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
5287 #if 1
5288 if (famT_drive) msg(DBG_TEA, "================ResponseStatus: %d=================.\n", i);
5289 #endif 1
5290 if (i<0)
5292 msg(DBG_INF,"bad cc_ReadStatus after read: %02X\n", D_S[d].status_bits);
5293 return (0);
5296 while ((fam0LV_drive)&&(!st_check)&&(!(i&p_success)));
5297 if (st_check)
5299 i=cc_ReadError();
5300 msg(DBG_INF,"cc_ReadError was necessary after read: %d\n",i);
5301 return (0);
5303 if (fatal_err)
5305 fatal_err=0;
5306 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1; /* purge buffer */
5307 D_S[d].sbp_current = 0;
5308 msg(DBG_INF,"sbp_data: fatal_err - retrying.\n");
5309 return (0);
5312 D_S[d].sbp_first_frame = req -> sector / 4;
5313 D_S[d].sbp_last_frame = D_S[d].sbp_first_frame + D_S[d].sbp_read_frames - 1;
5314 sbp_transfer(req);
5315 return (1);
5317 /*==========================================================================*/
5318 /*==========================================================================*/
5320 * Open the device special file. Check that a disk is in. Read TOC.
5322 static int sbpcd_open(struct cdrom_device_info *cdi, int purpose)
5324 int i;
5326 i = MINOR(cdi->dev);
5328 MOD_INC_USE_COUNT;
5329 down(&ioctl_read_sem);
5330 switch_drive(i);
5333 * try to keep an "open" counter here and lock the door if 0->1.
5335 msg(DBG_LCK,"open_count: %d -> %d\n",
5336 D_S[d].open_count,D_S[d].open_count+1);
5337 if (++D_S[d].open_count<=1)
5339 i=LockDoor();
5340 D_S[d].open_count=1;
5341 if (famT_drive) msg(DBG_TEA,"sbpcd_open: before i=DiskInfo();.\n");
5342 i=DiskInfo();
5343 if (famT_drive) msg(DBG_TEA,"sbpcd_open: after i=DiskInfo();.\n");
5344 if ((D_S[d].ored_ctl_adr&0x40)==0)
5346 msg(DBG_INF,"CD contains no data tracks.\n");
5347 #if SAFE_MIXED
5348 D_S[d].has_data=0;
5349 #endif SAFE_MIXED
5351 #if SAFE_MIXED
5352 else if (D_S[d].has_data<1) D_S[d].has_data=1;
5353 #endif SAFE_MIXED
5355 if (!st_spinning) cc_SpinUp();
5356 RETURN_UP(0);
5358 /*==========================================================================*/
5360 * On close, we flush all sbp blocks from the buffer cache.
5362 static void sbpcd_release(struct cdrom_device_info * cdi)
5364 int i;
5366 i = MINOR(cdi->dev);
5367 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
5369 msg(DBG_INF, "release: bad device: %04X\n", cdi->dev);
5370 return ;
5372 down(&ioctl_read_sem);
5373 switch_drive(i);
5375 * try to keep an "open" counter here and unlock the door if 1->0.
5377 msg(DBG_LCK,"open_count: %d -> %d\n",
5378 D_S[d].open_count,D_S[d].open_count-1);
5379 if (D_S[d].open_count>-2) /* CDROMEJECT may have been done */
5381 if (--D_S[d].open_count<=0)
5383 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;
5384 invalidate_buffers(cdi->dev);
5385 if (D_S[d].audio_state!=audio_playing)
5386 if (D_S[d].f_eject) cc_SpinDown();
5387 D_S[d].diskstate_flags &= ~cd_size_bit;
5388 D_S[d].open_count=0;
5389 #if SAFE_MIXED
5390 D_S[d].has_data=0;
5391 #endif SAFE_MIXED
5394 up(&ioctl_read_sem);
5395 MOD_DEC_USE_COUNT;
5396 return ;
5398 /*==========================================================================*/
5402 static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr);
5403 static struct cdrom_device_ops sbpcd_dops = {
5404 sbpcd_open, /* open */
5405 sbpcd_release, /* release */
5406 sbpcd_drive_status, /* drive status */
5407 sbpcd_media_changed, /* media changed */
5408 sbpcd_tray_move, /* tray move */
5409 sbpcd_lock_door, /* lock door */
5410 sbpcd_select_speed, /* select speed */
5411 NULL, /* select disc */
5412 sbpcd_get_last_session, /* get last session */
5413 sbpcd_get_mcn, /* get universal product code */
5414 sbpcd_reset, /* hard reset */
5415 sbpcd_audio_ioctl, /* audio ioctl */
5416 sbpcd_dev_ioctl, /* device-specific ioctl */
5417 CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_MULTI_SESSION |
5418 CDC_MEDIA_CHANGED | CDC_MCN | CDC_PLAY_AUDIO | CDC_IOCTLS, /* capability */
5419 1, /* number of minor devices */
5422 static struct cdrom_device_info sbpcd_info = {
5423 &sbpcd_dops, /* device operations */
5424 NULL, /* link */
5425 NULL, /* handle */
5426 0, /* dev */
5427 0, /* mask */
5428 2, /* maximum speed */
5429 1, /* number of discs */
5430 0, /* options, not owned */
5431 0, /* mc_flags, not owned */
5432 0 /* use count, not owned */
5434 /*==========================================================================*/
5436 * accept "kernel command line" parameters
5437 * (suggested by Peter MacDonald with SLS 1.03)
5439 * This is only implemented for the first controller. Should be enough to
5440 * allow installing with a "strange" distribution kernel.
5442 * use: tell LILO:
5443 * sbpcd=0x230,SoundBlaster
5444 * or
5445 * sbpcd=0x300,LaserMate
5446 * or
5447 * sbpcd=0x338,SoundScape
5448 * or
5449 * sbpcd=0x2C0,Teac16bit
5451 * (upper/lower case sensitive here - but all-lowercase is ok!!!).
5453 * the address value has to be the CDROM PORT ADDRESS -
5454 * not the soundcard base address.
5455 * For the SPEA/SoundScape setup, DO NOT specify the "configuration port"
5456 * address, but the address which is really used for the CDROM (usually 8
5457 * bytes above).
5460 #if (SBPCD_ISSUE-1)
5461 __initfunc(static void sbpcd_setup(const char *s, int *p))
5462 #else
5463 __initfunc(void sbpcd_setup(const char *s, int *p))
5464 #endif
5466 setup_done++;
5467 msg(DBG_INI,"sbpcd_setup called with %04X,%s\n",p[1], s);
5468 sbpro_type=0; /* default: "LaserMate" */
5469 if (p[0]>1) sbpro_type=p[2];
5470 else if (!strcmp(s,str_sb)) sbpro_type=1;
5471 else if (!strcmp(s,str_sb_l)) sbpro_type=1;
5472 else if (!strcmp(s,str_sp)) sbpro_type=2;
5473 else if (!strcmp(s,str_sp_l)) sbpro_type=2;
5474 else if (!strcmp(s,str_ss)) sbpro_type=2;
5475 else if (!strcmp(s,str_ss_l)) sbpro_type=2;
5476 else if (!strcmp(s,str_t16)) sbpro_type=3;
5477 else if (!strcmp(s,str_t16_l)) sbpro_type=3;
5478 if (p[0]>0) sbpcd_ioaddr=p[1];
5480 CDo_command=sbpcd_ioaddr;
5481 CDi_info=sbpcd_ioaddr;
5482 CDi_status=sbpcd_ioaddr+1;
5483 CDo_sel_i_d=sbpcd_ioaddr+1;
5484 CDo_reset=sbpcd_ioaddr+2;
5485 CDo_enable=sbpcd_ioaddr+3;
5486 f_16bit=0;
5487 if ((sbpro_type==1)||(sbpro_type==3))
5489 CDi_data=sbpcd_ioaddr;
5490 if (sbpro_type==3)
5492 f_16bit=1;
5493 sbpro_type=1;
5496 else CDi_data=sbpcd_ioaddr+2;
5498 /*==========================================================================*/
5500 * Sequoia S-1000 CD-ROM Interface Configuration
5501 * as used within SPEA Media FX, Ensonic SoundScape and some Reveal cards
5502 * The soundcard has to get jumpered for the interface type "Panasonic"
5503 * (not Sony or Mitsumi) and to get soft-configured for
5504 * -> configuration port address
5505 * -> CDROM port offset (num_ports): has to be 8 here. Possibly this
5506 * offset value determines the interface type (none, Panasonic,
5507 * Mitsumi, Sony).
5508 * The interface uses a configuration port (0x320, 0x330, 0x340, 0x350)
5509 * some bytes below the real CDROM address.
5511 * For the Panasonic style (LaserMate) interface and the configuration
5512 * port 0x330, we have to use an offset of 8; so, the real CDROM port
5513 * address is 0x338.
5515 __initfunc(static int config_spea(void))
5518 * base address offset between configuration port and CDROM port,
5519 * this probably defines the interface type
5520 * 2 (type=??): 0x00
5521 * 8 (type=LaserMate):0x10
5522 * 16 (type=??):0x20
5523 * 32 (type=??):0x30
5525 int n_ports=0x10;
5527 int irq_number=0; /* off:0x00, 2/9:0x01, 7:0x03, 12:0x05, 15:0x07 */
5528 int dma_channel=0; /* off: 0x00, 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68 */
5529 int dack_polarity=0; /* L:0x00, H:0x80 */
5530 int drq_polarity=0x40; /* L:0x00, H:0x40 */
5531 int i;
5533 #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
5534 #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
5536 OUT(SPEA_REG_1,0xFF);
5537 i=inb(SPEA_REG_1);
5538 if (i!=0x0F)
5540 msg(DBG_SEQ,"no SPEA interface at %04X present.\n", sbpcd_ioaddr);
5541 return (-1); /* no interface found */
5543 OUT(SPEA_REG_1,0x04);
5544 OUT(SPEA_REG_2,0xC0);
5546 OUT(SPEA_REG_1,0x05);
5547 OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
5549 #if 1
5550 #define SPEA_PATTERN 0x80
5551 #else
5552 #define SPEA_PATTERN 0x00
5553 #endif
5554 OUT(SPEA_REG_1,0x06);
5555 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5556 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5558 OUT(SPEA_REG_1,0x09);
5559 i=(inb(SPEA_REG_2)&0xCF)|n_ports;
5560 OUT(SPEA_REG_2,i);
5562 sbpro_type = 0; /* acts like a LaserMate interface now */
5563 msg(DBG_SEQ,"found SoundScape interface at %04X.\n", sbpcd_ioaddr);
5564 return (0);
5566 /*==========================================================================*/
5568 * Test for presence of drive and initialize it.
5569 * Called once at boot or load time.
5571 #ifdef MODULE
5572 int init_module(void)
5573 #else
5574 __initfunc(int SBPCD_INIT(void))
5575 #endif MODULE
5577 int i=0, j=0;
5578 int addr[2]={1, CDROM_PORT};
5579 int port_index;
5581 sti();
5583 msg(DBG_INF,"sbpcd.c %s\n", VERSION);
5584 #ifndef MODULE
5585 #if DISTRIBUTION
5586 if (!setup_done)
5588 msg(DBG_INF,"Looking for Matsushita/Panasonic, CreativeLabs, Longshine, TEAC CD-ROM drives\n");
5589 msg(DBG_INF,"= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
5590 msg(DBG_INF,"Auto-Probing can cause a hang (f.e. touching an NE2000 card).\n");
5591 msg(DBG_INF,"If that happens, you have to reboot and use the\n");
5592 msg(DBG_INF,"LILO (kernel) command line feature like:\n");
5593 msg(DBG_INF," LILO boot: ... sbpcd=0x230,SoundBlaster\n");
5594 msg(DBG_INF,"or like:\n");
5595 msg(DBG_INF," LILO boot: ... sbpcd=0x300,LaserMate\n");
5596 msg(DBG_INF,"or like:\n");
5597 msg(DBG_INF," LILO boot: ... sbpcd=0x338,SoundScape\n");
5598 msg(DBG_INF,"with your REAL address.\n");
5599 msg(DBG_INF,"= = = = = = = = = = END of WARNING = = = = = == = = =\n");
5601 #endif DISTRIBUTION
5602 sbpcd[0]=sbpcd_ioaddr; /* possibly changed by kernel command line */
5603 sbpcd[1]=sbpro_type; /* possibly changed by kernel command line */
5604 #endif MODULE
5606 for (port_index=0;port_index<NUM_PROBE;port_index+=2)
5608 addr[1]=sbpcd[port_index];
5609 if (addr[1]==0) break;
5610 if (check_region(addr[1],4))
5612 msg(DBG_INF,"check_region: %03X is not free.\n",addr[1]);
5613 continue;
5615 if (sbpcd[port_index+1]==2) type=str_sp;
5616 else if (sbpcd[port_index+1]==1) type=str_sb;
5617 else if (sbpcd[port_index+1]==3) type=str_t16;
5618 else type=str_lm;
5619 sbpcd_setup(type, addr);
5620 #if DISTRIBUTION
5621 msg(DBG_INF,"Scanning 0x%X (%s)...\n", CDo_command, type);
5622 #endif DISTRIBUTION
5623 if (sbpcd[port_index+1]==2)
5625 i=config_spea();
5626 if (i<0) continue;
5628 #ifdef PATH_CHECK
5629 if (check_card(addr[1])) continue;
5630 #endif PATH_CHECK
5631 i=check_drives();
5632 msg(DBG_INI,"check_drives done.\n");
5633 if (i>=0) break; /* drive found */
5634 } /* end of cycling through the set of possible I/O port addresses */
5636 if (ndrives==0)
5638 msg(DBG_INF, "No drive found.\n");
5639 #ifdef MODULE
5640 return -EIO;
5641 #else
5642 goto init_done;
5643 #endif MODULE
5646 if (port_index>0)
5648 msg(DBG_INF, "You should read linux/Documentation/cdrom/sbpcd\n");
5649 msg(DBG_INF, "and then configure sbpcd.h for your hardware.\n");
5651 check_datarate();
5652 msg(DBG_INI,"check_datarate done.\n");
5654 for (j=0;j<NR_SBPCD;j++)
5656 if (D_S[j].drv_id==-1) continue;
5657 switch_drive(j);
5658 #if 1
5659 if (!famL_drive) cc_DriveReset();
5660 #endif 0
5661 if (!st_spinning) cc_SpinUp();
5662 D_S[j].sbp_first_frame = -1; /* First frame in buffer */
5663 D_S[j].sbp_last_frame = -1; /* Last frame in buffer */
5664 D_S[j].sbp_read_frames = 0; /* Number of frames being read to buffer */
5665 D_S[j].sbp_current = 0; /* Frame being currently read */
5666 D_S[j].CD_changed=1;
5667 D_S[j].frame_size=CD_FRAMESIZE;
5668 D_S[j].f_eject=0;
5669 #if EJECT
5670 if (!fam0_drive) D_S[j].f_eject=1;
5671 #endif EJECT
5672 cc_ReadStatus();
5673 i=ResponseStatus(); /* returns orig. status or p_busy_new */
5674 if (famT_drive) i=ResponseStatus(); /* returns orig. status or p_busy_new */
5675 if (i<0)
5677 if (i!=-402)
5678 msg(DBG_INF,"init: ResponseStatus returns %d.\n",i);
5680 else
5682 if (st_check)
5684 i=cc_ReadError();
5685 msg(DBG_INI,"init: cc_ReadError returns %d\n",i);
5688 msg(DBG_INI,"init: first GetStatus: %d\n",i);
5689 msg(DBG_LCS,"init: first GetStatus: error_byte=%d\n",
5690 D_S[j].error_byte);
5691 if (D_S[j].error_byte==aud_12)
5693 timeout=jiffies+2*HZ;
5696 i=GetStatus();
5697 msg(DBG_INI,"init: second GetStatus: %02X\n",i);
5698 msg(DBG_LCS,
5699 "init: second GetStatus: error_byte=%d\n",
5700 D_S[j].error_byte);
5701 if (i<0) break;
5702 if (!st_caddy_in) break;
5704 while ((!st_diskok)||time_after(jiffies, timeout));
5706 i=SetSpeed();
5707 if (i>=0) D_S[j].CD_changed=1;
5711 * Turn on the CD audio channels.
5712 * The addresses are obtained from SOUND_BASE (see sbpcd.h).
5714 #if SOUND_BASE
5715 OUT(MIXER_addr,MIXER_CD_Volume); /* select SB Pro mixer register */
5716 OUT(MIXER_data,0xCC); /* one nibble per channel, max. value: 0xFF */
5717 #endif SOUND_BASE
5719 if (register_blkdev(MAJOR_NR, major_name, &cdrom_fops) != 0)
5721 msg(DBG_INF, "Can't get MAJOR %d for Matsushita CDROM\n", MAJOR_NR);
5722 #ifdef MODULE
5723 return -EIO;
5724 #else
5725 goto init_done;
5726 #endif MODULE
5728 blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST;
5729 read_ahead[MAJOR_NR] = buffers * (CD_FRAMESIZE / 512);
5731 request_region(CDo_command,4,major_name);
5733 for (j=0;j<NR_SBPCD;j++)
5735 struct cdrom_device_info * sbpcd_infop;
5737 if (D_S[j].drv_id==-1) continue;
5738 switch_drive(j);
5739 #if SAFE_MIXED
5740 D_S[j].has_data=0;
5741 #endif SAFE_MIXED
5743 * allocate memory for the frame buffers
5745 D_S[j].aud_buf=NULL;
5746 D_S[j].sbp_audsiz=0;
5747 D_S[j].sbp_bufsiz=buffers;
5748 if (D_S[j].drv_type&drv_fam1)
5749 if (READ_AUDIO>0) D_S[j].sbp_audsiz=READ_AUDIO;
5750 D_S[j].sbp_buf=(u_char *) vmalloc(D_S[j].sbp_bufsiz*CD_FRAMESIZE);
5751 if (D_S[j].sbp_buf==NULL)
5753 msg(DBG_INF,"data buffer (%d frames) not available.\n",D_S[j].sbp_bufsiz);
5754 if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
5756 printk("Can't unregister %s\n", major_name);
5758 release_region(CDo_command,4);
5759 return -EIO;
5761 #ifdef MODULE
5762 msg(DBG_INF,"data buffer size: %d frames.\n",buffers);
5763 #endif MODULE
5764 if (D_S[j].sbp_audsiz>0)
5766 D_S[j].aud_buf=(u_char *) vmalloc(D_S[j].sbp_audsiz*CD_FRAMESIZE_RAW);
5767 if (D_S[j].aud_buf==NULL) msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[j].sbp_audsiz);
5768 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[j].sbp_audsiz);
5770 sbpcd_infop = vmalloc(sizeof (struct cdrom_device_info));
5771 if (sbpcd_infop == NULL)
5773 release_region(CDo_command,4);
5774 return -ENOMEM;
5776 D_S[j].sbpcd_infop = sbpcd_infop;
5777 memcpy (sbpcd_infop, &sbpcd_info, sizeof(struct cdrom_device_info));
5778 sbpcd_infop->dev = MKDEV(MAJOR_NR, j);
5779 strncpy(sbpcd_infop->name,major_name, sizeof(sbpcd_infop->name));
5781 if (register_cdrom(sbpcd_infop))
5783 printk(" sbpcd: Unable to register with Uniform CD-ROm driver\n");
5787 * set the block size
5789 sbpcd_blocksizes[j]=CD_FRAMESIZE;
5791 blksize_size[MAJOR_NR]=sbpcd_blocksizes;
5793 #ifndef MODULE
5794 init_done:
5795 #if !(SBPCD_ISSUE-1)
5796 #ifdef CONFIG_SBPCD2
5797 sbpcd2_init();
5798 #endif CONFIG_SBPCD2
5799 #ifdef CONFIG_SBPCD3
5800 sbpcd3_init();
5801 #endif CONFIG_SBPCD3
5802 #ifdef CONFIG_SBPCD4
5803 sbpcd4_init();
5804 #endif CONFIG_SBPCD4
5805 #endif !(SBPCD_ISSUE-1)
5806 #endif MODULE
5807 return 0;
5809 /*==========================================================================*/
5810 #ifdef MODULE
5811 void cleanup_module(void)
5813 int j;
5815 if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
5817 msg(DBG_INF, "What's that: can't unregister %s.\n", major_name);
5818 return;
5820 release_region(CDo_command,4);
5822 for (j=0;j<NR_SBPCD;j++)
5824 if (D_S[j].drv_id==-1) continue;
5825 vfree(D_S[j].sbp_buf);
5826 if (D_S[j].sbp_audsiz>0) vfree(D_S[j].aud_buf);
5827 if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
5829 msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
5830 return;
5832 vfree(D_S[j].sbpcd_infop);
5834 msg(DBG_INF, "%s module released.\n", major_name);
5836 #endif MODULE
5837 /*==========================================================================*/
5839 * Check if the media has changed in the CD-ROM drive.
5840 * used externally (isofs/inode.c, fs/buffer.c)
5842 static int sbpcd_chk_disk_change(kdev_t full_dev)
5844 int i;
5846 msg(DBG_CHK,"media_check (%d) called\n", MINOR(full_dev));
5847 i=MINOR(full_dev);
5849 if (D_S[i].CD_changed==0xFF)
5851 D_S[i].CD_changed=0;
5852 msg(DBG_CHK,"medium changed (drive %d)\n", i);
5853 return (1);
5855 else
5856 return (0);
5859 static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr)
5861 return sbpcd_chk_disk_change(cdi->dev);
5863 /*==========================================================================*/
5865 * Overrides for Emacs so that we follow Linus's tabbing style.
5866 * Emacs will notice this stuff at the end of the file and automatically
5867 * adjust the settings for this buffer only. This must remain at the end
5868 * of the file.
5869 * ---------------------------------------------------------------------------
5870 * Local variables:
5871 * c-indent-level: 8
5872 * c-brace-imaginary-offset: 0
5873 * c-brace-offset: -8
5874 * c-argdecl-indent: 8
5875 * c-label-offset: -8
5876 * c-continued-statement-offset: 8
5877 * c-continued-brace-offset: 0
5878 * End: