blob: 9ee3a312c6793248e7752bf8b3691b4b43fd5dce [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// 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
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; /* Index 0-MAX */
61static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
62static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
63#ifdef CONFIG_PNP
64static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
65#endif
66static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
67static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
68static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
69static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
70static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
71static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
72static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
73static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
74static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
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 /* CONFIG_PNP */
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 * PNP BIOS
125 */
126static const struct pnp_device_id snd_cs423x_pnpbiosids[] = {
127 { .id = "CSC0100" },
128 { .id = "CSC0000" },
129 /* Guillemot Turtlebeach something appears to be cs4232 compatible
130 * (untested) */
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 /* Philips PCA70PS */
139 { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
140 /* TerraTec Maestro 32/96 (CS4232) */
141 { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
142 /* HP Omnibook 5500 onboard */
143 { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
144 /* Unnamed CS4236 card (Made in Taiwan) */
145 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
146 /* Turtle Beach TBS-2000 (CS4232) */
147 { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
148 /* Turtle Beach Tropez Plus (CS4232) */
149 { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
150 /* SIC CrystalWave 32 (CS4232) */
151 { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
152 /* Netfinity 3000 on-board soundcard */
153 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
154 /* Intel Marlin Spike Motherboard - CS4235 */
155 { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
156 /* Intel Marlin Spike Motherboard (#2) - CS4235 */
157 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
158 /* Unknown Intel mainboard - CS4235 */
159 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
160 /* Genius Sound Maker 3DJ - CS4237B */
161 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
162 /* Digital PC 5000 Onboard - CS4236B */
163 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
164 /* some unknown CS4236B */
165 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
166 /* Intel PR440FX Onboard sound */
167 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
168 /* CS4235 on mainboard without MPU */
169 { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
170 /* Gateway E1000 Onboard CS4236B */
171 { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
172 /* HP 6330 Onboard sound */
173 { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
174 /* Crystal Computer TidalWave128 */
175 { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
176 /* ACER AW37 - CS4235 */
177 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
178 /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
179 { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
180 /* Crystal 3D - CS4237B */
181 { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
182 /* Typhoon Soundsystem PnP - CS4236B */
183 { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
184 /* Crystal CX4235-XQ3 EP - CS4235 */
185 { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
186 /* Crystal Semiconductors CS4237B */
187 { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
188 /* NewClear 3D - CX4237B-XQ3 */
189 { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
190 /* Dell Optiplex GX1 - CS4236B */
191 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
192 /* Dell P410 motherboard - CS4236B */
193 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
194 /* Dell Workstation 400 Onboard - CS4236B */
195 { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
196 /* Turtle Beach Malibu - CS4237B */
197 { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
198 /* CS4235 - onboard */
199 { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
200 /* IBM Aptiva 2137 E24 Onboard - CS4237B */
201 { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
202 /* IBM IntelliStation M Pro motherboard */
203 { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
204 /* Guillemot MaxiSound 16 PnP - CS4236B */
205 { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
206 /* Gallant SC-70P */
207 { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
208 /* Techmakers MF-4236PW */
209 { .id = "CSCa736", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
210 /* TerraTec AudioSystem EWS64XL - CS4236B */
211 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
212 /* TerraTec AudioSystem EWS64XL - CS4236B */
213 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
214 /* ACER AW37/Pro - CS4235 */
215 { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
216 /* ACER AW35/Pro - CS4237B */
217 { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
218 /* CS4235 without MPU401 */
219 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
220 /* Unknown SiS530 - CS4235 */
221 { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
222 /* IBM IntelliStation M Pro 6898 11U - CS4236B */
223 { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
224 /* IBM PC 300PL Onboard - CS4236B */
225 { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
226 /* Some noname CS4236 based card */
227 { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
228 /* CS4236B */
229 { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
230 /* CS4236B */
231 { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
232 /* --- */
233 { .id = "" } /* end */
234};
235
236MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
237
238/* WSS initialization */
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/* CTRL initialization */
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/* MPU initialization */
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) &&
282 pnp_irq(pdev, 0) != (resource_size_t)-1) {
283 mpu_irq[dev] = pnp_irq(pdev, 0);
284 } else {
285 mpu_irq[dev] = -1; /* disable interrupt */
286 }
287 }
288 snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
289 return 0;
290}
291
292static int snd_card_cs423x_pnp(int dev, struct snd_card_cs4236 *acard,
293 struct pnp_dev *pdev,
294 struct pnp_dev *cdev)
295{
296 acard->wss = pdev;
297 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
298 return -EBUSY;
299 if (cdev)
300 cport[dev] = pnp_port_start(cdev, 0);
301 else
302 cport[dev] = -1;
303 return 0;
304}
305
306static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
307 struct pnp_card_link *card,
308 const struct pnp_card_device_id *id)
309{
310 acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
311 if (acard->wss == NULL)
312 return -EBUSY;
313 acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
314 if (acard->ctrl == NULL)
315 return -EBUSY;
316 if (id->devs[2].id[0]) {
317 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
318 if (acard->mpu == NULL)
319 return -EBUSY;
320 }
321
322 /* WSS initialization */
323 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
324 return -EBUSY;
325
326 /* CTRL initialization */
327 if (acard->ctrl && cport[dev] > 0) {
328 if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
329 return -EBUSY;
330 }
331 /* MPU initialization */
332 if (acard->mpu && mpu_port[dev] > 0) {
333 if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
334 return -EBUSY;
335 }
336 return 0;
337}
338#endif /* CONFIG_PNP */
339
340#ifdef CONFIG_PNP
341#define is_isapnp_selected(dev) isapnp[dev]
342#else
343#define is_isapnp_selected(dev) 0
344#endif
345
346static void snd_card_cs4236_free(struct snd_card *card)
347{
348 struct snd_card_cs4236 *acard = card->private_data;
349
350 release_and_free_resource(acard->res_sb_port);
351}
352
353static int snd_cs423x_card_new(struct device *pdev, int dev,
354 struct snd_card **cardp)
355{
356 struct snd_card *card;
357 int err;
358
359 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
360 sizeof(struct snd_card_cs4236), &card);
361 if (err < 0)
362 return err;
363 card->private_free = snd_card_cs4236_free;
364 *cardp = card;
365 return 0;
366}
367
368static int snd_cs423x_probe(struct snd_card *card, int dev)
369{
370 struct snd_card_cs4236 *acard;
371 struct snd_wss *chip;
372 struct snd_opl3 *opl3;
373 int err;
374
375 acard = card->private_data;
376 if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
377 if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
378 printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
379 return -EBUSY;
380 }
381
382 err = snd_cs4236_create(card, port[dev], cport[dev],
383 irq[dev],
384 dma1[dev], dma2[dev],
385 WSS_HW_DETECT3, 0, &chip);
386 if (err < 0)
387 return err;
388
389 acard->chip = chip;
390 if (chip->hardware & WSS_HW_CS4236B_MASK) {
391
392 err = snd_cs4236_pcm(chip, 0);
393 if (err < 0)
394 return err;
395
396 err = snd_cs4236_mixer(chip);
397 if (err < 0)
398 return err;
399 } else {
400 err = snd_wss_pcm(chip, 0);
401 if (err < 0)
402 return err;
403
404 err = snd_wss_mixer(chip);
405 if (err < 0)
406 return err;
407 }
408 strlcpy(card->driver, chip->pcm->name, sizeof(card->driver));
409 strlcpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
410 if (dma2[dev] < 0)
411 snprintf(card->longname, sizeof(card->longname),
412 "%s at 0x%lx, irq %i, dma %i",
413 chip->pcm->name, chip->port, irq[dev], dma1[dev]);
414 else
415 snprintf(card->longname, sizeof(card->longname),
416 "%s at 0x%lx, irq %i, dma %i&%d",
417 chip->pcm->name, chip->port, irq[dev], dma1[dev],
418 dma2[dev]);
419
420 err = snd_wss_timer(chip, 0);
421 if (err < 0)
422 return err;
423
424 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
425 if (snd_opl3_create(card,
426 fm_port[dev], fm_port[dev] + 2,
427 OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
428 printk(KERN_WARNING IDENT ": OPL3 not detected\n");
429 } else {
430 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
431 return err;
432 }
433 }
434
435 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
436 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
437 mpu_irq[dev] = -1;
438 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
439 mpu_port[dev], 0,
440 mpu_irq[dev], NULL) < 0)
441 printk(KERN_WARNING IDENT ": MPU401 not detected\n");
442 }
443
444 return snd_card_register(card);
445}
446
447static int snd_cs423x_isa_match(struct device *pdev,
448 unsigned int dev)
449{
450 if (!enable[dev] || is_isapnp_selected(dev))
451 return 0;
452
453 if (port[dev] == SNDRV_AUTO_PORT) {
454 dev_err(pdev, "please specify port\n");
455 return 0;
456 }
457 if (cport[dev] == SNDRV_AUTO_PORT) {
458 dev_err(pdev, "please specify cport\n");
459 return 0;
460 }
461 if (irq[dev] == SNDRV_AUTO_IRQ) {
462 dev_err(pdev, "please specify irq\n");
463 return 0;
464 }
465 if (dma1[dev] == SNDRV_AUTO_DMA) {
466 dev_err(pdev, "please specify dma1\n");
467 return 0;
468 }
469 return 1;
470}
471
472static int snd_cs423x_isa_probe(struct device *pdev,
473 unsigned int dev)
474{
475 struct snd_card *card;
476 int err;
477
478 err = snd_cs423x_card_new(pdev, dev, &card);
479 if (err < 0)
480 return err;
481 if ((err = snd_cs423x_probe(card, dev)) < 0) {
482 snd_card_free(card);
483 return err;
484 }
485
486 dev_set_drvdata(pdev, card);
487 return 0;
488}
489
490static int snd_cs423x_isa_remove(struct device *pdev,
491 unsigned int dev)
492{
493 snd_card_free(dev_get_drvdata(pdev));
494 return 0;
495}
496
497#ifdef CONFIG_PM
498static int snd_cs423x_suspend(struct snd_card *card)
499{
500 struct snd_card_cs4236 *acard = card->private_data;
501 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
502 acard->chip->suspend(acard->chip);
503 return 0;
504}
505
506static int snd_cs423x_resume(struct snd_card *card)
507{
508 struct snd_card_cs4236 *acard = card->private_data;
509 acard->chip->resume(acard->chip);
510 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
511 return 0;
512}
513
514static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
515 pm_message_t state)
516{
517 return snd_cs423x_suspend(dev_get_drvdata(dev));
518}
519
520static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
521{
522 return snd_cs423x_resume(dev_get_drvdata(dev));
523}
524#endif
525
526static struct isa_driver cs423x_isa_driver = {
527 .match = snd_cs423x_isa_match,
528 .probe = snd_cs423x_isa_probe,
529 .remove = snd_cs423x_isa_remove,
530#ifdef CONFIG_PM
531 .suspend = snd_cs423x_isa_suspend,
532 .resume = snd_cs423x_isa_resume,
533#endif
534 .driver = {
535 .name = DEV_NAME
536 },
537};
538
539
540#ifdef CONFIG_PNP
541static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
542 const struct pnp_device_id *id)
543{
544 static int dev;
545 int err;
546 struct snd_card *card;
547 struct pnp_dev *cdev, *iter;
548 char cid[PNP_ID_LEN];
549
550 if (pnp_device_is_isapnp(pdev))
551 return -ENOENT; /* we have another procedure - card */
552 for (; dev < SNDRV_CARDS; dev++) {
553 if (enable[dev] && isapnp[dev])
554 break;
555 }
556 if (dev >= SNDRV_CARDS)
557 return -ENODEV;
558
559 /* prepare second id */
560 strcpy(cid, pdev->id[0].id);
561 cid[5] = '1';
562 cdev = NULL;
563 list_for_each_entry(iter, &(pdev->protocol->devices), protocol_list) {
564 if (!strcmp(iter->id[0].id, cid)) {
565 cdev = iter;
566 break;
567 }
568 }
569 err = snd_cs423x_card_new(&pdev->dev, dev, &card);
570 if (err < 0)
571 return err;
572 err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
573 if (err < 0) {
574 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
575 snd_card_free(card);
576 return err;
577 }
578 if ((err = snd_cs423x_probe(card, dev)) < 0) {
579 snd_card_free(card);
580 return err;
581 }
582 pnp_set_drvdata(pdev, card);
583 dev++;
584 return 0;
585}
586
587static void snd_cs423x_pnp_remove(struct pnp_dev *pdev)
588{
589 snd_card_free(pnp_get_drvdata(pdev));
590}
591
592#ifdef CONFIG_PM
593static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
594{
595 return snd_cs423x_suspend(pnp_get_drvdata(pdev));
596}
597
598static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
599{
600 return snd_cs423x_resume(pnp_get_drvdata(pdev));
601}
602#endif
603
604static struct pnp_driver cs423x_pnp_driver = {
605 .name = "cs423x-pnpbios",
606 .id_table = snd_cs423x_pnpbiosids,
607 .probe = snd_cs423x_pnpbios_detect,
608 .remove = snd_cs423x_pnp_remove,
609#ifdef CONFIG_PM
610 .suspend = snd_cs423x_pnp_suspend,
611 .resume = snd_cs423x_pnp_resume,
612#endif
613};
614
615static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
616 const struct pnp_card_device_id *pid)
617{
618 static int dev;
619 struct snd_card *card;
620 int res;
621
622 for ( ; dev < SNDRV_CARDS; dev++) {
623 if (enable[dev] && isapnp[dev])
624 break;
625 }
626 if (dev >= SNDRV_CARDS)
627 return -ENODEV;
628
629 res = snd_cs423x_card_new(&pcard->card->dev, dev, &card);
630 if (res < 0)
631 return res;
632 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
633 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
634 " is not supported\n");
635 snd_card_free(card);
636 return res;
637 }
638 if ((res = snd_cs423x_probe(card, dev)) < 0) {
639 snd_card_free(card);
640 return res;
641 }
642 pnp_set_card_drvdata(pcard, card);
643 dev++;
644 return 0;
645}
646
647static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard)
648{
649 snd_card_free(pnp_get_card_drvdata(pcard));
650 pnp_set_card_drvdata(pcard, NULL);
651}
652
653#ifdef CONFIG_PM
654static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
655{
656 return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
657}
658
659static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
660{
661 return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
662}
663#endif
664
665static struct pnp_card_driver cs423x_pnpc_driver = {
666 .flags = PNP_DRIVER_RES_DISABLE,
667 .name = CS423X_ISAPNP_DRIVER,
668 .id_table = snd_cs423x_pnpids,
669 .probe = snd_cs423x_pnpc_detect,
670 .remove = snd_cs423x_pnpc_remove,
671#ifdef CONFIG_PM
672 .suspend = snd_cs423x_pnpc_suspend,
673 .resume = snd_cs423x_pnpc_resume,
674#endif
675};
676#endif /* CONFIG_PNP */
677
678static int __init alsa_card_cs423x_init(void)
679{
680 int err;
681
682 err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
683#ifdef CONFIG_PNP
684 if (!err)
685 isa_registered = 1;
686 err = pnp_register_driver(&cs423x_pnp_driver);
687 if (!err)
688 pnp_registered = 1;
689 err = pnp_register_card_driver(&cs423x_pnpc_driver);
690 if (!err)
691 pnpc_registered = 1;
692 if (pnp_registered)
693 err = 0;
694 if (isa_registered)
695 err = 0;
696#endif
697 return err;
698}
699
700static void __exit alsa_card_cs423x_exit(void)
701{
702#ifdef CONFIG_PNP
703 if (pnpc_registered)
704 pnp_unregister_card_driver(&cs423x_pnpc_driver);
705 if (pnp_registered)
706 pnp_unregister_driver(&cs423x_pnp_driver);
707 if (isa_registered)
708#endif
709 isa_unregister_driver(&cs423x_isa_driver);
710}
711
712module_init(alsa_card_cs423x_init)
713module_exit(alsa_card_cs423x_exit)