2 * Support for VIA 82Cxxx Audio Codecs
3 * Copyright 1999 Jeff Garzik <jgarzik@pobox.com>
5 * Distributed under the GNU GENERAL PUBLIC LICENSE (GPL) Version 2.
6 * See the "COPYING" file distributed with this software for more info.
8 ********************************************************************
12 * - Integrate AC'97 support, when AC'97 interface released
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/errno.h>
20 #include <linux/kernel.h>
21 #include <linux/pci.h>
22 #include <linux/init.h>
26 #include "sound_config.h"
27 #include "soundmodule.h"
31 #define SOUND_LOCK do {} while (0)
32 #define SOUND_LOCK_END do {} while (0)
37 #define PFX "via82cxxx: "
39 #define VIA_VERSION "1.0.0"
40 #define VIA_CARD_NAME "VIA 82Cxxx Audio driver " VIA_VERSION
42 #define VIA_FUNC_ENABLE 0x42
43 #define VIA_PNP_CONTROL 0x43
45 #define VIA_CR42_SB_ENABLE 0x01
46 #define VIA_CR42_MIDI_ENABLE 0x02
47 #define VIA_CR42_FM_ENABLE 0x04
49 #define via_probe_midi probe_uart401
50 #define via_attach_midi attach_uart401
51 #define via_unload_midi unload_uart401
53 static struct address_info sb_data
[MAX_CARDS
];
54 static struct address_info opl3_data
[MAX_CARDS
];
55 static unsigned cards
= 0;
58 static void __init
via_attach_sb(struct address_info
*hw_config
)
60 if(!sb_dsp_init(hw_config
))
61 hw_config
->slots
[0] = -1;
65 static int __init
via_probe_sb(struct address_info
*hw_config
)
67 if (check_region(hw_config
->io_base
, 16))
69 printk(KERN_DEBUG PFX
"SBPro port 0x%x is already in use\n",
73 return sb_dsp_detect(hw_config
, 0, 0);
77 static void __exit
via_unload_sb(struct address_info
*hw_config
, int unload_mpu
)
79 if(hw_config
->slots
[0]!=-1)
80 sb_dsp_unload(hw_config
, unload_mpu
);
84 static int __init
via82cxxx_install (struct pci_dev
*pcidev
)
92 memset (&sb_data
[cards
], 0, sizeof (struct address_info
));
93 memset (&opl3_data
[cards
], 0, sizeof (struct address_info
));
95 sb_data
[cards
].name
= opl3_data
[cards
].name
= VIA_CARD_NAME
;
96 opl3_data
[cards
].irq
= -1;
98 /* turn on features, if not already */
99 pci_read_config_byte (pcidev
, VIA_FUNC_ENABLE
, &tmp8
);
100 tmp8
|= VIA_CR42_SB_ENABLE
| VIA_CR42_MIDI_ENABLE
|
102 pci_write_config_byte (pcidev
, VIA_FUNC_ENABLE
, tmp8
);
104 /* read legacy PNP info byte */
105 pci_read_config_byte (pcidev
, VIA_PNP_CONTROL
, &tmp8
);
106 pci_write_config_byte (pcidev
, VIA_PNP_CONTROL
, tmp8
);
108 switch ((tmp8
>> 6) & 0x03) {
109 case 0: sb_irq
= 5; break;
110 case 1: sb_irq
= 7; break;
111 case 2: sb_irq
= 9; break;
112 case 3: sb_irq
= 10; break;
113 default: /* do nothing */ break;
115 switch ((tmp8
>> 4) & 0x03) {
116 case 0: sb_dma
= 0; break;
117 case 1: sb_dma
= 1; break;
118 case 2: sb_dma
= 2; break;
119 case 3: sb_dma
= 3; break;
120 default: /* do nothing */ break;
122 switch ((tmp8
>> 2) & 0x03) {
123 case 0: midi_base
= 0x300; break;
124 case 1: midi_base
= 0x310; break;
125 case 2: midi_base
= 0x320; break;
126 case 3: midi_base
= 0x330; break;
127 default: /* do nothing */ break;
129 switch (tmp8
& 0x03) {
130 case 0: sb_io_base
= 0x220; break;
131 case 1: sb_io_base
= 0x240; break;
132 case 2: sb_io_base
= 0x260; break;
133 case 3: sb_io_base
= 0x280; break;
134 default: /* do nothing */ break;
139 printk(KERN_INFO PFX
"legacy "
140 "MIDI: 0x%X, SB: 0x%X / %d IRQ / %d DMA\n",
141 midi_base
, sb_io_base
, sb_irq
, sb_dma
);
143 sb_data
[cards
].card_subtype
= MDL_SBPRO
;
144 sb_data
[cards
].io_base
= sb_io_base
;
145 sb_data
[cards
].irq
= sb_irq
;
146 sb_data
[cards
].dma
= sb_dma
;
148 opl3_data
[cards
].io_base
= midi_base
;
150 /* register legacy SoundBlaster Pro */
151 if (!via_probe_sb (&sb_data
[cards
])) {
153 "SB probe @ 0x%X failed, aborting\n",
157 via_attach_sb (&sb_data
[cards
]);
159 /* register legacy MIDI */
160 if (!via_probe_midi (&opl3_data
[cards
])) {
162 "MIDI probe @ 0x%X failed, aborting\n",
164 via_unload_sb (&sb_data
[cards
], 0);
167 via_attach_midi (&opl3_data
[cards
]);
175 * This loop walks the PCI configuration database and finds where
176 * the sound cards are.
179 static int __init
probe_via82cxxx (void)
181 struct pci_dev
*pcidev
= NULL
;
183 while ((pcidev
= pci_find_device (PCI_VENDOR_ID_VIA
,
184 PCI_DEVICE_ID_VIA_82C686_5
,
187 if (via82cxxx_install (pcidev
) != 0) {
188 printk (KERN_ERR PFX
"audio init failed\n");
192 if (cards
== MAX_CARDS
) {
193 printk (KERN_DEBUG PFX
"maximum number of cards reached\n");
203 * This function is called when the user or kernel loads the
204 * module into memory.
208 static int __init
init_via82cxxx_module(void)
210 if (!pci_present ()) {
211 printk (KERN_DEBUG PFX
"PCI not present, exiting\n");
215 if (probe_via82cxxx() != 0) {
216 printk(KERN_ERR PFX
"probe failed, aborting\n");
217 /* XXX unload cards registered so far, if any */
222 printk(KERN_DEBUG PFX
"No chips found, aborting\n");
226 printk (KERN_INFO PFX VIA_CARD_NAME
" loaded\n");
229 * Binds us to the sound subsystem
236 * This is called when it is removed. It will only be removed
237 * when its use count is 0. For sound the SOUND_LOCK/SOUND_UNLOCK
238 * macros hide the entire work for this.
241 static void __exit
cleanup_via82cxxx_module(void)
245 for (i
= 0; i
< cards
; i
++)
246 via_unload_sb (&sb_data
[i
], 1);
249 * Final clean up with the sound layer
254 module_init(init_via82cxxx_module
);
255 module_exit(cleanup_via82cxxx_module
);