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