blob: 9e399b6e6ed913c0a4c633828fce4de963e4d911 [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"
78#else
79#define IDENT "CS4236+"
80#endif
81
82static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
83static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
84static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
85#ifdef CONFIG_PNP
86static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
87#endif
88static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
89static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
90static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
91static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
92static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
93static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
94static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
95static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
96static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
97
98module_param_array(index, int, NULL, 0444);
99MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
100module_param_array(id, charp, NULL, 0444);
101MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
102module_param_array(enable, bool, NULL, 0444);
103MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
104#ifdef CONFIG_PNP
105module_param_array(isapnp, bool, NULL, 0444);
106MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
107#endif
108module_param_array(port, long, NULL, 0444);
109MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
110module_param_array(cport, long, NULL, 0444);
111MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
112module_param_array(mpu_port, long, NULL, 0444);
113MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
114module_param_array(fm_port, long, NULL, 0444);
115MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
116module_param_array(sb_port, long, NULL, 0444);
117MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
118module_param_array(irq, int, NULL, 0444);
119MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
120module_param_array(mpu_irq, int, NULL, 0444);
121MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
122module_param_array(dma1, int, NULL, 0444);
123MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
124module_param_array(dma2, int, NULL, 0444);
125MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
126
127struct snd_card_cs4236 {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100128 struct snd_cs4231 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 struct resource *res_sb_port;
130#ifdef CONFIG_PNP
131 struct pnp_dev *wss;
132 struct pnp_dev *ctrl;
133 struct pnp_dev *mpu;
134#endif
135};
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef CONFIG_PNP
138
Takashi Iwaia9824c82005-11-17 17:51:00 +0100139#ifdef CS4232
140/*
141 * PNP BIOS
142 */
143static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
144 { .id = "CSC0100" },
145 { .id = "CSC0000" },
146 /* Guillemot Turtlebeach something appears to be cs4232 compatible
147 * (untested) */
148 { .id = "GIM0100" },
149 { .id = "" }
150};
151MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
152#endif /* CS4232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154#ifdef CS4232
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100155#define CS423X_DRIVER "snd_cs4232"
156#define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157static struct pnp_card_device_id snd_cs423x_pnpids[] = {
158 /* Philips PCA70PS */
159 { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
160 /* TerraTec Maestro 32/96 (CS4232) */
161 { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
162 /* HP Omnibook 5500 onboard */
163 { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
164 /* Unnamed CS4236 card (Made in Taiwan) */
165 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
166 /* Turtle Beach TBS-2000 (CS4232) */
167 { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
168 /* Turtle Beach Tropez Plus (CS4232) */
169 { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
170 /* SIC CrystalWave 32 (CS4232) */
171 { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
172 /* --- */
173 { .id = "" } /* end */
174};
175#else /* CS4236 */
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100176#define CS423X_DRIVER "snd_cs4236"
177#define CS423X_ISAPNP_DRIVER "cs4236_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178static struct pnp_card_device_id snd_cs423x_pnpids[] = {
179 /* Intel Marlin Spike Motherboard - CS4235 */
180 { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
181 /* Intel Marlin Spike Motherboard (#2) - CS4235 */
182 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
183 /* Unknown Intel mainboard - CS4235 */
184 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
185 /* Genius Sound Maker 3DJ - CS4237B */
186 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
187 /* Digital PC 5000 Onboard - CS4236B */
188 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
189 /* some uknown CS4236B */
190 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
191 /* Intel PR440FX Onboard sound */
192 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
193 /* CS4235 on mainboard without MPU */
194 { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
195 /* Gateway E1000 Onboard CS4236B */
196 { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
197 /* HP 6330 Onboard sound */
198 { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
199 /* Crystal Computer TidalWave128 */
200 { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
201 /* ACER AW37 - CS4235 */
202 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
203 /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
204 { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
205 /* Crystal 3D - CS4237B */
206 { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
207 /* Typhoon Soundsystem PnP - CS4236B */
208 { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
209 /* Crystal CX4235-XQ3 EP - CS4235 */
210 { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
211 /* Crystal Semiconductors CS4237B */
212 { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
213 /* NewClear 3D - CX4237B-XQ3 */
214 { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
215 /* Dell Optiplex GX1 - CS4236B */
216 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
217 /* Dell P410 motherboard - CS4236B */
218 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
219 /* Dell Workstation 400 Onboard - CS4236B */
220 { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
221 /* Turtle Beach Malibu - CS4237B */
222 { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
223 /* CS4235 - onboard */
224 { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
225 /* IBM Aptiva 2137 E24 Onboard - CS4237B */
226 { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
227 /* IBM IntelliStation M Pro motherboard */
228 { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
229 /* Guillemot MaxiSound 16 PnP - CS4236B */
230 { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
231 /* Gallant SC-70P */
232 { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
233 /* TerraTec AudioSystem EWS64XL - CS4236B */
234 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
235 /* TerraTec AudioSystem EWS64XL - CS4236B */
236 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
237 /* ACER AW37/Pro - CS4235 */
238 { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
239 /* ACER AW35/Pro - CS4237B */
240 { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
241 /* CS4235 without MPU401 */
242 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
243 /* Unknown SiS530 - CS4235 */
244 { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
245 /* IBM IntelliStation M Pro 6898 11U - CS4236B */
246 { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
247 /* IBM PC 300PL Onboard - CS4236B */
248 { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
249 /* Some noname CS4236 based card */
250 { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
251 /* CS4236B */
252 { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
253 /* CS4236B */
254 { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
255 /* --- */
256 { .id = "" } /* end */
257};
258#endif
259
260MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
261
Takashi Iwaia9824c82005-11-17 17:51:00 +0100262/* WSS initialization */
263static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev,
264 struct pnp_resource_table *cfg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 int err;
267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 pnp_init_resource_table(cfg);
269 if (port[dev] != SNDRV_AUTO_PORT)
270 pnp_resource_change(&cfg->port_resource[0], port[dev], 4);
271 if (fm_port[dev] != SNDRV_AUTO_PORT && fm_port[dev] > 0)
272 pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
273 if (sb_port[dev] != SNDRV_AUTO_PORT)
274 pnp_resource_change(&cfg->port_resource[2], sb_port[dev], 16);
275 if (irq[dev] != SNDRV_AUTO_IRQ)
276 pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
277 if (dma1[dev] != SNDRV_AUTO_DMA)
278 pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
279 if (dma2[dev] != SNDRV_AUTO_DMA)
280 pnp_resource_change(&cfg->dma_resource[1], dma2[dev] < 0 ? 4 : dma2[dev], 1);
281 err = pnp_manual_config_dev(pdev, cfg, 0);
282 if (err < 0)
283 snd_printk(KERN_ERR IDENT " WSS PnP manual resources are invalid, using auto config\n");
284 err = pnp_activate_dev(pdev);
285 if (err < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
287 return -EBUSY;
288 }
289 port[dev] = pnp_port_start(pdev, 0);
290 if (fm_port[dev] > 0)
291 fm_port[dev] = pnp_port_start(pdev, 1);
292 sb_port[dev] = pnp_port_start(pdev, 2);
293 irq[dev] = pnp_irq(pdev, 0);
294 dma1[dev] = pnp_dma(pdev, 0);
295 dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
296 snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
297 port[dev], fm_port[dev], sb_port[dev]);
298 snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
299 irq[dev], dma1[dev], dma2[dev]);
Takashi Iwaia9824c82005-11-17 17:51:00 +0100300 return 0;
301}
302
303/* CTRL initialization */
304static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev,
305 struct pnp_resource_table *cfg)
306{
307 int err;
308
309 pnp_init_resource_table(cfg);
310 if (cport[dev] != SNDRV_AUTO_PORT)
311 pnp_resource_change(&cfg->port_resource[0], cport[dev], 8);
312 err = pnp_manual_config_dev(pdev, cfg, 0);
313 if (err < 0)
314 snd_printk(KERN_ERR IDENT " CTRL PnP manual resources are invalid, using auto config\n");
315 err = pnp_activate_dev(pdev);
316 if (err < 0) {
317 printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
318 return -EBUSY;
319 }
320 cport[dev] = pnp_port_start(pdev, 0);
321 snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
322 return 0;
323}
324
325/* MPU initialization */
326static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev,
327 struct pnp_resource_table *cfg)
328{
329 int err;
330
331 pnp_init_resource_table(cfg);
332 if (mpu_port[dev] != SNDRV_AUTO_PORT)
333 pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
334 if (mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] >= 0)
335 pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
336 err = pnp_manual_config_dev(pdev, cfg, 0);
337 if (err < 0)
338 snd_printk(KERN_ERR IDENT " MPU401 PnP manual resources are invalid, using auto config\n");
339 err = pnp_activate_dev(pdev);
340 if (err < 0) {
341 printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
342 mpu_port[dev] = SNDRV_AUTO_PORT;
343 mpu_irq[dev] = SNDRV_AUTO_IRQ;
344 } else {
345 mpu_port[dev] = pnp_port_start(pdev, 0);
346 if (mpu_irq[dev] >= 0 &&
347 pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
348 mpu_irq[dev] = pnp_irq(pdev, 0);
349 } else {
350 mpu_irq[dev] = -1; /* disable interrupt */
351 }
352 }
353 snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
354 return 0;
355}
356
357#ifdef CS4232
358static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard,
359 struct pnp_dev *pdev)
360{
361 struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
362
363 if (!cfg)
364 return -ENOMEM;
365 if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0) {
366 kfree(cfg);
367 return -EBUSY;
368 }
369 kfree(cfg);
370 cport[dev] = -1;
371 return 0;
372}
373#endif
374
375static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
376 struct pnp_card_link *card,
377 const struct pnp_card_device_id *id)
378{
379 struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
380
381 if (!cfg)
382 return -ENOMEM;
383
384 acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
385 if (acard->wss == NULL)
386 goto error;
387 acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
388 if (acard->ctrl == NULL)
389 goto error;
390 if (id->devs[2].id[0]) {
391 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
392 if (acard->mpu == NULL)
393 goto error;
394 }
395
396 /* WSS initialization */
397 if (snd_cs423x_pnp_init_wss(dev, acard->wss, cfg) < 0)
398 goto error;
399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 /* CTRL initialization */
401 if (acard->ctrl && cport[dev] > 0) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100402 if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl, cfg) < 0)
403 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405 /* MPU initialization */
406 if (acard->mpu && mpu_port[dev] > 0) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100407 if (snd_cs423x_pnp_init_mpu(dev, acard->ctrl, cfg) < 0)
408 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 }
410 kfree(cfg);
411 return 0;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100412
413 error:
414 kfree(cfg);
415 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417#endif /* CONFIG_PNP */
418
Takashi Iwai43bcd972005-09-05 17:19:20 +0200419#ifdef CONFIG_PNP
420#define is_isapnp_selected(dev) isapnp[dev]
421#else
422#define is_isapnp_selected(dev) 0
423#endif
424
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100425static void snd_card_cs4236_free(struct snd_card *card)
426{
427 struct snd_card_cs4236 *acard = card->private_data;
428
429 release_and_free_resource(acard->res_sb_port);
430}
431
432static struct snd_card *snd_cs423x_card_new(int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433{
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100434 struct snd_card *card;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100435
436 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
437 sizeof(struct snd_card_cs4236));
438 if (card == NULL)
439 return NULL;
440 card->private_free = snd_card_cs4236_free;
441 return card;
442}
443
444static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
445{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 struct snd_card_cs4236 *acard;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100447 struct snd_pcm *pcm;
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100448 struct snd_cs4231 *chip;
449 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 int err;
451
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100452 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
454 if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
455 printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100456 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458
459#ifdef CS4232
460 if ((err = snd_cs4231_create(card,
461 port[dev],
462 cport[dev],
463 irq[dev],
464 dma1[dev],
465 dma2[dev],
466 CS4231_HW_DETECT,
467 0,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200468 &chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100469 return err;
470 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200471
472 if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100473 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200474
475 if ((err = snd_cs4231_mixer(chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100476 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478#else /* CS4236 */
479 if ((err = snd_cs4236_create(card,
480 port[dev],
481 cport[dev],
482 irq[dev],
483 dma1[dev],
484 dma2[dev],
485 CS4231_HW_DETECT,
486 0,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200487 &chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100488 return err;
489 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200490
491 if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100492 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200493
494 if ((err = snd_cs4236_mixer(chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100495 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496#endif
497 strcpy(card->driver, pcm->name);
498 strcpy(card->shortname, pcm->name);
499 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
500 pcm->name,
501 chip->port,
502 irq[dev],
503 dma1[dev]);
504 if (dma2[dev] >= 0)
505 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
506
Takashi Iwai43bcd972005-09-05 17:19:20 +0200507 if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100508 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
511 if (snd_opl3_create(card,
512 fm_port[dev], fm_port[dev] + 2,
513 OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200514 printk(KERN_WARNING IDENT ": OPL3 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 } else {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200516 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100517 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519 }
520
521 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
522 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
523 mpu_irq[dev] = -1;
524 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
525 mpu_port[dev], 0,
526 mpu_irq[dev],
527 mpu_irq[dev] >= 0 ? SA_INTERRUPT : 0, NULL) < 0)
Takashi Iwai43bcd972005-09-05 17:19:20 +0200528 printk(KERN_WARNING IDENT ": MPU401 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200530
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100531 return snd_card_register(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532}
533
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100534static int __init snd_cs423x_nonpnp_probe(struct platform_device *pdev)
535{
536 int dev = pdev->id;
537 struct snd_card *card;
538 int err;
539
540 if (port[dev] == SNDRV_AUTO_PORT) {
541 snd_printk(KERN_ERR "specify port\n");
542 return -EINVAL;
543 }
544 if (cport[dev] == SNDRV_AUTO_PORT) {
545 snd_printk(KERN_ERR "specify cport\n");
546 return -EINVAL;
547 }
548
549 card = snd_cs423x_card_new(dev);
550 if (! card)
551 return -ENOMEM;
552 snd_card_set_dev(card, &pdev->dev);
553 if ((err = snd_cs423x_probe(card, dev)) < 0) {
554 snd_card_free(card);
555 return err;
556 }
557
558 platform_set_drvdata(pdev, card);
559 return 0;
560}
561
562static int __devexit snd_cs423x_nonpnp_remove(struct platform_device *devptr)
563{
564 snd_card_free(platform_get_drvdata(devptr));
565 platform_set_drvdata(devptr, NULL);
566 return 0;
567}
568
569#ifdef CONFIG_PM
570static int snd_cs423x_suspend(struct snd_card *card)
571{
572 struct snd_card_cs4236 *acard = card->private_data;
573 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
574 acard->chip->suspend(acard->chip);
575 return 0;
576}
577
578static int snd_cs423x_resume(struct snd_card *card)
579{
580 struct snd_card_cs4236 *acard = card->private_data;
581 acard->chip->resume(acard->chip);
582 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
583 return 0;
584}
585
586static int snd_cs423x_nonpnp_suspend(struct platform_device *dev, pm_message_t state)
587{
588 return snd_cs423x_suspend(platform_get_drvdata(dev));
589}
590
591static int snd_cs423x_nonpnp_resume(struct platform_device *dev)
592{
593 return snd_cs423x_resume(platform_get_drvdata(dev));
594}
595#endif
596
Takashi Iwaia9824c82005-11-17 17:51:00 +0100597static struct platform_driver cs423x_nonpnp_driver = {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100598 .probe = snd_cs423x_nonpnp_probe,
599 .remove = __devexit_p(snd_cs423x_nonpnp_remove),
600#ifdef CONFIG_PM
601 .suspend = snd_cs423x_nonpnp_suspend,
602 .resume = snd_cs423x_nonpnp_resume,
603#endif
604 .driver = {
605 .name = CS423X_DRIVER
606 },
607};
608
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#ifdef CONFIG_PNP
Takashi Iwaia9824c82005-11-17 17:51:00 +0100611#ifdef CS4232
612static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
613 const struct pnp_device_id *id)
614{
615 static int dev;
616 int err;
617 struct snd_card *card;
618
619 if (pnp_device_is_isapnp(pdev))
620 return -ENOENT; /* we have another procedure - card */
621 for (; dev < SNDRV_CARDS; dev++) {
622 if (enable[dev] && isapnp[dev])
623 break;
624 }
625 if (dev >= SNDRV_CARDS)
626 return -ENODEV;
627
628 card = snd_cs423x_card_new(dev);
629 if (! card)
630 return -ENOMEM;
631 if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
632 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
633 snd_card_free(card);
634 return err;
635 }
636 snd_card_set_dev(card, &pdev->dev);
637 if ((err = snd_cs423x_probe(card, dev)) < 0) {
638 snd_card_free(card);
639 return err;
640 }
641 pnp_set_drvdata(pdev, card);
642 dev++;
643 return 0;
644}
645
646static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
647{
648 snd_card_free(pnp_get_drvdata(pdev));
649 pnp_set_drvdata(pdev, NULL);
650}
651
652#ifdef CONFIG_PM
653static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
654{
655 return snd_cs423x_suspend(pnp_get_drvdata(pdev));
656}
657
658static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
659{
660 return snd_cs423x_resume(pnp_get_drvdata(pdev));
661}
662#endif
663
664static struct pnp_driver cs4232_pnp_driver = {
665 .name = "cs4232-pnpbios",
666 .id_table = snd_cs4232_pnpbiosids,
667 .probe = snd_cs4232_pnpbios_detect,
668 .remove = __devexit_p(snd_cs4232_pnp_remove),
669#ifdef CONFIG_PM
670 .suspend = snd_cs4232_pnp_suspend,
671 .resume = snd_cs4232_pnp_resume,
672#endif
673};
674#endif /* CS4232 */
675
676static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
677 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
679 static int dev;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100680 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 int res;
682
683 for ( ; dev < SNDRV_CARDS; dev++) {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100684 if (enable[dev] && isapnp[dev])
685 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100687 if (dev >= SNDRV_CARDS)
688 return -ENODEV;
689
690 card = snd_cs423x_card_new(dev);
691 if (! card)
692 return -ENOMEM;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100693 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
694 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
695 " is not supported\n");
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100696 snd_card_free(card);
697 return res;
698 }
699 snd_card_set_dev(card, &pcard->card->dev);
700 if ((res = snd_cs423x_probe(card, dev)) < 0) {
701 snd_card_free(card);
702 return res;
703 }
704 pnp_set_card_drvdata(pcard, card);
705 dev++;
706 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707}
708
Takashi Iwaia9824c82005-11-17 17:51:00 +0100709static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100711 snd_card_free(pnp_get_card_drvdata(pcard));
712 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713}
714
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100715#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100716static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100717{
718 return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
719}
720
Takashi Iwaia9824c82005-11-17 17:51:00 +0100721static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100722{
723 return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
724}
725#endif
726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727static struct pnp_card_driver cs423x_pnpc_driver = {
728 .flags = PNP_DRIVER_RES_DISABLE,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100729 .name = CS423X_ISAPNP_DRIVER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 .id_table = snd_cs423x_pnpids,
Takashi Iwaia9824c82005-11-17 17:51:00 +0100731 .probe = snd_cs423x_pnpc_detect,
732 .remove = __devexit_p(snd_cs423x_pnpc_remove),
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100733#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100734 .suspend = snd_cs423x_pnpc_suspend,
735 .resume = snd_cs423x_pnpc_resume,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100736#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737};
738#endif /* CONFIG_PNP */
739
740static int __init alsa_card_cs423x_init(void)
741{
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100742 int i, err, cards = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743
Takashi Iwaia9824c82005-11-17 17:51:00 +0100744 if ((err = platform_driver_register(&cs423x_nonpnp_driver)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100745 return err;
746
747 for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
748 struct platform_device *device;
749 if (is_isapnp_selected(i))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 continue;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100751 device = platform_device_register_simple(CS423X_DRIVER,
752 i, NULL, 0);
753 if (IS_ERR(device)) {
754 err = PTR_ERR(device);
Takashi Iwaia9824c82005-11-17 17:51:00 +0100755 platform_driver_unregister(&cs423x_nonpnp_driver);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100756 return err;
757 }
758 cards++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 }
Takashi Iwaia9824c82005-11-17 17:51:00 +0100760#ifdef CS4232
761 i = pnp_register_driver(&cs4232_pnp_driver);
762 if (i > 0)
763 cards += i;
764#endif
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100765 i = pnp_register_card_driver(&cs423x_pnpc_driver);
766 if (i > 0)
767 cards += i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 if (!cards) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100769#ifdef CS4232
770 pnp_unregister_driver(&cs4232_pnp_driver);
771#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 pnp_unregister_card_driver(&cs423x_pnpc_driver);
Takashi Iwaia9824c82005-11-17 17:51:00 +0100773 platform_driver_unregister(&cs423x_nonpnp_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774#ifdef MODULE
775 printk(KERN_ERR IDENT " soundcard not found or device busy\n");
776#endif
777 return -ENODEV;
778 }
779 return 0;
780}
781
782static void __exit alsa_card_cs423x_exit(void)
783{
Takashi Iwaia9824c82005-11-17 17:51:00 +0100784#ifdef CS4232
785 pnp_unregister_driver(&cs4232_pnp_driver);
786#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 pnp_unregister_card_driver(&cs423x_pnpc_driver);
Takashi Iwaia9824c82005-11-17 17:51:00 +0100788 platform_driver_unregister(&cs423x_nonpnp_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789}
790
791module_init(alsa_card_cs423x_init)
792module_exit(alsa_card_cs423x_exit)