?? sbpcd.c.txt
字號:
1 /*
2 * sbpcd.c CD-ROM device driver for the whole family of IDE-style
3 * Kotobuki/Matsushita/Panasonic CR-5xx drives for
4 * SoundBlaster ("Pro" or "16 ASP" or compatible) cards
5 * and for "no-sound" interfaces like Lasermate and the
6 * Panasonic CI-101P.
7 *
8 * NOTE: This is release 1.3.
9 * It works with my SbPro & drive CR-521 V2.11 from 2/92
10 * and with the new CR-562-B V0.75 on a "naked" Panasonic
11 * CI-101P interface. And vice versa.
12 *
13 *
14 * VERSION HISTORY
15 *
16 * 0.1 initial release, April/May 93, after mcd.c (Martin Harriss)
17 *
18 * 0.2 the "repeat:"-loop in do_sbpcd_request did not check for
19 * end-of-request_queue (resulting in kernel panic).
20 * Flow control seems stable, but throughput is not better.
21 *
22 * 0.3 interrupt locking totally eliminated (maybe "inb" and "outb"
23 * are still locking) - 0.2 made keyboard-type-ahead losses.
24 * check_sbpcd_media_change added (to use by isofs/inode.c)
25 * - but it detects almost nothing.
26 *
27 * 0.4 use MAJOR 25 definitely.
28 * Almost total re-design to support double-speed drives and
29 * "naked" (no sound) interface cards.
30 * Flow control should be exact now (tell me if not).
31 * Don't occupy the SbPro IRQ line (not needed either); will
32 * live together with Hannu Savolainen's sndkit now.
33 * Speeded up data transfer to 150 kB/sec, with help from Kai
34 * Makisara, the "provider" of the "mt" tape utility.
35 * Give "SpinUp" command if necessary.
36 * First steps to support up to 4 drives (but currently only one).
37 * Implemented audio capabilities - workman should work, xcdplayer
38 * gives some problems.
39 * This version is still consuming too much CPU time, and
40 * sleeping still has to be worked on.
41 * During "long" implied seeks, it seems possible that a
42 * ReadStatus command gets ignored. That gives the message
43 * "ResponseStatus timed out" (happens about 6 times here during
44 * a "ls -alR" of the YGGDRASIL LGX-Beta CD). Such a case is
45 * handled without data error, but it should get done better.
46 *
47 * 0.5 Free CPU during waits (again with help from Kai Makisara).
48 * Made it work together with the LILO/kernel setup standard.
49 * Included auto-probing code, as suggested by YGGDRASIL.
50 * Formal redesign to add DDI debugging.
51 * There are still flaws in IOCTL (workman with double speed drive).
52 *
53 * 1.0 Added support for all drive ids (0...3, no longer only 0)
54 * and up to 4 drives on one controller.
55 * Added "#define MANY_SESSION" for "old" multi session CDs.
56 *
57 * 1.1 Do SpinUp for new drives, too.
58 * Revised for clean compile under "old" kernels (pl9).
59 *
60 * 1.2 Found the "workman with double-speed drive" bug: use the driver's
61 * audio_state, not what the drive is reporting with ReadSubQ.
62 *
63 * 1.3 Minor cleanups.
64 * Refinements regarding Workman.
65 *
66 * special thanks to Kai Makisara (kai.makisara@vtt.fi) for his fine
67 * elaborated speed-up experiments (and the fabulous results!), for
68 * the "push" towards load-free wait loops, and for the extensive mail
69 * thread which brought additional hints and bug fixes.
70 *
71 *
72 * Copyright (C) 1993, 1994 Eberhard Moenkeberg <emoenke@gwdg.de>
73 * or <eberhard_moenkeberg@rollo.central.de>
74 *
75 * The FTP-home of this driver is
76 * ftp.gwdg.de:/pub/linux/cdrom/drivers/sbpcd/.
77 *
78 * If you change this software, you should mail a .diff
79 * file with some description lines to emoenke@gwdg.de.
80 * I want to know about it.
81 *
82 * If you are the editor of a Linux CD, you should
83 * enable sbpcd.c within your boot floppy kernel and
84 * send me one of your CDs for free.
85 *
86 * This program is free software; you can redistribute it and/or modify
87 * it under the terms of the GNU General Public License as published by
88 * the Free Software Foundation; either version 2, or (at your option)
89 * any later version.
90 *
91 * You should have received a copy of the GNU General Public License
92 * (for example /usr/src/linux/COPYING); if not, write to the Free
93 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
94 *
95 */
96
97 #include <linux/config.h>
98 #include <linux/errno.h>
99
100 #include <linux/sched.h>
101 #include <linux/timer.h>
102 #include <linux/fs.h>
103 #include <linux/kernel.h>
104 #include <linux/cdrom.h>
105 #include <linux/ioport.h>
106 #include <linux/sbpcd.h>
107
108 #if SBPCD_USE_IRQ
109 #include <linux/signal.h>
110 #endif SBPCD_USE_IRQ
111
112 #include <linux/ddi.h>
113 #include <linux/major.h>
114
115 #include <asm/system.h>
116 #include <asm/io.h>
117 #include <asm/segment.h>
118 #include <stdarg.h>
119
120 #define MAJOR_NR MATSUSHITA_CDROM_MAJOR
121 #include "blk.h"
122
123 #define VERSION "1.3 Eberhard Moenkeberg <emoenke@gwdg.de>"
124
125 #define SBPCD_DEBUG
126
127 #ifndef CONFIG_ISO9660_FS
128 #error "SBPCD: \"make config\" again. File system iso9660 is necessary."
129 #endif
130
131 /*
132 * still testing around...
133 */
134 #define MANY_SESSION 0
135 #define CDMKE
136 #undef FUTURE
137 #define WORKMAN 1 /* some testing stuff to make it better */
138
139 /*==========================================================================*/
140 /*==========================================================================*/
141 /*
142 * auto-probing address list
143 * inspired by Adam J. Richter from Yggdrasil
144 *
145 * still not good enough - can cause a hang.
146 * example: a NE 2000 ethernet card at 300 will cause a hang probing 310.
147 * if that happens, reboot and use the LILO (kernel) command line.
148 * The possibly conflicting ethernet card addresses get NOT probed
149 * by default - to minimize the hang possibilities.
150 *
151 * The SB Pro addresses get "mirrored" at 0x6xx - to avoid a type error,
152 * the 0x2xx-addresses must get checked before 0x6xx.
153 *
154 * send mail to emoenke@gwdg.de if your interface card is not FULLY
155 * represented here.
156 */
157 static int autoprobe[] =
158 {
159 CDROM_PORT, SBPRO, /* probe with user's setup first */
160 0x230, 1, /* Soundblaster Pro and 16 (default) */
161 0x300, 0, /* CI-101P (default), Galaxy (default), Reveal (one default) */
162 0x250, 1, /* OmniCD default, Soundblaster Pro and 16 */
163 0x260, 1, /* OmniCD */
164 0x320, 0, /* Lasermate, CI-101P, Galaxy, Reveal (other default) */
165 0x340, 0, /* Lasermate, CI-101P */
166 0x360, 0, /* Lasermate, CI-101P */
167 0x270, 1, /* Soundblaster 16 */
168 0x630, 0, /* "sound card #9" (default) */
169 0x650, 0, /* "sound card #9" */
170 0x670, 0, /* "sound card #9" */
171 0x690, 0, /* "sound card #9" */
172 #if 0
173 /* some "hazardous" locations (ethernet cards) */
174 0x330, 0, /* Lasermate, CI-101P */
175 0x350, 0, /* Lasermate, CI-101P */
176 0x370, 0, /* Lasermate, CI-101P */
177 0x290, 1, /* Soundblaster 16 */
178 0x310, 0, /* Lasermate, CI-101P */
179 #endif
180 };
181
182 #define NUM_AUTOPROBE (sizeof(autoprobe) / sizeof(int))
183
184
185 /*==========================================================================*/
186 /*
187 * the forward references:
188 */
189 static void sbp_read_cmd(void);
190 static int sbp_data(void);
191
192 /*==========================================================================*/
193
194 /*
195 * pattern for printk selection:
196 *
197 * (1<<DBG_INF) necessary information
198 * (1<<DBG_IRQ) interrupt trace
199 * (1<<DBG_REA) "read" status trace
200 * (1<<DBG_CHK) "media check" trace
201 * (1<<DBG_TIM) datarate timer test
202 * (1<<DBG_INI) initialization trace
203 * (1<<DBG_TOC) tell TocEntry values
204 * (1<<DBG_IOC) ioctl trace
205 * (1<<DBG_STA) "ResponseStatus" trace
206 * (1<<DBG_ERR) "xx_ReadError" trace
207 * (1<<DBG_CMD) "cmd_out" trace
208 * (1<<DBG_WRN) give explanation before auto-probing
209 * (1<<DBG_MUL) multi session code test
210 * (1<<DBG_ID) "drive_id != 0" test code
211 * (1<<DBG_IOX) some special information
212 * (1<<DBG_DID) drive ID test
213 * (1<<DBG_RES) drive reset info
214 * (1<<DBG_SPI) SpinUp test info
215 * (1<<DBG_IOS) ioctl trace: "subchannel"
216 * (1<<DBG_IO2) ioctl trace: general
217 * (1<<DBG_000) unnecessary information
218 */
219 #if 1
220 static int sbpcd_debug = (1<<DBG_INF) | (1<<DBG_WRN);
221 #else
222 static int sbpcd_debug = (1<<DBG_INF) |
223 (1<<DBG_TOC) |
224 (1<<DBG_IOC) |
225 (1<<DBG_IOX);
226 #endif
227 static int sbpcd_ioaddr = CDROM_PORT; /* default I/O base address */
228 static int sbpro_type = SBPRO;
229 static int CDo_command, CDo_reset;
230 static int CDo_sel_d_i, CDo_enable;
231 static int CDi_info, CDi_status, CDi_data;
232 static int MIXER_addr, MIXER_data;
233 static struct cdrom_msf msf;
234 static struct cdrom_ti ti;
235 static struct cdrom_tochdr tochdr;
236 static struct cdrom_tocentry tocentry;
237 static struct cdrom_subchnl SC;
238 static struct cdrom_volctrl volctrl;
239 char *str_sb = "SoundBlaster";
240 char *str_lm = "LaserMate";
241 char *type;
242
243 /*==========================================================================*/
244
245 #if FUTURE
246 static struct wait_queue *sbp_waitq = NULL;
247 #endif FUTURE
248
249 /*==========================================================================*/
250
251 #define SBP_BUFFER_FRAMES 4 /* driver's own read_ahead */
252
253 /*==========================================================================*/
254
255 static u_char drive_family[]="CR-5";
256 static u_char drive_vendor[]="MATSHITA";
257
258 static u_int response_count=0;
259 static u_int flags_cmd_out;
260 static u_char cmd_type=0;
261 static u_char drvcmd[7];
262 static u_char infobuf[20];
263
264 static u_char timed_out=0;
265 static u_int datarate= 1000000;
266 static u_int maxtim16=16000000;
267 static u_int maxtim04= 4000000;
268 static u_int maxtim02= 2000000;
269 static u_int maxtim_8= 30000;
270 #if MANY_SESSION
271 static u_int maxtim_data= 9000;
272 #else
273 static u_int maxtim_data= 3000;
274 #endif MANY_SESSION
275
276 /*==========================================================================*/
277
278 static int ndrives=0;
279 static u_char drv_pattern[4]={ 0x80, 0x80, 0x80, 0x80 }; /* auto speed */
280 /* /X:... drv_pattern[0] |= (sax_n1|sax_n2); */
281 /* /A:... for (i=0;i<4;i++) drv_pattern[i] |= sax_a; */
282 /* /N:... ndrives=i-''; */
283
284 /*==========================================================================*/
285 /*
286 * drive space begins here (needed separate for each unit)
287 */
288 static int d=0; /* DS index: drive number */
289
290 static struct {
291 char drv_minor; /* minor number or -1 */
292
293 char drive_model[4];
294 char firmware_version[4];
295 u_char *sbp_buf; /* Pointer to internal data buffer,
296 space allocated during sbpcd_init() */
297 int sbp_first_frame; /* First frame in buffer */
298 int sbp_last_frame; /* Last frame in buffer */
299 int sbp_read_frames; /* Number of frames being read to buffer */
300 int sbp_current; /* Frame being currently read */
301
302 u_char drv_type;
303 u_char drv_options;
304 u_char status_byte;
305 u_char diskstate_flags;
306 u_char sense_byte;
307
308 u_char CD_changed;
309
310 u_char error_byte;
311
312 u_char f_multisession;
313 u_int lba_multi;
314
315 u_char audio_state;
316 u_int pos_audio_start;
317 u_int pos_audio_end;
318 char vol_chan0;
319 u_char vol_ctrl0;
320 char vol_chan1;
321 u_char vol_ctrl1;
322 #if 000
323 char vol_chan2;
324 u_char vol_ctrl2;
325 char vol_chan3;
326 u_char vol_ctrl3;
327 #endif 000
328
329 u_char SubQ_audio;
330 u_char SubQ_ctl_adr;
331 u_char SubQ_trk;
332 u_char SubQ_pnt_idx;
333 u_int SubQ_run_tot;
334 u_int SubQ_run_trk;
335 u_char SubQ_whatisthis;
336
337 u_char UPC_ctl_adr;
338 u_char UPC_buf[7];
339
340 int CDsize_blk;
341 int frame_size;
342 int CDsize_frm;
343
344 u_char xa_byte; /* 0x20: XA capabilities */
345 u_char n_first_track; /* binary */
346 u_char n_last_track; /* binary (not bcd), 0x01...0x63 */
347 u_int size_msf; /* time of whole CD, position of LeadOut track */
348 u_int size_blk;
349
350 u_char TocEnt_nixbyte; /* em */
351 u_char TocEnt_ctl_adr;
352 u_char TocEnt_number;
353 u_char TocEnt_format; /* em */
354 u_int TocEnt_address;
355 u_char ored_ctl_adr; /* to detect if CDROM contains data tracks */
356
357 struct {
358 u_char nixbyte; /* em */
359 u_char ctl_adr; /* 0x4x: data, 0x0x: audio */
360 u_char number;
361 u_char format; /* em */ /* 0x00: lba, 0x01: msf */
362 u_int address;
363 } TocBuffer[MAX_TRACKS+1]; /* last entry faked */
364
365 int in_SpinUp;
366
367 } DS[4];
368
369 /*
370 * drive space ends here (needed separate for each unit)
371 */
372
373 /*==========================================================================*/
374 /*==========================================================================*/
375 /*
376 * DDI interface definitions
377 */
378 #ifdef SBPCD_DEBUG
379 # define DPRINTF(x) sbpcd_dprintf x
380
381 void sbpcd_dprintf(int level, char *fmt, ...)
382 {
383 char buff[256];
384 va_list args;
385 extern int vsprintf(char *buf, const char *fmt, va_list args);
386
387 if (! (sbpcd_debug & (1 << level))) return;
388
389 va_start(args, fmt);
390 vsprintf(buff, fmt, args);
391 va_end(args);
392 printk(buff);
393 }
394
395 #else
396 # define DPRINTF(x) /* nothing */
397
398 #endif SBPCD_DEBUG
399
400 /*
401 * maintain trace bit pattern
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -