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>
17 #include <linux/delay.h>
19 #include <linux/isa.h>
20 #include <sound/core.h>
21 #include <sound/mpu401.h>
22 #include <sound/opl3.h>
24 #define SNDRV_LEGACY_FIND_FREE_IRQ
25 #define SNDRV_LEGACY_FIND_FREE_DMA
26 #include <sound/initval.h>
28 #define PFX "jazz16: "
30 MODULE_DESCRIPTION("Media Vision Jazz16");
31 MODULE_SUPPORTED_DEVICE("{{Media Vision ??? },"
34 MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
35 MODULE_LICENSE("GPL");
37 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
38 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
39 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE
; /* Enable this card */
40 static unsigned long port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
41 static unsigned long mpu_port
[SNDRV_CARDS
] = SNDRV_DEFAULT_PORT
;
42 static int irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
;
43 static int mpu_irq
[SNDRV_CARDS
] = SNDRV_DEFAULT_IRQ
;
44 static int dma8
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
;
45 static int dma16
[SNDRV_CARDS
] = SNDRV_DEFAULT_DMA
;
47 module_param_array(index
, int, NULL
, 0444);
48 MODULE_PARM_DESC(index
, "Index value for Media Vision Jazz16 based soundcard.");
49 module_param_array(id
, charp
, NULL
, 0444);
50 MODULE_PARM_DESC(id
, "ID string for Media Vision Jazz16 based soundcard.");
51 module_param_array(enable
, bool, NULL
, 0444);
52 MODULE_PARM_DESC(enable
, "Enable Media Vision Jazz16 based soundcard.");
53 module_param_array(port
, long, NULL
, 0444);
54 MODULE_PARM_DESC(port
, "Port # for jazz16 driver.");
55 module_param_array(mpu_port
, long, NULL
, 0444);
56 MODULE_PARM_DESC(mpu_port
, "MPU-401 port # for jazz16 driver.");
57 module_param_array(irq
, int, NULL
, 0444);
58 MODULE_PARM_DESC(irq
, "IRQ # for jazz16 driver.");
59 module_param_array(mpu_irq
, int, NULL
, 0444);
60 MODULE_PARM_DESC(mpu_irq
, "MPU-401 IRQ # for jazz16 driver.");
61 module_param_array(dma8
, int, NULL
, 0444);
62 MODULE_PARM_DESC(dma8
, "DMA8 # for jazz16 driver.");
63 module_param_array(dma16
, int, NULL
, 0444);
64 MODULE_PARM_DESC(dma16
, "DMA16 # for jazz16 driver.");
66 #define SB_JAZZ16_WAKEUP 0xaf
67 #define SB_JAZZ16_SET_PORTS 0x50
68 #define SB_DSP_GET_JAZZ_BRD_REV 0xfa
69 #define SB_JAZZ16_SET_DMAINTR 0xfb
70 #define SB_DSP_GET_JAZZ_MODEL 0xfe
72 struct snd_card_jazz16
{
76 static irqreturn_t
jazz16_interrupt(int irq
, void *chip
)
78 return snd_sb8dsp_interrupt(chip
);
81 static int jazz16_configure_ports(unsigned long port
,
82 unsigned long mpu_port
, int idx
)
86 if (!request_region(0x201, 1, "jazz16 config")) {
87 snd_printk(KERN_ERR
"config port region is already in use.\n");
90 outb(SB_JAZZ16_WAKEUP
- idx
, 0x201);
92 outb(SB_JAZZ16_SET_PORTS
+ idx
, 0x201);
95 val
|= (mpu_port
& 0x30) >> 4;
98 release_region(0x201, 1);
102 static int jazz16_detect_board(unsigned long port
,
103 unsigned long mpu_port
)
109 if (!request_region(port
, 0x10, "jazz16")) {
110 snd_printk(KERN_ERR
"I/O port region is already in use.\n");
113 /* just to call snd_sbdsp_command/reset/get_byte() */
116 err
= snd_sbdsp_reset(&chip
);
118 for (val
= 0; val
< 4; val
++) {
119 err
= jazz16_configure_ports(port
, mpu_port
, val
);
123 err
= snd_sbdsp_reset(&chip
);
131 if (!snd_sbdsp_command(&chip
, SB_DSP_GET_JAZZ_BRD_REV
)) {
135 val
= snd_sbdsp_get_byte(&chip
);
137 snd_sbdsp_get_byte(&chip
);
139 if ((val
& 0xf0) != 0x10) {
143 if (!snd_sbdsp_command(&chip
, SB_DSP_GET_JAZZ_MODEL
)) {
147 snd_sbdsp_get_byte(&chip
);
148 err
= snd_sbdsp_get_byte(&chip
);
149 snd_printd("Media Vision Jazz16 board detected: rev 0x%x, model 0x%x\n",
155 release_region(port
, 0x10);
159 static int jazz16_configure_board(struct snd_sb
*chip
, int mpu_irq
)
161 static unsigned char jazz_irq_bits
[] = { 0, 0, 2, 3, 0, 1, 0, 4,
162 0, 2, 5, 0, 0, 0, 0, 6 };
163 static unsigned char jazz_dma_bits
[] = { 0, 1, 0, 2, 0, 3, 0, 4 };
165 if (jazz_dma_bits
[chip
->dma8
] == 0 ||
166 jazz_dma_bits
[chip
->dma16
] == 0 ||
167 jazz_irq_bits
[chip
->irq
] == 0)
170 if (!snd_sbdsp_command(chip
, SB_JAZZ16_SET_DMAINTR
))
173 if (!snd_sbdsp_command(chip
,
174 jazz_dma_bits
[chip
->dma8
] |
175 (jazz_dma_bits
[chip
->dma16
] << 4)))
178 if (!snd_sbdsp_command(chip
,
179 jazz_irq_bits
[chip
->irq
] |
180 (jazz_irq_bits
[mpu_irq
] << 4)))
186 static int snd_jazz16_match(struct device
*devptr
, unsigned int dev
)
190 if (port
[dev
] == SNDRV_AUTO_PORT
) {
191 snd_printk(KERN_ERR
"please specify port\n");
193 } else if (port
[dev
] == 0x200 || (port
[dev
] & ~0x270)) {
194 snd_printk(KERN_ERR
"incorrect port specified\n");
197 if (dma8
[dev
] != SNDRV_AUTO_DMA
&&
198 dma8
[dev
] != 1 && dma8
[dev
] != 3) {
199 snd_printk(KERN_ERR
"dma8 must be 1 or 3\n");
202 if (dma16
[dev
] != SNDRV_AUTO_DMA
&&
203 dma16
[dev
] != 5 && dma16
[dev
] != 7) {
204 snd_printk(KERN_ERR
"dma16 must be 5 or 7\n");
207 if (mpu_port
[dev
] != SNDRV_AUTO_PORT
&&
208 (mpu_port
[dev
] & ~0x030) != 0x300) {
209 snd_printk(KERN_ERR
"incorrect mpu_port specified\n");
212 if (mpu_irq
[dev
] != SNDRV_AUTO_DMA
&&
213 mpu_irq
[dev
] != 2 && mpu_irq
[dev
] != 3 &&
214 mpu_irq
[dev
] != 5 && mpu_irq
[dev
] != 7) {
215 snd_printk(KERN_ERR
"mpu_irq must be 2, 3, 5 or 7\n");
221 static int snd_jazz16_probe(struct device
*devptr
, unsigned int dev
)
223 struct snd_card
*card
;
224 struct snd_card_jazz16
*jazz16
;
226 struct snd_opl3
*opl3
;
227 static int possible_irqs
[] = {2, 3, 5, 7, 9, 10, 15, -1};
228 static int possible_dmas8
[] = {1, 3, -1};
229 static int possible_dmas16
[] = {5, 7, -1};
230 int err
, xirq
, xdma8
, xdma16
, xmpu_port
, xmpu_irq
;
232 err
= snd_card_new(devptr
, index
[dev
], id
[dev
], THIS_MODULE
,
233 sizeof(struct snd_card_jazz16
), &card
);
237 jazz16
= card
->private_data
;
240 if (xirq
== SNDRV_AUTO_IRQ
) {
241 xirq
= snd_legacy_find_free_irq(possible_irqs
);
243 snd_printk(KERN_ERR
"unable to find a free IRQ\n");
249 if (xdma8
== SNDRV_AUTO_DMA
) {
250 xdma8
= snd_legacy_find_free_dma(possible_dmas8
);
252 snd_printk(KERN_ERR
"unable to find a free DMA8\n");
258 if (xdma16
== SNDRV_AUTO_DMA
) {
259 xdma16
= snd_legacy_find_free_dma(possible_dmas16
);
261 snd_printk(KERN_ERR
"unable to find a free DMA16\n");
267 xmpu_port
= mpu_port
[dev
];
268 if (xmpu_port
== SNDRV_AUTO_PORT
)
270 err
= jazz16_detect_board(port
[dev
], xmpu_port
);
272 printk(KERN_ERR
"Media Vision Jazz16 board not detected\n");
275 err
= snd_sbdsp_create(card
, port
[dev
], irq
[dev
],
277 dma8
[dev
], dma16
[dev
],
283 xmpu_irq
= mpu_irq
[dev
];
284 if (xmpu_irq
== SNDRV_AUTO_IRQ
|| mpu_port
[dev
] == SNDRV_AUTO_PORT
)
286 err
= jazz16_configure_board(chip
, xmpu_irq
);
288 printk(KERN_ERR
"Media Vision Jazz16 configuration failed\n");
294 strcpy(card
->driver
, "jazz16");
295 strcpy(card
->shortname
, "Media Vision Jazz16");
296 sprintf(card
->longname
,
297 "Media Vision Jazz16 at 0x%lx, irq %d, dma8 %d, dma16 %d",
298 port
[dev
], xirq
, xdma8
, xdma16
);
300 err
= snd_sb8dsp_pcm(chip
, 0);
303 err
= snd_sbmixer_new(chip
);
307 err
= snd_opl3_create(card
, chip
->port
, chip
->port
+ 2,
308 OPL3_HW_AUTO
, 1, &opl3
);
310 snd_printk(KERN_WARNING
"no OPL device at 0x%lx-0x%lx\n",
311 chip
->port
, chip
->port
+ 2);
313 err
= snd_opl3_hwdep_new(opl3
, 0, 1, NULL
);
317 if (mpu_port
[dev
] > 0 && mpu_port
[dev
] != SNDRV_AUTO_PORT
) {
318 if (mpu_irq
[dev
] == SNDRV_AUTO_IRQ
)
321 if (snd_mpu401_uart_new(card
, 0,
326 snd_printk(KERN_ERR
"no MPU-401 device at 0x%lx\n",
330 err
= snd_card_register(card
);
334 dev_set_drvdata(devptr
, card
);
342 static int snd_jazz16_remove(struct device
*devptr
, unsigned int dev
)
344 struct snd_card
*card
= dev_get_drvdata(devptr
);
351 static int snd_jazz16_suspend(struct device
*pdev
, unsigned int n
,
354 struct snd_card
*card
= dev_get_drvdata(pdev
);
355 struct snd_card_jazz16
*acard
= card
->private_data
;
356 struct snd_sb
*chip
= acard
->chip
;
358 snd_power_change_state(card
, SNDRV_CTL_POWER_D3hot
);
359 snd_pcm_suspend_all(chip
->pcm
);
360 snd_sbmixer_suspend(chip
);
364 static int snd_jazz16_resume(struct device
*pdev
, unsigned int n
)
366 struct snd_card
*card
= dev_get_drvdata(pdev
);
367 struct snd_card_jazz16
*acard
= card
->private_data
;
368 struct snd_sb
*chip
= acard
->chip
;
370 snd_sbdsp_reset(chip
);
371 snd_sbmixer_resume(chip
);
372 snd_power_change_state(card
, SNDRV_CTL_POWER_D0
);
377 static struct isa_driver snd_jazz16_driver
= {
378 .match
= snd_jazz16_match
,
379 .probe
= snd_jazz16_probe
,
380 .remove
= snd_jazz16_remove
,
382 .suspend
= snd_jazz16_suspend
,
383 .resume
= snd_jazz16_resume
,
390 static int __init
alsa_card_jazz16_init(void)
392 return isa_register_driver(&snd_jazz16_driver
, SNDRV_CARDS
);
395 static void __exit
alsa_card_jazz16_exit(void)
397 isa_unregister_driver(&snd_jazz16_driver
);
400 module_init(alsa_card_jazz16_init
)
401 module_exit(alsa_card_jazz16_exit
)