* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / cdrom / isp16.c
blob7b070170749ac8eeadbd5a4bf2fd16786e403000
1 /* -- ISP16 cdrom detection and configuration
3 * Copyright (c) 1995,1996 Eric van der Maarel <H.T.M.v.d.Maarel@marin.nl>
5 * Version 0.6
7 * History:
8 * 0.5 First release.
9 * Was included in the sjcd and optcd cdrom drivers.
10 * 0.6 First "stand-alone" version.
11 * Removed sound configuration.
12 * Added "module" support.
14 * Detect cdrom interface on ISP16 sound card.
15 * Configure cdrom interface.
17 * Algorithm for the card with OPTi 82C928 taken
18 * from the CDSETUP.SYS driver for MSDOS,
19 * by OPTi Computers, version 2.03.
20 * Algorithm for the card with OPTi 82C929 as communicated
21 * to me by Vadim Model and Leo Spiekman.
23 * This program is free software; you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation; either version 2 of the License, or
26 * (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39 #define ISP16_VERSION_MAJOR 0
40 #define ISP16_VERSION_MINOR 6
42 #ifdef MODULE
43 #include <linux/module.h>
44 #endif /* MODULE */
46 #include <linux/fs.h>
47 #include <linux/kernel.h>
48 #include <linux/string.h>
49 #include <linux/ioport.h>
50 #include <linux/init.h>
51 #include <asm/io.h>
52 #include "isp16.h"
54 static short isp16_detect(void);
55 static short isp16_c928__detect(void);
56 static short isp16_c929__detect(void);
57 static short isp16_cdi_config(int base, u_char drive_type, int irq, int dma);
58 static short isp16_type; /* dependent on type of interface card */
59 static u_char isp16_ctrl;
60 static u_short isp16_enable_port;
62 static int isp16_cdrom_base = ISP16_CDROM_IO_BASE;
63 static int isp16_cdrom_irq = ISP16_CDROM_IRQ;
64 static int isp16_cdrom_dma = ISP16_CDROM_DMA;
65 static char *isp16_cdrom_type = ISP16_CDROM_TYPE;
67 #ifdef MODULE
68 MODULE_PARM(isp16_cdrom_base, "i");
69 MODULE_PARM(isp16_cdrom_irq, "i");
70 MODULE_PARM(isp16_cdrom_dma, "i");
71 MODULE_PARM(isp16_cdrom_type, "s");
72 int init_module(void);
73 void cleanup_module(void);
74 #endif
76 #define ISP16_IN(p) (outb(isp16_ctrl,ISP16_CTRL_PORT), inb(p))
77 #define ISP16_OUT(p,b) (outb(isp16_ctrl,ISP16_CTRL_PORT), outb(b,p))
80 void __init
81 isp16_setup(char *str, int *ints)
83 if ( ints[0] > 0 )
84 isp16_cdrom_base = ints[1];
85 if ( ints[0] > 1 )
86 isp16_cdrom_irq = ints[2];
87 if ( ints[0] > 2 )
88 isp16_cdrom_dma = ints[3];
89 if ( str )
90 isp16_cdrom_type = str;
94 * ISP16 initialisation.
97 int __init
98 isp16_init(void)
100 u_char expected_drive;
102 printk(KERN_INFO "ISP16: configuration cdrom interface, version %d.%d.\n", ISP16_VERSION_MAJOR,
103 ISP16_VERSION_MINOR);
105 if ( !strcmp(isp16_cdrom_type, "noisp16") ) {
106 printk("ISP16: no cdrom interface configured.\n");
107 return(0);
110 if (check_region(ISP16_IO_BASE, ISP16_IO_SIZE)) {
111 printk("ISP16: i/o ports already in use.\n");
112 return(-EIO);
115 if ( (isp16_type=isp16_detect()) < 0 ) {
116 printk("ISP16: no cdrom interface found.\n");
117 return(-EIO);
120 printk(KERN_INFO "ISP16: cdrom interface (with OPTi 82C92%d chip) detected.\n",
121 (isp16_type==2) ? 9 : 8);
123 if ( !strcmp(isp16_cdrom_type, "Sanyo") )
124 expected_drive = (isp16_type ? ISP16_SANYO1 : ISP16_SANYO0);
125 else if ( !strcmp(isp16_cdrom_type, "Sony") )
126 expected_drive = ISP16_SONY;
127 else if ( !strcmp(isp16_cdrom_type, "Panasonic") )
128 expected_drive = (isp16_type ? ISP16_PANASONIC1 : ISP16_PANASONIC0);
129 else if ( !strcmp(isp16_cdrom_type, "Mitsumi") )
130 expected_drive = ISP16_MITSUMI;
131 else {
132 printk("ISP16: %s not supported by cdrom interface.\n", isp16_cdrom_type);
133 return(-EIO);
136 if ( isp16_cdi_config(isp16_cdrom_base, expected_drive,
137 isp16_cdrom_irq, isp16_cdrom_dma ) < 0) {
138 printk("ISP16: cdrom interface has not been properly configured.\n");
139 return(-EIO);
141 printk(KERN_INFO "ISP16: cdrom interface set up with io base 0x%03X, irq %d, dma %d,"
142 " type %s.\n", isp16_cdrom_base, isp16_cdrom_irq, isp16_cdrom_dma,
143 isp16_cdrom_type);
144 return(0);
147 static short __init
148 isp16_detect(void)
151 if ( isp16_c929__detect() >= 0 )
152 return(2);
153 else
154 return(isp16_c928__detect());
157 static short __init
158 isp16_c928__detect(void)
160 u_char ctrl;
161 u_char enable_cdrom;
162 u_char io;
163 short i = -1;
165 isp16_ctrl = ISP16_C928__CTRL;
166 isp16_enable_port = ISP16_C928__ENABLE_PORT;
168 /* read' and write' are a special read and write, respectively */
170 /* read' ISP16_CTRL_PORT, clear last two bits and write' back the result */
171 ctrl = ISP16_IN( ISP16_CTRL_PORT ) & 0xFC;
172 ISP16_OUT( ISP16_CTRL_PORT, ctrl );
174 /* read' 3,4 and 5-bit from the cdrom enable port */
175 enable_cdrom = ISP16_IN( ISP16_C928__ENABLE_PORT ) & 0x38;
177 if ( !(enable_cdrom & 0x20) ) { /* 5-bit not set */
178 /* read' last 2 bits of ISP16_IO_SET_PORT */
179 io = ISP16_IN( ISP16_IO_SET_PORT ) & 0x03;
180 if ( ((io&0x01)<<1) == (io&0x02) ) { /* bits are the same */
181 if ( io == 0 ) { /* ...the same and 0 */
182 i = 0;
183 enable_cdrom |= 0x20;
185 else { /* ...the same and 1 */ /* my card, first time 'round */
186 i = 1;
187 enable_cdrom |= 0x28;
189 ISP16_OUT( ISP16_C928__ENABLE_PORT, enable_cdrom );
191 else { /* bits are not the same */
192 ISP16_OUT( ISP16_CTRL_PORT, ctrl );
193 return(i); /* -> not detected: possibly incorrect conclusion */
196 else if ( enable_cdrom == 0x20 )
197 i = 0;
198 else if ( enable_cdrom == 0x28 ) /* my card, already initialised */
199 i = 1;
201 ISP16_OUT( ISP16_CTRL_PORT, ctrl );
203 return(i);
206 static short __init
207 isp16_c929__detect(void)
209 u_char ctrl;
210 u_char tmp;
212 isp16_ctrl = ISP16_C929__CTRL;
213 isp16_enable_port = ISP16_C929__ENABLE_PORT;
215 /* read' and write' are a special read and write, respectively */
217 /* read' ISP16_CTRL_PORT and save */
218 ctrl = ISP16_IN( ISP16_CTRL_PORT );
220 /* write' zero to the ctrl port and get response */
221 ISP16_OUT( ISP16_CTRL_PORT, 0 );
222 tmp = ISP16_IN( ISP16_CTRL_PORT );
224 if ( tmp != 2 ) /* isp16 with 82C929 not detected */
225 return(-1);
227 /* restore ctrl port value */
228 ISP16_OUT( ISP16_CTRL_PORT, ctrl );
230 return(2);
233 static short __init
234 isp16_cdi_config(int base, u_char drive_type, int irq, int dma)
236 u_char base_code;
237 u_char irq_code;
238 u_char dma_code;
239 u_char i;
241 if ( (drive_type == ISP16_MITSUMI) && (dma != 0) )
242 printk("ISP16: Mitsumi cdrom drive has no dma support.\n");
244 switch (base) {
245 case 0x340: base_code = ISP16_BASE_340; break;
246 case 0x330: base_code = ISP16_BASE_330; break;
247 case 0x360: base_code = ISP16_BASE_360; break;
248 case 0x320: base_code = ISP16_BASE_320; break;
249 default:
250 printk("ISP16: base address 0x%03X not supported by cdrom interface.\n",
251 base);
252 return(-1);
254 switch (irq) {
255 case 0: irq_code = ISP16_IRQ_X; break; /* disable irq */
256 case 5: irq_code = ISP16_IRQ_5;
257 printk("ISP16: irq 5 shouldn't be used by cdrom interface,"
258 " due to possible conflicts with the sound card.\n");
259 break;
260 case 7: irq_code = ISP16_IRQ_7;
261 printk("ISP16: irq 7 shouldn't be used by cdrom interface,"
262 " due to possible conflicts with the sound card.\n");
263 break;
264 case 3: irq_code = ISP16_IRQ_3; break;
265 case 9: irq_code = ISP16_IRQ_9; break;
266 case 10: irq_code = ISP16_IRQ_10; break;
267 case 11: irq_code = ISP16_IRQ_11; break;
268 default:
269 printk("ISP16: irq %d not supported by cdrom interface.\n", irq );
270 return(-1);
272 switch (dma) {
273 case 0: dma_code = ISP16_DMA_X; break; /* disable dma */
274 case 1: printk("ISP16: dma 1 cannot be used by cdrom interface,"
275 " due to conflict with the sound card.\n");
276 return(-1); break;
277 case 3: dma_code = ISP16_DMA_3; break;
278 case 5: dma_code = ISP16_DMA_5; break;
279 case 6: dma_code = ISP16_DMA_6; break;
280 case 7: dma_code = ISP16_DMA_7; break;
281 default:
282 printk("ISP16: dma %d not supported by cdrom interface.\n", dma);
283 return(-1);
286 if ( drive_type != ISP16_SONY && drive_type != ISP16_PANASONIC0 &&
287 drive_type != ISP16_PANASONIC1 && drive_type != ISP16_SANYO0 &&
288 drive_type != ISP16_SANYO1 && drive_type != ISP16_MITSUMI &&
289 drive_type != ISP16_DRIVE_X ) {
290 printk("ISP16: drive type (code 0x%02X) not supported by cdrom"
291 " interface.\n", drive_type );
292 return(-1);
295 /* set type of interface */
296 i = ISP16_IN(ISP16_DRIVE_SET_PORT) & ISP16_DRIVE_SET_MASK; /* clear some bits */
297 ISP16_OUT( ISP16_DRIVE_SET_PORT, i|drive_type );
299 /* enable cdrom on interface with 82C929 chip */
300 if ( isp16_type > 1 )
301 ISP16_OUT( isp16_enable_port, ISP16_ENABLE_CDROM );
303 /* set base address, irq and dma */
304 i = ISP16_IN(ISP16_IO_SET_PORT) & ISP16_IO_SET_MASK; /* keep some bits */
305 ISP16_OUT( ISP16_IO_SET_PORT, i|base_code|irq_code|dma_code );
307 return(0);
310 #ifdef MODULE
311 int init_module(void)
313 return isp16_init();
316 void cleanup_module(void)
318 release_region(ISP16_IO_BASE, ISP16_IO_SIZE);
319 printk(KERN_INFO "ISP16: module released.\n");
321 #endif /* MODULE */