1
2
3
4
5
6
7#include <linux/init.h>
8#include <linux/err.h>
9#include <linux/isa.h>
10#include <linux/pnp.h>
11#include <linux/module.h>
12#include <sound/core.h>
13#include <sound/wss.h>
14#include <sound/mpu401.h>
15#include <sound/opl3.h>
16#include <sound/initval.h>
17
18MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
19MODULE_LICENSE("GPL");
20MODULE_DESCRIPTION("Cirrus Logic CS4232-9");
21MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000},"
22 "{Turtle Beach,Tropez Plus},"
23 "{SIC CrystalWave 32},"
24 "{Hewlett Packard,Omnibook 5500},"
25 "{TerraTec,Maestro 32/96},"
26 "{Philips,PCA70PS}},"
27 "{{Crystal Semiconductors,CS4235},"
28 "{Crystal Semiconductors,CS4236},"
29 "{Crystal Semiconductors,CS4237},"
30 "{Crystal Semiconductors,CS4238},"
31 "{Crystal Semiconductors,CS4239},"
32 "{Acer,AW37},"
33 "{Acer,AW35/Pro},"
34 "{Crystal,3D},"
35 "{Crystal Computer,TidalWave128},"
36 "{Dell,Optiplex GX1},"
37 "{Dell,Workstation 400 sound},"
38 "{EliteGroup,P5TX-LA sound},"
39 "{Gallant,SC-70P},"
40 "{Gateway,E1000 Onboard CS4236B},"
41 "{Genius,Sound Maker 3DJ},"
42 "{Hewlett Packard,HP6330 sound},"
43 "{IBM,PC 300PL sound},"
44 "{IBM,Aptiva 2137 E24},"
45 "{IBM,IntelliStation M Pro},"
46 "{Intel,Marlin Spike Mobo CS4235},"
47 "{Intel PR440FX Onboard},"
48 "{Guillemot,MaxiSound 16 PnP},"
49 "{NewClear,3D},"
50 "{TerraTec,AudioSystem EWS64L/XL},"
51 "{Typhoon Soundsystem,CS4236B},"
52 "{Turtle Beach,Malibu},"
53 "{Unknown,Digital PC 5000 Onboard}}");
54
55MODULE_ALIAS("snd_cs4232");
56
57#define IDENT "CS4232+"
58#define DEV_NAME "cs4232+"
59
60static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
61static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
62static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP;
63#ifdef CONFIG_PNP
64static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
65#endif
66static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
67static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
68static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
69static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
70static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
71static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
72static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
73static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
74static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
75
76module_param_array(index, int, NULL, 0444);
77MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
78module_param_array(id, charp, NULL, 0444);
79MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
80module_param_array(enable, bool, NULL, 0444);
81MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
82#ifdef CONFIG_PNP
83module_param_array(isapnp, bool, NULL, 0444);
84MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
85#endif
86module_param_hw_array(port, long, ioport, NULL, 0444);
87MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
88module_param_hw_array(cport, long, ioport, NULL, 0444);
89MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
90module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
91MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
92module_param_hw_array(fm_port, long, ioport, NULL, 0444);
93MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
94module_param_hw_array(sb_port, long, ioport, NULL, 0444);
95MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
96module_param_hw_array(irq, int, irq, NULL, 0444);
97MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
98module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
99MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
100module_param_hw_array(dma1, int, dma, NULL, 0444);
101MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
102module_param_hw_array(dma2, int, dma, NULL, 0444);
103MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
104
105#ifdef CONFIG_PNP
106static int isa_registered;
107static int pnpc_registered;
108static int pnp_registered;
109#endif
110
111struct snd_card_cs4236 {
112 struct snd_wss *chip;
113 struct resource *res_sb_port;
114#ifdef CONFIG_PNP
115 struct pnp_dev *wss;
116 struct pnp_dev *ctrl;
117 struct pnp_dev *mpu;
118#endif
119};
120
121#ifdef CONFIG_PNP
122
123
124
125
126static const struct pnp_device_id snd_cs423x_pnpbiosids[] = {
127 { .id = "CSC0100" },
128 { .id = "CSC0000" },
129
130
131 { .id = "GIM0100" },
132 { .id = "" }
133};
134MODULE_DEVICE_TABLE(pnp, snd_cs423x_pnpbiosids);
135
136#define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
137static const struct pnp_card_device_id snd_cs423x_pnpids[] = {
138
139 { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
140
141 { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
142
143 { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
144
145 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
146
147 { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
148
149 { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
150
151 { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
152
153 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
154
155 { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
156
157 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
158
159 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
160
161 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
162
163 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
164
165 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
166
167 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
168
169 { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
170
171 { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
172
173 { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
174
175 { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
176
177 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
178
179 { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
180
181 { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
182
183 { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
184
185 { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
186
187 { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
188
189 { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
190
191 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
192
193 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
194
195 { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
196
197 { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
198
199 { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
200
201 { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
202
203 { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
204
205 { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
206
207 { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
208
209 { .id = "CSCa736", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
210
211 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
212
213 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
214
215 { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
216
217 { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
218
219 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
220
221 { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
222
223 { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
224
225 { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
226
227 { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
228
229 { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
230
231 { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
232
233 { .id = "" }
234};
235
236MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
237
238
239static int snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev)
240{
241 if (pnp_activate_dev(pdev) < 0) {
242 printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
243 return -EBUSY;
244 }
245 port[dev] = pnp_port_start(pdev, 0);
246 if (fm_port[dev] > 0)
247 fm_port[dev] = pnp_port_start(pdev, 1);
248 sb_port[dev] = pnp_port_start(pdev, 2);
249 irq[dev] = pnp_irq(pdev, 0);
250 dma1[dev] = pnp_dma(pdev, 0);
251 dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
252 snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
253 port[dev], fm_port[dev], sb_port[dev]);
254 snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
255 irq[dev], dma1[dev], dma2[dev]);
256 return 0;
257}
258
259
260static int snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev)
261{
262 if (pnp_activate_dev(pdev) < 0) {
263 printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
264 return -EBUSY;
265 }
266 cport[dev] = pnp_port_start(pdev, 0);
267 snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
268 return 0;
269}
270
271
272static int snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev)
273{
274 if (pnp_activate_dev(pdev) < 0) {
275 printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
276 mpu_port[dev] = SNDRV_AUTO_PORT;
277 mpu_irq[dev] = SNDRV_AUTO_IRQ;
278 } else {
279 mpu_port[dev] = pnp_port_start(pdev, 0);
280 if (mpu_irq[dev] >= 0 &&
281 pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
282 mpu_irq[dev] = pnp_irq(pdev, 0);
283 } else {
284 mpu_irq[dev] = -1;
285 }
286 }
287 snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
288 return 0;
289}
290
291static int snd_card_cs423x_pnp(int dev, struct snd_card_cs4236 *acard,
292 struct pnp_dev *pdev,
293 struct pnp_dev *cdev)
294{
295 acard->wss = pdev;
296 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
297 return -EBUSY;
298 if (cdev)
299 cport[dev] = pnp_port_start(cdev, 0);
300 else
301 cport[dev] = -1;
302 return 0;
303}
304
305static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
306 struct pnp_card_link *card,
307 const struct pnp_card_device_id *id)
308{
309 acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
310 if (acard->wss == NULL)
311 return -EBUSY;
312 acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
313 if (acard->ctrl == NULL)
314 return -EBUSY;
315 if (id->devs[2].id[0]) {
316 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
317 if (acard->mpu == NULL)
318 return -EBUSY;
319 }
320
321
322 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
323 return -EBUSY;
324
325
326 if (acard->ctrl && cport[dev] > 0) {
327 if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
328 return -EBUSY;
329 }
330
331 if (acard->mpu && mpu_port[dev] > 0) {
332 if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
333 return -EBUSY;
334 }
335 return 0;
336}
337#endif
338
339#ifdef CONFIG_PNP
340#define is_isapnp_selected(dev) isapnp[dev]
341#else
342#define is_isapnp_selected(dev) 0
343#endif
344
345static void snd_card_cs4236_free(struct snd_card *card)
346{
347 struct snd_card_cs4236 *acard = card->private_data;
348
349 release_and_free_resource(acard->res_sb_port);
350}
351
352static int snd_cs423x_card_new(struct device *pdev, int dev,
353 struct snd_card **cardp)
354{
355 struct snd_card *card;
356 int err;
357
358 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
359 sizeof(struct snd_card_cs4236), &card);
360 if (err < 0)
361 return err;
362 card->private_free = snd_card_cs4236_free;
363 *cardp = card;
364 return 0;
365}
366
367static int snd_cs423x_probe(struct snd_card *card, int dev)
368{
369 struct snd_card_cs4236 *acard;
370 struct snd_wss *chip;
371 struct snd_opl3 *opl3;
372 int err;
373
374 acard = card->private_data;
375 if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
376 if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
377 printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
378 return -EBUSY;
379 }
380
381 err = snd_cs4236_create(card, port[dev], cport[dev],
382 irq[dev],
383 dma1[dev], dma2[dev],
384 WSS_HW_DETECT3, 0, &chip);
385 if (err < 0)
386 return err;
387
388 acard->chip = chip;
389 if (chip->hardware & WSS_HW_CS4236B_MASK) {
390
391 err = snd_cs4236_pcm(chip, 0);
392 if (err < 0)
393 return err;
394
395 err = snd_cs4236_mixer(chip);
396 if (err < 0)
397 return err;
398 } else {
399 err = snd_wss_pcm(chip, 0);
400 if (err < 0)
401 return err;
402
403 err = snd_wss_mixer(chip);
404 if (err < 0)
405 return err;
406 }
407 strlcpy(card->driver, chip->pcm->name, sizeof(card->driver));
408 strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
409 if (dma2[dev] < 0)
410 snprintf(card->longname, sizeof(card->longname),
411 "%s at 0x%lx, irq %i, dma %i",
412 chip->pcm->name, chip->port, irq[dev], dma1[dev]);
413 else
414 snprintf(card->longname, sizeof(card->longname),
415 "%s at 0x%lx, irq %i, dma %i&%d",
416 chip->pcm->name, chip->port, irq[dev], dma1[dev],
417 dma2[dev]);
418
419 err = snd_wss_timer(chip, 0);
420 if (err < 0)
421 return err;
422
423 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
424 if (snd_opl3_create(card,
425 fm_port[dev], fm_port[dev] + 2,
426 OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
427 printk(KERN_WARNING IDENT ": OPL3 not detected\n");
428 } else {
429 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
430 return err;
431 }
432 }
433
434 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
435 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
436 mpu_irq[dev] = -1;
437 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
438 mpu_port[dev], 0,
439 mpu_irq[dev], NULL) < 0)
440 printk(KERN_WARNING IDENT ": MPU401 not detected\n");
441 }
442
443 return snd_card_register(card);
444}
445
446static int snd_cs423x_isa_match(struct device *pdev,
447 unsigned int dev)
448{
449 if (!enable[dev] || is_isapnp_selected(dev))
450 return 0;
451
452 if (port[dev] == SNDRV_AUTO_PORT) {
453 dev_err(pdev, "please specify port\n");
454 return 0;
455 }
456 if (cport[dev] == SNDRV_AUTO_PORT) {
457 dev_err(pdev, "please specify cport\n");
458 return 0;
459 }
460 if (irq[dev] == SNDRV_AUTO_IRQ) {
461 dev_err(pdev, "please specify irq\n");
462 return 0;
463 }
464 if (dma1[dev] == SNDRV_AUTO_DMA) {
465 dev_err(pdev, "please specify dma1\n");
466 return 0;
467 }
468 return 1;
469}
470
471static int snd_cs423x_isa_probe(struct device *pdev,
472 unsigned int dev)
473{
474 struct snd_card *card;
475 int err;
476
477 err = snd_cs423x_card_new(pdev, dev, &card);
478 if (err < 0)
479 return err;
480 if ((err = snd_cs423x_probe(card, dev)) < 0) {
481 snd_card_free(card);
482 return err;
483 }
484
485 dev_set_drvdata(pdev, card);
486 return 0;
487}
488
489static int snd_cs423x_isa_remove(struct device *pdev,
490 unsigned int dev)
491{
492 snd_card_free(dev_get_drvdata(pdev));
493 return 0;
494}
495
496#ifdef CONFIG_PM
497static int snd_cs423x_suspend(struct snd_card *card)
498{
499 struct snd_card_cs4236 *acard = card->private_data;
500 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
501 acard->chip->suspend(acard->chip);
502 return 0;
503}
504
505static int snd_cs423x_resume(struct snd_card *card)
506{
507 struct snd_card_cs4236 *acard = card->private_data;
508 acard->chip->resume(acard->chip);
509 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
510 return 0;
511}
512
513static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
514 pm_message_t state)
515{
516 return snd_cs423x_suspend(dev_get_drvdata(dev));
517}
518
519static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
520{
521 return snd_cs423x_resume(dev_get_drvdata(dev));
522}
523#endif
524
525static struct isa_driver cs423x_isa_driver = {
526 .match = snd_cs423x_isa_match,
527 .probe = snd_cs423x_isa_probe,
528 .remove = snd_cs423x_isa_remove,
529#ifdef CONFIG_PM
530 .suspend = snd_cs423x_isa_suspend,
531 .resume = snd_cs423x_isa_resume,
532#endif
533 .driver = {
534 .name = DEV_NAME
535 },
536};
537
538
539#ifdef CONFIG_PNP
540static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
541 const struct pnp_device_id *id)
542{
543 static int dev;
544 int err;
545 struct snd_card *card;
546 struct pnp_dev *cdev;
547 char cid[PNP_ID_LEN];
548
549 if (pnp_device_is_isapnp(pdev))
550 return -ENOENT;
551 for (; dev < SNDRV_CARDS; dev++) {
552 if (enable[dev] && isapnp[dev])
553 break;
554 }
555 if (dev >= SNDRV_CARDS)
556 return -ENODEV;
557
558
559 strcpy(cid, pdev->id[0].id);
560 cid[5] = '1';
561 cdev = NULL;
562 list_for_each_entry(cdev, &(pdev->protocol->devices), protocol_list) {
563 if (!strcmp(cdev->id[0].id, cid))
564 break;
565 }
566 err = snd_cs423x_card_new(&pdev->dev, dev, &card);
567 if (err < 0)
568 return err;
569 err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
570 if (err < 0) {
571 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
572 snd_card_free(card);
573 return err;
574 }
575 if ((err = snd_cs423x_probe(card, dev)) < 0) {
576 snd_card_free(card);
577 return err;
578 }
579 pnp_set_drvdata(pdev, card);
580 dev++;
581 return 0;
582}
583
584static void snd_cs423x_pnp_remove(struct pnp_dev *pdev)
585{
586 snd_card_free(pnp_get_drvdata(pdev));
587}
588
589#ifdef CONFIG_PM
590static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
591{
592 return snd_cs423x_suspend(pnp_get_drvdata(pdev));
593}
594
595static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
596{
597 return snd_cs423x_resume(pnp_get_drvdata(pdev));
598}
599#endif
600
601static struct pnp_driver cs423x_pnp_driver = {
602 .name = "cs423x-pnpbios",
603 .id_table = snd_cs423x_pnpbiosids,
604 .probe = snd_cs423x_pnpbios_detect,
605 .remove = snd_cs423x_pnp_remove,
606#ifdef CONFIG_PM
607 .suspend = snd_cs423x_pnp_suspend,
608 .resume = snd_cs423x_pnp_resume,
609#endif
610};
611
612static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
613 const struct pnp_card_device_id *pid)
614{
615 static int dev;
616 struct snd_card *card;
617 int res;
618
619 for ( ; dev < SNDRV_CARDS; dev++) {
620 if (enable[dev] && isapnp[dev])
621 break;
622 }
623 if (dev >= SNDRV_CARDS)
624 return -ENODEV;
625
626 res = snd_cs423x_card_new(&pcard->card->dev, dev, &card);
627 if (res < 0)
628 return res;
629 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
630 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
631 " is not supported\n");
632 snd_card_free(card);
633 return res;
634 }
635 if ((res = snd_cs423x_probe(card, dev)) < 0) {
636 snd_card_free(card);
637 return res;
638 }
639 pnp_set_card_drvdata(pcard, card);
640 dev++;
641 return 0;
642}
643
644static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard)
645{
646 snd_card_free(pnp_get_card_drvdata(pcard));
647 pnp_set_card_drvdata(pcard, NULL);
648}
649
650#ifdef CONFIG_PM
651static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
652{
653 return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
654}
655
656static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
657{
658 return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
659}
660#endif
661
662static struct pnp_card_driver cs423x_pnpc_driver = {
663 .flags = PNP_DRIVER_RES_DISABLE,
664 .name = CS423X_ISAPNP_DRIVER,
665 .id_table = snd_cs423x_pnpids,
666 .probe = snd_cs423x_pnpc_detect,
667 .remove = snd_cs423x_pnpc_remove,
668#ifdef CONFIG_PM
669 .suspend = snd_cs423x_pnpc_suspend,
670 .resume = snd_cs423x_pnpc_resume,
671#endif
672};
673#endif
674
675static int __init alsa_card_cs423x_init(void)
676{
677 int err;
678
679 err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
680#ifdef CONFIG_PNP
681 if (!err)
682 isa_registered = 1;
683 err = pnp_register_driver(&cs423x_pnp_driver);
684 if (!err)
685 pnp_registered = 1;
686 err = pnp_register_card_driver(&cs423x_pnpc_driver);
687 if (!err)
688 pnpc_registered = 1;
689 if (pnp_registered)
690 err = 0;
691 if (isa_registered)
692 err = 0;
693#endif
694 return err;
695}
696
697static void __exit alsa_card_cs423x_exit(void)
698{
699#ifdef CONFIG_PNP
700 if (pnpc_registered)
701 pnp_unregister_card_driver(&cs423x_pnpc_driver);
702 if (pnp_registered)
703 pnp_unregister_driver(&cs423x_pnp_driver);
704 if (isa_registered)
705#endif
706 isa_unregister_driver(&cs423x_isa_driver);
707}
708
709module_init(alsa_card_cs423x_init)
710module_exit(alsa_card_cs423x_exit)
711