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