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