PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/cdrom/aztcd.c

https://bitbucket.org/evzijst/gittest
C | 2494 lines | 1959 code | 192 blank | 343 comment | 464 complexity | 8208f37e7a0ee868c3fbdee60ba9d725 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. #define AZT_VERSION "2.60"
  2. /* $Id: aztcd.c,v 2.60 1997/11/29 09:51:19 root Exp root $
  3. linux/drivers/block/aztcd.c - Aztech CD268 CDROM driver
  4. Copyright (C) 1994-98 Werner Zimmermann(Werner.Zimmermann@fht-esslingen.de)
  5. based on Mitsumi CDROM driver by Martin Hariss and preworks by
  6. Eberhard Moenkeberg; contains contributions by Joe Nardone and Robby
  7. Schirmer.
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. HISTORY
  20. V0.0 Adaption to Aztech CD268-01A Version 1.3
  21. Version is PRE_ALPHA, unresolved points:
  22. 1. I use busy wait instead of timer wait in STEN_LOW,DTEN_LOW
  23. thus driver causes CPU overhead and is very slow
  24. 2. could not find a way to stop the drive, when it is
  25. in data read mode, therefore I had to set
  26. msf.end.min/sec/frame to 0:0:1 (in azt_poll); so only one
  27. frame can be read in sequence, this is also the reason for
  28. 3. getting 'timeout in state 4' messages, but nevertheless
  29. it works
  30. W.Zimmermann, Oct. 31, 1994
  31. V0.1 Version is ALPHA, problems #2 and #3 resolved.
  32. W.Zimmermann, Nov. 3, 1994
  33. V0.2 Modification to some comments, debugging aids for partial test
  34. with Borland C under DOS eliminated. Timer interrupt wait
  35. STEN_LOW_WAIT additionally to busy wait for STEN_LOW implemented;
  36. use it only for the 'slow' commands (ACMD_GET_Q_CHANNEL, ACMD_
  37. SEEK_TO_LEAD_IN), all other commands are so 'fast', that busy
  38. waiting seems better to me than interrupt rescheduling.
  39. Besides that, when used in the wrong place, STEN_LOW_WAIT causes
  40. kernel panic.
  41. In function aztPlay command ACMD_PLAY_AUDIO added, should make
  42. audio functions work. The Aztech drive needs different commands
  43. to read data tracks and play audio tracks.
  44. W.Zimmermann, Nov. 8, 1994
  45. V0.3 Recognition of missing drive during boot up improved (speeded up).
  46. W.Zimmermann, Nov. 13, 1994
  47. V0.35 Rewrote the control mechanism in azt_poll (formerly mcd_poll)
  48. including removal of all 'goto' commands. :-);
  49. J. Nardone, Nov. 14, 1994
  50. V0.4 Renamed variables and constants to 'azt' instead of 'mcd'; had
  51. to make some "compatibility" defines in azt.h; please note,
  52. that the source file was renamed to azt.c, the include file to
  53. azt.h
  54. Speeded up drive recognition during init (will be a little bit
  55. slower than before if no drive is installed!); suggested by
  56. Robby Schirmer.
  57. read_count declared volatile and set to AZT_BUF_SIZ to make
  58. drive faster (now 300kB/sec, was 60kB/sec before, measured
  59. by 'time dd if=/dev/cdrom of=/dev/null bs=2048 count=4096';
  60. different AZT_BUF_SIZes were test, above 16 no further im-
  61. provement seems to be possible; suggested by E.Moenkeberg.
  62. W.Zimmermann, Nov. 18, 1994
  63. V0.42 Included getAztStatus command in GetQChannelInfo() to allow
  64. reading Q-channel info on audio disks, if drive is stopped,
  65. and some other bug fixes in the audio stuff, suggested by
  66. Robby Schirmer.
  67. Added more ioctls (reading data in mode 1 and mode 2).
  68. Completely removed the old azt_poll() routine.
  69. Detection of ORCHID CDS-3110 in aztcd_init implemented.
  70. Additional debugging aids (see the readme file).
  71. W.Zimmermann, Dec. 9, 1994
  72. V0.50 Autodetection of drives implemented.
  73. W.Zimmermann, Dec. 12, 1994
  74. V0.52 Prepared for including in the standard kernel, renamed most
  75. variables to contain 'azt', included autoconf.h
  76. W.Zimmermann, Dec. 16, 1994
  77. V0.6 Version for being included in the standard Linux kernel.
  78. Renamed source and header file to aztcd.c and aztcd.h
  79. W.Zimmermann, Dec. 24, 1994
  80. V0.7 Changed VERIFY_READ to VERIFY_WRITE in aztcd_ioctl, case
  81. CDROMREADMODE1 and CDROMREADMODE2; bug fix in the ioctl,
  82. which causes kernel crashes when playing audio, changed
  83. include-files (config.h instead of autoconf.h, removed
  84. delay.h)
  85. W.Zimmermann, Jan. 8, 1995
  86. V0.72 Some more modifications for adaption to the standard kernel.
  87. W.Zimmermann, Jan. 16, 1995
  88. V0.80 aztcd is now part of the standard kernel since version 1.1.83.
  89. Modified the SET_TIMER and CLEAR_TIMER macros to comply with
  90. the new timer scheme.
  91. W.Zimmermann, Jan. 21, 1995
  92. V0.90 Included CDROMVOLCTRL, but with my Aztech drive I can only turn
  93. the channels on and off. If it works better with your drive,
  94. please mail me. Also implemented ACMD_CLOSE for CDROMSTART.
  95. W.Zimmermann, Jan. 24, 1995
  96. V1.00 Implemented close and lock tray commands. Patches supplied by
  97. Frank Racis
  98. Added support for loadable MODULEs, so aztcd can now also be
  99. loaded by insmod and removed by rmmod during run time
  100. Werner Zimmermann, Mar. 24, 95
  101. V1.10 Implemented soundcard configuration for Orchid CDS-3110 drives
  102. connected to Soundwave32 cards. Release for LST 2.1.
  103. (still experimental)
  104. Werner Zimmermann, May 8, 95
  105. V1.20 Implemented limited support for DOSEMU0.60's cdrom.c. Now it works, but
  106. sometimes DOSEMU may hang for 30 seconds or so. A fully functional ver-
  107. sion needs an update of Dosemu0.60's cdrom.c, which will come with the
  108. next revision of Dosemu.
  109. Also Soundwave32 support now works.
  110. Werner Zimmermann, May 22, 95
  111. V1.30 Auto-eject feature. Inspired by Franc Racis (racis@psu.edu)
  112. Werner Zimmermann, July 4, 95
  113. V1.40 Started multisession support. Implementation copied from mcdx.c
  114. by Heiko Schlittermann. Not tested yet.
  115. Werner Zimmermann, July 15, 95
  116. V1.50 Implementation of ioctl CDROMRESET, continued multisession, began
  117. XA, but still untested. Heavy modifications to drive status de-
  118. tection.
  119. Werner Zimmermann, July 25, 95
  120. V1.60 XA support now should work. Speeded up drive recognition in cases,
  121. where no drive is installed.
  122. Werner Zimmermann, August 8, 1995
  123. V1.70 Multisession support now is completed, but there is still not
  124. enough testing done. If you can test it, please contact me. For
  125. details please read Documentation/cdrom/aztcd
  126. Werner Zimmermann, August 19, 1995
  127. V1.80 Modification to suit the new kernel boot procedure introduced
  128. with kernel 1.3.33. Will definitely not work with older kernels.
  129. Programming done by Linus himself.
  130. Werner Zimmermann, October 11, 1995
  131. V1.90 Support for Conrad TXC drives, thank's to Jochen Kunz and Olaf Kaluza.
  132. Werner Zimmermann, October 21, 1995
  133. V2.00 Changed #include "blk.h" to <linux/blk.h> as the directory
  134. structure was changed. README.aztcd is now /usr/src/docu-
  135. mentation/cdrom/aztcd
  136. Werner Zimmermann, November 10, 95
  137. V2.10 Started to modify azt_poll to prevent reading beyond end of
  138. tracks.
  139. Werner Zimmermann, December 3, 95
  140. V2.20 Changed some comments
  141. Werner Zimmermann, April 1, 96
  142. V2.30 Implemented support for CyCDROM CR520, CR940, Code for CR520
  143. delivered by H.Berger with preworks by E.Moenkeberg.
  144. Werner Zimmermann, April 29, 96
  145. V2.40 Reorganized the placement of functions in the source code file
  146. to reflect the layered approach; did not actually change code
  147. Werner Zimmermann, May 1, 96
  148. V2.50 Heiko Eissfeldt suggested to remove some VERIFY_READs in
  149. aztcd_ioctl; check_aztcd_media_change modified
  150. Werner Zimmermann, May 16, 96
  151. V2.60 Implemented Auto-Probing; made changes for kernel's 2.1.xx blocksize
  152. Adaption to linux kernel > 2.1.0
  153. Werner Zimmermann, Nov 29, 97
  154. November 1999 -- Make kernel-parameter implementation work with 2.3.x
  155. Removed init_module & cleanup_module in favor of
  156. module_init & module_exit.
  157. Torben Mathiasen <tmm@image.dk>
  158. */
  159. #include <linux/blkdev.h>
  160. #include "aztcd.h"
  161. #include <linux/module.h>
  162. #include <linux/errno.h>
  163. #include <linux/sched.h>
  164. #include <linux/mm.h>
  165. #include <linux/timer.h>
  166. #include <linux/fs.h>
  167. #include <linux/kernel.h>
  168. #include <linux/cdrom.h>
  169. #include <linux/ioport.h>
  170. #include <linux/string.h>
  171. #include <linux/major.h>
  172. #include <linux/init.h>
  173. #include <asm/system.h>
  174. #include <asm/io.h>
  175. #include <asm/uaccess.h>
  176. /*###########################################################################
  177. Defines
  178. ###########################################################################
  179. */
  180. #define MAJOR_NR AZTECH_CDROM_MAJOR
  181. #define QUEUE (azt_queue)
  182. #define CURRENT elv_next_request(azt_queue)
  183. #define SET_TIMER(func, jifs) delay_timer.expires = jiffies + (jifs); \
  184. delay_timer.function = (void *) (func); \
  185. add_timer(&delay_timer);
  186. #define CLEAR_TIMER del_timer(&delay_timer);
  187. #define RETURNM(message,value) {printk("aztcd: Warning: %s failed\n",message);\
  188. return value;}
  189. #define RETURN(message) {printk("aztcd: Warning: %s failed\n",message);\
  190. return;}
  191. /* Macros to switch the IDE-interface to the slave device and back to the master*/
  192. #define SWITCH_IDE_SLAVE outb_p(0xa0,azt_port+6); \
  193. outb_p(0x10,azt_port+6); \
  194. outb_p(0x00,azt_port+7); \
  195. outb_p(0x10,azt_port+6);
  196. #define SWITCH_IDE_MASTER outb_p(0xa0,azt_port+6);
  197. #if 0
  198. #define AZT_TEST
  199. #define AZT_TEST1 /* <int-..> */
  200. #define AZT_TEST2 /* do_aztcd_request */
  201. #define AZT_TEST3 /* AZT_S_state */
  202. #define AZT_TEST4 /* QUICK_LOOP-counter */
  203. #define AZT_TEST5 /* port(1) state */
  204. #define AZT_DEBUG
  205. #define AZT_DEBUG_MULTISESSION
  206. #endif
  207. static struct request_queue *azt_queue;
  208. static int current_valid(void)
  209. {
  210. return CURRENT &&
  211. CURRENT->cmd == READ &&
  212. CURRENT->sector != -1;
  213. }
  214. #define AFL_STATUSorDATA (AFL_STATUS | AFL_DATA)
  215. #define AZT_BUF_SIZ 16
  216. #define READ_TIMEOUT 3000
  217. #define azt_port aztcd /*needed for the modutils */
  218. /*##########################################################################
  219. Type Definitions
  220. ##########################################################################
  221. */
  222. enum azt_state_e { AZT_S_IDLE, /* 0 */
  223. AZT_S_START, /* 1 */
  224. AZT_S_MODE, /* 2 */
  225. AZT_S_READ, /* 3 */
  226. AZT_S_DATA, /* 4 */
  227. AZT_S_STOP, /* 5 */
  228. AZT_S_STOPPING /* 6 */
  229. };
  230. enum azt_read_modes { AZT_MODE_0, /*read mode for audio disks, not supported by Aztech firmware */
  231. AZT_MODE_1, /*read mode for normal CD-ROMs */
  232. AZT_MODE_2 /*read mode for XA CD-ROMs */
  233. };
  234. /*##########################################################################
  235. Global Variables
  236. ##########################################################################
  237. */
  238. static int aztPresent = 0;
  239. static volatile int azt_transfer_is_active = 0;
  240. static char azt_buf[CD_FRAMESIZE_RAW * AZT_BUF_SIZ]; /*buffer for block size conversion */
  241. #if AZT_PRIVATE_IOCTLS
  242. static char buf[CD_FRAMESIZE_RAW]; /*separate buffer for the ioctls */
  243. #endif
  244. static volatile int azt_buf_bn[AZT_BUF_SIZ], azt_next_bn;
  245. static volatile int azt_buf_in, azt_buf_out = -1;
  246. static volatile int azt_error = 0;
  247. static int azt_open_count = 0;
  248. static volatile enum azt_state_e azt_state = AZT_S_IDLE;
  249. #ifdef AZT_TEST3
  250. static volatile enum azt_state_e azt_state_old = AZT_S_STOP;
  251. static volatile int azt_st_old = 0;
  252. #endif
  253. static volatile enum azt_read_modes azt_read_mode = AZT_MODE_1;
  254. static int azt_mode = -1;
  255. static volatile int azt_read_count = 1;
  256. static int azt_port = AZT_BASE_ADDR;
  257. module_param(azt_port, int, 0);
  258. static int azt_port_auto[16] = AZT_BASE_AUTO;
  259. static char azt_cont = 0;
  260. static char azt_init_end = 0;
  261. static char azt_auto_eject = AZT_AUTO_EJECT;
  262. static int AztTimeout, AztTries;
  263. static DECLARE_WAIT_QUEUE_HEAD(azt_waitq);
  264. static struct timer_list delay_timer = TIMER_INITIALIZER(NULL, 0, 0);
  265. static struct azt_DiskInfo DiskInfo;
  266. static struct azt_Toc Toc[MAX_TRACKS];
  267. static struct azt_Play_msf azt_Play;
  268. static int aztAudioStatus = CDROM_AUDIO_NO_STATUS;
  269. static char aztDiskChanged = 1;
  270. static char aztTocUpToDate = 0;
  271. static unsigned char aztIndatum;
  272. static unsigned long aztTimeOutCount;
  273. static int aztCmd = 0;
  274. static DEFINE_SPINLOCK(aztSpin);
  275. /*###########################################################################
  276. Function Prototypes
  277. ###########################################################################
  278. */
  279. /* CDROM Drive Low Level I/O Functions */
  280. static void aztStatTimer(void);
  281. /* CDROM Drive Command Functions */
  282. static int aztGetDiskInfo(void);
  283. #if AZT_MULTISESSION
  284. static int aztGetMultiDiskInfo(void);
  285. #endif
  286. static int aztGetToc(int multi);
  287. /* Kernel Interface Functions */
  288. static int check_aztcd_media_change(struct gendisk *disk);
  289. static int aztcd_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
  290. unsigned long arg);
  291. static int aztcd_open(struct inode *ip, struct file *fp);
  292. static int aztcd_release(struct inode *inode, struct file *file);
  293. static struct block_device_operations azt_fops = {
  294. .owner = THIS_MODULE,
  295. .open = aztcd_open,
  296. .release = aztcd_release,
  297. .ioctl = aztcd_ioctl,
  298. .media_changed = check_aztcd_media_change,
  299. };
  300. /* Aztcd State Machine: Controls Drive Operating State */
  301. static void azt_poll(void);
  302. /* Miscellaneous support functions */
  303. static void azt_hsg2msf(long hsg, struct msf *msf);
  304. static long azt_msf2hsg(struct msf *mp);
  305. static void azt_bin2bcd(unsigned char *p);
  306. static int azt_bcd2bin(unsigned char bcd);
  307. /*##########################################################################
  308. CDROM Drive Low Level I/O Functions
  309. ##########################################################################
  310. */
  311. /* Macros for the drive hardware interface handshake, these macros use
  312. busy waiting */
  313. /* Wait for OP_OK = drive answers with AFL_OP_OK after receiving a command*/
  314. # define OP_OK op_ok()
  315. static void op_ok(void)
  316. {
  317. aztTimeOutCount = 0;
  318. do {
  319. aztIndatum = inb(DATA_PORT);
  320. aztTimeOutCount++;
  321. if (aztTimeOutCount >= AZT_TIMEOUT) {
  322. printk("aztcd: Error Wait OP_OK\n");
  323. break;
  324. }
  325. } while (aztIndatum != AFL_OP_OK);
  326. }
  327. /* Wait for PA_OK = drive answers with AFL_PA_OK after receiving parameters*/
  328. #if 0
  329. # define PA_OK pa_ok()
  330. static void pa_ok(void)
  331. {
  332. aztTimeOutCount = 0;
  333. do {
  334. aztIndatum = inb(DATA_PORT);
  335. aztTimeOutCount++;
  336. if (aztTimeOutCount >= AZT_TIMEOUT) {
  337. printk("aztcd: Error Wait PA_OK\n");
  338. break;
  339. }
  340. } while (aztIndatum != AFL_PA_OK);
  341. }
  342. #endif
  343. /* Wait for STEN=Low = handshake signal 'AFL_.._OK available or command executed*/
  344. # define STEN_LOW sten_low()
  345. static void sten_low(void)
  346. {
  347. aztTimeOutCount = 0;
  348. do {
  349. aztIndatum = inb(STATUS_PORT);
  350. aztTimeOutCount++;
  351. if (aztTimeOutCount >= AZT_TIMEOUT) {
  352. if (azt_init_end)
  353. printk
  354. ("aztcd: Error Wait STEN_LOW commands:%x\n",
  355. aztCmd);
  356. break;
  357. }
  358. } while (aztIndatum & AFL_STATUS);
  359. }
  360. /* Wait for DTEN=Low = handshake signal 'Data available'*/
  361. # define DTEN_LOW dten_low()
  362. static void dten_low(void)
  363. {
  364. aztTimeOutCount = 0;
  365. do {
  366. aztIndatum = inb(STATUS_PORT);
  367. aztTimeOutCount++;
  368. if (aztTimeOutCount >= AZT_TIMEOUT) {
  369. printk("aztcd: Error Wait DTEN_OK\n");
  370. break;
  371. }
  372. } while (aztIndatum & AFL_DATA);
  373. }
  374. /*
  375. * Macro for timer wait on STEN=Low, should only be used for 'slow' commands;
  376. * may cause kernel panic when used in the wrong place
  377. */
  378. #define STEN_LOW_WAIT statusAzt()
  379. static void statusAzt(void)
  380. {
  381. AztTimeout = AZT_STATUS_DELAY;
  382. SET_TIMER(aztStatTimer, HZ / 100);
  383. sleep_on(&azt_waitq);
  384. if (AztTimeout <= 0)
  385. printk("aztcd: Error Wait STEN_LOW_WAIT command:%x\n",
  386. aztCmd);
  387. return;
  388. }
  389. static void aztStatTimer(void)
  390. {
  391. if (!(inb(STATUS_PORT) & AFL_STATUS)) {
  392. wake_up(&azt_waitq);
  393. return;
  394. }
  395. AztTimeout--;
  396. if (AztTimeout <= 0) {
  397. wake_up(&azt_waitq);
  398. printk("aztcd: Error aztStatTimer: Timeout\n");
  399. return;
  400. }
  401. SET_TIMER(aztStatTimer, HZ / 100);
  402. }
  403. /*##########################################################################
  404. CDROM Drive Command Functions
  405. ##########################################################################
  406. */
  407. /*
  408. * Send a single command, return -1 on error, else 0
  409. */
  410. static int aztSendCmd(int cmd)
  411. {
  412. unsigned char data;
  413. int retry;
  414. #ifdef AZT_DEBUG
  415. printk("aztcd: Executing command %x\n", cmd);
  416. #endif
  417. if ((azt_port == 0x1f0) || (azt_port == 0x170))
  418. SWITCH_IDE_SLAVE; /*switch IDE interface to slave configuration */
  419. aztCmd = cmd;
  420. outb(POLLED, MODE_PORT);
  421. do {
  422. if (inb(STATUS_PORT) & AFL_STATUS)
  423. break;
  424. inb(DATA_PORT); /* if status left from last command, read and */
  425. } while (1); /* discard it */
  426. do {
  427. if (inb(STATUS_PORT) & AFL_DATA)
  428. break;
  429. inb(DATA_PORT); /* if data left from last command, read and */
  430. } while (1); /* discard it */
  431. for (retry = 0; retry < AZT_RETRY_ATTEMPTS; retry++) {
  432. outb((unsigned char) cmd, CMD_PORT);
  433. STEN_LOW;
  434. data = inb(DATA_PORT);
  435. if (data == AFL_OP_OK) {
  436. return 0;
  437. } /*OP_OK? */
  438. if (data == AFL_OP_ERR) {
  439. STEN_LOW;
  440. data = inb(DATA_PORT);
  441. printk
  442. ("### Error 1 aztcd: aztSendCmd %x Error Code %x\n",
  443. cmd, data);
  444. }
  445. }
  446. if (retry >= AZT_RETRY_ATTEMPTS) {
  447. printk("### Error 2 aztcd: aztSendCmd %x \n", cmd);
  448. azt_error = 0xA5;
  449. }
  450. RETURNM("aztSendCmd", -1);
  451. }
  452. /*
  453. * Send a play or read command to the drive, return -1 on error, else 0
  454. */
  455. static int sendAztCmd(int cmd, struct azt_Play_msf *params)
  456. {
  457. unsigned char data;
  458. int retry;
  459. #ifdef AZT_DEBUG
  460. printk("aztcd: play start=%02x:%02x:%02x end=%02x:%02x:%02x\n",
  461. params->start.min, params->start.sec, params->start.frame,
  462. params->end.min, params->end.sec, params->end.frame);
  463. #endif
  464. for (retry = 0; retry < AZT_RETRY_ATTEMPTS; retry++) {
  465. aztSendCmd(cmd);
  466. outb(params->start.min, CMD_PORT);
  467. outb(params->start.sec, CMD_PORT);
  468. outb(params->start.frame, CMD_PORT);
  469. outb(params->end.min, CMD_PORT);
  470. outb(params->end.sec, CMD_PORT);
  471. outb(params->end.frame, CMD_PORT);
  472. STEN_LOW;
  473. data = inb(DATA_PORT);
  474. if (data == AFL_PA_OK) {
  475. return 0;
  476. } /*PA_OK ? */
  477. if (data == AFL_PA_ERR) {
  478. STEN_LOW;
  479. data = inb(DATA_PORT);
  480. printk
  481. ("### Error 1 aztcd: sendAztCmd %x Error Code %x\n",
  482. cmd, data);
  483. }
  484. }
  485. if (retry >= AZT_RETRY_ATTEMPTS) {
  486. printk("### Error 2 aztcd: sendAztCmd %x\n ", cmd);
  487. azt_error = 0xA5;
  488. }
  489. RETURNM("sendAztCmd", -1);
  490. }
  491. /*
  492. * Send a seek command to the drive, return -1 on error, else 0
  493. */
  494. static int aztSeek(struct azt_Play_msf *params)
  495. {
  496. unsigned char data;
  497. int retry;
  498. #ifdef AZT_DEBUG
  499. printk("aztcd: aztSeek %02x:%02x:%02x\n",
  500. params->start.min, params->start.sec, params->start.frame);
  501. #endif
  502. for (retry = 0; retry < AZT_RETRY_ATTEMPTS; retry++) {
  503. aztSendCmd(ACMD_SEEK);
  504. outb(params->start.min, CMD_PORT);
  505. outb(params->start.sec, CMD_PORT);
  506. outb(params->start.frame, CMD_PORT);
  507. STEN_LOW;
  508. data = inb(DATA_PORT);
  509. if (data == AFL_PA_OK) {
  510. return 0;
  511. } /*PA_OK ? */
  512. if (data == AFL_PA_ERR) {
  513. STEN_LOW;
  514. data = inb(DATA_PORT);
  515. printk("### Error 1 aztcd: aztSeek\n");
  516. }
  517. }
  518. if (retry >= AZT_RETRY_ATTEMPTS) {
  519. printk("### Error 2 aztcd: aztSeek\n ");
  520. azt_error = 0xA5;
  521. }
  522. RETURNM("aztSeek", -1);
  523. }
  524. /* Send a Set Disk Type command
  525. does not seem to work with Aztech drives, behavior is completely indepen-
  526. dent on which mode is set ???
  527. */
  528. static int aztSetDiskType(int type)
  529. {
  530. unsigned char data;
  531. int retry;
  532. #ifdef AZT_DEBUG
  533. printk("aztcd: set disk type command: type= %i\n", type);
  534. #endif
  535. for (retry = 0; retry < AZT_RETRY_ATTEMPTS; retry++) {
  536. aztSendCmd(ACMD_SET_DISK_TYPE);
  537. outb(type, CMD_PORT);
  538. STEN_LOW;
  539. data = inb(DATA_PORT);
  540. if (data == AFL_PA_OK) { /*PA_OK ? */
  541. azt_read_mode = type;
  542. return 0;
  543. }
  544. if (data == AFL_PA_ERR) {
  545. STEN_LOW;
  546. data = inb(DATA_PORT);
  547. printk
  548. ("### Error 1 aztcd: aztSetDiskType %x Error Code %x\n",
  549. type, data);
  550. }
  551. }
  552. if (retry >= AZT_RETRY_ATTEMPTS) {
  553. printk("### Error 2 aztcd: aztSetDiskType %x\n ", type);
  554. azt_error = 0xA5;
  555. }
  556. RETURNM("aztSetDiskType", -1);
  557. }
  558. /* used in azt_poll to poll the status, expects another program to issue a
  559. * ACMD_GET_STATUS directly before
  560. */
  561. static int aztStatus(void)
  562. {
  563. int st;
  564. /* int i;
  565. i = inb(STATUS_PORT) & AFL_STATUS; is STEN=0? ???
  566. if (!i)
  567. */ STEN_LOW;
  568. if (aztTimeOutCount < AZT_TIMEOUT) {
  569. st = inb(DATA_PORT) & 0xFF;
  570. return st;
  571. } else
  572. RETURNM("aztStatus", -1);
  573. }
  574. /*
  575. * Get the drive status
  576. */
  577. static int getAztStatus(void)
  578. {
  579. int st;
  580. if (aztSendCmd(ACMD_GET_STATUS))
  581. RETURNM("getAztStatus 1", -1);
  582. STEN_LOW;
  583. st = inb(DATA_PORT) & 0xFF;
  584. #ifdef AZT_DEBUG
  585. printk("aztcd: Status = %x\n", st);
  586. #endif
  587. if ((st == 0xFF) || (st & AST_CMD_CHECK)) {
  588. printk
  589. ("aztcd: AST_CMD_CHECK error or no status available\n");
  590. return -1;
  591. }
  592. if (((st & AST_MODE_BITS) != AST_BUSY)
  593. && (aztAudioStatus == CDROM_AUDIO_PLAY))
  594. /* XXX might be an error? look at q-channel? */
  595. aztAudioStatus = CDROM_AUDIO_COMPLETED;
  596. if ((st & AST_DSK_CHG) || (st & AST_NOT_READY)) {
  597. aztDiskChanged = 1;
  598. aztTocUpToDate = 0;
  599. aztAudioStatus = CDROM_AUDIO_NO_STATUS;
  600. }
  601. return st;
  602. }
  603. /*
  604. * Send a 'Play' command and get the status. Use only from the top half.
  605. */
  606. static int aztPlay(struct azt_Play_msf *arg)
  607. {
  608. if (sendAztCmd(ACMD_PLAY_AUDIO, arg) < 0)
  609. RETURNM("aztPlay", -1);
  610. return 0;
  611. }
  612. /*
  613. * Subroutines to automatically close the door (tray) and
  614. * lock it closed when the cd is mounted. Leave the tray
  615. * locking as an option
  616. */
  617. static void aztCloseDoor(void)
  618. {
  619. aztSendCmd(ACMD_CLOSE);
  620. STEN_LOW;
  621. return;
  622. }
  623. static void aztLockDoor(void)
  624. {
  625. #if AZT_ALLOW_TRAY_LOCK
  626. aztSendCmd(ACMD_LOCK);
  627. STEN_LOW;
  628. #endif
  629. return;
  630. }
  631. static void aztUnlockDoor(void)
  632. {
  633. #if AZT_ALLOW_TRAY_LOCK
  634. aztSendCmd(ACMD_UNLOCK);
  635. STEN_LOW;
  636. #endif
  637. return;
  638. }
  639. /*
  640. * Read a value from the drive. Should return quickly, so a busy wait
  641. * is used to avoid excessive rescheduling. The read command itself must
  642. * be issued with aztSendCmd() directly before
  643. */
  644. static int aztGetValue(unsigned char *result)
  645. {
  646. int s;
  647. STEN_LOW;
  648. if (aztTimeOutCount >= AZT_TIMEOUT) {
  649. printk("aztcd: aztGetValue timeout\n");
  650. return -1;
  651. }
  652. s = inb(DATA_PORT) & 0xFF;
  653. *result = (unsigned char) s;
  654. return 0;
  655. }
  656. /*
  657. * Read the current Q-channel info. Also used for reading the
  658. * table of contents.
  659. */
  660. static int aztGetQChannelInfo(struct azt_Toc *qp)
  661. {
  662. unsigned char notUsed;
  663. int st;
  664. #ifdef AZT_DEBUG
  665. printk("aztcd: starting aztGetQChannelInfo Time:%li\n", jiffies);
  666. #endif
  667. if ((st = getAztStatus()) == -1)
  668. RETURNM("aztGetQChannelInfo 1", -1);
  669. if (aztSendCmd(ACMD_GET_Q_CHANNEL))
  670. RETURNM("aztGetQChannelInfo 2", -1);
  671. /*STEN_LOW_WAIT; ??? Dosemu0.60's cdrom.c does not like STEN_LOW_WAIT here */
  672. if (aztGetValue(&notUsed))
  673. RETURNM("aztGetQChannelInfo 3", -1); /*??? Nullbyte einlesen */
  674. if ((st & AST_MODE_BITS) == AST_INITIAL) {
  675. qp->ctrl_addr = 0; /* when audio stop ACMD_GET_Q_CHANNEL returns */
  676. qp->track = 0; /* only one byte with Aztech drives */
  677. qp->pointIndex = 0;
  678. qp->trackTime.min = 0;
  679. qp->trackTime.sec = 0;
  680. qp->trackTime.frame = 0;
  681. qp->diskTime.min = 0;
  682. qp->diskTime.sec = 0;
  683. qp->diskTime.frame = 0;
  684. return 0;
  685. } else {
  686. if (aztGetValue(&qp->ctrl_addr) < 0)
  687. RETURNM("aztGetQChannelInfo 4", -1);
  688. if (aztGetValue(&qp->track) < 0)
  689. RETURNM("aztGetQChannelInfo 4", -1);
  690. if (aztGetValue(&qp->pointIndex) < 0)
  691. RETURNM("aztGetQChannelInfo 4", -1);
  692. if (aztGetValue(&qp->trackTime.min) < 0)
  693. RETURNM("aztGetQChannelInfo 4", -1);
  694. if (aztGetValue(&qp->trackTime.sec) < 0)
  695. RETURNM("aztGetQChannelInfo 4", -1);
  696. if (aztGetValue(&qp->trackTime.frame) < 0)
  697. RETURNM("aztGetQChannelInfo 4", -1);
  698. if (aztGetValue(&notUsed) < 0)
  699. RETURNM("aztGetQChannelInfo 4", -1);
  700. if (aztGetValue(&qp->diskTime.min) < 0)
  701. RETURNM("aztGetQChannelInfo 4", -1);
  702. if (aztGetValue(&qp->diskTime.sec) < 0)
  703. RETURNM("aztGetQChannelInfo 4", -1);
  704. if (aztGetValue(&qp->diskTime.frame) < 0)
  705. RETURNM("aztGetQChannelInfo 4", -1);
  706. }
  707. #ifdef AZT_DEBUG
  708. printk("aztcd: exiting aztGetQChannelInfo Time:%li\n", jiffies);
  709. #endif
  710. return 0;
  711. }
  712. /*
  713. * Read the table of contents (TOC) and TOC header if necessary
  714. */
  715. static int aztUpdateToc(void)
  716. {
  717. int st;
  718. #ifdef AZT_DEBUG
  719. printk("aztcd: starting aztUpdateToc Time:%li\n", jiffies);
  720. #endif
  721. if (aztTocUpToDate)
  722. return 0;
  723. if (aztGetDiskInfo() < 0)
  724. return -EIO;
  725. if (aztGetToc(0) < 0)
  726. return -EIO;
  727. /*audio disk detection
  728. with my Aztech drive there is no audio status bit, so I use the copy
  729. protection bit of the first track. If this track is copy protected
  730. (copy bit = 0), I assume, it's an audio disk. Strange, but works ??? */
  731. if (!(Toc[DiskInfo.first].ctrl_addr & 0x40))
  732. DiskInfo.audio = 1;
  733. else
  734. DiskInfo.audio = 0;
  735. /* XA detection */
  736. if (!DiskInfo.audio) {
  737. azt_Play.start.min = 0; /*XA detection only seems to work */
  738. azt_Play.start.sec = 2; /*when we play a track */
  739. azt_Play.start.frame = 0;
  740. azt_Play.end.min = 0;
  741. azt_Play.end.sec = 0;
  742. azt_Play.end.frame = 1;
  743. if (sendAztCmd(ACMD_PLAY_READ, &azt_Play))
  744. return -1;
  745. DTEN_LOW;
  746. for (st = 0; st < CD_FRAMESIZE; st++)
  747. inb(DATA_PORT);
  748. }
  749. DiskInfo.xa = getAztStatus() & AST_MODE;
  750. if (DiskInfo.xa) {
  751. printk
  752. ("aztcd: XA support experimental - mail results to Werner.Zimmermann@fht-esslingen.de\n");
  753. }
  754. /*multisession detection
  755. support for multisession CDs is done automatically with Aztech drives,
  756. we don't have to take care about TOC redirection; if we want the isofs
  757. to take care about redirection, we have to set AZT_MULTISESSION to 1 */
  758. DiskInfo.multi = 0;
  759. #if AZT_MULTISESSION
  760. if (DiskInfo.xa) {
  761. aztGetMultiDiskInfo(); /*here Disk.Info.multi is set */
  762. }
  763. #endif
  764. if (DiskInfo.multi) {
  765. DiskInfo.lastSession.min = Toc[DiskInfo.next].diskTime.min;
  766. DiskInfo.lastSession.sec = Toc[DiskInfo.next].diskTime.sec;
  767. DiskInfo.lastSession.frame =
  768. Toc[DiskInfo.next].diskTime.frame;
  769. printk("aztcd: Multisession support experimental\n");
  770. } else {
  771. DiskInfo.lastSession.min =
  772. Toc[DiskInfo.first].diskTime.min;
  773. DiskInfo.lastSession.sec =
  774. Toc[DiskInfo.first].diskTime.sec;
  775. DiskInfo.lastSession.frame =
  776. Toc[DiskInfo.first].diskTime.frame;
  777. }
  778. aztTocUpToDate = 1;
  779. #ifdef AZT_DEBUG
  780. printk("aztcd: exiting aztUpdateToc Time:%li\n", jiffies);
  781. #endif
  782. return 0;
  783. }
  784. /* Read the table of contents header, i.e. no. of tracks and start of first
  785. * track
  786. */
  787. static int aztGetDiskInfo(void)
  788. {
  789. int limit;
  790. unsigned char test;
  791. struct azt_Toc qInfo;
  792. #ifdef AZT_DEBUG
  793. printk("aztcd: starting aztGetDiskInfo Time:%li\n", jiffies);
  794. #endif
  795. if (aztSendCmd(ACMD_SEEK_TO_LEADIN))
  796. RETURNM("aztGetDiskInfo 1", -1);
  797. STEN_LOW_WAIT;
  798. test = 0;
  799. for (limit = 300; limit > 0; limit--) {
  800. if (aztGetQChannelInfo(&qInfo) < 0)
  801. RETURNM("aztGetDiskInfo 2", -1);
  802. if (qInfo.pointIndex == 0xA0) { /*Number of FirstTrack */
  803. DiskInfo.first = qInfo.diskTime.min;
  804. DiskInfo.first = azt_bcd2bin(DiskInfo.first);
  805. test = test | 0x01;
  806. }
  807. if (qInfo.pointIndex == 0xA1) { /*Number of LastTrack */
  808. DiskInfo.last = qInfo.diskTime.min;
  809. DiskInfo.last = azt_bcd2bin(DiskInfo.last);
  810. test = test | 0x02;
  811. }
  812. if (qInfo.pointIndex == 0xA2) { /*DiskLength */
  813. DiskInfo.diskLength.min = qInfo.diskTime.min;
  814. DiskInfo.diskLength.sec = qInfo.diskTime.sec;
  815. DiskInfo.diskLength.frame = qInfo.diskTime.frame;
  816. test = test | 0x04;
  817. }
  818. if ((qInfo.pointIndex == DiskInfo.first) && (test & 0x01)) { /*StartTime of First Track */
  819. DiskInfo.firstTrack.min = qInfo.diskTime.min;
  820. DiskInfo.firstTrack.sec = qInfo.diskTime.sec;
  821. DiskInfo.firstTrack.frame = qInfo.diskTime.frame;
  822. test = test | 0x08;
  823. }
  824. if (test == 0x0F)
  825. break;
  826. }
  827. #ifdef AZT_DEBUG
  828. printk("aztcd: exiting aztGetDiskInfo Time:%li\n", jiffies);
  829. printk
  830. ("Disk Info: first %d last %d length %02X:%02X.%02X dez first %02X:%02X.%02X dez\n",
  831. DiskInfo.first, DiskInfo.last, DiskInfo.diskLength.min,
  832. DiskInfo.diskLength.sec, DiskInfo.diskLength.frame,
  833. DiskInfo.firstTrack.min, DiskInfo.firstTrack.sec,
  834. DiskInfo.firstTrack.frame);
  835. #endif
  836. if (test != 0x0F)
  837. return -1;
  838. return 0;
  839. }
  840. #if AZT_MULTISESSION
  841. /*
  842. * Get Multisession Disk Info
  843. */
  844. static int aztGetMultiDiskInfo(void)
  845. {
  846. int limit, k = 5;
  847. unsigned char test;
  848. struct azt_Toc qInfo;
  849. #ifdef AZT_DEBUG
  850. printk("aztcd: starting aztGetMultiDiskInfo\n");
  851. #endif
  852. do {
  853. azt_Play.start.min = Toc[DiskInfo.last + 1].diskTime.min;
  854. azt_Play.start.sec = Toc[DiskInfo.last + 1].diskTime.sec;
  855. azt_Play.start.frame =
  856. Toc[DiskInfo.last + 1].diskTime.frame;
  857. test = 0;
  858. for (limit = 30; limit > 0; limit--) { /*Seek for LeadIn of next session */
  859. if (aztSeek(&azt_Play))
  860. RETURNM("aztGetMultiDiskInfo 1", -1);
  861. if (aztGetQChannelInfo(&qInfo) < 0)
  862. RETURNM("aztGetMultiDiskInfo 2", -1);
  863. if ((qInfo.track == 0) && (qInfo.pointIndex))
  864. break; /*LeadIn found */
  865. if ((azt_Play.start.sec += 10) > 59) {
  866. azt_Play.start.sec = 0;
  867. azt_Play.start.min++;
  868. }
  869. }
  870. if (!limit)
  871. break; /*Check, if a leadin track was found, if not we're
  872. at the end of the disk */
  873. #ifdef AZT_DEBUG_MULTISESSION
  874. printk("leadin found track %d pointIndex %x limit %d\n",
  875. qInfo.track, qInfo.pointIndex, limit);
  876. #endif
  877. for (limit = 300; limit > 0; limit--) {
  878. if (++azt_Play.start.frame > 74) {
  879. azt_Play.start.frame = 0;
  880. if (azt_Play.start.sec > 59) {
  881. azt_Play.start.sec = 0;
  882. azt_Play.start.min++;
  883. }
  884. }
  885. if (aztSeek(&azt_Play))
  886. RETURNM("aztGetMultiDiskInfo 3", -1);
  887. if (aztGetQChannelInfo(&qInfo) < 0)
  888. RETURNM("aztGetMultiDiskInfo 4", -1);
  889. if (qInfo.pointIndex == 0xA0) { /*Number of NextTrack */
  890. DiskInfo.next = qInfo.diskTime.min;
  891. DiskInfo.next = azt_bcd2bin(DiskInfo.next);
  892. test = test | 0x01;
  893. }
  894. if (qInfo.pointIndex == 0xA1) { /*Number of LastTrack */
  895. DiskInfo.last = qInfo.diskTime.min;
  896. DiskInfo.last = azt_bcd2bin(DiskInfo.last);
  897. test = test | 0x02;
  898. }
  899. if (qInfo.pointIndex == 0xA2) { /*DiskLength */
  900. DiskInfo.diskLength.min =
  901. qInfo.diskTime.min;
  902. DiskInfo.diskLength.sec =
  903. qInfo.diskTime.sec;
  904. DiskInfo.diskLength.frame =
  905. qInfo.diskTime.frame;
  906. test = test | 0x04;
  907. }
  908. if ((qInfo.pointIndex == DiskInfo.next) && (test & 0x01)) { /*StartTime of Next Track */
  909. DiskInfo.nextSession.min =
  910. qInfo.diskTime.min;
  911. DiskInfo.nextSession.sec =
  912. qInfo.diskTime.sec;
  913. DiskInfo.nextSession.frame =
  914. qInfo.diskTime.frame;
  915. test = test | 0x08;
  916. }
  917. if (test == 0x0F)
  918. break;
  919. }
  920. #ifdef AZT_DEBUG_MULTISESSION
  921. printk
  922. ("MultiDisk Info: first %d next %d last %d length %02x:%02x.%02x dez first %02x:%02x.%02x dez next %02x:%02x.%02x dez\n",
  923. DiskInfo.first, DiskInfo.next, DiskInfo.last,
  924. DiskInfo.diskLength.min, DiskInfo.diskLength.sec,
  925. DiskInfo.diskLength.frame, DiskInfo.firstTrack.min,
  926. DiskInfo.firstTrack.sec, DiskInfo.firstTrack.frame,
  927. DiskInfo.nextSession.min, DiskInfo.nextSession.sec,
  928. DiskInfo.nextSession.frame);
  929. #endif
  930. if (test != 0x0F)
  931. break;
  932. else
  933. DiskInfo.multi = 1; /*found TOC of more than one session */
  934. aztGetToc(1);
  935. } while (--k);
  936. #ifdef AZT_DEBUG
  937. printk("aztcd: exiting aztGetMultiDiskInfo Time:%li\n", jiffies);
  938. #endif
  939. return 0;
  940. }
  941. #endif
  942. /*
  943. * Read the table of contents (TOC)
  944. */
  945. static int aztGetToc(int multi)
  946. {
  947. int i, px;
  948. int limit;
  949. struct azt_Toc qInfo;
  950. #ifdef AZT_DEBUG
  951. printk("aztcd: starting aztGetToc Time:%li\n", jiffies);
  952. #endif
  953. if (!multi) {
  954. for (i = 0; i < MAX_TRACKS; i++)
  955. Toc[i].pointIndex = 0;
  956. i = DiskInfo.last + 3;
  957. } else {
  958. for (i = DiskInfo.next; i < MAX_TRACKS; i++)
  959. Toc[i].pointIndex = 0;
  960. i = DiskInfo.last + 4 - DiskInfo.next;
  961. }
  962. /*Is there a good reason to stop motor before TOC read?
  963. if (aztSendCmd(ACMD_STOP)) RETURNM("aztGetToc 1",-1);
  964. STEN_LOW_WAIT;
  965. */
  966. if (!multi) {
  967. azt_mode = 0x05;
  968. if (aztSendCmd(ACMD_SEEK_TO_LEADIN))
  969. RETURNM("aztGetToc 2", -1);
  970. STEN_LOW_WAIT;
  971. }
  972. for (limit = 300; limit > 0; limit--) {
  973. if (multi) {
  974. if (++azt_Play.start.sec > 59) {
  975. azt_Play.start.sec = 0;
  976. azt_Play.start.min++;
  977. }
  978. if (aztSeek(&azt_Play))
  979. RETURNM("aztGetToc 3", -1);
  980. }
  981. if (aztGetQChannelInfo(&qInfo) < 0)
  982. break;
  983. px = azt_bcd2bin(qInfo.pointIndex);
  984. if (px > 0 && px < MAX_TRACKS && qInfo.track == 0)
  985. if (Toc[px].pointIndex == 0) {
  986. Toc[px] = qInfo;
  987. i--;
  988. }
  989. if (i <= 0)
  990. break;
  991. }
  992. Toc[DiskInfo.last + 1].diskTime = DiskInfo.diskLength;
  993. Toc[DiskInfo.last].trackTime = DiskInfo.diskLength;
  994. #ifdef AZT_DEBUG_MULTISESSION
  995. printk("aztcd: exiting aztGetToc\n");
  996. for (i = 1; i <= DiskInfo.last + 1; i++)
  997. printk
  998. ("i = %2d ctl-adr = %02X track %2d px %02X %02X:%02X.%02X dez %02X:%02X.%02X dez\n",
  999. i, Toc[i].ctrl_addr, Toc[i].track, Toc[i].pointIndex,
  1000. Toc[i].trackTime.min, Toc[i].trackTime.sec,
  1001. Toc[i].trackTime.frame, Toc[i].diskTime.min,
  1002. Toc[i].diskTime.sec, Toc[i].diskTime.frame);
  1003. for (i = 100; i < 103; i++)
  1004. printk
  1005. ("i = %2d ctl-adr = %02X track %2d px %02X %02X:%02X.%02X dez %02X:%02X.%02X dez\n",
  1006. i, Toc[i].ctrl_addr, Toc[i].track, Toc[i].pointIndex,
  1007. Toc[i].trackTime.min, Toc[i].trackTime.sec,
  1008. Toc[i].trackTime.frame, Toc[i].diskTime.min,
  1009. Toc[i].diskTime.sec, Toc[i].diskTime.frame);
  1010. #endif
  1011. return limit > 0 ? 0 : -1;
  1012. }
  1013. /*##########################################################################
  1014. Kernel Interface Functions
  1015. ##########################################################################
  1016. */
  1017. #ifndef MODULE
  1018. static int __init aztcd_setup(char *str)
  1019. {
  1020. int ints[4];
  1021. (void) get_options(str, ARRAY_SIZE(ints), ints);
  1022. if (ints[0] > 0)
  1023. azt_port = ints[1];
  1024. if (ints[1] > 1)
  1025. azt_cont = ints[2];
  1026. return 1;
  1027. }
  1028. __setup("aztcd=", aztcd_setup);
  1029. #endif /* !MODULE */
  1030. /*
  1031. * Checking if the media has been changed
  1032. */
  1033. static int check_aztcd_media_change(struct gendisk *disk)
  1034. {
  1035. if (aztDiskChanged) { /* disk changed */
  1036. aztDiskChanged = 0;
  1037. return 1;
  1038. } else
  1039. return 0; /* no change */
  1040. }
  1041. /*
  1042. * Kernel IO-controls
  1043. */
  1044. static int aztcd_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
  1045. unsigned long arg)
  1046. {
  1047. int i;
  1048. struct azt_Toc qInfo;
  1049. struct cdrom_ti ti;
  1050. struct cdrom_tochdr tocHdr;
  1051. struct cdrom_msf msf;
  1052. struct cdrom_tocentry entry;
  1053. struct azt_Toc *tocPtr;
  1054. struct cdrom_subchnl subchnl;
  1055. struct cdrom_volctrl volctrl;
  1056. void __user *argp = (void __user *)arg;
  1057. #ifdef AZT_DEBUG
  1058. printk("aztcd: starting aztcd_ioctl - Command:%x Time: %li\n",
  1059. cmd, jiffies);
  1060. printk("aztcd Status %x\n", getAztStatus());
  1061. #endif
  1062. if (!ip)
  1063. RETURNM("aztcd_ioctl 1", -EINVAL);
  1064. if (getAztStatus() < 0)
  1065. RETURNM("aztcd_ioctl 2", -EIO);
  1066. if ((!aztTocUpToDate) || (aztDiskChanged)) {
  1067. if ((i = aztUpdateToc()) < 0)
  1068. RETURNM("aztcd_ioctl 3", i); /* error reading TOC */
  1069. }
  1070. switch (cmd) {
  1071. case CDROMSTART: /* Spin up the drive. Don't know, what to do,
  1072. at least close the tray */
  1073. #if AZT_PRIVATE_IOCTLS
  1074. if (aztSendCmd(ACMD_CLOSE))
  1075. RETURNM("aztcd_ioctl 4", -1);
  1076. STEN_LOW_WAIT;
  1077. #endif
  1078. break;
  1079. case CDROMSTOP: /* Spin down the drive */
  1080. if (aztSendCmd(ACMD_STOP))
  1081. RETURNM("aztcd_ioctl 5", -1);
  1082. STEN_LOW_WAIT;
  1083. /* should we do anything if it fails? */
  1084. aztAudioStatus = CDROM_AUDIO_NO_STATUS;
  1085. break;
  1086. case CDROMPAUSE: /* Pause the drive */
  1087. if (aztAudioStatus != CDROM_AUDIO_PLAY)
  1088. return -EINVAL;
  1089. if (aztGetQChannelInfo(&qInfo) < 0) { /* didn't get q channel info */
  1090. aztAudioStatus = CDROM_AUDIO_NO_STATUS;
  1091. RETURNM("aztcd_ioctl 7", 0);
  1092. }
  1093. azt_Play.start = qInfo.diskTime; /* remember restart point */
  1094. if (aztSendCmd(ACMD_PAUSE))
  1095. RETURNM("aztcd_ioctl 8", -1);
  1096. STEN_LOW_WAIT;
  1097. aztAudioStatus = CDROM_AUDIO_PAUSED;
  1098. break;
  1099. case CDROMRESUME: /* Play it again, Sam */
  1100. if (aztAudioStatus != CDROM_AUDIO_PAUSED)
  1101. return -EINVAL;
  1102. /* restart the drive at the saved position. */
  1103. i = aztPlay(&azt_Play);
  1104. if (i < 0) {
  1105. aztAudioStatus = CDROM_AUDIO_ERROR;
  1106. return -EIO;
  1107. }
  1108. aztAudioStatus = CDROM_AUDIO_PLAY;
  1109. break;
  1110. case CDROMMULTISESSION: /*multisession support -- experimental */
  1111. {
  1112. struct cdrom_multisession ms;
  1113. #ifdef AZT_DEBUG
  1114. printk("aztcd ioctl MULTISESSION\n");
  1115. #endif
  1116. if (copy_from_user(&ms, argp,
  1117. sizeof(struct cdrom_multisession)))
  1118. return -EFAULT;
  1119. if (ms.addr_format == CDROM_MSF) {
  1120. ms.addr.msf.minute =
  1121. azt_bcd2bin(DiskInfo.lastSession.min);
  1122. ms.addr.msf.second =
  1123. azt_bcd2bin(DiskInfo.lastSession.sec);
  1124. ms.addr.msf.frame =
  1125. azt_bcd2bin(DiskInfo.lastSession.
  1126. frame);
  1127. } else if (ms.addr_format == CDROM_LBA)
  1128. ms.addr.lba =
  1129. azt_msf2hsg(&DiskInfo.lastSession);
  1130. else
  1131. return -EINVAL;
  1132. ms.xa_flag = DiskInfo.xa;
  1133. if (copy_to_user(argp, &ms,
  1134. sizeof(struct cdrom_multisession)))
  1135. return -EFAULT;
  1136. #ifdef AZT_DEBUG
  1137. if (ms.addr_format == CDROM_MSF)
  1138. printk
  1139. ("aztcd multisession xa:%d, msf:%02x:%02x.%02x [%02x:%02x.%02x])\n",
  1140. ms.xa_flag, ms.addr.msf.minute,
  1141. ms.addr.msf.second, ms.addr.msf.frame,
  1142. DiskInfo.lastSession.min,
  1143. DiskInfo.lastSession.sec,
  1144. DiskInfo.lastSession.frame);
  1145. else
  1146. printk
  1147. ("aztcd multisession %d, lba:0x%08x [%02x:%02x.%02x])\n",
  1148. ms.xa_flag, ms.addr.lba,
  1149. DiskInfo.lastSession.min,
  1150. DiskInfo.lastSession.sec,
  1151. DiskInfo.lastSession.frame);
  1152. #endif
  1153. return 0;
  1154. }
  1155. case CDROMPLAYTRKIND: /* Play a track. This currently ignores index. */
  1156. if (copy_from_user(&ti, argp, sizeof ti))
  1157. return -EFAULT;
  1158. if (ti.cdti_trk0 < DiskInfo.first
  1159. || ti.cdti_trk0 > DiskInfo.last
  1160. || ti.cdti_trk1 < ti.cdti_trk0) {
  1161. return -EINVAL;
  1162. }
  1163. if (ti.cdti_trk1 > DiskInfo.last)
  1164. ti.cdti_trk1 = DiskInfo.last;
  1165. azt_Play.start = Toc[ti.cdti_trk0].diskTime;
  1166. azt_Play.end = Toc[ti.cdti_trk1 + 1].diskTime;
  1167. #ifdef AZT_DEBUG
  1168. printk("aztcd play: %02x:%02x.%02x to %02x:%02x.%02x\n",
  1169. azt_Play.start.min, azt_Play.start.sec,
  1170. azt_Play.start.frame, azt_Play.end.min,
  1171. azt_Play.end.sec, azt_Play.end.frame);
  1172. #endif
  1173. i = aztPlay(&azt_Play);
  1174. if (i < 0) {
  1175. aztAudioStatus = CDROM_AUDIO_ERROR;
  1176. return -EIO;
  1177. }
  1178. aztAudioStatus = CDROM_AUDIO_PLAY;
  1179. break;
  1180. case CDROMPLAYMSF: /* Play starting at the given MSF address. */
  1181. /* if (aztAudioStatus == CDROM_AUDIO_PLAY)
  1182. { if (aztSendCmd(ACMD_STOP)) RETURNM("aztcd_ioctl 9",-1);
  1183. STEN_LOW;
  1184. aztAudioStatus = CDROM_AUDIO_NO_STATUS;
  1185. }
  1186. */
  1187. if (copy_from_user(&msf, argp, sizeof msf))
  1188. return -EFAULT;
  1189. /* convert to bcd */
  1190. azt_bin2bcd(&msf.cdmsf_min0);
  1191. azt_bin2bcd(&msf.cdmsf_sec0);
  1192. azt_bin2bcd(&msf.cdmsf_frame0);
  1193. azt_bin2bcd(&msf.cdmsf_min1);
  1194. azt_bin2bcd(&msf.cdmsf_sec1);
  1195. azt_bin2bcd(&msf.cdmsf_frame1);
  1196. azt_Play.start.min = msf.cdmsf_min0;
  1197. azt_Play.start.sec = msf.cdmsf_sec0;
  1198. azt_Play.start.frame = msf.cdmsf_frame0;
  1199. azt_Play.end.min = msf.cdmsf_min1;
  1200. azt_Play.end.sec = msf.cdmsf_sec1;
  1201. azt_Play.end.frame = msf.cdmsf_frame1;
  1202. #ifdef AZT_DEBUG
  1203. printk("aztcd play: %02x:%02x.%02x to %02x:%02x.%02x\n",
  1204. azt_Play.start.min, azt_Play.start.sec,
  1205. azt_Play.start.frame, azt_Play.end.min,
  1206. azt_Play.end.sec, azt_Play.end.frame);
  1207. #endif
  1208. i = aztPlay(&azt_Play);
  1209. if (i < 0) {
  1210. aztAudioStatus = CDROM_AUDIO_ERROR;
  1211. return -EIO;
  1212. }
  1213. aztAudioStatus = CDROM_AUDIO_PLAY;
  1214. break;
  1215. case CDROMREADTOCHDR: /* Read the table of contents header */
  1216. tocHdr.cdth_trk0 = DiskInfo.first;
  1217. tocHdr.cdth_trk1 = DiskInfo.last;
  1218. if (copy_to_user(argp, &tocHdr, sizeof tocHdr))
  1219. return -EFAULT;
  1220. break;
  1221. case CDROMREADTOCENTRY: /* Read an entry in the table of contents */
  1222. if (copy_from_user(&entry, argp, sizeof entry))
  1223. return -EFAULT;
  1224. if ((!aztTocUpToDate) || aztDiskChanged)
  1225. aztUpdateToc();
  1226. if (entry.cdte_track == CDROM_LEADOUT)
  1227. tocPtr = &Toc[DiskInfo.last + 1];
  1228. else if (entry.cdte_track > DiskInfo.last
  1229. || entry.cdte_track < DiskInfo.first) {
  1230. return -EINVAL;
  1231. } else
  1232. tocPtr = &Toc[entry.cdte_track];
  1233. entry.cdte_adr = tocPtr->ctrl_addr;
  1234. entry.cdte_ctrl = tocPtr->ctrl_addr >> 4;
  1235. if (entry.cdte_format == CDROM_LBA)
  1236. entry.cdte_addr.lba =
  1237. azt_msf2hsg(&tocPtr->diskTime);
  1238. else if (entry.cdte_format == CDROM_MSF) {
  1239. entry.cdte_addr.msf.minute =
  1240. azt_bcd2bin(tocPtr->diskTime.min);
  1241. entry.cdte_addr.msf.second =
  1242. azt_bcd2bin(tocPtr->diskTime.sec);
  1243. entry.cdte_addr.msf.frame =
  1244. azt_bcd2bin(tocPtr->diskTime.frame);
  1245. } else {
  1246. return -EINVAL;
  1247. }
  1248. if (copy_to_user(argp, &entry, sizeof entry))
  1249. return -EFAULT;
  1250. break;
  1251. case CDROMSUBCHNL: /* Get subchannel info */
  1252. if (copy_from_user
  1253. (&subchnl, argp, sizeof(struct cdrom_subchnl)))
  1254. return -EFAULT;
  1255. if (aztGetQChannelInfo(&qInfo) < 0) {
  1256. #ifdef AZT_DEBUG
  1257. printk
  1258. ("aztcd: exiting aztcd_ioctl - Error 3 - Command:%x\n",
  1259. cmd);
  1260. #endif
  1261. return -EIO;
  1262. }
  1263. subchnl.cdsc_audiostatus = aztAudioStatus;
  1264. subchnl.cdsc_adr = qInfo.ctrl_addr;
  1265. subchnl.cdsc_ctrl = qInfo.ctrl_addr >> 4;
  1266. subchnl.cdsc_trk = azt_bcd2bin(qInfo.track);
  1267. subchnl.cdsc_ind = azt_bcd2bin(qInfo.pointIndex);
  1268. if (subchnl.cdsc_format == CDROM_LBA) {
  1269. subchnl.cdsc_absaddr.lba =
  1270. azt_msf2hsg(&qInfo.diskTime);
  1271. subchnl.cdsc_reladdr.lba =
  1272. azt_msf2hsg(&qInfo.trackTime);
  1273. } else { /*default */
  1274. subchnl.cdsc_format = CDROM_MSF;
  1275. subchnl.cdsc_absaddr.msf.minute =
  1276. azt_bcd2bin(qInfo.diskTime.min);
  1277. subchnl.cdsc_absaddr.msf.second =
  1278. azt_bcd2bin(qInfo.diskTime.sec);
  1279. subchnl.cdsc_absaddr.msf.frame =
  1280. azt_bcd2bin(qInfo.diskTime.frame);
  1281. subchnl.cdsc_reladdr.msf.minute =
  1282. azt_bcd2bin(qInfo.trackTime.min);
  1283. subchnl.cdsc_reladdr.msf.second =
  1284. azt_bcd2bin(qInfo.trackTime.sec);
  1285. subchnl.cdsc_reladdr.msf.frame =
  1286. azt_bcd2bin(qInfo.trackTime.frame);
  1287. }
  1288. if (copy_to_user(argp, &subchnl, sizeof(struct cdrom_subchnl)))
  1289. return -EFAULT;
  1290. break;
  1291. case CDROMVOLCTRL: /* Volume control
  1292. * With my Aztech CD268-01A volume control does not work, I can only
  1293. turn the channels on (any value !=0) or off (value==0). Maybe it
  1294. works better with your drive */
  1295. if (copy_from_user(&volctrl, argp, sizeof(volctrl)))
  1296. return -EFAULT;
  1297. azt_Play.start.min = 0x21;
  1298. azt_Play.start.sec = 0x84;
  1299. azt_Play.start.frame = volctrl.channel0;
  1300. azt_Play.end.min = volctrl.channel1;
  1301. azt_Play.end.sec = volctrl.channel2;
  1302. azt_Play.end.frame = volctrl.channel3;
  1303. sendAztCmd(ACMD_SET_VOLUME, &azt_Play);
  1304. STEN_LOW_WAIT;
  1305. break;
  1306. case CDROMEJECT:
  1307. aztUnlockDoor(); /* Assume user knows what they're doing */
  1308. /* all drives can at least stop! */
  1309. if (aztAudioStatus == CDROM_AUDIO_PLAY) {
  1310. if (aztSendCmd(ACMD_STOP))
  1311. RETURNM("azt_ioctl 10", -1);
  1312. STEN_LOW_WAIT;
  1313. }
  1314. if (aztSendCmd(ACMD_EJECT))
  1315. RETURNM("azt_ioctl 11", -1);
  1316. STEN_LOW_WAIT;
  1317. aztAudioStatus = CDROM_AUDIO_NO_STATUS;
  1318. break;
  1319. case CDROMEJECT_SW:
  1320. azt_auto_eject = (char) arg;
  1321. break;
  1322. case CDROMRESET:
  1323. outb(ACMD_SOFT_RESET, CMD_PORT); /*send reset */
  1324. STEN_LOW;
  1325. if (inb(DATA_PORT) != AFL_OP_OK) { /*OP_OK? */
  1326. printk
  1327. ("aztcd: AZTECH CD-ROM drive does not respond\n");
  1328. }
  1329. break;
  1330. /*Take care, the following code is not compatible with other CD-ROM drivers,
  1331. use it at your own risk with cdplay.c. Set AZT_PRIVATE_IOCTLS to 0 in aztcd.h,
  1332. if you do not want to use it!
  1333. */
  1334. #if AZT_PRIVATE_IOCTLS
  1335. case CDROMREADCOOKED: /*read data in mode 1 (2048 Bytes) */
  1336. case CDROMREADRAW: /*read data in mode 2 (2336 Bytes) */
  1337. {
  1338. if (copy_from_user(&msf, argp, sizeof msf))
  1339. return -EFAULT;
  1340. /* convert to bcd */
  1341. azt_bin2bcd(&msf.cdmsf_min0);
  1342. azt_bin2bcd(&msf.cdmsf_sec0);
  1343. azt_bin2bcd(&msf.cdmsf_frame0);
  1344. msf.cdmsf_min1 = 0;
  1345. msf.cdmsf_sec1 = 0;
  1346. msf.cdmsf_frame1 = 1; /*read only one frame */
  1347. azt_Play.start.min = msf.cdmsf_min0;
  1348. azt_Play.start.sec = msf.cdmsf_sec0;
  1349. azt_Play.start.frame = msf.cdmsf_frame0;
  1350. azt_Play.end.min = msf.cdmsf_min1;
  1351. azt_Play.end.sec = msf.cdmsf_sec1;
  1352. azt_Play.end.frame = msf.cdmsf_frame1;
  1353. if (cmd == CDROMREADRAW) {
  1354. if (DiskInfo.xa) {
  1355. return -1; /*XA Disks can't be read raw */
  1356. } else {
  1357. if (sendAztCmd(ACMD_PLAY_READ_RAW, &azt_Play))
  1358. return -1;
  1359. DTEN_LOW;
  1360. insb(DATA_PORT, buf, CD_FRAMESIZE_RAW);
  1361. if (copy_to_user(argp, &buf, CD_FRAMESIZE_RAW))
  1362. return -EFAULT;
  1363. }
  1364. } else
  1365. /*CDROMREADCOOKED*/ {
  1366. if (sendAztCmd(ACMD_PLAY_READ, &azt_Play))
  1367. return -1;
  1368. DTEN_LOW;
  1369. insb(DATA_PORT, buf, CD_FRAMESIZE);
  1370. if (copy_to_user(argp, &buf, CD_FRAMESIZE))
  1371. return -EFAULT;
  1372. }
  1373. }
  1374. break;
  1375. case CDROMSEEK: /*seek msf address */
  1376. if (copy_from_user(&msf, argp, sizeof msf))
  1377. return -EFAULT;
  1378. /* convert to bcd */
  1379. azt_bin2bcd(&msf.cdmsf_min0);
  1380. azt_bin2bcd(&msf.cdmsf_sec0);
  1381. azt_bin2bcd(&msf.cdmsf_frame0);
  1382. azt_Play.start.min = msf.cdmsf_min0;
  1383. azt_Play.start.sec = msf.cdmsf_sec0;
  1384. azt_Play.start.frame = msf.cdmsf_frame0;
  1385. if (aztSeek(&azt_Play))
  1386. return -1;
  1387. break;
  1388. #endif /*end of incompatible code */
  1389. case CDROMREADMODE1: /*set read data in mode 1 */
  1390. return aztSetDiskType(AZT_MODE_1);
  1391. case CDROMREADMODE2: /*set read data in mode 2 */
  1392. return aztSetDiskType(AZT_MODE_2);
  1393. default:
  1394. return -EINVAL;
  1395. }
  1396. #ifdef AZT_DEBUG
  1397. printk("aztcd: exiting aztcd_ioctl Command:%x Time:%li\n", cmd,
  1398. jiffies);
  1399. #endif
  1400. return 0;
  1401. }
  1402. /*
  1403. * Take care of the different block sizes between cdrom and Linux.
  1404. * When Linux gets variable block sizes this will probably go away.
  1405. */
  1406. static void azt_transfer(void)
  1407. {
  1408. #ifdef AZT_TEST
  1409. printk("aztcd: executing azt_transfer Time:%li\n", jiffies);
  1410. #endif
  1411. if (!current_valid())
  1412. return;
  1413. while (CURRENT->nr_sectors) {
  1414. int bn = CURRENT->sector / 4;
  1415. int i;
  1416. for (i = 0; i < AZT_BUF_SIZ && azt_buf_bn[i] != bn; ++i);
  1417. if (i < AZT_BUF_SIZ) {
  1418. int offs = (i * 4 + (CURRENT->sector & 3)) * 512;
  1419. int nr_sectors = 4 - (CURRENT->sector & 3);
  1420. if (azt_buf_out != i) {
  1421. azt_buf_out = i;
  1422. if (azt_buf_bn[i] != bn) {
  1423. azt_buf_out = -1;
  1424. continue;
  1425. }
  1426. }
  1427. if (nr_sectors > CURRENT->nr_sectors)
  1428. nr_sectors = CURRENT->nr_sectors;
  1429. memcpy(CURRENT->buffer, azt_buf + offs,
  1430. nr_sectors * 512);
  1431. CURRENT->nr_sectors -= nr_sectors;
  1432. CURRENT->sector += nr_sectors;
  1433. CURRENT->buffer += nr_sectors * 512;
  1434. } else {
  1435. azt_buf_out = -1;
  1436. break;
  1437. }
  1438. }
  1439. }
  1440. static void do_aztcd_request(request_queue_t * q)
  1441. {
  1442. #ifdef AZT_TEST
  1443. printk(" do_aztcd_request(%ld+%ld) Time:%li\n", CURRENT->sector,
  1444. CURRENT->nr_sectors, jiffies);
  1445. #endif
  1446. if (DiskInfo.audio) {
  1447. printk("aztcd: Error, tried to mount an Audio CD\n");
  1448. end_request(CURRENT, 0);
  1449. return;
  1450. }
  1451. azt_transfer_is_active = 1;
  1452. while (current_valid()) {
  1453. azt_transfer();
  1454. if (CURRENT->nr_sectors == 0) {
  1455. end_request(CURRENT, 1);
  1456. } else {
  1457. azt_buf_out = -1; /* Want to read a block not in buffer */
  1458. if (azt_state == AZT_S_IDLE) {
  1459. if ((!aztTocUpToDate) || aztDiskChanged) {
  1460. if (aztUpdateToc() < 0) {
  1461. while (current_valid())
  1462. end_request(CURRENT, 0);
  1463. break;
  1464. }
  1465. }
  1466. azt_state = AZT_S_START;
  1467. AztTries = 5;
  1468. SET_TIMER(azt_poll, HZ / 100);
  1469. }
  1470. break;
  1471. }
  1472. }
  1473. azt_transfer_is_active = 0;
  1474. #ifdef AZT_TEST2
  1475. printk
  1476. ("azt_next_bn:%x azt_buf_in:%x azt_buf_out:%x azt_buf_bn:%x\n",
  1477. azt_next_bn, azt_buf_in, azt_buf_out, azt_buf_bn[azt_buf_in]);
  1478. printk(" do_aztcd_request ends Time:%li\n", jiffies);
  1479. #endif
  1480. }
  1481. static void azt_invalidate_buffers(void)
  1482. {
  1483. int i;
  1484. #ifdef AZT_DEBUG
  1485. printk("aztcd: executing azt_invalidate_buffers\n");
  1486. #endif
  1487. for (i = 0; i < AZT_BUF_SIZ; ++i)
  1488. azt_buf_bn[i] = -1;
  1489. azt_buf_out = -1;
  1490. }
  1491. /*
  1492. * Open the device special file. Check that a disk is in.
  1493. */
  1494. static int aztcd_open(struct inode *ip, struct file *fp)
  1495. {
  1496. int st;
  1497. #ifdef AZT_DEBUG
  1498. printk("aztcd: starting aztcd_open\n");
  1499. #endif
  1500. if (aztPresent == 0)
  1501. return -ENXIO; /* no hardware */
  1502. if (!azt_open_count && azt_state == AZT_S_IDLE) {
  1503. azt_invalidate_buffers();
  1504. st = getAztStatus(); /* check drive status */
  1505. if (st == -1)
  1506. goto err_out; /* drive doesn't respond */
  1507. if (st & AST_DOOR_OPEN) { /* close door, then get the status again. */
  1508. printk("aztcd: Door Open?\n");
  1509. aztCloseDoor();
  1510. st = getAztStatus();
  1511. }
  1512. if ((st & AST_NOT_READY) || (st & AST_DSK_CHG)) { /*no disk in drive or changed */
  1513. printk
  1514. ("aztcd: Disk Changed or No Disk in Drive?\n");
  1515. aztTocUpToDate = 0;
  1516. }
  1517. if (aztUpdateToc())
  1518. goto err_out;
  1519. }
  1520. ++azt_open_count;
  1521. aztLockDoor();
  1522. #ifdef AZT_DEBUG
  1523. printk("aztcd: exiting aztcd_open\n");
  1524. #endif
  1525. return 0;
  1526. err_out:
  1527. return -EIO;
  1528. }
  1529. /*
  1530. * On close, we flush all azt blocks from the buffer cache.
  1531. */
  1532. static int aztcd_release(struct inode *inode, struct file *file)
  1533. {
  1534. #ifdef AZT_DEBUG
  1535. printk("aztcd: executing aztcd_release\n");
  1536. printk("inode: %p, device: %s file: %p\n", inode,
  1537. inode->i_bdev->bd_disk->disk_name, file);
  1538. #endif
  1539. if (!--azt_open_count) {
  1540. azt_invalidate_buffers();
  1541. aztUnlockDoor();
  1542. if (azt_auto_eject)
  1543. aztSendCmd(ACMD_EJECT);
  1544. CLEAR_TIMER;
  1545. }
  1546. return 0;
  1547. }
  1548. static struct gendisk *azt_disk;
  1549. /*
  1550. * Test for presence of drive and initialize it. Called at boot time.
  1551. */
  1552. static int __init aztcd_init(void)
  1553. {
  1554. long int count, max_count;
  1555. unsigned char result[50];
  1556. int st;
  1557. void* status = NULL;
  1558. int i = 0;
  1559. int ret = 0;
  1560. if (azt_port == 0) {
  1561. printk(KERN_INFO "aztcd: no Aztech CD-ROM Initialization");
  1562. return -EIO;
  1563. }
  1564. printk(KERN_INFO "aztcd: AZTECH, ORCHID, OKANO, WEARNES, TXC, CyDROM "
  1565. "CD-ROM Driver\n");
  1566. printk(KERN_INFO "aztcd: (C) 1994-98 W.Zimmermann\n");
  1567. if (azt_port == -1) {
  1568. printk
  1569. ("aztcd: DriverVersion=%s For IDE/ATAPI-drives use ide-cd.c\n",
  1570. AZT_VERSION);
  1571. } else
  1572. printk
  1573. ("aztcd: DriverVersion=%s BaseAddress=0x%x For IDE/ATAPI-drives use ide-cd.c\n",
  1574. AZT_VERSION, azt_port);
  1575. printk(KERN_INFO "aztcd: If you have problems, read /usr/src/linux/"
  1576. "Documentation/cdrom/aztcd\n");
  1577. #ifdef AZT_SW32 /*CDROM connected to Soundwave32 card */
  1578. if ((0xFF00 & inw(AZT_SW32_ID_REG)) != 0x4500) {
  1579. printk
  1580. ("aztcd: no Soundwave32 card detected at base:%x init:%x config:%x id:%x\n",
  1581. AZT_SW32_BASE_ADDR, AZT_SW32_INIT,
  1582. AZT_SW32_CONFIG_REG, AZT_SW32_ID_REG);
  1583. return -EIO;
  1584. } else {
  1585. printk(KERN_INFO
  1586. "aztcd: Soundwave32 card detected at %x Version %x\n",
  1587. AZT_SW32_BASE_ADDR, inw(AZT_SW32_ID_REG));
  1588. outw(AZT_SW32_INIT, AZT_SW32_CONFIG_REG);
  1589. for (count = 0; count < 10000; count++); /*delay a bit */
  1590. }
  1591. #endif
  1592. /* check for presence of drive */
  1593. if (azt_port == -1) { /* autoprobing for proprietary interface */
  1594. for (i = 0; (azt_port_auto[i] != 0) && (i < 16); i++) {
  1595. azt_port = azt_port_auto[i];
  1596. printk(KERN_INFO "aztcd: Autoprobing BaseAddress=0x%x"
  1597. "\n", azt_port);
  1598. /*proprietary interfaces need 4 bytes */
  1599. if (!request_region(azt_port, 4, "aztcd")) {
  1600. continue;
  1601. }
  1602. outb(POLLED, MODE_PORT);
  1603. inb(CMD_PORT);
  1604. inb(CMD_PORT);
  1605. outb(ACMD_GET_VERSION, CMD_PORT); /*Try to get version info */
  1606. aztTimeOutCount = 0;
  1607. do {
  1608. aztIndatum = inb(STATUS_PORT);
  1609. aztTimeOutCount++;
  1610. if (aztTimeOutCount >= AZT_FAST_TIMEOUT)
  1611. break;
  1612. } while (aztIndatum & AFL_STATUS);
  1613. if (inb(DATA_PORT) == AFL_OP_OK) { /* OK drive found */
  1614. break;
  1615. }
  1616. else { /* Drive not found on this port - try next one */
  1617. release_region(azt_port, 4);
  1618. }
  1619. }
  1620. if ((azt_port_auto[i] == 0) || (i == 16)) {
  1621. printk(KERN_INFO "aztcd: no AZTECH CD-ROM drive found\n");
  1622. return -EIO;
  1623. }
  1624. } else { /* no autoprobing */
  1625. if ((azt_port == 0x1f0) || (azt_port == 0x170))
  1626. status = request_region(azt_port, 8, "aztcd"); /*IDE-interfaces need 8 bytes */
  1627. else
  1628. status = request_region(azt_port, 4, "aztcd"); /*proprietary interfaces need 4 bytes */
  1629. if (!status) {
  1630. printk(KERN_WARNING "aztcd: conflict, I/O port (%X) "
  1631. "already used\n", azt_port);
  1632. return -EIO;
  1633. }
  1634. if ((azt_port == 0x1f0) || (azt_port == 0x170))
  1635. SWITCH_IDE_SLAVE; /*switch IDE interface to slave configuration */
  1636. outb(POLLED, MODE_PORT);
  1637. inb(CMD_PORT);
  1638. inb(CMD_PORT);
  1639. outb(ACMD_GET_VERSION, CMD_PORT); /*Try to get version info */
  1640. aztTimeOutCount = 0;
  1641. do {
  1642. aztIndatum = inb(STATUS_PORT);
  1643. aztTimeOutCount++;
  1644. if (aztTimeOutCount >= AZT_FAST_TIMEOUT)
  1645. break;
  1646. } while (aztIndatum & AFL_STATUS);
  1647. if (inb(DATA_PORT) != AFL_OP_OK) { /*OP_OK? If not, reset and try again */
  1648. #ifndef MODULE
  1649. if (azt_cont != 0x79) {
  1650. printk(KERN_WARNING "aztcd: no AZTECH CD-ROM "
  1651. "drive found-Try boot parameter aztcd="
  1652. "<BaseAddress>,0x79\n");
  1653. ret = -EIO;
  1654. goto err_out;
  1655. }
  1656. #else
  1657. if (0) {
  1658. }
  1659. #endif
  1660. else {
  1661. printk(KERN_INFO "aztcd: drive reset - "
  1662. "please wait\n");
  1663. for (count = 0; count < 50; count++) {
  1664. inb(STATUS_PORT); /*removing all data from earlier tries */
  1665. inb(DATA_PORT);
  1666. }
  1667. outb(POLLED, MODE_PORT);
  1668. inb(CMD_PORT);
  1669. inb(CMD_PORT);
  1670. getAztStatus(); /*trap errors */
  1671. outb(ACMD_SOFT_RESET, CMD_PORT); /*send reset */
  1672. STEN_LOW;
  1673. if (inb(DATA_PORT) != AFL_OP_OK) { /*OP_OK? */
  1674. printk(KERN_WARNING "aztcd: no AZTECH "
  1675. "CD-ROM drive found\n");
  1676. ret = -EIO;
  1677. goto err_out;
  1678. }
  1679. for (count = 0; count < AZT_TIMEOUT;
  1680. count++)
  1681. barrier(); /* Stop gcc 2.96 being smart */
  1682. /* use udelay(), damnit -- AV */
  1683. if ((st = getAztStatus()) == -1) {
  1684. printk(KERN_WARNING "aztcd: Drive Status"
  1685. " Error Status=%x\n", st);
  1686. ret = -EIO;
  1687. goto err_out;
  1688. }
  1689. #ifdef AZT_DEBUG
  1690. printk(KERN_DEBUG "aztcd: Status = %x\n", st);
  1691. #endif
  1692. outb(POLLED, MODE_PORT);
  1693. inb(CMD_PORT);
  1694. inb(CMD_PORT);
  1695. outb(ACMD_GET_VERSION, CMD_PORT); /*GetVersion */
  1696. STEN_LOW;
  1697. OP_OK;
  1698. }
  1699. }
  1700. }
  1701. azt_init_end = 1;
  1702. STEN_LOW;
  1703. result[0] = inb(DATA_PORT); /*reading in a null byte??? */
  1704. for (count = 1; count < 50; count++) { /*Reading version string */
  1705. aztTimeOutCount = 0; /*here we must implement STEN_LOW differently */
  1706. do {
  1707. aztIndatum = inb(STATUS_PORT); /*because we want to exit by timeout */
  1708. aztTimeOutCount++;
  1709. if (aztTimeOutCount >= AZT_FAST_TIMEOUT)
  1710. break;
  1711. } while (aztIndatum & AFL_STATUS);
  1712. if (aztTimeOutCount >= AZT_FAST_TIMEOUT)
  1713. break; /*all chars read? */
  1714. result[count] = inb(DATA_PORT);
  1715. }
  1716. if (count > 30)
  1717. max_count = 30; /*print max.30 chars of the version string */
  1718. else
  1719. max_count = count;
  1720. printk(KERN_INFO "aztcd: FirmwareVersion=");
  1721. for (count = 1; count < max_count; count++)
  1722. printk("%c", result[count]);
  1723. printk("<<>> ");
  1724. if ((result[1] == 'A') && (result[2] == 'Z') && (result[3] == 'T')) {
  1725. printk("AZTECH drive detected\n");
  1726. /*AZTECH*/}
  1727. else if ((result[2] == 'C') && (result[3] == 'D')
  1728. && (result[4] == 'D')) {
  1729. printk("ORCHID or WEARNES drive detected\n"); /*ORCHID or WEARNES */
  1730. } else if ((result[1] == 0x03) && (result[2] == '5')) {
  1731. printk("TXC or CyCDROM drive detected\n"); /*Conrad TXC, CyCDROM */
  1732. } else { /*OTHERS or none */
  1733. printk("\nunknown drive or firmware version detected\n");
  1734. printk
  1735. ("aztcd may not run stable, if you want to try anyhow,\n");
  1736. printk("boot with: aztcd=<BaseAddress>,0x79\n");
  1737. if ((azt_cont != 0x79)) {
  1738. printk("aztcd: FirmwareVersion=");
  1739. for (count = 1; count < 5; count++)
  1740. printk("%c", result[count]);
  1741. printk("<<>> ");
  1742. printk("Aborted\n");
  1743. ret = -EIO;
  1744. goto err_out;
  1745. }
  1746. }
  1747. azt_disk = alloc_disk(1);
  1748. if (!azt_disk)
  1749. goto err_out;
  1750. if (register_blkdev(MAJOR_NR, "aztcd")) {
  1751. ret = -EIO;
  1752. goto err_out2;
  1753. }
  1754. azt_queue = blk_init_queue(do_aztcd_request, &aztSpin);
  1755. if (!azt_queue) {
  1756. ret = -ENOMEM;
  1757. goto err_out3;
  1758. }
  1759. blk_queue_hardsect_size(azt_queue, 2048);
  1760. azt_disk->major = MAJOR_NR;
  1761. azt_disk->first_minor = 0;
  1762. azt_disk->fops = &azt_fops;
  1763. sprintf(azt_disk->disk_name, "aztcd");
  1764. sprintf(azt_disk->devfs_name, "aztcd");
  1765. azt_disk->queue = azt_queue;
  1766. add_disk(azt_disk);
  1767. azt_invalidate_buffers();
  1768. aztPresent = 1;
  1769. aztCloseDoor();
  1770. return 0;
  1771. err_out3:
  1772. unregister_blkdev(MAJOR_NR, "aztcd");
  1773. err_out2:
  1774. put_disk(azt_disk);
  1775. err_out:
  1776. if ((azt_port == 0x1f0) || (azt_port == 0x170)) {
  1777. SWITCH_IDE_MASTER;
  1778. release_region(azt_port, 8); /*IDE-interface */
  1779. } else
  1780. release_region(azt_port, 4); /*proprietary interface */
  1781. return ret;
  1782. }
  1783. static void __exit aztcd_exit(void)
  1784. {
  1785. del_gendisk(azt_disk);
  1786. put_disk(azt_disk);
  1787. if ((unregister_blkdev(MAJOR_NR, "aztcd") == -EINVAL)) {
  1788. printk("What's that: can't unregister aztcd\n");
  1789. return;
  1790. }
  1791. blk_cleanup_queue(azt_queue);
  1792. if ((azt_port == 0x1f0) || (azt_port == 0x170)) {
  1793. SWITCH_IDE_MASTER;
  1794. release_region(azt_port, 8); /*IDE-interface */
  1795. } else
  1796. release_region(azt_port, 4); /*proprietary interface */
  1797. printk(KERN_INFO "aztcd module released.\n");
  1798. }
  1799. module_init(aztcd_init);
  1800. module_exit(aztcd_exit);
  1801. /*##########################################################################
  1802. Aztcd State Machine: Controls Drive Operating State
  1803. ##########################################################################
  1804. */
  1805. static void azt_poll(void)
  1806. {
  1807. int st = 0;
  1808. int loop_ctl = 1;
  1809. int skip = 0;
  1810. if (azt_error) {
  1811. if (aztSendCmd(ACMD_GET_ERROR))
  1812. RETURN("azt_poll 1");
  1813. STEN_LOW;
  1814. azt_error = inb(DATA_PORT) & 0xFF;
  1815. printk("aztcd: I/O error 0x%02x\n", azt_error);
  1816. azt_invalidate_buffers();
  1817. #ifdef WARN_IF_READ_FAILURE
  1818. if (AztTries == 5)
  1819. printk
  1820. ("aztcd: Read of Block %d Failed - Maybe Audio Disk?\n",
  1821. azt_next_bn);
  1822. #endif
  1823. if (!AztTries--) {
  1824. printk
  1825. ("aztcd: Read of Block %d Failed, Maybe Audio Disk? Giving up\n",
  1826. azt_next_bn);
  1827. if (azt_transfer_is_active) {
  1828. AztTries = 0;
  1829. loop_ctl = 0;
  1830. }
  1831. if (current_valid())
  1832. end_request(CURRENT, 0);
  1833. AztTries = 5;
  1834. }
  1835. azt_error = 0;
  1836. azt_state = AZT_S_STOP;
  1837. }
  1838. while (loop_ctl) {
  1839. loop_ctl = 0; /* each case must flip this back to 1 if we want
  1840. to come back up here */
  1841. switch (azt_state) {
  1842. case AZT_S_IDLE:
  1843. #ifdef AZT_TEST3
  1844. if (azt_state != azt_state_old) {
  1845. azt_state_old = azt_state;
  1846. printk("AZT_S_IDLE\n");
  1847. }
  1848. #endif
  1849. return;
  1850. case AZT_S_START:
  1851. #ifdef AZT_TEST3
  1852. if (azt_state != azt_state_old) {
  1853. azt_state_old = azt_state;
  1854. printk("AZT_S_START\n");
  1855. }
  1856. #endif
  1857. if (aztSendCmd(ACMD_GET_STATUS))
  1858. RETURN("azt_poll 2"); /*result will be checked by aztStatus() */
  1859. azt_state =
  1860. azt_mode == 1 ? AZT_S_READ : AZT_S_MODE;
  1861. AztTimeout = 3000;
  1862. break;
  1863. case AZT_S_MODE:
  1864. #ifdef AZT_TEST3
  1865. if (azt_state != azt_state_old) {
  1866. azt_state_old = azt_state;
  1867. printk("AZT_S_MODE\n");
  1868. }
  1869. #endif
  1870. if (!skip) {
  1871. if ((st = aztStatus()) != -1) {
  1872. if ((st & AST_DSK_CHG)
  1873. || (st & AST_NOT_READY)) {
  1874. aztDiskChanged = 1;
  1875. aztTocUpToDate = 0;
  1876. azt_invalidate_buffers();
  1877. end_request(CURRENT, 0);
  1878. printk
  1879. ("aztcd: Disk Changed or Not Ready 1 - Unmount Disk!\n");
  1880. }
  1881. } else
  1882. break;
  1883. }
  1884. skip = 0;
  1885. if ((st & AST_DOOR_OPEN) || (st & AST_NOT_READY)) {
  1886. aztDiskChanged = 1;
  1887. aztTocUpToDate = 0;
  1888. printk
  1889. ("aztcd: Disk Changed or Not Ready 2 - Unmount Disk!\n");
  1890. end_request(CURRENT, 0);
  1891. printk((st & AST_DOOR_OPEN) ?
  1892. "aztcd: door open\n" :
  1893. "aztcd: disk removed\n");
  1894. if (azt_transfer_is_active) {
  1895. azt_state = AZT_S_START;
  1896. loop_ctl = 1; /* goto immediately */
  1897. break;
  1898. }
  1899. azt_state = AZT_S_IDLE;
  1900. while (current_valid())
  1901. end_request(CURRENT, 0);
  1902. return;
  1903. }
  1904. /* if (aztSendCmd(ACMD_SET_MODE)) RETURN("azt_poll 3");
  1905. outb(0x01, DATA_PORT);
  1906. PA_OK;
  1907. STEN_LOW;
  1908. */
  1909. if (aztSendCmd(ACMD_GET_STATUS))
  1910. RETURN("azt_poll 4");
  1911. STEN_LOW;
  1912. azt_mode = 1;
  1913. azt_state = AZT_S_READ;
  1914. AztTimeout = 3000;
  1915. break;
  1916. case AZT_S_READ:
  1917. #ifdef AZT_TEST3
  1918. if (azt_state != azt_state_old) {
  1919. azt_state_old = azt_state;
  1920. printk("AZT_S_READ\n");
  1921. }
  1922. #endif
  1923. if (!skip) {
  1924. if ((st = aztStatus()) != -1) {
  1925. if ((st & AST_DSK_CHG)
  1926. || (st & AST_NOT_READY)) {
  1927. aztDiskChanged = 1;
  1928. aztTocUpToDate = 0;
  1929. azt_invalidate_buffers();
  1930. printk
  1931. ("aztcd: Disk Changed or Not Ready 3 - Unmount Disk!\n");
  1932. end_request(CURRENT, 0);
  1933. }
  1934. } else
  1935. break;
  1936. }
  1937. skip = 0;
  1938. if ((st & AST_DOOR_OPEN) || (st & AST_NOT_READY)) {
  1939. aztDiskChanged = 1;
  1940. aztTocUpToDate = 0;
  1941. printk((st & AST_DOOR_OPEN) ?
  1942. "aztcd: door open\n" :
  1943. "aztcd: disk removed\n");
  1944. if (azt_transfer_is_active) {
  1945. azt_state = AZT_S_START;
  1946. loop_ctl = 1;
  1947. break;
  1948. }
  1949. azt_state = AZT_S_IDLE;
  1950. while (current_valid())
  1951. end_request(CURRENT, 0);
  1952. return;
  1953. }
  1954. if (current_valid()) {
  1955. struct azt_Play_msf msf;
  1956. int i;
  1957. azt_next_bn = CURRENT->sector / 4;
  1958. azt_hsg2msf(azt_next_bn, &msf.start);
  1959. i = 0;
  1960. /* find out in which track we are */
  1961. while (azt_msf2hsg(&msf.start) >
  1962. azt_msf2hsg(&Toc[++i].trackTime)) {
  1963. };
  1964. if (azt_msf2hsg(&msf.start) <
  1965. azt_msf2hsg(&Toc[i].trackTime) -
  1966. AZT_BUF_SIZ) {
  1967. azt_read_count = AZT_BUF_SIZ; /*fast, because we read ahead */
  1968. /*azt_read_count=CURRENT->nr_sectors; slow, no read ahead */
  1969. } else /* don't read beyond end of track */
  1970. #if AZT_MULTISESSION
  1971. {
  1972. azt_read_count =
  1973. (azt_msf2hsg(&Toc[i].trackTime)
  1974. / 4) * 4 -
  1975. azt_msf2hsg(&msf.start);
  1976. if (azt_read_count < 0)
  1977. azt_read_count = 0;
  1978. if (azt_read_count > AZT_BUF_SIZ)
  1979. azt_read_count =
  1980. AZT_BUF_SIZ;
  1981. printk
  1982. ("aztcd: warning - trying to read beyond end of track\n");
  1983. /* printk("%i %i %li %li\n",i,azt_read_count,azt_msf2hsg(&msf.start),azt_msf2hsg(&Toc[i].trackTime));
  1984. */ }
  1985. #else
  1986. {
  1987. azt_read_count = AZT_BUF_SIZ;
  1988. }
  1989. #endif
  1990. msf.end.min = 0;
  1991. msf.end.sec = 0;
  1992. msf.end.frame = azt_read_count; /*Mitsumi here reads 0xffffff sectors */
  1993. #ifdef AZT_TEST3
  1994. printk
  1995. ("---reading msf-address %x:%x:%x %x:%x:%x\n",
  1996. msf.start.min, msf.start.sec,
  1997. msf.start.frame, msf.end.min,
  1998. msf.end.sec, msf.end.frame);
  1999. printk
  2000. ("azt_next_bn:%x azt_buf_in:%x azt_buf_out:%x azt_buf_bn:%x\n",
  2001. azt_next_bn, azt_buf_in, azt_buf_out,
  2002. azt_buf_bn[azt_buf_in]);
  2003. #endif
  2004. if (azt_read_mode == AZT_MODE_2) {
  2005. sendAztCmd(ACMD_PLAY_READ_RAW, &msf); /*XA disks in raw mode */
  2006. } else {
  2007. sendAztCmd(ACMD_PLAY_READ, &msf); /*others in cooked mode */
  2008. }
  2009. azt_state = AZT_S_DATA;
  2010. AztTimeout = READ_TIMEOUT;
  2011. } else {
  2012. azt_state = AZT_S_STOP;
  2013. loop_ctl = 1;
  2014. break;
  2015. }
  2016. break;
  2017. case AZT_S_DATA:
  2018. #ifdef AZT_TEST3
  2019. if (azt_state != azt_state_old) {
  2020. azt_state_old = azt_state;
  2021. printk("AZT_S_DATA\n");
  2022. }
  2023. #endif
  2024. st = inb(STATUS_PORT) & AFL_STATUSorDATA;
  2025. switch (st) {
  2026. case AFL_DATA:
  2027. #ifdef AZT_TEST3
  2028. if (st != azt_st_old) {
  2029. azt_st_old = st;
  2030. printk("---AFL_DATA st:%x\n", st);
  2031. }
  2032. #endif
  2033. if (!AztTries--) {
  2034. printk
  2035. ("aztcd: Read of Block %d Failed, Maybe Audio Disk ? Giving up\n",
  2036. azt_next_bn);
  2037. if (azt_transfer_is_active) {
  2038. AztTries = 0;
  2039. break;
  2040. }
  2041. if (current_valid())
  2042. end_request(CURRENT, 0);
  2043. AztTries = 5;
  2044. }
  2045. azt_state = AZT_S_START;
  2046. AztTimeout = READ_TIMEOUT;
  2047. loop_ctl = 1;
  2048. break;
  2049. case AFL_STATUSorDATA:
  2050. #ifdef AZT_TEST3
  2051. if (st != azt_st_old) {
  2052. azt_st_old = st;
  2053. printk
  2054. ("---AFL_STATUSorDATA st:%x\n",
  2055. st);
  2056. }
  2057. #endif
  2058. break;
  2059. default:
  2060. #ifdef AZT_TEST3
  2061. if (st != azt_st_old) {
  2062. azt_st_old = st;
  2063. printk("---default: st:%x\n", st);
  2064. }
  2065. #endif
  2066. AztTries = 5;
  2067. if (!current_valid() && azt_buf_in == azt_buf_out) {
  2068. azt_state = AZT_S_STOP;
  2069. loop_ctl = 1;
  2070. break;
  2071. }
  2072. if (azt_read_count <= 0)
  2073. printk
  2074. ("aztcd: warning - try to read 0 frames\n");
  2075. while (azt_read_count) { /*??? fast read ahead loop */
  2076. azt_buf_bn[azt_buf_in] = -1;
  2077. DTEN_LOW; /*??? unsolved problem, very
  2078. seldom we get timeouts
  2079. here, don't now the real
  2080. reason. With my drive this
  2081. sometimes also happens with
  2082. Aztech's original driver under
  2083. DOS. Is it a hardware bug?
  2084. I tried to recover from such
  2085. situations here. Zimmermann */
  2086. if (aztTimeOutCount >= AZT_TIMEOUT) {
  2087. printk
  2088. ("read_count:%d CURRENT->nr_sectors:%ld azt_buf_in:%d\n",
  2089. azt_read_count,
  2090. CURRENT->nr_sectors,
  2091. azt_buf_in);
  2092. printk
  2093. ("azt_transfer_is_active:%x\n",
  2094. azt_transfer_is_active);
  2095. azt_read_count = 0;
  2096. azt_state = AZT_S_STOP;
  2097. loop_ctl = 1;
  2098. end_request(CURRENT, 1); /*should we have here (1) or (0)? */
  2099. } else {
  2100. if (azt_read_mode ==
  2101. AZT_MODE_2) {
  2102. insb(DATA_PORT,
  2103. azt_buf +
  2104. CD_FRAMESIZE_RAW
  2105. * azt_buf_in,
  2106. CD_FRAMESIZE_RAW);
  2107. } else {
  2108. insb(DATA_PORT,
  2109. azt_buf +
  2110. CD_FRAMESIZE *
  2111. azt_buf_in,
  2112. CD_FRAMESIZE);
  2113. }
  2114. azt_read_count--;
  2115. #ifdef AZT_TEST3
  2116. printk
  2117. ("AZT_S_DATA; ---I've read data- read_count: %d\n",
  2118. azt_read_count);
  2119. printk
  2120. ("azt_next_bn:%d azt_buf_in:%d azt_buf_out:%d azt_buf_bn:%d\n",
  2121. azt_next_bn,
  2122. azt_buf_in,
  2123. azt_buf_out,
  2124. azt_buf_bn
  2125. [azt_buf_in]);
  2126. #endif
  2127. azt_buf_bn[azt_buf_in] =
  2128. azt_next_bn++;
  2129. if (azt_buf_out == -1)
  2130. azt_buf_out =
  2131. azt_buf_in;
  2132. azt_buf_in =
  2133. azt_buf_in + 1 ==
  2134. AZT_BUF_SIZ ? 0 :
  2135. azt_buf_in + 1;
  2136. }
  2137. }
  2138. if (!azt_transfer_is_active) {
  2139. while (current_valid()) {
  2140. azt_transfer();
  2141. if (CURRENT->nr_sectors ==
  2142. 0)
  2143. end_request(CURRENT, 1);
  2144. else
  2145. break;
  2146. }
  2147. }
  2148. if (current_valid()
  2149. && (CURRENT->sector / 4 < azt_next_bn
  2150. || CURRENT->sector / 4 >
  2151. azt_next_bn + AZT_BUF_SIZ)) {
  2152. azt_state = AZT_S_STOP;
  2153. loop_ctl = 1;
  2154. break;
  2155. }
  2156. AztTimeout = READ_TIMEOUT;
  2157. if (azt_read_count == 0) {
  2158. azt_state = AZT_S_STOP;
  2159. loop_ctl = 1;
  2160. break;
  2161. }
  2162. break;
  2163. }
  2164. break;
  2165. case AZT_S_STOP:
  2166. #ifdef AZT_TEST3
  2167. if (azt_state != azt_state_old) {
  2168. azt_state_old = azt_state;
  2169. printk("AZT_S_STOP\n");
  2170. }
  2171. #endif
  2172. if (azt_read_count != 0)
  2173. printk("aztcd: discard data=%x frames\n",
  2174. azt_read_count);
  2175. while (azt_read_count != 0) {
  2176. int i;
  2177. if (!(inb(STATUS_PORT) & AFL_DATA)) {
  2178. if (azt_read_mode == AZT_MODE_2)
  2179. for (i = 0;
  2180. i < CD_FRAMESIZE_RAW;
  2181. i++)
  2182. inb(DATA_PORT);
  2183. else
  2184. for (i = 0;
  2185. i < CD_FRAMESIZE; i++)
  2186. inb(DATA_PORT);
  2187. }
  2188. azt_read_count--;
  2189. }
  2190. if (aztSendCmd(ACMD_GET_STATUS))
  2191. RETURN("azt_poll 5");
  2192. azt_state = AZT_S_STOPPING;
  2193. AztTimeout = 1000;
  2194. break;
  2195. case AZT_S_STOPPING:
  2196. #ifdef AZT_TEST3
  2197. if (azt_state != azt_state_old) {
  2198. azt_state_old = azt_state;
  2199. printk("AZT_S_STOPPING\n");
  2200. }
  2201. #endif
  2202. if ((st = aztStatus()) == -1 && AztTimeout)
  2203. break;
  2204. if ((st != -1)
  2205. && ((st & AST_DSK_CHG)
  2206. || (st & AST_NOT_READY))) {
  2207. aztDiskChanged = 1;
  2208. aztTocUpToDate = 0;
  2209. azt_invalidate_buffers();
  2210. printk
  2211. ("aztcd: Disk Changed or Not Ready 4 - Unmount Disk!\n");
  2212. end_request(CURRENT, 0);
  2213. }
  2214. #ifdef AZT_TEST3
  2215. printk("CURRENT_VALID %d azt_mode %d\n",
  2216. current_valid(), azt_mode);
  2217. #endif
  2218. if (current_valid()) {
  2219. if (st != -1) {
  2220. if (azt_mode == 1) {
  2221. azt_state = AZT_S_READ;
  2222. loop_ctl = 1;
  2223. skip = 1;
  2224. break;
  2225. } else {
  2226. azt_state = AZT_S_MODE;
  2227. loop_ctl = 1;
  2228. skip = 1;
  2229. break;
  2230. }
  2231. } else {
  2232. azt_state = AZT_S_START;
  2233. AztTimeout = 1;
  2234. }
  2235. } else {
  2236. azt_state = AZT_S_IDLE;
  2237. return;
  2238. }
  2239. break;
  2240. default:
  2241. printk("aztcd: invalid state %d\n", azt_state);
  2242. return;
  2243. } /* case */
  2244. } /* while */
  2245. if (!AztTimeout--) {
  2246. printk("aztcd: timeout in state %d\n", azt_state);
  2247. azt_state = AZT_S_STOP;
  2248. if (aztSendCmd(ACMD_STOP))
  2249. RETURN("azt_poll 6");
  2250. STEN_LOW_WAIT;
  2251. };
  2252. SET_TIMER(azt_poll, HZ / 100);
  2253. }
  2254. /*###########################################################################
  2255. * Miscellaneous support functions
  2256. ###########################################################################
  2257. */
  2258. static void azt_hsg2msf(long hsg, struct msf *msf)
  2259. {
  2260. hsg += 150;
  2261. msf->min = hsg / 4500;
  2262. hsg %= 4500;
  2263. msf->sec = hsg / 75;
  2264. msf->frame = hsg % 75;
  2265. #ifdef AZT_DEBUG
  2266. if (msf->min >= 70)
  2267. printk("aztcd: Error hsg2msf address Minutes\n");
  2268. if (msf->sec >= 60)
  2269. printk("aztcd: Error hsg2msf address Seconds\n");
  2270. if (msf->frame >= 75)
  2271. printk("aztcd: Error hsg2msf address Frames\n");
  2272. #endif
  2273. azt_bin2bcd(&msf->min); /* convert to BCD */
  2274. azt_bin2bcd(&msf->sec);
  2275. azt_bin2bcd(&msf->frame);
  2276. }
  2277. static long azt_msf2hsg(struct msf *mp)
  2278. {
  2279. return azt_bcd2bin(mp->frame) + azt_bcd2bin(mp->sec) * 75
  2280. + azt_bcd2bin(mp->min) * 4500 - CD_MSF_OFFSET;
  2281. }
  2282. static void azt_bin2bcd(unsigned char *p)
  2283. {
  2284. int u, t;
  2285. u = *p % 10;
  2286. t = *p / 10;
  2287. *p = u | (t << 4);
  2288. }
  2289. static int azt_bcd2bin(unsigned char bcd)
  2290. {
  2291. return (bcd >> 4) * 10 + (bcd & 0xF);
  2292. }
  2293. MODULE_LICENSE("GPL");
  2294. MODULE_ALIAS_BLOCKDEV_MAJOR(AZTECH_CDROM_MAJOR);