1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * ALSA card-level driver for Turtle Beach Wavefront cards
4*4882a593Smuzhiyun * (Maui,Tropez,Tropez+)
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (c) 1997-1999 by Paul Barton-Davis <pbd@op.net>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/init.h>
10*4882a593Smuzhiyun #include <linux/interrupt.h>
11*4882a593Smuzhiyun #include <linux/err.h>
12*4882a593Smuzhiyun #include <linux/isa.h>
13*4882a593Smuzhiyun #include <linux/pnp.h>
14*4882a593Smuzhiyun #include <linux/module.h>
15*4882a593Smuzhiyun #include <sound/core.h>
16*4882a593Smuzhiyun #include <sound/initval.h>
17*4882a593Smuzhiyun #include <sound/opl3.h>
18*4882a593Smuzhiyun #include <sound/wss.h>
19*4882a593Smuzhiyun #include <sound/snd_wavefront.h>
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun MODULE_AUTHOR("Paul Barton-Davis <pbd@op.net>");
22*4882a593Smuzhiyun MODULE_DESCRIPTION("Turtle Beach Wavefront");
23*4882a593Smuzhiyun MODULE_LICENSE("GPL");
24*4882a593Smuzhiyun MODULE_SUPPORTED_DEVICE("{{Turtle Beach,Maui/Tropez/Tropez+}}");
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
27*4882a593Smuzhiyun static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
28*4882a593Smuzhiyun static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
29*4882a593Smuzhiyun #ifdef CONFIG_PNP
30*4882a593Smuzhiyun static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
31*4882a593Smuzhiyun #endif
32*4882a593Smuzhiyun static long cs4232_pcm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
33*4882a593Smuzhiyun static int cs4232_pcm_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
34*4882a593Smuzhiyun static long cs4232_mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
35*4882a593Smuzhiyun static int cs4232_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
36*4882a593Smuzhiyun static long ics2115_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
37*4882a593Smuzhiyun static int ics2115_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,9,11,12,15 */
38*4882a593Smuzhiyun static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
39*4882a593Smuzhiyun static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
40*4882a593Smuzhiyun static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
41*4882a593Smuzhiyun static bool use_cs4232_midi[SNDRV_CARDS];
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun module_param_array(index, int, NULL, 0444);
44*4882a593Smuzhiyun MODULE_PARM_DESC(index, "Index value for WaveFront soundcard.");
45*4882a593Smuzhiyun module_param_array(id, charp, NULL, 0444);
46*4882a593Smuzhiyun MODULE_PARM_DESC(id, "ID string for WaveFront soundcard.");
47*4882a593Smuzhiyun module_param_array(enable, bool, NULL, 0444);
48*4882a593Smuzhiyun MODULE_PARM_DESC(enable, "Enable WaveFront soundcard.");
49*4882a593Smuzhiyun #ifdef CONFIG_PNP
50*4882a593Smuzhiyun module_param_array(isapnp, bool, NULL, 0444);
51*4882a593Smuzhiyun MODULE_PARM_DESC(isapnp, "ISA PnP detection for WaveFront soundcards.");
52*4882a593Smuzhiyun #endif
53*4882a593Smuzhiyun module_param_hw_array(cs4232_pcm_port, long, ioport, NULL, 0444);
54*4882a593Smuzhiyun MODULE_PARM_DESC(cs4232_pcm_port, "Port # for CS4232 PCM interface.");
55*4882a593Smuzhiyun module_param_hw_array(cs4232_pcm_irq, int, irq, NULL, 0444);
56*4882a593Smuzhiyun MODULE_PARM_DESC(cs4232_pcm_irq, "IRQ # for CS4232 PCM interface.");
57*4882a593Smuzhiyun module_param_hw_array(dma1, int, dma, NULL, 0444);
58*4882a593Smuzhiyun MODULE_PARM_DESC(dma1, "DMA1 # for CS4232 PCM interface.");
59*4882a593Smuzhiyun module_param_hw_array(dma2, int, dma, NULL, 0444);
60*4882a593Smuzhiyun MODULE_PARM_DESC(dma2, "DMA2 # for CS4232 PCM interface.");
61*4882a593Smuzhiyun module_param_hw_array(cs4232_mpu_port, long, ioport, NULL, 0444);
62*4882a593Smuzhiyun MODULE_PARM_DESC(cs4232_mpu_port, "port # for CS4232 MPU-401 interface.");
63*4882a593Smuzhiyun module_param_hw_array(cs4232_mpu_irq, int, irq, NULL, 0444);
64*4882a593Smuzhiyun MODULE_PARM_DESC(cs4232_mpu_irq, "IRQ # for CS4232 MPU-401 interface.");
65*4882a593Smuzhiyun module_param_hw_array(ics2115_irq, int, irq, NULL, 0444);
66*4882a593Smuzhiyun MODULE_PARM_DESC(ics2115_irq, "IRQ # for ICS2115.");
67*4882a593Smuzhiyun module_param_hw_array(ics2115_port, long, ioport, NULL, 0444);
68*4882a593Smuzhiyun MODULE_PARM_DESC(ics2115_port, "Port # for ICS2115.");
69*4882a593Smuzhiyun module_param_hw_array(fm_port, long, ioport, NULL, 0444);
70*4882a593Smuzhiyun MODULE_PARM_DESC(fm_port, "FM port #.");
71*4882a593Smuzhiyun module_param_array(use_cs4232_midi, bool, NULL, 0444);
72*4882a593Smuzhiyun MODULE_PARM_DESC(use_cs4232_midi, "Use CS4232 MPU-401 interface (inaccessibly located inside your computer)");
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun #ifdef CONFIG_PNP
75*4882a593Smuzhiyun static int isa_registered;
76*4882a593Smuzhiyun static int pnp_registered;
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun static const struct pnp_card_device_id snd_wavefront_pnpids[] = {
79*4882a593Smuzhiyun /* Tropez */
80*4882a593Smuzhiyun { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
81*4882a593Smuzhiyun /* Tropez+ */
82*4882a593Smuzhiyun { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
83*4882a593Smuzhiyun { .id = "" }
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun
86*4882a593Smuzhiyun MODULE_DEVICE_TABLE(pnp_card, snd_wavefront_pnpids);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun static int
snd_wavefront_pnp(int dev,snd_wavefront_card_t * acard,struct pnp_card_link * card,const struct pnp_card_device_id * id)89*4882a593Smuzhiyun snd_wavefront_pnp (int dev, snd_wavefront_card_t *acard, struct pnp_card_link *card,
90*4882a593Smuzhiyun const struct pnp_card_device_id *id)
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun struct pnp_dev *pdev;
93*4882a593Smuzhiyun int err;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun /* Check for each logical device. */
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /* CS4232 chip (aka "windows sound system") is logical device 0 */
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
100*4882a593Smuzhiyun if (acard->wss == NULL)
101*4882a593Smuzhiyun return -EBUSY;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /* there is a game port at logical device 1, but we ignore it completely */
104*4882a593Smuzhiyun
105*4882a593Smuzhiyun /* the control interface is logical device 2, but we ignore it
106*4882a593Smuzhiyun completely. in fact, nobody even seems to know what it
107*4882a593Smuzhiyun does.
108*4882a593Smuzhiyun */
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun /* Only configure the CS4232 MIDI interface if its been
111*4882a593Smuzhiyun specifically requested. It is logical device 3.
112*4882a593Smuzhiyun */
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun if (use_cs4232_midi[dev]) {
115*4882a593Smuzhiyun acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
116*4882a593Smuzhiyun if (acard->mpu == NULL)
117*4882a593Smuzhiyun return -EBUSY;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun /* The ICS2115 synth is logical device 4 */
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun acard->synth = pnp_request_card_device(card, id->devs[3].id, NULL);
123*4882a593Smuzhiyun if (acard->synth == NULL)
124*4882a593Smuzhiyun return -EBUSY;
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /* PCM/FM initialization */
127*4882a593Smuzhiyun
128*4882a593Smuzhiyun pdev = acard->wss;
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun /* An interesting note from the Tropez+ FAQ:
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun Q. [Ports] Why is the base address of the WSS I/O ports off by 4?
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun A. WSS I/O requires a block of 8 I/O addresses ("ports"). Of these, the first
135*4882a593Smuzhiyun 4 are used to identify and configure the board. With the advent of PnP,
136*4882a593Smuzhiyun these first 4 addresses have become obsolete, and software applications
137*4882a593Smuzhiyun only use the last 4 addresses to control the codec chip. Therefore, the
138*4882a593Smuzhiyun base address setting "skips past" the 4 unused addresses.
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun err = pnp_activate_dev(pdev);
143*4882a593Smuzhiyun if (err < 0) {
144*4882a593Smuzhiyun snd_printk(KERN_ERR "PnP WSS pnp configure failure\n");
145*4882a593Smuzhiyun return err;
146*4882a593Smuzhiyun }
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun cs4232_pcm_port[dev] = pnp_port_start(pdev, 0);
149*4882a593Smuzhiyun fm_port[dev] = pnp_port_start(pdev, 1);
150*4882a593Smuzhiyun dma1[dev] = pnp_dma(pdev, 0);
151*4882a593Smuzhiyun dma2[dev] = pnp_dma(pdev, 1);
152*4882a593Smuzhiyun cs4232_pcm_irq[dev] = pnp_irq(pdev, 0);
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /* Synth initialization */
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun pdev = acard->synth;
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun err = pnp_activate_dev(pdev);
159*4882a593Smuzhiyun if (err < 0) {
160*4882a593Smuzhiyun snd_printk(KERN_ERR "PnP ICS2115 pnp configure failure\n");
161*4882a593Smuzhiyun return err;
162*4882a593Smuzhiyun }
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun ics2115_port[dev] = pnp_port_start(pdev, 0);
165*4882a593Smuzhiyun ics2115_irq[dev] = pnp_irq(pdev, 0);
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /* CS4232 MPU initialization. Configure this only if
168*4882a593Smuzhiyun explicitly requested, since its physically inaccessible and
169*4882a593Smuzhiyun consumes another IRQ.
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun if (use_cs4232_midi[dev]) {
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun pdev = acard->mpu;
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun err = pnp_activate_dev(pdev);
177*4882a593Smuzhiyun if (err < 0) {
178*4882a593Smuzhiyun snd_printk(KERN_ERR "PnP MPU401 pnp configure failure\n");
179*4882a593Smuzhiyun cs4232_mpu_port[dev] = SNDRV_AUTO_PORT;
180*4882a593Smuzhiyun } else {
181*4882a593Smuzhiyun cs4232_mpu_port[dev] = pnp_port_start(pdev, 0);
182*4882a593Smuzhiyun cs4232_mpu_irq[dev] = pnp_irq(pdev, 0);
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun snd_printk (KERN_INFO "CS4232 MPU: port=0x%lx, irq=%i\n",
186*4882a593Smuzhiyun cs4232_mpu_port[dev],
187*4882a593Smuzhiyun cs4232_mpu_irq[dev]);
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun snd_printdd ("CS4232: pcm port=0x%lx, fm port=0x%lx, dma1=%i, dma2=%i, irq=%i\nICS2115: port=0x%lx, irq=%i\n",
191*4882a593Smuzhiyun cs4232_pcm_port[dev],
192*4882a593Smuzhiyun fm_port[dev],
193*4882a593Smuzhiyun dma1[dev],
194*4882a593Smuzhiyun dma2[dev],
195*4882a593Smuzhiyun cs4232_pcm_irq[dev],
196*4882a593Smuzhiyun ics2115_port[dev],
197*4882a593Smuzhiyun ics2115_irq[dev]);
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun return 0;
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun #endif /* CONFIG_PNP */
203*4882a593Smuzhiyun
snd_wavefront_ics2115_interrupt(int irq,void * dev_id)204*4882a593Smuzhiyun static irqreturn_t snd_wavefront_ics2115_interrupt(int irq, void *dev_id)
205*4882a593Smuzhiyun {
206*4882a593Smuzhiyun snd_wavefront_card_t *acard;
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun acard = (snd_wavefront_card_t *) dev_id;
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun if (acard == NULL)
211*4882a593Smuzhiyun return IRQ_NONE;
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun if (acard->wavefront.interrupts_are_midi) {
214*4882a593Smuzhiyun snd_wavefront_midi_interrupt (acard);
215*4882a593Smuzhiyun } else {
216*4882a593Smuzhiyun snd_wavefront_internal_interrupt (acard);
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun return IRQ_HANDLED;
219*4882a593Smuzhiyun }
220*4882a593Smuzhiyun
snd_wavefront_new_synth(struct snd_card * card,int hw_dev,snd_wavefront_card_t * acard)221*4882a593Smuzhiyun static struct snd_hwdep *snd_wavefront_new_synth(struct snd_card *card,
222*4882a593Smuzhiyun int hw_dev,
223*4882a593Smuzhiyun snd_wavefront_card_t *acard)
224*4882a593Smuzhiyun {
225*4882a593Smuzhiyun struct snd_hwdep *wavefront_synth;
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun if (snd_wavefront_detect (acard) < 0) {
228*4882a593Smuzhiyun return NULL;
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun if (snd_wavefront_start (&acard->wavefront) < 0) {
232*4882a593Smuzhiyun return NULL;
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun if (snd_hwdep_new(card, "WaveFront", hw_dev, &wavefront_synth) < 0)
236*4882a593Smuzhiyun return NULL;
237*4882a593Smuzhiyun strcpy (wavefront_synth->name,
238*4882a593Smuzhiyun "WaveFront (ICS2115) wavetable synthesizer");
239*4882a593Smuzhiyun wavefront_synth->ops.open = snd_wavefront_synth_open;
240*4882a593Smuzhiyun wavefront_synth->ops.release = snd_wavefront_synth_release;
241*4882a593Smuzhiyun wavefront_synth->ops.ioctl = snd_wavefront_synth_ioctl;
242*4882a593Smuzhiyun
243*4882a593Smuzhiyun return wavefront_synth;
244*4882a593Smuzhiyun }
245*4882a593Smuzhiyun
snd_wavefront_new_fx(struct snd_card * card,int hw_dev,snd_wavefront_card_t * acard,unsigned long port)246*4882a593Smuzhiyun static struct snd_hwdep *snd_wavefront_new_fx(struct snd_card *card,
247*4882a593Smuzhiyun int hw_dev,
248*4882a593Smuzhiyun snd_wavefront_card_t *acard,
249*4882a593Smuzhiyun unsigned long port)
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun struct snd_hwdep *fx_processor;
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun if (snd_wavefront_fx_start (&acard->wavefront)) {
255*4882a593Smuzhiyun snd_printk (KERN_ERR "cannot initialize YSS225 FX processor");
256*4882a593Smuzhiyun return NULL;
257*4882a593Smuzhiyun }
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun if (snd_hwdep_new (card, "YSS225", hw_dev, &fx_processor) < 0)
260*4882a593Smuzhiyun return NULL;
261*4882a593Smuzhiyun sprintf (fx_processor->name, "YSS225 FX Processor at 0x%lx", port);
262*4882a593Smuzhiyun fx_processor->ops.open = snd_wavefront_fx_open;
263*4882a593Smuzhiyun fx_processor->ops.release = snd_wavefront_fx_release;
264*4882a593Smuzhiyun fx_processor->ops.ioctl = snd_wavefront_fx_ioctl;
265*4882a593Smuzhiyun
266*4882a593Smuzhiyun return fx_processor;
267*4882a593Smuzhiyun }
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun static snd_wavefront_mpu_id internal_id = internal_mpu;
270*4882a593Smuzhiyun static snd_wavefront_mpu_id external_id = external_mpu;
271*4882a593Smuzhiyun
snd_wavefront_new_midi(struct snd_card * card,int midi_dev,snd_wavefront_card_t * acard,unsigned long port,snd_wavefront_mpu_id mpu)272*4882a593Smuzhiyun static struct snd_rawmidi *snd_wavefront_new_midi(struct snd_card *card,
273*4882a593Smuzhiyun int midi_dev,
274*4882a593Smuzhiyun snd_wavefront_card_t *acard,
275*4882a593Smuzhiyun unsigned long port,
276*4882a593Smuzhiyun snd_wavefront_mpu_id mpu)
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun {
279*4882a593Smuzhiyun struct snd_rawmidi *rmidi;
280*4882a593Smuzhiyun static int first = 1;
281*4882a593Smuzhiyun
282*4882a593Smuzhiyun if (first) {
283*4882a593Smuzhiyun first = 0;
284*4882a593Smuzhiyun acard->wavefront.midi.base = port;
285*4882a593Smuzhiyun if (snd_wavefront_midi_start (acard)) {
286*4882a593Smuzhiyun snd_printk (KERN_ERR "cannot initialize MIDI interface\n");
287*4882a593Smuzhiyun return NULL;
288*4882a593Smuzhiyun }
289*4882a593Smuzhiyun }
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun if (snd_rawmidi_new (card, "WaveFront MIDI", midi_dev, 1, 1, &rmidi) < 0)
292*4882a593Smuzhiyun return NULL;
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun if (mpu == internal_mpu) {
295*4882a593Smuzhiyun strcpy(rmidi->name, "WaveFront MIDI (Internal)");
296*4882a593Smuzhiyun rmidi->private_data = &internal_id;
297*4882a593Smuzhiyun } else {
298*4882a593Smuzhiyun strcpy(rmidi->name, "WaveFront MIDI (External)");
299*4882a593Smuzhiyun rmidi->private_data = &external_id;
300*4882a593Smuzhiyun }
301*4882a593Smuzhiyun
302*4882a593Smuzhiyun snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_wavefront_midi_output);
303*4882a593Smuzhiyun snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_wavefront_midi_input);
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
306*4882a593Smuzhiyun SNDRV_RAWMIDI_INFO_INPUT |
307*4882a593Smuzhiyun SNDRV_RAWMIDI_INFO_DUPLEX;
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun return rmidi;
310*4882a593Smuzhiyun }
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun static void
snd_wavefront_free(struct snd_card * card)313*4882a593Smuzhiyun snd_wavefront_free(struct snd_card *card)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun snd_wavefront_card_t *acard = (snd_wavefront_card_t *)card->private_data;
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun if (acard) {
318*4882a593Smuzhiyun release_and_free_resource(acard->wavefront.res_base);
319*4882a593Smuzhiyun if (acard->wavefront.irq > 0)
320*4882a593Smuzhiyun free_irq(acard->wavefront.irq, (void *)acard);
321*4882a593Smuzhiyun }
322*4882a593Smuzhiyun }
323*4882a593Smuzhiyun
snd_wavefront_card_new(struct device * pdev,int dev,struct snd_card ** cardp)324*4882a593Smuzhiyun static int snd_wavefront_card_new(struct device *pdev, int dev,
325*4882a593Smuzhiyun struct snd_card **cardp)
326*4882a593Smuzhiyun {
327*4882a593Smuzhiyun struct snd_card *card;
328*4882a593Smuzhiyun snd_wavefront_card_t *acard;
329*4882a593Smuzhiyun int err;
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
332*4882a593Smuzhiyun sizeof(snd_wavefront_card_t), &card);
333*4882a593Smuzhiyun if (err < 0)
334*4882a593Smuzhiyun return err;
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun acard = card->private_data;
337*4882a593Smuzhiyun acard->wavefront.irq = -1;
338*4882a593Smuzhiyun spin_lock_init(&acard->wavefront.irq_lock);
339*4882a593Smuzhiyun init_waitqueue_head(&acard->wavefront.interrupt_sleeper);
340*4882a593Smuzhiyun spin_lock_init(&acard->wavefront.midi.open);
341*4882a593Smuzhiyun spin_lock_init(&acard->wavefront.midi.virtual);
342*4882a593Smuzhiyun acard->wavefront.card = card;
343*4882a593Smuzhiyun card->private_free = snd_wavefront_free;
344*4882a593Smuzhiyun
345*4882a593Smuzhiyun *cardp = card;
346*4882a593Smuzhiyun return 0;
347*4882a593Smuzhiyun }
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun static int
snd_wavefront_probe(struct snd_card * card,int dev)350*4882a593Smuzhiyun snd_wavefront_probe (struct snd_card *card, int dev)
351*4882a593Smuzhiyun {
352*4882a593Smuzhiyun snd_wavefront_card_t *acard = card->private_data;
353*4882a593Smuzhiyun struct snd_wss *chip;
354*4882a593Smuzhiyun struct snd_hwdep *wavefront_synth;
355*4882a593Smuzhiyun struct snd_rawmidi *ics2115_internal_rmidi = NULL;
356*4882a593Smuzhiyun struct snd_rawmidi *ics2115_external_rmidi = NULL;
357*4882a593Smuzhiyun struct snd_hwdep *fx_processor;
358*4882a593Smuzhiyun int hw_dev = 0, midi_dev = 0, err;
359*4882a593Smuzhiyun
360*4882a593Smuzhiyun /* --------- PCM --------------- */
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun err = snd_wss_create(card, cs4232_pcm_port[dev], -1,
363*4882a593Smuzhiyun cs4232_pcm_irq[dev], dma1[dev], dma2[dev],
364*4882a593Smuzhiyun WSS_HW_DETECT, 0, &chip);
365*4882a593Smuzhiyun if (err < 0) {
366*4882a593Smuzhiyun snd_printk(KERN_ERR "can't allocate WSS device\n");
367*4882a593Smuzhiyun return err;
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun err = snd_wss_pcm(chip, 0);
371*4882a593Smuzhiyun if (err < 0)
372*4882a593Smuzhiyun return err;
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun err = snd_wss_timer(chip, 0);
375*4882a593Smuzhiyun if (err < 0)
376*4882a593Smuzhiyun return err;
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun /* ---------- OPL3 synth --------- */
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
381*4882a593Smuzhiyun struct snd_opl3 *opl3;
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun err = snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2,
384*4882a593Smuzhiyun OPL3_HW_OPL3_CS, 0, &opl3);
385*4882a593Smuzhiyun if (err < 0) {
386*4882a593Smuzhiyun snd_printk (KERN_ERR "can't allocate or detect OPL3 synth\n");
387*4882a593Smuzhiyun return err;
388*4882a593Smuzhiyun }
389*4882a593Smuzhiyun
390*4882a593Smuzhiyun err = snd_opl3_hwdep_new(opl3, hw_dev, 1, NULL);
391*4882a593Smuzhiyun if (err < 0)
392*4882a593Smuzhiyun return err;
393*4882a593Smuzhiyun hw_dev++;
394*4882a593Smuzhiyun }
395*4882a593Smuzhiyun
396*4882a593Smuzhiyun /* ------- ICS2115 Wavetable synth ------- */
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun acard->wavefront.res_base = request_region(ics2115_port[dev], 16,
399*4882a593Smuzhiyun "ICS2115");
400*4882a593Smuzhiyun if (acard->wavefront.res_base == NULL) {
401*4882a593Smuzhiyun snd_printk(KERN_ERR "unable to grab ICS2115 i/o region 0x%lx-0x%lx\n",
402*4882a593Smuzhiyun ics2115_port[dev], ics2115_port[dev] + 16 - 1);
403*4882a593Smuzhiyun return -EBUSY;
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun if (request_irq(ics2115_irq[dev], snd_wavefront_ics2115_interrupt,
406*4882a593Smuzhiyun 0, "ICS2115", acard)) {
407*4882a593Smuzhiyun snd_printk(KERN_ERR "unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]);
408*4882a593Smuzhiyun return -EBUSY;
409*4882a593Smuzhiyun }
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun acard->wavefront.irq = ics2115_irq[dev];
412*4882a593Smuzhiyun card->sync_irq = acard->wavefront.irq;
413*4882a593Smuzhiyun acard->wavefront.base = ics2115_port[dev];
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun wavefront_synth = snd_wavefront_new_synth(card, hw_dev, acard);
416*4882a593Smuzhiyun if (wavefront_synth == NULL) {
417*4882a593Smuzhiyun snd_printk (KERN_ERR "can't create WaveFront synth device\n");
418*4882a593Smuzhiyun return -ENOMEM;
419*4882a593Smuzhiyun }
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun strcpy (wavefront_synth->name, "ICS2115 Wavetable MIDI Synthesizer");
422*4882a593Smuzhiyun wavefront_synth->iface = SNDRV_HWDEP_IFACE_ICS2115;
423*4882a593Smuzhiyun hw_dev++;
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun /* --------- Mixer ------------ */
426*4882a593Smuzhiyun
427*4882a593Smuzhiyun err = snd_wss_mixer(chip);
428*4882a593Smuzhiyun if (err < 0) {
429*4882a593Smuzhiyun snd_printk (KERN_ERR "can't allocate mixer device\n");
430*4882a593Smuzhiyun return err;
431*4882a593Smuzhiyun }
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun /* -------- CS4232 MPU-401 interface -------- */
434*4882a593Smuzhiyun
435*4882a593Smuzhiyun if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
436*4882a593Smuzhiyun err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232,
437*4882a593Smuzhiyun cs4232_mpu_port[dev], 0,
438*4882a593Smuzhiyun cs4232_mpu_irq[dev], NULL);
439*4882a593Smuzhiyun if (err < 0) {
440*4882a593Smuzhiyun snd_printk (KERN_ERR "can't allocate CS4232 MPU-401 device\n");
441*4882a593Smuzhiyun return err;
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun midi_dev++;
444*4882a593Smuzhiyun }
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun /* ------ ICS2115 internal MIDI ------------ */
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
449*4882a593Smuzhiyun ics2115_internal_rmidi =
450*4882a593Smuzhiyun snd_wavefront_new_midi (card,
451*4882a593Smuzhiyun midi_dev,
452*4882a593Smuzhiyun acard,
453*4882a593Smuzhiyun ics2115_port[dev],
454*4882a593Smuzhiyun internal_mpu);
455*4882a593Smuzhiyun if (ics2115_internal_rmidi == NULL) {
456*4882a593Smuzhiyun snd_printk (KERN_ERR "can't setup ICS2115 internal MIDI device\n");
457*4882a593Smuzhiyun return -ENOMEM;
458*4882a593Smuzhiyun }
459*4882a593Smuzhiyun midi_dev++;
460*4882a593Smuzhiyun }
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun /* ------ ICS2115 external MIDI ------------ */
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
465*4882a593Smuzhiyun ics2115_external_rmidi =
466*4882a593Smuzhiyun snd_wavefront_new_midi (card,
467*4882a593Smuzhiyun midi_dev,
468*4882a593Smuzhiyun acard,
469*4882a593Smuzhiyun ics2115_port[dev],
470*4882a593Smuzhiyun external_mpu);
471*4882a593Smuzhiyun if (ics2115_external_rmidi == NULL) {
472*4882a593Smuzhiyun snd_printk (KERN_ERR "can't setup ICS2115 external MIDI device\n");
473*4882a593Smuzhiyun return -ENOMEM;
474*4882a593Smuzhiyun }
475*4882a593Smuzhiyun midi_dev++;
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun /* FX processor for Tropez+ */
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun if (acard->wavefront.has_fx) {
481*4882a593Smuzhiyun fx_processor = snd_wavefront_new_fx (card,
482*4882a593Smuzhiyun hw_dev,
483*4882a593Smuzhiyun acard,
484*4882a593Smuzhiyun ics2115_port[dev]);
485*4882a593Smuzhiyun if (fx_processor == NULL) {
486*4882a593Smuzhiyun snd_printk (KERN_ERR "can't setup FX device\n");
487*4882a593Smuzhiyun return -ENOMEM;
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun hw_dev++;
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun strcpy(card->driver, "Tropez+");
493*4882a593Smuzhiyun strcpy(card->shortname, "Turtle Beach Tropez+");
494*4882a593Smuzhiyun } else {
495*4882a593Smuzhiyun /* Need a way to distinguish between Maui and Tropez */
496*4882a593Smuzhiyun strcpy(card->driver, "WaveFront");
497*4882a593Smuzhiyun strcpy(card->shortname, "Turtle Beach WaveFront");
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun /* ----- Register the card --------- */
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun /* Not safe to include "Turtle Beach" in longname, due to
503*4882a593Smuzhiyun length restrictions
504*4882a593Smuzhiyun */
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun sprintf(card->longname, "%s PCM 0x%lx irq %d dma %d",
507*4882a593Smuzhiyun card->driver,
508*4882a593Smuzhiyun chip->port,
509*4882a593Smuzhiyun cs4232_pcm_irq[dev],
510*4882a593Smuzhiyun dma1[dev]);
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun if (dma2[dev] >= 0 && dma2[dev] < 8)
513*4882a593Smuzhiyun sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
514*4882a593Smuzhiyun
515*4882a593Smuzhiyun if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
516*4882a593Smuzhiyun sprintf (card->longname + strlen (card->longname),
517*4882a593Smuzhiyun " MPU-401 0x%lx irq %d",
518*4882a593Smuzhiyun cs4232_mpu_port[dev],
519*4882a593Smuzhiyun cs4232_mpu_irq[dev]);
520*4882a593Smuzhiyun }
521*4882a593Smuzhiyun
522*4882a593Smuzhiyun sprintf (card->longname + strlen (card->longname),
523*4882a593Smuzhiyun " SYNTH 0x%lx irq %d",
524*4882a593Smuzhiyun ics2115_port[dev],
525*4882a593Smuzhiyun ics2115_irq[dev]);
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun return snd_card_register(card);
528*4882a593Smuzhiyun }
529*4882a593Smuzhiyun
snd_wavefront_isa_match(struct device * pdev,unsigned int dev)530*4882a593Smuzhiyun static int snd_wavefront_isa_match(struct device *pdev,
531*4882a593Smuzhiyun unsigned int dev)
532*4882a593Smuzhiyun {
533*4882a593Smuzhiyun if (!enable[dev])
534*4882a593Smuzhiyun return 0;
535*4882a593Smuzhiyun #ifdef CONFIG_PNP
536*4882a593Smuzhiyun if (isapnp[dev])
537*4882a593Smuzhiyun return 0;
538*4882a593Smuzhiyun #endif
539*4882a593Smuzhiyun if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
540*4882a593Smuzhiyun snd_printk(KERN_ERR "specify CS4232 port\n");
541*4882a593Smuzhiyun return 0;
542*4882a593Smuzhiyun }
543*4882a593Smuzhiyun if (ics2115_port[dev] == SNDRV_AUTO_PORT) {
544*4882a593Smuzhiyun snd_printk(KERN_ERR "specify ICS2115 port\n");
545*4882a593Smuzhiyun return 0;
546*4882a593Smuzhiyun }
547*4882a593Smuzhiyun return 1;
548*4882a593Smuzhiyun }
549*4882a593Smuzhiyun
snd_wavefront_isa_probe(struct device * pdev,unsigned int dev)550*4882a593Smuzhiyun static int snd_wavefront_isa_probe(struct device *pdev,
551*4882a593Smuzhiyun unsigned int dev)
552*4882a593Smuzhiyun {
553*4882a593Smuzhiyun struct snd_card *card;
554*4882a593Smuzhiyun int err;
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun err = snd_wavefront_card_new(pdev, dev, &card);
557*4882a593Smuzhiyun if (err < 0)
558*4882a593Smuzhiyun return err;
559*4882a593Smuzhiyun if ((err = snd_wavefront_probe(card, dev)) < 0) {
560*4882a593Smuzhiyun snd_card_free(card);
561*4882a593Smuzhiyun return err;
562*4882a593Smuzhiyun }
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun dev_set_drvdata(pdev, card);
565*4882a593Smuzhiyun return 0;
566*4882a593Smuzhiyun }
567*4882a593Smuzhiyun
snd_wavefront_isa_remove(struct device * devptr,unsigned int dev)568*4882a593Smuzhiyun static int snd_wavefront_isa_remove(struct device *devptr,
569*4882a593Smuzhiyun unsigned int dev)
570*4882a593Smuzhiyun {
571*4882a593Smuzhiyun snd_card_free(dev_get_drvdata(devptr));
572*4882a593Smuzhiyun return 0;
573*4882a593Smuzhiyun }
574*4882a593Smuzhiyun
575*4882a593Smuzhiyun #define DEV_NAME "wavefront"
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun static struct isa_driver snd_wavefront_driver = {
578*4882a593Smuzhiyun .match = snd_wavefront_isa_match,
579*4882a593Smuzhiyun .probe = snd_wavefront_isa_probe,
580*4882a593Smuzhiyun .remove = snd_wavefront_isa_remove,
581*4882a593Smuzhiyun /* FIXME: suspend, resume */
582*4882a593Smuzhiyun .driver = {
583*4882a593Smuzhiyun .name = DEV_NAME
584*4882a593Smuzhiyun },
585*4882a593Smuzhiyun };
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun #ifdef CONFIG_PNP
snd_wavefront_pnp_detect(struct pnp_card_link * pcard,const struct pnp_card_device_id * pid)589*4882a593Smuzhiyun static int snd_wavefront_pnp_detect(struct pnp_card_link *pcard,
590*4882a593Smuzhiyun const struct pnp_card_device_id *pid)
591*4882a593Smuzhiyun {
592*4882a593Smuzhiyun static int dev;
593*4882a593Smuzhiyun struct snd_card *card;
594*4882a593Smuzhiyun int res;
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun for ( ; dev < SNDRV_CARDS; dev++) {
597*4882a593Smuzhiyun if (enable[dev] && isapnp[dev])
598*4882a593Smuzhiyun break;
599*4882a593Smuzhiyun }
600*4882a593Smuzhiyun if (dev >= SNDRV_CARDS)
601*4882a593Smuzhiyun return -ENODEV;
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun res = snd_wavefront_card_new(&pcard->card->dev, dev, &card);
604*4882a593Smuzhiyun if (res < 0)
605*4882a593Smuzhiyun return res;
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun if (snd_wavefront_pnp (dev, card->private_data, pcard, pid) < 0) {
608*4882a593Smuzhiyun if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
609*4882a593Smuzhiyun snd_printk (KERN_ERR "isapnp detection failed\n");
610*4882a593Smuzhiyun snd_card_free (card);
611*4882a593Smuzhiyun return -ENODEV;
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun }
614*4882a593Smuzhiyun
615*4882a593Smuzhiyun if ((res = snd_wavefront_probe(card, dev)) < 0)
616*4882a593Smuzhiyun return res;
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun pnp_set_card_drvdata(pcard, card);
619*4882a593Smuzhiyun dev++;
620*4882a593Smuzhiyun return 0;
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun
snd_wavefront_pnp_remove(struct pnp_card_link * pcard)623*4882a593Smuzhiyun static void snd_wavefront_pnp_remove(struct pnp_card_link *pcard)
624*4882a593Smuzhiyun {
625*4882a593Smuzhiyun snd_card_free(pnp_get_card_drvdata(pcard));
626*4882a593Smuzhiyun pnp_set_card_drvdata(pcard, NULL);
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun static struct pnp_card_driver wavefront_pnpc_driver = {
630*4882a593Smuzhiyun .flags = PNP_DRIVER_RES_DISABLE,
631*4882a593Smuzhiyun .name = "wavefront",
632*4882a593Smuzhiyun .id_table = snd_wavefront_pnpids,
633*4882a593Smuzhiyun .probe = snd_wavefront_pnp_detect,
634*4882a593Smuzhiyun .remove = snd_wavefront_pnp_remove,
635*4882a593Smuzhiyun /* FIXME: suspend,resume */
636*4882a593Smuzhiyun };
637*4882a593Smuzhiyun
638*4882a593Smuzhiyun #endif /* CONFIG_PNP */
639*4882a593Smuzhiyun
alsa_card_wavefront_init(void)640*4882a593Smuzhiyun static int __init alsa_card_wavefront_init(void)
641*4882a593Smuzhiyun {
642*4882a593Smuzhiyun int err;
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun err = isa_register_driver(&snd_wavefront_driver, SNDRV_CARDS);
645*4882a593Smuzhiyun #ifdef CONFIG_PNP
646*4882a593Smuzhiyun if (!err)
647*4882a593Smuzhiyun isa_registered = 1;
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun err = pnp_register_card_driver(&wavefront_pnpc_driver);
650*4882a593Smuzhiyun if (!err)
651*4882a593Smuzhiyun pnp_registered = 1;
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun if (isa_registered)
654*4882a593Smuzhiyun err = 0;
655*4882a593Smuzhiyun #endif
656*4882a593Smuzhiyun return err;
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun
alsa_card_wavefront_exit(void)659*4882a593Smuzhiyun static void __exit alsa_card_wavefront_exit(void)
660*4882a593Smuzhiyun {
661*4882a593Smuzhiyun #ifdef CONFIG_PNP
662*4882a593Smuzhiyun if (pnp_registered)
663*4882a593Smuzhiyun pnp_unregister_card_driver(&wavefront_pnpc_driver);
664*4882a593Smuzhiyun if (isa_registered)
665*4882a593Smuzhiyun #endif
666*4882a593Smuzhiyun isa_unregister_driver(&snd_wavefront_driver);
667*4882a593Smuzhiyun }
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun module_init(alsa_card_wavefront_init)
670*4882a593Smuzhiyun module_exit(alsa_card_wavefront_exit)
671