blob: c2baf4cfb958dcef1ab44140268a9d77977eab6d [file] [log] [blame]
Martin Langer1841f612006-03-27 12:41:01 +02001/*
2 * ALSA soundcard driver for Miro miroSOUND PCM1 pro
3 * miroSOUND PCM12
4 * miroSOUND PCM20 Radio
5 *
6 * Copyright (C) 2004-2005 Martin Langer <martin-langer@gmx.de>
7 *
8 * Based on OSS ACI and ALSA OPTi9xx drivers
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <sound/driver.h>
26#include <linux/init.h>
27#include <linux/err.h>
Takashi Iwai5e24c1c2007-02-22 12:50:54 +010028#include <linux/isa.h>
Martin Langer1841f612006-03-27 12:41:01 +020029#include <linux/delay.h>
30#include <linux/slab.h>
31#include <linux/ioport.h>
32#include <linux/moduleparam.h>
33#include <asm/io.h>
34#include <asm/dma.h>
35#include <sound/core.h>
36#include <sound/cs4231.h>
37#include <sound/mpu401.h>
38#include <sound/opl4.h>
39#include <sound/control.h>
40#include <sound/info.h>
41#define SNDRV_LEGACY_FIND_FREE_IRQ
42#define SNDRV_LEGACY_FIND_FREE_DMA
43#include <sound/initval.h>
44#include "miro.h"
45
46MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>");
47MODULE_LICENSE("GPL");
48MODULE_DESCRIPTION("Miro miroSOUND PCM1 pro, PCM12, PCM20 Radio");
49MODULE_SUPPORTED_DEVICE("{{Miro,miroSOUND PCM1 pro}, "
50 "{Miro,miroSOUND PCM12}, "
51 "{Miro,miroSOUND PCM20 Radio}}");
52
53static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
54static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
55static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
56static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
57static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
58static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
59static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
60static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
61static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
62static int wss;
63static int ide;
64
65module_param(index, int, 0444);
66MODULE_PARM_DESC(index, "Index value for miro soundcard.");
67module_param(id, charp, 0444);
68MODULE_PARM_DESC(id, "ID string for miro soundcard.");
69module_param(port, long, 0444);
70MODULE_PARM_DESC(port, "WSS port # for miro driver.");
71module_param(mpu_port, long, 0444);
72MODULE_PARM_DESC(mpu_port, "MPU-401 port # for miro driver.");
73module_param(fm_port, long, 0444);
74MODULE_PARM_DESC(fm_port, "FM Port # for miro driver.");
75module_param(irq, int, 0444);
76MODULE_PARM_DESC(irq, "WSS irq # for miro driver.");
77module_param(mpu_irq, int, 0444);
78MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for miro driver.");
79module_param(dma1, int, 0444);
80MODULE_PARM_DESC(dma1, "1st dma # for miro driver.");
81module_param(dma2, int, 0444);
82MODULE_PARM_DESC(dma2, "2nd dma # for miro driver.");
83module_param(wss, int, 0444);
84MODULE_PARM_DESC(wss, "wss mode");
85module_param(ide, int, 0444);
86MODULE_PARM_DESC(ide, "enable ide port");
87
88#define OPTi9XX_HW_DETECT 0
89#define OPTi9XX_HW_82C928 1
90#define OPTi9XX_HW_82C929 2
91#define OPTi9XX_HW_82C924 3
92#define OPTi9XX_HW_82C925 4
93#define OPTi9XX_HW_82C930 5
94#define OPTi9XX_HW_82C931 6
95#define OPTi9XX_HW_82C933 7
96#define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
97
98#define OPTi9XX_MC_REG(n) n
99
100
101struct snd_miro {
102 unsigned short hardware;
103 unsigned char password;
104 char name[7];
105
106 struct resource *res_mc_base;
107 struct resource *res_aci_port;
108
109 unsigned long mc_base;
110 unsigned long mc_base_size;
111 unsigned long pwd_reg;
112
113 spinlock_t lock;
114 struct snd_card *card;
115 struct snd_pcm *pcm;
116
117 long wss_base;
118 int irq;
119 int dma1;
120 int dma2;
121
122 long fm_port;
123
124 long mpu_port;
125 int mpu_irq;
126
127 unsigned long aci_port;
128 int aci_vendor;
129 int aci_product;
130 int aci_version;
131 int aci_amp;
132 int aci_preamp;
133 int aci_solomode;
134
135 struct mutex aci_mutex;
136};
137
138static void snd_miro_proc_init(struct snd_miro * miro);
139
Martin Langer1841f612006-03-27 12:41:01 +0200140static char * snd_opti9xx_names[] = {
141 "unkown",
142 "82C928", "82C929",
143 "82C924", "82C925",
144 "82C930", "82C931", "82C933"
145};
146
147/*
148 * ACI control
149 */
150
151static int aci_busy_wait(struct snd_miro * miro)
152{
153 long timeout;
154 unsigned char byte;
155
156 for (timeout = 1; timeout <= ACI_MINTIME+30; timeout++) {
157 if (((byte=inb(miro->aci_port + ACI_REG_BUSY)) & 1) == 0) {
158 if (timeout >= ACI_MINTIME)
159 snd_printd("aci ready in round %ld.\n",
160 timeout-ACI_MINTIME);
161 return byte;
162 }
163 if (timeout >= ACI_MINTIME) {
164 long out=10*HZ;
165 switch (timeout-ACI_MINTIME) {
166 case 0 ... 9:
167 out /= 10;
168 case 10 ... 19:
169 out /= 10;
170 case 20 ... 30:
171 out /= 10;
172 default:
173 set_current_state(TASK_UNINTERRUPTIBLE);
174 schedule_timeout(out);
175 break;
176 }
177 }
178 }
179 snd_printk(KERN_ERR "aci_busy_wait() time out\n");
180 return -EBUSY;
181}
182
183static inline int aci_write(struct snd_miro * miro, unsigned char byte)
184{
185 if (aci_busy_wait(miro) >= 0) {
186 outb(byte, miro->aci_port + ACI_REG_COMMAND);
187 return 0;
188 } else {
189 snd_printk(KERN_ERR "aci busy, aci_write(0x%x) stopped.\n", byte);
190 return -EBUSY;
191 }
192}
193
194static inline int aci_read(struct snd_miro * miro)
195{
196 unsigned char byte;
197
198 if (aci_busy_wait(miro) >= 0) {
199 byte=inb(miro->aci_port + ACI_REG_STATUS);
200 return byte;
201 } else {
202 snd_printk(KERN_ERR "aci busy, aci_read() stopped.\n");
203 return -EBUSY;
204 }
205}
206
207static int aci_cmd(struct snd_miro * miro, int write1, int write2, int write3)
208{
209 int write[] = {write1, write2, write3};
210 int value, i;
211
212 if (mutex_lock_interruptible(&miro->aci_mutex))
213 return -EINTR;
214
215 for (i=0; i<3; i++) {
216 if (write[i]< 0 || write[i] > 255)
217 break;
218 else {
219 value = aci_write(miro, write[i]);
220 if (value < 0)
221 goto out;
222 }
223 }
224
225 value = aci_read(miro);
226
227out: mutex_unlock(&miro->aci_mutex);
228 return value;
229}
230
231static int aci_getvalue(struct snd_miro * miro, unsigned char index)
232{
233 return aci_cmd(miro, ACI_STATUS, index, -1);
234}
235
236static int aci_setvalue(struct snd_miro * miro, unsigned char index, int value)
237{
238 return aci_cmd(miro, index, value, -1);
239}
240
241/*
242 * MIXER part
243 */
244
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200245#define snd_miro_info_capture snd_ctl_boolean_mono_info
Martin Langer1841f612006-03-27 12:41:01 +0200246
247static int snd_miro_get_capture(struct snd_kcontrol *kcontrol,
248 struct snd_ctl_elem_value *ucontrol)
249{
250 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
251 int value;
252
253 if ((value = aci_getvalue(miro, ACI_S_GENERAL)) < 0) {
254 snd_printk(KERN_ERR "snd_miro_get_capture() failed: %d\n", value);
255 return value;
256 }
257
258 ucontrol->value.integer.value[0] = value & 0x20;
259
260 return 0;
261}
262
263static int snd_miro_put_capture(struct snd_kcontrol *kcontrol,
264 struct snd_ctl_elem_value *ucontrol)
265{
266 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
267 int change, value, error;
268
269 value = !(ucontrol->value.integer.value[0]);
270
271 if ((error = aci_setvalue(miro, ACI_SET_SOLOMODE, value)) < 0) {
272 snd_printk(KERN_ERR "snd_miro_put_capture() failed: %d\n", error);
273 return error;
274 }
275
276 change = (value != miro->aci_solomode);
277 miro->aci_solomode = value;
278
279 return change;
280}
281
282static int snd_miro_info_preamp(struct snd_kcontrol *kcontrol,
283 struct snd_ctl_elem_info *uinfo)
284{
285 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
286 uinfo->count = 1;
287 uinfo->value.integer.min = 0;
288 uinfo->value.integer.max = 3;
289
290 return 0;
291}
292
293static int snd_miro_get_preamp(struct snd_kcontrol *kcontrol,
294 struct snd_ctl_elem_value *ucontrol)
295{
296 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
297 int value;
298
299 if (miro->aci_version <= 176) {
300
301 /*
302 OSS says it's not readable with versions < 176.
303 But it doesn't work on my card,
304 which is a PCM12 with aci_version = 176.
305 */
306
307 ucontrol->value.integer.value[0] = miro->aci_preamp;
308 return 0;
309 }
310
311 if ((value = aci_getvalue(miro, ACI_GET_PREAMP)) < 0) {
312 snd_printk(KERN_ERR "snd_miro_get_preamp() failed: %d\n", value);
313 return value;
314 }
315
316 ucontrol->value.integer.value[0] = value;
317
318 return 0;
319}
320
321static int snd_miro_put_preamp(struct snd_kcontrol *kcontrol,
322 struct snd_ctl_elem_value *ucontrol)
323{
324 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
325 int error, value, change;
326
327 value = ucontrol->value.integer.value[0];
328
329 if ((error = aci_setvalue(miro, ACI_SET_PREAMP, value)) < 0) {
330 snd_printk(KERN_ERR "snd_miro_put_preamp() failed: %d\n", error);
331 return error;
332 }
333
334 change = (value != miro->aci_preamp);
335 miro->aci_preamp = value;
336
337 return change;
338}
339
Takashi Iwaia5ce8892007-07-23 15:42:26 +0200340#define snd_miro_info_amp snd_ctl_boolean_mono_info
Martin Langer1841f612006-03-27 12:41:01 +0200341
342static int snd_miro_get_amp(struct snd_kcontrol *kcontrol,
343 struct snd_ctl_elem_value *ucontrol)
344{
345 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
346 ucontrol->value.integer.value[0] = miro->aci_amp;
347
348 return 0;
349}
350
351static int snd_miro_put_amp(struct snd_kcontrol *kcontrol,
352 struct snd_ctl_elem_value *ucontrol)
353{
354 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
355 int error, value, change;
356
357 value = ucontrol->value.integer.value[0];
358
359 if ((error = aci_setvalue(miro, ACI_SET_POWERAMP, value)) < 0) {
360 snd_printk(KERN_ERR "snd_miro_put_amp() to %d failed: %d\n", value, error);
361 return error;
362 }
363
364 change = (value != miro->aci_amp);
365 miro->aci_amp = value;
366
367 return change;
368}
369
370#define MIRO_DOUBLE(ctl_name, ctl_index, get_right_reg, set_right_reg) \
371{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
372 .name = ctl_name, \
373 .index = ctl_index, \
374 .info = snd_miro_info_double, \
375 .get = snd_miro_get_double, \
376 .put = snd_miro_put_double, \
377 .private_value = get_right_reg | (set_right_reg << 8) \
378}
379
380static int snd_miro_info_double(struct snd_kcontrol *kcontrol,
381 struct snd_ctl_elem_info *uinfo)
382{
383 int reg = kcontrol->private_value & 0xff;
384
385 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
386 uinfo->count = 2;
387
388 if ((reg >= ACI_GET_EQ1) && (reg <= ACI_GET_EQ7)) {
389
390 /* equalizer elements */
391
392 uinfo->value.integer.min = - 0x7f;
393 uinfo->value.integer.max = 0x7f;
394 } else {
395
396 /* non-equalizer elements */
397
398 uinfo->value.integer.min = 0;
399 uinfo->value.integer.max = 0x20;
400 }
401
402 return 0;
403}
404
405static int snd_miro_get_double(struct snd_kcontrol *kcontrol,
406 struct snd_ctl_elem_value *uinfo)
407{
408 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
409 int left_val, right_val;
410
411 int right_reg = kcontrol->private_value & 0xff;
412 int left_reg = right_reg + 1;
413
414 if ((right_val = aci_getvalue(miro, right_reg)) < 0) {
415 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", right_reg, right_val);
416 return right_val;
417 }
418
419 if ((left_val = aci_getvalue(miro, left_reg)) < 0) {
420 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", left_reg, left_val);
421 return left_val;
422 }
423
424 if ((right_reg >= ACI_GET_EQ1) && (right_reg <= ACI_GET_EQ7)) {
425
426 /* equalizer elements */
427
428 if (left_val < 0x80) {
429 uinfo->value.integer.value[0] = left_val;
430 } else {
431 uinfo->value.integer.value[0] = 0x80 - left_val;
432 }
433
434 if (right_val < 0x80) {
435 uinfo->value.integer.value[1] = right_val;
436 } else {
437 uinfo->value.integer.value[1] = 0x80 - right_val;
438 }
439
440 } else {
441
442 /* non-equalizer elements */
443
444 uinfo->value.integer.value[0] = 0x20 - left_val;
445 uinfo->value.integer.value[1] = 0x20 - right_val;
446 }
447
448 return 0;
449}
450
451static int snd_miro_put_double(struct snd_kcontrol *kcontrol,
452 struct snd_ctl_elem_value *ucontrol)
453{
454 struct snd_miro *miro = snd_kcontrol_chip(kcontrol);
455 int left, right, left_old, right_old;
456 int setreg_left, setreg_right, getreg_left, getreg_right;
457 int change, error;
458
459 left = ucontrol->value.integer.value[0];
460 right = ucontrol->value.integer.value[1];
461
462 setreg_right = (kcontrol->private_value >> 8) & 0xff;
463 if (setreg_right == ACI_SET_MASTER) {
464 setreg_left = setreg_right + 1;
465 } else {
466 setreg_left = setreg_right + 8;
467 }
468
469 getreg_right = kcontrol->private_value & 0xff;
470 getreg_left = getreg_right + 1;
471
472 if ((left_old = aci_getvalue(miro, getreg_left)) < 0) {
473 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_left, left_old);
474 return left_old;
475 }
476
477 if ((right_old = aci_getvalue(miro, getreg_right)) < 0) {
478 snd_printk(KERN_ERR "aci_getvalue(%d) failed: %d\n", getreg_right, right_old);
479 return right_old;
480 }
481
482 if ((getreg_right >= ACI_GET_EQ1) && (getreg_right <= ACI_GET_EQ7)) {
483
484 /* equalizer elements */
485
Takashi Iwai3b892462007-11-15 16:17:24 +0100486 if (left < -0x7f || left > 0x7f ||
487 right < -0x7f || right > 0x7f)
488 return -EINVAL;
489
Martin Langer1841f612006-03-27 12:41:01 +0200490 if (left_old > 0x80)
491 left_old = 0x80 - left_old;
492 if (right_old > 0x80)
493 right_old = 0x80 - right_old;
494
495 if (left >= 0) {
496 if ((error = aci_setvalue(miro, setreg_left, left)) < 0) {
497 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
498 left, error);
499 return error;
500 }
501 } else {
502 if ((error = aci_setvalue(miro, setreg_left, 0x80 - left)) < 0) {
503 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
504 0x80 - left, error);
505 return error;
506 }
507 }
508
509 if (right >= 0) {
510 if ((error = aci_setvalue(miro, setreg_right, right)) < 0) {
511 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
512 right, error);
513 return error;
514 }
515 } else {
516 if ((error = aci_setvalue(miro, setreg_right, 0x80 - right)) < 0) {
517 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
518 0x80 - right, error);
519 return error;
520 }
521 }
522
523 } else {
524
525 /* non-equalizer elements */
526
Takashi Iwai3b892462007-11-15 16:17:24 +0100527 if (left < 0 || left > 0x20 ||
528 right < 0 || right > 0x20)
529 return -EINVAL;
530
Martin Langer1841f612006-03-27 12:41:01 +0200531 left_old = 0x20 - left_old;
532 right_old = 0x20 - right_old;
533
534 if ((error = aci_setvalue(miro, setreg_left, 0x20 - left)) < 0) {
535 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
536 0x20 - left, error);
537 return error;
538 }
539 if ((error = aci_setvalue(miro, setreg_right, 0x20 - right)) < 0) {
540 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
541 0x20 - right, error);
542 return error;
543 }
544 }
545
546 change = (left != left_old) || (right != right_old);
547
548 return change;
549}
550
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100551static struct snd_kcontrol_new snd_miro_controls[] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200552MIRO_DOUBLE("Master Playback Volume", 0, ACI_GET_MASTER, ACI_SET_MASTER),
553MIRO_DOUBLE("Mic Playback Volume", 1, ACI_GET_MIC, ACI_SET_MIC),
554MIRO_DOUBLE("Line Playback Volume", 1, ACI_GET_LINE, ACI_SET_LINE),
555MIRO_DOUBLE("CD Playback Volume", 0, ACI_GET_CD, ACI_SET_CD),
556MIRO_DOUBLE("Synth Playback Volume", 0, ACI_GET_SYNTH, ACI_SET_SYNTH),
557MIRO_DOUBLE("PCM Playback Volume", 1, ACI_GET_PCM, ACI_SET_PCM),
558MIRO_DOUBLE("Aux Playback Volume", 2, ACI_GET_LINE2, ACI_SET_LINE2),
559};
560
561/* Equalizer with seven bands (only PCM20)
562 from -12dB up to +12dB on each band */
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100563static struct snd_kcontrol_new snd_miro_eq_controls[] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200564MIRO_DOUBLE("Tone Control - 28 Hz", 0, ACI_GET_EQ1, ACI_SET_EQ1),
565MIRO_DOUBLE("Tone Control - 160 Hz", 0, ACI_GET_EQ2, ACI_SET_EQ2),
566MIRO_DOUBLE("Tone Control - 400 Hz", 0, ACI_GET_EQ3, ACI_SET_EQ3),
567MIRO_DOUBLE("Tone Control - 1 kHz", 0, ACI_GET_EQ4, ACI_SET_EQ4),
568MIRO_DOUBLE("Tone Control - 2.5 kHz", 0, ACI_GET_EQ5, ACI_SET_EQ5),
569MIRO_DOUBLE("Tone Control - 6.3 kHz", 0, ACI_GET_EQ6, ACI_SET_EQ6),
570MIRO_DOUBLE("Tone Control - 16 kHz", 0, ACI_GET_EQ7, ACI_SET_EQ7),
571};
572
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100573static struct snd_kcontrol_new snd_miro_radio_control[] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200574MIRO_DOUBLE("Radio Playback Volume", 0, ACI_GET_LINE1, ACI_SET_LINE1),
575};
576
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100577static struct snd_kcontrol_new snd_miro_line_control[] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200578MIRO_DOUBLE("Line Playback Volume", 2, ACI_GET_LINE1, ACI_SET_LINE1),
579};
580
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100581static struct snd_kcontrol_new snd_miro_preamp_control[] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200582{
583 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
584 .name = "Mic Boost",
585 .index = 1,
586 .info = snd_miro_info_preamp,
587 .get = snd_miro_get_preamp,
588 .put = snd_miro_put_preamp,
589}};
590
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100591static struct snd_kcontrol_new snd_miro_amp_control[] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200592{
593 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
594 .name = "Line Boost",
595 .index = 0,
596 .info = snd_miro_info_amp,
597 .get = snd_miro_get_amp,
598 .put = snd_miro_put_amp,
599}};
600
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100601static struct snd_kcontrol_new snd_miro_capture_control[] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200602{
603 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
604 .name = "PCM Capture Switch",
605 .index = 0,
606 .info = snd_miro_info_capture,
607 .get = snd_miro_get_capture,
608 .put = snd_miro_put_capture,
609}};
610
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100611static unsigned char aci_init_values[][2] __devinitdata = {
Martin Langer1841f612006-03-27 12:41:01 +0200612 { ACI_SET_MUTE, 0x00 },
613 { ACI_SET_POWERAMP, 0x00 },
614 { ACI_SET_PREAMP, 0x00 },
615 { ACI_SET_SOLOMODE, 0x00 },
616 { ACI_SET_MIC + 0, 0x20 },
617 { ACI_SET_MIC + 8, 0x20 },
618 { ACI_SET_LINE + 0, 0x20 },
619 { ACI_SET_LINE + 8, 0x20 },
620 { ACI_SET_CD + 0, 0x20 },
621 { ACI_SET_CD + 8, 0x20 },
622 { ACI_SET_PCM + 0, 0x20 },
623 { ACI_SET_PCM + 8, 0x20 },
624 { ACI_SET_LINE1 + 0, 0x20 },
625 { ACI_SET_LINE1 + 8, 0x20 },
626 { ACI_SET_LINE2 + 0, 0x20 },
627 { ACI_SET_LINE2 + 8, 0x20 },
628 { ACI_SET_SYNTH + 0, 0x20 },
629 { ACI_SET_SYNTH + 8, 0x20 },
630 { ACI_SET_MASTER + 0, 0x20 },
631 { ACI_SET_MASTER + 1, 0x20 },
632};
633
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100634static int __devinit snd_set_aci_init_values(struct snd_miro *miro)
Martin Langer1841f612006-03-27 12:41:01 +0200635{
636 int idx, error;
637
638 /* enable WSS on PCM1 */
639
640 if ((miro->aci_product == 'A') && wss) {
641 if ((error = aci_setvalue(miro, ACI_SET_WSS, wss)) < 0) {
642 snd_printk(KERN_ERR "enabling WSS mode failed\n");
643 return error;
644 }
645 }
646
647 /* enable IDE port */
648
649 if (ide) {
650 if ((error = aci_setvalue(miro, ACI_SET_IDE, ide)) < 0) {
651 snd_printk(KERN_ERR "enabling IDE port failed\n");
652 return error;
653 }
654 }
655
656 /* set common aci values */
657
658 for (idx = 0; idx < ARRAY_SIZE(aci_init_values); idx++)
659 if ((error = aci_setvalue(miro, aci_init_values[idx][0],
660 aci_init_values[idx][1])) < 0) {
661 snd_printk(KERN_ERR "aci_setvalue(%d) failed: %d\n",
662 aci_init_values[idx][0], error);
663 return error;
664 }
665
666 miro->aci_amp = 0;
667 miro->aci_preamp = 0;
668 miro->aci_solomode = 1;
669
670 return 0;
671}
672
673static int snd_miro_mixer(struct snd_miro *miro)
674{
675 struct snd_card *card;
676 unsigned int idx;
677 int err;
678
679 snd_assert(miro != NULL && miro->card != NULL, return -EINVAL);
680
681 card = miro->card;
682
683 switch (miro->hardware) {
684 case OPTi9XX_HW_82C924:
685 strcpy(card->mixername, "ACI & OPTi924");
686 break;
687 case OPTi9XX_HW_82C929:
688 strcpy(card->mixername, "ACI & OPTi929");
689 break;
690 default:
691 snd_BUG();
692 break;
693 }
694
695 for (idx = 0; idx < ARRAY_SIZE(snd_miro_controls); idx++) {
696 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_controls[idx], miro))) < 0)
697 return err;
698 }
699
700 if ((miro->aci_product == 'A') || (miro->aci_product == 'B')) {
701 /* PCM1/PCM12 with power-amp and Line 2 */
702 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_line_control[0], miro))) < 0)
703 return err;
704 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_amp_control[0], miro))) < 0)
705 return err;
706 }
707
708 if ((miro->aci_product == 'B') || (miro->aci_product == 'C')) {
709 /* PCM12/PCM20 with mic-preamp */
710 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_preamp_control[0], miro))) < 0)
711 return err;
712 if (miro->aci_version >= 176)
713 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_capture_control[0], miro))) < 0)
714 return err;
715 }
716
717 if (miro->aci_product == 'C') {
718 /* PCM20 with radio and 7 band equalizer */
719 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_radio_control[0], miro))) < 0)
720 return err;
721 for (idx = 0; idx < ARRAY_SIZE(snd_miro_eq_controls); idx++) {
722 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_miro_eq_controls[idx], miro))) < 0)
723 return err;
724 }
725 }
726
727 return 0;
728}
729
730static long snd_legacy_find_free_ioport(long *port_table, long size)
731{
732 while (*port_table != -1) {
733 struct resource *res;
734 if ((res = request_region(*port_table, size,
735 "ALSA test")) != NULL) {
Takashi Iwai10d150e2006-03-27 13:42:39 +0200736 release_and_free_resource(res);
Martin Langer1841f612006-03-27 12:41:01 +0200737 return *port_table;
738 }
739 port_table++;
740 }
741 return -1;
742}
743
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100744static int __devinit snd_miro_init(struct snd_miro *chip,
745 unsigned short hardware)
Martin Langer1841f612006-03-27 12:41:01 +0200746{
747 static int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
748
749 chip->hardware = hardware;
750 strcpy(chip->name, snd_opti9xx_names[hardware]);
751
752 chip->mc_base_size = opti9xx_mc_size[hardware];
753
754 spin_lock_init(&chip->lock);
755
756 chip->wss_base = -1;
757 chip->irq = -1;
758 chip->dma1 = -1;
759 chip->dma2 = -1;
760 chip->fm_port = -1;
761 chip->mpu_port = -1;
762 chip->mpu_irq = -1;
763
764 switch (hardware) {
765 case OPTi9XX_HW_82C929:
766 chip->mc_base = 0xf8c;
767 chip->password = 0xe3;
768 chip->pwd_reg = 3;
769 break;
770
771 case OPTi9XX_HW_82C924:
772 chip->mc_base = 0xf8c;
773 chip->password = 0xe5;
774 chip->pwd_reg = 3;
775 break;
776
777 default:
778 snd_printk(KERN_ERR "sorry, no support for %d\n", hardware);
779 return -ENODEV;
780 }
781
782 return 0;
783}
784
785static unsigned char snd_miro_read(struct snd_miro *chip,
786 unsigned char reg)
787{
788 unsigned long flags;
789 unsigned char retval = 0xff;
790
791 spin_lock_irqsave(&chip->lock, flags);
792 outb(chip->password, chip->mc_base + chip->pwd_reg);
793
794 switch (chip->hardware) {
795 case OPTi9XX_HW_82C924:
796 if (reg > 7) {
797 outb(reg, chip->mc_base + 8);
798 outb(chip->password, chip->mc_base + chip->pwd_reg);
799 retval = inb(chip->mc_base + 9);
800 break;
801 }
802
803 case OPTi9XX_HW_82C929:
804 retval = inb(chip->mc_base + reg);
805 break;
806
807 default:
808 snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
809 }
810
811 spin_unlock_irqrestore(&chip->lock, flags);
812 return retval;
813}
814
815static void snd_miro_write(struct snd_miro *chip, unsigned char reg,
816 unsigned char value)
817{
818 unsigned long flags;
819
820 spin_lock_irqsave(&chip->lock, flags);
821 outb(chip->password, chip->mc_base + chip->pwd_reg);
822
823 switch (chip->hardware) {
824 case OPTi9XX_HW_82C924:
825 if (reg > 7) {
826 outb(reg, chip->mc_base + 8);
827 outb(chip->password, chip->mc_base + chip->pwd_reg);
828 outb(value, chip->mc_base + 9);
829 break;
830 }
831
832 case OPTi9XX_HW_82C929:
833 outb(value, chip->mc_base + reg);
834 break;
835
836 default:
837 snd_printk(KERN_ERR "sorry, no support for %d\n", chip->hardware);
838 }
839
840 spin_unlock_irqrestore(&chip->lock, flags);
841}
842
843
844#define snd_miro_write_mask(chip, reg, value, mask) \
845 snd_miro_write(chip, reg, \
846 (snd_miro_read(chip, reg) & ~(mask)) | ((value) & (mask)))
847
848/*
849 * Proc Interface
850 */
851
852static void snd_miro_proc_read(struct snd_info_entry * entry,
853 struct snd_info_buffer *buffer)
854{
855 struct snd_miro *miro = (struct snd_miro *) entry->private_data;
856 char* model = "unknown";
857
858 /* miroSOUND PCM1 pro, early PCM12 */
859
860 if ((miro->hardware == OPTi9XX_HW_82C929) &&
861 (miro->aci_vendor == 'm') &&
862 (miro->aci_product == 'A')) {
863 switch(miro->aci_version) {
864 case 3:
865 model = "miroSOUND PCM1 pro";
866 break;
867 default:
868 model = "miroSOUND PCM1 pro / (early) PCM12";
869 break;
870 }
871 }
872
873 /* miroSOUND PCM12, PCM12 (Rev. E), PCM12 pnp */
874
875 if ((miro->hardware == OPTi9XX_HW_82C924) &&
876 (miro->aci_vendor == 'm') &&
877 (miro->aci_product == 'B')) {
878 switch(miro->aci_version) {
879 case 4:
880 model = "miroSOUND PCM12";
881 break;
882 case 176:
883 model = "miroSOUND PCM12 (Rev. E)";
884 break;
885 default:
886 model = "miroSOUND PCM12 / PCM12 pnp";
887 break;
888 }
889 }
890
891 /* miroSOUND PCM20 radio */
892
893 if ((miro->hardware == OPTi9XX_HW_82C924) &&
894 (miro->aci_vendor == 'm') &&
895 (miro->aci_product == 'C')) {
896 switch(miro->aci_version) {
897 case 7:
898 model = "miroSOUND PCM20 radio (Rev. E)";
899 break;
900 default:
901 model = "miroSOUND PCM20 radio";
902 break;
903 }
904 }
905
906 snd_iprintf(buffer, "\nGeneral information:\n");
907 snd_iprintf(buffer, " model : %s\n", model);
908 snd_iprintf(buffer, " opti : %s\n", miro->name);
909 snd_iprintf(buffer, " codec : %s\n", miro->pcm->name);
910 snd_iprintf(buffer, " port : 0x%lx\n", miro->wss_base);
911 snd_iprintf(buffer, " irq : %d\n", miro->irq);
912 snd_iprintf(buffer, " dma : %d,%d\n\n", miro->dma1, miro->dma2);
913
914 snd_iprintf(buffer, "MPU-401:\n");
915 snd_iprintf(buffer, " port : 0x%lx\n", miro->mpu_port);
916 snd_iprintf(buffer, " irq : %d\n\n", miro->mpu_irq);
917
918 snd_iprintf(buffer, "ACI information:\n");
919 snd_iprintf(buffer, " vendor : ");
920 switch(miro->aci_vendor) {
921 case 'm':
922 snd_iprintf(buffer, "Miro\n");
923 break;
924 default:
925 snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_vendor);
926 break;
927 }
928
929 snd_iprintf(buffer, " product : ");
930 switch(miro->aci_product) {
931 case 'A':
932 snd_iprintf(buffer, "miroSOUND PCM1 pro / (early) PCM12\n");
933 break;
934 case 'B':
935 snd_iprintf(buffer, "miroSOUND PCM12\n");
936 break;
937 case 'C':
938 snd_iprintf(buffer, "miroSOUND PCM20 radio\n");
939 break;
940 default:
941 snd_iprintf(buffer, "unknown (0x%x)\n", miro->aci_product);
942 break;
943 }
944
945 snd_iprintf(buffer, " firmware: %d (0x%x)\n",
946 miro->aci_version, miro->aci_version);
947 snd_iprintf(buffer, " port : 0x%lx-0x%lx\n",
948 miro->aci_port, miro->aci_port+2);
949 snd_iprintf(buffer, " wss : 0x%x\n", wss);
950 snd_iprintf(buffer, " ide : 0x%x\n", ide);
951 snd_iprintf(buffer, " solomode: 0x%x\n", miro->aci_solomode);
952 snd_iprintf(buffer, " amp : 0x%x\n", miro->aci_amp);
953 snd_iprintf(buffer, " preamp : 0x%x\n", miro->aci_preamp);
954}
955
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100956static void __devinit snd_miro_proc_init(struct snd_miro * miro)
Martin Langer1841f612006-03-27 12:41:01 +0200957{
958 struct snd_info_entry *entry;
959
960 if (! snd_card_proc_new(miro->card, "miro", &entry))
Takashi Iwaibf850202006-04-28 15:13:41 +0200961 snd_info_set_text_ops(entry, miro, snd_miro_proc_read);
Martin Langer1841f612006-03-27 12:41:01 +0200962}
963
964/*
965 * Init
966 */
967
Takashi Iwai5e24c1c2007-02-22 12:50:54 +0100968static int __devinit snd_miro_configure(struct snd_miro *chip)
Martin Langer1841f612006-03-27 12:41:01 +0200969{
970 unsigned char wss_base_bits;
971 unsigned char irq_bits;
972 unsigned char dma_bits;
973 unsigned char mpu_port_bits = 0;
974 unsigned char mpu_irq_bits;
975 unsigned long flags;
976
977 switch (chip->hardware) {
978 case OPTi9XX_HW_82C924:
979 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
980 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
981 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
982 snd_miro_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
983 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
984 break;
985 case OPTi9XX_HW_82C929:
986 /* untested init commands for OPTi929 */
987 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
988 snd_miro_write_mask(chip, OPTi9XX_MC_REG(2), 0x20, 0x20); /* OPL4 */
989 snd_miro_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
990 snd_miro_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
991 break;
992 default:
993 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
994 return -EINVAL;
995 }
996
997 switch (chip->wss_base) {
998 case 0x530:
999 wss_base_bits = 0x00;
1000 break;
1001 case 0x604:
1002 wss_base_bits = 0x03;
1003 break;
1004 case 0xe80:
1005 wss_base_bits = 0x01;
1006 break;
1007 case 0xf40:
1008 wss_base_bits = 0x02;
1009 break;
1010 default:
1011 snd_printk(KERN_ERR "WSS port 0x%lx not valid\n", chip->wss_base);
1012 goto __skip_base;
1013 }
1014 snd_miro_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
1015
1016__skip_base:
1017 switch (chip->irq) {
1018 case 5:
1019 irq_bits = 0x05;
1020 break;
1021 case 7:
1022 irq_bits = 0x01;
1023 break;
1024 case 9:
1025 irq_bits = 0x02;
1026 break;
1027 case 10:
1028 irq_bits = 0x03;
1029 break;
1030 case 11:
1031 irq_bits = 0x04;
1032 break;
1033 default:
1034 snd_printk(KERN_ERR "WSS irq # %d not valid\n", chip->irq);
1035 goto __skip_resources;
1036 }
1037
1038 switch (chip->dma1) {
1039 case 0:
1040 dma_bits = 0x01;
1041 break;
1042 case 1:
1043 dma_bits = 0x02;
1044 break;
1045 case 3:
1046 dma_bits = 0x03;
1047 break;
1048 default:
1049 snd_printk(KERN_ERR "WSS dma1 # %d not valid\n", chip->dma1);
1050 goto __skip_resources;
1051 }
1052
1053 if (chip->dma1 == chip->dma2) {
1054 snd_printk(KERN_ERR "don't want to share dmas\n");
1055 return -EBUSY;
1056 }
1057
1058 switch (chip->dma2) {
1059 case 0:
1060 case 1:
1061 break;
1062 default:
1063 snd_printk(KERN_ERR "WSS dma2 # %d not valid\n", chip->dma2);
1064 goto __skip_resources;
1065 }
1066 dma_bits |= 0x04;
1067
1068 spin_lock_irqsave(&chip->lock, flags);
1069 outb(irq_bits << 3 | dma_bits, chip->wss_base);
1070 spin_unlock_irqrestore(&chip->lock, flags);
1071
1072__skip_resources:
1073 if (chip->hardware > OPTi9XX_HW_82C928) {
1074 switch (chip->mpu_port) {
1075 case 0:
1076 case -1:
1077 break;
1078 case 0x300:
1079 mpu_port_bits = 0x03;
1080 break;
1081 case 0x310:
1082 mpu_port_bits = 0x02;
1083 break;
1084 case 0x320:
1085 mpu_port_bits = 0x01;
1086 break;
1087 case 0x330:
1088 mpu_port_bits = 0x00;
1089 break;
1090 default:
1091 snd_printk(KERN_ERR "MPU-401 port 0x%lx not valid\n",
1092 chip->mpu_port);
1093 goto __skip_mpu;
1094 }
1095
1096 switch (chip->mpu_irq) {
1097 case 5:
1098 mpu_irq_bits = 0x02;
1099 break;
1100 case 7:
1101 mpu_irq_bits = 0x03;
1102 break;
1103 case 9:
1104 mpu_irq_bits = 0x00;
1105 break;
1106 case 10:
1107 mpu_irq_bits = 0x01;
1108 break;
1109 default:
1110 snd_printk(KERN_ERR "MPU-401 irq # %d not valid\n",
1111 chip->mpu_irq);
1112 goto __skip_mpu;
1113 }
1114
1115 snd_miro_write_mask(chip, OPTi9XX_MC_REG(6),
1116 (chip->mpu_port <= 0) ? 0x00 :
1117 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
1118 0xf8);
1119 }
1120__skip_mpu:
1121
1122 return 0;
1123}
1124
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001125static int __devinit snd_card_miro_detect(struct snd_card *card,
1126 struct snd_miro *chip)
Martin Langer1841f612006-03-27 12:41:01 +02001127{
1128 int i, err;
1129 unsigned char value;
1130
1131 for (i = OPTi9XX_HW_82C929; i <= OPTi9XX_HW_82C924; i++) {
1132
1133 if ((err = snd_miro_init(chip, i)) < 0)
1134 return err;
1135
1136 if ((chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, "OPTi9xx MC")) == NULL)
1137 continue;
1138
1139 value = snd_miro_read(chip, OPTi9XX_MC_REG(1));
1140 if ((value != 0xff) && (value != inb(chip->mc_base + 1)))
1141 if (value == snd_miro_read(chip, OPTi9XX_MC_REG(1)))
1142 return 1;
1143
Takashi Iwai10d150e2006-03-27 13:42:39 +02001144 release_and_free_resource(chip->res_mc_base);
Martin Langer1841f612006-03-27 12:41:01 +02001145 chip->res_mc_base = NULL;
1146
1147 }
1148
1149 return -ENODEV;
1150}
1151
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001152static int __devinit snd_card_miro_aci_detect(struct snd_card *card,
1153 struct snd_miro * miro)
Martin Langer1841f612006-03-27 12:41:01 +02001154{
1155 unsigned char regval;
1156 int i;
1157
1158 mutex_init(&miro->aci_mutex);
1159
1160 /* get ACI port from OPTi9xx MC 4 */
1161
1162 miro->mc_base = 0xf8c;
1163 regval=inb(miro->mc_base + 4);
1164 miro->aci_port = (regval & 0x10) ? 0x344: 0x354;
1165
1166 if ((miro->res_aci_port = request_region(miro->aci_port, 3, "miro aci")) == NULL) {
1167 snd_printk(KERN_ERR "aci i/o area 0x%lx-0x%lx already used.\n",
1168 miro->aci_port, miro->aci_port+2);
1169 return -ENOMEM;
1170 }
1171
1172 /* force ACI into a known state */
1173 for (i = 0; i < 3; i++)
1174 if (aci_cmd(miro, ACI_ERROR_OP, -1, -1) < 0) {
Martin Langer1841f612006-03-27 12:41:01 +02001175 snd_printk(KERN_ERR "can't force aci into known state.\n");
1176 return -ENXIO;
1177 }
1178
1179 if ((miro->aci_vendor=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0 ||
1180 (miro->aci_product=aci_cmd(miro, ACI_READ_IDCODE, -1, -1)) < 0) {
Martin Langer1841f612006-03-27 12:41:01 +02001181 snd_printk(KERN_ERR "can't read aci id on 0x%lx.\n", miro->aci_port);
1182 return -ENXIO;
1183 }
1184
1185 if ((miro->aci_version=aci_cmd(miro, ACI_READ_VERSION, -1, -1)) < 0) {
Martin Langer1841f612006-03-27 12:41:01 +02001186 snd_printk(KERN_ERR "can't read aci version on 0x%lx.\n",
1187 miro->aci_port);
1188 return -ENXIO;
1189 }
1190
1191 if (aci_cmd(miro, ACI_INIT, -1, -1) < 0 ||
1192 aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0 ||
1193 aci_cmd(miro, ACI_ERROR_OP, ACI_ERROR_OP, ACI_ERROR_OP) < 0) {
1194 snd_printk(KERN_ERR "can't initialize aci.\n");
1195 return -ENXIO;
1196 }
1197
1198 return 0;
1199}
1200
1201static void snd_card_miro_free(struct snd_card *card)
1202{
1203 struct snd_miro *miro = card->private_data;
1204
1205 release_and_free_resource(miro->res_aci_port);
1206 release_and_free_resource(miro->res_mc_base);
1207}
1208
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001209static int __devinit snd_miro_match(struct device *devptr, unsigned int n)
1210{
1211 return 1;
1212}
1213
1214static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
Martin Langer1841f612006-03-27 12:41:01 +02001215{
1216 static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
1217 static long possible_mpu_ports[] = {0x330, 0x300, 0x310, 0x320, -1};
1218 static int possible_irqs[] = {11, 9, 10, 7, -1};
1219 static int possible_mpu_irqs[] = {10, 5, 9, 7, -1};
1220 static int possible_dma1s[] = {3, 1, 0, -1};
1221 static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
1222
1223 int error;
1224 struct snd_miro *miro;
1225 struct snd_cs4231 *codec;
1226 struct snd_timer *timer;
1227 struct snd_card *card;
1228 struct snd_pcm *pcm;
1229 struct snd_rawmidi *rmidi;
1230
1231 if (!(card = snd_card_new(index, id, THIS_MODULE,
1232 sizeof(struct snd_miro))))
1233 return -ENOMEM;
1234
1235 card->private_free = snd_card_miro_free;
1236 miro = card->private_data;
1237 miro->card = card;
1238
1239 if ((error = snd_card_miro_aci_detect(card, miro)) < 0) {
1240 snd_card_free(card);
1241 snd_printk(KERN_ERR "unable to detect aci chip\n");
1242 return -ENODEV;
1243 }
1244
1245 /* init proc interface */
1246 snd_miro_proc_init(miro);
1247
1248 if ((error = snd_card_miro_detect(card, miro)) < 0) {
1249 snd_card_free(card);
1250 snd_printk(KERN_ERR "unable to detect OPTi9xx chip\n");
1251 return -ENODEV;
1252 }
1253
1254 if (! miro->res_mc_base &&
1255 (miro->res_mc_base = request_region(miro->mc_base, miro->mc_base_size,
1256 "miro (OPTi9xx MC)")) == NULL) {
1257 snd_card_free(card);
1258 snd_printk(KERN_ERR "request for OPTI9xx MC failed\n");
1259 return -ENOMEM;
1260 }
1261
1262 miro->wss_base = port;
1263 miro->fm_port = fm_port;
1264 miro->mpu_port = mpu_port;
1265 miro->irq = irq;
1266 miro->mpu_irq = mpu_irq;
1267 miro->dma1 = dma1;
1268 miro->dma2 = dma2;
1269
1270 if (miro->wss_base == SNDRV_AUTO_PORT) {
1271 if ((miro->wss_base = snd_legacy_find_free_ioport(possible_ports, 4)) < 0) {
1272 snd_card_free(card);
1273 snd_printk(KERN_ERR "unable to find a free WSS port\n");
1274 return -EBUSY;
1275 }
1276 }
1277
1278 if (miro->mpu_port == SNDRV_AUTO_PORT) {
1279 if ((miro->mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
1280 snd_card_free(card);
1281 snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
1282 return -EBUSY;
1283 }
1284 }
1285 if (miro->irq == SNDRV_AUTO_IRQ) {
1286 if ((miro->irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
1287 snd_card_free(card);
1288 snd_printk(KERN_ERR "unable to find a free IRQ\n");
1289 return -EBUSY;
1290 }
1291 }
1292 if (miro->mpu_irq == SNDRV_AUTO_IRQ) {
1293 if ((miro->mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
1294 snd_card_free(card);
1295 snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
1296 return -EBUSY;
1297 }
1298 }
1299 if (miro->dma1 == SNDRV_AUTO_DMA) {
1300 if ((miro->dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
1301 snd_card_free(card);
1302 snd_printk(KERN_ERR "unable to find a free DMA1\n");
1303 return -EBUSY;
1304 }
1305 }
1306 if (miro->dma2 == SNDRV_AUTO_DMA) {
1307 if ((miro->dma2 = snd_legacy_find_free_dma(possible_dma2s[miro->dma1 % 4])) < 0) {
1308 snd_card_free(card);
1309 snd_printk(KERN_ERR "unable to find a free DMA2\n");
1310 return -EBUSY;
1311 }
1312 }
1313
1314 if ((error = snd_miro_configure(miro))) {
1315 snd_card_free(card);
1316 return error;
1317 }
1318
1319 if ((error = snd_cs4231_create(card, miro->wss_base + 4, -1,
1320 miro->irq, miro->dma1, miro->dma2,
1321 CS4231_HW_AD1845,
1322 0,
1323 &codec)) < 0) {
1324 snd_card_free(card);
1325 return error;
1326 }
1327
1328 if ((error = snd_cs4231_pcm(codec, 0, &pcm)) < 0) {
1329 snd_card_free(card);
1330 return error;
1331 }
1332 if ((error = snd_cs4231_mixer(codec)) < 0) {
1333 snd_card_free(card);
1334 return error;
1335 }
1336 if ((error = snd_cs4231_timer(codec, 0, &timer)) < 0) {
1337 snd_card_free(card);
1338 return error;
1339 }
1340
1341 miro->pcm = pcm;
1342
1343 if ((error = snd_miro_mixer(miro)) < 0) {
1344 snd_card_free(card);
1345 return error;
1346 }
1347
1348 if (miro->aci_vendor == 'm') {
1349 /* It looks like a miro sound card. */
1350 switch (miro->aci_product) {
1351 case 'A':
1352 sprintf(card->shortname,
1353 "miroSOUND PCM1 pro / PCM12");
1354 break;
1355 case 'B':
1356 sprintf(card->shortname,
1357 "miroSOUND PCM12");
1358 break;
1359 case 'C':
1360 sprintf(card->shortname,
1361 "miroSOUND PCM20 radio");
1362 break;
1363 default:
1364 sprintf(card->shortname,
1365 "unknown miro");
1366 snd_printk(KERN_INFO "unknown miro aci id\n");
1367 break;
1368 }
1369 } else {
1370 snd_printk(KERN_INFO "found unsupported aci card\n");
1371 sprintf(card->shortname, "unknown Cardinal Technologies");
1372 }
1373
1374 strcpy(card->driver, "miro");
1375 sprintf(card->longname, "%s: OPTi%s, %s at 0x%lx, irq %d, dma %d&%d",
1376 card->shortname, miro->name, pcm->name, miro->wss_base + 4,
1377 miro->irq, miro->dma1, miro->dma2);
1378
1379 if (miro->mpu_port <= 0 || miro->mpu_port == SNDRV_AUTO_PORT)
1380 rmidi = NULL;
1381 else
1382 if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
Thomas Gleixner65ca68b2006-07-01 19:29:46 -07001383 miro->mpu_port, 0, miro->mpu_irq, IRQF_DISABLED,
Martin Langer1841f612006-03-27 12:41:01 +02001384 &rmidi)))
1385 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", miro->mpu_port);
1386
1387 if (miro->fm_port > 0 && miro->fm_port != SNDRV_AUTO_PORT) {
1388 struct snd_opl3 *opl3 = NULL;
1389 struct snd_opl4 *opl4;
1390 if (snd_opl4_create(card, miro->fm_port, miro->fm_port - 8,
1391 2, &opl3, &opl4) < 0)
1392 snd_printk(KERN_WARNING "no OPL4 device at 0x%lx\n", miro->fm_port);
1393 }
1394
1395 if ((error = snd_set_aci_init_values(miro)) < 0) {
1396 snd_card_free(card);
1397 return error;
1398 }
1399
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001400 snd_card_set_dev(card, devptr);
Martin Langer1841f612006-03-27 12:41:01 +02001401
1402 if ((error = snd_card_register(card))) {
1403 snd_card_free(card);
1404 return error;
1405 }
1406
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001407 dev_set_drvdata(devptr, card);
Martin Langer1841f612006-03-27 12:41:01 +02001408 return 0;
1409}
1410
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001411static int __devexit snd_miro_remove(struct device *devptr, unsigned int dev)
Martin Langer1841f612006-03-27 12:41:01 +02001412{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001413 snd_card_free(dev_get_drvdata(devptr));
1414 dev_set_drvdata(devptr, NULL);
Martin Langer1841f612006-03-27 12:41:01 +02001415 return 0;
1416}
1417
Rene Herman83c51c02007-03-20 11:33:46 +01001418#define DEV_NAME "miro"
1419
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001420static struct isa_driver snd_miro_driver = {
1421 .match = snd_miro_match,
Martin Langer1841f612006-03-27 12:41:01 +02001422 .probe = snd_miro_probe,
1423 .remove = __devexit_p(snd_miro_remove),
1424 /* FIXME: suspend/resume */
1425 .driver = {
Rene Herman83c51c02007-03-20 11:33:46 +01001426 .name = DEV_NAME
Martin Langer1841f612006-03-27 12:41:01 +02001427 },
1428};
1429
1430static int __init alsa_card_miro_init(void)
1431{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001432 return isa_register_driver(&snd_miro_driver, 1);
Martin Langer1841f612006-03-27 12:41:01 +02001433}
1434
1435static void __exit alsa_card_miro_exit(void)
1436{
Takashi Iwai5e24c1c2007-02-22 12:50:54 +01001437 isa_unregister_driver(&snd_miro_driver);
Martin Langer1841f612006-03-27 12:41:01 +02001438}
1439
1440module_init(alsa_card_miro_init)
1441module_exit(alsa_card_miro_exit)