3 * jazz16.c - driver for Media Vision Jazz16 based soundcards.
4 * Copyright (C) 2009 Krzysztof Helt <krzysztof.h1@wp.pl>
5 * Based on patches posted by Rask Ingemann Lambertsen and Rene Herman.
6 * Based on OSS Sound Blaster driver.
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
14 #include <linux/init.h>
15 #include <linux/module.h>
18 #include <linux/isa.h>
19 #include <sound/core.h>
20 #include <sound/mpu401.h>
21 #include <sound/opl3.h>
23 #define SNDRV_LEGACY_FIND_FREE_IRQ
24 #define SNDRV_LEGACY_FIND_FREE_DMA
25 #include <sound/initval.h>
27 #define PFX "jazz16: "
29 MODULE_DESCRIPTION("Media Vision Jazz16");
30 MODULE_SUPPORTED_DEVICE("{{Media Vision ??? },"
33 MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
34 MODULE_LICENSE("GPL");
36 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
37 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
38 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
39 static unsigned long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
40 static unsigned long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
41 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
42 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
43 static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
44 static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
46 module_param_array(index, int, NULL, 0444);
47 MODULE_PARM_DESC(index, "Index value for Media Vision Jazz16 based soundcard.");
48 module_param_array(id, charp, NULL, 0444);
49 MODULE_PARM_DESC(id, "ID string for Media Vision Jazz16 based soundcard.");
50 module_param_array(enable, bool, NULL, 0444);
51 MODULE_PARM_DESC(enable, "Enable Media Vision Jazz16 based soundcard.");
52 module_param_array(port, long, NULL, 0444);
53 MODULE_PARM_DESC(port, "Port # for jazz16 driver.");
54 module_param_array(mpu_port, long, NULL, 0444);
55 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for jazz16 driver.");
56 module_param_array(irq, int, NULL, 0444);
57 MODULE_PARM_DESC(irq, "IRQ # for jazz16 driver.");
58 module_param_array(mpu_irq, int, NULL, 0444);
59 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for jazz16 driver.");
60 module_param_array(dma8, int, NULL, 0444);
61 MODULE_PARM_DESC(dma8, "DMA8 # for jazz16 driver.");
62 module_param_array(dma16, int, NULL, 0444);
63 MODULE_PARM_DESC(dma16, "DMA16 # for jazz16 driver.");
65 #define SB_JAZZ16_WAKEUP 0xaf
66 #define SB_JAZZ16_SET_PORTS 0x50
67 #define SB_DSP_GET_JAZZ_BRD_REV 0xfa
68 #define SB_JAZZ16_SET_DMAINTR 0xfb
69 #define SB_DSP_GET_JAZZ_MODEL 0xfe
71 struct snd_card_jazz16 {
75 static irqreturn_t jazz16_interrupt(int irq, void *chip)
77 return snd_sb8dsp_interrupt(chip);
80 static int __devinit jazz16_configure_ports(unsigned long port,
81 unsigned long mpu_port, int idx)
85 if (!request_region(0x201, 1, "jazz16 config")) {
86 snd_printk(KERN_ERR "config port region is already in use.\n");
89 outb(SB_JAZZ16_WAKEUP - idx, 0x201);
91 outb(SB_JAZZ16_SET_PORTS + idx, 0x201);
94 val |= (mpu_port & 0x30) >> 4;
97 release_region(0x201, 1);
101 static int __devinit jazz16_detect_board(unsigned long port,
102 unsigned long mpu_port)
108 if (!request_region(port, 0x10, "jazz16")) {
109 snd_printk(KERN_ERR "I/O port region is already in use.\n");
112 /* just to call snd_sbdsp_command/reset/get_byte() */
115 err = snd_sbdsp_reset(&chip);
117 for (val = 0; val < 4; val++) {
118 err = jazz16_configure_ports(port, mpu_port, val);
122 err = snd_sbdsp_reset(&chip);
130 if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_BRD_REV)) {
134 val = snd_sbdsp_get_byte(&chip);
136 snd_sbdsp_get_byte(&chip);
138 if ((val & 0xf0) != 0x10) {
142 if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_MODEL)) {
146 snd_sbdsp_get_byte(&chip);
147 err = snd_sbdsp_get_byte(&chip);
148 snd_printd("Media Vision Jazz16 board detected: rev 0x%x, model 0x%x\n",
154 release_region(port, 0x10);
158 static int __devinit jazz16_configure_board(struct snd_sb *chip, int mpu_irq)
160 static unsigned char jazz_irq_bits[] = { 0, 0, 2, 3, 0, 1, 0, 4,
161 0, 2, 5, 0, 0, 0, 0, 6 };
162 static unsigned char jazz_dma_bits[] = { 0, 1, 0, 2, 0, 3, 0, 4 };
164 if (jazz_dma_bits[chip->dma8] == 0 ||
165 jazz_dma_bits[chip->dma16] == 0 ||
166 jazz_irq_bits[chip->irq] == 0)
169 if (!snd_sbdsp_command(chip, SB_JAZZ16_SET_DMAINTR))
172 if (!snd_sbdsp_command(chip,
173 jazz_dma_bits[chip->dma8] |
174 (jazz_dma_bits[chip->dma16] << 4)))
177 if (!snd_sbdsp_command(chip,
178 jazz_irq_bits[chip->irq] |
179 (jazz_irq_bits[mpu_irq] << 4)))
185 static int __devinit snd_jazz16_match(struct device *devptr, unsigned int dev)
189 if (port[dev] == SNDRV_AUTO_PORT) {
190 snd_printk(KERN_ERR "please specify port\n");
193 if (dma16[dev] != SNDRV_AUTO_DMA &&
194 dma16[dev] != 5 && dma16[dev] != 7) {
195 snd_printk(KERN_ERR "dma16 must be 5 or 7");
201 static int __devinit snd_jazz16_probe(struct device *devptr, unsigned int dev)
203 struct snd_card *card;
204 struct snd_card_jazz16 *jazz16;
206 struct snd_opl3 *opl3;
207 static int possible_irqs[] = {2, 3, 5, 7, 9, 10, 15, -1};
208 static int possible_dmas8[] = {1, 3, -1};
209 static int possible_dmas16[] = {5, 7, -1};
210 int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq;
212 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
213 sizeof(struct snd_card_jazz16), &card);
217 jazz16 = card->private_data;
220 if (xirq == SNDRV_AUTO_IRQ) {
221 xirq = snd_legacy_find_free_irq(possible_irqs);
223 snd_printk(KERN_ERR "unable to find a free IRQ\n");
229 if (xdma8 == SNDRV_AUTO_DMA) {
230 xdma8 = snd_legacy_find_free_dma(possible_dmas8);
232 snd_printk(KERN_ERR "unable to find a free DMA8\n");
238 if (xdma16 == SNDRV_AUTO_DMA) {
239 xdma16 = snd_legacy_find_free_dma(possible_dmas16);
241 snd_printk(KERN_ERR "unable to find a free DMA16\n");
247 xmpu_port = mpu_port[dev];
248 if (xmpu_port == SNDRV_AUTO_PORT)
250 err = jazz16_detect_board(port[dev], xmpu_port);
252 printk(KERN_ERR "Media Vision Jazz16 board not detected\n");
255 err = snd_sbdsp_create(card, port[dev], irq[dev],
257 dma8[dev], dma16[dev],
263 xmpu_irq = mpu_irq[dev];
264 if (xmpu_irq == SNDRV_AUTO_IRQ || mpu_port[dev] == SNDRV_AUTO_PORT)
266 err = jazz16_configure_board(chip, xmpu_irq);
268 printk(KERN_ERR "Media Vision Jazz16 configuration failed\n");
274 strcpy(card->driver, "jazz16");
275 strcpy(card->shortname, "Media Vision Jazz16");
276 sprintf(card->longname,
277 "Media Vision Jazz16 at 0x%lx, irq %d, dma8 %d, dma16 %d",
278 port[dev], xirq, xdma8, xdma16);
280 err = snd_sb8dsp_pcm(chip, 0, NULL);
283 err = snd_sbmixer_new(chip);
287 err = snd_opl3_create(card, chip->port, chip->port + 2,
288 OPL3_HW_AUTO, 1, &opl3);
290 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
291 chip->port, chip->port + 2);
293 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
297 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
298 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
301 if (snd_mpu401_uart_new(card, 0,
305 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
307 snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n",
311 snd_card_set_dev(card, devptr);
313 err = snd_card_register(card);
317 dev_set_drvdata(devptr, card);
325 static int __devexit snd_jazz16_remove(struct device *devptr, unsigned int dev)
327 struct snd_card *card = dev_get_drvdata(devptr);
329 dev_set_drvdata(devptr, NULL);
335 static int snd_jazz16_suspend(struct device *pdev, unsigned int n,
338 struct snd_card *card = dev_get_drvdata(pdev);
339 struct snd_card_jazz16 *acard = card->private_data;
340 struct snd_sb *chip = acard->chip;
342 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
343 snd_pcm_suspend_all(chip->pcm);
344 snd_sbmixer_suspend(chip);
348 static int snd_jazz16_resume(struct device *pdev, unsigned int n)
350 struct snd_card *card = dev_get_drvdata(pdev);
351 struct snd_card_jazz16 *acard = card->private_data;
352 struct snd_sb *chip = acard->chip;
354 snd_sbdsp_reset(chip);
355 snd_sbmixer_resume(chip);
356 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
361 static struct isa_driver snd_jazz16_driver = {
362 .match = snd_jazz16_match,
363 .probe = snd_jazz16_probe,
364 .remove = __devexit_p(snd_jazz16_remove),
366 .suspend = snd_jazz16_suspend,
367 .resume = snd_jazz16_resume,
374 static int __init alsa_card_jazz16_init(void)
376 return isa_register_driver(&snd_jazz16_driver, SNDRV_CARDS);
379 static void __exit alsa_card_jazz16_exit(void)
381 isa_unregister_driver(&snd_jazz16_driver);
384 module_init(alsa_card_jazz16_init)
385 module_exit(alsa_card_jazz16_exit)