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