2 card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
3 Copyright (C) 1998-2000 by Massimo Piccioni <dafastidio@libero.it>
5 Part of this code was developed at the Italian Ministry of Air Defence,
6 Sixth Division (oh, che pace ...), Rome.
8 Thanks to Maria Grazia Pollarini, Salvatore Vassallo.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/init.h>
27 #include <linux/err.h>
28 #include <linux/isa.h>
29 #include <linux/delay.h>
30 #include <linux/pnp.h>
31 #include <linux/module.h>
34 #include <sound/core.h>
35 #include <sound/tlv.h>
36 #include <sound/wss.h>
37 #include <sound/mpu401.h>
38 #include <sound/opl3.h>
40 #include <sound/opl4.h>
42 #define SNDRV_LEGACY_FIND_FREE_IRQ
43 #define SNDRV_LEGACY_FIND_FREE_DMA
44 #include <sound/initval.h>
46 MODULE_AUTHOR("Massimo Piccioni <dafastidio@libero.it>");
47 MODULE_LICENSE("GPL");
49 MODULE_DESCRIPTION("OPTi93X");
50 MODULE_SUPPORTED_DEVICE("{{OPTi,82C931/3}}");
53 MODULE_DESCRIPTION("OPTi92X - CS4231");
54 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (CS4231)},"
55 "{OPTi,82C925 (CS4231)}}");
57 MODULE_DESCRIPTION("OPTi92X - AD1848");
58 MODULE_SUPPORTED_DEVICE("{{OPTi,82C924 (AD1848)},"
59 "{OPTi,82C925 (AD1848)},"
64 static int index
= SNDRV_DEFAULT_IDX1
; /* Index 0-MAX */
65 static char *id
= SNDRV_DEFAULT_STR1
; /* ID for this card */
66 //static bool enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
68 static int isapnp
= 1; /* Enable ISA PnP detection */
70 static long port
= SNDRV_DEFAULT_PORT1
; /* 0x530,0xe80,0xf40,0x604 */
71 static long mpu_port
= SNDRV_DEFAULT_PORT1
; /* 0x300,0x310,0x320,0x330 */
72 static long fm_port
= SNDRV_DEFAULT_PORT1
; /* 0x388 */
73 static int irq
= SNDRV_DEFAULT_IRQ1
; /* 5,7,9,10,11 */
74 static int mpu_irq
= SNDRV_DEFAULT_IRQ1
; /* 5,7,9,10 */
75 static int dma1
= SNDRV_DEFAULT_DMA1
; /* 0,1,3 */
76 #if defined(CS4231) || defined(OPTi93X)
77 static int dma2
= SNDRV_DEFAULT_DMA1
; /* 0,1,3 */
78 #endif /* CS4231 || OPTi93X */
80 module_param(index
, int, 0444);
81 MODULE_PARM_DESC(index
, "Index value for opti9xx based soundcard.");
82 module_param(id
, charp
, 0444);
83 MODULE_PARM_DESC(id
, "ID string for opti9xx based soundcard.");
84 //module_param(enable, bool, 0444);
85 //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
87 module_param(isapnp
, bool, 0444);
88 MODULE_PARM_DESC(isapnp
, "Enable ISA PnP detection for specified soundcard.");
90 module_param(port
, long, 0444);
91 MODULE_PARM_DESC(port
, "WSS port # for opti9xx driver.");
92 module_param(mpu_port
, long, 0444);
93 MODULE_PARM_DESC(mpu_port
, "MPU-401 port # for opti9xx driver.");
94 module_param(fm_port
, long, 0444);
95 MODULE_PARM_DESC(fm_port
, "FM port # for opti9xx driver.");
96 module_param(irq
, int, 0444);
97 MODULE_PARM_DESC(irq
, "WSS irq # for opti9xx driver.");
98 module_param(mpu_irq
, int, 0444);
99 MODULE_PARM_DESC(mpu_irq
, "MPU-401 irq # for opti9xx driver.");
100 module_param(dma1
, int, 0444);
101 MODULE_PARM_DESC(dma1
, "1st dma # for opti9xx driver.");
102 #if defined(CS4231) || defined(OPTi93X)
103 module_param(dma2
, int, 0444);
104 MODULE_PARM_DESC(dma2
, "2nd dma # for opti9xx driver.");
105 #endif /* CS4231 || OPTi93X */
107 #define OPTi9XX_HW_82C928 1
108 #define OPTi9XX_HW_82C929 2
109 #define OPTi9XX_HW_82C924 3
110 #define OPTi9XX_HW_82C925 4
111 #define OPTi9XX_HW_82C930 5
112 #define OPTi9XX_HW_82C931 6
113 #define OPTi9XX_HW_82C933 7
114 #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
116 #define OPTi9XX_MC_REG(n) n
120 #define OPTi93X_STATUS 0x02
121 #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
123 #define OPTi93X_IRQ_PLAYBACK 0x04
124 #define OPTi93X_IRQ_CAPTURE 0x08
129 unsigned short hardware
;
130 unsigned char password
;
133 unsigned long mc_base
;
134 struct resource
*res_mc_base
;
135 unsigned long mc_base_size
;
137 unsigned long mc_indir_index
;
138 unsigned long mc_indir_size
;
139 struct resource
*res_mc_indir
;
140 struct snd_wss
*codec
;
142 unsigned long pwd_reg
;
150 static int snd_opti9xx_pnp_is_probed
;
154 static struct pnp_card_device_id snd_opti9xx_pnpids
[] = {
158 .devs
= { { "OPT0000" }, { "OPT0002" }, { "OPT0005" } },
159 .driver_data
= 0x0924 },
162 .devs
= { { "OPT9250" }, { "OPT0002" }, { "OPT0005" } },
163 .driver_data
= 0x0925 },
166 { .id
= "OPT0931", .devs
= { { "OPT9310" }, { "OPT0002" } },
167 .driver_data
= 0x0931 },
172 MODULE_DEVICE_TABLE(pnp_card
, snd_opti9xx_pnpids
);
174 #endif /* CONFIG_PNP */
177 #define DEV_NAME "opti93x"
179 #define DEV_NAME "opti92x"
182 static char * snd_opti9xx_names
[] = {
186 "82C930", "82C931", "82C933"
190 static long __devinit
snd_legacy_find_free_ioport(long *port_table
, long size
)
192 while (*port_table
!= -1) {
193 if (request_region(*port_table
, size
, "ALSA test")) {
194 release_region(*port_table
, size
);
202 static int __devinit
snd_opti9xx_init(struct snd_opti9xx
*chip
,
203 unsigned short hardware
)
205 static int opti9xx_mc_size
[] = {7, 7, 10, 10, 2, 2, 2};
207 chip
->hardware
= hardware
;
208 strcpy(chip
->name
, snd_opti9xx_names
[hardware
]);
210 spin_lock_init(&chip
->lock
);
216 if (isapnp
&& chip
->mc_base
)
217 /* PnP resource gives the least 10 bits */
218 chip
->mc_base
|= 0xc00;
220 #endif /* CONFIG_PNP */
222 chip
->mc_base
= 0xf8c;
223 chip
->mc_base_size
= opti9xx_mc_size
[hardware
];
226 chip
->mc_base_size
= opti9xx_mc_size
[hardware
];
231 case OPTi9XX_HW_82C928
:
232 case OPTi9XX_HW_82C929
:
233 chip
->password
= (hardware
== OPTi9XX_HW_82C928
) ? 0xe2 : 0xe3;
237 case OPTi9XX_HW_82C924
:
238 case OPTi9XX_HW_82C925
:
239 chip
->password
= 0xe5;
244 case OPTi9XX_HW_82C930
:
245 case OPTi9XX_HW_82C931
:
246 case OPTi9XX_HW_82C933
:
247 chip
->mc_base
= (hardware
== OPTi9XX_HW_82C930
) ? 0xf8f : 0xf8d;
248 if (!chip
->mc_indir_index
) {
249 chip
->mc_indir_index
= 0xe0e;
250 chip
->mc_indir_size
= 2;
252 chip
->password
= 0xe4;
258 snd_printk(KERN_ERR
"chip %d not supported\n", hardware
);
264 static unsigned char snd_opti9xx_read(struct snd_opti9xx
*chip
,
268 unsigned char retval
= 0xff;
270 spin_lock_irqsave(&chip
->lock
, flags
);
271 outb(chip
->password
, chip
->mc_base
+ chip
->pwd_reg
);
273 switch (chip
->hardware
) {
275 case OPTi9XX_HW_82C924
:
276 case OPTi9XX_HW_82C925
:
278 outb(reg
, chip
->mc_base
+ 8);
279 outb(chip
->password
, chip
->mc_base
+ chip
->pwd_reg
);
280 retval
= inb(chip
->mc_base
+ 9);
284 case OPTi9XX_HW_82C928
:
285 case OPTi9XX_HW_82C929
:
286 retval
= inb(chip
->mc_base
+ reg
);
290 case OPTi9XX_HW_82C930
:
291 case OPTi9XX_HW_82C931
:
292 case OPTi9XX_HW_82C933
:
293 outb(reg
, chip
->mc_indir_index
);
294 outb(chip
->password
, chip
->mc_base
+ chip
->pwd_reg
);
295 retval
= inb(chip
->mc_indir_index
+ 1);
300 snd_printk(KERN_ERR
"chip %d not supported\n", chip
->hardware
);
303 spin_unlock_irqrestore(&chip
->lock
, flags
);
307 static void snd_opti9xx_write(struct snd_opti9xx
*chip
, unsigned char reg
,
312 spin_lock_irqsave(&chip
->lock
, flags
);
313 outb(chip
->password
, chip
->mc_base
+ chip
->pwd_reg
);
315 switch (chip
->hardware
) {
317 case OPTi9XX_HW_82C924
:
318 case OPTi9XX_HW_82C925
:
320 outb(reg
, chip
->mc_base
+ 8);
321 outb(chip
->password
, chip
->mc_base
+ chip
->pwd_reg
);
322 outb(value
, chip
->mc_base
+ 9);
326 case OPTi9XX_HW_82C928
:
327 case OPTi9XX_HW_82C929
:
328 outb(value
, chip
->mc_base
+ reg
);
332 case OPTi9XX_HW_82C930
:
333 case OPTi9XX_HW_82C931
:
334 case OPTi9XX_HW_82C933
:
335 outb(reg
, chip
->mc_indir_index
);
336 outb(chip
->password
, chip
->mc_base
+ chip
->pwd_reg
);
337 outb(value
, chip
->mc_indir_index
+ 1);
342 snd_printk(KERN_ERR
"chip %d not supported\n", chip
->hardware
);
345 spin_unlock_irqrestore(&chip
->lock
, flags
);
349 #define snd_opti9xx_write_mask(chip, reg, value, mask) \
350 snd_opti9xx_write(chip, reg, \
351 (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
354 static int __devinit
snd_opti9xx_configure(struct snd_opti9xx
*chip
,
356 int irq
, int dma1
, int dma2
,
357 long mpu_port
, int mpu_irq
)
359 unsigned char wss_base_bits
;
360 unsigned char irq_bits
;
361 unsigned char dma_bits
;
362 unsigned char mpu_port_bits
= 0;
363 unsigned char mpu_irq_bits
;
365 switch (chip
->hardware
) {
367 case OPTi9XX_HW_82C924
:
368 /* opti 929 mode (?), OPL3 clock output, audio enable */
369 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
370 /* enable wave audio */
371 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(6), 0x02, 0x02);
373 case OPTi9XX_HW_82C925
:
374 /* enable WSS mode */
375 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(1), 0x80, 0x80);
376 /* OPL3 FM synthesis */
377 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(2), 0x00, 0x20);
378 /* disable Sound Blaster IRQ and DMA */
379 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(3), 0xf0, 0xff);
381 /* cs4231/4248 fix enabled */
382 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(5), 0x02, 0x02);
384 /* cs4231/4248 fix disabled */
385 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(5), 0x00, 0x02);
389 case OPTi9XX_HW_82C928
:
390 case OPTi9XX_HW_82C929
:
391 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(1), 0x80, 0x80);
392 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(2), 0x00, 0x20);
394 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
396 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(4), 0x00, 0x0c);
398 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(5), 0x02, 0x02);
400 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(5), 0x00, 0x02);
405 case OPTi9XX_HW_82C931
:
406 case OPTi9XX_HW_82C933
:
408 * The BTC 1817DW has QS1000 wavetable which is connected
409 * to the serial digital input of the OPTI931.
411 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(21), 0x82, 0xff);
413 * This bit sets OPTI931 to automaticaly select FM
414 * or digital input signal.
416 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(26), 0x01, 0x01);
417 case OPTi9XX_HW_82C930
: /* FALL THROUGH */
418 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(6), 0x02, 0x03);
419 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(3), 0x00, 0xff);
420 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(4), 0x10 |
421 (chip
->hardware
== OPTi9XX_HW_82C930
? 0x00 : 0x04),
423 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(5), 0x20, 0xbf);
428 snd_printk(KERN_ERR
"chip %d not supported\n", chip
->hardware
);
432 /* PnP resource says it decodes only 10 bits of address */
433 switch (port
& 0x3ff) {
435 chip
->wss_base
= 0x530;
436 wss_base_bits
= 0x00;
439 chip
->wss_base
= 0x604;
440 wss_base_bits
= 0x03;
443 chip
->wss_base
= 0xe80;
444 wss_base_bits
= 0x01;
447 chip
->wss_base
= 0xf40;
448 wss_base_bits
= 0x02;
451 snd_printk(KERN_WARNING
"WSS port 0x%lx not valid\n", port
);
454 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(1), wss_base_bits
<< 4, 0x30);
462 //#endif /* OPTi93X */
476 snd_printk(KERN_WARNING
"WSS irq # %d not valid\n", irq
);
477 goto __skip_resources
;
491 snd_printk(KERN_WARNING
"WSS dma1 # %d not valid\n", dma1
);
492 goto __skip_resources
;
495 #if defined(CS4231) || defined(OPTi93X)
497 snd_printk(KERN_ERR
"don't want to share dmas\n");
506 snd_printk(KERN_WARNING
"WSS dma2 # %d not valid\n", dma2
);
507 goto __skip_resources
;
510 #endif /* CS4231 || OPTi93X */
513 outb(irq_bits
<< 3 | dma_bits
, chip
->wss_base
);
515 snd_opti9xx_write(chip
, OPTi9XX_MC_REG(3), (irq_bits
<< 3 | dma_bits
));
519 if (chip
->hardware
> OPTi9XX_HW_82C928
) {
525 mpu_port_bits
= 0x03;
528 mpu_port_bits
= 0x02;
531 mpu_port_bits
= 0x01;
534 mpu_port_bits
= 0x00;
537 snd_printk(KERN_WARNING
538 "MPU-401 port 0x%lx not valid\n", mpu_port
);
556 snd_printk(KERN_WARNING
"MPU-401 irq # %d not valid\n",
561 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(6),
562 (mpu_port
<= 0) ? 0x00 :
563 0x80 | mpu_port_bits
<< 5 | mpu_irq_bits
<< 3,
573 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step
, -9300, 300, 0);
574 static const DECLARE_TLV_DB_SCALE(db_scale_5bit
, -4650, 150, 0);
575 static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max
, -3300, 300, 0);
577 static struct snd_kcontrol_new snd_opti93x_controls
[] = {
578 WSS_DOUBLE("Master Playback Switch", 0,
579 OPTi93X_OUT_LEFT
, OPTi93X_OUT_RIGHT
, 7, 7, 1, 1),
580 WSS_DOUBLE_TLV("Master Playback Volume", 0,
581 OPTi93X_OUT_LEFT
, OPTi93X_OUT_RIGHT
, 1, 1, 31, 1,
582 db_scale_5bit_3db_step
),
583 WSS_DOUBLE_TLV("PCM Playback Volume", 0,
584 CS4231_LEFT_OUTPUT
, CS4231_RIGHT_OUTPUT
, 0, 0, 31, 1,
586 WSS_DOUBLE_TLV("FM Playback Volume", 0,
587 CS4231_AUX2_LEFT_INPUT
, CS4231_AUX2_RIGHT_INPUT
, 1, 1, 15, 1,
588 db_scale_4bit_12db_max
),
589 WSS_DOUBLE("Line Playback Switch", 0,
590 CS4231_LEFT_LINE_IN
, CS4231_RIGHT_LINE_IN
, 7, 7, 1, 1),
591 WSS_DOUBLE_TLV("Line Playback Volume", 0,
592 CS4231_LEFT_LINE_IN
, CS4231_RIGHT_LINE_IN
, 0, 0, 15, 1,
593 db_scale_4bit_12db_max
),
594 WSS_DOUBLE("Mic Playback Switch", 0,
595 OPTi93X_MIC_LEFT_INPUT
, OPTi93X_MIC_RIGHT_INPUT
, 7, 7, 1, 1),
596 WSS_DOUBLE_TLV("Mic Playback Volume", 0,
597 OPTi93X_MIC_LEFT_INPUT
, OPTi93X_MIC_RIGHT_INPUT
, 1, 1, 15, 1,
598 db_scale_4bit_12db_max
),
599 WSS_DOUBLE_TLV("CD Playback Volume", 0,
600 CS4231_AUX1_LEFT_INPUT
, CS4231_AUX1_RIGHT_INPUT
, 1, 1, 15, 1,
601 db_scale_4bit_12db_max
),
602 WSS_DOUBLE("Aux Playback Switch", 0,
603 OPTi931_AUX_LEFT_INPUT
, OPTi931_AUX_RIGHT_INPUT
, 7, 7, 1, 1),
604 WSS_DOUBLE_TLV("Aux Playback Volume", 0,
605 OPTi931_AUX_LEFT_INPUT
, OPTi931_AUX_RIGHT_INPUT
, 1, 1, 15, 1,
606 db_scale_4bit_12db_max
),
609 static int __devinit
snd_opti93x_mixer(struct snd_wss
*chip
)
611 struct snd_card
*card
;
613 struct snd_ctl_elem_id id1
, id2
;
616 if (snd_BUG_ON(!chip
|| !chip
->pcm
))
621 strcpy(card
->mixername
, chip
->pcm
->name
);
623 memset(&id1
, 0, sizeof(id1
));
624 memset(&id2
, 0, sizeof(id2
));
625 id1
.iface
= id2
.iface
= SNDRV_CTL_ELEM_IFACE_MIXER
;
626 /* reassign AUX0 switch to CD */
627 strcpy(id1
.name
, "Aux Playback Switch");
628 strcpy(id2
.name
, "CD Playback Switch");
629 err
= snd_ctl_rename_id(card
, &id1
, &id2
);
631 snd_printk(KERN_ERR
"Cannot rename opti93x control\n");
634 /* reassign AUX1 switch to FM */
635 strcpy(id1
.name
, "Aux Playback Switch"); id1
.index
= 1;
636 strcpy(id2
.name
, "FM Playback Switch");
637 err
= snd_ctl_rename_id(card
, &id1
, &id2
);
639 snd_printk(KERN_ERR
"Cannot rename opti93x control\n");
642 /* remove AUX1 volume */
643 strcpy(id1
.name
, "Aux Playback Volume"); id1
.index
= 1;
644 snd_ctl_remove_id(card
, &id1
);
646 /* Replace WSS volume controls with OPTi93x volume controls */
648 for (idx
= 0; idx
< ARRAY_SIZE(snd_opti93x_controls
); idx
++) {
649 strcpy(id1
.name
, snd_opti93x_controls
[idx
].name
);
650 snd_ctl_remove_id(card
, &id1
);
652 err
= snd_ctl_add(card
,
653 snd_ctl_new1(&snd_opti93x_controls
[idx
], chip
));
660 static irqreturn_t
snd_opti93x_interrupt(int irq
, void *dev_id
)
662 struct snd_opti9xx
*chip
= dev_id
;
663 struct snd_wss
*codec
= chip
->codec
;
664 unsigned char status
;
669 status
= snd_opti9xx_read(chip
, OPTi9XX_MC_REG(11));
670 if ((status
& OPTi93X_IRQ_PLAYBACK
) && codec
->playback_substream
)
671 snd_pcm_period_elapsed(codec
->playback_substream
);
672 if ((status
& OPTi93X_IRQ_CAPTURE
) && codec
->capture_substream
) {
673 snd_wss_overrange(codec
);
674 snd_pcm_period_elapsed(codec
->capture_substream
);
676 outb(0x00, OPTi93X_PORT(codec
, STATUS
));
682 static int __devinit
snd_opti9xx_read_check(struct snd_opti9xx
*chip
)
689 chip
->res_mc_base
= request_region(chip
->mc_base
, chip
->mc_base_size
,
691 if (chip
->res_mc_base
== NULL
)
694 value
= snd_opti9xx_read(chip
, OPTi9XX_MC_REG(1));
695 if (value
!= 0xff && value
!= inb(chip
->mc_base
+ OPTi9XX_MC_REG(1)))
696 if (value
== snd_opti9xx_read(chip
, OPTi9XX_MC_REG(1)))
699 chip
->res_mc_indir
= request_region(chip
->mc_indir_index
,
702 if (chip
->res_mc_indir
== NULL
)
705 spin_lock_irqsave(&chip
->lock
, flags
);
706 outb(chip
->password
, chip
->mc_base
+ chip
->pwd_reg
);
707 outb(((chip
->mc_indir_index
& 0x1f0) >> 4), chip
->mc_base
);
708 spin_unlock_irqrestore(&chip
->lock
, flags
);
710 value
= snd_opti9xx_read(chip
, OPTi9XX_MC_REG(7));
711 snd_opti9xx_write(chip
, OPTi9XX_MC_REG(7), 0xff - value
);
712 if (snd_opti9xx_read(chip
, OPTi9XX_MC_REG(7)) == 0xff - value
)
715 release_and_free_resource(chip
->res_mc_indir
);
716 chip
->res_mc_indir
= NULL
;
718 release_and_free_resource(chip
->res_mc_base
);
719 chip
->res_mc_base
= NULL
;
724 static int __devinit
snd_card_opti9xx_detect(struct snd_card
*card
,
725 struct snd_opti9xx
*chip
)
730 for (i
= OPTi9XX_HW_82C928
; i
< OPTi9XX_HW_82C930
; i
++) {
732 for (i
= OPTi9XX_HW_82C931
; i
>= OPTi9XX_HW_82C930
; i
--) {
734 err
= snd_opti9xx_init(chip
, i
);
738 err
= snd_opti9xx_read_check(chip
);
742 chip
->mc_indir_index
= 0;
749 static int __devinit
snd_card_opti9xx_pnp(struct snd_opti9xx
*chip
,
750 struct pnp_card_link
*card
,
751 const struct pnp_card_device_id
*pid
)
753 struct pnp_dev
*pdev
;
755 struct pnp_dev
*devmpu
;
757 struct pnp_dev
*devmc
;
760 pdev
= pnp_request_card_device(card
, pid
->devs
[0].id
, NULL
);
764 err
= pnp_activate_dev(pdev
);
766 snd_printk(KERN_ERR
"AUDIO pnp configure failure: %d\n", err
);
771 port
= pnp_port_start(pdev
, 0) - 4;
772 fm_port
= pnp_port_start(pdev
, 1) + 8;
773 chip
->mc_indir_index
= pnp_port_start(pdev
, 3) + 2;
774 chip
->mc_indir_size
= pnp_port_len(pdev
, 3) - 2;
776 devmc
= pnp_request_card_device(card
, pid
->devs
[2].id
, NULL
);
780 err
= pnp_activate_dev(devmc
);
782 snd_printk(KERN_ERR
"MC pnp configure failure: %d\n", err
);
786 port
= pnp_port_start(pdev
, 1);
787 fm_port
= pnp_port_start(pdev
, 2) + 8;
789 * The MC(0) is never accessed and card does not
790 * include it in the PnP resource range. OPTI93x include it.
792 chip
->mc_base
= pnp_port_start(devmc
, 0) - 1;
793 chip
->mc_base_size
= pnp_port_len(devmc
, 0) + 1;
795 irq
= pnp_irq(pdev
, 0);
796 dma1
= pnp_dma(pdev
, 0);
797 #if defined(CS4231) || defined(OPTi93X)
798 dma2
= pnp_dma(pdev
, 1);
799 #endif /* CS4231 || OPTi93X */
801 devmpu
= pnp_request_card_device(card
, pid
->devs
[1].id
, NULL
);
803 if (devmpu
&& mpu_port
> 0) {
804 err
= pnp_activate_dev(devmpu
);
806 snd_printk(KERN_ERR
"MPU401 pnp configure failure\n");
809 mpu_port
= pnp_port_start(devmpu
, 0);
810 mpu_irq
= pnp_irq(devmpu
, 0);
813 return pid
->driver_data
;
815 #endif /* CONFIG_PNP */
817 static void snd_card_opti9xx_free(struct snd_card
*card
)
819 struct snd_opti9xx
*chip
= card
->private_data
;
824 disable_irq(chip
->irq
);
825 free_irq(chip
->irq
, chip
);
827 release_and_free_resource(chip
->res_mc_indir
);
829 release_and_free_resource(chip
->res_mc_base
);
833 static int __devinit
snd_opti9xx_probe(struct snd_card
*card
)
835 static long possible_ports
[] = {0x530, 0xe80, 0xf40, 0x604, -1};
838 struct snd_opti9xx
*chip
= card
->private_data
;
839 struct snd_wss
*codec
;
841 struct snd_timer
*timer
;
844 struct snd_rawmidi
*rmidi
;
845 struct snd_hwdep
*synth
;
847 #if defined(CS4231) || defined(OPTi93X)
853 if (port
== SNDRV_AUTO_PORT
) {
854 port
= snd_legacy_find_free_ioport(possible_ports
, 4);
856 snd_printk(KERN_ERR
"unable to find a free WSS port\n");
860 error
= snd_opti9xx_configure(chip
, port
, irq
, dma1
, xdma2
,
865 error
= snd_wss_create(card
, chip
->wss_base
+ 4, -1, irq
, dma1
, xdma2
,
867 WSS_HW_OPTI93X
, WSS_HWSHARE_IRQ
,
877 error
= snd_wss_pcm(codec
, 0, &pcm
);
880 error
= snd_wss_mixer(codec
);
884 error
= snd_opti93x_mixer(codec
);
889 error
= snd_wss_timer(codec
, 0, &timer
);
894 error
= request_irq(irq
, snd_opti93x_interrupt
,
895 0, DEV_NAME
" - WSS", chip
);
897 snd_printk(KERN_ERR
"opti9xx: can't grab IRQ %d\n", irq
);
902 strcpy(card
->driver
, chip
->name
);
903 sprintf(card
->shortname
, "OPTi %s", card
->driver
);
904 #if defined(CS4231) || defined(OPTi93X)
905 sprintf(card
->longname
, "%s, %s at 0x%lx, irq %d, dma %d&%d",
906 card
->shortname
, pcm
->name
,
907 chip
->wss_base
+ 4, irq
, dma1
, xdma2
);
909 sprintf(card
->longname
, "%s, %s at 0x%lx, irq %d, dma %d",
910 card
->shortname
, pcm
->name
, chip
->wss_base
+ 4, irq
, dma1
);
911 #endif /* CS4231 || OPTi93X */
913 if (mpu_port
<= 0 || mpu_port
== SNDRV_AUTO_PORT
)
916 error
= snd_mpu401_uart_new(card
, 0, MPU401_HW_MPU401
,
917 mpu_port
, 0, mpu_irq
, &rmidi
);
919 snd_printk(KERN_WARNING
"no MPU-401 device at 0x%lx?\n",
923 if (fm_port
> 0 && fm_port
!= SNDRV_AUTO_PORT
) {
924 struct snd_opl3
*opl3
= NULL
;
926 if (chip
->hardware
== OPTi9XX_HW_82C928
||
927 chip
->hardware
== OPTi9XX_HW_82C929
||
928 chip
->hardware
== OPTi9XX_HW_82C924
) {
929 struct snd_opl4
*opl4
;
930 /* assume we have an OPL4 */
931 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(2),
933 if (snd_opl4_create(card
, fm_port
, fm_port
- 8,
934 2, &opl3
, &opl4
) < 0) {
935 /* no luck, use OPL3 instead */
936 snd_opti9xx_write_mask(chip
, OPTi9XX_MC_REG(2),
940 #endif /* !OPTi93X */
941 if (!opl3
&& snd_opl3_create(card
, fm_port
, fm_port
+ 2,
942 OPL3_HW_AUTO
, 0, &opl3
) < 0) {
943 snd_printk(KERN_WARNING
"no OPL device at 0x%lx-0x%lx\n",
944 fm_port
, fm_port
+ 4 - 1);
947 error
= snd_opl3_hwdep_new(opl3
, 0, 1, &synth
);
953 return snd_card_register(card
);
956 static int snd_opti9xx_card_new(struct snd_card
**cardp
)
958 struct snd_card
*card
;
961 err
= snd_card_create(index
, id
, THIS_MODULE
,
962 sizeof(struct snd_opti9xx
), &card
);
965 card
->private_free
= snd_card_opti9xx_free
;
970 static int __devinit
snd_opti9xx_isa_match(struct device
*devptr
,
974 if (snd_opti9xx_pnp_is_probed
)
982 static int __devinit
snd_opti9xx_isa_probe(struct device
*devptr
,
985 struct snd_card
*card
;
987 static long possible_mpu_ports
[] = {0x300, 0x310, 0x320, 0x330, -1};
989 static int possible_irqs
[] = {5, 9, 10, 11, 7, -1};
991 static int possible_irqs
[] = {9, 10, 11, 7, -1};
993 static int possible_mpu_irqs
[] = {5, 9, 10, 7, -1};
994 static int possible_dma1s
[] = {3, 1, 0, -1};
995 #if defined(CS4231) || defined(OPTi93X)
996 static int possible_dma2s
[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
997 #endif /* CS4231 || OPTi93X */
999 if (mpu_port
== SNDRV_AUTO_PORT
) {
1000 if ((mpu_port
= snd_legacy_find_free_ioport(possible_mpu_ports
, 2)) < 0) {
1001 snd_printk(KERN_ERR
"unable to find a free MPU401 port\n");
1005 if (irq
== SNDRV_AUTO_IRQ
) {
1006 if ((irq
= snd_legacy_find_free_irq(possible_irqs
)) < 0) {
1007 snd_printk(KERN_ERR
"unable to find a free IRQ\n");
1011 if (mpu_irq
== SNDRV_AUTO_IRQ
) {
1012 if ((mpu_irq
= snd_legacy_find_free_irq(possible_mpu_irqs
)) < 0) {
1013 snd_printk(KERN_ERR
"unable to find a free MPU401 IRQ\n");
1017 if (dma1
== SNDRV_AUTO_DMA
) {
1018 if ((dma1
= snd_legacy_find_free_dma(possible_dma1s
)) < 0) {
1019 snd_printk(KERN_ERR
"unable to find a free DMA1\n");
1023 #if defined(CS4231) || defined(OPTi93X)
1024 if (dma2
== SNDRV_AUTO_DMA
) {
1025 if ((dma2
= snd_legacy_find_free_dma(possible_dma2s
[dma1
% 4])) < 0) {
1026 snd_printk(KERN_ERR
"unable to find a free DMA2\n");
1032 error
= snd_opti9xx_card_new(&card
);
1036 if ((error
= snd_card_opti9xx_detect(card
, card
->private_data
)) < 0) {
1037 snd_card_free(card
);
1040 snd_card_set_dev(card
, devptr
);
1041 if ((error
= snd_opti9xx_probe(card
)) < 0) {
1042 snd_card_free(card
);
1045 dev_set_drvdata(devptr
, card
);
1049 static int __devexit
snd_opti9xx_isa_remove(struct device
*devptr
,
1052 snd_card_free(dev_get_drvdata(devptr
));
1053 dev_set_drvdata(devptr
, NULL
);
1057 static struct isa_driver snd_opti9xx_driver
= {
1058 .match
= snd_opti9xx_isa_match
,
1059 .probe
= snd_opti9xx_isa_probe
,
1060 .remove
= __devexit_p(snd_opti9xx_isa_remove
),
1061 /* FIXME: suspend/resume */
1068 static int __devinit
snd_opti9xx_pnp_probe(struct pnp_card_link
*pcard
,
1069 const struct pnp_card_device_id
*pid
)
1071 struct snd_card
*card
;
1073 struct snd_opti9xx
*chip
;
1075 if (snd_opti9xx_pnp_is_probed
)
1079 error
= snd_opti9xx_card_new(&card
);
1082 chip
= card
->private_data
;
1084 hw
= snd_card_opti9xx_pnp(chip
, pcard
, pid
);
1087 hw
= OPTi9XX_HW_82C924
;
1090 hw
= OPTi9XX_HW_82C925
;
1093 hw
= OPTi9XX_HW_82C931
;
1096 snd_card_free(card
);
1100 if ((error
= snd_opti9xx_init(chip
, hw
))) {
1101 snd_card_free(card
);
1104 error
= snd_opti9xx_read_check(chip
);
1106 snd_printk(KERN_ERR
"OPTI chip not found\n");
1107 snd_card_free(card
);
1110 snd_card_set_dev(card
, &pcard
->card
->dev
);
1111 if ((error
= snd_opti9xx_probe(card
)) < 0) {
1112 snd_card_free(card
);
1115 pnp_set_card_drvdata(pcard
, card
);
1116 snd_opti9xx_pnp_is_probed
= 1;
1120 static void __devexit
snd_opti9xx_pnp_remove(struct pnp_card_link
* pcard
)
1122 snd_card_free(pnp_get_card_drvdata(pcard
));
1123 pnp_set_card_drvdata(pcard
, NULL
);
1124 snd_opti9xx_pnp_is_probed
= 0;
1127 static struct pnp_card_driver opti9xx_pnpc_driver
= {
1128 .flags
= PNP_DRIVER_RES_DISABLE
,
1130 .id_table
= snd_opti9xx_pnpids
,
1131 .probe
= snd_opti9xx_pnp_probe
,
1132 .remove
= __devexit_p(snd_opti9xx_pnp_remove
),
1137 #define CHIP_NAME "82C93x"
1139 #define CHIP_NAME "82C92x"
1142 static int __init
alsa_card_opti9xx_init(void)
1145 pnp_register_card_driver(&opti9xx_pnpc_driver
);
1146 if (snd_opti9xx_pnp_is_probed
)
1148 pnp_unregister_card_driver(&opti9xx_pnpc_driver
);
1150 return isa_register_driver(&snd_opti9xx_driver
, 1);
1153 static void __exit
alsa_card_opti9xx_exit(void)
1155 if (!snd_opti9xx_pnp_is_probed
) {
1156 isa_unregister_driver(&snd_opti9xx_driver
);
1160 pnp_unregister_card_driver(&opti9xx_pnpc_driver
);
1164 module_init(alsa_card_opti9xx_init
)
1165 module_exit(alsa_card_opti9xx_exit
)