2 * sbpcd.c CD-ROM device driver for the whole family of traditional,
3 * non-ATAPI IDE-style Matsushita/Panasonic CR-5xx drives.
4 * Works with SoundBlaster compatible cards and with "no-sound"
5 * interface cards like Lasermate, Panasonic CI-101P, Teac, ...
6 * Also for the Longshine LCS-7260 drive.
7 * Also for the IBM "External ISA CD-Rom" drive.
8 * Also for the CreativeLabs CD200 drive.
9 * Also for the TEAC CD-55A drive.
10 * Also for the ECS-AT "Vertos 100" drive.
11 * Not for Sanyo drives (but for the H94A, sjcd is there...).
12 * Not for any other Funai drives than the CD200 types (sometimes
13 * labelled E2550UA or MK4015 or 2800F).
16 #define VERSION "v4.61 Eberhard Moenkeberg <emoenke@gwdg.de>"
18 /* Copyright (C) 1993, 1994, 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2, or (at your option)
25 * You should have received a copy of the GNU General Public License
26 * (for example /usr/src/linux/COPYING); if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 * If you change this software, you should mail a .diff file with some
30 * description lines to emoenke@gwdg.de. I want to know about it.
32 * If you are the editor of a Linux CD, you should enable sbpcd.c within
33 * your boot floppy kernel and send me one of your CDs for free.
35 * If you would like to port the driver to an other operating system (f.e.
36 * FreeBSD or NetBSD) or use it as an information source, you shall not be
37 * restricted by the GPL under the following conditions:
38 * a) the source code of your work is freely available
39 * b) my part of the work gets mentioned at all places where your
40 * authorship gets mentioned
41 * c) I receive a copy of your code together with a full installation
42 * package of your operating system for free.
47 * 0.1 initial release, April/May 93, after mcd.c (Martin Harriss)
49 * 0.2 the "repeat:"-loop in do_sbpcd_request did not check for
50 * end-of-request_queue (resulting in kernel panic).
51 * Flow control seems stable, but throughput is not better.
53 * 0.3 interrupt locking totally eliminated (maybe "inb" and "outb"
54 * are still locking) - 0.2 made keyboard-type-ahead losses.
55 * check_sbpcd_media_change added (to use by isofs/inode.c)
56 * - but it detects almost nothing.
58 * 0.4 use MAJOR 25 definitely.
59 * Almost total re-design to support double-speed drives and
60 * "naked" (no sound) interface cards ("LaserMate" interface type).
61 * Flow control should be exact now.
62 * Don't occupy the SbPro IRQ line (not needed either); will
63 * live together with Hannu Savolainen's sndkit now.
64 * Speeded up data transfer to 150 kB/sec, with help from Kai
65 * Makisara, the "provider" of the "mt" tape utility.
66 * Give "SpinUp" command if necessary.
67 * First steps to support up to 4 drives (but currently only one).
68 * Implemented audio capabilities - workman should work, xcdplayer
69 * gives some problems.
70 * This version is still consuming too much CPU time, and
71 * sleeping still has to be worked on.
72 * During "long" implied seeks, it seems possible that a
73 * ReadStatus command gets ignored. That gives the message
74 * "ResponseStatus timed out" (happens about 6 times here during
75 * a "ls -alR" of the YGGDRASIL LGX-Beta CD). Such a case is
76 * handled without data error, but it should get done better.
78 * 0.5 Free CPU during waits (again with help from Kai Makisara).
79 * Made it work together with the LILO/kernel setup standard.
80 * Included auto-probing code, as suggested by YGGDRASIL.
81 * Formal redesign to add DDI debugging.
82 * There are still flaws in IOCTL (workman with double speed drive).
84 * 1.0 Added support for all drive IDs (0...3, no longer only 0)
85 * and up to 4 drives on one controller.
86 * Added "#define MANY_SESSION" for "old" multi session CDs.
88 * 1.1 Do SpinUp for new drives, too.
89 * Revised for clean compile under "old" kernels (0.99pl9).
91 * 1.2 Found the "workman with double-speed drive" bug: use the driver's
92 * audio_state, not what the drive is reporting with ReadSubQ.
95 * Refinements regarding Workman.
97 * 1.4 Read XA disks (PhotoCDs) with "old" drives, too (but only the first
98 * session - no chance to fully access a "multi-session" CD).
99 * This currently still is too slow (50 kB/sec) - but possibly
100 * the old drives won't do it faster.
101 * Implemented "door (un)lock" for new drives (still does not work
102 * as wanted - no lock possible after an unlock).
103 * Added some debugging printout for the UPC/EAN code - but my drives
104 * return only zeroes. Is there no UPC/EAN code written?
106 * 1.5 Laborate with UPC/EAN code (not better yet).
107 * Adapt to kernel 1.1.8 change (have to explicitly include
108 * <linux/string.h> now).
110 * 1.6 Trying to read audio frames as data. Impossible with the current
111 * drive firmware levels, as it seems. Awaiting any hint. ;-)
112 * Changed "door unlock": repeat it until success.
113 * Changed CDROMSTOP routine (stop somewhat "softer" so that Workman
114 * won't get confused).
115 * Added a third interface type: Sequoia S-1000, as used with the SPEA
116 * Media FX sound card. This interface (usable for Sony and Mitsumi
117 * drives, too) needs a special configuration setup and behaves like a
118 * LaserMate type after that. Still experimental - I do not have such
120 * Use the "variable BLOCK_SIZE" feature (2048). But it does only work
121 * if you give the mount option "block=2048".
122 * The media_check routine is currently disabled; now that it gets
123 * called as it should I fear it must get synchronized for not to
124 * disturb the normal driver's activity.
126 * 2.0 Version number bumped - two reasons:
127 * - reading audio tracks as data works now with CR-562 and CR-563. We
128 * currently do it by an IOCTL (yet has to get standardized), one frame
129 * at a time; that is pretty slow. But it works.
130 * - we are maintaining now up to 4 interfaces (each up to 4 drives):
131 * did it the easy way - a different MAJOR (25, 26, ...) and a different
132 * copy of the driver (sbpcd.c, sbpcd2.c, sbpcd3.c, sbpcd4.c - only
133 * distinguished by the value of SBPCD_ISSUE and the driver's name),
134 * and a common sbpcd.h file.
135 * Bettered the "ReadCapacity error" problem with old CR-52x drives (the
136 * drives sometimes need a manual "eject/insert" before work): just
137 * reset the drive and do again. Needs lots of resets here and sometimes
138 * that does not cure, so this can't be the solution.
140 * 2.1 Found bug with multisession CDs (accessing frame 16).
141 * "read audio" works now with address type CDROM_MSF, too.
142 * Bigger audio frame buffer: allows reading max. 4 frames at time; this
143 * gives a significant speedup, but reading more than one frame at once
144 * gives missing chunks at each single frame boundary.
146 * 2.2 Kernel interface cleanups: timers, init, setup, media check.
148 * 2.3 Let "door lock" and "eject" live together.
149 * Implemented "close tray" (done automatically during open).
151 * 2.4 Use different names for device registering.
153 * 2.5 Added "#if EJECT" code (default: enabled) to automatically eject
154 * the tray during last call to "sbpcd_release".
155 * Added "#if JUKEBOX" code (default: disabled) to automatically eject
156 * the tray during call to "sbpcd_open" if no disk is in.
157 * Turn on the CD volume of "compatible" sound cards, too; just define
158 * SOUND_BASE (in sbpcd.h) accordingly (default: disabled).
162 * 2.7 Added CDROMEJECT_SW ioctl to set the "EJECT" behavior on the fly:
163 * 0 disables, 1 enables auto-ejecting. Useful to keep the tray in
166 * 2.8 Added first support (still BETA, I need feedback or a drive) for
167 * the Longshine LCS-7260 drives. They appear as double-speed drives
168 * using the "old" command scheme, extended by tray control and door
170 * Found (and fixed preliminary) a flaw with some multisession CDs: we
171 * have to re-direct not only the accesses to frame 16 (the isofs
172 * routines drive it up to max. 100), but also those to the continuation
173 * (repetition) frames (as far as they exist - currently set fix as
175 * Changed default of the "JUKEBOX" define. If you use this default,
176 * your tray will eject if you try to mount without a disk in. Next
177 * mount command will insert the tray - so, just fill in a disk. ;-)
179 * 2.9 Fulfilled the Longshine LCS-7260 support; with great help and
180 * experiments by Serge Robyns.
181 * First attempts to support the TEAC CD-55A drives; but still not
183 * Implemented the CDROMMULTISESSION ioctl; this is an attempt to handle
184 * multi session CDs more "transparent" (redirection handling has to be
185 * done within the isofs routines, and only for the special purpose of
186 * obtaining the "right" volume descriptor; accesses to the raw device
187 * should not get redirected).
189 * 3.0 Just a "normal" increment, with some provisions to do it better. ;-)
190 * Introduced "#define READ_AUDIO" to specify the maximum number of
191 * audio frames to grab with one request. This defines a buffer size
192 * within kernel space; a value of 0 will reserve no such space and
193 * disable the CDROMREADAUDIO ioctl. A value of 75 enables the reading
194 * of a whole second with one command, but will use a buffer of more
196 * Started CD200 support. Drive detection should work, but nothing
199 * 3.1 Working to support the CD200 and the Teac CD-55A drives.
200 * AT-BUS style device numbering no longer used: use SCSI style now.
201 * So, the first "found" device has MINOR 0, regardless of the
202 * jumpered drive ID. This implies modifications to the /dev/sbpcd*
203 * entries for some people, but will help the DAU (german TLA, english:
204 * "newbie", maybe ;-) to install his "first" system from a CD.
206 * 3.2 Still testing with CD200 and CD-55A drives.
208 * 3.3 Working with CD200 support.
210 * 3.4 Auto-probing stops if an address of 0 is seen (to be entered with
211 * the kernel command line).
212 * Made the driver "loadable". If used as a module, "audio copy" is
213 * disabled, and the internal read ahead data buffer has a reduced size
214 * of 4 kB; so, throughput may be reduced a little bit with slow CPUs.
216 * 3.5 Provisions to handle weird photoCDs which have an interrupted
217 * "formatting" immediately after the last frames of some files: simply
218 * never "read ahead" with MultiSession CDs. By this, CPU usage may be
219 * increased with those CDs, and there may be a loss in speed.
220 * Re-structured the messaging system.
221 * The "loadable" version no longer has a limited READ_AUDIO buffer
223 * Removed "MANY_SESSION" handling for "old" multi session CDs.
224 * Added "private" IOCTLs CDROMRESET and CDROMVOLREAD.
225 * Started again to support the TEAC CD-55A drives, now that I found
226 * the money for "my own" drive. ;-)
227 * The TEAC CD-55A support is fairly working now.
228 * I have measured that the drive "delivers" at 600 kB/sec (even with
229 * bigger requests than the drive's 64 kB buffer can satisfy), but
230 * the "real" rate does not exceed 520 kB/sec at the moment.
231 * Caused by the various changes to build in TEAC support, the timed
232 * loops are de-optimized at the moment (less throughput with CR-52x
233 * drives, and the TEAC will give speed only with SBP_BUFFER_FRAMES 64).
235 * 3.6 Fixed TEAC data read problems with SbPro interfaces.
236 * Initial size of the READ_AUDIO buffer is 0. Can get set to any size
239 * 3.7 Introduced MAX_DRIVES for some poor interface cards (seen with TEAC
240 * drives) which allow only one drive (ID 0); this avoids repetitive
241 * detection under IDs 1..3.
242 * Elongated cmd_out_T response waiting; necessary for photo CDs with
244 * Bettered the sbpcd_open() behavior with TEAC drives.
246 * 3.8 Elongated max_latency for CR-56x drives.
248 * 3.9 Finally fixed the long-known SoundScape/SPEA/Sequoia S-1000 interface
250 * Now Corey, Heiko, Ken, Leo, Vadim/Eric & Werner are invited to copy
251 * the config_spea() routine into their drivers. ;-)
253 * 4.0 No "big step" - normal version increment.
254 * Adapted the benefits from 1.3.33.
255 * Fiddled with CDROMREADAUDIO flaws.
256 * Avoid ReadCapacity command with CD200 drives (the MKE 1.01 version
257 * seems not to support it).
258 * Fulfilled "read audio" for CD200 drives, with help of Pete Heist
261 * 4.1 Use loglevel KERN_INFO with printk().
262 * Added support for "Vertos 100" drive ("ECS-AT") - it is very similar
263 * to the Longshine LCS-7260. Give feedback if you can - I never saw
264 * such a drive, and I have no specs.
266 * 4.2 Support for Teac 16-bit interface cards. Can't get auto-detected,
267 * so you have to jumper your card to 0x2C0. Still not 100% - come
268 * in contact if you can give qualified feedback.
269 * Use loglevel KERN_NOTICE with printk(). If you get annoyed by a
270 * flood of unwanted messages and the accompanied delay, try to read
271 * my documentation. Especially the Linux CDROM drivers have to do an
272 * important job for the newcomers, so the "distributed" version has
273 * to fit some special needs. Since generations, the flood of messages
274 * is user-configurable (even at runtime), but to get aware of this, one
275 * needs a special mental quality: the ability to read.
277 * 4.3 CD200F does not like to receive a command while the drive is
278 * reading the ToC; still trying to solve it.
279 * Removed some redundant verify_area calls (yes, Heiko Eissfeldt
280 * is visiting all the Linux CDROM drivers ;-).
282 * 4.4 Adapted one idea from tiensivu@pilot.msu.edu's "stripping-down"
283 * experiments: "KLOGD_PAUSE".
284 * Inhibited "play audio" attempts with data CDs. Provisions for a
285 * "data-safe" handling of "mixed" (data plus audio) Cds.
287 * 4.5 Meanwhile Gonzalo Tornaria <tornaria@cmat.edu.uy> (GTL) built a
288 * special end_request routine: we seem to have to take care for not
289 * to have two processes working at the request list. My understanding
290 * was and is that ll_rw_blk should not call do_sbpcd_request as long
291 * as there is still one call active (the first call will care for all
292 * outstanding I/Os, and if a second call happens, that is a bug in
294 * "Check media change" without touching any drive.
296 * 4.6 Use a semaphore to synchronize multi-activity; elaborated by Rob
297 * Riggs <rriggs@tesser.com>. At the moment, we simply block "read"
298 * against "ioctl" and vice versa. This could be refined further, but
299 * I guess with almost no performance increase.
300 * Experiments to speed up the CD-55A; again with help of Rob Riggs
301 * (to be true, he gave both, idea & code. ;-)
303 * 4.61 Ported to Uniform CD-ROM driver by
304 * Heiko Eissfeldt <heiko@colossus.escape.de> with additional
305 * changes by Erik Andersen <andersee@debian.org>
307 * 4.62 Fix a bug where playing audio left the drive in an unusable state.
308 * Heiko Eissfeldt <heiko@colossus.escape.de>
312 * implement "read all subchannel data" (96 bytes per frame)
314 * special thanks to Kai Makisara (kai.makisara@vtt.fi) for his fine
315 * elaborated speed-up experiments (and the fabulous results!), for
316 * the "push" towards load-free wait loops, and for the extensive mail
317 * thread which brought additional hints and bug fixes.
322 #define SBPCD_ISSUE 1
325 #include <linux/module.h>
327 #include <linux/errno.h>
328 #include <linux/sched.h>
329 #include <linux/mm.h>
330 #include <linux/timer.h>
331 #include <linux/fs.h>
332 #include <linux/kernel.h>
333 #include <linux/cdrom.h>
334 #include <linux/ioport.h>
335 #include <linux/major.h>
336 #include <linux/string.h>
337 #include <linux/vmalloc.h>
338 #include <linux/init.h>
339 #include <linux/interrupt.h>
341 #include <asm/system.h>
343 #include <asm/uaccess.h>
345 #include <linux/config.h>
349 #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
352 #define MAJOR_NR MATSUSHITA_CDROM2_MAJOR /* second driver issue */
355 #define MAJOR_NR MATSUSHITA_CDROM3_MAJOR /* third driver issue */
358 #define MAJOR_NR MATSUSHITA_CDROM4_MAJOR /* fourth driver issue */
361 #include <linux/blk.h>
363 /*==========================================================================*/
365 * provisions for more than 1 driver issues
366 * currently up to 4 drivers, expandable
369 #define DO_SBPCD_REQUEST(a) do_sbpcd_request(a)
370 #define SBPCD_INIT(a) sbpcd_init(a)
373 #define DO_SBPCD_REQUEST(a) do_sbpcd2_request(a)
374 #define SBPCD_INIT(a) sbpcd2_init(a)
377 #define DO_SBPCD_REQUEST(a) do_sbpcd3_request(a)
378 #define SBPCD_INIT(a) sbpcd3_init(a)
381 #define DO_SBPCD_REQUEST(a) do_sbpcd4_request(a)
382 #define SBPCD_INIT(a) sbpcd4_init(a)
384 /*==========================================================================*/
386 #define SBPCD_CLI cli()
387 #define SBPCD_STI sti()
392 /*==========================================================================*/
394 * auto-probing address list
395 * inspired by Adam J. Richter from Yggdrasil
397 * still not good enough - can cause a hang.
398 * example: a NE 2000 ethernet card at 300 will cause a hang probing 310.
399 * if that happens, reboot and use the LILO (kernel) command line.
400 * The possibly conflicting ethernet card addresses get NOT probed
401 * by default - to minimize the hang possibilities.
403 * The SB Pro addresses get "mirrored" at 0x6xx and some more locations - to
404 * avoid a type error, the 0x2xx-addresses must get checked before 0x6xx.
406 * send mail to emoenke@gwdg.de if your interface card is not FULLY
412 CDROM_PORT
, SBPRO
, /* probe with user's setup first */
414 0x230, 1, /* Soundblaster Pro and 16 (default) */
416 0x300, 0, /* CI-101P (default), WDH-7001C (default),
417 Galaxy (default), Reveal (one default) */
418 0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
419 0x2C0, 3, /* Teac 16-bit cards */
420 0x260, 1, /* OmniCD */
421 0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
422 Longshine LCS-6853 (default) */
423 0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
424 0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
425 0x360, 0, /* Lasermate, CI-101P */
426 0x270, 1, /* Soundblaster 16 */
427 0x670, 0, /* "sound card #9" */
428 0x690, 0, /* "sound card #9" */
429 0x338, 2, /* SPEA Media FX, Ensonic SoundScape (default) */
430 0x328, 2, /* SPEA Media FX */
431 0x348, 2, /* SPEA Media FX */
432 0x634, 0, /* some newer sound cards */
433 0x638, 0, /* some newer sound cards */
434 0x230, 1, /* some newer sound cards */
435 /* due to incomplete address decoding of the SbPro card, these must be last */
436 0x630, 0, /* "sound card #9" (default) */
437 0x650, 0, /* "sound card #9" */
440 * some "hazardous" locations (no harm with the loadable version)
441 * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
443 0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
444 0x350, 0, /* Lasermate, CI-101P */
445 0x358, 2, /* SPEA Media FX */
446 0x370, 0, /* Lasermate, CI-101P */
447 0x290, 1, /* Soundblaster 16 */
448 0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
454 static int sbpcd
[] = {CDROM_PORT
, SBPRO
}; /* probe with user's setup only */
456 MODULE_PARM(sbpcd
, "2i");
458 #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
460 /*==========================================================================*/
462 * the external references:
466 extern int sbpcd2_init(void);
469 extern int sbpcd3_init(void);
472 extern int sbpcd4_init(void);
476 /*==========================================================================*/
478 #define INLINE inline
480 /*==========================================================================*/
482 * the forward references:
484 static void sbp_sleep(u_int
);
485 static void mark_timeout_delay(u_long
);
486 static void mark_timeout_data(u_long
);
488 static void mark_timeout_audio(u_long
);
490 static void sbp_read_cmd(struct request
*req
);
491 static int sbp_data(struct request
*req
);
492 static int cmd_out(void);
493 static int DiskInfo(void);
494 static int sbpcd_chk_disk_change(kdev_t
);
496 /*==========================================================================*/
499 * pattern for printk selection:
501 * (1<<DBG_INF) necessary information
502 * (1<<DBG_BSZ) BLOCK_SIZE trace
503 * (1<<DBG_REA) "read" status trace
504 * (1<<DBG_CHK) "media check" trace
505 * (1<<DBG_TIM) datarate timer test
506 * (1<<DBG_INI) initialization trace
507 * (1<<DBG_TOC) tell TocEntry values
508 * (1<<DBG_IOC) ioctl trace
509 * (1<<DBG_STA) "ResponseStatus" trace
510 * (1<<DBG_ERR) "cc_ReadError" trace
511 * (1<<DBG_CMD) "cmd_out" trace
512 * (1<<DBG_WRN) give explanation before auto-probing
513 * (1<<DBG_MUL) multi session code test
514 * (1<<DBG_IDX) "drive_id != 0" test code
515 * (1<<DBG_IOX) some special information
516 * (1<<DBG_DID) drive ID test
517 * (1<<DBG_RES) drive reset info
518 * (1<<DBG_SPI) SpinUp test info
519 * (1<<DBG_IOS) ioctl trace: "subchannel"
520 * (1<<DBG_IO2) ioctl trace: general
521 * (1<<DBG_UPC) show UPC info
522 * (1<<DBG_XA1) XA mode debugging
523 * (1<<DBG_LCK) door (un)lock info
524 * (1<<DBG_SQ1) dump SubQ frame
525 * (1<<DBG_AUD) "read audio" debugging
526 * (1<<DBG_SEQ) Sequoia interface configuration trace
527 * (1<<DBG_LCS) Longshine LCS-7260 debugging trace
528 * (1<<DBG_CD2) MKE/Funai CD200 debugging trace
529 * (1<<DBG_TEA) TEAC CD-55A debugging trace
530 * (1<<DBG_ECS) ECS-AT (Vertos-100) debugging trace
531 * (1<<DBG_000) unnecessary information
534 static int sbpcd_debug
= (1<<DBG_INF
);
536 static int sbpcd_debug
= 0 & ((1<<DBG_INF
) |
542 static int sbpcd_ioaddr
= CDROM_PORT
; /* default I/O base address */
543 static int sbpro_type
= SBPRO
;
544 static unsigned char setup_done
= 0;
545 static unsigned char f_16bit
= 0;
546 static unsigned char do_16bit
= 0;
547 static int CDo_command
, CDo_reset
;
548 static int CDo_sel_i_d
, CDo_enable
;
549 static int CDi_info
, CDi_status
, CDi_data
;
550 static struct cdrom_msf msf
;
551 static struct cdrom_ti ti
;
552 static struct cdrom_tochdr tochdr
;
553 static struct cdrom_tocentry tocentry
;
554 static struct cdrom_subchnl SC
;
555 static struct cdrom_volctrl volctrl
;
556 static struct cdrom_read_audio read_audio
;
558 static unsigned char msgnum
=0;
559 static char msgbuf
[80];
561 static const char *str_sb
= "SoundBlaster";
562 static const char *str_sb_l
= "soundblaster";
563 static const char *str_lm
= "LaserMate";
564 static const char *str_sp
= "SPEA";
565 static const char *str_sp_l
= "spea";
566 static const char *str_ss
= "SoundScape";
567 static const char *str_ss_l
= "soundscape";
568 static const char *str_t16
= "Teac16bit";
569 static const char *str_t16_l
= "teac16bit";
570 static const char *type
;
573 static const char *major_name
="sbpcd";
576 static const char *major_name
="sbpcd2";
579 static const char *major_name
="sbpcd3";
582 static const char *major_name
="sbpcd4";
585 /*==========================================================================*/
588 static DECLARE_WAIT_QUEUE_HEAD(sbp_waitq
);
591 static int teac
=SBP_TEAC_SPEED
;
592 static int buffers
=SBP_BUFFER_FRAMES
;
594 static u_char family0
[]="MATSHITA"; /* MKE CR-521, CR-522, CR-523 */
595 static u_char family1
[]="CR-56"; /* MKE CR-562, CR-563 */
596 static u_char family2
[]="CD200"; /* MKE CD200, Funai CD200F */
597 static u_char familyL
[]="LCS-7260"; /* Longshine LCS-7260 */
598 static u_char familyT
[]="CD-55"; /* TEAC CD-55A */
599 static u_char familyV
[]="ECS-AT"; /* ECS Vertos 100 */
601 static u_int recursion
=0; /* internal testing only */
602 static u_int fatal_err
=0; /* internal testing only */
603 static u_int response_count
=0;
604 static u_int flags_cmd_out
;
605 static u_char cmd_type
=0;
606 static u_char drvcmd
[10];
607 static u_char infobuf
[20];
608 static u_char xa_head_buf
[CD_XA_HEAD
];
609 static u_char xa_tail_buf
[CD_XA_TAIL
];
612 static volatile u_char busy_data
=0;
613 static volatile u_char busy_audio
=0; /* true semaphores would be safer */
615 static DECLARE_MUTEX(ioctl_read_sem
);
616 static u_long timeout
;
617 static volatile u_char timed_out_delay
=0;
618 static volatile u_char timed_out_data
=0;
620 static volatile u_char timed_out_audio
=0;
622 static u_int datarate
= 1000000;
623 static u_int maxtim16
=16000000;
624 static u_int maxtim04
= 4000000;
625 static u_int maxtim02
= 2000000;
626 static u_int maxtim_8
= 30000;
628 static u_int maxtim_data
= 9000;
630 static u_int maxtim_data
= 3000;
633 static int n_retries
=3;
635 static int n_retries
=1;
637 /*==========================================================================*/
639 static int ndrives
=0;
640 static u_char drv_pattern
[NR_SBPCD
]={speed_auto
,speed_auto
,speed_auto
,speed_auto
};
641 static int sbpcd_blocksizes
[NR_SBPCD
] = {0, };
643 /*==========================================================================*/
645 * drive space begins here (needed separate for each unit)
647 static int d
=0; /* DriveStruct index: drive number */
650 char drv_id
; /* "jumpered" drive ID or -1 */
651 char drv_sel
; /* drive select lines bits */
654 u_char firmware_version
[4];
655 char f_eject
; /* auto-eject flag: 0 or 1 */
656 u_char
*sbp_buf
; /* Pointer to internal data buffer,
657 space allocated during sbpcd_init() */
658 u_int sbp_bufsiz
; /* size of sbp_buf (# of frames) */
659 int sbp_first_frame
; /* First frame in buffer */
660 int sbp_last_frame
; /* Last frame in buffer */
661 int sbp_read_frames
; /* Number of frames being read to buffer */
662 int sbp_current
; /* Frame being currently read */
664 u_char mode
; /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
665 u_char
*aud_buf
; /* Pointer to audio data buffer,
666 space allocated during sbpcd_init() */
667 u_int sbp_audsiz
; /* size of aud_buf (# of raw frames) */
671 u_char diskstate_flags
;
678 u_char f_multisession
;
682 int track_of_last_session
;
685 u_int pos_audio_start
;
691 #if 000 /* no supported drive has it */
697 u_char volume_control
; /* TEAC on/off bits */
704 u_char SubQ_whatisthis
;
712 u_char xa_byte
; /* 0x20: XA capabilities */
713 u_char n_first_track
; /* binary */
714 u_char n_last_track
; /* binary (not bcd), 0x01...0x63 */
715 u_int size_msf
; /* time of whole CD, position of LeadOut track */
718 u_char TocEnt_nixbyte
; /* em */
719 u_char TocEnt_ctl_adr
;
720 u_char TocEnt_number
;
721 u_char TocEnt_format
; /* em */
722 u_int TocEnt_address
;
726 u_char ored_ctl_adr
; /* to detect if CDROM contains data tracks */
729 u_char nixbyte
; /* em */
730 u_char ctl_adr
; /* 0x4x: data, 0x0x: audio */
732 u_char format
; /* em */ /* 0x00: lba, 0x01: msf */
734 } TocBuffer
[MAX_TRACKS
+1]; /* last entry faked */
736 int in_SpinUp
; /* CR-52x test flag */
737 int n_bytes
; /* TEAC awaited response count */
738 u_char error_state
, b3
, b4
; /* TEAC command error state */
739 u_char f_drv_error
; /* TEAC command error flag */
742 u_char f_XA
; /* 1: XA */
743 u_char type_byte
; /* 0, 1, 3 */
748 struct cdrom_device_info
*sbpcd_infop
;
753 * drive space ends here (needed separate for each unit)
755 /*==========================================================================*/
757 unsigned long cli_sti
; /* for saving the processor flags */
759 /*==========================================================================*/
760 static struct timer_list delay_timer
= { NULL
, NULL
, 0, 0, mark_timeout_delay
};
761 static struct timer_list data_timer
= { NULL
, NULL
, 0, 0, mark_timeout_data
};
763 static struct timer_list audio_timer
= { NULL
, NULL
, 0, 0, mark_timeout_audio
};
765 /*==========================================================================*/
769 static void msg(int level
, const char *fmt
, ...)
772 #define MSG_LEVEL KERN_NOTICE
774 #define MSG_LEVEL KERN_INFO
780 if (!(sbpcd_debug
&(1<<level
))) return;
783 if (msgnum
>99) msgnum
=0;
784 sprintf(buf
, MSG_LEVEL
"%s-%d [%02d]: ", major_name
, d
, msgnum
);
786 vsprintf(&buf
[18], fmt
, args
);
790 sbp_sleep(KLOGD_PAUSE
); /* else messages get lost */
794 /*==========================================================================*/
796 * DDI interface: runtime trace bit pattern maintenance
798 static int sbpcd_dbg_ioctl(unsigned long arg
, int level
)
803 sbpcd_debug
= DBG_INF
;
807 if (arg
>=128) sbpcd_debug
&= ~(1<<(arg
-128));
808 else sbpcd_debug
|= (1<<arg
);
812 /*==========================================================================*/
813 static void mark_timeout_delay(u_long i
)
817 msg(DBG_TIM
,"delay timer expired.\n");
820 /*==========================================================================*/
821 static void mark_timeout_data(u_long i
)
825 msg(DBG_TIM
,"data timer expired.\n");
828 /*==========================================================================*/
830 static void mark_timeout_audio(u_long i
)
834 msg(DBG_TIM
,"audio timer expired.\n");
838 /*==========================================================================*/
840 * Wait a little while (used for polling the drive).
842 static void sbp_sleep(u_int time
)
845 current
->state
= TASK_INTERRUPTIBLE
;
846 schedule_timeout(time
);
849 /*==========================================================================*/
850 #define RETURN_UP(rc) {up(&ioctl_read_sem); return(rc);}
851 /*==========================================================================*/
853 * convert logical_block_address to m-s-f_number (3 bytes only)
855 static INLINE
void lba2msf(int lba
, u_char
*msf
)
857 lba
+= CD_MSF_OFFSET
;
858 msf
[0] = lba
/ (CD_SECS
*CD_FRAMES
);
859 lba
%= CD_SECS
*CD_FRAMES
;
860 msf
[1] = lba
/ CD_FRAMES
;
861 msf
[2] = lba
% CD_FRAMES
;
863 /*==========================================================================*/
864 /*==========================================================================*/
866 * convert msf-bin to msf-bcd
868 static INLINE
void bin2bcdx(u_char
*p
) /* must work only up to 75 or 99 */
870 *p
=((*p
/10)<<4)|(*p
%10);
872 /*==========================================================================*/
873 static INLINE u_int
blk2msf(u_int blk
)
879 msf
.c
[2] = (blk
+ CD_MSF_OFFSET
) / (CD_SECS
* CD_FRAMES
);
880 mm
= (blk
+ CD_MSF_OFFSET
) % (CD_SECS
* CD_FRAMES
);
881 msf
.c
[1] = mm
/ CD_FRAMES
;
882 msf
.c
[0] = mm
% CD_FRAMES
;
885 /*==========================================================================*/
886 static INLINE u_int
make16(u_char rh
, u_char rl
)
890 /*==========================================================================*/
891 static INLINE u_int
make32(u_int rh
, u_int rl
)
893 return ((rh
<<16)|rl
);
895 /*==========================================================================*/
896 static INLINE u_char
swap_nibbles(u_char i
)
898 return ((i
<<4)|(i
>>4));
900 /*==========================================================================*/
901 static INLINE u_char
byt2bcd(u_char i
)
903 return (((i
/10)<<4)+i
%10);
905 /*==========================================================================*/
906 static INLINE u_char
bcd2bin(u_char bcd
)
908 return ((bcd
>>4)*10+(bcd
&0x0F));
910 /*==========================================================================*/
911 static INLINE
int msf2blk(int msfx
)
917 i
=(msf
.c
[2] * CD_SECS
+ msf
.c
[1]) * CD_FRAMES
+ msf
.c
[0] - CD_MSF_OFFSET
;
921 /*==========================================================================*/
923 * convert m-s-f_number (3 bytes only) to logical_block_address
925 static INLINE
int msf2lba(u_char
*msf
)
929 i
=(msf
[0] * CD_SECS
+ msf
[1]) * CD_FRAMES
+ msf
[2] - CD_MSF_OFFSET
;
933 /*==========================================================================*/
934 /* evaluate cc_ReadError code */
935 static int sta2err(int sta
)
939 if (sta
==0x00) return (0);
940 if (sta
==0x01) return (-604); /* CRC error */
941 if (sta
==0x02) return (-602); /* drive not ready */
942 if (sta
==0x03) return (-607); /* unknown media */
943 if (sta
==0x04) return (-612); /* general failure */
944 if (sta
==0x05) return (0);
945 if (sta
==0x06) return (-ERR_DISKCHANGE
); /* disk change */
946 if (sta
==0x0b) return (-612); /* general failure */
947 if (sta
==0xff) return (-612); /* general failure */
952 if (sta
<=2) return (sta
);
953 if (sta
==0x05) return (-604); /* CRC error */
954 if (sta
==0x06) return (-606); /* seek error */
955 if (sta
==0x0d) return (-606); /* seek error */
956 if (sta
==0x0e) return (-603); /* unknown command */
957 if (sta
==0x14) return (-603); /* unknown command */
958 if (sta
==0x0c) return (-611); /* read fault */
959 if (sta
==0x0f) return (-611); /* read fault */
960 if (sta
==0x10) return (-611); /* read fault */
961 if (sta
>=0x16) return (-612); /* general failure */
962 if (sta
==0x11) return (-ERR_DISKCHANGE
); /* disk change (LCS: removed) */
964 if (sta
==0x12) return (-ERR_DISKCHANGE
); /* disk change (inserted) */
965 return (-602); /* drive not ready */
968 /*==========================================================================*/
969 static INLINE
void clr_cmdbuf(void)
973 for (i
=0;i
<10;i
++) drvcmd
[i
]=0;
976 /*==========================================================================*/
977 static void flush_status(void)
982 for (i
=maxtim_data
;i
!=0;i
--) inb(CDi_status
);
984 /*====================================================================*/
986 * CDi status loop for Teac CD-55A (Rob Riggs)
988 * This is needed because for some strange reason
989 * the CD-55A can take a real long time to give a
990 * status response. This seems to happen after we
991 * issue a READ command where a long seek is involved.
993 * I tried to ensure that we get max throughput with
994 * minimal busy waiting. We busy wait at first, then
995 * "switch gears" and start sleeping. We sleep for
996 * longer periods of time the longer we wait.
999 static int CDi_stat_loop_T(void)
1002 u_long timeout_1
, timeout_2
, timeout_3
, timeout_4
;
1004 timeout_1
= jiffies
+ HZ
/ 50; /* sbp_sleep(0) for a short period */
1005 timeout_2
= jiffies
+ HZ
/ 5; /* nap for no more than 200ms */
1006 timeout_3
= jiffies
+ 5 * HZ
; /* sleep for up to 5s */
1007 timeout_4
= jiffies
+ 45 * HZ
; /* long sleep for up to 45s. */
1010 i
= inb(CDi_status
);
1011 if (!(i
&s_not_data_ready
)) return (i
);
1012 if (!(i
&s_not_result_ready
)) return (i
);
1017 if (time_after(jiffies
, timeout_4
)) gear
++;
1018 msg(DBG_TEA
, "CDi_stat_loop_T: long sleep active.\n");
1022 if (time_after(jiffies
, timeout_3
)) gear
++;
1026 if (time_after(jiffies
, timeout_2
)) gear
++;
1030 if (time_after(jiffies
, timeout_1
)) gear
++;
1035 /*==========================================================================*/
1036 static int CDi_stat_loop(void)
1040 for(timeout
= jiffies
+ 10*HZ
, i
=maxtim_data
; time_before(jiffies
, timeout
); )
1045 if (!(j
&s_not_data_ready
)) return (j
);
1046 if (!(j
&s_not_result_ready
)) return (j
);
1047 if (fam0L_drive
) if (j
&s_attention
) return (j
);
1052 msg(DBG_LCS
,"CDi_stat_loop failed in line %d\n", __LINE__
);
1055 /*==========================================================================*/
1057 /*==========================================================================*/
1058 static int tst_DataReady(void)
1063 if (i
&s_not_data_ready
) return (0);
1066 /*==========================================================================*/
1067 static int tst_ResultReady(void)
1072 if (i
&s_not_result_ready
) return (0);
1075 /*==========================================================================*/
1076 static int tst_Attention(void)
1081 if (i
&s_attention
) return (1);
1084 /*==========================================================================*/
1086 /*==========================================================================*/
1087 static int ResponseInfo(void)
1092 for (i
=0,timeout
=jiffies
+HZ
;i
<response_count
;i
++)
1094 for (j
=maxtim_data
; ; )
1099 if (!(st
&s_not_result_ready
)) break;
1101 if ((j
!=0)||time_after_eq(jiffies
, timeout
)) break;
1105 if (time_after_eq(jiffies
, timeout
)) break;
1106 infobuf
[i
]=inb(CDi_info
);
1109 while (!(inb(CDi_status
)&s_not_result_ready
))
1111 infobuf
[i
++]=inb(CDi_info
);
1114 if (j
>0) msg(DBG_INF
,"ResponseInfo: got %d trailing bytes.\n",j
);
1117 sprintf(&msgbuf
[j
*3]," %02X",infobuf
[j
]);
1119 msg(DBG_CMD
,"ResponseInfo:%s (%d,%d)\n",msgbuf
,response_count
,i
);
1121 if (j
>0) return (-j
);
1124 /*==========================================================================*/
1125 static void EvaluateStatus(int st
)
1127 D_S
[d
].status_bits
=0;
1128 if (fam1_drive
) D_S
[d
].status_bits
=st
|p_success
;
1129 else if (fam0_drive
)
1131 if (st
&p_caddin_old
) D_S
[d
].status_bits
|= p_door_closed
|p_caddy_in
;
1132 if (st
&p_spinning
) D_S
[d
].status_bits
|= p_spinning
;
1133 if (st
&p_check
) D_S
[d
].status_bits
|= p_check
;
1134 if (st
&p_success_old
) D_S
[d
].status_bits
|= p_success
;
1135 if (st
&p_busy_old
) D_S
[d
].status_bits
|= p_busy_new
;
1136 if (st
&p_disk_ok
) D_S
[d
].status_bits
|= p_disk_ok
;
1138 else if (famLV_drive
)
1140 D_S
[d
].status_bits
|= p_success
;
1141 if (st
&p_caddin_old
) D_S
[d
].status_bits
|= p_disk_ok
|p_caddy_in
;
1142 if (st
&p_spinning
) D_S
[d
].status_bits
|= p_spinning
;
1143 if (st
&p_check
) D_S
[d
].status_bits
|= p_check
;
1144 if (st
&p_busy_old
) D_S
[d
].status_bits
|= p_busy_new
;
1145 if (st
&p_lcs_door_closed
) D_S
[d
].status_bits
|= p_door_closed
;
1146 if (st
&p_lcs_door_locked
) D_S
[d
].status_bits
|= p_door_locked
;
1148 else if (fam2_drive
)
1150 D_S
[d
].status_bits
|= p_success
;
1151 if (st
&p2_check
) D_S
[d
].status_bits
|= p1_check
;
1152 if (st
&p2_door_closed
) D_S
[d
].status_bits
|= p1_door_closed
;
1153 if (st
&p2_disk_in
) D_S
[d
].status_bits
|= p1_disk_in
;
1154 if (st
&p2_busy1
) D_S
[d
].status_bits
|= p1_busy
;
1155 if (st
&p2_busy2
) D_S
[d
].status_bits
|= p1_busy
;
1156 if (st
&p2_spinning
) D_S
[d
].status_bits
|= p1_spinning
;
1157 if (st
&p2_door_locked
) D_S
[d
].status_bits
|= p1_door_locked
;
1158 if (st
&p2_disk_ok
) D_S
[d
].status_bits
|= p1_disk_ok
;
1160 else if (famT_drive
)
1162 return; /* still needs to get coded */
1163 D_S
[d
].status_bits
|= p_success
;
1164 if (st
&p2_check
) D_S
[d
].status_bits
|= p1_check
;
1165 if (st
&p2_door_closed
) D_S
[d
].status_bits
|= p1_door_closed
;
1166 if (st
&p2_disk_in
) D_S
[d
].status_bits
|= p1_disk_in
;
1167 if (st
&p2_busy1
) D_S
[d
].status_bits
|= p1_busy
;
1168 if (st
&p2_busy2
) D_S
[d
].status_bits
|= p1_busy
;
1169 if (st
&p2_spinning
) D_S
[d
].status_bits
|= p1_spinning
;
1170 if (st
&p2_door_locked
) D_S
[d
].status_bits
|= p1_door_locked
;
1171 if (st
&p2_disk_ok
) D_S
[d
].status_bits
|= p1_disk_ok
;
1175 /*==========================================================================*/
1176 static int get_state_T(void)
1180 static int cmd_out_T(void);
1184 drvcmd
[0]=CMDT_STATUS
;
1186 if (i
>=0) i
=infobuf
[0];
1189 msg(DBG_TEA
,"get_state_T error %d\n", i
);
1193 /* 2: closed, disk in */
1194 D_S
[d
].status_bits
=p1_door_closed
|p1_disk_in
|p1_spinning
|p1_disk_ok
;
1195 else if (D_S
[d
].error_state
==6)
1197 /* 3: closed, disk in, changed ("06 xx xx") */
1198 D_S
[d
].status_bits
=p1_door_closed
|p1_disk_in
;
1199 D_S
[d
].CD_changed
=0xFF;
1200 D_S
[d
].diskstate_flags
&= ~toc_bit
;
1202 else if ((D_S
[d
].error_state
!=2)||(D_S
[d
].b3
!=0x3A)||(D_S
[d
].b4
==0x00))
1204 /* 1: closed, no disk ("xx yy zz"or "02 3A 00") */
1205 D_S
[d
].status_bits
=p1_door_closed
;
1206 D_S
[d
].open_count
=0;
1208 else if (D_S
[d
].b4
==0x01)
1210 /* 0: open ("02 3A 01") */
1211 D_S
[d
].status_bits
=0;
1212 D_S
[d
].open_count
=0;
1216 /* 1: closed, no disk ("02 3A xx") */
1217 D_S
[d
].status_bits
=p1_door_closed
;
1218 D_S
[d
].open_count
=0;
1220 return (D_S
[d
].status_bits
);
1222 /*==========================================================================*/
1223 static int ResponseStatus(void)
1228 msg(DBG_STA
,"doing ResponseStatus...\n");
1229 if (famT_drive
) return (get_state_T());
1230 if (flags_cmd_out
& f_respo3
) timeout
= jiffies
;
1231 else if (flags_cmd_out
& f_respo2
) timeout
= jiffies
+ 16*HZ
;
1232 else timeout
= jiffies
+ 4*HZ
;
1239 if (!(i
&s_not_result_ready
)) break;
1241 if ((j
!=0)||time_after(jiffies
, timeout
)) break;
1248 if ((flags_cmd_out
& f_respo3
) == 0)
1249 msg(DBG_STA
,"ResponseStatus: timeout.\n");
1250 D_S
[d
].status_bits
=0;
1254 msg(DBG_STA
,"ResponseStatus: response %02X.\n", i
);
1256 msg(DBG_STA
,"status_bits=%02X, i=%02X\n",D_S
[d
].status_bits
,i
);
1257 return (D_S
[d
].status_bits
);
1259 /*==========================================================================*/
1260 static void cc_ReadStatus(void)
1264 msg(DBG_STA
,"giving cc_ReadStatus command\n");
1265 if (famT_drive
) return;
1267 if (fam0LV_drive
) OUT(CDo_command
,CMD0_STATUS
);
1268 else if (fam1_drive
) OUT(CDo_command
,CMD1_STATUS
);
1269 else if (fam2_drive
) OUT(CDo_command
,CMD2_STATUS
);
1270 if (!fam0LV_drive
) for (i
=0;i
<6;i
++) OUT(CDo_command
,0);
1273 /*==========================================================================*/
1274 static int cc_ReadError(void)
1279 msg(DBG_ERR
,"giving cc_ReadError command.\n");
1282 drvcmd
[0]=CMD1_READ_ERR
;
1284 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
1286 else if (fam0LV_drive
)
1288 drvcmd
[0]=CMD0_READ_ERR
;
1291 flags_cmd_out
=f_putcmd
;
1293 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
;
1295 else if (fam2_drive
)
1297 drvcmd
[0]=CMD2_READ_ERR
;
1299 flags_cmd_out
=f_putcmd
;
1301 else if (famT_drive
)
1304 drvcmd
[0]=CMDT_READ_ERR
;
1307 D_S
[d
].error_byte
=0;
1308 msg(DBG_ERR
,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i
,i
);
1309 if (i
<0) return (i
);
1310 if (fam0V_drive
) i
=1;
1312 D_S
[d
].error_byte
=infobuf
[i
];
1313 msg(DBG_ERR
,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i
,D_S
[d
].error_byte
,D_S
[d
].error_byte
);
1314 i
=sta2err(infobuf
[i
]);
1315 if (i
==-ERR_DISKCHANGE
)
1317 D_S
[d
].CD_changed
=0xFF;
1318 D_S
[d
].diskstate_flags
&= ~toc_bit
;
1322 /*==========================================================================*/
1323 static int cmd_out_T(void)
1326 #define CMDT_TRIES 1000
1327 #define TEST_FALSE_FF 1
1329 static int cc_DriveReset(void);
1330 int i
, j
, l
=0, m
, ntries
;
1333 D_S
[d
].error_state
=0;
1336 D_S
[d
].f_drv_error
=0;
1337 for (i
=0;i
<10;i
++) sprintf(&msgbuf
[i
*3]," %02X",drvcmd
[i
]);
1339 msg(DBG_CMD
,"cmd_out_T:%s\n",msgbuf
);
1342 OUT(CDo_enable
,D_S
[d
].drv_sel
);
1345 if ((f_16bit
)&&(!(i
&0x80)))
1348 msg(DBG_TEA
,"cmd_out_T: do_16bit set.\n");
1350 if (!(i
&s_not_result_ready
))
1356 msg(DBG_TEA
,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j
);
1358 while (!(i
&s_not_result_ready
));
1359 save_flags(flags
); cli();
1360 for (i
=0;i
<10;i
++) OUT(CDo_command
,drvcmd
[i
]);
1361 restore_flags(flags
);
1362 for (ntries
=CMDT_TRIES
;ntries
>0;ntries
--)
1364 if (drvcmd
[0]==CMDT_READ_VER
) sbp_sleep(HZ
); /* fixme */
1370 if ((i
=CDi_stat_loop_T()) == -1) break;
1379 if (!(i
&s_not_data_ready
)) /* f.e. CMDT_DISKINFO */
1382 if (drvcmd
[0]==CMDT_READ
) return (0); /* handled elsewhere */
1383 if (drvcmd
[0]==CMDT_DISKINFO
)
1391 infobuf
[l
++]=i
&0x0ff;
1394 if ((l
==2)&&(infobuf
[0]==0x0ff))
1396 infobuf
[0]=infobuf
[1];
1398 msg(DBG_TEA
,"cmd_out_T: do_16bit: false first byte!\n");
1400 #endif TEST_FALSE_FF
1402 else infobuf
[l
++]=inb(CDi_data
);
1405 while (!(i
&s_not_data_ready
));
1406 for (j
=0;j
<l
;j
++) sprintf(&msgbuf
[j
*3]," %02X",infobuf
[j
]);
1408 msg(DBG_CMD
,"cmd_out_T data response:%s\n", msgbuf
);
1412 msg(DBG_TEA
,"cmd_out_T: data response with cmd_%02X!\n",
1417 if (do_16bit
) i
=inw(CDi_data
);
1418 else i
=inb(CDi_data
);
1422 while (!(i
&s_not_data_ready
));
1423 msg(DBG_TEA
,"cmd_out_T: data response: discarded %d bytes/words.\n", j
);
1428 if (!(i
&s_not_result_ready
))
1431 if (drvcmd
[0]==CMDT_DISKINFO
) m
=l
;
1435 infobuf
[m
++]=inb(CDi_info
);
1438 while (!(i
&s_not_result_ready
));
1439 for (j
=0;j
<m
;j
++) sprintf(&msgbuf
[j
*3]," %02X",infobuf
[j
]);
1441 msg(DBG_CMD
,"cmd_out_T info response:%s\n", msgbuf
);
1442 if (drvcmd
[0]==CMDT_DISKINFO
)
1444 infobuf
[0]=infobuf
[l
];
1445 if (infobuf
[0]!=0x02) return (l
); /* data length */
1447 else if (infobuf
[0]!=0x02) return (m
); /* info length */
1451 if (recursion
>1) msg(DBG_TEA
,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd
[0], recursion
);
1453 drvcmd
[0]=CMDT_READ_ERR
;
1454 j
=cmd_out_T(); /* !!! recursive here !!! */
1459 D_S
[d
].error_state
=infobuf
[2];
1460 D_S
[d
].b3
=infobuf
[3];
1461 D_S
[d
].b4
=infobuf
[4];
1462 if (D_S
[d
].f_drv_error
)
1464 D_S
[d
].f_drv_error
=0;
1466 D_S
[d
].error_state
=2;
1468 return (-D_S
[d
].error_state
-400);
1470 if (drvcmd
[0]==CMDT_READ
) return (0); /* handled elsewhere */
1471 if ((teac
==0)||(ntries
<(CMDT_TRIES
-5))) sbp_sleep(HZ
/10);
1472 else sbp_sleep(HZ
/100);
1473 if (ntries
>(CMDT_TRIES
-50)) continue;
1474 msg(DBG_TEA
,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd
[0], ntries
-1);
1476 D_S
[d
].f_drv_error
=1;
1478 D_S
[d
].error_state
=2;
1481 /*==========================================================================*/
1482 static int cmd_out(void)
1486 if (famT_drive
) return(cmd_out_T());
1488 if (flags_cmd_out
&f_putcmd
)
1490 unsigned long flags
;
1492 sprintf(&msgbuf
[i
*3], " %02X", drvcmd
[i
]);
1494 msg(DBG_CMD
,"cmd_out:%s\n", msgbuf
);
1495 save_flags(flags
); cli();
1496 for (i
=0;i
<7;i
++) OUT(CDo_command
,drvcmd
[i
]);
1497 restore_flags(flags
);
1499 if (response_count
!=0)
1503 if (sbpro_type
==1) OUT(CDo_sel_i_d
,1);
1504 msg(DBG_INF
,"misleaded to try ResponseData.\n");
1505 if (sbpro_type
==1) OUT(CDo_sel_i_d
,0);
1508 else i
=ResponseInfo();
1509 if (i
<0) return (i
);
1511 if (D_S
[d
].in_SpinUp
) msg(DBG_SPI
,"in_SpinUp: to CDi_stat_loop.\n");
1512 if (flags_cmd_out
&f_lopsta
)
1515 if ((i
<0)||!(i
&s_attention
)) return (-8);
1517 if (!(flags_cmd_out
&f_getsta
)) goto LOC_229
;
1520 if (D_S
[d
].in_SpinUp
) msg(DBG_SPI
,"in_SpinUp: to cc_ReadStatus.\n");
1524 if (flags_cmd_out
&f_ResponseStatus
)
1526 if (D_S
[d
].in_SpinUp
) msg(DBG_SPI
,"in_SpinUp: to ResponseStatus.\n");
1528 /* builds status_bits, returns orig. status or p_busy_new */
1529 if (i
<0) return (i
);
1530 if (flags_cmd_out
&(f_bit1
|f_wait_if_busy
))
1534 if ((flags_cmd_out
&f_bit1
)&&(i
&p_success
)) goto LOC_232
;
1535 if ((!(flags_cmd_out
&f_wait_if_busy
))||(!st_busy
)) goto LOC_228
;
1540 if (!(flags_cmd_out
&f_obey_p_check
)) return (0);
1541 if (!st_check
) return (0);
1542 if (D_S
[d
].in_SpinUp
) msg(DBG_SPI
,"in_SpinUp: to cc_ReadError.\n");
1544 if (D_S
[d
].in_SpinUp
) msg(DBG_SPI
,"in_SpinUp: to cmd_out OK.\n");
1545 msg(DBG_000
,"cmd_out: cc_ReadError=%d\n", i
);
1548 /*==========================================================================*/
1549 static int cc_Seek(u_int pos
, char f_blk_msf
)
1554 if (f_blk_msf
>1) return (-3);
1557 drvcmd
[0]=CMD0_SEEK
;
1558 if (f_blk_msf
==1) pos
=msf2blk(pos
);
1559 drvcmd
[2]=(pos
>>16)&0x00FF;
1560 drvcmd
[3]=(pos
>>8)&0x00FF;
1561 drvcmd
[4]=pos
&0x00FF;
1563 flags_cmd_out
= f_putcmd
| f_respo2
| f_lopsta
| f_getsta
|
1564 f_ResponseStatus
| f_obey_p_check
| f_bit1
;
1566 flags_cmd_out
= f_putcmd
;
1568 else if (fam1L_drive
)
1570 drvcmd
[0]=CMD1_SEEK
; /* same as CMD1_ and CMDL_ */
1571 if (f_blk_msf
==0) pos
=blk2msf(pos
);
1572 drvcmd
[1]=(pos
>>16)&0x00FF;
1573 drvcmd
[2]=(pos
>>8)&0x00FF;
1574 drvcmd
[3]=pos
&0x00FF;
1576 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
1578 flags_cmd_out
=f_putcmd
|f_respo2
|f_ResponseStatus
|f_obey_p_check
;
1580 else if (fam2_drive
)
1582 drvcmd
[0]=CMD2_SEEK
;
1583 if (f_blk_msf
==0) pos
=blk2msf(pos
);
1584 drvcmd
[2]=(pos
>>24)&0x00FF;
1585 drvcmd
[3]=(pos
>>16)&0x00FF;
1586 drvcmd
[4]=(pos
>>8)&0x00FF;
1587 drvcmd
[5]=pos
&0x00FF;
1588 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
1590 else if (famT_drive
)
1592 drvcmd
[0]=CMDT_SEEK
;
1593 if (f_blk_msf
==1) pos
=msf2blk(pos
);
1594 drvcmd
[2]=(pos
>>24)&0x00FF;
1595 drvcmd
[3]=(pos
>>16)&0x00FF;
1596 drvcmd
[4]=(pos
>>8)&0x00FF;
1597 drvcmd
[5]=pos
&0x00FF;
1604 /*==========================================================================*/
1605 static int cc_SpinUp(void)
1609 msg(DBG_SPI
,"SpinUp.\n");
1610 D_S
[d
].in_SpinUp
= 1;
1614 drvcmd
[0]=CMD0_SPINUP
;
1616 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|
1617 f_ResponseStatus
|f_obey_p_check
|f_bit1
;
1619 flags_cmd_out
=f_putcmd
;
1621 else if (fam1_drive
)
1623 drvcmd
[0]=CMD1_SPINUP
;
1624 flags_cmd_out
=f_putcmd
|f_respo2
|f_ResponseStatus
|f_obey_p_check
;
1626 else if (fam2_drive
)
1628 drvcmd
[0]=CMD2_TRAY_CTL
;
1629 drvcmd
[4]=0x01; /* "spinup" */
1630 flags_cmd_out
=f_putcmd
|f_respo2
|f_ResponseStatus
|f_obey_p_check
;
1632 else if (famT_drive
)
1634 drvcmd
[0]=CMDT_TRAY_CTL
;
1635 drvcmd
[4]=0x03; /* "insert", it hopefully spins the drive up */
1639 D_S
[d
].in_SpinUp
= 0;
1642 /*==========================================================================*/
1643 static int cc_SpinDown(void)
1647 if (fam0_drive
) return (0);
1652 drvcmd
[0]=CMD1_SPINDOWN
;
1653 flags_cmd_out
=f_putcmd
|f_respo2
|f_ResponseStatus
|f_obey_p_check
;
1655 else if (fam2_drive
)
1657 drvcmd
[0]=CMD2_TRAY_CTL
;
1658 drvcmd
[4]=0x02; /* "eject" */
1659 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
1661 else if (famL_drive
)
1663 drvcmd
[0]=CMDL_SPINDOWN
;
1665 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
1667 else if (famV_drive
)
1669 drvcmd
[0]=CMDV_SPINDOWN
;
1670 flags_cmd_out
=f_putcmd
;
1672 else if (famT_drive
)
1674 drvcmd
[0]=CMDT_TRAY_CTL
;
1675 drvcmd
[4]=0x02; /* "eject" */
1680 /*==========================================================================*/
1681 static int cc_get_mode_T(void)
1687 drvcmd
[0]=CMDT_GETMODE
;
1688 drvcmd
[4]=response_count
;
1692 /*==========================================================================*/
1693 static int cc_set_mode_T(void)
1699 drvcmd
[0]=CMDT_SETMODE
;
1700 drvcmd
[1]=D_S
[d
].speed_byte
;
1701 drvcmd
[2]=D_S
[d
].frmsiz
>>8;
1702 drvcmd
[3]=D_S
[d
].frmsiz
&0x0FF;
1703 drvcmd
[4]=D_S
[d
].f_XA
; /* 1: XA */
1704 drvcmd
[5]=D_S
[d
].type_byte
; /* 0, 1, 3 */
1705 drvcmd
[6]=D_S
[d
].mode_xb_6
;
1706 drvcmd
[7]=D_S
[d
].mode_yb_7
|D_S
[d
].volume_control
;
1707 drvcmd
[8]=D_S
[d
].mode_xb_8
;
1708 drvcmd
[9]=D_S
[d
].delay
;
1712 /*==========================================================================*/
1713 static int cc_prep_mode_T(void)
1718 if (i
<0) return (i
);
1720 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
1722 msg(DBG_TEA
,"CMDT_GETMODE:%s\n", msgbuf
);
1723 D_S
[d
].speed_byte
=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
1724 D_S
[d
].frmsiz
=make16(infobuf
[2],infobuf
[3]);
1725 D_S
[d
].f_XA
=infobuf
[4];
1726 if (D_S
[d
].f_XA
==0) D_S
[d
].type_byte
=0;
1727 else D_S
[d
].type_byte
=1;
1728 D_S
[d
].mode_xb_6
=infobuf
[6];
1730 D_S
[d
].mode_xb_8
=infobuf
[8];
1731 D_S
[d
].delay
=0; /* 0, 1, 2, 3 */
1735 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
1737 msg(DBG_TEA
,"CMDT_GETMODE:%s\n", msgbuf
);
1740 /*==========================================================================*/
1741 static int cc_SetSpeed(u_char speed
, u_char x1
, u_char x2
)
1745 if (fam0LV_drive
) return (0);
1750 drvcmd
[0]=CMD1_SETMODE
;
1755 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
1757 else if (fam2_drive
)
1759 drvcmd
[0]=CMD2_SETSPEED
;
1760 if (speed
&speed_auto
)
1770 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
1772 else if (famT_drive
)
1779 /*==========================================================================*/
1780 static int cc_SetVolume(void)
1783 u_char channel0
,channel1
,volume0
,volume1
;
1784 u_char control0
,value0
,control1
,value1
;
1786 D_S
[d
].diskstate_flags
&= ~volume_bit
;
1788 channel0
=D_S
[d
].vol_chan0
;
1789 volume0
=D_S
[d
].vol_ctrl0
;
1790 channel1
=control1
=D_S
[d
].vol_chan1
;
1791 volume1
=value1
=D_S
[d
].vol_ctrl1
;
1794 if (famV_drive
) return (0);
1796 if (((D_S
[d
].drv_options
&audio_mono
)!=0)&&(D_S
[d
].drv_type
>=drv_211
))
1798 if ((volume0
!=0)&&(volume1
==0))
1803 else if ((volume0
==0)&&(volume1
!=0))
1822 control0
=channel0
+1;
1823 control1
=channel1
+1;
1824 value0
=(volume0
>volume1
)?volume0
:volume1
;
1826 if (volume0
==0) control0
=0;
1827 if (volume1
==0) control1
=0;
1828 drvcmd
[0]=CMD1_SETMODE
;
1834 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
1836 else if (fam2_drive
)
1838 control0
=channel0
+1;
1839 control1
=channel1
+1;
1840 value0
=(volume0
>volume1
)?volume0
:volume1
;
1842 if (volume0
==0) control0
=0;
1843 if (volume1
==0) control1
=0;
1844 drvcmd
[0]=CMD2_SETMODE
;
1850 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
1852 else if (famL_drive
)
1854 if ((volume0
==0)||(channel0
!=0)) control0
|= 0x80;
1855 if ((volume1
==0)||(channel1
!=1)) control0
|= 0x40;
1856 if (volume0
|volume1
) value0
=0x80;
1857 drvcmd
[0]=CMDL_SETMODE
;
1861 flags_cmd_out
=f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
1863 else if (fam0_drive
) /* different firmware levels */
1865 if (D_S
[d
].drv_type
>=drv_300
)
1867 control0
=volume0
&0xFC;
1868 value0
=volume1
&0xFC;
1869 if ((volume0
!=0)&&(volume0
<4)) control0
|= 0x04;
1870 if ((volume1
!=0)&&(volume1
<4)) value0
|= 0x04;
1871 if (channel0
!=0) control0
|= 0x01;
1872 if (channel1
==1) value0
|= 0x01;
1876 value0
=(volume0
>volume1
)?volume0
:volume1
;
1877 if (D_S
[d
].drv_type
<drv_211
)
1888 if (channel0
==channel1
)
1905 if ((volume0
!=0)&&(volume1
!=0))
1907 if (volume0
==0xFF) volume1
=0xFF;
1908 else if (volume1
==0xFF) volume0
=0xFF;
1910 else if (D_S
[d
].drv_type
<drv_201
) volume0
=volume1
=value0
;
1912 if (D_S
[d
].drv_type
>=drv_201
)
1914 if (volume0
==0) control0
|= 0x80;
1915 if (volume1
==0) control0
|= 0x40;
1917 if (D_S
[d
].drv_type
>=drv_211
)
1919 if (channel0
!=0) control0
|= 0x20;
1920 if (channel1
!=1) control0
|= 0x10;
1923 drvcmd
[0]=CMD0_SETMODE
;
1927 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
1929 else if (famT_drive
)
1931 D_S
[d
].volume_control
=0;
1932 if (!volume0
) D_S
[d
].volume_control
|=0x10;
1933 if (!volume1
) D_S
[d
].volume_control
|=0x20;
1935 if (i
<0) return (i
);
1941 if (i
<0) return (i
);
1943 D_S
[d
].diskstate_flags
|= volume_bit
;
1946 /*==========================================================================*/
1947 static int GetStatus(void)
1951 if (famT_drive
) return (0);
1952 flags_cmd_out
=f_getsta
|f_ResponseStatus
|f_obey_p_check
;
1958 /*==========================================================================*/
1959 static int cc_DriveReset(void)
1963 msg(DBG_RES
,"cc_DriveReset called.\n");
1966 if (fam0LV_drive
) OUT(CDo_reset
,0x00);
1967 else if (fam1_drive
)
1969 drvcmd
[0]=CMD1_RESET
;
1970 flags_cmd_out
=f_putcmd
;
1973 else if (fam2_drive
)
1975 drvcmd
[0]=CMD2_RESET
;
1976 flags_cmd_out
=f_putcmd
;
1978 OUT(CDo_reset
,0x00);
1980 else if (famT_drive
)
1983 OUT(CDo_enable
,D_S
[d
].drv_sel
);
1984 OUT(CDo_command
,CMDT_RESET
);
1985 for (i
=1;i
<10;i
++) OUT(CDo_command
,0);
1987 if (fam0LV_drive
) sbp_sleep(5*HZ
); /* wait 5 seconds */
1988 else sbp_sleep(1*HZ
); /* wait a second */
1992 msg(DBG_TEA
, "================CMDT_RESET given=================.\n");
2000 if (D_S
[d
].error_byte
!=aud_12
) return -501;
2004 /*==========================================================================*/
2005 static int SetSpeed(void)
2009 if (!(D_S
[d
].drv_options
&(speed_auto
|speed_300
|speed_150
))) return (0);
2011 if (!(D_S
[d
].drv_options
&speed_auto
))
2014 if (!(D_S
[d
].drv_options
&speed_300
)) speed
=0;
2016 i
=cc_SetSpeed(speed
,0,0);
2020 static void switch_drive(int i
);
2022 static int sbpcd_select_speed(struct cdrom_device_info
*cdi
, int speed
)
2024 int i
= MINOR(cdi
->dev
);
2029 return cc_SetSpeed(speed
== 2 ? speed_300
: speed_150
, 0, 0);
2032 /*==========================================================================*/
2033 static int DriveReset(void)
2038 if (i
<0) return (-22);
2042 if ((i
<0)&&(i
!=-ERR_DISKCHANGE
)) return (-2); /* from sta2err */
2043 if (!st_caddy_in
) break;
2048 D_S
[d
].CD_changed
=1;
2050 if ((st_door_closed
) && (st_caddy_in
))
2053 if (i
<0) return (-23);
2058 static int sbpcd_reset(struct cdrom_device_info
*cdi
)
2060 int i
= MINOR(cdi
->dev
);
2065 return DriveReset();
2068 /*==========================================================================*/
2069 static int cc_PlayAudio(int pos_audio_start
,int pos_audio_end
)
2073 if (D_S
[d
].audio_state
==audio_playing
) return (-EINVAL
);
2078 drvcmd
[0]=CMDL_PLAY
;
2079 i
=msf2blk(pos_audio_start
);
2080 n
=msf2blk(pos_audio_end
)+1-i
;
2081 drvcmd
[1]=(i
>>16)&0x00FF;
2082 drvcmd
[2]=(i
>>8)&0x00FF;
2084 drvcmd
[4]=(n
>>16)&0x00FF;
2085 drvcmd
[5]=(n
>>8)&0x00FF;
2088 flags_cmd_out
= f_putcmd
| f_respo2
| f_lopsta
| f_getsta
|
2089 f_ResponseStatus
| f_obey_p_check
| f_wait_if_busy
;
2091 flags_cmd_out
= f_putcmd
;
2098 drvcmd
[0]=CMD1_PLAY_MSF
;
2099 flags_cmd_out
= f_putcmd
| f_respo2
| f_ResponseStatus
|
2100 f_obey_p_check
| f_wait_if_busy
;
2102 else if (fam2_drive
)
2104 drvcmd
[0]=CMD2_PLAY_MSF
;
2105 flags_cmd_out
= f_putcmd
| f_ResponseStatus
| f_obey_p_check
;
2107 else if (famT_drive
)
2109 drvcmd
[0]=CMDT_PLAY_MSF
;
2113 else if (fam0_drive
)
2115 drvcmd
[0]=CMD0_PLAY_MSF
;
2116 flags_cmd_out
= f_putcmd
| f_respo2
| f_lopsta
| f_getsta
|
2117 f_ResponseStatus
| f_obey_p_check
| f_wait_if_busy
;
2119 drvcmd
[j
]=(pos_audio_start
>>16)&0x00FF;
2120 drvcmd
[j
+1]=(pos_audio_start
>>8)&0x00FF;
2121 drvcmd
[j
+2]=pos_audio_start
&0x00FF;
2122 drvcmd
[j
+3]=(pos_audio_end
>>16)&0x00FF;
2123 drvcmd
[j
+4]=(pos_audio_end
>>8)&0x00FF;
2124 drvcmd
[j
+5]=pos_audio_end
&0x00FF;
2129 /*==========================================================================*/
2130 static int cc_Pause_Resume(int pau_res
)
2138 drvcmd
[0]=CMD1_PAU_RES
;
2139 if (pau_res
!=1) drvcmd
[1]=0x80;
2140 flags_cmd_out
=f_putcmd
|f_respo2
|f_ResponseStatus
|f_obey_p_check
;
2142 else if (fam2_drive
)
2144 drvcmd
[0]=CMD2_PAU_RES
;
2145 if (pau_res
!=1) drvcmd
[2]=0x01;
2146 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
2148 else if (fam0LV_drive
)
2150 drvcmd
[0]=CMD0_PAU_RES
;
2151 if (pau_res
!=1) drvcmd
[1]=0x80;
2153 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|
2154 f_obey_p_check
|f_bit1
;
2155 else if (famV_drive
)
2156 flags_cmd_out
=f_putcmd
;
2158 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|
2161 else if (famT_drive
)
2163 if (pau_res
==3) return (cc_PlayAudio(D_S
[d
].pos_audio_start
,D_S
[d
].pos_audio_end
));
2164 else if (pau_res
==1) drvcmd
[0]=CMDT_PAUSE
;
2170 /*==========================================================================*/
2171 static int cc_LockDoor(char lock
)
2175 if (fam0_drive
) return (0);
2176 msg(DBG_LCK
,"cc_LockDoor: %d (drive %d)\n", lock
, d
);
2177 msg(DBG_LCS
,"p_door_locked bit %d before\n", st_door_locked
);
2182 drvcmd
[0]=CMD1_LOCK_CTL
;
2183 if (lock
==1) drvcmd
[1]=0x01;
2184 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2186 else if (fam2_drive
)
2188 drvcmd
[0]=CMD2_LOCK_CTL
;
2189 if (lock
==1) drvcmd
[4]=0x01;
2190 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
2192 else if (famLV_drive
)
2194 drvcmd
[0]=CMDL_LOCK_CTL
;
2195 if (lock
==1) drvcmd
[1]=0x01;
2197 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
2199 flags_cmd_out
=f_putcmd
;
2201 else if (famT_drive
)
2203 drvcmd
[0]=CMDT_LOCK_CTL
;
2204 if (lock
==1) drvcmd
[4]=0x01;
2207 msg(DBG_LCS
,"p_door_locked bit %d after\n", st_door_locked
);
2210 /*==========================================================================*/
2211 /*==========================================================================*/
2212 static int UnLockDoor(void)
2231 /*==========================================================================*/
2232 static int LockDoor(void)
2259 static int sbpcd_lock_door(struct cdrom_device_info
*cdi
, int lock
)
2261 return lock
? LockDoor() : UnLockDoor();
2264 /*==========================================================================*/
2265 static int cc_CloseTray(void)
2269 if (fam0_drive
) return (0);
2270 msg(DBG_LCK
,"cc_CloseTray (drive %d)\n", d
);
2271 msg(DBG_LCS
,"p_door_closed bit %d before\n", st_door_closed
);
2277 drvcmd
[0]=CMD1_TRAY_CTL
;
2278 flags_cmd_out
=f_putcmd
|f_respo2
|f_ResponseStatus
|f_obey_p_check
;
2280 else if (fam2_drive
)
2282 drvcmd
[0]=CMD2_TRAY_CTL
;
2284 drvcmd
[4]=0x03; /* "insert" */
2285 flags_cmd_out
=f_putcmd
|f_ResponseStatus
;
2287 else if (famLV_drive
)
2289 drvcmd
[0]=CMDL_TRAY_CTL
;
2291 flags_cmd_out
=f_putcmd
|f_respo2
|f_lopsta
|f_getsta
|
2292 f_ResponseStatus
|f_obey_p_check
|f_bit1
;
2294 flags_cmd_out
=f_putcmd
;
2296 else if (famT_drive
)
2298 drvcmd
[0]=CMDT_TRAY_CTL
;
2299 drvcmd
[4]=0x03; /* "insert" */
2302 msg(DBG_LCS
,"p_door_closed bit %d after\n", st_door_closed
);
2305 flags_cmd_out
|= f_respo2
;
2306 cc_ReadStatus(); /* command: give 1-byte status */
2308 if (famT_drive
&&(i
<0))
2319 msg(DBG_INF
,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i
);
2326 if (st_check
) i
=cc_ReadError();
2327 flags_cmd_out
|= f_respo2
;
2337 static int sbpcd_tray_move(struct cdrom_device_info
*cdi
, int position
)
2340 i
= MINOR(cdi
->dev
);
2343 if (position
== 1) {
2346 return cc_CloseTray();
2351 /*==========================================================================*/
2352 static int cc_ReadSubQ(void)
2356 D_S
[d
].diskstate_flags
&= ~subq_bit
;
2362 drvcmd
[0]=CMD1_READSUBQ
;
2363 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2366 else if (fam2_drive
)
2368 drvcmd
[0]=CMD2_READSUBQ
;
2371 flags_cmd_out
=f_putcmd
;
2374 else if (fam0LV_drive
)
2376 drvcmd
[0]=CMD0_READSUBQ
;
2379 flags_cmd_out
=f_putcmd
;
2381 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2384 else if (famT_drive
)
2387 drvcmd
[0]=CMDT_READSUBQ
;
2391 drvcmd
[8]=response_count
;
2394 if (i
<0) return (i
);
2395 for (i
=0;i
<response_count
;i
++)
2397 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
2399 msg(DBG_SQ1
,"cc_ReadSubQ:%s\n", msgbuf
);
2401 if (famT_drive
) break;
2402 if (infobuf
[0]!=0) break;
2403 if ((!st_spinning
) || (j
==1))
2405 D_S
[d
].SubQ_ctl_adr
=D_S
[d
].SubQ_trk
=D_S
[d
].SubQ_pnt_idx
=D_S
[d
].SubQ_whatisthis
=0;
2406 D_S
[d
].SubQ_run_tot
=D_S
[d
].SubQ_run_trk
=0;
2410 if (famT_drive
) D_S
[d
].SubQ_ctl_adr
=infobuf
[1];
2411 else D_S
[d
].SubQ_ctl_adr
=swap_nibbles(infobuf
[1]);
2412 D_S
[d
].SubQ_trk
=byt2bcd(infobuf
[2]);
2413 D_S
[d
].SubQ_pnt_idx
=byt2bcd(infobuf
[3]);
2414 if (fam0LV_drive
) i
=5;
2415 else if (fam12_drive
) i
=4;
2416 else if (famT_drive
) i
=8;
2417 D_S
[d
].SubQ_run_tot
=make32(make16(0,infobuf
[i
]),make16(infobuf
[i
+1],infobuf
[i
+2])); /* msf-bin */
2419 if (fam0LV_drive
) i
=9;
2420 else if (fam12_drive
) i
=7;
2421 else if (famT_drive
) i
=4;
2422 D_S
[d
].SubQ_run_trk
=make32(make16(0,infobuf
[i
]),make16(infobuf
[i
+1],infobuf
[i
+2])); /* msf-bin */
2423 D_S
[d
].SubQ_whatisthis
=infobuf
[i
+3];
2424 D_S
[d
].diskstate_flags
|= subq_bit
;
2427 /*==========================================================================*/
2428 static int cc_ModeSense(void)
2432 if (fam2_drive
) return (0);
2433 if (famV_drive
) return (0);
2434 D_S
[d
].diskstate_flags
&= ~frame_size_bit
;
2439 drvcmd
[0]=CMD1_GETMODE
;
2440 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2442 else if (fam0L_drive
)
2445 drvcmd
[0]=CMD0_GETMODE
;
2446 if (famL_drive
) flags_cmd_out
=f_putcmd
;
2447 else flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2449 else if (famT_drive
)
2452 drvcmd
[0]=CMDT_GETMODE
;
2453 drvcmd
[4]=response_count
;
2456 if (i
<0) return (i
);
2458 D_S
[d
].sense_byte
=0;
2459 if (fam1_drive
) D_S
[d
].sense_byte
=infobuf
[i
++];
2460 else if (famT_drive
)
2462 if (infobuf
[4]==0x01) D_S
[d
].xa_byte
=0x20;
2463 else D_S
[d
].xa_byte
=0;
2466 D_S
[d
].frame_size
=make16(infobuf
[i
],infobuf
[i
+1]);
2467 for (i
=0;i
<response_count
;i
++)
2468 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
2470 msg(DBG_XA1
,"cc_ModeSense:%s\n", msgbuf
);
2472 D_S
[d
].diskstate_flags
|= frame_size_bit
;
2475 /*==========================================================================*/
2476 /*==========================================================================*/
2477 static int cc_ModeSelect(int framesize
)
2481 if (fam2_drive
) return (0);
2482 if (famV_drive
) return (0);
2483 D_S
[d
].diskstate_flags
&= ~frame_size_bit
;
2485 D_S
[d
].frame_size
=framesize
;
2486 if (framesize
==CD_FRAMESIZE_RAW
) D_S
[d
].sense_byte
=0x82;
2487 else D_S
[d
].sense_byte
=0x00;
2489 msg(DBG_XA1
,"cc_ModeSelect: %02X %04X\n",
2490 D_S
[d
].sense_byte
, D_S
[d
].frame_size
);
2494 drvcmd
[0]=CMD1_SETMODE
;
2496 drvcmd
[2]=D_S
[d
].sense_byte
;
2497 drvcmd
[3]=(D_S
[d
].frame_size
>>8)&0xFF;
2498 drvcmd
[4]=D_S
[d
].frame_size
&0xFF;
2499 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2501 else if (fam0L_drive
)
2503 drvcmd
[0]=CMD0_SETMODE
;
2505 drvcmd
[2]=(D_S
[d
].frame_size
>>8)&0xFF;
2506 drvcmd
[3]=D_S
[d
].frame_size
&0xFF;
2509 flags_cmd_out
=f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2511 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2513 else if (famT_drive
)
2519 if (i
<0) return (i
);
2520 D_S
[d
].diskstate_flags
|= frame_size_bit
;
2523 /*==========================================================================*/
2524 static int cc_GetVolume(void)
2533 if (famV_drive
) return (0);
2534 D_S
[d
].diskstate_flags
&= ~volume_bit
;
2538 drvcmd
[0]=CMD1_GETMODE
;
2541 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2543 else if (fam2_drive
)
2545 drvcmd
[0]=CMD2_GETMODE
;
2548 flags_cmd_out
=f_putcmd
;
2550 else if (fam0L_drive
)
2552 drvcmd
[0]=CMD0_GETMODE
;
2556 flags_cmd_out
=f_putcmd
;
2558 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2560 else if (famT_drive
)
2563 if (i
<0) return (i
);
2568 if (i
<0) return (i
);
2572 chan0
=infobuf
[1]&0x0F;
2574 chan1
=infobuf
[3]&0x0F;
2589 else if (fam2_drive
)
2596 else if (famL_drive
)
2600 vol0
=vol1
=infobuf
[1];
2601 switches
=infobuf
[0];
2602 if ((switches
&0x80)!=0) chan0
=1;
2603 if ((switches
&0x40)!=0) chan1
=0;
2605 else if (fam0_drive
) /* different firmware levels */
2609 vol0
=vol1
=infobuf
[1];
2610 if (D_S
[d
].drv_type
>=drv_201
)
2612 if (D_S
[d
].drv_type
<drv_300
)
2614 switches
=infobuf
[0];
2615 if ((switches
&0x80)!=0) vol0
=0;
2616 if ((switches
&0x40)!=0) vol1
=0;
2617 if (D_S
[d
].drv_type
>=drv_211
)
2619 if ((switches
&0x20)!=0) chan0
=1;
2620 if ((switches
&0x10)!=0) chan1
=0;
2626 if ((vol0
&0x01)!=0) chan0
=1;
2627 if ((vol1
&0x01)==0) chan1
=0;
2630 if (vol0
!=0) vol0
+= 3;
2631 if (vol1
!=0) vol1
+= 3;
2635 else if (famT_drive
)
2637 D_S
[d
].volume_control
=infobuf
[7];
2640 if (D_S
[d
].volume_control
&0x10) vol0
=0;
2642 if (D_S
[d
].volume_control
&0x20) vol1
=0;
2645 D_S
[d
].vol_chan0
=chan0
;
2646 D_S
[d
].vol_ctrl0
=vol0
;
2647 D_S
[d
].vol_chan1
=chan1
;
2648 D_S
[d
].vol_ctrl1
=vol1
;
2651 D_S
[d
].vol_ctrl2
=0xFF;
2653 D_S
[d
].vol_ctrl3
=0xFF;
2655 D_S
[d
].diskstate_flags
|= volume_bit
;
2658 /*==========================================================================*/
2659 static int cc_ReadCapacity(void)
2663 if (fam2_drive
) return (0); /* some firmware lacks this command */
2664 if (famLV_drive
) return (0); /* some firmware lacks this command */
2665 if (famT_drive
) return (0); /* done with cc_ReadTocDescr() */
2666 D_S
[d
].diskstate_flags
&= ~cd_size_bit
;
2672 drvcmd
[0]=CMD1_CAPACITY
;
2674 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2677 else if (fam2_drive
)
2679 drvcmd
[0]=CMD2_CAPACITY
;
2681 flags_cmd_out
=f_putcmd
;
2684 else if (fam0_drive
)
2686 drvcmd
[0]=CMD0_CAPACITY
;
2688 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2692 msg(DBG_000
,"cc_ReadCapacity: cmd_out: err %d\n", i
);
2695 if (j
==0) return (i
);
2696 if (fam1_drive
) D_S
[d
].CDsize_frm
=msf2blk(make32(make16(0,infobuf
[0]),make16(infobuf
[1],infobuf
[2])))+CD_MSF_OFFSET
;
2697 else if (fam0_drive
) D_S
[d
].CDsize_frm
=make32(make16(0,infobuf
[0]),make16(infobuf
[1],infobuf
[2]));
2699 else if (fam2_drive
) D_S
[d
].CDsize_frm
=make32(make16(infobuf
[0],infobuf
[1]),make16(infobuf
[2],infobuf
[3]));
2701 D_S
[d
].diskstate_flags
|= cd_size_bit
;
2702 msg(DBG_000
,"cc_ReadCapacity: %d frames.\n", D_S
[d
].CDsize_frm
);
2705 /*==========================================================================*/
2706 static int cc_ReadTocDescr(void)
2710 D_S
[d
].diskstate_flags
&= ~toc_bit
;
2714 drvcmd
[0]=CMD1_DISKINFO
;
2716 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2718 else if (fam0LV_drive
)
2720 drvcmd
[0]=CMD0_DISKINFO
;
2723 flags_cmd_out
=f_putcmd
;
2725 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2727 else if (fam2_drive
)
2729 /* possibly longer timeout periods necessary */
2730 D_S
[d
].f_multisession
=0;
2731 drvcmd
[0]=CMD2_DISKINFO
;
2734 drvcmd
[3]=0xFF; /* session */
2736 flags_cmd_out
=f_putcmd
;
2738 else if (famT_drive
)
2740 D_S
[d
].f_multisession
=0;
2742 drvcmd
[0]=CMDT_DISKINFO
;
2744 drvcmd
[6]=CDROM_LEADOUT
;
2745 drvcmd
[8]=response_count
;
2749 if (i
<0) return (i
);
2750 if ((famT_drive
)&&(i
<response_count
)) return (-100-i
);
2751 if ((fam1_drive
)||(fam2_drive
)||(fam0LV_drive
))
2752 D_S
[d
].xa_byte
=infobuf
[0];
2755 D_S
[d
].first_session
=infobuf
[1];
2756 D_S
[d
].last_session
=infobuf
[2];
2757 D_S
[d
].n_first_track
=infobuf
[3];
2758 D_S
[d
].n_last_track
=infobuf
[4];
2759 if (D_S
[d
].first_session
!=D_S
[d
].last_session
)
2761 D_S
[d
].f_multisession
=1;
2762 D_S
[d
].lba_multi
=msf2blk(make32(make16(0,infobuf
[5]),make16(infobuf
[6],infobuf
[7])));
2765 if (D_S
[d
].first_session
!=D_S
[d
].last_session
)
2767 if (D_S
[d
].last_session
<=20)
2768 zwanzig
=D_S
[d
].last_session
+1;
2770 for (count
=D_S
[d
].first_session
;count
<zwanzig
;count
++)
2772 drvcmd
[0]=CMD2_DISKINFO
;
2777 flags_cmd_out
=f_putcmd
;
2779 if (i
<0) return (i
);
2780 D_S
[d
].msf_multi_n
[count
]=make32(make16(0,infobuf
[5]),make16(infobuf
[6],infobuf
[7]));
2782 D_S
[d
].diskstate_flags
|= multisession_bit
;
2785 drvcmd
[0]=CMD2_DISKINFO
;
2790 flags_cmd_out
=f_putcmd
;
2792 if (i
<0) return (i
);
2793 D_S
[d
].size_msf
=make32(make16(0,infobuf
[2]),make16(infobuf
[3],infobuf
[4]));
2794 D_S
[d
].size_blk
=msf2blk(D_S
[d
].size_msf
);
2795 D_S
[d
].CDsize_frm
=D_S
[d
].size_blk
+1;
2797 else if (famT_drive
)
2799 D_S
[d
].size_msf
=make32(make16(infobuf
[8],infobuf
[9]),make16(infobuf
[10],infobuf
[11]));
2800 D_S
[d
].size_blk
=msf2blk(D_S
[d
].size_msf
);
2801 D_S
[d
].CDsize_frm
=D_S
[d
].size_blk
+1;
2802 D_S
[d
].n_first_track
=infobuf
[2];
2803 D_S
[d
].n_last_track
=infobuf
[3];
2807 D_S
[d
].n_first_track
=infobuf
[1];
2808 D_S
[d
].n_last_track
=infobuf
[2];
2809 D_S
[d
].size_msf
=make32(make16(0,infobuf
[3]),make16(infobuf
[4],infobuf
[5]));
2810 D_S
[d
].size_blk
=msf2blk(D_S
[d
].size_msf
);
2811 if (famLV_drive
) D_S
[d
].CDsize_frm
=D_S
[d
].size_blk
+1;
2813 D_S
[d
].diskstate_flags
|= toc_bit
;
2814 msg(DBG_TOC
,"TocDesc: xa %02X firstt %02X lastt %02X size %08X firstses %02X lastsess %02X\n",
2816 D_S
[d
].n_first_track
,
2817 D_S
[d
].n_last_track
,
2819 D_S
[d
].first_session
,
2820 D_S
[d
].last_session
);
2823 /*==========================================================================*/
2824 static int cc_ReadTocEntry(int num
)
2831 drvcmd
[0]=CMD1_READTOC
;
2834 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2836 else if (fam2_drive
)
2838 /* possibly longer timeout periods necessary */
2839 drvcmd
[0]=CMD2_DISKINFO
;
2843 flags_cmd_out
=f_putcmd
;
2845 else if (fam0LV_drive
)
2847 drvcmd
[0]=CMD0_READTOC
;
2852 flags_cmd_out
=f_putcmd
;
2854 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2856 else if (famT_drive
)
2859 drvcmd
[0]=CMDT_DISKINFO
;
2862 drvcmd
[8]=response_count
;
2866 if (i
<0) return (i
);
2867 if ((famT_drive
)&&(i
<response_count
)) return (-100-i
);
2868 if ((fam1_drive
)||(fam0LV_drive
))
2870 D_S
[d
].TocEnt_nixbyte
=infobuf
[0];
2873 else if (fam2_drive
) i
=0;
2874 else if (famT_drive
) i
=5;
2875 D_S
[d
].TocEnt_ctl_adr
=swap_nibbles(infobuf
[i
++]);
2876 if ((fam1_drive
)||(fam0L_drive
))
2878 D_S
[d
].TocEnt_number
=infobuf
[i
++];
2879 D_S
[d
].TocEnt_format
=infobuf
[i
];
2883 D_S
[d
].TocEnt_number
=num
;
2884 D_S
[d
].TocEnt_format
=0;
2886 if (fam1_drive
) i
=4;
2887 else if (fam0LV_drive
) i
=5;
2888 else if (fam2_drive
) i
=2;
2889 else if (famT_drive
) i
=9;
2890 D_S
[d
].TocEnt_address
=make32(make16(0,infobuf
[i
]),
2891 make16(infobuf
[i
+1],infobuf
[i
+2]));
2892 for (i
=0;i
<response_count
;i
++)
2893 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
2895 msg(DBG_ECS
,"TocEntry:%s\n", msgbuf
);
2896 msg(DBG_TOC
,"TocEntry: %02X %02X %02X %02X %08X\n",
2897 D_S
[d
].TocEnt_nixbyte
, D_S
[d
].TocEnt_ctl_adr
,
2898 D_S
[d
].TocEnt_number
, D_S
[d
].TocEnt_format
,
2899 D_S
[d
].TocEnt_address
);
2902 /*==========================================================================*/
2903 static int cc_ReadPacket(void)
2908 drvcmd
[0]=CMD0_PACKET
;
2909 drvcmd
[1]=response_count
;
2910 if(famL_drive
) flags_cmd_out
=f_putcmd
;
2911 else if (fam01_drive
)
2912 flags_cmd_out
=f_putcmd
|f_getsta
|f_ResponseStatus
|f_obey_p_check
;
2913 else if (fam2_drive
) return (-1); /* not implemented yet */
2914 else if (famT_drive
)
2921 /*==========================================================================*/
2922 static int convert_UPC(u_char
*p
)
2927 if (fam0L_drive
) p
[13]=0;
2930 if (fam1_drive
) D_S
[d
].UPC_buf
[i
]=swap_nibbles(*p
++);
2931 else if (fam0L_drive
)
2933 D_S
[d
].UPC_buf
[i
]=((*p
++)<<4)&0xFF;
2934 D_S
[d
].UPC_buf
[i
] |= *p
++;
2936 else if (famT_drive
)
2945 D_S
[d
].UPC_buf
[6] &= 0xF0;
2948 /*==========================================================================*/
2949 static int cc_ReadUPC(void)
2953 int block
, checksum
;
2956 if (fam2_drive
) return (0); /* not implemented yet */
2957 if (famT_drive
) return (0); /* not implemented yet */
2958 if (famV_drive
) return (0); /* not implemented yet */
2960 if (fam0_drive
) return (0); /* but it should work */
2963 D_S
[d
].diskstate_flags
&= ~upc_bit
;
2965 for (block
=CD_MSF_OFFSET
+1;block
<CD_MSF_OFFSET
+200;block
++)
2971 drvcmd
[0]=CMD1_READ_UPC
;
2973 drvcmd
[1]=(block
>>16)&0xFF;
2974 drvcmd
[2]=(block
>>8)&0xFF;
2975 drvcmd
[3]=block
&0xFF;
2978 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
2980 else if (fam0L_drive
)
2982 drvcmd
[0]=CMD0_READ_UPC
;
2984 drvcmd
[2]=(block
>>16)&0xFF;
2985 drvcmd
[3]=(block
>>8)&0xFF;
2986 drvcmd
[4]=block
&0xFF;
2989 flags_cmd_out
=f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
2991 else if (fam2_drive
)
2995 else if (famT_drive
)
3002 msg(DBG_000
,"cc_ReadUPC cmd_out: err %d\n", i
);
3008 if (famL_drive
) flags_cmd_out
=f_putcmd
;
3012 msg(DBG_000
,"cc_ReadUPC ReadPacket: err %d\n", i
);
3019 for (i
=0;i
<(fam1_drive
?8:16);i
++)
3022 checksum
|= infobuf
[i
];
3024 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3027 msg(DBG_UPC
,"UPC info:%s\n", msgbuf
);
3029 if ((checksum
&0x7F)!=0) break;
3032 D_S
[d
].UPC_ctl_adr
=0;
3033 if (fam1_drive
) i
=0;
3035 if ((infobuf
[i
]&0x80)!=0)
3037 convert_UPC(&infobuf
[i
]);
3038 D_S
[d
].UPC_ctl_adr
= (D_S
[d
].TocEnt_ctl_adr
& 0xF0) | 0x02;
3041 sprintf(&msgbuf
[i
*3], " %02X", D_S
[d
].UPC_buf
[i
]);
3042 sprintf(&msgbuf
[i
*3], " (%02X)", D_S
[d
].UPC_ctl_adr
);
3044 msg(DBG_UPC
,"UPC code:%s\n", msgbuf
);
3045 D_S
[d
].diskstate_flags
|= upc_bit
;
3049 static int sbpcd_get_mcn(struct cdrom_device_info
*cdi
, struct cdrom_mcn
*mcn
)
3052 unsigned char *mcnp
= mcn
->medium_catalog_number
;
3053 unsigned char *resp
;
3055 D_S
[d
].diskstate_flags
&= ~upc_bit
;
3059 drvcmd
[0]=CMD1_READ_UPC
;
3061 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
3063 else if (fam0L_drive
)
3065 drvcmd
[0]=CMD0_READ_UPC
;
3067 flags_cmd_out
=f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
|f_obey_p_check
|f_bit1
;
3069 else if (fam2_drive
)
3073 else if (famT_drive
)
3080 msg(DBG_000
,"cc_ReadUPC cmd_out: err %d\n", i
);
3086 if (famL_drive
) flags_cmd_out
=f_putcmd
;
3090 msg(DBG_000
,"cc_ReadUPC ReadPacket: err %d\n", i
);
3094 D_S
[d
].UPC_ctl_adr
=0;
3095 if (fam1_drive
) i
=0;
3099 if (*resp
++ == 0x80) {
3100 /* packed bcd to single ASCII digits */
3101 *mcnp
++ = (*resp
>> 4) + '0';
3102 *mcnp
++ = (*resp
++ & 0x0f) + '0';
3103 *mcnp
++ = (*resp
>> 4) + '0';
3104 *mcnp
++ = (*resp
++ & 0x0f) + '0';
3105 *mcnp
++ = (*resp
>> 4) + '0';
3106 *mcnp
++ = (*resp
++ & 0x0f) + '0';
3107 *mcnp
++ = (*resp
>> 4) + '0';
3108 *mcnp
++ = (*resp
++ & 0x0f) + '0';
3109 *mcnp
++ = (*resp
>> 4) + '0';
3110 *mcnp
++ = (*resp
++ & 0x0f) + '0';
3111 *mcnp
++ = (*resp
>> 4) + '0';
3112 *mcnp
++ = (*resp
++ & 0x0f) + '0';
3113 *mcnp
++ = (*resp
>> 4) + '0';
3117 D_S
[d
].diskstate_flags
|= upc_bit
;
3121 /*==========================================================================*/
3122 static int cc_CheckMultiSession(void)
3126 if (fam2_drive
) return (0);
3127 D_S
[d
].f_multisession
=0;
3129 if (fam0_drive
) return (0);
3133 drvcmd
[0]=CMD1_MULTISESS
;
3135 flags_cmd_out
=f_putcmd
|f_ResponseStatus
|f_obey_p_check
;
3137 if (i
<0) return (i
);
3138 if ((infobuf
[0]&0x80)!=0)
3140 D_S
[d
].f_multisession
=1;
3141 D_S
[d
].lba_multi
=msf2blk(make32(make16(0,infobuf
[1]),
3142 make16(infobuf
[2],infobuf
[3])));
3145 else if (famLV_drive
)
3147 drvcmd
[0]=CMDL_MULTISESS
;
3151 flags_cmd_out
=f_putcmd
;
3153 if (i
<0) return (i
);
3154 D_S
[d
].lba_multi
=msf2blk(make32(make16(0,infobuf
[5]),
3155 make16(infobuf
[6],infobuf
[7])));
3157 else if (famT_drive
)
3160 drvcmd
[0]=CMDT_DISKINFO
;
3163 drvcmd
[8]=response_count
;
3166 if (i
<0) return (i
);
3167 if (i
<response_count
) return (-100-i
);
3168 D_S
[d
].first_session
=infobuf
[2];
3169 D_S
[d
].last_session
=infobuf
[3];
3170 D_S
[d
].track_of_last_session
=infobuf
[6];
3171 if (D_S
[d
].first_session
!=D_S
[d
].last_session
)
3173 D_S
[d
].f_multisession
=1;
3174 D_S
[d
].lba_multi
=msf2blk(make32(make16(0,infobuf
[9]),make16(infobuf
[10],infobuf
[11])));
3177 for (i
=0;i
<response_count
;i
++)
3178 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3180 msg(DBG_MUL
,"MultiSession Info:%s (%d)\n", msgbuf
, D_S
[d
].lba_multi
);
3181 if (D_S
[d
].lba_multi
>200)
3183 D_S
[d
].f_multisession
=1;
3184 msg(DBG_MUL
,"MultiSession base: %06X\n", D_S
[d
].lba_multi
);
3188 /*==========================================================================*/
3190 static int cc_SubChanInfo(int frame
, int count
, u_char
*buffer
)
3191 /* "frame" is a RED BOOK (msf-bin) address */
3195 if (fam0LV_drive
) return (-ENOSYS
); /* drive firmware lacks it */
3201 if (D_S
[d
].audio_state
!=audio_playing
) return (-ENODATA
);
3204 drvcmd
[0]=CMD1_SUBCHANINF
;
3205 drvcmd
[1]=(frame
>>16)&0xFF;
3206 drvcmd
[2]=(frame
>>8)&0xFF;
3207 drvcmd
[3]=frame
&0xFF;
3208 drvcmd
[5]=(count
>>8)&0xFF;
3209 drvcmd
[6]=count
&0xFF;
3210 flags_cmd_out
=f_putcmd
|f_respo2
|f_ResponseStatus
|f_obey_p_check
;
3212 D_S
[d
].frame_size
=CD_FRAMESIZE_SUB
;
3213 i
=cmd_out(); /* which buffer to use? */
3217 /*==========================================================================*/
3218 __initfunc(static void check_datarate(void))
3222 msg(DBG_IOX
,"check_datarate entered.\n");
3225 for (i
=0;i
<=1000;i
++) printk(".");
3227 /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
3229 del_timer(&delay_timer
);
3231 delay_timer
.expires
=jiffies
+11*HZ
/10;
3233 add_timer(&delay_timer
);
3235 msg(DBG_TIM
,"delay timer started (11*HZ/10).\n");
3242 if (datarate
>0x6FFFFFFF) break;
3245 while (!timed_out_delay
);
3246 del_timer(&delay_timer
);
3248 msg(DBG_TIM
,"datarate: %04X\n", datarate
);
3250 if (datarate
<65536) datarate
=65536;
3251 maxtim16
=datarate
*16;
3252 maxtim04
=datarate
*4;
3253 maxtim02
=datarate
*2;
3254 maxtim_8
=datarate
/32;
3256 maxtim_data
=datarate
/100;
3258 maxtim_data
=datarate
/300;
3261 msg(DBG_TIM
,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8
, maxtim_data
);
3264 /*==========================================================================*/
3266 static int c2_ReadError(int fam
)
3275 drvcmd
[0]=CMD0_READ_ERR
; /* same as CMD1_ and CMDL_ */
3276 i
=do_cmd(f_putcmd
|f_lopsta
|f_getsta
|f_ResponseStatus
);
3280 drvcmd
[0]=CMD2_READ_ERR
;
3287 /*==========================================================================*/
3288 __initfunc(static void ask_mail(void))
3292 msg(DBG_INF
, "please mail the following lines to emoenke@gwdg.de\n");
3293 msg(DBG_INF
, "(don't mail if you are not using the actual kernel):\n");
3294 msg(DBG_INF
, "%s\n", VERSION
);
3295 msg(DBG_INF
, "address %03X, type %s, drive %s (ID %d)\n",
3296 CDo_command
, type
, D_S
[d
].drive_model
, D_S
[d
].drv_id
);
3298 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3300 msg(DBG_INF
,"infobuf =%s\n", msgbuf
);
3302 sprintf(&msgbuf
[i
*3], " %c ", infobuf
[i
]);
3304 msg(DBG_INF
,"infobuf =%s\n", msgbuf
);
3306 /*==========================================================================*/
3307 __initfunc(static int check_version(void))
3310 int teac_possible
=0;
3312 msg(DBG_INI
,"check_version: id=%d, d=%d.\n", D_S
[d
].drv_id
, d
);
3315 /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
3316 /* clear any pending error state */
3318 drvcmd
[0]=CMD0_READ_ERR
; /* same as CMD1_ and CMDL_ */
3320 flags_cmd_out
=f_putcmd
;
3322 if (i
<0) msg(DBG_INI
,"CMD0_READ_ERR returns %d (ok anyway).\n",i
);
3323 /* read drive version */
3325 for (i
=0;i
<12;i
++) infobuf
[i
]=0;
3326 drvcmd
[0]=CMD0_READ_VER
; /* same as CMD1_ and CMDL_ */
3327 response_count
=12; /* fam1: only 11 */
3328 flags_cmd_out
=f_putcmd
;
3330 if (i
<-1) msg(DBG_INI
,"CMD0_READ_VER returns %d\n",i
);
3331 if (i
==-11) teac_possible
++;
3333 for (i
=0;i
<12;i
++) j
+=infobuf
[i
];
3337 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3339 msg(DBG_ECS
,"infobuf =%s\n", msgbuf
);
3341 sprintf(&msgbuf
[i
*3], " %c ", infobuf
[i
]);
3343 msg(DBG_ECS
,"infobuf =%s\n", msgbuf
);
3345 for (i
=0;i
<4;i
++) if (infobuf
[i
]!=family1
[i
]) break;
3348 D_S
[d
].drive_model
[0]='C';
3349 D_S
[d
].drive_model
[1]='R';
3350 D_S
[d
].drive_model
[2]='-';
3351 D_S
[d
].drive_model
[3]='5';
3352 D_S
[d
].drive_model
[4]=infobuf
[i
++];
3353 D_S
[d
].drive_model
[5]=infobuf
[i
++];
3354 D_S
[d
].drive_model
[6]=0;
3355 D_S
[d
].drv_type
=drv_fam1
;
3357 if (!D_S
[d
].drv_type
)
3359 for (i
=0;i
<8;i
++) if (infobuf
[i
]!=family0
[i
]) break;
3362 D_S
[d
].drive_model
[0]='C';
3363 D_S
[d
].drive_model
[1]='R';
3364 D_S
[d
].drive_model
[2]='-';
3365 D_S
[d
].drive_model
[3]='5';
3366 D_S
[d
].drive_model
[4]='2';
3367 D_S
[d
].drive_model
[5]='x';
3368 D_S
[d
].drive_model
[6]=0;
3369 D_S
[d
].drv_type
=drv_fam0
;
3372 if (!D_S
[d
].drv_type
)
3374 for (i
=0;i
<8;i
++) if (infobuf
[i
]!=familyL
[i
]) break;
3378 D_S
[d
].drive_model
[j
]=infobuf
[j
];
3379 D_S
[d
].drive_model
[8]=0;
3380 D_S
[d
].drv_type
=drv_famL
;
3383 if (!D_S
[d
].drv_type
)
3385 for (i
=0;i
<6;i
++) if (infobuf
[i
]!=familyV
[i
]) break;
3389 D_S
[d
].drive_model
[j
]=infobuf
[j
];
3390 D_S
[d
].drive_model
[6]=0;
3391 D_S
[d
].drv_type
=drv_famV
;
3392 i
+=2; /* 2 blanks before version */
3395 if (!D_S
[d
].drv_type
)
3397 /* check for CD200 */
3399 drvcmd
[0]=CMD2_READ_ERR
;
3401 flags_cmd_out
=f_putcmd
;
3403 if (i
<0) msg(DBG_INI
,"CMD2_READERR returns %d (ok anyway).\n",i
);
3404 if (i
<0) msg(DBG_000
,"CMD2_READERR returns %d (ok anyway).\n",i
);
3405 /* read drive version */
3407 for (i
=0;i
<12;i
++) infobuf
[i
]=0;
3408 if (sbpro_type
==1) OUT(CDo_sel_i_d
,0);
3412 OUT(CDo_enable
,D_S
[d
].drv_sel
);
3414 drvcmd
[0]=CMD2_READ_VER
;
3416 flags_cmd_out
=f_putcmd
;
3418 if (i
<0) msg(DBG_INI
,"CMD2_READ_VER returns %d\n",i
);
3419 if (i
==-7) teac_possible
++;
3421 for (i
=0;i
<12;i
++) j
+=infobuf
[i
];
3425 sprintf(&msgbuf
[i
*3], " %02X", infobuf
[i
]);
3427 msg(DBG_IDX
,"infobuf =%s\n", msgbuf
);
3429 sprintf(&msgbuf
[i
*3], " %c ", infobuf
[i
]);
3431 msg(DBG_IDX
,"infobuf =%s\n", msgbuf
);
3435 for (i
=0;i
<5;i
++) if (infobuf
[i
]!=family2
[i
]) break;
3438 D_S
[d
].drive_model
[0]='C';
3439 D_S
[d
].drive_model
[1]='D';
3440 D_S
[d
].drive_model
[2]='2';
3441 D_S
[d
].drive_model
[3]='0';
3442 D_S
[d
].drive_model
[4]='0';
3443 D_S
[d
].drive_model
[5]=infobuf
[i
++];
3444 D_S
[d
].drive_model
[6]=infobuf
[i
++];
3445 D_S
[d
].drive_model
[7]=0;
3446 D_S
[d
].drv_type
=drv_fam2
;
3450 if (!D_S
[d
].drv_type
)
3452 /* check for TEAC CD-55A */
3453 msg(DBG_TEA
,"teac_possible: %d\n",teac_possible
);
3454 for (j
=1;j
<=((D_S
[d
].drv_id
==0)?3:1);j
++)
3456 for (l
=1;l
<=((D_S
[d
].drv_id
==0)?10:1);l
++)
3458 msg(DBG_TEA
,"TEAC reset #%d-%d.\n", j
, l
);
3459 if (sbpro_type
==1) OUT(CDo_reset
,0);
3462 OUT(CDo_enable
,D_S
[d
].drv_sel
);
3464 OUT(CDo_command
,CMDT_RESET
);
3465 for (i
=0;i
<9;i
++) OUT(CDo_command
,0);
3468 OUT(CDo_enable
,D_S
[d
].drv_sel
);
3471 msg(DBG_TEA
,"TEAC CDi_status: %02X.\n",i
);
3473 if (i
&s_not_result_ready
) continue; /* drive not present or ready */
3476 msg(DBG_TEA
,"TEAC CDi_info: %02X.\n",i
);
3477 if (i
==0x55) break; /* drive found */
3479 if (i
==0x55) break; /* drive found */
3481 if (i
==0x55) /* drive found */
3483 msg(DBG_TEA
,"TEAC drive found.\n");
3485 flags_cmd_out
=f_putcmd
;
3487 drvcmd
[0]=CMDT_READ_VER
;
3488 drvcmd
[4]=response_count
;
3489 for (i
=0;i
<12;i
++) infobuf
[i
]=0;
3491 if (i
!=0) msg(DBG_TEA
,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i
);
3492 for (i
=1;i
<6;i
++) if (infobuf
[i
]!=familyT
[i
-1]) break;
3495 D_S
[d
].drive_model
[0]='C';
3496 D_S
[d
].drive_model
[1]='D';
3497 D_S
[d
].drive_model
[2]='-';
3498 D_S
[d
].drive_model
[3]='5';
3499 D_S
[d
].drive_model
[4]='5';
3500 D_S
[d
].drive_model
[5]=0;
3501 D_S
[d
].drv_type
=drv_famT
;
3505 if (!D_S
[d
].drv_type
)
3507 msg(DBG_TEA
,"no drive found at address %03X under ID %d.\n",CDo_command
,D_S
[d
].drv_id
);
3510 for (j
=0;j
<4;j
++) D_S
[d
].firmware_version
[j
]=infobuf
[i
+j
];
3513 u_char lcs_firm_e1
[]="A E1";
3514 u_char lcs_firm_f4
[]="A4F4";
3517 if (D_S
[d
].firmware_version
[j
]!=lcs_firm_e1
[j
]) break;
3518 if (j
==4) D_S
[d
].drv_type
=drv_e1
;
3521 if (D_S
[d
].firmware_version
[j
]!=lcs_firm_f4
[j
]) break;
3522 if (j
==4) D_S
[d
].drv_type
=drv_f4
;
3524 if (D_S
[d
].drv_type
==drv_famL
) ask_mail();
3526 else if (famT_drive
)
3528 j
=infobuf
[4]; /* one-byte version??? - here: 0x15 */
3531 D_S
[d
].firmware_version
[0]=infobuf
[7];
3532 D_S
[d
].firmware_version
[1]=infobuf
[8];
3533 D_S
[d
].firmware_version
[2]=infobuf
[10];
3534 D_S
[d
].firmware_version
[3]=infobuf
[11];
3538 if (j
!=0x15) ask_mail();
3539 D_S
[d
].firmware_version
[0]='0';
3540 D_S
[d
].firmware_version
[1]='.';
3541 D_S
[d
].firmware_version
[2]='0'+(j
>>4);
3542 D_S
[d
].firmware_version
[3]='0'+(j
&0x0f);
3545 else /* CR-52x, CR-56x, CD200, ECS-AT */
3547 j
= (D_S
[d
].firmware_version
[0] & 0x0F) * 100 +
3548 (D_S
[d
].firmware_version
[2] & 0x0F) *10 +
3549 (D_S
[d
].firmware_version
[3] & 0x0F);
3552 if (j
<200) D_S
[d
].drv_type
=drv_199
;
3553 else if (j
<201) D_S
[d
].drv_type
=drv_200
;
3554 else if (j
<210) D_S
[d
].drv_type
=drv_201
;
3555 else if (j
<211) D_S
[d
].drv_type
=drv_210
;
3556 else if (j
<300) D_S
[d
].drv_type
=drv_211
;
3557 else if (j
>=300) D_S
[d
].drv_type
=drv_300
;
3559 else if (fam1_drive
)
3561 if (j
<100) D_S
[d
].drv_type
=drv_099
;
3564 D_S
[d
].drv_type
=drv_100
;
3565 if ((j
!=500)&&(j
!=102)) ask_mail();
3568 else if (fam2_drive
)
3570 if (D_S
[d
].drive_model
[5]=='F')
3572 if ((j
!=1)&&(j
!=35)&&(j
!=200)&&(j
!=210))
3573 ask_mail(); /* unknown version at time */
3577 msg(DBG_INF
,"this CD200 drive is not fully supported yet - only audio will work.\n");
3578 if ((j
!=101)&&(j
!=35))
3579 ask_mail(); /* unknown version at time */
3582 else if (famV_drive
)
3584 if ((j
==100)||(j
==150)) D_S
[d
].drv_type
=drv_at
;
3585 ask_mail(); /* hopefully we get some feedback by this */
3588 msg(DBG_LCS
,"drive type %02X\n",D_S
[d
].drv_type
);
3589 msg(DBG_INI
,"check_version done.\n");
3592 /*==========================================================================*/
3593 static void switch_drive(int i
)
3596 OUT(CDo_enable
,D_S
[d
].drv_sel
);
3597 msg(DBG_DID
,"drive %d (ID=%d) activated.\n", i
, D_S
[d
].drv_id
);
3600 /*==========================================================================*/
3603 * probe for the presence of an interface card
3605 __initfunc(static int check_card(int port
))
3610 u_char response
[N_RESPO
];
3614 msg(DBG_INI
,"check_card entered.\n");
3615 save_port0
=inb(port
+0);
3616 save_port3
=inb(port
+3);
3618 for (j
=0;j
<NR_SBPCD
;j
++)
3620 OUT(port
+3,j
) ; /* enable drive #j */
3621 OUT(port
+0,CMD0_PATH_CHECK
);
3622 for (i
=10;i
>0;i
--) OUT(port
+0,0);
3623 for (k
=0;k
<N_RESPO
;k
++) response
[k
]=0;
3624 for (k
=0;k
<N_RESPO
;k
++)
3626 for (i
=10000;i
>0;i
--)
3628 if (inb(port
+1)&s_not_result_ready
) continue;
3629 response
[k
]=inb(port
+0);
3633 for (i
=0;i
<N_RESPO
;i
++)
3634 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
3636 msg(DBG_TEA
,"path check 00 (%d): %s\n", j
, msgbuf
);
3637 OUT(port
+0,CMD0_PATH_CHECK
);
3638 for (i
=10;i
>0;i
--) OUT(port
+0,0);
3639 for (k
=0;k
<N_RESPO
;k
++) response
[k
]=0xFF;
3640 for (k
=0;k
<N_RESPO
;k
++)
3642 for (i
=10000;i
>0;i
--)
3644 if (inb(port
+1)&s_not_result_ready
) continue;
3645 response
[k
]=inb(port
+0);
3649 for (i
=0;i
<N_RESPO
;i
++)
3650 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
3652 msg(DBG_TEA
,"path check 00 (%d): %s\n", j
, msgbuf
);
3654 if (response
[0]==0xAA)
3655 if (response
[1]==0x55)
3658 for (j
=0;j
<NR_SBPCD
;j
++)
3660 OUT(port
+3,j
) ; /* enable drive #j */
3661 OUT(port
+0,CMD2_READ_VER
);
3662 for (i
=10;i
>0;i
--) OUT(port
+0,0);
3663 for (k
=0;k
<N_RESPO
;k
++) response
[k
]=0;
3664 for (k
=0;k
<N_RESPO
;k
++)
3666 for (i
=1000000;i
>0;i
--)
3668 if (inb(port
+1)&s_not_result_ready
) continue;
3669 response
[k
]=inb(port
+0);
3673 for (i
=0;i
<N_RESPO
;i
++)
3674 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
3676 msg(DBG_TEA
,"path check 12 (%d): %s\n", j
, msgbuf
);
3678 OUT(port
+0,CMD2_READ_VER
);
3679 for (i
=10;i
>0;i
--) OUT(port
+0,0);
3680 for (k
=0;k
<N_RESPO
;k
++) response
[k
]=0xFF;
3681 for (k
=0;k
<N_RESPO
;k
++)
3683 for (i
=1000000;i
>0;i
--)
3685 if (inb(port
+1)&s_not_result_ready
) continue;
3686 response
[k
]=inb(port
+0);
3690 for (i
=0;i
<N_RESPO
;i
++)
3691 sprintf(&msgbuf
[i
*3], " %02X", response
[i
]);
3693 msg(DBG_TEA
,"path check 12 (%d): %s\n", j
, msgbuf
);
3695 if (response
[0]==0xAA)
3696 if (response
[1]==0x55)
3699 OUT(port
+0,save_port0
);
3700 OUT(port
+3,save_port3
);
3701 return (0); /* in any case - no real "function" at time */
3704 /*==========================================================================*/
3705 /*==========================================================================*/
3707 * probe for the presence of drives on the selected controller
3709 __initfunc(static int check_drives(void))
3713 msg(DBG_INI
,"check_drives entered.\n");
3715 for (j
=0;j
<MAX_DRIVES
;j
++)
3717 D_S
[ndrives
].drv_id
=j
;
3718 if (sbpro_type
==1) D_S
[ndrives
].drv_sel
=(j
&0x01)<<1|(j
&0x02)>>1;
3719 else D_S
[ndrives
].drv_sel
=j
;
3720 switch_drive(ndrives
);
3721 msg(DBG_INI
,"check_drives: drive %d (ID=%d) activated.\n",ndrives
,j
);
3722 msg(DBG_000
,"check_drives: drive %d (ID=%d) activated.\n",ndrives
,j
);
3724 if (i
<0) msg(DBG_INI
,"check_version returns %d.\n",i
);
3727 D_S
[d
].drv_options
=drv_pattern
[j
];
3728 if (fam0L_drive
) D_S
[d
].drv_options
&=~(speed_auto
|speed_300
|speed_150
);
3729 msg(DBG_INF
, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
3733 D_S
[d
].firmware_version
,
3739 for (j
=ndrives
;j
<NR_SBPCD
;j
++) D_S
[j
].drv_id
=-1;
3740 if (ndrives
==0) return (-1);
3743 /*==========================================================================*/
3746 * obtain if requested service disturbs current audio state
3748 static int obey_audio_state(u_char audio_state
, u_char func
,u_char subfunc
)
3750 switch (audio_state
) /* audio status from controller */
3752 case aud_11
: /* "audio play in progress" */
3754 switch (func
) /* DOS command code */
3756 case cmd_07
: /* input flush */
3757 case cmd_0d
: /* open device */
3758 case cmd_0e
: /* close device */
3759 case cmd_0c
: /* ioctl output */
3761 case cmd_03
: /* ioctl input */
3763 /* DOS ioctl input subfunction */
3777 case aud_12
: /* "audio play paused" */
3784 /*==========================================================================*/
3786 * ioctl_o, flush_input, open_device, close_device,
3787 * tell_address, tell_volume, tell_capabiliti,
3788 * tell_framesize, tell_CD_changed, tell_audio_posi
3790 static int check_allowed1(u_char func1
, u_char func2
)
3793 if (func1
==ioctl_o
) return (0);
3794 if (func1
==read_long
) return (-1);
3795 if (func1
==read_long_prefetch
) return (-1);
3796 if (func1
==seek
) return (-1);
3797 if (func1
==audio_play
) return (-1);
3798 if (func1
==audio_pause
) return (-1);
3799 if (func1
==audio_resume
) return (-1);
3800 if (func1
!=ioctl_i
) return (0);
3801 if (func2
==tell_SubQ_run_tot
) return (-1);
3802 if (func2
==tell_cdsize
) return (-1);
3803 if (func2
==tell_TocDescrip
) return (-1);
3804 if (func2
==tell_TocEntry
) return (-1);
3805 if (func2
==tell_subQ_info
) return (-1);
3806 if (fam1_drive
) if (func2
==tell_SubChanInfo
) return (-1);
3807 if (func2
==tell_UPC
) return (-1);
3812 /*==========================================================================*/
3813 static int check_allowed2(u_char func1
, u_char func2
)
3816 if (func1
==read_long
) return (-1);
3817 if (func1
==read_long_prefetch
) return (-1);
3818 if (func1
==seek
) return (-1);
3819 if (func1
==audio_play
) return (-1);
3820 if (func1
!=ioctl_o
) return (0);
3823 if (func2
==EjectDisk
) return (-1);
3824 if (func2
==CloseTray
) return (-1);
3830 /*==========================================================================*/
3831 static int check_allowed3(u_char func1
, u_char func2
)
3836 if (func2
==tell_address
) return (0);
3837 if (func2
==tell_capabiliti
) return (0);
3838 if (func2
==tell_CD_changed
) return (0);
3839 if (fam0L_drive
) if (func2
==tell_SubChanInfo
) return (0);
3844 if (func2
==DriveReset
) return (0);
3847 if (func2
==EjectDisk
) return (0);
3848 if (func2
==LockDoor
) return (0);
3849 if (func2
==CloseTray
) return (0);
3853 if (func1
==flush_input
) return (-1);
3854 if (func1
==read_long
) return (-1);
3855 if (func1
==read_long_prefetch
) return (-1);
3856 if (func1
==seek
) return (-1);
3857 if (func1
==audio_play
) return (-1);
3858 if (func1
==audio_pause
) return (-1);
3859 if (func1
==audio_resume
) return (-1);
3864 /*==========================================================================*/
3865 static int seek_pos_audio_end(void)
3869 i
=msf2blk(D_S
[d
].pos_audio_end
)-1;
3870 if (i
<0) return (-1);
3875 /*==========================================================================*/
3876 static int ReadToC(void)
3879 D_S
[d
].diskstate_flags
&= ~toc_bit
;
3880 D_S
[d
].ored_ctl_adr
=0;
3881 /* special handling of CD-I HE */
3882 if ((D_S
[d
].n_first_track
== 2 && D_S
[d
].n_last_track
== 2) ||
3883 D_S
[d
].xa_byte
== 0x10)
3885 D_S
[d
].TocBuffer
[1].nixbyte
=0;
3886 D_S
[d
].TocBuffer
[1].ctl_adr
=0x40;
3887 D_S
[d
].TocBuffer
[1].number
=1;
3888 D_S
[d
].TocBuffer
[1].format
=0;
3889 D_S
[d
].TocBuffer
[1].address
=blk2msf(0);
3890 D_S
[d
].ored_ctl_adr
|= 0x40;
3891 D_S
[d
].n_first_track
= 1;
3892 D_S
[d
].n_last_track
= 1;
3893 D_S
[d
].xa_byte
= 0x10;
3896 for (j
=D_S
[d
].n_first_track
;j
<=D_S
[d
].n_last_track
;j
++)
3898 i
=cc_ReadTocEntry(j
);
3901 msg(DBG_INF
,"cc_ReadTocEntry(%d) returns %d.\n",j
,i
);
3904 D_S
[d
].TocBuffer
[j
].nixbyte
=D_S
[d
].TocEnt_nixbyte
;
3905 D_S
[d
].TocBuffer
[j
].ctl_adr
=D_S
[d
].TocEnt_ctl_adr
;
3906 D_S
[d
].TocBuffer
[j
].number
=D_S
[d
].TocEnt_number
;
3907 D_S
[d
].TocBuffer
[j
].format
=D_S
[d
].TocEnt_format
;
3908 D_S
[d
].TocBuffer
[j
].address
=D_S
[d
].TocEnt_address
;
3909 D_S
[d
].ored_ctl_adr
|= D_S
[d
].TocEnt_ctl_adr
;
3911 /* fake entry for LeadOut Track */
3912 D_S
[d
].TocBuffer
[j
].nixbyte
=0;
3913 D_S
[d
].TocBuffer
[j
].ctl_adr
=0;
3914 D_S
[d
].TocBuffer
[j
].number
=CDROM_LEADOUT
;
3915 D_S
[d
].TocBuffer
[j
].format
=0;
3916 D_S
[d
].TocBuffer
[j
].address
=D_S
[d
].size_msf
;
3918 D_S
[d
].diskstate_flags
|= toc_bit
;
3921 /*==========================================================================*/
3922 static int DiskInfo(void)
3926 D_S
[d
].mode
=READ_M1
;
3929 #define LOOP_COUNT 10 /* needed for some "old" drives */
3931 msg(DBG_000
,"DiskInfo entered.\n");
3932 for (j
=1;j
<LOOP_COUNT
;j
++)
3938 msg(DBG_INF
,"DiskInfo: SetSpeed returns %d\n", i
);
3944 msg(DBG_INF
,"DiskInfo: cc_ModeSense returns %d\n", i
);
3948 i
=cc_ReadCapacity();
3950 msg(DBG_INF
,"DiskInfo: ReadCapacity #%d returns %d\n", j
, i
);
3954 if (!fam0_drive
&& j
== 2) break;
3956 if (j
==LOOP_COUNT
) return (-33); /* give up */
3958 i
=cc_ReadTocDescr();
3961 msg(DBG_INF
,"DiskInfo: ReadTocDescr returns %d\n", i
);
3967 msg(DBG_INF
,"DiskInfo: ReadToC returns %d\n", i
);
3970 i
=cc_CheckMultiSession();
3973 msg(DBG_INF
,"DiskInfo: cc_CheckMultiSession returns %d\n", i
);
3976 if (D_S
[d
].f_multisession
) D_S
[d
].sbp_bufsiz
=1; /* possibly a weird PhotoCD */
3977 else D_S
[d
].sbp_bufsiz
=buffers
;
3978 i
=cc_ReadTocEntry(D_S
[d
].n_first_track
);
3981 msg(DBG_INF
,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i
);
3985 if (i
<0) msg(DBG_INF
,"DiskInfo: cc_ReadUPC returns %d\n", i
);
3986 if ((fam0L_drive
) && (D_S
[d
].xa_byte
==0x20 || D_S
[d
].xa_byte
== 0x10))
3988 /* XA disk with old drive */
3989 cc_ModeSelect(CD_FRAMESIZE_RAW1
);
3992 if (famT_drive
) cc_prep_mode_T();
3993 msg(DBG_000
,"DiskInfo done.\n");
3997 static int sbpcd_drive_status(struct cdrom_device_info
*cdi
, int slot_nr
)
4001 if (CDSL_CURRENT
!= slot_nr
) {
4002 /* we have no changer support */
4007 st
=ResponseStatus();
4010 msg(DBG_INF
,"sbpcd_drive_status: timeout.\n");
4013 msg(DBG_000
,"Drive Status: door_locked =%d.\n", st_door_locked
);
4014 msg(DBG_000
,"Drive Status: door_closed =%d.\n", st_door_closed
);
4015 msg(DBG_000
,"Drive Status: caddy_in =%d.\n", st_caddy_in
);
4016 msg(DBG_000
,"Drive Status: disk_ok =%d.\n", st_diskok
);
4017 msg(DBG_000
,"Drive Status: spinning =%d.\n", st_spinning
);
4018 msg(DBG_000
,"Drive Status: busy =%d.\n", st_busy
);
4020 if (!(D_S
[MINOR(cdi
->dev
)].status_bits
& p_door_closed
)) return CDS_TRAY_OPEN
;
4021 if (D_S
[MINOR(cdi
->dev
)].status_bits
& p_disk_ok
) return CDS_DISC_OK
;
4022 if (D_S
[MINOR(cdi
->dev
)].status_bits
& p_disk_in
) return CDS_DRIVE_NOT_READY
;
4026 if (D_S
[MINOR(cdi
->dev
)].status_bits
& p_spinning
) return CDS_DISC_OK
;
4027 return CDS_TRAY_OPEN
;
4032 /*==========================================================================*/
4035 * called always if driver gets entered
4036 * returns 0 or ERROR2 or ERROR15
4038 static int prepare(u_char func
, u_char subfunc
)
4045 if (i
&s_attention
) GetStatus();
4047 else if (fam1_drive
) GetStatus();
4048 else if (fam2_drive
) GetStatus();
4049 else if (famT_drive
) GetStatus();
4050 if (D_S
[d
].CD_changed
==0xFF)
4052 D_S
[d
].diskstate_flags
=0;
4053 D_S
[d
].audio_state
=0;
4056 i
=check_allowed1(func
,subfunc
);
4057 if (i
<0) return (-2);
4061 i
=check_allowed3(func
,subfunc
);
4064 D_S
[d
].CD_changed
=1;
4073 D_S
[d
].diskstate_flags
=0;
4074 D_S
[d
].audio_state
=0;
4075 i
=check_allowed1(func
,subfunc
);
4076 if (i
<0) return (-2);
4082 if (D_S
[d
].audio_state
!=audio_pausing
)
4084 i
=check_allowed2(func
,subfunc
);
4085 if (i
<0) return (-2);
4090 if (D_S
[d
].audio_state
==audio_playing
) seek_pos_audio_end();
4091 D_S
[d
].audio_state
=0;
4093 if (!frame_size_valid
)
4098 D_S
[d
].diskstate_flags
=0;
4099 D_S
[d
].audio_state
=0;
4100 i
=check_allowed1(func
,subfunc
);
4101 if (i
<0) return (-2);
4109 /*==========================================================================*/
4110 /*==========================================================================*/
4112 * Check the results of the "get status" command.
4114 static int sbp_status(void)
4118 st
=ResponseStatus();
4121 msg(DBG_INF
,"sbp_status: timeout.\n");
4125 if (!st_spinning
) msg(DBG_SPI
,"motor got off - ignoring.\n");
4129 msg(DBG_INF
,"st_check detected - retrying.\n");
4132 if (!st_door_closed
)
4134 msg(DBG_INF
,"door is open - retrying.\n");
4139 msg(DBG_INF
,"disk removed - retrying.\n");
4144 msg(DBG_INF
,"!st_diskok detected - retrying.\n");
4149 msg(DBG_INF
,"st_busy detected - retrying.\n");
4154 /*==========================================================================*/
4156 static int sbpcd_get_last_session(struct cdrom_device_info
*cdi
, struct cdrom_multisession
*ms_infp
)
4158 ms_infp
->addr_format
= CDROM_LBA
;
4159 ms_infp
->addr
.lba
= D_S
[MINOR(cdi
->dev
)].lba_multi
;
4160 if (D_S
[MINOR(cdi
->dev
)].f_multisession
)
4161 ms_infp
->xa_flag
=1; /* valid redirection address */
4163 ms_infp
->xa_flag
=0; /* invalid redirection address */
4168 /*==========================================================================*/
4169 /*==========================================================================*/
4173 static int sbpcd_dev_ioctl(struct cdrom_device_info
*cdi
, u_int cmd
,
4178 msg(DBG_IO2
,"ioctl(%d, 0x%08lX, 0x%08lX)\n",
4179 MINOR(cdi
->dev
), cmd
, arg
);
4181 if ((i
<0) || (i
>=NR_SBPCD
) || (D_S
[i
].drv_id
==-1))
4183 msg(DBG_INF
, "ioctl: bad device: %04X\n", cdi
->dev
);
4184 return (-ENXIO
); /* no such drive */
4186 down(&ioctl_read_sem
);
4187 if (d
!=i
) switch_drive(i
);
4189 msg(DBG_IO2
,"ioctl: device %d, request %04X\n",i
,cmd
);
4190 switch (cmd
) /* Sun-compatible */
4192 case DDIOCSDBG
: /* DDI Debug */
4193 if (!capable(CAP_SYS_ADMIN
)) RETURN_UP(-EPERM
);
4194 i
=sbpcd_dbg_ioctl(arg
,1);
4196 case CDROMRESET
: /* hard reset the drive */
4197 msg(DBG_IOC
,"ioctl: CDROMRESET entered.\n");
4199 D_S
[d
].audio_state
=0;
4202 case CDROMREADMODE1
:
4203 msg(DBG_IOC
,"ioctl: CDROMREADMODE1 requested.\n");
4205 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4207 cc_ModeSelect(CD_FRAMESIZE
);
4209 D_S
[d
].mode
=READ_M1
;
4212 case CDROMREADMODE2
: /* not usable at the moment */
4213 msg(DBG_IOC
,"ioctl: CDROMREADMODE2 requested.\n");
4215 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4217 cc_ModeSelect(CD_FRAMESIZE_RAW1
);
4219 D_S
[d
].mode
=READ_M2
;
4222 case CDROMAUDIOBUFSIZ
: /* configure the audio buffer size */
4223 msg(DBG_IOC
,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
4224 if (D_S
[d
].sbp_audsiz
>0) vfree(D_S
[d
].aud_buf
);
4225 D_S
[d
].aud_buf
=NULL
;
4226 D_S
[d
].sbp_audsiz
=arg
;
4228 if (D_S
[d
].sbp_audsiz
>0)
4230 D_S
[d
].aud_buf
=(u_char
*) vmalloc(D_S
[d
].sbp_audsiz
*CD_FRAMESIZE_RAW
);
4231 if (D_S
[d
].aud_buf
==NULL
)
4233 msg(DBG_INF
,"audio buffer (%d frames) not available.\n",D_S
[d
].sbp_audsiz
);
4234 D_S
[d
].sbp_audsiz
=0;
4236 else msg(DBG_INF
,"audio buffer size: %d frames.\n",D_S
[d
].sbp_audsiz
);
4238 RETURN_UP(D_S
[d
].sbp_audsiz
);
4240 case CDROMREADAUDIO
:
4241 { /* start of CDROMREADAUDIO */
4242 int i
=0, j
=0, frame
, block
=0;
4246 u_int data_tries
= 0;
4247 u_int data_waits
= 0;
4248 u_int data_retrying
= 0;
4252 msg(DBG_IOC
,"ioctl: CDROMREADAUDIO entered.\n");
4253 if (fam0_drive
) RETURN_UP(-EINVAL
);
4254 if (famL_drive
) RETURN_UP(-EINVAL
);
4255 if (famV_drive
) RETURN_UP(-EINVAL
);
4256 if (famT_drive
) RETURN_UP(-EINVAL
);
4258 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4260 if (D_S
[d
].aud_buf
==NULL
) RETURN_UP(-EINVAL
);
4261 i
=verify_area(VERIFY_READ
, (void *) arg
, sizeof(struct cdrom_read_audio
));
4262 if (i
) RETURN_UP(i
);
4263 copy_from_user(&read_audio
, (void *) arg
, sizeof(struct cdrom_read_audio
));
4264 if (read_audio
.nframes
>D_S
[d
].sbp_audsiz
) RETURN_UP(-EINVAL
);
4265 i
=verify_area(VERIFY_WRITE
, read_audio
.buf
,
4266 read_audio
.nframes
*CD_FRAMESIZE_RAW
);
4267 if (i
) RETURN_UP(i
);
4269 if (read_audio
.addr_format
==CDROM_MSF
) /* MSF-bin specification of where to start */
4270 block
=msf2lba(&read_audio
.addr
.msf
.minute
);
4271 else if (read_audio
.addr_format
==CDROM_LBA
) /* lba specification of where to start */
4272 block
=read_audio
.addr
.lba
;
4273 else RETURN_UP(-EINVAL
);
4275 i
=cc_SetSpeed(speed_150
,0,0);
4276 if (i
) msg(DBG_AUD
,"read_audio: SetSpeed error %d\n", i
);
4278 msg(DBG_AUD
,"read_audio: lba: %d, msf: %06X\n",
4279 block
, blk2msf(block
));
4280 msg(DBG_AUD
,"read_audio: before cc_ReadStatus.\n");
4282 while (busy_data
) sbp_sleep(HZ
/10); /* wait a bit */
4286 for (data_tries
=5; data_tries
>0; data_tries
--)
4288 msg(DBG_AUD
,"data_tries=%d ...\n", data_tries
);
4289 D_S
[d
].mode
=READ_AU
;
4290 cc_ModeSelect(CD_FRAMESIZE_RAW
);
4292 for (status_tries
=3; status_tries
> 0; status_tries
--)
4294 flags_cmd_out
|= f_respo3
;
4296 if (sbp_status() != 0) break;
4297 if (st_check
) cc_ReadError();
4298 sbp_sleep(1); /* wait a bit, try again */
4300 if (status_tries
== 0)
4302 msg(DBG_AUD
,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__
);
4305 msg(DBG_AUD
,"read_audio: sbp_status: ok.\n");
4307 flags_cmd_out
= f_putcmd
| f_respo2
| f_ResponseStatus
| f_obey_p_check
;
4310 flags_cmd_out
|= f_lopsta
| f_getsta
| f_bit1
;
4312 drvcmd
[0]=CMD0_READ_XA
; /* "read XA frames", old drives */
4313 drvcmd
[1]=(block
>>16)&0x000000ff;
4314 drvcmd
[2]=(block
>>8)&0x000000ff;
4315 drvcmd
[3]=block
&0x000000ff;
4317 drvcmd
[5]=read_audio
.nframes
; /* # of frames */
4320 else if (fam1_drive
)
4322 drvcmd
[0]=CMD1_READ
; /* "read frames", new drives */
4323 lba2msf(block
,&drvcmd
[1]); /* msf-bin format required */
4326 drvcmd
[6]=read_audio
.nframes
; /* # of frames */
4328 else if (fam2_drive
)
4330 drvcmd
[0]=CMD2_READ_XA2
;
4331 lba2msf(block
,&drvcmd
[1]); /* msf-bin format required */
4333 drvcmd
[5]=read_audio
.nframes
; /* # of frames */
4334 drvcmd
[6]=0x11; /* raw mode */
4336 else if (famT_drive
) /* CD-55A: not tested yet */
4339 msg(DBG_AUD
,"read_audio: before giving \"read\" command.\n");
4340 flags_cmd_out
=f_putcmd
;
4343 if (i
<0) msg(DBG_INF
,"error giving READ AUDIO command: %0d\n", i
);
4345 msg(DBG_AUD
,"read_audio: after giving \"read\" command.\n");
4346 for (frame
=1;frame
<2 && !error_flag
; frame
++)
4349 for (timeout
=jiffies
+9*HZ
; ; )
4351 for ( ; try!=0;try--)
4354 if (!(j
&s_not_data_ready
)) break;
4355 if (!(j
&s_not_result_ready
)) break;
4356 if (fam0L_drive
) if (j
&s_attention
) break;
4358 if (try != 0 || time_after_eq(jiffies
, timeout
)) break;
4359 if (data_retrying
== 0) data_waits
++;
4366 msg(DBG_INF
,"read_audio: sbp_data: CDi_status timeout.\n");
4370 msg(DBG_AUD
,"read_audio: sbp_data: CDi_status ok.\n");
4371 if (j
&s_not_data_ready
)
4373 msg(DBG_INF
, "read_audio: sbp_data: DATA_READY timeout.\n");
4377 msg(DBG_AUD
,"read_audio: before reading data.\n");
4380 if (sbpro_type
==1) OUT(CDo_sel_i_d
,1);
4383 u_short
*p2
= (u_short
*) p
;
4385 for (; (u_char
*) p2
< D_S
[d
].aud_buf
+ read_audio
.nframes
*CD_FRAMESIZE_RAW
;)
4387 if ((inb_p(CDi_status
)&s_not_data_ready
)) continue;
4389 /* get one sample */
4390 *p2
++ = inw_p(CDi_data
);
4391 *p2
++ = inw_p(CDi_data
);
4394 for (; p
< D_S
[d
].aud_buf
+ read_audio
.nframes
*CD_FRAMESIZE_RAW
;)
4396 if ((inb_p(CDi_status
)&s_not_data_ready
)) continue;
4398 /* get one sample */
4399 *p
++ = inb_p(CDi_data
);
4400 *p
++ = inb_p(CDi_data
);
4401 *p
++ = inb_p(CDi_data
);
4402 *p
++ = inb_p(CDi_data
);
4405 if (sbpro_type
==1) OUT(CDo_sel_i_d
,0);
4408 msg(DBG_AUD
,"read_audio: after reading data.\n");
4409 if (error_flag
) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
4411 msg(DBG_AUD
,"read_audio: read aborted by drive\n");
4413 i
=cc_DriveReset(); /* ugly fix to prevent a hang */
4422 for (timeout
=jiffies
+9*HZ
; time_before(jiffies
, timeout
); timeout
--)
4427 if (!(j
&s_not_data_ready
)) break;
4428 if (!(j
&s_not_result_ready
)) break;
4429 if (j
&s_attention
) break;
4431 if (i
!= 0 || time_after_eq(jiffies
, timeout
)) break;
4435 if (i
==0) msg(DBG_AUD
,"read_audio: STATUS TIMEOUT AFTER READ");
4436 if (!(j
&s_attention
))
4438 msg(DBG_AUD
,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
4439 i
=cc_DriveReset(); /* ugly fix to prevent a hang */
4445 if (fam0L_drive
) cc_ReadStatus();
4446 i
=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
4447 if (i
<0) { msg(DBG_AUD
,
4448 "read_audio: cc_ReadStatus error after read: %02X\n",
4449 D_S
[d
].status_bits
);
4450 continue; /* FIXME */
4453 while ((fam0L_drive
)&&(!st_check
)&&(!(i
&p_success
)));
4457 msg(DBG_AUD
,"read_audio: cc_ReadError was necessary after read: %02X\n",i
);
4460 copy_to_user((u_char
*) read_audio
.buf
,
4461 (u_char
*) D_S
[d
].aud_buf
,
4462 read_audio
.nframes
*CD_FRAMESIZE_RAW
);
4463 msg(DBG_AUD
,"read_audio: copy_to_user done.\n");
4466 cc_ModeSelect(CD_FRAMESIZE
);
4468 D_S
[d
].mode
=READ_M1
;
4472 if (data_tries
== 0)
4474 msg(DBG_AUD
,"read_audio: failed after 5 tries in line %d.\n", __LINE__
);
4477 msg(DBG_AUD
,"read_audio: successful return.\n");
4479 } /* end of CDROMREADAUDIO */
4482 if(!capable(CAP_SYS_ADMIN
)) RETURN_UP(-EACCES
);
4483 if(!(cdi
->dev
)) RETURN_UP(-EINVAL
);
4484 if(arg
> 0xff) RETURN_UP(-EINVAL
);
4485 read_ahead
[MAJOR(cdi
->dev
)] = arg
;
4488 msg(DBG_IOC
,"ioctl: unknown function request %04X\n", cmd
);
4490 } /* end switch(cmd) */
4493 static int sbpcd_audio_ioctl(struct cdrom_device_info
*cdi
, u_int cmd
,
4498 msg(DBG_IO2
,"ioctl(%d, 0x%08lX, 0x%08p)\n",
4499 MINOR(cdi
->dev
), cmd
, arg
);
4501 if ((i
<0) || (i
>=NR_SBPCD
) || (D_S
[i
].drv_id
==-1))
4503 msg(DBG_INF
, "ioctl: bad device: %04X\n", cdi
->dev
);
4504 return (-ENXIO
); /* no such drive */
4506 down(&ioctl_read_sem
);
4507 if (d
!=i
) switch_drive(i
);
4509 msg(DBG_IO2
,"ioctl: device %d, request %04X\n",i
,cmd
);
4510 switch (cmd
) /* Sun-compatible */
4513 case CDROMPAUSE
: /* Pause the drive */
4514 msg(DBG_IOC
,"ioctl: CDROMPAUSE entered.\n");
4515 /* pause the drive unit when it is currently in PLAY mode, */
4516 /* or reset the starting and ending locations when in PAUSED mode. */
4517 /* If applicable, at the next stopping point it reaches */
4518 /* the drive will discontinue playing. */
4519 switch (D_S
[d
].audio_state
)
4522 if (famL_drive
) i
=cc_ReadSubQ();
4523 else i
=cc_Pause_Resume(1);
4524 if (i
<0) RETURN_UP(-EIO
);
4525 if (famL_drive
) i
=cc_Pause_Resume(1);
4526 else i
=cc_ReadSubQ();
4527 if (i
<0) RETURN_UP(-EIO
);
4528 D_S
[d
].pos_audio_start
=D_S
[d
].SubQ_run_tot
;
4529 D_S
[d
].audio_state
=audio_pausing
;
4532 i
=cc_Seek(D_S
[d
].pos_audio_start
,1);
4533 if (i
<0) RETURN_UP(-EIO
);
4539 case CDROMRESUME
: /* resume paused audio play */
4540 msg(DBG_IOC
,"ioctl: CDROMRESUME entered.\n");
4541 /* resume playing audio tracks when a previous PLAY AUDIO call has */
4542 /* been paused with a PAUSE command. */
4543 /* It will resume playing from the location saved in SubQ_run_tot. */
4544 if (D_S
[d
].audio_state
!=audio_pausing
) RETURN_UP(-EINVAL
);
4546 i
=cc_PlayAudio(D_S
[d
].pos_audio_start
,
4547 D_S
[d
].pos_audio_end
);
4548 else i
=cc_Pause_Resume(3);
4549 if (i
<0) RETURN_UP(-EIO
);
4550 D_S
[d
].audio_state
=audio_playing
;
4554 msg(DBG_IOC
,"ioctl: CDROMPLAYMSF entered.\n");
4556 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4558 if (D_S
[d
].audio_state
==audio_playing
)
4560 i
=cc_Pause_Resume(1);
4561 if (i
<0) RETURN_UP(-EIO
);
4563 if (i
<0) RETURN_UP(-EIO
);
4564 D_S
[d
].pos_audio_start
=D_S
[d
].SubQ_run_tot
;
4565 i
=cc_Seek(D_S
[d
].pos_audio_start
,1);
4567 memcpy(&msf
, (void *) arg
, sizeof(struct cdrom_msf
));
4568 /* values come as msf-bin */
4569 D_S
[d
].pos_audio_start
= (msf
.cdmsf_min0
<<16) |
4570 (msf
.cdmsf_sec0
<<8) |
4572 D_S
[d
].pos_audio_end
= (msf
.cdmsf_min1
<<16) |
4573 (msf
.cdmsf_sec1
<<8) |
4575 msg(DBG_IOX
,"ioctl: CDROMPLAYMSF %08X %08X\n",
4576 D_S
[d
].pos_audio_start
,D_S
[d
].pos_audio_end
);
4577 i
=cc_PlayAudio(D_S
[d
].pos_audio_start
,D_S
[d
].pos_audio_end
);
4580 msg(DBG_INF
,"ioctl: cc_PlayAudio returns %d\n",i
);
4582 D_S
[d
].audio_state
=0;
4585 D_S
[d
].audio_state
=audio_playing
;
4588 case CDROMPLAYTRKIND
: /* Play a track. This currently ignores index. */
4589 msg(DBG_IOC
,"ioctl: CDROMPLAYTRKIND entered.\n");
4591 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4593 if (D_S
[d
].audio_state
==audio_playing
)
4595 msg(DBG_IOX
,"CDROMPLAYTRKIND: already audio_playing.\n");
4597 RETURN_UP(0); /* just let us play on */
4599 RETURN_UP(-EINVAL
); /* play on, but say "error" */
4602 memcpy(&ti
,(void *) arg
,sizeof(struct cdrom_ti
));
4603 msg(DBG_IOX
,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
4604 ti
.cdti_trk0
,ti
.cdti_ind0
,ti
.cdti_trk1
,ti
.cdti_ind1
);
4605 if (ti
.cdti_trk0
<D_S
[d
].n_first_track
) RETURN_UP(-EINVAL
);
4606 if (ti
.cdti_trk0
>D_S
[d
].n_last_track
) RETURN_UP(-EINVAL
);
4607 if (ti
.cdti_trk1
<ti
.cdti_trk0
) ti
.cdti_trk1
=ti
.cdti_trk0
;
4608 if (ti
.cdti_trk1
>D_S
[d
].n_last_track
) ti
.cdti_trk1
=D_S
[d
].n_last_track
;
4609 D_S
[d
].pos_audio_start
=D_S
[d
].TocBuffer
[ti
.cdti_trk0
].address
;
4610 D_S
[d
].pos_audio_end
=D_S
[d
].TocBuffer
[ti
.cdti_trk1
+1].address
;
4611 i
=cc_PlayAudio(D_S
[d
].pos_audio_start
,D_S
[d
].pos_audio_end
);
4614 msg(DBG_INF
,"ioctl: cc_PlayAudio returns %d\n",i
);
4616 D_S
[d
].audio_state
=0;
4619 D_S
[d
].audio_state
=audio_playing
;
4622 case CDROMREADTOCHDR
: /* Read the table of contents header */
4623 msg(DBG_IOC
,"ioctl: CDROMREADTOCHDR entered.\n");
4624 tochdr
.cdth_trk0
=D_S
[d
].n_first_track
;
4625 tochdr
.cdth_trk1
=D_S
[d
].n_last_track
;
4626 memcpy((void *) arg
, &tochdr
, sizeof(struct cdrom_tochdr
));
4629 case CDROMREADTOCENTRY
: /* Read an entry in the table of contents */
4630 msg(DBG_IOC
,"ioctl: CDROMREADTOCENTRY entered.\n");
4631 memcpy(&tocentry
, (void *) arg
, sizeof(struct cdrom_tocentry
));
4632 i
=tocentry
.cdte_track
;
4633 if (i
==CDROM_LEADOUT
) i
=D_S
[d
].n_last_track
+1;
4634 else if (i
<D_S
[d
].n_first_track
||i
>D_S
[d
].n_last_track
)
4636 tocentry
.cdte_adr
=D_S
[d
].TocBuffer
[i
].ctl_adr
&0x0F;
4637 tocentry
.cdte_ctrl
=(D_S
[d
].TocBuffer
[i
].ctl_adr
>>4)&0x0F;
4638 tocentry
.cdte_datamode
=D_S
[d
].TocBuffer
[i
].format
;
4639 if (tocentry
.cdte_format
==CDROM_MSF
) /* MSF-bin required */
4641 tocentry
.cdte_addr
.msf
.minute
=(D_S
[d
].TocBuffer
[i
].address
>>16)&0x00FF;
4642 tocentry
.cdte_addr
.msf
.second
=(D_S
[d
].TocBuffer
[i
].address
>>8)&0x00FF;
4643 tocentry
.cdte_addr
.msf
.frame
=D_S
[d
].TocBuffer
[i
].address
&0x00FF;
4645 else if (tocentry
.cdte_format
==CDROM_LBA
) /* blk required */
4646 tocentry
.cdte_addr
.lba
=msf2blk(D_S
[d
].TocBuffer
[i
].address
);
4647 else RETURN_UP(-EINVAL
);
4648 memcpy((void *) arg
, &tocentry
, sizeof(struct cdrom_tocentry
));
4651 case CDROMSTOP
: /* Spin down the drive */
4652 msg(DBG_IOC
,"ioctl: CDROMSTOP entered.\n");
4654 if (D_S
[d
].has_data
>1) RETURN_UP(-EBUSY
);
4656 i
=cc_Pause_Resume(1);
4657 D_S
[d
].audio_state
=0;
4663 case CDROMSTART
: /* Spin up the drive */
4664 msg(DBG_IOC
,"ioctl: CDROMSTART entered.\n");
4666 D_S
[d
].audio_state
=0;
4669 case CDROMVOLCTRL
: /* Volume control */
4670 msg(DBG_IOC
,"ioctl: CDROMVOLCTRL entered.\n");
4671 memcpy(&volctrl
,(char *) arg
,sizeof(volctrl
));
4673 D_S
[d
].vol_ctrl0
=volctrl
.channel0
;
4675 D_S
[d
].vol_ctrl1
=volctrl
.channel1
;
4679 case CDROMVOLREAD
: /* read Volume settings from drive */
4680 msg(DBG_IOC
,"ioctl: CDROMVOLREAD entered.\n");
4682 if (st
<0) RETURN_UP(st
);
4683 volctrl
.channel0
=D_S
[d
].vol_ctrl0
;
4684 volctrl
.channel1
=D_S
[d
].vol_ctrl1
;
4687 memcpy((void *)arg
,&volctrl
,sizeof(volctrl
));
4690 case CDROMSUBCHNL
: /* Get subchannel info */
4691 msg(DBG_IOS
,"ioctl: CDROMSUBCHNL entered.\n");
4692 if ((st_spinning
)||(!subq_valid
)) {
4694 if (i
<0) RETURN_UP(-EIO
);
4696 memcpy(&SC
, (void *) arg
, sizeof(struct cdrom_subchnl
));
4697 switch (D_S
[d
].audio_state
)
4700 SC
.cdsc_audiostatus
=CDROM_AUDIO_PLAY
;
4703 SC
.cdsc_audiostatus
=CDROM_AUDIO_PAUSED
;
4706 SC
.cdsc_audiostatus
=CDROM_AUDIO_NO_STATUS
;
4709 SC
.cdsc_adr
=D_S
[d
].SubQ_ctl_adr
;
4710 SC
.cdsc_ctrl
=D_S
[d
].SubQ_ctl_adr
>>4;
4711 SC
.cdsc_trk
=bcd2bin(D_S
[d
].SubQ_trk
);
4712 SC
.cdsc_ind
=bcd2bin(D_S
[d
].SubQ_pnt_idx
);
4713 if (SC
.cdsc_format
==CDROM_LBA
)
4715 SC
.cdsc_absaddr
.lba
=msf2blk(D_S
[d
].SubQ_run_tot
);
4716 SC
.cdsc_reladdr
.lba
=msf2blk(D_S
[d
].SubQ_run_trk
);
4718 else /* not only if (SC.cdsc_format==CDROM_MSF) */
4720 SC
.cdsc_absaddr
.msf
.minute
=(D_S
[d
].SubQ_run_tot
>>16)&0x00FF;
4721 SC
.cdsc_absaddr
.msf
.second
=(D_S
[d
].SubQ_run_tot
>>8)&0x00FF;
4722 SC
.cdsc_absaddr
.msf
.frame
=D_S
[d
].SubQ_run_tot
&0x00FF;
4723 SC
.cdsc_reladdr
.msf
.minute
=(D_S
[d
].SubQ_run_trk
>>16)&0x00FF;
4724 SC
.cdsc_reladdr
.msf
.second
=(D_S
[d
].SubQ_run_trk
>>8)&0x00FF;
4725 SC
.cdsc_reladdr
.msf
.frame
=D_S
[d
].SubQ_run_trk
&0x00FF;
4727 memcpy((void *) arg
, &SC
, sizeof(struct cdrom_subchnl
));
4728 msg(DBG_IOS
,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
4729 SC
.cdsc_format
,SC
.cdsc_audiostatus
,
4730 SC
.cdsc_adr
,SC
.cdsc_ctrl
,
4731 SC
.cdsc_trk
,SC
.cdsc_ind
,
4732 SC
.cdsc_absaddr
,SC
.cdsc_reladdr
);
4736 msg(DBG_IOC
,"ioctl: unknown function request %04X\n", cmd
);
4738 } /* end switch(cmd) */
4740 /*==========================================================================*/
4742 * Take care of the different block sizes between cdrom and Linux.
4744 static void sbp_transfer(struct request
*req
)
4748 while ( (req
->nr_sectors
> 0) &&
4749 (req
->sector
/4 >= D_S
[d
].sbp_first_frame
) &&
4750 (req
->sector
/4 <= D_S
[d
].sbp_last_frame
) )
4752 offs
= (req
->sector
- D_S
[d
].sbp_first_frame
* 4) * 512;
4753 memcpy(req
->buffer
, D_S
[d
].sbp_buf
+ offs
, 512);
4759 /*==========================================================================*/
4761 * special end_request for sbpcd to solve CURRENT==NULL bug. (GTL)
4762 * GTL = Gonzalo Tornaria <tornaria@cmat.edu.uy>
4764 * This is a kludge so we don't need to modify end_request.
4765 * We put the req we take out after INIT_REQUEST in the requests list,
4766 * so that end_request will discard it.
4768 * The bug could be present in other block devices, perhaps we
4769 * should modify INIT_REQUEST and end_request instead, and
4770 * change every block device..
4772 * Could be a race here?? Could e.g. a timer interrupt schedule() us?
4773 * If so, we should copy end_request here, and do it right.. (or
4774 * modify end_request and the block devices).
4776 * In any case, the race here would be much small than it was, and
4777 * I couldn't reproduce..
4779 * The race could be: suppose CURRENT==NULL. We put our req in the list,
4780 * and we are scheduled. Other process takes over, and gets into
4781 * do_sbpcd_request. It sees CURRENT!=NULL (it is == to our req), so
4782 * proceeds. It ends, so CURRENT is now NULL.. Now we awake somewhere in
4783 * end_request, but now CURRENT==NULL... oops!
4787 static inline void sbpcd_end_request(struct request
*req
, int uptodate
) {
4790 up(&ioctl_read_sem
);
4791 end_request(uptodate
);
4793 /*==========================================================================*/
4795 * I/O request routine, called from Linux kernel.
4797 static void DO_SBPCD_REQUEST(void)
4801 int i
, status_tries
, data_tries
;
4802 struct request
*req
;
4814 printk( "do_sbpcd_request[%di](NULL), Pid:%d, Time:%li\n",
4815 xnr
, current
->pid
, jiffies
);
4816 printk( "do_sbpcd_request[%do](NULL) end 0 (null), Time:%li\n",
4822 printk(" do_sbpcd_request[%di](%p:%ld+%ld), Pid:%d, Time:%li\n",
4823 xnr
, CURRENT
, CURRENT
->sector
, CURRENT
->nr_sectors
, current
->pid
, jiffies
);
4826 req
=CURRENT
; /* take out our request so no other */
4827 CURRENT
=req
->next
; /* task can fuck it up GTL */
4828 spin_unlock_irq(&io_request_lock
); /* FIXME!!!! */
4830 down(&ioctl_read_sem
);
4831 if (req
->rq_status
== RQ_INACTIVE
)
4832 sbpcd_end_request(req
, 0);
4833 if (req
-> sector
== -1)
4834 sbpcd_end_request(req
, 0);
4836 if (req
->cmd
!= READ
)
4838 msg(DBG_INF
, "bad cmd %d\n", req
->cmd
);
4841 i
= MINOR(req
->rq_dev
);
4842 if ( (i
<0) || (i
>=NR_SBPCD
) || (D_S
[i
].drv_id
==-1))
4844 msg(DBG_INF
, "do_request: bad device: %s\n",
4845 kdevname(req
->rq_dev
));
4849 while (busy_audio
) sbp_sleep(HZ
); /* wait a bit */
4853 if (D_S
[i
].audio_state
==audio_playing
) goto err_done
;
4854 if (d
!=i
) switch_drive(i
);
4856 block
= req
->sector
; /* always numbered as 512-byte-pieces */
4857 nsect
= req
->nr_sectors
; /* always counted as 512-byte-pieces */
4859 msg(DBG_BSZ
,"read sector %d (%d sectors)\n", block
, nsect
);
4861 msg(DBG_MUL
,"read LBA %d\n", block
/4);
4865 /* if we satisfied the request from the buffer, we're done. */
4866 if (req
->nr_sectors
== 0)
4869 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 2, Time:%li\n",
4870 xnr
, req
, req
->sector
, req
->nr_sectors
, jiffies
);
4872 sbpcd_end_request(req
, 1);
4873 spin_lock_irq(&io_request_lock
); /* FIXME!!!! */
4878 i
=prepare(0,0); /* at moment not really a hassle check, but ... */
4880 msg(DBG_INF
,"\"prepare\" tells error %d -- ignored\n", i
);
4883 if (!st_spinning
) cc_SpinUp();
4885 for (data_tries
=n_retries
; data_tries
> 0; data_tries
--)
4887 for (status_tries
=3; status_tries
> 0; status_tries
--)
4889 flags_cmd_out
|= f_respo3
;
4891 if (sbp_status() != 0) break;
4892 if (st_check
) cc_ReadError();
4893 sbp_sleep(1); /* wait a bit, try again */
4895 if (status_tries
== 0)
4897 msg(DBG_INF
,"sbp_status: failed after 3 tries in line %d\n", __LINE__
);
4903 if (sbp_data(req
) != 0)
4906 D_S
[d
].has_data
=2; /* is really a data disk */
4909 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
4910 xnr
, req
, req
->sector
, req
->nr_sectors
, jiffies
);
4912 sbpcd_end_request(req
, 1);
4913 spin_lock_irq(&io_request_lock
); /* FIXME!!!! */
4923 printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 4 (error), Time:%li\n",
4924 xnr
, req
, req
->sector
, req
->nr_sectors
, jiffies
);
4926 sbpcd_end_request(req
, 0);
4927 sbp_sleep(0); /* wait a bit, try again */
4928 spin_lock_irq(&io_request_lock
); /* FIXME!!!! */
4931 /*==========================================================================*/
4933 * build and send the READ command.
4935 static void sbp_read_cmd(struct request
*req
)
4942 D_S
[d
].sbp_first_frame
=D_S
[d
].sbp_last_frame
=-1; /* purge buffer */
4943 D_S
[d
].sbp_current
= 0;
4944 block
=req
->sector
/4;
4945 if (block
+D_S
[d
].sbp_bufsiz
<= D_S
[d
].CDsize_frm
)
4946 D_S
[d
].sbp_read_frames
= D_S
[d
].sbp_bufsiz
;
4949 D_S
[d
].sbp_read_frames
=D_S
[d
].CDsize_frm
-block
;
4950 /* avoid reading past end of data */
4951 if (D_S
[d
].sbp_read_frames
< 1)
4953 msg(DBG_INF
,"requested frame %d, CD size %d ???\n",
4954 block
, D_S
[d
].CDsize_frm
);
4955 D_S
[d
].sbp_read_frames
=1;
4959 flags_cmd_out
= f_putcmd
| f_respo2
| f_ResponseStatus
| f_obey_p_check
;
4963 drvcmd
[0]=CMDV_READ
;
4964 lba2msf(block
,&drvcmd
[1]); /* msf-bcd format required */
4965 bin2bcdx(&drvcmd
[1]);
4966 bin2bcdx(&drvcmd
[2]);
4967 bin2bcdx(&drvcmd
[3]);
4968 drvcmd
[4]=D_S
[d
].sbp_read_frames
>>8;
4969 drvcmd
[5]=D_S
[d
].sbp_read_frames
&0xff;
4970 drvcmd
[6]=0x02; /* flag "msf-bcd" */
4972 else if (fam0L_drive
)
4974 flags_cmd_out
|= f_lopsta
| f_getsta
| f_bit1
;
4975 if (D_S
[d
].xa_byte
==0x20)
4978 drvcmd
[0]=CMD0_READ_XA
; /* "read XA frames", old drives */
4979 drvcmd
[1]=(block
>>16)&0x0ff;
4980 drvcmd
[2]=(block
>>8)&0x0ff;
4981 drvcmd
[3]=block
&0x0ff;
4982 drvcmd
[4]=(D_S
[d
].sbp_read_frames
>>8)&0x0ff;
4983 drvcmd
[5]=D_S
[d
].sbp_read_frames
&0x0ff;
4987 drvcmd
[0]=CMD0_READ
; /* "read frames", old drives */
4988 if (D_S
[d
].drv_type
>=drv_201
)
4990 lba2msf(block
,&drvcmd
[1]); /* msf-bcd format required */
4991 bin2bcdx(&drvcmd
[1]);
4992 bin2bcdx(&drvcmd
[2]);
4993 bin2bcdx(&drvcmd
[3]);
4997 drvcmd
[1]=(block
>>16)&0x0ff;
4998 drvcmd
[2]=(block
>>8)&0x0ff;
4999 drvcmd
[3]=block
&0x0ff;
5001 drvcmd
[4]=(D_S
[d
].sbp_read_frames
>>8)&0x0ff;
5002 drvcmd
[5]=D_S
[d
].sbp_read_frames
&0x0ff;
5003 drvcmd
[6]=(D_S
[d
].drv_type
<drv_201
)?0:2; /* flag "lba or msf-bcd format" */
5006 else if (fam1_drive
)
5008 drvcmd
[0]=CMD1_READ
;
5009 lba2msf(block
,&drvcmd
[1]); /* msf-bin format required */
5010 drvcmd
[5]=(D_S
[d
].sbp_read_frames
>>8)&0x0ff;
5011 drvcmd
[6]=D_S
[d
].sbp_read_frames
&0x0ff;
5013 else if (fam2_drive
)
5015 drvcmd
[0]=CMD2_READ
;
5016 lba2msf(block
,&drvcmd
[1]); /* msf-bin format required */
5017 drvcmd
[4]=(D_S
[d
].sbp_read_frames
>>8)&0x0ff;
5018 drvcmd
[5]=D_S
[d
].sbp_read_frames
&0x0ff;
5021 else if (famT_drive
)
5023 drvcmd
[0]=CMDT_READ
;
5024 drvcmd
[2]=(block
>>24)&0x0ff;
5025 drvcmd
[3]=(block
>>16)&0x0ff;
5026 drvcmd
[4]=(block
>>8)&0x0ff;
5027 drvcmd
[5]=block
&0x0ff;
5028 drvcmd
[7]=(D_S
[d
].sbp_read_frames
>>8)&0x0ff;
5029 drvcmd
[8]=D_S
[d
].sbp_read_frames
&0x0ff;
5031 flags_cmd_out
=f_putcmd
;
5034 if (i
<0) msg(DBG_INF
,"error giving READ command: %0d\n", i
);
5037 /*==========================================================================*/
5039 * Check the completion of the read-data command. On success, read
5040 * the D_S[d].sbp_bufsiz * 2048 bytes of data from the disk into buffer.
5042 static int sbp_data(struct request
*req
)
5044 int i
=0, j
=0, l
, frame
;
5048 u_int data_tries
= 0;
5049 u_int data_waits
= 0;
5050 u_int data_retrying
= 0;
5063 if (D_S
[d
].f_multisession
) max_latency
=15*HZ
;
5064 else max_latency
=5*HZ
;
5067 for (frame
=0;frame
<D_S
[d
].sbp_read_frames
&&!error_flag
; frame
++)
5071 del_timer(&data_timer
);
5072 data_timer
.expires
=jiffies
+max_latency
;
5074 add_timer(&data_timer
);
5075 while (!timed_out_data
)
5077 if (D_S
[d
].f_multisession
) try=maxtim_data
*4;
5078 else try=maxtim_data
;
5079 msg(DBG_000
,"sbp_data: CDi_status loop: try=%d.\n",try);
5080 for ( ; try!=0;try--)
5083 if (!(j
&s_not_data_ready
)) break;;
5084 if (!(j
&s_not_result_ready
)) break;
5085 if (fam0LV_drive
) if (j
&s_attention
) break;
5087 if (!(j
&s_not_data_ready
)) goto data_ready
;
5090 if (data_retrying
== 0) data_waits
++;
5092 msg(DBG_000
,"sbp_data: CDi_status loop: sleeping.\n");
5097 msg(DBG_INF
,"sbp_data: CDi_status loop expired.\n");
5099 del_timer(&data_timer
);
5103 msg(DBG_INF
,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j
);
5108 msg(DBG_INF
,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j
);
5111 if (!(j
&s_not_result_ready
))
5113 msg(DBG_INF
, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j
);
5118 if (j
&s_not_data_ready
)
5120 if ((D_S
[d
].ored_ctl_adr
&0x40)==0)
5121 msg(DBG_INF
, "CD contains no data tracks.\n");
5122 else msg(DBG_INF
, "sbp_data: DATA_READY timeout (%02X).\n", j
);
5126 if (error_flag
) break;
5128 msg(DBG_000
, "sbp_data: beginning to read.\n");
5129 p
= D_S
[d
].sbp_buf
+ frame
* CD_FRAMESIZE
;
5130 if (sbpro_type
==1) OUT(CDo_sel_i_d
,1);
5131 if (cmd_type
==READ_M2
) {
5132 if (do_16bit
) insw(CDi_data
, xa_head_buf
, CD_XA_HEAD
>>1);
5133 else insb(CDi_data
, xa_head_buf
, CD_XA_HEAD
);
5135 if (do_16bit
) insw(CDi_data
, p
, CD_FRAMESIZE
>>1);
5136 else insb(CDi_data
, p
, CD_FRAMESIZE
);
5137 if (cmd_type
==READ_M2
) {
5138 if (do_16bit
) insw(CDi_data
, xa_tail_buf
, CD_XA_TAIL
>>1);
5139 else insb(CDi_data
, xa_tail_buf
, CD_XA_TAIL
);
5141 D_S
[d
].sbp_current
++;
5142 if (sbpro_type
==1) OUT(CDo_sel_i_d
,0);
5143 if (cmd_type
==READ_M2
)
5145 for (xa_count
=0;xa_count
<CD_XA_HEAD
;xa_count
++)
5146 sprintf(&msgbuf
[xa_count
*3], " %02X", xa_head_buf
[xa_count
]);
5147 msgbuf
[xa_count
*3]=0;
5148 msg(DBG_XA1
,"xa head:%s\n", msgbuf
);
5152 if (data_tries
>= 1000)
5154 msg(DBG_INF
,"sbp_data() statistics: %d waits in %d frames.\n", data_waits
, data_tries
);
5155 data_waits
= data_tries
= 0;
5158 duration
=jiffies
-duration
;
5159 msg(DBG_TEA
,"time to read %d frames: %d jiffies .\n",frame
,duration
);
5167 if ((i
=CDi_stat_loop_T()) == -1) break;
5175 if (!(i
&s_not_data_ready
))
5181 if (do_16bit
) i
=inw(CDi_data
);
5182 else i
=inb(CDi_data
);
5186 while (!(i
&s_not_data_ready
));
5187 msg(DBG_TEA
, "==========too much data (%d bytes/words)==============.\n", j
);
5189 if (!(i
&s_not_result_ready
))
5195 infobuf
[l
++]=inb(CDi_info
);
5198 while (!(i
&s_not_result_ready
));
5199 if (infobuf
[0]==0x00) success
=1;
5201 for (j
=0;j
<l
;j
++) sprintf(&msgbuf
[j
*3], " %02X", infobuf
[j
]);
5203 msg(DBG_TEA
,"sbp_data info response:%s\n", msgbuf
);
5205 if (infobuf
[0]==0x02)
5211 if (recursion
>1) msg(DBG_TEA
,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion
);
5212 else msg(DBG_TEA
,"sbp_data: CMDT_READ_ERR necessary.\n");
5214 drvcmd
[0]=CMDT_READ_ERR
;
5215 j
=cmd_out_T(); /* !!! recursive here !!! */
5220 D_S
[d
].error_state
=infobuf
[2];
5221 D_S
[d
].b3
=infobuf
[3];
5222 D_S
[d
].b4
=infobuf
[4];
5229 msg(DBG_TEA
, "============= waiting for result=================.\n");
5237 if (error_flag
) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
5239 msg(DBG_TEA
, "================error flag: %d=================.\n", error_flag
);
5240 msg(DBG_INF
,"sbp_data: read aborted by drive.\n");
5242 i
=cc_DriveReset(); /* ugly fix to prevent a hang */
5253 for (timeout
=jiffies
+HZ
; time_before(jiffies
, timeout
); timeout
--)
5258 if (!(j
&s_not_data_ready
)) break;
5259 if (!(j
&s_not_result_ready
)) break;
5260 if (j
&s_attention
) break;
5262 if (i
!= 0 || time_after_eq(jiffies
, timeout
)) break;
5266 if (i
==0) msg(DBG_INF
,"status timeout after READ.\n");
5267 if (!(j
&s_attention
))
5269 msg(DBG_INF
,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
5270 i
=cc_DriveReset(); /* ugly fix to prevent a hang */
5282 if (fam0LV_drive
) cc_ReadStatus();
5284 if (famT_drive
) msg(DBG_TEA
, "================before ResponseStatus=================.\n", i
);
5286 i
=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
5288 if (famT_drive
) msg(DBG_TEA
, "================ResponseStatus: %d=================.\n", i
);
5292 msg(DBG_INF
,"bad cc_ReadStatus after read: %02X\n", D_S
[d
].status_bits
);
5296 while ((fam0LV_drive
)&&(!st_check
)&&(!(i
&p_success
)));
5300 msg(DBG_INF
,"cc_ReadError was necessary after read: %d\n",i
);
5306 D_S
[d
].sbp_first_frame
=D_S
[d
].sbp_last_frame
=-1; /* purge buffer */
5307 D_S
[d
].sbp_current
= 0;
5308 msg(DBG_INF
,"sbp_data: fatal_err - retrying.\n");
5312 D_S
[d
].sbp_first_frame
= req
-> sector
/ 4;
5313 D_S
[d
].sbp_last_frame
= D_S
[d
].sbp_first_frame
+ D_S
[d
].sbp_read_frames
- 1;
5317 /*==========================================================================*/
5318 /*==========================================================================*/
5320 * Open the device special file. Check that a disk is in. Read TOC.
5322 static int sbpcd_open(struct cdrom_device_info
*cdi
, int purpose
)
5326 i
= MINOR(cdi
->dev
);
5329 down(&ioctl_read_sem
);
5333 * try to keep an "open" counter here and lock the door if 0->1.
5335 msg(DBG_LCK
,"open_count: %d -> %d\n",
5336 D_S
[d
].open_count
,D_S
[d
].open_count
+1);
5337 if (++D_S
[d
].open_count
<=1)
5340 D_S
[d
].open_count
=1;
5341 if (famT_drive
) msg(DBG_TEA
,"sbpcd_open: before i=DiskInfo();.\n");
5343 if (famT_drive
) msg(DBG_TEA
,"sbpcd_open: after i=DiskInfo();.\n");
5344 if ((D_S
[d
].ored_ctl_adr
&0x40)==0)
5346 msg(DBG_INF
,"CD contains no data tracks.\n");
5352 else if (D_S
[d
].has_data
<1) D_S
[d
].has_data
=1;
5355 if (!st_spinning
) cc_SpinUp();
5358 /*==========================================================================*/
5360 * On close, we flush all sbp blocks from the buffer cache.
5362 static void sbpcd_release(struct cdrom_device_info
* cdi
)
5366 i
= MINOR(cdi
->dev
);
5367 if ((i
<0) || (i
>=NR_SBPCD
) || (D_S
[i
].drv_id
==-1))
5369 msg(DBG_INF
, "release: bad device: %04X\n", cdi
->dev
);
5372 down(&ioctl_read_sem
);
5375 * try to keep an "open" counter here and unlock the door if 1->0.
5377 msg(DBG_LCK
,"open_count: %d -> %d\n",
5378 D_S
[d
].open_count
,D_S
[d
].open_count
-1);
5379 if (D_S
[d
].open_count
>-2) /* CDROMEJECT may have been done */
5381 if (--D_S
[d
].open_count
<=0)
5383 D_S
[d
].sbp_first_frame
=D_S
[d
].sbp_last_frame
=-1;
5384 invalidate_buffers(cdi
->dev
);
5385 if (D_S
[d
].audio_state
!=audio_playing
)
5386 if (D_S
[d
].f_eject
) cc_SpinDown();
5387 D_S
[d
].diskstate_flags
&= ~cd_size_bit
;
5388 D_S
[d
].open_count
=0;
5394 up(&ioctl_read_sem
);
5398 /*==========================================================================*/
5402 static int sbpcd_media_changed( struct cdrom_device_info
*cdi
, int disc_nr
);
5403 static struct cdrom_device_ops sbpcd_dops
= {
5404 sbpcd_open
, /* open */
5405 sbpcd_release
, /* release */
5406 sbpcd_drive_status
, /* drive status */
5407 sbpcd_media_changed
, /* media changed */
5408 sbpcd_tray_move
, /* tray move */
5409 sbpcd_lock_door
, /* lock door */
5410 sbpcd_select_speed
, /* select speed */
5411 NULL
, /* select disc */
5412 sbpcd_get_last_session
, /* get last session */
5413 sbpcd_get_mcn
, /* get universal product code */
5414 sbpcd_reset
, /* hard reset */
5415 sbpcd_audio_ioctl
, /* audio ioctl */
5416 sbpcd_dev_ioctl
, /* device-specific ioctl */
5417 CDC_CLOSE_TRAY
| CDC_OPEN_TRAY
| CDC_LOCK
| CDC_MULTI_SESSION
|
5418 CDC_MEDIA_CHANGED
| CDC_MCN
| CDC_PLAY_AUDIO
| CDC_IOCTLS
, /* capability */
5419 1, /* number of minor devices */
5422 static struct cdrom_device_info sbpcd_info
= {
5423 &sbpcd_dops
, /* device operations */
5428 2, /* maximum speed */
5429 1, /* number of discs */
5430 0, /* options, not owned */
5431 0, /* mc_flags, not owned */
5432 0 /* use count, not owned */
5434 /*==========================================================================*/
5436 * accept "kernel command line" parameters
5437 * (suggested by Peter MacDonald with SLS 1.03)
5439 * This is only implemented for the first controller. Should be enough to
5440 * allow installing with a "strange" distribution kernel.
5443 * sbpcd=0x230,SoundBlaster
5445 * sbpcd=0x300,LaserMate
5447 * sbpcd=0x338,SoundScape
5449 * sbpcd=0x2C0,Teac16bit
5451 * (upper/lower case sensitive here - but all-lowercase is ok!!!).
5453 * the address value has to be the CDROM PORT ADDRESS -
5454 * not the soundcard base address.
5455 * For the SPEA/SoundScape setup, DO NOT specify the "configuration port"
5456 * address, but the address which is really used for the CDROM (usually 8
5461 __initfunc(static void sbpcd_setup(const char *s
, int *p
))
5463 __initfunc(void sbpcd_setup(const char *s
, int *p
))
5467 msg(DBG_INI
,"sbpcd_setup called with %04X,%s\n",p
[1], s
);
5468 sbpro_type
=0; /* default: "LaserMate" */
5469 if (p
[0]>1) sbpro_type
=p
[2];
5470 else if (!strcmp(s
,str_sb
)) sbpro_type
=1;
5471 else if (!strcmp(s
,str_sb_l
)) sbpro_type
=1;
5472 else if (!strcmp(s
,str_sp
)) sbpro_type
=2;
5473 else if (!strcmp(s
,str_sp_l
)) sbpro_type
=2;
5474 else if (!strcmp(s
,str_ss
)) sbpro_type
=2;
5475 else if (!strcmp(s
,str_ss_l
)) sbpro_type
=2;
5476 else if (!strcmp(s
,str_t16
)) sbpro_type
=3;
5477 else if (!strcmp(s
,str_t16_l
)) sbpro_type
=3;
5478 if (p
[0]>0) sbpcd_ioaddr
=p
[1];
5480 CDo_command
=sbpcd_ioaddr
;
5481 CDi_info
=sbpcd_ioaddr
;
5482 CDi_status
=sbpcd_ioaddr
+1;
5483 CDo_sel_i_d
=sbpcd_ioaddr
+1;
5484 CDo_reset
=sbpcd_ioaddr
+2;
5485 CDo_enable
=sbpcd_ioaddr
+3;
5487 if ((sbpro_type
==1)||(sbpro_type
==3))
5489 CDi_data
=sbpcd_ioaddr
;
5496 else CDi_data
=sbpcd_ioaddr
+2;
5498 /*==========================================================================*/
5500 * Sequoia S-1000 CD-ROM Interface Configuration
5501 * as used within SPEA Media FX, Ensonic SoundScape and some Reveal cards
5502 * The soundcard has to get jumpered for the interface type "Panasonic"
5503 * (not Sony or Mitsumi) and to get soft-configured for
5504 * -> configuration port address
5505 * -> CDROM port offset (num_ports): has to be 8 here. Possibly this
5506 * offset value determines the interface type (none, Panasonic,
5508 * The interface uses a configuration port (0x320, 0x330, 0x340, 0x350)
5509 * some bytes below the real CDROM address.
5511 * For the Panasonic style (LaserMate) interface and the configuration
5512 * port 0x330, we have to use an offset of 8; so, the real CDROM port
5515 __initfunc(static int config_spea(void))
5518 * base address offset between configuration port and CDROM port,
5519 * this probably defines the interface type
5521 * 8 (type=LaserMate):0x10
5527 int irq_number
=0; /* off:0x00, 2/9:0x01, 7:0x03, 12:0x05, 15:0x07 */
5528 int dma_channel
=0; /* off: 0x00, 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68 */
5529 int dack_polarity
=0; /* L:0x00, H:0x80 */
5530 int drq_polarity
=0x40; /* L:0x00, H:0x40 */
5533 #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
5534 #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
5536 OUT(SPEA_REG_1
,0xFF);
5540 msg(DBG_SEQ
,"no SPEA interface at %04X present.\n", sbpcd_ioaddr
);
5541 return (-1); /* no interface found */
5543 OUT(SPEA_REG_1
,0x04);
5544 OUT(SPEA_REG_2
,0xC0);
5546 OUT(SPEA_REG_1
,0x05);
5547 OUT(SPEA_REG_2
,0x10|drq_polarity
|dack_polarity
);
5550 #define SPEA_PATTERN 0x80
5552 #define SPEA_PATTERN 0x00
5554 OUT(SPEA_REG_1
,0x06);
5555 OUT(SPEA_REG_2
,dma_channel
|irq_number
|SPEA_PATTERN
);
5556 OUT(SPEA_REG_2
,dma_channel
|irq_number
|SPEA_PATTERN
);
5558 OUT(SPEA_REG_1
,0x09);
5559 i
=(inb(SPEA_REG_2
)&0xCF)|n_ports
;
5562 sbpro_type
= 0; /* acts like a LaserMate interface now */
5563 msg(DBG_SEQ
,"found SoundScape interface at %04X.\n", sbpcd_ioaddr
);
5566 /*==========================================================================*/
5568 * Test for presence of drive and initialize it.
5569 * Called once at boot or load time.
5572 int init_module(void)
5574 __initfunc(int SBPCD_INIT(void))
5578 int addr
[2]={1, CDROM_PORT
};
5583 msg(DBG_INF
,"sbpcd.c %s\n", VERSION
);
5588 msg(DBG_INF
,"Looking for Matsushita/Panasonic, CreativeLabs, Longshine, TEAC CD-ROM drives\n");
5589 msg(DBG_INF
,"= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
5590 msg(DBG_INF
,"Auto-Probing can cause a hang (f.e. touching an NE2000 card).\n");
5591 msg(DBG_INF
,"If that happens, you have to reboot and use the\n");
5592 msg(DBG_INF
,"LILO (kernel) command line feature like:\n");
5593 msg(DBG_INF
," LILO boot: ... sbpcd=0x230,SoundBlaster\n");
5594 msg(DBG_INF
,"or like:\n");
5595 msg(DBG_INF
," LILO boot: ... sbpcd=0x300,LaserMate\n");
5596 msg(DBG_INF
,"or like:\n");
5597 msg(DBG_INF
," LILO boot: ... sbpcd=0x338,SoundScape\n");
5598 msg(DBG_INF
,"with your REAL address.\n");
5599 msg(DBG_INF
,"= = = = = = = = = = END of WARNING = = = = = == = = =\n");
5602 sbpcd
[0]=sbpcd_ioaddr
; /* possibly changed by kernel command line */
5603 sbpcd
[1]=sbpro_type
; /* possibly changed by kernel command line */
5606 for (port_index
=0;port_index
<NUM_PROBE
;port_index
+=2)
5608 addr
[1]=sbpcd
[port_index
];
5609 if (addr
[1]==0) break;
5610 if (check_region(addr
[1],4))
5612 msg(DBG_INF
,"check_region: %03X is not free.\n",addr
[1]);
5615 if (sbpcd
[port_index
+1]==2) type
=str_sp
;
5616 else if (sbpcd
[port_index
+1]==1) type
=str_sb
;
5617 else if (sbpcd
[port_index
+1]==3) type
=str_t16
;
5619 sbpcd_setup(type
, addr
);
5621 msg(DBG_INF
,"Scanning 0x%X (%s)...\n", CDo_command
, type
);
5623 if (sbpcd
[port_index
+1]==2)
5629 if (check_card(addr
[1])) continue;
5632 msg(DBG_INI
,"check_drives done.\n");
5633 if (i
>=0) break; /* drive found */
5634 } /* end of cycling through the set of possible I/O port addresses */
5638 msg(DBG_INF
, "No drive found.\n");
5648 msg(DBG_INF
, "You should read linux/Documentation/cdrom/sbpcd\n");
5649 msg(DBG_INF
, "and then configure sbpcd.h for your hardware.\n");
5652 msg(DBG_INI
,"check_datarate done.\n");
5654 for (j
=0;j
<NR_SBPCD
;j
++)
5656 if (D_S
[j
].drv_id
==-1) continue;
5659 if (!famL_drive
) cc_DriveReset();
5661 if (!st_spinning
) cc_SpinUp();
5662 D_S
[j
].sbp_first_frame
= -1; /* First frame in buffer */
5663 D_S
[j
].sbp_last_frame
= -1; /* Last frame in buffer */
5664 D_S
[j
].sbp_read_frames
= 0; /* Number of frames being read to buffer */
5665 D_S
[j
].sbp_current
= 0; /* Frame being currently read */
5666 D_S
[j
].CD_changed
=1;
5667 D_S
[j
].frame_size
=CD_FRAMESIZE
;
5670 if (!fam0_drive
) D_S
[j
].f_eject
=1;
5673 i
=ResponseStatus(); /* returns orig. status or p_busy_new */
5674 if (famT_drive
) i
=ResponseStatus(); /* returns orig. status or p_busy_new */
5678 msg(DBG_INF
,"init: ResponseStatus returns %d.\n",i
);
5685 msg(DBG_INI
,"init: cc_ReadError returns %d\n",i
);
5688 msg(DBG_INI
,"init: first GetStatus: %d\n",i
);
5689 msg(DBG_LCS
,"init: first GetStatus: error_byte=%d\n",
5691 if (D_S
[j
].error_byte
==aud_12
)
5693 timeout
=jiffies
+2*HZ
;
5697 msg(DBG_INI
,"init: second GetStatus: %02X\n",i
);
5699 "init: second GetStatus: error_byte=%d\n",
5702 if (!st_caddy_in
) break;
5704 while ((!st_diskok
)||time_after(jiffies
, timeout
));
5707 if (i
>=0) D_S
[j
].CD_changed
=1;
5711 * Turn on the CD audio channels.
5712 * The addresses are obtained from SOUND_BASE (see sbpcd.h).
5715 OUT(MIXER_addr
,MIXER_CD_Volume
); /* select SB Pro mixer register */
5716 OUT(MIXER_data
,0xCC); /* one nibble per channel, max. value: 0xFF */
5719 if (register_blkdev(MAJOR_NR
, major_name
, &cdrom_fops
) != 0)
5721 msg(DBG_INF
, "Can't get MAJOR %d for Matsushita CDROM\n", MAJOR_NR
);
5728 blk_dev
[MAJOR_NR
].request_fn
= DEVICE_REQUEST
;
5729 read_ahead
[MAJOR_NR
] = buffers
* (CD_FRAMESIZE
/ 512);
5731 request_region(CDo_command
,4,major_name
);
5733 for (j
=0;j
<NR_SBPCD
;j
++)
5735 struct cdrom_device_info
* sbpcd_infop
;
5737 if (D_S
[j
].drv_id
==-1) continue;
5743 * allocate memory for the frame buffers
5745 D_S
[j
].aud_buf
=NULL
;
5746 D_S
[j
].sbp_audsiz
=0;
5747 D_S
[j
].sbp_bufsiz
=buffers
;
5748 if (D_S
[j
].drv_type
&drv_fam1
)
5749 if (READ_AUDIO
>0) D_S
[j
].sbp_audsiz
=READ_AUDIO
;
5750 D_S
[j
].sbp_buf
=(u_char
*) vmalloc(D_S
[j
].sbp_bufsiz
*CD_FRAMESIZE
);
5751 if (D_S
[j
].sbp_buf
==NULL
)
5753 msg(DBG_INF
,"data buffer (%d frames) not available.\n",D_S
[j
].sbp_bufsiz
);
5754 if ((unregister_blkdev(MAJOR_NR
, major_name
) == -EINVAL
))
5756 printk("Can't unregister %s\n", major_name
);
5758 release_region(CDo_command
,4);
5762 msg(DBG_INF
,"data buffer size: %d frames.\n",buffers
);
5764 if (D_S
[j
].sbp_audsiz
>0)
5766 D_S
[j
].aud_buf
=(u_char
*) vmalloc(D_S
[j
].sbp_audsiz
*CD_FRAMESIZE_RAW
);
5767 if (D_S
[j
].aud_buf
==NULL
) msg(DBG_INF
,"audio buffer (%d frames) not available.\n",D_S
[j
].sbp_audsiz
);
5768 else msg(DBG_INF
,"audio buffer size: %d frames.\n",D_S
[j
].sbp_audsiz
);
5770 sbpcd_infop
= vmalloc(sizeof (struct cdrom_device_info
));
5771 if (sbpcd_infop
== NULL
)
5773 release_region(CDo_command
,4);
5776 D_S
[j
].sbpcd_infop
= sbpcd_infop
;
5777 memcpy (sbpcd_infop
, &sbpcd_info
, sizeof(struct cdrom_device_info
));
5778 sbpcd_infop
->dev
= MKDEV(MAJOR_NR
, j
);
5779 strncpy(sbpcd_infop
->name
,major_name
, sizeof(sbpcd_infop
->name
));
5781 if (register_cdrom(sbpcd_infop
))
5783 printk(" sbpcd: Unable to register with Uniform CD-ROm driver\n");
5787 * set the block size
5789 sbpcd_blocksizes
[j
]=CD_FRAMESIZE
;
5791 blksize_size
[MAJOR_NR
]=sbpcd_blocksizes
;
5795 #if !(SBPCD_ISSUE-1)
5796 #ifdef CONFIG_SBPCD2
5798 #endif CONFIG_SBPCD2
5799 #ifdef CONFIG_SBPCD3
5801 #endif CONFIG_SBPCD3
5802 #ifdef CONFIG_SBPCD4
5804 #endif CONFIG_SBPCD4
5805 #endif !(SBPCD_ISSUE-1)
5809 /*==========================================================================*/
5811 void cleanup_module(void)
5815 if ((unregister_blkdev(MAJOR_NR
, major_name
) == -EINVAL
))
5817 msg(DBG_INF
, "What's that: can't unregister %s.\n", major_name
);
5820 release_region(CDo_command
,4);
5822 for (j
=0;j
<NR_SBPCD
;j
++)
5824 if (D_S
[j
].drv_id
==-1) continue;
5825 vfree(D_S
[j
].sbp_buf
);
5826 if (D_S
[j
].sbp_audsiz
>0) vfree(D_S
[j
].aud_buf
);
5827 if ((unregister_cdrom(D_S
[j
].sbpcd_infop
) == -EINVAL
))
5829 msg(DBG_INF
, "What's that: can't unregister info %s.\n", major_name
);
5832 vfree(D_S
[j
].sbpcd_infop
);
5834 msg(DBG_INF
, "%s module released.\n", major_name
);
5837 /*==========================================================================*/
5839 * Check if the media has changed in the CD-ROM drive.
5840 * used externally (isofs/inode.c, fs/buffer.c)
5842 static int sbpcd_chk_disk_change(kdev_t full_dev
)
5846 msg(DBG_CHK
,"media_check (%d) called\n", MINOR(full_dev
));
5849 if (D_S
[i
].CD_changed
==0xFF)
5851 D_S
[i
].CD_changed
=0;
5852 msg(DBG_CHK
,"medium changed (drive %d)\n", i
);
5859 static int sbpcd_media_changed( struct cdrom_device_info
*cdi
, int disc_nr
)
5861 return sbpcd_chk_disk_change(cdi
->dev
);
5863 /*==========================================================================*/
5865 * Overrides for Emacs so that we follow Linus's tabbing style.
5866 * Emacs will notice this stuff at the end of the file and automatically
5867 * adjust the settings for this buffer only. This must remain at the end
5869 * ---------------------------------------------------------------------------
5872 * c-brace-imaginary-offset: 0
5873 * c-brace-offset: -8
5874 * c-argdecl-indent: 8
5875 * c-label-offset: -8
5876 * c-continued-statement-offset: 8
5877 * c-continued-brace-offset: 0