vserver 1.9.3
[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@suse.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 <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/slab.h>
25 #include <linux/pnp.h>
26 #include <linux/moduleparam.h>
27 #include <sound/core.h>
28 #include <sound/cs4231.h>
29 #include <sound/mpu401.h>
30 #include <sound/opl3.h>
31 #include <sound/initval.h>
32
33 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
34 MODULE_LICENSE("GPL");
35 #ifdef CS4232
36 MODULE_DESCRIPTION("Cirrus Logic CS4232");
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 #else
44 MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
45 MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
46                 "{Crystal Semiconductors,CS4236},"
47                 "{Crystal Semiconductors,CS4237},"
48                 "{Crystal Semiconductors,CS4238},"
49                 "{Crystal Semiconductors,CS4239},"
50                 "{Acer,AW37},"
51                 "{Acer,AW35/Pro},"
52                 "{Crystal,3D},"
53                 "{Crystal Computer,TidalWave128},"
54                 "{Dell,Optiplex GX1},"
55                 "{Dell,Workstation 400 sound},"
56                 "{EliteGroup,P5TX-LA sound},"
57                 "{Gallant,SC-70P},"
58                 "{Gateway,E1000 Onboard CS4236B},"
59                 "{Genius,Sound Maker 3DJ},"
60                 "{Hewlett Packard,HP6330 sound},"
61                 "{IBM,PC 300PL sound},"
62                 "{IBM,Aptiva 2137 E24},"
63                 "{IBM,IntelliStation M Pro},"
64                 "{Intel,Marlin Spike Mobo CS4235},"
65                 "{Intel PR440FX Onboard},"
66                 "{Guillemot,MaxiSound 16 PnP},"
67                 "{NewClear,3D},"
68                 "{TerraTec,AudioSystem EWS64L/XL},"
69                 "{Typhoon Soundsystem,CS4236B},"
70                 "{Turtle Beach,Malibu},"
71                 "{Unknown,Digital PC 5000 Onboard}}");
72 #endif
73
74 #ifdef CS4232
75 #define IDENT "CS4232"
76 #else
77 #define IDENT "CS4236+"
78 #endif
79
80 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
81 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
82 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
83 #ifdef CONFIG_PNP
84 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
85 #endif
86 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;     /* PnP setup */
87 static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;    /* PnP setup */
88 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
89 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;  /* PnP setup */
90 static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;  /* PnP setup */
91 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;        /* 5,7,9,11,12,15 */
92 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;    /* 9,11,12,15 */
93 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* 0,1,3,5,6,7 */
94 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;       /* 0,1,3,5,6,7 */
95 static int boot_devs;
96
97 module_param_array(index, int, boot_devs, 0444);
98 MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
99 module_param_array(id, charp, boot_devs, 0444);
100 MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
101 module_param_array(enable, bool, boot_devs, 0444);
102 MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
103 #ifdef CONFIG_PNP
104 module_param_array(isapnp, bool, boot_devs, 0444);
105 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
106 #endif
107 module_param_array(port, long, boot_devs, 0444);
108 MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
109 module_param_array(cport, long, boot_devs, 0444);
110 MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
111 module_param_array(mpu_port, long, boot_devs, 0444);
112 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
113 module_param_array(fm_port, long, boot_devs, 0444);
114 MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
115 module_param_array(sb_port, long, boot_devs, 0444);
116 MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
117 module_param_array(irq, int, boot_devs, 0444);
118 MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
119 module_param_array(mpu_irq, int, boot_devs, 0444);
120 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
121 module_param_array(dma1, int, boot_devs, 0444);
122 MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
123 module_param_array(dma2, int, boot_devs, 0444);
124 MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
125
126 struct snd_card_cs4236 {
127         struct resource *res_sb_port;
128 #ifdef CONFIG_PNP
129         struct pnp_dev *wss;
130         struct pnp_dev *ctrl;
131         struct pnp_dev *mpu;
132 #endif
133 };
134
135 static snd_card_t *snd_cs4236_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
136
137 #ifdef CONFIG_PNP
138
139 #define ISAPNP_CS4232(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \
140         { \
141                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
142                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
143                           ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \
144                           ISAPNP_DEVICE_ID(_va, _vb, _vc, _mpu401) } \
145         }
146 #define ISAPNP_CS4232_1(_va, _vb, _vc, _device, _wss, _ctrl, _mpu401) \
147         { \
148                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
149                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
150                           ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl), \
151                           ISAPNP_DEVICE_ID('P', 'N', 'P', _mpu401) } \
152         }
153 #define ISAPNP_CS4232_WOMPU(_va, _vb, _vc, _device, _wss, _ctrl) \
154         { \
155                 ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
156                 .devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _wss), \
157                           ISAPNP_DEVICE_ID(_va, _vb, _vc, _ctrl) } \
158         }
159
160
161 #ifdef CS4232
162 static struct pnp_card_device_id snd_cs423x_pnpids[] = {
163         /* Philips PCA70PS */
164         { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
165         /* TerraTec Maestro 32/96 (CS4232) */
166         { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
167         /* HP Omnibook 5500 onboard */
168         { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
169         /* Unnamed CS4236 card (Made in Taiwan) */
170         { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
171         /* Turtle Beach TBS-2000 (CS4232) */
172         { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
173         /* Turtle Beach Tropez Plus (CS4232) */
174         { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
175         /* SIC CrystalWave 32 (CS4232) */
176         { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
177         /* --- */
178         { .id = "" }    /* end */
179 };
180 #else /* CS4236 */
181 static struct pnp_card_device_id snd_cs423x_pnpids[] = {
182         /* Intel Marlin Spike Motherboard - CS4235 */
183         { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
184         /* Intel Marlin Spike Motherboard (#2) - CS4235 */
185         { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
186         /* Unknown Intel mainboard - CS4235 */
187         { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
188         /* Genius Sound Maker 3DJ - CS4237B */
189         { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
190         /* Digital PC 5000 Onboard - CS4236B */
191         { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
192         /* some uknown CS4236B */
193         { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
194         /* Intel PR440FX Onboard sound */
195         { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
196         /* CS4235 on mainboard without MPU */
197         { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
198         /* Gateway E1000 Onboard CS4236B */
199         { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
200         /* HP 6330 Onboard sound */
201         { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
202         /* Crystal Computer TidalWave128 */
203         { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
204         /* ACER AW37 - CS4235 */
205         { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
206         /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
207         { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
208         /* Crystal 3D - CS4237B */
209         { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
210         /* Typhoon Soundsystem PnP - CS4236B */
211         { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
212         /* Crystal CX4235-XQ3 EP - CS4235 */
213         { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
214         /* Crystal Semiconductors CS4237B */
215         { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
216         /* NewClear 3D - CX4237B-XQ3 */
217         { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
218         /* Dell Optiplex GX1 - CS4236B */
219         { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
220         /* Dell P410 motherboard - CS4236B */
221         { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
222         /* Dell Workstation 400 Onboard - CS4236B */
223         { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
224         /* Turtle Beach Malibu - CS4237B */
225         { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
226         /* CS4235 - onboard */
227         { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
228         /* IBM Aptiva 2137 E24 Onboard - CS4237B */
229         { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
230         /* IBM IntelliStation M Pro motherboard */
231         { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
232         /* Guillemot MaxiSound 16 PnP - CS4236B */
233         { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
234         /* Gallant SC-70P */
235         { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
236         /* TerraTec AudioSystem EWS64XL - CS4236B */
237         { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
238         /* TerraTec AudioSystem EWS64XL - CS4236B */
239         { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
240         /* ACER AW37/Pro - CS4235 */
241         { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
242         /* ACER AW35/Pro - CS4237B */
243         { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
244         /* CS4235 without MPU401 */
245         { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
246         /* IBM IntelliStation M Pro 6898 11U - CS4236B */
247         { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
248         /* IBM PC 300PL Onboard - CS4236B */
249         { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
250         /* Some noname CS4236 based card */
251         { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
252         /* CS4236B */
253         { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
254         /* CS4236B */
255         { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
256         /* --- */
257         { .id = "" }    /* end */
258 };
259 #endif
260
261 MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
262
263 static int __devinit snd_card_cs4236_pnp(int dev, struct snd_card_cs4236 *acard,
264                                          struct pnp_card_link *card,
265                                          const struct pnp_card_device_id *id)
266 {
267         struct pnp_dev *pdev;
268         struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
269         int err;
270
271         if (!cfg)
272                 return -ENOMEM;
273
274         acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
275         if (acard->wss == NULL) {
276                 kfree(cfg);
277                 return -EBUSY;
278         }
279         acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
280         if (acard->ctrl == NULL) {
281                 kfree(cfg);
282                 return -EBUSY;
283         }
284         if (id->devs[2].id[0]) {
285                 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
286                 if (acard->mpu == NULL) {
287                         kfree(cfg);
288                         return -EBUSY;
289                 }
290         }
291
292         /* WSS initialization */
293         pdev = acard->wss;
294         pnp_init_resource_table(cfg);
295         if (port[dev] != SNDRV_AUTO_PORT)
296                 pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
297         if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0)
298                 pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
299         if (sb_port[dev] != SNDRV_AUTO_PORT)
300                 pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
301         if (irq[dev] != SNDRV_AUTO_IRQ)
302                 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
303         if (dma1[dev] != SNDRV_AUTO_DMA)
304                 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
305         if (dma2[dev] != SNDRV_AUTO_DMA)
306                 pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
307         err = pnp_manual_config_dev(pdev, cfg, 0);
308         if (err < 0)
309                 snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
310         err = pnp_activate_dev(pdev);
311         if (err < 0) {
312                 kfree(cfg);
313                 printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
314                 return -EBUSY;
315         }
316         port[dev] = pnp_port_start(pdev, 0);
317         if (fm_port[dev] > 0)
318                 fm_port[dev] = pnp_port_start(pdev, 1);
319         sb_port[dev] = pnp_port_start(pdev, 2);
320         irq[dev] = pnp_irq(pdev, 0);
321         dma1[dev] = pnp_dma(pdev, 0);
322         dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
323         snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
324                         port[dev], fm_port[dev], sb_port[dev]);
325         snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
326                         irq[dev], dma1[dev], dma2[dev]);
327         /* CTRL initialization */
328         if (acard->ctrl && cport[dev] > 0) {
329                 pdev = acard->ctrl;
330                 pnp_init_resource_table(cfg);
331                 if (cport[dev] != SNDRV_AUTO_PORT)
332                         pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
333                 err = pnp_manual_config_dev(pdev, cfg, 0);
334                 if (err < 0)
335                         snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
336                 err = pnp_activate_dev(pdev);
337                 if (err < 0) {
338                         kfree(cfg);
339                         printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
340                         return -EBUSY;
341                 }
342                 cport[dev] = pnp_port_start(pdev, 0);
343                 snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
344         }
345         /* MPU initialization */
346         if (acard->mpu && mpu_port[dev] > 0) {
347                 pdev = acard->mpu;
348                 pnp_init_resource_table(cfg);
349                 if (mpu_port[dev] != SNDRV_AUTO_PORT)
350                         pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
351                 if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0 &&
352                     pnp_irq_valid(pdev, 0))
353                         pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
354                 err = pnp_manual_config_dev(pdev, cfg, 0);
355                 if (err < 0)
356                         snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
357                 err = pnp_activate_dev(pdev);
358                 if (err < 0) {
359                         printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
360                         mpu_port[dev] = SNDRV_AUTO_PORT;
361                         mpu_irq[dev] = SNDRV_AUTO_IRQ;
362                 } else {
363                         mpu_port[dev] = pnp_port_start(pdev, 0);
364                         if (mpu_irq[dev] >= 0 &&
365                             pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
366                                 mpu_irq[dev] = pnp_irq(pdev, 0);
367                         } else {
368                                 mpu_irq[dev] = -1;      /* disable interrupt */
369                         }
370                 }
371                 snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
372         }
373         kfree(cfg);
374         return 0;
375 }
376 #endif /* CONFIG_PNP */
377
378 static void snd_card_cs4236_free(snd_card_t *card)
379 {
380         struct snd_card_cs4236 *acard = (struct snd_card_cs4236 *)card->private_data;
381
382         if (acard) {
383                 if (acard->res_sb_port) {
384                         release_resource(acard->res_sb_port);
385                         kfree_nocheck(acard->res_sb_port);
386                 }
387         }
388 }
389
390 static int __devinit snd_card_cs423x_probe(int dev, struct pnp_card_link *pcard,
391                                            const struct pnp_card_device_id *pid)
392 {
393         snd_card_t *card;
394         struct snd_card_cs4236 *acard;
395         snd_pcm_t *pcm = NULL;
396         cs4231_t *chip;
397         opl3_t *opl3;
398         int err;
399
400 #ifdef CONFIG_PNP
401         if (!isapnp[dev]) {
402 #endif
403                 if (port[dev] == SNDRV_AUTO_PORT) {
404                         snd_printk("specify port\n");
405                         return -EINVAL;
406                 }
407                 if (cport[dev] == SNDRV_AUTO_PORT) {
408                         snd_printk("specify cport\n");
409                         return -EINVAL;
410                 }
411 #ifdef CONFIG_PNP
412         }
413 #endif
414         card = snd_card_new(index[dev], id[dev], THIS_MODULE,
415                             sizeof(struct snd_card_cs4236));
416         if (card == NULL)
417                 return -ENOMEM;
418         acard = (struct snd_card_cs4236 *)card->private_data;
419         card->private_free = snd_card_cs4236_free;
420 #ifdef CONFIG_PNP
421         if (isapnp[dev]) {
422                 if ((err = snd_card_cs4236_pnp(dev, acard, pcard, pid))<0) {
423                         printk(KERN_ERR "isapnp detection failed and probing for " IDENT " is not supported\n");
424                         snd_card_free(card);
425                         return -ENXIO;
426                 }
427                 snd_card_set_dev(card, &pcard->card->dev);
428         }
429 #endif
430         if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
431                 if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
432                         printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
433                         snd_card_free(card);
434                         return -ENOMEM;
435                 }
436
437 #ifdef CS4232
438         if ((err = snd_cs4231_create(card,
439                                      port[dev],
440                                      cport[dev],
441                                      irq[dev],
442                                      dma1[dev],
443                                      dma2[dev],
444                                      CS4231_HW_DETECT,
445                                      0,
446                                      &chip)) < 0) {
447                 snd_card_free(card);
448                 return err;
449         }
450         if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0) {
451                 snd_card_free(card);
452                 return err;
453         }
454         if ((err = snd_cs4231_mixer(chip)) < 0) {
455                 snd_card_free(card);
456                 return err;
457         }
458
459 #else /* CS4236 */
460         if ((err = snd_cs4236_create(card,
461                                      port[dev],
462                                      cport[dev],
463                                      irq[dev],
464                                      dma1[dev],
465                                      dma2[dev],
466                                      CS4231_HW_DETECT,
467                                      0,
468                                      &chip)) < 0) {
469                 snd_card_free(card);
470                 return err;
471         }
472         if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0) {
473                 snd_card_free(card);
474                 return err;
475         }
476         if ((err = snd_cs4236_mixer(chip)) < 0) {
477                 snd_card_free(card);
478                 return err;
479         }
480 #endif
481         strcpy(card->driver, pcm->name);
482         strcpy(card->shortname, pcm->name);
483         sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
484                 pcm->name,
485                 chip->port,
486                 irq[dev],
487                 dma1[dev]);
488         if (dma2[dev] >= 0)
489                 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
490
491         if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0) {
492                 snd_card_free(card);
493                 return err;
494         }
495
496         if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
497                 if (snd_opl3_create(card,
498                                     fm_port[dev], fm_port[dev] + 2,
499                                     OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
500                         printk(KERN_ERR IDENT ": OPL3 not detected\n");
501                 } else {
502                         if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
503                                 snd_card_free(card);
504                                 return err;
505                         }
506                 }
507         }
508
509         if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
510                 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
511                         mpu_irq[dev] = -1;
512                 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
513                                         mpu_port[dev], 0,
514                                         mpu_irq[dev],
515                                         mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0)
516                         printk(KERN_ERR IDENT ": MPU401 not detected\n");
517         }
518         if ((err = snd_card_register(card)) < 0) {
519                 snd_card_free(card);
520                 return err;
521         }
522         if (pcard)
523                 pnp_set_card_drvdata(pcard, card);
524         else
525                 snd_cs4236_legacy[dev] = card;
526         return 0;
527 }
528
529 #ifdef CONFIG_PNP
530 static int __devinit snd_cs423x_pnp_detect(struct pnp_card_link *card,
531                                            const struct pnp_card_device_id *id)
532 {
533         static int dev;
534         int res;
535
536         for ( ; dev < SNDRV_CARDS; dev++) {
537                 if (!enable[dev] || !isapnp[dev])
538                         continue;
539                 res = snd_card_cs423x_probe(dev, card, id);
540                 if (res < 0)
541                         return res;
542                 dev++;
543                 return 0;
544         }
545         return -ENODEV;
546 }
547
548 static void __devexit snd_cs423x_pnp_remove(struct pnp_card_link * pcard)
549 {
550         snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
551         
552         snd_card_disconnect(card);
553         snd_card_free_in_thread(card);
554 }
555                         
556 static struct pnp_card_driver cs423x_pnpc_driver = {
557         .flags = PNP_DRIVER_RES_DISABLE,
558         .name = "cs423x",
559         .id_table = snd_cs423x_pnpids,
560         .probe = snd_cs423x_pnp_detect,
561         .remove = __devexit_p(snd_cs423x_pnp_remove),
562 };
563 #endif /* CONFIG_PNP */
564
565 static int __init alsa_card_cs423x_init(void)
566 {
567         int dev, cards = 0;
568
569         for (dev = 0; dev < SNDRV_CARDS; dev++) {
570                 if (!enable[dev])
571                         continue;
572 #ifdef CONFIG_PNP
573                 if (isapnp[dev])
574                         continue;
575 #endif
576                 if (snd_card_cs423x_probe(dev, NULL, NULL) >= 0)
577                         cards++;
578         }
579 #ifdef CONFIG_PNP
580         cards += pnp_register_card_driver(&cs423x_pnpc_driver);
581 #endif
582         if (!cards) {
583 #ifdef CONFIG_PNP
584                 pnp_unregister_card_driver(&cs423x_pnpc_driver);
585 #endif
586 #ifdef MODULE
587                 printk(KERN_ERR IDENT " soundcard not found or device busy\n");
588 #endif
589                 return -ENODEV;
590         }
591         return 0;
592 }
593
594 static void __exit alsa_card_cs423x_exit(void)
595 {
596         int idx;
597
598 #ifdef CONFIG_PNP
599         /* PnP cards first */
600         pnp_unregister_card_driver(&cs423x_pnpc_driver);
601 #endif
602         for (idx = 0; idx < SNDRV_CARDS; idx++)
603                 snd_card_free(snd_cs4236_legacy[idx]);
604 }
605
606 module_init(alsa_card_cs423x_init)
607 module_exit(alsa_card_cs423x_exit)