PageRenderTime 85ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/drivers/cdrom/sbpcd.c

https://bitbucket.org/evzijst/gittest
C | 5978 lines | 4918 code | 272 blank | 788 comment | 1194 complexity | def27a3f5ff2b3207e0ee3902794f44c MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /*
  2. * sbpcd.c CD-ROM device driver for the whole family of traditional,
  3. * non-ATAPI IDE-style Matsushita/Panasonic CR-5xx drives.
  4. * Works with SoundBlaster compatible cards and with "no-sound"
  5. * interface cards like Lasermate, Panasonic CI-101P, Teac, ...
  6. * Also for the Longshine LCS-7260 drive.
  7. * Also for the IBM "External ISA CD-Rom" drive.
  8. * Also for the CreativeLabs CD200 drive.
  9. * Also for the TEAC CD-55A drive.
  10. * Also for the ECS-AT "Vertos 100" drive.
  11. * Not for Sanyo drives (but for the H94A, sjcd is there...).
  12. * Not for any other Funai drives than the CD200 types (sometimes
  13. * labelled E2550UA or MK4015 or 2800F).
  14. */
  15. #define VERSION "v4.63 Andrew J. Kroll <ag784@freenet.buffalo.edu> Wed Jul 26 04:24:10 EDT 2000"
  16. /* Copyright (C) 1993, 1994, 1995 Eberhard Moenkeberg <emoenke@gwdg.de>
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2, or (at your option)
  21. * any later version.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * (for example /usr/src/linux/COPYING); if not, write to the Free
  25. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. *
  27. * If you change this software, you should mail a .diff file with some
  28. * description lines to emoenke@gwdg.de. I want to know about it.
  29. *
  30. * If you are the editor of a Linux CD, you should enable sbpcd.c within
  31. * your boot floppy kernel and send me one of your CDs for free.
  32. *
  33. * If you would like to port the driver to an other operating system (f.e.
  34. * FreeBSD or NetBSD) or use it as an information source, you shall not be
  35. * restricted by the GPL under the following conditions:
  36. * a) the source code of your work is freely available
  37. * b) my part of the work gets mentioned at all places where your
  38. * authorship gets mentioned
  39. * c) I receive a copy of your code together with a full installation
  40. * package of your operating system for free.
  41. *
  42. *
  43. * VERSION HISTORY
  44. *
  45. * 0.1 initial release, April/May 93, after mcd.c (Martin Harriss)
  46. *
  47. * 0.2 thek "repeat:"-loop in do_sbpcd_request did not check for
  48. * end-of-request_queue (resulting in kernel panic).
  49. * Flow control seems stable, but throughput is not better.
  50. *
  51. * 0.3 interrupt locking totally eliminated (maybe "inb" and "outb"
  52. * are still locking) - 0.2 made keyboard-type-ahead losses.
  53. * check_sbpcd_media_change added (to use by isofs/inode.c)
  54. * - but it detects almost nothing.
  55. *
  56. * 0.4 use MAJOR 25 definitely.
  57. * Almost total re-design to support double-speed drives and
  58. * "naked" (no sound) interface cards ("LaserMate" interface type).
  59. * Flow control should be exact now.
  60. * Don't occupy the SbPro IRQ line (not needed either); will
  61. * live together with Hannu Savolainen's sndkit now.
  62. * Speeded up data transfer to 150 kB/sec, with help from Kai
  63. * Makisara, the "provider" of the "mt" tape utility.
  64. * Give "SpinUp" command if necessary.
  65. * First steps to support up to 4 drives (but currently only one).
  66. * Implemented audio capabilities - workman should work, xcdplayer
  67. * gives some problems.
  68. * This version is still consuming too much CPU time, and
  69. * sleeping still has to be worked on.
  70. * During "long" implied seeks, it seems possible that a
  71. * ReadStatus command gets ignored. That gives the message
  72. * "ResponseStatus timed out" (happens about 6 times here during
  73. * a "ls -alR" of the YGGDRASIL LGX-Beta CD). Such a case is
  74. * handled without data error, but it should get done better.
  75. *
  76. * 0.5 Free CPU during waits (again with help from Kai Makisara).
  77. * Made it work together with the LILO/kernel setup standard.
  78. * Included auto-probing code, as suggested by YGGDRASIL.
  79. * Formal redesign to add DDI debugging.
  80. * There are still flaws in IOCTL (workman with double speed drive).
  81. *
  82. * 1.0 Added support for all drive IDs (0...3, no longer only 0)
  83. * and up to 4 drives on one controller.
  84. * Added "#define MANY_SESSION" for "old" multi session CDs.
  85. *
  86. * 1.1 Do SpinUp for new drives, too.
  87. * Revised for clean compile under "old" kernels (0.99pl9).
  88. *
  89. * 1.2 Found the "workman with double-speed drive" bug: use the driver's
  90. * audio_state, not what the drive is reporting with ReadSubQ.
  91. *
  92. * 1.3 Minor cleanups.
  93. * Refinements regarding Workman.
  94. *
  95. * 1.4 Read XA disks (PhotoCDs) with "old" drives, too (but only the first
  96. * session - no chance to fully access a "multi-session" CD).
  97. * This currently still is too slow (50 kB/sec) - but possibly
  98. * the old drives won't do it faster.
  99. * Implemented "door (un)lock" for new drives (still does not work
  100. * as wanted - no lock possible after an unlock).
  101. * Added some debugging printout for the UPC/EAN code - but my drives
  102. * return only zeroes. Is there no UPC/EAN code written?
  103. *
  104. * 1.5 Laborate with UPC/EAN code (not better yet).
  105. * Adapt to kernel 1.1.8 change (have to explicitly include
  106. * <linux/string.h> now).
  107. *
  108. * 1.6 Trying to read audio frames as data. Impossible with the current
  109. * drive firmware levels, as it seems. Awaiting any hint. ;-)
  110. * Changed "door unlock": repeat it until success.
  111. * Changed CDROMSTOP routine (stop somewhat "softer" so that Workman
  112. * won't get confused).
  113. * Added a third interface type: Sequoia S-1000, as used with the SPEA
  114. * Media FX sound card. This interface (usable for Sony and Mitsumi
  115. * drives, too) needs a special configuration setup and behaves like a
  116. * LaserMate type after that. Still experimental - I do not have such
  117. * an interface.
  118. * Use the "variable BLOCK_SIZE" feature (2048). But it does only work
  119. * if you give the mount option "block=2048".
  120. * The media_check routine is currently disabled; now that it gets
  121. * called as it should I fear it must get synchronized for not to
  122. * disturb the normal driver's activity.
  123. *
  124. * 2.0 Version number bumped - two reasons:
  125. * - reading audio tracks as data works now with CR-562 and CR-563. We
  126. * currently do it by an IOCTL (yet has to get standardized), one frame
  127. * at a time; that is pretty slow. But it works.
  128. * - we are maintaining now up to 4 interfaces (each up to 4 drives):
  129. * did it the easy way - a different MAJOR (25, 26, ...) and a different
  130. * copy of the driver (sbpcd.c, sbpcd2.c, sbpcd3.c, sbpcd4.c - only
  131. * distinguished by the value of SBPCD_ISSUE and the driver's name),
  132. * and a common sbpcd.h file.
  133. * Bettered the "ReadCapacity error" problem with old CR-52x drives (the
  134. * drives sometimes need a manual "eject/insert" before work): just
  135. * reset the drive and do again. Needs lots of resets here and sometimes
  136. * that does not cure, so this can't be the solution.
  137. *
  138. * 2.1 Found bug with multisession CDs (accessing frame 16).
  139. * "read audio" works now with address type CDROM_MSF, too.
  140. * Bigger audio frame buffer: allows reading max. 4 frames at time; this
  141. * gives a significant speedup, but reading more than one frame at once
  142. * gives missing chunks at each single frame boundary.
  143. *
  144. * 2.2 Kernel interface cleanups: timers, init, setup, media check.
  145. *
  146. * 2.3 Let "door lock" and "eject" live together.
  147. * Implemented "close tray" (done automatically during open).
  148. *
  149. * 2.4 Use different names for device registering.
  150. *
  151. * 2.5 Added "#if EJECT" code (default: enabled) to automatically eject
  152. * the tray during last call to "sbpcd_release".
  153. * Added "#if JUKEBOX" code (default: disabled) to automatically eject
  154. * the tray during call to "sbpcd_open" if no disk is in.
  155. * Turn on the CD volume of "compatible" sound cards, too; just define
  156. * SOUND_BASE (in sbpcd.h) accordingly (default: disabled).
  157. *
  158. * 2.6 Nothing new.
  159. *
  160. * 2.7 Added CDROMEJECT_SW ioctl to set the "EJECT" behavior on the fly:
  161. * 0 disables, 1 enables auto-ejecting. Useful to keep the tray in
  162. * during shutdown.
  163. *
  164. * 2.8 Added first support (still BETA, I need feedback or a drive) for
  165. * the Longshine LCS-7260 drives. They appear as double-speed drives
  166. * using the "old" command scheme, extended by tray control and door
  167. * lock functions.
  168. * Found (and fixed preliminary) a flaw with some multisession CDs: we
  169. * have to re-direct not only the accesses to frame 16 (the isofs
  170. * routines drive it up to max. 100), but also those to the continuation
  171. * (repetition) frames (as far as they exist - currently set fix as
  172. * 16..20).
  173. * Changed default of the "JUKEBOX" define. If you use this default,
  174. * your tray will eject if you try to mount without a disk in. Next
  175. * mount command will insert the tray - so, just fill in a disk. ;-)
  176. *
  177. * 2.9 Fulfilled the Longshine LCS-7260 support; with great help and
  178. * experiments by Serge Robyns.
  179. * First attempts to support the TEAC CD-55A drives; but still not
  180. * usable yet.
  181. * Implemented the CDROMMULTISESSION ioctl; this is an attempt to handle
  182. * multi session CDs more "transparent" (redirection handling has to be
  183. * done within the isofs routines, and only for the special purpose of
  184. * obtaining the "right" volume descriptor; accesses to the raw device
  185. * should not get redirected).
  186. *
  187. * 3.0 Just a "normal" increment, with some provisions to do it better. ;-)
  188. * Introduced "#define READ_AUDIO" to specify the maximum number of
  189. * audio frames to grab with one request. This defines a buffer size
  190. * within kernel space; a value of 0 will reserve no such space and
  191. * disable the CDROMREADAUDIO ioctl. A value of 75 enables the reading
  192. * of a whole second with one command, but will use a buffer of more
  193. * than 172 kB.
  194. * Started CD200 support. Drive detection should work, but nothing
  195. * more.
  196. *
  197. * 3.1 Working to support the CD200 and the Teac CD-55A drives.
  198. * AT-BUS style device numbering no longer used: use SCSI style now.
  199. * So, the first "found" device has MINOR 0, regardless of the
  200. * jumpered drive ID. This implies modifications to the /dev/sbpcd*
  201. * entries for some people, but will help the DAU (german TLA, english:
  202. * "newbie", maybe ;-) to install his "first" system from a CD.
  203. *
  204. * 3.2 Still testing with CD200 and CD-55A drives.
  205. *
  206. * 3.3 Working with CD200 support.
  207. *
  208. * 3.4 Auto-probing stops if an address of 0 is seen (to be entered with
  209. * the kernel command line).
  210. * Made the driver "loadable". If used as a module, "audio copy" is
  211. * disabled, and the internal read ahead data buffer has a reduced size
  212. * of 4 kB; so, throughput may be reduced a little bit with slow CPUs.
  213. *
  214. * 3.5 Provisions to handle weird photoCDs which have an interrupted
  215. * "formatting" immediately after the last frames of some files: simply
  216. * never "read ahead" with MultiSession CDs. By this, CPU usage may be
  217. * increased with those CDs, and there may be a loss in speed.
  218. * Re-structured the messaging system.
  219. * The "loadable" version no longer has a limited READ_AUDIO buffer
  220. * size.
  221. * Removed "MANY_SESSION" handling for "old" multi session CDs.
  222. * Added "private" IOCTLs CDROMRESET and CDROMVOLREAD.
  223. * Started again to support the TEAC CD-55A drives, now that I found
  224. * the money for "my own" drive. ;-)
  225. * The TEAC CD-55A support is fairly working now.
  226. * I have measured that the drive "delivers" at 600 kB/sec (even with
  227. * bigger requests than the drive's 64 kB buffer can satisfy), but
  228. * the "real" rate does not exceed 520 kB/sec at the moment.
  229. * Caused by the various changes to build in TEAC support, the timed
  230. * loops are de-optimized at the moment (less throughput with CR-52x
  231. * drives, and the TEAC will give speed only with SBP_BUFFER_FRAMES 64).
  232. *
  233. * 3.6 Fixed TEAC data read problems with SbPro interfaces.
  234. * Initial size of the READ_AUDIO buffer is 0. Can get set to any size
  235. * during runtime.
  236. *
  237. * 3.7 Introduced MAX_DRIVES for some poor interface cards (seen with TEAC
  238. * drives) which allow only one drive (ID 0); this avoids repetitive
  239. * detection under IDs 1..3.
  240. * Elongated cmd_out_T response waiting; necessary for photo CDs with
  241. * a lot of sessions.
  242. * Bettered the sbpcd_open() behavior with TEAC drives.
  243. *
  244. * 3.8 Elongated max_latency for CR-56x drives.
  245. *
  246. * 3.9 Finally fixed the long-known SoundScape/SPEA/Sequoia S-1000 interface
  247. * configuration bug.
  248. * Now Corey, Heiko, Ken, Leo, Vadim/Eric & Werner are invited to copy
  249. * the config_spea() routine into their drivers. ;-)
  250. *
  251. * 4.0 No "big step" - normal version increment.
  252. * Adapted the benefits from 1.3.33.
  253. * Fiddled with CDROMREADAUDIO flaws.
  254. * Avoid ReadCapacity command with CD200 drives (the MKE 1.01 version
  255. * seems not to support it).
  256. * Fulfilled "read audio" for CD200 drives, with help of Pete Heist
  257. * (heistp@rpi.edu).
  258. *
  259. * 4.1 Use loglevel KERN_INFO with printk().
  260. * Added support for "Vertos 100" drive ("ECS-AT") - it is very similar
  261. * to the Longshine LCS-7260. Give feedback if you can - I never saw
  262. * such a drive, and I have no specs.
  263. *
  264. * 4.2 Support for Teac 16-bit interface cards. Can't get auto-detected,
  265. * so you have to jumper your card to 0x2C0. Still not 100% - come
  266. * in contact if you can give qualified feedback.
  267. * Use loglevel KERN_NOTICE with printk(). If you get annoyed by a
  268. * flood of unwanted messages and the accompanied delay, try to read
  269. * my documentation. Especially the Linux CDROM drivers have to do an
  270. * important job for the newcomers, so the "distributed" version has
  271. * to fit some special needs. Since generations, the flood of messages
  272. * is user-configurable (even at runtime), but to get aware of this, one
  273. * needs a special mental quality: the ability to read.
  274. *
  275. * 4.3 CD200F does not like to receive a command while the drive is
  276. * reading the ToC; still trying to solve it.
  277. * Removed some redundant verify_area calls (yes, Heiko Eissfeldt
  278. * is visiting all the Linux CDROM drivers ;-).
  279. *
  280. * 4.4 Adapted one idea from tiensivu@pilot.msu.edu's "stripping-down"
  281. * experiments: "KLOGD_PAUSE".
  282. * Inhibited "play audio" attempts with data CDs. Provisions for a
  283. * "data-safe" handling of "mixed" (data plus audio) Cds.
  284. *
  285. * 4.5 Meanwhile Gonzalo Tornaria <tornaria@cmat.edu.uy> (GTL) built a
  286. * special end_request routine: we seem to have to take care for not
  287. * to have two processes working at the request list. My understanding
  288. * was and is that ll_rw_blk should not call do_sbpcd_request as long
  289. * as there is still one call active (the first call will care for all
  290. * outstanding I/Os, and if a second call happens, that is a bug in
  291. * ll_rw_blk.c).
  292. * "Check media change" without touching any drive.
  293. *
  294. * 4.6 Use a semaphore to synchronize multi-activity; elaborated by Rob
  295. * Riggs <rriggs@tesser.com>. At the moment, we simply block "read"
  296. * against "ioctl" and vice versa. This could be refined further, but
  297. * I guess with almost no performance increase.
  298. * Experiments to speed up the CD-55A; again with help of Rob Riggs
  299. * (to be true, he gave both, idea & code. ;-)
  300. *
  301. * 4.61 Ported to Uniform CD-ROM driver by
  302. * Heiko Eissfeldt <heiko@colossus.escape.de> with additional
  303. * changes by Erik Andersen <andersee@debian.org>
  304. *
  305. * 4.62 Fix a bug where playing audio left the drive in an unusable state.
  306. * Heiko Eissfeldt <heiko@colossus.escape.de>
  307. *
  308. * November 1999 -- Make kernel-parameter implementation work with 2.3.x
  309. * Removed init_module & cleanup_module in favor of
  310. * module_init & module_exit.
  311. * Torben Mathiasen <tmm@image.dk>
  312. *
  313. * 4.63 Bug fixes for audio annoyances, new legacy CDROM maintainer.
  314. * Annoying things fixed:
  315. * TOC reread on automated disk changes
  316. * TOC reread on manual cd changes
  317. * Play IOCTL tries to play CD before it's actually ready... sometimes.
  318. * CD_AUDIO_COMPLETED state so workman (and other playes) can repeat play.
  319. * Andrew J. Kroll <ag784@freenet.buffalo.edu> Wed Jul 26 04:24:10 EDT 2000
  320. *
  321. * 4.64 Fix module parameters - were being completely ignored.
  322. * Can also specify max_drives=N as a setup int to get rid of
  323. * "ghost" drives on crap hardware (aren't they all?) Paul Gortmaker
  324. *
  325. * TODO
  326. * implement "read all subchannel data" (96 bytes per frame)
  327. * remove alot of the virtual status bits and deal with hardware status
  328. * move the change of cd for audio to a better place
  329. * add debug levels to insmod parameters (trivial)
  330. *
  331. * special thanks to Kai Makisara (kai.makisara@vtt.fi) for his fine
  332. * elaborated speed-up experiments (and the fabulous results!), for
  333. * the "push" towards load-free wait loops, and for the extensive mail
  334. * thread which brought additional hints and bug fixes.
  335. *
  336. */
  337. /*
  338. * Trying to merge requests breaks this driver horribly (as in it goes
  339. * boom and apparently has done so since 2.3.41). As it is a legacy
  340. * driver for a horribly slow double speed CD on a hideous interface
  341. * designed for polled operation, I won't lose any sleep in simply
  342. * disallowing merging. Paul G. 02/2001
  343. *
  344. * Thu May 30 14:14:47 CEST 2002:
  345. *
  346. * I have presumably found the reson for the above - there was a bogous
  347. * end_request substitute, which was manipulating the request queues
  348. * incorrectly. If someone has access to the actual hardware, and it's
  349. * still operations - well please free to test it.
  350. *
  351. * Marcin Dalecki
  352. */
  353. /*
  354. * Add bio/kdev_t changes for 2.5.x required to make it work again.
  355. * Still room for improvement in the request handling here if anyone
  356. * actually cares. Bring your own chainsaw. Paul G. 02/2002
  357. */
  358. #include <linux/module.h>
  359. #include <linux/errno.h>
  360. #include <linux/sched.h>
  361. #include <linux/mm.h>
  362. #include <linux/timer.h>
  363. #include <linux/fs.h>
  364. #include <linux/kernel.h>
  365. #include <linux/cdrom.h>
  366. #include <linux/ioport.h>
  367. #include <linux/devfs_fs_kernel.h>
  368. #include <linux/major.h>
  369. #include <linux/string.h>
  370. #include <linux/vmalloc.h>
  371. #include <linux/init.h>
  372. #include <linux/interrupt.h>
  373. #include <asm/system.h>
  374. #include <asm/io.h>
  375. #include <asm/uaccess.h>
  376. #include <stdarg.h>
  377. #include <linux/config.h>
  378. #include "sbpcd.h"
  379. #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
  380. #include <linux/blkdev.h>
  381. /*==========================================================================*/
  382. #if SBPCD_DIS_IRQ
  383. # define SBPCD_CLI cli()
  384. # define SBPCD_STI sti()
  385. #else
  386. # define SBPCD_CLI
  387. # define SBPCD_STI
  388. #endif
  389. /*==========================================================================*/
  390. /*
  391. * auto-probing address list
  392. * inspired by Adam J. Richter from Yggdrasil
  393. *
  394. * still not good enough - can cause a hang.
  395. * example: a NE 2000 ethernet card at 300 will cause a hang probing 310.
  396. * if that happens, reboot and use the LILO (kernel) command line.
  397. * The possibly conflicting ethernet card addresses get NOT probed
  398. * by default - to minimize the hang possibilities.
  399. *
  400. * The SB Pro addresses get "mirrored" at 0x6xx and some more locations - to
  401. * avoid a type error, the 0x2xx-addresses must get checked before 0x6xx.
  402. *
  403. * send mail to emoenke@gwdg.de if your interface card is not FULLY
  404. * represented here.
  405. */
  406. static int sbpcd[] =
  407. {
  408. CDROM_PORT, SBPRO, /* probe with user's setup first */
  409. #if DISTRIBUTION
  410. 0x230, 1, /* Soundblaster Pro and 16 (default) */
  411. #if 0
  412. 0x300, 0, /* CI-101P (default), WDH-7001C (default),
  413. Galaxy (default), Reveal (one default) */
  414. 0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
  415. 0x2C0, 3, /* Teac 16-bit cards */
  416. 0x260, 1, /* OmniCD */
  417. 0x320, 0, /* Lasermate, CI-101P, WDH-7001C, Galaxy, Reveal (other default),
  418. Longshine LCS-6853 (default) */
  419. 0x338, 0, /* Reveal Sound Wave 32 card model #SC600 */
  420. 0x340, 0, /* Mozart sound card (default), Lasermate, CI-101P */
  421. 0x360, 0, /* Lasermate, CI-101P */
  422. 0x270, 1, /* Soundblaster 16 */
  423. 0x670, 0, /* "sound card #9" */
  424. 0x690, 0, /* "sound card #9" */
  425. 0x338, 2, /* SPEA Media FX, Ensonic SoundScape (default) */
  426. 0x328, 2, /* SPEA Media FX */
  427. 0x348, 2, /* SPEA Media FX */
  428. 0x634, 0, /* some newer sound cards */
  429. 0x638, 0, /* some newer sound cards */
  430. 0x230, 1, /* some newer sound cards */
  431. /* due to incomplete address decoding of the SbPro card, these must be last */
  432. 0x630, 0, /* "sound card #9" (default) */
  433. 0x650, 0, /* "sound card #9" */
  434. #ifdef MODULE
  435. /*
  436. * some "hazardous" locations (no harm with the loadable version)
  437. * (will stop the bus if a NE2000 ethernet card resides at offset -0x10)
  438. */
  439. 0x330, 0, /* Lasermate, CI-101P, WDH-7001C */
  440. 0x350, 0, /* Lasermate, CI-101P */
  441. 0x358, 2, /* SPEA Media FX */
  442. 0x370, 0, /* Lasermate, CI-101P */
  443. 0x290, 1, /* Soundblaster 16 */
  444. 0x310, 0, /* Lasermate, CI-101P, WDH-7001C */
  445. #endif /* MODULE */
  446. #endif
  447. #endif /* DISTRIBUTION */
  448. };
  449. /*
  450. * Protects access to global structures etc.
  451. */
  452. static __cacheline_aligned DEFINE_SPINLOCK(sbpcd_lock);
  453. static struct request_queue *sbpcd_queue;
  454. MODULE_PARM(sbpcd, "2i");
  455. MODULE_PARM(max_drives, "i");
  456. #define NUM_PROBE (sizeof(sbpcd) / sizeof(int))
  457. /*==========================================================================*/
  458. #define INLINE inline
  459. /*==========================================================================*/
  460. /*
  461. * the forward references:
  462. */
  463. static void sbp_sleep(u_int);
  464. static void mark_timeout_delay(u_long);
  465. static void mark_timeout_data(u_long);
  466. #if 0
  467. static void mark_timeout_audio(u_long);
  468. #endif
  469. static void sbp_read_cmd(struct request *req);
  470. static int sbp_data(struct request *req);
  471. static int cmd_out(void);
  472. static int DiskInfo(void);
  473. /*==========================================================================*/
  474. /*
  475. * pattern for printk selection:
  476. *
  477. * (1<<DBG_INF) necessary information
  478. * (1<<DBG_BSZ) BLOCK_SIZE trace
  479. * (1<<DBG_REA) "read" status trace
  480. * (1<<DBG_CHK) "media check" trace
  481. * (1<<DBG_TIM) datarate timer test
  482. * (1<<DBG_INI) initialization trace
  483. * (1<<DBG_TOC) tell TocEntry values
  484. * (1<<DBG_IOC) ioctl trace
  485. * (1<<DBG_STA) "ResponseStatus" trace
  486. * (1<<DBG_ERR) "cc_ReadError" trace
  487. * (1<<DBG_CMD) "cmd_out" trace
  488. * (1<<DBG_WRN) give explanation before auto-probing
  489. * (1<<DBG_MUL) multi session code test
  490. * (1<<DBG_IDX) "drive_id != 0" test code
  491. * (1<<DBG_IOX) some special information
  492. * (1<<DBG_DID) drive ID test
  493. * (1<<DBG_RES) drive reset info
  494. * (1<<DBG_SPI) SpinUp test info
  495. * (1<<DBG_IOS) ioctl trace: "subchannel"
  496. * (1<<DBG_IO2) ioctl trace: general
  497. * (1<<DBG_UPC) show UPC info
  498. * (1<<DBG_XA1) XA mode debugging
  499. * (1<<DBG_LCK) door (un)lock info
  500. * (1<<DBG_SQ1) dump SubQ frame
  501. * (1<<DBG_AUD) "read audio" debugging
  502. * (1<<DBG_SEQ) Sequoia interface configuration trace
  503. * (1<<DBG_LCS) Longshine LCS-7260 debugging trace
  504. * (1<<DBG_CD2) MKE/Funai CD200 debugging trace
  505. * (1<<DBG_TEA) TEAC CD-55A debugging trace
  506. * (1<<DBG_ECS) ECS-AT (Vertos-100) debugging trace
  507. * (1<<DBG_000) unnecessary information
  508. */
  509. #if DISTRIBUTION
  510. static int sbpcd_debug = (1<<DBG_INF);
  511. #else
  512. static int sbpcd_debug = 0 & ((1<<DBG_INF) |
  513. (1<<DBG_TOC) |
  514. (1<<DBG_MUL) |
  515. (1<<DBG_UPC));
  516. #endif /* DISTRIBUTION */
  517. static int sbpcd_ioaddr = CDROM_PORT; /* default I/O base address */
  518. static int sbpro_type = SBPRO;
  519. static unsigned char f_16bit;
  520. static unsigned char do_16bit;
  521. static int CDo_command, CDo_reset;
  522. static int CDo_sel_i_d, CDo_enable;
  523. static int CDi_info, CDi_status, CDi_data;
  524. static struct cdrom_msf msf;
  525. static struct cdrom_ti ti;
  526. static struct cdrom_tochdr tochdr;
  527. static struct cdrom_tocentry tocentry;
  528. static struct cdrom_subchnl SC;
  529. static struct cdrom_volctrl volctrl;
  530. static struct cdrom_read_audio read_audio;
  531. static unsigned char msgnum;
  532. static char msgbuf[80];
  533. static int max_drives = MAX_DRIVES;
  534. #ifndef MODULE
  535. static unsigned char setup_done;
  536. static const char *str_sb_l = "soundblaster";
  537. static const char *str_sp_l = "spea";
  538. static const char *str_ss_l = "soundscape";
  539. static const char *str_t16_l = "teac16bit";
  540. static const char *str_ss = "SoundScape";
  541. #endif
  542. static const char *str_sb = "SoundBlaster";
  543. static const char *str_lm = "LaserMate";
  544. static const char *str_sp = "SPEA";
  545. static const char *str_t16 = "Teac16bit";
  546. static const char *type;
  547. static const char *major_name="sbpcd";
  548. /*==========================================================================*/
  549. #ifdef FUTURE
  550. static DECLARE_WAIT_QUEUE_HEAD(sbp_waitq);
  551. #endif /* FUTURE */
  552. static int teac=SBP_TEAC_SPEED;
  553. static int buffers=SBP_BUFFER_FRAMES;
  554. static u_char family0[]="MATSHITA"; /* MKE CR-521, CR-522, CR-523 */
  555. static u_char family1[]="CR-56"; /* MKE CR-562, CR-563 */
  556. static u_char family2[]="CD200"; /* MKE CD200, Funai CD200F */
  557. static u_char familyL[]="LCS-7260"; /* Longshine LCS-7260 */
  558. static u_char familyT[]="CD-55"; /* TEAC CD-55A */
  559. static u_char familyV[]="ECS-AT"; /* ECS Vertos 100 */
  560. static u_int recursion; /* internal testing only */
  561. static u_int fatal_err; /* internal testing only */
  562. static u_int response_count;
  563. static u_int flags_cmd_out;
  564. static u_char cmd_type;
  565. static u_char drvcmd[10];
  566. static u_char infobuf[20];
  567. static u_char xa_head_buf[CD_XA_HEAD];
  568. static u_char xa_tail_buf[CD_XA_TAIL];
  569. #if OLD_BUSY
  570. static volatile u_char busy_data;
  571. static volatile u_char busy_audio; /* true semaphores would be safer */
  572. #endif /* OLD_BUSY */
  573. static DECLARE_MUTEX(ioctl_read_sem);
  574. static u_long timeout;
  575. static volatile u_char timed_out_delay;
  576. static volatile u_char timed_out_data;
  577. #if 0
  578. static volatile u_char timed_out_audio;
  579. #endif
  580. static u_int datarate= 1000000;
  581. static u_int maxtim16=16000000;
  582. static u_int maxtim04= 4000000;
  583. static u_int maxtim02= 2000000;
  584. static u_int maxtim_8= 30000;
  585. #if LONG_TIMING
  586. static u_int maxtim_data= 9000;
  587. #else
  588. static u_int maxtim_data= 3000;
  589. #endif /* LONG_TIMING */
  590. #if DISTRIBUTION
  591. static int n_retries=6;
  592. #else
  593. static int n_retries=6;
  594. #endif
  595. /*==========================================================================*/
  596. static int ndrives;
  597. static u_char drv_pattern[NR_SBPCD]={speed_auto,speed_auto,speed_auto,speed_auto};
  598. /*==========================================================================*/
  599. /*
  600. * drive space begins here (needed separate for each unit)
  601. */
  602. static struct sbpcd_drive {
  603. char drv_id; /* "jumpered" drive ID or -1 */
  604. char drv_sel; /* drive select lines bits */
  605. char drive_model[9];
  606. u_char firmware_version[4];
  607. char f_eject; /* auto-eject flag: 0 or 1 */
  608. u_char *sbp_buf; /* Pointer to internal data buffer,
  609. space allocated during sbpcd_init() */
  610. u_int sbp_bufsiz; /* size of sbp_buf (# of frames) */
  611. int sbp_first_frame; /* First frame in buffer */
  612. int sbp_last_frame; /* Last frame in buffer */
  613. int sbp_read_frames; /* Number of frames being read to buffer */
  614. int sbp_current; /* Frame being currently read */
  615. u_char mode; /* read_mode: READ_M1, READ_M2, READ_SC, READ_AU */
  616. u_char *aud_buf; /* Pointer to audio data buffer,
  617. space allocated during sbpcd_init() */
  618. u_int sbp_audsiz; /* size of aud_buf (# of raw frames) */
  619. u_int drv_type;
  620. u_char drv_options;
  621. int status_bits;
  622. u_char diskstate_flags;
  623. u_char sense_byte;
  624. u_char CD_changed;
  625. char open_count;
  626. u_char error_byte;
  627. u_char f_multisession;
  628. u_int lba_multi;
  629. int first_session;
  630. int last_session;
  631. int track_of_last_session;
  632. u_char audio_state;
  633. u_int pos_audio_start;
  634. u_int pos_audio_end;
  635. char vol_chan0;
  636. u_char vol_ctrl0;
  637. char vol_chan1;
  638. u_char vol_ctrl1;
  639. #if 000 /* no supported drive has it */
  640. char vol_chan2;
  641. u_char vol_ctrl2;
  642. char vol_chan3;
  643. u_char vol_ctrl3;
  644. #endif /*000 */
  645. u_char volume_control; /* TEAC on/off bits */
  646. u_char SubQ_ctl_adr;
  647. u_char SubQ_trk;
  648. u_char SubQ_pnt_idx;
  649. u_int SubQ_run_tot;
  650. u_int SubQ_run_trk;
  651. u_char SubQ_whatisthis;
  652. u_char UPC_ctl_adr;
  653. u_char UPC_buf[7];
  654. int frame_size;
  655. int CDsize_frm;
  656. u_char xa_byte; /* 0x20: XA capabilities */
  657. u_char n_first_track; /* binary */
  658. u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
  659. u_int size_msf; /* time of whole CD, position of LeadOut track */
  660. u_int size_blk;
  661. u_char TocEnt_nixbyte; /* em */
  662. u_char TocEnt_ctl_adr;
  663. u_char TocEnt_number;
  664. u_char TocEnt_format; /* em */
  665. u_int TocEnt_address;
  666. #ifdef SAFE_MIXED
  667. char has_data;
  668. #endif /* SAFE_MIXED */
  669. u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
  670. struct {
  671. u_char nixbyte; /* em */
  672. u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
  673. u_char number;
  674. u_char format; /* em */ /* 0x00: lba, 0x01: msf */
  675. u_int address;
  676. } TocBuffer[MAX_TRACKS+1]; /* last entry faked */
  677. int in_SpinUp; /* CR-52x test flag */
  678. int n_bytes; /* TEAC awaited response count */
  679. u_char error_state, b3, b4; /* TEAC command error state */
  680. u_char f_drv_error; /* TEAC command error flag */
  681. u_char speed_byte;
  682. int frmsiz;
  683. u_char f_XA; /* 1: XA */
  684. u_char type_byte; /* 0, 1, 3 */
  685. u_char mode_xb_6;
  686. u_char mode_yb_7;
  687. u_char mode_xb_8;
  688. u_char delay;
  689. struct cdrom_device_info *sbpcd_infop;
  690. struct gendisk *disk;
  691. } D_S[NR_SBPCD];
  692. static struct sbpcd_drive *current_drive = D_S;
  693. /*
  694. * drive space ends here (needed separate for each unit)
  695. */
  696. /*==========================================================================*/
  697. #if 0
  698. unsigned long cli_sti; /* for saving the processor flags */
  699. #endif
  700. /*==========================================================================*/
  701. static struct timer_list delay_timer =
  702. TIMER_INITIALIZER(mark_timeout_delay, 0, 0);
  703. static struct timer_list data_timer =
  704. TIMER_INITIALIZER(mark_timeout_data, 0, 0);
  705. #if 0
  706. static struct timer_list audio_timer =
  707. TIMER_INITIALIZER(mark_timeout_audio, 0, 0);
  708. #endif
  709. /*==========================================================================*/
  710. /*
  711. * DDI interface
  712. */
  713. static void msg(int level, const char *fmt, ...)
  714. {
  715. #if DISTRIBUTION
  716. #define MSG_LEVEL KERN_NOTICE
  717. #else
  718. #define MSG_LEVEL KERN_INFO
  719. #endif /* DISTRIBUTION */
  720. char buf[256];
  721. va_list args;
  722. if (!(sbpcd_debug&(1<<level))) return;
  723. msgnum++;
  724. if (msgnum>99) msgnum=0;
  725. sprintf(buf, MSG_LEVEL "%s-%d [%02d]: ", major_name, current_drive - D_S, msgnum);
  726. va_start(args, fmt);
  727. vsprintf(&buf[18], fmt, args);
  728. va_end(args);
  729. printk(buf);
  730. #if KLOGD_PAUSE
  731. sbp_sleep(KLOGD_PAUSE); /* else messages get lost */
  732. #endif /* KLOGD_PAUSE */
  733. return;
  734. }
  735. /*==========================================================================*/
  736. /*
  737. * DDI interface: runtime trace bit pattern maintenance
  738. */
  739. static int sbpcd_dbg_ioctl(unsigned long arg, int level)
  740. {
  741. switch(arg)
  742. {
  743. case 0: /* OFF */
  744. sbpcd_debug = DBG_INF;
  745. break;
  746. default:
  747. if (arg>=128) sbpcd_debug &= ~(1<<(arg-128));
  748. else sbpcd_debug |= (1<<arg);
  749. }
  750. return (arg);
  751. }
  752. /*==========================================================================*/
  753. static void mark_timeout_delay(u_long i)
  754. {
  755. timed_out_delay=1;
  756. #if 0
  757. msg(DBG_TIM,"delay timer expired.\n");
  758. #endif
  759. }
  760. /*==========================================================================*/
  761. static void mark_timeout_data(u_long i)
  762. {
  763. timed_out_data=1;
  764. #if 0
  765. msg(DBG_TIM,"data timer expired.\n");
  766. #endif
  767. }
  768. /*==========================================================================*/
  769. #if 0
  770. static void mark_timeout_audio(u_long i)
  771. {
  772. timed_out_audio=1;
  773. #if 0
  774. msg(DBG_TIM,"audio timer expired.\n");
  775. #endif
  776. }
  777. #endif
  778. /*==========================================================================*/
  779. /*
  780. * Wait a little while (used for polling the drive).
  781. */
  782. static void sbp_sleep(u_int time)
  783. {
  784. sti();
  785. current->state = TASK_INTERRUPTIBLE;
  786. schedule_timeout(time);
  787. sti();
  788. }
  789. /*==========================================================================*/
  790. #define RETURN_UP(rc) {up(&ioctl_read_sem); return(rc);}
  791. /*==========================================================================*/
  792. /*
  793. * convert logical_block_address to m-s-f_number (3 bytes only)
  794. */
  795. static INLINE void lba2msf(int lba, u_char *msf)
  796. {
  797. lba += CD_MSF_OFFSET;
  798. msf[0] = lba / (CD_SECS*CD_FRAMES);
  799. lba %= CD_SECS*CD_FRAMES;
  800. msf[1] = lba / CD_FRAMES;
  801. msf[2] = lba % CD_FRAMES;
  802. }
  803. /*==========================================================================*/
  804. /*==========================================================================*/
  805. /*
  806. * convert msf-bin to msf-bcd
  807. */
  808. static INLINE void bin2bcdx(u_char *p) /* must work only up to 75 or 99 */
  809. {
  810. *p=((*p/10)<<4)|(*p%10);
  811. }
  812. /*==========================================================================*/
  813. static INLINE u_int blk2msf(u_int blk)
  814. {
  815. MSF msf;
  816. u_int mm;
  817. msf.c[3] = 0;
  818. msf.c[2] = (blk + CD_MSF_OFFSET) / (CD_SECS * CD_FRAMES);
  819. mm = (blk + CD_MSF_OFFSET) % (CD_SECS * CD_FRAMES);
  820. msf.c[1] = mm / CD_FRAMES;
  821. msf.c[0] = mm % CD_FRAMES;
  822. return (msf.n);
  823. }
  824. /*==========================================================================*/
  825. static INLINE u_int make16(u_char rh, u_char rl)
  826. {
  827. return ((rh<<8)|rl);
  828. }
  829. /*==========================================================================*/
  830. static INLINE u_int make32(u_int rh, u_int rl)
  831. {
  832. return ((rh<<16)|rl);
  833. }
  834. /*==========================================================================*/
  835. static INLINE u_char swap_nibbles(u_char i)
  836. {
  837. return ((i<<4)|(i>>4));
  838. }
  839. /*==========================================================================*/
  840. static INLINE u_char byt2bcd(u_char i)
  841. {
  842. return (((i/10)<<4)+i%10);
  843. }
  844. /*==========================================================================*/
  845. static INLINE u_char bcd2bin(u_char bcd)
  846. {
  847. return ((bcd>>4)*10+(bcd&0x0F));
  848. }
  849. /*==========================================================================*/
  850. static INLINE int msf2blk(int msfx)
  851. {
  852. MSF msf;
  853. int i;
  854. msf.n=msfx;
  855. i=(msf.c[2] * CD_SECS + msf.c[1]) * CD_FRAMES + msf.c[0] - CD_MSF_OFFSET;
  856. if (i<0) return (0);
  857. return (i);
  858. }
  859. /*==========================================================================*/
  860. /*
  861. * convert m-s-f_number (3 bytes only) to logical_block_address
  862. */
  863. static INLINE int msf2lba(u_char *msf)
  864. {
  865. int i;
  866. i=(msf[0] * CD_SECS + msf[1]) * CD_FRAMES + msf[2] - CD_MSF_OFFSET;
  867. if (i<0) return (0);
  868. return (i);
  869. }
  870. /*==========================================================================*/
  871. /* evaluate cc_ReadError code */
  872. static int sta2err(int sta)
  873. {
  874. if (famT_drive)
  875. {
  876. if (sta==0x00) return (0);
  877. if (sta==0x01) return (-604); /* CRC error */
  878. if (sta==0x02) return (-602); /* drive not ready */
  879. if (sta==0x03) return (-607); /* unknown media */
  880. if (sta==0x04) return (-612); /* general failure */
  881. if (sta==0x05) return (0);
  882. if (sta==0x06) return (-ERR_DISKCHANGE); /* disk change */
  883. if (sta==0x0b) return (-612); /* general failure */
  884. if (sta==0xff) return (-612); /* general failure */
  885. return (0);
  886. }
  887. else
  888. {
  889. if (sta<=2) return (sta);
  890. if (sta==0x05) return (-604); /* CRC error */
  891. if (sta==0x06) return (-606); /* seek error */
  892. if (sta==0x0d) return (-606); /* seek error */
  893. if (sta==0x0e) return (-603); /* unknown command */
  894. if (sta==0x14) return (-603); /* unknown command */
  895. if (sta==0x0c) return (-611); /* read fault */
  896. if (sta==0x0f) return (-611); /* read fault */
  897. if (sta==0x10) return (-611); /* read fault */
  898. if (sta>=0x16) return (-612); /* general failure */
  899. if (sta==0x11) return (-ERR_DISKCHANGE); /* disk change (LCS: removed) */
  900. if (famL_drive)
  901. if (sta==0x12) return (-ERR_DISKCHANGE); /* disk change (inserted) */
  902. return (-602); /* drive not ready */
  903. }
  904. }
  905. /*==========================================================================*/
  906. static INLINE void clr_cmdbuf(void)
  907. {
  908. int i;
  909. for (i=0;i<10;i++) drvcmd[i]=0;
  910. cmd_type=0;
  911. }
  912. /*==========================================================================*/
  913. static void flush_status(void)
  914. {
  915. int i;
  916. sbp_sleep(15*HZ/10);
  917. for (i=maxtim_data;i!=0;i--) inb(CDi_status);
  918. }
  919. /*====================================================================*/
  920. /*
  921. * CDi status loop for Teac CD-55A (Rob Riggs)
  922. *
  923. * This is needed because for some strange reason
  924. * the CD-55A can take a real long time to give a
  925. * status response. This seems to happen after we
  926. * issue a READ command where a long seek is involved.
  927. *
  928. * I tried to ensure that we get max throughput with
  929. * minimal busy waiting. We busy wait at first, then
  930. * "switch gears" and start sleeping. We sleep for
  931. * longer periods of time the longer we wait.
  932. *
  933. */
  934. static int CDi_stat_loop_T(void)
  935. {
  936. int i, gear=1;
  937. u_long timeout_1, timeout_2, timeout_3, timeout_4;
  938. timeout_1 = jiffies + HZ / 50; /* sbp_sleep(0) for a short period */
  939. timeout_2 = jiffies + HZ / 5; /* nap for no more than 200ms */
  940. timeout_3 = jiffies + 5 * HZ; /* sleep for up to 5s */
  941. timeout_4 = jiffies + 45 * HZ; /* long sleep for up to 45s. */
  942. do
  943. {
  944. i = inb(CDi_status);
  945. if (!(i&s_not_data_ready)) return (i);
  946. if (!(i&s_not_result_ready)) return (i);
  947. switch(gear)
  948. {
  949. case 4:
  950. sbp_sleep(HZ);
  951. if (time_after(jiffies, timeout_4)) gear++;
  952. msg(DBG_TEA, "CDi_stat_loop_T: long sleep active.\n");
  953. break;
  954. case 3:
  955. sbp_sleep(HZ/10);
  956. if (time_after(jiffies, timeout_3)) gear++;
  957. break;
  958. case 2:
  959. sbp_sleep(HZ/100);
  960. if (time_after(jiffies, timeout_2)) gear++;
  961. break;
  962. case 1:
  963. sbp_sleep(0);
  964. if (time_after(jiffies, timeout_1)) gear++;
  965. }
  966. } while (gear < 5);
  967. return -1;
  968. }
  969. /*==========================================================================*/
  970. static int CDi_stat_loop(void)
  971. {
  972. int i,j;
  973. for(timeout = jiffies + 10*HZ, i=maxtim_data; time_before(jiffies, timeout); )
  974. {
  975. for ( ;i!=0;i--)
  976. {
  977. j=inb(CDi_status);
  978. if (!(j&s_not_data_ready)) return (j);
  979. if (!(j&s_not_result_ready)) return (j);
  980. if (fam0L_drive) if (j&s_attention) return (j);
  981. }
  982. sbp_sleep(1);
  983. i = 1;
  984. }
  985. msg(DBG_LCS,"CDi_stat_loop failed in line %d\n", __LINE__);
  986. return (-1);
  987. }
  988. /*==========================================================================*/
  989. #if 00000
  990. /*==========================================================================*/
  991. static int tst_DataReady(void)
  992. {
  993. int i;
  994. i=inb(CDi_status);
  995. if (i&s_not_data_ready) return (0);
  996. return (1);
  997. }
  998. /*==========================================================================*/
  999. static int tst_ResultReady(void)
  1000. {
  1001. int i;
  1002. i=inb(CDi_status);
  1003. if (i&s_not_result_ready) return (0);
  1004. return (1);
  1005. }
  1006. /*==========================================================================*/
  1007. static int tst_Attention(void)
  1008. {
  1009. int i;
  1010. i=inb(CDi_status);
  1011. if (i&s_attention) return (1);
  1012. return (0);
  1013. }
  1014. /*==========================================================================*/
  1015. #endif
  1016. /*==========================================================================*/
  1017. static int ResponseInfo(void)
  1018. {
  1019. int i,j,st=0;
  1020. u_long timeout;
  1021. for (i=0,timeout=jiffies+HZ;i<response_count;i++)
  1022. {
  1023. for (j=maxtim_data; ; )
  1024. {
  1025. for ( ;j!=0;j-- )
  1026. {
  1027. st=inb(CDi_status);
  1028. if (!(st&s_not_result_ready)) break;
  1029. }
  1030. if ((j!=0)||time_after_eq(jiffies, timeout)) break;
  1031. sbp_sleep(1);
  1032. j = 1;
  1033. }
  1034. if (time_after_eq(jiffies, timeout)) break;
  1035. infobuf[i]=inb(CDi_info);
  1036. }
  1037. #if 000
  1038. while (!(inb(CDi_status)&s_not_result_ready))
  1039. {
  1040. infobuf[i++]=inb(CDi_info);
  1041. }
  1042. j=i-response_count;
  1043. if (j>0) msg(DBG_INF,"ResponseInfo: got %d trailing bytes.\n",j);
  1044. #endif /* 000 */
  1045. for (j=0;j<i;j++)
  1046. sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1047. msgbuf[j*3]=0;
  1048. msg(DBG_CMD,"ResponseInfo:%s (%d,%d)\n",msgbuf,response_count,i);
  1049. j=response_count-i;
  1050. if (j>0) return (-j);
  1051. else return (i);
  1052. }
  1053. /*==========================================================================*/
  1054. static void EvaluateStatus(int st)
  1055. {
  1056. current_drive->status_bits=0;
  1057. if (fam1_drive) current_drive->status_bits=st|p_success;
  1058. else if (fam0_drive)
  1059. {
  1060. if (st&p_caddin_old) current_drive->status_bits |= p_door_closed|p_caddy_in;
  1061. if (st&p_spinning) current_drive->status_bits |= p_spinning;
  1062. if (st&p_check) current_drive->status_bits |= p_check;
  1063. if (st&p_success_old) current_drive->status_bits |= p_success;
  1064. if (st&p_busy_old) current_drive->status_bits |= p_busy_new;
  1065. if (st&p_disk_ok) current_drive->status_bits |= p_disk_ok;
  1066. }
  1067. else if (famLV_drive)
  1068. {
  1069. current_drive->status_bits |= p_success;
  1070. if (st&p_caddin_old) current_drive->status_bits |= p_disk_ok|p_caddy_in;
  1071. if (st&p_spinning) current_drive->status_bits |= p_spinning;
  1072. if (st&p_check) current_drive->status_bits |= p_check;
  1073. if (st&p_busy_old) current_drive->status_bits |= p_busy_new;
  1074. if (st&p_lcs_door_closed) current_drive->status_bits |= p_door_closed;
  1075. if (st&p_lcs_door_locked) current_drive->status_bits |= p_door_locked;
  1076. }
  1077. else if (fam2_drive)
  1078. {
  1079. current_drive->status_bits |= p_success;
  1080. if (st&p2_check) current_drive->status_bits |= p1_check;
  1081. if (st&p2_door_closed) current_drive->status_bits |= p1_door_closed;
  1082. if (st&p2_disk_in) current_drive->status_bits |= p1_disk_in;
  1083. if (st&p2_busy1) current_drive->status_bits |= p1_busy;
  1084. if (st&p2_busy2) current_drive->status_bits |= p1_busy;
  1085. if (st&p2_spinning) current_drive->status_bits |= p1_spinning;
  1086. if (st&p2_door_locked) current_drive->status_bits |= p1_door_locked;
  1087. if (st&p2_disk_ok) current_drive->status_bits |= p1_disk_ok;
  1088. }
  1089. else if (famT_drive)
  1090. {
  1091. return; /* still needs to get coded */
  1092. current_drive->status_bits |= p_success;
  1093. if (st&p2_check) current_drive->status_bits |= p1_check;
  1094. if (st&p2_door_closed) current_drive->status_bits |= p1_door_closed;
  1095. if (st&p2_disk_in) current_drive->status_bits |= p1_disk_in;
  1096. if (st&p2_busy1) current_drive->status_bits |= p1_busy;
  1097. if (st&p2_busy2) current_drive->status_bits |= p1_busy;
  1098. if (st&p2_spinning) current_drive->status_bits |= p1_spinning;
  1099. if (st&p2_door_locked) current_drive->status_bits |= p1_door_locked;
  1100. if (st&p2_disk_ok) current_drive->status_bits |= p1_disk_ok;
  1101. }
  1102. return;
  1103. }
  1104. /*==========================================================================*/
  1105. static int cmd_out_T(void);
  1106. static int get_state_T(void)
  1107. {
  1108. int i;
  1109. clr_cmdbuf();
  1110. current_drive->n_bytes=1;
  1111. drvcmd[0]=CMDT_STATUS;
  1112. i=cmd_out_T();
  1113. if (i>=0) i=infobuf[0];
  1114. else
  1115. {
  1116. msg(DBG_TEA,"get_state_T error %d\n", i);
  1117. return (i);
  1118. }
  1119. if (i>=0)
  1120. /* 2: closed, disk in */
  1121. current_drive->status_bits=p1_door_closed|p1_disk_in|p1_spinning|p1_disk_ok;
  1122. else if (current_drive->error_state==6)
  1123. {
  1124. /* 3: closed, disk in, changed ("06 xx xx") */
  1125. current_drive->status_bits=p1_door_closed|p1_disk_in;
  1126. current_drive->CD_changed=0xFF;
  1127. current_drive->diskstate_flags &= ~toc_bit;
  1128. }
  1129. else if ((current_drive->error_state!=2)||(current_drive->b3!=0x3A)||(current_drive->b4==0x00))
  1130. {
  1131. /* 1: closed, no disk ("xx yy zz"or "02 3A 00") */
  1132. current_drive->status_bits=p1_door_closed;
  1133. current_drive->open_count=0;
  1134. }
  1135. else if (current_drive->b4==0x01)
  1136. {
  1137. /* 0: open ("02 3A 01") */
  1138. current_drive->status_bits=0;
  1139. current_drive->open_count=0;
  1140. }
  1141. else
  1142. {
  1143. /* 1: closed, no disk ("02 3A xx") */
  1144. current_drive->status_bits=p1_door_closed;
  1145. current_drive->open_count=0;
  1146. }
  1147. return (current_drive->status_bits);
  1148. }
  1149. /*==========================================================================*/
  1150. static int ResponseStatus(void)
  1151. {
  1152. int i,j;
  1153. u_long timeout;
  1154. msg(DBG_STA,"doing ResponseStatus...\n");
  1155. if (famT_drive) return (get_state_T());
  1156. if (flags_cmd_out & f_respo3) timeout = jiffies;
  1157. else if (flags_cmd_out & f_respo2) timeout = jiffies + 16*HZ;
  1158. else timeout = jiffies + 4*HZ;
  1159. j=maxtim_8;
  1160. do
  1161. {
  1162. for ( ;j!=0;j--)
  1163. {
  1164. i=inb(CDi_status);
  1165. if (!(i&s_not_result_ready)) break;
  1166. }
  1167. if ((j!=0)||time_after(jiffies, timeout)) break;
  1168. sbp_sleep(1);
  1169. j = 1;
  1170. }
  1171. while (1);
  1172. if (j==0)
  1173. {
  1174. if ((flags_cmd_out & f_respo3) == 0)
  1175. msg(DBG_STA,"ResponseStatus: timeout.\n");
  1176. current_drive->status_bits=0;
  1177. return (-401);
  1178. }
  1179. i=inb(CDi_info);
  1180. msg(DBG_STA,"ResponseStatus: response %02X.\n", i);
  1181. EvaluateStatus(i);
  1182. msg(DBG_STA,"status_bits=%02X, i=%02X\n",current_drive->status_bits,i);
  1183. return (current_drive->status_bits);
  1184. }
  1185. /*==========================================================================*/
  1186. static void cc_ReadStatus(void)
  1187. {
  1188. int i;
  1189. msg(DBG_STA,"giving cc_ReadStatus command\n");
  1190. if (famT_drive) return;
  1191. SBPCD_CLI;
  1192. if (fam0LV_drive) OUT(CDo_command,CMD0_STATUS);
  1193. else if (fam1_drive) OUT(CDo_command,CMD1_STATUS);
  1194. else if (fam2_drive) OUT(CDo_command,CMD2_STATUS);
  1195. if (!fam0LV_drive) for (i=0;i<6;i++) OUT(CDo_command,0);
  1196. SBPCD_STI;
  1197. }
  1198. /*==========================================================================*/
  1199. static int cc_ReadError(void)
  1200. {
  1201. int i;
  1202. clr_cmdbuf();
  1203. msg(DBG_ERR,"giving cc_ReadError command.\n");
  1204. if (fam1_drive)
  1205. {
  1206. drvcmd[0]=CMD1_READ_ERR;
  1207. response_count=8;
  1208. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1209. }
  1210. else if (fam0LV_drive)
  1211. {
  1212. drvcmd[0]=CMD0_READ_ERR;
  1213. response_count=6;
  1214. if (famLV_drive)
  1215. flags_cmd_out=f_putcmd;
  1216. else
  1217. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus;
  1218. }
  1219. else if (fam2_drive)
  1220. {
  1221. drvcmd[0]=CMD2_READ_ERR;
  1222. response_count=6;
  1223. flags_cmd_out=f_putcmd;
  1224. }
  1225. else if (famT_drive)
  1226. {
  1227. response_count=5;
  1228. drvcmd[0]=CMDT_READ_ERR;
  1229. }
  1230. i=cmd_out();
  1231. current_drive->error_byte=0;
  1232. msg(DBG_ERR,"cc_ReadError: cmd_out(CMDx_READ_ERR) returns %d (%02X)\n",i,i);
  1233. if (i<0) return (i);
  1234. if (fam0V_drive) i=1;
  1235. else i=2;
  1236. current_drive->error_byte=infobuf[i];
  1237. msg(DBG_ERR,"cc_ReadError: infobuf[%d] is %d (%02X)\n",i,current_drive->error_byte,current_drive->error_byte);
  1238. i=sta2err(infobuf[i]);
  1239. if (i==-ERR_DISKCHANGE)
  1240. {
  1241. current_drive->CD_changed=0xFF;
  1242. current_drive->diskstate_flags &= ~toc_bit;
  1243. }
  1244. return (i);
  1245. }
  1246. /*==========================================================================*/
  1247. static int cc_DriveReset(void);
  1248. static int cmd_out_T(void)
  1249. {
  1250. #undef CMDT_TRIES
  1251. #define CMDT_TRIES 1000
  1252. #define TEST_FALSE_FF 1
  1253. int i, j, l=0, m, ntries;
  1254. unsigned long flags;
  1255. current_drive->error_state=0;
  1256. current_drive->b3=0;
  1257. current_drive->b4=0;
  1258. current_drive->f_drv_error=0;
  1259. for (i=0;i<10;i++) sprintf(&msgbuf[i*3]," %02X",drvcmd[i]);
  1260. msgbuf[i*3]=0;
  1261. msg(DBG_CMD,"cmd_out_T:%s\n",msgbuf);
  1262. OUT(CDo_sel_i_d,0);
  1263. OUT(CDo_enable,current_drive->drv_sel);
  1264. i=inb(CDi_status);
  1265. do_16bit=0;
  1266. if ((f_16bit)&&(!(i&0x80)))
  1267. {
  1268. do_16bit=1;
  1269. msg(DBG_TEA,"cmd_out_T: do_16bit set.\n");
  1270. }
  1271. if (!(i&s_not_result_ready))
  1272. do
  1273. {
  1274. j=inb(CDi_info);
  1275. i=inb(CDi_status);
  1276. sbp_sleep(0);
  1277. msg(DBG_TEA,"cmd_out_T: spurious !s_not_result_ready. (%02X)\n", j);
  1278. }
  1279. while (!(i&s_not_result_ready));
  1280. save_flags(flags); cli();
  1281. for (i=0;i<10;i++) OUT(CDo_command,drvcmd[i]);
  1282. restore_flags(flags);
  1283. for (ntries=CMDT_TRIES;ntries>0;ntries--)
  1284. {
  1285. if (drvcmd[0]==CMDT_READ_VER) sbp_sleep(HZ); /* fixme */
  1286. #if 01
  1287. OUT(CDo_sel_i_d,1);
  1288. #endif /* 01 */
  1289. if (teac==2)
  1290. {
  1291. if ((i=CDi_stat_loop_T()) == -1) break;
  1292. }
  1293. else
  1294. {
  1295. #if 0
  1296. OUT(CDo_sel_i_d,1);
  1297. #endif /* 0 */
  1298. i=inb(CDi_status);
  1299. }
  1300. if (!(i&s_not_data_ready)) /* f.e. CMDT_DISKINFO */
  1301. {
  1302. OUT(CDo_sel_i_d,1);
  1303. if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  1304. if (drvcmd[0]==CMDT_DISKINFO)
  1305. {
  1306. l=0;
  1307. do
  1308. {
  1309. if (do_16bit)
  1310. {
  1311. i=inw(CDi_data);
  1312. infobuf[l++]=i&0x0ff;
  1313. infobuf[l++]=i>>8;
  1314. #if TEST_FALSE_FF
  1315. if ((l==2)&&(infobuf[0]==0x0ff))
  1316. {
  1317. infobuf[0]=infobuf[1];
  1318. l=1;
  1319. msg(DBG_TEA,"cmd_out_T: do_16bit: false first byte!\n");
  1320. }
  1321. #endif /* TEST_FALSE_FF */
  1322. }
  1323. else infobuf[l++]=inb(CDi_data);
  1324. i=inb(CDi_status);
  1325. }
  1326. while (!(i&s_not_data_ready));
  1327. for (j=0;j<l;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1328. msgbuf[j*3]=0;
  1329. msg(DBG_CMD,"cmd_out_T data response:%s\n", msgbuf);
  1330. }
  1331. else
  1332. {
  1333. msg(DBG_TEA,"cmd_out_T: data response with cmd_%02X!\n",
  1334. drvcmd[0]);
  1335. j=0;
  1336. do
  1337. {
  1338. if (do_16bit) i=inw(CDi_data);
  1339. else i=inb(CDi_data);
  1340. j++;
  1341. i=inb(CDi_status);
  1342. }
  1343. while (!(i&s_not_data_ready));
  1344. msg(DBG_TEA,"cmd_out_T: data response: discarded %d bytes/words.\n", j);
  1345. fatal_err++;
  1346. }
  1347. }
  1348. i=inb(CDi_status);
  1349. if (!(i&s_not_result_ready))
  1350. {
  1351. OUT(CDo_sel_i_d,0);
  1352. if (drvcmd[0]==CMDT_DISKINFO) m=l;
  1353. else m=0;
  1354. do
  1355. {
  1356. infobuf[m++]=inb(CDi_info);
  1357. i=inb(CDi_status);
  1358. }
  1359. while (!(i&s_not_result_ready));
  1360. for (j=0;j<m;j++) sprintf(&msgbuf[j*3]," %02X",infobuf[j]);
  1361. msgbuf[j*3]=0;
  1362. msg(DBG_CMD,"cmd_out_T info response:%s\n", msgbuf);
  1363. if (drvcmd[0]==CMDT_DISKINFO)
  1364. {
  1365. infobuf[0]=infobuf[l];
  1366. if (infobuf[0]!=0x02) return (l); /* data length */
  1367. }
  1368. else if (infobuf[0]!=0x02) return (m); /* info length */
  1369. do
  1370. {
  1371. ++recursion;
  1372. if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (%02X): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", drvcmd[0], recursion);
  1373. clr_cmdbuf();
  1374. drvcmd[0]=CMDT_READ_ERR;
  1375. j=cmd_out_T(); /* !!! recursive here !!! */
  1376. --recursion;
  1377. sbp_sleep(1);
  1378. }
  1379. while (j<0);
  1380. current_drive->error_state=infobuf[2];
  1381. current_drive->b3=infobuf[3];
  1382. current_drive->b4=infobuf[4];
  1383. if (current_drive->f_drv_error)
  1384. {
  1385. current_drive->f_drv_error=0;
  1386. cc_DriveReset();
  1387. current_drive->error_state=2;
  1388. }
  1389. return (-current_drive->error_state-400);
  1390. }
  1391. if (drvcmd[0]==CMDT_READ) return (0); /* handled elsewhere */
  1392. if ((teac==0)||(ntries<(CMDT_TRIES-5))) sbp_sleep(HZ/10);
  1393. else sbp_sleep(HZ/100);
  1394. if (ntries>(CMDT_TRIES-50)) continue;
  1395. msg(DBG_TEA,"cmd_out_T: next CMDT_TRIES (%02X): %d.\n", drvcmd[0], ntries-1);
  1396. }
  1397. current_drive->f_drv_error=1;
  1398. cc_DriveReset();
  1399. current_drive->error_state=2;
  1400. return (-99);
  1401. }
  1402. /*==========================================================================*/
  1403. static int cmd_out(void)
  1404. {
  1405. int i=0;
  1406. if (famT_drive) return(cmd_out_T());
  1407. if (flags_cmd_out&f_putcmd)
  1408. {
  1409. unsigned long flags;
  1410. for (i=0;i<7;i++)
  1411. sprintf(&msgbuf[i*3], " %02X", drvcmd[i]);
  1412. msgbuf[i*3]=0;
  1413. msg(DBG_CMD,"cmd_out:%s\n", msgbuf);
  1414. save_flags(flags); cli();
  1415. for (i=0;i<7;i++) OUT(CDo_command,drvcmd[i]);
  1416. restore_flags(flags);
  1417. }
  1418. if (response_count!=0)
  1419. {
  1420. if (cmd_type!=0)
  1421. {
  1422. if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  1423. msg(DBG_INF,"misleaded to try ResponseData.\n");
  1424. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  1425. return (-22);
  1426. }
  1427. else i=ResponseInfo();
  1428. if (i<0) return (i);
  1429. }
  1430. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to CDi_stat_loop.\n");
  1431. if (flags_cmd_out&f_lopsta)
  1432. {
  1433. i=CDi_stat_loop();
  1434. if ((i<0)||!(i&s_attention)) return (-8);
  1435. }
  1436. if (!(flags_cmd_out&f_getsta)) goto LOC_229;
  1437. LOC_228:
  1438. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadStatus.\n");
  1439. cc_ReadStatus();
  1440. LOC_229:
  1441. if (flags_cmd_out&f_ResponseStatus)
  1442. {
  1443. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to ResponseStatus.\n");
  1444. i=ResponseStatus();
  1445. /* builds status_bits, returns orig. status or p_busy_new */
  1446. if (i<0) return (i);
  1447. if (flags_cmd_out&(f_bit1|f_wait_if_busy))
  1448. {
  1449. if (!st_check)
  1450. {
  1451. if ((flags_cmd_out&f_bit1)&&(i&p_success)) goto LOC_232;
  1452. if ((!(flags_cmd_out&f_wait_if_busy))||(!st_busy)) goto LOC_228;
  1453. }
  1454. }
  1455. }
  1456. LOC_232:
  1457. if (!(flags_cmd_out&f_obey_p_check)) return (0);
  1458. if (!st_check) return (0);
  1459. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cc_ReadError.\n");
  1460. i=cc_ReadError();
  1461. if (current_drive->in_SpinUp) msg(DBG_SPI,"in_SpinUp: to cmd_out OK.\n");
  1462. msg(DBG_000,"cmd_out: cc_ReadError=%d\n", i);
  1463. return (i);
  1464. }
  1465. /*==========================================================================*/
  1466. static int cc_Seek(u_int pos, char f_blk_msf)
  1467. {
  1468. int i;
  1469. clr_cmdbuf();
  1470. if (f_blk_msf>1) return (-3);
  1471. if (fam0V_drive)
  1472. {
  1473. drvcmd[0]=CMD0_SEEK;
  1474. if (f_blk_msf==1) pos=msf2blk(pos);
  1475. drvcmd[2]=(pos>>16)&0x00FF;
  1476. drvcmd[3]=(pos>>8)&0x00FF;
  1477. drvcmd[4]=pos&0x00FF;
  1478. if (fam0_drive)
  1479. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  1480. f_ResponseStatus | f_obey_p_check | f_bit1;
  1481. else
  1482. flags_cmd_out = f_putcmd;
  1483. }
  1484. else if (fam1L_drive)
  1485. {
  1486. drvcmd[0]=CMD1_SEEK; /* same as CMD1_ and CMDL_ */
  1487. if (f_blk_msf==0) pos=blk2msf(pos);
  1488. drvcmd[1]=(pos>>16)&0x00FF;
  1489. drvcmd[2]=(pos>>8)&0x00FF;
  1490. drvcmd[3]=pos&0x00FF;
  1491. if (famL_drive)
  1492. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1493. else
  1494. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1495. }
  1496. else if (fam2_drive)
  1497. {
  1498. drvcmd[0]=CMD2_SEEK;
  1499. if (f_blk_msf==0) pos=blk2msf(pos);
  1500. drvcmd[2]=(pos>>24)&0x00FF;
  1501. drvcmd[3]=(pos>>16)&0x00FF;
  1502. drvcmd[4]=(pos>>8)&0x00FF;
  1503. drvcmd[5]=pos&0x00FF;
  1504. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1505. }
  1506. else if (famT_drive)
  1507. {
  1508. drvcmd[0]=CMDT_SEEK;
  1509. if (f_blk_msf==1) pos=msf2blk(pos);
  1510. drvcmd[2]=(pos>>24)&0x00FF;
  1511. drvcmd[3]=(pos>>16)&0x00FF;
  1512. drvcmd[4]=(pos>>8)&0x00FF;
  1513. drvcmd[5]=pos&0x00FF;
  1514. current_drive->n_bytes=1;
  1515. }
  1516. response_count=0;
  1517. i=cmd_out();
  1518. return (i);
  1519. }
  1520. /*==========================================================================*/
  1521. static int cc_SpinUp(void)
  1522. {
  1523. int i;
  1524. msg(DBG_SPI,"SpinUp.\n");
  1525. current_drive->in_SpinUp = 1;
  1526. clr_cmdbuf();
  1527. if (fam0LV_drive)
  1528. {
  1529. drvcmd[0]=CMD0_SPINUP;
  1530. if (fam0L_drive)
  1531. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  1532. f_ResponseStatus|f_obey_p_check|f_bit1;
  1533. else
  1534. flags_cmd_out=f_putcmd;
  1535. }
  1536. else if (fam1_drive)
  1537. {
  1538. drvcmd[0]=CMD1_SPINUP;
  1539. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1540. }
  1541. else if (fam2_drive)
  1542. {
  1543. drvcmd[0]=CMD2_TRAY_CTL;
  1544. drvcmd[4]=0x01; /* "spinup" */
  1545. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1546. }
  1547. else if (famT_drive)
  1548. {
  1549. drvcmd[0]=CMDT_TRAY_CTL;
  1550. drvcmd[4]=0x03; /* "insert", it hopefully spins the drive up */
  1551. }
  1552. response_count=0;
  1553. i=cmd_out();
  1554. current_drive->in_SpinUp = 0;
  1555. return (i);
  1556. }
  1557. /*==========================================================================*/
  1558. static int cc_SpinDown(void)
  1559. {
  1560. int i;
  1561. if (fam0_drive) return (0);
  1562. clr_cmdbuf();
  1563. response_count=0;
  1564. if (fam1_drive)
  1565. {
  1566. drvcmd[0]=CMD1_SPINDOWN;
  1567. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  1568. }
  1569. else if (fam2_drive)
  1570. {
  1571. drvcmd[0]=CMD2_TRAY_CTL;
  1572. drvcmd[4]=0x02; /* "eject" */
  1573. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1574. }
  1575. else if (famL_drive)
  1576. {
  1577. drvcmd[0]=CMDL_SPINDOWN;
  1578. drvcmd[1]=1;
  1579. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1580. }
  1581. else if (famV_drive)
  1582. {
  1583. drvcmd[0]=CMDV_SPINDOWN;
  1584. flags_cmd_out=f_putcmd;
  1585. }
  1586. else if (famT_drive)
  1587. {
  1588. drvcmd[0]=CMDT_TRAY_CTL;
  1589. drvcmd[4]=0x02; /* "eject" */
  1590. }
  1591. i=cmd_out();
  1592. return (i);
  1593. }
  1594. /*==========================================================================*/
  1595. static int cc_get_mode_T(void)
  1596. {
  1597. int i;
  1598. clr_cmdbuf();
  1599. response_count=10;
  1600. drvcmd[0]=CMDT_GETMODE;
  1601. drvcmd[4]=response_count;
  1602. i=cmd_out_T();
  1603. return (i);
  1604. }
  1605. /*==========================================================================*/
  1606. static int cc_set_mode_T(void)
  1607. {
  1608. int i;
  1609. clr_cmdbuf();
  1610. response_count=1;
  1611. drvcmd[0]=CMDT_SETMODE;
  1612. drvcmd[1]=current_drive->speed_byte;
  1613. drvcmd[2]=current_drive->frmsiz>>8;
  1614. drvcmd[3]=current_drive->frmsiz&0x0FF;
  1615. drvcmd[4]=current_drive->f_XA; /* 1: XA */
  1616. drvcmd[5]=current_drive->type_byte; /* 0, 1, 3 */
  1617. drvcmd[6]=current_drive->mode_xb_6;
  1618. drvcmd[7]=current_drive->mode_yb_7|current_drive->volume_control;
  1619. drvcmd[8]=current_drive->mode_xb_8;
  1620. drvcmd[9]=current_drive->delay;
  1621. i=cmd_out_T();
  1622. return (i);
  1623. }
  1624. /*==========================================================================*/
  1625. static int cc_prep_mode_T(void)
  1626. {
  1627. int i, j;
  1628. i=cc_get_mode_T();
  1629. if (i<0) return (i);
  1630. for (i=0;i<10;i++)
  1631. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  1632. msgbuf[i*3]=0;
  1633. msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  1634. current_drive->speed_byte=0x02; /* 0x02: auto quad, 0x82: quad, 0x81: double, 0x80: single */
  1635. current_drive->frmsiz=make16(infobuf[2],infobuf[3]);
  1636. current_drive->f_XA=infobuf[4];
  1637. if (current_drive->f_XA==0) current_drive->type_byte=0;
  1638. else current_drive->type_byte=1;
  1639. current_drive->mode_xb_6=infobuf[6];
  1640. current_drive->mode_yb_7=1;
  1641. current_drive->mode_xb_8=infobuf[8];
  1642. current_drive->delay=0; /* 0, 1, 2, 3 */
  1643. j=cc_set_mode_T();
  1644. i=cc_get_mode_T();
  1645. for (i=0;i<10;i++)
  1646. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  1647. msgbuf[i*3]=0;
  1648. msg(DBG_TEA,"CMDT_GETMODE:%s\n", msgbuf);
  1649. return (j);
  1650. }
  1651. /*==========================================================================*/
  1652. static int cc_SetSpeed(u_char speed, u_char x1, u_char x2)
  1653. {
  1654. int i;
  1655. if (fam0LV_drive) return (0);
  1656. clr_cmdbuf();
  1657. response_count=0;
  1658. if (fam1_drive)
  1659. {
  1660. drvcmd[0]=CMD1_SETMODE;
  1661. drvcmd[1]=0x03;
  1662. drvcmd[2]=speed;
  1663. drvcmd[3]=x1;
  1664. drvcmd[4]=x2;
  1665. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1666. }
  1667. else if (fam2_drive)
  1668. {
  1669. drvcmd[0]=CMD2_SETSPEED;
  1670. if (speed&speed_auto)
  1671. {
  1672. drvcmd[2]=0xFF;
  1673. drvcmd[3]=0xFF;
  1674. }
  1675. else
  1676. {
  1677. drvcmd[2]=0;
  1678. drvcmd[3]=150;
  1679. }
  1680. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1681. }
  1682. else if (famT_drive)
  1683. {
  1684. return (0);
  1685. }
  1686. i=cmd_out();
  1687. return (i);
  1688. }
  1689. /*==========================================================================*/
  1690. static int cc_SetVolume(void)
  1691. {
  1692. int i;
  1693. u_char channel0,channel1,volume0,volume1;
  1694. u_char control0,value0,control1,value1;
  1695. current_drive->diskstate_flags &= ~volume_bit;
  1696. clr_cmdbuf();
  1697. channel0=current_drive->vol_chan0;
  1698. volume0=current_drive->vol_ctrl0;
  1699. channel1=control1=current_drive->vol_chan1;
  1700. volume1=value1=current_drive->vol_ctrl1;
  1701. control0=value0=0;
  1702. if (famV_drive) return (0);
  1703. if (((current_drive->drv_options&audio_mono)!=0)&&(current_drive->drv_type>=drv_211))
  1704. {
  1705. if ((volume0!=0)&&(volume1==0))
  1706. {
  1707. volume1=volume0;
  1708. channel1=channel0;
  1709. }
  1710. else if ((volume0==0)&&(volume1!=0))
  1711. {
  1712. volume0=volume1;
  1713. channel0=channel1;
  1714. }
  1715. }
  1716. if (channel0>1)
  1717. {
  1718. channel0=0;
  1719. volume0=0;
  1720. }
  1721. if (channel1>1)
  1722. {
  1723. channel1=1;
  1724. volume1=0;
  1725. }
  1726. if (fam1_drive)
  1727. {
  1728. control0=channel0+1;
  1729. control1=channel1+1;
  1730. value0=(volume0>volume1)?volume0:volume1;
  1731. value1=value0;
  1732. if (volume0==0) control0=0;
  1733. if (volume1==0) control1=0;
  1734. drvcmd[0]=CMD1_SETMODE;
  1735. drvcmd[1]=0x05;
  1736. drvcmd[3]=control0;
  1737. drvcmd[4]=value0;
  1738. drvcmd[5]=control1;
  1739. drvcmd[6]=value1;
  1740. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  1741. }
  1742. else if (fam2_drive)
  1743. {
  1744. control0=channel0+1;
  1745. control1=channel1+1;
  1746. value0=(volume0>volume1)?volume0:volume1;
  1747. value1=value0;
  1748. if (volume0==0) control0=0;
  1749. if (volume1==0) control1=0;
  1750. drvcmd[0]=CMD2_SETMODE;
  1751. drvcmd[1]=0x0E;
  1752. drvcmd[3]=control0;
  1753. drvcmd[4]=value0;
  1754. drvcmd[5]=control1;
  1755. drvcmd[6]=value1;
  1756. flags_cmd_out=f_putcmd|f_ResponseStatus;
  1757. }
  1758. else if (famL_drive)
  1759. {
  1760. if ((volume0==0)||(channel0!=0)) control0 |= 0x80;
  1761. if ((volume1==0)||(channel1!=1)) control0 |= 0x40;
  1762. if (volume0|volume1) value0=0x80;
  1763. drvcmd[0]=CMDL_SETMODE;
  1764. drvcmd[1]=0x03;
  1765. drvcmd[4]=control0;
  1766. drvcmd[5]=value0;
  1767. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  1768. }
  1769. else if (fam0_drive) /* different firmware levels */
  1770. {
  1771. if (current_drive->drv_type>=drv_300)
  1772. {
  1773. control0=volume0&0xFC;
  1774. value0=volume1&0xFC;
  1775. if ((volume0!=0)&&(volume0<4)) control0 |= 0x04;
  1776. if ((volume1!=0)&&(volume1<4)) value0 |= 0x04;
  1777. if (channel0!=0) control0 |= 0x01;
  1778. if (channel1==1) value0 |= 0x01;
  1779. }
  1780. else
  1781. {
  1782. value0=(volume0>volume1)?volume0:volume1;
  1783. if (current_drive->drv_type<drv_211)
  1784. {
  1785. if (channel0!=0)
  1786. {
  1787. i=channel1;
  1788. channel1=channel0;
  1789. channel0=i;
  1790. i=volume1;
  1791. volume1=volume0;
  1792. volume0=i;
  1793. }
  1794. if (channel0==channel1)
  1795. {
  1796. if (channel0==0)
  1797. {
  1798. channel1=1;
  1799. volume1=0;
  1800. volume0=value0;
  1801. }
  1802. else
  1803. {
  1804. channel0=0;
  1805. volume0=0;
  1806. volume1=value0;
  1807. }
  1808. }
  1809. }
  1810. if ((volume0!=0)&&(volume1!=0))
  1811. {
  1812. if (volume0==0xFF) volume1=0xFF;
  1813. else if (volume1==0xFF) volume0=0xFF;
  1814. }
  1815. else if (current_drive->drv_type<drv_201) volume0=volume1=value0;
  1816. if (current_drive->drv_type>=drv_201)
  1817. {
  1818. if (volume0==0) control0 |= 0x80;
  1819. if (volume1==0) control0 |= 0x40;
  1820. }
  1821. if (current_drive->drv_type>=drv_211)
  1822. {
  1823. if (channel0!=0) control0 |= 0x20;
  1824. if (channel1!=1) control0 |= 0x10;
  1825. }
  1826. }
  1827. drvcmd[0]=CMD0_SETMODE;
  1828. drvcmd[1]=0x83;
  1829. drvcmd[4]=control0;
  1830. drvcmd[5]=value0;
  1831. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  1832. }
  1833. else if (famT_drive)
  1834. {
  1835. current_drive->volume_control=0;
  1836. if (!volume0) current_drive->volume_control|=0x10;
  1837. if (!volume1) current_drive->volume_control|=0x20;
  1838. i=cc_prep_mode_T();
  1839. if (i<0) return (i);
  1840. }
  1841. if (!famT_drive)
  1842. {
  1843. response_count=0;
  1844. i=cmd_out();
  1845. if (i<0) return (i);
  1846. }
  1847. current_drive->diskstate_flags |= volume_bit;
  1848. return (0);
  1849. }
  1850. /*==========================================================================*/
  1851. static int GetStatus(void)
  1852. {
  1853. int i;
  1854. if (famT_drive) return (0);
  1855. flags_cmd_out=f_getsta|f_ResponseStatus|f_obey_p_check;
  1856. response_count=0;
  1857. cmd_type=0;
  1858. i=cmd_out();
  1859. return (i);
  1860. }
  1861. /*==========================================================================*/
  1862. static int cc_DriveReset(void)
  1863. {
  1864. int i;
  1865. msg(DBG_RES,"cc_DriveReset called.\n");
  1866. clr_cmdbuf();
  1867. response_count=0;
  1868. if (fam0LV_drive) OUT(CDo_reset,0x00);
  1869. else if (fam1_drive)
  1870. {
  1871. drvcmd[0]=CMD1_RESET;
  1872. flags_cmd_out=f_putcmd;
  1873. i=cmd_out();
  1874. }
  1875. else if (fam2_drive)
  1876. {
  1877. drvcmd[0]=CMD2_RESET;
  1878. flags_cmd_out=f_putcmd;
  1879. i=cmd_out();
  1880. OUT(CDo_reset,0x00);
  1881. }
  1882. else if (famT_drive)
  1883. {
  1884. OUT(CDo_sel_i_d,0);
  1885. OUT(CDo_enable,current_drive->drv_sel);
  1886. OUT(CDo_command,CMDT_RESET);
  1887. for (i=1;i<10;i++) OUT(CDo_command,0);
  1888. }
  1889. if (fam0LV_drive) sbp_sleep(5*HZ); /* wait 5 seconds */
  1890. else sbp_sleep(1*HZ); /* wait a second */
  1891. #if 1
  1892. if (famT_drive)
  1893. {
  1894. msg(DBG_TEA, "================CMDT_RESET given=================.\n");
  1895. sbp_sleep(3*HZ);
  1896. }
  1897. #endif /* 1 */
  1898. flush_status();
  1899. i=GetStatus();
  1900. if (i<0) return i;
  1901. if (!famT_drive)
  1902. if (current_drive->error_byte!=aud_12) return -501;
  1903. return (0);
  1904. }
  1905. /*==========================================================================*/
  1906. static int SetSpeed(void)
  1907. {
  1908. int i, speed;
  1909. if (!(current_drive->drv_options&(speed_auto|speed_300|speed_150))) return (0);
  1910. speed=speed_auto;
  1911. if (!(current_drive->drv_options&speed_auto))
  1912. {
  1913. speed |= speed_300;
  1914. if (!(current_drive->drv_options&speed_300)) speed=0;
  1915. }
  1916. i=cc_SetSpeed(speed,0,0);
  1917. return (i);
  1918. }
  1919. static void switch_drive(struct sbpcd_drive *);
  1920. static int sbpcd_select_speed(struct cdrom_device_info *cdi, int speed)
  1921. {
  1922. struct sbpcd_drive *p = cdi->handle;
  1923. if (p != current_drive)
  1924. switch_drive(p);
  1925. return cc_SetSpeed(speed == 2 ? speed_300 : speed_150, 0, 0);
  1926. }
  1927. /*==========================================================================*/
  1928. static int DriveReset(void)
  1929. {
  1930. int i;
  1931. i=cc_DriveReset();
  1932. if (i<0) return (-22);
  1933. do
  1934. {
  1935. i=GetStatus();
  1936. if ((i<0)&&(i!=-ERR_DISKCHANGE)) {
  1937. return (-2); /* from sta2err */
  1938. }
  1939. if (!st_caddy_in) break;
  1940. sbp_sleep(1);
  1941. }
  1942. while (!st_diskok);
  1943. #if 000
  1944. current_drive->CD_changed=1;
  1945. #endif
  1946. if ((st_door_closed) && (st_caddy_in))
  1947. {
  1948. i=DiskInfo();
  1949. if (i<0) return (-23);
  1950. }
  1951. return (0);
  1952. }
  1953. static int sbpcd_reset(struct cdrom_device_info *cdi)
  1954. {
  1955. struct sbpcd_drive *p = cdi->handle;
  1956. if (p != current_drive)
  1957. switch_drive(p);
  1958. return DriveReset();
  1959. }
  1960. /*==========================================================================*/
  1961. static int cc_PlayAudio(int pos_audio_start,int pos_audio_end)
  1962. {
  1963. int i, j, n;
  1964. if (current_drive->audio_state==audio_playing) return (-EINVAL);
  1965. clr_cmdbuf();
  1966. response_count=0;
  1967. if (famLV_drive)
  1968. {
  1969. drvcmd[0]=CMDL_PLAY;
  1970. i=msf2blk(pos_audio_start);
  1971. n=msf2blk(pos_audio_end)+1-i;
  1972. drvcmd[1]=(i>>16)&0x00FF;
  1973. drvcmd[2]=(i>>8)&0x00FF;
  1974. drvcmd[3]=i&0x00FF;
  1975. drvcmd[4]=(n>>16)&0x00FF;
  1976. drvcmd[5]=(n>>8)&0x00FF;
  1977. drvcmd[6]=n&0x00FF;
  1978. if (famL_drive)
  1979. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  1980. f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  1981. else
  1982. flags_cmd_out = f_putcmd;
  1983. }
  1984. else
  1985. {
  1986. j=1;
  1987. if (fam1_drive)
  1988. {
  1989. drvcmd[0]=CMD1_PLAY_MSF;
  1990. flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus |
  1991. f_obey_p_check | f_wait_if_busy;
  1992. }
  1993. else if (fam2_drive)
  1994. {
  1995. drvcmd[0]=CMD2_PLAY_MSF;
  1996. flags_cmd_out = f_putcmd | f_ResponseStatus | f_obey_p_check;
  1997. }
  1998. else if (famT_drive)
  1999. {
  2000. drvcmd[0]=CMDT_PLAY_MSF;
  2001. j=3;
  2002. response_count=1;
  2003. }
  2004. else if (fam0_drive)
  2005. {
  2006. drvcmd[0]=CMD0_PLAY_MSF;
  2007. flags_cmd_out = f_putcmd | f_respo2 | f_lopsta | f_getsta |
  2008. f_ResponseStatus | f_obey_p_check | f_wait_if_busy;
  2009. }
  2010. drvcmd[j]=(pos_audio_start>>16)&0x00FF;
  2011. drvcmd[j+1]=(pos_audio_start>>8)&0x00FF;
  2012. drvcmd[j+2]=pos_audio_start&0x00FF;
  2013. drvcmd[j+3]=(pos_audio_end>>16)&0x00FF;
  2014. drvcmd[j+4]=(pos_audio_end>>8)&0x00FF;
  2015. drvcmd[j+5]=pos_audio_end&0x00FF;
  2016. }
  2017. i=cmd_out();
  2018. return (i);
  2019. }
  2020. /*==========================================================================*/
  2021. static int cc_Pause_Resume(int pau_res)
  2022. {
  2023. int i;
  2024. clr_cmdbuf();
  2025. response_count=0;
  2026. if (fam1_drive)
  2027. {
  2028. drvcmd[0]=CMD1_PAU_RES;
  2029. if (pau_res!=1) drvcmd[1]=0x80;
  2030. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2031. }
  2032. else if (fam2_drive)
  2033. {
  2034. drvcmd[0]=CMD2_PAU_RES;
  2035. if (pau_res!=1) drvcmd[2]=0x01;
  2036. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2037. }
  2038. else if (fam0LV_drive)
  2039. {
  2040. drvcmd[0]=CMD0_PAU_RES;
  2041. if (pau_res!=1) drvcmd[1]=0x80;
  2042. if (famL_drive)
  2043. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  2044. f_obey_p_check|f_bit1;
  2045. else if (famV_drive)
  2046. flags_cmd_out=f_putcmd;
  2047. else
  2048. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|
  2049. f_obey_p_check;
  2050. }
  2051. else if (famT_drive)
  2052. {
  2053. if (pau_res==3) return (cc_PlayAudio(current_drive->pos_audio_start,current_drive->pos_audio_end));
  2054. else if (pau_res==1) drvcmd[0]=CMDT_PAUSE;
  2055. else return (-56);
  2056. }
  2057. i=cmd_out();
  2058. return (i);
  2059. }
  2060. /*==========================================================================*/
  2061. static int cc_LockDoor(char lock)
  2062. {
  2063. int i;
  2064. if (fam0_drive) return (0);
  2065. msg(DBG_LCK,"cc_LockDoor: %d (drive %d)\n", lock, current_drive - D_S);
  2066. msg(DBG_LCS,"p_door_locked bit %d before\n", st_door_locked);
  2067. clr_cmdbuf();
  2068. response_count=0;
  2069. if (fam1_drive)
  2070. {
  2071. drvcmd[0]=CMD1_LOCK_CTL;
  2072. if (lock==1) drvcmd[1]=0x01;
  2073. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2074. }
  2075. else if (fam2_drive)
  2076. {
  2077. drvcmd[0]=CMD2_LOCK_CTL;
  2078. if (lock==1) drvcmd[4]=0x01;
  2079. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2080. }
  2081. else if (famLV_drive)
  2082. {
  2083. drvcmd[0]=CMDL_LOCK_CTL;
  2084. if (lock==1) drvcmd[1]=0x01;
  2085. if (famL_drive)
  2086. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2087. else
  2088. flags_cmd_out=f_putcmd;
  2089. }
  2090. else if (famT_drive)
  2091. {
  2092. drvcmd[0]=CMDT_LOCK_CTL;
  2093. if (lock==1) drvcmd[4]=0x01;
  2094. }
  2095. i=cmd_out();
  2096. msg(DBG_LCS,"p_door_locked bit %d after\n", st_door_locked);
  2097. return (i);
  2098. }
  2099. /*==========================================================================*/
  2100. /*==========================================================================*/
  2101. static int UnLockDoor(void)
  2102. {
  2103. int i,j;
  2104. j=20;
  2105. do
  2106. {
  2107. i=cc_LockDoor(0);
  2108. --j;
  2109. sbp_sleep(1);
  2110. }
  2111. while ((i<0)&&(j));
  2112. if (i<0)
  2113. {
  2114. cc_DriveReset();
  2115. return -84;
  2116. }
  2117. return (0);
  2118. }
  2119. /*==========================================================================*/
  2120. static int LockDoor(void)
  2121. {
  2122. int i,j;
  2123. j=20;
  2124. do
  2125. {
  2126. i=cc_LockDoor(1);
  2127. --j;
  2128. sbp_sleep(1);
  2129. }
  2130. while ((i<0)&&(j));
  2131. if (j==0)
  2132. {
  2133. cc_DriveReset();
  2134. j=20;
  2135. do
  2136. {
  2137. i=cc_LockDoor(1);
  2138. --j;
  2139. sbp_sleep(1);
  2140. }
  2141. while ((i<0)&&(j));
  2142. }
  2143. return (i);
  2144. }
  2145. static int sbpcd_lock_door(struct cdrom_device_info *cdi, int lock)
  2146. {
  2147. return lock ? LockDoor() : UnLockDoor();
  2148. }
  2149. /*==========================================================================*/
  2150. static int cc_CloseTray(void)
  2151. {
  2152. int i;
  2153. if (fam0_drive) return (0);
  2154. msg(DBG_LCK,"cc_CloseTray (drive %d)\n", current_drive - D_S);
  2155. msg(DBG_LCS,"p_door_closed bit %d before\n", st_door_closed);
  2156. clr_cmdbuf();
  2157. response_count=0;
  2158. if (fam1_drive)
  2159. {
  2160. drvcmd[0]=CMD1_TRAY_CTL;
  2161. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  2162. }
  2163. else if (fam2_drive)
  2164. {
  2165. drvcmd[0]=CMD2_TRAY_CTL;
  2166. drvcmd[1]=0x01;
  2167. drvcmd[4]=0x03; /* "insert" */
  2168. flags_cmd_out=f_putcmd|f_ResponseStatus;
  2169. }
  2170. else if (famLV_drive)
  2171. {
  2172. drvcmd[0]=CMDL_TRAY_CTL;
  2173. if (famLV_drive)
  2174. flags_cmd_out=f_putcmd|f_respo2|f_lopsta|f_getsta|
  2175. f_ResponseStatus|f_obey_p_check|f_bit1;
  2176. else
  2177. flags_cmd_out=f_putcmd;
  2178. }
  2179. else if (famT_drive)
  2180. {
  2181. drvcmd[0]=CMDT_TRAY_CTL;
  2182. drvcmd[4]=0x03; /* "insert" */
  2183. }
  2184. i=cmd_out();
  2185. msg(DBG_LCS,"p_door_closed bit %d after\n", st_door_closed);
  2186. i=cc_ReadError();
  2187. flags_cmd_out |= f_respo2;
  2188. cc_ReadStatus(); /* command: give 1-byte status */
  2189. i=ResponseStatus();
  2190. if (famT_drive&&(i<0))
  2191. {
  2192. cc_DriveReset();
  2193. i=ResponseStatus();
  2194. #if 0
  2195. sbp_sleep(HZ);
  2196. #endif /* 0 */
  2197. i=ResponseStatus();
  2198. }
  2199. if (i<0)
  2200. {
  2201. msg(DBG_INF,"sbpcd cc_CloseTray: ResponseStatus timed out (%d).\n",i);
  2202. }
  2203. if (!(famT_drive))
  2204. {
  2205. if (!st_spinning)
  2206. {
  2207. cc_SpinUp();
  2208. if (st_check) i=cc_ReadError();
  2209. flags_cmd_out |= f_respo2;
  2210. cc_ReadStatus();
  2211. i=ResponseStatus();
  2212. } else {
  2213. }
  2214. }
  2215. i=DiskInfo();
  2216. return (i);
  2217. }
  2218. static int sbpcd_tray_move(struct cdrom_device_info *cdi, int position)
  2219. {
  2220. int retval=0;
  2221. switch_drive(cdi->handle);
  2222. /* DUH! --AJK */
  2223. if(current_drive->CD_changed != 0xFF) {
  2224. current_drive->CD_changed=0xFF;
  2225. current_drive->diskstate_flags &= ~cd_size_bit;
  2226. }
  2227. if (position == 1) {
  2228. cc_SpinDown();
  2229. } else {
  2230. retval=cc_CloseTray();
  2231. }
  2232. return retval;
  2233. }
  2234. /*==========================================================================*/
  2235. static int cc_ReadSubQ(void)
  2236. {
  2237. int i,j;
  2238. current_drive->diskstate_flags &= ~subq_bit;
  2239. for (j=255;j>0;j--)
  2240. {
  2241. clr_cmdbuf();
  2242. if (fam1_drive)
  2243. {
  2244. drvcmd[0]=CMD1_READSUBQ;
  2245. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2246. response_count=11;
  2247. }
  2248. else if (fam2_drive)
  2249. {
  2250. drvcmd[0]=CMD2_READSUBQ;
  2251. drvcmd[1]=0x02;
  2252. drvcmd[3]=0x01;
  2253. flags_cmd_out=f_putcmd;
  2254. response_count=10;
  2255. }
  2256. else if (fam0LV_drive)
  2257. {
  2258. drvcmd[0]=CMD0_READSUBQ;
  2259. drvcmd[1]=0x02;
  2260. if (famLV_drive)
  2261. flags_cmd_out=f_putcmd;
  2262. else
  2263. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2264. response_count=13;
  2265. }
  2266. else if (famT_drive)
  2267. {
  2268. response_count=12;
  2269. drvcmd[0]=CMDT_READSUBQ;
  2270. drvcmd[1]=0x02;
  2271. drvcmd[2]=0x40;
  2272. drvcmd[3]=0x01;
  2273. drvcmd[8]=response_count;
  2274. }
  2275. i=cmd_out();
  2276. if (i<0) return (i);
  2277. for (i=0;i<response_count;i++)
  2278. {
  2279. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2280. msgbuf[i*3]=0;
  2281. msg(DBG_SQ1,"cc_ReadSubQ:%s\n", msgbuf);
  2282. }
  2283. if (famT_drive) break;
  2284. if (infobuf[0]!=0) break;
  2285. if ((!st_spinning) || (j==1))
  2286. {
  2287. current_drive->SubQ_ctl_adr=current_drive->SubQ_trk=current_drive->SubQ_pnt_idx=current_drive->SubQ_whatisthis=0;
  2288. current_drive->SubQ_run_tot=current_drive->SubQ_run_trk=0;
  2289. return (0);
  2290. }
  2291. }
  2292. if (famT_drive) current_drive->SubQ_ctl_adr=infobuf[1];
  2293. else current_drive->SubQ_ctl_adr=swap_nibbles(infobuf[1]);
  2294. current_drive->SubQ_trk=byt2bcd(infobuf[2]);
  2295. current_drive->SubQ_pnt_idx=byt2bcd(infobuf[3]);
  2296. if (fam0LV_drive) i=5;
  2297. else if (fam12_drive) i=4;
  2298. else if (famT_drive) i=8;
  2299. current_drive->SubQ_run_tot=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  2300. i=7;
  2301. if (fam0LV_drive) i=9;
  2302. else if (fam12_drive) i=7;
  2303. else if (famT_drive) i=4;
  2304. current_drive->SubQ_run_trk=make32(make16(0,infobuf[i]),make16(infobuf[i+1],infobuf[i+2])); /* msf-bin */
  2305. current_drive->SubQ_whatisthis=infobuf[i+3];
  2306. current_drive->diskstate_flags |= subq_bit;
  2307. return (0);
  2308. }
  2309. /*==========================================================================*/
  2310. static int cc_ModeSense(void)
  2311. {
  2312. int i;
  2313. if (fam2_drive) return (0);
  2314. if (famV_drive) return (0);
  2315. current_drive->diskstate_flags &= ~frame_size_bit;
  2316. clr_cmdbuf();
  2317. if (fam1_drive)
  2318. {
  2319. response_count=5;
  2320. drvcmd[0]=CMD1_GETMODE;
  2321. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2322. }
  2323. else if (fam0L_drive)
  2324. {
  2325. response_count=2;
  2326. drvcmd[0]=CMD0_GETMODE;
  2327. if (famL_drive) flags_cmd_out=f_putcmd;
  2328. else flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2329. }
  2330. else if (famT_drive)
  2331. {
  2332. response_count=10;
  2333. drvcmd[0]=CMDT_GETMODE;
  2334. drvcmd[4]=response_count;
  2335. }
  2336. i=cmd_out();
  2337. if (i<0) return (i);
  2338. i=0;
  2339. current_drive->sense_byte=0;
  2340. if (fam1_drive) current_drive->sense_byte=infobuf[i++];
  2341. else if (famT_drive)
  2342. {
  2343. if (infobuf[4]==0x01) current_drive->xa_byte=0x20;
  2344. else current_drive->xa_byte=0;
  2345. i=2;
  2346. }
  2347. current_drive->frame_size=make16(infobuf[i],infobuf[i+1]);
  2348. for (i=0;i<response_count;i++)
  2349. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2350. msgbuf[i*3]=0;
  2351. msg(DBG_XA1,"cc_ModeSense:%s\n", msgbuf);
  2352. current_drive->diskstate_flags |= frame_size_bit;
  2353. return (0);
  2354. }
  2355. /*==========================================================================*/
  2356. /*==========================================================================*/
  2357. static int cc_ModeSelect(int framesize)
  2358. {
  2359. int i;
  2360. if (fam2_drive) return (0);
  2361. if (famV_drive) return (0);
  2362. current_drive->diskstate_flags &= ~frame_size_bit;
  2363. clr_cmdbuf();
  2364. current_drive->frame_size=framesize;
  2365. if (framesize==CD_FRAMESIZE_RAW) current_drive->sense_byte=0x82;
  2366. else current_drive->sense_byte=0x00;
  2367. msg(DBG_XA1,"cc_ModeSelect: %02X %04X\n",
  2368. current_drive->sense_byte, current_drive->frame_size);
  2369. if (fam1_drive)
  2370. {
  2371. drvcmd[0]=CMD1_SETMODE;
  2372. drvcmd[1]=0x00;
  2373. drvcmd[2]=current_drive->sense_byte;
  2374. drvcmd[3]=(current_drive->frame_size>>8)&0xFF;
  2375. drvcmd[4]=current_drive->frame_size&0xFF;
  2376. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2377. }
  2378. else if (fam0L_drive)
  2379. {
  2380. drvcmd[0]=CMD0_SETMODE;
  2381. drvcmd[1]=0x00;
  2382. drvcmd[2]=(current_drive->frame_size>>8)&0xFF;
  2383. drvcmd[3]=current_drive->frame_size&0xFF;
  2384. drvcmd[4]=0x00;
  2385. if(famL_drive)
  2386. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check;
  2387. else
  2388. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2389. }
  2390. else if (famT_drive)
  2391. {
  2392. return (-1);
  2393. }
  2394. response_count=0;
  2395. i=cmd_out();
  2396. if (i<0) return (i);
  2397. current_drive->diskstate_flags |= frame_size_bit;
  2398. return (0);
  2399. }
  2400. /*==========================================================================*/
  2401. static int cc_GetVolume(void)
  2402. {
  2403. int i;
  2404. u_char switches;
  2405. u_char chan0=0;
  2406. u_char vol0=0;
  2407. u_char chan1=1;
  2408. u_char vol1=0;
  2409. if (famV_drive) return (0);
  2410. current_drive->diskstate_flags &= ~volume_bit;
  2411. clr_cmdbuf();
  2412. if (fam1_drive)
  2413. {
  2414. drvcmd[0]=CMD1_GETMODE;
  2415. drvcmd[1]=0x05;
  2416. response_count=5;
  2417. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2418. }
  2419. else if (fam2_drive)
  2420. {
  2421. drvcmd[0]=CMD2_GETMODE;
  2422. drvcmd[1]=0x0E;
  2423. response_count=5;
  2424. flags_cmd_out=f_putcmd;
  2425. }
  2426. else if (fam0L_drive)
  2427. {
  2428. drvcmd[0]=CMD0_GETMODE;
  2429. drvcmd[1]=0x03;
  2430. response_count=2;
  2431. if(famL_drive)
  2432. flags_cmd_out=f_putcmd;
  2433. else
  2434. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2435. }
  2436. else if (famT_drive)
  2437. {
  2438. i=cc_get_mode_T();
  2439. if (i<0) return (i);
  2440. }
  2441. if (!famT_drive)
  2442. {
  2443. i=cmd_out();
  2444. if (i<0) return (i);
  2445. }
  2446. if (fam1_drive)
  2447. {
  2448. chan0=infobuf[1]&0x0F;
  2449. vol0=infobuf[2];
  2450. chan1=infobuf[3]&0x0F;
  2451. vol1=infobuf[4];
  2452. if (chan0==0)
  2453. {
  2454. chan0=1;
  2455. vol0=0;
  2456. }
  2457. if (chan1==0)
  2458. {
  2459. chan1=2;
  2460. vol1=0;
  2461. }
  2462. chan0 >>= 1;
  2463. chan1 >>= 1;
  2464. }
  2465. else if (fam2_drive)
  2466. {
  2467. chan0=infobuf[1];
  2468. vol0=infobuf[2];
  2469. chan1=infobuf[3];
  2470. vol1=infobuf[4];
  2471. }
  2472. else if (famL_drive)
  2473. {
  2474. chan0=0;
  2475. chan1=1;
  2476. vol0=vol1=infobuf[1];
  2477. switches=infobuf[0];
  2478. if ((switches&0x80)!=0) chan0=1;
  2479. if ((switches&0x40)!=0) chan1=0;
  2480. }
  2481. else if (fam0_drive) /* different firmware levels */
  2482. {
  2483. chan0=0;
  2484. chan1=1;
  2485. vol0=vol1=infobuf[1];
  2486. if (current_drive->drv_type>=drv_201)
  2487. {
  2488. if (current_drive->drv_type<drv_300)
  2489. {
  2490. switches=infobuf[0];
  2491. if ((switches&0x80)!=0) vol0=0;
  2492. if ((switches&0x40)!=0) vol1=0;
  2493. if (current_drive->drv_type>=drv_211)
  2494. {
  2495. if ((switches&0x20)!=0) chan0=1;
  2496. if ((switches&0x10)!=0) chan1=0;
  2497. }
  2498. }
  2499. else
  2500. {
  2501. vol0=infobuf[0];
  2502. if ((vol0&0x01)!=0) chan0=1;
  2503. if ((vol1&0x01)==0) chan1=0;
  2504. vol0 &= 0xFC;
  2505. vol1 &= 0xFC;
  2506. if (vol0!=0) vol0 += 3;
  2507. if (vol1!=0) vol1 += 3;
  2508. }
  2509. }
  2510. }
  2511. else if (famT_drive)
  2512. {
  2513. current_drive->volume_control=infobuf[7];
  2514. chan0=0;
  2515. chan1=1;
  2516. if (current_drive->volume_control&0x10) vol0=0;
  2517. else vol0=0xff;
  2518. if (current_drive->volume_control&0x20) vol1=0;
  2519. else vol1=0xff;
  2520. }
  2521. current_drive->vol_chan0=chan0;
  2522. current_drive->vol_ctrl0=vol0;
  2523. current_drive->vol_chan1=chan1;
  2524. current_drive->vol_ctrl1=vol1;
  2525. #if 000
  2526. current_drive->vol_chan2=2;
  2527. current_drive->vol_ctrl2=0xFF;
  2528. current_drive->vol_chan3=3;
  2529. current_drive->vol_ctrl3=0xFF;
  2530. #endif /* 000 */
  2531. current_drive->diskstate_flags |= volume_bit;
  2532. return (0);
  2533. }
  2534. /*==========================================================================*/
  2535. static int cc_ReadCapacity(void)
  2536. {
  2537. int i, j;
  2538. if (fam2_drive) return (0); /* some firmware lacks this command */
  2539. if (famLV_drive) return (0); /* some firmware lacks this command */
  2540. if (famT_drive) return (0); /* done with cc_ReadTocDescr() */
  2541. current_drive->diskstate_flags &= ~cd_size_bit;
  2542. for (j=3;j>0;j--)
  2543. {
  2544. clr_cmdbuf();
  2545. if (fam1_drive)
  2546. {
  2547. drvcmd[0]=CMD1_CAPACITY;
  2548. response_count=5;
  2549. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2550. }
  2551. #if 00
  2552. else if (fam2_drive)
  2553. {
  2554. drvcmd[0]=CMD2_CAPACITY;
  2555. response_count=8;
  2556. flags_cmd_out=f_putcmd;
  2557. }
  2558. #endif
  2559. else if (fam0_drive)
  2560. {
  2561. drvcmd[0]=CMD0_CAPACITY;
  2562. response_count=5;
  2563. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2564. }
  2565. i=cmd_out();
  2566. if (i>=0) break;
  2567. msg(DBG_000,"cc_ReadCapacity: cmd_out: err %d\n", i);
  2568. cc_ReadError();
  2569. }
  2570. if (j==0) return (i);
  2571. if (fam1_drive) current_drive->CDsize_frm=msf2blk(make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2])))+CD_MSF_OFFSET;
  2572. else if (fam0_drive) current_drive->CDsize_frm=make32(make16(0,infobuf[0]),make16(infobuf[1],infobuf[2]));
  2573. #if 00
  2574. else if (fam2_drive) current_drive->CDsize_frm=make32(make16(infobuf[0],infobuf[1]),make16(infobuf[2],infobuf[3]));
  2575. #endif
  2576. current_drive->diskstate_flags |= cd_size_bit;
  2577. msg(DBG_000,"cc_ReadCapacity: %d frames.\n", current_drive->CDsize_frm);
  2578. return (0);
  2579. }
  2580. /*==========================================================================*/
  2581. static int cc_ReadTocDescr(void)
  2582. {
  2583. int i;
  2584. current_drive->diskstate_flags &= ~toc_bit;
  2585. clr_cmdbuf();
  2586. if (fam1_drive)
  2587. {
  2588. drvcmd[0]=CMD1_DISKINFO;
  2589. response_count=6;
  2590. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2591. }
  2592. else if (fam0LV_drive)
  2593. {
  2594. drvcmd[0]=CMD0_DISKINFO;
  2595. response_count=6;
  2596. if(famLV_drive)
  2597. flags_cmd_out=f_putcmd;
  2598. else
  2599. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2600. }
  2601. else if (fam2_drive)
  2602. {
  2603. /* possibly longer timeout periods necessary */
  2604. current_drive->f_multisession=0;
  2605. drvcmd[0]=CMD2_DISKINFO;
  2606. drvcmd[1]=0x02;
  2607. drvcmd[2]=0xAB;
  2608. drvcmd[3]=0xFF; /* session */
  2609. response_count=8;
  2610. flags_cmd_out=f_putcmd;
  2611. }
  2612. else if (famT_drive)
  2613. {
  2614. current_drive->f_multisession=0;
  2615. response_count=12;
  2616. drvcmd[0]=CMDT_DISKINFO;
  2617. drvcmd[1]=0x02;
  2618. drvcmd[6]=CDROM_LEADOUT;
  2619. drvcmd[8]=response_count;
  2620. drvcmd[9]=0x00;
  2621. }
  2622. i=cmd_out();
  2623. if (i<0) return (i);
  2624. if ((famT_drive)&&(i<response_count)) return (-100-i);
  2625. if ((fam1_drive)||(fam2_drive)||(fam0LV_drive))
  2626. current_drive->xa_byte=infobuf[0];
  2627. if (fam2_drive)
  2628. {
  2629. current_drive->first_session=infobuf[1];
  2630. current_drive->last_session=infobuf[2];
  2631. current_drive->n_first_track=infobuf[3];
  2632. current_drive->n_last_track=infobuf[4];
  2633. if (current_drive->first_session!=current_drive->last_session)
  2634. {
  2635. current_drive->f_multisession=1;
  2636. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7])));
  2637. }
  2638. #if 0
  2639. if (current_drive->first_session!=current_drive->last_session)
  2640. {
  2641. if (current_drive->last_session<=20)
  2642. zwanzig=current_drive->last_session+1;
  2643. else zwanzig=20;
  2644. for (count=current_drive->first_session;count<zwanzig;count++)
  2645. {
  2646. drvcmd[0]=CMD2_DISKINFO;
  2647. drvcmd[1]=0x02;
  2648. drvcmd[2]=0xAB;
  2649. drvcmd[3]=count;
  2650. response_count=8;
  2651. flags_cmd_out=f_putcmd;
  2652. i=cmd_out();
  2653. if (i<0) return (i);
  2654. current_drive->msf_multi_n[count]=make32(make16(0,infobuf[5]),make16(infobuf[6],infobuf[7]));
  2655. }
  2656. current_drive->diskstate_flags |= multisession_bit;
  2657. }
  2658. #endif
  2659. drvcmd[0]=CMD2_DISKINFO;
  2660. drvcmd[1]=0x02;
  2661. drvcmd[2]=0xAA;
  2662. drvcmd[3]=0xFF;
  2663. response_count=5;
  2664. flags_cmd_out=f_putcmd;
  2665. i=cmd_out();
  2666. if (i<0) return (i);
  2667. current_drive->size_msf=make32(make16(0,infobuf[2]),make16(infobuf[3],infobuf[4]));
  2668. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2669. current_drive->CDsize_frm=current_drive->size_blk+1;
  2670. }
  2671. else if (famT_drive)
  2672. {
  2673. current_drive->size_msf=make32(make16(infobuf[8],infobuf[9]),make16(infobuf[10],infobuf[11]));
  2674. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2675. current_drive->CDsize_frm=current_drive->size_blk+1;
  2676. current_drive->n_first_track=infobuf[2];
  2677. current_drive->n_last_track=infobuf[3];
  2678. }
  2679. else
  2680. {
  2681. current_drive->n_first_track=infobuf[1];
  2682. current_drive->n_last_track=infobuf[2];
  2683. current_drive->size_msf=make32(make16(0,infobuf[3]),make16(infobuf[4],infobuf[5]));
  2684. current_drive->size_blk=msf2blk(current_drive->size_msf);
  2685. if (famLV_drive) current_drive->CDsize_frm=current_drive->size_blk+1;
  2686. }
  2687. current_drive->diskstate_flags |= toc_bit;
  2688. msg(DBG_TOC,"TocDesc: xa %02X firstt %02X lastt %02X size %08X firstses %02X lastsess %02X\n",
  2689. current_drive->xa_byte,
  2690. current_drive->n_first_track,
  2691. current_drive->n_last_track,
  2692. current_drive->size_msf,
  2693. current_drive->first_session,
  2694. current_drive->last_session);
  2695. return (0);
  2696. }
  2697. /*==========================================================================*/
  2698. static int cc_ReadTocEntry(int num)
  2699. {
  2700. int i;
  2701. clr_cmdbuf();
  2702. if (fam1_drive)
  2703. {
  2704. drvcmd[0]=CMD1_READTOC;
  2705. drvcmd[2]=num;
  2706. response_count=8;
  2707. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2708. }
  2709. else if (fam2_drive)
  2710. {
  2711. /* possibly longer timeout periods necessary */
  2712. drvcmd[0]=CMD2_DISKINFO;
  2713. drvcmd[1]=0x02;
  2714. drvcmd[2]=num;
  2715. response_count=5;
  2716. flags_cmd_out=f_putcmd;
  2717. }
  2718. else if (fam0LV_drive)
  2719. {
  2720. drvcmd[0]=CMD0_READTOC;
  2721. drvcmd[1]=0x02;
  2722. drvcmd[2]=num;
  2723. response_count=8;
  2724. if (famLV_drive)
  2725. flags_cmd_out=f_putcmd;
  2726. else
  2727. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2728. }
  2729. else if (famT_drive)
  2730. {
  2731. response_count=12;
  2732. drvcmd[0]=CMDT_DISKINFO;
  2733. drvcmd[1]=0x02;
  2734. drvcmd[6]=num;
  2735. drvcmd[8]=response_count;
  2736. drvcmd[9]=0x00;
  2737. }
  2738. i=cmd_out();
  2739. if (i<0) return (i);
  2740. if ((famT_drive)&&(i<response_count)) return (-100-i);
  2741. if ((fam1_drive)||(fam0LV_drive))
  2742. {
  2743. current_drive->TocEnt_nixbyte=infobuf[0];
  2744. i=1;
  2745. }
  2746. else if (fam2_drive) i=0;
  2747. else if (famT_drive) i=5;
  2748. current_drive->TocEnt_ctl_adr=swap_nibbles(infobuf[i++]);
  2749. if ((fam1_drive)||(fam0L_drive))
  2750. {
  2751. current_drive->TocEnt_number=infobuf[i++];
  2752. current_drive->TocEnt_format=infobuf[i];
  2753. }
  2754. else
  2755. {
  2756. current_drive->TocEnt_number=num;
  2757. current_drive->TocEnt_format=0;
  2758. }
  2759. if (fam1_drive) i=4;
  2760. else if (fam0LV_drive) i=5;
  2761. else if (fam2_drive) i=2;
  2762. else if (famT_drive) i=9;
  2763. current_drive->TocEnt_address=make32(make16(0,infobuf[i]),
  2764. make16(infobuf[i+1],infobuf[i+2]));
  2765. for (i=0;i<response_count;i++)
  2766. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2767. msgbuf[i*3]=0;
  2768. msg(DBG_ECS,"TocEntry:%s\n", msgbuf);
  2769. msg(DBG_TOC,"TocEntry: %02X %02X %02X %02X %08X\n",
  2770. current_drive->TocEnt_nixbyte, current_drive->TocEnt_ctl_adr,
  2771. current_drive->TocEnt_number, current_drive->TocEnt_format,
  2772. current_drive->TocEnt_address);
  2773. return (0);
  2774. }
  2775. /*==========================================================================*/
  2776. static int cc_ReadPacket(void)
  2777. {
  2778. int i;
  2779. clr_cmdbuf();
  2780. drvcmd[0]=CMD0_PACKET;
  2781. drvcmd[1]=response_count;
  2782. if(famL_drive) flags_cmd_out=f_putcmd;
  2783. else if (fam01_drive)
  2784. flags_cmd_out=f_putcmd|f_getsta|f_ResponseStatus|f_obey_p_check;
  2785. else if (fam2_drive) return (-1); /* not implemented yet */
  2786. else if (famT_drive)
  2787. {
  2788. return (-1);
  2789. }
  2790. i=cmd_out();
  2791. return (i);
  2792. }
  2793. /*==========================================================================*/
  2794. static int convert_UPC(u_char *p)
  2795. {
  2796. int i;
  2797. p++;
  2798. if (fam0L_drive) p[13]=0;
  2799. for (i=0;i<7;i++)
  2800. {
  2801. if (fam1_drive) current_drive->UPC_buf[i]=swap_nibbles(*p++);
  2802. else if (fam0L_drive)
  2803. {
  2804. current_drive->UPC_buf[i]=((*p++)<<4)&0xFF;
  2805. current_drive->UPC_buf[i] |= *p++;
  2806. }
  2807. else if (famT_drive)
  2808. {
  2809. return (-1);
  2810. }
  2811. else /* CD200 */
  2812. {
  2813. return (-1);
  2814. }
  2815. }
  2816. current_drive->UPC_buf[6] &= 0xF0;
  2817. return (0);
  2818. }
  2819. /*==========================================================================*/
  2820. static int cc_ReadUPC(void)
  2821. {
  2822. int i;
  2823. #if TEST_UPC
  2824. int block, checksum;
  2825. #endif /* TEST_UPC */
  2826. if (fam2_drive) return (0); /* not implemented yet */
  2827. if (famT_drive) return (0); /* not implemented yet */
  2828. if (famV_drive) return (0); /* not implemented yet */
  2829. #if 1
  2830. if (fam0_drive) return (0); /* but it should work */
  2831. #endif
  2832. current_drive->diskstate_flags &= ~upc_bit;
  2833. #if TEST_UPC
  2834. for (block=CD_MSF_OFFSET+1;block<CD_MSF_OFFSET+200;block++)
  2835. {
  2836. #endif /* TEST_UPC */
  2837. clr_cmdbuf();
  2838. if (fam1_drive)
  2839. {
  2840. drvcmd[0]=CMD1_READ_UPC;
  2841. #if TEST_UPC
  2842. drvcmd[1]=(block>>16)&0xFF;
  2843. drvcmd[2]=(block>>8)&0xFF;
  2844. drvcmd[3]=block&0xFF;
  2845. #endif /* TEST_UPC */
  2846. response_count=8;
  2847. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2848. }
  2849. else if (fam0L_drive)
  2850. {
  2851. drvcmd[0]=CMD0_READ_UPC;
  2852. #if TEST_UPC
  2853. drvcmd[2]=(block>>16)&0xFF;
  2854. drvcmd[3]=(block>>8)&0xFF;
  2855. drvcmd[4]=block&0xFF;
  2856. #endif /* TEST_UPC */
  2857. response_count=0;
  2858. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2859. }
  2860. else if (fam2_drive)
  2861. {
  2862. return (-1);
  2863. }
  2864. else if (famT_drive)
  2865. {
  2866. return (-1);
  2867. }
  2868. i=cmd_out();
  2869. if (i<0)
  2870. {
  2871. msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
  2872. return (i);
  2873. }
  2874. if (fam0L_drive)
  2875. {
  2876. response_count=16;
  2877. if (famL_drive) flags_cmd_out=f_putcmd;
  2878. i=cc_ReadPacket();
  2879. if (i<0)
  2880. {
  2881. msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
  2882. return (i);
  2883. }
  2884. }
  2885. #if TEST_UPC
  2886. checksum=0;
  2887. #endif /* TEST_UPC */
  2888. for (i=0;i<(fam1_drive?8:16);i++)
  2889. {
  2890. #if TEST_UPC
  2891. checksum |= infobuf[i];
  2892. #endif /* TEST_UPC */
  2893. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  2894. }
  2895. msgbuf[i*3]=0;
  2896. msg(DBG_UPC,"UPC info:%s\n", msgbuf);
  2897. #if TEST_UPC
  2898. if ((checksum&0x7F)!=0) break;
  2899. }
  2900. #endif /* TEST_UPC */
  2901. current_drive->UPC_ctl_adr=0;
  2902. if (fam1_drive) i=0;
  2903. else i=2;
  2904. if ((infobuf[i]&0x80)!=0)
  2905. {
  2906. convert_UPC(&infobuf[i]);
  2907. current_drive->UPC_ctl_adr = (current_drive->TocEnt_ctl_adr & 0xF0) | 0x02;
  2908. }
  2909. for (i=0;i<7;i++)
  2910. sprintf(&msgbuf[i*3], " %02X", current_drive->UPC_buf[i]);
  2911. sprintf(&msgbuf[i*3], " (%02X)", current_drive->UPC_ctl_adr);
  2912. msgbuf[i*3+5]=0;
  2913. msg(DBG_UPC,"UPC code:%s\n", msgbuf);
  2914. current_drive->diskstate_flags |= upc_bit;
  2915. return (0);
  2916. }
  2917. static int sbpcd_get_mcn(struct cdrom_device_info *cdi, struct cdrom_mcn *mcn)
  2918. {
  2919. int i;
  2920. unsigned char *mcnp = mcn->medium_catalog_number;
  2921. unsigned char *resp;
  2922. current_drive->diskstate_flags &= ~upc_bit;
  2923. clr_cmdbuf();
  2924. if (fam1_drive)
  2925. {
  2926. drvcmd[0]=CMD1_READ_UPC;
  2927. response_count=8;
  2928. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2929. }
  2930. else if (fam0L_drive)
  2931. {
  2932. drvcmd[0]=CMD0_READ_UPC;
  2933. response_count=0;
  2934. flags_cmd_out=f_putcmd|f_lopsta|f_getsta|f_ResponseStatus|f_obey_p_check|f_bit1;
  2935. }
  2936. else if (fam2_drive)
  2937. {
  2938. return (-1);
  2939. }
  2940. else if (famT_drive)
  2941. {
  2942. return (-1);
  2943. }
  2944. i=cmd_out();
  2945. if (i<0)
  2946. {
  2947. msg(DBG_000,"cc_ReadUPC cmd_out: err %d\n", i);
  2948. return (i);
  2949. }
  2950. if (fam0L_drive)
  2951. {
  2952. response_count=16;
  2953. if (famL_drive) flags_cmd_out=f_putcmd;
  2954. i=cc_ReadPacket();
  2955. if (i<0)
  2956. {
  2957. msg(DBG_000,"cc_ReadUPC ReadPacket: err %d\n", i);
  2958. return (i);
  2959. }
  2960. }
  2961. current_drive->UPC_ctl_adr=0;
  2962. if (fam1_drive) i=0;
  2963. else i=2;
  2964. resp = infobuf + i;
  2965. if (*resp++ == 0x80) {
  2966. /* packed bcd to single ASCII digits */
  2967. *mcnp++ = (*resp >> 4) + '0';
  2968. *mcnp++ = (*resp++ & 0x0f) + '0';
  2969. *mcnp++ = (*resp >> 4) + '0';
  2970. *mcnp++ = (*resp++ & 0x0f) + '0';
  2971. *mcnp++ = (*resp >> 4) + '0';
  2972. *mcnp++ = (*resp++ & 0x0f) + '0';
  2973. *mcnp++ = (*resp >> 4) + '0';
  2974. *mcnp++ = (*resp++ & 0x0f) + '0';
  2975. *mcnp++ = (*resp >> 4) + '0';
  2976. *mcnp++ = (*resp++ & 0x0f) + '0';
  2977. *mcnp++ = (*resp >> 4) + '0';
  2978. *mcnp++ = (*resp++ & 0x0f) + '0';
  2979. *mcnp++ = (*resp >> 4) + '0';
  2980. }
  2981. *mcnp = '\0';
  2982. current_drive->diskstate_flags |= upc_bit;
  2983. return (0);
  2984. }
  2985. /*==========================================================================*/
  2986. static int cc_CheckMultiSession(void)
  2987. {
  2988. int i;
  2989. if (fam2_drive) return (0);
  2990. current_drive->f_multisession=0;
  2991. current_drive->lba_multi=0;
  2992. if (fam0_drive) return (0);
  2993. clr_cmdbuf();
  2994. if (fam1_drive)
  2995. {
  2996. drvcmd[0]=CMD1_MULTISESS;
  2997. response_count=6;
  2998. flags_cmd_out=f_putcmd|f_ResponseStatus|f_obey_p_check;
  2999. i=cmd_out();
  3000. if (i<0) return (i);
  3001. if ((infobuf[0]&0x80)!=0)
  3002. {
  3003. current_drive->f_multisession=1;
  3004. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[1]),
  3005. make16(infobuf[2],infobuf[3])));
  3006. }
  3007. }
  3008. else if (famLV_drive)
  3009. {
  3010. drvcmd[0]=CMDL_MULTISESS;
  3011. drvcmd[1]=3;
  3012. drvcmd[2]=1;
  3013. response_count=8;
  3014. flags_cmd_out=f_putcmd;
  3015. i=cmd_out();
  3016. if (i<0) return (i);
  3017. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[5]),
  3018. make16(infobuf[6],infobuf[7])));
  3019. }
  3020. else if (famT_drive)
  3021. {
  3022. response_count=12;
  3023. drvcmd[0]=CMDT_DISKINFO;
  3024. drvcmd[1]=0x02;
  3025. drvcmd[6]=0;
  3026. drvcmd[8]=response_count;
  3027. drvcmd[9]=0x40;
  3028. i=cmd_out();
  3029. if (i<0) return (i);
  3030. if (i<response_count) return (-100-i);
  3031. current_drive->first_session=infobuf[2];
  3032. current_drive->last_session=infobuf[3];
  3033. current_drive->track_of_last_session=infobuf[6];
  3034. if (current_drive->first_session!=current_drive->last_session)
  3035. {
  3036. current_drive->f_multisession=1;
  3037. current_drive->lba_multi=msf2blk(make32(make16(0,infobuf[9]),make16(infobuf[10],infobuf[11])));
  3038. }
  3039. }
  3040. for (i=0;i<response_count;i++)
  3041. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3042. msgbuf[i*3]=0;
  3043. msg(DBG_MUL,"MultiSession Info:%s (%d)\n", msgbuf, current_drive->lba_multi);
  3044. if (current_drive->lba_multi>200)
  3045. {
  3046. current_drive->f_multisession=1;
  3047. msg(DBG_MUL,"MultiSession base: %06X\n", current_drive->lba_multi);
  3048. }
  3049. return (0);
  3050. }
  3051. /*==========================================================================*/
  3052. #ifdef FUTURE
  3053. static int cc_SubChanInfo(int frame, int count, u_char *buffer)
  3054. /* "frame" is a RED BOOK (msf-bin) address */
  3055. {
  3056. int i;
  3057. if (fam0LV_drive) return (-ENOSYS); /* drive firmware lacks it */
  3058. if (famT_drive)
  3059. {
  3060. return (-1);
  3061. }
  3062. #if 0
  3063. if (current_drive->audio_state!=audio_playing) return (-ENODATA);
  3064. #endif
  3065. clr_cmdbuf();
  3066. drvcmd[0]=CMD1_SUBCHANINF;
  3067. drvcmd[1]=(frame>>16)&0xFF;
  3068. drvcmd[2]=(frame>>8)&0xFF;
  3069. drvcmd[3]=frame&0xFF;
  3070. drvcmd[5]=(count>>8)&0xFF;
  3071. drvcmd[6]=count&0xFF;
  3072. flags_cmd_out=f_putcmd|f_respo2|f_ResponseStatus|f_obey_p_check;
  3073. cmd_type=READ_SC;
  3074. current_drive->frame_size=CD_FRAMESIZE_SUB;
  3075. i=cmd_out(); /* which buffer to use? */
  3076. return (i);
  3077. }
  3078. #endif /* FUTURE */
  3079. /*==========================================================================*/
  3080. static void __init check_datarate(void)
  3081. {
  3082. int i=0;
  3083. msg(DBG_IOX,"check_datarate entered.\n");
  3084. datarate=0;
  3085. #if TEST_STI
  3086. for (i=0;i<=1000;i++) printk(".");
  3087. #endif
  3088. /* set a timer to make (timed_out_delay!=0) after 1.1 seconds */
  3089. #if 1
  3090. del_timer(&delay_timer);
  3091. #endif
  3092. delay_timer.expires=jiffies+11*HZ/10;
  3093. timed_out_delay=0;
  3094. add_timer(&delay_timer);
  3095. #if 0
  3096. msg(DBG_TIM,"delay timer started (11*HZ/10).\n");
  3097. #endif
  3098. do
  3099. {
  3100. i=inb(CDi_status);
  3101. datarate++;
  3102. #if 1
  3103. if (datarate>0x6FFFFFFF) break;
  3104. #endif
  3105. }
  3106. while (!timed_out_delay);
  3107. del_timer(&delay_timer);
  3108. #if 0
  3109. msg(DBG_TIM,"datarate: %04X\n", datarate);
  3110. #endif
  3111. if (datarate<65536) datarate=65536;
  3112. maxtim16=datarate*16;
  3113. maxtim04=datarate*4;
  3114. maxtim02=datarate*2;
  3115. maxtim_8=datarate/32;
  3116. #if LONG_TIMING
  3117. maxtim_data=datarate/100;
  3118. #else
  3119. maxtim_data=datarate/300;
  3120. #endif /* LONG_TIMING */
  3121. #if 0
  3122. msg(DBG_TIM,"maxtim_8 %d, maxtim_data %d.\n", maxtim_8, maxtim_data);
  3123. #endif
  3124. }
  3125. /*==========================================================================*/
  3126. #if 0
  3127. static int c2_ReadError(int fam)
  3128. {
  3129. int i;
  3130. clr_cmdbuf();
  3131. response_count=9;
  3132. clr_respo_buf(9);
  3133. if (fam==1)
  3134. {
  3135. drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  3136. i=do_cmd(f_putcmd|f_lopsta|f_getsta|f_ResponseStatus);
  3137. }
  3138. else if (fam==2)
  3139. {
  3140. drvcmd[0]=CMD2_READ_ERR;
  3141. i=do_cmd(f_putcmd);
  3142. }
  3143. else return (-1);
  3144. return (i);
  3145. }
  3146. #endif
  3147. /*==========================================================================*/
  3148. static void __init ask_mail(void)
  3149. {
  3150. int i;
  3151. msg(DBG_INF, "please mail the following lines to emoenke@gwdg.de\n");
  3152. msg(DBG_INF, "(don't mail if you are not using the actual kernel):\n");
  3153. msg(DBG_INF, "%s\n", VERSION);
  3154. msg(DBG_INF, "address %03X, type %s, drive %s (ID %d)\n",
  3155. CDo_command, type, current_drive->drive_model, current_drive->drv_id);
  3156. for (i=0;i<12;i++)
  3157. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3158. msgbuf[i*3]=0;
  3159. msg(DBG_INF,"infobuf =%s\n", msgbuf);
  3160. for (i=0;i<12;i++)
  3161. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3162. msgbuf[i*3]=0;
  3163. msg(DBG_INF,"infobuf =%s\n", msgbuf);
  3164. }
  3165. /*==========================================================================*/
  3166. static int __init check_version(void)
  3167. {
  3168. int i, j, l;
  3169. int teac_possible=0;
  3170. msg(DBG_INI,"check_version: id=%d, d=%d.\n", current_drive->drv_id, current_drive - D_S);
  3171. current_drive->drv_type=0;
  3172. /* check for CR-52x, CR-56x, LCS-7260 and ECS-AT */
  3173. /* clear any pending error state */
  3174. clr_cmdbuf();
  3175. drvcmd[0]=CMD0_READ_ERR; /* same as CMD1_ and CMDL_ */
  3176. response_count=9;
  3177. flags_cmd_out=f_putcmd;
  3178. i=cmd_out();
  3179. if (i<0) msg(DBG_INI,"CMD0_READ_ERR returns %d (ok anyway).\n",i);
  3180. /* read drive version */
  3181. clr_cmdbuf();
  3182. for (i=0;i<12;i++) infobuf[i]=0;
  3183. drvcmd[0]=CMD0_READ_VER; /* same as CMD1_ and CMDL_ */
  3184. response_count=12; /* fam1: only 11 */
  3185. flags_cmd_out=f_putcmd;
  3186. i=cmd_out();
  3187. if (i<-1) msg(DBG_INI,"CMD0_READ_VER returns %d\n",i);
  3188. if (i==-11) teac_possible++;
  3189. j=0;
  3190. for (i=0;i<12;i++) j+=infobuf[i];
  3191. if (j)
  3192. {
  3193. for (i=0;i<12;i++)
  3194. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3195. msgbuf[i*3]=0;
  3196. msg(DBG_ECS,"infobuf =%s\n", msgbuf);
  3197. for (i=0;i<12;i++)
  3198. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3199. msgbuf[i*3]=0;
  3200. msg(DBG_ECS,"infobuf =%s\n", msgbuf);
  3201. }
  3202. for (i=0;i<4;i++) if (infobuf[i]!=family1[i]) break;
  3203. if (i==4)
  3204. {
  3205. current_drive->drive_model[0]='C';
  3206. current_drive->drive_model[1]='R';
  3207. current_drive->drive_model[2]='-';
  3208. current_drive->drive_model[3]='5';
  3209. current_drive->drive_model[4]=infobuf[i++];
  3210. current_drive->drive_model[5]=infobuf[i++];
  3211. current_drive->drive_model[6]=0;
  3212. current_drive->drv_type=drv_fam1;
  3213. }
  3214. if (!current_drive->drv_type)
  3215. {
  3216. for (i=0;i<8;i++) if (infobuf[i]!=family0[i]) break;
  3217. if (i==8)
  3218. {
  3219. current_drive->drive_model[0]='C';
  3220. current_drive->drive_model[1]='R';
  3221. current_drive->drive_model[2]='-';
  3222. current_drive->drive_model[3]='5';
  3223. current_drive->drive_model[4]='2';
  3224. current_drive->drive_model[5]='x';
  3225. current_drive->drive_model[6]=0;
  3226. current_drive->drv_type=drv_fam0;
  3227. }
  3228. }
  3229. if (!current_drive->drv_type)
  3230. {
  3231. for (i=0;i<8;i++) if (infobuf[i]!=familyL[i]) break;
  3232. if (i==8)
  3233. {
  3234. for (j=0;j<8;j++)
  3235. current_drive->drive_model[j]=infobuf[j];
  3236. current_drive->drive_model[8]=0;
  3237. current_drive->drv_type=drv_famL;
  3238. }
  3239. }
  3240. if (!current_drive->drv_type)
  3241. {
  3242. for (i=0;i<6;i++) if (infobuf[i]!=familyV[i]) break;
  3243. if (i==6)
  3244. {
  3245. for (j=0;j<6;j++)
  3246. current_drive->drive_model[j]=infobuf[j];
  3247. current_drive->drive_model[6]=0;
  3248. current_drive->drv_type=drv_famV;
  3249. i+=2; /* 2 blanks before version */
  3250. }
  3251. }
  3252. if (!current_drive->drv_type)
  3253. {
  3254. /* check for CD200 */
  3255. clr_cmdbuf();
  3256. drvcmd[0]=CMD2_READ_ERR;
  3257. response_count=9;
  3258. flags_cmd_out=f_putcmd;
  3259. i=cmd_out();
  3260. if (i<0) msg(DBG_INI,"CMD2_READERR returns %d (ok anyway).\n",i);
  3261. if (i<0) msg(DBG_000,"CMD2_READERR returns %d (ok anyway).\n",i);
  3262. /* read drive version */
  3263. clr_cmdbuf();
  3264. for (i=0;i<12;i++) infobuf[i]=0;
  3265. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  3266. #if 0
  3267. OUT(CDo_reset,0);
  3268. sbp_sleep(6*HZ);
  3269. OUT(CDo_enable,current_drive->drv_sel);
  3270. #endif
  3271. drvcmd[0]=CMD2_READ_VER;
  3272. response_count=12;
  3273. flags_cmd_out=f_putcmd;
  3274. i=cmd_out();
  3275. if (i<0) msg(DBG_INI,"CMD2_READ_VER returns %d\n",i);
  3276. if (i==-7) teac_possible++;
  3277. j=0;
  3278. for (i=0;i<12;i++) j+=infobuf[i];
  3279. if (j)
  3280. {
  3281. for (i=0;i<12;i++)
  3282. sprintf(&msgbuf[i*3], " %02X", infobuf[i]);
  3283. msgbuf[i*3]=0;
  3284. msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  3285. for (i=0;i<12;i++)
  3286. sprintf(&msgbuf[i*3], " %c ", infobuf[i]);
  3287. msgbuf[i*3]=0;
  3288. msg(DBG_IDX,"infobuf =%s\n", msgbuf);
  3289. }
  3290. if (i>=0)
  3291. {
  3292. for (i=0;i<5;i++) if (infobuf[i]!=family2[i]) break;
  3293. if (i==5)
  3294. {
  3295. current_drive->drive_model[0]='C';
  3296. current_drive->drive_model[1]='D';
  3297. current_drive->drive_model[2]='2';
  3298. current_drive->drive_model[3]='0';
  3299. current_drive->drive_model[4]='0';
  3300. current_drive->drive_model[5]=infobuf[i++];
  3301. current_drive->drive_model[6]=infobuf[i++];
  3302. current_drive->drive_model[7]=0;
  3303. current_drive->drv_type=drv_fam2;
  3304. }
  3305. }
  3306. }
  3307. if (!current_drive->drv_type)
  3308. {
  3309. /* check for TEAC CD-55A */
  3310. msg(DBG_TEA,"teac_possible: %d\n",teac_possible);
  3311. for (j=1;j<=((current_drive->drv_id==0)?3:1);j++)
  3312. {
  3313. for (l=1;l<=((current_drive->drv_id==0)?10:1);l++)
  3314. {
  3315. msg(DBG_TEA,"TEAC reset #%d-%d.\n", j, l);
  3316. if (sbpro_type==1) OUT(CDo_reset,0);
  3317. else
  3318. {
  3319. OUT(CDo_enable,current_drive->drv_sel);
  3320. OUT(CDo_sel_i_d,0);
  3321. OUT(CDo_command,CMDT_RESET);
  3322. for (i=0;i<9;i++) OUT(CDo_command,0);
  3323. }
  3324. sbp_sleep(5*HZ/10);
  3325. OUT(CDo_enable,current_drive->drv_sel);
  3326. OUT(CDo_sel_i_d,0);
  3327. i=inb(CDi_status);
  3328. msg(DBG_TEA,"TEAC CDi_status: %02X.\n",i);
  3329. #if 0
  3330. if (i&s_not_result_ready) continue; /* drive not present or ready */
  3331. #endif
  3332. i=inb(CDi_info);
  3333. msg(DBG_TEA,"TEAC CDi_info: %02X.\n",i);
  3334. if (i==0x55) break; /* drive found */
  3335. }
  3336. if (i==0x55) break; /* drive found */
  3337. }
  3338. if (i==0x55) /* drive found */
  3339. {
  3340. msg(DBG_TEA,"TEAC drive found.\n");
  3341. clr_cmdbuf();
  3342. flags_cmd_out=f_putcmd;
  3343. response_count=12;
  3344. drvcmd[0]=CMDT_READ_VER;
  3345. drvcmd[4]=response_count;
  3346. for (i=0;i<12;i++) infobuf[i]=0;
  3347. i=cmd_out_T();
  3348. if (i!=0) msg(DBG_TEA,"cmd_out_T(CMDT_READ_VER) returns %d.\n",i);
  3349. for (i=1;i<6;i++) if (infobuf[i]!=familyT[i-1]) break;
  3350. if (i==6)
  3351. {
  3352. current_drive->drive_model[0]='C';
  3353. current_drive->drive_model[1]='D';
  3354. current_drive->drive_model[2]='-';
  3355. current_drive->drive_model[3]='5';
  3356. current_drive->drive_model[4]='5';
  3357. current_drive->drive_model[5]=0;
  3358. current_drive->drv_type=drv_famT;
  3359. }
  3360. }
  3361. }
  3362. if (!current_drive->drv_type)
  3363. {
  3364. msg(DBG_TEA,"no drive found at address %03X under ID %d.\n",CDo_command,current_drive->drv_id);
  3365. return (-522);
  3366. }
  3367. for (j=0;j<4;j++) current_drive->firmware_version[j]=infobuf[i+j];
  3368. if (famL_drive)
  3369. {
  3370. u_char lcs_firm_e1[]="A E1";
  3371. u_char lcs_firm_f4[]="A4F4";
  3372. for (j=0;j<4;j++)
  3373. if (current_drive->firmware_version[j]!=lcs_firm_e1[j]) break;
  3374. if (j==4) current_drive->drv_type=drv_e1;
  3375. for (j=0;j<4;j++)
  3376. if (current_drive->firmware_version[j]!=lcs_firm_f4[j]) break;
  3377. if (j==4) current_drive->drv_type=drv_f4;
  3378. if (current_drive->drv_type==drv_famL) ask_mail();
  3379. }
  3380. else if (famT_drive)
  3381. {
  3382. j=infobuf[4]; /* one-byte version??? - here: 0x15 */
  3383. if (j=='5')
  3384. {
  3385. current_drive->firmware_version[0]=infobuf[7];
  3386. current_drive->firmware_version[1]=infobuf[8];
  3387. current_drive->firmware_version[2]=infobuf[10];
  3388. current_drive->firmware_version[3]=infobuf[11];
  3389. }
  3390. else
  3391. {
  3392. if (j!=0x15) ask_mail();
  3393. current_drive->firmware_version[0]='0';
  3394. current_drive->firmware_version[1]='.';
  3395. current_drive->firmware_version[2]='0'+(j>>4);
  3396. current_drive->firmware_version[3]='0'+(j&0x0f);
  3397. }
  3398. }
  3399. else /* CR-52x, CR-56x, CD200, ECS-AT */
  3400. {
  3401. j = (current_drive->firmware_version[0] & 0x0F) * 100 +
  3402. (current_drive->firmware_version[2] & 0x0F) *10 +
  3403. (current_drive->firmware_version[3] & 0x0F);
  3404. if (fam0_drive)
  3405. {
  3406. if (j<200) current_drive->drv_type=drv_199;
  3407. else if (j<201) current_drive->drv_type=drv_200;
  3408. else if (j<210) current_drive->drv_type=drv_201;
  3409. else if (j<211) current_drive->drv_type=drv_210;
  3410. else if (j<300) current_drive->drv_type=drv_211;
  3411. else if (j>=300) current_drive->drv_type=drv_300;
  3412. }
  3413. else if (fam1_drive)
  3414. {
  3415. if (j<100) current_drive->drv_type=drv_099;
  3416. else
  3417. {
  3418. current_drive->drv_type=drv_100;
  3419. if ((j!=500)&&(j!=102)) ask_mail();
  3420. }
  3421. }
  3422. else if (fam2_drive)
  3423. {
  3424. if (current_drive->drive_model[5]=='F')
  3425. {
  3426. if ((j!=1)&&(j!=35)&&(j!=200)&&(j!=210))
  3427. ask_mail(); /* unknown version at time */
  3428. }
  3429. else
  3430. {
  3431. msg(DBG_INF,"this CD200 drive is not fully supported yet - only audio will work.\n");
  3432. if ((j!=101)&&(j!=35))
  3433. ask_mail(); /* unknown version at time */
  3434. }
  3435. }
  3436. else if (famV_drive)
  3437. {
  3438. if ((j==100)||(j==150)) current_drive->drv_type=drv_at;
  3439. ask_mail(); /* hopefully we get some feedback by this */
  3440. }
  3441. }
  3442. msg(DBG_LCS,"drive type %02X\n",current_drive->drv_type);
  3443. msg(DBG_INI,"check_version done.\n");
  3444. return (0);
  3445. }
  3446. /*==========================================================================*/
  3447. static void switch_drive(struct sbpcd_drive *p)
  3448. {
  3449. current_drive = p;
  3450. OUT(CDo_enable,current_drive->drv_sel);
  3451. msg(DBG_DID,"drive %d (ID=%d) activated.\n",
  3452. current_drive - D_S, current_drive->drv_id);
  3453. return;
  3454. }
  3455. /*==========================================================================*/
  3456. #ifdef PATH_CHECK
  3457. /*
  3458. * probe for the presence of an interface card
  3459. */
  3460. static int __init check_card(int port)
  3461. {
  3462. #undef N_RESPO
  3463. #define N_RESPO 20
  3464. int i, j, k;
  3465. u_char response[N_RESPO];
  3466. u_char save_port0;
  3467. u_char save_port3;
  3468. msg(DBG_INI,"check_card entered.\n");
  3469. save_port0=inb(port+0);
  3470. save_port3=inb(port+3);
  3471. for (j=0;j<NR_SBPCD;j++)
  3472. {
  3473. OUT(port+3,j) ; /* enable drive #j */
  3474. OUT(port+0,CMD0_PATH_CHECK);
  3475. for (i=10;i>0;i--) OUT(port+0,0);
  3476. for (k=0;k<N_RESPO;k++) response[k]=0;
  3477. for (k=0;k<N_RESPO;k++)
  3478. {
  3479. for (i=10000;i>0;i--)
  3480. {
  3481. if (inb(port+1)&s_not_result_ready) continue;
  3482. response[k]=inb(port+0);
  3483. break;
  3484. }
  3485. }
  3486. for (i=0;i<N_RESPO;i++)
  3487. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3488. msgbuf[i*3]=0;
  3489. msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  3490. OUT(port+0,CMD0_PATH_CHECK);
  3491. for (i=10;i>0;i--) OUT(port+0,0);
  3492. for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  3493. for (k=0;k<N_RESPO;k++)
  3494. {
  3495. for (i=10000;i>0;i--)
  3496. {
  3497. if (inb(port+1)&s_not_result_ready) continue;
  3498. response[k]=inb(port+0);
  3499. break;
  3500. }
  3501. }
  3502. for (i=0;i<N_RESPO;i++)
  3503. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3504. msgbuf[i*3]=0;
  3505. msg(DBG_TEA,"path check 00 (%d): %s\n", j, msgbuf);
  3506. if (response[0]==0xAA)
  3507. if (response[1]==0x55)
  3508. return (0);
  3509. }
  3510. for (j=0;j<NR_SBPCD;j++)
  3511. {
  3512. OUT(port+3,j) ; /* enable drive #j */
  3513. OUT(port+0,CMD2_READ_VER);
  3514. for (i=10;i>0;i--) OUT(port+0,0);
  3515. for (k=0;k<N_RESPO;k++) response[k]=0;
  3516. for (k=0;k<N_RESPO;k++)
  3517. {
  3518. for (i=1000000;i>0;i--)
  3519. {
  3520. if (inb(port+1)&s_not_result_ready) continue;
  3521. response[k]=inb(port+0);
  3522. break;
  3523. }
  3524. }
  3525. for (i=0;i<N_RESPO;i++)
  3526. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3527. msgbuf[i*3]=0;
  3528. msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  3529. OUT(port+0,CMD2_READ_VER);
  3530. for (i=10;i>0;i--) OUT(port+0,0);
  3531. for (k=0;k<N_RESPO;k++) response[k]=0xFF;
  3532. for (k=0;k<N_RESPO;k++)
  3533. {
  3534. for (i=1000000;i>0;i--)
  3535. {
  3536. if (inb(port+1)&s_not_result_ready) continue;
  3537. response[k]=inb(port+0);
  3538. break;
  3539. }
  3540. }
  3541. for (i=0;i<N_RESPO;i++)
  3542. sprintf(&msgbuf[i*3], " %02X", response[i]);
  3543. msgbuf[i*3]=0;
  3544. msg(DBG_TEA,"path check 12 (%d): %s\n", j, msgbuf);
  3545. if (response[0]==0xAA)
  3546. if (response[1]==0x55)
  3547. return (0);
  3548. }
  3549. OUT(port+0,save_port0);
  3550. OUT(port+3,save_port3);
  3551. return (0); /* in any case - no real "function" at time */
  3552. }
  3553. #endif /* PATH_CHECK */
  3554. /*==========================================================================*/
  3555. /*==========================================================================*/
  3556. /*
  3557. * probe for the presence of drives on the selected controller
  3558. */
  3559. static int __init check_drives(void)
  3560. {
  3561. int i, j;
  3562. msg(DBG_INI,"check_drives entered.\n");
  3563. ndrives=0;
  3564. for (j=0;j<max_drives;j++)
  3565. {
  3566. struct sbpcd_drive *p = D_S + ndrives;
  3567. p->drv_id=j;
  3568. if (sbpro_type==1) p->drv_sel=(j&0x01)<<1|(j&0x02)>>1;
  3569. else p->drv_sel=j;
  3570. switch_drive(p);
  3571. msg(DBG_INI,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  3572. msg(DBG_000,"check_drives: drive %d (ID=%d) activated.\n",ndrives,j);
  3573. i=check_version();
  3574. if (i<0) msg(DBG_INI,"check_version returns %d.\n",i);
  3575. else
  3576. {
  3577. current_drive->drv_options=drv_pattern[j];
  3578. if (fam0L_drive) current_drive->drv_options&=~(speed_auto|speed_300|speed_150);
  3579. msg(DBG_INF, "Drive %d (ID=%d): %.9s (%.4s) at 0x%03X (type %d)\n",
  3580. current_drive - D_S,
  3581. current_drive->drv_id,
  3582. current_drive->drive_model,
  3583. current_drive->firmware_version,
  3584. CDo_command,
  3585. sbpro_type);
  3586. ndrives++;
  3587. }
  3588. }
  3589. for (j=ndrives;j<NR_SBPCD;j++) D_S[j].drv_id=-1;
  3590. if (ndrives==0) return (-1);
  3591. return (0);
  3592. }
  3593. /*==========================================================================*/
  3594. #ifdef FUTURE
  3595. /*
  3596. * obtain if requested service disturbs current audio state
  3597. */
  3598. static int obey_audio_state(u_char audio_state, u_char func,u_char subfunc)
  3599. {
  3600. switch (audio_state) /* audio status from controller */
  3601. {
  3602. case aud_11: /* "audio play in progress" */
  3603. case audx11:
  3604. switch (func) /* DOS command code */
  3605. {
  3606. case cmd_07: /* input flush */
  3607. case cmd_0d: /* open device */
  3608. case cmd_0e: /* close device */
  3609. case cmd_0c: /* ioctl output */
  3610. return (1);
  3611. case cmd_03: /* ioctl input */
  3612. switch (subfunc)
  3613. /* DOS ioctl input subfunction */
  3614. {
  3615. case cxi_00:
  3616. case cxi_06:
  3617. case cxi_09:
  3618. return (1);
  3619. default:
  3620. return (ERROR15);
  3621. }
  3622. return (1);
  3623. default:
  3624. return (ERROR15);
  3625. }
  3626. return (1);
  3627. case aud_12: /* "audio play paused" */
  3628. case audx12:
  3629. return (1);
  3630. default:
  3631. return (2);
  3632. }
  3633. }
  3634. /*==========================================================================*/
  3635. /* allowed is only
  3636. * ioctl_o, flush_input, open_device, close_device,
  3637. * tell_address, tell_volume, tell_capabiliti,
  3638. * tell_framesize, tell_CD_changed, tell_audio_posi
  3639. */
  3640. static int check_allowed1(u_char func1, u_char func2)
  3641. {
  3642. #if 000
  3643. if (func1==ioctl_o) return (0);
  3644. if (func1==read_long) return (-1);
  3645. if (func1==read_long_prefetch) return (-1);
  3646. if (func1==seek) return (-1);
  3647. if (func1==audio_play) return (-1);
  3648. if (func1==audio_pause) return (-1);
  3649. if (func1==audio_resume) return (-1);
  3650. if (func1!=ioctl_i) return (0);
  3651. if (func2==tell_SubQ_run_tot) return (-1);
  3652. if (func2==tell_cdsize) return (-1);
  3653. if (func2==tell_TocDescrip) return (-1);
  3654. if (func2==tell_TocEntry) return (-1);
  3655. if (func2==tell_subQ_info) return (-1);
  3656. if (fam1_drive) if (func2==tell_SubChanInfo) return (-1);
  3657. if (func2==tell_UPC) return (-1);
  3658. #else
  3659. return (0);
  3660. #endif
  3661. }
  3662. /*==========================================================================*/
  3663. static int check_allowed2(u_char func1, u_char func2)
  3664. {
  3665. #if 000
  3666. if (func1==read_long) return (-1);
  3667. if (func1==read_long_prefetch) return (-1);
  3668. if (func1==seek) return (-1);
  3669. if (func1==audio_play) return (-1);
  3670. if (func1!=ioctl_o) return (0);
  3671. if (fam1_drive)
  3672. {
  3673. if (func2==EjectDisk) return (-1);
  3674. if (func2==CloseTray) return (-1);
  3675. }
  3676. #else
  3677. return (0);
  3678. #endif
  3679. }
  3680. /*==========================================================================*/
  3681. static int check_allowed3(u_char func1, u_char func2)
  3682. {
  3683. #if 000
  3684. if (func1==ioctl_i)
  3685. {
  3686. if (func2==tell_address) return (0);
  3687. if (func2==tell_capabiliti) return (0);
  3688. if (func2==tell_CD_changed) return (0);
  3689. if (fam0L_drive) if (func2==tell_SubChanInfo) return (0);
  3690. return (-1);
  3691. }
  3692. if (func1==ioctl_o)
  3693. {
  3694. if (func2==DriveReset) return (0);
  3695. if (fam0L_drive)
  3696. {
  3697. if (func2==EjectDisk) return (0);
  3698. if (func2==LockDoor) return (0);
  3699. if (func2==CloseTray) return (0);
  3700. }
  3701. return (-1);
  3702. }
  3703. if (func1==flush_input) return (-1);
  3704. if (func1==read_long) return (-1);
  3705. if (func1==read_long_prefetch) return (-1);
  3706. if (func1==seek) return (-1);
  3707. if (func1==audio_play) return (-1);
  3708. if (func1==audio_pause) return (-1);
  3709. if (func1==audio_resume) return (-1);
  3710. #else
  3711. return (0);
  3712. #endif
  3713. }
  3714. /*==========================================================================*/
  3715. static int seek_pos_audio_end(void)
  3716. {
  3717. int i;
  3718. i=msf2blk(current_drive->pos_audio_end)-1;
  3719. if (i<0) return (-1);
  3720. i=cc_Seek(i,0);
  3721. return (i);
  3722. }
  3723. #endif /* FUTURE */
  3724. /*==========================================================================*/
  3725. static int ReadToC(void)
  3726. {
  3727. int i, j;
  3728. current_drive->diskstate_flags &= ~toc_bit;
  3729. current_drive->ored_ctl_adr=0;
  3730. /* special handling of CD-I HE */
  3731. if ((current_drive->n_first_track == 2 && current_drive->n_last_track == 2) ||
  3732. current_drive->xa_byte == 0x10)
  3733. {
  3734. current_drive->TocBuffer[1].nixbyte=0;
  3735. current_drive->TocBuffer[1].ctl_adr=0x40;
  3736. current_drive->TocBuffer[1].number=1;
  3737. current_drive->TocBuffer[1].format=0;
  3738. current_drive->TocBuffer[1].address=blk2msf(0);
  3739. current_drive->ored_ctl_adr |= 0x40;
  3740. current_drive->n_first_track = 1;
  3741. current_drive->n_last_track = 1;
  3742. current_drive->xa_byte = 0x10;
  3743. j = 2;
  3744. } else
  3745. for (j=current_drive->n_first_track;j<=current_drive->n_last_track;j++)
  3746. {
  3747. i=cc_ReadTocEntry(j);
  3748. if (i<0)
  3749. {
  3750. msg(DBG_INF,"cc_ReadTocEntry(%d) returns %d.\n",j,i);
  3751. return (i);
  3752. }
  3753. current_drive->TocBuffer[j].nixbyte=current_drive->TocEnt_nixbyte;
  3754. current_drive->TocBuffer[j].ctl_adr=current_drive->TocEnt_ctl_adr;
  3755. current_drive->TocBuffer[j].number=current_drive->TocEnt_number;
  3756. current_drive->TocBuffer[j].format=current_drive->TocEnt_format;
  3757. current_drive->TocBuffer[j].address=current_drive->TocEnt_address;
  3758. current_drive->ored_ctl_adr |= current_drive->TocEnt_ctl_adr;
  3759. }
  3760. /* fake entry for LeadOut Track */
  3761. current_drive->TocBuffer[j].nixbyte=0;
  3762. current_drive->TocBuffer[j].ctl_adr=0;
  3763. current_drive->TocBuffer[j].number=CDROM_LEADOUT;
  3764. current_drive->TocBuffer[j].format=0;
  3765. current_drive->TocBuffer[j].address=current_drive->size_msf;
  3766. current_drive->diskstate_flags |= toc_bit;
  3767. return (0);
  3768. }
  3769. /*==========================================================================*/
  3770. static int DiskInfo(void)
  3771. {
  3772. int i, j;
  3773. current_drive->mode=READ_M1;
  3774. #undef LOOP_COUNT
  3775. #define LOOP_COUNT 10 /* needed for some "old" drives */
  3776. msg(DBG_000,"DiskInfo entered.\n");
  3777. for (j=1;j<LOOP_COUNT;j++)
  3778. {
  3779. #if 0
  3780. i=SetSpeed();
  3781. if (i<0)
  3782. {
  3783. msg(DBG_INF,"DiskInfo: SetSpeed returns %d\n", i);
  3784. continue;
  3785. }
  3786. i=cc_ModeSense();
  3787. if (i<0)
  3788. {
  3789. msg(DBG_INF,"DiskInfo: cc_ModeSense returns %d\n", i);
  3790. continue;
  3791. }
  3792. #endif
  3793. i=cc_ReadCapacity();
  3794. if (i>=0) break;
  3795. msg(DBG_INF,"DiskInfo: ReadCapacity #%d returns %d\n", j, i);
  3796. #if 0
  3797. i=cc_DriveReset();
  3798. #endif
  3799. if (!fam0_drive && j == 2) break;
  3800. }
  3801. if (j==LOOP_COUNT) return (-33); /* give up */
  3802. i=cc_ReadTocDescr();
  3803. if (i<0)
  3804. {
  3805. msg(DBG_INF,"DiskInfo: ReadTocDescr returns %d\n", i);
  3806. return (i);
  3807. }
  3808. i=ReadToC();
  3809. if (i<0)
  3810. {
  3811. msg(DBG_INF,"DiskInfo: ReadToC returns %d\n", i);
  3812. return (i);
  3813. }
  3814. i=cc_CheckMultiSession();
  3815. if (i<0)
  3816. {
  3817. msg(DBG_INF,"DiskInfo: cc_CheckMultiSession returns %d\n", i);
  3818. return (i);
  3819. }
  3820. if (current_drive->f_multisession) current_drive->sbp_bufsiz=1; /* possibly a weird PhotoCD */
  3821. else current_drive->sbp_bufsiz=buffers;
  3822. i=cc_ReadTocEntry(current_drive->n_first_track);
  3823. if (i<0)
  3824. {
  3825. msg(DBG_INF,"DiskInfo: cc_ReadTocEntry(1) returns %d\n", i);
  3826. return (i);
  3827. }
  3828. i=cc_ReadUPC();
  3829. if (i<0) msg(DBG_INF,"DiskInfo: cc_ReadUPC returns %d\n", i);
  3830. if ((fam0L_drive) && (current_drive->xa_byte==0x20 || current_drive->xa_byte == 0x10))
  3831. {
  3832. /* XA disk with old drive */
  3833. cc_ModeSelect(CD_FRAMESIZE_RAW1);
  3834. cc_ModeSense();
  3835. }
  3836. if (famT_drive) cc_prep_mode_T();
  3837. msg(DBG_000,"DiskInfo done.\n");
  3838. return (0);
  3839. }
  3840. static int sbpcd_drive_status(struct cdrom_device_info *cdi, int slot_nr)
  3841. {
  3842. struct sbpcd_drive *p = cdi->handle;
  3843. int st;
  3844. if (CDSL_CURRENT != slot_nr) {
  3845. /* we have no changer support */
  3846. return -EINVAL;
  3847. }
  3848. cc_ReadStatus();
  3849. st=ResponseStatus();
  3850. if (st<0)
  3851. {
  3852. msg(DBG_INF,"sbpcd_drive_status: timeout.\n");
  3853. return (0);
  3854. }
  3855. msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
  3856. msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
  3857. msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
  3858. msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
  3859. msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
  3860. msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
  3861. #if 0
  3862. if (!(p->status_bits & p_door_closed)) return CDS_TRAY_OPEN;
  3863. if (p->status_bits & p_disk_ok) return CDS_DISC_OK;
  3864. if (p->status_bits & p_disk_in) return CDS_DRIVE_NOT_READY;
  3865. return CDS_NO_DISC;
  3866. #else
  3867. if (p->status_bits & p_spinning) return CDS_DISC_OK;
  3868. /* return CDS_TRAY_OPEN; */
  3869. return CDS_NO_DISC;
  3870. #endif
  3871. }
  3872. /*==========================================================================*/
  3873. #ifdef FUTURE
  3874. /*
  3875. * called always if driver gets entered
  3876. * returns 0 or ERROR2 or ERROR15
  3877. */
  3878. static int prepare(u_char func, u_char subfunc)
  3879. {
  3880. int i;
  3881. if (fam0L_drive)
  3882. {
  3883. i=inb(CDi_status);
  3884. if (i&s_attention) GetStatus();
  3885. }
  3886. else if (fam1_drive) GetStatus();
  3887. else if (fam2_drive) GetStatus();
  3888. else if (famT_drive) GetStatus();
  3889. if (current_drive->CD_changed==0xFF)
  3890. {
  3891. current_drive->diskstate_flags=0;
  3892. current_drive->audio_state=0;
  3893. if (!st_diskok)
  3894. {
  3895. i=check_allowed1(func,subfunc);
  3896. if (i<0) return (-2);
  3897. }
  3898. else
  3899. {
  3900. i=check_allowed3(func,subfunc);
  3901. if (i<0)
  3902. {
  3903. current_drive->CD_changed=1;
  3904. return (-15);
  3905. }
  3906. }
  3907. }
  3908. else
  3909. {
  3910. if (!st_diskok)
  3911. {
  3912. current_drive->diskstate_flags=0;
  3913. current_drive->audio_state=0;
  3914. i=check_allowed1(func,subfunc);
  3915. if (i<0) return (-2);
  3916. }
  3917. else
  3918. {
  3919. if (st_busy)
  3920. {
  3921. if (current_drive->audio_state!=audio_pausing)
  3922. {
  3923. i=check_allowed2(func,subfunc);
  3924. if (i<0) return (-2);
  3925. }
  3926. }
  3927. else
  3928. {
  3929. if (current_drive->audio_state==audio_playing) seek_pos_audio_end();
  3930. current_drive->audio_state=0;
  3931. }
  3932. if (!frame_size_valid)
  3933. {
  3934. i=DiskInfo();
  3935. if (i<0)
  3936. {
  3937. current_drive->diskstate_flags=0;
  3938. current_drive->audio_state=0;
  3939. i=check_allowed1(func,subfunc);
  3940. if (i<0) return (-2);
  3941. }
  3942. }
  3943. }
  3944. }
  3945. return (0);
  3946. }
  3947. #endif /* FUTURE */
  3948. /*==========================================================================*/
  3949. /*==========================================================================*/
  3950. /*
  3951. * Check the results of the "get status" command.
  3952. */
  3953. static int sbp_status(void)
  3954. {
  3955. int st;
  3956. st=ResponseStatus();
  3957. if (st<0)
  3958. {
  3959. msg(DBG_INF,"sbp_status: timeout.\n");
  3960. return (0);
  3961. }
  3962. if (!st_spinning) msg(DBG_SPI,"motor got off - ignoring.\n");
  3963. if (st_check)
  3964. {
  3965. msg(DBG_INF,"st_check detected - retrying.\n");
  3966. return (0);
  3967. }
  3968. if (!st_door_closed)
  3969. {
  3970. msg(DBG_INF,"door is open - retrying.\n");
  3971. return (0);
  3972. }
  3973. if (!st_caddy_in)
  3974. {
  3975. msg(DBG_INF,"disk removed - retrying.\n");
  3976. return (0);
  3977. }
  3978. if (!st_diskok)
  3979. {
  3980. msg(DBG_INF,"!st_diskok detected - retrying.\n");
  3981. return (0);
  3982. }
  3983. if (st_busy)
  3984. {
  3985. msg(DBG_INF,"st_busy detected - retrying.\n");
  3986. return (0);
  3987. }
  3988. return (1);
  3989. }
  3990. /*==========================================================================*/
  3991. static int sbpcd_get_last_session(struct cdrom_device_info *cdi, struct cdrom_multisession *ms_infp)
  3992. {
  3993. struct sbpcd_drive *p = cdi->handle;
  3994. ms_infp->addr_format = CDROM_LBA;
  3995. ms_infp->addr.lba = p->lba_multi;
  3996. if (p->f_multisession)
  3997. ms_infp->xa_flag=1; /* valid redirection address */
  3998. else
  3999. ms_infp->xa_flag=0; /* invalid redirection address */
  4000. return 0;
  4001. }
  4002. /*==========================================================================*/
  4003. /*==========================================================================*/
  4004. /*
  4005. * ioctl support
  4006. */
  4007. static int sbpcd_dev_ioctl(struct cdrom_device_info *cdi, u_int cmd,
  4008. u_long arg)
  4009. {
  4010. struct sbpcd_drive *p = cdi->handle;
  4011. int i;
  4012. msg(DBG_IO2,"ioctl(%s, 0x%08lX, 0x%08lX)\n", cdi->name, cmd, arg);
  4013. if (p->drv_id==-1) {
  4014. msg(DBG_INF, "ioctl: bad device: %s\n", cdi->name);
  4015. return (-ENXIO); /* no such drive */
  4016. }
  4017. down(&ioctl_read_sem);
  4018. if (p != current_drive)
  4019. switch_drive(p);
  4020. msg(DBG_IO2,"ioctl: device %s, request %04X\n",cdi->name,cmd);
  4021. switch (cmd) /* Sun-compatible */
  4022. {
  4023. case DDIOCSDBG: /* DDI Debug */
  4024. if (!capable(CAP_SYS_ADMIN)) RETURN_UP(-EPERM);
  4025. i=sbpcd_dbg_ioctl(arg,1);
  4026. RETURN_UP(i);
  4027. case CDROMRESET: /* hard reset the drive */
  4028. msg(DBG_IOC,"ioctl: CDROMRESET entered.\n");
  4029. i=DriveReset();
  4030. current_drive->audio_state=0;
  4031. RETURN_UP(i);
  4032. case CDROMREADMODE1:
  4033. msg(DBG_IOC,"ioctl: CDROMREADMODE1 requested.\n");
  4034. #ifdef SAFE_MIXED
  4035. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4036. #endif /* SAFE_MIXED */
  4037. cc_ModeSelect(CD_FRAMESIZE);
  4038. cc_ModeSense();
  4039. current_drive->mode=READ_M1;
  4040. RETURN_UP(0);
  4041. case CDROMREADMODE2: /* not usable at the moment */
  4042. msg(DBG_IOC,"ioctl: CDROMREADMODE2 requested.\n");
  4043. #ifdef SAFE_MIXED
  4044. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4045. #endif /* SAFE_MIXED */
  4046. cc_ModeSelect(CD_FRAMESIZE_RAW1);
  4047. cc_ModeSense();
  4048. current_drive->mode=READ_M2;
  4049. RETURN_UP(0);
  4050. case CDROMAUDIOBUFSIZ: /* configure the audio buffer size */
  4051. msg(DBG_IOC,"ioctl: CDROMAUDIOBUFSIZ entered.\n");
  4052. if (current_drive->sbp_audsiz>0) vfree(current_drive->aud_buf);
  4053. current_drive->aud_buf=NULL;
  4054. current_drive->sbp_audsiz=arg;
  4055. if (current_drive->sbp_audsiz>16)
  4056. {
  4057. current_drive->sbp_audsiz = 0;
  4058. RETURN_UP(current_drive->sbp_audsiz);
  4059. }
  4060. if (current_drive->sbp_audsiz>0)
  4061. {
  4062. current_drive->aud_buf=(u_char *) vmalloc(current_drive->sbp_audsiz*CD_FRAMESIZE_RAW);
  4063. if (current_drive->aud_buf==NULL)
  4064. {
  4065. msg(DBG_INF,"audio buffer (%d frames) not available.\n",current_drive->sbp_audsiz);
  4066. current_drive->sbp_audsiz=0;
  4067. }
  4068. else msg(DBG_INF,"audio buffer size: %d frames.\n",current_drive->sbp_audsiz);
  4069. }
  4070. RETURN_UP(current_drive->sbp_audsiz);
  4071. case CDROMREADAUDIO:
  4072. { /* start of CDROMREADAUDIO */
  4073. int i=0, j=0, frame, block=0;
  4074. u_int try=0;
  4075. u_long timeout;
  4076. u_char *p;
  4077. u_int data_tries = 0;
  4078. u_int data_waits = 0;
  4079. u_int data_retrying = 0;
  4080. int status_tries;
  4081. int error_flag;
  4082. msg(DBG_IOC,"ioctl: CDROMREADAUDIO entered.\n");
  4083. if (fam0_drive) RETURN_UP(-EINVAL);
  4084. if (famL_drive) RETURN_UP(-EINVAL);
  4085. if (famV_drive) RETURN_UP(-EINVAL);
  4086. if (famT_drive) RETURN_UP(-EINVAL);
  4087. #ifdef SAFE_MIXED
  4088. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4089. #endif /* SAFE_MIXED */
  4090. if (current_drive->aud_buf==NULL) RETURN_UP(-EINVAL);
  4091. if (copy_from_user(&read_audio, (void __user *)arg,
  4092. sizeof(struct cdrom_read_audio)))
  4093. RETURN_UP(-EFAULT);
  4094. if (read_audio.nframes < 0 || read_audio.nframes>current_drive->sbp_audsiz) RETURN_UP(-EINVAL);
  4095. if (!access_ok(VERIFY_WRITE, read_audio.buf,
  4096. read_audio.nframes*CD_FRAMESIZE_RAW))
  4097. RETURN_UP(-EFAULT);
  4098. if (read_audio.addr_format==CDROM_MSF) /* MSF-bin specification of where to start */
  4099. block=msf2lba(&read_audio.addr.msf.minute);
  4100. else if (read_audio.addr_format==CDROM_LBA) /* lba specification of where to start */
  4101. block=read_audio.addr.lba;
  4102. else RETURN_UP(-EINVAL);
  4103. #if 000
  4104. i=cc_SetSpeed(speed_150,0,0);
  4105. if (i) msg(DBG_AUD,"read_audio: SetSpeed error %d\n", i);
  4106. #endif
  4107. msg(DBG_AUD,"read_audio: lba: %d, msf: %06X\n",
  4108. block, blk2msf(block));
  4109. msg(DBG_AUD,"read_audio: before cc_ReadStatus.\n");
  4110. #if OLD_BUSY
  4111. while (busy_data) sbp_sleep(HZ/10); /* wait a bit */
  4112. busy_audio=1;
  4113. #endif /* OLD_BUSY */
  4114. error_flag=0;
  4115. for (data_tries=5; data_tries>0; data_tries--)
  4116. {
  4117. msg(DBG_AUD,"data_tries=%d ...\n", data_tries);
  4118. current_drive->mode=READ_AU;
  4119. cc_ModeSelect(CD_FRAMESIZE_RAW);
  4120. cc_ModeSense();
  4121. for (status_tries=3; status_tries > 0; status_tries--)
  4122. {
  4123. flags_cmd_out |= f_respo3;
  4124. cc_ReadStatus();
  4125. if (sbp_status() != 0) break;
  4126. if (st_check) cc_ReadError();
  4127. sbp_sleep(1); /* wait a bit, try again */
  4128. }
  4129. if (status_tries == 0)
  4130. {
  4131. msg(DBG_AUD,"read_audio: sbp_status: failed after 3 tries in line %d.\n", __LINE__);
  4132. continue;
  4133. }
  4134. msg(DBG_AUD,"read_audio: sbp_status: ok.\n");
  4135. flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
  4136. if (fam0L_drive)
  4137. {
  4138. flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  4139. cmd_type=READ_M2;
  4140. drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  4141. drvcmd[1]=(block>>16)&0x000000ff;
  4142. drvcmd[2]=(block>>8)&0x000000ff;
  4143. drvcmd[3]=block&0x000000ff;
  4144. drvcmd[4]=0;
  4145. drvcmd[5]=read_audio.nframes; /* # of frames */
  4146. drvcmd[6]=0;
  4147. }
  4148. else if (fam1_drive)
  4149. {
  4150. drvcmd[0]=CMD1_READ; /* "read frames", new drives */
  4151. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4152. drvcmd[4]=0;
  4153. drvcmd[5]=0;
  4154. drvcmd[6]=read_audio.nframes; /* # of frames */
  4155. }
  4156. else if (fam2_drive)
  4157. {
  4158. drvcmd[0]=CMD2_READ_XA2;
  4159. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4160. drvcmd[4]=0;
  4161. drvcmd[5]=read_audio.nframes; /* # of frames */
  4162. drvcmd[6]=0x11; /* raw mode */
  4163. }
  4164. else if (famT_drive) /* CD-55A: not tested yet */
  4165. {
  4166. }
  4167. msg(DBG_AUD,"read_audio: before giving \"read\" command.\n");
  4168. flags_cmd_out=f_putcmd;
  4169. response_count=0;
  4170. i=cmd_out();
  4171. if (i<0) msg(DBG_INF,"error giving READ AUDIO command: %0d\n", i);
  4172. sbp_sleep(0);
  4173. msg(DBG_AUD,"read_audio: after giving \"read\" command.\n");
  4174. for (frame=1;frame<2 && !error_flag; frame++)
  4175. {
  4176. try=maxtim_data;
  4177. for (timeout=jiffies+9*HZ; ; )
  4178. {
  4179. for ( ; try!=0;try--)
  4180. {
  4181. j=inb(CDi_status);
  4182. if (!(j&s_not_data_ready)) break;
  4183. if (!(j&s_not_result_ready)) break;
  4184. if (fam0L_drive) if (j&s_attention) break;
  4185. }
  4186. if (try != 0 || time_after_eq(jiffies, timeout)) break;
  4187. if (data_retrying == 0) data_waits++;
  4188. data_retrying = 1;
  4189. sbp_sleep(1);
  4190. try = 1;
  4191. }
  4192. if (try==0)
  4193. {
  4194. msg(DBG_INF,"read_audio: sbp_data: CDi_status timeout.\n");
  4195. error_flag++;
  4196. break;
  4197. }
  4198. msg(DBG_AUD,"read_audio: sbp_data: CDi_status ok.\n");
  4199. if (j&s_not_data_ready)
  4200. {
  4201. msg(DBG_INF, "read_audio: sbp_data: DATA_READY timeout.\n");
  4202. error_flag++;
  4203. break;
  4204. }
  4205. msg(DBG_AUD,"read_audio: before reading data.\n");
  4206. error_flag=0;
  4207. p = current_drive->aud_buf;
  4208. if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  4209. if (do_16bit)
  4210. {
  4211. u_short *p2 = (u_short *) p;
  4212. for (; (u_char *) p2 < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
  4213. {
  4214. if ((inb_p(CDi_status)&s_not_data_ready)) continue;
  4215. /* get one sample */
  4216. *p2++ = inw_p(CDi_data);
  4217. *p2++ = inw_p(CDi_data);
  4218. }
  4219. } else {
  4220. for (; p < current_drive->aud_buf + read_audio.nframes*CD_FRAMESIZE_RAW;)
  4221. {
  4222. if ((inb_p(CDi_status)&s_not_data_ready)) continue;
  4223. /* get one sample */
  4224. *p++ = inb_p(CDi_data);
  4225. *p++ = inb_p(CDi_data);
  4226. *p++ = inb_p(CDi_data);
  4227. *p++ = inb_p(CDi_data);
  4228. }
  4229. }
  4230. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  4231. data_retrying = 0;
  4232. }
  4233. msg(DBG_AUD,"read_audio: after reading data.\n");
  4234. if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  4235. {
  4236. msg(DBG_AUD,"read_audio: read aborted by drive\n");
  4237. #if 0000
  4238. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  4239. #else
  4240. i=cc_ReadError();
  4241. #endif
  4242. continue;
  4243. }
  4244. if (fam0L_drive)
  4245. {
  4246. i=maxtim_data;
  4247. for (timeout=jiffies+9*HZ; time_before(jiffies, timeout); timeout--)
  4248. {
  4249. for ( ;i!=0;i--)
  4250. {
  4251. j=inb(CDi_status);
  4252. if (!(j&s_not_data_ready)) break;
  4253. if (!(j&s_not_result_ready)) break;
  4254. if (j&s_attention) break;
  4255. }
  4256. if (i != 0 || time_after_eq(jiffies, timeout)) break;
  4257. sbp_sleep(0);
  4258. i = 1;
  4259. }
  4260. if (i==0) msg(DBG_AUD,"read_audio: STATUS TIMEOUT AFTER READ");
  4261. if (!(j&s_attention))
  4262. {
  4263. msg(DBG_AUD,"read_audio: sbp_data: timeout waiting DRV_ATTN - retrying\n");
  4264. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  4265. continue;
  4266. }
  4267. }
  4268. do
  4269. {
  4270. if (fam0L_drive) cc_ReadStatus();
  4271. i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
  4272. if (i<0) { msg(DBG_AUD,
  4273. "read_audio: cc_ReadStatus error after read: %02X\n",
  4274. current_drive->status_bits);
  4275. continue; /* FIXME */
  4276. }
  4277. }
  4278. while ((fam0L_drive)&&(!st_check)&&(!(i&p_success)));
  4279. if (st_check)
  4280. {
  4281. i=cc_ReadError();
  4282. msg(DBG_AUD,"read_audio: cc_ReadError was necessary after read: %02X\n",i);
  4283. continue;
  4284. }
  4285. if (copy_to_user(read_audio.buf,
  4286. current_drive->aud_buf,
  4287. read_audio.nframes * CD_FRAMESIZE_RAW))
  4288. RETURN_UP(-EFAULT);
  4289. msg(DBG_AUD,"read_audio: copy_to_user done.\n");
  4290. break;
  4291. }
  4292. cc_ModeSelect(CD_FRAMESIZE);
  4293. cc_ModeSense();
  4294. current_drive->mode=READ_M1;
  4295. #if OLD_BUSY
  4296. busy_audio=0;
  4297. #endif /* OLD_BUSY */
  4298. if (data_tries == 0)
  4299. {
  4300. msg(DBG_AUD,"read_audio: failed after 5 tries in line %d.\n", __LINE__);
  4301. RETURN_UP(-EIO);
  4302. }
  4303. msg(DBG_AUD,"read_audio: successful return.\n");
  4304. RETURN_UP(0);
  4305. } /* end of CDROMREADAUDIO */
  4306. default:
  4307. msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
  4308. RETURN_UP(-EINVAL);
  4309. } /* end switch(cmd) */
  4310. }
  4311. static int sbpcd_audio_ioctl(struct cdrom_device_info *cdi, u_int cmd,
  4312. void * arg)
  4313. {
  4314. struct sbpcd_drive *p = cdi->handle;
  4315. int i, st, j;
  4316. msg(DBG_IO2,"ioctl(%s, 0x%08lX, 0x%08p)\n", cdi->name, cmd, arg);
  4317. if (p->drv_id==-1) {
  4318. msg(DBG_INF, "ioctl: bad device: %s\n", cdi->name);
  4319. return (-ENXIO); /* no such drive */
  4320. }
  4321. down(&ioctl_read_sem);
  4322. if (p != current_drive)
  4323. switch_drive(p);
  4324. msg(DBG_IO2,"ioctl: device %s, request %04X\n",cdi->name,cmd);
  4325. switch (cmd) /* Sun-compatible */
  4326. {
  4327. case CDROMPAUSE: /* Pause the drive */
  4328. msg(DBG_IOC,"ioctl: CDROMPAUSE entered.\n");
  4329. /* pause the drive unit when it is currently in PLAY mode, */
  4330. /* or reset the starting and ending locations when in PAUSED mode. */
  4331. /* If applicable, at the next stopping point it reaches */
  4332. /* the drive will discontinue playing. */
  4333. switch (current_drive->audio_state)
  4334. {
  4335. case audio_playing:
  4336. if (famL_drive) i=cc_ReadSubQ();
  4337. else i=cc_Pause_Resume(1);
  4338. if (i<0) RETURN_UP(-EIO);
  4339. if (famL_drive) i=cc_Pause_Resume(1);
  4340. else i=cc_ReadSubQ();
  4341. if (i<0) RETURN_UP(-EIO);
  4342. current_drive->pos_audio_start=current_drive->SubQ_run_tot;
  4343. current_drive->audio_state=audio_pausing;
  4344. RETURN_UP(0);
  4345. case audio_pausing:
  4346. i=cc_Seek(current_drive->pos_audio_start,1);
  4347. if (i<0) RETURN_UP(-EIO);
  4348. RETURN_UP(0);
  4349. default:
  4350. RETURN_UP(-EINVAL);
  4351. }
  4352. case CDROMRESUME: /* resume paused audio play */
  4353. msg(DBG_IOC,"ioctl: CDROMRESUME entered.\n");
  4354. /* resume playing audio tracks when a previous PLAY AUDIO call has */
  4355. /* been paused with a PAUSE command. */
  4356. /* It will resume playing from the location saved in SubQ_run_tot. */
  4357. if (current_drive->audio_state!=audio_pausing) RETURN_UP(-EINVAL);
  4358. if (famL_drive)
  4359. i=cc_PlayAudio(current_drive->pos_audio_start,
  4360. current_drive->pos_audio_end);
  4361. else i=cc_Pause_Resume(3);
  4362. if (i<0) RETURN_UP(-EIO);
  4363. current_drive->audio_state=audio_playing;
  4364. RETURN_UP(0);
  4365. case CDROMPLAYMSF:
  4366. msg(DBG_IOC,"ioctl: CDROMPLAYMSF entered.\n");
  4367. #ifdef SAFE_MIXED
  4368. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4369. #endif /* SAFE_MIXED */
  4370. if (current_drive->audio_state==audio_playing)
  4371. {
  4372. i=cc_Pause_Resume(1);
  4373. if (i<0) RETURN_UP(-EIO);
  4374. i=cc_ReadSubQ();
  4375. if (i<0) RETURN_UP(-EIO);
  4376. current_drive->pos_audio_start=current_drive->SubQ_run_tot;
  4377. i=cc_Seek(current_drive->pos_audio_start,1);
  4378. }
  4379. memcpy(&msf, (void *) arg, sizeof(struct cdrom_msf));
  4380. /* values come as msf-bin */
  4381. current_drive->pos_audio_start = (msf.cdmsf_min0<<16) |
  4382. (msf.cdmsf_sec0<<8) |
  4383. msf.cdmsf_frame0;
  4384. current_drive->pos_audio_end = (msf.cdmsf_min1<<16) |
  4385. (msf.cdmsf_sec1<<8) |
  4386. msf.cdmsf_frame1;
  4387. msg(DBG_IOX,"ioctl: CDROMPLAYMSF %08X %08X\n",
  4388. current_drive->pos_audio_start,current_drive->pos_audio_end);
  4389. i=cc_PlayAudio(current_drive->pos_audio_start,current_drive->pos_audio_end);
  4390. if (i<0)
  4391. {
  4392. msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
  4393. DriveReset();
  4394. current_drive->audio_state=0;
  4395. RETURN_UP(-EIO);
  4396. }
  4397. current_drive->audio_state=audio_playing;
  4398. RETURN_UP(0);
  4399. case CDROMPLAYTRKIND: /* Play a track. This currently ignores index. */
  4400. msg(DBG_IOC,"ioctl: CDROMPLAYTRKIND entered.\n");
  4401. #ifdef SAFE_MIXED
  4402. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4403. #endif /* SAFE_MIXED */
  4404. if (current_drive->audio_state==audio_playing)
  4405. {
  4406. msg(DBG_IOX,"CDROMPLAYTRKIND: already audio_playing.\n");
  4407. #if 1
  4408. RETURN_UP(0); /* just let us play on */
  4409. #else
  4410. RETURN_UP(-EINVAL); /* play on, but say "error" */
  4411. #endif
  4412. }
  4413. memcpy(&ti,(void *) arg,sizeof(struct cdrom_ti));
  4414. msg(DBG_IOX,"ioctl: trk0: %d, ind0: %d, trk1:%d, ind1:%d\n",
  4415. ti.cdti_trk0,ti.cdti_ind0,ti.cdti_trk1,ti.cdti_ind1);
  4416. if (ti.cdti_trk0<current_drive->n_first_track) RETURN_UP(-EINVAL);
  4417. if (ti.cdti_trk0>current_drive->n_last_track) RETURN_UP(-EINVAL);
  4418. if (ti.cdti_trk1<ti.cdti_trk0) ti.cdti_trk1=ti.cdti_trk0;
  4419. if (ti.cdti_trk1>current_drive->n_last_track) ti.cdti_trk1=current_drive->n_last_track;
  4420. current_drive->pos_audio_start=current_drive->TocBuffer[ti.cdti_trk0].address;
  4421. current_drive->pos_audio_end=current_drive->TocBuffer[ti.cdti_trk1+1].address;
  4422. i=cc_PlayAudio(current_drive->pos_audio_start,current_drive->pos_audio_end);
  4423. if (i<0)
  4424. {
  4425. msg(DBG_INF,"ioctl: cc_PlayAudio returns %d\n",i);
  4426. DriveReset();
  4427. current_drive->audio_state=0;
  4428. RETURN_UP(-EIO);
  4429. }
  4430. current_drive->audio_state=audio_playing;
  4431. RETURN_UP(0);
  4432. case CDROMREADTOCHDR: /* Read the table of contents header */
  4433. msg(DBG_IOC,"ioctl: CDROMREADTOCHDR entered.\n");
  4434. tochdr.cdth_trk0=current_drive->n_first_track;
  4435. tochdr.cdth_trk1=current_drive->n_last_track;
  4436. memcpy((void *) arg, &tochdr, sizeof(struct cdrom_tochdr));
  4437. RETURN_UP(0);
  4438. case CDROMREADTOCENTRY: /* Read an entry in the table of contents */
  4439. msg(DBG_IOC,"ioctl: CDROMREADTOCENTRY entered.\n");
  4440. memcpy(&tocentry, (void *) arg, sizeof(struct cdrom_tocentry));
  4441. i=tocentry.cdte_track;
  4442. if (i==CDROM_LEADOUT) i=current_drive->n_last_track+1;
  4443. else if (i<current_drive->n_first_track||i>current_drive->n_last_track)
  4444. RETURN_UP(-EINVAL);
  4445. tocentry.cdte_adr=current_drive->TocBuffer[i].ctl_adr&0x0F;
  4446. tocentry.cdte_ctrl=(current_drive->TocBuffer[i].ctl_adr>>4)&0x0F;
  4447. tocentry.cdte_datamode=current_drive->TocBuffer[i].format;
  4448. if (tocentry.cdte_format==CDROM_MSF) /* MSF-bin required */
  4449. {
  4450. tocentry.cdte_addr.msf.minute=(current_drive->TocBuffer[i].address>>16)&0x00FF;
  4451. tocentry.cdte_addr.msf.second=(current_drive->TocBuffer[i].address>>8)&0x00FF;
  4452. tocentry.cdte_addr.msf.frame=current_drive->TocBuffer[i].address&0x00FF;
  4453. }
  4454. else if (tocentry.cdte_format==CDROM_LBA) /* blk required */
  4455. tocentry.cdte_addr.lba=msf2blk(current_drive->TocBuffer[i].address);
  4456. else RETURN_UP(-EINVAL);
  4457. memcpy((void *) arg, &tocentry, sizeof(struct cdrom_tocentry));
  4458. RETURN_UP(0);
  4459. case CDROMSTOP: /* Spin down the drive */
  4460. msg(DBG_IOC,"ioctl: CDROMSTOP entered.\n");
  4461. #ifdef SAFE_MIXED
  4462. if (current_drive->has_data>1) RETURN_UP(-EBUSY);
  4463. #endif /* SAFE_MIXED */
  4464. i=cc_Pause_Resume(1);
  4465. current_drive->audio_state=0;
  4466. #if 0
  4467. cc_DriveReset();
  4468. #endif
  4469. RETURN_UP(i);
  4470. case CDROMSTART: /* Spin up the drive */
  4471. msg(DBG_IOC,"ioctl: CDROMSTART entered.\n");
  4472. cc_SpinUp();
  4473. current_drive->audio_state=0;
  4474. RETURN_UP(0);
  4475. case CDROMVOLCTRL: /* Volume control */
  4476. msg(DBG_IOC,"ioctl: CDROMVOLCTRL entered.\n");
  4477. memcpy(&volctrl,(char *) arg,sizeof(volctrl));
  4478. current_drive->vol_chan0=0;
  4479. current_drive->vol_ctrl0=volctrl.channel0;
  4480. current_drive->vol_chan1=1;
  4481. current_drive->vol_ctrl1=volctrl.channel1;
  4482. i=cc_SetVolume();
  4483. RETURN_UP(0);
  4484. case CDROMVOLREAD: /* read Volume settings from drive */
  4485. msg(DBG_IOC,"ioctl: CDROMVOLREAD entered.\n");
  4486. st=cc_GetVolume();
  4487. if (st<0) RETURN_UP(st);
  4488. volctrl.channel0=current_drive->vol_ctrl0;
  4489. volctrl.channel1=current_drive->vol_ctrl1;
  4490. volctrl.channel2=0;
  4491. volctrl.channel2=0;
  4492. memcpy((void *)arg,&volctrl,sizeof(volctrl));
  4493. RETURN_UP(0);
  4494. case CDROMSUBCHNL: /* Get subchannel info */
  4495. msg(DBG_IOS,"ioctl: CDROMSUBCHNL entered.\n");
  4496. /* Bogus, I can do better than this! --AJK
  4497. if ((st_spinning)||(!subq_valid)) {
  4498. i=cc_ReadSubQ();
  4499. if (i<0) RETURN_UP(-EIO);
  4500. }
  4501. */
  4502. i=cc_ReadSubQ();
  4503. if (i<0) {
  4504. j=cc_ReadError(); /* clear out error status from drive */
  4505. current_drive->audio_state=CDROM_AUDIO_NO_STATUS;
  4506. /* get and set the disk state here,
  4507. probably not the right place, but who cares!
  4508. It makes it work properly! --AJK */
  4509. if (current_drive->CD_changed==0xFF) {
  4510. msg(DBG_000,"Disk changed detect\n");
  4511. current_drive->diskstate_flags &= ~cd_size_bit;
  4512. }
  4513. RETURN_UP(-EIO);
  4514. }
  4515. if (current_drive->CD_changed==0xFF) {
  4516. /* reread the TOC because the disk has changed! --AJK */
  4517. msg(DBG_000,"Disk changed STILL detected, rereading TOC!\n");
  4518. i=DiskInfo();
  4519. if(i==0) {
  4520. current_drive->CD_changed=0x00; /* cd has changed, procede, */
  4521. RETURN_UP(-EIO); /* and get TOC, etc on next try! --AJK */
  4522. } else {
  4523. RETURN_UP(-EIO); /* we weren't ready yet! --AJK */
  4524. }
  4525. }
  4526. memcpy(&SC, (void *) arg, sizeof(struct cdrom_subchnl));
  4527. /*
  4528. This virtual crap is very bogus!
  4529. It doesn't detect when the cd is done playing audio!
  4530. Lets do this right with proper hardware register reading!
  4531. */
  4532. cc_ReadStatus();
  4533. i=ResponseStatus();
  4534. msg(DBG_000,"Drive Status: door_locked =%d.\n", st_door_locked);
  4535. msg(DBG_000,"Drive Status: door_closed =%d.\n", st_door_closed);
  4536. msg(DBG_000,"Drive Status: caddy_in =%d.\n", st_caddy_in);
  4537. msg(DBG_000,"Drive Status: disk_ok =%d.\n", st_diskok);
  4538. msg(DBG_000,"Drive Status: spinning =%d.\n", st_spinning);
  4539. msg(DBG_000,"Drive Status: busy =%d.\n", st_busy);
  4540. /* st_busy indicates if it's _ACTUALLY_ playing audio */
  4541. switch (current_drive->audio_state)
  4542. {
  4543. case audio_playing:
  4544. if(st_busy==0) {
  4545. /* CD has stopped playing audio --AJK */
  4546. current_drive->audio_state=audio_completed;
  4547. SC.cdsc_audiostatus=CDROM_AUDIO_COMPLETED;
  4548. } else {
  4549. SC.cdsc_audiostatus=CDROM_AUDIO_PLAY;
  4550. }
  4551. break;
  4552. case audio_pausing:
  4553. SC.cdsc_audiostatus=CDROM_AUDIO_PAUSED;
  4554. break;
  4555. case audio_completed:
  4556. SC.cdsc_audiostatus=CDROM_AUDIO_COMPLETED;
  4557. break;
  4558. default:
  4559. SC.cdsc_audiostatus=CDROM_AUDIO_NO_STATUS;
  4560. break;
  4561. }
  4562. SC.cdsc_adr=current_drive->SubQ_ctl_adr;
  4563. SC.cdsc_ctrl=current_drive->SubQ_ctl_adr>>4;
  4564. SC.cdsc_trk=bcd2bin(current_drive->SubQ_trk);
  4565. SC.cdsc_ind=bcd2bin(current_drive->SubQ_pnt_idx);
  4566. if (SC.cdsc_format==CDROM_LBA)
  4567. {
  4568. SC.cdsc_absaddr.lba=msf2blk(current_drive->SubQ_run_tot);
  4569. SC.cdsc_reladdr.lba=msf2blk(current_drive->SubQ_run_trk);
  4570. }
  4571. else /* not only if (SC.cdsc_format==CDROM_MSF) */
  4572. {
  4573. SC.cdsc_absaddr.msf.minute=(current_drive->SubQ_run_tot>>16)&0x00FF;
  4574. SC.cdsc_absaddr.msf.second=(current_drive->SubQ_run_tot>>8)&0x00FF;
  4575. SC.cdsc_absaddr.msf.frame=current_drive->SubQ_run_tot&0x00FF;
  4576. SC.cdsc_reladdr.msf.minute=(current_drive->SubQ_run_trk>>16)&0x00FF;
  4577. SC.cdsc_reladdr.msf.second=(current_drive->SubQ_run_trk>>8)&0x00FF;
  4578. SC.cdsc_reladdr.msf.frame=current_drive->SubQ_run_trk&0x00FF;
  4579. }
  4580. memcpy((void *) arg, &SC, sizeof(struct cdrom_subchnl));
  4581. msg(DBG_IOS,"CDROMSUBCHNL: %1X %02X %08X %08X %02X %02X %06X %06X\n",
  4582. SC.cdsc_format,SC.cdsc_audiostatus,
  4583. SC.cdsc_adr,SC.cdsc_ctrl,
  4584. SC.cdsc_trk,SC.cdsc_ind,
  4585. SC.cdsc_absaddr,SC.cdsc_reladdr);
  4586. RETURN_UP(0);
  4587. default:
  4588. msg(DBG_IOC,"ioctl: unknown function request %04X\n", cmd);
  4589. RETURN_UP(-EINVAL);
  4590. } /* end switch(cmd) */
  4591. }
  4592. /*==========================================================================*/
  4593. /*
  4594. * Take care of the different block sizes between cdrom and Linux.
  4595. */
  4596. static void sbp_transfer(struct request *req)
  4597. {
  4598. long offs;
  4599. while ( (req->nr_sectors > 0) &&
  4600. (req->sector/4 >= current_drive->sbp_first_frame) &&
  4601. (req->sector/4 <= current_drive->sbp_last_frame) )
  4602. {
  4603. offs = (req->sector - current_drive->sbp_first_frame * 4) * 512;
  4604. memcpy(req->buffer, current_drive->sbp_buf + offs, 512);
  4605. req->nr_sectors--;
  4606. req->sector++;
  4607. req->buffer += 512;
  4608. }
  4609. }
  4610. /*==========================================================================*/
  4611. /*
  4612. * special end_request for sbpcd to solve CURRENT==NULL bug. (GTL)
  4613. * GTL = Gonzalo Tornaria <tornaria@cmat.edu.uy>
  4614. *
  4615. * This is a kludge so we don't need to modify end_request.
  4616. * We put the req we take out after INIT_REQUEST in the requests list,
  4617. * so that end_request will discard it.
  4618. *
  4619. * The bug could be present in other block devices, perhaps we
  4620. * should modify INIT_REQUEST and end_request instead, and
  4621. * change every block device..
  4622. *
  4623. * Could be a race here?? Could e.g. a timer interrupt schedule() us?
  4624. * If so, we should copy end_request here, and do it right.. (or
  4625. * modify end_request and the block devices).
  4626. *
  4627. * In any case, the race here would be much small than it was, and
  4628. * I couldn't reproduce..
  4629. *
  4630. * The race could be: suppose CURRENT==NULL. We put our req in the list,
  4631. * and we are scheduled. Other process takes over, and gets into
  4632. * do_sbpcd_request. It sees CURRENT!=NULL (it is == to our req), so
  4633. * proceeds. It ends, so CURRENT is now NULL.. Now we awake somewhere in
  4634. * end_request, but now CURRENT==NULL... oops!
  4635. *
  4636. */
  4637. #undef DEBUG_GTL
  4638. /*==========================================================================*/
  4639. /*
  4640. * I/O request routine, called from Linux kernel.
  4641. */
  4642. static void do_sbpcd_request(request_queue_t * q)
  4643. {
  4644. u_int block;
  4645. u_int nsect;
  4646. int status_tries, data_tries;
  4647. struct request *req;
  4648. struct sbpcd_drive *p;
  4649. #ifdef DEBUG_GTL
  4650. static int xx_nr=0;
  4651. int xnr;
  4652. #endif
  4653. request_loop:
  4654. #ifdef DEBUG_GTL
  4655. xnr=++xx_nr;
  4656. req = elv_next_request(q);
  4657. if (!req)
  4658. {
  4659. printk( "do_sbpcd_request[%di](NULL), Pid:%d, Time:%li\n",
  4660. xnr, current->pid, jiffies);
  4661. printk( "do_sbpcd_request[%do](NULL) end 0 (null), Time:%li\n",
  4662. xnr, jiffies);
  4663. return;
  4664. }
  4665. printk(" do_sbpcd_request[%di](%p:%ld+%ld), Pid:%d, Time:%li\n",
  4666. xnr, req, req->sector, req->nr_sectors, current->pid, jiffies);
  4667. #endif
  4668. req = elv_next_request(q); /* take out our request so no other */
  4669. if (!req)
  4670. return;
  4671. if (req -> sector == -1)
  4672. end_request(req, 0);
  4673. spin_unlock_irq(q->queue_lock);
  4674. down(&ioctl_read_sem);
  4675. if (rq_data_dir(elv_next_request(q)) != READ)
  4676. {
  4677. msg(DBG_INF, "bad cmd %d\n", req->cmd[0]);
  4678. goto err_done;
  4679. }
  4680. p = req->rq_disk->private_data;
  4681. #if OLD_BUSY
  4682. while (busy_audio) sbp_sleep(HZ); /* wait a bit */
  4683. busy_data=1;
  4684. #endif /* OLD_BUSY */
  4685. if (p->audio_state==audio_playing) goto err_done;
  4686. if (p != current_drive)
  4687. switch_drive(p);
  4688. block = req->sector; /* always numbered as 512-byte-pieces */
  4689. nsect = req->nr_sectors; /* always counted as 512-byte-pieces */
  4690. msg(DBG_BSZ,"read sector %d (%d sectors)\n", block, nsect);
  4691. #if 0
  4692. msg(DBG_MUL,"read LBA %d\n", block/4);
  4693. #endif
  4694. sbp_transfer(req);
  4695. /* if we satisfied the request from the buffer, we're done. */
  4696. if (req->nr_sectors == 0)
  4697. {
  4698. #ifdef DEBUG_GTL
  4699. printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 2, Time:%li\n",
  4700. xnr, req, req->sector, req->nr_sectors, jiffies);
  4701. #endif
  4702. up(&ioctl_read_sem);
  4703. spin_lock_irq(q->queue_lock);
  4704. end_request(req, 1);
  4705. goto request_loop;
  4706. }
  4707. #ifdef FUTURE
  4708. i=prepare(0,0); /* at moment not really a hassle check, but ... */
  4709. if (i!=0)
  4710. msg(DBG_INF,"\"prepare\" tells error %d -- ignored\n", i);
  4711. #endif /* FUTURE */
  4712. if (!st_spinning) cc_SpinUp();
  4713. for (data_tries=n_retries; data_tries > 0; data_tries--)
  4714. {
  4715. for (status_tries=3; status_tries > 0; status_tries--)
  4716. {
  4717. flags_cmd_out |= f_respo3;
  4718. cc_ReadStatus();
  4719. if (sbp_status() != 0) break;
  4720. if (st_check) cc_ReadError();
  4721. sbp_sleep(1); /* wait a bit, try again */
  4722. }
  4723. if (status_tries == 0)
  4724. {
  4725. msg(DBG_INF,"sbp_status: failed after 3 tries in line %d\n", __LINE__);
  4726. break;
  4727. }
  4728. sbp_read_cmd(req);
  4729. sbp_sleep(0);
  4730. if (sbp_data(req) != 0)
  4731. {
  4732. #ifdef SAFE_MIXED
  4733. current_drive->has_data=2; /* is really a data disk */
  4734. #endif /* SAFE_MIXED */
  4735. #ifdef DEBUG_GTL
  4736. printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 3, Time:%li\n",
  4737. xnr, req, req->sector, req->nr_sectors, jiffies);
  4738. #endif
  4739. up(&ioctl_read_sem);
  4740. spin_lock_irq(q->queue_lock);
  4741. end_request(req, 1);
  4742. goto request_loop;
  4743. }
  4744. }
  4745. err_done:
  4746. #if OLD_BUSY
  4747. busy_data=0;
  4748. #endif /* OLD_BUSY */
  4749. #ifdef DEBUG_GTL
  4750. printk(" do_sbpcd_request[%do](%p:%ld+%ld) end 4 (error), Time:%li\n",
  4751. xnr, req, req->sector, req->nr_sectors, jiffies);
  4752. #endif
  4753. up(&ioctl_read_sem);
  4754. sbp_sleep(0); /* wait a bit, try again */
  4755. spin_lock_irq(q->queue_lock);
  4756. end_request(req, 0);
  4757. goto request_loop;
  4758. }
  4759. /*==========================================================================*/
  4760. /*
  4761. * build and send the READ command.
  4762. */
  4763. static void sbp_read_cmd(struct request *req)
  4764. {
  4765. #undef OLD
  4766. int i;
  4767. int block;
  4768. current_drive->sbp_first_frame=current_drive->sbp_last_frame=-1; /* purge buffer */
  4769. current_drive->sbp_current = 0;
  4770. block=req->sector/4;
  4771. if (block+current_drive->sbp_bufsiz <= current_drive->CDsize_frm)
  4772. current_drive->sbp_read_frames = current_drive->sbp_bufsiz;
  4773. else
  4774. {
  4775. current_drive->sbp_read_frames=current_drive->CDsize_frm-block;
  4776. /* avoid reading past end of data */
  4777. if (current_drive->sbp_read_frames < 1)
  4778. {
  4779. msg(DBG_INF,"requested frame %d, CD size %d ???\n",
  4780. block, current_drive->CDsize_frm);
  4781. current_drive->sbp_read_frames=1;
  4782. }
  4783. }
  4784. flags_cmd_out = f_putcmd | f_respo2 | f_ResponseStatus | f_obey_p_check;
  4785. clr_cmdbuf();
  4786. if (famV_drive)
  4787. {
  4788. drvcmd[0]=CMDV_READ;
  4789. lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
  4790. bin2bcdx(&drvcmd[1]);
  4791. bin2bcdx(&drvcmd[2]);
  4792. bin2bcdx(&drvcmd[3]);
  4793. drvcmd[4]=current_drive->sbp_read_frames>>8;
  4794. drvcmd[5]=current_drive->sbp_read_frames&0xff;
  4795. drvcmd[6]=0x02; /* flag "msf-bcd" */
  4796. }
  4797. else if (fam0L_drive)
  4798. {
  4799. flags_cmd_out |= f_lopsta | f_getsta | f_bit1;
  4800. if (current_drive->xa_byte==0x20)
  4801. {
  4802. cmd_type=READ_M2;
  4803. drvcmd[0]=CMD0_READ_XA; /* "read XA frames", old drives */
  4804. drvcmd[1]=(block>>16)&0x0ff;
  4805. drvcmd[2]=(block>>8)&0x0ff;
  4806. drvcmd[3]=block&0x0ff;
  4807. drvcmd[4]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4808. drvcmd[5]=current_drive->sbp_read_frames&0x0ff;
  4809. }
  4810. else
  4811. {
  4812. drvcmd[0]=CMD0_READ; /* "read frames", old drives */
  4813. if (current_drive->drv_type>=drv_201)
  4814. {
  4815. lba2msf(block,&drvcmd[1]); /* msf-bcd format required */
  4816. bin2bcdx(&drvcmd[1]);
  4817. bin2bcdx(&drvcmd[2]);
  4818. bin2bcdx(&drvcmd[3]);
  4819. }
  4820. else
  4821. {
  4822. drvcmd[1]=(block>>16)&0x0ff;
  4823. drvcmd[2]=(block>>8)&0x0ff;
  4824. drvcmd[3]=block&0x0ff;
  4825. }
  4826. drvcmd[4]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4827. drvcmd[5]=current_drive->sbp_read_frames&0x0ff;
  4828. drvcmd[6]=(current_drive->drv_type<drv_201)?0:2; /* flag "lba or msf-bcd format" */
  4829. }
  4830. }
  4831. else if (fam1_drive)
  4832. {
  4833. drvcmd[0]=CMD1_READ;
  4834. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4835. drvcmd[5]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4836. drvcmd[6]=current_drive->sbp_read_frames&0x0ff;
  4837. }
  4838. else if (fam2_drive)
  4839. {
  4840. drvcmd[0]=CMD2_READ;
  4841. lba2msf(block,&drvcmd[1]); /* msf-bin format required */
  4842. drvcmd[4]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4843. drvcmd[5]=current_drive->sbp_read_frames&0x0ff;
  4844. drvcmd[6]=0x02;
  4845. }
  4846. else if (famT_drive)
  4847. {
  4848. drvcmd[0]=CMDT_READ;
  4849. drvcmd[2]=(block>>24)&0x0ff;
  4850. drvcmd[3]=(block>>16)&0x0ff;
  4851. drvcmd[4]=(block>>8)&0x0ff;
  4852. drvcmd[5]=block&0x0ff;
  4853. drvcmd[7]=(current_drive->sbp_read_frames>>8)&0x0ff;
  4854. drvcmd[8]=current_drive->sbp_read_frames&0x0ff;
  4855. }
  4856. flags_cmd_out=f_putcmd;
  4857. response_count=0;
  4858. i=cmd_out();
  4859. if (i<0) msg(DBG_INF,"error giving READ command: %0d\n", i);
  4860. return;
  4861. }
  4862. /*==========================================================================*/
  4863. /*
  4864. * Check the completion of the read-data command. On success, read
  4865. * the current_drive->sbp_bufsiz * 2048 bytes of data from the disk into buffer.
  4866. */
  4867. static int sbp_data(struct request *req)
  4868. {
  4869. int i=0, j=0, l, frame;
  4870. u_int try=0;
  4871. u_long timeout;
  4872. u_char *p;
  4873. u_int data_tries = 0;
  4874. u_int data_waits = 0;
  4875. u_int data_retrying = 0;
  4876. int error_flag;
  4877. int xa_count;
  4878. int max_latency;
  4879. int success;
  4880. int wait;
  4881. int duration;
  4882. error_flag=0;
  4883. success=0;
  4884. #if LONG_TIMING
  4885. max_latency=9*HZ;
  4886. #else
  4887. if (current_drive->f_multisession) max_latency=15*HZ;
  4888. else max_latency=5*HZ;
  4889. #endif
  4890. duration=jiffies;
  4891. for (frame=0;frame<current_drive->sbp_read_frames&&!error_flag; frame++)
  4892. {
  4893. SBPCD_CLI;
  4894. del_timer(&data_timer);
  4895. data_timer.expires=jiffies+max_latency;
  4896. timed_out_data=0;
  4897. add_timer(&data_timer);
  4898. while (!timed_out_data)
  4899. {
  4900. if (current_drive->f_multisession) try=maxtim_data*4;
  4901. else try=maxtim_data;
  4902. msg(DBG_000,"sbp_data: CDi_status loop: try=%d.\n",try);
  4903. for ( ; try!=0;try--)
  4904. {
  4905. j=inb(CDi_status);
  4906. if (!(j&s_not_data_ready)) break;
  4907. if (!(j&s_not_result_ready)) break;
  4908. if (fam0LV_drive) if (j&s_attention) break;
  4909. }
  4910. if (!(j&s_not_data_ready)) goto data_ready;
  4911. if (try==0)
  4912. {
  4913. if (data_retrying == 0) data_waits++;
  4914. data_retrying = 1;
  4915. msg(DBG_000,"sbp_data: CDi_status loop: sleeping.\n");
  4916. sbp_sleep(1);
  4917. try = 1;
  4918. }
  4919. }
  4920. msg(DBG_INF,"sbp_data: CDi_status loop expired.\n");
  4921. data_ready:
  4922. del_timer(&data_timer);
  4923. if (timed_out_data)
  4924. {
  4925. msg(DBG_INF,"sbp_data: CDi_status timeout (timed_out_data) (%02X).\n", j);
  4926. error_flag++;
  4927. }
  4928. if (try==0)
  4929. {
  4930. msg(DBG_INF,"sbp_data: CDi_status timeout (try=0) (%02X).\n", j);
  4931. error_flag++;
  4932. }
  4933. if (!(j&s_not_result_ready))
  4934. {
  4935. msg(DBG_INF, "sbp_data: RESULT_READY where DATA_READY awaited (%02X).\n", j);
  4936. response_count=20;
  4937. j=ResponseInfo();
  4938. j=inb(CDi_status);
  4939. }
  4940. if (j&s_not_data_ready)
  4941. {
  4942. if ((current_drive->ored_ctl_adr&0x40)==0)
  4943. msg(DBG_INF, "CD contains no data tracks.\n");
  4944. else msg(DBG_INF, "sbp_data: DATA_READY timeout (%02X).\n", j);
  4945. error_flag++;
  4946. }
  4947. SBPCD_STI;
  4948. if (error_flag) break;
  4949. msg(DBG_000, "sbp_data: beginning to read.\n");
  4950. p = current_drive->sbp_buf + frame * CD_FRAMESIZE;
  4951. if (sbpro_type==1) OUT(CDo_sel_i_d,1);
  4952. if (cmd_type==READ_M2) {
  4953. if (do_16bit) insw(CDi_data, xa_head_buf, CD_XA_HEAD>>1);
  4954. else insb(CDi_data, xa_head_buf, CD_XA_HEAD);
  4955. }
  4956. if (do_16bit) insw(CDi_data, p, CD_FRAMESIZE>>1);
  4957. else insb(CDi_data, p, CD_FRAMESIZE);
  4958. if (cmd_type==READ_M2) {
  4959. if (do_16bit) insw(CDi_data, xa_tail_buf, CD_XA_TAIL>>1);
  4960. else insb(CDi_data, xa_tail_buf, CD_XA_TAIL);
  4961. }
  4962. current_drive->sbp_current++;
  4963. if (sbpro_type==1) OUT(CDo_sel_i_d,0);
  4964. if (cmd_type==READ_M2)
  4965. {
  4966. for (xa_count=0;xa_count<CD_XA_HEAD;xa_count++)
  4967. sprintf(&msgbuf[xa_count*3], " %02X", xa_head_buf[xa_count]);
  4968. msgbuf[xa_count*3]=0;
  4969. msg(DBG_XA1,"xa head:%s\n", msgbuf);
  4970. }
  4971. data_retrying = 0;
  4972. data_tries++;
  4973. if (data_tries >= 1000)
  4974. {
  4975. msg(DBG_INF,"sbp_data() statistics: %d waits in %d frames.\n", data_waits, data_tries);
  4976. data_waits = data_tries = 0;
  4977. }
  4978. }
  4979. duration=jiffies-duration;
  4980. msg(DBG_TEA,"time to read %d frames: %d jiffies .\n",frame,duration);
  4981. if (famT_drive)
  4982. {
  4983. wait=8;
  4984. do
  4985. {
  4986. if (teac==2)
  4987. {
  4988. if ((i=CDi_stat_loop_T()) == -1) break;
  4989. }
  4990. else
  4991. {
  4992. sbp_sleep(1);
  4993. OUT(CDo_sel_i_d,0);
  4994. i=inb(CDi_status);
  4995. }
  4996. if (!(i&s_not_data_ready))
  4997. {
  4998. OUT(CDo_sel_i_d,1);
  4999. j=0;
  5000. do
  5001. {
  5002. if (do_16bit) i=inw(CDi_data);
  5003. else i=inb(CDi_data);
  5004. j++;
  5005. i=inb(CDi_status);
  5006. }
  5007. while (!(i&s_not_data_ready));
  5008. msg(DBG_TEA, "==========too much data (%d bytes/words)==============.\n", j);
  5009. }
  5010. if (!(i&s_not_result_ready))
  5011. {
  5012. OUT(CDo_sel_i_d,0);
  5013. l=0;
  5014. do
  5015. {
  5016. infobuf[l++]=inb(CDi_info);
  5017. i=inb(CDi_status);
  5018. }
  5019. while (!(i&s_not_result_ready));
  5020. if (infobuf[0]==0x00) success=1;
  5021. #if 1
  5022. for (j=0;j<l;j++) sprintf(&msgbuf[j*3], " %02X", infobuf[j]);
  5023. msgbuf[j*3]=0;
  5024. msg(DBG_TEA,"sbp_data info response:%s\n", msgbuf);
  5025. #endif
  5026. if (infobuf[0]==0x02)
  5027. {
  5028. error_flag++;
  5029. do
  5030. {
  5031. ++recursion;
  5032. if (recursion>1) msg(DBG_TEA,"cmd_out_T READ_ERR recursion (sbp_data): %d !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n",recursion);
  5033. else msg(DBG_TEA,"sbp_data: CMDT_READ_ERR necessary.\n");
  5034. clr_cmdbuf();
  5035. drvcmd[0]=CMDT_READ_ERR;
  5036. j=cmd_out_T(); /* !!! recursive here !!! */
  5037. --recursion;
  5038. sbp_sleep(1);
  5039. }
  5040. while (j<0);
  5041. current_drive->error_state=infobuf[2];
  5042. current_drive->b3=infobuf[3];
  5043. current_drive->b4=infobuf[4];
  5044. }
  5045. break;
  5046. }
  5047. else
  5048. {
  5049. #if 0
  5050. msg(DBG_TEA, "============= waiting for result=================.\n");
  5051. sbp_sleep(1);
  5052. #endif
  5053. }
  5054. }
  5055. while (wait--);
  5056. }
  5057. if (error_flag) /* must have been spurious D_RDY or (ATTN&&!D_RDY) */
  5058. {
  5059. msg(DBG_TEA, "================error flag: %d=================.\n", error_flag);
  5060. msg(DBG_INF,"sbp_data: read aborted by drive.\n");
  5061. #if 1
  5062. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  5063. #else
  5064. i=cc_ReadError();
  5065. #endif
  5066. return (0);
  5067. }
  5068. if (fam0LV_drive)
  5069. {
  5070. SBPCD_CLI;
  5071. i=maxtim_data;
  5072. for (timeout=jiffies+HZ; time_before(jiffies, timeout); timeout--)
  5073. {
  5074. for ( ;i!=0;i--)
  5075. {
  5076. j=inb(CDi_status);
  5077. if (!(j&s_not_data_ready)) break;
  5078. if (!(j&s_not_result_ready)) break;
  5079. if (j&s_attention) break;
  5080. }
  5081. if (i != 0 || time_after_eq(jiffies, timeout)) break;
  5082. sbp_sleep(0);
  5083. i = 1;
  5084. }
  5085. if (i==0) msg(DBG_INF,"status timeout after READ.\n");
  5086. if (!(j&s_attention))
  5087. {
  5088. msg(DBG_INF,"sbp_data: timeout waiting DRV_ATTN - retrying.\n");
  5089. i=cc_DriveReset(); /* ugly fix to prevent a hang */
  5090. SBPCD_STI;
  5091. return (0);
  5092. }
  5093. SBPCD_STI;
  5094. }
  5095. #if 0
  5096. if (!success)
  5097. #endif
  5098. do
  5099. {
  5100. if (fam0LV_drive) cc_ReadStatus();
  5101. #if 1
  5102. if (famT_drive) msg(DBG_TEA, "================before ResponseStatus=================.\n", i);
  5103. #endif
  5104. i=ResponseStatus(); /* builds status_bits, returns orig. status (old) or faked p_success (new) */
  5105. #if 1
  5106. if (famT_drive) msg(DBG_TEA, "================ResponseStatus: %d=================.\n", i);
  5107. #endif
  5108. if (i<0)
  5109. {
  5110. msg(DBG_INF,"bad cc_ReadStatus after read: %02X\n", current_drive->status_bits);
  5111. return (0);
  5112. }
  5113. }
  5114. while ((fam0LV_drive)&&(!st_check)&&(!(i&p_success)));
  5115. if (st_check)
  5116. {
  5117. i=cc_ReadError();
  5118. msg(DBG_INF,"cc_ReadError was necessary after read: %d\n",i);
  5119. return (0);
  5120. }
  5121. if (fatal_err)
  5122. {
  5123. fatal_err=0;
  5124. current_drive->sbp_first_frame=current_drive->sbp_last_frame=-1; /* purge buffer */
  5125. current_drive->sbp_current = 0;
  5126. msg(DBG_INF,"sbp_data: fatal_err - retrying.\n");
  5127. return (0);
  5128. }
  5129. current_drive->sbp_first_frame = req -> sector / 4;
  5130. current_drive->sbp_last_frame = current_drive->sbp_first_frame + current_drive->sbp_read_frames - 1;
  5131. sbp_transfer(req);
  5132. return (1);
  5133. }
  5134. /*==========================================================================*/
  5135. static int sbpcd_block_open(struct inode *inode, struct file *file)
  5136. {
  5137. struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data;
  5138. return cdrom_open(p->sbpcd_infop, inode, file);
  5139. }
  5140. static int sbpcd_block_release(struct inode *inode, struct file *file)
  5141. {
  5142. struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data;
  5143. return cdrom_release(p->sbpcd_infop, file);
  5144. }
  5145. static int sbpcd_block_ioctl(struct inode *inode, struct file *file,
  5146. unsigned cmd, unsigned long arg)
  5147. {
  5148. struct sbpcd_drive *p = inode->i_bdev->bd_disk->private_data;
  5149. return cdrom_ioctl(file, p->sbpcd_infop, inode, cmd, arg);
  5150. }
  5151. static int sbpcd_block_media_changed(struct gendisk *disk)
  5152. {
  5153. struct sbpcd_drive *p = disk->private_data;
  5154. return cdrom_media_changed(p->sbpcd_infop);
  5155. }
  5156. static struct block_device_operations sbpcd_bdops =
  5157. {
  5158. .owner = THIS_MODULE,
  5159. .open = sbpcd_block_open,
  5160. .release = sbpcd_block_release,
  5161. .ioctl = sbpcd_block_ioctl,
  5162. .media_changed = sbpcd_block_media_changed,
  5163. };
  5164. /*==========================================================================*/
  5165. /*
  5166. * Open the device special file. Check that a disk is in. Read TOC.
  5167. */
  5168. static int sbpcd_open(struct cdrom_device_info *cdi, int purpose)
  5169. {
  5170. struct sbpcd_drive *p = cdi->handle;
  5171. down(&ioctl_read_sem);
  5172. switch_drive(p);
  5173. /*
  5174. * try to keep an "open" counter here and lock the door if 0->1.
  5175. */
  5176. msg(DBG_LCK,"open_count: %d -> %d\n",
  5177. current_drive->open_count,current_drive->open_count+1);
  5178. if (++current_drive->open_count<=1)
  5179. {
  5180. int i;
  5181. i=LockDoor();
  5182. current_drive->open_count=1;
  5183. if (famT_drive) msg(DBG_TEA,"sbpcd_open: before i=DiskInfo();.\n");
  5184. i=DiskInfo();
  5185. if (famT_drive) msg(DBG_TEA,"sbpcd_open: after i=DiskInfo();.\n");
  5186. if ((current_drive->ored_ctl_adr&0x40)==0)
  5187. {
  5188. msg(DBG_INF,"CD contains no data tracks.\n");
  5189. #ifdef SAFE_MIXED
  5190. current_drive->has_data=0;
  5191. #endif /* SAFE_MIXED */
  5192. }
  5193. #ifdef SAFE_MIXED
  5194. else if (current_drive->has_data<1) current_drive->has_data=1;
  5195. #endif /* SAFE_MIXED */
  5196. }
  5197. if (!st_spinning) cc_SpinUp();
  5198. RETURN_UP(0);
  5199. }
  5200. /*==========================================================================*/
  5201. /*
  5202. * On close, we flush all sbp blocks from the buffer cache.
  5203. */
  5204. static void sbpcd_release(struct cdrom_device_info * cdi)
  5205. {
  5206. struct sbpcd_drive *p = cdi->handle;
  5207. if (p->drv_id==-1) {
  5208. msg(DBG_INF, "release: bad device: %s\n", cdi->name);
  5209. return;
  5210. }
  5211. down(&ioctl_read_sem);
  5212. switch_drive(p);
  5213. /*
  5214. * try to keep an "open" counter here and unlock the door if 1->0.
  5215. */
  5216. msg(DBG_LCK,"open_count: %d -> %d\n",
  5217. p->open_count,p->open_count-1);
  5218. if (p->open_count>-2) /* CDROMEJECT may have been done */
  5219. {
  5220. if (--p->open_count<=0)
  5221. {
  5222. p->sbp_first_frame=p->sbp_last_frame=-1;
  5223. if (p->audio_state!=audio_playing)
  5224. if (p->f_eject) cc_SpinDown();
  5225. p->diskstate_flags &= ~cd_size_bit;
  5226. p->open_count=0;
  5227. #ifdef SAFE_MIXED
  5228. p->has_data=0;
  5229. #endif /* SAFE_MIXED */
  5230. }
  5231. }
  5232. up(&ioctl_read_sem);
  5233. return ;
  5234. }
  5235. /*==========================================================================*/
  5236. /*
  5237. *
  5238. */
  5239. static int sbpcd_media_changed( struct cdrom_device_info *cdi, int disc_nr);
  5240. static struct cdrom_device_ops sbpcd_dops = {
  5241. .open = sbpcd_open,
  5242. .release = sbpcd_release,
  5243. .drive_status = sbpcd_drive_status,
  5244. .media_changed = sbpcd_media_changed,
  5245. .tray_move = sbpcd_tray_move,
  5246. .lock_door = sbpcd_lock_door,
  5247. .select_speed = sbpcd_select_speed,
  5248. .get_last_session = sbpcd_get_last_session,
  5249. .get_mcn = sbpcd_get_mcn,
  5250. .reset = sbpcd_reset,
  5251. .audio_ioctl = sbpcd_audio_ioctl,
  5252. .dev_ioctl = sbpcd_dev_ioctl,
  5253. .capability = CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK |
  5254. CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
  5255. CDC_MCN | CDC_PLAY_AUDIO | CDC_IOCTLS,
  5256. .n_minors = 1,
  5257. };
  5258. /*==========================================================================*/
  5259. /*
  5260. * accept "kernel command line" parameters
  5261. * (suggested by Peter MacDonald with SLS 1.03)
  5262. *
  5263. * This is only implemented for the first controller. Should be enough to
  5264. * allow installing with a "strange" distribution kernel.
  5265. *
  5266. * use: tell LILO:
  5267. * sbpcd=0x230,SoundBlaster
  5268. * or
  5269. * sbpcd=0x300,LaserMate
  5270. * or
  5271. * sbpcd=0x338,SoundScape
  5272. * or
  5273. * sbpcd=0x2C0,Teac16bit
  5274. *
  5275. * (upper/lower case sensitive here - but all-lowercase is ok!!!).
  5276. *
  5277. * the address value has to be the CDROM PORT ADDRESS -
  5278. * not the soundcard base address.
  5279. * For the SPEA/SoundScape setup, DO NOT specify the "configuration port"
  5280. * address, but the address which is really used for the CDROM (usually 8
  5281. * bytes above).
  5282. *
  5283. */
  5284. int sbpcd_setup(char *s)
  5285. {
  5286. #ifndef MODULE
  5287. int p[4];
  5288. (void)get_options(s, ARRAY_SIZE(p), p);
  5289. setup_done++;
  5290. msg(DBG_INI,"sbpcd_setup called with %04X,%s\n",p[1], s);
  5291. sbpro_type=0; /* default: "LaserMate" */
  5292. if (p[0]>1) sbpro_type=p[2];
  5293. else if (!strcmp(s,str_sb)) sbpro_type=1;
  5294. else if (!strcmp(s,str_sb_l)) sbpro_type=1;
  5295. else if (!strcmp(s,str_sp)) sbpro_type=2;
  5296. else if (!strcmp(s,str_sp_l)) sbpro_type=2;
  5297. else if (!strcmp(s,str_ss)) sbpro_type=2;
  5298. else if (!strcmp(s,str_ss_l)) sbpro_type=2;
  5299. else if (!strcmp(s,str_t16)) sbpro_type=3;
  5300. else if (!strcmp(s,str_t16_l)) sbpro_type=3;
  5301. if (p[0]>0) sbpcd_ioaddr=p[1];
  5302. if (p[0]>2) max_drives=p[3];
  5303. #else
  5304. sbpcd_ioaddr = sbpcd[0];
  5305. sbpro_type = sbpcd[1];
  5306. #endif
  5307. CDo_command=sbpcd_ioaddr;
  5308. CDi_info=sbpcd_ioaddr;
  5309. CDi_status=sbpcd_ioaddr+1;
  5310. CDo_sel_i_d=sbpcd_ioaddr+1;
  5311. CDo_reset=sbpcd_ioaddr+2;
  5312. CDo_enable=sbpcd_ioaddr+3;
  5313. f_16bit=0;
  5314. if ((sbpro_type==1)||(sbpro_type==3))
  5315. {
  5316. CDi_data=sbpcd_ioaddr;
  5317. if (sbpro_type==3)
  5318. {
  5319. f_16bit=1;
  5320. sbpro_type=1;
  5321. }
  5322. }
  5323. else CDi_data=sbpcd_ioaddr+2;
  5324. return 1;
  5325. }
  5326. __setup("sbpcd=", sbpcd_setup);
  5327. /*==========================================================================*/
  5328. /*
  5329. * Sequoia S-1000 CD-ROM Interface Configuration
  5330. * as used within SPEA Media FX, Ensonic SoundScape and some Reveal cards
  5331. * The soundcard has to get jumpered for the interface type "Panasonic"
  5332. * (not Sony or Mitsumi) and to get soft-configured for
  5333. * -> configuration port address
  5334. * -> CDROM port offset (num_ports): has to be 8 here. Possibly this
  5335. * offset value determines the interface type (none, Panasonic,
  5336. * Mitsumi, Sony).
  5337. * The interface uses a configuration port (0x320, 0x330, 0x340, 0x350)
  5338. * some bytes below the real CDROM address.
  5339. *
  5340. * For the Panasonic style (LaserMate) interface and the configuration
  5341. * port 0x330, we have to use an offset of 8; so, the real CDROM port
  5342. * address is 0x338.
  5343. */
  5344. static int __init config_spea(void)
  5345. {
  5346. /*
  5347. * base address offset between configuration port and CDROM port,
  5348. * this probably defines the interface type
  5349. * 2 (type=??): 0x00
  5350. * 8 (type=LaserMate):0x10
  5351. * 16 (type=??):0x20
  5352. * 32 (type=??):0x30
  5353. */
  5354. int n_ports=0x10;
  5355. int irq_number=0; /* off:0x00, 2/9:0x01, 7:0x03, 12:0x05, 15:0x07 */
  5356. int dma_channel=0; /* off: 0x00, 0:0x08, 1:0x18, 3:0x38, 5:0x58, 6:0x68 */
  5357. int dack_polarity=0; /* L:0x00, H:0x80 */
  5358. int drq_polarity=0x40; /* L:0x00, H:0x40 */
  5359. int i;
  5360. #define SPEA_REG_1 sbpcd_ioaddr-0x08+4
  5361. #define SPEA_REG_2 sbpcd_ioaddr-0x08+5
  5362. OUT(SPEA_REG_1,0xFF);
  5363. i=inb(SPEA_REG_1);
  5364. if (i!=0x0F)
  5365. {
  5366. msg(DBG_SEQ,"no SPEA interface at %04X present.\n", sbpcd_ioaddr);
  5367. return (-1); /* no interface found */
  5368. }
  5369. OUT(SPEA_REG_1,0x04);
  5370. OUT(SPEA_REG_2,0xC0);
  5371. OUT(SPEA_REG_1,0x05);
  5372. OUT(SPEA_REG_2,0x10|drq_polarity|dack_polarity);
  5373. #if 1
  5374. #define SPEA_PATTERN 0x80
  5375. #else
  5376. #define SPEA_PATTERN 0x00
  5377. #endif
  5378. OUT(SPEA_REG_1,0x06);
  5379. OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  5380. OUT(SPEA_REG_2,dma_channel|irq_number|SPEA_PATTERN);
  5381. OUT(SPEA_REG_1,0x09);
  5382. i=(inb(SPEA_REG_2)&0xCF)|n_ports;
  5383. OUT(SPEA_REG_2,i);
  5384. sbpro_type = 0; /* acts like a LaserMate interface now */
  5385. msg(DBG_SEQ,"found SoundScape interface at %04X.\n", sbpcd_ioaddr);
  5386. return (0);
  5387. }
  5388. /*==========================================================================*/
  5389. /*
  5390. * Test for presence of drive and initialize it.
  5391. * Called once at boot or load time.
  5392. */
  5393. /* FIXME: cleanups after failed allocations are too ugly for words */
  5394. #ifdef MODULE
  5395. int __init __sbpcd_init(void)
  5396. #else
  5397. int __init sbpcd_init(void)
  5398. #endif
  5399. {
  5400. int i=0, j=0;
  5401. int addr[2]={1, CDROM_PORT};
  5402. int port_index;
  5403. sti();
  5404. msg(DBG_INF,"sbpcd.c %s\n", VERSION);
  5405. #ifndef MODULE
  5406. #if DISTRIBUTION
  5407. if (!setup_done)
  5408. {
  5409. msg(DBG_INF,"Looking for Matsushita/Panasonic, CreativeLabs, Longshine, TEAC CD-ROM drives\n");
  5410. msg(DBG_INF,"= = = = = = = = = = W A R N I N G = = = = = = = = = =\n");
  5411. msg(DBG_INF,"Auto-Probing can cause a hang (f.e. touching an NE2000 card).\n");
  5412. msg(DBG_INF,"If that happens, you have to reboot and use the\n");
  5413. msg(DBG_INF,"LILO (kernel) command line feature like:\n");
  5414. msg(DBG_INF," LILO boot: ... sbpcd=0x230,SoundBlaster\n");
  5415. msg(DBG_INF,"or like:\n");
  5416. msg(DBG_INF," LILO boot: ... sbpcd=0x300,LaserMate\n");
  5417. msg(DBG_INF,"or like:\n");
  5418. msg(DBG_INF," LILO boot: ... sbpcd=0x338,SoundScape\n");
  5419. msg(DBG_INF,"with your REAL address.\n");
  5420. msg(DBG_INF,"= = = = = = = = = = END of WARNING = = = = = == = = =\n");
  5421. }
  5422. #endif /* DISTRIBUTION */
  5423. sbpcd[0]=sbpcd_ioaddr; /* possibly changed by kernel command line */
  5424. sbpcd[1]=sbpro_type; /* possibly changed by kernel command line */
  5425. #endif /* MODULE */
  5426. for (port_index=0;port_index<NUM_PROBE;port_index+=2)
  5427. {
  5428. addr[1]=sbpcd[port_index];
  5429. if (addr[1]==0) break;
  5430. if (check_region(addr[1],4))
  5431. {
  5432. msg(DBG_INF,"check_region: %03X is not free.\n",addr[1]);
  5433. continue;
  5434. }
  5435. if (sbpcd[port_index+1]==2) type=str_sp;
  5436. else if (sbpcd[port_index+1]==1) type=str_sb;
  5437. else if (sbpcd[port_index+1]==3) type=str_t16;
  5438. else type=str_lm;
  5439. sbpcd_setup((char *)type);
  5440. #if DISTRIBUTION
  5441. msg(DBG_INF,"Scanning 0x%X (%s)...\n", CDo_command, type);
  5442. #endif /* DISTRIBUTION */
  5443. if (sbpcd[port_index+1]==2)
  5444. {
  5445. i=config_spea();
  5446. if (i<0) continue;
  5447. }
  5448. #ifdef PATH_CHECK
  5449. if (check_card(addr[1])) continue;
  5450. #endif /* PATH_CHECK */
  5451. i=check_drives();
  5452. msg(DBG_INI,"check_drives done.\n");
  5453. if (i>=0) break; /* drive found */
  5454. } /* end of cycling through the set of possible I/O port addresses */
  5455. if (ndrives==0)
  5456. {
  5457. msg(DBG_INF, "No drive found.\n");
  5458. #ifdef MODULE
  5459. return -EIO;
  5460. #else
  5461. goto init_done;
  5462. #endif /* MODULE */
  5463. }
  5464. if (port_index>0)
  5465. {
  5466. msg(DBG_INF, "You should read Documentation/cdrom/sbpcd\n");
  5467. msg(DBG_INF, "and then configure sbpcd.h for your hardware.\n");
  5468. }
  5469. check_datarate();
  5470. msg(DBG_INI,"check_datarate done.\n");
  5471. for (j=0;j<NR_SBPCD;j++)
  5472. {
  5473. struct sbpcd_drive *p = D_S + j;
  5474. if (p->drv_id==-1)
  5475. continue;
  5476. switch_drive(p);
  5477. #if 1
  5478. if (!famL_drive) cc_DriveReset();
  5479. #endif
  5480. if (!st_spinning) cc_SpinUp();
  5481. p->sbp_first_frame = -1; /* First frame in buffer */
  5482. p->sbp_last_frame = -1; /* Last frame in buffer */
  5483. p->sbp_read_frames = 0; /* Number of frames being read to buffer */
  5484. p->sbp_current = 0; /* Frame being currently read */
  5485. p->CD_changed=1;
  5486. p->frame_size=CD_FRAMESIZE;
  5487. p->f_eject=0;
  5488. #if EJECT
  5489. if (!fam0_drive) p->f_eject=1;
  5490. #endif /* EJECT */
  5491. cc_ReadStatus();
  5492. i=ResponseStatus(); /* returns orig. status or p_busy_new */
  5493. if (famT_drive) i=ResponseStatus(); /* returns orig. status or p_busy_new */
  5494. if (i<0)
  5495. {
  5496. if (i!=-402)
  5497. msg(DBG_INF,"init: ResponseStatus returns %d.\n",i);
  5498. }
  5499. else
  5500. {
  5501. if (st_check)
  5502. {
  5503. i=cc_ReadError();
  5504. msg(DBG_INI,"init: cc_ReadError returns %d\n",i);
  5505. }
  5506. }
  5507. msg(DBG_INI,"init: first GetStatus: %d\n",i);
  5508. msg(DBG_LCS,"init: first GetStatus: error_byte=%d\n",
  5509. p->error_byte);
  5510. if (p->error_byte==aud_12)
  5511. {
  5512. timeout=jiffies+2*HZ;
  5513. do
  5514. {
  5515. i=GetStatus();
  5516. msg(DBG_INI,"init: second GetStatus: %02X\n",i);
  5517. msg(DBG_LCS,
  5518. "init: second GetStatus: error_byte=%d\n",
  5519. p->error_byte);
  5520. if (i<0) break;
  5521. if (!st_caddy_in) break;
  5522. }
  5523. while ((!st_diskok)||time_after(jiffies, timeout));
  5524. }
  5525. i=SetSpeed();
  5526. if (i>=0) p->CD_changed=1;
  5527. }
  5528. if (!request_region(CDo_command,4,major_name))
  5529. {
  5530. printk(KERN_WARNING "sbpcd: Unable to request region 0x%x\n", CDo_command);
  5531. return -EIO;
  5532. }
  5533. /*
  5534. * Turn on the CD audio channels.
  5535. * The addresses are obtained from SOUND_BASE (see sbpcd.h).
  5536. */
  5537. #if SOUND_BASE
  5538. OUT(MIXER_addr,MIXER_CD_Volume); /* select SB Pro mixer register */
  5539. OUT(MIXER_data,0xCC); /* one nibble per channel, max. value: 0xFF */
  5540. #endif /* SOUND_BASE */
  5541. if (register_blkdev(MAJOR_NR, major_name)) {
  5542. #ifdef MODULE
  5543. return -EIO;
  5544. #else
  5545. goto init_done;
  5546. #endif /* MODULE */
  5547. }
  5548. /*
  5549. * init error handling is broken beyond belief in this driver...
  5550. */
  5551. sbpcd_queue = blk_init_queue(do_sbpcd_request, &sbpcd_lock);
  5552. if (!sbpcd_queue) {
  5553. release_region(CDo_command,4);
  5554. unregister_blkdev(MAJOR_NR, major_name);
  5555. return -ENOMEM;
  5556. }
  5557. devfs_mk_dir("sbp");
  5558. for (j=0;j<NR_SBPCD;j++)
  5559. {
  5560. struct cdrom_device_info * sbpcd_infop;
  5561. struct gendisk *disk;
  5562. struct sbpcd_drive *p = D_S + j;
  5563. if (p->drv_id==-1) continue;
  5564. switch_drive(p);
  5565. #ifdef SAFE_MIXED
  5566. p->has_data=0;
  5567. #endif /* SAFE_MIXED */
  5568. /*
  5569. * allocate memory for the frame buffers
  5570. */
  5571. p->aud_buf=NULL;
  5572. p->sbp_audsiz=0;
  5573. p->sbp_bufsiz=buffers;
  5574. if (p->drv_type&drv_fam1)
  5575. if (READ_AUDIO>0)
  5576. p->sbp_audsiz = READ_AUDIO;
  5577. p->sbp_buf=(u_char *) vmalloc(buffers*CD_FRAMESIZE);
  5578. if (!p->sbp_buf) {
  5579. msg(DBG_INF,"data buffer (%d frames) not available.\n",
  5580. buffers);
  5581. if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
  5582. {
  5583. printk("Can't unregister %s\n", major_name);
  5584. }
  5585. release_region(CDo_command,4);
  5586. blk_cleanup_queue(sbpcd_queue);
  5587. return -EIO;
  5588. }
  5589. #ifdef MODULE
  5590. msg(DBG_INF,"data buffer size: %d frames.\n",buffers);
  5591. #endif /* MODULE */
  5592. if (p->sbp_audsiz>0)
  5593. {
  5594. p->aud_buf=(u_char *) vmalloc(p->sbp_audsiz*CD_FRAMESIZE_RAW);
  5595. if (p->aud_buf==NULL) msg(DBG_INF,"audio buffer (%d frames) not available.\n",p->sbp_audsiz);
  5596. else msg(DBG_INF,"audio buffer size: %d frames.\n",p->sbp_audsiz);
  5597. }
  5598. sbpcd_infop = vmalloc(sizeof (struct cdrom_device_info));
  5599. if (sbpcd_infop == NULL)
  5600. {
  5601. release_region(CDo_command,4);
  5602. blk_cleanup_queue(sbpcd_queue);
  5603. return -ENOMEM;
  5604. }
  5605. memset(sbpcd_infop, 0, sizeof(struct cdrom_device_info));
  5606. sbpcd_infop->ops = &sbpcd_dops;
  5607. sbpcd_infop->speed = 2;
  5608. sbpcd_infop->capacity = 1;
  5609. sprintf(sbpcd_infop->name, "sbpcd%d", j);
  5610. sbpcd_infop->handle = p;
  5611. p->sbpcd_infop = sbpcd_infop;
  5612. disk = alloc_disk(1);
  5613. disk->major = MAJOR_NR;
  5614. disk->first_minor = j;
  5615. disk->fops = &sbpcd_bdops;
  5616. strcpy(disk->disk_name, sbpcd_infop->name);
  5617. disk->flags = GENHD_FL_CD;
  5618. sprintf(disk->devfs_name, "sbp/c0t%d", p->drv_id);
  5619. p->disk = disk;
  5620. if (register_cdrom(sbpcd_infop))
  5621. {
  5622. printk(" sbpcd: Unable to register with Uniform CD-ROm driver\n");
  5623. }
  5624. disk->private_data = p;
  5625. disk->queue = sbpcd_queue;
  5626. add_disk(disk);
  5627. }
  5628. blk_queue_hardsect_size(sbpcd_queue, CD_FRAMESIZE);
  5629. #ifndef MODULE
  5630. init_done:
  5631. #endif
  5632. return 0;
  5633. }
  5634. /*==========================================================================*/
  5635. #ifdef MODULE
  5636. void sbpcd_exit(void)
  5637. {
  5638. int j;
  5639. if ((unregister_blkdev(MAJOR_NR, major_name) == -EINVAL))
  5640. {
  5641. msg(DBG_INF, "What's that: can't unregister %s.\n", major_name);
  5642. return;
  5643. }
  5644. release_region(CDo_command,4);
  5645. blk_cleanup_queue(sbpcd_queue);
  5646. for (j=0;j<NR_SBPCD;j++)
  5647. {
  5648. if (D_S[j].drv_id==-1) continue;
  5649. del_gendisk(D_S[j].disk);
  5650. put_disk(D_S[j].disk);
  5651. devfs_remove("sbp/c0t%d", j);
  5652. vfree(D_S[j].sbp_buf);
  5653. if (D_S[j].sbp_audsiz>0) vfree(D_S[j].aud_buf);
  5654. if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
  5655. {
  5656. msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
  5657. return;
  5658. }
  5659. vfree(D_S[j].sbpcd_infop);
  5660. }
  5661. devfs_remove("sbp");
  5662. msg(DBG_INF, "%s module released.\n", major_name);
  5663. }
  5664. module_init(__sbpcd_init) /*HACK!*/;
  5665. module_exit(sbpcd_exit);
  5666. #endif /* MODULE */
  5667. static int sbpcd_media_changed(struct cdrom_device_info *cdi, int disc_nr)
  5668. {
  5669. struct sbpcd_drive *p = cdi->handle;
  5670. msg(DBG_CHK,"media_check (%s) called\n", cdi->name);
  5671. if (p->CD_changed==0xFF)
  5672. {
  5673. p->CD_changed=0;
  5674. msg(DBG_CHK,"medium changed (drive %s)\n", cdi->name);
  5675. current_drive->diskstate_flags &= ~toc_bit;
  5676. /* we *don't* need invalidate here, it's done by caller */
  5677. current_drive->diskstate_flags &= ~cd_size_bit;
  5678. #ifdef SAFE_MIXED
  5679. current_drive->has_data=0;
  5680. #endif /* SAFE_MIXED */
  5681. return (1);
  5682. }
  5683. else
  5684. return (0);
  5685. }
  5686. MODULE_LICENSE("GPL");
  5687. /* FIXME: Old modules.conf claims MATSUSHITA_CDROM2_MAJOR and CDROM3, but
  5688. AFAICT this doesn't support those majors, so why? --RR 30 Jul 2003 */
  5689. MODULE_ALIAS_BLOCKDEV_MAJOR(MATSUSHITA_CDROM_MAJOR);
  5690. /*==========================================================================*/
  5691. /*
  5692. * Overrides for Emacs so that we follow Linus's tabbing style.
  5693. * Emacs will notice this stuff at the end of the file and automatically
  5694. * adjust the settings for this buffer only. This must remain at the end
  5695. * of the file.
  5696. * ---------------------------------------------------------------------------
  5697. * Local variables:
  5698. * c-indent-level: 8
  5699. * c-brace-imaginary-offset: 0
  5700. * c-brace-offset: -8
  5701. * c-argdecl-indent: 8
  5702. * c-label-offset: -8
  5703. * c-continued-statement-offset: 8
  5704. * c-continued-brace-offset: 0
  5705. * End:
  5706. */