xref: /linux/sound/isa/cs423x/cs4236.c (revision 14b42963f64b98ab61fa9723c03d71aa5ef4f862)
1 /*
2  *  Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips
3  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4  *
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  *
20  */
21 
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/err.h>
25 #include <linux/platform_device.h>
26 #include <linux/slab.h>
27 #include <linux/pnp.h>
28 #include <linux/moduleparam.h>
29 #include <sound/core.h>
30 #include <sound/cs4231.h>
31 #include <sound/mpu401.h>
32 #include <sound/opl3.h>
33 #include <sound/initval.h>
34 
35 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
36 MODULE_LICENSE("GPL");
37 #ifdef CS4232
38 MODULE_DESCRIPTION("Cirrus Logic CS4232");
39 MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000},"
40 		"{Turtle Beach,Tropez Plus},"
41 		"{SIC CrystalWave 32},"
42 		"{Hewlett Packard,Omnibook 5500},"
43 		"{TerraTec,Maestro 32/96},"
44 		"{Philips,PCA70PS}}");
45 #else
46 MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
47 MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
48 		"{Crystal Semiconductors,CS4236},"
49 		"{Crystal Semiconductors,CS4237},"
50 		"{Crystal Semiconductors,CS4238},"
51 		"{Crystal Semiconductors,CS4239},"
52 		"{Acer,AW37},"
53 		"{Acer,AW35/Pro},"
54 		"{Crystal,3D},"
55 		"{Crystal Computer,TidalWave128},"
56 		"{Dell,Optiplex GX1},"
57 		"{Dell,Workstation 400 sound},"
58 		"{EliteGroup,P5TX-LA sound},"
59 		"{Gallant,SC-70P},"
60 		"{Gateway,E1000 Onboard CS4236B},"
61 		"{Genius,Sound Maker 3DJ},"
62 		"{Hewlett Packard,HP6330 sound},"
63 		"{IBM,PC 300PL sound},"
64 		"{IBM,Aptiva 2137 E24},"
65 		"{IBM,IntelliStation M Pro},"
66 		"{Intel,Marlin Spike Mobo CS4235},"
67 		"{Intel PR440FX Onboard},"
68 		"{Guillemot,MaxiSound 16 PnP},"
69 		"{NewClear,3D},"
70 		"{TerraTec,AudioSystem EWS64L/XL},"
71 		"{Typhoon Soundsystem,CS4236B},"
72 		"{Turtle Beach,Malibu},"
73 		"{Unknown,Digital PC 5000 Onboard}}");
74 #endif
75 
76 #ifdef CS4232
77 #define IDENT "CS4232"
78 #define CS423X_DRIVER "snd_cs4232"
79 #else
80 #define IDENT "CS4236+"
81 #define CS423X_DRIVER "snd_cs4236"
82 #endif
83 
84 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
85 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
86 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
87 #ifdef CONFIG_PNP
88 static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
89 #endif
90 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
91 static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
92 static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
93 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
94 static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;	/* PnP setup */
95 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 5,7,9,11,12,15 */
96 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;	/* 9,11,12,15 */
97 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
98 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;	/* 0,1,3,5,6,7 */
99 
100 module_param_array(index, int, NULL, 0444);
101 MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
102 module_param_array(id, charp, NULL, 0444);
103 MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
104 module_param_array(enable, bool, NULL, 0444);
105 MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
106 #ifdef CONFIG_PNP
107 module_param_array(isapnp, bool, NULL, 0444);
108 MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
109 #endif
110 module_param_array(port, long, NULL, 0444);
111 MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
112 module_param_array(cport, long, NULL, 0444);
113 MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
114 module_param_array(mpu_port, long, NULL, 0444);
115 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
116 module_param_array(fm_port, long, NULL, 0444);
117 MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
118 module_param_array(sb_port, long, NULL, 0444);
119 MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
120 module_param_array(irq, int, NULL, 0444);
121 MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
122 module_param_array(mpu_irq, int, NULL, 0444);
123 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
124 module_param_array(dma1, int, NULL, 0444);
125 MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
126 module_param_array(dma2, int, NULL, 0444);
127 MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
128 
129 static struct platform_device *platform_devices[SNDRV_CARDS];
130 #ifdef CONFIG_PNP
131 static int pnpc_registered;
132 #ifdef CS4232
133 static int pnp_registered;
134 #endif
135 #endif /* CONFIG_PNP */
136 static unsigned int snd_cs423x_devices;
137 
138 struct snd_card_cs4236 {
139 	struct snd_cs4231 *chip;
140 	struct resource *res_sb_port;
141 #ifdef CONFIG_PNP
142 	struct pnp_dev *wss;
143 	struct pnp_dev *ctrl;
144 	struct pnp_dev *mpu;
145 #endif
146 };
147 
148 #ifdef CONFIG_PNP
149 
150 #ifdef CS4232
151 /*
152  * PNP BIOS
153  */
154 static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
155 	{ .id = "CSC0100" },
156 	{ .id = "CSC0000" },
157 	/* Guillemot Turtlebeach something appears to be cs4232 compatible
158 	 * (untested) */
159 	{ .id = "GIM0100" },
160 	{ .id = "" }
161 };
162 MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
163 #endif /* CS4232 */
164 
165 #ifdef CS4232
166 #define CS423X_ISAPNP_DRIVER	"cs4232_isapnp"
167 static struct pnp_card_device_id snd_cs423x_pnpids[] = {
168 	/* Philips PCA70PS */
169 	{ .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
170 	/* TerraTec Maestro 32/96 (CS4232) */
171 	{ .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
172 	/* HP Omnibook 5500 onboard */
173 	{ .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
174 	/* Unnamed CS4236 card (Made in Taiwan) */
175 	{ .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
176 	/* Turtle Beach TBS-2000 (CS4232) */
177 	{ .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
178 	/* Turtle Beach Tropez Plus (CS4232) */
179 	{ .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
180 	/* SIC CrystalWave 32 (CS4232) */
181 	{ .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
182 	/* Netfinity 3000 on-board soundcard */
183 	{ .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
184 	/* --- */
185 	{ .id = "" }	/* end */
186 };
187 #else /* CS4236 */
188 #define CS423X_ISAPNP_DRIVER	"cs4236_isapnp"
189 static struct pnp_card_device_id snd_cs423x_pnpids[] = {
190 	/* Intel Marlin Spike Motherboard - CS4235 */
191 	{ .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
192 	/* Intel Marlin Spike Motherboard (#2) - CS4235 */
193 	{ .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
194 	/* Unknown Intel mainboard - CS4235 */
195 	{ .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
196 	/* Genius Sound Maker 3DJ - CS4237B */
197 	{ .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
198 	/* Digital PC 5000 Onboard - CS4236B */
199 	{ .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
200 	/* some uknown CS4236B */
201 	{ .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
202 	/* Intel PR440FX Onboard sound */
203 	{ .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
204 	/* CS4235 on mainboard without MPU */
205 	{ .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
206 	/* Gateway E1000 Onboard CS4236B */
207 	{ .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
208 	/* HP 6330 Onboard sound */
209 	{ .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
210 	/* Crystal Computer TidalWave128 */
211 	{ .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
212 	/* ACER AW37 - CS4235 */
213 	{ .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
214 	/* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
215 	{ .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
216 	/* Crystal 3D - CS4237B */
217 	{ .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
218 	/* Typhoon Soundsystem PnP - CS4236B */
219 	{ .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
220 	/* Crystal CX4235-XQ3 EP - CS4235 */
221 	{ .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
222 	/* Crystal Semiconductors CS4237B */
223 	{ .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
224 	/* NewClear 3D - CX4237B-XQ3 */
225 	{ .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
226 	/* Dell Optiplex GX1 - CS4236B */
227 	{ .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
228 	/* Dell P410 motherboard - CS4236B */
229 	{ .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
230 	/* Dell Workstation 400 Onboard - CS4236B */
231 	{ .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
232 	/* Turtle Beach Malibu - CS4237B */
233 	{ .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
234 	/* CS4235 - onboard */
235 	{ .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
236 	/* IBM Aptiva 2137 E24 Onboard - CS4237B */
237 	{ .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
238 	/* IBM IntelliStation M Pro motherboard */
239 	{ .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
240 	/* Guillemot MaxiSound 16 PnP - CS4236B */
241 	{ .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
242 	/* Gallant SC-70P */
243 	{ .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
244 	/* TerraTec AudioSystem EWS64XL - CS4236B */
245 	{ .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
246 	/* TerraTec AudioSystem EWS64XL - CS4236B */
247 	{ .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
248 	/* ACER AW37/Pro - CS4235 */
249 	{ .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
250 	/* ACER AW35/Pro - CS4237B */
251 	{ .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
252 	/* CS4235 without MPU401 */
253 	{ .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
254 	/* Unknown SiS530 - CS4235 */
255 	{ .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
256 	/* IBM IntelliStation M Pro 6898 11U - CS4236B */
257 	{ .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
258 	/* IBM PC 300PL Onboard - CS4236B */
259 	{ .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
260 	/* Some noname CS4236 based card */
261 	{ .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
262 	/* CS4236B */
263 	{ .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
264 	/* CS4236B */
265 	{ .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
266 	/* --- */
267 	{ .id = "" }	/* end */
268 };
269 #endif
270 
271 MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
272 
273 /* WSS initialization */
274 static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev,
275 					     struct pnp_resource_table *cfg)
276 {
277 	int err;
278 
279 	pnp_init_resource_table(cfg);
280 	if (port[dev] != SNDRV_AUTO_PORT)
281 		pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
282 	if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0)
283 		pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
284 	if (sb_port[dev] != SNDRV_AUTO_PORT)
285 		pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
286 	if (irq[dev] != SNDRV_AUTO_IRQ)
287 		pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
288 	if (dma1[dev] != SNDRV_AUTO_DMA)
289 		pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
290 	if (dma2[dev] != SNDRV_AUTO_DMA)
291 		pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
292 	err = pnp_manual_config_dev(pdev, cfg, 0);
293 	if (err < 0)
294 		snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
295 	err = pnp_activate_dev(pdev);
296 	if (err < 0) {
297 		printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
298 		return -EBUSY;
299 	}
300 	port[dev] = pnp_port_start(pdev, 0);
301 	if (fm_port[dev] > 0)
302 		fm_port[dev] = pnp_port_start(pdev, 1);
303 	sb_port[dev] = pnp_port_start(pdev, 2);
304 	irq[dev] = pnp_irq(pdev, 0);
305 	dma1[dev] = pnp_dma(pdev, 0);
306 	dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
307 	snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
308 			port[dev], fm_port[dev], sb_port[dev]);
309 	snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
310 			irq[dev], dma1[dev], dma2[dev]);
311 	return 0;
312 }
313 
314 /* CTRL initialization */
315 static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev,
316 					      struct pnp_resource_table *cfg)
317 {
318 	int err;
319 
320 	pnp_init_resource_table(cfg);
321 	if (cport[dev] != SNDRV_AUTO_PORT)
322 		pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
323 	err = pnp_manual_config_dev(pdev, cfg, 0);
324 	if (err < 0)
325 		snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
326 	err = pnp_activate_dev(pdev);
327 	if (err < 0) {
328 		printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
329 		return -EBUSY;
330 	}
331 	cport[dev] = pnp_port_start(pdev, 0);
332 	snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
333 	return 0;
334 }
335 
336 /* MPU initialization */
337 static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev,
338 					     struct pnp_resource_table *cfg)
339 {
340 	int err;
341 
342 	pnp_init_resource_table(cfg);
343 	if (mpu_port[dev] != SNDRV_AUTO_PORT)
344 		pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
345 	if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0)
346 		pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
347 	err = pnp_manual_config_dev(pdev, cfg, 0);
348 	if (err < 0)
349 		snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
350 	err = pnp_activate_dev(pdev);
351 	if (err < 0) {
352 		printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
353 		mpu_port[dev] = SNDRV_AUTO_PORT;
354 		mpu_irq[dev] = SNDRV_AUTO_IRQ;
355 	} else {
356 		mpu_port[dev] = pnp_port_start(pdev, 0);
357 		if (mpu_irq[dev] >= 0 &&
358 		    pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
359 			mpu_irq[dev] = pnp_irq(pdev, 0);
360 		} else {
361 			mpu_irq[dev] = -1;	/* disable interrupt */
362 		}
363 	}
364 	snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
365 	return 0;
366 }
367 
368 #ifdef CS4232
369 static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard,
370 					 struct pnp_dev *pdev)
371 {
372 	struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
373 
374 	if (!cfg)
375 		return -ENOMEM;
376 	if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) {
377 		kfree(cfg);
378 		return -EBUSY;
379 	}
380 	kfree(cfg);
381 	cport[dev] = -1;
382 	return 0;
383 }
384 #endif
385 
386 static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
387 					  struct pnp_card_link *card,
388 					  const struct pnp_card_device_id *id)
389 {
390 	struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
391 
392 	if (!cfg)
393 		return -ENOMEM;
394 
395 	acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
396 	if (acard->wss == NULL)
397 		goto error;
398 	acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
399 	if (acard->ctrl == NULL)
400 		goto error;
401 	if (id->devs[2].id[0]) {
402 		acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
403 		if (acard->mpu == NULL)
404 			goto error;
405 	}
406 
407 	/* WSS initialization */
408 	if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0)
409 		goto error;
410 
411 	/* CTRL initialization */
412 	if (acard->ctrl && cport[dev] > 0) {
413 		if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl, cfg) < 0)
414 			goto error;
415 	}
416 	/* MPU initialization */
417 	if (acard->mpu && mpu_port[dev] > 0) {
418 		if (snd_cs423x_pnp_init_mpu(dev, acard->mpu, cfg) < 0)
419 			goto error;
420 	}
421 	kfree(cfg);
422 	return 0;
423 
424  error:
425 	kfree(cfg);
426 	return -EBUSY;
427 }
428 #endif /* CONFIG_PNP */
429 
430 #ifdef CONFIG_PNP
431 #define is_isapnp_selected(dev)		isapnp[dev]
432 #else
433 #define is_isapnp_selected(dev)		0
434 #endif
435 
436 static void snd_card_cs4236_free(struct snd_card *card)
437 {
438 	struct snd_card_cs4236 *acard = card->private_data;
439 
440 	release_and_free_resource(acard->res_sb_port);
441 }
442 
443 static struct snd_card *snd_cs423x_card_new(int dev)
444 {
445 	struct snd_card *card;
446 
447 	card = snd_card_new(index[dev], id[dev], THIS_MODULE,
448 			    sizeof(struct snd_card_cs4236));
449 	if (card == NULL)
450 		return NULL;
451 	card->private_free = snd_card_cs4236_free;
452 	return card;
453 }
454 
455 static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
456 {
457 	struct snd_card_cs4236 *acard;
458 	struct snd_pcm *pcm;
459 	struct snd_cs4231 *chip;
460 	struct snd_opl3 *opl3;
461 	int err;
462 
463 	acard = card->private_data;
464 	if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
465 		if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
466 			printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
467 			return -EBUSY;
468 		}
469 
470 #ifdef CS4232
471 	if ((err = snd_cs4231_create(card,
472 				     port[dev],
473 				     cport[dev],
474 				     irq[dev],
475 				     dma1[dev],
476 				     dma2[dev],
477 				     CS4231_HW_DETECT,
478 				     0,
479 				     &chip)) < 0)
480 		return err;
481 	acard->chip = chip;
482 
483 	if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0)
484 		return err;
485 
486 	if ((err = snd_cs4231_mixer(chip)) < 0)
487 		return err;
488 
489 #else /* CS4236 */
490 	if ((err = snd_cs4236_create(card,
491 				     port[dev],
492 				     cport[dev],
493 				     irq[dev],
494 				     dma1[dev],
495 				     dma2[dev],
496 				     CS4231_HW_DETECT,
497 				     0,
498 				     &chip)) < 0)
499 		return err;
500 	acard->chip = chip;
501 
502 	if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0)
503 		return err;
504 
505 	if ((err = snd_cs4236_mixer(chip)) < 0)
506 		return err;
507 #endif
508 	strcpy(card->driver, pcm->name);
509 	strcpy(card->shortname, pcm->name);
510 	sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
511 		pcm->name,
512 		chip->port,
513 		irq[dev],
514 		dma1[dev]);
515 	if (dma2[dev] >= 0)
516 		sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
517 
518 	if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0)
519 		return err;
520 
521 	if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
522 		if (snd_opl3_create(card,
523 				    fm_port[dev], fm_port[dev] + 2,
524 				    OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
525 			printk(KERN_WARNING IDENT ": OPL3 not detected\n");
526 		} else {
527 			if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
528 				return err;
529 		}
530 	}
531 
532 	if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
533 		if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
534 			mpu_irq[dev] = -1;
535 		if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
536 					mpu_port[dev], 0,
537 					mpu_irq[dev],
538 					mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
539 			printk(KERN_WARNING IDENT ": MPU401 not detected\n");
540 	}
541 
542 	return snd_card_register(card);
543 }
544 
545 static int __init snd_cs423x_nonpnp_probe(struct platform_device *pdev)
546 {
547 	int dev = pdev->id;
548 	struct snd_card *card;
549 	int err;
550 
551 	if (port[dev] == SNDRV_AUTO_PORT) {
552 		snd_printk(KERN_ERR "specify port\n");
553 		return -EINVAL;
554 	}
555 	if (cport[dev] == SNDRV_AUTO_PORT) {
556 		snd_printk(KERN_ERR "specify cport\n");
557 		return -EINVAL;
558 	}
559 
560 	card = snd_cs423x_card_new(dev);
561 	if (! card)
562 		return -ENOMEM;
563 	snd_card_set_dev(card, &pdev->dev);
564 	if ((err = snd_cs423x_probe(card, dev)) < 0) {
565 		snd_card_free(card);
566 		return err;
567 	}
568 
569 	platform_set_drvdata(pdev, card);
570 	return 0;
571 }
572 
573 static int __devexit snd_cs423x_nonpnp_remove(struct platform_device *devptr)
574 {
575 	snd_card_free(platform_get_drvdata(devptr));
576 	platform_set_drvdata(devptr, NULL);
577 	return 0;
578 }
579 
580 #ifdef CONFIG_PM
581 static int snd_cs423x_suspend(struct snd_card *card)
582 {
583 	struct snd_card_cs4236 *acard = card->private_data;
584 	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
585 	acard->chip->suspend(acard->chip);
586 	return 0;
587 }
588 
589 static int snd_cs423x_resume(struct snd_card *card)
590 {
591 	struct snd_card_cs4236 *acard = card->private_data;
592 	acard->chip->resume(acard->chip);
593 	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
594 	return 0;
595 }
596 
597 static int snd_cs423x_nonpnp_suspend(struct platform_device *dev, pm_message_t state)
598 {
599 	return snd_cs423x_suspend(platform_get_drvdata(dev));
600 }
601 
602 static int snd_cs423x_nonpnp_resume(struct platform_device *dev)
603 {
604 	return snd_cs423x_resume(platform_get_drvdata(dev));
605 }
606 #endif
607 
608 static struct platform_driver cs423x_nonpnp_driver = {
609 	.probe		= snd_cs423x_nonpnp_probe,
610 	.remove		= __devexit_p(snd_cs423x_nonpnp_remove),
611 #ifdef CONFIG_PM
612 	.suspend	= snd_cs423x_nonpnp_suspend,
613 	.resume		= snd_cs423x_nonpnp_resume,
614 #endif
615 	.driver		= {
616 		.name	= CS423X_DRIVER
617 	},
618 };
619 
620 
621 #ifdef CONFIG_PNP
622 #ifdef CS4232
623 static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
624 					       const struct pnp_device_id *id)
625 {
626 	static int dev;
627 	int err;
628 	struct snd_card *card;
629 
630 	if (pnp_device_is_isapnp(pdev))
631 		return -ENOENT;	/* we have another procedure - card */
632 	for (; dev < SNDRV_CARDS; dev++) {
633 		if (enable[dev] && isapnp[dev])
634 			break;
635 	}
636 	if (dev >= SNDRV_CARDS)
637 		return -ENODEV;
638 
639 	card = snd_cs423x_card_new(dev);
640 	if (! card)
641 		return -ENOMEM;
642 	if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
643 		printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
644 		snd_card_free(card);
645 		return err;
646 	}
647 	snd_card_set_dev(card, &pdev->dev);
648 	if ((err = snd_cs423x_probe(card, dev)) < 0) {
649 		snd_card_free(card);
650 		return err;
651 	}
652 	pnp_set_drvdata(pdev, card);
653 	dev++;
654 	snd_cs423x_devices++;
655 	return 0;
656 }
657 
658 static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
659 {
660 	snd_card_free(pnp_get_drvdata(pdev));
661 	pnp_set_drvdata(pdev, NULL);
662 }
663 
664 #ifdef CONFIG_PM
665 static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
666 {
667 	return snd_cs423x_suspend(pnp_get_drvdata(pdev));
668 }
669 
670 static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
671 {
672 	return snd_cs423x_resume(pnp_get_drvdata(pdev));
673 }
674 #endif
675 
676 static struct pnp_driver cs4232_pnp_driver = {
677 	.name = "cs4232-pnpbios",
678 	.id_table = snd_cs4232_pnpbiosids,
679 	.probe = snd_cs4232_pnpbios_detect,
680 	.remove = __devexit_p(snd_cs4232_pnp_remove),
681 #ifdef CONFIG_PM
682 	.suspend	= snd_cs4232_pnp_suspend,
683 	.resume		= snd_cs4232_pnp_resume,
684 #endif
685 };
686 #endif /* CS4232 */
687 
688 static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
689 					    const struct pnp_card_device_id *pid)
690 {
691 	static int dev;
692 	struct snd_card *card;
693 	int res;
694 
695 	for ( ; dev < SNDRV_CARDS; dev++) {
696 		if (enable[dev] && isapnp[dev])
697 			break;
698 	}
699 	if (dev >= SNDRV_CARDS)
700 		return -ENODEV;
701 
702 	card = snd_cs423x_card_new(dev);
703 	if (! card)
704 		return -ENOMEM;
705 	if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
706 		printk(KERN_ERR "isapnp detection failed and probing for " IDENT
707 		       " is not supported\n");
708 		snd_card_free(card);
709 		return res;
710 	}
711 	snd_card_set_dev(card, &pcard->card->dev);
712 	if ((res = snd_cs423x_probe(card, dev)) < 0) {
713 		snd_card_free(card);
714 		return res;
715 	}
716 	pnp_set_card_drvdata(pcard, card);
717 	dev++;
718 	snd_cs423x_devices++;
719 	return 0;
720 }
721 
722 static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
723 {
724 	snd_card_free(pnp_get_card_drvdata(pcard));
725 	pnp_set_card_drvdata(pcard, NULL);
726 }
727 
728 #ifdef CONFIG_PM
729 static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
730 {
731 	return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
732 }
733 
734 static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
735 {
736 	return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
737 }
738 #endif
739 
740 static struct pnp_card_driver cs423x_pnpc_driver = {
741 	.flags = PNP_DRIVER_RES_DISABLE,
742 	.name = CS423X_ISAPNP_DRIVER,
743 	.id_table = snd_cs423x_pnpids,
744 	.probe = snd_cs423x_pnpc_detect,
745 	.remove = __devexit_p(snd_cs423x_pnpc_remove),
746 #ifdef CONFIG_PM
747 	.suspend	= snd_cs423x_pnpc_suspend,
748 	.resume		= snd_cs423x_pnpc_resume,
749 #endif
750 };
751 #endif /* CONFIG_PNP */
752 
753 static void __init_or_module snd_cs423x_unregister_all(void)
754 {
755 	int i;
756 
757 #ifdef CONFIG_PNP
758 	if (pnpc_registered)
759 		pnp_unregister_card_driver(&cs423x_pnpc_driver);
760 #ifdef CS4232
761 	if (pnp_registered)
762 		pnp_unregister_driver(&cs4232_pnp_driver);
763 #endif
764 #endif /* CONFIG_PNP */
765 	for (i = 0; i < ARRAY_SIZE(platform_devices); ++i)
766 		platform_device_unregister(platform_devices[i]);
767 	platform_driver_unregister(&cs423x_nonpnp_driver);
768 }
769 
770 static int __init alsa_card_cs423x_init(void)
771 {
772 	int i, err;
773 
774 	if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0)
775 		return err;
776 
777 	for (i = 0; i < SNDRV_CARDS; i++) {
778 		struct platform_device *device;
779 		if (! enable[i] || is_isapnp_selected(i))
780 			continue;
781 		device = platform_device_register_simple(CS423X_DRIVER,
782 							 i, NULL, 0);
783 		if (IS_ERR(device))
784 			continue;
785 		if (!platform_get_drvdata(device)) {
786 			platform_device_unregister(device);
787 			continue;
788 		}
789 		platform_devices[i] = device;
790 		snd_cs423x_devices++;
791 	}
792 #ifdef CONFIG_PNP
793 #ifdef CS4232
794 	err = pnp_register_driver(&cs4232_pnp_driver);
795 	if (!err)
796 		pnp_registered = 1;
797 #endif
798 	err = pnp_register_card_driver(&cs423x_pnpc_driver);
799 	if (!err)
800 		pnpc_registered = 1;
801 #endif /* CONFIG_PNP */
802 
803 	if (!snd_cs423x_devices) {
804 #ifdef MODULE
805 		printk(KERN_ERR IDENT " soundcard not found or device busy\n");
806 #endif
807 		snd_cs423x_unregister_all();
808 		return -ENODEV;
809 	}
810 	return 0;
811 }
812 
813 static void __exit alsa_card_cs423x_exit(void)
814 {
815 	snd_cs423x_unregister_all();
816 }
817 
818 module_init(alsa_card_cs423x_init)
819 module_exit(alsa_card_cs423x_exit)
820