xref: /openbmc/linux/sound/isa/cs423x/cs4236.c (revision 547840bd)
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_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 
55 MODULE_ALIAS("snd_cs4232");
56 
57 #define IDENT "CS4232+"
58 #define DEV_NAME "cs4232+"
59 
60 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
61 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
62 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
63 #ifdef CONFIG_PNP
64 static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
65 #endif
66 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
67 static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
68 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
69 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
70 static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
71 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 5,7,9,11,12,15 */
72 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 9,11,12,15 */
73 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
74 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
75 
76 module_param_array(index, int, NULL, 0444);
77 MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
78 module_param_array(id, charp, NULL, 0444);
79 MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
80 module_param_array(enable, bool, NULL, 0444);
81 MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
82 #ifdef CONFIG_PNP
83 module_param_array(isapnp, bool, NULL, 0444);
84 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
85 #endif
86 module_param_hw_array(port, long, ioport, NULL, 0444);
87 MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
88 module_param_hw_array(cport, long, ioport, NULL, 0444);
89 MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
90 module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
91 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
92 module_param_hw_array(fm_port, long, ioport, NULL, 0444);
93 MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
94 module_param_hw_array(sb_port, long, ioport, NULL, 0444);
95 MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
96 module_param_hw_array(irq, int, irq, NULL, 0444);
97 MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
98 module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
99 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
100 module_param_hw_array(dma1, int, dma, NULL, 0444);
101 MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
102 module_param_hw_array(dma2, int, dma, NULL, 0444);
103 MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
104 
105 #ifdef CONFIG_PNP
106 static int isa_registered;
107 static int pnpc_registered;
108 static int pnp_registered;
109 #endif /* CONFIG_PNP */
110 
111 struct 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  */
126 static 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 };
134 MODULE_DEVICE_TABLE(pnp, snd_cs423x_pnpbiosids);
135 
136 #define CS423X_ISAPNP_DRIVER	"cs4232_isapnp"
137 static 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 
236 MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
237 
238 /* WSS initialization */
239 static 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 */
260 static 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 */
272 static 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 
292 static 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 
306 static 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 
346 static 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 
353 static 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 
368 static 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 
447 static 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 
472 static 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 
490 static 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
498 static 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 
506 static 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 
514 static 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 
520 static 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 
526 static 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
541 static 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;
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(cdev, &(pdev->protocol->devices), protocol_list) {
564 		if (!strcmp(cdev->id[0].id, cid))
565 			break;
566 	}
567 	err = snd_cs423x_card_new(&pdev->dev, dev, &card);
568 	if (err < 0)
569 		return err;
570 	err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
571 	if (err < 0) {
572 		printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
573 		snd_card_free(card);
574 		return err;
575 	}
576 	if ((err = snd_cs423x_probe(card, dev)) < 0) {
577 		snd_card_free(card);
578 		return err;
579 	}
580 	pnp_set_drvdata(pdev, card);
581 	dev++;
582 	return 0;
583 }
584 
585 static void snd_cs423x_pnp_remove(struct pnp_dev *pdev)
586 {
587 	snd_card_free(pnp_get_drvdata(pdev));
588 }
589 
590 #ifdef CONFIG_PM
591 static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
592 {
593 	return snd_cs423x_suspend(pnp_get_drvdata(pdev));
594 }
595 
596 static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
597 {
598 	return snd_cs423x_resume(pnp_get_drvdata(pdev));
599 }
600 #endif
601 
602 static struct pnp_driver cs423x_pnp_driver = {
603 	.name = "cs423x-pnpbios",
604 	.id_table = snd_cs423x_pnpbiosids,
605 	.probe = snd_cs423x_pnpbios_detect,
606 	.remove = snd_cs423x_pnp_remove,
607 #ifdef CONFIG_PM
608 	.suspend	= snd_cs423x_pnp_suspend,
609 	.resume		= snd_cs423x_pnp_resume,
610 #endif
611 };
612 
613 static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
614 				  const struct pnp_card_device_id *pid)
615 {
616 	static int dev;
617 	struct snd_card *card;
618 	int res;
619 
620 	for ( ; dev < SNDRV_CARDS; dev++) {
621 		if (enable[dev] && isapnp[dev])
622 			break;
623 	}
624 	if (dev >= SNDRV_CARDS)
625 		return -ENODEV;
626 
627 	res = snd_cs423x_card_new(&pcard->card->dev, dev, &card);
628 	if (res < 0)
629 		return res;
630 	if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
631 		printk(KERN_ERR "isapnp detection failed and probing for " IDENT
632 		       " is not supported\n");
633 		snd_card_free(card);
634 		return res;
635 	}
636 	if ((res = snd_cs423x_probe(card, dev)) < 0) {
637 		snd_card_free(card);
638 		return res;
639 	}
640 	pnp_set_card_drvdata(pcard, card);
641 	dev++;
642 	return 0;
643 }
644 
645 static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard)
646 {
647 	snd_card_free(pnp_get_card_drvdata(pcard));
648 	pnp_set_card_drvdata(pcard, NULL);
649 }
650 
651 #ifdef CONFIG_PM
652 static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
653 {
654 	return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
655 }
656 
657 static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
658 {
659 	return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
660 }
661 #endif
662 
663 static struct pnp_card_driver cs423x_pnpc_driver = {
664 	.flags = PNP_DRIVER_RES_DISABLE,
665 	.name = CS423X_ISAPNP_DRIVER,
666 	.id_table = snd_cs423x_pnpids,
667 	.probe = snd_cs423x_pnpc_detect,
668 	.remove = snd_cs423x_pnpc_remove,
669 #ifdef CONFIG_PM
670 	.suspend	= snd_cs423x_pnpc_suspend,
671 	.resume		= snd_cs423x_pnpc_resume,
672 #endif
673 };
674 #endif /* CONFIG_PNP */
675 
676 static int __init alsa_card_cs423x_init(void)
677 {
678 	int err;
679 
680 	err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
681 #ifdef CONFIG_PNP
682 	if (!err)
683 		isa_registered = 1;
684 	err = pnp_register_driver(&cs423x_pnp_driver);
685 	if (!err)
686 		pnp_registered = 1;
687 	err = pnp_register_card_driver(&cs423x_pnpc_driver);
688 	if (!err)
689 		pnpc_registered = 1;
690 	if (pnp_registered)
691 		err = 0;
692 	if (isa_registered)
693 		err = 0;
694 #endif
695 	return err;
696 }
697 
698 static void __exit alsa_card_cs423x_exit(void)
699 {
700 #ifdef CONFIG_PNP
701 	if (pnpc_registered)
702 		pnp_unregister_card_driver(&cs423x_pnpc_driver);
703 	if (pnp_registered)
704 		pnp_unregister_driver(&cs423x_pnp_driver);
705 	if (isa_registered)
706 #endif
707 		isa_unregister_driver(&cs423x_isa_driver);
708 }
709 
710 module_init(alsa_card_cs423x_init)
711 module_exit(alsa_card_cs423x_exit)
712