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>)
35 * - handle errors and status better, put everything into a single word
36 * - use interrupts (code mostly there, but a big hole still missing)
37 * - handle multi-session CDs?
43 * Ken Pizzini (ken@halcyon.com)
46 * Ron Jeppesen (ronj.an@site007.saic.com)
49 *------------------------------------------------------------------------
50 * Sony CDROM interface device driver.
52 * Corey Minyard (minyard@wf-rch.cirr.com) (CDU-535 complaints to Ken above)
56 * The Sony interface device driver handles Sony interface CDROM
57 * drives and provides a complete block-level interface as well as an
58 * ioctl() interface compatible with the Sun (as specified in
59 * include/linux/cdrom.h). With this interface, CDROMs can be
60 * accessed and standard audio CDs can be played back normally.
62 * This interface is (unfortunately) a polled interface. This is
63 * because most Sony interfaces are set up with DMA and interrupts
64 * disables. Some (like mine) do not even have the capability to
65 * handle interrupts or DMA. For this reason you will see a lot of
68 * retry_count = jiffies+ SONY_JIFFIES_TIMEOUT;
69 * while ((retry_count > jiffies) && (! <some condition to wait for))
71 * while (handle_sony_cd_attention())
76 * if (the condition not met)
81 * This ugly hack waits for something to happen, sleeping a little
82 * between every try. it also handles attentions, which are
83 * asynchronous events from the drive informing the driver that a disk
84 * has been inserted, removed, etc.
86 * One thing about these drives: They talk in MSF (Minute Second Frame) format.
87 * There are 75 frames a second, 60 seconds a minute, and up to 75 minutes on a
88 * disk. The funny thing is that these are sent to the drive in BCD, but the
89 * interface wants to see them in decimal. A lot of conversion goes on.
91 * Copyright (C) 1993 Corey Minyard
93 * This program is free software; you can redistribute it and/or modify
94 * it under the terms of the GNU General Public License as published by
95 * the Free Software Foundation; either version 2 of the License, or
96 * (at your option) any later version.
98 * This program is distributed in the hope that it will be useful,
99 * but WITHOUT ANY WARRANTY; without even the implied warranty of
100 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
101 * GNU General Public License for more details.
103 * You should have received a copy of the GNU General Public License
104 * along with this program; if not, write to the Free Software
105 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
110 # include <linux/module.h>
112 #include <linux/errno.h>
113 #include <linux/signal.h>
114 #include <linux/sched.h>
115 #include <linux/timer.h>
116 #include <linux/fs.h>
117 #include <linux/kernel.h>
118 #include <linux/ioport.h>
119 #include <linux/hdreg.h>
120 #include <linux/genhd.h>
121 #include <linux/mm.h>
122 #include <linux/malloc.h>
123 #include <linux/init.h>
125 #define REALLY_SLOW_IO
126 #include <asm/system.h>
128 #include <asm/uaccess.h>
130 #include <linux/cdrom.h>
132 #define MAJOR_NR CDU535_CDROM_MAJOR
133 # include <linux/blk.h>
134 #define sony535_cd_base_io sonycd535 /* for compatible parameter passing with "insmod" */
135 #include "sonycd535.h"
138 * this is the base address of the interface card for the Sony CDU-535
139 * CDROM drive. If your jumpers are set for an address other than
140 * this one (the default), change the following line to the
143 #ifndef CDU535_ADDRESS
144 # define CDU535_ADDRESS 0x340
146 #ifndef CDU535_INTERRUPT
147 # define CDU535_INTERRUPT 0
149 #ifndef CDU535_HANDLE
150 # define CDU535_HANDLE "cdu535"
152 #ifndef CDU535_MESSAGE_NAME
153 # define CDU535_MESSAGE_NAME "Sony CDU-535"
156 #ifndef MAX_SPINUP_RETRY
157 # define MAX_SPINUP_RETRY 3 /* 1 is sufficient for most drives... */
159 #ifndef RETRY_FOR_BAD_STATUS
160 # define RETRY_FOR_BAD_STATUS 100 /* in 10th of second */
168 * SONY535_BUFFER_SIZE determines the size of internal buffer used
169 * by the drive. It must be at least 2K and the larger the buffer
170 * the better the transfer rate. It does however take system memory.
171 * On my system I get the following transfer rates using dd to read
172 * 10 Mb off /dev/cdrom.
174 * 8K buffer 43 Kb/sec
175 * 16K buffer 66 Kb/sec
176 * 32K buffer 91 Kb/sec
177 * 64K buffer 111 Kb/sec
178 * 128K buffer 123 Kb/sec
179 * 512K buffer 123 Kb/sec
181 #define SONY535_BUFFER_SIZE (64*1024)
184 * if LOCK_DOORS is defined then the eject button is disabled while
185 * the device is open.
187 #ifndef NO_LOCK_DOORS
191 static int read_subcode(void);
192 static void sony_get_toc(void);
193 static int cdu_open(struct inode
*inode
, struct file
*filp
);
194 static inline unsigned int int_to_bcd(unsigned int val
);
195 static unsigned int bcd_to_int(unsigned int bcd
);
196 static int do_sony_cmd(Byte
* cmd
, int nCmd
, Byte status
[2],
197 Byte
* response
, int n_response
, int ignoreStatusBit7
);
199 /* The base I/O address of the Sony Interface. This is a variable (not a
200 #define) so it can be easily changed via some future ioctl() */
201 static unsigned int sony535_cd_base_io
= CDU535_ADDRESS
;
202 MODULE_PARM(sony535_cd_base_io
, "i");
205 * The following are I/O addresses of the various registers for the drive. The
206 * comment for the base address also applies here.
208 static unsigned short select_unit_reg
;
209 static unsigned short result_reg
;
210 static unsigned short command_reg
;
211 static unsigned short read_status_reg
;
212 static unsigned short data_reg
;
214 static int initialized
= 0; /* Has the drive been initialized? */
215 static int sony_disc_changed
= 1; /* Has the disk been changed
216 since the last check? */
217 static int sony_toc_read
= 0; /* Has the table of contents been
219 static unsigned int sony_buffer_size
; /* Size in bytes of the read-ahead
221 static unsigned int sony_buffer_sectors
; /* Size (in 2048 byte records) of
222 the read-ahead buffer. */
223 static unsigned int sony_usage
= 0; /* How many processes have the
226 static int sony_first_block
= -1; /* First OS block (512 byte) in
227 the read-ahead buffer */
228 static int sony_last_block
= -1; /* Last OS block (512 byte) in
229 the read-ahead buffer */
231 static struct s535_sony_toc
*sony_toc
; /* Points to the table of
234 static struct s535_sony_subcode
*last_sony_subcode
; /* Points to the last
235 subcode address read */
236 static Byte
**sony_buffer
; /* Points to the pointers
237 to the sector buffers */
239 static int sony_inuse
= 0; /* is the drive in use? Only one
240 open at a time allowed */
243 * The audio status uses the values from read subchannel data as specified
244 * in include/linux/cdrom.h.
246 static int sony_audio_status
= CDROM_AUDIO_NO_STATUS
;
249 * The following are a hack for pausing and resuming audio play. The drive
250 * does not work as I would expect it, if you stop it then start it again,
251 * the drive seeks back to the beginning and starts over. This holds the
252 * position during a pause so a resume can restart it. It uses the
253 * audio status variable above to tell if it is paused.
254 * I just kept the CDU-31A driver behavior rather than using the PAUSE
255 * command on the CDU-535.
257 static Byte cur_pos_msf
[3] = {0, 0, 0};
258 static Byte final_pos_msf
[3] = {0, 0, 0};
260 /* What IRQ is the drive using? 0 if none. */
261 static int sony535_irq_used
= CDU535_INTERRUPT
;
263 /* The interrupt handler will wake this queue up when it gets an interrupt. */
264 static struct wait_queue
*cdu535_irq_wait
= NULL
;
268 * This routine returns 1 if the disk has been changed since the last
269 * check or 0 if it hasn't. Setting flag to 0 resets the changed flag.
272 cdu535_check_media_change(kdev_t full_dev
)
276 if (MINOR(full_dev
) != 0) {
277 printk(CDU535_MESSAGE_NAME
" request error: invalid device.\n");
281 /* if driver is not initialized, always return 0 */
282 retval
= initialized
? sony_disc_changed
: 0;
283 sony_disc_changed
= 0;
288 enable_interrupts(void)
292 * This code was taken from cdu31a.c; it will not
293 * directly work for the cdu535 as written...
295 curr_control_reg
|= ( SONY_ATTN_INT_EN_BIT
296 | SONY_RES_RDY_INT_EN_BIT
297 | SONY_DATA_RDY_INT_EN_BIT
);
298 outb(curr_control_reg
, sony_cd_control_reg
);
303 disable_interrupts(void)
307 * This code was taken from cdu31a.c; it will not
308 * directly work for the cdu535 as written...
310 curr_control_reg
&= ~(SONY_ATTN_INT_EN_BIT
311 | SONY_RES_RDY_INT_EN_BIT
312 | SONY_DATA_RDY_INT_EN_BIT
);
313 outb(curr_control_reg
, sony_cd_control_reg
);
318 cdu535_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
320 disable_interrupts();
321 if (cdu535_irq_wait
!= NULL
)
322 wake_up(&cdu535_irq_wait
);
324 printk(CDU535_MESSAGE_NAME
325 ": Got an interrupt but nothing was waiting\n");
330 * Wait a little while (used for polling the drive). If in initialization,
331 * setting a timeout doesn't work, so just loop for a while. (We trust
332 * that the sony_sleep() call is protected by a test for proper jiffies count.)
337 if (sony535_irq_used
<= 0) { /* poll */
338 current
->state
= TASK_INTERRUPTIBLE
;
339 current
->timeout
= jiffies
;
341 } else { /* Interrupt driven */
344 interruptible_sleep_on(&cdu535_irq_wait
);
349 /*------------------start of SONY CDU535 very specific ---------------------*/
351 /****************************************************************************
352 * void select_unit( int unit_no )
354 * Select the specified unit (0-3) so that subsequent commands reference it
355 ****************************************************************************/
357 select_unit(int unit_no
)
359 unsigned int select_mask
= ~(1 << unit_no
);
360 outb(select_mask
, select_unit_reg
);
363 /***************************************************************************
364 * int read_result_reg( Byte *data_ptr )
366 * Read a result byte from the Sony CDU controller, store in location pointed
367 * to by data_ptr. Return zero on success, TIME_OUT if we did not receive
369 ***************************************************************************/
371 read_result_reg(Byte
*data_ptr
)
376 retry_count
= jiffies
+ SONY_JIFFIES_TIMEOUT
;
377 while (jiffies
< retry_count
) {
378 if (((read_status
= inb(read_status_reg
)) & SONY535_RESULT_NOT_READY_BIT
) == 0) {
380 printk(CDU535_MESSAGE_NAME
381 ": read_result_reg(): readStatReg = 0x%x\n", read_status
);
383 *data_ptr
= inb(result_reg
);
389 printk(CDU535_MESSAGE_NAME
" read_result_reg: TIME OUT!\n");
393 /****************************************************************************
394 * int read_exec_status( Byte status[2] )
396 * Read the execution status of the last command and put into status.
397 * Handles reading second status word if available. Returns 0 on success,
398 * TIME_OUT on failure.
399 ****************************************************************************/
401 read_exec_status(Byte status
[2])
404 if (read_result_reg(&(status
[0])) != 0)
406 if ((status
[0] & 0x80) != 0) { /* byte two follows */
407 if (read_result_reg(&(status
[1])) != 0)
411 printk(CDU535_MESSAGE_NAME
": read_exec_status: read 0x%x 0x%x\n",
412 status
[0], status
[1]);
417 /****************************************************************************
418 * int check_drive_status( void )
420 * Check the current drive status. Using this before executing a command
421 * takes care of the problem of unsolicited drive status-2 messages.
422 * Add a check of the audio status if we think the disk is playing.
423 ****************************************************************************/
425 check_drive_status(void)
427 Byte status
, e_status
[2];
432 if (sony_audio_status
== CDROM_AUDIO_PLAY
) { /* check status */
433 outb(SONY535_REQUEST_AUDIO_STATUS
, command_reg
);
434 if (read_result_reg(&status
) == 0) {
437 break; /* play in progress */
440 case 0x3: /* audio play completed */
441 case 0x5: /* play not requested */
442 sony_audio_status
= CDROM_AUDIO_COMPLETED
;
445 case 0x4: /* error during play */
446 sony_audio_status
= CDROM_AUDIO_ERROR
;
451 /* now check drive status */
452 outb(SONY535_REQUEST_DRIVE_STATUS_2
, command_reg
);
453 if (read_result_reg(&status
) != 0)
457 printk(CDU535_MESSAGE_NAME
": check_drive_status() got 0x%x\n", status
);
464 CDD
= (status
>> 4) & 0xf;
468 break; /* go on to CDD stuff */
469 case SONY535_ATN_BUSY
:
471 printk(CDU535_MESSAGE_NAME
" error: drive busy\n");
473 case SONY535_ATN_EJECT_IN_PROGRESS
:
474 printk(CDU535_MESSAGE_NAME
" error: eject in progress\n");
475 sony_audio_status
= CDROM_AUDIO_INVALID
;
477 case SONY535_ATN_RESET_OCCURRED
:
478 case SONY535_ATN_DISC_CHANGED
:
479 case SONY535_ATN_RESET_AND_DISC_CHANGED
:
481 printk(CDU535_MESSAGE_NAME
" notice: reset occurred or disc changed\n");
483 sony_disc_changed
= 1;
485 sony_audio_status
= CDROM_AUDIO_NO_STATUS
;
486 sony_first_block
= -1;
487 sony_last_block
= -1;
489 cmd
= SONY535_SPIN_UP
;
490 do_sony_cmd(&cmd
, 1, e_status
, NULL
, 0, 0);
495 printk(CDU535_MESSAGE_NAME
" error: drive busy (ATN=0x%x)\n", ATN
);
498 switch (CDD
) { /* the 531 docs are not helpful in decoding this */
499 case 0x0: /* just use the values from the DOS driver */
502 break; /* no error */
504 printk(CDU535_MESSAGE_NAME
505 ": check_drive_status(): CDD = 0xc! Not properly handled!\n");
506 return CD_BUSY
; /* ? */
511 } /* check_drive_status() */
513 /*****************************************************************************
514 * int do_sony_cmd( Byte *cmd, int n_cmd, Byte status[2],
515 * Byte *response, int n_response, int ignore_status_bit7 )
517 * Generic routine for executing commands. The command and its parameters
518 * should be placed in the cmd[] array, number of bytes in the command is
519 * stored in nCmd. The response from the command will be stored in the
520 * response array. The number of bytes you expect back (excluding status)
521 * should be passed in n_response. Finally, some
522 * commands set bit 7 of the return status even when there is no second
523 * status byte, on these commands set ignoreStatusBit7 TRUE.
524 * If the command was sent and data received back, then we return 0,
525 * else we return TIME_OUT. You still have to check the status yourself.
526 * You should call check_drive_status() before calling this routine
527 * so that you do not lose notifications of disk changes, etc.
528 ****************************************************************************/
530 do_sony_cmd(Byte
* cmd
, int n_cmd
, Byte status
[2],
531 Byte
* response
, int n_response
, int ignore_status_bit7
)
535 /* write out the command */
536 for (i
= 0; i
< n_cmd
; i
++)
537 outb(cmd
[i
], command_reg
);
539 /* read back the status */
540 if (read_result_reg(status
) != 0)
542 if (!ignore_status_bit7
&& ((status
[0] & 0x80) != 0)) {
543 /* get second status byte */
544 if (read_result_reg(status
+ 1) != 0)
550 printk(CDU535_MESSAGE_NAME
": do_sony_cmd %x: %x %x\n",
551 *cmd
, status
[0], status
[1]);
554 /* do not know about when I should read set of data and when not to */
555 if ((status
[0] & ((ignore_status_bit7
? 0x7f : 0xff) & 0x8f)) != 0)
558 /* else, read in rest of data */
559 for (i
= 0; 0 < n_response
; n_response
--, i
++)
560 if (read_result_reg(response
+ i
) != 0)
563 } /* do_sony_cmd() */
565 /**************************************************************************
566 * int set_drive_mode( int mode, Byte status[2] )
568 * Set the drive mode to the specified value (mode=0 is audio, mode=e0
570 **************************************************************************/
572 set_drive_mode(int mode
, Byte status
[2])
577 cmd_buff
[0] = SONY535_SET_DRIVE_MODE
;
579 return do_sony_cmd(cmd_buff
, 2, status
, ret_buff
, 1, 1);
582 /***************************************************************************
583 * int seek_and_read_N_blocks( Byte params[], int n_blocks, Byte status[2],
584 * Byte *data_buff, int buff_size )
586 * Read n_blocks of data from the CDROM starting at position params[0:2],
587 * number of blocks in stored in params[3:5] -- both these are already
589 * Transfer the data into the buffer pointed at by data_buff. buff_size
590 * gives the number of bytes available in the buffer.
591 * The routine returns number of bytes read in if successful, otherwise
592 * it returns one of the standard error returns.
593 ***************************************************************************/
595 seek_and_read_N_blocks(Byte params
[], int n_blocks
, Byte status
[2],
596 Byte
**buff
, int buf_size
)
598 const int block_size
= 2048;
604 int sector_count
= 0;
606 if (buf_size
< ((long)block_size
) * n_blocks
)
609 set_drive_mode(SONY535_CDROM_DRIVE_MODE
, status
);
611 /* send command to read the data */
612 cmd_buff
[0] = SONY535_SEEK_AND_READ_N_BLOCKS_1
;
613 for (i
= 0; i
< 6; i
++)
614 cmd_buff
[i
+ 1] = params
[i
];
615 for (i
= 0; i
< 7; i
++)
616 outb(cmd_buff
[i
], command_reg
);
618 /* read back the data one block at a time */
619 while (0 < n_blocks
--) {
620 /* wait for data to be ready */
621 retry_count
= jiffies
+ SONY_JIFFIES_TIMEOUT
;
622 while (jiffies
< retry_count
) {
623 read_status
= inb(read_status_reg
);
624 if ((read_status
& SONY535_RESULT_NOT_READY_BIT
) == 0) {
625 read_exec_status(status
);
628 if ((read_status
& SONY535_DATA_NOT_READY_BIT
) == 0) {
629 /* data is ready, read it */
630 data_buff
= buff
[sector_count
++];
631 for (i
= 0; i
< block_size
; i
++)
632 *data_buff
++ = inb(data_reg
); /* unrolling this loop does not seem to help */
633 break; /* exit the timeout loop */
635 sony_sleep(); /* data not ready, sleep a while */
637 if (retry_count
<= jiffies
)
638 return TIME_OUT
; /* if we reach this stage */
641 /* read all the data, now read the status */
642 if ((i
= read_exec_status(status
)) != 0)
644 return block_size
* sector_count
;
645 } /* seek_and_read_N_blocks() */
647 /****************************************************************************
648 * int request_toc_data( Byte status[2], struct s535_sony_toc *toc )
650 * Read in the table of contents data. Converts all the bcd data
651 * into integers in the toc structure.
652 ****************************************************************************/
654 request_toc_data(Byte status
[2], struct s535_sony_toc
*toc
)
657 int i
, j
, n_tracks
, track_no
;
658 int first_track_num
, last_track_num
;
660 Byte track_address_buffer
[5];
662 /* read the fixed portion of the table of contents */
663 if ((to_status
= do_sony_cmd(&cmd_no
, 1, status
, (Byte
*) toc
, 15, 1)) != 0)
666 /* convert the data into integers so we can use them */
667 first_track_num
= bcd_to_int(toc
->first_track_num
);
668 last_track_num
= bcd_to_int(toc
->last_track_num
);
669 n_tracks
= last_track_num
- first_track_num
+ 1;
671 /* read each of the track address descriptors */
672 for (i
= 0; i
< n_tracks
; i
++) {
673 /* read the descriptor into a temporary buffer */
674 for (j
= 0; j
< 5; j
++) {
675 if (read_result_reg(track_address_buffer
+ j
) != 0)
677 if (j
== 1) /* need to convert from bcd */
678 track_no
= bcd_to_int(track_address_buffer
[j
]);
680 /* copy the descriptor to proper location - sonycd.c just fills */
681 memcpy(toc
->tracks
+ i
, track_address_buffer
, 5);
684 } /* request_toc_data() */
686 /***************************************************************************
687 * int spin_up_drive( Byte status[2] )
689 * Spin up the drive (unless it is already spinning).
690 ***************************************************************************/
692 spin_up_drive(Byte status
[2])
696 /* first see if the drive is already spinning */
697 cmd
= SONY535_REQUEST_DRIVE_STATUS_1
;
698 if (do_sony_cmd(&cmd
, 1, status
, NULL
, 0, 0) != 0)
700 if ((status
[0] & SONY535_STATUS1_NOT_SPINNING
) == 0)
701 return 0; /* it's already spinning */
703 /* otherwise, give the spin-up command */
704 cmd
= SONY535_SPIN_UP
;
705 return do_sony_cmd(&cmd
, 1, status
, NULL
, 0, 0);
708 /*--------------------end of SONY CDU535 very specific ---------------------*/
710 /* Convert from an integer 0-99 to BCD */
711 static inline unsigned int
712 int_to_bcd(unsigned int val
)
716 retval
= (val
/ 10) << 4;
717 retval
= retval
| val
% 10;
722 /* Convert from BCD to an integer from 0-99 */
724 bcd_to_int(unsigned int bcd
)
726 return (((bcd
>> 4) & 0x0f) * 10) + (bcd
& 0x0f);
731 * Convert a logical sector value (like the OS would want to use for
732 * a block device) to an MSF format.
735 log_to_msf(unsigned int log
, Byte
*msf
)
737 log
= log
+ LOG_START_OFFSET
;
738 msf
[0] = int_to_bcd(log
/ 4500);
740 msf
[1] = int_to_bcd(log
/ 75);
741 msf
[2] = int_to_bcd(log
% 75);
746 * Convert an MSF format to a logical sector.
749 msf_to_log(Byte
*msf
)
754 log
= bcd_to_int(msf
[2]);
755 log
+= bcd_to_int(msf
[1]) * 75;
756 log
+= bcd_to_int(msf
[0]) * 4500;
757 log
= log
- LOG_START_OFFSET
;
764 * Take in integer size value and put it into a buffer like
765 * the drive would want to see a number-of-sector value.
768 size_to_buf(unsigned int size
, Byte
*buf
)
770 buf
[0] = size
/ 65536;
778 * The OS calls this to perform a read or write operation to the drive.
779 * Write obviously fail. Reads to a read ahead of sony_buffer_size
780 * bytes to help speed operations. This especially helps since the OS
781 * uses 1024 byte blocks and the drive uses 2048 byte blocks. Since most
782 * data access on a CD is done sequentially, this saves a lot of operations.
785 do_cdu535_request(void)
788 unsigned int read_size
;
798 cdu_open(NULL
, NULL
);
802 * The beginning here is stolen from the hard disk driver. I hope
805 if (!(CURRENT
) || CURRENT
->rq_status
== RQ_INACTIVE
) {
809 dev
= MINOR(CURRENT
->rq_dev
);
810 block
= CURRENT
->sector
;
811 nsect
= CURRENT
->nr_sectors
;
816 switch (CURRENT
->cmd
) {
819 * If the block address is invalid or the request goes beyond the end of
820 * the media, return an error.
823 if (sony_toc
->lead_out_start_lba
<= (block
/ 4)) {
827 if (sony_toc
->lead_out_start_lba
<= ((block
+ nsect
) / 4)) {
833 * If the requested sector is not currently in the read-ahead buffer,
834 * it must be read in.
836 if ((block
< sony_first_block
) || (sony_last_block
< block
)) {
837 sony_first_block
= (block
/ 4) * 4;
838 log_to_msf(block
/ 4, params
);
841 * If the full read-ahead would go beyond the end of the media, trim
842 * it back to read just till the end of the media.
844 if (sony_toc
->lead_out_start_lba
<= ((block
/ 4) + sony_buffer_sectors
)) {
845 sony_last_block
= (sony_toc
->lead_out_start_lba
* 4) - 1;
846 read_size
= sony_toc
->lead_out_start_lba
- (block
/ 4);
848 sony_last_block
= sony_first_block
+ (sony_buffer_sectors
* 4) - 1;
849 read_size
= sony_buffer_sectors
;
851 size_to_buf(read_size
, ¶ms
[3]);
854 * Read the data. If the drive was not spinning,
855 * spin it up and try some more.
857 for (spin_up_retry
=0 ;; ++spin_up_retry
) {
858 /* This loop has been modified to support the Sony
859 * CDU-510/515 series, thanks to Claudio Porfiri
860 * <C.Porfiri@nisms.tei.ericsson.se>.
863 * This part is to deal with very slow hardware. We
864 * try at most MAX_SPINUP_RETRY times to read the same
865 * block. A check for seek_and_read_N_blocks' result is
866 * performed; if the result is wrong, the CDROM's engine
867 * is restarted and the operation is tried again.
870 * 1995-06-01: The system got problems when downloading
871 * from Slackware CDROM, the problem seems to be:
872 * seek_and_read_N_blocks returns BAD_STATUS and we
873 * should wait for a while before retrying, so a new
874 * part was added to discriminate the return value from
875 * seek_and_read_N_blocks for the various cases.
877 int readStatus
= seek_and_read_N_blocks(params
, read_size
,
878 status
, sony_buffer
, (read_size
* 2048));
879 if (0 <= readStatus
) /* Good data; common case, placed first */
881 if (readStatus
== NO_ROOM
|| spin_up_retry
== MAX_SPINUP_RETRY
) {
883 if (readStatus
== NO_ROOM
)
884 printk(CDU535_MESSAGE_NAME
" No room to read from CD\n");
886 printk(CDU535_MESSAGE_NAME
" Read error: 0x%.2x\n",
888 sony_first_block
= -1;
889 sony_last_block
= -1;
893 if (readStatus
== BAD_STATUS
) {
894 /* Sleep for a while, then retry */
895 current
->state
= TASK_INTERRUPTIBLE
;
896 current
->timeout
= jiffies
+ RETRY_FOR_BAD_STATUS
;
900 printk(CDU535_MESSAGE_NAME
901 " debug: calling spin up when reading data!\n");
903 cmd
[0] = SONY535_SPIN_UP
;
904 do_sony_cmd(cmd
, 1, status
, NULL
, 0, 0);
908 * The data is in memory now, copy it to the buffer and advance to the
909 * next block to read.
911 copyoff
= block
- sony_first_block
;
912 memcpy(CURRENT
->buffer
,
913 sony_buffer
[copyoff
/ 4] + 512 * (copyoff
% 4), 512);
917 CURRENT
->buffer
+= 512;
928 panic("Unknown SONY CD cmd");
935 * Read the table of contents from the drive and set sony_toc_read if
942 if (!sony_toc_read
) {
943 /* do not call check_drive_status() from here since it can call this routine */
944 if (request_toc_data(status
, sony_toc
) < 0)
946 sony_toc
->lead_out_start_lba
= msf_to_log(sony_toc
->lead_out_start_msf
);
953 * Search for a specific track in the table of contents. track is
954 * passed in bcd format
957 find_track(int track
)
963 num_tracks
= bcd_to_int(sony_toc
->last_track_num
) -
964 bcd_to_int(sony_toc
->first_track_num
) + 1;
965 for (i
= 0; i
< num_tracks
; i
++) {
966 if (sony_toc
->tracks
[i
].track
== track
) {
975 * Read the subcode and put it int last_sony_subcode for future use.
980 Byte cmd
= SONY535_REQUEST_SUB_Q_DATA
;
984 if (check_drive_status() != 0)
987 if ((dsc_status
= do_sony_cmd(&cmd
, 1, status
, (Byte
*) last_sony_subcode
,
988 sizeof(struct s535_sony_subcode
), 1)) != 0) {
989 printk(CDU535_MESSAGE_NAME
" error 0x%.2x, %d (read_subcode)\n",
990 status
[0], dsc_status
);
998 * Get the subchannel info like the CDROMSUBCHNL command wants to see it. If
999 * the drive is playing, the subchannel needs to be read (since it would be
1000 * changing). If the drive is paused or completed, the subcode information has
1001 * already been stored, just use that. The ioctl call wants things in decimal
1002 * (not BCD), so all the conversions are done.
1005 sony_get_subchnl_info(long arg
)
1007 struct cdrom_subchnl schi
;
1010 /* Get attention stuff */
1011 if (check_drive_status() != 0)
1015 if (!sony_toc_read
) {
1018 err
= verify_area(VERIFY_WRITE
/* and read */ , (char *)arg
, sizeof schi
);
1022 copy_from_user(&schi
, (char *)arg
, sizeof schi
);
1024 switch (sony_audio_status
) {
1025 case CDROM_AUDIO_PLAY
:
1026 if (read_subcode() < 0) {
1031 case CDROM_AUDIO_PAUSED
:
1032 case CDROM_AUDIO_COMPLETED
:
1035 case CDROM_AUDIO_NO_STATUS
:
1036 schi
.cdsc_audiostatus
= sony_audio_status
;
1037 copy_to_user((char *)arg
, &schi
, sizeof schi
);
1041 case CDROM_AUDIO_INVALID
:
1042 case CDROM_AUDIO_ERROR
:
1047 schi
.cdsc_audiostatus
= sony_audio_status
;
1048 schi
.cdsc_adr
= last_sony_subcode
->address
;
1049 schi
.cdsc_ctrl
= last_sony_subcode
->control
;
1050 schi
.cdsc_trk
= bcd_to_int(last_sony_subcode
->track_num
);
1051 schi
.cdsc_ind
= bcd_to_int(last_sony_subcode
->index_num
);
1052 if (schi
.cdsc_format
== CDROM_MSF
) {
1053 schi
.cdsc_absaddr
.msf
.minute
= bcd_to_int(last_sony_subcode
->abs_msf
[0]);
1054 schi
.cdsc_absaddr
.msf
.second
= bcd_to_int(last_sony_subcode
->abs_msf
[1]);
1055 schi
.cdsc_absaddr
.msf
.frame
= bcd_to_int(last_sony_subcode
->abs_msf
[2]);
1057 schi
.cdsc_reladdr
.msf
.minute
= bcd_to_int(last_sony_subcode
->rel_msf
[0]);
1058 schi
.cdsc_reladdr
.msf
.second
= bcd_to_int(last_sony_subcode
->rel_msf
[1]);
1059 schi
.cdsc_reladdr
.msf
.frame
= bcd_to_int(last_sony_subcode
->rel_msf
[2]);
1060 } else if (schi
.cdsc_format
== CDROM_LBA
) {
1061 schi
.cdsc_absaddr
.lba
= msf_to_log(last_sony_subcode
->abs_msf
);
1062 schi
.cdsc_reladdr
.lba
= msf_to_log(last_sony_subcode
->rel_msf
);
1064 copy_to_user((char *)arg
, &schi
, sizeof schi
);
1070 * The big ugly ioctl handler.
1073 cdu_ioctl(struct inode
*inode
,
1080 Byte cmd_buff
[10], params
[10];
1088 dev
= MINOR(inode
->i_rdev
) >> 6;
1092 if (check_drive_status() != 0)
1096 case CDROMSTART
: /* Spin up the drive */
1097 if (spin_up_drive(status
) < 0) {
1098 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMSTART)\n",
1105 case CDROMSTOP
: /* Spin down the drive */
1106 cmd_buff
[0] = SONY535_HOLD
;
1107 do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0);
1110 * Spin the drive down, ignoring the error if the disk was
1111 * already not spinning.
1113 sony_audio_status
= CDROM_AUDIO_NO_STATUS
;
1114 cmd_buff
[0] = SONY535_SPIN_DOWN
;
1115 dsc_status
= do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0);
1116 if (((dsc_status
< 0) && (dsc_status
!= BAD_STATUS
)) ||
1117 ((status
[0] & ~(SONY535_STATUS1_NOT_SPINNING
)) != 0)) {
1118 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMSTOP)\n",
1125 case CDROMPAUSE
: /* Pause the drive */
1126 cmd_buff
[0] = SONY535_HOLD
; /* CDU-31 driver uses AUDIO_STOP, not pause */
1127 if (do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0) != 0) {
1128 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMPAUSE)\n",
1132 /* Get the current position and save it for resuming */
1133 if (read_subcode() < 0) {
1136 cur_pos_msf
[0] = last_sony_subcode
->abs_msf
[0];
1137 cur_pos_msf
[1] = last_sony_subcode
->abs_msf
[1];
1138 cur_pos_msf
[2] = last_sony_subcode
->abs_msf
[2];
1139 sony_audio_status
= CDROM_AUDIO_PAUSED
;
1143 case CDROMRESUME
: /* Start the drive after being paused */
1144 set_drive_mode(SONY535_AUDIO_DRIVE_MODE
, status
);
1146 if (sony_audio_status
!= CDROM_AUDIO_PAUSED
) {
1149 spin_up_drive(status
);
1151 /* Start the drive at the saved position. */
1152 cmd_buff
[0] = SONY535_PLAY_AUDIO
;
1153 cmd_buff
[1] = 0; /* play back starting at this address */
1154 cmd_buff
[2] = cur_pos_msf
[0];
1155 cmd_buff
[3] = cur_pos_msf
[1];
1156 cmd_buff
[4] = cur_pos_msf
[2];
1157 cmd_buff
[5] = SONY535_PLAY_AUDIO
;
1158 cmd_buff
[6] = 2; /* set ending address */
1159 cmd_buff
[7] = final_pos_msf
[0];
1160 cmd_buff
[8] = final_pos_msf
[1];
1161 cmd_buff
[9] = final_pos_msf
[2];
1162 if ((do_sony_cmd(cmd_buff
, 5, status
, NULL
, 0, 0) != 0) ||
1163 (do_sony_cmd(cmd_buff
+ 5, 5, status
, NULL
, 0, 0) != 0)) {
1164 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMRESUME)\n",
1168 sony_audio_status
= CDROM_AUDIO_PLAY
;
1172 case CDROMPLAYMSF
: /* Play starting at the given MSF address. */
1173 err
= verify_area(VERIFY_READ
, (char *)arg
, 6);
1176 spin_up_drive(status
);
1177 set_drive_mode(SONY535_AUDIO_DRIVE_MODE
, status
);
1178 copy_from_user(params
, (void *)arg
, 6);
1180 /* The parameters are given in int, must be converted */
1181 for (i
= 0; i
< 3; i
++) {
1182 cmd_buff
[2 + i
] = int_to_bcd(params
[i
]);
1183 cmd_buff
[7 + i
] = int_to_bcd(params
[i
+ 3]);
1185 cmd_buff
[0] = SONY535_PLAY_AUDIO
;
1186 cmd_buff
[1] = 0; /* play back starting at this address */
1187 /* cmd_buff[2-4] are filled in for loop above */
1188 cmd_buff
[5] = SONY535_PLAY_AUDIO
;
1189 cmd_buff
[6] = 2; /* set ending address */
1190 /* cmd_buff[7-9] are filled in for loop above */
1191 if ((do_sony_cmd(cmd_buff
, 5, status
, NULL
, 0, 0) != 0) ||
1192 (do_sony_cmd(cmd_buff
+ 5, 5, status
, NULL
, 0, 0) != 0)) {
1193 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMPLAYMSF)\n",
1197 /* Save the final position for pauses and resumes */
1198 final_pos_msf
[0] = cmd_buff
[7];
1199 final_pos_msf
[1] = cmd_buff
[8];
1200 final_pos_msf
[2] = cmd_buff
[9];
1201 sony_audio_status
= CDROM_AUDIO_PLAY
;
1205 case CDROMREADTOCHDR
: /* Read the table of contents header */
1207 struct cdrom_tochdr
*hdr
;
1208 struct cdrom_tochdr loc_hdr
;
1213 hdr
= (struct cdrom_tochdr
*)arg
;
1214 err
= verify_area(VERIFY_WRITE
, hdr
, sizeof *hdr
);
1217 loc_hdr
.cdth_trk0
= bcd_to_int(sony_toc
->first_track_num
);
1218 loc_hdr
.cdth_trk1
= bcd_to_int(sony_toc
->last_track_num
);
1219 copy_to_user(hdr
, &loc_hdr
, sizeof *hdr
);
1224 case CDROMREADTOCENTRY
: /* Read a given table of contents entry */
1226 struct cdrom_tocentry
*entry
;
1227 struct cdrom_tocentry loc_entry
;
1229 Byte
*msf_val
= NULL
;
1232 if (!sony_toc_read
) {
1235 entry
= (struct cdrom_tocentry
*)arg
;
1236 err
= verify_area(VERIFY_WRITE
/* and read */ , entry
, sizeof *entry
);
1240 copy_from_user(&loc_entry
, entry
, sizeof loc_entry
);
1242 /* Lead out is handled separately since it is special. */
1243 if (loc_entry
.cdte_track
== CDROM_LEADOUT
) {
1244 loc_entry
.cdte_adr
= 0 /*sony_toc->address2 */ ;
1245 loc_entry
.cdte_ctrl
= sony_toc
->control2
;
1246 msf_val
= sony_toc
->lead_out_start_msf
;
1248 track_idx
= find_track(int_to_bcd(loc_entry
.cdte_track
));
1251 loc_entry
.cdte_adr
= 0 /*sony_toc->tracks[track_idx].address */ ;
1252 loc_entry
.cdte_ctrl
= sony_toc
->tracks
[track_idx
].control
;
1253 msf_val
= sony_toc
->tracks
[track_idx
].track_start_msf
;
1256 /* Logical buffer address or MSF format requested? */
1257 if (loc_entry
.cdte_format
== CDROM_LBA
) {
1258 loc_entry
.cdte_addr
.lba
= msf_to_log(msf_val
);
1259 } else if (loc_entry
.cdte_format
== CDROM_MSF
) {
1260 loc_entry
.cdte_addr
.msf
.minute
= bcd_to_int(*msf_val
);
1261 loc_entry
.cdte_addr
.msf
.second
= bcd_to_int(*(msf_val
+ 1));
1262 loc_entry
.cdte_addr
.msf
.frame
= bcd_to_int(*(msf_val
+ 2));
1264 copy_to_user(entry
, &loc_entry
, sizeof *entry
);
1269 case CDROMPLAYTRKIND
: /* Play a track. This currently ignores index. */
1277 err
= verify_area(VERIFY_READ
, (char *)arg
, sizeof ti
);
1281 copy_from_user(&ti
, (char *)arg
, sizeof ti
);
1282 if ((ti
.cdti_trk0
< sony_toc
->first_track_num
)
1283 || (sony_toc
->last_track_num
< ti
.cdti_trk0
)
1284 || (ti
.cdti_trk1
< ti
.cdti_trk0
)) {
1287 track_idx
= find_track(int_to_bcd(ti
.cdti_trk0
));
1290 params
[1] = sony_toc
->tracks
[track_idx
].track_start_msf
[0];
1291 params
[2] = sony_toc
->tracks
[track_idx
].track_start_msf
[1];
1292 params
[3] = sony_toc
->tracks
[track_idx
].track_start_msf
[2];
1294 * If we want to stop after the last track, use the lead-out
1297 if (bcd_to_int(sony_toc
->last_track_num
) <= ti
.cdti_trk1
) {
1298 log_to_msf(msf_to_log(sony_toc
->lead_out_start_msf
) - 1,
1301 track_idx
= find_track(int_to_bcd(ti
.cdti_trk1
+ 1));
1304 log_to_msf(msf_to_log(sony_toc
->tracks
[track_idx
].track_start_msf
) - 1,
1309 spin_up_drive(status
);
1311 set_drive_mode(SONY535_AUDIO_DRIVE_MODE
, status
);
1313 /* Start the drive at the saved position. */
1314 cmd_buff
[0] = SONY535_PLAY_AUDIO
;
1315 cmd_buff
[1] = 0; /* play back starting at this address */
1316 cmd_buff
[2] = params
[1];
1317 cmd_buff
[3] = params
[2];
1318 cmd_buff
[4] = params
[3];
1319 cmd_buff
[5] = SONY535_PLAY_AUDIO
;
1320 cmd_buff
[6] = 2; /* set ending address */
1321 cmd_buff
[7] = params
[4];
1322 cmd_buff
[8] = params
[5];
1323 cmd_buff
[9] = params
[6];
1324 if ((do_sony_cmd(cmd_buff
, 5, status
, NULL
, 0, 0) != 0) ||
1325 (do_sony_cmd(cmd_buff
+ 5, 5, status
, NULL
, 0, 0) != 0)) {
1326 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMPLAYTRKIND)\n",
1328 printk("... Params: %x %x %x %x %x %x %x\n",
1329 params
[0], params
[1], params
[2],
1330 params
[3], params
[4], params
[5], params
[6]);
1333 /* Save the final position for pauses and resumes */
1334 final_pos_msf
[0] = params
[4];
1335 final_pos_msf
[1] = params
[5];
1336 final_pos_msf
[2] = params
[6];
1337 sony_audio_status
= CDROM_AUDIO_PLAY
;
1341 case CDROMSUBCHNL
: /* Get subchannel info */
1342 return sony_get_subchnl_info(arg
);
1344 case CDROMVOLCTRL
: /* Volume control. What volume does this change, anyway? */
1346 struct cdrom_volctrl volctrl
;
1348 err
= verify_area(VERIFY_READ
, (char *)arg
, sizeof volctrl
);
1352 copy_from_user(&volctrl
, (char *)arg
, sizeof volctrl
);
1353 cmd_buff
[0] = SONY535_SET_VOLUME
;
1354 cmd_buff
[1] = volctrl
.channel0
;
1355 cmd_buff
[2] = volctrl
.channel1
;
1356 if (do_sony_cmd(cmd_buff
, 3, status
, NULL
, 0, 0) != 0) {
1357 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMVOLCTRL)\n",
1364 case CDROMEJECT
: /* Eject the drive */
1365 cmd_buff
[0] = SONY535_STOP
;
1366 do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0);
1367 cmd_buff
[0] = SONY535_SPIN_DOWN
;
1368 do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0);
1370 sony_audio_status
= CDROM_AUDIO_INVALID
;
1371 cmd_buff
[0] = SONY535_EJECT_CADDY
;
1372 if (do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0) != 0) {
1373 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (CDROMEJECT)\n",
1387 * Open the drive for operations. Spin the drive up and read the table of
1388 * contents if these have not already been done.
1391 cdu_open(struct inode
*inode
,
1394 Byte status
[2], cmd_buff
[2];
1399 if (check_drive_status() != 0)
1404 if (spin_up_drive(status
) != 0) {
1405 printk(CDU535_MESSAGE_NAME
" error 0x%.2x (cdu_open, spin up)\n",
1412 if (!sony_toc_read
) {
1413 cmd_buff
[0] = SONY535_SPIN_DOWN
;
1414 do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0);
1420 check_disk_change(inode
->i_rdev
);
1425 /* disable the eject button while mounted */
1426 cmd_buff
[0] = SONY535_DISABLE_EJECT_BUTTON
;
1427 do_sony_cmd(cmd_buff
, 1, status
, NULL
, 0, 0);
1435 * Close the drive. Spin it down if no task is using it. The spin
1436 * down will fail if playing audio, so audio play is OK.
1439 cdu_release(struct inode
*inode
,
1442 Byte status
[2], cmd_no
;
1447 if (0 < sony_usage
) {
1450 if (sony_usage
== 0) {
1451 sync_dev(inode
->i_rdev
);
1452 check_drive_status();
1454 if (sony_audio_status
!= CDROM_AUDIO_PLAY
) {
1455 cmd_no
= SONY535_SPIN_DOWN
;
1456 do_sony_cmd(&cmd_no
, 1, status
, NULL
, 0, 0);
1459 /* enable the eject button after umount */
1460 cmd_no
= SONY535_ENABLE_EJECT_BUTTON
;
1461 do_sony_cmd(&cmd_no
, 1, status
, NULL
, 0, 0);
1468 static struct file_operations cdu_fops
=
1470 NULL
, /* lseek - default */
1471 block_read
, /* read - general block-dev read */
1472 block_write
, /* write - general block-dev write */
1473 NULL
, /* readdir - bad */
1475 cdu_ioctl
, /* ioctl */
1477 cdu_open
, /* open */
1479 cdu_release
, /* release */
1482 cdu535_check_media_change
, /* check media change */
1483 NULL
/* revalidate */
1487 * Initialize the driver.
1492 struct s535_sony_drive_config drive_config
;
1500 /* Setting the base I/O address to 0 will disable it. */
1501 if ((sony535_cd_base_io
== 0xffff)||(sony535_cd_base_io
== 0))
1504 /* Set up all the register locations */
1505 result_reg
= sony535_cd_base_io
;
1506 command_reg
= sony535_cd_base_io
;
1507 data_reg
= sony535_cd_base_io
+ 1;
1508 read_status_reg
= sony535_cd_base_io
+ 2;
1509 select_unit_reg
= sony535_cd_base_io
+ 3;
1512 sony535_irq_used
= 0; /* polling only until this is ready... */
1514 /* we need to poll until things get initialized */
1515 tmp_irq
= sony535_irq_used
;
1516 sony535_irq_used
= 0;
1519 printk(KERN_INFO CDU535_MESSAGE_NAME
": probing base address %03X\n",
1520 sony535_cd_base_io
);
1522 if (check_region(sony535_cd_base_io
,4)) {
1523 printk(CDU535_MESSAGE_NAME
": my base address is not free!\n");
1526 /* look for the CD-ROM, follows the procedure in the DOS driver */
1527 inb(select_unit_reg
);
1528 retry_count
= jiffies
+ 2 * HZ
;
1529 while (jiffies
< retry_count
)
1530 sony_sleep(); /* wait for 40 18 Hz ticks (from DOS driver) */
1533 outb(0, read_status_reg
); /* does a reset? */
1534 retry_count
= jiffies
+ SONY_JIFFIES_TIMEOUT
;
1535 while (jiffies
< retry_count
) {
1537 if (inb(result_reg
) != 0xff)
1542 if ((jiffies
< retry_count
) && (check_drive_status() != TIME_OUT
)) {
1543 /* CD-ROM drive responded -- get the drive configuration */
1544 cmd_buff
[0] = SONY535_INQUIRY
;
1545 if (do_sony_cmd(cmd_buff
, 1, status
,
1546 (Byte
*)&drive_config
, 28, 1) == 0) {
1547 /* was able to get the configuration,
1548 * set drive mode as rest of init
1551 /* 0x50 == CADDY_NOT_INSERTED | NOT_SPINNING */
1552 if ( (status
[0] & 0x7f) != 0 && (status
[0] & 0x7f) != 0x50 )
1553 printk(CDU535_MESSAGE_NAME
1554 "Inquiry command returned status = 0x%x\n", status
[0]);
1556 /* now ready to use interrupts, if available */
1557 sony535_irq_used
= tmp_irq
;
1559 /* This code is not in MODULEs by default, since the autoirq stuff might
1560 * not be in the module-accessible symbol table.
1562 /* A negative sony535_irq_used will attempt an autoirq. */
1563 if (sony535_irq_used
< 0) {
1565 enable_interrupts();
1566 outb(0, read_status_reg
); /* does a reset? */
1567 sony535_irq_used
= autoirq_report(10);
1568 disable_interrupts();
1571 if (sony535_irq_used
> 0) {
1572 if (request_irq(sony535_irq_used
, cdu535_interrupt
,
1573 SA_INTERRUPT
, CDU535_HANDLE
, NULL
)) {
1574 printk("Unable to grab IRQ%d for the " CDU535_MESSAGE_NAME
1575 " driver; polling instead.\n", sony535_irq_used
);
1576 sony535_irq_used
= 0;
1579 cmd_buff
[0] = SONY535_SET_DRIVE_MODE
;
1580 cmd_buff
[1] = 0x0; /* default audio */
1581 if (do_sony_cmd(cmd_buff
, 2, status
, ret_buff
, 1, 1) == 0) {
1582 /* set the drive mode successful, we are set! */
1583 sony_buffer_size
= SONY535_BUFFER_SIZE
;
1584 sony_buffer_sectors
= sony_buffer_size
/ 2048;
1586 printk(KERN_INFO CDU535_MESSAGE_NAME
" I/F CDROM : %8.8s %16.16s %4.4s",
1587 drive_config
.vendor_id
,
1588 drive_config
.product_id
,
1589 drive_config
.product_rev_level
);
1590 printk(" base address %03X, ", sony535_cd_base_io
);
1592 printk("IRQ%d, ", tmp_irq
);
1593 printk("using %d byte buffer\n", sony_buffer_size
);
1595 if (register_blkdev(MAJOR_NR
, CDU535_HANDLE
, &cdu_fops
)) {
1596 printk("Unable to get major %d for %s\n",
1597 MAJOR_NR
, CDU535_MESSAGE_NAME
);
1600 blk_dev
[MAJOR_NR
].request_fn
= DEVICE_REQUEST
;
1601 read_ahead
[MAJOR_NR
] = 8; /* 8 sector (4kB) read-ahead */
1603 sony_toc
= (struct s535_sony_toc
*)
1604 kmalloc(sizeof *sony_toc
, GFP_KERNEL
);
1605 if (sony_toc
== NULL
)
1607 last_sony_subcode
= (struct s535_sony_subcode
*)
1608 kmalloc(sizeof *last_sony_subcode
, GFP_KERNEL
);
1609 if (last_sony_subcode
== NULL
) {
1613 sony_buffer
= (Byte
**)
1614 kmalloc(4 * sony_buffer_sectors
, GFP_KERNEL
);
1615 if (sony_buffer
== NULL
) {
1617 kfree(last_sony_subcode
);
1620 for (i
= 0; i
< sony_buffer_sectors
; i
++) {
1621 sony_buffer
[i
] = (Byte
*)kmalloc(2048, GFP_KERNEL
);
1622 if (sony_buffer
[i
] == NULL
) {
1624 kfree(sony_buffer
[i
]);
1627 kfree(last_sony_subcode
);
1637 printk("Did not find a " CDU535_MESSAGE_NAME
" drive\n");
1640 request_region(sony535_cd_base_io
, 4, CDU535_HANDLE
);
1646 * accept "kernel command line" parameters
1647 * (added by emoenke@gwdg.de)
1652 * the address value has to be the existing CDROM port address.
1655 sonycd535_setup(char *strings
, int *ints
))
1657 /* if IRQ change and default io base desired,
1658 * then call with io base of 0
1662 sony535_cd_base_io
= ints
[1];
1664 sony535_irq_used
= ints
[2];
1665 if ((strings
!= NULL
) && (*strings
!= '\0'))
1666 printk(CDU535_MESSAGE_NAME
1667 ": Warning: Unknown interface type: %s\n", strings
);
1672 int init_module(void)
1674 return sony535_init();
1678 cleanup_module(void)
1682 release_region(sony535_cd_base_io
, 4);
1683 for (i
= 0; i
< sony_buffer_sectors
; i
++)
1684 kfree_s(sony_buffer
[i
], 2048);
1685 kfree_s(sony_buffer
, 4 * sony_buffer_sectors
);
1686 kfree_s(last_sony_subcode
, sizeof *last_sony_subcode
);
1687 kfree_s(sony_toc
, sizeof *sony_toc
);
1688 if (unregister_blkdev(MAJOR_NR
, CDU535_HANDLE
) == -EINVAL
)
1689 printk("Uh oh, couldn't unregister " CDU535_HANDLE
"\n");
1691 printk(KERN_INFO CDU535_HANDLE
" module released\n");