1 /* -- ISP16 cdrom detection and configuration
3 * Copyright (c) 1995,1996 Eric van der Maarel <H.T.M.v.d.Maarel@marin.nl>
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 * 9 November 1999 -- Make kernel-parameter implementation work with 2.3.x
15 * Removed init_module & cleanup_module in favor of
16 * module_init & module_exit.
17 * Torben Mathiasen <tmm@image.dk>
19 * 19 June 2004 -- check_region() converted to request_region()
20 * and return statement cleanups.
21 * Jesper Juhl <juhl-lkml@dif.dk>
23 * Detect cdrom interface on ISP16 sound card.
24 * Configure cdrom interface.
26 * Algorithm for the card with OPTi 82C928 taken
27 * from the CDSETUP.SYS driver for MSDOS,
28 * by OPTi Computers, version 2.03.
29 * Algorithm for the card with OPTi 82C929 as communicated
30 * to me by Vadim Model and Leo Spiekman.
32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
48 #define ISP16_VERSION_MAJOR 0
49 #define ISP16_VERSION_MINOR 6
51 #include <linux/module.h>
54 #include <linux/kernel.h>
55 #include <linux/string.h>
56 #include <linux/ioport.h>
57 #include <linux/init.h>
61 static short isp16_detect(void);
62 static short isp16_c928__detect(void);
63 static short isp16_c929__detect(void);
64 static short isp16_cdi_config(int base
, u_char drive_type
, int irq
,
66 static short isp16_type
; /* dependent on type of interface card */
67 static u_char isp16_ctrl
;
68 static u_short isp16_enable_port
;
70 static int isp16_cdrom_base
= ISP16_CDROM_IO_BASE
;
71 static int isp16_cdrom_irq
= ISP16_CDROM_IRQ
;
72 static int isp16_cdrom_dma
= ISP16_CDROM_DMA
;
73 static char *isp16_cdrom_type
= ISP16_CDROM_TYPE
;
75 MODULE_PARM(isp16_cdrom_base
, "i");
76 MODULE_PARM(isp16_cdrom_irq
, "i");
77 MODULE_PARM(isp16_cdrom_dma
, "i");
78 MODULE_PARM(isp16_cdrom_type
, "s");
81 void isp16_exit(void);
84 #define ISP16_IN(p) (outb(isp16_ctrl,ISP16_CTRL_PORT), inb(p))
85 #define ISP16_OUT(p,b) (outb(isp16_ctrl,ISP16_CTRL_PORT), outb(b,p))
90 __init
isp16_setup(char *str
)
94 (void) get_options(str
, ARRAY_SIZE(ints
), ints
);
96 isp16_cdrom_base
= ints
[1];
98 isp16_cdrom_irq
= ints
[2];
100 isp16_cdrom_dma
= ints
[3];
102 isp16_cdrom_type
= str
;
107 __setup("isp16=", isp16_setup
);
112 * ISP16 initialisation.
115 int __init
isp16_init(void)
117 u_char expected_drive
;
120 "ISP16: configuration cdrom interface, version %d.%d.\n",
121 ISP16_VERSION_MAJOR
, ISP16_VERSION_MINOR
);
123 if (!strcmp(isp16_cdrom_type
, "noisp16")) {
124 printk("ISP16: no cdrom interface configured.\n");
128 if (!request_region(ISP16_IO_BASE
, ISP16_IO_SIZE
, "isp16")) {
129 printk("ISP16: i/o ports already in use.\n");
133 if ((isp16_type
= isp16_detect()) < 0) {
134 printk("ISP16: no cdrom interface found.\n");
139 "ISP16: cdrom interface (with OPTi 82C92%d chip) detected.\n",
140 (isp16_type
== 2) ? 9 : 8);
142 if (!strcmp(isp16_cdrom_type
, "Sanyo"))
144 (isp16_type
? ISP16_SANYO1
: ISP16_SANYO0
);
145 else if (!strcmp(isp16_cdrom_type
, "Sony"))
146 expected_drive
= ISP16_SONY
;
147 else if (!strcmp(isp16_cdrom_type
, "Panasonic"))
149 (isp16_type
? ISP16_PANASONIC1
: ISP16_PANASONIC0
);
150 else if (!strcmp(isp16_cdrom_type
, "Mitsumi"))
151 expected_drive
= ISP16_MITSUMI
;
153 printk("ISP16: %s not supported by cdrom interface.\n",
158 if (isp16_cdi_config(isp16_cdrom_base
, expected_drive
,
159 isp16_cdrom_irq
, isp16_cdrom_dma
) < 0) {
161 ("ISP16: cdrom interface has not been properly configured.\n");
165 "ISP16: cdrom interface set up with io base 0x%03X, irq %d, dma %d,"
166 " type %s.\n", isp16_cdrom_base
, isp16_cdrom_irq
,
167 isp16_cdrom_dma
, isp16_cdrom_type
);
171 release_region(ISP16_IO_BASE
, ISP16_IO_SIZE
);
176 static short __init
isp16_detect(void)
179 if (isp16_c929__detect() >= 0)
182 return (isp16_c928__detect());
185 static short __init
isp16_c928__detect(void)
192 isp16_ctrl
= ISP16_C928__CTRL
;
193 isp16_enable_port
= ISP16_C928__ENABLE_PORT
;
195 /* read' and write' are a special read and write, respectively */
197 /* read' ISP16_CTRL_PORT, clear last two bits and write' back the result */
198 ctrl
= ISP16_IN(ISP16_CTRL_PORT
) & 0xFC;
199 ISP16_OUT(ISP16_CTRL_PORT
, ctrl
);
201 /* read' 3,4 and 5-bit from the cdrom enable port */
202 enable_cdrom
= ISP16_IN(ISP16_C928__ENABLE_PORT
) & 0x38;
204 if (!(enable_cdrom
& 0x20)) { /* 5-bit not set */
205 /* read' last 2 bits of ISP16_IO_SET_PORT */
206 io
= ISP16_IN(ISP16_IO_SET_PORT
) & 0x03;
207 if (((io
& 0x01) << 1) == (io
& 0x02)) { /* bits are the same */
208 if (io
== 0) { /* ...the same and 0 */
210 enable_cdrom
|= 0x20;
211 } else { /* ...the same and 1 *//* my card, first time 'round */
213 enable_cdrom
|= 0x28;
215 ISP16_OUT(ISP16_C928__ENABLE_PORT
, enable_cdrom
);
216 } else { /* bits are not the same */
217 ISP16_OUT(ISP16_CTRL_PORT
, ctrl
);
218 return i
; /* -> not detected: possibly incorrect conclusion */
220 } else if (enable_cdrom
== 0x20)
222 else if (enable_cdrom
== 0x28) /* my card, already initialised */
225 ISP16_OUT(ISP16_CTRL_PORT
, ctrl
);
230 static short __init
isp16_c929__detect(void)
235 isp16_ctrl
= ISP16_C929__CTRL
;
236 isp16_enable_port
= ISP16_C929__ENABLE_PORT
;
238 /* read' and write' are a special read and write, respectively */
240 /* read' ISP16_CTRL_PORT and save */
241 ctrl
= ISP16_IN(ISP16_CTRL_PORT
);
243 /* write' zero to the ctrl port and get response */
244 ISP16_OUT(ISP16_CTRL_PORT
, 0);
245 tmp
= ISP16_IN(ISP16_CTRL_PORT
);
247 if (tmp
!= 2) /* isp16 with 82C929 not detected */
250 /* restore ctrl port value */
251 ISP16_OUT(ISP16_CTRL_PORT
, ctrl
);
257 isp16_cdi_config(int base
, u_char drive_type
, int irq
, int dma
)
264 if ((drive_type
== ISP16_MITSUMI
) && (dma
!= 0))
265 printk("ISP16: Mitsumi cdrom drive has no dma support.\n");
269 base_code
= ISP16_BASE_340
;
272 base_code
= ISP16_BASE_330
;
275 base_code
= ISP16_BASE_360
;
278 base_code
= ISP16_BASE_320
;
282 ("ISP16: base address 0x%03X not supported by cdrom interface.\n",
288 irq_code
= ISP16_IRQ_X
;
289 break; /* disable irq */
291 irq_code
= ISP16_IRQ_5
;
292 printk("ISP16: irq 5 shouldn't be used by cdrom interface,"
293 " due to possible conflicts with the sound card.\n");
296 irq_code
= ISP16_IRQ_7
;
297 printk("ISP16: irq 7 shouldn't be used by cdrom interface,"
298 " due to possible conflicts with the sound card.\n");
301 irq_code
= ISP16_IRQ_3
;
304 irq_code
= ISP16_IRQ_9
;
307 irq_code
= ISP16_IRQ_10
;
310 irq_code
= ISP16_IRQ_11
;
313 printk("ISP16: irq %d not supported by cdrom interface.\n",
319 dma_code
= ISP16_DMA_X
;
320 break; /* disable dma */
322 printk("ISP16: dma 1 cannot be used by cdrom interface,"
323 " due to conflict with the sound card.\n");
327 dma_code
= ISP16_DMA_3
;
330 dma_code
= ISP16_DMA_5
;
333 dma_code
= ISP16_DMA_6
;
336 dma_code
= ISP16_DMA_7
;
339 printk("ISP16: dma %d not supported by cdrom interface.\n",
344 if (drive_type
!= ISP16_SONY
&& drive_type
!= ISP16_PANASONIC0
&&
345 drive_type
!= ISP16_PANASONIC1
&& drive_type
!= ISP16_SANYO0
&&
346 drive_type
!= ISP16_SANYO1
&& drive_type
!= ISP16_MITSUMI
&&
347 drive_type
!= ISP16_DRIVE_X
) {
349 ("ISP16: drive type (code 0x%02X) not supported by cdrom"
350 " interface.\n", drive_type
);
354 /* set type of interface */
355 i
= ISP16_IN(ISP16_DRIVE_SET_PORT
) & ISP16_DRIVE_SET_MASK
; /* clear some bits */
356 ISP16_OUT(ISP16_DRIVE_SET_PORT
, i
| drive_type
);
358 /* enable cdrom on interface with 82C929 chip */
360 ISP16_OUT(isp16_enable_port
, ISP16_ENABLE_CDROM
);
362 /* set base address, irq and dma */
363 i
= ISP16_IN(ISP16_IO_SET_PORT
) & ISP16_IO_SET_MASK
; /* keep some bits */
364 ISP16_OUT(ISP16_IO_SET_PORT
, i
| base_code
| irq_code
| dma_code
);
369 void __exit
isp16_exit(void)
371 release_region(ISP16_IO_BASE
, ISP16_IO_SIZE
);
372 printk(KERN_INFO
"ISP16: module released.\n");
376 module_init(isp16_init
);
378 module_exit(isp16_exit
);
380 MODULE_LICENSE("GPL");