gscd.c 19 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. #define GSCD_VERSION "0.4a Oliver Raupach <raupach@nwfs1.rz.fh-hannover.de>"
  2. /*
  3. linux/drivers/block/gscd.c - GoldStar R420 CDROM driver
  4. Copyright (C) 1995 Oliver Raupach <raupach@nwfs1.rz.fh-hannover.de>
  5. based upon pre-works by Eberhard Moenkeberg <emoenke@gwdg.de>
  6. For all kind of other information about the GoldStar CDROM
  7. and this Linux device driver I installed a WWW-URL:
  8. http://linux.rz.fh-hannover.de/~raupach
  9. If you are the editor of a Linux CD, you should
  10. enable gscd.c within your boot floppy kernel and
  11. send me one of your CDs for free.
  12. --------------------------------------------------------------------
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2, or (at your option)
  16. any later version.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. --------------------------------------------------------------------
  25. 9 November 1999 -- Make kernel-parameter implementation work with 2.3.x
  26. Removed init_module & cleanup_module in favor of
  27. module_init & module_exit.
  28. Torben Mathiasen <tmm@image.dk>
  29. */
  30. /* These settings are for various debug-level. Leave they untouched ... */
  31. #define NO_GSCD_DEBUG
  32. #define NO_IOCTL_DEBUG
  33. #define NO_MODULE_DEBUG
  34. #define NO_FUTURE_WORK
  35. /*------------------------*/
  36. #include <linux/module.h>
  37. #include <linux/slab.h>
  38. #include <linux/errno.h>
  39. #include <linux/signal.h>
  40. #include <linux/sched.h>
  41. #include <linux/timer.h>
  42. #include <linux/fs.h>
  43. #include <linux/mm.h>
  44. #include <linux/kernel.h>
  45. #include <linux/cdrom.h>
  46. #include <linux/ioport.h>
  47. #include <linux/major.h>
  48. #include <linux/string.h>
  49. #include <linux/init.h>
  50. #include <asm/system.h>
  51. #include <asm/io.h>
  52. #include <asm/uaccess.h>
  53. #define MAJOR_NR GOLDSTAR_CDROM_MAJOR
  54. #include <linux/blkdev.h>
  55. #include "gscd.h"
  56. static int gscdPresent = 0;
  57. static unsigned char gscd_buf[2048]; /* buffer for block size conversion */
  58. static int gscd_bn = -1;
  59. static short gscd_port = GSCD_BASE_ADDR;
  60. module_param_named(gscd, gscd_port, short, 0);
  61. /* Kommt spaeter vielleicht noch mal dran ...
  62. * static DECLARE_WAIT_QUEUE_HEAD(gscd_waitq);
  63. */
  64. static void gscd_read_cmd(struct request *req);
  65. static void gscd_hsg2msf(long hsg, struct msf *msf);
  66. static void gscd_bin2bcd(unsigned char *p);
  67. /* Schnittstellen zum Kern/FS */
  68. static void __do_gscd_request(unsigned long dummy);
  69. static int gscd_ioctl(struct inode *, struct file *, unsigned int,
  70. unsigned long);
  71. static int gscd_open(struct inode *, struct file *);
  72. static int gscd_release(struct inode *, struct file *);
  73. static int check_gscd_med_chg(struct gendisk *disk);
  74. /* GoldStar Funktionen */
  75. static void cmd_out(int, char *, char *, int);
  76. static void cmd_status(void);
  77. static void init_cd_drive(int);
  78. static int get_status(void);
  79. static void clear_Audio(void);
  80. static void cc_invalidate(void);
  81. /* some things for the next version */
  82. #ifdef FUTURE_WORK
  83. static void update_state(void);
  84. static long gscd_msf2hsg(struct msf *mp);
  85. static int gscd_bcd2bin(unsigned char bcd);
  86. #endif
  87. /* lo-level cmd-Funktionen */
  88. static void cmd_info_in(char *, int);
  89. static void cmd_end(void);
  90. static void cmd_read_b(char *, int, int);
  91. static void cmd_read_w(char *, int, int);
  92. static int cmd_unit_alive(void);
  93. static void cmd_write_cmd(char *);
  94. /* GoldStar Variablen */
  95. static int curr_drv_state;
  96. static int drv_states[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  97. static int drv_mode;
  98. static int disk_state;
  99. static int speed;
  100. static int ndrives;
  101. static unsigned char drv_num_read;
  102. static unsigned char f_dsk_valid;
  103. static unsigned char current_drive;
  104. static unsigned char f_drv_ok;
  105. static char f_AudioPlay;
  106. static char f_AudioPause;
  107. static int AudioStart_m;
  108. static int AudioStart_f;
  109. static int AudioEnd_m;
  110. static int AudioEnd_f;
  111. static DEFINE_TIMER(gscd_timer, NULL, 0, 0);
  112. static DEFINE_SPINLOCK(gscd_lock);
  113. static struct request_queue *gscd_queue;
  114. static struct block_device_operations gscd_fops = {
  115. .owner = THIS_MODULE,
  116. .open = gscd_open,
  117. .release = gscd_release,
  118. .ioctl = gscd_ioctl,
  119. .media_changed = check_gscd_med_chg,
  120. };
  121. /*
  122. * Checking if the media has been changed
  123. * (not yet implemented)
  124. */
  125. static int check_gscd_med_chg(struct gendisk *disk)
  126. {
  127. #ifdef GSCD_DEBUG
  128. printk("gscd: check_med_change\n");
  129. #endif
  130. return 0;
  131. }
  132. #ifndef MODULE
  133. /* Using new interface for kernel-parameters */
  134. static int __init gscd_setup(char *str)
  135. {
  136. int ints[2];
  137. (void) get_options(str, ARRAY_SIZE(ints), ints);
  138. if (ints[0] > 0) {
  139. gscd_port = ints[1];
  140. }
  141. return 1;
  142. }
  143. __setup("gscd=", gscd_setup);
  144. #endif
  145. static int gscd_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
  146. unsigned long arg)
  147. {
  148. unsigned char to_do[10];
  149. unsigned char dummy;
  150. switch (cmd) {
  151. case CDROMSTART: /* Spin up the drive */
  152. /* Don't think we can do this. Even if we could,
  153. * I think the drive times out and stops after a while
  154. * anyway. For now, ignore it.
  155. */
  156. return 0;
  157. case CDROMRESUME: /* keine Ahnung was das ist */
  158. return 0;
  159. case CDROMEJECT:
  160. cmd_status();
  161. to_do[0] = CMD_TRAY_CTL;
  162. cmd_out(TYPE_INFO, (char *) &to_do, (char *) &dummy, 0);
  163. return 0;
  164. default:
  165. return -EINVAL;
  166. }
  167. }
  168. /*
  169. * Take care of the different block sizes between cdrom and Linux.
  170. * When Linux gets variable block sizes this will probably go away.
  171. */
  172. static void gscd_transfer(struct request *req)
  173. {
  174. while (req->nr_sectors > 0 && gscd_bn == req->sector / 4) {
  175. long offs = (req->sector & 3) * 512;
  176. memcpy(req->buffer, gscd_buf + offs, 512);
  177. req->nr_sectors--;
  178. req->sector++;
  179. req->buffer += 512;
  180. }
  181. }
  182. /*
  183. * I/O request routine called from Linux kernel.
  184. */
  185. static void do_gscd_request(request_queue_t * q)
  186. {
  187. __do_gscd_request(0);
  188. }
  189. static void __do_gscd_request(unsigned long dummy)
  190. {
  191. struct request *req;
  192. unsigned int block;
  193. unsigned int nsect;
  194. repeat:
  195. req = elv_next_request(gscd_queue);
  196. if (!req)
  197. return;
  198. block = req->sector;
  199. nsect = req->nr_sectors;
  200. if (req->sector == -1)
  201. goto out;
  202. if (req->cmd != READ) {
  203. printk("GSCD: bad cmd %u\n", rq_data_dir(req));
  204. end_request(req, 0);
  205. goto repeat;
  206. }
  207. gscd_transfer(req);
  208. /* if we satisfied the request from the buffer, we're done. */
  209. if (req->nr_sectors == 0) {
  210. end_request(req, 1);
  211. goto repeat;
  212. }
  213. #ifdef GSCD_DEBUG
  214. printk("GSCD: block %d, nsect %d\n", block, nsect);
  215. #endif
  216. gscd_read_cmd(req);
  217. out:
  218. return;
  219. }
  220. /*
  221. * Check the result of the set-mode command. On success, send the
  222. * read-data command.
  223. */
  224. static void gscd_read_cmd(struct request *req)
  225. {
  226. long block;
  227. struct gscd_Play_msf gscdcmd;
  228. char cmd[] = { CMD_READ, 0x80, 0, 0, 0, 0, 1 }; /* cmd mode M-S-F secth sectl */
  229. cmd_status();
  230. if (disk_state & (ST_NO_DISK | ST_DOOR_OPEN)) {
  231. printk("GSCD: no disk or door open\n");
  232. end_request(req, 0);
  233. } else {
  234. if (disk_state & ST_INVALID) {
  235. printk("GSCD: disk invalid\n");
  236. end_request(req, 0);
  237. } else {
  238. gscd_bn = -1; /* purge our buffer */
  239. block = req->sector / 4;
  240. gscd_hsg2msf(block, &gscdcmd.start); /* cvt to msf format */
  241. cmd[2] = gscdcmd.start.min;
  242. cmd[3] = gscdcmd.start.sec;
  243. cmd[4] = gscdcmd.start.frame;
  244. #ifdef GSCD_DEBUG
  245. printk("GSCD: read msf %d:%d:%d\n", cmd[2], cmd[3],
  246. cmd[4]);
  247. #endif
  248. cmd_out(TYPE_DATA, (char *) &cmd,
  249. (char *) &gscd_buf[0], 1);
  250. gscd_bn = req->sector / 4;
  251. gscd_transfer(req);
  252. end_request(req, 1);
  253. }
  254. }
  255. SET_TIMER(__do_gscd_request, 1);
  256. }
  257. /*
  258. * Open the device special file. Check that a disk is in.
  259. */
  260. static int gscd_open(struct inode *ip, struct file *fp)
  261. {
  262. int st;
  263. #ifdef GSCD_DEBUG
  264. printk("GSCD: open\n");
  265. #endif
  266. if (gscdPresent == 0)
  267. return -ENXIO; /* no hardware */
  268. get_status();
  269. st = disk_state & (ST_NO_DISK | ST_DOOR_OPEN);
  270. if (st) {
  271. printk("GSCD: no disk or door open\n");
  272. return -ENXIO;
  273. }
  274. /* if (updateToc() < 0)
  275. return -EIO;
  276. */
  277. return 0;
  278. }
  279. /*
  280. * On close, we flush all gscd blocks from the buffer cache.
  281. */
  282. static int gscd_release(struct inode *inode, struct file *file)
  283. {
  284. #ifdef GSCD_DEBUG
  285. printk("GSCD: release\n");
  286. #endif
  287. gscd_bn = -1;
  288. return 0;
  289. }
  290. static int get_status(void)
  291. {
  292. int status;
  293. cmd_status();
  294. status = disk_state & (ST_x08 | ST_x04 | ST_INVALID | ST_x01);
  295. if (status == (ST_x08 | ST_x04 | ST_INVALID | ST_x01)) {
  296. cc_invalidate();
  297. return 1;
  298. } else {
  299. return 0;
  300. }
  301. }
  302. static void cc_invalidate(void)
  303. {
  304. drv_num_read = 0xFF;
  305. f_dsk_valid = 0xFF;
  306. current_drive = 0xFF;
  307. f_drv_ok = 0xFF;
  308. clear_Audio();
  309. }
  310. static void clear_Audio(void)
  311. {
  312. f_AudioPlay = 0;
  313. f_AudioPause = 0;
  314. AudioStart_m = 0;
  315. AudioStart_f = 0;
  316. AudioEnd_m = 0;
  317. AudioEnd_f = 0;
  318. }
  319. /*
  320. * waiting ?
  321. */
  322. static int wait_drv_ready(void)
  323. {
  324. int found, read;
  325. do {
  326. found = inb(GSCDPORT(0));
  327. found &= 0x0f;
  328. read = inb(GSCDPORT(0));
  329. read &= 0x0f;
  330. } while (read != found);
  331. #ifdef GSCD_DEBUG
  332. printk("Wait for: %d\n", read);
  333. #endif
  334. return read;
  335. }
  336. static void cc_Ident(char *respons)
  337. {
  338. char to_do[] = { CMD_IDENT, 0, 0 };
  339. cmd_out(TYPE_INFO, (char *) &to_do, (char *) respons, (int) 0x1E);
  340. }
  341. static void cc_SetSpeed(void)
  342. {
  343. char to_do[] = { CMD_SETSPEED, 0, 0 };
  344. char dummy;
  345. if (speed > 0) {
  346. to_do[1] = speed & 0x0F;
  347. cmd_out(TYPE_INFO, (char *) &to_do, (char *) &dummy, 0);
  348. }
  349. }
  350. static void cc_Reset(void)
  351. {
  352. char to_do[] = { CMD_RESET, 0 };
  353. char dummy;
  354. cmd_out(TYPE_INFO, (char *) &to_do, (char *) &dummy, 0);
  355. }
  356. static void cmd_status(void)
  357. {
  358. char to_do[] = { CMD_STATUS, 0 };
  359. char dummy;
  360. cmd_out(TYPE_INFO, (char *) &to_do, (char *) &dummy, 0);
  361. #ifdef GSCD_DEBUG
  362. printk("GSCD: Status: %d\n", disk_state);
  363. #endif
  364. }
  365. static void cmd_out(int cmd_type, char *cmd, char *respo_buf, int respo_count)
  366. {
  367. int result;
  368. result = wait_drv_ready();
  369. if (result != drv_mode) {
  370. unsigned long test_loops = 0xFFFF;
  371. int i, dummy;
  372. outb(curr_drv_state, GSCDPORT(0));
  373. /* LOCLOOP_170 */
  374. do {
  375. result = wait_drv_ready();
  376. test_loops--;
  377. } while ((result != drv_mode) && (test_loops > 0));
  378. if (result != drv_mode) {
  379. disk_state = ST_x08 | ST_x04 | ST_INVALID;
  380. return;
  381. }
  382. /* ...and waiting */
  383. for (i = 1, dummy = 1; i < 0xFFFF; i++) {
  384. dummy *= i;
  385. }
  386. }
  387. /* LOC_172 */
  388. /* check the unit */
  389. /* and wake it up */
  390. if (cmd_unit_alive() != 0x08) {
  391. /* LOC_174 */
  392. /* game over for this unit */
  393. disk_state = ST_x08 | ST_x04 | ST_INVALID;
  394. return;
  395. }
  396. /* LOC_176 */
  397. #ifdef GSCD_DEBUG
  398. printk("LOC_176 ");
  399. #endif
  400. if (drv_mode == 0x09) {
  401. /* magic... */
  402. printk("GSCD: magic ...\n");
  403. outb(result, GSCDPORT(2));
  404. }
  405. /* write the command to the drive */
  406. cmd_write_cmd(cmd);
  407. /* LOC_178 */
  408. for (;;) {
  409. result = wait_drv_ready();
  410. if (result != drv_mode) {
  411. /* LOC_179 */
  412. if (result == 0x04) { /* Mode 4 */
  413. /* LOC_205 */
  414. #ifdef GSCD_DEBUG
  415. printk("LOC_205 ");
  416. #endif
  417. disk_state = inb(GSCDPORT(2));
  418. do {
  419. result = wait_drv_ready();
  420. } while (result != drv_mode);
  421. return;
  422. } else {
  423. if (result == 0x06) { /* Mode 6 */
  424. /* LOC_181 */
  425. #ifdef GSCD_DEBUG
  426. printk("LOC_181 ");
  427. #endif
  428. if (cmd_type == TYPE_DATA) {
  429. /* read data */
  430. /* LOC_184 */
  431. if (drv_mode == 9) {
  432. /* read the data to the buffer (word) */
  433. /* (*(cmd+1))?(CD_FRAMESIZE/2):(CD_FRAMESIZE_RAW/2) */
  434. cmd_read_w
  435. (respo_buf,
  436. respo_count,
  437. CD_FRAMESIZE /
  438. 2);
  439. return;
  440. } else {
  441. /* read the data to the buffer (byte) */
  442. /* (*(cmd+1))?(CD_FRAMESIZE):(CD_FRAMESIZE_RAW) */
  443. cmd_read_b
  444. (respo_buf,
  445. respo_count,
  446. CD_FRAMESIZE);
  447. return;
  448. }
  449. } else {
  450. /* read the info to the buffer */
  451. cmd_info_in(respo_buf,
  452. respo_count);
  453. return;
  454. }
  455. return;
  456. }
  457. }
  458. } else {
  459. disk_state = ST_x08 | ST_x04 | ST_INVALID;
  460. return;
  461. }
  462. } /* for (;;) */
  463. #ifdef GSCD_DEBUG
  464. printk("\n");
  465. #endif
  466. }
  467. static void cmd_write_cmd(char *pstr)
  468. {
  469. int i, j;
  470. /* LOC_177 */
  471. #ifdef GSCD_DEBUG
  472. printk("LOC_177 ");
  473. #endif
  474. /* calculate the number of parameter */
  475. j = *pstr & 0x0F;
  476. /* shift it out */
  477. for (i = 0; i < j; i++) {
  478. outb(*pstr, GSCDPORT(2));
  479. pstr++;
  480. }
  481. }
  482. static int cmd_unit_alive(void)
  483. {
  484. int result;
  485. unsigned long max_test_loops;
  486. /* LOC_172 */
  487. #ifdef GSCD_DEBUG
  488. printk("LOC_172 ");
  489. #endif
  490. outb(curr_drv_state, GSCDPORT(0));
  491. max_test_loops = 0xFFFF;
  492. do {
  493. result = wait_drv_ready();
  494. max_test_loops--;
  495. } while ((result != 0x08) && (max_test_loops > 0));
  496. return result;
  497. }
  498. static void cmd_info_in(char *pb, int count)
  499. {
  500. int result;
  501. char read;
  502. /* read info */
  503. /* LOC_182 */
  504. #ifdef GSCD_DEBUG
  505. printk("LOC_182 ");
  506. #endif
  507. do {
  508. read = inb(GSCDPORT(2));
  509. if (count > 0) {
  510. *pb = read;
  511. pb++;
  512. count--;
  513. }
  514. /* LOC_183 */
  515. do {
  516. result = wait_drv_ready();
  517. } while (result == 0x0E);
  518. } while (result == 6);
  519. cmd_end();
  520. return;
  521. }
  522. static void cmd_read_b(char *pb, int count, int size)
  523. {
  524. int result;
  525. int i;
  526. /* LOC_188 */
  527. /* LOC_189 */
  528. #ifdef GSCD_DEBUG
  529. printk("LOC_189 ");
  530. #endif
  531. do {
  532. do {
  533. result = wait_drv_ready();
  534. } while (result != 6 || result == 0x0E);
  535. if (result != 6) {
  536. cmd_end();
  537. return;
  538. }
  539. #ifdef GSCD_DEBUG
  540. printk("LOC_191 ");
  541. #endif
  542. for (i = 0; i < size; i++) {
  543. *pb = inb(GSCDPORT(2));
  544. pb++;
  545. }
  546. count--;
  547. } while (count > 0);
  548. cmd_end();
  549. return;
  550. }
  551. static void cmd_end(void)
  552. {
  553. int result;
  554. /* LOC_204 */
  555. #ifdef GSCD_DEBUG
  556. printk("LOC_204 ");
  557. #endif
  558. do {
  559. result = wait_drv_ready();
  560. if (result == drv_mode) {
  561. return;
  562. }
  563. } while (result != 4);
  564. /* LOC_205 */
  565. #ifdef GSCD_DEBUG
  566. printk("LOC_205 ");
  567. #endif
  568. disk_state = inb(GSCDPORT(2));
  569. do {
  570. result = wait_drv_ready();
  571. } while (result != drv_mode);
  572. return;
  573. }
  574. static void cmd_read_w(char *pb, int count, int size)
  575. {
  576. int result;
  577. int i;
  578. #ifdef GSCD_DEBUG
  579. printk("LOC_185 ");
  580. #endif
  581. do {
  582. /* LOC_185 */
  583. do {
  584. result = wait_drv_ready();
  585. } while (result != 6 || result == 0x0E);
  586. if (result != 6) {
  587. cmd_end();
  588. return;
  589. }
  590. for (i = 0; i < size; i++) {
  591. /* na, hier muss ich noch mal drueber nachdenken */
  592. *pb = inw(GSCDPORT(2));
  593. pb++;
  594. }
  595. count--;
  596. } while (count > 0);
  597. cmd_end();
  598. return;
  599. }
  600. static int __init find_drives(void)
  601. {
  602. int *pdrv;
  603. int drvnum;
  604. int subdrv;
  605. int i;
  606. speed = 0;
  607. pdrv = (int *) &drv_states;
  608. curr_drv_state = 0xFE;
  609. subdrv = 0;
  610. drvnum = 0;
  611. for (i = 0; i < 8; i++) {
  612. subdrv++;
  613. cmd_status();
  614. disk_state &= ST_x08 | ST_x04 | ST_INVALID | ST_x01;
  615. if (disk_state != (ST_x08 | ST_x04 | ST_INVALID)) {
  616. /* LOC_240 */
  617. *pdrv = curr_drv_state;
  618. init_cd_drive(drvnum);
  619. pdrv++;
  620. drvnum++;
  621. } else {
  622. if (subdrv < 2) {
  623. continue;
  624. } else {
  625. subdrv = 0;
  626. }
  627. }
  628. /* curr_drv_state<<1; <-- das geht irgendwie nicht */
  629. /* muss heissen: curr_drv_state <<= 1; (ist ja Wert-Zuweisung) */
  630. curr_drv_state *= 2;
  631. curr_drv_state |= 1;
  632. #ifdef GSCD_DEBUG
  633. printk("DriveState: %d\n", curr_drv_state);
  634. #endif
  635. }
  636. ndrives = drvnum;
  637. return drvnum;
  638. }
  639. static void __init init_cd_drive(int num)
  640. {
  641. char resp[50];
  642. int i;
  643. printk("GSCD: init unit %d\n", num);
  644. cc_Ident((char *) &resp);
  645. printk("GSCD: identification: ");
  646. for (i = 0; i < 0x1E; i++) {
  647. printk("%c", resp[i]);
  648. }
  649. printk("\n");
  650. cc_SetSpeed();
  651. }
  652. #ifdef FUTURE_WORK
  653. /* return_done */
  654. static void update_state(void)
  655. {
  656. unsigned int AX;
  657. if ((disk_state & (ST_x08 | ST_x04 | ST_INVALID | ST_x01)) == 0) {
  658. if (disk_state == (ST_x08 | ST_x04 | ST_INVALID)) {
  659. AX = ST_INVALID;
  660. }
  661. if ((disk_state & (ST_x08 | ST_x04 | ST_INVALID | ST_x01))
  662. == 0) {
  663. invalidate();
  664. f_drv_ok = 0;
  665. }
  666. AX |= 0x8000;
  667. }
  668. if (disk_state & ST_PLAYING) {
  669. AX |= 0x200;
  670. }
  671. AX |= 0x100;
  672. /* pkt_esbx = AX; */
  673. disk_state = 0;
  674. }
  675. #endif
  676. static struct gendisk *gscd_disk;
  677. static void __exit gscd_exit(void)
  678. {
  679. CLEAR_TIMER;
  680. del_gendisk(gscd_disk);
  681. put_disk(gscd_disk);
  682. if ((unregister_blkdev(MAJOR_NR, "gscd") == -EINVAL)) {
  683. printk("What's that: can't unregister GoldStar-module\n");
  684. return;
  685. }
  686. blk_cleanup_queue(gscd_queue);
  687. release_region(gscd_port, GSCD_IO_EXTENT);
  688. printk(KERN_INFO "GoldStar-module released.\n");
  689. }
  690. /* This is the common initialisation for the GoldStar drive. */
  691. /* It is called at boot time AND for module init. */
  692. static int __init gscd_init(void)
  693. {
  694. int i;
  695. int result;
  696. int ret=0;
  697. printk(KERN_INFO "GSCD: version %s\n", GSCD_VERSION);
  698. printk(KERN_INFO
  699. "GSCD: Trying to detect a Goldstar R420 CD-ROM drive at 0x%X.\n",
  700. gscd_port);
  701. if (!request_region(gscd_port, GSCD_IO_EXTENT, "gscd")) {
  702. printk(KERN_WARNING "GSCD: Init failed, I/O port (%X) already"
  703. " in use.\n", gscd_port);
  704. return -EIO;
  705. }
  706. /* check for card */
  707. result = wait_drv_ready();
  708. if (result == 0x09) {
  709. printk(KERN_WARNING "GSCD: DMA kann ich noch nicht!\n");
  710. ret = -EIO;
  711. goto err_out1;
  712. }
  713. if (result == 0x0b) {
  714. drv_mode = result;
  715. i = find_drives();
  716. if (i == 0) {
  717. printk(KERN_WARNING "GSCD: GoldStar CD-ROM Drive is"
  718. " not found.\n");
  719. ret = -EIO;
  720. goto err_out1;
  721. }
  722. }
  723. if ((result != 0x0b) && (result != 0x09)) {
  724. printk(KERN_WARNING "GSCD: GoldStar Interface Adapter does not "
  725. "exist or H/W error\n");
  726. ret = -EIO;
  727. goto err_out1;
  728. }
  729. /* reset all drives */
  730. i = 0;
  731. while (drv_states[i] != 0) {
  732. curr_drv_state = drv_states[i];
  733. printk(KERN_INFO "GSCD: Reset unit %d ... ", i);
  734. cc_Reset();
  735. printk("done\n");
  736. i++;
  737. }
  738. gscd_disk = alloc_disk(1);
  739. if (!gscd_disk)
  740. goto err_out1;
  741. gscd_disk->major = MAJOR_NR;
  742. gscd_disk->first_minor = 0;
  743. gscd_disk->fops = &gscd_fops;
  744. sprintf(gscd_disk->disk_name, "gscd");
  745. if (register_blkdev(MAJOR_NR, "gscd")) {
  746. ret = -EIO;
  747. goto err_out2;
  748. }
  749. gscd_queue = blk_init_queue(do_gscd_request, &gscd_lock);
  750. if (!gscd_queue) {
  751. ret = -ENOMEM;
  752. goto err_out3;
  753. }
  754. disk_state = 0;
  755. gscdPresent = 1;
  756. gscd_disk->queue = gscd_queue;
  757. add_disk(gscd_disk);
  758. printk(KERN_INFO "GSCD: GoldStar CD-ROM Drive found.\n");
  759. return 0;
  760. err_out3:
  761. unregister_blkdev(MAJOR_NR, "gscd");
  762. err_out2:
  763. put_disk(gscd_disk);
  764. err_out1:
  765. release_region(gscd_port, GSCD_IO_EXTENT);
  766. return ret;
  767. }
  768. static void gscd_hsg2msf(long hsg, struct msf *msf)
  769. {
  770. hsg += CD_MSF_OFFSET;
  771. msf->min = hsg / (CD_FRAMES * CD_SECS);
  772. hsg %= CD_FRAMES * CD_SECS;
  773. msf->sec = hsg / CD_FRAMES;
  774. msf->frame = hsg % CD_FRAMES;
  775. gscd_bin2bcd(&msf->min); /* convert to BCD */
  776. gscd_bin2bcd(&msf->sec);
  777. gscd_bin2bcd(&msf->frame);
  778. }
  779. static void gscd_bin2bcd(unsigned char *p)
  780. {
  781. int u, t;
  782. u = *p % 10;
  783. t = *p / 10;
  784. *p = u | (t << 4);
  785. }
  786. #ifdef FUTURE_WORK
  787. static long gscd_msf2hsg(struct msf *mp)
  788. {
  789. return gscd_bcd2bin(mp->frame)
  790. + gscd_bcd2bin(mp->sec) * CD_FRAMES
  791. + gscd_bcd2bin(mp->min) * CD_FRAMES * CD_SECS - CD_MSF_OFFSET;
  792. }
  793. static int gscd_bcd2bin(unsigned char bcd)
  794. {
  795. return (bcd >> 4) * 10 + (bcd & 0xF);
  796. }
  797. #endif
  798. MODULE_AUTHOR("Oliver Raupach <raupach@nwfs1.rz.fh-hannover.de>");
  799. MODULE_LICENSE("GPL");
  800. module_init(gscd_init);
  801. module_exit(gscd_exit);
  802. MODULE_ALIAS_BLOCKDEV_MAJOR(GOLDSTAR_CDROM_MAJOR);