2 * Sony CDU-535 interface device driver
4 * This is a modified version of the CDU-31A device driver (see below).
5 * Changes were made using documentation for the CDU-531 (which Sony
6 * assures me is very similar to the 535) and partial disassembly of the
7 * DOS driver. I used Minyard's driver and replaced the CDU-31A
8 * commands with the CDU-531 commands. This was complicated by a different
9 * interface protocol with the drive. The driver is still polled.
11 * Data transfer rate is about 110 Kb/sec, theoretical maximum is 150 Kb/sec.
12 * I tried polling without the sony_sleep during the data transfers but
13 * it did not speed things up any.
15 * 1993-05-23 (rgj) changed the major number to 21 to get rid of conflict
16 * with CDU-31A driver. This is the also the number from the Linux
17 * Device Driver Registry for the Sony Drive. Hope nobody else is using it.
19 * 1993-08-29 (rgj) remove the configuring of the interface board address
20 * from the top level configuration, you have to modify it in this file.
22 * 1995-01-26 Made module-capable (Joel Katz <Stimpson@Panix.COM>)
25 * Modified to support CDU-510/515 series
26 * (Claudio Porfiri<C.Porfiri@nisms.tei.ericsson.se>)
27 * Fixed to report verify_area() failures
28 * (Heiko Eissfeldt <heiko@colossus.escape.de>)
31 * More changes to support CDU-510/515 series
32 * (Claudio Porfiri<C.Porfiri@nisms.tei.ericsson.se>)
34 * November 1999 -- Make kernel-parameter implementation work with 2.3.x
35 * Removed init_module & cleanup_module in favor of
36 * module_init & module_exit.
37 * Torben Mathiasen <tmm@image.dk>
39 * September 2003 - Fix SMP support by removing cli/sti calls.
40 * Using spinlocks with a wait_queue instead.
41 * Felipe Damasio <felipewd@terra.com.br>
44 * - handle errors and status better, put everything into a single word
45 * - use interrupts (code mostly there, but a big hole still missing)
46 * - handle multi-session CDs?
52 * Ken Pizzini (ken@halcyon.com)
55 * Ron Jeppesen (ronj.an@site007.saic.com)
58 *------------------------------------------------------------------------
59 * Sony CDROM interface device driver.
61 * Corey Minyard (minyard@wf-rch.cirr.com) (CDU-535 complaints to Ken above)
65 * The Sony interface device driver handles Sony interface CDROM
66 * drives and provides a complete block-level interface as well as an
67 * ioctl() interface compatible with the Sun (as specified in
68 * include/linux/cdrom.h). With this interface, CDROMs can be
69 * accessed and standard audio CDs can be played back normally.
71 * This interface is (unfortunately) a polled interface. This is
72 * because most Sony interfaces are set up with DMA and interrupts
73 * disables. Some (like mine) do not even have the capability to
74 * handle interrupts or DMA. For this reason you will see a bit of
78 * while (jiffies-snap < SONY_JIFFIES_TIMEOUT)
80 * if (some_condition())
84 * if (some_condition not met)
89 * This ugly hack waits for something to happen, sleeping a little
90 * between every try. (The conditional is written so that jiffies
91 * wrap-around is handled properly.)
93 * One thing about these drives: They talk in MSF (Minute Second Frame) format.
94 * There are 75 frames a second, 60 seconds a minute, and up to 75 minutes on a
95 * disk. The funny thing is that these are sent to the drive in BCD, but the
96 * interface wants to see them in decimal. A lot of conversion goes on.
98 * Copyright (C) 1993 Corey Minyard
100 * This program is free software; you can redistribute it and/or modify
101 * it under the terms of the GNU General Public License as published by
102 * the Free Software Foundation; either version 2 of the License, or
103 * (at your option) any later version.
105 * This program is distributed in the hope that it will be useful,
106 * but WITHOUT ANY WARRANTY; without even the implied warranty of
107 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
108 * GNU General Public License for more details.
110 * You should have received a copy of the GNU General Public License
111 * along with this program; if not, write to the Free Software
112 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
117 # include <linux/module.h>
119 #include <linux/errno.h>
120 #include <linux/signal.h>
121 #include <linux/sched.h>
122 #include <linux/timer.h>
123 #include <linux/fs.h>
124 #include <linux/kernel.h>
125 #include <linux/interrupt.h>
126 #include <linux/ioport.h>
127 #include <linux/hdreg.h>
128 #include <linux/genhd.h>
129 #include <linux/mm.h>
130 #include <linux/slab.h>
131 #include <linux/init.h>
133 #define REALLY_SLOW_IO
134 #include <asm/system.h>
136 #include <asm/uaccess.h>
138 #include <linux/cdrom.h>
140 #define MAJOR_NR CDU535_CDROM_MAJOR
141 #include <linux/blkdev.h>
143 #define sony535_cd_base_io sonycd535 /* for compatible parameter passing with "insmod" */
144 #include "sonycd535.h"
147 * this is the base address of the interface card for the Sony CDU-535
148 * CDROM drive. If your jumpers are set for an address other than
149 * this one (the default), change the following line to the
152 #ifndef CDU535_ADDRESS
153 # define CDU535_ADDRESS 0x340
155 #ifndef CDU535_INTERRUPT
156 # define CDU535_INTERRUPT 0
158 #ifndef CDU535_HANDLE
159 # define CDU535_HANDLE "cdu535"
161 #ifndef CDU535_MESSAGE_NAME
162 # define CDU535_MESSAGE_NAME "Sony CDU-535"
165 #define CDU535_BLOCK_SIZE 2048
167 #ifndef MAX_SPINUP_RETRY
168 # define MAX_SPINUP_RETRY 3 /* 1 is sufficient for most drives... */
170 #ifndef RETRY_FOR_BAD_STATUS
171 # define RETRY_FOR_BAD_STATUS 100 /* in 10th of second */
179 * SONY535_BUFFER_SIZE determines the size of internal buffer used
180 * by the drive. It must be at least 2K and the larger the buffer
181 * the better the transfer rate. It does however take system memory.
182 * On my system I get the following transfer rates using dd to read
183 * 10 Mb off /dev/cdrom.
185 * 8K buffer 43 Kb/sec
186 * 16K buffer 66 Kb/sec
187 * 32K buffer 91 Kb/sec
188 * 64K buffer 111 Kb/sec
189 * 128K buffer 123 Kb/sec
190 * 512K buffer 123 Kb/sec
192 #define SONY535_BUFFER_SIZE (64*1024)
195 * if LOCK_DOORS is defined then the eject button is disabled while
196 * the device is open.
198 #ifndef NO_LOCK_DOORS
202 static int read_subcode(void);
203 static void sony_get_toc(void);
204 static int cdu_open(struct inode *inode, struct file *filp);
205 static inline unsigned int int_to_bcd(unsigned int val);
206 static unsigned int bcd_to_int(unsigned int bcd);
207 static int do_sony_cmd(Byte * cmd, int nCmd, Byte status[2],
208 Byte * response, int n_response, int ignoreStatusBit7);
210 /* The base I/O address of the Sony Interface. This is a variable (not a
211 #define) so it can be easily changed via some future ioctl() */
212 static unsigned int sony535_cd_base_io = CDU535_ADDRESS;
213 MODULE_PARM(sony535_cd_base_io, "i");
216 * The following are I/O addresses of the various registers for the drive. The
217 * comment for the base address also applies here.
219 static unsigned short select_unit_reg;
220 static unsigned short result_reg;
221 static unsigned short command_reg;
222 static unsigned short read_status_reg;
223 static unsigned short data_reg;
225 static spinlock_t sonycd535_lock = SPIN_LOCK_UNLOCKED; /* queue lock */
226 static struct request_queue *sonycd535_queue;
228 static int initialized; /* Has the drive been initialized? */
229 static int sony_disc_changed = 1; /* Has the disk been changed
230 since the last check? */
231 static int sony_toc_read; /* Has the table of contents been
233 static unsigned int sony_buffer_size; /* Size in bytes of the read-ahead
235 static unsigned int sony_buffer_sectors; /* Size (in 2048 byte records) of
236 the read-ahead buffer. */
237 static unsigned int sony_usage; /* How many processes have the
240 static int sony_first_block = -1; /* First OS block (512 byte) in
241 the read-ahead buffer */
242 static int sony_last_block = -1; /* Last OS block (512 byte) in
243 the read-ahead buffer */
245 static struct s535_sony_toc *sony_toc; /* Points to the table of
248 static struct s535_sony_subcode *last_sony_subcode; /* Points to the last
249 subcode address read */
250 static Byte **sony_buffer; /* Points to the pointers
251 to the sector buffers */
253 static int sony_inuse; /* is the drive in use? Only one
254 open at a time allowed */
257 * The audio status uses the values from read subchannel data as specified
258 * in include/linux/cdrom.h.
260 static int sony_audio_status = CDROM_AUDIO_NO_STATUS;
263 * The following are a hack for pausing and resuming audio play. The drive
264 * does not work as I would expect it, if you stop it then start it again,
265 * the drive seeks back to the beginning and starts over. This holds the
266 * position during a pause so a resume can restart it. It uses the
267 * audio status variable above to tell if it is paused.
268 * I just kept the CDU-31A driver behavior rather than using the PAUSE
269 * command on the CDU-535.
271 static Byte cur_pos_msf[3];
272 static Byte final_pos_msf[3];
274 /* What IRQ is the drive using? 0 if none. */
275 static int sony535_irq_used = CDU535_INTERRUPT;
277 /* The interrupt handler will wake this queue up when it gets an interrupt. */
278 static DECLARE_WAIT_QUEUE_HEAD(cdu535_irq_wait);
282 * This routine returns 1 if the disk has been changed since the last
283 * check or 0 if it hasn't. Setting flag to 0 resets the changed flag.
286 cdu535_check_media_change(struct gendisk *disk)
288 /* if driver is not initialized, always return 0 */
289 int retval = initialized ? sony_disc_changed : 0;
290 sony_disc_changed = 0;
295 enable_interrupts(void)
299 * This code was taken from cdu31a.c; it will not
300 * directly work for the cdu535 as written...
302 curr_control_reg |= ( SONY_ATTN_INT_EN_BIT
303 | SONY_RES_RDY_INT_EN_BIT
304 | SONY_DATA_RDY_INT_EN_BIT);
305 outb(curr_control_reg, sony_cd_control_reg);
310 disable_interrupts(void)
314 * This code was taken from cdu31a.c; it will not
315 * directly work for the cdu535 as written...
317 curr_control_reg &= ~(SONY_ATTN_INT_EN_BIT
318 | SONY_RES_RDY_INT_EN_BIT
319 | SONY_DATA_RDY_INT_EN_BIT);
320 outb(curr_control_reg, sony_cd_control_reg);
325 cdu535_interrupt(int irq, void *dev_id, struct pt_regs *regs)
327 disable_interrupts();
328 if (waitqueue_active(&cdu535_irq_wait)) {
329 wake_up(&cdu535_irq_wait);
332 printk(CDU535_MESSAGE_NAME
333 ": Got an interrupt but nothing was waiting\n");
339 * Wait a little while.
344 if (sony535_irq_used <= 0) { /* poll */
346 } else { /* Interrupt driven */
349 spin_lock_irq(&sonycd535_lock);
351 prepare_to_wait(&cdu535_irq_wait, &wait, TASK_INTERRUPTIBLE);
352 spin_unlock_irq(&sonycd535_lock);
354 finish_wait(&cdu535_irq_wait, &wait);
358 /*------------------start of SONY CDU535 very specific ---------------------*/
360 /****************************************************************************
361 * void select_unit( int unit_no )
363 * Select the specified unit (0-3) so that subsequent commands reference it
364 ****************************************************************************/
366 select_unit(int unit_no)
368 unsigned int select_mask = ~(1 << unit_no);
369 outb(select_mask, select_unit_reg);
372 /***************************************************************************
373 * int read_result_reg( Byte *data_ptr )
375 * Read a result byte from the Sony CDU controller, store in location pointed
376 * to by data_ptr. Return zero on success, TIME_OUT if we did not receive
378 ***************************************************************************/
380 read_result_reg(Byte *data_ptr)
386 while (jiffies-snap < SONY_JIFFIES_TIMEOUT) {
387 read_status = inb(read_status_reg);
388 if ((read_status & SONY535_RESULT_NOT_READY_BIT) == 0) {
390 printk(CDU535_MESSAGE_NAME
391 ": read_result_reg(): readStatReg = 0x%x\n", read_status);
393 *data_ptr = inb(result_reg);
399 printk(CDU535_MESSAGE_NAME " read_result_reg: TIME OUT!\n");
403 /****************************************************************************
404 * int read_exec_status( Byte status[2] )
406 * Read the execution status of the last command and put into status.
407 * Handles reading second status word if available. Returns 0 on success,
408 * TIME_OUT on failure.
409 ****************************************************************************/
411 read_exec_status(Byte status[2])
414 if (read_result_reg(&(status[0])) != 0)
416 if ((status[0] & 0x80) != 0) { /* byte two follows */
417 if (read_result_reg(&(status[1])) != 0)
421 printk(CDU535_MESSAGE_NAME ": read_exec_status: read 0x%x 0x%x\n",
422 status[0], status[1]);
427 /****************************************************************************
428 * int check_drive_status( void )
430 * Check the current drive status. Using this before executing a command
431 * takes care of the problem of unsolicited drive status-2 messages.
432 * Add a check of the audio status if we think the disk is playing.
433 ****************************************************************************/
435 check_drive_status(void)
437 Byte status, e_status[2];
442 if (sony_audio_status == CDROM_AUDIO_PLAY) { /* check status */
443 outb(SONY535_REQUEST_AUDIO_STATUS, command_reg);
444 if (read_result_reg(&status) == 0) {
447 break; /* play in progress */
450 case 0x3: /* audio play completed */
451 case 0x5: /* play not requested */
452 sony_audio_status = CDROM_AUDIO_COMPLETED;
455 case 0x4: /* error during play */
456 sony_audio_status = CDROM_AUDIO_ERROR;
461 /* now check drive status */
462 outb(SONY535_REQUEST_DRIVE_STATUS_2, command_reg);
463 if (read_result_reg(&status) != 0)
467 printk(CDU535_MESSAGE_NAME ": check_drive_status() got 0x%x\n", status);
474 CDD = (status >> 4) & 0xf;
478 break; /* go on to CDD stuff */
479 case SONY535_ATN_BUSY:
481 printk(CDU535_MESSAGE_NAME " error: drive busy\n");
483 case SONY535_ATN_EJECT_IN_PROGRESS:
484 printk(CDU535_MESSAGE_NAME " error: eject in progress\n");
485 sony_audio_status = CDROM_AUDIO_INVALID;
487 case SONY535_ATN_RESET_OCCURRED:
488 case SONY535_ATN_DISC_CHANGED:
489 case SONY535_ATN_RESET_AND_DISC_CHANGED:
491 printk(CDU535_MESSAGE_NAME " notice: reset occurred or disc changed\n");
493 sony_disc_changed = 1;
495 sony_audio_status = CDROM_AUDIO_NO_STATUS;
496 sony_first_block = -1;
497 sony_last_block = -1;
499 cmd = SONY535_SPIN_UP;
500 do_sony_cmd(&cmd, 1, e_status, NULL, 0, 0);
505 printk(CDU535_MESSAGE_NAME " error: drive busy (ATN=0x%x)\n", ATN);
508 switch (CDD) { /* the 531 docs are not helpful in decoding this */
509 case 0x0: /* just use the values from the DOS driver */
512 break; /* no error */
514 printk(CDU535_MESSAGE_NAME
515 ": check_drive_status(): CDD = 0xc! Not properly handled!\n");
516 return CD_BUSY; /* ? */
521 } /* check_drive_status() */
523 /*****************************************************************************
524 * int do_sony_cmd( Byte *cmd, int n_cmd, Byte status[2],
525 * Byte *response, int n_response, int ignore_status_bit7 )
527 * Generic routine for executing commands. The command and its parameters
528 * should be placed in the cmd[] array, number of bytes in the command is
529 * stored in nCmd. The response from the command will be stored in the
530 * response array. The number of bytes you expect back (excluding status)
531 * should be passed in n_response. Finally, some
532 * commands set bit 7 of the return status even when there is no second
533 * status byte, on these commands set ignoreStatusBit7 TRUE.
534 * If the command was sent and data received back, then we return 0,
535 * else we return TIME_OUT. You still have to check the status yourself.
536 * You should call check_drive_status() before calling this routine
537 * so that you do not lose notifications of disk changes, etc.
538 ****************************************************************************/
540 do_sony_cmd(Byte * cmd, int n_cmd, Byte status[2],
541 Byte * response, int n_response, int ignore_status_bit7)
545 /* write out the command */
546 for (i = 0; i < n_cmd; i++)
547 outb(cmd[i], command_reg);
549 /* read back the status */
550 if (read_result_reg(status) != 0)
552 if (!ignore_status_bit7 && ((status[0] & 0x80) != 0)) {
553 /* get second status byte */
554 if (read_result_reg(status + 1) != 0)
560 printk(CDU535_MESSAGE_NAME ": do_sony_cmd %x: %x %x\n",
561 *cmd, status[0], status[1]);
564 /* do not know about when I should read set of data and when not to */
565 if ((status[0] & ((ignore_status_bit7 ? 0x7f : 0xff) & 0x8f)) != 0)
568 /* else, read in rest of data */
569 for (i = 0; 0 < n_response; n_response--, i++)
570 if (read_result_reg(response + i) != 0)
573 } /* do_sony_cmd() */
575 /**************************************************************************
576 * int set_drive_mode( int mode, Byte status[2] )
578 * Set the drive mode to the specified value (mode=0 is audio, mode=e0
580 **************************************************************************/
582 set_drive_mode(int mode, Byte status[2])
587 cmd_buff[0] = SONY535_SET_DRIVE_MODE;
589 return do_sony_cmd(cmd_buff, 2, status, ret_buff, 1, 1);
592 /***************************************************************************
593 * int seek_and_read_N_blocks( Byte params[], int n_blocks, Byte status[2],
594 * Byte *data_buff, int buff_size )
596 * Read n_blocks of data from the CDROM starting at position params[0:2],
597 * number of blocks in stored in params[3:5] -- both these are already
599 * Transfer the data into the buffer pointed at by data_buff. buff_size
600 * gives the number of bytes available in the buffer.
601 * The routine returns number of bytes read in if successful, otherwise
602 * it returns one of the standard error returns.
603 ***************************************************************************/
605 seek_and_read_N_blocks(Byte params[], int n_blocks, Byte status[2],
606 Byte **buff, int buf_size)
613 int sector_count = 0;
615 if (buf_size < CDU535_BLOCK_SIZE * n_blocks)
618 set_drive_mode(SONY535_CDROM_DRIVE_MODE, status);
620 /* send command to read the data */
621 cmd_buff[0] = SONY535_SEEK_AND_READ_N_BLOCKS_1;
622 for (i = 0; i < 6; i++)
623 cmd_buff[i + 1] = params[i];
624 for (i = 0; i < 7; i++)
625 outb(cmd_buff[i], command_reg);
627 /* read back the data one block at a time */
628 while (0 < n_blocks--) {
629 /* wait for data to be ready */
632 while (jiffies-snap < SONY_JIFFIES_TIMEOUT) {
633 read_status = inb(read_status_reg);
634 if ((read_status & SONY535_RESULT_NOT_READY_BIT) == 0) {
635 read_exec_status(status);
638 if ((read_status & SONY535_DATA_NOT_READY_BIT) == 0) {
639 /* data is ready, read it */
640 data_buff = buff[sector_count++];
641 for (i = 0; i < CDU535_BLOCK_SIZE; i++)
642 *data_buff++ = inb(data_reg); /* unrolling this loop does not seem to help */
644 break; /* exit the timeout loop */
646 sony_sleep(); /* data not ready, sleep a while */
649 return TIME_OUT; /* if we reach this stage */
652 /* read all the data, now read the status */
653 if ((i = read_exec_status(status)) != 0)
655 return CDU535_BLOCK_SIZE * sector_count;
656 } /* seek_and_read_N_blocks() */
658 /****************************************************************************
659 * int request_toc_data( Byte status[2], struct s535_sony_toc *toc )
661 * Read in the table of contents data. Converts all the bcd data
662 * into integers in the toc structure.
663 ****************************************************************************/
665 request_toc_data(Byte status[2], struct s535_sony_toc *toc)
668 int i, j, n_tracks, track_no;
669 int first_track_num, last_track_num;
671 Byte track_address_buffer[5];
673 /* read the fixed portion of the table of contents */
674 if ((to_status = do_sony_cmd(&cmd_no, 1, status, (Byte *) toc, 15, 1)) != 0)
677 /* convert the data into integers so we can use them */
678 first_track_num = bcd_to_int(toc->first_track_num);
679 last_track_num = bcd_to_int(toc->last_track_num);
680 n_tracks = last_track_num - first_track_num + 1;
682 /* read each of the track address descriptors */
683 for (i = 0; i < n_tracks; i++) {
684 /* read the descriptor into a temporary buffer */
685 for (j = 0; j < 5; j++) {
686 if (read_result_reg(track_address_buffer + j) != 0)
688 if (j == 1) /* need to convert from bcd */
689 track_no = bcd_to_int(track_address_buffer[j]);
691 /* copy the descriptor to proper location - sonycd.c just fills */
692 memcpy(toc->tracks + i, track_address_buffer, 5);
695 } /* request_toc_data() */
697 /***************************************************************************
698 * int spin_up_drive( Byte status[2] )
700 * Spin up the drive (unless it is already spinning).
701 ***************************************************************************/
703 spin_up_drive(Byte status[2])
707 /* first see if the drive is already spinning */
708 cmd = SONY535_REQUEST_DRIVE_STATUS_1;
709 if (do_sony_cmd(&cmd, 1, status, NULL, 0, 0) != 0)
711 if ((status[0] & SONY535_STATUS1_NOT_SPINNING) == 0)
712 return 0; /* it's already spinning */
714 /* otherwise, give the spin-up command */
715 cmd = SONY535_SPIN_UP;
716 return do_sony_cmd(&cmd, 1, status, NULL, 0, 0);
719 /*--------------------end of SONY CDU535 very specific ---------------------*/
721 /* Convert from an integer 0-99 to BCD */
722 static inline unsigned int
723 int_to_bcd(unsigned int val)
727 retval = (val / 10) << 4;
728 retval = retval | val % 10;
733 /* Convert from BCD to an integer from 0-99 */
735 bcd_to_int(unsigned int bcd)
737 return (((bcd >> 4) & 0x0f) * 10) + (bcd & 0x0f);
742 * Convert a logical sector value (like the OS would want to use for
743 * a block device) to an MSF format.
746 log_to_msf(unsigned int log, Byte *msf)
748 log = log + LOG_START_OFFSET;
749 msf[0] = int_to_bcd(log / 4500);
751 msf[1] = int_to_bcd(log / 75);
752 msf[2] = int_to_bcd(log % 75);
757 * Convert an MSF format to a logical sector.
760 msf_to_log(Byte *msf)
765 log = bcd_to_int(msf[2]);
766 log += bcd_to_int(msf[1]) * 75;
767 log += bcd_to_int(msf[0]) * 4500;
768 log = log - LOG_START_OFFSET;
775 * Take in integer size value and put it into a buffer like
776 * the drive would want to see a number-of-sector value.
779 size_to_buf(unsigned int size, Byte *buf)
781 buf[0] = size / 65536;
789 * The OS calls this to perform a read or write operation to the drive.
790 * Write obviously fail. Reads to a read ahead of sony_buffer_size
791 * bytes to help speed operations. This especially helps since the OS
792 * may use 1024 byte blocks and the drive uses 2048 byte blocks. Since most
793 * data access on a CD is done sequentially, this saves a lot of operations.
796 do_cdu535_request(request_queue_t * q)
799 unsigned int read_size;
809 req = elv_next_request(q);
814 nsect = req->nr_sectors;
815 if (!blk_fs_request(req)) {
819 if (rq_data_dir(req) == WRITE) {
824 * If the block address is invalid or the request goes beyond
825 * the end of the media, return an error.
827 if (sony_toc->lead_out_start_lba <= (block/4)) {
831 if (sony_toc->lead_out_start_lba <= ((block + nsect) / 4)) {
837 * If the requested sector is not currently in
838 * the read-ahead buffer, it must be read in.
840 if ((block < sony_first_block) || (sony_last_block < block)) {
841 sony_first_block = (block / 4) * 4;
842 log_to_msf(block / 4, params);
845 * If the full read-ahead would go beyond the end of the media, trim
846 * it back to read just till the end of the media.
848 if (sony_toc->lead_out_start_lba <= ((block / 4) + sony_buffer_sectors)) {
849 sony_last_block = (sony_toc->lead_out_start_lba * 4) - 1;
850 read_size = sony_toc->lead_out_start_lba - (block / 4);
852 sony_last_block = sony_first_block + (sony_buffer_sectors * 4) - 1;
853 read_size = sony_buffer_sectors;
855 size_to_buf(read_size, ¶ms[3]);
858 * Read the data. If the drive was not spinning,
859 * spin it up and try some more.
861 for (spin_up_retry=0 ;; ++spin_up_retry) {
862 /* This loop has been modified to support the Sony
863 * CDU-510/515 series, thanks to Claudio Porfiri
864 * <C.Porfiri@nisms.tei.ericsson.se>.
867 * This part is to deal with very slow hardware. We
868 * try at most MAX_SPINUP_RETRY times to read the same
869 * block. A check for seek_and_read_N_blocks' result is
870 * performed; if the result is wrong, the CDROM's engine
871 * is restarted and the operation is tried again.
874 * 1995-06-01: The system got problems when downloading
875 * from Slackware CDROM, the problem seems to be:
876 * seek_and_read_N_blocks returns BAD_STATUS and we
877 * should wait for a while before retrying, so a new
878 * part was added to discriminate the return value from
879 * seek_and_read_N_blocks for the various cases.
881 int readStatus = seek_and_read_N_blocks(params, read_size,
882 status, sony_buffer, (read_size * CDU535_BLOCK_SIZE));
883 if (0 <= readStatus) /* Good data; common case, placed first */
885 if (readStatus == NO_ROOM || spin_up_retry == MAX_SPINUP_RETRY) {
887 if (readStatus == NO_ROOM)
888 printk(CDU535_MESSAGE_NAME " No room to read from CD\n");
890 printk(CDU535_MESSAGE_NAME " Read error: 0x%.2x\n",
892 sony_first_block = -1;
893 sony_last_block = -1;
897 if (readStatus == BAD_STATUS) {
898 /* Sleep for a while, then retry */
899 set_current_state(TASK_INTERRUPTIBLE);
900 spin_unlock_irq(&sonycd535_lock);
901 schedule_timeout(RETRY_FOR_BAD_STATUS*HZ/10);
902 spin_lock_irq(&sonycd535_lock);
905 printk(CDU535_MESSAGE_NAME
906 " debug: calling spin up when reading data!\n");
908 cmd[0] = SONY535_SPIN_UP;
909 do_sony_cmd(cmd, 1, status, NULL, 0, 0);
913 * The data is in memory now, copy it to the buffer and advance to the
914 * next block to read.
916 copyoff = block - sony_first_block;
918 sony_buffer[copyoff / 4] + 512 * (copyoff % 4), 512);
930 * Read the table of contents from the drive and set sony_toc_read if
937 if (!sony_toc_read) {
938 /* do not call check_drive_status() from here since it can call this routine */
939 if (request_toc_data(status, sony_toc) < 0)
941 sony_toc->lead_out_start_lba = msf_to_log(sony_toc->lead_out_start_msf);
948 * Search for a specific track in the table of contents. track is
949 * passed in bcd format
952 find_track(int track)
958 num_tracks = bcd_to_int(sony_toc->last_track_num) -
959 bcd_to_int(sony_toc->first_track_num) + 1;
960 for (i = 0; i < num_tracks; i++) {
961 if (sony_toc->tracks[i].track == track) {
970 * Read the subcode and put it int last_sony_subcode for future use.
975 Byte cmd = SONY535_REQUEST_SUB_Q_DATA;
979 if (check_drive_status() != 0)
982 if ((dsc_status = do_sony_cmd(&cmd, 1, status, (Byte *) last_sony_subcode,
983 sizeof(struct s535_sony_subcode), 1)) != 0) {
984 printk(CDU535_MESSAGE_NAME " error 0x%.2x, %d (read_subcode)\n",
985 status[0], dsc_status);
993 * Get the subchannel info like the CDROMSUBCHNL command wants to see it. If
994 * the drive is playing, the subchannel needs to be read (since it would be
995 * changing). If the drive is paused or completed, the subcode information has
996 * already been stored, just use that. The ioctl call wants things in decimal
997 * (not BCD), so all the conversions are done.
1000 sony_get_subchnl_info(long arg)
1002 struct cdrom_subchnl schi;
1004 /* Get attention stuff */
1005 if (check_drive_status() != 0)
1009 if (!sony_toc_read) {
1012 if (copy_from_user(&schi, (char *)arg, sizeof schi))
1015 switch (sony_audio_status) {
1016 case CDROM_AUDIO_PLAY:
1017 if (read_subcode() < 0) {
1022 case CDROM_AUDIO_PAUSED:
1023 case CDROM_AUDIO_COMPLETED:
1026 case CDROM_AUDIO_NO_STATUS:
1027 schi.cdsc_audiostatus = sony_audio_status;
1028 if (copy_to_user((char *)arg, &schi, sizeof schi))
1033 case CDROM_AUDIO_INVALID:
1034 case CDROM_AUDIO_ERROR:
1039 schi.cdsc_audiostatus = sony_audio_status;
1040 schi.cdsc_adr = last_sony_subcode->address;
1041 schi.cdsc_ctrl = last_sony_subcode->control;
1042 schi.cdsc_trk = bcd_to_int(last_sony_subcode->track_num);
1043 schi.cdsc_ind = bcd_to_int(last_sony_subcode->index_num);
1044 if (schi.cdsc_format == CDROM_MSF) {
1045 schi.cdsc_absaddr.msf.minute = bcd_to_int(last_sony_subcode->abs_msf[0]);
1046 schi.cdsc_absaddr.msf.second = bcd_to_int(last_sony_subcode->abs_msf[1]);
1047 schi.cdsc_absaddr.msf.frame = bcd_to_int(last_sony_subcode->abs_msf[2]);
1049 schi.cdsc_reladdr.msf.minute = bcd_to_int(last_sony_subcode->rel_msf[0]);
1050 schi.cdsc_reladdr.msf.second = bcd_to_int(last_sony_subcode->rel_msf[1]);
1051 schi.cdsc_reladdr.msf.frame = bcd_to_int(last_sony_subcode->rel_msf[2]);
1052 } else if (schi.cdsc_format == CDROM_LBA) {
1053 schi.cdsc_absaddr.lba = msf_to_log(last_sony_subcode->abs_msf);
1054 schi.cdsc_reladdr.lba = msf_to_log(last_sony_subcode->rel_msf);
1056 return copy_to_user((char *)arg, &schi, sizeof schi) ? -EFAULT : 0;
1061 * The big ugly ioctl handler.
1064 cdu_ioctl(struct inode *inode,
1070 Byte cmd_buff[10], params[10];
1074 if (check_drive_status() != 0)
1078 case CDROMSTART: /* Spin up the drive */
1079 if (spin_up_drive(status) < 0) {
1080 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMSTART)\n",
1087 case CDROMSTOP: /* Spin down the drive */
1088 cmd_buff[0] = SONY535_HOLD;
1089 do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0);
1092 * Spin the drive down, ignoring the error if the disk was
1093 * already not spinning.
1095 sony_audio_status = CDROM_AUDIO_NO_STATUS;
1096 cmd_buff[0] = SONY535_SPIN_DOWN;
1097 dsc_status = do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0);
1098 if (((dsc_status < 0) && (dsc_status != BAD_STATUS)) ||
1099 ((status[0] & ~(SONY535_STATUS1_NOT_SPINNING)) != 0)) {
1100 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMSTOP)\n",
1107 case CDROMPAUSE: /* Pause the drive */
1108 cmd_buff[0] = SONY535_HOLD; /* CDU-31 driver uses AUDIO_STOP, not pause */
1109 if (do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0) != 0) {
1110 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMPAUSE)\n",
1114 /* Get the current position and save it for resuming */
1115 if (read_subcode() < 0) {
1118 cur_pos_msf[0] = last_sony_subcode->abs_msf[0];
1119 cur_pos_msf[1] = last_sony_subcode->abs_msf[1];
1120 cur_pos_msf[2] = last_sony_subcode->abs_msf[2];
1121 sony_audio_status = CDROM_AUDIO_PAUSED;
1125 case CDROMRESUME: /* Start the drive after being paused */
1126 set_drive_mode(SONY535_AUDIO_DRIVE_MODE, status);
1128 if (sony_audio_status != CDROM_AUDIO_PAUSED) {
1131 spin_up_drive(status);
1133 /* Start the drive at the saved position. */
1134 cmd_buff[0] = SONY535_PLAY_AUDIO;
1135 cmd_buff[1] = 0; /* play back starting at this address */
1136 cmd_buff[2] = cur_pos_msf[0];
1137 cmd_buff[3] = cur_pos_msf[1];
1138 cmd_buff[4] = cur_pos_msf[2];
1139 cmd_buff[5] = SONY535_PLAY_AUDIO;
1140 cmd_buff[6] = 2; /* set ending address */
1141 cmd_buff[7] = final_pos_msf[0];
1142 cmd_buff[8] = final_pos_msf[1];
1143 cmd_buff[9] = final_pos_msf[2];
1144 if ((do_sony_cmd(cmd_buff, 5, status, NULL, 0, 0) != 0) ||
1145 (do_sony_cmd(cmd_buff + 5, 5, status, NULL, 0, 0) != 0)) {
1146 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMRESUME)\n",
1150 sony_audio_status = CDROM_AUDIO_PLAY;
1154 case CDROMPLAYMSF: /* Play starting at the given MSF address. */
1155 if (copy_from_user(params, (void *)arg, 6))
1157 spin_up_drive(status);
1158 set_drive_mode(SONY535_AUDIO_DRIVE_MODE, status);
1160 /* The parameters are given in int, must be converted */
1161 for (i = 0; i < 3; i++) {
1162 cmd_buff[2 + i] = int_to_bcd(params[i]);
1163 cmd_buff[7 + i] = int_to_bcd(params[i + 3]);
1165 cmd_buff[0] = SONY535_PLAY_AUDIO;
1166 cmd_buff[1] = 0; /* play back starting at this address */
1167 /* cmd_buff[2-4] are filled in for loop above */
1168 cmd_buff[5] = SONY535_PLAY_AUDIO;
1169 cmd_buff[6] = 2; /* set ending address */
1170 /* cmd_buff[7-9] are filled in for loop above */
1171 if ((do_sony_cmd(cmd_buff, 5, status, NULL, 0, 0) != 0) ||
1172 (do_sony_cmd(cmd_buff + 5, 5, status, NULL, 0, 0) != 0)) {
1173 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMPLAYMSF)\n",
1177 /* Save the final position for pauses and resumes */
1178 final_pos_msf[0] = cmd_buff[7];
1179 final_pos_msf[1] = cmd_buff[8];
1180 final_pos_msf[2] = cmd_buff[9];
1181 sony_audio_status = CDROM_AUDIO_PLAY;
1185 case CDROMREADTOCHDR: /* Read the table of contents header */
1187 struct cdrom_tochdr *hdr;
1188 struct cdrom_tochdr loc_hdr;
1193 hdr = (struct cdrom_tochdr *)arg;
1194 loc_hdr.cdth_trk0 = bcd_to_int(sony_toc->first_track_num);
1195 loc_hdr.cdth_trk1 = bcd_to_int(sony_toc->last_track_num);
1196 if (copy_to_user(hdr, &loc_hdr, sizeof *hdr))
1202 case CDROMREADTOCENTRY: /* Read a given table of contents entry */
1204 struct cdrom_tocentry *entry;
1205 struct cdrom_tocentry loc_entry;
1207 Byte *msf_val = NULL;
1210 if (!sony_toc_read) {
1213 entry = (struct cdrom_tocentry *)arg;
1215 if (copy_from_user(&loc_entry, entry, sizeof loc_entry))
1218 /* Lead out is handled separately since it is special. */
1219 if (loc_entry.cdte_track == CDROM_LEADOUT) {
1220 loc_entry.cdte_adr = 0 /*sony_toc->address2 */ ;
1221 loc_entry.cdte_ctrl = sony_toc->control2;
1222 msf_val = sony_toc->lead_out_start_msf;
1224 track_idx = find_track(int_to_bcd(loc_entry.cdte_track));
1227 loc_entry.cdte_adr = 0 /*sony_toc->tracks[track_idx].address */ ;
1228 loc_entry.cdte_ctrl = sony_toc->tracks[track_idx].control;
1229 msf_val = sony_toc->tracks[track_idx].track_start_msf;
1232 /* Logical buffer address or MSF format requested? */
1233 if (loc_entry.cdte_format == CDROM_LBA) {
1234 loc_entry.cdte_addr.lba = msf_to_log(msf_val);
1235 } else if (loc_entry.cdte_format == CDROM_MSF) {
1236 loc_entry.cdte_addr.msf.minute = bcd_to_int(*msf_val);
1237 loc_entry.cdte_addr.msf.second = bcd_to_int(*(msf_val + 1));
1238 loc_entry.cdte_addr.msf.frame = bcd_to_int(*(msf_val + 2));
1240 if (copy_to_user(entry, &loc_entry, sizeof *entry))
1246 case CDROMPLAYTRKIND: /* Play a track. This currently ignores index. */
1255 if (copy_from_user(&ti, (char *)arg, sizeof ti))
1257 if ((ti.cdti_trk0 < sony_toc->first_track_num)
1258 || (sony_toc->last_track_num < ti.cdti_trk0)
1259 || (ti.cdti_trk1 < ti.cdti_trk0)) {
1262 track_idx = find_track(int_to_bcd(ti.cdti_trk0));
1265 params[1] = sony_toc->tracks[track_idx].track_start_msf[0];
1266 params[2] = sony_toc->tracks[track_idx].track_start_msf[1];
1267 params[3] = sony_toc->tracks[track_idx].track_start_msf[2];
1269 * If we want to stop after the last track, use the lead-out
1272 if (bcd_to_int(sony_toc->last_track_num) <= ti.cdti_trk1) {
1273 log_to_msf(msf_to_log(sony_toc->lead_out_start_msf) - 1,
1276 track_idx = find_track(int_to_bcd(ti.cdti_trk1 + 1));
1279 log_to_msf(msf_to_log(sony_toc->tracks[track_idx].track_start_msf) - 1,
1284 spin_up_drive(status);
1286 set_drive_mode(SONY535_AUDIO_DRIVE_MODE, status);
1288 /* Start the drive at the saved position. */
1289 cmd_buff[0] = SONY535_PLAY_AUDIO;
1290 cmd_buff[1] = 0; /* play back starting at this address */
1291 cmd_buff[2] = params[1];
1292 cmd_buff[3] = params[2];
1293 cmd_buff[4] = params[3];
1294 cmd_buff[5] = SONY535_PLAY_AUDIO;
1295 cmd_buff[6] = 2; /* set ending address */
1296 cmd_buff[7] = params[4];
1297 cmd_buff[8] = params[5];
1298 cmd_buff[9] = params[6];
1299 if ((do_sony_cmd(cmd_buff, 5, status, NULL, 0, 0) != 0) ||
1300 (do_sony_cmd(cmd_buff + 5, 5, status, NULL, 0, 0) != 0)) {
1301 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMPLAYTRKIND)\n",
1303 printk("... Params: %x %x %x %x %x %x %x\n",
1304 params[0], params[1], params[2],
1305 params[3], params[4], params[5], params[6]);
1308 /* Save the final position for pauses and resumes */
1309 final_pos_msf[0] = params[4];
1310 final_pos_msf[1] = params[5];
1311 final_pos_msf[2] = params[6];
1312 sony_audio_status = CDROM_AUDIO_PLAY;
1316 case CDROMSUBCHNL: /* Get subchannel info */
1317 return sony_get_subchnl_info(arg);
1319 case CDROMVOLCTRL: /* Volume control. What volume does this change, anyway? */
1321 struct cdrom_volctrl volctrl;
1323 if (copy_from_user(&volctrl, (char *)arg,
1326 cmd_buff[0] = SONY535_SET_VOLUME;
1327 cmd_buff[1] = volctrl.channel0;
1328 cmd_buff[2] = volctrl.channel1;
1329 if (do_sony_cmd(cmd_buff, 3, status, NULL, 0, 0) != 0) {
1330 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMVOLCTRL)\n",
1337 case CDROMEJECT: /* Eject the drive */
1338 cmd_buff[0] = SONY535_STOP;
1339 do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0);
1340 cmd_buff[0] = SONY535_SPIN_DOWN;
1341 do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0);
1343 sony_audio_status = CDROM_AUDIO_INVALID;
1344 cmd_buff[0] = SONY535_EJECT_CADDY;
1345 if (do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0) != 0) {
1346 printk(CDU535_MESSAGE_NAME " error 0x%.2x (CDROMEJECT)\n",
1360 * Open the drive for operations. Spin the drive up and read the table of
1361 * contents if these have not already been done.
1364 cdu_open(struct inode *inode,
1367 Byte status[2], cmd_buff[2];
1371 if (check_drive_status() != 0)
1375 if (spin_up_drive(status) != 0) {
1376 printk(CDU535_MESSAGE_NAME " error 0x%.2x (cdu_open, spin up)\n",
1382 if (!sony_toc_read) {
1383 cmd_buff[0] = SONY535_SPIN_DOWN;
1384 do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0);
1388 check_disk_change(inode->i_bdev);
1392 /* disable the eject button while mounted */
1393 cmd_buff[0] = SONY535_DISABLE_EJECT_BUTTON;
1394 do_sony_cmd(cmd_buff, 1, status, NULL, 0, 0);
1402 * Close the drive. Spin it down if no task is using it. The spin
1403 * down will fail if playing audio, so audio play is OK.
1406 cdu_release(struct inode *inode,
1409 Byte status[2], cmd_no;
1413 if (0 < sony_usage) {
1416 if (sony_usage == 0) {
1417 check_drive_status();
1419 if (sony_audio_status != CDROM_AUDIO_PLAY) {
1420 cmd_no = SONY535_SPIN_DOWN;
1421 do_sony_cmd(&cmd_no, 1, status, NULL, 0, 0);
1424 /* enable the eject button after umount */
1425 cmd_no = SONY535_ENABLE_EJECT_BUTTON;
1426 do_sony_cmd(&cmd_no, 1, status, NULL, 0, 0);
1432 static struct block_device_operations cdu_fops =
1434 .owner = THIS_MODULE,
1436 .release = cdu_release,
1438 .media_changed = cdu535_check_media_change,
1441 static struct gendisk *cdu_disk;
1444 * Initialize the driver.
1446 static int __init sony535_init(void)
1448 struct s535_sony_drive_config drive_config;
1458 /* Setting the base I/O address to 0 will disable it. */
1459 if ((sony535_cd_base_io == 0xffff)||(sony535_cd_base_io == 0))
1462 /* Set up all the register locations */
1463 result_reg = sony535_cd_base_io;
1464 command_reg = sony535_cd_base_io;
1465 data_reg = sony535_cd_base_io + 1;
1466 read_status_reg = sony535_cd_base_io + 2;
1467 select_unit_reg = sony535_cd_base_io + 3;
1470 sony535_irq_used = 0; /* polling only until this is ready... */
1472 /* we need to poll until things get initialized */
1473 tmp_irq = sony535_irq_used;
1474 sony535_irq_used = 0;
1477 printk(KERN_INFO CDU535_MESSAGE_NAME ": probing base address %03X\n",
1478 sony535_cd_base_io);
1480 /* look for the CD-ROM, follows the procedure in the DOS driver */
1481 inb(select_unit_reg);
1482 /* wait for 40 18 Hz ticks (reverse-engineered from DOS driver) */
1483 set_current_state(TASK_INTERRUPTIBLE);
1484 schedule_timeout((HZ+17)*40/18);
1487 outb(0, read_status_reg); /* does a reset? */
1489 while (jiffies-snap < SONY_JIFFIES_TIMEOUT) {
1491 if (inb(result_reg) != 0xff) {
1498 if (!got_result || check_drive_status() == TIME_OUT)
1501 /* CD-ROM drive responded -- get the drive configuration */
1502 cmd_buff[0] = SONY535_INQUIRY;
1503 if (do_sony_cmd(cmd_buff, 1, status, (Byte *)&drive_config, 28, 1) != 0)
1506 /* was able to get the configuration,
1507 * set drive mode as rest of init
1510 /* 0x50 == CADDY_NOT_INSERTED | NOT_SPINNING */
1511 if ( (status[0] & 0x7f) != 0 && (status[0] & 0x7f) != 0x50 )
1512 printk(CDU535_MESSAGE_NAME
1513 "Inquiry command returned status = 0x%x\n", status[0]);
1515 /* now ready to use interrupts, if available */
1516 sony535_irq_used = tmp_irq;
1518 /* A negative sony535_irq_used will attempt an autoirq. */
1519 if (sony535_irq_used < 0) {
1520 unsigned long irq_mask, delay;
1522 irq_mask = probe_irq_on();
1523 enable_interrupts();
1524 outb(0, read_status_reg); /* does a reset? */
1525 delay = jiffies + HZ/10;
1526 while (time_before(jiffies, delay)) ;
1528 sony535_irq_used = probe_irq_off(irq_mask);
1529 disable_interrupts();
1531 if (sony535_irq_used > 0) {
1532 if (request_irq(sony535_irq_used, cdu535_interrupt,
1533 SA_INTERRUPT, CDU535_HANDLE, NULL)) {
1534 printk("Unable to grab IRQ%d for the " CDU535_MESSAGE_NAME
1535 " driver; polling instead.\n", sony535_irq_used);
1536 sony535_irq_used = 0;
1539 cmd_buff[0] = SONY535_SET_DRIVE_MODE;
1540 cmd_buff[1] = 0x0; /* default audio */
1541 if (do_sony_cmd(cmd_buff, 2, status, ret_buff, 1, 1) != 0)
1544 /* set the drive mode successful, we are set! */
1545 sony_buffer_size = SONY535_BUFFER_SIZE;
1546 sony_buffer_sectors = sony_buffer_size / CDU535_BLOCK_SIZE;
1548 printk(KERN_INFO CDU535_MESSAGE_NAME " I/F CDROM : %8.8s %16.16s %4.4s",
1549 drive_config.vendor_id,
1550 drive_config.product_id,
1551 drive_config.product_rev_level);
1552 printk(" base address %03X, ", sony535_cd_base_io);
1554 printk("IRQ%d, ", tmp_irq);
1555 printk("using %d byte buffer\n", sony_buffer_size);
1557 if (register_blkdev(MAJOR_NR, CDU535_HANDLE)) {
1561 sonycd535_queue = blk_init_queue(do_cdu535_request, &sonycd535_lock);
1562 if (!sonycd535_queue) {
1567 blk_queue_hardsect_size(sonycd535_queue, CDU535_BLOCK_SIZE);
1568 sony_toc = kmalloc(sizeof(struct s535_sony_toc), GFP_KERNEL);
1572 last_sony_subcode = kmalloc(sizeof(struct s535_sony_subcode), GFP_KERNEL);
1573 if (!last_sony_subcode)
1575 sony_buffer = kmalloc(sizeof(Byte *) * sony_buffer_sectors, GFP_KERNEL);
1578 for (i = 0; i < sony_buffer_sectors; i++) {
1579 sony_buffer[i] = kmalloc(CDU535_BLOCK_SIZE, GFP_KERNEL);
1580 if (!sony_buffer[i]) {
1582 kfree(sony_buffer[i]);
1588 cdu_disk = alloc_disk(1);
1591 cdu_disk->major = MAJOR_NR;
1592 cdu_disk->first_minor = 0;
1593 cdu_disk->fops = &cdu_fops;
1594 sprintf(cdu_disk->disk_name, "cdu");
1595 sprintf(cdu_disk->devfs_name, "cdu535");
1597 if (!request_region(sony535_cd_base_io, 4, CDU535_HANDLE)) {
1598 printk(KERN_WARNING"sonycd535: Unable to request region 0x%x\n",
1599 sony535_cd_base_io);
1602 cdu_disk->queue = sonycd535_queue;
1609 for (i = 0; i < sony_buffer_sectors; i++)
1611 kfree(sony_buffer[i]);
1615 kfree(last_sony_subcode);
1619 blk_cleanup_queue(sonycd535_queue);
1621 unregister_blkdev(MAJOR_NR, CDU535_HANDLE);
1623 if (sony535_irq_used)
1624 free_irq(sony535_irq_used, NULL);
1627 if (sony535_irq_used)
1628 free_irq(sony535_irq_used, NULL);
1630 printk("Did not find a " CDU535_MESSAGE_NAME " drive\n");
1637 * accept "kernel command line" parameters
1638 * (added by emoenke@gwdg.de)
1643 * the address value has to be the existing CDROM port address.
1646 sonycd535_setup(char *strings)
1649 (void)get_options(strings, ARRAY_SIZE(ints), ints);
1650 /* if IRQ change and default io base desired,
1651 * then call with io base of 0
1655 sony535_cd_base_io = ints[1];
1657 sony535_irq_used = ints[2];
1658 if ((strings != NULL) && (*strings != '\0'))
1659 printk(CDU535_MESSAGE_NAME
1660 ": Warning: Unknown interface type: %s\n", strings);
1665 __setup("sonycd535=", sonycd535_setup);
1674 release_region(sony535_cd_base_io, 4);
1675 for (i = 0; i < sony_buffer_sectors; i++)
1676 kfree(sony_buffer[i]);
1678 kfree(last_sony_subcode);
1680 del_gendisk(cdu_disk);
1682 blk_cleanup_queue(sonycd535_queue);
1683 if (unregister_blkdev(MAJOR_NR, CDU535_HANDLE) == -EINVAL)
1684 printk("Uh oh, couldn't unregister " CDU535_HANDLE "\n");
1686 printk(KERN_INFO CDU535_HANDLE " module released\n");
1689 module_init(sony535_init);
1690 module_exit(sony535_exit);
1693 MODULE_LICENSE("GPL");
1694 MODULE_ALIAS_BLOCKDEV_MAJOR(CDU535_CDROM_MAJOR);