Loading...
1
2/*
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.
7 *
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
10 * more details.
11 *
12 */
13
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/io.h>
17#include <linux/delay.h>
18#include <asm/dma.h>
19#include <linux/isa.h>
20#include <sound/core.h>
21#include <sound/mpu401.h>
22#include <sound/opl3.h>
23#include <sound/sb.h>
24#define SNDRV_LEGACY_FIND_FREE_IRQ
25#define SNDRV_LEGACY_FIND_FREE_DMA
26#include <sound/initval.h>
27
28#define PFX "jazz16: "
29
30MODULE_DESCRIPTION("Media Vision Jazz16");
31MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
32MODULE_LICENSE("GPL");
33
34static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
35static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
36static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
37static unsigned long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
38static unsigned long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
39static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
40static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
41static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
42static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
43
44module_param_array(index, int, NULL, 0444);
45MODULE_PARM_DESC(index, "Index value for Media Vision Jazz16 based soundcard.");
46module_param_array(id, charp, NULL, 0444);
47MODULE_PARM_DESC(id, "ID string for Media Vision Jazz16 based soundcard.");
48module_param_array(enable, bool, NULL, 0444);
49MODULE_PARM_DESC(enable, "Enable Media Vision Jazz16 based soundcard.");
50module_param_hw_array(port, long, ioport, NULL, 0444);
51MODULE_PARM_DESC(port, "Port # for jazz16 driver.");
52module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
53MODULE_PARM_DESC(mpu_port, "MPU-401 port # for jazz16 driver.");
54module_param_hw_array(irq, int, irq, NULL, 0444);
55MODULE_PARM_DESC(irq, "IRQ # for jazz16 driver.");
56module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
57MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for jazz16 driver.");
58module_param_hw_array(dma8, int, dma, NULL, 0444);
59MODULE_PARM_DESC(dma8, "DMA8 # for jazz16 driver.");
60module_param_hw_array(dma16, int, dma, NULL, 0444);
61MODULE_PARM_DESC(dma16, "DMA16 # for jazz16 driver.");
62
63#define SB_JAZZ16_WAKEUP 0xaf
64#define SB_JAZZ16_SET_PORTS 0x50
65#define SB_DSP_GET_JAZZ_BRD_REV 0xfa
66#define SB_JAZZ16_SET_DMAINTR 0xfb
67#define SB_DSP_GET_JAZZ_MODEL 0xfe
68
69struct snd_card_jazz16 {
70 struct snd_sb *chip;
71};
72
73static irqreturn_t jazz16_interrupt(int irq, void *chip)
74{
75 return snd_sb8dsp_interrupt(chip);
76}
77
78static int jazz16_configure_ports(unsigned long port,
79 unsigned long mpu_port, int idx)
80{
81 unsigned char val;
82
83 if (!request_region(0x201, 1, "jazz16 config")) {
84 snd_printk(KERN_ERR "config port region is already in use.\n");
85 return -EBUSY;
86 }
87 outb(SB_JAZZ16_WAKEUP - idx, 0x201);
88 udelay(100);
89 outb(SB_JAZZ16_SET_PORTS + idx, 0x201);
90 udelay(100);
91 val = port & 0x70;
92 val |= (mpu_port & 0x30) >> 4;
93 outb(val, 0x201);
94
95 release_region(0x201, 1);
96 return 0;
97}
98
99static int jazz16_detect_board(unsigned long port,
100 unsigned long mpu_port)
101{
102 int err;
103 int val;
104 struct snd_sb chip;
105
106 if (!request_region(port, 0x10, "jazz16")) {
107 snd_printk(KERN_ERR "I/O port region is already in use.\n");
108 return -EBUSY;
109 }
110 /* just to call snd_sbdsp_command/reset/get_byte() */
111 chip.port = port;
112
113 err = snd_sbdsp_reset(&chip);
114 if (err < 0)
115 for (val = 0; val < 4; val++) {
116 err = jazz16_configure_ports(port, mpu_port, val);
117 if (err < 0)
118 break;
119
120 err = snd_sbdsp_reset(&chip);
121 if (!err)
122 break;
123 }
124 if (err < 0) {
125 err = -ENODEV;
126 goto err_unmap;
127 }
128 if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_BRD_REV)) {
129 err = -EBUSY;
130 goto err_unmap;
131 }
132 val = snd_sbdsp_get_byte(&chip);
133 if (val >= 0x30)
134 snd_sbdsp_get_byte(&chip);
135
136 if ((val & 0xf0) != 0x10) {
137 err = -ENODEV;
138 goto err_unmap;
139 }
140 if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_MODEL)) {
141 err = -EBUSY;
142 goto err_unmap;
143 }
144 snd_sbdsp_get_byte(&chip);
145 err = snd_sbdsp_get_byte(&chip);
146 snd_printd("Media Vision Jazz16 board detected: rev 0x%x, model 0x%x\n",
147 val, err);
148
149 err = 0;
150
151err_unmap:
152 release_region(port, 0x10);
153 return err;
154}
155
156static int jazz16_configure_board(struct snd_sb *chip, int mpu_irq)
157{
158 static const unsigned char jazz_irq_bits[] = { 0, 0, 2, 3, 0, 1, 0, 4,
159 0, 2, 5, 0, 0, 0, 0, 6 };
160 static const unsigned char jazz_dma_bits[] = { 0, 1, 0, 2, 0, 3, 0, 4 };
161
162 if (jazz_dma_bits[chip->dma8] == 0 ||
163 jazz_dma_bits[chip->dma16] == 0 ||
164 jazz_irq_bits[chip->irq] == 0)
165 return -EINVAL;
166
167 if (!snd_sbdsp_command(chip, SB_JAZZ16_SET_DMAINTR))
168 return -EBUSY;
169
170 if (!snd_sbdsp_command(chip,
171 jazz_dma_bits[chip->dma8] |
172 (jazz_dma_bits[chip->dma16] << 4)))
173 return -EBUSY;
174
175 if (!snd_sbdsp_command(chip,
176 jazz_irq_bits[chip->irq] |
177 (jazz_irq_bits[mpu_irq] << 4)))
178 return -EBUSY;
179
180 return 0;
181}
182
183static int snd_jazz16_match(struct device *devptr, unsigned int dev)
184{
185 if (!enable[dev])
186 return 0;
187 if (port[dev] == SNDRV_AUTO_PORT) {
188 snd_printk(KERN_ERR "please specify port\n");
189 return 0;
190 } else if (port[dev] == 0x200 || (port[dev] & ~0x270)) {
191 snd_printk(KERN_ERR "incorrect port specified\n");
192 return 0;
193 }
194 if (dma8[dev] != SNDRV_AUTO_DMA &&
195 dma8[dev] != 1 && dma8[dev] != 3) {
196 snd_printk(KERN_ERR "dma8 must be 1 or 3\n");
197 return 0;
198 }
199 if (dma16[dev] != SNDRV_AUTO_DMA &&
200 dma16[dev] != 5 && dma16[dev] != 7) {
201 snd_printk(KERN_ERR "dma16 must be 5 or 7\n");
202 return 0;
203 }
204 if (mpu_port[dev] != SNDRV_AUTO_PORT &&
205 (mpu_port[dev] & ~0x030) != 0x300) {
206 snd_printk(KERN_ERR "incorrect mpu_port specified\n");
207 return 0;
208 }
209 if (mpu_irq[dev] != SNDRV_AUTO_DMA &&
210 mpu_irq[dev] != 2 && mpu_irq[dev] != 3 &&
211 mpu_irq[dev] != 5 && mpu_irq[dev] != 7) {
212 snd_printk(KERN_ERR "mpu_irq must be 2, 3, 5 or 7\n");
213 return 0;
214 }
215 return 1;
216}
217
218static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
219{
220 struct snd_card *card;
221 struct snd_card_jazz16 *jazz16;
222 struct snd_sb *chip;
223 struct snd_opl3 *opl3;
224 static const int possible_irqs[] = {2, 3, 5, 7, 9, 10, 15, -1};
225 static const int possible_dmas8[] = {1, 3, -1};
226 static const int possible_dmas16[] = {5, 7, -1};
227 int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq;
228
229 err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE,
230 sizeof(struct snd_card_jazz16), &card);
231 if (err < 0)
232 return err;
233
234 jazz16 = card->private_data;
235
236 xirq = irq[dev];
237 if (xirq == SNDRV_AUTO_IRQ) {
238 xirq = snd_legacy_find_free_irq(possible_irqs);
239 if (xirq < 0) {
240 snd_printk(KERN_ERR "unable to find a free IRQ\n");
241 return -EBUSY;
242 }
243 }
244 xdma8 = dma8[dev];
245 if (xdma8 == SNDRV_AUTO_DMA) {
246 xdma8 = snd_legacy_find_free_dma(possible_dmas8);
247 if (xdma8 < 0) {
248 snd_printk(KERN_ERR "unable to find a free DMA8\n");
249 return -EBUSY;
250 }
251 }
252 xdma16 = dma16[dev];
253 if (xdma16 == SNDRV_AUTO_DMA) {
254 xdma16 = snd_legacy_find_free_dma(possible_dmas16);
255 if (xdma16 < 0) {
256 snd_printk(KERN_ERR "unable to find a free DMA16\n");
257 return -EBUSY;
258 }
259 }
260
261 xmpu_port = mpu_port[dev];
262 if (xmpu_port == SNDRV_AUTO_PORT)
263 xmpu_port = 0;
264 err = jazz16_detect_board(port[dev], xmpu_port);
265 if (err < 0) {
266 printk(KERN_ERR "Media Vision Jazz16 board not detected\n");
267 return err;
268 }
269 err = snd_sbdsp_create(card, port[dev], irq[dev],
270 jazz16_interrupt,
271 dma8[dev], dma16[dev],
272 SB_HW_JAZZ16,
273 &chip);
274 if (err < 0)
275 return err;
276
277 xmpu_irq = mpu_irq[dev];
278 if (xmpu_irq == SNDRV_AUTO_IRQ || mpu_port[dev] == SNDRV_AUTO_PORT)
279 xmpu_irq = 0;
280 err = jazz16_configure_board(chip, xmpu_irq);
281 if (err < 0) {
282 printk(KERN_ERR "Media Vision Jazz16 configuration failed\n");
283 return err;
284 }
285
286 jazz16->chip = chip;
287
288 strcpy(card->driver, "jazz16");
289 strcpy(card->shortname, "Media Vision Jazz16");
290 sprintf(card->longname,
291 "Media Vision Jazz16 at 0x%lx, irq %d, dma8 %d, dma16 %d",
292 port[dev], xirq, xdma8, xdma16);
293
294 err = snd_sb8dsp_pcm(chip, 0);
295 if (err < 0)
296 return err;
297 err = snd_sbmixer_new(chip);
298 if (err < 0)
299 return err;
300
301 err = snd_opl3_create(card, chip->port, chip->port + 2,
302 OPL3_HW_AUTO, 1, &opl3);
303 if (err < 0)
304 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
305 chip->port, chip->port + 2);
306 else {
307 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
308 if (err < 0)
309 return err;
310 }
311 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
312 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
313 mpu_irq[dev] = -1;
314
315 if (snd_mpu401_uart_new(card, 0,
316 MPU401_HW_MPU401,
317 mpu_port[dev], 0,
318 mpu_irq[dev],
319 NULL) < 0)
320 snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n",
321 mpu_port[dev]);
322 }
323
324 err = snd_card_register(card);
325 if (err < 0)
326 return err;
327
328 dev_set_drvdata(devptr, card);
329 return 0;
330}
331
332#ifdef CONFIG_PM
333static int snd_jazz16_suspend(struct device *pdev, unsigned int n,
334 pm_message_t state)
335{
336 struct snd_card *card = dev_get_drvdata(pdev);
337 struct snd_card_jazz16 *acard = card->private_data;
338 struct snd_sb *chip = acard->chip;
339
340 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
341 snd_sbmixer_suspend(chip);
342 return 0;
343}
344
345static int snd_jazz16_resume(struct device *pdev, unsigned int n)
346{
347 struct snd_card *card = dev_get_drvdata(pdev);
348 struct snd_card_jazz16 *acard = card->private_data;
349 struct snd_sb *chip = acard->chip;
350
351 snd_sbdsp_reset(chip);
352 snd_sbmixer_resume(chip);
353 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
354 return 0;
355}
356#endif
357
358static struct isa_driver snd_jazz16_driver = {
359 .match = snd_jazz16_match,
360 .probe = snd_jazz16_probe,
361#ifdef CONFIG_PM
362 .suspend = snd_jazz16_suspend,
363 .resume = snd_jazz16_resume,
364#endif
365 .driver = {
366 .name = "jazz16"
367 },
368};
369
370module_isa_driver(snd_jazz16_driver, SNDRV_CARDS);
1
2/*
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.
7 *
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
10 * more details.
11 *
12 */
13
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/io.h>
17#include <linux/delay.h>
18#include <asm/dma.h>
19#include <linux/isa.h>
20#include <sound/core.h>
21#include <sound/mpu401.h>
22#include <sound/opl3.h>
23#include <sound/sb.h>
24#define SNDRV_LEGACY_FIND_FREE_IRQ
25#define SNDRV_LEGACY_FIND_FREE_DMA
26#include <sound/initval.h>
27
28#define PFX "jazz16: "
29
30MODULE_DESCRIPTION("Media Vision Jazz16");
31MODULE_SUPPORTED_DEVICE("{{Media Vision ??? },"
32 "{RTL,RTL3000}}");
33
34MODULE_AUTHOR("Krzysztof Helt <krzysztof.h1@wp.pl>");
35MODULE_LICENSE("GPL");
36
37static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
38static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
39static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
40static unsigned long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
41static unsigned long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
42static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
43static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
44static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
45static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
46
47module_param_array(index, int, NULL, 0444);
48MODULE_PARM_DESC(index, "Index value for Media Vision Jazz16 based soundcard.");
49module_param_array(id, charp, NULL, 0444);
50MODULE_PARM_DESC(id, "ID string for Media Vision Jazz16 based soundcard.");
51module_param_array(enable, bool, NULL, 0444);
52MODULE_PARM_DESC(enable, "Enable Media Vision Jazz16 based soundcard.");
53module_param_hw_array(port, long, ioport, NULL, 0444);
54MODULE_PARM_DESC(port, "Port # for jazz16 driver.");
55module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
56MODULE_PARM_DESC(mpu_port, "MPU-401 port # for jazz16 driver.");
57module_param_hw_array(irq, int, irq, NULL, 0444);
58MODULE_PARM_DESC(irq, "IRQ # for jazz16 driver.");
59module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
60MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for jazz16 driver.");
61module_param_hw_array(dma8, int, dma, NULL, 0444);
62MODULE_PARM_DESC(dma8, "DMA8 # for jazz16 driver.");
63module_param_hw_array(dma16, int, dma, NULL, 0444);
64MODULE_PARM_DESC(dma16, "DMA16 # for jazz16 driver.");
65
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
71
72struct snd_card_jazz16 {
73 struct snd_sb *chip;
74};
75
76static irqreturn_t jazz16_interrupt(int irq, void *chip)
77{
78 return snd_sb8dsp_interrupt(chip);
79}
80
81static int jazz16_configure_ports(unsigned long port,
82 unsigned long mpu_port, int idx)
83{
84 unsigned char val;
85
86 if (!request_region(0x201, 1, "jazz16 config")) {
87 snd_printk(KERN_ERR "config port region is already in use.\n");
88 return -EBUSY;
89 }
90 outb(SB_JAZZ16_WAKEUP - idx, 0x201);
91 udelay(100);
92 outb(SB_JAZZ16_SET_PORTS + idx, 0x201);
93 udelay(100);
94 val = port & 0x70;
95 val |= (mpu_port & 0x30) >> 4;
96 outb(val, 0x201);
97
98 release_region(0x201, 1);
99 return 0;
100}
101
102static int jazz16_detect_board(unsigned long port,
103 unsigned long mpu_port)
104{
105 int err;
106 int val;
107 struct snd_sb chip;
108
109 if (!request_region(port, 0x10, "jazz16")) {
110 snd_printk(KERN_ERR "I/O port region is already in use.\n");
111 return -EBUSY;
112 }
113 /* just to call snd_sbdsp_command/reset/get_byte() */
114 chip.port = port;
115
116 err = snd_sbdsp_reset(&chip);
117 if (err < 0)
118 for (val = 0; val < 4; val++) {
119 err = jazz16_configure_ports(port, mpu_port, val);
120 if (err < 0)
121 break;
122
123 err = snd_sbdsp_reset(&chip);
124 if (!err)
125 break;
126 }
127 if (err < 0) {
128 err = -ENODEV;
129 goto err_unmap;
130 }
131 if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_BRD_REV)) {
132 err = -EBUSY;
133 goto err_unmap;
134 }
135 val = snd_sbdsp_get_byte(&chip);
136 if (val >= 0x30)
137 snd_sbdsp_get_byte(&chip);
138
139 if ((val & 0xf0) != 0x10) {
140 err = -ENODEV;
141 goto err_unmap;
142 }
143 if (!snd_sbdsp_command(&chip, SB_DSP_GET_JAZZ_MODEL)) {
144 err = -EBUSY;
145 goto err_unmap;
146 }
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",
150 val, err);
151
152 err = 0;
153
154err_unmap:
155 release_region(port, 0x10);
156 return err;
157}
158
159static int jazz16_configure_board(struct snd_sb *chip, int mpu_irq)
160{
161 static const unsigned char jazz_irq_bits[] = { 0, 0, 2, 3, 0, 1, 0, 4,
162 0, 2, 5, 0, 0, 0, 0, 6 };
163 static const unsigned char jazz_dma_bits[] = { 0, 1, 0, 2, 0, 3, 0, 4 };
164
165 if (jazz_dma_bits[chip->dma8] == 0 ||
166 jazz_dma_bits[chip->dma16] == 0 ||
167 jazz_irq_bits[chip->irq] == 0)
168 return -EINVAL;
169
170 if (!snd_sbdsp_command(chip, SB_JAZZ16_SET_DMAINTR))
171 return -EBUSY;
172
173 if (!snd_sbdsp_command(chip,
174 jazz_dma_bits[chip->dma8] |
175 (jazz_dma_bits[chip->dma16] << 4)))
176 return -EBUSY;
177
178 if (!snd_sbdsp_command(chip,
179 jazz_irq_bits[chip->irq] |
180 (jazz_irq_bits[mpu_irq] << 4)))
181 return -EBUSY;
182
183 return 0;
184}
185
186static int snd_jazz16_match(struct device *devptr, unsigned int dev)
187{
188 if (!enable[dev])
189 return 0;
190 if (port[dev] == SNDRV_AUTO_PORT) {
191 snd_printk(KERN_ERR "please specify port\n");
192 return 0;
193 } else if (port[dev] == 0x200 || (port[dev] & ~0x270)) {
194 snd_printk(KERN_ERR "incorrect port specified\n");
195 return 0;
196 }
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");
200 return 0;
201 }
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");
205 return 0;
206 }
207 if (mpu_port[dev] != SNDRV_AUTO_PORT &&
208 (mpu_port[dev] & ~0x030) != 0x300) {
209 snd_printk(KERN_ERR "incorrect mpu_port specified\n");
210 return 0;
211 }
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");
216 return 0;
217 }
218 return 1;
219}
220
221static int snd_jazz16_probe(struct device *devptr, unsigned int dev)
222{
223 struct snd_card *card;
224 struct snd_card_jazz16 *jazz16;
225 struct snd_sb *chip;
226 struct snd_opl3 *opl3;
227 static const int possible_irqs[] = {2, 3, 5, 7, 9, 10, 15, -1};
228 static const int possible_dmas8[] = {1, 3, -1};
229 static const int possible_dmas16[] = {5, 7, -1};
230 int err, xirq, xdma8, xdma16, xmpu_port, xmpu_irq;
231
232 err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
233 sizeof(struct snd_card_jazz16), &card);
234 if (err < 0)
235 return err;
236
237 jazz16 = card->private_data;
238
239 xirq = irq[dev];
240 if (xirq == SNDRV_AUTO_IRQ) {
241 xirq = snd_legacy_find_free_irq(possible_irqs);
242 if (xirq < 0) {
243 snd_printk(KERN_ERR "unable to find a free IRQ\n");
244 err = -EBUSY;
245 goto err_free;
246 }
247 }
248 xdma8 = dma8[dev];
249 if (xdma8 == SNDRV_AUTO_DMA) {
250 xdma8 = snd_legacy_find_free_dma(possible_dmas8);
251 if (xdma8 < 0) {
252 snd_printk(KERN_ERR "unable to find a free DMA8\n");
253 err = -EBUSY;
254 goto err_free;
255 }
256 }
257 xdma16 = dma16[dev];
258 if (xdma16 == SNDRV_AUTO_DMA) {
259 xdma16 = snd_legacy_find_free_dma(possible_dmas16);
260 if (xdma16 < 0) {
261 snd_printk(KERN_ERR "unable to find a free DMA16\n");
262 err = -EBUSY;
263 goto err_free;
264 }
265 }
266
267 xmpu_port = mpu_port[dev];
268 if (xmpu_port == SNDRV_AUTO_PORT)
269 xmpu_port = 0;
270 err = jazz16_detect_board(port[dev], xmpu_port);
271 if (err < 0) {
272 printk(KERN_ERR "Media Vision Jazz16 board not detected\n");
273 goto err_free;
274 }
275 err = snd_sbdsp_create(card, port[dev], irq[dev],
276 jazz16_interrupt,
277 dma8[dev], dma16[dev],
278 SB_HW_JAZZ16,
279 &chip);
280 if (err < 0)
281 goto err_free;
282
283 xmpu_irq = mpu_irq[dev];
284 if (xmpu_irq == SNDRV_AUTO_IRQ || mpu_port[dev] == SNDRV_AUTO_PORT)
285 xmpu_irq = 0;
286 err = jazz16_configure_board(chip, xmpu_irq);
287 if (err < 0) {
288 printk(KERN_ERR "Media Vision Jazz16 configuration failed\n");
289 goto err_free;
290 }
291
292 jazz16->chip = chip;
293
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);
299
300 err = snd_sb8dsp_pcm(chip, 0);
301 if (err < 0)
302 goto err_free;
303 err = snd_sbmixer_new(chip);
304 if (err < 0)
305 goto err_free;
306
307 err = snd_opl3_create(card, chip->port, chip->port + 2,
308 OPL3_HW_AUTO, 1, &opl3);
309 if (err < 0)
310 snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
311 chip->port, chip->port + 2);
312 else {
313 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
314 if (err < 0)
315 goto err_free;
316 }
317 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
318 if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
319 mpu_irq[dev] = -1;
320
321 if (snd_mpu401_uart_new(card, 0,
322 MPU401_HW_MPU401,
323 mpu_port[dev], 0,
324 mpu_irq[dev],
325 NULL) < 0)
326 snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n",
327 mpu_port[dev]);
328 }
329
330 err = snd_card_register(card);
331 if (err < 0)
332 goto err_free;
333
334 dev_set_drvdata(devptr, card);
335 return 0;
336
337err_free:
338 snd_card_free(card);
339 return err;
340}
341
342static int snd_jazz16_remove(struct device *devptr, unsigned int dev)
343{
344 struct snd_card *card = dev_get_drvdata(devptr);
345
346 snd_card_free(card);
347 return 0;
348}
349
350#ifdef CONFIG_PM
351static int snd_jazz16_suspend(struct device *pdev, unsigned int n,
352 pm_message_t state)
353{
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;
357
358 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
359 snd_sbmixer_suspend(chip);
360 return 0;
361}
362
363static int snd_jazz16_resume(struct device *pdev, unsigned int n)
364{
365 struct snd_card *card = dev_get_drvdata(pdev);
366 struct snd_card_jazz16 *acard = card->private_data;
367 struct snd_sb *chip = acard->chip;
368
369 snd_sbdsp_reset(chip);
370 snd_sbmixer_resume(chip);
371 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
372 return 0;
373}
374#endif
375
376static struct isa_driver snd_jazz16_driver = {
377 .match = snd_jazz16_match,
378 .probe = snd_jazz16_probe,
379 .remove = snd_jazz16_remove,
380#ifdef CONFIG_PM
381 .suspend = snd_jazz16_suspend,
382 .resume = snd_jazz16_resume,
383#endif
384 .driver = {
385 .name = "jazz16"
386 },
387};
388
389module_isa_driver(snd_jazz16_driver, SNDRV_CARDS);