2 * Driver for C-Media's CMI8330 soundcards.
3 * Copyright (c) by George Talusan <gstalusan@uwaterloo.ca>
4 * http://www.undergrad.math.uwaterloo.ca/~gstalusa
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * The extended registers contain mixer settings which are largely
26 * untapped for the time being.
28 * MPU401 and SPDIF are not supported yet. I don't have the hardware
29 * to aid in coding and testing, so I won't bother.
31 * To quickly load the module,
33 * modprobe -a snd-cmi8330 sbport=0x220 sbirq=5 sbdma8=1
34 * sbdma16=5 wssport=0x530 wssirq=11 wssdma=0
36 * This card has two mixers and two PCM devices. I've cheesed it such
37 * that recording and playback can be done through the same device.
38 * The driver "magically" routes the capturing to the AD1848 codec,
39 * and playback to the SB16 codec. This allows for full-duplex mode
41 * The utilities in alsa-utils are aware of both devices, so passing
42 * the appropriate parameters to amixer and alsactl will give you
43 * full control over both mixers.
46 #include <sound/driver.h>
47 #include <linux/init.h>
48 #include <linux/slab.h>
49 #include <linux/pnp.h>
50 #include <linux/moduleparam.h>
51 #include <sound/core.h>
52 #include <sound/ad1848.h>
54 #include <sound/initval.h>
58 /* #define ENABLE_SB_MIXER */
59 #define PLAYBACK_ON_SB
63 MODULE_AUTHOR("George Talusan <gstalusan@uwaterloo.ca>");
64 MODULE_DESCRIPTION("C-Media CMI8330");
65 MODULE_LICENSE("GPL");
66 MODULE_CLASSES("{sound}");
67 MODULE_DEVICES("{{C-Media,CMI8330,isapnp:{CMI0001,@@@0001,@X@0001}}}");
69 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
70 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
71 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
73 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
75 static long sbport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
76 static int sbirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
77 static int sbdma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
78 static int sbdma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
79 static long wssport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
80 static int wssirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
81 static int wssdma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
84 module_param_array(index, int, boot_devs, 0444);
85 MODULE_PARM_DESC(index, "Index value for CMI8330 soundcard.");
86 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
87 module_param_array(id, charp, boot_devs, 0444);
88 MODULE_PARM_DESC(id, "ID string for CMI8330 soundcard.");
89 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
90 module_param_array(enable, bool, boot_devs, 0444);
91 MODULE_PARM_DESC(enable, "Enable CMI8330 soundcard.");
92 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
94 module_param_array(isapnp, bool, boot_devs, 0444);
95 MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
96 MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
99 module_param_array(sbport, long, boot_devs, 0444);
100 MODULE_PARM_DESC(sbport, "Port # for CMI8330 SB driver.");
101 MODULE_PARM_SYNTAX(sbport, SNDRV_ENABLED ",allows:{{0x220,0x280,0x20}},prefers:{0x220},base:16,dialog:list");
102 module_param_array(sbirq, int, boot_devs, 0444);
103 MODULE_PARM_DESC(sbirq, "IRQ # for CMI8330 SB driver.");
104 MODULE_PARM_SYNTAX(sbirq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10},{11},{12}},prefers:{5},dialog:list");
105 module_param_array(sbdma8, int, boot_devs, 0444);
106 MODULE_PARM_DESC(sbdma8, "DMA8 for CMI8330 SB driver.");
107 MODULE_PARM_SYNTAX(sbdma8, SNDRV_DMA8_DESC ",prefers:{1}");
108 module_param_array(sbdma16, int, boot_devs, 0444);
109 MODULE_PARM_DESC(sbdma16, "DMA16 for CMI8330 SB driver.");
110 MODULE_PARM_SYNTAX(sbdma16, SNDRV_ENABLED ",allows:{{5},{7}},prefers:{5},dialog:list");
112 module_param_array(wssport, long, boot_devs, 0444);
113 MODULE_PARM_DESC(wssport, "Port # for CMI8330 WSS driver.");
114 MODULE_PARM_SYNTAX(wssport, SNDRV_ENABLED ",allows:{{0x530},{0xe80,0xf40,0xc0}},prefers:{0x530},base:16,dialog:list");
115 module_param_array(wssirq, int, boot_devs, 0444);
116 MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330 WSS driver.");
117 MODULE_PARM_SYNTAX(wssirq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10},{11},{12}},prefers:{11},dialog:list");
118 module_param_array(wssdma, int, boot_devs, 0444);
119 MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver.");
120 MODULE_PARM_SYNTAX(wssdma, SNDRV_DMA8_DESC ",prefers:{0}");
122 #define CMI8330_RMUX3D 16
123 #define CMI8330_MUTEMUX 17
124 #define CMI8330_OUTPUTVOL 18
125 #define CMI8330_MASTVOL 19
126 #define CMI8330_LINVOL 20
127 #define CMI8330_CDINVOL 21
128 #define CMI8330_WAVVOL 22
129 #define CMI8330_RECMUX 23
130 #define CMI8330_WAVGAIN 24
131 #define CMI8330_LINGAIN 25
132 #define CMI8330_CDINGAIN 26
134 static unsigned char snd_cmi8330_image[((CMI8330_CDINGAIN)-16) + 1] =
136 0x40, /* 16 - recording mux (SB-mixer-enabled) */
137 #ifdef ENABLE_SB_MIXER
138 0x40, /* 17 - mute mux (Mode2) */
140 0x0, /* 17 - mute mux */
143 0x0, /* 19 - master volume */
144 0x0, /* 20 - line-in volume */
145 0x0, /* 21 - cd-in volume */
146 0x0, /* 22 - wave volume */
147 0x0, /* 23 - mute/rec mux */
148 0x0, /* 24 - wave rec gain */
149 0x0, /* 25 - line-in rec gain */
150 0x0 /* 26 - cd-in rec gain */
153 typedef int (*snd_pcm_open_callback_t)(snd_pcm_substream_t *);
158 struct pnp_dev *play;
165 struct snd_cmi8330_stream {
167 snd_pcm_open_callback_t open;
168 void *private_data; /* sb or wss */
172 static snd_card_t *snd_cmi8330_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
176 static struct pnp_card_device_id snd_cmi8330_pnpids[] = {
177 { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" } } },
181 MODULE_DEVICE_TABLE(pnp_card, snd_cmi8330_pnpids);
186 static struct ad1848_mix_elem snd_cmi8330_controls[] __initdata = {
187 AD1848_DOUBLE("Master Playback Volume", 0, CMI8330_MASTVOL, CMI8330_MASTVOL, 4, 0, 15, 0),
188 AD1848_SINGLE("Loud Playback Switch", 0, CMI8330_MUTEMUX, 6, 1, 1),
189 AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
190 AD1848_DOUBLE("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1),
191 AD1848_DOUBLE("Line Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 4, 3, 1, 0),
192 AD1848_DOUBLE("Line Playback Volume", 0, CMI8330_LINVOL, CMI8330_LINVOL, 4, 0, 15, 0),
193 AD1848_DOUBLE("Line Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 2, 1, 1, 0),
194 AD1848_DOUBLE("Line Capture Volume", 0, CMI8330_LINGAIN, CMI8330_LINGAIN, 4, 0, 15, 0),
195 AD1848_DOUBLE("CD Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 2, 1, 1, 0),
196 AD1848_DOUBLE("CD Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 4, 3, 1, 0),
197 AD1848_DOUBLE("CD Playback Volume", 0, CMI8330_CDINVOL, CMI8330_CDINVOL, 4, 0, 15, 0),
198 AD1848_DOUBLE("CD Capture Volume", 0, CMI8330_CDINGAIN, CMI8330_CDINGAIN, 4, 0, 15, 0),
199 AD1848_SINGLE("Mic Playback Switch", 0, CMI8330_MUTEMUX, 0, 1, 0),
200 AD1848_SINGLE("Mic Playback Volume", 0, CMI8330_OUTPUTVOL, 0, 7, 0),
201 AD1848_SINGLE("Mic Capture Switch", 0, CMI8330_RMUX3D, 0, 1, 0),
202 AD1848_SINGLE("Mic Capture Volume", 0, CMI8330_OUTPUTVOL, 5, 7, 0),
203 AD1848_DOUBLE("Wavetable Playback Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 1, 0, 1, 0),
204 AD1848_DOUBLE("Wavetable Playback Volume", 0, CMI8330_WAVVOL, CMI8330_WAVVOL, 4, 0, 15, 0),
205 AD1848_DOUBLE("Wavetable Capture Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 5, 4, 1, 0),
206 AD1848_DOUBLE("Wavetable Capture Volume", 0, CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0),
207 AD1848_SINGLE("3D Control - Switch", 0, CMI8330_RMUX3D, 5, 1, 1),
208 AD1848_SINGLE("PC Speaker Playback Volume", 0, CMI8330_OUTPUTVOL, 3, 3, 0),
209 AD1848_SINGLE("FM Playback Switch", 0, CMI8330_RECMUX, 3, 1, 1),
210 AD1848_SINGLE("IEC958 Input Capture Switch", 0, CMI8330_RMUX3D, 7, 1, 1),
211 AD1848_SINGLE("IEC958 Input Playback Switch", 0, CMI8330_MUTEMUX, 7, 1, 1),
214 #ifdef ENABLE_SB_MIXER
215 static struct sbmix_elem cmi8330_sb_mixers[] __initdata = {
216 SB_DOUBLE("SB Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31),
217 SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15),
218 SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15),
219 SB_DOUBLE("SB PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31),
220 SB_DOUBLE("SB Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31),
221 SB_DOUBLE("SB CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
222 SB_DOUBLE("SB CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31),
223 SB_DOUBLE("SB Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
224 SB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
225 SB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
226 SB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
227 SB_SINGLE("SB PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
228 SB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
229 SB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
230 SB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
233 static unsigned char cmi8330_sb_init_values[][2] __initdata = {
234 { SB_DSP4_MASTER_DEV + 0, 0 },
235 { SB_DSP4_MASTER_DEV + 1, 0 },
236 { SB_DSP4_PCM_DEV + 0, 0 },
237 { SB_DSP4_PCM_DEV + 1, 0 },
238 { SB_DSP4_SYNTH_DEV + 0, 0 },
239 { SB_DSP4_SYNTH_DEV + 1, 0 },
240 { SB_DSP4_INPUT_LEFT, 0 },
241 { SB_DSP4_INPUT_RIGHT, 0 },
242 { SB_DSP4_OUTPUT_SW, 0 },
243 { SB_DSP4_SPEAKER_DEV, 0 },
247 static int __devinit cmi8330_add_sb_mixers(sb_t *chip)
252 spin_lock_irqsave(&chip->mixer_lock, flags);
253 snd_sbmixer_write(chip, 0x00, 0x00); /* mixer reset */
254 spin_unlock_irqrestore(&chip->mixer_lock, flags);
256 /* mute and zero volume channels */
257 for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_init_values); idx++) {
258 spin_lock_irqsave(&chip->mixer_lock, flags);
259 snd_sbmixer_write(chip, cmi8330_sb_init_values[idx][0],
260 cmi8330_sb_init_values[idx][1]);
261 spin_unlock_irqrestore(&chip->mixer_lock, flags);
264 for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_mixers); idx++) {
265 if ((err = snd_sbmixer_add_ctl_elem(chip, &cmi8330_sb_mixers[idx])) < 0)
272 static int __devinit snd_cmi8330_mixer(snd_card_t *card, struct snd_cmi8330 *acard)
277 strcpy(card->mixername, "CMI8330/C3D");
279 for (idx = 0; idx < ARRAY_SIZE(snd_cmi8330_controls); idx++) {
280 if ((err = snd_ad1848_add_ctl_elem(acard->wss, &snd_cmi8330_controls[idx])) < 0)
284 #ifdef ENABLE_SB_MIXER
285 if ((err = cmi8330_add_sb_mixers(acard->sb)) < 0)
292 static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
293 struct pnp_card_link *card,
294 const struct pnp_card_device_id *id)
296 struct pnp_dev *pdev;
297 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
300 acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL);
301 if (acard->cap == NULL) {
305 acard->play = pnp_request_card_device(card, id->devs[1].id, NULL);
306 if (acard->play == NULL) {
312 pnp_init_resource_table(cfg);
313 /* allocate AD1848 resources */
314 if (wssport[dev] != SNDRV_AUTO_PORT)
315 pnp_resource_change(&cfg->port_resource[0], wssport[dev], 8);
316 if (wssdma[dev] != SNDRV_AUTO_DMA)
317 pnp_resource_change(&cfg->dma_resource[0], wssdma[dev], 1);
318 if (wssirq[dev] != SNDRV_AUTO_IRQ)
319 pnp_resource_change(&cfg->irq_resource[0], wssirq[dev], 1);
321 err = pnp_manual_config_dev(pdev, cfg, 0);
323 snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP manual resources are invalid, using auto config\n");
324 err = pnp_activate_dev(pdev);
326 snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP configure failure\n");
330 wssport[dev] = pnp_port_start(pdev, 0);
331 wssdma[dev] = pnp_dma(pdev, 0);
332 wssirq[dev] = pnp_irq(pdev, 0);
334 /* allocate SB16 resources */
336 pnp_init_resource_table(cfg);
337 if (sbport[dev] != SNDRV_AUTO_PORT)
338 pnp_resource_change(&cfg->port_resource[0], sbport[dev], 16);
339 if (sbdma8[dev] != SNDRV_AUTO_DMA)
340 pnp_resource_change(&cfg->dma_resource[0], sbdma8[dev], 1);
341 if (sbdma16[dev] != SNDRV_AUTO_DMA)
342 pnp_resource_change(&cfg->dma_resource[1], sbdma16[dev], 1);
343 if (sbirq[dev] != SNDRV_AUTO_IRQ)
344 pnp_resource_change(&cfg->irq_resource[0], sbirq[dev], 1);
346 err = pnp_manual_config_dev(pdev, cfg, 0);
348 snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP manual resources are invalid, using auto config\n");
349 err = pnp_activate_dev(pdev);
351 snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n");
355 sbport[dev] = pnp_port_start(pdev, 0);
356 sbdma8[dev] = pnp_dma(pdev, 0);
357 sbdma16[dev] = pnp_dma(pdev, 1);
358 sbirq[dev] = pnp_irq(pdev, 0);
368 * since we call the different chip interfaces for playback and capture
369 * directions, we need a trick.
371 * - copy the ops for each direction into a local record.
372 * - replace the open callback with the new one, which replaces the
373 * substream->private_data with the corresponding chip instance
374 * and calls again the original open callback of the chip.
378 #ifdef PLAYBACK_ON_SB
379 #define CMI_SB_STREAM SNDRV_PCM_STREAM_PLAYBACK
380 #define CMI_AD_STREAM SNDRV_PCM_STREAM_CAPTURE
382 #define CMI_SB_STREAM SNDRV_PCM_STREAM_CAPTURE
383 #define CMI_AD_STREAM SNDRV_PCM_STREAM_PLAYBACK
386 static int snd_cmi8330_playback_open(snd_pcm_substream_t * substream)
388 struct snd_cmi8330 *chip = (struct snd_cmi8330 *)_snd_pcm_substream_chip(substream);
390 /* replace the private_data and call the original open callback */
391 substream->private_data = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].private_data;
392 return chip->streams[SNDRV_PCM_STREAM_PLAYBACK].open(substream);
395 static int snd_cmi8330_capture_open(snd_pcm_substream_t * substream)
397 struct snd_cmi8330 *chip = (struct snd_cmi8330 *)_snd_pcm_substream_chip(substream);
399 /* replace the private_data and call the original open callback */
400 substream->private_data = chip->streams[SNDRV_PCM_STREAM_CAPTURE].private_data;
401 return chip->streams[SNDRV_PCM_STREAM_CAPTURE].open(substream);
404 static void snd_cmi8330_pcm_free(snd_pcm_t *pcm)
406 snd_pcm_lib_preallocate_free_for_all(pcm);
409 static int __devinit snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip)
412 const snd_pcm_ops_t *ops;
414 static snd_pcm_open_callback_t cmi_open_callbacks[2] = {
415 snd_cmi8330_playback_open,
416 snd_cmi8330_capture_open
419 if ((err = snd_pcm_new(card, "CMI8330", 0, 1, 1, &pcm)) < 0)
421 strcpy(pcm->name, "CMI8330");
422 pcm->private_data = chip;
423 pcm->private_free = snd_cmi8330_pcm_free;
426 ops = snd_sb16dsp_get_pcm_ops(CMI_SB_STREAM);
427 chip->streams[CMI_SB_STREAM].ops = *ops;
428 chip->streams[CMI_SB_STREAM].open = ops->open;
429 chip->streams[CMI_SB_STREAM].ops.open = cmi_open_callbacks[CMI_SB_STREAM];
430 chip->streams[CMI_SB_STREAM].private_data = chip->sb;
433 ops = snd_ad1848_get_pcm_ops(CMI_AD_STREAM);
434 chip->streams[CMI_AD_STREAM].ops = *ops;
435 chip->streams[CMI_AD_STREAM].open = ops->open;
436 chip->streams[CMI_AD_STREAM].ops.open = cmi_open_callbacks[CMI_AD_STREAM];
437 chip->streams[CMI_AD_STREAM].private_data = chip->wss;
439 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK].ops);
440 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &chip->streams[SNDRV_PCM_STREAM_CAPTURE].ops);
442 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
454 static int __devinit snd_cmi8330_probe(int dev,
455 struct pnp_card_link *pcard,
456 const struct pnp_card_device_id *pid)
459 struct snd_cmi8330 *acard;
466 if (wssport[dev] == SNDRV_AUTO_PORT) {
467 snd_printk("specify wssport\n");
470 if (sbport[dev] == SNDRV_AUTO_PORT) {
471 snd_printk("specify sbport\n");
477 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
478 sizeof(struct snd_cmi8330));
480 snd_printk("could not get a new card\n");
483 acard = (struct snd_cmi8330 *)card->private_data;
488 if ((err = snd_cmi8330_pnp(dev, acard, pcard, pid)) < 0) {
489 snd_printk("PnP detection failed\n");
493 snd_card_set_dev(card, &pcard->card->dev);
497 if ((err = snd_ad1848_create(card,
503 snd_printk("(AD1848) device busy??\n");
507 if (acard->wss->hardware != AD1848_HW_CMI8330) {
508 snd_printk("(AD1848) not found during probe\n");
513 if ((err = snd_sbdsp_create(card, sbport[dev],
515 snd_sb16dsp_interrupt,
518 SB_HW_AUTO, &acard->sb)) < 0) {
519 snd_printk("(SB16) device busy??\n");
523 if (acard->sb->hardware != SB_HW_16) {
524 snd_printk("(SB16) not found during probe\n");
529 spin_lock_irqsave(&acard->wss->reg_lock, flags);
530 snd_ad1848_out(acard->wss, AD1848_MISC_INFO, 0x40); /* switch on MODE2 */
531 for (i = CMI8330_RMUX3D; i <= CMI8330_CDINGAIN; i++)
532 snd_ad1848_out(acard->wss, i, snd_cmi8330_image[i - CMI8330_RMUX3D]);
533 spin_unlock_irqrestore(&acard->wss->reg_lock, flags);
535 if ((err = snd_cmi8330_mixer(card, acard)) < 0) {
536 snd_printk("failed to create mixers\n");
541 if ((err = snd_cmi8330_pcm(card, acard)) < 0) {
542 snd_printk("failed to create pcms\n");
547 strcpy(card->driver, "CMI8330/C3D");
548 strcpy(card->shortname, "C-Media CMI8330/C3D");
549 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
555 if ((err = snd_card_register(card)) < 0) {
561 pnp_set_card_drvdata(pcard, card);
563 snd_cmi8330_legacy[dev] = card;
568 static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *card,
569 const struct pnp_card_device_id *id)
574 for ( ; dev < SNDRV_CARDS; dev++) {
575 if (!enable[dev] || !isapnp[dev])
577 res = snd_cmi8330_probe(dev, card, id);
586 static void __devexit snd_cmi8330_pnp_remove(struct pnp_card_link * pcard)
588 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
590 snd_card_disconnect(card);
591 snd_card_free_in_thread(card);
594 static struct pnp_card_driver cmi8330_pnpc_driver = {
595 .flags = PNP_DRIVER_RES_DISABLE,
597 .id_table = snd_cmi8330_pnpids,
598 .probe = snd_cmi8330_pnp_detect,
599 .remove = __devexit_p(snd_cmi8330_pnp_remove),
601 #endif /* CONFIG_PNP */
603 static int __init alsa_card_cmi8330_init(void)
607 for (dev = 0; dev < SNDRV_CARDS; dev++) {
614 if (snd_cmi8330_probe(dev, NULL, NULL) >= 0)
618 cards += pnp_register_card_driver(&cmi8330_pnpc_driver);
623 pnp_unregister_card_driver(&cmi8330_pnpc_driver);
626 snd_printk(KERN_ERR "CMI8330 not found or device busy\n");
633 static void __exit alsa_card_cmi8330_exit(void)
638 /* PnP cards first */
639 pnp_unregister_card_driver(&cmi8330_pnpc_driver);
641 for (i = 0; i < SNDRV_CARDS; i++)
642 snd_card_free(snd_cmi8330_legacy[i]);
645 module_init(alsa_card_cmi8330_init)
646 module_exit(alsa_card_cmi8330_exit)