blob: f7845986f467babe1ca09c96d001fd8747e943f7 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/init.h>
Takashi Iwai6bba41a2005-11-17 17:00:53 +010023#include <linux/err.h>
Takashi Iwai5e24c1c2007-02-22 12:50:54 +010024#include <linux/isa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/slab.h>
26#include <linux/pnp.h>
27#include <linux/moduleparam.h>
28#include <sound/core.h>
Krzysztof Helt61ef19d2008-07-31 21:02:42 +020029#include <sound/wss.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <sound/mpu401.h>
31#include <sound/opl3.h>
32#include <sound/initval.h>
33
Jaroslav Kyselac1017a42007-10-15 09:50:19 +020034MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
Linus Torvalds1da177e2005-04-16 15:20:36 -070035MODULE_LICENSE("GPL");
36#ifdef CS4232
37MODULE_DESCRIPTION("Cirrus Logic CS4232");
38MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000},"
39 "{Turtle Beach,Tropez Plus},"
40 "{SIC CrystalWave 32},"
41 "{Hewlett Packard,Omnibook 5500},"
42 "{TerraTec,Maestro 32/96},"
43 "{Philips,PCA70PS}}");
44#else
45MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
46MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
47 "{Crystal Semiconductors,CS4236},"
48 "{Crystal Semiconductors,CS4237},"
49 "{Crystal Semiconductors,CS4238},"
50 "{Crystal Semiconductors,CS4239},"
51 "{Acer,AW37},"
52 "{Acer,AW35/Pro},"
53 "{Crystal,3D},"
54 "{Crystal Computer,TidalWave128},"
55 "{Dell,Optiplex GX1},"
56 "{Dell,Workstation 400 sound},"
57 "{EliteGroup,P5TX-LA sound},"
58 "{Gallant,SC-70P},"
59 "{Gateway,E1000 Onboard CS4236B},"
60 "{Genius,Sound Maker 3DJ},"
61 "{Hewlett Packard,HP6330 sound},"
62 "{IBM,PC 300PL sound},"
63 "{IBM,Aptiva 2137 E24},"
64 "{IBM,IntelliStation M Pro},"
65 "{Intel,Marlin Spike Mobo CS4235},"
66 "{Intel PR440FX Onboard},"
67 "{Guillemot,MaxiSound 16 PnP},"
68 "{NewClear,3D},"
69 "{TerraTec,AudioSystem EWS64L/XL},"
70 "{Typhoon Soundsystem,CS4236B},"
71 "{Turtle Beach,Malibu},"
72 "{Unknown,Digital PC 5000 Onboard}}");
73#endif
74
75#ifdef CS4232
76#define IDENT "CS4232"
Rene Herman83c51c02007-03-20 11:33:46 +010077#define DEV_NAME "cs4232"
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#else
79#define IDENT "CS4236+"
Rene Herman83c51c02007-03-20 11:33:46 +010080#define DEV_NAME "cs4236"
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#endif
82
83static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
84static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
85static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
86#ifdef CONFIG_PNP
87static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
88#endif
89static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
90static long cport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
91static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* PnP setup */
92static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
93static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
94static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
95static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
96static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
97static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
98
99module_param_array(index, int, NULL, 0444);
100MODULE_PARM_DESC(index, "Index value for " IDENT " soundcard.");
101module_param_array(id, charp, NULL, 0444);
102MODULE_PARM_DESC(id, "ID string for " IDENT " soundcard.");
103module_param_array(enable, bool, NULL, 0444);
104MODULE_PARM_DESC(enable, "Enable " IDENT " soundcard.");
105#ifdef CONFIG_PNP
106module_param_array(isapnp, bool, NULL, 0444);
107MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
108#endif
109module_param_array(port, long, NULL, 0444);
110MODULE_PARM_DESC(port, "Port # for " IDENT " driver.");
111module_param_array(cport, long, NULL, 0444);
112MODULE_PARM_DESC(cport, "Control port # for " IDENT " driver.");
113module_param_array(mpu_port, long, NULL, 0444);
114MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " IDENT " driver.");
115module_param_array(fm_port, long, NULL, 0444);
116MODULE_PARM_DESC(fm_port, "FM port # for " IDENT " driver.");
117module_param_array(sb_port, long, NULL, 0444);
118MODULE_PARM_DESC(sb_port, "SB port # for " IDENT " driver (optional).");
119module_param_array(irq, int, NULL, 0444);
120MODULE_PARM_DESC(irq, "IRQ # for " IDENT " driver.");
121module_param_array(mpu_irq, int, NULL, 0444);
122MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " IDENT " driver.");
123module_param_array(dma1, int, NULL, 0444);
124MODULE_PARM_DESC(dma1, "DMA1 # for " IDENT " driver.");
125module_param_array(dma2, int, NULL, 0444);
126MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
127
Takashi Iwai59b1b342006-01-04 15:06:44 +0100128#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +0200129static int isa_registered;
Clemens Ladischf7a92752005-12-07 09:13:42 +0100130static int pnpc_registered;
131#ifdef CS4232
132static int pnp_registered;
133#endif
Takashi Iwai59b1b342006-01-04 15:06:44 +0100134#endif /* CONFIG_PNP */
Clemens Ladischf7a92752005-12-07 09:13:42 +0100135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136struct snd_card_cs4236 {
Krzysztof Helt7779f752008-07-31 21:03:41 +0200137 struct snd_wss *chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 struct resource *res_sb_port;
139#ifdef CONFIG_PNP
140 struct pnp_dev *wss;
141 struct pnp_dev *ctrl;
142 struct pnp_dev *mpu;
143#endif
144};
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#ifdef CONFIG_PNP
147
Takashi Iwaia9824c82005-11-17 17:51:00 +0100148#ifdef CS4232
149/*
150 * PNP BIOS
151 */
152static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
153 { .id = "CSC0100" },
154 { .id = "CSC0000" },
155 /* Guillemot Turtlebeach something appears to be cs4232 compatible
156 * (untested) */
157 { .id = "GIM0100" },
158 { .id = "" }
159};
160MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids);
161#endif /* CS4232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163#ifdef CS4232
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100164#define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165static struct pnp_card_device_id snd_cs423x_pnpids[] = {
166 /* Philips PCA70PS */
167 { .id = "CSC0d32", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
168 /* TerraTec Maestro 32/96 (CS4232) */
169 { .id = "CSC1a32", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
170 /* HP Omnibook 5500 onboard */
171 { .id = "CSC4232", .devs = { { "CSC0000" }, { "CSC0002" }, { "CSC0003" } } },
172 /* Unnamed CS4236 card (Made in Taiwan) */
173 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
174 /* Turtle Beach TBS-2000 (CS4232) */
175 { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSCb006" } } },
176 /* Turtle Beach Tropez Plus (CS4232) */
177 { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PNPb006" } } },
178 /* SIC CrystalWave 32 (CS4232) */
179 { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
Lukasz Stemach50f794c2006-01-23 15:22:13 +0100180 /* Netfinity 3000 on-board soundcard */
181 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 /* --- */
183 { .id = "" } /* end */
184};
185#else /* CS4236 */
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100186#define CS423X_ISAPNP_DRIVER "cs4236_isapnp"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187static struct pnp_card_device_id snd_cs423x_pnpids[] = {
188 /* Intel Marlin Spike Motherboard - CS4235 */
189 { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
190 /* Intel Marlin Spike Motherboard (#2) - CS4235 */
191 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
192 /* Unknown Intel mainboard - CS4235 */
193 { .id = "CSC0225", .devs = { { "CSC0100" }, { "CSC0110" } } },
194 /* Genius Sound Maker 3DJ - CS4237B */
195 { .id = "CSC0437", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
196 /* Digital PC 5000 Onboard - CS4236B */
197 { .id = "CSC0735", .devs = { { "CSC0000" }, { "CSC0010" } } },
198 /* some uknown CS4236B */
199 { .id = "CSC0b35", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
200 /* Intel PR440FX Onboard sound */
201 { .id = "CSC0b36", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
202 /* CS4235 on mainboard without MPU */
203 { .id = "CSC1425", .devs = { { "CSC0100" }, { "CSC0110" } } },
204 /* Gateway E1000 Onboard CS4236B */
205 { .id = "CSC1335", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
206 /* HP 6330 Onboard sound */
207 { .id = "CSC1525", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
208 /* Crystal Computer TidalWave128 */
209 { .id = "CSC1e37", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
210 /* ACER AW37 - CS4235 */
211 { .id = "CSC4236", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
212 /* build-in soundcard in EliteGroup P5TX-LA motherboard - CS4237B */
213 { .id = "CSC4237", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
214 /* Crystal 3D - CS4237B */
215 { .id = "CSC4336", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
216 /* Typhoon Soundsystem PnP - CS4236B */
217 { .id = "CSC4536", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
218 /* Crystal CX4235-XQ3 EP - CS4235 */
219 { .id = "CSC4625", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
220 /* Crystal Semiconductors CS4237B */
221 { .id = "CSC4637", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
222 /* NewClear 3D - CX4237B-XQ3 */
223 { .id = "CSC4837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
224 /* Dell Optiplex GX1 - CS4236B */
225 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
226 /* Dell P410 motherboard - CS4236B */
227 { .id = "CSC6835", .devs = { { "CSC0000" }, { "CSC0010" } } },
228 /* Dell Workstation 400 Onboard - CS4236B */
229 { .id = "CSC6836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
230 /* Turtle Beach Malibu - CS4237B */
231 { .id = "CSC7537", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
232 /* CS4235 - onboard */
233 { .id = "CSC8025", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC0103" } } },
234 /* IBM Aptiva 2137 E24 Onboard - CS4237B */
235 { .id = "CSC8037", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
236 /* IBM IntelliStation M Pro motherboard */
237 { .id = "CSCc835", .devs = { { "CSC0000" }, { "CSC0010" } } },
238 /* Guillemot MaxiSound 16 PnP - CS4236B */
239 { .id = "CSC9836", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
240 /* Gallant SC-70P */
241 { .id = "CSC9837", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
Rene Hermanebae2252008-08-04 01:23:43 +0200242 /* Techmakers MF-4236PW */
243 { .id = "CSCa736", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /* 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 */
Rene Herman109c53f842007-11-30 17:59:25 +0100274static int __devinit snd_cs423x_pnp_init_wss(int dev, struct pnp_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Rene Herman109c53f842007-11-30 17:59:25 +0100276 if (pnp_activate_dev(pdev) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 printk(KERN_ERR IDENT " WSS PnP configure failed for WSS (out of resources?)\n");
278 return -EBUSY;
279 }
280 port[dev] = pnp_port_start(pdev, 0);
281 if (fm_port[dev] > 0)
282 fm_port[dev] = pnp_port_start(pdev, 1);
283 sb_port[dev] = pnp_port_start(pdev, 2);
284 irq[dev] = pnp_irq(pdev, 0);
285 dma1[dev] = pnp_dma(pdev, 0);
286 dma2[dev] = pnp_dma(pdev, 1) == 4 ? -1 : (int)pnp_dma(pdev, 1);
287 snd_printdd("isapnp WSS: wss port=0x%lx, fm port=0x%lx, sb port=0x%lx\n",
288 port[dev], fm_port[dev], sb_port[dev]);
289 snd_printdd("isapnp WSS: irq=%i, dma1=%i, dma2=%i\n",
290 irq[dev], dma1[dev], dma2[dev]);
Takashi Iwaia9824c82005-11-17 17:51:00 +0100291 return 0;
292}
293
294/* CTRL initialization */
Rene Herman109c53f842007-11-30 17:59:25 +0100295static int __devinit snd_cs423x_pnp_init_ctrl(int dev, struct pnp_dev *pdev)
Takashi Iwaia9824c82005-11-17 17:51:00 +0100296{
Rene Herman109c53f842007-11-30 17:59:25 +0100297 if (pnp_activate_dev(pdev) < 0) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100298 printk(KERN_ERR IDENT " CTRL PnP configure failed for WSS (out of resources?)\n");
299 return -EBUSY;
300 }
301 cport[dev] = pnp_port_start(pdev, 0);
302 snd_printdd("isapnp CTRL: control port=0x%lx\n", cport[dev]);
303 return 0;
304}
305
306/* MPU initialization */
Rene Herman109c53f842007-11-30 17:59:25 +0100307static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev)
Takashi Iwaia9824c82005-11-17 17:51:00 +0100308{
Rene Herman109c53f842007-11-30 17:59:25 +0100309 if (pnp_activate_dev(pdev) < 0) {
Takashi Iwaia9824c82005-11-17 17:51:00 +0100310 printk(KERN_ERR IDENT " MPU401 PnP configure failed for WSS (out of resources?)\n");
311 mpu_port[dev] = SNDRV_AUTO_PORT;
312 mpu_irq[dev] = SNDRV_AUTO_IRQ;
313 } else {
314 mpu_port[dev] = pnp_port_start(pdev, 0);
315 if (mpu_irq[dev] >= 0 &&
316 pnp_irq_valid(pdev, 0) && pnp_irq(pdev, 0) >= 0) {
317 mpu_irq[dev] = pnp_irq(pdev, 0);
318 } else {
319 mpu_irq[dev] = -1; /* disable interrupt */
320 }
321 }
322 snd_printdd("isapnp MPU: port=0x%lx, irq=%i\n", mpu_port[dev], mpu_irq[dev]);
323 return 0;
324}
325
326#ifdef CS4232
327static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard,
328 struct pnp_dev *pdev)
329{
Krzysztof Heltb15ebe22008-07-23 07:48:49 +0200330 acard->wss = pdev;
Rene Herman109c53f842007-11-30 17:59:25 +0100331 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
Takashi Iwaia9824c82005-11-17 17:51:00 +0100332 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100333 cport[dev] = -1;
334 return 0;
335}
336#endif
337
338static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
339 struct pnp_card_link *card,
340 const struct pnp_card_device_id *id)
341{
Takashi Iwaia9824c82005-11-17 17:51:00 +0100342 acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
343 if (acard->wss == NULL)
Rene Herman109c53f842007-11-30 17:59:25 +0100344 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100345 acard->ctrl = pnp_request_card_device(card, id->devs[1].id, NULL);
346 if (acard->ctrl == NULL)
Rene Herman109c53f842007-11-30 17:59:25 +0100347 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100348 if (id->devs[2].id[0]) {
349 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
350 if (acard->mpu == NULL)
Rene Herman109c53f842007-11-30 17:59:25 +0100351 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100352 }
353
354 /* WSS initialization */
Rene Herman109c53f842007-11-30 17:59:25 +0100355 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
356 return -EBUSY;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /* CTRL initialization */
359 if (acard->ctrl && cport[dev] > 0) {
Rene Herman109c53f842007-11-30 17:59:25 +0100360 if (snd_cs423x_pnp_init_ctrl(dev, acard->ctrl) < 0)
361 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
363 /* MPU initialization */
364 if (acard->mpu && mpu_port[dev] > 0) {
Rene Herman109c53f842007-11-30 17:59:25 +0100365 if (snd_cs423x_pnp_init_mpu(dev, acard->mpu) < 0)
366 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 return 0;
369}
370#endif /* CONFIG_PNP */
371
Takashi Iwai43bcd972005-09-05 17:19:20 +0200372#ifdef CONFIG_PNP
373#define is_isapnp_selected(dev) isapnp[dev]
374#else
375#define is_isapnp_selected(dev) 0
376#endif
377
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100378static void snd_card_cs4236_free(struct snd_card *card)
379{
380 struct snd_card_cs4236 *acard = card->private_data;
381
382 release_and_free_resource(acard->res_sb_port);
383}
384
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100385static int snd_cs423x_card_new(int dev, struct snd_card **cardp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100387 struct snd_card *card;
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100388 int err;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100389
Takashi Iwaic95eadd2008-12-28 16:43:35 +0100390 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
391 sizeof(struct snd_card_cs4236), &card);
392 if (err < 0)
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100393 return err;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100394 card->private_free = snd_card_cs4236_free;
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100395 *cardp = card;
396 return 0;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100397}
398
399static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
400{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 struct snd_card_cs4236 *acard;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100402 struct snd_pcm *pcm;
Krzysztof Helt7779f752008-07-31 21:03:41 +0200403 struct snd_wss *chip;
Takashi Iwaiba2375a2005-11-17 14:30:42 +0100404 struct snd_opl3 *opl3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 int err;
406
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100407 acard = card->private_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT)
409 if ((acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB")) == NULL) {
410 printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100411 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
413
414#ifdef CS4232
Krzysztof Helt7779f752008-07-31 21:03:41 +0200415 err = snd_wss_create(card, port[dev], cport[dev],
416 irq[dev],
417 dma1[dev], dma2[dev],
418 WSS_HW_DETECT, 0, &chip);
419 if (err < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100420 return err;
421 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200422
Krzysztof Helt7779f752008-07-31 21:03:41 +0200423 err = snd_wss_pcm(chip, 0, &pcm);
424 if (err < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100425 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200426
Krzysztof Helt7779f752008-07-31 21:03:41 +0200427 err = snd_wss_mixer(chip);
428 if (err < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100429 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431#else /* CS4236 */
Krzysztof Helt7779f752008-07-31 21:03:41 +0200432 err = snd_cs4236_create(card,
433 port[dev], cport[dev],
434 irq[dev], dma1[dev], dma2[dev],
435 WSS_HW_DETECT, 0, &chip);
436 if (err < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100437 return err;
438 acard->chip = chip;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200439
Krzysztof Helt7779f752008-07-31 21:03:41 +0200440 err = snd_cs4236_pcm(chip, 0, &pcm);
441 if (err < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100442 return err;
Takashi Iwai43bcd972005-09-05 17:19:20 +0200443
Krzysztof Helt7779f752008-07-31 21:03:41 +0200444 err = snd_cs4236_mixer(chip);
445 if (err < 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
Krzysztof Helt7779f752008-07-31 21:03:41 +0200458 err = snd_wss_timer(chip, 0, NULL);
459 if (err < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100460 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
462 if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
463 if (snd_opl3_create(card,
464 fm_port[dev], fm_port[dev] + 2,
465 OPL3_HW_OPL3_CS, 0, &opl3) < 0) {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200466 printk(KERN_WARNING IDENT ": OPL3 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 } else {
Takashi Iwai43bcd972005-09-05 17:19:20 +0200468 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100469 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 }
471 }
472
473 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
474 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
475 mpu_irq[dev] = -1;
476 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
477 mpu_port[dev], 0,
478 mpu_irq[dev],
Thomas Gleixner65ca68b2006-07-01 19:29:46 -0700479 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
Takashi Iwai43bcd972005-09-05 17:19:20 +0200480 printk(KERN_WARNING IDENT ": MPU401 not detected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
Takashi Iwai43bcd972005-09-05 17:19:20 +0200482
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100483 return snd_card_register(card);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484}
485
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100486static int __devinit snd_cs423x_isa_match(struct device *pdev,
487 unsigned int dev)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100488{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100489 if (!enable[dev] || is_isapnp_selected(dev))
490 return 0;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100491
492 if (port[dev] == SNDRV_AUTO_PORT) {
Takashi Iwai0418ff02008-11-03 08:51:33 +0100493 dev_err(pdev, "please specify port\n");
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100494 return 0;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100495 }
496 if (cport[dev] == SNDRV_AUTO_PORT) {
Takashi Iwai0418ff02008-11-03 08:51:33 +0100497 dev_err(pdev, "please specify cport\n");
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100498 return 0;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100499 }
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100500 if (irq[dev] == SNDRV_AUTO_IRQ) {
Takashi Iwai0418ff02008-11-03 08:51:33 +0100501 dev_err(pdev, "please specify irq\n");
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100502 return 0;
503 }
504 if (dma1[dev] == SNDRV_AUTO_DMA) {
Takashi Iwai0418ff02008-11-03 08:51:33 +0100505 dev_err(pdev, "please specify dma1\n");
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100506 return 0;
507 }
508 return 1;
509}
510
511static int __devinit snd_cs423x_isa_probe(struct device *pdev,
512 unsigned int dev)
513{
514 struct snd_card *card;
515 int err;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100516
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100517 err = snd_cs423x_card_new(dev, &card);
518 if (err < 0)
519 return err;
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100520 snd_card_set_dev(card, pdev);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100521 if ((err = snd_cs423x_probe(card, dev)) < 0) {
522 snd_card_free(card);
523 return err;
524 }
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800525
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100526 dev_set_drvdata(pdev, card);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100527 return 0;
528}
529
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100530static int __devexit snd_cs423x_isa_remove(struct device *pdev,
531 unsigned int dev)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100532{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100533 snd_card_free(dev_get_drvdata(pdev));
534 dev_set_drvdata(pdev, NULL);
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100535 return 0;
536}
537
538#ifdef CONFIG_PM
539static int snd_cs423x_suspend(struct snd_card *card)
540{
541 struct snd_card_cs4236 *acard = card->private_data;
542 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
543 acard->chip->suspend(acard->chip);
544 return 0;
545}
546
547static int snd_cs423x_resume(struct snd_card *card)
548{
549 struct snd_card_cs4236 *acard = card->private_data;
550 acard->chip->resume(acard->chip);
551 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
552 return 0;
553}
554
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100555static int snd_cs423x_isa_suspend(struct device *dev, unsigned int n,
556 pm_message_t state)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100557{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100558 return snd_cs423x_suspend(dev_get_drvdata(dev));
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100559}
560
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100561static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100562{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100563 return snd_cs423x_resume(dev_get_drvdata(dev));
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100564}
565#endif
566
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100567static struct isa_driver cs423x_isa_driver = {
568 .match = snd_cs423x_isa_match,
569 .probe = snd_cs423x_isa_probe,
570 .remove = __devexit_p(snd_cs423x_isa_remove),
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100571#ifdef CONFIG_PM
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100572 .suspend = snd_cs423x_isa_suspend,
573 .resume = snd_cs423x_isa_resume,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100574#endif
575 .driver = {
Rene Herman83c51c02007-03-20 11:33:46 +0100576 .name = DEV_NAME
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100577 },
578};
579
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#ifdef CONFIG_PNP
Takashi Iwaia9824c82005-11-17 17:51:00 +0100582#ifdef CS4232
583static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
584 const struct pnp_device_id *id)
585{
586 static int dev;
587 int err;
588 struct snd_card *card;
589
590 if (pnp_device_is_isapnp(pdev))
591 return -ENOENT; /* we have another procedure - card */
592 for (; dev < SNDRV_CARDS; dev++) {
593 if (enable[dev] && isapnp[dev])
594 break;
595 }
596 if (dev >= SNDRV_CARDS)
597 return -ENODEV;
598
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100599 err = snd_cs423x_card_new(dev, &card);
600 if (err < 0)
601 return err;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100602 if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) {
603 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
604 snd_card_free(card);
605 return err;
606 }
607 snd_card_set_dev(card, &pdev->dev);
608 if ((err = snd_cs423x_probe(card, dev)) < 0) {
609 snd_card_free(card);
610 return err;
611 }
612 pnp_set_drvdata(pdev, card);
613 dev++;
614 return 0;
615}
616
617static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev)
618{
619 snd_card_free(pnp_get_drvdata(pdev));
620 pnp_set_drvdata(pdev, NULL);
621}
622
623#ifdef CONFIG_PM
624static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
625{
626 return snd_cs423x_suspend(pnp_get_drvdata(pdev));
627}
628
629static int snd_cs4232_pnp_resume(struct pnp_dev *pdev)
630{
631 return snd_cs423x_resume(pnp_get_drvdata(pdev));
632}
633#endif
634
635static struct pnp_driver cs4232_pnp_driver = {
636 .name = "cs4232-pnpbios",
637 .id_table = snd_cs4232_pnpbiosids,
638 .probe = snd_cs4232_pnpbios_detect,
639 .remove = __devexit_p(snd_cs4232_pnp_remove),
640#ifdef CONFIG_PM
641 .suspend = snd_cs4232_pnp_suspend,
642 .resume = snd_cs4232_pnp_resume,
643#endif
644};
645#endif /* CS4232 */
646
647static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
648 const struct pnp_card_device_id *pid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
650 static int dev;
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100651 struct snd_card *card;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 int res;
653
654 for ( ; dev < SNDRV_CARDS; dev++) {
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100655 if (enable[dev] && isapnp[dev])
656 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100658 if (dev >= SNDRV_CARDS)
659 return -ENODEV;
660
Takashi Iwai3e7fb9f2008-12-28 16:47:30 +0100661 res = snd_cs423x_card_new(dev, &card);
662 if (res < 0)
663 return res;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100664 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
665 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
666 " is not supported\n");
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100667 snd_card_free(card);
668 return res;
669 }
670 snd_card_set_dev(card, &pcard->card->dev);
671 if ((res = snd_cs423x_probe(card, dev)) < 0) {
672 snd_card_free(card);
673 return res;
674 }
675 pnp_set_card_drvdata(pcard, card);
676 dev++;
677 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678}
679
Takashi Iwaia9824c82005-11-17 17:51:00 +0100680static void __devexit snd_cs423x_pnpc_remove(struct pnp_card_link * pcard)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681{
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100682 snd_card_free(pnp_get_card_drvdata(pcard));
683 pnp_set_card_drvdata(pcard, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684}
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800685
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100686#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100687static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100688{
689 return snd_cs423x_suspend(pnp_get_card_drvdata(pcard));
690}
691
Takashi Iwaia9824c82005-11-17 17:51:00 +0100692static int snd_cs423x_pnpc_resume(struct pnp_card_link *pcard)
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100693{
694 return snd_cs423x_resume(pnp_get_card_drvdata(pcard));
695}
696#endif
697
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698static struct pnp_card_driver cs423x_pnpc_driver = {
699 .flags = PNP_DRIVER_RES_DISABLE,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100700 .name = CS423X_ISAPNP_DRIVER,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 .id_table = snd_cs423x_pnpids,
Takashi Iwaia9824c82005-11-17 17:51:00 +0100702 .probe = snd_cs423x_pnpc_detect,
703 .remove = __devexit_p(snd_cs423x_pnpc_remove),
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100704#ifdef CONFIG_PM
Takashi Iwaia9824c82005-11-17 17:51:00 +0100705 .suspend = snd_cs423x_pnpc_suspend,
706 .resume = snd_cs423x_pnpc_resume,
Takashi Iwai6bba41a2005-11-17 17:00:53 +0100707#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708};
709#endif /* CONFIG_PNP */
710
711static int __init alsa_card_cs423x_init(void)
712{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100713 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100715 err = isa_register_driver(&cs423x_isa_driver, SNDRV_CARDS);
Takashi Iwai59b1b342006-01-04 15:06:44 +0100716#ifdef CONFIG_PNP
Rene Herman609d7692007-05-15 11:42:56 +0200717 if (!err)
718 isa_registered = 1;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100719#ifdef CS4232
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800720 err = pnp_register_driver(&cs4232_pnp_driver);
721 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100722 pnp_registered = 1;
Takashi Iwaia9824c82005-11-17 17:51:00 +0100723#endif
Bjorn Helgaased7cb192006-03-27 01:17:04 -0800724 err = pnp_register_card_driver(&cs423x_pnpc_driver);
725 if (!err)
Clemens Ladischf7a92752005-12-07 09:13:42 +0100726 pnpc_registered = 1;
Rene Herman609d7692007-05-15 11:42:56 +0200727#ifdef CS4232
728 if (pnp_registered)
729 err = 0;
730#endif
731 if (isa_registered)
732 err = 0;
733#endif
734 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735}
736
737static void __exit alsa_card_cs423x_exit(void)
738{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100739#ifdef CONFIG_PNP
740 if (pnpc_registered)
741 pnp_unregister_card_driver(&cs423x_pnpc_driver);
742#ifdef CS4232
743 if (pnp_registered)
744 pnp_unregister_driver(&cs4232_pnp_driver);
745#endif
Rene Herman609d7692007-05-15 11:42:56 +0200746 if (isa_registered)
747#endif
748 isa_unregister_driver(&cs423x_isa_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749}
750
751module_init(alsa_card_cs423x_init)
752module_exit(alsa_card_cs423x_exit)