- pre5:
[davej-history.git] / drivers / cdrom / sbpcd.c
blob07e97a1d73ef92451e3b9cf931cff81726d88df5
3 /*
4 * sbpcd.c CD-ROM device driver for the whole family of traditional,
5 * non-ATAPI IDE-style Matsushita/Panasonic CR-5xx drives.
6 * Works with SoundBlaster compatible cards and with "no-sound"
7 * interface cards like Lasermate, Panasonic CI-101P, Teac, ...
8 * Also for the Longshine LCS-7260 drive.
9 * Also for the IBM "External ISA CD-Rom" drive.
10 * Also for the CreativeLabs CD200 drive.
11 * Also for the TEAC CD-55A drive.
12 * Also for the ECS-AT "Vertos 100" drive.
13 * Not for Sanyo drives (but for the H94A, sjcd is there...).
14 * Not for any other Funai drives than the CD200 types (sometimes
15 * labelled E2550UA or MK4015 or 2800F).
18 #define VERSION "v4.63 Andrew J. Kroll <ag784@freenet.buffalo.edu> Wed Jul 26 04:24:10 EDT 2000"
20 /* Copyright (C) 1993, 1994, 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2, or (at your option)
25 * any later version.
27 * You should have received a copy of the GNU General Public License
28 * (for example /usr/src/linux/COPYING); if not, write to the Free
29 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 * If you change this software, you should mail a .diff file with some
32 * description lines to emoenke@gwdg.de. I want to know about it.
34 * If you are the editor of a Linux CD, you should enable sbpcd.c within
35 * your boot floppy kernel and send me one of your CDs for free.
37 * If you would like to port the driver to an other operating system (f.e.
38 * FreeBSD or NetBSD) or use it as an information source, you shall not be
39 * restricted by the GPL under the following conditions:
40 * a) the source code of your work is freely available
41 * b) my part of the work gets mentioned at all places where your
42 * authorship gets mentioned
43 * c) I receive a copy of your code together with a full installation
44 * package of your operating system for free.
47 * VERSION HISTORY
49 * 0.1 initial release, April/May 93, after mcd.c (Martin Harriss)
51 * 0.2 thek "repeat:"-loop in do_sbpcd_request did not check for
52 * end-of-request_queue (resulting in kernel panic).
53 * Flow control seems stable, but throughput is not better.
55 * 0.3 interrupt locking totally eliminated (maybe "inb" and "outb"
56 * are still locking) - 0.2 made keyboard-type-ahead losses.
57 * check_sbpcd_media_change added (to use by isofs/inode.c)
58 * - but it detects almost nothing.
60 * 0.4 use MAJOR 25 definitely.
61 * Almost total re-design to support double-speed drives and
62 * "naked" (no sound) interface cards ("LaserMate" interface type).
63 * Flow control should be exact now.
64 * Don't occupy the SbPro IRQ line (not needed either); will
65 * live together with Hannu Savolainen's sndkit now.
66 * Speeded up data transfer to 150 kB/sec, with help from Kai
67 * Makisara, the "provider" of the "mt" tape utility.
68 * Give "SpinUp" command if necessary.
69 * First steps to support up to 4 drives (but currently only one).
70 * Implemented audio capabilities - workman should work, xcdplayer
71 * gives some problems.
72 * This version is still consuming too much CPU time, and
73 * sleeping still has to be worked on.
74 * During "long" implied seeks, it seems possible that a
75 * ReadStatus command gets ignored. That gives the message
76 * "ResponseStatus timed out" (happens about 6 times here during
77 * a "ls -alR" of the YGGDRASIL LGX-Beta CD). Such a case is
78 * handled without data error, but it should get done better.
80 * 0.5 Free CPU during waits (again with help from Kai Makisara).
81 * Made it work together with the LILO/kernel setup standard.
82 * Included auto-probing code, as suggested by YGGDRASIL.
83 * Formal redesign to add DDI debugging.
84 * There are still flaws in IOCTL (workman with double speed drive).
86 * 1.0 Added support for all drive IDs (0...3, no longer only 0)
87 * and up to 4 drives on one controller.
88 * Added "#define MANY_SESSION" for "old" multi session CDs.
90 * 1.1 Do SpinUp for new drives, too.
91 * Revised for clean compile under "old" kernels (0.99pl9).
93 * 1.2 Found the "workman with double-speed drive" bug: use the driver's
94 * audio_state, not what the drive is reporting with ReadSubQ.
96 * 1.3 Minor cleanups.
97 * Refinements regarding Workman.
99 * 1.4 Read XA disks (PhotoCDs) with "old" drives, too (but only the first
100 * session - no chance to fully access a "multi-session" CD).
101 * This currently still is too slow (50 kB/sec) - but possibly
102 * the old drives won't do it faster.
103 * Implemented "door (un)lock" for new drives (still does not work
104 * as wanted - no lock possible after an unlock).
105 * Added some debugging printout for the UPC/EAN code - but my drives
106 * return only zeroes. Is there no UPC/EAN code written?
108 * 1.5 Laborate with UPC/EAN code (not better yet).
109 * Adapt to kernel 1.1.8 change (have to explicitly include
110 * <linux/string.h> now).
112 * 1.6 Trying to read audio frames as data. Impossible with the current
113 * drive firmware levels, as it seems. Awaiting any hint. ;-)
114 * Changed "door unlock": repeat it until success.
115 * Changed CDROMSTOP routine (stop somewhat "softer" so that Workman
116 * won't get confused).
117 * Added a third interface type: Sequoia S-1000, as used with the SPEA
118 * Media FX sound card. This interface (usable for Sony and Mitsumi
119 * drives, too) needs a special configuration setup and behaves like a
120 * LaserMate type after that. Still experimental - I do not have such
121 * an interface.
122 * Use the "variable BLOCK_SIZE" feature (2048). But it does only work
123 * if you give the mount option "block=2048".
124 * The media_check routine is currently disabled; now that it gets
125 * called as it should I fear it must get synchronized for not to
126 * disturb the normal driver's activity.
128 * 2.0 Version number bumped - two reasons:
129 * - reading audio tracks as data works now with CR-562 and CR-563. We
130 * currently do it by an IOCTL (yet has to get standardized), one frame
131 * at a time; that is pretty slow. But it works.
132 * - we are maintaining now up to 4 interfaces (each up to 4 drives):
133 * did it the easy way - a different MAJOR (25, 26, ...) and a different
134 * copy of the driver (sbpcd.c, sbpcd2.c, sbpcd3.c, sbpcd4.c - only
135 * distinguished by the value of SBPCD_ISSUE and the driver's name),
136 * and a common sbpcd.h file.
137 * Bettered the "ReadCapacity error" problem with old CR-52x drives (the
138 * drives sometimes need a manual "eject/insert" before work): just
139 * reset the drive and do again. Needs lots of resets here and sometimes
140 * that does not cure, so this can't be the solution.
142 * 2.1 Found bug with multisession CDs (accessing frame 16).
143 * "read audio" works now with address type CDROM_MSF, too.
144 * Bigger audio frame buffer: allows reading max. 4 frames at time; this
145 * gives a significant speedup, but reading more than one frame at once
146 * gives missing chunks at each single frame boundary.
148 * 2.2 Kernel interface cleanups: timers, init, setup, media check.
150 * 2.3 Let "door lock" and "eject" live together.
151 * Implemented "close tray" (done automatically during open).
153 * 2.4 Use different names for device registering.
155 * 2.5 Added "#if EJECT" code (default: enabled) to automatically eject
156 * the tray during last call to "sbpcd_release".
157 * Added "#if JUKEBOX" code (default: disabled) to automatically eject
158 * the tray during call to "sbpcd_open" if no disk is in.
159 * Turn on the CD volume of "compatible" sound cards, too; just define
160 * SOUND_BASE (in sbpcd.h) accordingly (default: disabled).
162 * 2.6 Nothing new.
164 * 2.7 Added CDROMEJECT_SW ioctl to set the "EJECT" behavior on the fly:
165 * 0 disables, 1 enables auto-ejecting. Useful to keep the tray in
166 * during shutdown.
168 * 2.8 Added first support (still BETA, I need feedback or a drive) for
169 * the Longshine LCS-7260 drives. They appear as double-speed drives
170 * using the "old" command scheme, extended by tray control and door
171 * lock functions.
172 * Found (and fixed preliminary) a flaw with some multisession CDs: we
173 * have to re-direct not only the accesses to frame 16 (the isofs
174 * routines drive it up to max. 100), but also those to the continuation
175 * (repetition) frames (as far as they exist - currently set fix as
176 * 16..20).
177 * Changed default of the "JUKEBOX" define. If you use this default,
178 * your tray will eject if you try to mount without a disk in. Next
179 * mount command will insert the tray - so, just fill in a disk. ;-)
181 * 2.9 Fulfilled the Longshine LCS-7260 support; with great help and
182 * experiments by Serge Robyns.
183 * First attempts to support the TEAC CD-55A drives; but still not
184 * usable yet.
185 * Implemented the CDROMMULTISESSION ioctl; this is an attempt to handle
186 * multi session CDs more "transparent" (redirection handling has to be
187 * done within the isofs routines, and only for the special purpose of
188 * obtaining the "right" volume descriptor; accesses to the raw device
189 * should not get redirected).
191 * 3.0 Just a "normal" increment, with some provisions to do it better. ;-)
192 * Introduced "#define READ_AUDIO" to specify the maximum number of
193 * audio frames to grab with one request. This defines a buffer size
194 * within kernel space; a value of 0 will reserve no such space and
195 * disable the CDROMREADAUDIO ioctl. A value of 75 enables the reading
196 * of a whole second with one command, but will use a buffer of more
197 * than 172 kB.
198 * Started CD200 support. Drive detection should work, but nothing
199 * more.
201 * 3.1 Working to support the CD200 and the Teac CD-55A drives.
202 * AT-BUS style device numbering no longer used: use SCSI style now.
203 * So, the first "found" device has MINOR 0, regardless of the
204 * jumpered drive ID. This implies modifications to the /dev/sbpcd*
205 * entries for some people, but will help the DAU (german TLA, english:
206 * "newbie", maybe ;-) to install his "first" system from a CD.
208 * 3.2 Still testing with CD200 and CD-55A drives.
210 * 3.3 Working with CD200 support.
212 * 3.4 Auto-probing stops if an address of 0 is seen (to be entered with
213 * the kernel command line).
214 * Made the driver "loadable". If used as a module, "audio copy" is
215 * disabled, and the internal read ahead data buffer has a reduced size
216 * of 4 kB; so, throughput may be reduced a little bit with slow CPUs.
218 * 3.5 Provisions to handle weird photoCDs which have an interrupted
219 * "formatting" immediately after the last frames of some files: simply
220 * never "read ahead" with MultiSession CDs. By this, CPU usage may be
221 * increased with those CDs, and there may be a loss in speed.
222 * Re-structured the messaging system.
223 * The "loadable" version no longer has a limited READ_AUDIO buffer
224 * size.
225 * Removed "MANY_SESSION" handling for "old" multi session CDs.
226 * Added "private" IOCTLs CDROMRESET and CDROMVOLREAD.
227 * Started again to support the TEAC CD-55A drives, now that I found
228 * the money for "my own" drive. ;-)
229 * The TEAC CD-55A support is fairly working now.
230 * I have measured that the drive "delivers" at 600 kB/sec (even with
231 * bigger requests than the drive's 64 kB buffer can satisfy), but
232 * the "real" rate does not exceed 520 kB/sec at the moment.
233 * Caused by the various changes to build in TEAC support, the timed
234 * loops are de-optimized at the moment (less throughput with CR-52x
235 * drives, and the TEAC will give speed only with SBP_BUFFER_FRAMES 64).
237 * 3.6 Fixed TEAC data read problems with SbPro interfaces.
238 * Initial size of the READ_AUDIO buffer is 0. Can get set to any size
239 * during runtime.
241 * 3.7 Introduced MAX_DRIVES for some poor interface cards (seen with TEAC
242 * drives) which allow only one drive (ID 0); this avoids repetitive
243 * detection under IDs 1..3.
244 * Elongated cmd_out_T response waiting; necessary for photo CDs with
245 * a lot of sessions.
246 * Bettered the sbpcd_open() behavior with TEAC drives.
248 * 3.8 Elongated max_latency for CR-56x drives.
250 * 3.9 Finally fixed the long-known SoundScape/SPEA/Sequoia S-1000 interface
251 * configuration bug.
252 * Now Corey, Heiko, Ken, Leo, Vadim/Eric & Werner are invited to copy
253 * the config_spea() routine into their drivers. ;-)
255 * 4.0 No "big step" - normal version increment.
256 * Adapted the benefits from 1.3.33.
257 * Fiddled with CDROMREADAUDIO flaws.
258 * Avoid ReadCapacity command with CD200 drives (the MKE 1.01 version
259 * seems not to support it).
260 * Fulfilled "read audio" for CD200 drives, with help of Pete Heist
261 * (heistp@rpi.edu).
263 * 4.1 Use loglevel KERN_INFO with printk().
264 * Added support for "Vertos 100" drive ("ECS-AT") - it is very similar
265 * to the Longshine LCS-7260. Give feedback if you can - I never saw
266 * such a drive, and I have no specs.
268 * 4.2 Support for Teac 16-bit interface cards. Can't get auto-detected,
269 * so you have to jumper your card to 0x2C0. Still not 100% - come
270 * in contact if you can give qualified feedback.
271 * Use loglevel KERN_NOTICE with printk(). If you get annoyed by a
272 * flood of unwanted messages and the accompanied delay, try to read
273 * my documentation. Especially the Linux CDROM drivers have to do an
274 * important job for the newcomers, so the "distributed" version has
275 * to fit some special needs. Since generations, the flood of messages
276 * is user-configurable (even at runtime), but to get aware of this, one
277 * needs a special mental quality: the ability to read.
279 * 4.3 CD200F does not like to receive a command while the drive is
280 * reading the ToC; still trying to solve it.
281 * Removed some redundant verify_area calls (yes, Heiko Eissfeldt
282 * is visiting all the Linux CDROM drivers ;-).
284 * 4.4 Adapted one idea from tiensivu@pilot.msu.edu's "stripping-down"
285 * experiments: "KLOGD_PAUSE".
286 * Inhibited "play audio" attempts with data CDs. Provisions for a
287 * "data-safe" handling of "mixed" (data plus audio) Cds.
289 * 4.5 Meanwhile Gonzalo Tornaria <tornaria@cmat.edu.uy> (GTL) built a
290 * special end_request routine: we seem to have to take care for not
291 * to have two processes working at the request list. My understanding
292 * was and is that ll_rw_blk should not call do_sbpcd_request as long
293 * as there is still one call active (the first call will care for all
294 * outstanding I/Os, and if a second call happens, that is a bug in
295 * ll_rw_blk.c).
296 * "Check media change" without touching any drive.
298 * 4.6 Use a semaphore to synchronize multi-activity; elaborated by Rob
299 * Riggs <rriggs@tesser.com>. At the moment, we simply block "read"
300 * against "ioctl" and vice versa. This could be refined further, but
301 * I guess with almost no performance increase.
302 * Experiments to speed up the CD-55A; again with help of Rob Riggs
303 * (to be true, he gave both, idea & code. ;-)
305 * 4.61 Ported to Uniform CD-ROM driver by
306 * Heiko Eissfeldt <heiko@colossus.escape.de> with additional
307 * changes by Erik Andersen <andersee@debian.org>
309 * 4.62 Fix a bug where playing audio left the drive in an unusable state.
310 * Heiko Eissfeldt <heiko@colossus.escape.de>
312 * November 1999 -- Make kernel-parameter implementation work with 2.3.x
313 * Removed init_module & cleanup_module in favor of
314 * module_init & module_exit.
315 * Torben Mathiasen <tmm@image.dk>
317 * 4.63 Bug fixes for audio annoyances, new legacy CDROM maintainer.
318 * Annoying things fixed:
319 * TOC reread on automated disk changes
320 * TOC reread on manual cd changes
321 * Play IOCTL tries to play CD before it's actually ready... sometimes.
322 * CD_AUDIO_COMPLETED state so workman (and other playes) can repeat play.
323 * Andrew J. Kroll <ag784@freenet.buffalo.edu> Wed Jul 26 04:24:10 EDT 2000
326 * TODO
327 * implement "read all subchannel data" (96 bytes per frame)
328 * remove alot of the virtual status bits and deal with hardware status
329 * move the change of cd for audio to a better place
330 * add debug levels to insmod parameters (trivial)
332 * special thanks to Kai Makisara (kai.makisara@vtt.fi) for his fine
333 * elaborated speed-up experiments (and the fabulous results!), for
334 * the "push" towards load-free wait loops, and for the extensive mail
335 * thread which brought additional hints and bug fixes.
339 #ifndef SBPCD_ISSUE
340 #define SBPCD_ISSUE 1
341 #endif SBPCD_ISSUE
343 #include <linux/module.h>
345 #include <linux/version.h>
346 #include <linux/errno.h>
347 #include <linux/sched.h>
348 #include <linux/mm.h>
349 #include <linux/timer.h>
350 #include <linux/fs.h>
351 #include <linux/kernel.h>
352 #include <linux/cdrom.h>
353 #include <linux/ioport.h>
354 #include <linux/devfs_fs_kernel.h>
355 #include <linux/major.h>
356 #include <linux/string.h>
357 #include <linux/vmalloc.h>
358 #include <linux/init.h>
359 #include <linux/interrupt.h>
361 #include <asm/system.h>
362 #include <asm/io.h>
363 #include <asm/uaccess.h>
364 #include <stdarg.h>
365 #include <linux/config.h>
366 #include "sbpcd.h"
368 #if !(SBPCD_ISSUE-1)
369 #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
370 #endif
371 #if !(SBPCD_ISSUE-2)
372 #define MAJOR_NR MATSUSHITA_CDROM2_MAJOR /* second driver issue */
373 #endif
374 #if !(SBPCD_ISSUE-3)
375 #define MAJOR_NR MATSUSHITA_CDROM3_MAJOR /* third driver issue */
376 #endif
377 #if !(SBPCD_ISSUE-4)
378 #define MAJOR_NR MATSUSHITA_CDROM4_MAJOR /* fourth driver issue */
379 #endif
381 #include <linux/blk.h>
383 /*==========================================================================*/
385 * provisions for more than 1 driver issues
386 * currently up to 4 drivers, expandable
388 #if !(SBPCD_ISSUE-1)
389 #define DO_SBPCD_REQUEST(a) do_sbpcd_request(a)
390 #define SBPCD_INIT(a) sbpcd_init(a)
391 #endif
392 #if !(SBPCD_ISSUE-2)
393 #define DO_SBPCD_REQUEST(a) do_sbpcd2_request(a)
394 #define SBPCD_INIT(a) sbpcd2_init(a)
395 #endif
396 #if !(SBPCD_ISSUE-3)
397 #define DO_SBPCD_REQUEST(a) do_sbpcd3_request(a)
398 #define SBPCD_INIT(a) sbpcd3_init(a)
399 #endif
400 #if !(SBPCD_ISSUE-4)
401 #define DO_SBPCD_REQUEST(a) do_sbpcd4_request(a)
402 #define SBPCD_INIT(a) sbpcd4_init(a)
403 #endif
404 /*==========================================================================*/
405 #if SBPCD_DIS_IRQ
406 #define SBPCD_CLI cli()
407 #define SBPCD_STI sti()
408 #else
409 #define SBPCD_CLI
410 #define SBPCD_STI
411 #endif SBPCD_DIS_IRQ
412 /*==========================================================================*/
414 * auto-probing address list
415 * inspired by Adam J. Richter from Yggdrasil
417 * still not good enough - can cause a hang.
418 * example: a NE 2000 ethernet card at 300 will cause a hang probing 310.
419 * if that happens, reboot and use the LILO (kernel) command line.
420 * The possibly conflicting ethernet card addresses get NOT probed
421 * by default - to minimize the hang possibilities.
423 * The SB Pro addresses get "mirrored" at 0x6xx and some more locations - to
424 * avoid a type error, the 0x2xx-addresses must get checked before 0x6xx.
426 * send mail to emoenke@gwdg.de if your interface card is not FULLY
427 * represented here.
429 #if !(SBPCD_ISSUE-1)
430 static int sbpcd[] =
432 CDROM_PORT, SBPRO, /* probe with user's setup first */
433 #if DISTRIBUTION
434 0x230, 1, /* Soundblaster Pro and 16 (default) */
435 #if 0
436 0x300, 0, /* CI-101P (default), WDH-7001C (default),
437 Galaxy (default), Reveal (one default) */
438 0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
439 0x2C0, 3, /* Teac 16-bit cards */
440 0x260, 1, /* OmniCD */
441 0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
442 Longshine LCS-6853 (default) */
443 0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
444 0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
445 0x360, 0, /* Lasermate, CI-101P */
446 0x270, 1, /* Soundblaster 16 */
447 0x670, 0, /* "sound card #9" */
448 0x690, 0, /* "sound card #9" */
449 0x338, 2, /* SPEA Media FX, Ensonic SoundScape (default) */
450 0x328, 2, /* SPEA Media FX */
451 0x348, 2, /* SPEA Media FX */
452 0x634, 0, /* some newer sound cards */
453 0x638, 0, /* some newer sound cards */
454 0x230, 1, /* some newer sound cards */
455 /* due to incomplete address decoding of the SbPro card, these must be last */
456 0x630, 0, /* "sound card #9" (default) */
457 0x650, 0, /* "sound card #9" */
458 #ifdef MODULE
460 * some "hazardous" locations (no harm with the loadable version)
461 * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
463 0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
464 0x350, 0, /* Lasermate, CI-101P */
465 0x358, 2, /* SPEA Media FX */
466 0x370, 0, /* Lasermate, CI-101P */
467 0x290, 1, /* Soundblaster 16 */
468 0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
469 #endif MODULE
470 #endif
471 #endif DISTRIBUTION
473 #else
474 static int sbpcd[] = {CDROM_PORT, SBPRO}; /* probe with user's setup only */
475 #endif
476 MODULE_PARM(sbpcd, "2i");
478 #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
480 /*==========================================================================*/
482 * the external references:
484 #if !(SBPCD_ISSUE-1)
485 #ifdef CONFIG_SBPCD2
486 extern int sbpcd2_init(void);
487 #endif
488 #ifdef CONFIG_SBPCD3
489 extern int sbpcd3_init(void);
490 #endif
491 #ifdef CONFIG_SBPCD4
492 extern int sbpcd4_init(void);
493 #endif
494 #endif
496 /*==========================================================================*/
498 #define INLINE inline
500 /*==========================================================================*/
502 * the forward references:
504 static void sbp_sleep(u_int);
505 static void mark_timeout_delay(u_long);
506 static void mark_timeout_data(u_long);
507 #if 0
508 static void mark_timeout_audio(u_long);
509 #endif
510 static void sbp_read_cmd(struct request *req);
511 static int sbp_data(struct request *req);
512 static int cmd_out(void);
513 static int DiskInfo(void);
514 static int sbpcd_chk_disk_change(kdev_t);
516 /*==========================================================================*/
519 * pattern for printk selection:
521 * (1<<DBG_INF) necessary information
522 * (1<<DBG_BSZ) BLOCK_SIZE trace
523 * (1<<DBG_REA) "read" status trace
524 * (1<<DBG_CHK) "media check" trace
525 * (1<<DBG_TIM) datarate timer test
526 * (1<<DBG_INI) initialization trace
527 * (1<<DBG_TOC) tell TocEntry values
528 * (1<<DBG_IOC) ioctl trace
529 * (1<<DBG_STA) "ResponseStatus" trace
530 * (1<<DBG_ERR) "cc_ReadError" trace
531 * (1<<DBG_CMD) "cmd_out" trace
532 * (1<<DBG_WRN) give explanation before auto-probing
533 * (1<<DBG_MUL) multi session code test
534 * (1<<DBG_IDX) "drive_id != 0" test code
535 * (1<<DBG_IOX) some special information
536 * (1<<DBG_DID) drive ID test
537 * (1<<DBG_RES) drive reset info
538 * (1<<DBG_SPI) SpinUp test info
539 * (1<<DBG_IOS) ioctl trace: "subchannel"
540 * (1<<DBG_IO2) ioctl trace: general
541 * (1<<DBG_UPC) show UPC info
542 * (1<<DBG_XA1) XA mode debugging
543 * (1<<DBG_LCK) door (un)lock info
544 * (1<<DBG_SQ1) dump SubQ frame
545 * (1<<DBG_AUD) "read audio" debugging
546 * (1<<DBG_SEQ) Sequoia interface configuration trace
547 * (1<<DBG_LCS) Longshine LCS-7260 debugging trace
548 * (1<<DBG_CD2) MKE/Funai CD200 debugging trace
549 * (1<<DBG_TEA) TEAC CD-55A debugging trace
550 * (1<<DBG_ECS) ECS-AT (Vertos-100) debugging trace
551 * (1<<DBG_000) unnecessary information
553 #if DISTRIBUTION
554 static int sbpcd_debug = (1<<DBG_INF);
555 #else
556 static int sbpcd_debug = 0 & ((1<<DBG_INF) |
557 (1<<DBG_TOC) |
558 (1<<DBG_MUL) |
559 (1<<DBG_UPC));
560 #endif DISTRIBUTION
562 static int sbpcd_ioaddr = CDROM_PORT; /* default I/O base address */
563 static int sbpro_type = SBPRO;
564 static unsigned char setup_done = 0;
565 static unsigned char f_16bit = 0;
566 static unsigned char do_16bit = 0;
567 static int CDo_command, CDo_reset;
568 static int CDo_sel_i_d, CDo_enable;
569 static int CDi_info, CDi_status, CDi_data;
570 static struct cdrom_msf msf;
571 static struct cdrom_ti ti;
572 static struct cdrom_tochdr tochdr;
573 static struct cdrom_tocentry tocentry;
574 static struct cdrom_subchnl SC;
575 static struct cdrom_volctrl volctrl;
576 static struct cdrom_read_audio read_audio;
578 static unsigned char msgnum=0;
579 static char msgbuf[80];
581 static const char *str_sb = "SoundBlaster";
582 static const char *str_sb_l = "soundblaster";
583 static const char *str_lm = "LaserMate";
584 static const char *str_sp = "SPEA";
585 static const char *str_sp_l = "spea";
586 static const char *str_ss = "SoundScape";
587 static const char *str_ss_l = "soundscape";
588 static const char *str_t16 = "Teac16bit";
589 static const char *str_t16_l = "teac16bit";
590 static const char *type;
592 #if !(SBPCD_ISSUE-1)
593 static const char *major_name="sbpcd";
594 #endif
595 #if !(SBPCD_ISSUE-2)
596 static const char *major_name="sbpcd2";
597 #endif
598 #if !(SBPCD_ISSUE-3)
599 static const char *major_name="sbpcd3";
600 #endif
601 #if !(SBPCD_ISSUE-4)
602 static const char *major_name="sbpcd4";
603 #endif
605 /*==========================================================================*/
607 #if FUTURE
608 static DECLARE_WAIT_QUEUE_HEAD(sbp_waitq);
609 #endif FUTURE
611 static int teac=SBP_TEAC_SPEED;
612 static int buffers=SBP_BUFFER_FRAMES;
614 static u_char family0[]="MATSHITA"; /* MKE CR-521, CR-522, CR-523 */
615 static u_char family1[]="CR-56"; /* MKE CR-562, CR-563 */
616 static u_char family2[]="CD200"; /* MKE CD200, Funai CD200F */
617 static u_char familyL[]="LCS-7260"; /* Longshine LCS-7260 */
618 static u_char familyT[]="CD-55"; /* TEAC CD-55A */
619 static u_char familyV[]="ECS-AT"; /* ECS Vertos 100 */
621 static u_int recursion=0; /* internal testing only */
622 static u_int fatal_err=0; /* internal testing only */
623 static u_int response_count=0;
624 static u_int flags_cmd_out;
625 static u_char cmd_type=0;
626 static u_char drvcmd[10];
627 static u_char infobuf[20];
628 static u_char xa_head_buf[CD_XA_HEAD];
629 static u_char xa_tail_buf[CD_XA_TAIL];
631 #if OLD_BUSY
632 static volatile u_char busy_data=0;
633 static volatile u_char busy_audio=0; /* true semaphores would be safer */
634 #endif OLD_BUSY
635 static DECLARE_MUTEX(ioctl_read_sem);
636 static u_long timeout;
637 static volatile u_char timed_out_delay=0;
638 static volatile u_char timed_out_data=0;
639 #if 0
640 static volatile u_char timed_out_audio=0;
641 #endif
642 static u_int datarate= 1000000;
643 static u_int maxtim16=16000000;
644 static u_int maxtim04= 4000000;
645 static u_int maxtim02= 2000000;
646 static u_int maxtim_8= 30000;
647 #if LONG_TIMING
648 static u_int maxtim_data= 9000;
649 #else
650 static u_int maxtim_data= 3000;
651 #endif LONG_TIMING
652 #if DISTRIBUTION
653 static int n_retries=6;
654 #else
655 static int n_retries=6;
656 #endif
657 /*==========================================================================*/
659 static int ndrives=0;
660 static u_char drv_pattern[NR_SBPCD]={speed_auto,speed_auto,speed_auto,speed_auto};
661 static int sbpcd_blocksizes[NR_SBPCD] = {0, };
663 /*==========================================================================*/
665 * drive space begins here (needed separate for each unit)
667 static int d=0; /* DriveStruct index: drive number */
669 static struct {
670 char drv_id; /* "jumpered" drive ID or -1 */
671 char drv_sel; /* drive select lines bits */
673 char drive_model[9];
674 u_char firmware_version[4];
675 char f_eject; /* auto-eject flag: 0 or 1 */
676 u_char *sbp_buf; /* Pointer to internal data buffer,
677 space allocated during sbpcd_init() */
678 u_int sbp_bufsiz; /* size of sbp_buf (# of frames) */
679 int sbp_first_frame; /* First frame in buffer */
680 int sbp_last_frame; /* Last frame in buffer */
681 int sbp_read_frames; /* Number of frames being read to buffer */
682 int sbp_current; /* Frame being currently read */
684 u_char mode; /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
685 u_char *aud_buf; /* Pointer to audio data buffer,
686 space allocated during sbpcd_init() */
687 u_int sbp_audsiz; /* size of aud_buf (# of raw frames) */
688 u_int drv_type;
689 u_char drv_options;
690 int status_bits;
691 u_char diskstate_flags;
692 u_char sense_byte;
694 u_char CD_changed;
695 char open_count;
696 u_char error_byte;
698 u_char f_multisession;
699 u_int lba_multi;
700 int first_session;
701 int last_session;
702 int track_of_last_session;
704 u_char audio_state;
705 u_int pos_audio_start;
706 u_int pos_audio_end;
707 char vol_chan0;
708 u_char vol_ctrl0;
709 char vol_chan1;
710 u_char vol_ctrl1;
711 #if 000 /* no supported drive has it */
712 char vol_chan2;
713 u_char vol_ctrl2;
714 char vol_chan3;
715 u_char vol_ctrl3;
716 #endif 000
717 u_char volume_control; /* TEAC on/off bits */
719 u_char SubQ_ctl_adr;
720 u_char SubQ_trk;
721 u_char SubQ_pnt_idx;
722 u_int SubQ_run_tot;
723 u_int SubQ_run_trk;
724 u_char SubQ_whatisthis;
726 u_char UPC_ctl_adr;
727 u_char UPC_buf[7];
729 int frame_size;
730 int CDsize_frm;
732 u_char xa_byte; /* 0x20: XA capabilities */
733 u_char n_first_track; /* binary */
734 u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
735 u_int size_msf; /* time of whole CD, position of LeadOut track */
736 u_int size_blk;
738 u_char TocEnt_nixbyte; /* em */
739 u_char TocEnt_ctl_adr;
740 u_char TocEnt_number;
741 u_char TocEnt_format; /* em */
742 u_int TocEnt_address;
743 #if SAFE_MIXED
744 char has_data;
745 #endif SAFE_MIXED
746 u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
748 struct {
749 u_char nixbyte; /* em */
750 u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
751 u_char number;
752 u_char format; /* em */ /* 0x00: lba, 0x01: msf */
753 u_int address;
754 } TocBuffer[MAX_TRACKS+1]; /* last entry faked */
756 int in_SpinUp; /* CR-52x test flag */
757 int n_bytes; /* TEAC awaited response count */
758 u_char error_state, b3, b4; /* TEAC command error state */
759 u_char f_drv_error; /* TEAC command error flag */
760 u_char speed_byte;
761 int frmsiz;
762 u_char f_XA; /* 1: XA */
763 u_char type_byte; /* 0, 1, 3 */
764 u_char mode_xb_6;
765 u_char mode_yb_7;
766 u_char mode_xb_8;
767 u_char delay;
768 struct cdrom_device_info *sbpcd_infop;
770 } D_S[NR_SBPCD];
773 * drive space ends here (needed separate for each unit)
775 /*==========================================================================*/
776 #if 0
777 unsigned long cli_sti; /* for saving the processor flags */
778 #endif
779 /*==========================================================================*/
780 static struct timer_list delay_timer = { function: mark_timeout_delay};
781 static struct timer_list data_timer = { function: mark_timeout_data};
782 #if 0
783 static struct timer_list audio_timer = { function: mark_timeout_audio};
784 #endif
785 /*==========================================================================*/
787 * DDI interface
789 static void msg(int level, const char *fmt, ...)
791 #if DISTRIBUTION
792 #define MSG_LEVEL KERN_NOTICE
793 #else
794 #define MSG_LEVEL KERN_INFO
795 #endif DISTRIBUTION
797 char buf[256];
798 va_list args;
800 if (!(sbpcd_debug&(1<<level))) return;
802 msgnum++;
803 if (msgnum>99) msgnum=0;
804 sprintf(buf, MSG_LEVEL "%s-%d [%02d]: ", major_name, d, msgnum);
805 va_start(args, fmt);
806 vsprintf(&buf[18], fmt, args);
807 va_end(args);
808 printk(buf);
809 #if KLOGD_PAUSE
810 sbp_sleep(KLOGD_PAUSE); /* else messages get lost */
811 #endif KLOGD_PAUSE
812 return;
814 /*==========================================================================*/
816 * DDI interface: runtime trace bit pattern maintenance
818 static int sbpcd_dbg_ioctl(unsigned long arg, int level)
820 switch(arg)
822 case 0: /* OFF */
823 sbpcd_debug = DBG_INF;
824 break;
826 default:
827 if (arg>=128) sbpcd_debug &= ~(1<<(arg-128));
828 else sbpcd_debug |= (1<<arg);
830 return (arg);
832 /*==========================================================================*/
833 static void mark_timeout_delay(u_long i)
835 timed_out_delay=1;
836 #if 0
837 msg(DBG_TIM,"delay timer expired.\n");
838 #endif
840 /*==========================================================================*/
841 static void mark_timeout_data(u_long i)
843 timed_out_data=1;
844 #if 0
845 msg(DBG_TIM,"data timer expired.\n");
846 #endif
848 /*==========================================================================*/
849 #if 0
850 static void mark_timeout_audio(u_long i)
852 timed_out_audio=1;
853 #if 0
854 msg(DBG_TIM,"audio timer expired.\n");
855 #endif
857 #endif
858 /*==========================================================================*/
860 * Wait a little while (used for polling the drive).
862 static void sbp_sleep(u_int time)
864 sti();
865 current->state = TASK_INTERRUPTIBLE;
866 schedule_timeout(time);
867 sti();
869 /*==========================================================================*/
870 #define RETURN_UP(rc) {up(&ioctl_read_sem); return(rc);}
871 /*==========================================================================*/
873 * convert logical_block_address to m-s-f_number (3 bytes only)
875 static INLINE void lba2msf(int lba, u_char *msf)
877 lba += CD_MSF_OFFSET;
878 msf[0] = lba / (CD_SECS*CD_FRAMES);
879 lba %= CD_SECS*CD_FRAMES;
880 msf[1] = lba / CD_FRAMES;
881 msf[2] = lba % CD_FRAMES;
883 /*==========================================================================*/
884 /*==========================================================================*/
886 * convert msf-bin to msf-bcd
888 static INLINE void bin2bcdx(u_char *p) /* must work only up to 75 or 99 */
890 *p=((*p/10)<<4)|(*p%10);
892 /*==========================================================================*/
893 static INLINE u_int blk2msf(u_int blk)
895 MSF msf;
896 u_int mm;
898 msf.c[3] = 0;
899 msf.c[2] = (blk + CD_MSF_OFFSET) / (CD_SECS * CD_FRAMES);
900 mm = (blk + CD_MSF_OFFSET) % (CD_SECS * CD_FRAMES);
901 msf.c[1] = mm / CD_FRAMES;
902 msf.c[0] = mm % CD_FRAMES;
903 return (msf.n);
905 /*==========================================================================*/
906 static INLINE u_int make16(u_char rh, u_char rl)
908 return ((rh<<8)|rl);
910 /*==========================================================================*/
911 static INLINE u_int make32(u_int rh, u_int rl)
913 return ((rh<<16)|rl);
915 /*==========================================================================*/
916 static INLINE u_char swap_nibbles(u_char i)
918 return ((i<<4)|(i>>4));
920 /*==========================================================================*/
921 static INLINE u_char byt2bcd(u_char i)
923 return (((i/10)<<4)+i%10);
925 /*==========================================================================*/
926 static INLINE u_char bcd2bin(u_char bcd)
928 return ((bcd>>4)*10+(bcd&0x0F));
930 /*==========================================================================*/
931 static INLINE int msf2blk(int msfx)
933 MSF msf;
934 int i;
936 msf.n=msfx;
937 i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_MSF_OFFSET;
938 if (i<0) return (0);
939 return (i);
941 /*==========================================================================*/
943 * convert m-s-f_number (3 bytes only) to logical_block_address
945 static INLINE int msf2lba(u_char *msf)
947 int i;
949 i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_MSF_OFFSET;
950 if (i<0) return (0);
951 return (i);
953 /*==========================================================================*/
954 /* evaluate cc_ReadError code */
955 static int sta2err(int sta)
957 if (famT_drive)
959 if (sta==0x00) return (0);
960 if (sta==0x01) return (-604); /* CRC error */
961 if (sta==0x02) return (-602); /* drive not ready */
962 if (sta==0x03) return (-607); /* unknown media */
963 if (sta==0x04) return (-612); /* general failure */
964 if (sta==0x05) return (0);
965 if (sta==0x06) return (-ERR_DISKCHANGE); /* disk change */
966 if (sta==0x0b) return (-612); /* general failure */
967 if (sta==0xff) return (-612); /* general failure */
968 return (0);
970 else
972 if (sta<=2) return (sta);
973 if (sta==0x05) return (-604); /* CRC error */
974 if (sta==0x06) return (-606); /* seek error */
975 if (sta==0x0d) return (-606); /* seek error */
976 if (sta==0x0e) return (-603); /* unknown command */
977 if (sta==0x14) return (-603); /* unknown command */
978 if (sta==0x0c) return (-611); /* read fault */
979 if (sta==0x0f) return (-611); /* read fault */
980 if (sta==0x10) return (-611); /* read fault */
981 if (sta>=0x16) return (-612); /* general failure */
982 if (sta==0x11) return (-ERR_DISKCHANGE); /* disk change (LCS: removed) */
983 if (famL_drive)
984 if (sta==0x12) return (-ERR_DISKCHANGE); /* disk change (inserted) */
985 return (-602); /* drive not ready */
988 /*==========================================================================*/
989 static INLINE void clr_cmdbuf(void)
991 int i;
993 for (i=0;i<10;i++) drvcmd[i]=0;
994 cmd_type=0;
996 /*==========================================================================*/
997 static void flush_status(void)
999 int i;
1001 sbp_sleep(15*HZ/10);
1002 for (i=maxtim_data;i!=0;i--) inb(CDi_status);
1004 /*====================================================================*/
1006 * CDi status loop for Teac CD-55A (Rob Riggs)
1008 * This is needed because for some strange reason
1009 * the CD-55A can take a real long time to give a
1010 * status response. This seems to happen after we
1011 * issue a READ command where a long seek is involved.
1013 * I tried to ensure that we get max throughput with
1014 * minimal busy waiting. We busy wait at first, then
1015 * "switch gears" and start sleeping. We sleep for
1016 * longer periods of time the longer we wait.
1019 static int CDi_stat_loop_T(void)
1021 int i, gear=1;
1022 u_long timeout_1, timeout_2, timeout_3, timeout_4;
1024 timeout_1 = jiffies + HZ / 50; /* sbp_sleep(0) for a short period */
1025 timeout_2 = jiffies + HZ / 5; /* nap for no more than 200ms */
1026 timeout_3 = jiffies + 5 * HZ; /* sleep for up to 5s */
1027 timeout_4 = jiffies + 45 * HZ; /* long sleep for up to 45s. */
1030 i = inb(CDi_status);
1031 if (!(i&s_not_data_ready)) return (i);
1032 if (!(i&s_not_result_ready)) return (i);
1033 switch(gear)
1035 case 4:
1036 sbp_sleep(HZ);
1037 if (time_after(jiffies, timeout_4)) gear++;
1038 msg(DBG_TEA, "CDi_stat_loop_T: long sleep active.\n");
1039 break;
1040 case 3:
1041 sbp_sleep(HZ/10);
1042 if (time_after(jiffies, timeout_3)) gear++;
1043 break;
1044 case 2:
1045 sbp_sleep(HZ/100);
1046 if (time_after(jiffies, timeout_2)) gear++;
1047 break;
1048 case 1:
1049 sbp_sleep(0);
1050 if (time_after(jiffies, timeout_1)) gear++;
1052 } while (gear < 5);
1053 return -1;
1055 /*==========================================================================*/
1056 static int CDi_stat_loop(void)
1058 int i,j;
1060 for(timeout = jiffies + 10*HZ, i=maxtim_data; time_before(jiffies, timeout); )
1062 for ( ;i!=0;i--)
1064 j=inb(CDi_status);
1065 if (!(j&s_not_data_ready)) return (j);
1066 if (!(j&s_not_result_ready)) return (j);
1067 if (fam0L_drive) if (j&s_attention) return (j);
1069 sbp_sleep(1);
1070 i = 1;
1072 msg(DBG_LCS,"CDi_stat_loop failed in line %d\n", __LINE__);
1073 return (-1);
1075 /*==========================================================================*/
1076 #if 00000
1077 /*==========================================================================*/
1078 static int tst_DataReady(void)
1080 int i;
1082 i=inb(CDi_status);
1083 if (i&s_not_data_ready) return (0);
1084 return (1);
1086 /*==========================================================================*/
1087 static int tst_ResultReady(void)
1089 int i;
1091 i=inb(CDi_status);
1092 if (i&s_not_result_ready) return (0);
1093 return (1);
1095 /*==========================================================================*/
1096 static int tst_Attention(void)
1098 int i;
1100 i=inb(CDi_status);
1101 if (i&s_attention) return (1);
1102 return (0);
1104 /*==========================================================================*/
1105 #endif 00000
1106 /*==========================================================================*/
1107 static int ResponseInfo(void)
1109 int i,j,st=0;
1110 u_long timeout;
1112 for (i=0,timeout=jiffies+HZ;i<response_count;i++)
1114 for (j=maxtim_data; ; )
1116 for ( ;j!=0;j-- )
1118 st=inb(CDi_status);
1119 if (!(st&s_not_result_ready)) break;
1121 if ((j!=0)||time_after_eq(jiffies, timeout)) break;
1122 sbp_sleep(1);
1123 j = 1;
1125 if (time_after_eq(jiffies, timeout)) break;
1126 infobuf[i]=inb(CDi_info);
1128 #if 000
1129 while (!(inb(CDi_status)&s_not_result_ready))
1131 infobuf[i++]=inb(CDi_info);
1133 j=i-response_count;
1134 if (j>0) msg(DBG_INF,"ResponseInfo: got %d trailing bytes.\n",j);
1135 #endif 000
1136 for (j=0;j<i;j++)
1137 sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1138 msgbuf[j*3]=0;
1139 msg(DBG_CMD,"ResponseInfo:%s (%d,%d)\n",msgbuf,response_count,i);
1140 j=response_count-i;
1141 if (j>0) return (-j);
1142 else return (i);
1144 /*==========================================================================*/
1145 static void EvaluateStatus(int st)
1147 D_S[d].status_bits=0;
1148 if (fam1_drive) D_S[d].status_bits=st|p_success;
1149 else if (fam0_drive)
1151 if (st&p_caddin_old) D_S[d].status_bits |= p_door_closed|p_caddy_in;
1152 if (st&p_spinning) D_S[d].status_bits |= p_spinning;
1153 if (st&p_check) D_S[d].status_bits |= p_check;
1154 if (st&p_success_old) D_S[d].status_bits |= p_success;
1155 if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
1156 if (st&p_disk_ok) D_S[d].status_bits |= p_disk_ok;
1158 else if (famLV_drive)
1160 D_S[d].status_bits |= p_success;
1161 if (st&p_caddin_old) D_S[d].status_bits |= p_disk_ok|p_caddy_in;
1162 if (st&p_spinning) D_S[d].status_bits |= p_spinning;
1163 if (st&p_check) D_S[d].status_bits |= p_check;
1164 if (st&p_busy_old) D_S[d].status_bits |= p_busy_new;
1165 if (st&p_lcs_door_closed) D_S[d].status_bits |= p_door_closed;
1166 if (st&p_lcs_door_locked) D_S[d].status_bits |= p_door_locked;
1168 else if (fam2_drive)
1170 D_S[d].status_bits |= p_success;
1171 if (st&p2_check) D_S[d].status_bits |= p1_check;
1172 if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
1173 if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
1174 if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
1175 if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
1176 if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
1177 if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
1178 if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
1180 else if (famT_drive)
1182 return; /* still needs to get coded */
1183 D_S[d].status_bits |= p_success;
1184 if (st&p2_check) D_S[d].status_bits |= p1_check;
1185 if (st&p2_door_closed) D_S[d].status_bits |= p1_door_closed;
1186 if (st&p2_disk_in) D_S[d].status_bits |= p1_disk_in;
1187 if (st&p2_busy1) D_S[d].status_bits |= p1_busy;
1188 if (st&p2_busy2) D_S[d].status_bits |= p1_busy;
1189 if (st&p2_spinning) D_S[d].status_bits |= p1_spinning;
1190 if (st&p2_door_locked) D_S[d].status_bits |= p1_door_locked;
1191 if (st&p2_disk_ok) D_S[d].status_bits |= p1_disk_ok;
1193 return;
1195 /*==========================================================================*/
1196 static int get_state_T(void)
1198 int i;
1200 static int cmd_out_T(void);
1202 clr_cmdbuf();
1203 D_S[d].n_bytes=1;
1204 drvcmd[0]=CMDT_STATUS;
1205 i=cmd_out_T();
1206 if (i>=0) i=infobuf[0];
1207 else
1209 msg(DBG_TEA,"get_state_T error %d\n", i);
1210 return (i);
1212 if (i>=0)
1213 /* 2: closed, disk in */
1214 D_S[d].status_bits=p1_door_closed|p1_disk_in|p1_spinning|p1_disk_ok;
1215 else if (D_S[d].error_state==6)
1217 /* 3: closed, disk in, changed ("06 xx xx") */
1218 D_S[d].status_bits=p1_door_closed|p1_disk_in;
1219 D_S[d].CD_changed=0xFF;
1220 D_S[d].diskstate_flags &= ~toc_bit;
1222 else if ((D_S[d].error_state!=2)||(D_S[d].b3!=0x3A)||(D_S[d].b4==0x00))
1224 /* 1: closed, no disk ("xx yy zz"or "02 3A 00") */
1225 D_S[d].status_bits=p1_door_closed;
1226 D_S[d].open_count=0;
1228 else if (D_S[d].b4==0x01)
1230 /* 0: open ("02 3A 01") */
1231 D_S[d].status_bits=0;
1232 D_S[d].open_count=0;
1234 else
1236 /* 1: closed, no disk ("02 3A xx") */
1237 D_S[d].status_bits=p1_door_closed;
1238 D_S[d].open_count=0;
1240 return (D_S[d].status_bits);
1242 /*==========================================================================*/
1243 static int ResponseStatus(void)
1245 int i,j;
1246 u_long timeout;
1248 msg(DBG_STA,"doing ResponseStatus...\n");
1249 if (famT_drive) return (get_state_T());
1250 if (flags_cmd_out & f_respo3) timeout = jiffies;
1251 else if (flags_cmd_out & f_respo2) timeout = jiffies + 16*HZ;
1252 else timeout = jiffies + 4*HZ;
1253 j=maxtim_8;
1256 for ( ;j!=0;j--)
1258 i=inb(CDi_status);
1259 if (!(i&s_not_result_ready)) break;
1261 if ((j!=0)||time_after(jiffies, timeout)) break;
1262 sbp_sleep(1);
1263 j = 1;
1265 while (1);
1266 if (j==0)
1268 if ((flags_cmd_out & f_respo3) == 0)
1269 msg(DBG_STA,"ResponseStatus: timeout.\n");
1270 D_S[d].status_bits=0;
1271 return (-401);
1273 i=inb(CDi_info);
1274 msg(DBG_STA,"ResponseStatus: response %02X.\n", i);
1275 EvaluateStatus(i);
1276 msg(DBG_STA,"status_bits=%02X, i=%02X\n",D_S[d].status_bits,i);
1277 return (D_S[d].status_bits);
1279 /*==========================================================================*/
1280 static void cc_ReadStatus(void)
1282 int i;
1284 msg(DBG_STA,"giving cc_ReadStatus command\n");
1285 if (famT_drive) return;
1286 SBPCD_CLI;
1287 if (fam0LV_drive) OUT(CDo_command,CMD0_STATUS);
1288 else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
1289 else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
1290 if (!fam0LV_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
1291 SBPCD_STI;
1293 /*==========================================================================*/
1294 static int cc_ReadError(void)
1296 int i;
1298 clr_cmdbuf();
1299 msg(DBG_ERR,"giving cc_ReadError command.\n");
1300 if (fam1_drive)
1302 drvcmd[0]=CMD1_READ_ERR;
1303 response_count=8;
1304 flags_cmd_out=f_putcmd|f_ResponseStatus;
1306 else if (fam0LV_drive)
1308 drvcmd[0]=CMD0_READ_ERR;
1309 response_count=6;
1310 if (famLV_drive)
1311 flags_cmd_out=f_putcmd;
1312 else
1313 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
1315 else if (fam2_drive)
1317 drvcmd[0]=CMD2_READ_ERR;
1318 response_count=6;
1319 flags_cmd_out=f_putcmd;
1321 else if (famT_drive)
1323 response_count=5;
1324 drvcmd[0]=CMDT_READ_ERR;
1326 i=cmd_out();
1327 D_S[d].error_byte=0;
1328 msg(DBG_ERR,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i,i);
1329 if (i<0) return (i);
1330 if (fam0V_drive) i=1;
1331 else i=2;
1332 D_S[d].error_byte=infobuf[i];
1333 msg(DBG_ERR,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i,D_S[d].error_byte,D_S[d].error_byte);
1334 i=sta2err(infobuf[i]);
1335 if (i==-ERR_DISKCHANGE)
1337 D_S[d].CD_changed=0xFF;
1338 D_S[d].diskstate_flags &= ~toc_bit;
1340 return (i);
1342 /*==========================================================================*/
1343 static int cmd_out_T(void)
1345 #undef CMDT_TRIES
1346 #define CMDT_TRIES 1000
1347 #define TEST_FALSE_FF 1
1349 static int cc_DriveReset(void);
1350 int i, j, l=0, m, ntries;
1351 long flags;
1353 D_S[d].error_state=0;
1354 D_S[d].b3=0;
1355 D_S[d].b4=0;
1356 D_S[d].f_drv_error=0;
1357 for (i=0;i<10;i++) sprintf(&msgbuf[i*3]," %02X",drvcmd[i]);
1358 msgbuf[i*3]=0;
1359 msg(DBG_CMD,"cmd_out_T:%s\n",msgbuf);
1361 OUT(CDo_sel_i_d,0);
1362 OUT(CDo_enable,D_S[d].drv_sel);
1363 i=inb(CDi_status);
1364 do_16bit=0;
1365 if ((f_16bit)&&(!(i&0x80)))
1367 do_16bit=1;
1368 msg(DBG_TEA,"cmd_out_T: do_16bit set.\n");
1370 if (!(i&s_not_result_ready))
1373 j=inb(CDi_info);
1374 i=inb(CDi_status);
1375 sbp_sleep(0);
1376 msg(DBG_TEA,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j);
1378 while (!(i&s_not_result_ready));
1379 save_flags(flags); cli();
1380 for (i=0;i<10;i++) OUT(CDo_command,drvcmd[i]);
1381 restore_flags(flags);
1382 for (ntries=CMDT_TRIES;ntries>0;ntries--)
1384 if (drvcmd[0]==CMDT_READ_VER) sbp_sleep(HZ); /* fixme */
1385 #if 01
1386 OUT(CDo_sel_i_d,1);
1387 #endif 01
1388 if (teac==2)
1390 if ((i=CDi_stat_loop_T()) == -1) break;
1392 else
1394 #if 0
1395 OUT(CDo_sel_i_d,1);
1396 #endif 0
1397 i=inb(CDi_status);
1399 if (!(i&s_not_data_ready)) /* f.e. CMDT_DISKINFO */
1401 OUT(CDo_sel_i_d,1);
1402 if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
1403 if (drvcmd[0]==CMDT_DISKINFO)
1405 l=0;
1408 if (do_16bit)
1410 i=inw(CDi_data);
1411 infobuf[l++]=i&0x0ff;
1412 infobuf[l++]=i>>8;
1413 #if TEST_FALSE_FF
1414 if ((l==2)&&(infobuf[0]==0x0ff))
1416 infobuf[0]=infobuf[1];
1417 l=1;
1418 msg(DBG_TEA,"cmd_out_T: do_16bit: false first byte!\n");
1420 #endif TEST_FALSE_FF
1422 else infobuf[l++]=inb(CDi_data);
1423 i=inb(CDi_status);
1425 while (!(i&s_not_data_ready));
1426 for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1427 msgbuf[j*3]=0;
1428 msg(DBG_CMD,"cmd_out_T data response:%s\n", msgbuf);
1430 else
1432 msg(DBG_TEA,"cmd_out_T: data response with cmd_%02X!\n",
1433 drvcmd[0]);
1434 j=0;
1437 if (do_16bit) i=inw(CDi_data);
1438 else i=inb(CDi_data);
1439 j++;
1440 i=inb(CDi_status);
1442 while (!(i&s_not_data_ready));
1443 msg(DBG_TEA,"cmd_out_T: data response: discarded %d bytes/words.\n", j);
1444 fatal_err++;
1447 i=inb(CDi_status);
1448 if (!(i&s_not_result_ready))
1450 OUT(CDo_sel_i_d,0);
1451 if (drvcmd[0]==CMDT_DISKINFO) m=l;
1452 else m=0;
1455 infobuf[m++]=inb(CDi_info);
1456 i=inb(CDi_status);
1458 while (!(i&s_not_result_ready));
1459 for (j=0;j<m;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
1460 msgbuf[j*3]=0;
1461 msg(DBG_CMD,"cmd_out_T info response:%s\n", msgbuf);
1462 if (drvcmd[0]==CMDT_DISKINFO)
1464 infobuf[0]=infobuf[l];
1465 if (infobuf[0]!=0x02) return (l); /* data length */
1467 else if (infobuf[0]!=0x02) return (m); /* info length */
1470 ++recursion;
1471 if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd[0], recursion);
1472 clr_cmdbuf();
1473 drvcmd[0]=CMDT_READ_ERR;
1474 j=cmd_out_T(); /* !!! recursive here !!! */
1475 --recursion;
1476 sbp_sleep(1);
1478 while (j<0);
1479 D_S[d].error_state=infobuf[2];
1480 D_S[d].b3=infobuf[3];
1481 D_S[d].b4=infobuf[4];
1482 if (D_S[d].f_drv_error)
1484 D_S[d].f_drv_error=0;
1485 cc_DriveReset();
1486 D_S[d].error_state=2;
1488 return (-D_S[d].error_state-400);
1490 if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
1491 if ((teac==0)||(ntries<(CMDT_TRIES-5))) sbp_sleep(HZ/10);
1492 else sbp_sleep(HZ/100);
1493 if (ntries>(CMDT_TRIES-50)) continue;
1494 msg(DBG_TEA,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd[0], ntries-1);
1496 D_S[d].f_drv_error=1;
1497 cc_DriveReset();
1498 D_S[d].error_state=2;
1499 return (-99);
1501 /*==========================================================================*/
1502 static int cmd_out(void)
1504 int i=0;
1506 if (famT_drive) return(cmd_out_T());
1508 if (flags_cmd_out&f_putcmd)
1510 unsigned long flags;
1511 for (i=0;i<7;i++)
1512 sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
1513 msgbuf[i*3]=0;
1514 msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
1515 save_flags(flags); cli();
1516 for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
1517 restore_flags(flags);
1519 if (response_count!=0)
1521 if (cmd_type!=0)
1523 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
1524 msg(DBG_INF,"misleaded to try ResponseData.\n");
1525 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
1526 return (-22);
1528 else i=ResponseInfo();
1529 if (i<0) return (i);
1531 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
1532 if (flags_cmd_out&f_lopsta)
1534 i=CDi_stat_loop();
1535 if ((i<0)||!(i&s_attention)) return (-8);
1537 if (!(flags_cmd_out&f_getsta)) goto LOC_229;
1539 LOC_228:
1540 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
1541 cc_ReadStatus();
1543 LOC_229:
1544 if (flags_cmd_out&f_ResponseStatus)
1546 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
1547 i=ResponseStatus();
1548 /* builds status_bits, returns orig. status or p_busy_new */
1549 if (i<0) return (i);
1550 if (flags_cmd_out&(f_bit1|f_wait_if_busy))
1552 if (!st_check)
1554 if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
1555 if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
1559 LOC_232:
1560 if (!(flags_cmd_out&f_obey_p_check)) return (0);
1561 if (!st_check) return (0);
1562 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
1563 i=cc_ReadError();
1564 if (D_S[d].in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
1565 msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
1566 return (i);
1568 /*==========================================================================*/
1569 static int cc_Seek(u_int pos, char f_blk_msf)
1571 int i;
1573 clr_cmdbuf();
1574 if (f_blk_msf>1) return (-3);
1575 if (fam0V_drive)
1577 drvcmd[0]=CMD0_SEEK;
1578 if (f_blk_msf==1) pos=msf2blk(pos);
1579 drvcmd[2]=(pos>>16)&0x00FF;
1580 drvcmd[3]=(pos>>8)&0x00FF;
1581 drvcmd[4]=pos&0x00FF;
1582 if (fam0_drive)
1583 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
1584 f_ResponseStatus | f_obey_p_check | f_bit1;
1585 else
1586 flags_cmd_out = f_putcmd;
1588 else if (fam1L_drive)
1590 drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
1591 if (f_blk_msf==0) pos=blk2msf(pos);
1592 drvcmd[1]=(pos>>16)&0x00FF;
1593 drvcmd[2]=(pos>>8)&0x00FF;
1594 drvcmd[3]=pos&0x00FF;
1595 if (famL_drive)
1596 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1597 else
1598 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1600 else if (fam2_drive)
1602 drvcmd[0]=CMD2_SEEK;
1603 if (f_blk_msf==0) pos=blk2msf(pos);
1604 drvcmd[2]=(pos>>24)&0x00FF;
1605 drvcmd[3]=(pos>>16)&0x00FF;
1606 drvcmd[4]=(pos>>8)&0x00FF;
1607 drvcmd[5]=pos&0x00FF;
1608 flags_cmd_out=f_putcmd|f_ResponseStatus;
1610 else if (famT_drive)
1612 drvcmd[0]=CMDT_SEEK;
1613 if (f_blk_msf==1) pos=msf2blk(pos);
1614 drvcmd[2]=(pos>>24)&0x00FF;
1615 drvcmd[3]=(pos>>16)&0x00FF;
1616 drvcmd[4]=(pos>>8)&0x00FF;
1617 drvcmd[5]=pos&0x00FF;
1618 D_S[d].n_bytes=1;
1620 response_count=0;
1621 i=cmd_out();
1622 return (i);
1624 /*==========================================================================*/
1625 static int cc_SpinUp(void)
1627 int i;
1629 msg(DBG_SPI,"SpinUp.\n");
1630 D_S[d].in_SpinUp = 1;
1631 clr_cmdbuf();
1632 if (fam0LV_drive)
1634 drvcmd[0]=CMD0_SPINUP;
1635 if (fam0L_drive)
1636 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
1637 f_ResponseStatus|f_obey_p_check|f_bit1;
1638 else
1639 flags_cmd_out=f_putcmd;
1641 else if (fam1_drive)
1643 drvcmd[0]=CMD1_SPINUP;
1644 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1646 else if (fam2_drive)
1648 drvcmd[0]=CMD2_TRAY_CTL;
1649 drvcmd[4]=0x01; /* "spinup" */
1650 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1652 else if (famT_drive)
1654 drvcmd[0]=CMDT_TRAY_CTL;
1655 drvcmd[4]=0x03; /* "insert", it hopefully spins the drive up */
1657 response_count=0;
1658 i=cmd_out();
1659 D_S[d].in_SpinUp = 0;
1660 return (i);
1662 /*==========================================================================*/
1663 static int cc_SpinDown(void)
1665 int i;
1667 if (fam0_drive) return (0);
1668 clr_cmdbuf();
1669 response_count=0;
1670 if (fam1_drive)
1672 drvcmd[0]=CMD1_SPINDOWN;
1673 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
1675 else if (fam2_drive)
1677 drvcmd[0]=CMD2_TRAY_CTL;
1678 drvcmd[4]=0x02; /* "eject" */
1679 flags_cmd_out=f_putcmd|f_ResponseStatus;
1681 else if (famL_drive)
1683 drvcmd[0]=CMDL_SPINDOWN;
1684 drvcmd[1]=1;
1685 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1687 else if (famV_drive)
1689 drvcmd[0]=CMDV_SPINDOWN;
1690 flags_cmd_out=f_putcmd;
1692 else if (famT_drive)
1694 drvcmd[0]=CMDT_TRAY_CTL;
1695 drvcmd[4]=0x02; /* "eject" */
1697 i=cmd_out();
1698 return (i);
1700 /*==========================================================================*/
1701 static int cc_get_mode_T(void)
1703 int i;
1705 clr_cmdbuf();
1706 response_count=10;
1707 drvcmd[0]=CMDT_GETMODE;
1708 drvcmd[4]=response_count;
1709 i=cmd_out_T();
1710 return (i);
1712 /*==========================================================================*/
1713 static int cc_set_mode_T(void)
1715 int i;
1717 clr_cmdbuf();
1718 response_count=1;
1719 drvcmd[0]=CMDT_SETMODE;
1720 drvcmd[1]=D_S[d].speed_byte;
1721 drvcmd[2]=D_S[d].frmsiz>>8;
1722 drvcmd[3]=D_S[d].frmsiz&0x0FF;
1723 drvcmd[4]=D_S[d].f_XA; /* 1: XA */
1724 drvcmd[5]=D_S[d].type_byte; /* 0, 1, 3 */
1725 drvcmd[6]=D_S[d].mode_xb_6;
1726 drvcmd[7]=D_S[d].mode_yb_7|D_S[d].volume_control;
1727 drvcmd[8]=D_S[d].mode_xb_8;
1728 drvcmd[9]=D_S[d].delay;
1729 i=cmd_out_T();
1730 return (i);
1732 /*==========================================================================*/
1733 static int cc_prep_mode_T(void)
1735 int i, j;
1737 i=cc_get_mode_T();
1738 if (i<0) return (i);
1739 for (i=0;i<10;i++)
1740 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1741 msgbuf[i*3]=0;
1742 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1743 D_S[d].speed_byte=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
1744 D_S[d].frmsiz=make16(infobuf[2],infobuf[3]);
1745 D_S[d].f_XA=infobuf[4];
1746 if (D_S[d].f_XA==0) D_S[d].type_byte=0;
1747 else D_S[d].type_byte=1;
1748 D_S[d].mode_xb_6=infobuf[6];
1749 D_S[d].mode_yb_7=1;
1750 D_S[d].mode_xb_8=infobuf[8];
1751 D_S[d].delay=0; /* 0, 1, 2, 3 */
1752 j=cc_set_mode_T();
1753 i=cc_get_mode_T();
1754 for (i=0;i<10;i++)
1755 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
1756 msgbuf[i*3]=0;
1757 msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
1758 return (j);
1760 /*==========================================================================*/
1761 static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
1763 int i;
1765 if (fam0LV_drive) return (0);
1766 clr_cmdbuf();
1767 response_count=0;
1768 if (fam1_drive)
1770 drvcmd[0]=CMD1_SETMODE;
1771 drvcmd[1]=0x03;
1772 drvcmd[2]=speed;
1773 drvcmd[3]=x1;
1774 drvcmd[4]=x2;
1775 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1777 else if (fam2_drive)
1779 drvcmd[0]=CMD2_SETSPEED;
1780 if (speed&speed_auto)
1782 drvcmd[2]=0xFF;
1783 drvcmd[3]=0xFF;
1785 else
1787 drvcmd[2]=0;
1788 drvcmd[3]=150;
1790 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1792 else if (famT_drive)
1794 return (0);
1796 i=cmd_out();
1797 return (i);
1799 /*==========================================================================*/
1800 static int cc_SetVolume(void)
1802 int i;
1803 u_char channel0,channel1,volume0,volume1;
1804 u_char control0,value0,control1,value1;
1806 D_S[d].diskstate_flags &= ~volume_bit;
1807 clr_cmdbuf();
1808 channel0=D_S[d].vol_chan0;
1809 volume0=D_S[d].vol_ctrl0;
1810 channel1=control1=D_S[d].vol_chan1;
1811 volume1=value1=D_S[d].vol_ctrl1;
1812 control0=value0=0;
1814 if (famV_drive) return (0);
1816 if (((D_S[d].drv_options&audio_mono)!=0)&&(D_S[d].drv_type>=drv_211))
1818 if ((volume0!=0)&&(volume1==0))
1820 volume1=volume0;
1821 channel1=channel0;
1823 else if ((volume0==0)&&(volume1!=0))
1825 volume0=volume1;
1826 channel0=channel1;
1829 if (channel0>1)
1831 channel0=0;
1832 volume0=0;
1834 if (channel1>1)
1836 channel1=1;
1837 volume1=0;
1840 if (fam1_drive)
1842 control0=channel0+1;
1843 control1=channel1+1;
1844 value0=(volume0>volume1)?volume0:volume1;
1845 value1=value0;
1846 if (volume0==0) control0=0;
1847 if (volume1==0) control1=0;
1848 drvcmd[0]=CMD1_SETMODE;
1849 drvcmd[1]=0x05;
1850 drvcmd[3]=control0;
1851 drvcmd[4]=value0;
1852 drvcmd[5]=control1;
1853 drvcmd[6]=value1;
1854 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
1856 else if (fam2_drive)
1858 control0=channel0+1;
1859 control1=channel1+1;
1860 value0=(volume0>volume1)?volume0:volume1;
1861 value1=value0;
1862 if (volume0==0) control0=0;
1863 if (volume1==0) control1=0;
1864 drvcmd[0]=CMD2_SETMODE;
1865 drvcmd[1]=0x0E;
1866 drvcmd[3]=control0;
1867 drvcmd[4]=value0;
1868 drvcmd[5]=control1;
1869 drvcmd[6]=value1;
1870 flags_cmd_out=f_putcmd|f_ResponseStatus;
1872 else if (famL_drive)
1874 if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
1875 if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
1876 if (volume0|volume1) value0=0x80;
1877 drvcmd[0]=CMDL_SETMODE;
1878 drvcmd[1]=0x03;
1879 drvcmd[4]=control0;
1880 drvcmd[5]=value0;
1881 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
1883 else if (fam0_drive) /* different firmware levels */
1885 if (D_S[d].drv_type>=drv_300)
1887 control0=volume0&0xFC;
1888 value0=volume1&0xFC;
1889 if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
1890 if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
1891 if (channel0!=0) control0 |= 0x01;
1892 if (channel1==1) value0 |= 0x01;
1894 else
1896 value0=(volume0>volume1)?volume0:volume1;
1897 if (D_S[d].drv_type<drv_211)
1899 if (channel0!=0)
1901 i=channel1;
1902 channel1=channel0;
1903 channel0=i;
1904 i=volume1;
1905 volume1=volume0;
1906 volume0=i;
1908 if (channel0==channel1)
1910 if (channel0==0)
1912 channel1=1;
1913 volume1=0;
1914 volume0=value0;
1916 else
1918 channel0=0;
1919 volume0=0;
1920 volume1=value0;
1925 if ((volume0!=0)&&(volume1!=0))
1927 if (volume0==0xFF) volume1=0xFF;
1928 else if (volume1==0xFF) volume0=0xFF;
1930 else if (D_S[d].drv_type<drv_201) volume0=volume1=value0;
1932 if (D_S[d].drv_type>=drv_201)
1934 if (volume0==0) control0 |= 0x80;
1935 if (volume1==0) control0 |= 0x40;
1937 if (D_S[d].drv_type>=drv_211)
1939 if (channel0!=0) control0 |= 0x20;
1940 if (channel1!=1) control0 |= 0x10;
1943 drvcmd[0]=CMD0_SETMODE;
1944 drvcmd[1]=0x83;
1945 drvcmd[4]=control0;
1946 drvcmd[5]=value0;
1947 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
1949 else if (famT_drive)
1951 D_S[d].volume_control=0;
1952 if (!volume0) D_S[d].volume_control|=0x10;
1953 if (!volume1) D_S[d].volume_control|=0x20;
1954 i=cc_prep_mode_T();
1955 if (i<0) return (i);
1957 if (!famT_drive)
1959 response_count=0;
1960 i=cmd_out();
1961 if (i<0) return (i);
1963 D_S[d].diskstate_flags |= volume_bit;
1964 return (0);
1966 /*==========================================================================*/
1967 static int GetStatus(void)
1969 int i;
1971 if (famT_drive) return (0);
1972 flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
1973 response_count=0;
1974 cmd_type=0;
1975 i=cmd_out();
1976 return (i);
1978 /*==========================================================================*/
1979 static int cc_DriveReset(void)
1981 int i;
1983 msg(DBG_RES,"cc_DriveReset called.\n");
1984 clr_cmdbuf();
1985 response_count=0;
1986 if (fam0LV_drive) OUT(CDo_reset,0x00);
1987 else if (fam1_drive)
1989 drvcmd[0]=CMD1_RESET;
1990 flags_cmd_out=f_putcmd;
1991 i=cmd_out();
1993 else if (fam2_drive)
1995 drvcmd[0]=CMD2_RESET;
1996 flags_cmd_out=f_putcmd;
1997 i=cmd_out();
1998 OUT(CDo_reset,0x00);
2000 else if (famT_drive)
2002 OUT(CDo_sel_i_d,0);
2003 OUT(CDo_enable,D_S[d].drv_sel);
2004 OUT(CDo_command,CMDT_RESET);
2005 for (i=1;i<10;i++) OUT(CDo_command,0);
2007 if (fam0LV_drive) sbp_sleep(5*HZ); /* wait 5 seconds */
2008 else sbp_sleep(1*HZ); /* wait a second */
2009 #if 1
2010 if (famT_drive)
2012 msg(DBG_TEA, "================CMDT_RESET given=================.\n");
2013 sbp_sleep(3*HZ);
2015 #endif 1
2016 flush_status();
2017 i=GetStatus();
2018 if (i<0) return i;
2019 if (!famT_drive)
2020 if (D_S[d].error_byte!=aud_12) return -501;
2021 return (0);
2024 /*==========================================================================*/
2025 static int SetSpeed(void)
2027 int i, speed;
2029 if (!(D_S[d].drv_options&(speed_auto|speed_300|speed_150))) return (0);
2030 speed=speed_auto;
2031 if (!(D_S[d].drv_options&speed_auto))
2033 speed |= speed_300;
2034 if (!(D_S[d].drv_options&speed_300)) speed=0;
2036 i=cc_SetSpeed(speed,0,0);
2037 return (i);
2040 static void switch_drive(int i);
2042 static int sbpcd_select_speed(struct cdrom_device_info *cdi, int speed)
2044 int i = MINOR(cdi->dev);
2046 if (i != d)
2047 switch_drive(i);
2049 return cc_SetSpeed(speed == 2 ? speed_300 : speed_150, 0, 0);
2052 /*==========================================================================*/
2053 static int DriveReset(void)
2055 int i;
2057 i=cc_DriveReset();
2058 if (i<0) return (-22);
2061 i=GetStatus();
2062 if ((i<0)&&(i!=-ERR_DISKCHANGE)) {
2063 return (-2); /* from sta2err */
2065 if (!st_caddy_in) break;
2066 sbp_sleep(1);
2068 while (!st_diskok);
2069 #if 000
2070 D_S[d].CD_changed=1;
2071 #endif
2072 if ((st_door_closed) && (st_caddy_in))
2074 i=DiskInfo();
2075 if (i<0) return (-23);
2077 return (0);
2080 static int sbpcd_reset(struct cdrom_device_info *cdi)
2082 int i = MINOR(cdi->dev);
2084 if (i != d)
2085 switch_drive(i);
2087 return DriveReset();
2090 /*==========================================================================*/
2091 static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
2093 int i, j, n;
2095 if (D_S[d].audio_state==audio_playing) return (-EINVAL);
2096 clr_cmdbuf();
2097 response_count=0;
2098 if (famLV_drive)
2100 drvcmd[0]=CMDL_PLAY;
2101 i=msf2blk(pos_audio_start);
2102 n=msf2blk(pos_audio_end)+1-i;
2103 drvcmd[1]=(i>>16)&0x00FF;
2104 drvcmd[2]=(i>>8)&0x00FF;
2105 drvcmd[3]=i&0x00FF;
2106 drvcmd[4]=(n>>16)&0x00FF;
2107 drvcmd[5]=(n>>8)&0x00FF;
2108 drvcmd[6]=n&0x00FF;
2109 if (famL_drive)
2110 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
2111 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
2112 else
2113 flags_cmd_out = f_putcmd;
2115 else
2117 j=1;
2118 if (fam1_drive)
2120 drvcmd[0]=CMD1_PLAY_MSF;
2121 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
2122 f_obey_p_check | f_wait_if_busy;
2124 else if (fam2_drive)
2126 drvcmd[0]=CMD2_PLAY_MSF;
2127 flags_cmd_out = f_putcmd | f_ResponseStatus | f_obey_p_check;
2129 else if (famT_drive)
2131 drvcmd[0]=CMDT_PLAY_MSF;
2132 j=3;
2133 response_count=1;
2135 else if (fam0_drive)
2137 drvcmd[0]=CMD0_PLAY_MSF;
2138 flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
2139 f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
2141 drvcmd[j]=(pos_audio_start>>16)&0x00FF;
2142 drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
2143 drvcmd[j+2]=pos_audio_start&0x00FF;
2144 drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
2145 drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
2146 drvcmd[j+5]=pos_audio_end&0x00FF;
2148 i=cmd_out();
2149 return (i);
2151 /*==========================================================================*/
2152 static int cc_Pause_Resume(int pau_res)
2154 int i;
2156 clr_cmdbuf();
2157 response_count=0;
2158 if (fam1_drive)
2160 drvcmd[0]=CMD1_PAU_RES;
2161 if (pau_res!=1) drvcmd[1]=0x80;
2162 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2164 else if (fam2_drive)
2166 drvcmd[0]=CMD2_PAU_RES;
2167 if (pau_res!=1) drvcmd[2]=0x01;
2168 flags_cmd_out=f_putcmd|f_ResponseStatus;
2170 else if (fam0LV_drive)
2172 drvcmd[0]=CMD0_PAU_RES;
2173 if (pau_res!=1) drvcmd[1]=0x80;
2174 if (famL_drive)
2175 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2176 f_obey_p_check|f_bit1;
2177 else if (famV_drive)
2178 flags_cmd_out=f_putcmd;
2179 else
2180 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
2181 f_obey_p_check;
2183 else if (famT_drive)
2185 if (pau_res==3) return (cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end));
2186 else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
2187 else return (-56);
2189 i=cmd_out();
2190 return (i);
2192 /*==========================================================================*/
2193 static int cc_LockDoor(char lock)
2195 int i;
2197 if (fam0_drive) return (0);
2198 msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, d);
2199 msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
2200 clr_cmdbuf();
2201 response_count=0;
2202 if (fam1_drive)
2204 drvcmd[0]=CMD1_LOCK_CTL;
2205 if (lock==1) drvcmd[1]=0x01;
2206 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2208 else if (fam2_drive)
2210 drvcmd[0]=CMD2_LOCK_CTL;
2211 if (lock==1) drvcmd[4]=0x01;
2212 flags_cmd_out=f_putcmd|f_ResponseStatus;
2214 else if (famLV_drive)
2216 drvcmd[0]=CMDL_LOCK_CTL;
2217 if (lock==1) drvcmd[1]=0x01;
2218 if (famL_drive)
2219 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
2220 else
2221 flags_cmd_out=f_putcmd;
2223 else if (famT_drive)
2225 drvcmd[0]=CMDT_LOCK_CTL;
2226 if (lock==1) drvcmd[4]=0x01;
2228 i=cmd_out();
2229 msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
2230 return (i);
2232 /*==========================================================================*/
2233 /*==========================================================================*/
2234 static int UnLockDoor(void)
2236 int i,j;
2238 j=20;
2241 i=cc_LockDoor(0);
2242 --j;
2243 sbp_sleep(1);
2245 while ((i<0)&&(j));
2246 if (i<0)
2248 cc_DriveReset();
2249 return -84;
2251 return (0);
2253 /*==========================================================================*/
2254 static int LockDoor(void)
2256 int i,j;
2258 j=20;
2261 i=cc_LockDoor(1);
2262 --j;
2263 sbp_sleep(1);
2265 while ((i<0)&&(j));
2266 if (j==0)
2268 cc_DriveReset();
2269 j=20;
2272 i=cc_LockDoor(1);
2273 --j;
2274 sbp_sleep(1);
2276 while ((i<0)&&(j));
2278 return (i);
2281 static int sbpcd_lock_door(struct cdrom_device_info *cdi, int lock)
2283 return lock ? LockDoor() : UnLockDoor();
2286 /*==========================================================================*/
2287 static int cc_CloseTray(void)
2289 int i;
2291 if (fam0_drive) return (0);
2292 msg(DBG_LCK,"cc_CloseTray (drive %d)\n", d);
2293 msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
2295 clr_cmdbuf();
2296 response_count=0;
2297 if (fam1_drive)
2299 drvcmd[0]=CMD1_TRAY_CTL;
2300 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
2302 else if (fam2_drive)
2304 drvcmd[0]=CMD2_TRAY_CTL;
2305 drvcmd[1]=0x01;
2306 drvcmd[4]=0x03; /* "insert" */
2307 flags_cmd_out=f_putcmd|f_ResponseStatus;
2309 else if (famLV_drive)
2311 drvcmd[0]=CMDL_TRAY_CTL;
2312 if (famLV_drive)
2313 flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
2314 f_ResponseStatus|f_obey_p_check|f_bit1;
2315 else
2316 flags_cmd_out=f_putcmd;
2318 else if (famT_drive)
2320 drvcmd[0]=CMDT_TRAY_CTL;
2321 drvcmd[4]=0x03; /* "insert" */
2323 i=cmd_out();
2324 msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
2326 i=cc_ReadError();
2327 flags_cmd_out |= f_respo2;
2328 cc_ReadStatus(); /* command: give 1-byte status */
2329 i=ResponseStatus();
2330 if (famT_drive&&(i<0))
2332 cc_DriveReset();
2333 i=ResponseStatus();
2334 #if 0
2335 sbp_sleep(HZ);
2336 #endif 0
2337 i=ResponseStatus();
2339 if (i<0)
2341 msg(DBG_INF,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i);
2343 if (!(famT_drive))
2345 if (!st_spinning)
2347 cc_SpinUp();
2348 if (st_check) i=cc_ReadError();
2349 flags_cmd_out |= f_respo2;
2350 cc_ReadStatus();
2351 i=ResponseStatus();
2352 } else {
2355 i=DiskInfo();
2356 return (i);
2359 static int sbpcd_tray_move(struct cdrom_device_info *cdi, int position)
2361 int i;
2362 int retval=0;
2363 i = MINOR(cdi->dev);
2364 switch_drive(i);
2365 /* DUH! --AJK */
2366 if(D_S[d].CD_changed != 0xFF) {
2367 D_S[d].CD_changed=0xFF;
2368 D_S[d].diskstate_flags &= ~cd_size_bit;
2370 if (position == 1) {
2371 cc_SpinDown();
2372 } else {
2373 retval=cc_CloseTray();
2375 return retval;
2378 /*==========================================================================*/
2379 static int cc_ReadSubQ(void)
2381 int i,j;
2383 D_S[d].diskstate_flags &= ~subq_bit;
2384 for (j=255;j>0;j--)
2386 clr_cmdbuf();
2387 if (fam1_drive)
2389 drvcmd[0]=CMD1_READSUBQ;
2390 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2391 response_count=11;
2393 else if (fam2_drive)
2395 drvcmd[0]=CMD2_READSUBQ;
2396 drvcmd[1]=0x02;
2397 drvcmd[3]=0x01;
2398 flags_cmd_out=f_putcmd;
2399 response_count=10;
2401 else if (fam0LV_drive)
2403 drvcmd[0]=CMD0_READSUBQ;
2404 drvcmd[1]=0x02;
2405 if (famLV_drive)
2406 flags_cmd_out=f_putcmd;
2407 else
2408 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2409 response_count=13;
2411 else if (famT_drive)
2413 response_count=12;
2414 drvcmd[0]=CMDT_READSUBQ;
2415 drvcmd[1]=0x02;
2416 drvcmd[2]=0x40;
2417 drvcmd[3]=0x01;
2418 drvcmd[8]=response_count;
2420 i=cmd_out();
2421 if (i<0) return (i);
2422 for (i=0;i<response_count;i++)
2424 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2425 msgbuf[i*3]=0;
2426 msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
2428 if (famT_drive) break;
2429 if (infobuf[0]!=0) break;
2430 if ((!st_spinning) || (j==1))
2432 D_S[d].SubQ_ctl_adr=D_S[d].SubQ_trk=D_S[d].SubQ_pnt_idx=D_S[d].SubQ_whatisthis=0;
2433 D_S[d].SubQ_run_tot=D_S[d].SubQ_run_trk=0;
2434 return (0);
2437 if (famT_drive) D_S[d].SubQ_ctl_adr=infobuf[1];
2438 else D_S[d].SubQ_ctl_adr=swap_nibbles(infobuf[1]);
2439 D_S[d].SubQ_trk=byt2bcd(infobuf[2]);
2440 D_S[d].SubQ_pnt_idx=byt2bcd(infobuf[3]);
2441 if (fam0LV_drive) i=5;
2442 else if (fam12_drive) i=4;
2443 else if (famT_drive) i=8;
2444 D_S[d].SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
2445 i=7;
2446 if (fam0LV_drive) i=9;
2447 else if (fam12_drive) i=7;
2448 else if (famT_drive) i=4;
2449 D_S[d].SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
2450 D_S[d].SubQ_whatisthis=infobuf[i+3];
2451 D_S[d].diskstate_flags |= subq_bit;
2452 return (0);
2454 /*==========================================================================*/
2455 static int cc_ModeSense(void)
2457 int i;
2459 if (fam2_drive) return (0);
2460 if (famV_drive) return (0);
2461 D_S[d].diskstate_flags &= ~frame_size_bit;
2462 clr_cmdbuf();
2463 if (fam1_drive)
2465 response_count=5;
2466 drvcmd[0]=CMD1_GETMODE;
2467 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2469 else if (fam0L_drive)
2471 response_count=2;
2472 drvcmd[0]=CMD0_GETMODE;
2473 if (famL_drive) flags_cmd_out=f_putcmd;
2474 else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2476 else if (famT_drive)
2478 response_count=10;
2479 drvcmd[0]=CMDT_GETMODE;
2480 drvcmd[4]=response_count;
2482 i=cmd_out();
2483 if (i<0) return (i);
2484 i=0;
2485 D_S[d].sense_byte=0;
2486 if (fam1_drive) D_S[d].sense_byte=infobuf[i++];
2487 else if (famT_drive)
2489 if (infobuf[4]==0x01) D_S[d].xa_byte=0x20;
2490 else D_S[d].xa_byte=0;
2491 i=2;
2493 D_S[d].frame_size=make16(infobuf[i],infobuf[i+1]);
2494 for (i=0;i<response_count;i++)
2495 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2496 msgbuf[i*3]=0;
2497 msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
2499 D_S[d].diskstate_flags |= frame_size_bit;
2500 return (0);
2502 /*==========================================================================*/
2503 /*==========================================================================*/
2504 static int cc_ModeSelect(int framesize)
2506 int i;
2508 if (fam2_drive) return (0);
2509 if (famV_drive) return (0);
2510 D_S[d].diskstate_flags &= ~frame_size_bit;
2511 clr_cmdbuf();
2512 D_S[d].frame_size=framesize;
2513 if (framesize==CD_FRAMESIZE_RAW) D_S[d].sense_byte=0x82;
2514 else D_S[d].sense_byte=0x00;
2516 msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
2517 D_S[d].sense_byte, D_S[d].frame_size);
2519 if (fam1_drive)
2521 drvcmd[0]=CMD1_SETMODE;
2522 drvcmd[1]=0x00;
2523 drvcmd[2]=D_S[d].sense_byte;
2524 drvcmd[3]=(D_S[d].frame_size>>8)&0xFF;
2525 drvcmd[4]=D_S[d].frame_size&0xFF;
2526 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2528 else if (fam0L_drive)
2530 drvcmd[0]=CMD0_SETMODE;
2531 drvcmd[1]=0x00;
2532 drvcmd[2]=(D_S[d].frame_size>>8)&0xFF;
2533 drvcmd[3]=D_S[d].frame_size&0xFF;
2534 drvcmd[4]=0x00;
2535 if(famL_drive)
2536 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
2537 else
2538 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2540 else if (famT_drive)
2542 return (-1);
2544 response_count=0;
2545 i=cmd_out();
2546 if (i<0) return (i);
2547 D_S[d].diskstate_flags |= frame_size_bit;
2548 return (0);
2550 /*==========================================================================*/
2551 static int cc_GetVolume(void)
2553 int i;
2554 u_char switches;
2555 u_char chan0=0;
2556 u_char vol0=0;
2557 u_char chan1=1;
2558 u_char vol1=0;
2560 if (famV_drive) return (0);
2561 D_S[d].diskstate_flags &= ~volume_bit;
2562 clr_cmdbuf();
2563 if (fam1_drive)
2565 drvcmd[0]=CMD1_GETMODE;
2566 drvcmd[1]=0x05;
2567 response_count=5;
2568 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2570 else if (fam2_drive)
2572 drvcmd[0]=CMD2_GETMODE;
2573 drvcmd[1]=0x0E;
2574 response_count=5;
2575 flags_cmd_out=f_putcmd;
2577 else if (fam0L_drive)
2579 drvcmd[0]=CMD0_GETMODE;
2580 drvcmd[1]=0x03;
2581 response_count=2;
2582 if(famL_drive)
2583 flags_cmd_out=f_putcmd;
2584 else
2585 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2587 else if (famT_drive)
2589 i=cc_get_mode_T();
2590 if (i<0) return (i);
2592 if (!famT_drive)
2594 i=cmd_out();
2595 if (i<0) return (i);
2597 if (fam1_drive)
2599 chan0=infobuf[1]&0x0F;
2600 vol0=infobuf[2];
2601 chan1=infobuf[3]&0x0F;
2602 vol1=infobuf[4];
2603 if (chan0==0)
2605 chan0=1;
2606 vol0=0;
2608 if (chan1==0)
2610 chan1=2;
2611 vol1=0;
2613 chan0 >>= 1;
2614 chan1 >>= 1;
2616 else if (fam2_drive)
2618 chan0=infobuf[1];
2619 vol0=infobuf[2];
2620 chan1=infobuf[3];
2621 vol1=infobuf[4];
2623 else if (famL_drive)
2625 chan0=0;
2626 chan1=1;
2627 vol0=vol1=infobuf[1];
2628 switches=infobuf[0];
2629 if ((switches&0x80)!=0) chan0=1;
2630 if ((switches&0x40)!=0) chan1=0;
2632 else if (fam0_drive) /* different firmware levels */
2634 chan0=0;
2635 chan1=1;
2636 vol0=vol1=infobuf[1];
2637 if (D_S[d].drv_type>=drv_201)
2639 if (D_S[d].drv_type<drv_300)
2641 switches=infobuf[0];
2642 if ((switches&0x80)!=0) vol0=0;
2643 if ((switches&0x40)!=0) vol1=0;
2644 if (D_S[d].drv_type>=drv_211)
2646 if ((switches&0x20)!=0) chan0=1;
2647 if ((switches&0x10)!=0) chan1=0;
2650 else
2652 vol0=infobuf[0];
2653 if ((vol0&0x01)!=0) chan0=1;
2654 if ((vol1&0x01)==0) chan1=0;
2655 vol0 &= 0xFC;
2656 vol1 &= 0xFC;
2657 if (vol0!=0) vol0 += 3;
2658 if (vol1!=0) vol1 += 3;
2662 else if (famT_drive)
2664 D_S[d].volume_control=infobuf[7];
2665 chan0=0;
2666 chan1=1;
2667 if (D_S[d].volume_control&0x10) vol0=0;
2668 else vol0=0xff;
2669 if (D_S[d].volume_control&0x20) vol1=0;
2670 else vol1=0xff;
2672 D_S[d].vol_chan0=chan0;
2673 D_S[d].vol_ctrl0=vol0;
2674 D_S[d].vol_chan1=chan1;
2675 D_S[d].vol_ctrl1=vol1;
2676 #if 000
2677 D_S[d].vol_chan2=2;
2678 D_S[d].vol_ctrl2=0xFF;
2679 D_S[d].vol_chan3=3;
2680 D_S[d].vol_ctrl3=0xFF;
2681 #endif 000
2682 D_S[d].diskstate_flags |= volume_bit;
2683 return (0);
2685 /*==========================================================================*/
2686 static int cc_ReadCapacity(void)
2688 int i, j;
2690 if (fam2_drive) return (0); /* some firmware lacks this command */
2691 if (famLV_drive) return (0); /* some firmware lacks this command */
2692 if (famT_drive) return (0); /* done with cc_ReadTocDescr() */
2693 D_S[d].diskstate_flags &= ~cd_size_bit;
2694 for (j=3;j>0;j--)
2696 clr_cmdbuf();
2697 if (fam1_drive)
2699 drvcmd[0]=CMD1_CAPACITY;
2700 response_count=5;
2701 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2703 #if 00
2704 else if (fam2_drive)
2706 drvcmd[0]=CMD2_CAPACITY;
2707 response_count=8;
2708 flags_cmd_out=f_putcmd;
2710 #endif
2711 else if (fam0_drive)
2713 drvcmd[0]=CMD0_CAPACITY;
2714 response_count=5;
2715 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2717 i=cmd_out();
2718 if (i>=0) break;
2719 msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
2720 cc_ReadError();
2722 if (j==0) return (i);
2723 if (fam1_drive) D_S[d].CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_MSF_OFFSET;
2724 else if (fam0_drive) D_S[d].CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
2725 #if 00
2726 else if (fam2_drive) D_S[d].CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
2727 #endif
2728 D_S[d].diskstate_flags |= cd_size_bit;
2729 msg(DBG_000,"cc_ReadCapacity: %d frames.\n", D_S[d].CDsize_frm);
2730 return (0);
2732 /*==========================================================================*/
2733 static int cc_ReadTocDescr(void)
2735 int i;
2737 D_S[d].diskstate_flags &= ~toc_bit;
2738 clr_cmdbuf();
2739 if (fam1_drive)
2741 drvcmd[0]=CMD1_DISKINFO;
2742 response_count=6;
2743 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2745 else if (fam0LV_drive)
2747 drvcmd[0]=CMD0_DISKINFO;
2748 response_count=6;
2749 if(famLV_drive)
2750 flags_cmd_out=f_putcmd;
2751 else
2752 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2754 else if (fam2_drive)
2756 /* possibly longer timeout periods necessary */
2757 D_S[d].f_multisession=0;
2758 drvcmd[0]=CMD2_DISKINFO;
2759 drvcmd[1]=0x02;
2760 drvcmd[2]=0xAB;
2761 drvcmd[3]=0xFF; /* session */
2762 response_count=8;
2763 flags_cmd_out=f_putcmd;
2765 else if (famT_drive)
2767 D_S[d].f_multisession=0;
2768 response_count=12;
2769 drvcmd[0]=CMDT_DISKINFO;
2770 drvcmd[1]=0x02;
2771 drvcmd[6]=CDROM_LEADOUT;
2772 drvcmd[8]=response_count;
2773 drvcmd[9]=0x00;
2775 i=cmd_out();
2776 if (i<0) return (i);
2777 if ((famT_drive)&&(i<response_count)) return (-100-i);
2778 if ((fam1_drive)||(fam2_drive)||(fam0LV_drive))
2779 D_S[d].xa_byte=infobuf[0];
2780 if (fam2_drive)
2782 D_S[d].first_session=infobuf[1];
2783 D_S[d].last_session=infobuf[2];
2784 D_S[d].n_first_track=infobuf[3];
2785 D_S[d].n_last_track=infobuf[4];
2786 if (D_S[d].first_session!=D_S[d].last_session)
2788 D_S[d].f_multisession=1;
2789 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
2791 #if 0
2792 if (D_S[d].first_session!=D_S[d].last_session)
2794 if (D_S[d].last_session<=20)
2795 zwanzig=D_S[d].last_session+1;
2796 else zwanzig=20;
2797 for (count=D_S[d].first_session;count<zwanzig;count++)
2799 drvcmd[0]=CMD2_DISKINFO;
2800 drvcmd[1]=0x02;
2801 drvcmd[2]=0xAB;
2802 drvcmd[3]=count;
2803 response_count=8;
2804 flags_cmd_out=f_putcmd;
2805 i=cmd_out();
2806 if (i<0) return (i);
2807 D_S[d].msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
2809 D_S[d].diskstate_flags |= multisession_bit;
2811 #endif
2812 drvcmd[0]=CMD2_DISKINFO;
2813 drvcmd[1]=0x02;
2814 drvcmd[2]=0xAA;
2815 drvcmd[3]=0xFF;
2816 response_count=5;
2817 flags_cmd_out=f_putcmd;
2818 i=cmd_out();
2819 if (i<0) return (i);
2820 D_S[d].size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
2821 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2822 D_S[d].CDsize_frm=D_S[d].size_blk+1;
2824 else if (famT_drive)
2826 D_S[d].size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
2827 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2828 D_S[d].CDsize_frm=D_S[d].size_blk+1;
2829 D_S[d].n_first_track=infobuf[2];
2830 D_S[d].n_last_track=infobuf[3];
2832 else
2834 D_S[d].n_first_track=infobuf[1];
2835 D_S[d].n_last_track=infobuf[2];
2836 D_S[d].size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
2837 D_S[d].size_blk=msf2blk(D_S[d].size_msf);
2838 if (famLV_drive) D_S[d].CDsize_frm=D_S[d].size_blk+1;
2840 D_S[d].diskstate_flags |= toc_bit;
2841 msg(DBG_TOC,"TocDesc: xa %02X firstt %02X lastt %02X size %08X firstses %02X lastsess %02X\n",
2842 D_S[d].xa_byte,
2843 D_S[d].n_first_track,
2844 D_S[d].n_last_track,
2845 D_S[d].size_msf,
2846 D_S[d].first_session,
2847 D_S[d].last_session);
2848 return (0);
2850 /*==========================================================================*/
2851 static int cc_ReadTocEntry(int num)
2853 int i;
2855 clr_cmdbuf();
2856 if (fam1_drive)
2858 drvcmd[0]=CMD1_READTOC;
2859 drvcmd[2]=num;
2860 response_count=8;
2861 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
2863 else if (fam2_drive)
2865 /* possibly longer timeout periods necessary */
2866 drvcmd[0]=CMD2_DISKINFO;
2867 drvcmd[1]=0x02;
2868 drvcmd[2]=num;
2869 response_count=5;
2870 flags_cmd_out=f_putcmd;
2872 else if (fam0LV_drive)
2874 drvcmd[0]=CMD0_READTOC;
2875 drvcmd[1]=0x02;
2876 drvcmd[2]=num;
2877 response_count=8;
2878 if (famLV_drive)
2879 flags_cmd_out=f_putcmd;
2880 else
2881 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2883 else if (famT_drive)
2885 response_count=12;
2886 drvcmd[0]=CMDT_DISKINFO;
2887 drvcmd[1]=0x02;
2888 drvcmd[6]=num;
2889 drvcmd[8]=response_count;
2890 drvcmd[9]=0x00;
2892 i=cmd_out();
2893 if (i<0) return (i);
2894 if ((famT_drive)&&(i<response_count)) return (-100-i);
2895 if ((fam1_drive)||(fam0LV_drive))
2897 D_S[d].TocEnt_nixbyte=infobuf[0];
2898 i=1;
2900 else if (fam2_drive) i=0;
2901 else if (famT_drive) i=5;
2902 D_S[d].TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
2903 if ((fam1_drive)||(fam0L_drive))
2905 D_S[d].TocEnt_number=infobuf[i++];
2906 D_S[d].TocEnt_format=infobuf[i];
2908 else
2910 D_S[d].TocEnt_number=num;
2911 D_S[d].TocEnt_format=0;
2913 if (fam1_drive) i=4;
2914 else if (fam0LV_drive) i=5;
2915 else if (fam2_drive) i=2;
2916 else if (famT_drive) i=9;
2917 D_S[d].TocEnt_address=make32(make16(0,infobuf[i]),
2918 make16(infobuf[i+1],infobuf[i+2]));
2919 for (i=0;i<response_count;i++)
2920 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
2921 msgbuf[i*3]=0;
2922 msg(DBG_ECS,"TocEntry:%s\n", msgbuf);
2923 msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
2924 D_S[d].TocEnt_nixbyte, D_S[d].TocEnt_ctl_adr,
2925 D_S[d].TocEnt_number, D_S[d].TocEnt_format,
2926 D_S[d].TocEnt_address);
2927 return (0);
2929 /*==========================================================================*/
2930 static int cc_ReadPacket(void)
2932 int i;
2934 clr_cmdbuf();
2935 drvcmd[0]=CMD0_PACKET;
2936 drvcmd[1]=response_count;
2937 if(famL_drive) flags_cmd_out=f_putcmd;
2938 else if (fam01_drive)
2939 flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
2940 else if (fam2_drive) return (-1); /* not implemented yet */
2941 else if (famT_drive)
2943 return (-1);
2945 i=cmd_out();
2946 return (i);
2948 /*==========================================================================*/
2949 static int convert_UPC(u_char *p)
2951 int i;
2953 p++;
2954 if (fam0L_drive) p[13]=0;
2955 for (i=0;i<7;i++)
2957 if (fam1_drive) D_S[d].UPC_buf[i]=swap_nibbles(*p++);
2958 else if (fam0L_drive)
2960 D_S[d].UPC_buf[i]=((*p++)<<4)&0xFF;
2961 D_S[d].UPC_buf[i] |= *p++;
2963 else if (famT_drive)
2965 return (-1);
2967 else /* CD200 */
2969 return (-1);
2972 D_S[d].UPC_buf[6] &= 0xF0;
2973 return (0);
2975 /*==========================================================================*/
2976 static int cc_ReadUPC(void)
2978 int i;
2979 #if TEST_UPC
2980 int block, checksum;
2981 #endif TEST_UPC
2983 if (fam2_drive) return (0); /* not implemented yet */
2984 if (famT_drive) return (0); /* not implemented yet */
2985 if (famV_drive) return (0); /* not implemented yet */
2986 #if 1
2987 if (fam0_drive) return (0); /* but it should work */
2988 #endif 1
2990 D_S[d].diskstate_flags &= ~upc_bit;
2991 #if TEST_UPC
2992 for (block=CD_MSF_OFFSET+1;block<CD_MSF_OFFSET+200;block++)
2994 #endif TEST_UPC
2995 clr_cmdbuf();
2996 if (fam1_drive)
2998 drvcmd[0]=CMD1_READ_UPC;
2999 #if TEST_UPC
3000 drvcmd[1]=(block>>16)&0xFF;
3001 drvcmd[2]=(block>>8)&0xFF;
3002 drvcmd[3]=block&0xFF;
3003 #endif TEST_UPC
3004 response_count=8;
3005 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
3007 else if (fam0L_drive)
3009 drvcmd[0]=CMD0_READ_UPC;
3010 #if TEST_UPC
3011 drvcmd[2]=(block>>16)&0xFF;
3012 drvcmd[3]=(block>>8)&0xFF;
3013 drvcmd[4]=block&0xFF;
3014 #endif TEST_UPC
3015 response_count=0;
3016 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
3018 else if (fam2_drive)
3020 return (-1);
3022 else if (famT_drive)
3024 return (-1);
3026 i=cmd_out();
3027 if (i<0)
3029 msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
3030 return (i);
3032 if (fam0L_drive)
3034 response_count=16;
3035 if (famL_drive) flags_cmd_out=f_putcmd;
3036 i=cc_ReadPacket();
3037 if (i<0)
3039 msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
3040 return (i);
3043 #if TEST_UPC
3044 checksum=0;
3045 #endif TEST_UPC
3046 for (i=0;i<(fam1_drive?8:16);i++)
3048 #if TEST_UPC
3049 checksum |= infobuf[i];
3050 #endif TEST_UPC
3051 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3053 msgbuf[i*3]=0;
3054 msg(DBG_UPC,"UPC info:%s\n", msgbuf);
3055 #if TEST_UPC
3056 if ((checksum&0x7F)!=0) break;
3058 #endif TEST_UPC
3059 D_S[d].UPC_ctl_adr=0;
3060 if (fam1_drive) i=0;
3061 else i=2;
3062 if ((infobuf[i]&0x80)!=0)
3064 convert_UPC(&infobuf[i]);
3065 D_S[d].UPC_ctl_adr = (D_S[d].TocEnt_ctl_adr & 0xF0) | 0x02;
3067 for (i=0;i<7;i++)
3068 sprintf(&msgbuf[i*3], " %02X", D_S[d].UPC_buf[i]);
3069 sprintf(&msgbuf[i*3], " (%02X)", D_S[d].UPC_ctl_adr);
3070 msgbuf[i*3+5]=0;
3071 msg(DBG_UPC,"UPC code:%s\n", msgbuf);
3072 D_S[d].diskstate_flags |= upc_bit;
3073 return (0);
3076 static int sbpcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
3078 int i;
3079 unsigned char *mcnp = mcn->medium_catalog_number;
3080 unsigned char *resp;
3082 D_S[d].diskstate_flags &= ~upc_bit;
3083 clr_cmdbuf();
3084 if (fam1_drive)
3086 drvcmd[0]=CMD1_READ_UPC;
3087 response_count=8;
3088 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
3090 else if (fam0L_drive)
3092 drvcmd[0]=CMD0_READ_UPC;
3093 response_count=0;
3094 flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
3096 else if (fam2_drive)
3098 return (-1);
3100 else if (famT_drive)
3102 return (-1);
3104 i=cmd_out();
3105 if (i<0)
3107 msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
3108 return (i);
3110 if (fam0L_drive)
3112 response_count=16;
3113 if (famL_drive) flags_cmd_out=f_putcmd;
3114 i=cc_ReadPacket();
3115 if (i<0)
3117 msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
3118 return (i);
3121 D_S[d].UPC_ctl_adr=0;
3122 if (fam1_drive) i=0;
3123 else i=2;
3125 resp = infobuf + i;
3126 if (*resp++ == 0x80) {
3127 /* packed bcd to single ASCII digits */
3128 *mcnp++ = (*resp >> 4) + '0';
3129 *mcnp++ = (*resp++ & 0x0f) + '0';
3130 *mcnp++ = (*resp >> 4) + '0';
3131 *mcnp++ = (*resp++ & 0x0f) + '0';
3132 *mcnp++ = (*resp >> 4) + '0';
3133 *mcnp++ = (*resp++ & 0x0f) + '0';
3134 *mcnp++ = (*resp >> 4) + '0';
3135 *mcnp++ = (*resp++ & 0x0f) + '0';
3136 *mcnp++ = (*resp >> 4) + '0';
3137 *mcnp++ = (*resp++ & 0x0f) + '0';
3138 *mcnp++ = (*resp >> 4) + '0';
3139 *mcnp++ = (*resp++ & 0x0f) + '0';
3140 *mcnp++ = (*resp >> 4) + '0';
3142 *mcnp = '\0';
3144 D_S[d].diskstate_flags |= upc_bit;
3145 return (0);
3148 /*==========================================================================*/
3149 static int cc_CheckMultiSession(void)
3151 int i;
3153 if (fam2_drive) return (0);
3154 D_S[d].f_multisession=0;
3155 D_S[d].lba_multi=0;
3156 if (fam0_drive) return (0);
3157 clr_cmdbuf();
3158 if (fam1_drive)
3160 drvcmd[0]=CMD1_MULTISESS;
3161 response_count=6;
3162 flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
3163 i=cmd_out();
3164 if (i<0) return (i);
3165 if ((infobuf[0]&0x80)!=0)
3167 D_S[d].f_multisession=1;
3168 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[1]),
3169 make16(infobuf[2],infobuf[3])));
3172 else if (famLV_drive)
3174 drvcmd[0]=CMDL_MULTISESS;
3175 drvcmd[1]=3;
3176 drvcmd[2]=1;
3177 response_count=8;
3178 flags_cmd_out=f_putcmd;
3179 i=cmd_out();
3180 if (i<0) return (i);
3181 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[5]),
3182 make16(infobuf[6],infobuf[7])));
3184 else if (famT_drive)
3186 response_count=12;
3187 drvcmd[0]=CMDT_DISKINFO;
3188 drvcmd[1]=0x02;
3189 drvcmd[6]=0;
3190 drvcmd[8]=response_count;
3191 drvcmd[9]=0x40;
3192 i=cmd_out();
3193 if (i<0) return (i);
3194 if (i<response_count) return (-100-i);
3195 D_S[d].first_session=infobuf[2];
3196 D_S[d].last_session=infobuf[3];
3197 D_S[d].track_of_last_session=infobuf[6];
3198 if (D_S[d].first_session!=D_S[d].last_session)
3200 D_S[d].f_multisession=1;
3201 D_S[d].lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
3204 for (i=0;i<response_count;i++)
3205 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3206 msgbuf[i*3]=0;
3207 msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, D_S[d].lba_multi);
3208 if (D_S[d].lba_multi>200)
3210 D_S[d].f_multisession=1;
3211 msg(DBG_MUL,"MultiSession base: %06X\n", D_S[d].lba_multi);
3213 return (0);
3215 /*==========================================================================*/
3216 #if FUTURE
3217 static int cc_SubChanInfo(int frame, int count, u_char *buffer)
3218 /* "frame" is a RED BOOK (msf-bin) address */
3220 int i;
3222 if (fam0LV_drive) return (-ENOSYS); /* drive firmware lacks it */
3223 if (famT_drive)
3225 return (-1);
3227 #if 0
3228 if (D_S[d].audio_state!=audio_playing) return (-ENODATA);
3229 #endif
3230 clr_cmdbuf();
3231 drvcmd[0]=CMD1_SUBCHANINF;
3232 drvcmd[1]=(frame>>16)&0xFF;
3233 drvcmd[2]=(frame>>8)&0xFF;
3234 drvcmd[3]=frame&0xFF;
3235 drvcmd[5]=(count>>8)&0xFF;
3236 drvcmd[6]=count&0xFF;
3237 flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
3238 cmd_type=READ_SC;
3239 D_S[d].frame_size=CD_FRAMESIZE_SUB;
3240 i=cmd_out(); /* which buffer to use? */
3241 return (i);
3243 #endif FUTURE
3244 /*==========================================================================*/
3245 static void __init check_datarate(void)
3247 int i=0;
3249 msg(DBG_IOX,"check_datarate entered.\n");
3250 datarate=0;
3251 #if TEST_STI
3252 for (i=0;i<=1000;i++) printk(".");
3253 #endif
3254 /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
3255 #if 1
3256 del_timer(&delay_timer);
3257 #endif
3258 delay_timer.expires=jiffies+11*HZ/10;
3259 timed_out_delay=0;
3260 add_timer(&delay_timer);
3261 #if 0
3262 msg(DBG_TIM,"delay timer started (11*HZ/10).\n");
3263 #endif
3266 i=inb(CDi_status);
3267 datarate++;
3268 #if 1
3269 if (datarate>0x6FFFFFFF) break;
3270 #endif 00000
3272 while (!timed_out_delay);
3273 del_timer(&delay_timer);
3274 #if 0
3275 msg(DBG_TIM,"datarate: %04X\n", datarate);
3276 #endif
3277 if (datarate<65536) datarate=65536;
3278 maxtim16=datarate*16;
3279 maxtim04=datarate*4;
3280 maxtim02=datarate*2;
3281 maxtim_8=datarate/32;
3282 #if LONG_TIMING
3283 maxtim_data=datarate/100;
3284 #else
3285 maxtim_data=datarate/300;
3286 #endif LONG_TIMING
3287 #if 0
3288 msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8, maxtim_data);
3289 #endif
3291 /*==========================================================================*/
3292 #if 0
3293 static int c2_ReadError(int fam)
3295 int i;
3297 clr_cmdbuf();
3298 response_count=9;
3299 clr_respo_buf(9);
3300 if (fam==1)
3302 drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
3303 i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
3305 else if (fam==2)
3307 drvcmd[0]=CMD2_READ_ERR;
3308 i=do_cmd(f_putcmd);
3310 else return (-1);
3311 return (i);
3313 #endif
3314 /*==========================================================================*/
3315 static void __init ask_mail(void)
3317 int i;
3319 msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de\n");
3320 msg(DBG_INF, "(don't mail if you are not using the actual kernel):\n");
3321 msg(DBG_INF, "%s\n", VERSION);
3322 msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
3323 CDo_command, type, D_S[d].drive_model, D_S[d].drv_id);
3324 for (i=0;i<12;i++)
3325 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3326 msgbuf[i*3]=0;
3327 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3328 for (i=0;i<12;i++)
3329 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3330 msgbuf[i*3]=0;
3331 msg(DBG_INF,"infobuf =%s\n", msgbuf);
3333 /*==========================================================================*/
3334 static int __init check_version(void)
3336 int i, j, l;
3337 int teac_possible=0;
3339 msg(DBG_INI,"check_version: id=%d, d=%d.\n", D_S[d].drv_id, d);
3340 D_S[d].drv_type=0;
3342 /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
3343 /* clear any pending error state */
3344 clr_cmdbuf();
3345 drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
3346 response_count=9;
3347 flags_cmd_out=f_putcmd;
3348 i=cmd_out();
3349 if (i<0) msg(DBG_INI,"CMD0_READ_ERR returns %d (ok anyway).\n",i);
3350 /* read drive version */
3351 clr_cmdbuf();
3352 for (i=0;i<12;i++) infobuf[i]=0;
3353 drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
3354 response_count=12; /* fam1: only 11 */
3355 flags_cmd_out=f_putcmd;
3356 i=cmd_out();
3357 if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
3358 if (i==-11) teac_possible++;
3359 j=0;
3360 for (i=0;i<12;i++) j+=infobuf[i];
3361 if (j)
3363 for (i=0;i<12;i++)
3364 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3365 msgbuf[i*3]=0;
3366 msg(DBG_ECS,"infobuf =%s\n", msgbuf);
3367 for (i=0;i<12;i++)
3368 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3369 msgbuf[i*3]=0;
3370 msg(DBG_ECS,"infobuf =%s\n", msgbuf);
3372 for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
3373 if (i==4)
3375 D_S[d].drive_model[0]='C';
3376 D_S[d].drive_model[1]='R';
3377 D_S[d].drive_model[2]='-';
3378 D_S[d].drive_model[3]='5';
3379 D_S[d].drive_model[4]=infobuf[i++];
3380 D_S[d].drive_model[5]=infobuf[i++];
3381 D_S[d].drive_model[6]=0;
3382 D_S[d].drv_type=drv_fam1;
3384 if (!D_S[d].drv_type)
3386 for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
3387 if (i==8)
3389 D_S[d].drive_model[0]='C';
3390 D_S[d].drive_model[1]='R';
3391 D_S[d].drive_model[2]='-';
3392 D_S[d].drive_model[3]='5';
3393 D_S[d].drive_model[4]='2';
3394 D_S[d].drive_model[5]='x';
3395 D_S[d].drive_model[6]=0;
3396 D_S[d].drv_type=drv_fam0;
3399 if (!D_S[d].drv_type)
3401 for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
3402 if (i==8)
3404 for (j=0;j<8;j++)
3405 D_S[d].drive_model[j]=infobuf[j];
3406 D_S[d].drive_model[8]=0;
3407 D_S[d].drv_type=drv_famL;
3410 if (!D_S[d].drv_type)
3412 for (i=0;i<6;i++) if (infobuf[i]!=familyV[i]) break;
3413 if (i==6)
3415 for (j=0;j<6;j++)
3416 D_S[d].drive_model[j]=infobuf[j];
3417 D_S[d].drive_model[6]=0;
3418 D_S[d].drv_type=drv_famV;
3419 i+=2; /* 2 blanks before version */
3422 if (!D_S[d].drv_type)
3424 /* check for CD200 */
3425 clr_cmdbuf();
3426 drvcmd[0]=CMD2_READ_ERR;
3427 response_count=9;
3428 flags_cmd_out=f_putcmd;
3429 i=cmd_out();
3430 if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
3431 if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
3432 /* read drive version */
3433 clr_cmdbuf();
3434 for (i=0;i<12;i++) infobuf[i]=0;
3435 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
3436 #if 0
3437 OUT(CDo_reset,0);
3438 sbp_sleep(6*HZ);
3439 OUT(CDo_enable,D_S[d].drv_sel);
3440 #endif 0
3441 drvcmd[0]=CMD2_READ_VER;
3442 response_count=12;
3443 flags_cmd_out=f_putcmd;
3444 i=cmd_out();
3445 if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
3446 if (i==-7) teac_possible++;
3447 j=0;
3448 for (i=0;i<12;i++) j+=infobuf[i];
3449 if (j)
3451 for (i=0;i<12;i++)
3452 sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
3453 msgbuf[i*3]=0;
3454 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3455 for (i=0;i<12;i++)
3456 sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
3457 msgbuf[i*3]=0;
3458 msg(DBG_IDX,"infobuf =%s\n", msgbuf);
3460 if (i>=0)
3462 for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
3463 if (i==5)
3465 D_S[d].drive_model[0]='C';
3466 D_S[d].drive_model[1]='D';
3467 D_S[d].drive_model[2]='2';
3468 D_S[d].drive_model[3]='0';
3469 D_S[d].drive_model[4]='0';
3470 D_S[d].drive_model[5]=infobuf[i++];
3471 D_S[d].drive_model[6]=infobuf[i++];
3472 D_S[d].drive_model[7]=0;
3473 D_S[d].drv_type=drv_fam2;
3477 if (!D_S[d].drv_type)
3479 /* check for TEAC CD-55A */
3480 msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
3481 for (j=1;j<=((D_S[d].drv_id==0)?3:1);j++)
3483 for (l=1;l<=((D_S[d].drv_id==0)?10:1);l++)
3485 msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
3486 if (sbpro_type==1) OUT(CDo_reset,0);
3487 else
3489 OUT(CDo_enable,D_S[d].drv_sel);
3490 OUT(CDo_sel_i_d,0);
3491 OUT(CDo_command,CMDT_RESET);
3492 for (i=0;i<9;i++) OUT(CDo_command,0);
3494 sbp_sleep(5*HZ/10);
3495 OUT(CDo_enable,D_S[d].drv_sel);
3496 OUT(CDo_sel_i_d,0);
3497 i=inb(CDi_status);
3498 msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
3499 #if 0
3500 if (i&s_not_result_ready) continue; /* drive not present or ready */
3501 #endif
3502 i=inb(CDi_info);
3503 msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
3504 if (i==0x55) break; /* drive found */
3506 if (i==0x55) break; /* drive found */
3508 if (i==0x55) /* drive found */
3510 msg(DBG_TEA,"TEAC drive found.\n");
3511 clr_cmdbuf();
3512 flags_cmd_out=f_putcmd;
3513 response_count=12;
3514 drvcmd[0]=CMDT_READ_VER;
3515 drvcmd[4]=response_count;
3516 for (i=0;i<12;i++) infobuf[i]=0;
3517 i=cmd_out_T();
3518 if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
3519 for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
3520 if (i==6)
3522 D_S[d].drive_model[0]='C';
3523 D_S[d].drive_model[1]='D';
3524 D_S[d].drive_model[2]='-';
3525 D_S[d].drive_model[3]='5';
3526 D_S[d].drive_model[4]='5';
3527 D_S[d].drive_model[5]=0;
3528 D_S[d].drv_type=drv_famT;
3532 if (!D_S[d].drv_type)
3534 msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,D_S[d].drv_id);
3535 return (-522);
3537 for (j=0;j<4;j++) D_S[d].firmware_version[j]=infobuf[i+j];
3538 if (famL_drive)
3540 u_char lcs_firm_e1[]="A E1";
3541 u_char lcs_firm_f4[]="A4F4";
3543 for (j=0;j<4;j++)
3544 if (D_S[d].firmware_version[j]!=lcs_firm_e1[j]) break;
3545 if (j==4) D_S[d].drv_type=drv_e1;
3547 for (j=0;j<4;j++)
3548 if (D_S[d].firmware_version[j]!=lcs_firm_f4[j]) break;
3549 if (j==4) D_S[d].drv_type=drv_f4;
3551 if (D_S[d].drv_type==drv_famL) ask_mail();
3553 else if (famT_drive)
3555 j=infobuf[4]; /* one-byte version??? - here: 0x15 */
3556 if (j=='5')
3558 D_S[d].firmware_version[0]=infobuf[7];
3559 D_S[d].firmware_version[1]=infobuf[8];
3560 D_S[d].firmware_version[2]=infobuf[10];
3561 D_S[d].firmware_version[3]=infobuf[11];
3563 else
3565 if (j!=0x15) ask_mail();
3566 D_S[d].firmware_version[0]='0';
3567 D_S[d].firmware_version[1]='.';
3568 D_S[d].firmware_version[2]='0'+(j>>4);
3569 D_S[d].firmware_version[3]='0'+(j&0x0f);
3572 else /* CR-52x, CR-56x, CD200, ECS-AT */
3574 j = (D_S[d].firmware_version[0] & 0x0F) * 100 +
3575 (D_S[d].firmware_version[2] & 0x0F) *10 +
3576 (D_S[d].firmware_version[3] & 0x0F);
3577 if (fam0_drive)
3579 if (j<200) D_S[d].drv_type=drv_199;
3580 else if (j<201) D_S[d].drv_type=drv_200;
3581 else if (j<210) D_S[d].drv_type=drv_201;
3582 else if (j<211) D_S[d].drv_type=drv_210;
3583 else if (j<300) D_S[d].drv_type=drv_211;
3584 else if (j>=300) D_S[d].drv_type=drv_300;
3586 else if (fam1_drive)
3588 if (j<100) D_S[d].drv_type=drv_099;
3589 else
3591 D_S[d].drv_type=drv_100;
3592 if ((j!=500)&&(j!=102)) ask_mail();
3595 else if (fam2_drive)
3597 if (D_S[d].drive_model[5]=='F')
3599 if ((j!=1)&&(j!=35)&&(j!=200)&&(j!=210))
3600 ask_mail(); /* unknown version at time */
3602 else
3604 msg(DBG_INF,"this CD200 drive is not fully supported yet - only audio will work.\n");
3605 if ((j!=101)&&(j!=35))
3606 ask_mail(); /* unknown version at time */
3609 else if (famV_drive)
3611 if ((j==100)||(j==150)) D_S[d].drv_type=drv_at;
3612 ask_mail(); /* hopefully we get some feedback by this */
3615 msg(DBG_LCS,"drive type %02X\n",D_S[d].drv_type);
3616 msg(DBG_INI,"check_version done.\n");
3617 return (0);
3619 /*==========================================================================*/
3620 static void switch_drive(int i)
3622 d=i;
3623 OUT(CDo_enable,D_S[d].drv_sel);
3624 msg(DBG_DID,"drive %d (ID=%d) activated.\n", i, D_S[d].drv_id);
3625 return;
3627 /*==========================================================================*/
3628 #ifdef PATH_CHECK
3630 * probe for the presence of an interface card
3632 static int __init check_card(int port)
3634 #undef N_RESPO
3635 #define N_RESPO 20
3636 int i, j, k;
3637 u_char response[N_RESPO];
3638 u_char save_port0;
3639 u_char save_port3;
3641 msg(DBG_INI,"check_card entered.\n");
3642 save_port0=inb(port+0);
3643 save_port3=inb(port+3);
3645 for (j=0;j<NR_SBPCD;j++)
3647 OUT(port+3,j) ; /* enable drive #j */
3648 OUT(port+0,CMD0_PATH_CHECK);
3649 for (i=10;i>0;i--) OUT(port+0,0);
3650 for (k=0;k<N_RESPO;k++) response[k]=0;
3651 for (k=0;k<N_RESPO;k++)
3653 for (i=10000;i>0;i--)
3655 if (inb(port+1)&s_not_result_ready) continue;
3656 response[k]=inb(port+0);
3657 break;
3660 for (i=0;i<N_RESPO;i++)
3661 sprintf(&msgbuf[i*3], " %02X", response[i]);
3662 msgbuf[i*3]=0;
3663 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3664 OUT(port+0,CMD0_PATH_CHECK);
3665 for (i=10;i>0;i--) OUT(port+0,0);
3666 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3667 for (k=0;k<N_RESPO;k++)
3669 for (i=10000;i>0;i--)
3671 if (inb(port+1)&s_not_result_ready) continue;
3672 response[k]=inb(port+0);
3673 break;
3676 for (i=0;i<N_RESPO;i++)
3677 sprintf(&msgbuf[i*3], " %02X", response[i]);
3678 msgbuf[i*3]=0;
3679 msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
3681 if (response[0]==0xAA)
3682 if (response[1]==0x55)
3683 return (0);
3685 for (j=0;j<NR_SBPCD;j++)
3687 OUT(port+3,j) ; /* enable drive #j */
3688 OUT(port+0,CMD2_READ_VER);
3689 for (i=10;i>0;i--) OUT(port+0,0);
3690 for (k=0;k<N_RESPO;k++) response[k]=0;
3691 for (k=0;k<N_RESPO;k++)
3693 for (i=1000000;i>0;i--)
3695 if (inb(port+1)&s_not_result_ready) continue;
3696 response[k]=inb(port+0);
3697 break;
3700 for (i=0;i<N_RESPO;i++)
3701 sprintf(&msgbuf[i*3], " %02X", response[i]);
3702 msgbuf[i*3]=0;
3703 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3705 OUT(port+0,CMD2_READ_VER);
3706 for (i=10;i>0;i--) OUT(port+0,0);
3707 for (k=0;k<N_RESPO;k++) response[k]=0xFF;
3708 for (k=0;k<N_RESPO;k++)
3710 for (i=1000000;i>0;i--)
3712 if (inb(port+1)&s_not_result_ready) continue;
3713 response[k]=inb(port+0);
3714 break;
3717 for (i=0;i<N_RESPO;i++)
3718 sprintf(&msgbuf[i*3], " %02X", response[i]);
3719 msgbuf[i*3]=0;
3720 msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
3722 if (response[0]==0xAA)
3723 if (response[1]==0x55)
3724 return (0);
3726 OUT(port+0,save_port0);
3727 OUT(port+3,save_port3);
3728 return (0); /* in any case - no real "function" at time */
3730 #endif PATH_CHECK
3731 /*==========================================================================*/
3732 /*==========================================================================*/
3734 * probe for the presence of drives on the selected controller
3736 static int __init check_drives(void)
3738 int i, j;
3740 msg(DBG_INI,"check_drives entered.\n");
3741 ndrives=0;
3742 for (j=0;j<MAX_DRIVES;j++)
3744 D_S[ndrives].drv_id=j;
3745 if (sbpro_type==1) D_S[ndrives].drv_sel=(j&0x01)<<1|(j&0x02)>>1;
3746 else D_S[ndrives].drv_sel=j;
3747 switch_drive(ndrives);
3748 msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3749 msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
3750 i=check_version();
3751 if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
3752 else
3754 D_S[d].drv_options=drv_pattern[j];
3755 if (fam0L_drive) D_S[d].drv_options&=~(speed_auto|speed_300|speed_150);
3756 msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
3758 D_S[d].drv_id,
3759 D_S[d].drive_model,
3760 D_S[d].firmware_version,
3761 CDo_command,
3762 sbpro_type);
3763 ndrives++;
3766 for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
3767 if (ndrives==0) return (-1);
3768 return (0);
3770 /*==========================================================================*/
3771 #if FUTURE
3773 * obtain if requested service disturbs current audio state
3775 static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
3777 switch (audio_state) /* audio status from controller */
3779 case aud_11: /* "audio play in progress" */
3780 case audx11:
3781 switch (func) /* DOS command code */
3783 case cmd_07: /* input flush */
3784 case cmd_0d: /* open device */
3785 case cmd_0e: /* close device */
3786 case cmd_0c: /* ioctl output */
3787 return (1);
3788 case cmd_03: /* ioctl input */
3789 switch (subfunc)
3790 /* DOS ioctl input subfunction */
3792 case cxi_00:
3793 case cxi_06:
3794 case cxi_09:
3795 return (1);
3796 default:
3797 return (ERROR15);
3799 return (1);
3800 default:
3801 return (ERROR15);
3803 return (1);
3804 case aud_12: /* "audio play paused" */
3805 case audx12:
3806 return (1);
3807 default:
3808 return (2);
3811 /*==========================================================================*/
3812 /* allowed is only
3813 * ioctl_o, flush_input, open_device, close_device,
3814 * tell_address, tell_volume, tell_capabiliti,
3815 * tell_framesize, tell_CD_changed, tell_audio_posi
3817 static int check_allowed1(u_char func1, u_char func2)
3819 #if 000
3820 if (func1==ioctl_o) return (0);
3821 if (func1==read_long) return (-1);
3822 if (func1==read_long_prefetch) return (-1);
3823 if (func1==seek) return (-1);
3824 if (func1==audio_play) return (-1);
3825 if (func1==audio_pause) return (-1);
3826 if (func1==audio_resume) return (-1);
3827 if (func1!=ioctl_i) return (0);
3828 if (func2==tell_SubQ_run_tot) return (-1);
3829 if (func2==tell_cdsize) return (-1);
3830 if (func2==tell_TocDescrip) return (-1);
3831 if (func2==tell_TocEntry) return (-1);
3832 if (func2==tell_subQ_info) return (-1);
3833 if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
3834 if (func2==tell_UPC) return (-1);
3835 #else
3836 return (0);
3837 #endif 000
3839 /*==========================================================================*/
3840 static int check_allowed2(u_char func1, u_char func2)
3842 #if 000
3843 if (func1==read_long) return (-1);
3844 if (func1==read_long_prefetch) return (-1);
3845 if (func1==seek) return (-1);
3846 if (func1==audio_play) return (-1);
3847 if (func1!=ioctl_o) return (0);
3848 if (fam1_drive)
3850 if (func2==EjectDisk) return (-1);
3851 if (func2==CloseTray) return (-1);
3853 #else
3854 return (0);
3855 #endif 000
3857 /*==========================================================================*/
3858 static int check_allowed3(u_char func1, u_char func2)
3860 #if 000
3861 if (func1==ioctl_i)
3863 if (func2==tell_address) return (0);
3864 if (func2==tell_capabiliti) return (0);
3865 if (func2==tell_CD_changed) return (0);
3866 if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
3867 return (-1);
3869 if (func1==ioctl_o)
3871 if (func2==DriveReset) return (0);
3872 if (fam0L_drive)
3874 if (func2==EjectDisk) return (0);
3875 if (func2==LockDoor) return (0);
3876 if (func2==CloseTray) return (0);
3878 return (-1);
3880 if (func1==flush_input) return (-1);
3881 if (func1==read_long) return (-1);
3882 if (func1==read_long_prefetch) return (-1);
3883 if (func1==seek) return (-1);
3884 if (func1==audio_play) return (-1);
3885 if (func1==audio_pause) return (-1);
3886 if (func1==audio_resume) return (-1);
3887 #else
3888 return (0);
3889 #endif 000
3891 /*==========================================================================*/
3892 static int seek_pos_audio_end(void)
3894 int i;
3896 i=msf2blk(D_S[d].pos_audio_end)-1;
3897 if (i<0) return (-1);
3898 i=cc_Seek(i,0);
3899 return (i);
3901 #endif FUTURE
3902 /*==========================================================================*/
3903 static int ReadToC(void)
3905 int i, j;
3906 D_S[d].diskstate_flags &= ~toc_bit;
3907 D_S[d].ored_ctl_adr=0;
3908 /* special handling of CD-I HE */
3909 if ((D_S[d].n_first_track == 2 && D_S[d].n_last_track == 2) ||
3910 D_S[d].xa_byte == 0x10)
3912 D_S[d].TocBuffer[1].nixbyte=0;
3913 D_S[d].TocBuffer[1].ctl_adr=0x40;
3914 D_S[d].TocBuffer[1].number=1;
3915 D_S[d].TocBuffer[1].format=0;
3916 D_S[d].TocBuffer[1].address=blk2msf(0);
3917 D_S[d].ored_ctl_adr |= 0x40;
3918 D_S[d].n_first_track = 1;
3919 D_S[d].n_last_track = 1;
3920 D_S[d].xa_byte = 0x10;
3921 j = 2;
3922 } else
3923 for (j=D_S[d].n_first_track;j<=D_S[d].n_last_track;j++)
3925 i=cc_ReadTocEntry(j);
3926 if (i<0)
3928 msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
3929 return (i);
3931 D_S[d].TocBuffer[j].nixbyte=D_S[d].TocEnt_nixbyte;
3932 D_S[d].TocBuffer[j].ctl_adr=D_S[d].TocEnt_ctl_adr;
3933 D_S[d].TocBuffer[j].number=D_S[d].TocEnt_number;
3934 D_S[d].TocBuffer[j].format=D_S[d].TocEnt_format;
3935 D_S[d].TocBuffer[j].address=D_S[d].TocEnt_address;
3936 D_S[d].ored_ctl_adr |= D_S[d].TocEnt_ctl_adr;
3938 /* fake entry for LeadOut Track */
3939 D_S[d].TocBuffer[j].nixbyte=0;
3940 D_S[d].TocBuffer[j].ctl_adr=0;
3941 D_S[d].TocBuffer[j].number=CDROM_LEADOUT;
3942 D_S[d].TocBuffer[j].format=0;
3943 D_S[d].TocBuffer[j].address=D_S[d].size_msf;
3945 D_S[d].diskstate_flags |= toc_bit;
3946 return (0);
3948 /*==========================================================================*/
3949 static int DiskInfo(void)
3951 int i, j;
3953 D_S[d].mode=READ_M1;
3955 #undef LOOP_COUNT
3956 #define LOOP_COUNT 10 /* needed for some "old" drives */
3958 msg(DBG_000,"DiskInfo entered.\n");
3959 for (j=1;j<LOOP_COUNT;j++)
3961 #if 0
3962 i=SetSpeed();
3963 if (i<0)
3965 msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
3966 continue;
3968 i=cc_ModeSense();
3969 if (i<0)
3971 msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
3972 continue;
3974 #endif
3975 i=cc_ReadCapacity();
3976 if (i>=0) break;
3977 msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
3978 #if 0
3979 i=cc_DriveReset();
3980 #endif
3981 if (!fam0_drive && j == 2) break;
3983 if (j==LOOP_COUNT) return (-33); /* give up */
3985 i=cc_ReadTocDescr();
3986 if (i<0)
3988 msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
3989 return (i);
3991 i=ReadToC();
3992 if (i<0)
3994 msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
3995 return (i);
3997 i=cc_CheckMultiSession();
3998 if (i<0)
4000 msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
4001 return (i);
4003 if (D_S[d].f_multisession) D_S[d].sbp_bufsiz=1; /* possibly a weird PhotoCD */
4004 else D_S[d].sbp_bufsiz=buffers;
4005 i=cc_ReadTocEntry(D_S[d].n_first_track);
4006 if (i<0)
4008 msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
4009 return (i);
4011 i=cc_ReadUPC();
4012 if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
4013 if ((fam0L_drive) && (D_S[d].xa_byte==0x20 || D_S[d].xa_byte == 0x10))
4015 /* XA disk with old drive */
4016 cc_ModeSelect(CD_FRAMESIZE_RAW1);
4017 cc_ModeSense();
4019 if (famT_drive) cc_prep_mode_T();
4020 msg(DBG_000,"DiskInfo done.\n");
4021 return (0);
4024 static int sbpcd_drive_status(struct cdrom_device_info *cdi, int slot_nr)
4026 int st;
4028 if (CDSL_CURRENT != slot_nr) {
4029 /* we have no changer support */
4030 return -EINVAL;
4033 cc_ReadStatus();
4034 st=ResponseStatus();
4035 if (st<0)
4037 msg(DBG_INF,"sbpcd_drive_status: timeout.\n");
4038 return (0);
4040 msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
4041 msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
4042 msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
4043 msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
4044 msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
4045 msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
4047 #if 0
4048 if (!(D_S[MINOR(cdi->dev)].status_bits & p_door_closed)) return CDS_TRAY_OPEN;
4049 if (D_S[MINOR(cdi->dev)].status_bits & p_disk_ok) return CDS_DISC_OK;
4050 if (D_S[MINOR(cdi->dev)].status_bits & p_disk_in) return CDS_DRIVE_NOT_READY;
4052 return CDS_NO_DISC;
4053 #else
4054 if (D_S[MINOR(cdi->dev)].status_bits & p_spinning) return CDS_DISC_OK;
4055 /* return CDS_TRAY_OPEN; */
4056 return CDS_NO_DISC;
4058 #endif
4063 /*==========================================================================*/
4064 #if FUTURE
4066 * called always if driver gets entered
4067 * returns 0 or ERROR2 or ERROR15
4069 static int prepare(u_char func, u_char subfunc)
4071 int i;
4073 if (fam0L_drive)
4075 i=inb(CDi_status);
4076 if (i&s_attention) GetStatus();
4078 else if (fam1_drive) GetStatus();
4079 else if (fam2_drive) GetStatus();
4080 else if (famT_drive) GetStatus();
4081 if (D_S[d].CD_changed==0xFF)
4083 D_S[d].diskstate_flags=0;
4084 D_S[d].audio_state=0;
4085 if (!st_diskok)
4087 i=check_allowed1(func,subfunc);
4088 if (i<0) return (-2);
4090 else
4092 i=check_allowed3(func,subfunc);
4093 if (i<0)
4095 D_S[d].CD_changed=1;
4096 return (-15);
4100 else
4102 if (!st_diskok)
4104 D_S[d].diskstate_flags=0;
4105 D_S[d].audio_state=0;
4106 i=check_allowed1(func,subfunc);
4107 if (i<0) return (-2);
4109 else
4111 if (st_busy)
4113 if (D_S[d].audio_state!=audio_pausing)
4115 i=check_allowed2(func,subfunc);
4116 if (i<0) return (-2);
4119 else
4121 if (D_S[d].audio_state==audio_playing) seek_pos_audio_end();
4122 D_S[d].audio_state=0;
4124 if (!frame_size_valid)
4126 i=DiskInfo();
4127 if (i<0)
4129 D_S[d].diskstate_flags=0;
4130 D_S[d].audio_state=0;
4131 i=check_allowed1(func,subfunc);
4132 if (i<0) return (-2);
4137 return (0);
4139 #endif FUTURE
4140 /*==========================================================================*/
4141 /*==========================================================================*/
4143 * Check the results of the "get status" command.
4145 static int sbp_status(void)
4147 int st;
4149 st=ResponseStatus();
4150 if (st<0)
4152 msg(DBG_INF,"sbp_status: timeout.\n");
4153 return (0);
4156 if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
4158 if (st_check)
4160 msg(DBG_INF,"st_check detected - retrying.\n");
4161 return (0);
4163 if (!st_door_closed)
4165 msg(DBG_INF,"door is open - retrying.\n");
4166 return (0);
4168 if (!st_caddy_in)
4170 msg(DBG_INF,"disk removed - retrying.\n");
4171 return (0);
4173 if (!st_diskok)
4175 msg(DBG_INF,"!st_diskok detected - retrying.\n");
4176 return (0);
4178 if (st_busy)
4180 msg(DBG_INF,"st_busy detected - retrying.\n");
4181 return (0);
4183 return (1);
4185 /*==========================================================================*/
4187 static int sbpcd_get_last_session(struct cdrom_device_info *cdi, struct cdrom_multisession *ms_infp)
4189 ms_infp->addr_format = CDROM_LBA;
4190 ms_infp->addr.lba = D_S[MINOR(cdi->dev)].lba_multi;
4191 if (D_S[MINOR(cdi->dev)].f_multisession)
4192 ms_infp->xa_flag=1; /* valid redirection address */
4193 else
4194 ms_infp->xa_flag=0; /* invalid redirection address */
4196 return 0;
4199 /*==========================================================================*/
4200 /*==========================================================================*/
4202 * ioctl support
4204 static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4205 u_long arg)
4207 int i;
4209 msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08lX)\n",
4210 MINOR(cdi->dev), cmd, arg);
4211 i=MINOR(cdi->dev);
4212 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4214 msg(DBG_INF, "ioctl: bad device: %04X\n", cdi->dev);
4215 return (-ENXIO); /* no such drive */
4217 down(&ioctl_read_sem);
4218 if (d!=i) switch_drive(i);
4220 msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
4221 switch (cmd) /* Sun-compatible */
4223 case DDIOCSDBG: /* DDI Debug */
4224 if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
4225 i=sbpcd_dbg_ioctl(arg,1);
4226 RETURN_UP(i);
4227 case CDROMRESET: /* hard reset the drive */
4228 msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
4229 i=DriveReset();
4230 D_S[d].audio_state=0;
4231 RETURN_UP(i);
4233 case CDROMREADMODE1:
4234 msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
4235 #if SAFE_MIXED
4236 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4237 #endif SAFE_MIXED
4238 cc_ModeSelect(CD_FRAMESIZE);
4239 cc_ModeSense();
4240 D_S[d].mode=READ_M1;
4241 RETURN_UP(0);
4243 case CDROMREADMODE2: /* not usable at the moment */
4244 msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
4245 #if SAFE_MIXED
4246 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4247 #endif SAFE_MIXED
4248 cc_ModeSelect(CD_FRAMESIZE_RAW1);
4249 cc_ModeSense();
4250 D_S[d].mode=READ_M2;
4251 RETURN_UP(0);
4253 case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
4254 msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
4255 if (D_S[d].sbp_audsiz>0) vfree(D_S[d].aud_buf);
4256 D_S[d].aud_buf=NULL;
4257 D_S[d].sbp_audsiz=arg;
4259 if (D_S[d].sbp_audsiz>0)
4261 D_S[d].aud_buf=(u_char *) vmalloc(D_S[d].sbp_audsiz*CD_FRAMESIZE_RAW);
4262 if (D_S[d].aud_buf==NULL)
4264 msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[d].sbp_audsiz);
4265 D_S[d].sbp_audsiz=0;
4267 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[d].sbp_audsiz);
4269 RETURN_UP(D_S[d].sbp_audsiz);
4271 case CDROMREADAUDIO:
4272 { /* start of CDROMREADAUDIO */
4273 int i=0, j=0, frame, block=0;
4274 u_int try=0;
4275 u_long timeout;
4276 u_char *p;
4277 u_int data_tries = 0;
4278 u_int data_waits = 0;
4279 u_int data_retrying = 0;
4280 int status_tries;
4281 int error_flag;
4283 msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
4284 if (fam0_drive) RETURN_UP(-EINVAL);
4285 if (famL_drive) RETURN_UP(-EINVAL);
4286 if (famV_drive) RETURN_UP(-EINVAL);
4287 if (famT_drive) RETURN_UP(-EINVAL);
4288 #if SAFE_MIXED
4289 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4290 #endif SAFE_MIXED
4291 if (D_S[d].aud_buf==NULL) RETURN_UP(-EINVAL);
4292 i=verify_area(VERIFY_READ, (void *) arg, sizeof(struct cdrom_read_audio));
4293 if (i) RETURN_UP(i);
4294 copy_from_user(&read_audio, (void *) arg, sizeof(struct cdrom_read_audio));
4295 if (read_audio.nframes>D_S[d].sbp_audsiz) RETURN_UP(-EINVAL);
4296 i=verify_area(VERIFY_WRITE, read_audio.buf,
4297 read_audio.nframes*CD_FRAMESIZE_RAW);
4298 if (i) RETURN_UP(i);
4300 if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
4301 block=msf2lba(&read_audio.addr.msf.minute);
4302 else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
4303 block=read_audio.addr.lba;
4304 else RETURN_UP(-EINVAL);
4305 #if 000
4306 i=cc_SetSpeed(speed_150,0,0);
4307 if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
4308 #endif
4309 msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
4310 block, blk2msf(block));
4311 msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
4312 #if OLD_BUSY
4313 while (busy_data) sbp_sleep(HZ/10); /* wait a bit */
4314 busy_audio=1;
4315 #endif OLD_BUSY
4316 error_flag=0;
4317 for (data_tries=5; data_tries>0; data_tries--)
4319 msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
4320 D_S[d].mode=READ_AU;
4321 cc_ModeSelect(CD_FRAMESIZE_RAW);
4322 cc_ModeSense();
4323 for (status_tries=3; status_tries > 0; status_tries--)
4325 flags_cmd_out |= f_respo3;
4326 cc_ReadStatus();
4327 if (sbp_status() != 0) break;
4328 if (st_check) cc_ReadError();
4329 sbp_sleep(1); /* wait a bit, try again */
4331 if (status_tries == 0)
4333 msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__);
4334 continue;
4336 msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
4338 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
4339 if (fam0L_drive)
4341 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
4342 cmd_type=READ_M2;
4343 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
4344 drvcmd[1]=(block>>16)&0x000000ff;
4345 drvcmd[2]=(block>>8)&0x000000ff;
4346 drvcmd[3]=block&0x000000ff;
4347 drvcmd[4]=0;
4348 drvcmd[5]=read_audio.nframes; /* # of frames */
4349 drvcmd[6]=0;
4351 else if (fam1_drive)
4353 drvcmd[0]=CMD1_READ; /* "read frames", new drives */
4354 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4355 drvcmd[4]=0;
4356 drvcmd[5]=0;
4357 drvcmd[6]=read_audio.nframes; /* # of frames */
4359 else if (fam2_drive)
4361 drvcmd[0]=CMD2_READ_XA2;
4362 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
4363 drvcmd[4]=0;
4364 drvcmd[5]=read_audio.nframes; /* # of frames */
4365 drvcmd[6]=0x11; /* raw mode */
4367 else if (famT_drive) /* CD-55A: not tested yet */
4370 msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
4371 flags_cmd_out=f_putcmd;
4372 response_count=0;
4373 i=cmd_out();
4374 if (i<0) msg(DBG_INF,"error giving READ AUDIO command: %0d\n", i);
4375 sbp_sleep(0);
4376 msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
4377 for (frame=1;frame<2 && !error_flag; frame++)
4379 try=maxtim_data;
4380 for (timeout=jiffies+9*HZ; ; )
4382 for ( ; try!=0;try--)
4384 j=inb(CDi_status);
4385 if (!(j&s_not_data_ready)) break;
4386 if (!(j&s_not_result_ready)) break;
4387 if (fam0L_drive) if (j&s_attention) break;
4389 if (try != 0 || time_after_eq(jiffies, timeout)) break;
4390 if (data_retrying == 0) data_waits++;
4391 data_retrying = 1;
4392 sbp_sleep(1);
4393 try = 1;
4395 if (try==0)
4397 msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
4398 error_flag++;
4399 break;
4401 msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
4402 if (j&s_not_data_ready)
4404 msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
4405 error_flag++;
4406 break;
4408 msg(DBG_AUD,"read_audio: before reading data.\n");
4409 error_flag=0;
4410 p = D_S[d].aud_buf;
4411 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
4412 if (do_16bit)
4414 u_short *p2 = (u_short *) p;
4416 for (; (u_char *) p2 < D_S[d].aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4418 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4420 /* get one sample */
4421 *p2++ = inw_p(CDi_data);
4422 *p2++ = inw_p(CDi_data);
4424 } else {
4425 for (; p < D_S[d].aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
4427 if ((inb_p(CDi_status)&s_not_data_ready)) continue;
4429 /* get one sample */
4430 *p++ = inb_p(CDi_data);
4431 *p++ = inb_p(CDi_data);
4432 *p++ = inb_p(CDi_data);
4433 *p++ = inb_p(CDi_data);
4436 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
4437 data_retrying = 0;
4439 msg(DBG_AUD,"read_audio: after reading data.\n");
4440 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
4442 msg(DBG_AUD,"read_audio: read aborted by drive\n");
4443 #if 0000
4444 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4445 #else
4446 i=cc_ReadError();
4447 #endif 0000
4448 continue;
4450 if (fam0L_drive)
4452 i=maxtim_data;
4453 for (timeout=jiffies+9*HZ; time_before(jiffies, timeout); timeout--)
4455 for ( ;i!=0;i--)
4457 j=inb(CDi_status);
4458 if (!(j&s_not_data_ready)) break;
4459 if (!(j&s_not_result_ready)) break;
4460 if (j&s_attention) break;
4462 if (i != 0 || time_after_eq(jiffies, timeout)) break;
4463 sbp_sleep(0);
4464 i = 1;
4466 if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
4467 if (!(j&s_attention))
4469 msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
4470 i=cc_DriveReset(); /* ugly fix to prevent a hang */
4471 continue;
4476 if (fam0L_drive) cc_ReadStatus();
4477 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
4478 if (i<0) { msg(DBG_AUD,
4479 "read_audio: cc_ReadStatus error after read: %02X\n",
4480 D_S[d].status_bits);
4481 continue; /* FIXME */
4484 while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
4485 if (st_check)
4487 i=cc_ReadError();
4488 msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
4489 continue;
4491 copy_to_user((u_char *) read_audio.buf,
4492 (u_char *) D_S[d].aud_buf,
4493 read_audio.nframes*CD_FRAMESIZE_RAW);
4494 msg(DBG_AUD,"read_audio: copy_to_user done.\n");
4495 break;
4497 cc_ModeSelect(CD_FRAMESIZE);
4498 cc_ModeSense();
4499 D_S[d].mode=READ_M1;
4500 #if OLD_BUSY
4501 busy_audio=0;
4502 #endif OLD_BUSY
4503 if (data_tries == 0)
4505 msg(DBG_AUD,"read_audio: failed after 5 tries in line %d.\n", __LINE__);
4506 RETURN_UP(-EIO);
4508 msg(DBG_AUD,"read_audio: successful return.\n");
4509 RETURN_UP(0);
4510 } /* end of CDROMREADAUDIO */
4512 case BLKRASET:
4513 if(!capable(CAP_SYS_ADMIN)) RETURN_UP(-EACCES);
4514 if(!(cdi->dev)) RETURN_UP(-EINVAL);
4515 if(arg > 0xff) RETURN_UP(-EINVAL);
4516 read_ahead[MAJOR(cdi->dev)] = arg;
4517 RETURN_UP(0);
4518 default:
4519 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4520 RETURN_UP(-EINVAL);
4521 } /* end switch(cmd) */
4524 static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
4525 void * arg)
4527 int i, st, j;
4529 msg(DBG_IO2,"ioctl(%d, 0x%08lX, 0x%08p)\n",
4530 MINOR(cdi->dev), cmd, arg);
4531 i=MINOR(cdi->dev);
4532 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4534 msg(DBG_INF, "ioctl: bad device: %04X\n", cdi->dev);
4535 return (-ENXIO); /* no such drive */
4537 down(&ioctl_read_sem);
4538 if (d!=i) switch_drive(i);
4540 msg(DBG_IO2,"ioctl: device %d, request %04X\n",i,cmd);
4541 switch (cmd) /* Sun-compatible */
4544 case CDROMPAUSE: /* Pause the drive */
4545 msg(DBG_IOC,"ioctl: CDROMPAUSE entered.\n");
4546 /* pause the drive unit when it is currently in PLAY mode, */
4547 /* or reset the starting and ending locations when in PAUSED mode. */
4548 /* If applicable, at the next stopping point it reaches */
4549 /* the drive will discontinue playing. */
4550 switch (D_S[d].audio_state)
4552 case audio_playing:
4553 if (famL_drive) i=cc_ReadSubQ();
4554 else i=cc_Pause_Resume(1);
4555 if (i<0) RETURN_UP(-EIO);
4556 if (famL_drive) i=cc_Pause_Resume(1);
4557 else i=cc_ReadSubQ();
4558 if (i<0) RETURN_UP(-EIO);
4559 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
4560 D_S[d].audio_state=audio_pausing;
4561 RETURN_UP(0);
4562 case audio_pausing:
4563 i=cc_Seek(D_S[d].pos_audio_start,1);
4564 if (i<0) RETURN_UP(-EIO);
4565 RETURN_UP(0);
4566 default:
4567 RETURN_UP(-EINVAL);
4570 case CDROMRESUME: /* resume paused audio play */
4571 msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
4572 /* resume playing audio tracks when a previous PLAY AUDIO call has */
4573 /* been paused with a PAUSE command. */
4574 /* It will resume playing from the location saved in SubQ_run_tot. */
4575 if (D_S[d].audio_state!=audio_pausing) RETURN_UP(-EINVAL);
4576 if (famL_drive)
4577 i=cc_PlayAudio(D_S[d].pos_audio_start,
4578 D_S[d].pos_audio_end);
4579 else i=cc_Pause_Resume(3);
4580 if (i<0) RETURN_UP(-EIO);
4581 D_S[d].audio_state=audio_playing;
4582 RETURN_UP(0);
4584 case CDROMPLAYMSF:
4585 msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
4586 #if SAFE_MIXED
4587 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4588 #endif SAFE_MIXED
4589 if (D_S[d].audio_state==audio_playing)
4591 i=cc_Pause_Resume(1);
4592 if (i<0) RETURN_UP(-EIO);
4593 i=cc_ReadSubQ();
4594 if (i<0) RETURN_UP(-EIO);
4595 D_S[d].pos_audio_start=D_S[d].SubQ_run_tot;
4596 i=cc_Seek(D_S[d].pos_audio_start,1);
4598 memcpy(&msf, (void *) arg, sizeof(struct cdrom_msf));
4599 /* values come as msf-bin */
4600 D_S[d].pos_audio_start = (msf.cdmsf_min0<<16) |
4601 (msf.cdmsf_sec0<<8) |
4602 msf.cdmsf_frame0;
4603 D_S[d].pos_audio_end = (msf.cdmsf_min1<<16) |
4604 (msf.cdmsf_sec1<<8) |
4605 msf.cdmsf_frame1;
4606 msg(DBG_IOX,"ioctl: CDROMPLAYMSF %08X %08X\n",
4607 D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4608 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4609 if (i<0)
4611 msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
4612 DriveReset();
4613 D_S[d].audio_state=0;
4614 RETURN_UP(-EIO);
4616 D_S[d].audio_state=audio_playing;
4617 RETURN_UP(0);
4619 case CDROMPLAYTRKIND: /* Play a track. This currently ignores index. */
4620 msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
4621 #if SAFE_MIXED
4622 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4623 #endif SAFE_MIXED
4624 if (D_S[d].audio_state==audio_playing)
4626 msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
4627 #if 1
4628 RETURN_UP(0); /* just let us play on */
4629 #else
4630 RETURN_UP(-EINVAL); /* play on, but say "error" */
4631 #endif
4633 memcpy(&ti,(void *) arg,sizeof(struct cdrom_ti));
4634 msg(DBG_IOX,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
4635 ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1);
4636 if (ti.cdti_trk0<D_S[d].n_first_track) RETURN_UP(-EINVAL);
4637 if (ti.cdti_trk0>D_S[d].n_last_track) RETURN_UP(-EINVAL);
4638 if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
4639 if (ti.cdti_trk1>D_S[d].n_last_track) ti.cdti_trk1=D_S[d].n_last_track;
4640 D_S[d].pos_audio_start=D_S[d].TocBuffer[ti.cdti_trk0].address;
4641 D_S[d].pos_audio_end=D_S[d].TocBuffer[ti.cdti_trk1+1].address;
4642 i=cc_PlayAudio(D_S[d].pos_audio_start,D_S[d].pos_audio_end);
4643 if (i<0)
4645 msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
4646 DriveReset();
4647 D_S[d].audio_state=0;
4648 RETURN_UP(-EIO);
4650 D_S[d].audio_state=audio_playing;
4651 RETURN_UP(0);
4653 case CDROMREADTOCHDR: /* Read the table of contents header */
4654 msg(DBG_IOC,"ioctl: CDROMREADTOCHDR entered.\n");
4655 tochdr.cdth_trk0=D_S[d].n_first_track;
4656 tochdr.cdth_trk1=D_S[d].n_last_track;
4657 memcpy((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
4658 RETURN_UP(0);
4660 case CDROMREADTOCENTRY: /* Read an entry in the table of contents */
4661 msg(DBG_IOC,"ioctl: CDROMREADTOCENTRY entered.\n");
4662 memcpy(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
4663 i=tocentry.cdte_track;
4664 if (i==CDROM_LEADOUT) i=D_S[d].n_last_track+1;
4665 else if (i<D_S[d].n_first_track||i>D_S[d].n_last_track)
4666 RETURN_UP(-EINVAL);
4667 tocentry.cdte_adr=D_S[d].TocBuffer[i].ctl_adr&0x0F;
4668 tocentry.cdte_ctrl=(D_S[d].TocBuffer[i].ctl_adr>>4)&0x0F;
4669 tocentry.cdte_datamode=D_S[d].TocBuffer[i].format;
4670 if (tocentry.cdte_format==CDROM_MSF) /* MSF-bin required */
4672 tocentry.cdte_addr.msf.minute=(D_S[d].TocBuffer[i].address>>16)&0x00FF;
4673 tocentry.cdte_addr.msf.second=(D_S[d].TocBuffer[i].address>>8)&0x00FF;
4674 tocentry.cdte_addr.msf.frame=D_S[d].TocBuffer[i].address&0x00FF;
4676 else if (tocentry.cdte_format==CDROM_LBA) /* blk required */
4677 tocentry.cdte_addr.lba=msf2blk(D_S[d].TocBuffer[i].address);
4678 else RETURN_UP(-EINVAL);
4679 memcpy((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
4680 RETURN_UP(0);
4682 case CDROMSTOP: /* Spin down the drive */
4683 msg(DBG_IOC,"ioctl: CDROMSTOP entered.\n");
4684 #if SAFE_MIXED
4685 if (D_S[d].has_data>1) RETURN_UP(-EBUSY);
4686 #endif SAFE_MIXED
4687 i=cc_Pause_Resume(1);
4688 D_S[d].audio_state=0;
4689 #if 0
4690 cc_DriveReset();
4691 #endif
4692 RETURN_UP(i);
4694 case CDROMSTART: /* Spin up the drive */
4695 msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
4696 cc_SpinUp();
4697 D_S[d].audio_state=0;
4698 RETURN_UP(0);
4700 case CDROMVOLCTRL: /* Volume control */
4701 msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
4702 memcpy(&volctrl,(char *) arg,sizeof(volctrl));
4703 D_S[d].vol_chan0=0;
4704 D_S[d].vol_ctrl0=volctrl.channel0;
4705 D_S[d].vol_chan1=1;
4706 D_S[d].vol_ctrl1=volctrl.channel1;
4707 i=cc_SetVolume();
4708 RETURN_UP(0);
4710 case CDROMVOLREAD: /* read Volume settings from drive */
4711 msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
4712 st=cc_GetVolume();
4713 if (st<0) RETURN_UP(st);
4714 volctrl.channel0=D_S[d].vol_ctrl0;
4715 volctrl.channel1=D_S[d].vol_ctrl1;
4716 volctrl.channel2=0;
4717 volctrl.channel2=0;
4718 memcpy((void *)arg,&volctrl,sizeof(volctrl));
4719 RETURN_UP(0);
4721 case CDROMSUBCHNL: /* Get subchannel info */
4722 msg(DBG_IOS,"ioctl: CDROMSUBCHNL entered.\n");
4723 /* Bogus, I can do better than this! --AJK
4724 if ((st_spinning)||(!subq_valid)) {
4725 i=cc_ReadSubQ();
4726 if (i<0) RETURN_UP(-EIO);
4729 i=cc_ReadSubQ();
4730 if (i<0) {
4731 j=cc_ReadError(); /* clear out error status from drive */
4732 D_S[d].audio_state=CDROM_AUDIO_NO_STATUS;
4733 /* get and set the disk state here,
4734 probably not the right place, but who cares!
4735 It makes it work properly! --AJK */
4736 if (D_S[d].CD_changed==0xFF) {
4737 msg(DBG_000,"Disk changed detect\n");
4738 D_S[d].diskstate_flags &= ~cd_size_bit;
4740 RETURN_UP(-EIO);
4742 if (D_S[d].CD_changed==0xFF) {
4743 /* reread the TOC because the disk has changed! --AJK */
4744 msg(DBG_000,"Disk changed STILL detected, rereading TOC!\n");
4745 i=DiskInfo();
4746 if(i==0) {
4747 D_S[d].CD_changed=0x00; /* cd has changed, procede, */
4748 RETURN_UP(-EIO); /* and get TOC, etc on next try! --AJK */
4749 } else {
4750 RETURN_UP(-EIO); /* we weren't ready yet! --AJK */
4753 memcpy(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
4755 This virtual crap is very bogus!
4756 It doesn't detect when the cd is done playing audio!
4757 Lets do this right with proper hardware register reading!
4759 cc_ReadStatus();
4760 i=ResponseStatus();
4761 msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
4762 msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
4763 msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
4764 msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
4765 msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
4766 msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
4767 /* st_busy indicates if it's _ACTUALLY_ playing audio */
4768 switch (D_S[d].audio_state)
4770 case audio_playing:
4771 if(st_busy==0) {
4772 /* CD has stopped playing audio --AJK */
4773 D_S[d].audio_state=audio_completed;
4774 SC.cdsc_audiostatus=CDROM_AUDIO_COMPLETED;
4775 } else {
4776 SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
4778 break;
4779 case audio_pausing:
4780 SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
4781 break;
4782 case audio_completed:
4783 SC.cdsc_audiostatus=CDROM_AUDIO_COMPLETED;
4784 break;
4785 default:
4786 SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
4787 break;
4789 SC.cdsc_adr=D_S[d].SubQ_ctl_adr;
4790 SC.cdsc_ctrl=D_S[d].SubQ_ctl_adr>>4;
4791 SC.cdsc_trk=bcd2bin(D_S[d].SubQ_trk);
4792 SC.cdsc_ind=bcd2bin(D_S[d].SubQ_pnt_idx);
4793 if (SC.cdsc_format==CDROM_LBA)
4795 SC.cdsc_absaddr.lba=msf2blk(D_S[d].SubQ_run_tot);
4796 SC.cdsc_reladdr.lba=msf2blk(D_S[d].SubQ_run_trk);
4798 else /* not only if (SC.cdsc_format==CDROM_MSF) */
4800 SC.cdsc_absaddr.msf.minute=(D_S[d].SubQ_run_tot>>16)&0x00FF;
4801 SC.cdsc_absaddr.msf.second=(D_S[d].SubQ_run_tot>>8)&0x00FF;
4802 SC.cdsc_absaddr.msf.frame=D_S[d].SubQ_run_tot&0x00FF;
4803 SC.cdsc_reladdr.msf.minute=(D_S[d].SubQ_run_trk>>16)&0x00FF;
4804 SC.cdsc_reladdr.msf.second=(D_S[d].SubQ_run_trk>>8)&0x00FF;
4805 SC.cdsc_reladdr.msf.frame=D_S[d].SubQ_run_trk&0x00FF;
4807 memcpy((void *) arg, &SC, sizeof(struct cdrom_subchnl));
4808 msg(DBG_IOS,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
4809 SC.cdsc_format,SC.cdsc_audiostatus,
4810 SC.cdsc_adr,SC.cdsc_ctrl,
4811 SC.cdsc_trk,SC.cdsc_ind,
4812 SC.cdsc_absaddr,SC.cdsc_reladdr);
4813 RETURN_UP(0);
4815 default:
4816 msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
4817 RETURN_UP(-EINVAL);
4818 } /* end switch(cmd) */
4820 /*==========================================================================*/
4822 * Take care of the different block sizes between cdrom and Linux.
4824 static void sbp_transfer(struct request *req)
4826 long offs;
4828 while ( (req->nr_sectors > 0) &&
4829 (req->sector/4 >= D_S[d].sbp_first_frame) &&
4830 (req->sector/4 <= D_S[d].sbp_last_frame) )
4832 offs = (req->sector - D_S[d].sbp_first_frame * 4) * 512;
4833 memcpy(req->buffer, D_S[d].sbp_buf + offs, 512);
4834 req->nr_sectors--;
4835 req->sector++;
4836 req->buffer += 512;
4839 /*==========================================================================*/
4841 * special end_request for sbpcd to solve CURRENT==NULL bug. (GTL)
4842 * GTL = Gonzalo Tornaria <tornaria@cmat.edu.uy>
4844 * This is a kludge so we don't need to modify end_request.
4845 * We put the req we take out after INIT_REQUEST in the requests list,
4846 * so that end_request will discard it.
4848 * The bug could be present in other block devices, perhaps we
4849 * should modify INIT_REQUEST and end_request instead, and
4850 * change every block device..
4852 * Could be a race here?? Could e.g. a timer interrupt schedule() us?
4853 * If so, we should copy end_request here, and do it right.. (or
4854 * modify end_request and the block devices).
4856 * In any case, the race here would be much small than it was, and
4857 * I couldn't reproduce..
4859 * The race could be: suppose CURRENT==NULL. We put our req in the list,
4860 * and we are scheduled. Other process takes over, and gets into
4861 * do_sbpcd_request. It sees CURRENT!=NULL (it is == to our req), so
4862 * proceeds. It ends, so CURRENT is now NULL.. Now we awake somewhere in
4863 * end_request, but now CURRENT==NULL... oops!
4866 #undef DEBUG_GTL
4867 static inline void sbpcd_end_request(struct request *req, int uptodate) {
4868 list_add(&req->queue, &req->q->queue_head);
4869 end_request(uptodate);
4871 /*==========================================================================*/
4873 * I/O request routine, called from Linux kernel.
4875 static void DO_SBPCD_REQUEST(request_queue_t * q)
4877 u_int block;
4878 u_int nsect;
4879 int i, status_tries, data_tries;
4880 struct request *req;
4881 #ifdef DEBUG_GTL
4882 static int xx_nr=0;
4883 int xnr;
4884 #endif
4886 request_loop:
4887 #ifdef DEBUG_GTL
4888 xnr=++xx_nr;
4890 if(QUEUE_EMPTY)
4892 printk( "do_sbpcd_request[%di](NULL), Pid:%d, Time:%li\n",
4893 xnr, current->pid, jiffies);
4894 printk( "do_sbpcd_request[%do](NULL) end 0 (null), Time:%li\n",
4895 xnr, jiffies);
4896 CLEAR_INTR;
4897 return;
4900 printk(" do_sbpcd_request[%di](%p:%ld+%ld), Pid:%d, Time:%li\n",
4901 xnr, CURRENT, CURRENT->sector, CURRENT->nr_sectors, current->pid, jiffies);
4902 #endif
4903 INIT_REQUEST;
4904 req=CURRENT; /* take out our request so no other */
4905 blkdev_dequeue_request(req); /* task can fuck it up GTL */
4907 if (req->rq_status == RQ_INACTIVE)
4908 sbpcd_end_request(req, 0);
4909 if (req -> sector == -1)
4910 sbpcd_end_request(req, 0);
4911 spin_unlock_irq(&io_request_lock);
4913 down(&ioctl_read_sem);
4914 if (req->cmd != READ)
4916 msg(DBG_INF, "bad cmd %d\n", req->cmd);
4917 goto err_done;
4919 i = MINOR(req->rq_dev);
4920 if ( (i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
4922 msg(DBG_INF, "do_request: bad device: %s\n",
4923 kdevname(req->rq_dev));
4924 goto err_done;
4926 #if OLD_BUSY
4927 while (busy_audio) sbp_sleep(HZ); /* wait a bit */
4928 busy_data=1;
4929 #endif OLD_BUSY
4931 if (D_S[i].audio_state==audio_playing) goto err_done;
4932 if (d!=i) switch_drive(i);
4934 block = req->sector; /* always numbered as 512-byte-pieces */
4935 nsect = req->nr_sectors; /* always counted as 512-byte-pieces */
4937 msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
4938 #if 0
4939 msg(DBG_MUL,"read LBA %d\n", block/4);
4940 #endif
4942 sbp_transfer(req);
4943 /* if we satisfied the request from the buffer, we're done. */
4944 if (req->nr_sectors == 0)
4946 #ifdef DEBUG_GTL
4947 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 2, Time:%li\n",
4948 xnr, req, req->sector, req->nr_sectors, jiffies);
4949 #endif
4950 up(&ioctl_read_sem);
4951 spin_lock_irq(&io_request_lock);
4952 sbpcd_end_request(req, 1);
4953 goto request_loop;
4956 #if FUTURE
4957 i=prepare(0,0); /* at moment not really a hassle check, but ... */
4958 if (i!=0)
4959 msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
4960 #endif FUTURE
4962 if (!st_spinning) cc_SpinUp();
4964 for (data_tries=n_retries; data_tries > 0; data_tries--)
4966 for (status_tries=3; status_tries > 0; status_tries--)
4968 flags_cmd_out |= f_respo3;
4969 cc_ReadStatus();
4970 if (sbp_status() != 0) break;
4971 if (st_check) cc_ReadError();
4972 sbp_sleep(1); /* wait a bit, try again */
4974 if (status_tries == 0)
4976 msg(DBG_INF,"sbp_status: failed after 3 tries in line %d\n", __LINE__);
4977 break;
4980 sbp_read_cmd(req);
4981 sbp_sleep(0);
4982 if (sbp_data(req) != 0)
4984 #if SAFE_MIXED
4985 D_S[d].has_data=2; /* is really a data disk */
4986 #endif SAFE_MIXED
4987 #ifdef DEBUG_GTL
4988 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
4989 xnr, req, req->sector, req->nr_sectors, jiffies);
4990 #endif
4991 up(&ioctl_read_sem);
4992 spin_lock_irq(&io_request_lock);
4993 sbpcd_end_request(req, 1);
4994 goto request_loop;
4998 err_done:
4999 #if OLD_BUSY
5000 busy_data=0;
5001 #endif OLD_BUSY
5002 #ifdef DEBUG_GTL
5003 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 4 (error), Time:%li\n",
5004 xnr, req, req->sector, req->nr_sectors, jiffies);
5005 #endif
5006 up(&ioctl_read_sem);
5007 sbp_sleep(0); /* wait a bit, try again */
5008 spin_lock_irq(&io_request_lock);
5009 sbpcd_end_request(req, 0);
5010 goto request_loop;
5012 /*==========================================================================*/
5014 * build and send the READ command.
5016 static void sbp_read_cmd(struct request *req)
5018 #undef OLD
5020 int i;
5021 int block;
5023 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1; /* purge buffer */
5024 D_S[d].sbp_current = 0;
5025 block=req->sector/4;
5026 if (block+D_S[d].sbp_bufsiz <= D_S[d].CDsize_frm)
5027 D_S[d].sbp_read_frames = D_S[d].sbp_bufsiz;
5028 else
5030 D_S[d].sbp_read_frames=D_S[d].CDsize_frm-block;
5031 /* avoid reading past end of data */
5032 if (D_S[d].sbp_read_frames < 1)
5034 msg(DBG_INF,"requested frame %d, CD size %d ???\n",
5035 block, D_S[d].CDsize_frm);
5036 D_S[d].sbp_read_frames=1;
5040 flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
5041 clr_cmdbuf();
5042 if (famV_drive)
5044 drvcmd[0]=CMDV_READ;
5045 lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
5046 bin2bcdx(&drvcmd[1]);
5047 bin2bcdx(&drvcmd[2]);
5048 bin2bcdx(&drvcmd[3]);
5049 drvcmd[4]=D_S[d].sbp_read_frames>>8;
5050 drvcmd[5]=D_S[d].sbp_read_frames&0xff;
5051 drvcmd[6]=0x02; /* flag "msf-bcd" */
5053 else if (fam0L_drive)
5055 flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
5056 if (D_S[d].xa_byte==0x20)
5058 cmd_type=READ_M2;
5059 drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
5060 drvcmd[1]=(block>>16)&0x0ff;
5061 drvcmd[2]=(block>>8)&0x0ff;
5062 drvcmd[3]=block&0x0ff;
5063 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5064 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
5066 else
5068 drvcmd[0]=CMD0_READ; /* "read frames", old drives */
5069 if (D_S[d].drv_type>=drv_201)
5071 lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
5072 bin2bcdx(&drvcmd[1]);
5073 bin2bcdx(&drvcmd[2]);
5074 bin2bcdx(&drvcmd[3]);
5076 else
5078 drvcmd[1]=(block>>16)&0x0ff;
5079 drvcmd[2]=(block>>8)&0x0ff;
5080 drvcmd[3]=block&0x0ff;
5082 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5083 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
5084 drvcmd[6]=(D_S[d].drv_type<drv_201)?0:2; /* flag "lba or msf-bcd format" */
5087 else if (fam1_drive)
5089 drvcmd[0]=CMD1_READ;
5090 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5091 drvcmd[5]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5092 drvcmd[6]=D_S[d].sbp_read_frames&0x0ff;
5094 else if (fam2_drive)
5096 drvcmd[0]=CMD2_READ;
5097 lba2msf(block,&drvcmd[1]); /* msf-bin format required */
5098 drvcmd[4]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5099 drvcmd[5]=D_S[d].sbp_read_frames&0x0ff;
5100 drvcmd[6]=0x02;
5102 else if (famT_drive)
5104 drvcmd[0]=CMDT_READ;
5105 drvcmd[2]=(block>>24)&0x0ff;
5106 drvcmd[3]=(block>>16)&0x0ff;
5107 drvcmd[4]=(block>>8)&0x0ff;
5108 drvcmd[5]=block&0x0ff;
5109 drvcmd[7]=(D_S[d].sbp_read_frames>>8)&0x0ff;
5110 drvcmd[8]=D_S[d].sbp_read_frames&0x0ff;
5112 flags_cmd_out=f_putcmd;
5113 response_count=0;
5114 i=cmd_out();
5115 if (i<0) msg(DBG_INF,"error giving READ command: %0d\n", i);
5116 return;
5118 /*==========================================================================*/
5120 * Check the completion of the read-data command. On success, read
5121 * the D_S[d].sbp_bufsiz * 2048 bytes of data from the disk into buffer.
5123 static int sbp_data(struct request *req)
5125 int i=0, j=0, l, frame;
5126 u_int try=0;
5127 u_long timeout;
5128 u_char *p;
5129 u_int data_tries = 0;
5130 u_int data_waits = 0;
5131 u_int data_retrying = 0;
5132 int error_flag;
5133 int xa_count;
5134 int max_latency;
5135 int success;
5136 int wait;
5137 int duration;
5139 error_flag=0;
5140 success=0;
5141 #if LONG_TIMING
5142 max_latency=9*HZ;
5143 #else
5144 if (D_S[d].f_multisession) max_latency=15*HZ;
5145 else max_latency=5*HZ;
5146 #endif
5147 duration=jiffies;
5148 for (frame=0;frame<D_S[d].sbp_read_frames&&!error_flag; frame++)
5150 SBPCD_CLI;
5152 del_timer(&data_timer);
5153 data_timer.expires=jiffies+max_latency;
5154 timed_out_data=0;
5155 add_timer(&data_timer);
5156 while (!timed_out_data)
5158 if (D_S[d].f_multisession) try=maxtim_data*4;
5159 else try=maxtim_data;
5160 msg(DBG_000,"sbp_data: CDi_status loop: try=%d.\n",try);
5161 for ( ; try!=0;try--)
5163 j=inb(CDi_status);
5164 if (!(j&s_not_data_ready)) break;;
5165 if (!(j&s_not_result_ready)) break;
5166 if (fam0LV_drive) if (j&s_attention) break;
5168 if (!(j&s_not_data_ready)) goto data_ready;
5169 if (try==0)
5171 if (data_retrying == 0) data_waits++;
5172 data_retrying = 1;
5173 msg(DBG_000,"sbp_data: CDi_status loop: sleeping.\n");
5174 sbp_sleep(1);
5175 try = 1;
5178 msg(DBG_INF,"sbp_data: CDi_status loop expired.\n");
5179 data_ready:
5180 del_timer(&data_timer);
5182 if (timed_out_data)
5184 msg(DBG_INF,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j);
5185 error_flag++;
5187 if (try==0)
5189 msg(DBG_INF,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j);
5190 error_flag++;
5192 if (!(j&s_not_result_ready))
5194 msg(DBG_INF, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j);
5195 response_count=20;
5196 j=ResponseInfo();
5197 j=inb(CDi_status);
5199 if (j&s_not_data_ready)
5201 if ((D_S[d].ored_ctl_adr&0x40)==0)
5202 msg(DBG_INF, "CD contains no data tracks.\n");
5203 else msg(DBG_INF, "sbp_data: DATA_READY timeout (%02X).\n", j);
5204 error_flag++;
5206 SBPCD_STI;
5207 if (error_flag) break;
5209 msg(DBG_000, "sbp_data: beginning to read.\n");
5210 p = D_S[d].sbp_buf + frame * CD_FRAMESIZE;
5211 if (sbpro_type==1) OUT(CDo_sel_i_d,1);
5212 if (cmd_type==READ_M2) {
5213 if (do_16bit) insw(CDi_data, xa_head_buf, CD_XA_HEAD>>1);
5214 else insb(CDi_data, xa_head_buf, CD_XA_HEAD);
5216 if (do_16bit) insw(CDi_data, p, CD_FRAMESIZE>>1);
5217 else insb(CDi_data, p, CD_FRAMESIZE);
5218 if (cmd_type==READ_M2) {
5219 if (do_16bit) insw(CDi_data, xa_tail_buf, CD_XA_TAIL>>1);
5220 else insb(CDi_data, xa_tail_buf, CD_XA_TAIL);
5222 D_S[d].sbp_current++;
5223 if (sbpro_type==1) OUT(CDo_sel_i_d,0);
5224 if (cmd_type==READ_M2)
5226 for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
5227 sprintf(&msgbuf[xa_count*3], " %02X", xa_head_buf[xa_count]);
5228 msgbuf[xa_count*3]=0;
5229 msg(DBG_XA1,"xa head:%s\n", msgbuf);
5231 data_retrying = 0;
5232 data_tries++;
5233 if (data_tries >= 1000)
5235 msg(DBG_INF,"sbp_data() statistics: %d waits in %d frames.\n", data_waits, data_tries);
5236 data_waits = data_tries = 0;
5239 duration=jiffies-duration;
5240 msg(DBG_TEA,"time to read %d frames: %d jiffies .\n",frame,duration);
5241 if (famT_drive)
5243 wait=8;
5246 if (teac==2)
5248 if ((i=CDi_stat_loop_T()) == -1) break;
5250 else
5252 sbp_sleep(1);
5253 OUT(CDo_sel_i_d,0);
5254 i=inb(CDi_status);
5256 if (!(i&s_not_data_ready))
5258 OUT(CDo_sel_i_d,1);
5259 j=0;
5262 if (do_16bit) i=inw(CDi_data);
5263 else i=inb(CDi_data);
5264 j++;
5265 i=inb(CDi_status);
5267 while (!(i&s_not_data_ready));
5268 msg(DBG_TEA, "==========too much data (%d bytes/words)==============.\n", j);
5270 if (!(i&s_not_result_ready))
5272 OUT(CDo_sel_i_d,0);
5273 l=0;
5276 infobuf[l++]=inb(CDi_info);
5277 i=inb(CDi_status);
5279 while (!(i&s_not_result_ready));
5280 if (infobuf[0]==0x00) success=1;
5281 #if 1
5282 for (j=0;j<l;j++) sprintf(&msgbuf[j*3], " %02X", infobuf[j]);
5283 msgbuf[j*3]=0;
5284 msg(DBG_TEA,"sbp_data info response:%s\n", msgbuf);
5285 #endif
5286 if (infobuf[0]==0x02)
5288 error_flag++;
5291 ++recursion;
5292 if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion);
5293 else msg(DBG_TEA,"sbp_data: CMDT_READ_ERR necessary.\n");
5294 clr_cmdbuf();
5295 drvcmd[0]=CMDT_READ_ERR;
5296 j=cmd_out_T(); /* !!! recursive here !!! */
5297 --recursion;
5298 sbp_sleep(1);
5300 while (j<0);
5301 D_S[d].error_state=infobuf[2];
5302 D_S[d].b3=infobuf[3];
5303 D_S[d].b4=infobuf[4];
5305 break;
5307 else
5309 #if 0
5310 msg(DBG_TEA, "============= waiting for result=================.\n");
5311 sbp_sleep(1);
5312 #endif
5315 while (wait--);
5318 if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
5320 msg(DBG_TEA, "================error flag: %d=================.\n", error_flag);
5321 msg(DBG_INF,"sbp_data: read aborted by drive.\n");
5322 #if 1
5323 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5324 #else
5325 i=cc_ReadError();
5326 #endif
5327 return (0);
5330 if (fam0LV_drive)
5332 SBPCD_CLI;
5333 i=maxtim_data;
5334 for (timeout=jiffies+HZ; time_before(jiffies, timeout); timeout--)
5336 for ( ;i!=0;i--)
5338 j=inb(CDi_status);
5339 if (!(j&s_not_data_ready)) break;
5340 if (!(j&s_not_result_ready)) break;
5341 if (j&s_attention) break;
5343 if (i != 0 || time_after_eq(jiffies, timeout)) break;
5344 sbp_sleep(0);
5345 i = 1;
5347 if (i==0) msg(DBG_INF,"status timeout after READ.\n");
5348 if (!(j&s_attention))
5350 msg(DBG_INF,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
5351 i=cc_DriveReset(); /* ugly fix to prevent a hang */
5352 SBPCD_STI;
5353 return (0);
5355 SBPCD_STI;
5358 #if 0
5359 if (!success)
5360 #endif 0
5363 if (fam0LV_drive) cc_ReadStatus();
5364 #if 1
5365 if (famT_drive) msg(DBG_TEA, "================before ResponseStatus=================.\n", i);
5366 #endif 1
5367 i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
5368 #if 1
5369 if (famT_drive) msg(DBG_TEA, "================ResponseStatus: %d=================.\n", i);
5370 #endif 1
5371 if (i<0)
5373 msg(DBG_INF,"bad cc_ReadStatus after read: %02X\n", D_S[d].status_bits);
5374 return (0);
5377 while ((fam0LV_drive)&&(!st_check)&&(!(i&p_success)));
5378 if (st_check)
5380 i=cc_ReadError();
5381 msg(DBG_INF,"cc_ReadError was necessary after read: %d\n",i);
5382 return (0);
5384 if (fatal_err)
5386 fatal_err=0;
5387 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1; /* purge buffer */
5388 D_S[d].sbp_current = 0;
5389 msg(DBG_INF,"sbp_data: fatal_err - retrying.\n");
5390 return (0);
5393 D_S[d].sbp_first_frame = req -> sector / 4;
5394 D_S[d].sbp_last_frame = D_S[d].sbp_first_frame + D_S[d].sbp_read_frames - 1;
5395 sbp_transfer(req);
5396 return (1);
5398 /*==========================================================================*/
5399 /*==========================================================================*/
5401 * Open the device special file. Check that a disk is in. Read TOC.
5403 static int sbpcd_open(struct cdrom_device_info *cdi, int purpose)
5405 int i;
5407 i = MINOR(cdi->dev);
5409 MOD_INC_USE_COUNT;
5410 down(&ioctl_read_sem);
5411 switch_drive(i);
5414 * try to keep an "open" counter here and lock the door if 0->1.
5416 msg(DBG_LCK,"open_count: %d -> %d\n",
5417 D_S[d].open_count,D_S[d].open_count+1);
5418 if (++D_S[d].open_count<=1)
5420 i=LockDoor();
5421 D_S[d].open_count=1;
5422 if (famT_drive) msg(DBG_TEA,"sbpcd_open: before i=DiskInfo();.\n");
5423 i=DiskInfo();
5424 if (famT_drive) msg(DBG_TEA,"sbpcd_open: after i=DiskInfo();.\n");
5425 if ((D_S[d].ored_ctl_adr&0x40)==0)
5427 msg(DBG_INF,"CD contains no data tracks.\n");
5428 #if SAFE_MIXED
5429 D_S[d].has_data=0;
5430 #endif SAFE_MIXED
5432 #if SAFE_MIXED
5433 else if (D_S[d].has_data<1) D_S[d].has_data=1;
5434 #endif SAFE_MIXED
5436 if (!st_spinning) cc_SpinUp();
5437 RETURN_UP(0);
5439 /*==========================================================================*/
5441 * On close, we flush all sbp blocks from the buffer cache.
5443 static void sbpcd_release(struct cdrom_device_info * cdi)
5445 int i;
5447 i = MINOR(cdi->dev);
5448 if ((i<0) || (i>=NR_SBPCD) || (D_S[i].drv_id==-1))
5450 msg(DBG_INF, "release: bad device: %04X\n", cdi->dev);
5451 return ;
5453 down(&ioctl_read_sem);
5454 switch_drive(i);
5456 * try to keep an "open" counter here and unlock the door if 1->0.
5458 msg(DBG_LCK,"open_count: %d -> %d\n",
5459 D_S[d].open_count,D_S[d].open_count-1);
5460 if (D_S[d].open_count>-2) /* CDROMEJECT may have been done */
5462 if (--D_S[d].open_count<=0)
5464 D_S[d].sbp_first_frame=D_S[d].sbp_last_frame=-1;
5465 invalidate_buffers(cdi->dev);
5466 if (D_S[d].audio_state!=audio_playing)
5467 if (D_S[d].f_eject) cc_SpinDown();
5468 D_S[d].diskstate_flags &= ~cd_size_bit;
5469 D_S[d].open_count=0;
5470 #if SAFE_MIXED
5471 D_S[d].has_data=0;
5472 #endif SAFE_MIXED
5475 up(&ioctl_read_sem);
5476 MOD_DEC_USE_COUNT;
5477 return ;
5479 /*==========================================================================*/
5483 static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr);
5484 static struct cdrom_device_ops sbpcd_dops = {
5485 open: sbpcd_open,
5486 release: sbpcd_release,
5487 drive_status: sbpcd_drive_status,
5488 media_changed: sbpcd_media_changed,
5489 tray_move: sbpcd_tray_move,
5490 lock_door: sbpcd_lock_door,
5491 select_speed: sbpcd_select_speed,
5492 get_last_session: sbpcd_get_last_session,
5493 get_mcn: sbpcd_get_mcn,
5494 reset: sbpcd_reset,
5495 audio_ioctl: sbpcd_audio_ioctl,
5496 dev_ioctl: sbpcd_dev_ioctl,
5497 capability: CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
5498 CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
5499 CDC_MCN | CDC_PLAY_AUDIO | CDC_IOCTLS,
5500 n_minors: 1,
5503 static struct cdrom_device_info sbpcd_info = {
5504 ops: &sbpcd_dops,
5505 speed: 2,
5506 capacity: 1,
5507 name: "sbpcd",
5510 /*==========================================================================*/
5512 * accept "kernel command line" parameters
5513 * (suggested by Peter MacDonald with SLS 1.03)
5515 * This is only implemented for the first controller. Should be enough to
5516 * allow installing with a "strange" distribution kernel.
5518 * use: tell LILO:
5519 * sbpcd=0x230,SoundBlaster
5520 * or
5521 * sbpcd=0x300,LaserMate
5522 * or
5523 * sbpcd=0x338,SoundScape
5524 * or
5525 * sbpcd=0x2C0,Teac16bit
5527 * (upper/lower case sensitive here - but all-lowercase is ok!!!).
5529 * the address value has to be the CDROM PORT ADDRESS -
5530 * not the soundcard base address.
5531 * For the SPEA/SoundScape setup, DO NOT specify the "configuration port"
5532 * address, but the address which is really used for the CDROM (usually 8
5533 * bytes above).
5537 #if (SBPCD_ISSUE-1)
5538 static int sbpcd_setup(char *s)
5539 #else
5540 int sbpcd_setup(char *s)
5541 #endif
5543 int p[4];
5544 (void)get_options(s, ARRAY_SIZE(p), p);
5545 setup_done++;
5546 msg(DBG_INI,"sbpcd_setup called with %04X,%s\n",p[1], s);
5547 sbpro_type=0; /* default: "LaserMate" */
5548 if (p[0]>1) sbpro_type=p[2];
5549 else if (!strcmp(s,str_sb)) sbpro_type=1;
5550 else if (!strcmp(s,str_sb_l)) sbpro_type=1;
5551 else if (!strcmp(s,str_sp)) sbpro_type=2;
5552 else if (!strcmp(s,str_sp_l)) sbpro_type=2;
5553 else if (!strcmp(s,str_ss)) sbpro_type=2;
5554 else if (!strcmp(s,str_ss_l)) sbpro_type=2;
5555 else if (!strcmp(s,str_t16)) sbpro_type=3;
5556 else if (!strcmp(s,str_t16_l)) sbpro_type=3;
5557 if (p[0]>0) sbpcd_ioaddr=p[1];
5559 CDo_command=sbpcd_ioaddr;
5560 CDi_info=sbpcd_ioaddr;
5561 CDi_status=sbpcd_ioaddr+1;
5562 CDo_sel_i_d=sbpcd_ioaddr+1;
5563 CDo_reset=sbpcd_ioaddr+2;
5564 CDo_enable=sbpcd_ioaddr+3;
5565 f_16bit=0;
5566 if ((sbpro_type==1)||(sbpro_type==3))
5568 CDi_data=sbpcd_ioaddr;
5569 if (sbpro_type==3)
5571 f_16bit=1;
5572 sbpro_type=1;
5575 else CDi_data=sbpcd_ioaddr+2;
5577 return 1;
5580 __setup("sbpcd=", sbpcd_setup);
5583 /*==========================================================================*/
5585 * Sequoia S-1000 CD-ROM Interface Configuration
5586 * as used within SPEA Media FX, Ensonic SoundScape and some Reveal cards
5587 * The soundcard has to get jumpered for the interface type "Panasonic"
5588 * (not Sony or Mitsumi) and to get soft-configured for
5589 * -> configuration port address
5590 * -> CDROM port offset (num_ports): has to be 8 here. Possibly this
5591 * offset value determines the interface type (none, Panasonic,
5592 * Mitsumi, Sony).
5593 * The interface uses a configuration port (0x320, 0x330, 0x340, 0x350)
5594 * some bytes below the real CDROM address.
5596 * For the Panasonic style (LaserMate) interface and the configuration
5597 * port 0x330, we have to use an offset of 8; so, the real CDROM port
5598 * address is 0x338.
5600 static int __init config_spea(void)
5603 * base address offset between configuration port and CDROM port,
5604 * this probably defines the interface type
5605 * 2 (type=??): 0x00
5606 * 8 (type=LaserMate):0x10
5607 * 16 (type=??):0x20
5608 * 32 (type=??):0x30
5610 int n_ports=0x10;
5612 int irq_number=0; /* off:0x00, 2/9:0x01, 7:0x03, 12:0x05, 15:0x07 */
5613 int dma_channel=0; /* off: 0x00, 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68 */
5614 int dack_polarity=0; /* L:0x00, H:0x80 */
5615 int drq_polarity=0x40; /* L:0x00, H:0x40 */
5616 int i;
5618 #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
5619 #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
5621 OUT(SPEA_REG_1,0xFF);
5622 i=inb(SPEA_REG_1);
5623 if (i!=0x0F)
5625 msg(DBG_SEQ,"no SPEA interface at %04X present.\n", sbpcd_ioaddr);
5626 return (-1); /* no interface found */
5628 OUT(SPEA_REG_1,0x04);
5629 OUT(SPEA_REG_2,0xC0);
5631 OUT(SPEA_REG_1,0x05);
5632 OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
5634 #if 1
5635 #define SPEA_PATTERN 0x80
5636 #else
5637 #define SPEA_PATTERN 0x00
5638 #endif
5639 OUT(SPEA_REG_1,0x06);
5640 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5641 OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
5643 OUT(SPEA_REG_1,0x09);
5644 i=(inb(SPEA_REG_2)&0xCF)|n_ports;
5645 OUT(SPEA_REG_2,i);
5647 sbpro_type = 0; /* acts like a LaserMate interface now */
5648 msg(DBG_SEQ,"found SoundScape interface at %04X.\n", sbpcd_ioaddr);
5649 return (0);
5651 /*==========================================================================*/
5653 * Test for presence of drive and initialize it.
5654 * Called once at boot or load time.
5657 static devfs_handle_t devfs_handle = NULL;
5659 #ifdef MODULE
5660 int __init __SBPCD_INIT(void)
5661 #else
5662 int __init SBPCD_INIT(void)
5663 #endif MODULE
5665 char nbuff[16];
5666 int i=0, j=0;
5667 int addr[2]={1, CDROM_PORT};
5668 int port_index;
5670 sti();
5672 msg(DBG_INF,"sbpcd.c %s\n", VERSION);
5673 #ifndef MODULE
5674 #if DISTRIBUTION
5675 if (!setup_done)
5677 msg(DBG_INF,"Looking for Matsushita/Panasonic, CreativeLabs, Longshine, TEAC CD-ROM drives\n");
5678 msg(DBG_INF,"= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
5679 msg(DBG_INF,"Auto-Probing can cause a hang (f.e. touching an NE2000 card).\n");
5680 msg(DBG_INF,"If that happens, you have to reboot and use the\n");
5681 msg(DBG_INF,"LILO (kernel) command line feature like:\n");
5682 msg(DBG_INF," LILO boot: ... sbpcd=0x230,SoundBlaster\n");
5683 msg(DBG_INF,"or like:\n");
5684 msg(DBG_INF," LILO boot: ... sbpcd=0x300,LaserMate\n");
5685 msg(DBG_INF,"or like:\n");
5686 msg(DBG_INF," LILO boot: ... sbpcd=0x338,SoundScape\n");
5687 msg(DBG_INF,"with your REAL address.\n");
5688 msg(DBG_INF,"= = = = = = = = = = END of WARNING = = = = = == = = =\n");
5690 #endif DISTRIBUTION
5691 sbpcd[0]=sbpcd_ioaddr; /* possibly changed by kernel command line */
5692 sbpcd[1]=sbpro_type; /* possibly changed by kernel command line */
5693 #endif MODULE
5695 for (port_index=0;port_index<NUM_PROBE;port_index+=2)
5697 addr[1]=sbpcd[port_index];
5698 if (addr[1]==0) break;
5699 if (check_region(addr[1],4))
5701 msg(DBG_INF,"check_region: %03X is not free.\n",addr[1]);
5702 continue;
5704 if (sbpcd[port_index+1]==2) type=str_sp;
5705 else if (sbpcd[port_index+1]==1) type=str_sb;
5706 else if (sbpcd[port_index+1]==3) type=str_t16;
5707 else type=str_lm;
5708 sbpcd_setup((char *)type);
5709 #if DISTRIBUTION
5710 msg(DBG_INF,"Scanning 0x%X (%s)...\n", CDo_command, type);
5711 #endif DISTRIBUTION
5712 if (sbpcd[port_index+1]==2)
5714 i=config_spea();
5715 if (i<0) continue;
5717 #ifdef PATH_CHECK
5718 if (check_card(addr[1])) continue;
5719 #endif PATH_CHECK
5720 i=check_drives();
5721 msg(DBG_INI,"check_drives done.\n");
5722 if (i>=0) break; /* drive found */
5723 } /* end of cycling through the set of possible I/O port addresses */
5725 if (ndrives==0)
5727 msg(DBG_INF, "No drive found.\n");
5728 #ifdef MODULE
5729 return -EIO;
5730 #else
5731 goto init_done;
5732 #endif MODULE
5735 if (port_index>0)
5737 msg(DBG_INF, "You should read linux/Documentation/cdrom/sbpcd\n");
5738 msg(DBG_INF, "and then configure sbpcd.h for your hardware.\n");
5740 check_datarate();
5741 msg(DBG_INI,"check_datarate done.\n");
5743 for (j=0;j<NR_SBPCD;j++)
5745 if (D_S[j].drv_id==-1) continue;
5746 switch_drive(j);
5747 #if 1
5748 if (!famL_drive) cc_DriveReset();
5749 #endif 0
5750 if (!st_spinning) cc_SpinUp();
5751 D_S[j].sbp_first_frame = -1; /* First frame in buffer */
5752 D_S[j].sbp_last_frame = -1; /* Last frame in buffer */
5753 D_S[j].sbp_read_frames = 0; /* Number of frames being read to buffer */
5754 D_S[j].sbp_current = 0; /* Frame being currently read */
5755 D_S[j].CD_changed=1;
5756 D_S[j].frame_size=CD_FRAMESIZE;
5757 D_S[j].f_eject=0;
5758 #if EJECT
5759 if (!fam0_drive) D_S[j].f_eject=1;
5760 #endif EJECT
5761 cc_ReadStatus();
5762 i=ResponseStatus(); /* returns orig. status or p_busy_new */
5763 if (famT_drive) i=ResponseStatus(); /* returns orig. status or p_busy_new */
5764 if (i<0)
5766 if (i!=-402)
5767 msg(DBG_INF,"init: ResponseStatus returns %d.\n",i);
5769 else
5771 if (st_check)
5773 i=cc_ReadError();
5774 msg(DBG_INI,"init: cc_ReadError returns %d\n",i);
5777 msg(DBG_INI,"init: first GetStatus: %d\n",i);
5778 msg(DBG_LCS,"init: first GetStatus: error_byte=%d\n",
5779 D_S[j].error_byte);
5780 if (D_S[j].error_byte==aud_12)
5782 timeout=jiffies+2*HZ;
5785 i=GetStatus();
5786 msg(DBG_INI,"init: second GetStatus: %02X\n",i);
5787 msg(DBG_LCS,
5788 "init: second GetStatus: error_byte=%d\n",
5789 D_S[j].error_byte);
5790 if (i<0) break;
5791 if (!st_caddy_in) break;
5793 while ((!st_diskok)||time_after(jiffies, timeout));
5795 i=SetSpeed();
5796 if (i>=0) D_S[j].CD_changed=1;
5800 * Turn on the CD audio channels.
5801 * The addresses are obtained from SOUND_BASE (see sbpcd.h).
5803 #if SOUND_BASE
5804 OUT(MIXER_addr,MIXER_CD_Volume); /* select SB Pro mixer register */
5805 OUT(MIXER_data,0xCC); /* one nibble per channel, max. value: 0xFF */
5806 #endif SOUND_BASE
5808 if (devfs_register_blkdev(MAJOR_NR, major_name, &cdrom_fops) != 0)
5810 msg(DBG_INF, "Can't get MAJOR %d for Matsushita CDROM\n", MAJOR_NR);
5811 #ifdef MODULE
5812 return -EIO;
5813 #else
5814 goto init_done;
5815 #endif MODULE
5817 blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), DEVICE_REQUEST);
5818 blk_queue_headactive(BLK_DEFAULT_QUEUE(MAJOR_NR), 0);
5819 read_ahead[MAJOR_NR] = buffers * (CD_FRAMESIZE / 512);
5821 request_region(CDo_command,4,major_name);
5823 devfs_handle = devfs_mk_dir (NULL, "sbp", NULL);
5824 for (j=0;j<NR_SBPCD;j++)
5826 struct cdrom_device_info * sbpcd_infop;
5828 if (D_S[j].drv_id==-1) continue;
5829 switch_drive(j);
5830 #if SAFE_MIXED
5831 D_S[j].has_data=0;
5832 #endif SAFE_MIXED
5834 * allocate memory for the frame buffers
5836 D_S[j].aud_buf=NULL;
5837 D_S[j].sbp_audsiz=0;
5838 D_S[j].sbp_bufsiz=buffers;
5839 if (D_S[j].drv_type&drv_fam1)
5840 if (READ_AUDIO>0) D_S[j].sbp_audsiz=READ_AUDIO;
5841 D_S[j].sbp_buf=(u_char *) vmalloc(D_S[j].sbp_bufsiz*CD_FRAMESIZE);
5842 if (D_S[j].sbp_buf==NULL)
5844 msg(DBG_INF,"data buffer (%d frames) not available.\n",D_S[j].sbp_bufsiz);
5845 if ((devfs_unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
5847 printk("Can't unregister %s\n", major_name);
5849 release_region(CDo_command,4);
5850 blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
5851 return -EIO;
5853 #ifdef MODULE
5854 msg(DBG_INF,"data buffer size: %d frames.\n",buffers);
5855 #endif MODULE
5856 if (D_S[j].sbp_audsiz>0)
5858 D_S[j].aud_buf=(u_char *) vmalloc(D_S[j].sbp_audsiz*CD_FRAMESIZE_RAW);
5859 if (D_S[j].aud_buf==NULL) msg(DBG_INF,"audio buffer (%d frames) not available.\n",D_S[j].sbp_audsiz);
5860 else msg(DBG_INF,"audio buffer size: %d frames.\n",D_S[j].sbp_audsiz);
5862 sbpcd_infop = vmalloc(sizeof (struct cdrom_device_info));
5863 if (sbpcd_infop == NULL)
5865 release_region(CDo_command,4);
5866 blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
5867 return -ENOMEM;
5869 D_S[j].sbpcd_infop = sbpcd_infop;
5870 memcpy (sbpcd_infop, &sbpcd_info, sizeof(struct cdrom_device_info));
5871 sbpcd_infop->dev = MKDEV(MAJOR_NR, j);
5872 strncpy(sbpcd_infop->name,major_name, sizeof(sbpcd_infop->name));
5874 sprintf (nbuff, "c%dt%d/cd", SBPCD_ISSUE - 1, D_S[j].drv_id);
5875 sbpcd_infop->de =
5876 devfs_register (devfs_handle, nbuff, DEVFS_FL_DEFAULT,
5877 MAJOR_NR, j, S_IFBLK | S_IRUGO | S_IWUGO,
5878 &cdrom_fops, NULL);
5879 if (register_cdrom(sbpcd_infop))
5881 printk(" sbpcd: Unable to register with Uniform CD-ROm driver\n");
5884 * set the block size
5886 sbpcd_blocksizes[j]=CD_FRAMESIZE;
5888 blksize_size[MAJOR_NR]=sbpcd_blocksizes;
5890 #ifndef MODULE
5891 init_done:
5892 #if !(SBPCD_ISSUE-1)
5893 #ifdef CONFIG_SBPCD2
5894 sbpcd2_init();
5895 #endif CONFIG_SBPCD2
5896 #ifdef CONFIG_SBPCD3
5897 sbpcd3_init();
5898 #endif CONFIG_SBPCD3
5899 #ifdef CONFIG_SBPCD4
5900 sbpcd4_init();
5901 #endif CONFIG_SBPCD4
5902 #endif !(SBPCD_ISSUE-1)
5903 #endif MODULE
5904 return 0;
5906 /*==========================================================================*/
5907 #ifdef MODULE
5908 void sbpcd_exit(void)
5910 int j;
5912 if ((devfs_unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
5914 msg(DBG_INF, "What's that: can't unregister %s.\n", major_name);
5915 return;
5917 release_region(CDo_command,4);
5918 blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
5919 devfs_unregister (devfs_handle);
5920 for (j=0;j<NR_SBPCD;j++)
5922 if (D_S[j].drv_id==-1) continue;
5923 vfree(D_S[j].sbp_buf);
5924 if (D_S[j].sbp_audsiz>0) vfree(D_S[j].aud_buf);
5925 if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
5927 msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
5928 return;
5930 vfree(D_S[j].sbpcd_infop);
5932 msg(DBG_INF, "%s module released.\n", major_name);
5936 #ifdef MODULE
5937 module_init(__SBPCD_INIT) /*HACK!*/;
5938 #endif
5939 module_exit(sbpcd_exit);
5942 #endif MODULE
5943 /*==========================================================================*/
5945 * Check if the media has changed in the CD-ROM drive.
5946 * used externally (isofs/inode.c, fs/buffer.c)
5948 static int sbpcd_chk_disk_change(kdev_t full_dev)
5950 int i;
5952 msg(DBG_CHK,"media_check (%d) called\n", MINOR(full_dev));
5953 i=MINOR(full_dev);
5955 if (D_S[i].CD_changed==0xFF)
5957 D_S[i].CD_changed=0;
5958 msg(DBG_CHK,"medium changed (drive %d)\n", i);
5959 /* BUG! Should invalidate buffers! --AJK */
5960 invalidate_buffers(full_dev);
5961 D_S[d].diskstate_flags &= ~toc_bit;
5962 D_S[d].diskstate_flags &= ~cd_size_bit;
5963 #if SAFE_MIXED
5964 D_S[d].has_data=0;
5965 #endif SAFE_MIXED
5967 return (1);
5969 else
5970 return (0);
5973 static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr)
5975 return sbpcd_chk_disk_change(cdi->dev);
5977 /*==========================================================================*/
5979 * Overrides for Emacs so that we follow Linus's tabbing style.
5980 * Emacs will notice this stuff at the end of the file and automatically
5981 * adjust the settings for this buffer only. This must remain at the end
5982 * of the file.
5983 * ---------------------------------------------------------------------------
5984 * Local variables:
5985 * c-indent-level: 8
5986 * c-brace-imaginary-offset: 0
5987 * c-brace-offset: -8
5988 * c-argdecl-indent: 8
5989 * c-label-offset: -8
5990 * c-continued-statement-offset: 8
5991 * c-continued-brace-offset: 0
5992 * End: