blob: 0a3fece40f8b79b0f5a85566a029dd3ce2cd69e7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Driver for generic CS4232/CS4235/CS4236/CS4236B/CS4237B/CS4238B/CS4239 chips
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02003 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
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>
Takashi Iwai5e24c1c2007-02-22 12:50:54 +010025#include <linux/isa.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
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020035MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070036MODULE_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"
Rene Herman83c51c02007-03-20 11:33:46 +010078#define DEV_NAME "cs4232"
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#else
80#define IDENT "CS4236+"
Rene Herman83c51c02007-03-20 11:33:46 +010081#define DEV_NAME "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
Takashi Iwai59b1b342006-01-04 15:06:44 +0100129#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +0200130static int isa_registered;
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 */
Clemens Ladischf7a92752005-12-07 09:13:42 +0100136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137struct snd_card_cs4236 {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100138 struct snd_cs4231 *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 struct resource *res_sb_port;
140#ifdef CONFIG_PNP
141 struct pnp_dev *wss;
142 struct pnp_dev *ctrl;
143 struct pnp_dev *mpu;
144#endif
145};
146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#ifdef CONFIG_PNP
148
Takashi Iwaia9824c82005-11-17 17:51:00 +0100149#ifdef CS4232
150/*
151 * PNP BIOS
152 */
153static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
154 { .id = "CSC0100" },
155 { .id = "CSC0000" },
156 /* Guillemot Turtlebeach something appears to be cs4232 compatible
157 * (untested) */
158 { .id = "GIM0100" },
159 { .id = "" }
160};
161MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
162#endif /* CS4232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164#ifdef CS4232
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100165#define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166static struct pnp_card_device_id snd_cs423x_pnpids[] = {
167 /* Philips PCA70PS */
168 { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
169 /* TerraTec Maestro 32/96 (CS4232) */
170 { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
171 /* HP Omnibook 5500 onboard */
172 { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
173 /* Unnamed CS4236 card (Made in Taiwan) */
174 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
175 /* Turtle Beach TBS-2000 (CS4232) */
176 { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
177 /* Turtle Beach Tropez Plus (CS4232) */
178 { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
179 /* SIC CrystalWave 32 (CS4232) */
180 { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
Lukasz Stemach50f794c2006-01-23 15:22:13 +0100181 /* Netfinity 3000 on-board soundcard */
182 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 /* --- */
184 { .id = "" } /* end */
185};
186#else /* CS4236 */
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100187#define CS423X_ISAPNP_DRIVER "cs4236_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static struct pnp_card_device_id snd_cs423x_pnpids[] = {
189 /* Intel Marlin Spike Motherboard - CS4235 */
190 { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
191 /* Intel Marlin Spike Motherboard (#2) - CS4235 */
192 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
193 /* Unknown Intel mainboard - CS4235 */
194 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
195 /* Genius Sound Maker 3DJ - CS4237B */
196 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
197 /* Digital PC 5000 Onboard - CS4236B */
198 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
199 /* some uknown CS4236B */
200 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
201 /* Intel PR440FX Onboard sound */
202 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
203 /* CS4235 on mainboard without MPU */
204 { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
205 /* Gateway E1000 Onboard CS4236B */
206 { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
207 /* HP 6330 Onboard sound */
208 { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
209 /* Crystal Computer TidalWave128 */
210 { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
211 /* ACER AW37 - CS4235 */
212 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
213 /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
214 { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
215 /* Crystal 3D - CS4237B */
216 { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
217 /* Typhoon Soundsystem PnP - CS4236B */
218 { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
219 /* Crystal CX4235-XQ3 EP - CS4235 */
220 { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
221 /* Crystal Semiconductors CS4237B */
222 { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
223 /* NewClear 3D - CX4237B-XQ3 */
224 { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
225 /* Dell Optiplex GX1 - CS4236B */
226 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
227 /* Dell P410 motherboard - CS4236B */
228 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
229 /* Dell Workstation 400 Onboard - CS4236B */
230 { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
231 /* Turtle Beach Malibu - CS4237B */
232 { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
233 /* CS4235 - onboard */
234 { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
235 /* IBM Aptiva 2137 E24 Onboard - CS4237B */
236 { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
237 /* IBM IntelliStation M Pro motherboard */
238 { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
239 /* Guillemot MaxiSound 16 PnP - CS4236B */
240 { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
241 /* Gallant SC-70P */
242 { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
243 /* TerraTec AudioSystem EWS64XL - CS4236B */
244 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" }, { "CSCa803" } } },
245 /* TerraTec AudioSystem EWS64XL - CS4236B */
246 { .id = "CSCa836", .devs = { { "CSCa800" }, { "CSCa810" } } },
247 /* ACER AW37/Pro - CS4235 */
248 { .id = "CSCd925", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
249 /* ACER AW35/Pro - CS4237B */
250 { .id = "CSCd937", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
251 /* CS4235 without MPU401 */
252 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" } } },
253 /* Unknown SiS530 - CS4235 */
254 { .id = "CSC4825", .devs = { { "CSC0100" }, { "CSC0110" } } },
255 /* IBM IntelliStation M Pro 6898 11U - CS4236B */
256 { .id = "CSCe835", .devs = { { "CSC0000" }, { "CSC0010" } } },
257 /* IBM PC 300PL Onboard - CS4236B */
258 { .id = "CSCe836", .devs = { { "CSC0000" }, { "CSC0010" } } },
259 /* Some noname CS4236 based card */
260 { .id = "CSCe936", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
261 /* CS4236B */
262 { .id = "CSCf235", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
263 /* CS4236B */
264 { .id = "CSCf238", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
265 /* --- */
266 { .id = "" } /* end */
267};
268#endif
269
270MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
271
Takashi Iwaia9824c82005-11-17 17:51:00 +0100272/* WSS initialization */
Rene Herman109c53f842007-11-30 17:59:25 +0100273static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Rene Herman109c53f842007-11-30 17:59:25 +0100275 if (pnp_activate_dev(pdev) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
277 return -EBUSY;
278 }
279 port[dev] = pnp_port_start(pdev, 0);
280 if (fm_port[dev] > 0)
281 fm_port[dev] = pnp_port_start(pdev, 1);
282 sb_port[dev] = pnp_port_start(pdev, 2);
283 irq[dev] = pnp_irq(pdev, 0);
284 dma1[dev] = pnp_dma(pdev, 0);
285 dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
286 snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
287 port[dev], fm_port[dev], sb_port[dev]);
288 snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
289 irq[dev], dma1[dev], dma2[dev]);
Takashi Iwaia9824c82005-11-17 17:51:00 +0100290 return 0;
291}
292
293/* CTRL initialization */
Rene Herman109c53f842007-11-30 17:59:25 +0100294static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev)
Takashi Iwaia9824c82005-11-17 17:51:00 +0100295{
Rene Herman109c53f842007-11-30 17:59:25 +0100296 if (pnp_activate_dev(pdev) < 0) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100297 printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
298 return -EBUSY;
299 }
300 cport[dev] = pnp_port_start(pdev, 0);
301 snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
302 return 0;
303}
304
305/* MPU initialization */
Rene Herman109c53f842007-11-30 17:59:25 +0100306static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev)
Takashi Iwaia9824c82005-11-17 17:51:00 +0100307{
Rene Herman109c53f842007-11-30 17:59:25 +0100308 if (pnp_activate_dev(pdev) < 0) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100309 printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
310 mpu_port[dev] = SNDRV_AUTO_PORT;
311 mpu_irq[dev] = SNDRV_AUTO_IRQ;
312 } else {
313 mpu_port[dev] = pnp_port_start(pdev, 0);
314 if (mpu_irq[dev] >= 0 &&
315 pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
316 mpu_irq[dev] = pnp_irq(pdev, 0);
317 } else {
318 mpu_irq[dev] = -1; /* disable interrupt */
319 }
320 }
321 snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
322 return 0;
323}
324
325#ifdef CS4232
326static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard,
327 struct pnp_dev *pdev)
328{
Rene Herman109c53f842007-11-30 17:59:25 +0100329 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
Takashi Iwaia9824c82005-11-17 17:51:00 +0100330 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100331 cport[dev] = -1;
332 return 0;
333}
334#endif
335
336static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
337 struct pnp_card_link *card,
338 const struct pnp_card_device_id *id)
339{
Takashi Iwaia9824c82005-11-17 17:51:00 +0100340 acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
341 if (acard->wss == NULL)
Rene Herman109c53f842007-11-30 17:59:25 +0100342 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100343 acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
344 if (acard->ctrl == NULL)
Rene Herman109c53f842007-11-30 17:59:25 +0100345 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100346 if (id->devs[2].id[0]) {
347 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
348 if (acard->mpu == NULL)
Rene Herman109c53f842007-11-30 17:59:25 +0100349 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100350 }
351
352 /* WSS initialization */
Rene Herman109c53f842007-11-30 17:59:25 +0100353 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
354 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 /* CTRL initialization */
357 if (acard->ctrl && cport[dev] > 0) {
Rene Herman109c53f842007-11-30 17:59:25 +0100358 if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
359 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361 /* MPU initialization */
362 if (acard->mpu && mpu_port[dev] > 0) {
Rene Herman109c53f842007-11-30 17:59:25 +0100363 if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
364 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 return 0;
367}
368#endif /* CONFIG_PNP */
369
Takashi Iwai43bcd972005-09-05 17:19:20 +0200370#ifdef CONFIG_PNP
371#define is_isapnp_selected(dev) isapnp[dev]
372#else
373#define is_isapnp_selected(dev) 0
374#endif
375
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100376static void snd_card_cs4236_free(struct snd_card *card)
377{
378 struct snd_card_cs4236 *acard = card->private_data;
379
380 release_and_free_resource(acard->res_sb_port);
381}
382
383static struct snd_card *snd_cs423x_card_new(int dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100385 struct snd_card *card;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100386
387 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
388 sizeof(struct snd_card_cs4236));
389 if (card == NULL)
390 return NULL;
391 card->private_free = snd_card_cs4236_free;
392 return card;
393}
394
395static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
396{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 struct snd_card_cs4236 *acard;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100398 struct snd_pcm *pcm;
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100399 struct snd_cs4231 *chip;
400 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 int err;
402
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100403 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
405 if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
406 printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100407 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 }
409
410#ifdef CS4232
411 if ((err = snd_cs4231_create(card,
412 port[dev],
413 cport[dev],
414 irq[dev],
415 dma1[dev],
416 dma2[dev],
417 CS4231_HW_DETECT,
418 0,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200419 &chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100420 return err;
421 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200422
423 if ((err = snd_cs4231_pcm(chip, 0, &pcm)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100424 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200425
426 if ((err = snd_cs4231_mixer(chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100427 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429#else /* CS4236 */
430 if ((err = snd_cs4236_create(card,
431 port[dev],
432 cport[dev],
433 irq[dev],
434 dma1[dev],
435 dma2[dev],
436 CS4231_HW_DETECT,
437 0,
Takashi Iwai43bcd972005-09-05 17:19:20 +0200438 &chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100439 return err;
440 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200441
442 if ((err = snd_cs4236_pcm(chip, 0, &pcm)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100443 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200444
445 if ((err = snd_cs4236_mixer(chip)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100446 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#endif
448 strcpy(card->driver, pcm->name);
449 strcpy(card->shortname, pcm->name);
450 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
451 pcm->name,
452 chip->port,
453 irq[dev],
454 dma1[dev]);
455 if (dma2[dev] >= 0)
456 sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
457
Takashi Iwai43bcd972005-09-05 17:19:20 +0200458 if ((err = snd_cs4231_timer(chip, 0, NULL)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100459 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
462 if (snd_opl3_create(card,
463 fm_port[dev], fm_port[dev] + 2,
464 OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200465 printk(KERN_WARNING IDENT ": OPL3 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 } else {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200467 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100468 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470 }
471
472 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
473 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
474 mpu_irq[dev] = -1;
475 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
476 mpu_port[dev], 0,
477 mpu_irq[dev],
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700478 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
Takashi Iwai43bcd972005-09-05 17:19:20 +0200479 printk(KERN_WARNING IDENT ": MPU401 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200481
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100482 return snd_card_register(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483}
484
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100485static int __devinit snd_cs423x_isa_match(struct device *pdev,
486 unsigned int dev)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100487{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100488 if (!enable[dev] || is_isapnp_selected(dev))
489 return 0;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100490
491 if (port[dev] == SNDRV_AUTO_PORT) {
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100492 snd_printk(KERN_ERR "%s: please specify port\n", pdev->bus_id);
493 return 0;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100494 }
495 if (cport[dev] == SNDRV_AUTO_PORT) {
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100496 snd_printk(KERN_ERR "%s: please specify cport\n", pdev->bus_id);
497 return 0;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100498 }
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100499 if (irq[dev] == SNDRV_AUTO_IRQ) {
500 snd_printk(KERN_ERR "%s: please specify irq\n", pdev->bus_id);
501 return 0;
502 }
503 if (dma1[dev] == SNDRV_AUTO_DMA) {
504 snd_printk(KERN_ERR "%s: please specify dma1\n", pdev->bus_id);
505 return 0;
506 }
507 return 1;
508}
509
510static int __devinit snd_cs423x_isa_probe(struct device *pdev,
511 unsigned int dev)
512{
513 struct snd_card *card;
514 int err;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100515
516 card = snd_cs423x_card_new(dev);
517 if (! card)
518 return -ENOMEM;
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100519 snd_card_set_dev(card, pdev);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100520 if ((err = snd_cs423x_probe(card, dev)) < 0) {
521 snd_card_free(card);
522 return err;
523 }
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800524
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100525 dev_set_drvdata(pdev, card);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100526 return 0;
527}
528
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100529static int __devexit snd_cs423x_isa_remove(struct device *pdev,
530 unsigned int dev)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100531{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100532 snd_card_free(dev_get_drvdata(pdev));
533 dev_set_drvdata(pdev, NULL);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100534 return 0;
535}
536
537#ifdef CONFIG_PM
538static int snd_cs423x_suspend(struct snd_card *card)
539{
540 struct snd_card_cs4236 *acard = card->private_data;
541 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
542 acard->chip->suspend(acard->chip);
543 return 0;
544}
545
546static int snd_cs423x_resume(struct snd_card *card)
547{
548 struct snd_card_cs4236 *acard = card->private_data;
549 acard->chip->resume(acard->chip);
550 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
551 return 0;
552}
553
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100554static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
555 pm_message_t state)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100556{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100557 return snd_cs423x_suspend(dev_get_drvdata(dev));
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100558}
559
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100560static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100561{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100562 return snd_cs423x_resume(dev_get_drvdata(dev));
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100563}
564#endif
565
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100566static struct isa_driver cs423x_isa_driver = {
567 .match = snd_cs423x_isa_match,
568 .probe = snd_cs423x_isa_probe,
569 .remove = __devexit_p(snd_cs423x_isa_remove),
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100570#ifdef CONFIG_PM
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100571 .suspend = snd_cs423x_isa_suspend,
572 .resume = snd_cs423x_isa_resume,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100573#endif
574 .driver = {
Rene Herman83c51c02007-03-20 11:33:46 +0100575 .name = DEV_NAME
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100576 },
577};
578
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580#ifdef CONFIG_PNP
Takashi Iwaia9824c82005-11-17 17:51:00 +0100581#ifdef CS4232
582static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
583 const struct pnp_device_id *id)
584{
585 static int dev;
586 int err;
587 struct snd_card *card;
588
589 if (pnp_device_is_isapnp(pdev))
590 return -ENOENT; /* we have another procedure - card */
591 for (; dev < SNDRV_CARDS; dev++) {
592 if (enable[dev] && isapnp[dev])
593 break;
594 }
595 if (dev >= SNDRV_CARDS)
596 return -ENODEV;
597
598 card = snd_cs423x_card_new(dev);
599 if (! card)
600 return -ENOMEM;
601 if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
602 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
603 snd_card_free(card);
604 return err;
605 }
606 snd_card_set_dev(card, &pdev->dev);
607 if ((err = snd_cs423x_probe(card, dev)) < 0) {
608 snd_card_free(card);
609 return err;
610 }
611 pnp_set_drvdata(pdev, card);
612 dev++;
613 return 0;
614}
615
616static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
617{
618 snd_card_free(pnp_get_drvdata(pdev));
619 pnp_set_drvdata(pdev, NULL);
620}
621
622#ifdef CONFIG_PM
623static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
624{
625 return snd_cs423x_suspend(pnp_get_drvdata(pdev));
626}
627
628static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
629{
630 return snd_cs423x_resume(pnp_get_drvdata(pdev));
631}
632#endif
633
634static struct pnp_driver cs4232_pnp_driver = {
635 .name = "cs4232-pnpbios",
636 .id_table = snd_cs4232_pnpbiosids,
637 .probe = snd_cs4232_pnpbios_detect,
638 .remove = __devexit_p(snd_cs4232_pnp_remove),
639#ifdef CONFIG_PM
640 .suspend = snd_cs4232_pnp_suspend,
641 .resume = snd_cs4232_pnp_resume,
642#endif
643};
644#endif /* CS4232 */
645
646static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
647 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
649 static int dev;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100650 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 int res;
652
653 for ( ; dev < SNDRV_CARDS; dev++) {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100654 if (enable[dev] && isapnp[dev])
655 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 }
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100657 if (dev >= SNDRV_CARDS)
658 return -ENODEV;
659
660 card = snd_cs423x_card_new(dev);
661 if (! card)
662 return -ENOMEM;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100663 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
664 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
665 " is not supported\n");
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100666 snd_card_free(card);
667 return res;
668 }
669 snd_card_set_dev(card, &pcard->card->dev);
670 if ((res = snd_cs423x_probe(card, dev)) < 0) {
671 snd_card_free(card);
672 return res;
673 }
674 pnp_set_card_drvdata(pcard, card);
675 dev++;
676 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
Takashi Iwaia9824c82005-11-17 17:51:00 +0100679static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680{
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100681 snd_card_free(pnp_get_card_drvdata(pcard));
682 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800684
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100685#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100686static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100687{
688 return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
689}
690
Takashi Iwaia9824c82005-11-17 17:51:00 +0100691static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100692{
693 return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
694}
695#endif
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697static struct pnp_card_driver cs423x_pnpc_driver = {
698 .flags = PNP_DRIVER_RES_DISABLE,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100699 .name = CS423X_ISAPNP_DRIVER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 .id_table = snd_cs423x_pnpids,
Takashi Iwaia9824c82005-11-17 17:51:00 +0100701 .probe = snd_cs423x_pnpc_detect,
702 .remove = __devexit_p(snd_cs423x_pnpc_remove),
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100703#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100704 .suspend = snd_cs423x_pnpc_suspend,
705 .resume = snd_cs423x_pnpc_resume,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100706#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707};
708#endif /* CONFIG_PNP */
709
710static int __init alsa_card_cs423x_init(void)
711{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100712 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100714 err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
Takashi Iwai59b1b342006-01-04 15:06:44 +0100715#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +0200716 if (!err)
717 isa_registered = 1;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100718#ifdef CS4232
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800719 err = pnp_register_driver(&cs4232_pnp_driver);
720 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100721 pnp_registered = 1;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100722#endif
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800723 err = pnp_register_card_driver(&cs423x_pnpc_driver);
724 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100725 pnpc_registered = 1;
Rene Herman609d7692007-05-15 11:42:56 +0200726#ifdef CS4232
727 if (pnp_registered)
728 err = 0;
729#endif
730 if (isa_registered)
731 err = 0;
732#endif
733 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734}
735
736static void __exit alsa_card_cs423x_exit(void)
737{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100738#ifdef CONFIG_PNP
739 if (pnpc_registered)
740 pnp_unregister_card_driver(&cs423x_pnpc_driver);
741#ifdef CS4232
742 if (pnp_registered)
743 pnp_unregister_driver(&cs4232_pnp_driver);
744#endif
Rene Herman609d7692007-05-15 11:42:56 +0200745 if (isa_registered)
746#endif
747 isa_unregister_driver(&cs423x_isa_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
749
750module_init(alsa_card_cs423x_init)
751module_exit(alsa_card_cs423x_exit)