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