1 /* cm206.c. A linux-driver for the cm206 cdrom player with cm260 adapter card.
2 Copyright (c) 1995--1997 David A. van Leeuwen.
3 $Id: cm206.c,v 1.5 1997/12/26 11:02:51 david Exp $
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 Started 25 jan 1994. Waiting for documentation...
21 22 feb 1995: 0.1a first reasonably safe polling driver.
22 Two major bugs, one in read_sector and one in
23 do_cm206_request, happened to cancel!
24 25 feb 1995: 0.2a first reasonable interrupt driven version of above.
25 uart writes are still done in polling mode.
26 25 feb 1995: 0.21a writes also in interrupt mode, still some
27 small bugs to be found... Larger buffer.
28 2 mrt 1995: 0.22 Bug found (cd-> nowhere, interrupt was called in
29 initialization), read_ahead of 16. Timeouts implemented.
30 unclear if they do something...
31 7 mrt 1995: 0.23 Start of background read-ahead.
32 18 mrt 1995: 0.24 Working background read-ahead. (still problems)
33 26 mrt 1995: 0.25 Multi-session ioctl added (kernel v1.2).
34 Statistics implemented, though separate stats206.h.
35 Accessible trough ioctl 0x1000 (just a number).
36 Hard to choose between v1.2 development and 1.1.75.
37 Bottom-half doesn't work with 1.2...
38 0.25a: fixed... typo. Still problems...
39 1 apr 1995: 0.26 Module support added. Most bugs found. Use kernel 1.2.n.
40 5 apr 1995: 0.27 Auto-probe for the adapter card base address.
41 Auto-probe for the adaptor card irq line.
42 7 apr 1995: 0.28 Added lilo setup support for base address and irq.
43 Use major number 32 (not in this source), officially
44 assigned to this driver.
45 9 apr 1995: 0.29 Added very limited audio support. Toc_header, stop, pause,
46 resume, eject. Play_track ignores track info, because we can't
47 read a table-of-contents entry. Toc_entry is implemented
48 as a `placebo' function: always returns start of disc.
49 3 may 1995: 0.30 Audio support completed. The get_toc_entry function
50 is implemented as a binary search.
51 15 may 1995: 0.31 More work on audio stuff. Workman is not easy to
52 satisfy; changed binary search into linear search.
53 Auto-probe for base address somewhat relaxed.
54 1 jun 1995: 0.32 Removed probe_irq_on/off for module version.
55 10 jun 1995: 0.33 Workman still behaves funny, but you should be
56 able to eject and substitute another disc.
58 An adaptation of 0.33 is included in linux-1.3.7 by Eberhard Moenkeberg
60 18 jul 1995: 0.34 Patch by Heiko Eissfeldt included, mainly considering
61 verify_area's in the ioctls. Some bugs introduced by
62 EM considering the base port and irq fixed.
64 18 dec 1995: 0.35 Add some code for error checking... no luck...
66 We jump to reach our goal: version 1.0 in the next stable linux kernel.
68 19 mar 1996: 0.95 Different implementation of CDROM_GET_UPC, on
69 request of Thomas Quinot.
70 25 mar 1996: 0.96 Interpretation of opening with O_WRONLY or O_RDWR:
71 open only for ioctl operation, e.g., for operation of
73 4 apr 1996: 0.97 First implementation of layer between VFS and cdrom
74 driver, a generic interface. Much of the functionality
75 of cm206_open() and cm206_ioctl() is transferred to a
76 new file cdrom.c and its header ucdrom.h.
78 Upgrade to Linux kernel 1.3.78.
80 11 apr 1996 0.98 Upgrade to Linux kernel 1.3.85
81 More code moved to cdrom.c
83 0.99 Some more small changes to decrease number
84 of oopses at module load;
86 27 jul 1996 0.100 Many hours of debugging, kernel change from 1.2.13
87 to 2.0.7 seems to have introduced some weird behavior
88 in (interruptible_)sleep_on(&cd->data): the process
89 seems to be woken without any explicit wake_up in my own
90 code. Patch to try 100x in case such untriggered wake_up's
93 28 jul 1996 0.101 Rewriting of the code that receives the command echo,
94 using a fifo to store echoed bytes.
98 0.99.1.0 Update to kernel release 2.0.10 dev_t -> kdev_t
99 (emoenke) various typos found by others. extra
100 module-load oops protection.
102 0.99.1.1 Initialization constant cdrom_dops.speed
103 changed from float (2.0) to int (2); Cli()-sti() pair
104 around cm260_reset() in module initialization code.
106 0.99.1.2 Changes literally as proposed by Scott Snyder
107 <snyder@d0sgif.fnal.gov> for the 2.1 kernel line, which
108 have to do mainly with the poor minor support i had. The
109 major new concept is to change a cdrom driver's
110 operations struct from the capabilities struct. This
111 reflects the fact that there is one major for a driver,
112 whilst there can be many minors whith completely
113 different capabilities.
115 0.99.1.3 More changes for operations/info separation.
117 0.99.1.4 Added speed selection (someone had to do this
120 23 jan 1997 0.99.1.5 MODULE_PARMS call added.
122 23 jan 1997 0.100.1.2--0.100.1.5 following similar lines as
123 0.99.1.1--0.99.1.5. I get too many complaints about the
124 drive making read errors. What't wrong with the 2.0+
125 kernel line? Why get i (and othe cm206 owners) weird
126 results? Why were things good in the good old 1.1--1.2
127 era? Why don't i throw away the drive?
129 2 feb 1997 0.102 Added `volatile' to values in cm206_struct. Seems to
130 reduce many of the problems. Rewrote polling routines
131 to use fixed delays between polls.
132 0.103 Changed printk behavior.
133 0.104 Added a 0.100 -> 0.100.1.1 change
135 11 feb 1997 0.105 Allow auto_probe during module load, disable
136 with module option "auto_probe=0". Moved some debugging
137 statements to lower priority. Implemented select_speed()
140 13 feb 1997 1.0 Final version for 2.0 kernel line.
142 All following changes will be for the 2.1 kernel line.
144 15 feb 1997 1.1 Keep up with kernel 2.1.26, merge in changes from
145 cdrom.c 0.100.1.1--1.0. Add some more MODULE_PARMS.
147 14 sep 1997 1.2 Upgrade to Linux 2.1.55. Added blksize_size[], patch
148 sent by James Bottomley <James.Bottomley@columbiasc.ncr.com>.
150 21 dec 1997 1.4 Upgrade to Linux 2.1.72.
152 24 jan 1998 Removed the cm206_disc_status() function, as it was now dead
153 code. The Uniform CDROM driver now provides this functionality.
155 * Parts of the code are based upon lmscd.c written by Kai Petzke,
156 * sbpcd.c written by Eberhard Moenkeberg, and mcd.c by Martin
157 * Harriss, but any off-the-shelf dynamic programming algorithm won't
158 * be able to find them.
160 * The cm206 drive interface and the cm260 adapter card seem to be
161 * sufficiently different from their cm205/cm250 counterparts
162 * in order to write a complete new driver.
164 * I call all routines connected to the Linux kernel something
165 * with `cm206' in it, as this stuff is too series-dependent.
167 * Currently, my limited knowledge is based on:
168 * - The Linux Kernel Hacker's guide, v. 0.5, by Michael K. Johnson
169 * - Linux Kernel Programmierung, by Michael Beck and others
170 * - Philips/LMS cm206 and cm226 product specification
171 * - Philips/LMS cm260 product specification
173 * David van Leeuwen, david@tm.tno.nl. */
174 #define REVISION "$Revision: 1.5 $"
176 #include <linux/module.h>
178 #include <linux/errno.h> /* These include what we really need */
179 #include <linux/delay.h>
180 #include <linux/string.h>
181 #include <linux/sched.h>
182 #include <linux/interrupt.h>
183 #include <linux/timer.h>
184 #include <linux/cdrom.h>
185 #include <linux/ioport.h>
186 #include <linux/mm.h>
187 #include <linux/malloc.h>
188 #include <linux/init.h>
190 /* #include <linux/ucdrom.h> */
194 #define MAJOR_NR CM206_CDROM_MAJOR
195 #include <linux/blk.h>
198 #define STATISTICS /* record times and frequencies of events */
199 #define AUTO_PROBE_MODULE
204 /* This variable defines whether or not to probe for adapter base port
205 address and interrupt request. It can be overridden by the boot
208 static int auto_probe
=1; /* Yes, why not? */
210 static int cm206_base
= CM206_BASE
;
211 static int cm206_irq
= CM206_IRQ
;
212 MODULE_PARM(cm206_base
, "i"); /* base */
213 MODULE_PARM(cm206_irq
, "i"); /* irq */
214 MODULE_PARM(cm206
, "1-2i"); /* base,irq or irq,base */
215 MODULE_PARM(auto_probe
, "i"); /* auto probe base and irq */
217 #define POLLOOP 100 /* milliseconds */
218 #define READ_AHEAD 1 /* defines private buffer, waste! */
219 #define BACK_AHEAD 1 /* defines adapter-read ahead */
220 #define DATA_TIMEOUT (3*HZ) /* measured in jiffies (10 ms) */
221 #define UART_TIMEOUT (5*HZ/100)
222 #define DSB_TIMEOUT (7*HZ) /* time for the slowest command to finish */
223 #define UR_SIZE 4 /* uart receive buffer fifo size */
225 #define LINUX_BLOCK_SIZE 512 /* WHERE is this defined? */
226 #define RAW_SECTOR_SIZE 2352 /* ok, is also defined in cdrom.h */
227 #define ISO_SECTOR_SIZE 2048
228 #define BLOCKS_ISO (ISO_SECTOR_SIZE/LINUX_BLOCK_SIZE) /* 4 */
229 #define CD_SYNC_HEAD 16 /* CD_SYNC + CD_HEAD */
231 #ifdef STATISTICS /* keep track of errors in counters */
232 #define stats(i) { ++cd->stats[st_ ## i]; \
233 cd->last_stat[st_ ## i] = cd->stat_counter++; \
236 #define stats(i) (void) 0;
239 #define Debug(a) {printk (KERN_DEBUG); printk a;}
241 #define debug(a) Debug(a)
243 #define debug(a) (void) 0;
246 typedef unsigned char uch
; /* 8-bits */
247 typedef unsigned short ush
; /* 16-bits */
249 struct toc_struct
{ /* private copy of Table of Contents */
250 uch track
, fsm
[3], q0
;
253 static int cm206_blocksizes
[1] = { 2048 };
255 struct cm206_struct
{
256 volatile ush intr_ds
; /* data status read on last interrupt */
257 volatile ush intr_ls
; /* uart line status read on last interrupt*/
258 volatile uch ur
[UR_SIZE
]; /* uart receive buffer fifo */
259 volatile uch ur_w
, ur_r
; /* write/read buffer index */
260 volatile uch dsb
, cc
; /* drive status byte and condition (error) code */
261 int command
; /* command to be written to the uart */
263 ush sector
[READ_AHEAD
*RAW_SECTOR_SIZE
/2]; /* buffered cd-sector */
264 int sector_first
, sector_last
; /* range of these sectors */
265 wait_queue_head_t uart
; /* wait queues for interrupt */
266 wait_queue_head_t data
;
267 struct timer_list timer
; /* time-out */
269 signed char max_sectors
; /* number of sectors that fit in adapter mem */
270 char wait_back
; /* we're waiting for a background-read */
271 char background
; /* is a read going on in the background? */
272 int adapter_first
; /* if so, that's the starting sector */
274 char fifo_overflowed
;
275 uch disc_status
[7]; /* result of get_disc_status command */
278 int last_stat
[NR_STATS
]; /* `time' at which stat was stat */
281 struct toc_struct toc
[101]; /* The whole table of contents + lead-out */
282 uch q
[10]; /* Last read q-channel info */
283 uch audio_status
[5]; /* last read position on pause */
284 uch media_changed
; /* record if media changed */
287 #define DISC_STATUS cd->disc_status[0]
288 #define FIRST_TRACK cd->disc_status[1]
289 #define LAST_TRACK cd->disc_status[2]
290 #define PAUSED cd->audio_status[0] /* misuse this memory byte! */
291 #define PLAY_TO cd->toc[0] /* toc[0] records end-time in play */
293 static struct cm206_struct
* cd
; /* the main memory structure */
295 /* First, we define some polling functions. These are actually
296 only being used in the initialization. */
298 void send_command_polled(int command
)
301 while (!(inw(r_line_status
) & ls_transmitter_buffer_empty
) && loop
>0) {
302 mdelay(1); /* one millisec delay */
305 outw(command
, r_uart_transmit
);
308 uch
receive_echo_polled(void)
311 while (!(inw(r_line_status
) & ls_receive_buffer_full
) && loop
>0) {
315 return ((uch
) inw(r_uart_receive
));
318 uch
send_receive_polled(int command
)
320 send_command_polled(command
);
321 return receive_echo_polled();
324 inline void clear_ur(void) {
325 if (cd
->ur_r
!= cd
->ur_w
) {
326 debug(("Deleting bytes from fifo:"));
327 for(;cd
->ur_r
!= cd
->ur_w
; cd
->ur_r
++, cd
->ur_r
%= UR_SIZE
)
328 debug((" 0x%x", cd
->ur
[cd
->ur_r
]));
333 /* The interrupt handler. When the cm260 generates an interrupt, very
334 much care has to be taken in reading out the registers in the right
335 order; in case of a receive_buffer_full interrupt, first the
336 uart_receive must be read, and then the line status again to
337 de-assert the interrupt line. It took me a couple of hours to find
340 The function reset_cm206 appears to cause an interrupt, because
341 pulling up the INIT line clears both the uart-write-buffer /and/
342 the uart-write-buffer-empty mask. We call this a `lost interrupt,'
343 as there seems so reason for this to happen.
346 static void cm206_interrupt(int sig
, void *dev_id
, struct pt_regs
* regs
)
350 cd
->intr_ds
= inw(r_data_status
); /* resets data_ready, data_error,
351 crc_error, sync_error, toc_ready
353 cd
->intr_ls
= inw(r_line_status
); /* resets overrun bit */
354 debug(("Intr, 0x%x 0x%x, %d\n", cd
->intr_ds
, cd
->intr_ls
, cd
->background
));
355 if (cd
->intr_ls
& ls_attention
) stats(attention
);
356 /* receive buffer full? */
357 if (cd
->intr_ls
& ls_receive_buffer_full
) {
358 cd
->ur
[cd
->ur_w
] = inb(r_uart_receive
); /* get order right! */
359 cd
->intr_ls
= inw(r_line_status
); /* resets rbf interrupt */
360 debug(("receiving #%d: 0x%x\n", cd
->ur_w
, cd
->ur
[cd
->ur_w
]));
361 cd
->ur_w
++; cd
->ur_w
%= UR_SIZE
;
362 if (cd
->ur_w
== cd
->ur_r
) debug(("cd->ur overflow!\n"));
363 if (waitqueue_active(&cd
->uart
) && cd
->background
< 2) {
364 del_timer(&cd
->timer
);
365 wake_up_interruptible(&cd
->uart
);
368 /* data ready in fifo? */
369 else if (cd
->intr_ds
& ds_data_ready
) {
370 if (cd
->background
) ++cd
->adapter_last
;
371 if (waitqueue_active(&cd
->data
) && (cd
->wait_back
|| !cd
->background
)) {
372 del_timer(&cd
->timer
);
373 wake_up_interruptible(&cd
->data
);
377 /* ready to issue a write command? */
378 else if (cd
->command
&& cd
->intr_ls
& ls_transmitter_buffer_empty
) {
379 outw(dc_normal
| (inw(r_data_status
) & 0x7f), r_data_control
);
380 outw(cd
->command
, r_uart_transmit
);
382 if (!cd
->background
) wake_up_interruptible(&cd
->uart
);
384 /* now treat errors (at least, identify them for debugging) */
385 else if (cd
->intr_ds
& ds_fifo_overflow
) {
386 debug(("Fifo overflow at sectors 0x%x\n", cd
->sector_first
));
387 fool
= inw(r_fifo_output_buffer
); /* de-assert the interrupt */
388 cd
->fifo_overflowed
=1; /* signal one word less should be read */
389 stats(fifo_overflow
);
391 else if (cd
->intr_ds
& ds_data_error
) {
392 debug(("Data error at sector 0x%x\n", cd
->sector_first
));
395 else if (cd
->intr_ds
& ds_crc_error
) {
396 debug(("CRC error at sector 0x%x\n", cd
->sector_first
));
399 else if (cd
->intr_ds
& ds_sync_error
) {
400 debug(("Sync at sector 0x%x\n", cd
->sector_first
));
403 else if (cd
->intr_ds
& ds_toc_ready
) {
404 /* do something appropriate */
406 /* couldn't see why this interrupt, maybe due to init */
408 outw(dc_normal
| READ_AHEAD
, r_data_control
);
411 if (cd
->background
&& (cd
->adapter_last
-cd
->adapter_first
== cd
->max_sectors
412 || cd
->fifo_overflowed
))
413 mark_bh(CM206_BH
); /* issue a stop read command */
417 /* we have put the address of the wait queue in who */
418 void cm206_timeout(unsigned long who
)
421 debug(("Timing out\n"));
422 wake_up_interruptible((wait_queue_head_t
*)who
);
425 /* This function returns 1 if a timeout occurred, 0 if an interrupt
427 int sleep_or_timeout(wait_queue_head_t
*wait
, int timeout
)
430 cd
->timer
.data
=(unsigned long) wait
;
431 cd
->timer
.expires
= jiffies
+ timeout
;
432 add_timer(&cd
->timer
);
433 debug(("going to sleep\n"));
434 interruptible_sleep_on(wait
);
435 del_timer(&cd
->timer
);
443 void cm206_delay(int nr_jiffies
)
445 DECLARE_WAIT_QUEUE_HEAD(wait
);
446 sleep_or_timeout(&wait
, nr_jiffies
);
449 void send_command(int command
)
451 debug(("Sending 0x%x\n", command
));
452 if (!(inw(r_line_status
) & ls_transmitter_buffer_empty
)) {
453 cd
->command
= command
;
454 cli(); /* don't interrupt before sleep */
455 outw(dc_mask_sync_error
| dc_no_stop_on_error
|
456 (inw(r_data_status
) & 0x7f), r_data_control
);
457 /* interrupt routine sends command */
458 if (sleep_or_timeout(&cd
->uart
, UART_TIMEOUT
)) {
459 debug(("Time out on write-buffer\n"));
460 stats(write_timeout
);
461 outw(command
, r_uart_transmit
);
463 debug(("Write commmand delayed\n"));
465 else outw(command
, r_uart_transmit
);
468 uch
receive_byte(int timeout
)
473 ret
= cd
->ur
[cd
->ur_r
];
474 if (cd
->ur_r
!= cd
->ur_w
) {
476 debug(("returning #%d: 0x%x\n", cd
->ur_r
, cd
->ur
[cd
->ur_r
]));
477 cd
->ur_r
++; cd
->ur_r
%= UR_SIZE
;
480 else if (sleep_or_timeout(&cd
->uart
, timeout
)) { /* does sti() */
481 debug(("Time out on receive-buffer\n"));
483 if (timeout
==UART_TIMEOUT
) stats(receive_timeout
) /* no `;'! */
484 else stats(dsb_timeout
);
488 ret
= cd
->ur
[cd
->ur_r
];
489 debug(("slept; returning #%d: 0x%x\n", cd
->ur_r
, cd
->ur
[cd
->ur_r
]));
490 cd
->ur_r
++; cd
->ur_r
%= UR_SIZE
;
494 inline uch
receive_echo(void)
496 return receive_byte(UART_TIMEOUT
);
499 inline uch
send_receive(int command
)
501 send_command(command
);
502 return receive_echo();
505 inline uch
wait_dsb(void)
507 return receive_byte(DSB_TIMEOUT
);
510 int type_0_command(int command
, int expect_dsb
)
514 if (command
!= (e
=send_receive(command
))) {
515 debug(("command 0x%x echoed as 0x%x\n", command
, e
));
520 cd
->dsb
= wait_dsb(); /* wait for command to finish */
525 int type_1_command(int command
, int bytes
, uch
* status
) /* returns info */
528 if (type_0_command(command
,0)) return -1;
529 for(i
=0; i
<bytes
; i
++)
530 status
[i
] = send_receive(c_gimme
);
534 /* This function resets the adapter card. We'd better not do this too
535 * often, because it tends to generate `lost interrupts.' */
536 void reset_cm260(void)
538 outw(dc_normal
| dc_initialize
| READ_AHEAD
, r_data_control
);
539 udelay(10); /* 3.3 mu sec minimum */
540 outw(dc_normal
| READ_AHEAD
, r_data_control
);
543 /* fsm: frame-sec-min from linear address; one of many */
544 void fsm(int lba
, uch
* fsm
)
548 fsm
[1] = lba
% 60; fsm
[2] = lba
/ 60;
551 inline int fsm2lba(uch
* fsm
)
553 return fsm
[0] + 75*(fsm
[1]-2 + 60*fsm
[2]);
556 inline int f_s_m2lba(uch f
, uch s
, uch m
)
558 return f
+ 75*(s
-2 + 60*m
);
561 int start_read(int start
)
563 uch read_sector
[4] = {c_read_data
, };
566 fsm(start
, &read_sector
[1]);
569 if (read_sector
[i
] != (e
=send_receive(read_sector
[i
]))) {
570 debug(("read_sector: %x echoes %x\n", read_sector
[i
], e
));
572 if (e
==0xff) { /* this seems to happen often */
574 debug(("Second try %x\n", e
));
575 if (e
!=read_sector
[i
]) return -1;
584 type_0_command(c_stop
,0);
585 if((e
=receive_echo()) != 0xff) {
586 debug(("c_stop didn't send 0xff, but 0x%x\n", e
));
593 /* This function starts to read sectors in adapter memory, the
594 interrupt routine should stop the read. In fact, the bottom_half
595 routine takes care of this. Set a flag `background' in the cd
596 struct to indicate the process. */
598 int read_background(int start
, int reading
)
600 if (cd
->background
) return -1; /* can't do twice */
601 outw(dc_normal
| BACK_AHEAD
, r_data_control
);
602 if (!reading
&& start_read(start
)) return -2;
603 cd
->adapter_first
= cd
->adapter_last
= start
;
604 cd
->background
= 1; /* flag a read is going on */
609 #define transport_data insw
611 /* this routine implements insw(,,). There was a time i had the
612 impression that there would be any difference in error-behaviour. */
613 void transport_data(int port
, ush
* dest
, int count
)
617 for (i
=0, d
=dest
; i
<count
; i
++, d
++)
623 #define MAX_TRIES 100
624 int read_sector(int start
)
627 if (cd
->background
) {
629 cd
->adapter_last
= -1; /* invalidate adapter memory */
632 cd
->fifo_overflowed
=0;
633 reset_cm260(); /* empty fifo etc. */
634 if (start_read(start
)) return -1;
636 if (sleep_or_timeout(&cd
->data
, DATA_TIMEOUT
)) {
637 debug(("Read timed out sector 0x%x\n", start
));
643 } while (cd
->intr_ds
& ds_fifo_empty
&& tries
< MAX_TRIES
);
644 if (tries
>1) debug(("Took me some tries\n"))
645 else if (tries
== MAX_TRIES
)
646 debug(("MAX_TRIES tries for read sector\n"));
647 transport_data(r_fifo_output_buffer
, cd
->sector
,
648 READ_AHEAD
*RAW_SECTOR_SIZE
/2);
649 if (read_background(start
+READ_AHEAD
,1)) stats(read_background
);
650 cd
->sector_first
= start
; cd
->sector_last
= start
+READ_AHEAD
;
651 stats(read_restarted
);
655 /* The function of bottom-half is to send a stop command to the drive
656 This isn't easy because the routine is not `owned' by any process;
657 we can't go to sleep! The variable cd->background gives the status:
660 2 c_stop waits for write_buffer_empty
661 3 c_stop waits for receive_buffer_full: echo
662 4 c_stop waits for receive_buffer_full: 0xff
667 debug(("bh: %d\n", cd
->background
));
668 switch (cd
->background
) {
671 if (!(cd
->intr_ls
& ls_transmitter_buffer_empty
)) {
672 cd
->command
= c_stop
;
673 outw(dc_mask_sync_error
| dc_no_stop_on_error
|
674 (inw(r_data_status
) & 0x7f), r_data_control
);
676 break; /* we'd better not time-out here! */
678 else outw(c_stop
, r_uart_transmit
);
679 /* fall into case 2: */
681 /* the write has been satisfied by interrupt routine */
685 if (cd
->ur_r
!= cd
->ur_w
) {
686 if (cd
->ur
[cd
->ur_r
] != c_stop
) {
687 debug(("cm206_bh: c_stop echoed 0x%x\n", cd
->ur
[cd
->ur_r
]));
690 cd
->ur_r
++; cd
->ur_r
%= UR_SIZE
;
695 if (cd
->ur_r
!= cd
->ur_w
) {
696 if (cd
->ur
[cd
->ur_r
] != 0xff) {
697 debug(("cm206_bh: c_stop reacted with 0x%x\n", cd
->ur
[cd
->ur_r
]));
700 cd
->ur_r
++; cd
->ur_r
%= UR_SIZE
;
706 /* This command clears the dsb_possible_media_change flag, so we must
709 void get_drive_status(void)
712 type_1_command(c_drive_status
, 2, status
); /* this might be done faster */
716 !!(cd
->dsb
& (dsb_possible_media_change
|
717 dsb_drive_not_ready
| dsb_tray_not_closed
));
720 void get_disc_status(void)
722 if (type_1_command(c_disc_status
, 7, cd
->disc_status
)) {
723 debug(("get_disc_status: error\n"));
727 /* The new open. The real opening strategy is defined in cdrom.c. */
729 static int cm206_open(struct cdrom_device_info
* cdi
, int purpose
)
731 if (!cd
->openfiles
) { /* reset only first time */
734 cd
->adapter_last
= -1; /* invalidate adapter memory */
735 cd
->sector_last
= -1;
737 ++cd
->openfiles
; MOD_INC_USE_COUNT
;
742 static void cm206_release(struct cdrom_device_info
* cdi
)
744 if (cd
->openfiles
==1) {
745 if (cd
->background
) {
749 cd
->sector_last
= -1; /* Make our internal buffer invalid */
750 FIRST_TRACK
= 0; /* No valid disc status */
752 --cd
->openfiles
; MOD_DEC_USE_COUNT
;
755 /* Empty buffer empties $sectors$ sectors of the adapter card buffer,
756 * and then reads a sector in kernel memory. */
757 void empty_buffer(int sectors
)
760 transport_data(r_fifo_output_buffer
, cd
->sector
+ cd
->fifo_overflowed
,
761 RAW_SECTOR_SIZE
/2 - cd
->fifo_overflowed
);
763 ++cd
->adapter_first
; /* update the current adapter sector */
764 cd
->fifo_overflowed
=0; /* reset overflow bit */
765 stats(sector_transferred
);
767 cd
->sector_first
=cd
->adapter_first
-1;
768 cd
->sector_last
=cd
->adapter_first
; /* update the buffer sector */
771 /* try_adapter. This function determines if the requested sector is
772 in adapter memory, or will appear there soon. Returns 0 upon
774 int try_adapter(int sector
)
776 if (cd
->adapter_first
<= sector
&& sector
< cd
->adapter_last
) {
777 /* sector is in adapter memory */
778 empty_buffer(sector
- cd
->adapter_first
);
781 else if (cd
->background
==1 && cd
->adapter_first
<= sector
782 && sector
< cd
->adapter_first
+cd
->max_sectors
) {
783 /* a read is going on, we can wait for it */
785 while (sector
>= cd
->adapter_last
) {
786 if (sleep_or_timeout(&cd
->data
, DATA_TIMEOUT
)) {
787 debug(("Timed out during background wait: %d %d %d %d\n", sector
,
788 cd
->adapter_last
, cd
->adapter_first
, cd
->background
));
789 stats(back_read_timeout
);
795 empty_buffer(sector
- cd
->adapter_first
);
801 /* This is not a very smart implementation. We could optimize for
802 consecutive block numbers. I'm not convinced this would really
803 bring down the processor load. */
804 static void do_cm206_request(void)
806 long int i
, cd_sec_no
;
808 uch
* source
, * dest
;
810 while(1) { /* repeat until all requests have been satisfied */
812 if (CURRENT
== NULL
|| CURRENT
->rq_status
== RQ_INACTIVE
)
814 if (CURRENT
->cmd
!= READ
) {
815 debug(("Non-read command %d on cdrom\n", CURRENT
->cmd
));
819 spin_unlock_irq(&io_request_lock
);
821 for (i
=0; i
<CURRENT
->nr_sectors
; i
++) {
823 cd_sec_no
= (CURRENT
->sector
+i
)/BLOCKS_ISO
; /* 4 times 512 bytes */
824 quarter
= (CURRENT
->sector
+i
) % BLOCKS_ISO
;
825 dest
= CURRENT
->buffer
+ i
*LINUX_BLOCK_SIZE
;
826 /* is already in buffer memory? */
827 if (cd
->sector_first
<= cd_sec_no
&& cd_sec_no
< cd
->sector_last
) {
828 source
= ((uch
*) cd
->sector
) + 16 + quarter
*LINUX_BLOCK_SIZE
829 + (cd_sec_no
-cd
->sector_first
)*RAW_SECTOR_SIZE
;
830 memcpy(dest
, source
, LINUX_BLOCK_SIZE
);
832 else if (!(e1
=try_adapter(cd_sec_no
)) ||
833 !(e2
=read_sector(cd_sec_no
))) {
834 source
= ((uch
*) cd
->sector
)+16+quarter
*LINUX_BLOCK_SIZE
;
835 memcpy(dest
, source
, LINUX_BLOCK_SIZE
);
839 debug(("cm206_request: %d %d\n", e1
, e2
));
842 spin_lock_irq(&io_request_lock
);
847 /* Audio support. I've tried very hard, but the cm206 drive doesn't
848 seem to have a get_toc (table-of-contents) function, while i'm
849 pretty sure it must read the toc upon disc insertion. Therefore
850 this function has been implemented through a binary search
851 strategy. All track starts that happen to be found are stored in
852 cd->toc[], for future use.
854 I've spent a whole day on a bug that only shows under Workman---
855 I don't get it. Tried everything, nothing works. If workman asks
856 for track# 0xaa, it'll get the wrong time back. Any other program
857 receives the correct value. I'm stymied.
860 /* seek seeks to address lba. It does wait to arrive there. */
864 uch seek_command
[4]={c_seek
, };
866 fsm(lba
, &seek_command
[1]);
867 for (i
=0; i
<4; i
++) type_0_command(seek_command
[i
], 0);
868 cd
->dsb
= wait_dsb();
871 uch
bcdbin(unsigned char bcd
) /* stolen from mcd.c! */
873 return (bcd
>> 4)*10 + (bcd
& 0xf);
876 inline uch
normalize_track(uch track
)
878 if (track
<1) return 1;
879 if (track
>LAST_TRACK
) return LAST_TRACK
+1;
883 /* This function does a binary search for track start. It records all
884 * tracks seen in the process. Input $track$ must be between 1 and
885 * #-of-tracks+1. Note that the start of the disc must be in toc[1].fsm.
887 int get_toc_lba(uch track
)
889 int max
=74*60*75-150, min
=fsm2lba(cd
->toc
[1].fsm
);
890 int i
, lba
, l
, old_lba
=0;
892 uch ct
; /* current track */
894 const int skip
= 3*60*75; /* 3 minutes */
896 for (i
=track
; i
>0; i
--) if (cd
->toc
[i
].track
) {
897 min
= fsm2lba(cd
->toc
[i
].fsm
);
903 type_1_command(c_read_current_q
, 10, q
);
904 ct
= normalize_track(q
[1]);
905 if (!cd
->toc
[ct
].track
) {
906 l
= q
[9]-bcdbin(q
[5]) + 75*(q
[8]-bcdbin(q
[4])-2 +
907 60*(q
[7]-bcdbin(q
[3])));
908 cd
->toc
[ct
].track
=q
[1]; /* lead out still 0xaa */
909 fsm(l
, cd
->toc
[ct
].fsm
);
910 cd
->toc
[ct
].q0
= q
[0]; /* contains adr and ctrl info */
911 if (ct
==track
) return l
;
915 if (ct
< track
) min
= lba
; else max
= lba
;
918 if(ct
< track
) lba
+= skip
;
921 max
= lba
; min
= lba
- skip
;
925 } while (lba
!=old_lba
);
929 void update_toc_entry(uch track
)
931 track
= normalize_track(track
);
932 if (!cd
->toc
[track
].track
) get_toc_lba(track
);
935 /* return 0 upon success */
936 int read_toc_header(struct cdrom_tochdr
* hp
)
938 if (!FIRST_TRACK
) get_disc_status();
941 hp
->cdth_trk0
= FIRST_TRACK
;
942 hp
->cdth_trk1
= LAST_TRACK
;
943 /* fill in first track position */
944 for (i
=0; i
<3; i
++) cd
->toc
[1].fsm
[i
] = cd
->disc_status
[3+i
];
945 update_toc_entry(LAST_TRACK
+1); /* find most entries */
951 void play_from_to_msf(struct cdrom_msf
* msfp
)
953 uch play_command
[] = {c_play
,
954 msfp
->cdmsf_frame0
, msfp
->cdmsf_sec0
, msfp
->cdmsf_min0
,
955 msfp
->cdmsf_frame1
, msfp
->cdmsf_sec1
, msfp
->cdmsf_min1
, 2, 2};
957 for (i
=0; i
<9; i
++) type_0_command(play_command
[i
], 0);
959 PLAY_TO
.fsm
[i
] = play_command
[i
+4];
960 PLAY_TO
.track
= 0; /* say no track end */
961 cd
->dsb
= wait_dsb();
964 void play_from_to_track(int from
, int to
)
966 uch play_command
[8] = {c_play
, };
969 if (from
==0) { /* continue paused play */
970 for (i
=0; i
<3; i
++) {
971 play_command
[i
+1] = cd
->audio_status
[i
+2];
972 play_command
[i
+4] = PLAY_TO
.fsm
[i
];
975 update_toc_entry(from
); update_toc_entry(to
+1);
976 for (i
=0; i
<3; i
++) {
977 play_command
[i
+1] = cd
->toc
[from
].fsm
[i
];
978 PLAY_TO
.fsm
[i
] = play_command
[i
+4] = cd
->toc
[to
+1].fsm
[i
];
982 for (i
=0; i
<7; i
++) type_0_command(play_command
[i
],0);
983 for (i
=0; i
<2; i
++) type_0_command(0x2, 0); /* volume */
984 cd
->dsb
= wait_dsb();
987 int get_current_q(struct cdrom_subchnl
* qp
)
991 if (type_1_command(c_read_current_q
, 10, q
)) return 0;
992 /* q[0] = bcdbin(q[0]); Don't think so! */
993 for (i
=2; i
<6; i
++) q
[i
]=bcdbin(q
[i
]);
994 qp
->cdsc_adr
= q
[0] & 0xf; qp
->cdsc_ctrl
= q
[0] >> 4; /* from mcd.c */
995 qp
->cdsc_trk
= q
[1]; qp
->cdsc_ind
= q
[2];
996 if (qp
->cdsc_format
== CDROM_MSF
) {
997 qp
->cdsc_reladdr
.msf
.minute
= q
[3];
998 qp
->cdsc_reladdr
.msf
.second
= q
[4];
999 qp
->cdsc_reladdr
.msf
.frame
= q
[5];
1000 qp
->cdsc_absaddr
.msf
.minute
= q
[7];
1001 qp
->cdsc_absaddr
.msf
.second
= q
[8];
1002 qp
->cdsc_absaddr
.msf
.frame
= q
[9];
1004 qp
->cdsc_reladdr
.lba
= f_s_m2lba(q
[5], q
[4], q
[3]);
1005 qp
->cdsc_absaddr
.lba
= f_s_m2lba(q
[9], q
[8], q
[7]);
1008 if (cd
->dsb
& dsb_play_in_progress
)
1009 qp
->cdsc_audiostatus
= CDROM_AUDIO_PLAY
;
1011 qp
->cdsc_audiostatus
= CDROM_AUDIO_PAUSED
;
1012 else qp
->cdsc_audiostatus
= CDROM_AUDIO_NO_STATUS
;
1016 void invalidate_toc(void)
1018 memset(cd
->toc
, 0, sizeof(cd
->toc
));
1019 memset(cd
->disc_status
, 0, sizeof(cd
->disc_status
));
1022 /* cdrom.c guarantees that cdte_format == CDROM_MSF */
1023 void get_toc_entry(struct cdrom_tocentry
* ep
)
1025 uch track
= normalize_track(ep
->cdte_track
);
1026 update_toc_entry(track
);
1027 ep
->cdte_addr
.msf
.frame
= cd
->toc
[track
].fsm
[0];
1028 ep
->cdte_addr
.msf
.second
= cd
->toc
[track
].fsm
[1];
1029 ep
->cdte_addr
.msf
.minute
= cd
->toc
[track
].fsm
[2];
1030 ep
->cdte_adr
= cd
->toc
[track
].q0
& 0xf;
1031 ep
->cdte_ctrl
= cd
->toc
[track
].q0
>> 4;
1032 ep
->cdte_datamode
=0;
1035 /* Audio ioctl. Ioctl commands connected to audio are in such an
1036 * idiosyncratic i/o format, that we leave these untouched. Return 0
1037 * upon success. Memory checking has been done by cdrom_ioctl(), the
1038 * calling function, as well as LBA/MSF sanitization.
1040 int cm206_audio_ioctl(struct cdrom_device_info
* cdi
, unsigned int cmd
,
1044 case CDROMREADTOCHDR
:
1045 return read_toc_header((struct cdrom_tochdr
*) arg
);
1046 case CDROMREADTOCENTRY
:
1047 get_toc_entry((struct cdrom_tocentry
*) arg
);
1050 play_from_to_msf((struct cdrom_msf
*) arg
);
1052 case CDROMPLAYTRKIND
: /* admittedly, not particularly beautiful */
1053 play_from_to_track(((struct cdrom_ti
*)arg
)->cdti_trk0
,
1054 ((struct cdrom_ti
*)arg
)->cdti_trk1
);
1058 if (cd
->dsb
& dsb_play_in_progress
) return type_0_command(c_stop
, 1);
1062 if (cd
->dsb
& dsb_play_in_progress
) {
1063 type_0_command(c_stop
, 1);
1064 type_1_command(c_audio_status
, 5, cd
->audio_status
);
1065 PAUSED
=1; /* say we're paused */
1069 if (PAUSED
) play_from_to_track(0,0);
1076 return get_current_q((struct cdrom_subchnl
*)arg
);
1082 /* Ioctl. These ioctls are specific to the cm206 driver. I have made
1083 some driver statistics accessible through ioctl calls.
1086 static int cm206_ioctl(struct cdrom_device_info
* cdi
, unsigned int cmd
,
1091 case CM206CTL_GET_STAT
:
1092 if (arg
>= NR_STATS
) return -EINVAL
;
1093 else return cd
->stats
[arg
];
1094 case CM206CTL_GET_LAST_STAT
:
1095 if (arg
>= NR_STATS
) return -EINVAL
;
1096 else return cd
->last_stat
[arg
];
1099 debug(("Unknown ioctl call 0x%x\n", cmd
));
1104 int cm206_media_changed(struct cdrom_device_info
* cdi
, int disc_nr
)
1108 get_drive_status(); /* ensure cd->media_changed OK */
1109 r
= cd
->media_changed
;
1110 cd
->media_changed
= 0; /* clear bit */
1116 /* The new generic cdrom support. Routines should be concise, most of
1117 the logic should be in cdrom.c */
1119 /* returns number of times device is in use */
1120 int cm206_open_files(struct cdrom_device_info
* cdi
)
1122 if (cd
) return cd
->openfiles
;
1126 /* controls tray movement */
1127 int cm206_tray_move(struct cdrom_device_info
* cdi
, int position
)
1129 if (position
) { /* 1: eject */
1130 type_0_command(c_open_tray
,1);
1133 else type_0_command(c_close_tray
, 1); /* 0: close */
1137 /* gives current state of the drive */
1138 int cm206_drive_status(struct cdrom_device_info
* cdi
, int slot_nr
)
1141 if (cd
->dsb
& dsb_tray_not_closed
) return CDS_TRAY_OPEN
;
1142 if (!(cd
->dsb
& dsb_disc_present
)) return CDS_NO_DISC
;
1143 if (cd
->dsb
& dsb_drive_not_ready
) return CDS_DRIVE_NOT_READY
;
1147 /* locks or unlocks door lock==1: lock; return 0 upon success */
1148 int cm206_lock_door(struct cdrom_device_info
* cdi
, int lock
)
1150 uch command
= (lock
) ? c_lock_tray
: c_unlock_tray
;
1151 type_0_command(command
, 1); /* wait and get dsb */
1152 /* the logic calculates the success, 0 means successful */
1153 return lock
^ ((cd
->dsb
& dsb_tray_locked
) != 0);
1156 /* Although a session start should be in LBA format, we return it in
1157 MSF format because it is slightly easier, and the new generic ioctl
1158 will take care of the necessary conversion. */
1159 int cm206_get_last_session(struct cdrom_device_info
* cdi
,
1160 struct cdrom_multisession
* mssp
)
1162 if (!FIRST_TRACK
) get_disc_status();
1164 if (DISC_STATUS
& cds_multi_session
) { /* multi-session */
1165 mssp
->addr
.msf
.frame
= cd
->disc_status
[3];
1166 mssp
->addr
.msf
.second
= cd
->disc_status
[4];
1167 mssp
->addr
.msf
.minute
= cd
->disc_status
[5];
1168 mssp
->addr_format
= CDROM_MSF
;
1178 int cm206_get_upc(struct cdrom_device_info
* cdi
, struct cdrom_mcn
* mcn
)
1181 char * ret
= mcn
->medium_catalog_number
;
1184 if (type_1_command(c_read_upc
, 10, upc
)) return -EIO
;
1185 for (i
=0; i
<13; i
++) {
1187 if (r
) ret
[i
] = 0x30 | (upc
[w
] & 0x0f);
1188 else ret
[i
] = 0x30 | ((upc
[w
] >> 4) & 0x0f);
1194 int cm206_reset(struct cdrom_device_info
* cdi
)
1198 outw(dc_normal
| dc_break
| READ_AHEAD
, r_data_control
);
1199 mdelay(1); /* 750 musec minimum */
1200 outw(dc_normal
| READ_AHEAD
, r_data_control
);
1201 cd
->sector_last
= -1; /* flag no data buffered */
1202 cd
->adapter_last
= -1;
1207 int cm206_select_speed(struct cdrom_device_info
* cdi
, int speed
)
1212 r
= type_0_command(c_auto_mode
, 1);
1215 r
= type_0_command(c_force_1x
, 1);
1218 r
= type_0_command(c_force_2x
, 1);
1227 static struct cdrom_device_ops cm206_dops
= {
1228 cm206_open
, /* open */
1229 cm206_release
, /* release */
1230 cm206_drive_status
, /* drive status */
1231 cm206_media_changed
, /* media changed */
1232 cm206_tray_move
, /* tray move */
1233 cm206_lock_door
, /* lock door */
1234 cm206_select_speed
, /* select speed */
1235 NULL
, /* select disc */
1236 cm206_get_last_session
, /* get last session */
1237 cm206_get_upc
, /* get universal product code */
1238 cm206_reset
, /* hard reset */
1239 cm206_audio_ioctl
, /* audio ioctl */
1240 cm206_ioctl
, /* device-specific ioctl */
1241 CDC_CLOSE_TRAY
| CDC_OPEN_TRAY
| CDC_LOCK
| CDC_MULTI_SESSION
|
1242 CDC_MEDIA_CHANGED
| CDC_MCN
| CDC_PLAY_AUDIO
| CDC_SELECT_SPEED
|
1243 CDC_IOCTLS
| CDC_DRIVE_STATUS
,
1245 1, /* number of minor devices */
1249 static struct cdrom_device_info cm206_info
= {
1250 &cm206_dops
, /* device operations */
1252 NULL
, /* handle (not used by cm206) */
1255 2, /* maximum speed */
1256 1, /* number of discs */
1257 0, /* options, not owned */
1258 0, /* mc_flags, not owned */
1259 0, /* use count, not owned */
1260 "cm206" /* name of the device type */
1263 /* This routine gets called during initialization if things go wrong,
1264 * can be used in cleanup_module as well. */
1265 static void cleanup(int level
)
1269 if (unregister_cdrom(&cm206_info
)) {
1270 printk("Can't unregister cdrom cm206\n");
1273 if (unregister_blkdev(MAJOR_NR
, "cm206")) {
1274 printk("Can't unregister major cm206\n");
1278 free_irq(cm206_irq
, NULL
);
1282 release_region(cm206_base
, 16);
1287 /* This function probes for the adapter card. It returns the base
1288 address if it has found the adapter card. One can specify a base
1289 port to probe specifically, or 0 which means span all possible
1292 Linus says it is too dangerous to use writes for probing, so we
1293 stick with pure reads for a while. Hope that 8 possible ranges,
1294 check_region, 15 bits of one port and 6 of another make things
1295 likely enough to accept the region on the first hit...
1297 int __init
probe_base_port(int base
)
1299 int b
=0x300, e
=0x370; /* this is the range of start addresses */
1300 volatile int fool
, i
;
1303 for (base
=b
; base
<=e
; base
+= 0x10) {
1304 if (check_region(base
, 0x10)) continue;
1306 fool
= inw(base
+2); /* empty possibly uart_receive_buffer */
1307 if((inw(base
+6) & 0xffef) != 0x0001 || /* line_status */
1308 (inw(base
) & 0xad00) != 0) /* data status */
1315 #if !defined(MODULE) || defined(AUTO_PROBE_MODULE)
1316 /* Probe for irq# nr. If nr==0, probe for all possible irq's. */
1317 int __init
probe_irq(int nr
){
1319 outw(dc_normal
| READ_AHEAD
, r_data_control
); /* disable irq-generation */
1321 irqs
= probe_irq_on();
1322 reset_cm260(); /* causes interrupt */
1323 udelay(100); /* wait for it */
1324 irq
= probe_irq_off(irqs
);
1325 outw(dc_normal
| READ_AHEAD
, r_data_control
); /* services interrupt */
1326 if (nr
&& irq
!=nr
&& irq
>0) return 0; /* wrong interrupt happened */
1331 int __init
cm206_init(void)
1334 long int size
=sizeof(struct cm206_struct
);
1336 printk(KERN_INFO
"cm206 cdrom driver " REVISION
);
1337 cm206_base
= probe_base_port(auto_probe
? 0 : cm206_base
);
1339 printk(" can't find adapter!\n");
1342 printk(" adapter at 0x%x", cm206_base
);
1343 request_region(cm206_base
, 16, "cm206");
1344 cd
= (struct cm206_struct
*) kmalloc(size
, GFP_KERNEL
);
1345 if (!cd
) return -EIO
;
1346 /* Now we have found the adaptor card, try to reset it. As we have
1347 * found out earlier, this process generates an interrupt as well,
1348 * so we might just exploit that fact for irq probing! */
1349 #if !defined(MODULE) || defined(AUTO_PROBE_MODULE)
1350 cm206_irq
= probe_irq(auto_probe
? 0 : cm206_irq
);
1352 printk("can't find IRQ!\n");
1356 else printk(" IRQ %d found\n", cm206_irq
);
1360 /* Now, the problem here is that reset_cm260 can generate an
1361 interrupt. It seems that this can cause a kernel oops some time
1362 later. So we wait a while and `service' this interrupt. */
1364 outw(dc_normal
| READ_AHEAD
, r_data_control
);
1366 printk(" using IRQ %d\n", cm206_irq
);
1368 if (send_receive_polled(c_drive_configuration
) != c_drive_configuration
)
1370 printk(KERN_INFO
" drive not there\n");
1374 e
= send_receive_polled(c_gimme
);
1375 printk(KERN_INFO
"Firmware revision %d", e
& dcf_revision_code
);
1376 if (e
& dcf_transfer_rate
) printk(" double");
1377 else printk(" single");
1378 printk(" speed drive");
1379 if (e
& dcf_motorized_tray
) printk(", motorized tray");
1380 if (request_irq(cm206_irq
, cm206_interrupt
, 0, "cm206", NULL
)) {
1381 printk("\nUnable to reserve IRQ---aborted\n");
1386 if (register_blkdev(MAJOR_NR
, "cm206", &cdrom_fops
) != 0) {
1387 printk(KERN_INFO
"Cannot register for major %d!\n", MAJOR_NR
);
1391 cm206_info
.dev
= MKDEV(MAJOR_NR
,0);
1392 if (register_cdrom(&cm206_info
) != 0) {
1393 printk(KERN_INFO
"Cannot register for cdrom %d!\n", MAJOR_NR
);
1397 blk_dev
[MAJOR_NR
].request_fn
= DEVICE_REQUEST
;
1398 blksize_size
[MAJOR_NR
] = cm206_blocksizes
;
1399 read_ahead
[MAJOR_NR
] = 16; /* reads ahead what? */
1400 init_bh(CM206_BH
, cm206_bh
);
1402 memset(cd
, 0, sizeof(*cd
)); /* give'm some reasonable value */
1403 cd
->sector_last
= -1; /* flag no data buffered */
1404 cd
->adapter_last
= -1;
1405 cd
->timer
.function
= cm206_timeout
;
1406 cd
->max_sectors
= (inw(r_data_status
) & ds_ram_size
) ? 24 : 97;
1407 printk(KERN_INFO
"%d kB adapter memory available, "
1408 " %ld bytes kernel memory used.\n", cd
->max_sectors
*2, size
);
1414 static int cm206
[2] = {0,0}; /* for compatible `insmod' parameter passing */
1416 void __init
parse_options(void)
1419 for (i
=0; i
<2; i
++) {
1420 if (0x300 <= cm206
[i
] && i
<= 0x370 && cm206
[i
] % 0x10 == 0) {
1421 cm206_base
= cm206
[i
];
1424 else if (3 <= cm206
[i
] && cm206
[i
] <= 15) {
1425 cm206_irq
= cm206
[i
];
1431 int init_module(void)
1434 #if !defined(AUTO_PROBE_MODULE)
1437 return cm206_init();
1440 void cleanup_module(void)
1443 printk(KERN_INFO
"cm206 removed\n");
1448 /* This setup function accepts either `auto' or numbers in the range
1449 * 3--11 (for irq) or 0x300--0x370 (for base port) or both. */
1450 void __init
cm206_setup(char *s
, int *p
)
1453 if (!strcmp(s
, "auto")) auto_probe
=1;
1454 for(i
=1; i
<=p
[0]; i
++) {
1455 if (0x300 <= p
[i
] && i
<= 0x370 && p
[i
] % 0x10 == 0) {
1459 else if (3 <= p
[i
] && p
[i
] <= 15) {
1468 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -D__SMP__ -pipe -fno-strength-reduce -m486 -DCPU=486 -D__SMP__ -DMODULE -DMODVERSIONS -include /usr/src/linux/include/linux/modversions.h -c -o cm206.o cm206.c"