tree-wide: fix assorted typos all over the place
[linux-2.6.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_wss_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         if (chip->hardware & WSS_HW_CS4236B_MASK) {
404                 snd_wss_free(chip);
405                 err = snd_cs4236_create(card,
406                                         port[dev], cport[dev],
407                                         irq[dev], dma1[dev], dma2[dev],
408                                         WSS_HW_DETECT, 0, &chip);
409                 if (err < 0)
410                         return err;
411                 acard->chip = chip;
412
413                 err = snd_cs4236_pcm(chip, 0, &pcm);
414                 if (err < 0)
415                         return err;
416
417                 err = snd_cs4236_mixer(chip);
418                 if (err < 0)
419                         return err;
420         } else {
421                 acard->chip = chip;
422                 err = snd_wss_pcm(chip, 0, &pcm);
423                 if (err < 0)
424                         return err;
425
426                 err = snd_wss_mixer(chip);
427                 if (err < 0)
428                         return err;
429         }
430         strcpy(card->driver, pcm->name);
431         strcpy(card->shortname, pcm->name);
432         sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
433                 pcm->name,
434                 chip->port,
435                 irq[dev],
436                 dma1[dev]);
437         if (dma2[dev] >= 0)
438                 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
439
440         err = snd_wss_timer(chip, 0, NULL);
441         if (err < 0)
442                 return err;
443
444         if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
445                 if (snd_opl3_create(card,
446                                     fm_port[dev], fm_port[dev] + 2,
447                                     OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
448                         printk(KERN_WARNING IDENT ": OPL3 not detected\n");
449                 } else {
450                         if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
451                                 return err;
452                 }
453         }
454
455         if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
456                 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
457                         mpu_irq[dev] = -1;
458                 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
459                                         mpu_port[dev], 0,
460                                         mpu_irq[dev],
461                                         mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
462                         printk(KERN_WARNING IDENT ": MPU401 not detected\n");
463         }
464
465         return snd_card_register(card);
466 }
467
468 static int __devinit snd_cs423x_isa_match(struct device *pdev,
469                                           unsigned int dev)
470 {
471         if (!enable[dev] || is_isapnp_selected(dev))
472                 return 0;
473
474         if (port[dev] == SNDRV_AUTO_PORT) {
475                 dev_err(pdev, "please specify port\n");
476                 return 0;
477         }
478         if (cport[dev] == SNDRV_AUTO_PORT) {
479                 dev_err(pdev, "please specify cport\n");
480                 return 0;
481         }
482         if (irq[dev] == SNDRV_AUTO_IRQ) {
483                 dev_err(pdev, "please specify irq\n");
484                 return 0;
485         }
486         if (dma1[dev] == SNDRV_AUTO_DMA) {
487                 dev_err(pdev, "please specify dma1\n");
488                 return 0;
489         }
490         return 1;
491 }
492
493 static int __devinit snd_cs423x_isa_probe(struct device *pdev,
494                                           unsigned int dev)
495 {
496         struct snd_card *card;
497         int err;
498
499         err = snd_cs423x_card_new(dev, &card);
500         if (err < 0)
501                 return err;
502         snd_card_set_dev(card, pdev);
503         if ((err = snd_cs423x_probe(card, dev)) < 0) {
504                 snd_card_free(card);
505                 return err;
506         }
507
508         dev_set_drvdata(pdev, card);
509         return 0;
510 }
511
512 static int __devexit snd_cs423x_isa_remove(struct device *pdev,
513                                            unsigned int dev)
514 {
515         snd_card_free(dev_get_drvdata(pdev));
516         dev_set_drvdata(pdev, NULL);
517         return 0;
518 }
519
520 #ifdef CONFIG_PM
521 static int snd_cs423x_suspend(struct snd_card *card)
522 {
523         struct snd_card_cs4236 *acard = card->private_data;
524         snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
525         acard->chip->suspend(acard->chip);
526         return 0;
527 }
528
529 static int snd_cs423x_resume(struct snd_card *card)
530 {
531         struct snd_card_cs4236 *acard = card->private_data;
532         acard->chip->resume(acard->chip);
533         snd_power_change_state(card, SNDRV_CTL_POWER_D0);
534         return 0;
535 }
536
537 static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
538                                   pm_message_t state)
539 {
540         return snd_cs423x_suspend(dev_get_drvdata(dev));
541 }
542
543 static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
544 {
545         return snd_cs423x_resume(dev_get_drvdata(dev));
546 }
547 #endif
548
549 static struct isa_driver cs423x_isa_driver = {
550         .match          = snd_cs423x_isa_match,
551         .probe          = snd_cs423x_isa_probe,
552         .remove         = __devexit_p(snd_cs423x_isa_remove),
553 #ifdef CONFIG_PM
554         .suspend        = snd_cs423x_isa_suspend,
555         .resume         = snd_cs423x_isa_resume,
556 #endif
557         .driver         = {
558                 .name   = DEV_NAME
559         },
560 };
561
562
563 #ifdef CONFIG_PNP
564 static int __devinit snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
565                                                const struct pnp_device_id *id)
566 {
567         static int dev;
568         int err;
569         struct snd_card *card;
570         struct pnp_dev *cdev;
571         char cid[PNP_ID_LEN];
572
573         if (pnp_device_is_isapnp(pdev))
574                 return -ENOENT; /* we have another procedure - card */
575         for (; dev < SNDRV_CARDS; dev++) {
576                 if (enable[dev] && isapnp[dev])
577                         break;
578         }
579         if (dev >= SNDRV_CARDS)
580                 return -ENODEV;
581
582         /* prepare second id */
583         strcpy(cid, pdev->id[0].id);
584         cid[5] = '1';
585         cdev = NULL;
586         list_for_each_entry(cdev, &(pdev->protocol->devices), protocol_list) {
587                 if (!strcmp(cdev->id[0].id, cid))
588                         break;
589         }
590         err = snd_cs423x_card_new(dev, &card);
591         if (err < 0)
592                 return err;
593         err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
594         if (err < 0) {
595                 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
596                 snd_card_free(card);
597                 return err;
598         }
599         snd_card_set_dev(card, &pdev->dev);
600         if ((err = snd_cs423x_probe(card, dev)) < 0) {
601                 snd_card_free(card);
602                 return err;
603         }
604         pnp_set_drvdata(pdev, card);
605         dev++;
606         return 0;
607 }
608
609 static void __devexit snd_cs423x_pnp_remove(struct pnp_dev *pdev)
610 {
611         snd_card_free(pnp_get_drvdata(pdev));
612         pnp_set_drvdata(pdev, NULL);
613 }
614
615 #ifdef CONFIG_PM
616 static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
617 {
618         return snd_cs423x_suspend(pnp_get_drvdata(pdev));
619 }
620
621 static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
622 {
623         return snd_cs423x_resume(pnp_get_drvdata(pdev));
624 }
625 #endif
626
627 static struct pnp_driver cs423x_pnp_driver = {
628         .name = "cs423x-pnpbios",
629         .id_table = snd_cs423x_pnpbiosids,
630         .probe = snd_cs423x_pnpbios_detect,
631         .remove = __devexit_p(snd_cs423x_pnp_remove),
632 #ifdef CONFIG_PM
633         .suspend        = snd_cs423x_pnp_suspend,
634         .resume         = snd_cs423x_pnp_resume,
635 #endif
636 };
637
638 static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
639                                             const struct pnp_card_device_id *pid)
640 {
641         static int dev;
642         struct snd_card *card;
643         int res;
644
645         for ( ; dev < SNDRV_CARDS; dev++) {
646                 if (enable[dev] && isapnp[dev])
647                         break;
648         }
649         if (dev >= SNDRV_CARDS)
650                 return -ENODEV;
651
652         res = snd_cs423x_card_new(dev, &card);
653         if (res < 0)
654                 return res;
655         if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
656                 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
657                        " is not supported\n");
658                 snd_card_free(card);
659                 return res;
660         }
661         snd_card_set_dev(card, &pcard->card->dev);
662         if ((res = snd_cs423x_probe(card, dev)) < 0) {
663                 snd_card_free(card);
664                 return res;
665         }
666         pnp_set_card_drvdata(pcard, card);
667         dev++;
668         return 0;
669 }
670
671 static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
672 {
673         snd_card_free(pnp_get_card_drvdata(pcard));
674         pnp_set_card_drvdata(pcard, NULL);
675 }
676
677 #ifdef CONFIG_PM
678 static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
679 {
680         return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
681 }
682
683 static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
684 {
685         return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
686 }
687 #endif
688
689 static struct pnp_card_driver cs423x_pnpc_driver = {
690         .flags = PNP_DRIVER_RES_DISABLE,
691         .name = CS423X_ISAPNP_DRIVER,
692         .id_table = snd_cs423x_pnpids,
693         .probe = snd_cs423x_pnpc_detect,
694         .remove = __devexit_p(snd_cs423x_pnpc_remove),
695 #ifdef CONFIG_PM
696         .suspend        = snd_cs423x_pnpc_suspend,
697         .resume         = snd_cs423x_pnpc_resume,
698 #endif
699 };
700 #endif /* CONFIG_PNP */
701
702 static int __init alsa_card_cs423x_init(void)
703 {
704         int err;
705
706         err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
707 #ifdef CONFIG_PNP
708         if (!err)
709                 isa_registered = 1;
710         err = pnp_register_driver(&cs423x_pnp_driver);
711         if (!err)
712                 pnp_registered = 1;
713         err = pnp_register_card_driver(&cs423x_pnpc_driver);
714         if (!err)
715                 pnpc_registered = 1;
716         if (pnp_registered)
717                 err = 0;
718         if (isa_registered)
719                 err = 0;
720 #endif
721         return err;
722 }
723
724 static void __exit alsa_card_cs423x_exit(void)
725 {
726 #ifdef CONFIG_PNP
727         if (pnpc_registered)
728                 pnp_unregister_card_driver(&cs423x_pnpc_driver);
729         if (pnp_registered)
730                 pnp_unregister_driver(&cs423x_pnp_driver);
731         if (isa_registered)
732 #endif
733                 isa_unregister_driver(&cs423x_isa_driver);
734 }
735
736 module_init(alsa_card_cs423x_init)
737 module_exit(alsa_card_cs423x_exit)