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 <sound/core.h>
51 #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;
83 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
84 MODULE_PARM_DESC(index, "Index value for CMI8330 soundcard.");
85 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
86 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
87 MODULE_PARM_DESC(id, "ID string for CMI8330 soundcard.");
88 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
89 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
90 MODULE_PARM_DESC(enable, "Enable CMI8330 soundcard.");
91 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
93 MODULE_PARM(isapnp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
94 MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
95 MODULE_PARM_SYNTAX(isapnp, SNDRV_ISAPNP_DESC);
98 MODULE_PARM(sbport, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
99 MODULE_PARM_DESC(sbport, "Port # for CMI8330 SB driver.");
100 MODULE_PARM_SYNTAX(sbport, SNDRV_ENABLED ",allows:{{0x220,0x280,0x20}},prefers:{0x220},base:16,dialog:list");
101 MODULE_PARM(sbirq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
102 MODULE_PARM_DESC(sbirq, "IRQ # for CMI8330 SB driver.");
103 MODULE_PARM_SYNTAX(sbirq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10},{11},{12}},prefers:{5},dialog:list");
104 MODULE_PARM(sbdma8, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
105 MODULE_PARM_DESC(sbdma8, "DMA8 for CMI8330 SB driver.");
106 MODULE_PARM_SYNTAX(sbdma8, SNDRV_DMA8_DESC ",prefers:{1}");
107 MODULE_PARM(sbdma16, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
108 MODULE_PARM_DESC(sbdma16, "DMA16 for CMI8330 SB driver.");
109 MODULE_PARM_SYNTAX(sbdma16, SNDRV_ENABLED ",allows:{{5},{7}},prefers:{5},dialog:list");
111 MODULE_PARM(wssport, "1-" __MODULE_STRING(SNDRV_CARDS) "l");
112 MODULE_PARM_DESC(wssport, "Port # for CMI8330 WSS driver.");
113 MODULE_PARM_SYNTAX(wssport, SNDRV_ENABLED ",allows:{{0x530},{0xe80,0xf40,0xc0}},prefers:{0x530},base:16,dialog:list");
114 MODULE_PARM(wssirq, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
115 MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330 WSS driver.");
116 MODULE_PARM_SYNTAX(wssirq, SNDRV_ENABLED ",allows:{{5},{7},{9},{10},{11},{12}},prefers:{11},dialog:list");
117 MODULE_PARM(wssdma, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
118 MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver.");
119 MODULE_PARM_SYNTAX(wssdma, SNDRV_DMA8_DESC ",prefers:{0}");
121 #define CMI8330_RMUX3D 16
122 #define CMI8330_MUTEMUX 17
123 #define CMI8330_OUTPUTVOL 18
124 #define CMI8330_MASTVOL 19
125 #define CMI8330_LINVOL 20
126 #define CMI8330_CDINVOL 21
127 #define CMI8330_WAVVOL 22
128 #define CMI8330_RECMUX 23
129 #define CMI8330_WAVGAIN 24
130 #define CMI8330_LINGAIN 25
131 #define CMI8330_CDINGAIN 26
133 static unsigned char snd_cmi8330_image[((CMI8330_CDINGAIN)-16) + 1] =
135 0x40, /* 16 - recording mux (SB-mixer-enabled) */
136 #ifdef ENABLE_SB_MIXER
137 0x40, /* 17 - mute mux (Mode2) */
139 0x0, /* 17 - mute mux */
142 0x0, /* 19 - master volume */
143 0x0, /* 20 - line-in volume */
144 0x0, /* 21 - cd-in volume */
145 0x0, /* 22 - wave volume */
146 0x0, /* 23 - mute/rec mux */
147 0x0, /* 24 - wave rec gain */
148 0x0, /* 25 - line-in rec gain */
149 0x0 /* 26 - cd-in rec gain */
152 typedef int (*snd_pcm_open_callback_t)(snd_pcm_substream_t *);
157 struct pnp_dev *play;
164 struct snd_cmi8330_stream {
166 snd_pcm_open_callback_t open;
167 void *private_data; /* sb or wss */
171 static snd_card_t *snd_cmi8330_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
175 static struct pnp_card_device_id snd_cmi8330_pnpids[] = {
176 { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" } } },
180 MODULE_DEVICE_TABLE(pnp_card, snd_cmi8330_pnpids);
185 static struct ad1848_mix_elem snd_cmi8330_controls[] __initdata = {
186 AD1848_DOUBLE("Master Playback Volume", 0, CMI8330_MASTVOL, CMI8330_MASTVOL, 4, 0, 15, 0),
187 AD1848_SINGLE("Loud Playback Switch", 0, CMI8330_MUTEMUX, 6, 1, 1),
188 AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
189 AD1848_DOUBLE("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1),
190 AD1848_DOUBLE("Line Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 4, 3, 1, 0),
191 AD1848_DOUBLE("Line Playback Volume", 0, CMI8330_LINVOL, CMI8330_LINVOL, 4, 0, 15, 0),
192 AD1848_DOUBLE("Line Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 2, 1, 1, 0),
193 AD1848_DOUBLE("Line Capture Volume", 0, CMI8330_LINGAIN, CMI8330_LINGAIN, 4, 0, 15, 0),
194 AD1848_DOUBLE("CD Playback Switch", 0, CMI8330_MUTEMUX, CMI8330_MUTEMUX, 2, 1, 1, 0),
195 AD1848_DOUBLE("CD Capture Switch", 0, CMI8330_RMUX3D, CMI8330_RMUX3D, 4, 3, 1, 0),
196 AD1848_DOUBLE("CD Playback Volume", 0, CMI8330_CDINVOL, CMI8330_CDINVOL, 4, 0, 15, 0),
197 AD1848_DOUBLE("CD Capture Volume", 0, CMI8330_CDINGAIN, CMI8330_CDINGAIN, 4, 0, 15, 0),
198 AD1848_SINGLE("Mic Playback Switch", 0, CMI8330_MUTEMUX, 0, 1, 0),
199 AD1848_SINGLE("Mic Playback Volume", 0, CMI8330_OUTPUTVOL, 0, 7, 0),
200 AD1848_SINGLE("Mic Capture Switch", 0, CMI8330_RMUX3D, 0, 1, 0),
201 AD1848_SINGLE("Mic Capture Volume", 0, CMI8330_OUTPUTVOL, 5, 7, 0),
202 AD1848_DOUBLE("Wavetable Playback Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 1, 0, 1, 0),
203 AD1848_DOUBLE("Wavetable Playback Volume", 0, CMI8330_WAVVOL, CMI8330_WAVVOL, 4, 0, 15, 0),
204 AD1848_DOUBLE("Wavetable Capture Switch", 0, CMI8330_RECMUX, CMI8330_RECMUX, 5, 4, 1, 0),
205 AD1848_DOUBLE("Wavetable Capture Volume", 0, CMI8330_WAVGAIN, CMI8330_WAVGAIN, 4, 0, 15, 0),
206 AD1848_SINGLE("3D Control - Switch", 0, CMI8330_RMUX3D, 5, 1, 1),
207 AD1848_SINGLE("PC Speaker Playback Volume", 0, CMI8330_OUTPUTVOL, 3, 3, 0),
208 AD1848_SINGLE("FM Playback Switch", 0, CMI8330_RECMUX, 3, 1, 1),
209 AD1848_SINGLE("IEC958 Input Capture Switch", 0, CMI8330_RMUX3D, 7, 1, 1),
210 AD1848_SINGLE("IEC958 Input Playback Switch", 0, CMI8330_MUTEMUX, 7, 1, 1),
213 #ifdef ENABLE_SB_MIXER
214 static struct sbmix_elem cmi8330_sb_mixers[] __initdata = {
215 SB_DOUBLE("SB Master Playback Volume", SB_DSP4_MASTER_DEV, (SB_DSP4_MASTER_DEV + 1), 3, 3, 31),
216 SB_DOUBLE("Tone Control - Bass", SB_DSP4_BASS_DEV, (SB_DSP4_BASS_DEV + 1), 4, 4, 15),
217 SB_DOUBLE("Tone Control - Treble", SB_DSP4_TREBLE_DEV, (SB_DSP4_TREBLE_DEV + 1), 4, 4, 15),
218 SB_DOUBLE("SB PCM Playback Volume", SB_DSP4_PCM_DEV, (SB_DSP4_PCM_DEV + 1), 3, 3, 31),
219 SB_DOUBLE("SB Synth Playback Volume", SB_DSP4_SYNTH_DEV, (SB_DSP4_SYNTH_DEV + 1), 3, 3, 31),
220 SB_DOUBLE("SB CD Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 2, 1, 1),
221 SB_DOUBLE("SB CD Playback Volume", SB_DSP4_CD_DEV, (SB_DSP4_CD_DEV + 1), 3, 3, 31),
222 SB_DOUBLE("SB Line Playback Switch", SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, 4, 3, 1),
223 SB_DOUBLE("SB Line Playback Volume", SB_DSP4_LINE_DEV, (SB_DSP4_LINE_DEV + 1), 3, 3, 31),
224 SB_SINGLE("SB Mic Playback Switch", SB_DSP4_OUTPUT_SW, 0, 1),
225 SB_SINGLE("SB Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
226 SB_SINGLE("SB PC Speaker Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
227 SB_DOUBLE("SB Capture Volume", SB_DSP4_IGAIN_DEV, (SB_DSP4_IGAIN_DEV + 1), 6, 6, 3),
228 SB_DOUBLE("SB Playback Volume", SB_DSP4_OGAIN_DEV, (SB_DSP4_OGAIN_DEV + 1), 6, 6, 3),
229 SB_SINGLE("SB Mic Auto Gain", SB_DSP4_MIC_AGC, 0, 1),
232 static unsigned char cmi8330_sb_init_values[][2] __initdata = {
233 { SB_DSP4_MASTER_DEV + 0, 0 },
234 { SB_DSP4_MASTER_DEV + 1, 0 },
235 { SB_DSP4_PCM_DEV + 0, 0 },
236 { SB_DSP4_PCM_DEV + 1, 0 },
237 { SB_DSP4_SYNTH_DEV + 0, 0 },
238 { SB_DSP4_SYNTH_DEV + 1, 0 },
239 { SB_DSP4_INPUT_LEFT, 0 },
240 { SB_DSP4_INPUT_RIGHT, 0 },
241 { SB_DSP4_OUTPUT_SW, 0 },
242 { SB_DSP4_SPEAKER_DEV, 0 },
246 static int __devinit cmi8330_add_sb_mixers(sb_t *chip)
251 spin_lock_irqsave(&chip->mixer_lock, flags);
252 snd_sbmixer_write(chip, 0x00, 0x00); /* mixer reset */
253 spin_unlock_irqrestore(&chip->mixer_lock, flags);
255 /* mute and zero volume channels */
256 for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_init_values); idx++) {
257 spin_lock_irqsave(&chip->mixer_lock, flags);
258 snd_sbmixer_write(chip, cmi8330_sb_init_values[idx][0],
259 cmi8330_sb_init_values[idx][1]);
260 spin_unlock_irqrestore(&chip->mixer_lock, flags);
263 for (idx = 0; idx < ARRAY_SIZE(cmi8330_sb_mixers); idx++) {
264 if ((err = snd_sbmixer_add_ctl_elem(chip, &cmi8330_sb_mixers[idx])) < 0)
271 static int __devinit snd_cmi8330_mixer(snd_card_t *card, struct snd_cmi8330 *acard)
276 strcpy(card->mixername, "CMI8330/C3D");
278 for (idx = 0; idx < ARRAY_SIZE(snd_cmi8330_controls); idx++) {
279 if ((err = snd_ad1848_add_ctl_elem(acard->wss, &snd_cmi8330_controls[idx])) < 0)
283 #ifdef ENABLE_SB_MIXER
284 if ((err = cmi8330_add_sb_mixers(acard->sb)) < 0)
291 static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
292 struct pnp_card_link *card,
293 const struct pnp_card_device_id *id)
295 struct pnp_dev *pdev;
296 struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
299 acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL);
300 if (acard->cap == NULL) {
304 acard->play = pnp_request_card_device(card, id->devs[1].id, NULL);
305 if (acard->play == NULL) {
311 pnp_init_resource_table(cfg);
312 /* allocate AD1848 resources */
313 if (wssport[dev] != SNDRV_AUTO_PORT)
314 pnp_resource_change(&cfg->port_resource[0], wssport[dev], 8);
315 if (wssdma[dev] != SNDRV_AUTO_DMA)
316 pnp_resource_change(&cfg->dma_resource[0], wssdma[dev], 1);
317 if (wssirq[dev] != SNDRV_AUTO_IRQ)
318 pnp_resource_change(&cfg->irq_resource[0], wssirq[dev], 1);
320 err = pnp_manual_config_dev(pdev, cfg, 0);
322 snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP manual resources are invalid, using auto config\n");
323 err = pnp_activate_dev(pdev);
325 snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP configure failure\n");
329 wssport[dev] = pnp_port_start(pdev, 0);
330 wssdma[dev] = pnp_dma(pdev, 0);
331 wssirq[dev] = pnp_irq(pdev, 0);
333 /* allocate SB16 resources */
335 pnp_init_resource_table(cfg);
336 if (sbport[dev] != SNDRV_AUTO_PORT)
337 pnp_resource_change(&cfg->port_resource[0], sbport[dev], 16);
338 if (sbdma8[dev] != SNDRV_AUTO_DMA)
339 pnp_resource_change(&cfg->dma_resource[0], sbdma8[dev], 1);
340 if (sbdma16[dev] != SNDRV_AUTO_DMA)
341 pnp_resource_change(&cfg->dma_resource[1], sbdma16[dev], 1);
342 if (sbirq[dev] != SNDRV_AUTO_IRQ)
343 pnp_resource_change(&cfg->irq_resource[0], sbirq[dev], 1);
345 err = pnp_manual_config_dev(pdev, cfg, 0);
347 snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP manual resources are invalid, using auto config\n");
348 err = pnp_activate_dev(pdev);
350 snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n");
354 sbport[dev] = pnp_port_start(pdev, 0);
355 sbdma8[dev] = pnp_dma(pdev, 0);
356 sbdma16[dev] = pnp_dma(pdev, 1);
357 sbirq[dev] = pnp_irq(pdev, 0);
367 * since we call the different chip interfaces for playback and capture
368 * directions, we need a trick.
370 * - copy the ops for each direction into a local record.
371 * - replace the open callback with the new one, which replaces the
372 * substream->private_data with the corresponding chip instance
373 * and calls again the original open callback of the chip.
377 #ifdef PLAYBACK_ON_SB
378 #define CMI_SB_STREAM SNDRV_PCM_STREAM_PLAYBACK
379 #define CMI_AD_STREAM SNDRV_PCM_STREAM_CAPTURE
381 #define CMI_SB_STREAM SNDRV_PCM_STREAM_CAPTURE
382 #define CMI_AD_STREAM SNDRV_PCM_STREAM_PLAYBACK
385 static int snd_cmi8330_playback_open(snd_pcm_substream_t * substream)
387 struct snd_cmi8330 *chip = (struct snd_cmi8330 *)_snd_pcm_substream_chip(substream);
389 /* replace the private_data and call the original open callback */
390 substream->private_data = chip->streams[SNDRV_PCM_STREAM_PLAYBACK].private_data;
391 return chip->streams[SNDRV_PCM_STREAM_PLAYBACK].open(substream);
394 static int snd_cmi8330_capture_open(snd_pcm_substream_t * substream)
396 struct snd_cmi8330 *chip = (struct snd_cmi8330 *)_snd_pcm_substream_chip(substream);
398 /* replace the private_data and call the original open callback */
399 substream->private_data = chip->streams[SNDRV_PCM_STREAM_CAPTURE].private_data;
400 return chip->streams[SNDRV_PCM_STREAM_CAPTURE].open(substream);
403 static void snd_cmi8330_pcm_free(snd_pcm_t *pcm)
405 snd_pcm_lib_preallocate_free_for_all(pcm);
408 static int __devinit snd_cmi8330_pcm(snd_card_t *card, struct snd_cmi8330 *chip)
411 const snd_pcm_ops_t *ops;
413 static snd_pcm_open_callback_t cmi_open_callbacks[2] = {
414 snd_cmi8330_playback_open,
415 snd_cmi8330_capture_open
418 if ((err = snd_pcm_new(card, "CMI8330", 0, 1, 1, &pcm)) < 0)
420 strcpy(pcm->name, "CMI8330");
421 pcm->private_data = chip;
422 pcm->private_free = snd_cmi8330_pcm_free;
425 ops = snd_sb16dsp_get_pcm_ops(CMI_SB_STREAM);
426 chip->streams[CMI_SB_STREAM].ops = *ops;
427 chip->streams[CMI_SB_STREAM].open = ops->open;
428 chip->streams[CMI_SB_STREAM].ops.open = cmi_open_callbacks[CMI_SB_STREAM];
429 chip->streams[CMI_SB_STREAM].private_data = chip->sb;
432 ops = snd_ad1848_get_pcm_ops(CMI_AD_STREAM);
433 chip->streams[CMI_AD_STREAM].ops = *ops;
434 chip->streams[CMI_AD_STREAM].open = ops->open;
435 chip->streams[CMI_AD_STREAM].ops.open = cmi_open_callbacks[CMI_AD_STREAM];
436 chip->streams[CMI_AD_STREAM].private_data = chip->wss;
438 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &chip->streams[SNDRV_PCM_STREAM_PLAYBACK].ops);
439 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &chip->streams[SNDRV_PCM_STREAM_CAPTURE].ops);
441 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
453 static int __devinit snd_cmi8330_probe(int dev,
454 struct pnp_card_link *pcard,
455 const struct pnp_card_device_id *pid)
458 struct snd_cmi8330 *acard;
465 if (wssport[dev] == SNDRV_AUTO_PORT) {
466 snd_printk("specify wssport\n");
469 if (sbport[dev] == SNDRV_AUTO_PORT) {
470 snd_printk("specify sbport\n");
476 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
477 sizeof(struct snd_cmi8330));
479 snd_printk("could not get a new card\n");
482 acard = (struct snd_cmi8330 *)card->private_data;
487 if ((err = snd_cmi8330_pnp(dev, acard, pcard, pid)) < 0) {
488 snd_printk("PnP detection failed\n");
492 snd_card_set_dev(card, &pcard->card->dev);
496 if ((err = snd_ad1848_create(card,
502 snd_printk("(AD1848) device busy??\n");
506 if (acard->wss->hardware != AD1848_HW_CMI8330) {
507 snd_printk("(AD1848) not found during probe\n");
512 if ((err = snd_sbdsp_create(card, sbport[dev],
514 snd_sb16dsp_interrupt,
517 SB_HW_AUTO, &acard->sb)) < 0) {
518 snd_printk("(SB16) device busy??\n");
522 if (acard->sb->hardware != SB_HW_16) {
523 snd_printk("(SB16) not found during probe\n");
528 spin_lock_irqsave(&acard->wss->reg_lock, flags);
529 snd_ad1848_out(acard->wss, AD1848_MISC_INFO, 0x40); /* switch on MODE2 */
530 for (i = CMI8330_RMUX3D; i <= CMI8330_CDINGAIN; i++)
531 snd_ad1848_out(acard->wss, i, snd_cmi8330_image[i - CMI8330_RMUX3D]);
532 spin_unlock_irqrestore(&acard->wss->reg_lock, flags);
534 if ((err = snd_cmi8330_mixer(card, acard)) < 0) {
535 snd_printk("failed to create mixers\n");
540 if ((err = snd_cmi8330_pcm(card, acard)) < 0) {
541 snd_printk("failed to create pcms\n");
546 strcpy(card->driver, "CMI8330/C3D");
547 strcpy(card->shortname, "C-Media CMI8330/C3D");
548 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
554 if ((err = snd_card_register(card)) < 0) {
560 pnp_set_card_drvdata(pcard, card);
562 snd_cmi8330_legacy[dev] = card;
567 static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *card,
568 const struct pnp_card_device_id *id)
573 for ( ; dev < SNDRV_CARDS; dev++) {
574 if (!enable[dev] || !isapnp[dev])
576 res = snd_cmi8330_probe(dev, card, id);
585 static void __devexit snd_cmi8330_pnp_remove(struct pnp_card_link * pcard)
587 snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
589 snd_card_disconnect(card);
590 snd_card_free_in_thread(card);
593 static struct pnp_card_driver cmi8330_pnpc_driver = {
594 .flags = PNP_DRIVER_RES_DISABLE,
596 .id_table = snd_cmi8330_pnpids,
597 .probe = snd_cmi8330_pnp_detect,
598 .remove = __devexit_p(snd_cmi8330_pnp_remove),
600 #endif /* CONFIG_PNP */
602 static int __init alsa_card_cmi8330_init(void)
606 for (dev = 0; dev < SNDRV_CARDS; dev++) {
613 if (snd_cmi8330_probe(dev, NULL, NULL) >= 0)
617 cards += pnp_register_card_driver(&cmi8330_pnpc_driver);
622 pnp_unregister_card_driver(&cmi8330_pnpc_driver);
625 snd_printk(KERN_ERR "CMI8330 not found or device busy\n");
632 static void __exit alsa_card_cmi8330_exit(void)
637 /* PnP cards first */
638 pnp_unregister_card_driver(&cmi8330_pnpc_driver);
640 for (i = 0; i < SNDRV_CARDS; i++)
641 snd_card_free(snd_cmi8330_legacy[i]);
644 module_init(alsa_card_cmi8330_init)
645 module_exit(alsa_card_cmi8330_exit)
649 /* format is: snd-cmi8330=enable,index,id,isapnp,
655 static int __init alsa_card_cmi8330_setup(char *str)
657 static unsigned __initdata nr_dev = 0;
658 int __attribute__ ((__unused__)) pnp = INT_MAX;
660 if (nr_dev >= SNDRV_CARDS)
662 (void)(get_option(&str,&enable[nr_dev]) == 2 &&
663 get_option(&str,&index[nr_dev]) == 2 &&
664 get_id(&str,&id[nr_dev]) == 2 &&
665 get_option(&str,&pnp) == 2 &&
666 get_option_long(&str,&sbport[nr_dev]) == 2 &&
667 get_option(&str,&sbirq[nr_dev]) == 2 &&
668 get_option(&str,&sbdma8[nr_dev]) == 2 &&
669 get_option(&str,&sbdma16[nr_dev]) == 2 &&
670 get_option_long(&str,&wssport[nr_dev]) == 2 &&
671 get_option(&str,&wssirq[nr_dev]) == 2 &&
672 get_option(&str,&wssdma[nr_dev]) == 2);
675 isapnp[nr_dev] = pnp;
681 __setup("snd-cmi8330=", alsa_card_cmi8330_setup);
683 #endif /* ifndef MODULE */