blob: 382bb17ef49f08941fb88c76c037ff54caf02b57 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Takashi Iwai6bba41a2005-11-17 17:00:53 +010024#include <linux/err.h>
25#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#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
35MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
36MODULE_LICENSE("GPL");
37#ifdef CS4232
38MODULE_DESCRIPTION("Cirrus Logic CS4232");
39MODULE_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
46MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
47MODULE_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"
Jaroslav Kyselaec808592006-01-22 09:28:15 +010078#define CS423X_DRIVER "snd_cs4232"
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#else
80#define IDENT "CS4236+"
Jaroslav Kyselaec808592006-01-22 09:28:15 +010081#define CS423X_DRIVER "snd_cs4236"
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#endif
83
84static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
85static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
86static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
87#ifdef CONFIG_PNP
88static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
89#endif
90static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
91static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
92static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
93static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
94static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
95static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
96static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
97static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
98static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
99
100module_param_array(index, int, NULL, 0444);
101MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
102module_param_array(id, charp, NULL, 0444);
103MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
104module_param_array(enable, bool, NULL, 0444);
105MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
106#ifdef CONFIG_PNP
107module_param_array(isapnp, bool, NULL, 0444);
108MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
109#endif
110module_param_array(port, long, NULL, 0444);
111MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
112module_param_array(cport, long, NULL, 0444);
113MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
114module_param_array(mpu_port, long, NULL, 0444);
115MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
116module_param_array(fm_port, long, NULL, 0444);
117MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
118module_param_array(sb_port, long, NULL, 0444);
119MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
120module_param_array(irq, int, NULL, 0444);
121MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
122module_param_array(mpu_irq, int, NULL, 0444);
123MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
124module_param_array(dma1, int, NULL, 0444);
125MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
126module_param_array(dma2, int, NULL, 0444);
127MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
128
Clemens Ladischf7a92752005-12-07 09:13:42 +0100129static struct platform_device *platform_devices[SNDRV_CARDS];
Takashi Iwai59b1b342006-01-04 15:06:44 +0100130#ifdef CONFIG_PNP
Clemens Ladischf7a92752005-12-07 09:13:42 +0100131static int pnpc_registered;
132#ifdef CS4232
133static int pnp_registered;
134#endif
Takashi Iwai59b1b342006-01-04 15:06:44 +0100135#endif /* CONFIG_PNP */
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800136static unsigned int snd_cs423x_devices;
Clemens Ladischf7a92752005-12-07 09:13:42 +0100137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138struct snd_card_cs4236 {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100139 struct snd_cs4231 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#ifdef CONFIG_PNP
149
Takashi Iwaia9824c82005-11-17 17:51:00 +0100150#ifdef CS4232
151/*
152 * PNP BIOS
153 */
154static 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};
162MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
163#endif /* CS4232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165#ifdef CS4232
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100166#define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167static 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" } } },
Lukasz Stemach50f794c2006-01-23 15:22:13 +0100182 /* Netfinity 3000 on-board soundcard */
183 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 /* --- */
185 { .id = "" } /* end */
186};
187#else /* CS4236 */
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100188#define CS423X_ISAPNP_DRIVER "cs4236_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189static 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
271MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
272
Takashi Iwaia9824c82005-11-17 17:51:00 +0100273/* WSS initialization */
274static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev,
275 struct pnp_resource_table *cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 int err;
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 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]);
Takashi Iwaia9824c82005-11-17 17:51:00 +0100311 return 0;
312}
313
314/* CTRL initialization */
315static 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 */
337static 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
369static 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
386static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 /* CTRL initialization */
412 if (acard->ctrl && cport[dev] > 0) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100413 if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl, cfg) < 0)
414 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416 /* MPU initialization */
417 if (acard->mpu && mpu_port[dev] > 0) {
Rene Herman6f595cf2006-02-24 13:03:51 -0800418 if (snd_cs423x_pnp_init_mpu(dev, acard->mpu, cfg) < 0)
Takashi Iwaia9824c82005-11-17 17:51:00 +0100419 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
421 kfree(cfg);
422 return 0;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100423
424 error:
425 kfree(cfg);
426 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428#endif /* CONFIG_PNP */
429
Takashi Iwai43bcd972005-09-05 17:19:20 +0200430#ifdef CONFIG_PNP
431#define is_isapnp_selected(dev) isapnp[dev]
432#else
433#define is_isapnp_selected(dev) 0
434#endif
435
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100436static 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
443static struct snd_card *snd_cs423x_card_new(int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100445 struct snd_card *card;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100446
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
455static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
456{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 struct snd_card_cs4236 *acard;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100458 struct snd_pcm *pcm;
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100459 struct snd_cs4231 *chip;
460 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 int err;
462
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100463 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 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]);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100467 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
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,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200479 &chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100480 return err;
481 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200482
483 if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100484 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200485
486 if ((err = snd_cs4231_mixer(chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100487 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
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,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200498 &chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100499 return err;
500 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200501
502 if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100503 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200504
505 if ((err = snd_cs4236_mixer(chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100506 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507#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
Takashi Iwai43bcd972005-09-05 17:19:20 +0200518 if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100519 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
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) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200525 printk(KERN_WARNING IDENT ": OPL3 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 } else {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200527 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100528 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
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 ? SA_INTERRUPT : 0, NULL) < 0)
Takashi Iwai43bcd972005-09-05 17:19:20 +0200539 printk(KERN_WARNING IDENT ": MPU401 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200541
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100542 return snd_card_register(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100545static 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 }
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800568
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100569 platform_set_drvdata(pdev, card);
570 return 0;
571}
572
573static 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
581static 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
589static 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
597static 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
602static int snd_cs423x_nonpnp_resume(struct platform_device *dev)
603{
604 return snd_cs423x_resume(platform_get_drvdata(dev));
605}
606#endif
607
Takashi Iwaia9824c82005-11-17 17:51:00 +0100608static struct platform_driver cs423x_nonpnp_driver = {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100609 .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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621#ifdef CONFIG_PNP
Takashi Iwaia9824c82005-11-17 17:51:00 +0100622#ifdef CS4232
623static 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++;
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800654 snd_cs423x_devices++;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100655 return 0;
656}
657
658static 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
665static 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
670static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
671{
672 return snd_cs423x_resume(pnp_get_drvdata(pdev));
673}
674#endif
675
676static 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
688static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
689 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
691 static int dev;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100692 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 int res;
694
695 for ( ; dev < SNDRV_CARDS; dev++) {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100696 if (enable[dev] && isapnp[dev])
697 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 }
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100699 if (dev >= SNDRV_CARDS)
700 return -ENODEV;
701
702 card = snd_cs423x_card_new(dev);
703 if (! card)
704 return -ENOMEM;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100705 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");
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100708 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++;
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800718 snd_cs423x_devices++;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100719 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}
721
Takashi Iwaia9824c82005-11-17 17:51:00 +0100722static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100724 snd_card_free(pnp_get_card_drvdata(pcard));
725 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800727
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100728#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100729static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100730{
731 return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
732}
733
Takashi Iwaia9824c82005-11-17 17:51:00 +0100734static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100735{
736 return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
737}
738#endif
739
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740static struct pnp_card_driver cs423x_pnpc_driver = {
741 .flags = PNP_DRIVER_RES_DISABLE,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100742 .name = CS423X_ISAPNP_DRIVER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 .id_table = snd_cs423x_pnpids,
Takashi Iwaia9824c82005-11-17 17:51:00 +0100744 .probe = snd_cs423x_pnpc_detect,
745 .remove = __devexit_p(snd_cs423x_pnpc_remove),
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100746#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100747 .suspend = snd_cs423x_pnpc_suspend,
748 .resume = snd_cs423x_pnpc_resume,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100749#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750};
751#endif /* CONFIG_PNP */
752
Clemens Ladischf7a92752005-12-07 09:13:42 +0100753static void __init_or_module snd_cs423x_unregister_all(void)
754{
755 int i;
756
Takashi Iwai59b1b342006-01-04 15:06:44 +0100757#ifdef CONFIG_PNP
Clemens Ladischf7a92752005-12-07 09:13:42 +0100758 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
Takashi Iwai59b1b342006-01-04 15:06:44 +0100764#endif /* CONFIG_PNP */
Clemens Ladischf7a92752005-12-07 09:13:42 +0100765 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770static int __init alsa_card_cs423x_init(void)
771{
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800772 int i, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Takashi Iwaia9824c82005-11-17 17:51:00 +0100774 if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100775 return err;
776
Takashi Iwai8278ca82006-02-20 11:57:34 +0100777 for (i = 0; i < SNDRV_CARDS; i++) {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100778 struct platform_device *device;
Takashi Iwai8278ca82006-02-20 11:57:34 +0100779 if (! enable[i] || is_isapnp_selected(i))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 continue;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100781 device = platform_device_register_simple(CS423X_DRIVER,
782 i, NULL, 0);
783 if (IS_ERR(device)) {
784 err = PTR_ERR(device);
Clemens Ladischf7a92752005-12-07 09:13:42 +0100785 goto errout;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100786 }
Clemens Ladischf7a92752005-12-07 09:13:42 +0100787 platform_devices[i] = device;
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800788 snd_cs423x_devices++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 }
Takashi Iwai59b1b342006-01-04 15:06:44 +0100790#ifdef CONFIG_PNP
Takashi Iwaia9824c82005-11-17 17:51:00 +0100791#ifdef CS4232
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800792 err = pnp_register_driver(&cs4232_pnp_driver);
793 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100794 pnp_registered = 1;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100795#endif
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800796 err = pnp_register_card_driver(&cs423x_pnpc_driver);
797 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100798 pnpc_registered = 1;
Takashi Iwai59b1b342006-01-04 15:06:44 +0100799#endif /* CONFIG_PNP */
800
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800801 if (!snd_cs423x_devices) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802#ifdef MODULE
803 printk(KERN_ERR IDENT " soundcard not found or device busy\n");
804#endif
Clemens Ladischf7a92752005-12-07 09:13:42 +0100805 err = -ENODEV;
806 goto errout;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
808 return 0;
Clemens Ladischf7a92752005-12-07 09:13:42 +0100809
810 errout:
811 snd_cs423x_unregister_all();
812 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813}
814
815static void __exit alsa_card_cs423x_exit(void)
816{
Clemens Ladischf7a92752005-12-07 09:13:42 +0100817 snd_cs423x_unregister_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818}
819
820module_init(alsa_card_cs423x_init)
821module_exit(alsa_card_cs423x_exit)