ALSA: wss_lib: rename cs4321_foo to wss_foo
[safe/jmp/linux-2.6] / sound / isa / cs423x / cs4236.c
1 /*
2  *  Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips
3  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4  *
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include <linux/init.h>
23 #include <linux/err.h>
24 #include <linux/isa.h>
25 #include <linux/slab.h>
26 #include <linux/pnp.h>
27 #include <linux/moduleparam.h>
28 #include <sound/core.h>
29 #include <sound/wss.h>
30 #include <sound/mpu401.h>
31 #include <sound/opl3.h>
32 #include <sound/initval.h>
33
34 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
35 MODULE_LICENSE("GPL");
36 #ifdef CS4232
37 MODULE_DESCRIPTION("Cirrus Logic CS4232");
38 MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000},"
39                 "{Turtle Beach,Tropez Plus},"
40                 "{SIC CrystalWave 32},"
41                 "{Hewlett Packard,Omnibook 5500},"
42                 "{TerraTec,Maestro 32/96},"
43                 "{Philips,PCA70PS}}");
44 #else
45 MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
46 MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
47                 "{Crystal Semiconductors,CS4236},"
48                 "{Crystal Semiconductors,CS4237},"
49                 "{Crystal Semiconductors,CS4238},"
50                 "{Crystal Semiconductors,CS4239},"
51                 "{Acer,AW37},"
52                 "{Acer,AW35/Pro},"
53                 "{Crystal,3D},"
54                 "{Crystal Computer,TidalWave128},"
55                 "{Dell,Optiplex GX1},"
56                 "{Dell,Workstation 400 sound},"
57                 "{EliteGroup,P5TX-LA sound},"
58                 "{Gallant,SC-70P},"
59                 "{Gateway,E1000 Onboard CS4236B},"
60                 "{Genius,Sound Maker 3DJ},"
61                 "{Hewlett Packard,HP6330 sound},"
62                 "{IBM,PC 300PL sound},"
63                 "{IBM,Aptiva 2137 E24},"
64                 "{IBM,IntelliStation M Pro},"
65                 "{Intel,Marlin Spike Mobo CS4235},"
66                 "{Intel PR440FX Onboard},"
67                 "{Guillemot,MaxiSound 16 PnP},"
68                 "{NewClear,3D},"
69                 "{TerraTec,AudioSystem EWS64L/XL},"
70                 "{Typhoon Soundsystem,CS4236B},"
71                 "{Turtle Beach,Malibu},"
72                 "{Unknown,Digital PC 5000 Onboard}}");
73 #endif
74
75 #ifdef CS4232
76 #define IDENT "CS4232"
77 #define DEV_NAME "cs4232"
78 #else
79 #define IDENT "CS4236+"
80 #define DEV_NAME "cs4236"
81 #endif
82
83 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
84 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
85 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
86 #ifdef CONFIG_PNP
87 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
88 #endif
89 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;     /* PnP setup */
90 static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;    /* PnP setup */
91 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
92 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;  /* PnP setup */
93 static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;  /* PnP setup */
94 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;        /* 5,7,9,11,12,15 */
95 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;    /* 9,11,12,15 */
96 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* 0,1,3,5,6,7 */
97 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* 0,1,3,5,6,7 */
98
99 module_param_array(index, int, NULL, 0444);
100 MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
101 module_param_array(id, charp, NULL, 0444);
102 MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
103 module_param_array(enable, bool, NULL, 0444);
104 MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
105 #ifdef CONFIG_PNP
106 module_param_array(isapnp, bool, NULL, 0444);
107 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
108 #endif
109 module_param_array(port, long, NULL, 0444);
110 MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
111 module_param_array(cport, long, NULL, 0444);
112 MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
113 module_param_array(mpu_port, long, NULL, 0444);
114 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
115 module_param_array(fm_port, long, NULL, 0444);
116 MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
117 module_param_array(sb_port, long, NULL, 0444);
118 MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
119 module_param_array(irq, int, NULL, 0444);
120 MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
121 module_param_array(mpu_irq, int, NULL, 0444);
122 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
123 module_param_array(dma1, int, NULL, 0444);
124 MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
125 module_param_array(dma2, int, NULL, 0444);
126 MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
127
128 #ifdef CONFIG_PNP
129 static int isa_registered;
130 static int pnpc_registered;
131 #ifdef CS4232
132 static int pnp_registered;
133 #endif
134 #endif /* CONFIG_PNP */
135
136 struct snd_card_cs4236 {
137         struct snd_wss *chip;
138         struct resource *res_sb_port;
139 #ifdef CONFIG_PNP
140         struct pnp_dev *wss;
141         struct pnp_dev *ctrl;
142         struct pnp_dev *mpu;
143 #endif
144 };
145
146 #ifdef CONFIG_PNP
147
148 #ifdef CS4232
149 /*
150  * PNP BIOS
151  */
152 static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
153         { .id = "CSC0100" },
154         { .id = "CSC0000" },
155         /* Guillemot Turtlebeach something appears to be cs4232 compatible
156          * (untested) */
157         { .id = "GIM0100" },
158         { .id = "" }
159 };
160 MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
161 #endif /* CS4232 */
162
163 #ifdef CS4232
164 #define CS423X_ISAPNP_DRIVER    "cs4232_isapnp"
165 static struct pnp_card_device_id snd_cs423x_pnpids[] = {
166         /* Philips PCA70PS */
167         { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
168         /* TerraTec Maestro 32/96 (CS4232) */
169         { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
170         /* HP Omnibook 5500 onboard */
171         { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
172         /* Unnamed CS4236 card (Made in Taiwan) */
173         { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
174         /* Turtle Beach TBS-2000 (CS4232) */
175         { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
176         /* Turtle Beach Tropez Plus (CS4232) */
177         { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
178         /* SIC CrystalWave 32 (CS4232) */
179         { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
180         /* Netfinity 3000 on-board soundcard */
181         { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
182         /* --- */
183         { .id = "" }    /* end */
184 };
185 #else /* CS4236 */
186 #define CS423X_ISAPNP_DRIVER    "cs4236_isapnp"
187 static struct pnp_card_device_id snd_cs423x_pnpids[] = {
188         /* Intel Marlin Spike Motherboard - CS4235 */
189         { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
190         /* Intel Marlin Spike Motherboard (#2) - CS4235 */
191         { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
192         /* Unknown Intel mainboard - CS4235 */
193         { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
194         /* Genius Sound Maker 3DJ - CS4237B */
195         { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
196         /* Digital PC 5000 Onboard - CS4236B */
197         { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
198         /* some uknown CS4236B */
199         { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
200         /* Intel PR440FX Onboard sound */
201         { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
202         /* CS4235 on mainboard without MPU */
203         { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
204         /* Gateway E1000 Onboard CS4236B */
205         { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
206         /* HP 6330 Onboard sound */
207         { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
208         /* Crystal Computer TidalWave128 */
209         { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
210         /* ACER AW37 - CS4235 */
211         { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
212         /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
213         { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
214         /* Crystal 3D - CS4237B */
215         { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
216         /* Typhoon Soundsystem PnP - CS4236B */
217         { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
218         /* Crystal CX4235-XQ3 EP - CS4235 */
219         { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
220         /* Crystal Semiconductors CS4237B */
221         { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
222         /* NewClear 3D - CX4237B-XQ3 */
223         { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
224         /* Dell Optiplex GX1 - CS4236B */
225         { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
226         /* Dell P410 motherboard - CS4236B */
227         { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
228         /* Dell Workstation 400 Onboard - CS4236B */
229         { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
230         /* Turtle Beach Malibu - CS4237B */
231         { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
232         /* CS4235 - onboard */
233         { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
234         /* IBM Aptiva 2137 E24 Onboard - CS4237B */
235         { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
236         /* IBM IntelliStation M Pro motherboard */
237         { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
238         /* Guillemot MaxiSound 16 PnP - CS4236B */
239         { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
240         /* Gallant SC-70P */
241         { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
242         /* TerraTec AudioSystem EWS64XL - CS4236B */
243         { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
244         /* TerraTec AudioSystem EWS64XL - CS4236B */
245         { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
246         /* ACER AW37/Pro - CS4235 */
247         { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
248         /* ACER AW35/Pro - CS4237B */
249         { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
250         /* CS4235 without MPU401 */
251         { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
252         /* Unknown SiS530 - CS4235 */
253         { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
254         /* IBM IntelliStation M Pro 6898 11U - CS4236B */
255         { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
256         /* IBM PC 300PL Onboard - CS4236B */
257         { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
258         /* Some noname CS4236 based card */
259         { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
260         /* CS4236B */
261         { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
262         /* CS4236B */
263         { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
264         /* --- */
265         { .id = "" }    /* end */
266 };
267 #endif
268
269 MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
270
271 /* WSS initialization */
272 static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev)
273 {
274         if (pnp_activate_dev(pdev) < 0) {
275                 printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
276                 return -EBUSY;
277         }
278         port[dev] = pnp_port_start(pdev, 0);
279         if (fm_port[dev] > 0)
280                 fm_port[dev] = pnp_port_start(pdev, 1);
281         sb_port[dev] = pnp_port_start(pdev, 2);
282         irq[dev] = pnp_irq(pdev, 0);
283         dma1[dev] = pnp_dma(pdev, 0);
284         dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
285         snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
286                         port[dev], fm_port[dev], sb_port[dev]);
287         snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
288                         irq[dev], dma1[dev], dma2[dev]);
289         return 0;
290 }
291
292 /* CTRL initialization */
293 static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev)
294 {
295         if (pnp_activate_dev(pdev) < 0) {
296                 printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
297                 return -EBUSY;
298         }
299         cport[dev] = pnp_port_start(pdev, 0);
300         snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
301         return 0;
302 }
303
304 /* MPU initialization */
305 static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev)
306 {
307         if (pnp_activate_dev(pdev) < 0) {
308                 printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
309                 mpu_port[dev] = SNDRV_AUTO_PORT;
310                 mpu_irq[dev] = SNDRV_AUTO_IRQ;
311         } else {
312                 mpu_port[dev] = pnp_port_start(pdev, 0);
313                 if (mpu_irq[dev] >= 0 &&
314                     pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
315                         mpu_irq[dev] = pnp_irq(pdev, 0);
316                 } else {
317                         mpu_irq[dev] = -1;      /* disable interrupt */
318                 }
319         }
320         snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
321         return 0;
322 }
323
324 #ifdef CS4232
325 static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard,
326                                          struct pnp_dev *pdev)
327 {
328         acard->wss = pdev;
329         if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
330                 return -EBUSY;
331         cport[dev] = -1;
332         return 0;
333 }
334 #endif
335
336 static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
337                                           struct pnp_card_link *card,
338                                           const struct pnp_card_device_id *id)
339 {
340         acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
341         if (acard->wss == NULL)
342                 return -EBUSY;
343         acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
344         if (acard->ctrl == NULL)
345                 return -EBUSY;
346         if (id->devs[2].id[0]) {
347                 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
348                 if (acard->mpu == NULL)
349                         return -EBUSY;
350         }
351
352         /* WSS initialization */
353         if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
354                 return -EBUSY;
355
356         /* CTRL initialization */
357         if (acard->ctrl && cport[dev] > 0) {
358                 if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
359                         return -EBUSY;
360         }
361         /* MPU initialization */
362         if (acard->mpu && mpu_port[dev] > 0) {
363                 if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
364                         return -EBUSY;
365         }
366         return 0;
367 }
368 #endif /* CONFIG_PNP */
369
370 #ifdef CONFIG_PNP
371 #define is_isapnp_selected(dev)         isapnp[dev]
372 #else
373 #define is_isapnp_selected(dev)         0
374 #endif
375
376 static void snd_card_cs4236_free(struct snd_card *card)
377 {
378         struct snd_card_cs4236 *acard = card->private_data;
379
380         release_and_free_resource(acard->res_sb_port);
381 }
382
383 static struct snd_card *snd_cs423x_card_new(int dev)
384 {
385         struct snd_card *card;
386
387         card = snd_card_new(index[dev], id[dev], THIS_MODULE,
388                             sizeof(struct snd_card_cs4236));
389         if (card == NULL)
390                 return NULL;
391         card->private_free = snd_card_cs4236_free;
392         return card;
393 }
394
395 static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
396 {
397         struct snd_card_cs4236 *acard;
398         struct snd_pcm *pcm;
399         struct snd_wss *chip;
400         struct snd_opl3 *opl3;
401         int err;
402
403         acard = card->private_data;
404         if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
405                 if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
406                         printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
407                         return -EBUSY;
408                 }
409
410 #ifdef CS4232
411         err = snd_wss_create(card, port[dev], cport[dev],
412                              irq[dev],
413                              dma1[dev], dma2[dev],
414                              WSS_HW_DETECT, 0, &chip);
415         if (err < 0)
416                 return err;
417         acard->chip = chip;
418
419         err = snd_wss_pcm(chip, 0, &pcm);
420         if (err < 0)
421                 return err;
422
423         err = snd_wss_mixer(chip);
424         if (err < 0)
425                 return err;
426
427 #else /* CS4236 */
428         err = snd_cs4236_create(card,
429                                 port[dev], cport[dev],
430                                 irq[dev], dma1[dev], dma2[dev],
431                                 WSS_HW_DETECT, 0, &chip);
432         if (err < 0)
433                 return err;
434         acard->chip = chip;
435
436         err = snd_cs4236_pcm(chip, 0, &pcm);
437         if (err < 0)
438                 return err;
439
440         err = snd_cs4236_mixer(chip);
441         if (err < 0)
442                 return err;
443 #endif
444         strcpy(card->driver, pcm->name);
445         strcpy(card->shortname, pcm->name);
446         sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
447                 pcm->name,
448                 chip->port,
449                 irq[dev],
450                 dma1[dev]);
451         if (dma2[dev] >= 0)
452                 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
453
454         err = snd_wss_timer(chip, 0, NULL);
455         if (err < 0)
456                 return err;
457
458         if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
459                 if (snd_opl3_create(card,
460                                     fm_port[dev], fm_port[dev] + 2,
461                                     OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
462                         printk(KERN_WARNING IDENT ": OPL3 not detected\n");
463                 } else {
464                         if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
465                                 return err;
466                 }
467         }
468
469         if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
470                 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
471                         mpu_irq[dev] = -1;
472                 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
473                                         mpu_port[dev], 0,
474                                         mpu_irq[dev],
475                                         mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
476                         printk(KERN_WARNING IDENT ": MPU401 not detected\n");
477         }
478
479         return snd_card_register(card);
480 }
481
482 static int __devinit snd_cs423x_isa_match(struct device *pdev,
483                                           unsigned int dev)
484 {
485         if (!enable[dev] || is_isapnp_selected(dev))
486                 return 0;
487
488         if (port[dev] == SNDRV_AUTO_PORT) {
489                 snd_printk(KERN_ERR "%s: please specify port\n", pdev->bus_id);
490                 return 0;
491         }
492         if (cport[dev] == SNDRV_AUTO_PORT) {
493                 snd_printk(KERN_ERR "%s: please specify cport\n", pdev->bus_id);
494                 return 0;
495         }
496         if (irq[dev] == SNDRV_AUTO_IRQ) {
497                 snd_printk(KERN_ERR "%s: please specify irq\n", pdev->bus_id);
498                 return 0;
499         }
500         if (dma1[dev] == SNDRV_AUTO_DMA) {
501                 snd_printk(KERN_ERR "%s: please specify dma1\n", pdev->bus_id);
502                 return 0;
503         }
504         return 1;
505 }
506
507 static int __devinit snd_cs423x_isa_probe(struct device *pdev,
508                                           unsigned int dev)
509 {
510         struct snd_card *card;
511         int err;
512
513         card = snd_cs423x_card_new(dev);
514         if (! card)
515                 return -ENOMEM;
516         snd_card_set_dev(card, pdev);
517         if ((err = snd_cs423x_probe(card, dev)) < 0) {
518                 snd_card_free(card);
519                 return err;
520         }
521
522         dev_set_drvdata(pdev, card);
523         return 0;
524 }
525
526 static int __devexit snd_cs423x_isa_remove(struct device *pdev,
527                                            unsigned int dev)
528 {
529         snd_card_free(dev_get_drvdata(pdev));
530         dev_set_drvdata(pdev, NULL);
531         return 0;
532 }
533
534 #ifdef CONFIG_PM
535 static int snd_cs423x_suspend(struct snd_card *card)
536 {
537         struct snd_card_cs4236 *acard = card->private_data;
538         snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
539         acard->chip->suspend(acard->chip);
540         return 0;
541 }
542
543 static int snd_cs423x_resume(struct snd_card *card)
544 {
545         struct snd_card_cs4236 *acard = card->private_data;
546         acard->chip->resume(acard->chip);
547         snd_power_change_state(card, SNDRV_CTL_POWER_D0);
548         return 0;
549 }
550
551 static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
552                                   pm_message_t state)
553 {
554         return snd_cs423x_suspend(dev_get_drvdata(dev));
555 }
556
557 static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
558 {
559         return snd_cs423x_resume(dev_get_drvdata(dev));
560 }
561 #endif
562
563 static struct isa_driver cs423x_isa_driver = {
564         .match          = snd_cs423x_isa_match,
565         .probe          = snd_cs423x_isa_probe,
566         .remove         = __devexit_p(snd_cs423x_isa_remove),
567 #ifdef CONFIG_PM
568         .suspend        = snd_cs423x_isa_suspend,
569         .resume         = snd_cs423x_isa_resume,
570 #endif
571         .driver         = {
572                 .name   = DEV_NAME
573         },
574 };
575
576
577 #ifdef CONFIG_PNP
578 #ifdef CS4232
579 static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
580                                                const struct pnp_device_id *id)
581 {
582         static int dev;
583         int err;
584         struct snd_card *card;
585
586         if (pnp_device_is_isapnp(pdev))
587                 return -ENOENT; /* we have another procedure - card */
588         for (; dev < SNDRV_CARDS; dev++) {
589                 if (enable[dev] && isapnp[dev])
590                         break;
591         }
592         if (dev >= SNDRV_CARDS)
593                 return -ENODEV;
594
595         card = snd_cs423x_card_new(dev);
596         if (! card)
597                 return -ENOMEM;
598         if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
599                 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
600                 snd_card_free(card);
601                 return err;
602         }
603         snd_card_set_dev(card, &pdev->dev);
604         if ((err = snd_cs423x_probe(card, dev)) < 0) {
605                 snd_card_free(card);
606                 return err;
607         }
608         pnp_set_drvdata(pdev, card);
609         dev++;
610         return 0;
611 }
612
613 static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
614 {
615         snd_card_free(pnp_get_drvdata(pdev));
616         pnp_set_drvdata(pdev, NULL);
617 }
618
619 #ifdef CONFIG_PM
620 static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
621 {
622         return snd_cs423x_suspend(pnp_get_drvdata(pdev));
623 }
624
625 static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
626 {
627         return snd_cs423x_resume(pnp_get_drvdata(pdev));
628 }
629 #endif
630
631 static struct pnp_driver cs4232_pnp_driver = {
632         .name = "cs4232-pnpbios",
633         .id_table = snd_cs4232_pnpbiosids,
634         .probe = snd_cs4232_pnpbios_detect,
635         .remove = __devexit_p(snd_cs4232_pnp_remove),
636 #ifdef CONFIG_PM
637         .suspend        = snd_cs4232_pnp_suspend,
638         .resume         = snd_cs4232_pnp_resume,
639 #endif
640 };
641 #endif /* CS4232 */
642
643 static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
644                                             const struct pnp_card_device_id *pid)
645 {
646         static int dev;
647         struct snd_card *card;
648         int res;
649
650         for ( ; dev < SNDRV_CARDS; dev++) {
651                 if (enable[dev] && isapnp[dev])
652                         break;
653         }
654         if (dev >= SNDRV_CARDS)
655                 return -ENODEV;
656
657         card = snd_cs423x_card_new(dev);
658         if (! card)
659                 return -ENOMEM;
660         if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
661                 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
662                        " is not supported\n");
663                 snd_card_free(card);
664                 return res;
665         }
666         snd_card_set_dev(card, &pcard->card->dev);
667         if ((res = snd_cs423x_probe(card, dev)) < 0) {
668                 snd_card_free(card);
669                 return res;
670         }
671         pnp_set_card_drvdata(pcard, card);
672         dev++;
673         return 0;
674 }
675
676 static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
677 {
678         snd_card_free(pnp_get_card_drvdata(pcard));
679         pnp_set_card_drvdata(pcard, NULL);
680 }
681
682 #ifdef CONFIG_PM
683 static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
684 {
685         return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
686 }
687
688 static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
689 {
690         return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
691 }
692 #endif
693
694 static struct pnp_card_driver cs423x_pnpc_driver = {
695         .flags = PNP_DRIVER_RES_DISABLE,
696         .name = CS423X_ISAPNP_DRIVER,
697         .id_table = snd_cs423x_pnpids,
698         .probe = snd_cs423x_pnpc_detect,
699         .remove = __devexit_p(snd_cs423x_pnpc_remove),
700 #ifdef CONFIG_PM
701         .suspend        = snd_cs423x_pnpc_suspend,
702         .resume         = snd_cs423x_pnpc_resume,
703 #endif
704 };
705 #endif /* CONFIG_PNP */
706
707 static int __init alsa_card_cs423x_init(void)
708 {
709         int err;
710
711         err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
712 #ifdef CONFIG_PNP
713         if (!err)
714                 isa_registered = 1;
715 #ifdef CS4232
716         err = pnp_register_driver(&cs4232_pnp_driver);
717         if (!err)
718                 pnp_registered = 1;
719 #endif
720         err = pnp_register_card_driver(&cs423x_pnpc_driver);
721         if (!err)
722                 pnpc_registered = 1;
723 #ifdef CS4232
724         if (pnp_registered)
725                 err = 0;
726 #endif
727         if (isa_registered)
728                 err = 0;
729 #endif
730         return err;
731 }
732
733 static void __exit alsa_card_cs423x_exit(void)
734 {
735 #ifdef CONFIG_PNP
736         if (pnpc_registered)
737                 pnp_unregister_card_driver(&cs423x_pnpc_driver);
738 #ifdef CS4232
739         if (pnp_registered)
740                 pnp_unregister_driver(&cs4232_pnp_driver);
741 #endif
742         if (isa_registered)
743 #endif
744                 isa_unregister_driver(&cs423x_isa_driver);
745 }
746
747 module_init(alsa_card_cs423x_init)
748 module_exit(alsa_card_cs423x_exit)