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)
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.
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.
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
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).
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
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
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
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
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
198 * Started CD200 support. Drive detection should work, but nothing
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
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
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
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
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
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
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
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.
340 #define SBPCD_ISSUE 1
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>
363 #include <asm/uaccess.h>
365 #include <linux/config.h>
369 #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
372 #define MAJOR_NR MATSUSHITA_CDROM2_MAJOR /* second driver issue */
375 #define MAJOR_NR MATSUSHITA_CDROM3_MAJOR /* third driver issue */
378 #define MAJOR_NR MATSUSHITA_CDROM4_MAJOR /* fourth driver issue */
381 #include <linux/blk.h>
383 /*==========================================================================*/
385 * provisions for more than 1 driver issues
386 * currently up to 4 drivers, expandable
389 #define DO_SBPCD_REQUEST(a) do_sbpcd_request(a)
390 #define SBPCD_INIT(a) sbpcd_init(a)
393 #define DO_SBPCD_REQUEST(a) do_sbpcd2_request(a)
394 #define SBPCD_INIT(a) sbpcd2_init(a)
397 #define DO_SBPCD_REQUEST(a) do_sbpcd3_request(a)
398 #define SBPCD_INIT(a) sbpcd3_init(a)
401 #define DO_SBPCD_REQUEST(a) do_sbpcd4_request(a)
402 #define SBPCD_INIT(a) sbpcd4_init(a)
404 /*==========================================================================*/
406 #define SBPCD_CLI cli()
407 #define SBPCD_STI sti()
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
432 CDROM_PORT
, SBPRO
, /* probe with user's setup first */
434 0x230, 1, /* Soundblaster Pro and 16 (default) */
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" */
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 */
474 static int sbpcd
[] = {CDROM_PORT
, SBPRO
}; /* probe with user's setup only */
476 MODULE_PARM(sbpcd
, "2i");
478 #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
480 /*==========================================================================*/
482 * the external references:
486 extern int sbpcd2_init(void);
489 extern int sbpcd3_init(void);
492 extern int sbpcd4_init(void);
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
);
508 static void mark_timeout_audio(u_long
);
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
554 static int sbpcd_debug
= (1<<DBG_INF
);
556 static int sbpcd_debug
= 0 & ((1<<DBG_INF
) |
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
;
593 static const char *major_name
="sbpcd";
596 static const char *major_name
="sbpcd2";
599 static const char *major_name
="sbpcd3";
602 static const char *major_name
="sbpcd4";
605 /*==========================================================================*/
608 static DECLARE_WAIT_QUEUE_HEAD(sbp_waitq
);
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
];
632 static volatile u_char busy_data
=0;
633 static volatile u_char busy_audio
=0; /* true semaphores would be safer */
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;
640 static volatile u_char timed_out_audio
=0;
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;
648 static u_int maxtim_data
= 9000;
650 static u_int maxtim_data
= 3000;
653 static int n_retries
=6;
655 static int n_retries
=6;
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 */
670 char drv_id
; /* "jumpered" drive ID or -1 */
671 char drv_sel
; /* drive select lines bits */
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) */
691 u_char diskstate_flags
;
698 u_char f_multisession
;
702 int track_of_last_session
;
705 u_int pos_audio_start
;
711 #if 000 /* no supported drive has it */
717 u_char volume_control
; /* TEAC on/off bits */
724 u_char SubQ_whatisthis
;
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 */
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
;
746 u_char ored_ctl_adr
; /* to detect if CDROM contains data tracks */
749 u_char nixbyte
; /* em */
750 u_char ctl_adr
; /* 0x4x: data, 0x0x: audio */
752 u_char format
; /* em */ /* 0x00: lba, 0x01: msf */
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 */
762 u_char f_XA
; /* 1: XA */
763 u_char type_byte
; /* 0, 1, 3 */
768 struct cdrom_device_info
*sbpcd_infop
;
773 * drive space ends here (needed separate for each unit)
775 /*==========================================================================*/
777 unsigned long cli_sti
; /* for saving the processor flags */
779 /*==========================================================================*/
780 static struct timer_list delay_timer
= { function
: mark_timeout_delay
};
781 static struct timer_list data_timer
= { function
: mark_timeout_data
};
783 static struct timer_list audio_timer
= { function
: mark_timeout_audio
};
785 /*==========================================================================*/
789 static void msg(int level
, const char *fmt
, ...)
792 #define MSG_LEVEL KERN_NOTICE
794 #define MSG_LEVEL KERN_INFO
800 if (!(sbpcd_debug
&(1<<level
))) return;
803 if (msgnum
>99) msgnum
=0;
804 sprintf(buf
, MSG_LEVEL
"%s-%d [%02d]: ", major_name
, d
, msgnum
);
806 vsprintf(&buf
[18], fmt
, args
);
810 sbp_sleep(KLOGD_PAUSE
); /* else messages get lost */
814 /*==========================================================================*/
816 * DDI interface: runtime trace bit pattern maintenance
818 static int sbpcd_dbg_ioctl(unsigned long arg
, int level
)
823 sbpcd_debug
= DBG_INF
;
827 if (arg
>=128) sbpcd_debug
&= ~(1<<(arg
-128));
828 else sbpcd_debug
|= (1<<arg
);
832 /*==========================================================================*/
833 static void mark_timeout_delay(u_long i
)
837 msg(DBG_TIM
,"delay timer expired.\n");
840 /*==========================================================================*/
841 static void mark_timeout_data(u_long i
)
845 msg(DBG_TIM
,"data timer expired.\n");
848 /*==========================================================================*/
850 static void mark_timeout_audio(u_long i
)
854 msg(DBG_TIM
,"audio timer expired.\n");
858 /*==========================================================================*/
860 * Wait a little while (used for polling the drive).
862 static void sbp_sleep(u_int time
)
865 current
->state
= TASK_INTERRUPTIBLE
;
866 schedule_timeout(time
);
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
)
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
;
905 /*==========================================================================*/
906 static INLINE u_int
make16(u_char rh
, u_char 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
)
937 i
=(msf
.c
[2] * CD_SECS
+ msf
.c
[1]) * CD_FRAMES
+ msf
.c
[0] - CD_MSF_OFFSET
;
941 /*==========================================================================*/
943 * convert m-s-f_number (3 bytes only) to logical_block_address
945 static INLINE
int msf2lba(u_char
*msf
)
949 i
=(msf
[0] * CD_SECS
+ msf
[1]) * CD_FRAMES
+ msf
[2] - CD_MSF_OFFSET
;
953 /*==========================================================================*/
954 /* evaluate cc_ReadError code */
955 static int sta2err(int sta
)
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 */
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) */
984 if (sta
==0x12) return (-ERR_DISKCHANGE
); /* disk change (inserted) */
985 return (-602); /* drive not ready */
988 /*==========================================================================*/
989 static INLINE
void clr_cmdbuf(void)
993 for (i
=0;i
<10;i
++) drvcmd
[i
]=0;
996 /*==========================================================================*/
997 static void flush_status(void)
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)
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
);
1037 if (time_after(jiffies
, timeout_4
)) gear
++;
1038 msg(DBG_TEA
, "CDi_stat_loop_T: long sleep active.\n");
1042 if (time_after(jiffies
, timeout_3
)) gear
++;
1046 if (time_after(jiffies
, timeout_2
)) gear
++;
1050 if (time_after(jiffies
, timeout_1
)) gear
++;
1055 /*==========================================================================*/
1056 static int CDi_stat_loop(void)
1060 for(timeout
= jiffies
+ 10*HZ
, i
=maxtim_data
; time_before(jiffies
, timeout
); )
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
);
1072 msg(DBG_LCS
,"CDi_stat_loop failed in line %d\n", __LINE__
);
1075 /*==========================================================================*/
1077 /*==========================================================================*/
1078 static int tst_DataReady(void)
1083 if (i
&s_not_data_ready
) return (0);
1086 /*==========================================================================*/
1087 static int tst_ResultReady(void)
1092 if (i
&s_not_result_ready
) return (0);
1095 /*==========================================================================*/
1096 static int tst_Attention(void)
1101 if (i
&s_attention
) return (1);
1104 /*==========================================================================*/
1106 /*==========================================================================*/
1107 static int ResponseInfo(void)
1112 for (i
=0,timeout
=jiffies
+HZ
;i
<response_count
;i
++)
1114 for (j
=maxtim_data
; ; )
1119 if (!(st
&s_not_result_ready
)) break;
1121 if ((j
!=0)||time_after_eq(jiffies
, timeout
)) break;
1125 if (time_after_eq(jiffies
, timeout
)) break;
1126 infobuf
[i
]=inb(CDi_info
);
1129 while (!(inb(CDi_status
)&s_not_result_ready
))
1131 infobuf
[i
++]=inb(CDi_info
);
1134 if (j
>0) msg(DBG_INF
,"ResponseInfo: got %d trailing bytes.\n",j
);
1137 sprintf(&msgbuf
[j
*3]," %02X",infobuf
[j
]);
1139 msg(DBG_CMD
,"ResponseInfo:%s (%d,%d)\n",msgbuf
,response_count
,i
);
1141 if (j
>0) return (-j
);
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
;
1195 /*==========================================================================*/
1196 static int get_state_T(void)
1200 static int cmd_out_T(void);
1204 drvcmd
[0]=CMDT_STATUS
;
1206 if (i
>=0) i
=infobuf
[0];
1209 msg(DBG_TEA
,"get_state_T error %d\n", i
);
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;
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)
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
;
1259 if (!(i
&s_not_result_ready
)) break;
1261 if ((j
!=0)||time_after(jiffies
, timeout
)) break;
1268 if ((flags_cmd_out
& f_respo3
) == 0)
1269 msg(DBG_STA
,"ResponseStatus: timeout.\n");
1270 D_S
[d
].status_bits
=0;
1274 msg(DBG_STA
,"ResponseStatus: response %02X.\n", 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)
1284 msg(DBG_STA
,"giving cc_ReadStatus command\n");
1285 if (famT_drive
) return;
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);
1293 /*==========================================================================*/
1294 static int cc_ReadError(void)
1299 msg(DBG_ERR
,"giving cc_ReadError command.\n");
1302 drvcmd
[0]=CMD1_READ_ERR
;
1304 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
1306 else if (fam0LV_drive
)
1308 drvcmd
[0]=CMD0_READ_ERR
;
1311 flags_cmd_out
=f_putcmd
;
1313 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
;
1315 else if (fam2_drive
)
1317 drvcmd
[0]=CMD2_READ_ERR
;
1319 flags_cmd_out
=f_putcmd
;
1321 else if (famT_drive
)
1324 drvcmd
[0]=CMDT_READ_ERR
;
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;
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
;
1342 /*==========================================================================*/
1343 static int cmd_out_T(void)
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
;
1353 D_S
[d
].error_state
=0;
1356 D_S
[d
].f_drv_error
=0;
1357 for (i
=0;i
<10;i
++) sprintf(&msgbuf
[i
*3]," %02X",drvcmd
[i
]);
1359 msg(DBG_CMD
,"cmd_out_T:%s\n",msgbuf
);
1362 OUT(CDo_enable
,D_S
[d
].drv_sel
);
1365 if ((f_16bit
)&&(!(i
&0x80)))
1368 msg(DBG_TEA
,"cmd_out_T: do_16bit set.\n");
1370 if (!(i
&s_not_result_ready
))
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 */
1390 if ((i
=CDi_stat_loop_T()) == -1) break;
1399 if (!(i
&s_not_data_ready
)) /* f.e. CMDT_DISKINFO */
1402 if (drvcmd
[0]==CMDT_READ
) return (0); /* handled elsewhere */
1403 if (drvcmd
[0]==CMDT_DISKINFO
)
1411 infobuf
[l
++]=i
&0x0ff;
1414 if ((l
==2)&&(infobuf
[0]==0x0ff))
1416 infobuf
[0]=infobuf
[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
);
1425 while (!(i
&s_not_data_ready
));
1426 for (j
=0;j
<l
;j
++) sprintf(&msgbuf
[j
*3]," %02X",infobuf
[j
]);
1428 msg(DBG_CMD
,"cmd_out_T data response:%s\n", msgbuf
);
1432 msg(DBG_TEA
,"cmd_out_T: data response with cmd_%02X!\n",
1437 if (do_16bit
) i
=inw(CDi_data
);
1438 else i
=inb(CDi_data
);
1442 while (!(i
&s_not_data_ready
));
1443 msg(DBG_TEA
,"cmd_out_T: data response: discarded %d bytes/words.\n", j
);
1448 if (!(i
&s_not_result_ready
))
1451 if (drvcmd
[0]==CMDT_DISKINFO
) m
=l
;
1455 infobuf
[m
++]=inb(CDi_info
);
1458 while (!(i
&s_not_result_ready
));
1459 for (j
=0;j
<m
;j
++) sprintf(&msgbuf
[j
*3]," %02X",infobuf
[j
]);
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 */
1471 if (recursion
>1) msg(DBG_TEA
,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd
[0], recursion
);
1473 drvcmd
[0]=CMDT_READ_ERR
;
1474 j
=cmd_out_T(); /* !!! recursive here !!! */
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;
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;
1498 D_S
[d
].error_state
=2;
1501 /*==========================================================================*/
1502 static int cmd_out(void)
1506 if (famT_drive
) return(cmd_out_T());
1508 if (flags_cmd_out
&f_putcmd
)
1510 unsigned long flags
;
1512 sprintf(&msgbuf
[i
*3], " %02X", drvcmd
[i
]);
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)
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);
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
)
1535 if ((i
<0)||!(i
&s_attention
)) return (-8);
1537 if (!(flags_cmd_out
&f_getsta
)) goto LOC_229
;
1540 if (D_S
[d
].in_SpinUp
) msg(DBG_SPI
,"in_SpinUp: to cc_ReadStatus.\n");
1544 if (flags_cmd_out
&f_ResponseStatus
)
1546 if (D_S
[d
].in_SpinUp
) msg(DBG_SPI
,"in_SpinUp: to ResponseStatus.\n");
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
))
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
;
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");
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
);
1568 /*==========================================================================*/
1569 static int cc_Seek(u_int pos
, char f_blk_msf
)
1574 if (f_blk_msf
>1) return (-3);
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;
1583 flags_cmd_out
= f_putcmd
| f_respo2
| f_lopsta
| f_getsta
|
1584 f_ResponseStatus
| f_obey_p_check
| f_bit1
;
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;
1596 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
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;
1624 /*==========================================================================*/
1625 static int cc_SpinUp(void)
1629 msg(DBG_SPI
,"SpinUp.\n");
1630 D_S
[d
].in_SpinUp
= 1;
1634 drvcmd
[0]=CMD0_SPINUP
;
1636 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|
1637 f_ResponseStatus
|f_obey_p_check
|f_bit1
;
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 */
1659 D_S
[d
].in_SpinUp
= 0;
1662 /*==========================================================================*/
1663 static int cc_SpinDown(void)
1667 if (fam0_drive
) return (0);
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
;
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" */
1700 /*==========================================================================*/
1701 static int cc_get_mode_T(void)
1707 drvcmd
[0]=CMDT_GETMODE
;
1708 drvcmd
[4]=response_count
;
1712 /*==========================================================================*/
1713 static int cc_set_mode_T(void)
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
;
1732 /*==========================================================================*/
1733 static int cc_prep_mode_T(void)
1738 if (i
<0) return (i
);
1740 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
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];
1750 D_S
[d
].mode_xb_8
=infobuf
[8];
1751 D_S
[d
].delay
=0; /* 0, 1, 2, 3 */
1755 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
1757 msg(DBG_TEA
,"CMDT_GETMODE:%s\n", msgbuf
);
1760 /*==========================================================================*/
1761 static int cc_SetSpeed(u_char speed
, u_char x1
, u_char x2
)
1765 if (fam0LV_drive
) return (0);
1770 drvcmd
[0]=CMD1_SETMODE
;
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
)
1790 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
1792 else if (famT_drive
)
1799 /*==========================================================================*/
1800 static int cc_SetVolume(void)
1803 u_char channel0
,channel1
,volume0
,volume1
;
1804 u_char control0
,value0
,control1
,value1
;
1806 D_S
[d
].diskstate_flags
&= ~volume_bit
;
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
;
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))
1823 else if ((volume0
==0)&&(volume1
!=0))
1842 control0
=channel0
+1;
1843 control1
=channel1
+1;
1844 value0
=(volume0
>volume1
)?volume0
:volume1
;
1846 if (volume0
==0) control0
=0;
1847 if (volume1
==0) control1
=0;
1848 drvcmd
[0]=CMD1_SETMODE
;
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
;
1862 if (volume0
==0) control0
=0;
1863 if (volume1
==0) control1
=0;
1864 drvcmd
[0]=CMD2_SETMODE
;
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
;
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;
1896 value0
=(volume0
>volume1
)?volume0
:volume1
;
1897 if (D_S
[d
].drv_type
<drv_211
)
1908 if (channel0
==channel1
)
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
;
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;
1955 if (i
<0) return (i
);
1961 if (i
<0) return (i
);
1963 D_S
[d
].diskstate_flags
|= volume_bit
;
1966 /*==========================================================================*/
1967 static int GetStatus(void)
1971 if (famT_drive
) return (0);
1972 flags_cmd_out
=f_getsta
|f_ResponseStatus
|f_obey_p_check
;
1978 /*==========================================================================*/
1979 static int cc_DriveReset(void)
1983 msg(DBG_RES
,"cc_DriveReset called.\n");
1986 if (fam0LV_drive
) OUT(CDo_reset
,0x00);
1987 else if (fam1_drive
)
1989 drvcmd
[0]=CMD1_RESET
;
1990 flags_cmd_out
=f_putcmd
;
1993 else if (fam2_drive
)
1995 drvcmd
[0]=CMD2_RESET
;
1996 flags_cmd_out
=f_putcmd
;
1998 OUT(CDo_reset
,0x00);
2000 else if (famT_drive
)
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 */
2012 msg(DBG_TEA
, "================CMDT_RESET given=================.\n");
2020 if (D_S
[d
].error_byte
!=aud_12
) return -501;
2024 /*==========================================================================*/
2025 static int SetSpeed(void)
2029 if (!(D_S
[d
].drv_options
&(speed_auto
|speed_300
|speed_150
))) return (0);
2031 if (!(D_S
[d
].drv_options
&speed_auto
))
2034 if (!(D_S
[d
].drv_options
&speed_300
)) speed
=0;
2036 i
=cc_SetSpeed(speed
,0,0);
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
);
2049 return cc_SetSpeed(speed
== 2 ? speed_300
: speed_150
, 0, 0);
2052 /*==========================================================================*/
2053 static int DriveReset(void)
2058 if (i
<0) return (-22);
2062 if ((i
<0)&&(i
!=-ERR_DISKCHANGE
)) {
2063 return (-2); /* from sta2err */
2065 if (!st_caddy_in
) break;
2070 D_S
[d
].CD_changed
=1;
2072 if ((st_door_closed
) && (st_caddy_in
))
2075 if (i
<0) return (-23);
2080 static int sbpcd_reset(struct cdrom_device_info
*cdi
)
2082 int i
= MINOR(cdi
->dev
);
2087 return DriveReset();
2090 /*==========================================================================*/
2091 static int cc_PlayAudio(int pos_audio_start
,int pos_audio_end
)
2095 if (D_S
[d
].audio_state
==audio_playing
) return (-EINVAL
);
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;
2106 drvcmd
[4]=(n
>>16)&0x00FF;
2107 drvcmd
[5]=(n
>>8)&0x00FF;
2110 flags_cmd_out
= f_putcmd
| f_respo2
| f_lopsta
| f_getsta
|
2111 f_ResponseStatus
| f_obey_p_check
| f_wait_if_busy
;
2113 flags_cmd_out
= f_putcmd
;
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
;
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;
2151 /*==========================================================================*/
2152 static int cc_Pause_Resume(int pau_res
)
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;
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
;
2180 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|
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
;
2192 /*==========================================================================*/
2193 static int cc_LockDoor(char lock
)
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
);
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;
2219 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
2221 flags_cmd_out
=f_putcmd
;
2223 else if (famT_drive
)
2225 drvcmd
[0]=CMDT_LOCK_CTL
;
2226 if (lock
==1) drvcmd
[4]=0x01;
2229 msg(DBG_LCS
,"p_door_locked bit %d after\n", st_door_locked
);
2232 /*==========================================================================*/
2233 /*==========================================================================*/
2234 static int UnLockDoor(void)
2253 /*==========================================================================*/
2254 static int LockDoor(void)
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)
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
);
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
;
2306 drvcmd
[4]=0x03; /* "insert" */
2307 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
2309 else if (famLV_drive
)
2311 drvcmd
[0]=CMDL_TRAY_CTL
;
2313 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|
2314 f_ResponseStatus
|f_obey_p_check
|f_bit1
;
2316 flags_cmd_out
=f_putcmd
;
2318 else if (famT_drive
)
2320 drvcmd
[0]=CMDT_TRAY_CTL
;
2321 drvcmd
[4]=0x03; /* "insert" */
2324 msg(DBG_LCS
,"p_door_closed bit %d after\n", st_door_closed
);
2327 flags_cmd_out
|= f_respo2
;
2328 cc_ReadStatus(); /* command: give 1-byte status */
2330 if (famT_drive
&&(i
<0))
2341 msg(DBG_INF
,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i
);
2348 if (st_check
) i
=cc_ReadError();
2349 flags_cmd_out
|= f_respo2
;
2359 static int sbpcd_tray_move(struct cdrom_device_info
*cdi
, int position
)
2363 i
= MINOR(cdi
->dev
);
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) {
2373 retval
=cc_CloseTray();
2378 /*==========================================================================*/
2379 static int cc_ReadSubQ(void)
2383 D_S
[d
].diskstate_flags
&= ~subq_bit
;
2389 drvcmd
[0]=CMD1_READSUBQ
;
2390 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2393 else if (fam2_drive
)
2395 drvcmd
[0]=CMD2_READSUBQ
;
2398 flags_cmd_out
=f_putcmd
;
2401 else if (fam0LV_drive
)
2403 drvcmd
[0]=CMD0_READSUBQ
;
2406 flags_cmd_out
=f_putcmd
;
2408 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2411 else if (famT_drive
)
2414 drvcmd
[0]=CMDT_READSUBQ
;
2418 drvcmd
[8]=response_count
;
2421 if (i
<0) return (i
);
2422 for (i
=0;i
<response_count
;i
++)
2424 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
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;
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 */
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
;
2454 /*==========================================================================*/
2455 static int cc_ModeSense(void)
2459 if (fam2_drive
) return (0);
2460 if (famV_drive
) return (0);
2461 D_S
[d
].diskstate_flags
&= ~frame_size_bit
;
2466 drvcmd
[0]=CMD1_GETMODE
;
2467 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2469 else if (fam0L_drive
)
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
)
2479 drvcmd
[0]=CMDT_GETMODE
;
2480 drvcmd
[4]=response_count
;
2483 if (i
<0) return (i
);
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;
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
]);
2497 msg(DBG_XA1
,"cc_ModeSense:%s\n", msgbuf
);
2499 D_S
[d
].diskstate_flags
|= frame_size_bit
;
2502 /*==========================================================================*/
2503 /*==========================================================================*/
2504 static int cc_ModeSelect(int framesize
)
2508 if (fam2_drive
) return (0);
2509 if (famV_drive
) return (0);
2510 D_S
[d
].diskstate_flags
&= ~frame_size_bit
;
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
);
2521 drvcmd
[0]=CMD1_SETMODE
;
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
;
2532 drvcmd
[2]=(D_S
[d
].frame_size
>>8)&0xFF;
2533 drvcmd
[3]=D_S
[d
].frame_size
&0xFF;
2536 flags_cmd_out
=f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2538 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2540 else if (famT_drive
)
2546 if (i
<0) return (i
);
2547 D_S
[d
].diskstate_flags
|= frame_size_bit
;
2550 /*==========================================================================*/
2551 static int cc_GetVolume(void)
2560 if (famV_drive
) return (0);
2561 D_S
[d
].diskstate_flags
&= ~volume_bit
;
2565 drvcmd
[0]=CMD1_GETMODE
;
2568 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2570 else if (fam2_drive
)
2572 drvcmd
[0]=CMD2_GETMODE
;
2575 flags_cmd_out
=f_putcmd
;
2577 else if (fam0L_drive
)
2579 drvcmd
[0]=CMD0_GETMODE
;
2583 flags_cmd_out
=f_putcmd
;
2585 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2587 else if (famT_drive
)
2590 if (i
<0) return (i
);
2595 if (i
<0) return (i
);
2599 chan0
=infobuf
[1]&0x0F;
2601 chan1
=infobuf
[3]&0x0F;
2616 else if (fam2_drive
)
2623 else if (famL_drive
)
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 */
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;
2653 if ((vol0
&0x01)!=0) chan0
=1;
2654 if ((vol1
&0x01)==0) chan1
=0;
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];
2667 if (D_S
[d
].volume_control
&0x10) vol0
=0;
2669 if (D_S
[d
].volume_control
&0x20) vol1
=0;
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
;
2678 D_S
[d
].vol_ctrl2
=0xFF;
2680 D_S
[d
].vol_ctrl3
=0xFF;
2682 D_S
[d
].diskstate_flags
|= volume_bit
;
2685 /*==========================================================================*/
2686 static int cc_ReadCapacity(void)
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
;
2699 drvcmd
[0]=CMD1_CAPACITY
;
2701 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2704 else if (fam2_drive
)
2706 drvcmd
[0]=CMD2_CAPACITY
;
2708 flags_cmd_out
=f_putcmd
;
2711 else if (fam0_drive
)
2713 drvcmd
[0]=CMD0_CAPACITY
;
2715 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2719 msg(DBG_000
,"cc_ReadCapacity: cmd_out: err %d\n", i
);
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]));
2726 else if (fam2_drive
) D_S
[d
].CDsize_frm
=make32(make16(infobuf
[0],infobuf
[1]),make16(infobuf
[2],infobuf
[3]));
2728 D_S
[d
].diskstate_flags
|= cd_size_bit
;
2729 msg(DBG_000
,"cc_ReadCapacity: %d frames.\n", D_S
[d
].CDsize_frm
);
2732 /*==========================================================================*/
2733 static int cc_ReadTocDescr(void)
2737 D_S
[d
].diskstate_flags
&= ~toc_bit
;
2741 drvcmd
[0]=CMD1_DISKINFO
;
2743 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2745 else if (fam0LV_drive
)
2747 drvcmd
[0]=CMD0_DISKINFO
;
2750 flags_cmd_out
=f_putcmd
;
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
;
2761 drvcmd
[3]=0xFF; /* session */
2763 flags_cmd_out
=f_putcmd
;
2765 else if (famT_drive
)
2767 D_S
[d
].f_multisession
=0;
2769 drvcmd
[0]=CMDT_DISKINFO
;
2771 drvcmd
[6]=CDROM_LEADOUT
;
2772 drvcmd
[8]=response_count
;
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];
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])));
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;
2797 for (count
=D_S
[d
].first_session
;count
<zwanzig
;count
++)
2799 drvcmd
[0]=CMD2_DISKINFO
;
2804 flags_cmd_out
=f_putcmd
;
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
;
2812 drvcmd
[0]=CMD2_DISKINFO
;
2817 flags_cmd_out
=f_putcmd
;
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];
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",
2843 D_S
[d
].n_first_track
,
2844 D_S
[d
].n_last_track
,
2846 D_S
[d
].first_session
,
2847 D_S
[d
].last_session
);
2850 /*==========================================================================*/
2851 static int cc_ReadTocEntry(int num
)
2858 drvcmd
[0]=CMD1_READTOC
;
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
;
2870 flags_cmd_out
=f_putcmd
;
2872 else if (fam0LV_drive
)
2874 drvcmd
[0]=CMD0_READTOC
;
2879 flags_cmd_out
=f_putcmd
;
2881 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2883 else if (famT_drive
)
2886 drvcmd
[0]=CMDT_DISKINFO
;
2889 drvcmd
[8]=response_count
;
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];
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
];
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
]);
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
);
2929 /*==========================================================================*/
2930 static int cc_ReadPacket(void)
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
)
2948 /*==========================================================================*/
2949 static int convert_UPC(u_char
*p
)
2954 if (fam0L_drive
) p
[13]=0;
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
)
2972 D_S
[d
].UPC_buf
[6] &= 0xF0;
2975 /*==========================================================================*/
2976 static int cc_ReadUPC(void)
2980 int block
, checksum
;
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 */
2987 if (fam0_drive
) return (0); /* but it should work */
2990 D_S
[d
].diskstate_flags
&= ~upc_bit
;
2992 for (block
=CD_MSF_OFFSET
+1;block
<CD_MSF_OFFSET
+200;block
++)
2998 drvcmd
[0]=CMD1_READ_UPC
;
3000 drvcmd
[1]=(block
>>16)&0xFF;
3001 drvcmd
[2]=(block
>>8)&0xFF;
3002 drvcmd
[3]=block
&0xFF;
3005 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
3007 else if (fam0L_drive
)
3009 drvcmd
[0]=CMD0_READ_UPC
;
3011 drvcmd
[2]=(block
>>16)&0xFF;
3012 drvcmd
[3]=(block
>>8)&0xFF;
3013 drvcmd
[4]=block
&0xFF;
3016 flags_cmd_out
=f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
3018 else if (fam2_drive
)
3022 else if (famT_drive
)
3029 msg(DBG_000
,"cc_ReadUPC cmd_out: err %d\n", i
);
3035 if (famL_drive
) flags_cmd_out
=f_putcmd
;
3039 msg(DBG_000
,"cc_ReadUPC ReadPacket: err %d\n", i
);
3046 for (i
=0;i
<(fam1_drive
?8:16);i
++)
3049 checksum
|= infobuf
[i
];
3051 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3054 msg(DBG_UPC
,"UPC info:%s\n", msgbuf
);
3056 if ((checksum
&0x7F)!=0) break;
3059 D_S
[d
].UPC_ctl_adr
=0;
3060 if (fam1_drive
) i
=0;
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;
3068 sprintf(&msgbuf
[i
*3], " %02X", D_S
[d
].UPC_buf
[i
]);
3069 sprintf(&msgbuf
[i
*3], " (%02X)", D_S
[d
].UPC_ctl_adr
);
3071 msg(DBG_UPC
,"UPC code:%s\n", msgbuf
);
3072 D_S
[d
].diskstate_flags
|= upc_bit
;
3076 static int sbpcd_get_mcn(struct cdrom_device_info
*cdi
, struct cdrom_mcn
*mcn
)
3079 unsigned char *mcnp
= mcn
->medium_catalog_number
;
3080 unsigned char *resp
;
3082 D_S
[d
].diskstate_flags
&= ~upc_bit
;
3086 drvcmd
[0]=CMD1_READ_UPC
;
3088 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
3090 else if (fam0L_drive
)
3092 drvcmd
[0]=CMD0_READ_UPC
;
3094 flags_cmd_out
=f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
3096 else if (fam2_drive
)
3100 else if (famT_drive
)
3107 msg(DBG_000
,"cc_ReadUPC cmd_out: err %d\n", i
);
3113 if (famL_drive
) flags_cmd_out
=f_putcmd
;
3117 msg(DBG_000
,"cc_ReadUPC ReadPacket: err %d\n", i
);
3121 D_S
[d
].UPC_ctl_adr
=0;
3122 if (fam1_drive
) i
=0;
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';
3144 D_S
[d
].diskstate_flags
|= upc_bit
;
3148 /*==========================================================================*/
3149 static int cc_CheckMultiSession(void)
3153 if (fam2_drive
) return (0);
3154 D_S
[d
].f_multisession
=0;
3156 if (fam0_drive
) return (0);
3160 drvcmd
[0]=CMD1_MULTISESS
;
3162 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
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
;
3178 flags_cmd_out
=f_putcmd
;
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
)
3187 drvcmd
[0]=CMDT_DISKINFO
;
3190 drvcmd
[8]=response_count
;
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
]);
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
);
3215 /*==========================================================================*/
3217 static int cc_SubChanInfo(int frame
, int count
, u_char
*buffer
)
3218 /* "frame" is a RED BOOK (msf-bin) address */
3222 if (fam0LV_drive
) return (-ENOSYS
); /* drive firmware lacks it */
3228 if (D_S
[d
].audio_state
!=audio_playing
) return (-ENODATA
);
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
;
3239 D_S
[d
].frame_size
=CD_FRAMESIZE_SUB
;
3240 i
=cmd_out(); /* which buffer to use? */
3244 /*==========================================================================*/
3245 static void __init
check_datarate(void)
3249 msg(DBG_IOX
,"check_datarate entered.\n");
3252 for (i
=0;i
<=1000;i
++) printk(".");
3254 /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
3256 del_timer(&delay_timer
);
3258 delay_timer
.expires
=jiffies
+11*HZ
/10;
3260 add_timer(&delay_timer
);
3262 msg(DBG_TIM
,"delay timer started (11*HZ/10).\n");
3269 if (datarate
>0x6FFFFFFF) break;
3272 while (!timed_out_delay
);
3273 del_timer(&delay_timer
);
3275 msg(DBG_TIM
,"datarate: %04X\n", datarate
);
3277 if (datarate
<65536) datarate
=65536;
3278 maxtim16
=datarate
*16;
3279 maxtim04
=datarate
*4;
3280 maxtim02
=datarate
*2;
3281 maxtim_8
=datarate
/32;
3283 maxtim_data
=datarate
/100;
3285 maxtim_data
=datarate
/300;
3288 msg(DBG_TIM
,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8
, maxtim_data
);
3291 /*==========================================================================*/
3293 static int c2_ReadError(int fam
)
3302 drvcmd
[0]=CMD0_READ_ERR
; /* same as CMD1_ and CMDL_ */
3303 i
=do_cmd(f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
);
3307 drvcmd
[0]=CMD2_READ_ERR
;
3314 /*==========================================================================*/
3315 static void __init
ask_mail(void)
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
);
3325 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3327 msg(DBG_INF
,"infobuf =%s\n", msgbuf
);
3329 sprintf(&msgbuf
[i
*3], " %c ", infobuf
[i
]);
3331 msg(DBG_INF
,"infobuf =%s\n", msgbuf
);
3333 /*==========================================================================*/
3334 static int __init
check_version(void)
3337 int teac_possible
=0;
3339 msg(DBG_INI
,"check_version: id=%d, d=%d.\n", D_S
[d
].drv_id
, d
);
3342 /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
3343 /* clear any pending error state */
3345 drvcmd
[0]=CMD0_READ_ERR
; /* same as CMD1_ and CMDL_ */
3347 flags_cmd_out
=f_putcmd
;
3349 if (i
<0) msg(DBG_INI
,"CMD0_READ_ERR returns %d (ok anyway).\n",i
);
3350 /* read drive version */
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
;
3357 if (i
<-1) msg(DBG_INI
,"CMD0_READ_VER returns %d\n",i
);
3358 if (i
==-11) teac_possible
++;
3360 for (i
=0;i
<12;i
++) j
+=infobuf
[i
];
3364 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3366 msg(DBG_ECS
,"infobuf =%s\n", msgbuf
);
3368 sprintf(&msgbuf
[i
*3], " %c ", infobuf
[i
]);
3370 msg(DBG_ECS
,"infobuf =%s\n", msgbuf
);
3372 for (i
=0;i
<4;i
++) if (infobuf
[i
]!=family1
[i
]) break;
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;
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;
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;
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 */
3426 drvcmd
[0]=CMD2_READ_ERR
;
3428 flags_cmd_out
=f_putcmd
;
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 */
3434 for (i
=0;i
<12;i
++) infobuf
[i
]=0;
3435 if (sbpro_type
==1) OUT(CDo_sel_i_d
,0);
3439 OUT(CDo_enable
,D_S
[d
].drv_sel
);
3441 drvcmd
[0]=CMD2_READ_VER
;
3443 flags_cmd_out
=f_putcmd
;
3445 if (i
<0) msg(DBG_INI
,"CMD2_READ_VER returns %d\n",i
);
3446 if (i
==-7) teac_possible
++;
3448 for (i
=0;i
<12;i
++) j
+=infobuf
[i
];
3452 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3454 msg(DBG_IDX
,"infobuf =%s\n", msgbuf
);
3456 sprintf(&msgbuf
[i
*3], " %c ", infobuf
[i
]);
3458 msg(DBG_IDX
,"infobuf =%s\n", msgbuf
);
3462 for (i
=0;i
<5;i
++) if (infobuf
[i
]!=family2
[i
]) break;
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);
3489 OUT(CDo_enable
,D_S
[d
].drv_sel
);
3491 OUT(CDo_command
,CMDT_RESET
);
3492 for (i
=0;i
<9;i
++) OUT(CDo_command
,0);
3495 OUT(CDo_enable
,D_S
[d
].drv_sel
);
3498 msg(DBG_TEA
,"TEAC CDi_status: %02X.\n",i
);
3500 if (i
&s_not_result_ready
) continue; /* drive not present or ready */
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");
3512 flags_cmd_out
=f_putcmd
;
3514 drvcmd
[0]=CMDT_READ_VER
;
3515 drvcmd
[4]=response_count
;
3516 for (i
=0;i
<12;i
++) infobuf
[i
]=0;
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;
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
);
3537 for (j
=0;j
<4;j
++) D_S
[d
].firmware_version
[j
]=infobuf
[i
+j
];
3540 u_char lcs_firm_e1
[]="A E1";
3541 u_char lcs_firm_f4
[]="A4F4";
3544 if (D_S
[d
].firmware_version
[j
]!=lcs_firm_e1
[j
]) break;
3545 if (j
==4) D_S
[d
].drv_type
=drv_e1
;
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 */
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];
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);
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
;
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 */
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");
3619 /*==========================================================================*/
3620 static void switch_drive(int 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
);
3627 /*==========================================================================*/
3630 * probe for the presence of an interface card
3632 static int __init
check_card(int port
)
3637 u_char response
[N_RESPO
];
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);
3660 for (i
=0;i
<N_RESPO
;i
++)
3661 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
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);
3676 for (i
=0;i
<N_RESPO
;i
++)
3677 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
3679 msg(DBG_TEA
,"path check 00 (%d): %s\n", j
, msgbuf
);
3681 if (response
[0]==0xAA)
3682 if (response
[1]==0x55)
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);
3700 for (i
=0;i
<N_RESPO
;i
++)
3701 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
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);
3717 for (i
=0;i
<N_RESPO
;i
++)
3718 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
3720 msg(DBG_TEA
,"path check 12 (%d): %s\n", j
, msgbuf
);
3722 if (response
[0]==0xAA)
3723 if (response
[1]==0x55)
3726 OUT(port
+0,save_port0
);
3727 OUT(port
+3,save_port3
);
3728 return (0); /* in any case - no real "function" at time */
3731 /*==========================================================================*/
3732 /*==========================================================================*/
3734 * probe for the presence of drives on the selected controller
3736 static int __init
check_drives(void)
3740 msg(DBG_INI
,"check_drives entered.\n");
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
);
3751 if (i
<0) msg(DBG_INI
,"check_version returns %d.\n",i
);
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",
3760 D_S
[d
].firmware_version
,
3766 for (j
=ndrives
;j
<NR_SBPCD
;j
++) D_S
[j
].drv_id
=-1;
3767 if (ndrives
==0) return (-1);
3770 /*==========================================================================*/
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" */
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 */
3788 case cmd_03
: /* ioctl input */
3790 /* DOS ioctl input subfunction */
3804 case aud_12
: /* "audio play paused" */
3811 /*==========================================================================*/
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
)
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);
3839 /*==========================================================================*/
3840 static int check_allowed2(u_char func1
, u_char func2
)
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);
3850 if (func2
==EjectDisk
) return (-1);
3851 if (func2
==CloseTray
) return (-1);
3857 /*==========================================================================*/
3858 static int check_allowed3(u_char func1
, u_char func2
)
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);
3871 if (func2
==DriveReset
) return (0);
3874 if (func2
==EjectDisk
) return (0);
3875 if (func2
==LockDoor
) return (0);
3876 if (func2
==CloseTray
) return (0);
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);
3891 /*==========================================================================*/
3892 static int seek_pos_audio_end(void)
3896 i
=msf2blk(D_S
[d
].pos_audio_end
)-1;
3897 if (i
<0) return (-1);
3902 /*==========================================================================*/
3903 static int ReadToC(void)
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;
3923 for (j
=D_S
[d
].n_first_track
;j
<=D_S
[d
].n_last_track
;j
++)
3925 i
=cc_ReadTocEntry(j
);
3928 msg(DBG_INF
,"cc_ReadTocEntry(%d) returns %d.\n",j
,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
;
3948 /*==========================================================================*/
3949 static int DiskInfo(void)
3953 D_S
[d
].mode
=READ_M1
;
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
++)
3965 msg(DBG_INF
,"DiskInfo: SetSpeed returns %d\n", i
);
3971 msg(DBG_INF
,"DiskInfo: cc_ModeSense returns %d\n", i
);
3975 i
=cc_ReadCapacity();
3977 msg(DBG_INF
,"DiskInfo: ReadCapacity #%d returns %d\n", j
, i
);
3981 if (!fam0_drive
&& j
== 2) break;
3983 if (j
==LOOP_COUNT
) return (-33); /* give up */
3985 i
=cc_ReadTocDescr();
3988 msg(DBG_INF
,"DiskInfo: ReadTocDescr returns %d\n", i
);
3994 msg(DBG_INF
,"DiskInfo: ReadToC returns %d\n", i
);
3997 i
=cc_CheckMultiSession();
4000 msg(DBG_INF
,"DiskInfo: cc_CheckMultiSession returns %d\n", 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
);
4008 msg(DBG_INF
,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i
);
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
);
4019 if (famT_drive
) cc_prep_mode_T();
4020 msg(DBG_000
,"DiskInfo done.\n");
4024 static int sbpcd_drive_status(struct cdrom_device_info
*cdi
, int slot_nr
)
4028 if (CDSL_CURRENT
!= slot_nr
) {
4029 /* we have no changer support */
4034 st
=ResponseStatus();
4037 msg(DBG_INF
,"sbpcd_drive_status: timeout.\n");
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
);
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
;
4054 if (D_S
[MINOR(cdi
->dev
)].status_bits
& p_spinning
) return CDS_DISC_OK
;
4055 /* return CDS_TRAY_OPEN; */
4063 /*==========================================================================*/
4066 * called always if driver gets entered
4067 * returns 0 or ERROR2 or ERROR15
4069 static int prepare(u_char func
, u_char subfunc
)
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;
4087 i
=check_allowed1(func
,subfunc
);
4088 if (i
<0) return (-2);
4092 i
=check_allowed3(func
,subfunc
);
4095 D_S
[d
].CD_changed
=1;
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);
4113 if (D_S
[d
].audio_state
!=audio_pausing
)
4115 i
=check_allowed2(func
,subfunc
);
4116 if (i
<0) return (-2);
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
)
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);
4140 /*==========================================================================*/
4141 /*==========================================================================*/
4143 * Check the results of the "get status" command.
4145 static int sbp_status(void)
4149 st
=ResponseStatus();
4152 msg(DBG_INF
,"sbp_status: timeout.\n");
4156 if (!st_spinning
) msg(DBG_SPI
,"motor got off - ignoring.\n");
4160 msg(DBG_INF
,"st_check detected - retrying.\n");
4163 if (!st_door_closed
)
4165 msg(DBG_INF
,"door is open - retrying.\n");
4170 msg(DBG_INF
,"disk removed - retrying.\n");
4175 msg(DBG_INF
,"!st_diskok detected - retrying.\n");
4180 msg(DBG_INF
,"st_busy detected - retrying.\n");
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 */
4194 ms_infp
->xa_flag
=0; /* invalid redirection address */
4199 /*==========================================================================*/
4200 /*==========================================================================*/
4204 static int sbpcd_dev_ioctl(struct cdrom_device_info
*cdi
, u_int cmd
,
4209 msg(DBG_IO2
,"ioctl(%d, 0x%08lX, 0x%08lX)\n",
4210 MINOR(cdi
->dev
), cmd
, arg
);
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);
4227 case CDROMRESET
: /* hard reset the drive */
4228 msg(DBG_IOC
,"ioctl: CDROMRESET entered.\n");
4230 D_S
[d
].audio_state
=0;
4233 case CDROMREADMODE1
:
4234 msg(DBG_IOC
,"ioctl: CDROMREADMODE1 requested.\n");
4236 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4238 cc_ModeSelect(CD_FRAMESIZE
);
4240 D_S
[d
].mode
=READ_M1
;
4243 case CDROMREADMODE2
: /* not usable at the moment */
4244 msg(DBG_IOC
,"ioctl: CDROMREADMODE2 requested.\n");
4246 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4248 cc_ModeSelect(CD_FRAMESIZE_RAW1
);
4250 D_S
[d
].mode
=READ_M2
;
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;
4277 u_int data_tries
= 0;
4278 u_int data_waits
= 0;
4279 u_int data_retrying
= 0;
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
);
4289 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
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
);
4306 i
=cc_SetSpeed(speed_150
,0,0);
4307 if (i
) msg(DBG_AUD
,"read_audio: SetSpeed error %d\n", i
);
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");
4313 while (busy_data
) sbp_sleep(HZ
/10); /* wait a bit */
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
);
4323 for (status_tries
=3; status_tries
> 0; status_tries
--)
4325 flags_cmd_out
|= f_respo3
;
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__
);
4336 msg(DBG_AUD
,"read_audio: sbp_status: ok.\n");
4338 flags_cmd_out
= f_putcmd
| f_respo2
| f_ResponseStatus
| f_obey_p_check
;
4341 flags_cmd_out
|= f_lopsta
| f_getsta
| f_bit1
;
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;
4348 drvcmd
[5]=read_audio
.nframes
; /* # of frames */
4351 else if (fam1_drive
)
4353 drvcmd
[0]=CMD1_READ
; /* "read frames", new drives */
4354 lba2msf(block
,&drvcmd
[1]); /* msf-bin format required */
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 */
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
;
4374 if (i
<0) msg(DBG_INF
,"error giving READ AUDIO command: %0d\n", i
);
4376 msg(DBG_AUD
,"read_audio: after giving \"read\" command.\n");
4377 for (frame
=1;frame
<2 && !error_flag
; frame
++)
4380 for (timeout
=jiffies
+9*HZ
; ; )
4382 for ( ; try!=0;try--)
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
++;
4397 msg(DBG_INF
,"read_audio: sbp_data: CDi_status timeout.\n");
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");
4408 msg(DBG_AUD
,"read_audio: before reading data.\n");
4411 if (sbpro_type
==1) OUT(CDo_sel_i_d
,1);
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
);
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);
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");
4444 i
=cc_DriveReset(); /* ugly fix to prevent a hang */
4453 for (timeout
=jiffies
+9*HZ
; time_before(jiffies
, timeout
); timeout
--)
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;
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 */
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
)));
4488 msg(DBG_AUD
,"read_audio: cc_ReadError was necessary after read: %02X\n",i
);
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");
4497 cc_ModeSelect(CD_FRAMESIZE
);
4499 D_S
[d
].mode
=READ_M1
;
4503 if (data_tries
== 0)
4505 msg(DBG_AUD
,"read_audio: failed after 5 tries in line %d.\n", __LINE__
);
4508 msg(DBG_AUD
,"read_audio: successful return.\n");
4510 } /* end of CDROMREADAUDIO */
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
;
4519 msg(DBG_IOC
,"ioctl: unknown function request %04X\n", cmd
);
4521 } /* end switch(cmd) */
4524 static int sbpcd_audio_ioctl(struct cdrom_device_info
*cdi
, u_int cmd
,
4529 msg(DBG_IO2
,"ioctl(%d, 0x%08lX, 0x%08p)\n",
4530 MINOR(cdi
->dev
), cmd
, arg
);
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
)
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
;
4563 i
=cc_Seek(D_S
[d
].pos_audio_start
,1);
4564 if (i
<0) RETURN_UP(-EIO
);
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
);
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
;
4585 msg(DBG_IOC
,"ioctl: CDROMPLAYMSF entered.\n");
4587 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4589 if (D_S
[d
].audio_state
==audio_playing
)
4591 i
=cc_Pause_Resume(1);
4592 if (i
<0) RETURN_UP(-EIO
);
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) |
4603 D_S
[d
].pos_audio_end
= (msf
.cdmsf_min1
<<16) |
4604 (msf
.cdmsf_sec1
<<8) |
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
);
4611 msg(DBG_INF
,"ioctl: cc_PlayAudio returns %d\n",i
);
4613 D_S
[d
].audio_state
=0;
4616 D_S
[d
].audio_state
=audio_playing
;
4619 case CDROMPLAYTRKIND
: /* Play a track. This currently ignores index. */
4620 msg(DBG_IOC
,"ioctl: CDROMPLAYTRKIND entered.\n");
4622 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4624 if (D_S
[d
].audio_state
==audio_playing
)
4626 msg(DBG_IOX
,"CDROMPLAYTRKIND: already audio_playing.\n");
4628 RETURN_UP(0); /* just let us play on */
4630 RETURN_UP(-EINVAL
); /* play on, but say "error" */
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
);
4645 msg(DBG_INF
,"ioctl: cc_PlayAudio returns %d\n",i
);
4647 D_S
[d
].audio_state
=0;
4650 D_S
[d
].audio_state
=audio_playing
;
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
));
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
)
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
));
4682 case CDROMSTOP
: /* Spin down the drive */
4683 msg(DBG_IOC
,"ioctl: CDROMSTOP entered.\n");
4685 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4687 i
=cc_Pause_Resume(1);
4688 D_S
[d
].audio_state
=0;
4694 case CDROMSTART
: /* Spin up the drive */
4695 msg(DBG_IOC
,"ioctl: CDROMSTART entered.\n");
4697 D_S
[d
].audio_state
=0;
4700 case CDROMVOLCTRL
: /* Volume control */
4701 msg(DBG_IOC
,"ioctl: CDROMVOLCTRL entered.\n");
4702 memcpy(&volctrl
,(char *) arg
,sizeof(volctrl
));
4704 D_S
[d
].vol_ctrl0
=volctrl
.channel0
;
4706 D_S
[d
].vol_ctrl1
=volctrl
.channel1
;
4710 case CDROMVOLREAD
: /* read Volume settings from drive */
4711 msg(DBG_IOC
,"ioctl: CDROMVOLREAD entered.\n");
4713 if (st
<0) RETURN_UP(st
);
4714 volctrl
.channel0
=D_S
[d
].vol_ctrl0
;
4715 volctrl
.channel1
=D_S
[d
].vol_ctrl1
;
4718 memcpy((void *)arg
,&volctrl
,sizeof(volctrl
));
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)) {
4726 if (i<0) RETURN_UP(-EIO);
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
;
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");
4747 D_S
[d
].CD_changed
=0x00; /* cd has changed, procede, */
4748 RETURN_UP(-EIO
); /* and get TOC, etc on next try! --AJK */
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!
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
)
4772 /* CD has stopped playing audio --AJK */
4773 D_S
[d
].audio_state
=audio_completed
;
4774 SC
.cdsc_audiostatus
=CDROM_AUDIO_COMPLETED
;
4776 SC
.cdsc_audiostatus
=CDROM_AUDIO_PLAY
;
4780 SC
.cdsc_audiostatus
=CDROM_AUDIO_PAUSED
;
4782 case audio_completed
:
4783 SC
.cdsc_audiostatus
=CDROM_AUDIO_COMPLETED
;
4786 SC
.cdsc_audiostatus
=CDROM_AUDIO_NO_STATUS
;
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
);
4816 msg(DBG_IOC
,"ioctl: unknown function request %04X\n", cmd
);
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
)
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);
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!
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
)
4879 int i
, status_tries
, data_tries
;
4880 struct request
*req
;
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",
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
);
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
);
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
));
4927 while (busy_audio
) sbp_sleep(HZ
); /* wait a bit */
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
);
4939 msg(DBG_MUL
,"read LBA %d\n", block
/4);
4943 /* if we satisfied the request from the buffer, we're done. */
4944 if (req
->nr_sectors
== 0)
4947 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 2, Time:%li\n",
4948 xnr
, req
, req
->sector
, req
->nr_sectors
, jiffies
);
4950 up(&ioctl_read_sem
);
4951 spin_lock_irq(&io_request_lock
);
4952 sbpcd_end_request(req
, 1);
4957 i
=prepare(0,0); /* at moment not really a hassle check, but ... */
4959 msg(DBG_INF
,"\"prepare\" tells error %d -- ignored\n", i
);
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
;
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__
);
4982 if (sbp_data(req
) != 0)
4985 D_S
[d
].has_data
=2; /* is really a data disk */
4988 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
4989 xnr
, req
, req
->sector
, req
->nr_sectors
, jiffies
);
4991 up(&ioctl_read_sem
);
4992 spin_lock_irq(&io_request_lock
);
4993 sbpcd_end_request(req
, 1);
5003 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 4 (error), Time:%li\n",
5004 xnr
, req
, req
->sector
, req
->nr_sectors
, jiffies
);
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);
5012 /*==========================================================================*/
5014 * build and send the READ command.
5016 static void sbp_read_cmd(struct request
*req
)
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
;
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
;
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)
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;
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]);
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;
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
;
5115 if (i
<0) msg(DBG_INF
,"error giving READ command: %0d\n", i
);
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
;
5129 u_int data_tries
= 0;
5130 u_int data_waits
= 0;
5131 u_int data_retrying
= 0;
5144 if (D_S
[d
].f_multisession
) max_latency
=15*HZ
;
5145 else max_latency
=5*HZ
;
5148 for (frame
=0;frame
<D_S
[d
].sbp_read_frames
&&!error_flag
; frame
++)
5152 del_timer(&data_timer
);
5153 data_timer
.expires
=jiffies
+max_latency
;
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--)
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
;
5171 if (data_retrying
== 0) data_waits
++;
5173 msg(DBG_000
,"sbp_data: CDi_status loop: sleeping.\n");
5178 msg(DBG_INF
,"sbp_data: CDi_status loop expired.\n");
5180 del_timer(&data_timer
);
5184 msg(DBG_INF
,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j
);
5189 msg(DBG_INF
,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j
);
5192 if (!(j
&s_not_result_ready
))
5194 msg(DBG_INF
, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j
);
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
);
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
);
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
);
5248 if ((i
=CDi_stat_loop_T()) == -1) break;
5256 if (!(i
&s_not_data_ready
))
5262 if (do_16bit
) i
=inw(CDi_data
);
5263 else i
=inb(CDi_data
);
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
))
5276 infobuf
[l
++]=inb(CDi_info
);
5279 while (!(i
&s_not_result_ready
));
5280 if (infobuf
[0]==0x00) success
=1;
5282 for (j
=0;j
<l
;j
++) sprintf(&msgbuf
[j
*3], " %02X", infobuf
[j
]);
5284 msg(DBG_TEA
,"sbp_data info response:%s\n", msgbuf
);
5286 if (infobuf
[0]==0x02)
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");
5295 drvcmd
[0]=CMDT_READ_ERR
;
5296 j
=cmd_out_T(); /* !!! recursive here !!! */
5301 D_S
[d
].error_state
=infobuf
[2];
5302 D_S
[d
].b3
=infobuf
[3];
5303 D_S
[d
].b4
=infobuf
[4];
5310 msg(DBG_TEA
, "============= waiting for result=================.\n");
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");
5323 i
=cc_DriveReset(); /* ugly fix to prevent a hang */
5334 for (timeout
=jiffies
+HZ
; time_before(jiffies
, timeout
); timeout
--)
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;
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 */
5363 if (fam0LV_drive
) cc_ReadStatus();
5365 if (famT_drive
) msg(DBG_TEA
, "================before ResponseStatus=================.\n", i
);
5367 i
=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
5369 if (famT_drive
) msg(DBG_TEA
, "================ResponseStatus: %d=================.\n", i
);
5373 msg(DBG_INF
,"bad cc_ReadStatus after read: %02X\n", D_S
[d
].status_bits
);
5377 while ((fam0LV_drive
)&&(!st_check
)&&(!(i
&p_success
)));
5381 msg(DBG_INF
,"cc_ReadError was necessary after read: %d\n",i
);
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");
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;
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
)
5407 i
= MINOR(cdi
->dev
);
5410 down(&ioctl_read_sem
);
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)
5421 D_S
[d
].open_count
=1;
5422 if (famT_drive
) msg(DBG_TEA
,"sbpcd_open: before i=DiskInfo();.\n");
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");
5433 else if (D_S
[d
].has_data
<1) D_S
[d
].has_data
=1;
5436 if (!st_spinning
) cc_SpinUp();
5439 /*==========================================================================*/
5441 * On close, we flush all sbp blocks from the buffer cache.
5443 static void sbpcd_release(struct cdrom_device_info
* cdi
)
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
);
5453 down(&ioctl_read_sem
);
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;
5475 up(&ioctl_read_sem
);
5479 /*==========================================================================*/
5483 static int sbpcd_media_changed( struct cdrom_device_info
*cdi
, int disc_nr
);
5484 static struct cdrom_device_ops sbpcd_dops
= {
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
,
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
,
5503 static struct cdrom_device_info sbpcd_info
= {
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.
5519 * sbpcd=0x230,SoundBlaster
5521 * sbpcd=0x300,LaserMate
5523 * sbpcd=0x338,SoundScape
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
5538 static int sbpcd_setup(char *s
)
5540 int sbpcd_setup(char *s
)
5544 (void)get_options(s
, ARRAY_SIZE(p
), p
);
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;
5566 if ((sbpro_type
==1)||(sbpro_type
==3))
5568 CDi_data
=sbpcd_ioaddr
;
5575 else CDi_data
=sbpcd_ioaddr
+2;
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,
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
5600 static int __init
config_spea(void)
5603 * base address offset between configuration port and CDROM port,
5604 * this probably defines the interface type
5606 * 8 (type=LaserMate):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 */
5618 #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
5619 #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
5621 OUT(SPEA_REG_1
,0xFF);
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
);
5635 #define SPEA_PATTERN 0x80
5637 #define SPEA_PATTERN 0x00
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
;
5647 sbpro_type
= 0; /* acts like a LaserMate interface now */
5648 msg(DBG_SEQ
,"found SoundScape interface at %04X.\n", sbpcd_ioaddr
);
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
;
5660 int __init
__SBPCD_INIT(void)
5662 int __init
SBPCD_INIT(void)
5667 int addr
[2]={1, CDROM_PORT
};
5672 msg(DBG_INF
,"sbpcd.c %s\n", VERSION
);
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");
5691 sbpcd
[0]=sbpcd_ioaddr
; /* possibly changed by kernel command line */
5692 sbpcd
[1]=sbpro_type
; /* possibly changed by kernel command line */
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]);
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
;
5708 sbpcd_setup((char *)type
);
5710 msg(DBG_INF
,"Scanning 0x%X (%s)...\n", CDo_command
, type
);
5712 if (sbpcd
[port_index
+1]==2)
5718 if (check_card(addr
[1])) continue;
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 */
5727 msg(DBG_INF
, "No drive found.\n");
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");
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;
5748 if (!famL_drive
) cc_DriveReset();
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
;
5759 if (!fam0_drive
) D_S
[j
].f_eject
=1;
5762 i
=ResponseStatus(); /* returns orig. status or p_busy_new */
5763 if (famT_drive
) i
=ResponseStatus(); /* returns orig. status or p_busy_new */
5767 msg(DBG_INF
,"init: ResponseStatus returns %d.\n",i
);
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",
5780 if (D_S
[j
].error_byte
==aud_12
)
5782 timeout
=jiffies
+2*HZ
;
5786 msg(DBG_INI
,"init: second GetStatus: %02X\n",i
);
5788 "init: second GetStatus: error_byte=%d\n",
5791 if (!st_caddy_in
) break;
5793 while ((!st_diskok
)||time_after(jiffies
, timeout
));
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).
5804 OUT(MIXER_addr
,MIXER_CD_Volume
); /* select SB Pro mixer register */
5805 OUT(MIXER_data
,0xCC); /* one nibble per channel, max. value: 0xFF */
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
);
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;
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
));
5854 msg(DBG_INF
,"data buffer size: %d frames.\n",buffers
);
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
));
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
);
5876 devfs_register (devfs_handle
, nbuff
, DEVFS_FL_DEFAULT
,
5877 MAJOR_NR
, j
, S_IFBLK
| S_IRUGO
| S_IWUGO
,
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
;
5892 #if !(SBPCD_ISSUE-1)
5893 #ifdef CONFIG_SBPCD2
5895 #endif CONFIG_SBPCD2
5896 #ifdef CONFIG_SBPCD3
5898 #endif CONFIG_SBPCD3
5899 #ifdef CONFIG_SBPCD4
5901 #endif CONFIG_SBPCD4
5902 #endif !(SBPCD_ISSUE-1)
5906 /*==========================================================================*/
5908 void sbpcd_exit(void)
5912 if ((devfs_unregister_blkdev(MAJOR_NR
, major_name
) == -EINVAL
))
5914 msg(DBG_INF
, "What's that: can't unregister %s.\n", major_name
);
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
);
5930 vfree(D_S
[j
].sbpcd_infop
);
5932 msg(DBG_INF
, "%s module released.\n", major_name
);
5937 module_init(__SBPCD_INIT
) /*HACK!*/;
5939 module_exit(sbpcd_exit
);
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
)
5952 msg(DBG_CHK
,"media_check (%d) called\n", 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
;
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
5983 * ---------------------------------------------------------------------------
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