gscd.c 19 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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 %lu\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. sprintf(gscd_disk->devfs_name, "gscd");
  746. if (register_blkdev(MAJOR_NR, "gscd")) {
  747. ret = -EIO;
  748. goto err_out2;
  749. }
  750. gscd_queue = blk_init_queue(do_gscd_request, &gscd_lock);
  751. if (!gscd_queue) {
  752. ret = -ENOMEM;
  753. goto err_out3;
  754. }
  755. disk_state = 0;
  756. gscdPresent = 1;
  757. gscd_disk->queue = gscd_queue;
  758. add_disk(gscd_disk);
  759. printk(KERN_INFO "GSCD: GoldStar CD-ROM Drive found.\n");
  760. return 0;
  761. err_out3:
  762. unregister_blkdev(MAJOR_NR, "gscd");
  763. err_out2:
  764. put_disk(gscd_disk);
  765. err_out1:
  766. release_region(gscd_port, GSCD_IO_EXTENT);
  767. return ret;
  768. }
  769. static void gscd_hsg2msf(long hsg, struct msf *msf)
  770. {
  771. hsg += CD_MSF_OFFSET;
  772. msf->min = hsg / (CD_FRAMES * CD_SECS);
  773. hsg %= CD_FRAMES * CD_SECS;
  774. msf->sec = hsg / CD_FRAMES;
  775. msf->frame = hsg % CD_FRAMES;
  776. gscd_bin2bcd(&msf->min); /* convert to BCD */
  777. gscd_bin2bcd(&msf->sec);
  778. gscd_bin2bcd(&msf->frame);
  779. }
  780. static void gscd_bin2bcd(unsigned char *p)
  781. {
  782. int u, t;
  783. u = *p % 10;
  784. t = *p / 10;
  785. *p = u | (t << 4);
  786. }
  787. #ifdef FUTURE_WORK
  788. static long gscd_msf2hsg(struct msf *mp)
  789. {
  790. return gscd_bcd2bin(mp->frame)
  791. + gscd_bcd2bin(mp->sec) * CD_FRAMES
  792. + gscd_bcd2bin(mp->min) * CD_FRAMES * CD_SECS - CD_MSF_OFFSET;
  793. }
  794. static int gscd_bcd2bin(unsigned char bcd)
  795. {
  796. return (bcd >> 4) * 10 + (bcd & 0xF);
  797. }
  798. #endif
  799. MODULE_AUTHOR("Oliver Raupach <raupach@nwfs1.rz.fh-hannover.de>");
  800. MODULE_LICENSE("GPL");
  801. module_init(gscd_init);
  802. module_exit(gscd_exit);
  803. MODULE_ALIAS_BLOCKDEV_MAJOR(GOLDSTAR_CDROM_MAJOR);